class

Bindgen::Parser::Method

Inherits JSON::Serializable < Reference < Object

Describes a method as found by the clang tool.

Constants

Log = ::Log.for(self)
RESERVED_NAMES = ["initialize", "finalize"] of ::String

Method names Crystal reserves, which a C++ method of that name gets prefixed with cpp_: QHeaderView::initialize is #cpp_initialize.

Constructors

build(name, return_type : Parser::Type, arguments : Array(Parser::Argument), class_name : String, type = Parser::Method::Type::MemberMethod, access = AccessSpecifier::Public, crystal_name = nil) : self

Utility method to easily build a Method using a more Crystal-style syntax.

Source
from_signature(signature : String, class_name : String) : Method

Parses a C++ member method declaration, as written in a header, into a Method of the class class_name, for the declare_methods: type rule: QMenu *menu() const, static Foo *make(int count = 1), void setMenu(QMenu *menu). Every argument is named, like in a declaration. A default is exposed if it's a literal number, boolean or nullptr. Raises an ArgumentError for anything else.

Source
new(name : String, class_name : String, return_type : Bindgen::Parser::Type, arguments : Array(Bindgen::Parser::Argument), first_default_argument : Int32 | Nil = nil, access : Bindgen::Parser::AccessSpecifier = AccessSpecifier::Public, type : Bindgen::Parser::Method::Type = Type::MemberMethod, const : Bool = false, virtual : Bool = false, pure : Bool = false, final : Bool = false, extern_c : Bool = false, builtin : Bool = false, origin : Nil | Bindgen::Parser::Method = nil, crystal_name : Nil | String = nil, binding_name : Nil | String = nil, doc : Nil | String = nil, deprecated : Bool = false, free_function : Bool = false)
Source
new(*, __pull_for_json_serializable pull : JSON::PullParser)
Source

Instance methods

==(other : self)

Returns true if this reference is the same as other. Invokes same?.

access

Visibility of the method.

Source
aggregate_constructor?(*args, **options)
Source
aggregate_constructor?(*args, **options, &)
Source
any_constructor?(*args, **options)
Source
any_constructor?(*args, **options, &)
Source
any_default_constructor?

Is this a constructor that can take no arguments?

Source
arguments

Arguments of the method.

Source
arguments=(arguments : Array(Argument))

Arguments of the method.

Source
binding_method_name

Name of the method in C++ and Crystal bindings. If an explicit #binding_name name is set, it'll be returned without further processing.

Source
binding_name=(binding_name : String | Nil)

Forces the bindings to use the specified name.

Source
binding_operator_name

Name of the unary operator method in C++ and Crystal bindings. Uniquely identifies a C++ operator.

Source
builtin?

Is this a method implicitly generated by C++?

Source
class_name

Fully qualified name of the class in which the method is defined.

Source
const?

Returns if the method is const-qualified: std::string getName() const;

Source
constructor?(*args, **options)
Source
constructor?(*args, **options, &)
Source
conversion_operator?(*args, **options)
Source
conversion_operator?(*args, **options, &)
Source
copy_constructor?(*args, **options)
Source
copy_constructor?(*args, **options, &)
Source
crystal_name(override : String | Nil = nil) : String

Turns the method name into something canonical to Crystal. If an explicit #crystal_name name is set, it'll be returned without further processing. If override is not nil, it'll be used over #name. Otherwise, the generated name will be based on #name.

Source
crystal_name=(crystal_name : String | Nil)

Forces the Crystal wrapper to use the specified name.

Source
deprecated?

Is this method declared [[deprecated]]? Removed by the filter_methods processor if ignore_deprecated is configured.

Source
destructor?(*args, **options)
Source
destructor?(*args, **options, &)
Source
doc

Documentation comment from the C++ source, without comment markers.

Source
equals_except_const?(other : Method) : Bool

Checks if this method is equal to other, except for the const-qualification.

Source
equals_virtually?(other : Method) : Bool

Checks if this method is equal to other, as is suitable to determine if they're the same for C++ virtual methods between parent- and sub-classes.

Source
explicit_crystal_name?

Checks if the #crystal_name was set explicitly (true), or will be generated (false).

Source
extern_c?

Does this function use the C ABI?

Source
filtered?(db : TypeDatabase) : Bool

Is this method filtered out?

TODO: Can we move this into Processor::FilterMethods?

Source
final?

Is this a final virtual function, which can't be overridden?

Source
first_default_argument

The index of the first argument with a default value, if any.

Source
fix_post_succ_or_pred?

Checks if this method is a post-increment or post-decrement method that takes a placeholder int argument. If true, returns a copy of this method with the int argument removed.

Source
free_function?

Is this a free function of member_functions, like qHash, bound as a member method of the class of its first argument, which is self? The C++ glue calls it with *_self_ first.

Source
function_pointer(name : String | Nil = nil) : String

Generates a C++ function pointer type matching this methods prototype.

Source
getter?(name = @name)

Try to deduce if this is a getter.

Source
has_move_semantics?

Does this method have move semantics anywhere?

Source
has_result?

Returns if this method returns something, or not

Source
hash(hasher)

See Object#hash(hasher)

macro?(*args, **options)
Source
macro?(*args, **options, &)
Source
mangled_name

Mangled name for the C++ wrapper method name

Source
member_getter?(*args, **options)
Source
member_getter?(*args, **options, &)
Source
member_method?(*args, **options)
Source
member_method?(*args, **options, &)
Source
member_setter?(*args, **options)
Source
member_setter?(*args, **options, &)
Source
merge(other : Method) : Method

Merges this and the other method with regards to default values and type deductions. Expects that this and other methods point at the same method, but in different classes in the inheritance chain.

Keeps the class name, access, constness, virtuality and type of this method.

Source
merge_args!(other : Method)

Unify arguments of this and another method.

Modifies the argument list of this method.

Source
name

Name of the method.

Source
needs_instance?

Returns if this method needs a class instance to be called.

Source
operator?(*args, **options)
Source
operator?(*args, **options, &)
Source
origin

The method this method is based on. Used by #variants to indicate the methods origin when splitting occurs.

Source
out_arguments(db : TypeDatabase) : Array(Int32)

The indices of the out arguments: the non-const references and pointers to converted value types (TypeDatabase#converted_out_argument?), like QString & or QString *, and in a method having one, those to built-in types and enums too (TypeDatabase#builtin_out_argument?), like int &. The wrapper appends their values to the result: a reference is an in/out argument, which it keeps, a pointer is out-only, which it drops. Empty for a method which can't take out arguments, see #takes_out_arguments?, and for one without a converted out argument, whose int & stays an Int32*.

An out_arguments entry of the class decides instead, see TypeDatabase#out_arguments_rule: true takes every such argument, false none, and a list of indices those among them. Without one, with TypeDatabase#builtin_out_arguments? the built-in ones are out arguments in every method, not only next to a converted one; a pointer to a byte or character type, or to void, is a buffer then, not an out argument (TypeDatabase#buffer_argument?).

Source
private?(*args, **options)
Source
private?(*args, **options, &)
Source
protected?(*args, **options)
Source
protected?(*args, **options, &)
Source
public?(*args, **options)
Source
public?(*args, **options, &)
Source
pure?

Is this a pure virtual function?

Source
qualified_name

Fully qualified name of the method: class_name::name. For a function in the global scope, it's the name itself.

Source
question_getter?(name = @name)

Try to deduce if this is a getter for a boolean value.

Source
return_type

The return type of this method

Source
return_type=(return_type : Bindgen::Parser::Type)

Replaces the return type, see the nilable: type rule.

Source
same_crystal_signature?(other : Method) : Bool

Does other have the same Crystal name and argument types, like try_lock next to tryLock? Both would define the same method.

Source
setter?(name = @name)

Try to deduce if this is a setter.

Source
signal?(*args, **options)
Source
signal?(*args, **options, &)
Source
signature

C++ signature of the method, naming its overload: name(type, type), with const appended for a const method. The argument types are written like the parser prints them, const QString &, int *. TypeDatabase::MethodPattern matches ignore_methods against it.

Source
static?(*args, **options)
Source
static?(*args, **options, &)
Source
static_getter?(*args, **options)
Source
static_getter?(*args, **options, &)
Source
static_method?(*args, **options)
Source
static_method?(*args, **options, &)
Source
static_setter?(*args, **options)
Source
static_setter?(*args, **options, &)
Source
substitute_type(name : String, with type : Type) : Method

Substitutes all uses of name on the argument and return types of this method with the given type.

Source
substitute_type(replacements : Hash(String, Parser::Type)) : Method

Performs type substitution on the argument and return types of this method using the given replacements.

Source
superclass_copy

Returns a non-virtual copy of this method suitable for use in superclass wrapper structs. The bodies of such copies are expected to ignore method overriding.

Source
supported_operator?

Is this operator one bindgen can name, like operator+? Not operator-> or operator,, which filter_methods drops.

Source
takes_out_arguments?

Can this method have out arguments? A constructor usually keeps the pointer it is given, like QTextStream(QString *), and so does the setter of a pointer member, a signal passes its arguments to the block, and an operator returning a tuple would be odd: these keep dropping the non-const references and pointers to converted types.

Source
takes_storage_references?

Can this method take a pointer to the structure a wrapper hosts, see TypeDatabase#storage_reference?? Not a virtual method, whose Crystal override would get a copy, nor a signal or a constructor.

Source
type

Type of the method.

Source
variadic?

Does this function take a variable amount of arguments?

Source
variants

Yields all variants of this method, going through an increasing level of default arguments. It will respect exposed default-values.

A C++ method like int foo(int a, int b = 1, std::string c = "foo") would yield two methods like:

  • int foo(int a, int b, std::string c)
  • int foo(int a, int b = 1)

Note that only built-in types (These are: Integers, Floats and Booleans) support an exposed default value. For other types (Like std::string in the example), no default value will be set.

Also see #find_variant_splits for the algorithm.

Source
variants

Non-yielding version of #variants.

Source
virtual=(virtual : Bool)

Makes the method non-virtual for the wrappers, so a Crystal subclass can't override it, and the C++ subclass of Processor::VirtualOverride gets no forwarder for it: the Qt processor does this to the methods Q_OBJECT declares, which Processor::QtMetaObject overrides itself.

Source
virtual?

Is this a virtual function?

Source

Nested types