struct

Bindgen::Cpp::Pass

Inherits Bindgen::TypeHelper < Struct < Value < Object

Methods for passing data from and to C++.

This is a helper struct: Cheap to create and to pass around.

Constructors

new(db : TypeDatabase)
Source

Instance methods

arguments_from_cpp(list : Enumerable(Parser::Argument))

Builds the out argument arg of a C++ wrapper function, see TypeDatabase#converted_out_argument?. The function takes a pointer to the binding structure, like CrystalString *, converts it into a local of the C++ type, passes that to the method, and converts the local back through the pointer afterwards. The local is moved into the from_cpp conversion, so a conversion keeping a temporary's data, like the std::string one, copies it. A pointer argument is out-only: the local starts out value-initialized.

Source
arguments_to_cpp(list : Enumerable(Parser::Argument))

Turns the list of arguments into a list of Call::Arguments. A non-const reference or pointer to a converted type becomes a Call::OutArgument, see #out_argument_to_cpp.

Source
passthrough_to_crystal(type : Parser::Type)

Computes a result which is directly usable from C++ code, without changes, and passes it through to crystal using conversion.

The pass rules are similar to #to_crystal. The primary difference is that this version has no special handling of constructors.

There is a second major difference: This method always signals the C++ type to the outside, as received by C++ (Thus even ignoring rules.cpp_type!). It still follows the passing rules towards Crystal.

Source
through(type : Parser::Type)

Passes the type through without changes.

Source
through_arguments(list : Enumerable(Parser::Argument))

Builds the out argument arg of a C++ wrapper function, see TypeDatabase#converted_out_argument?. The function takes a pointer to the binding structure, like CrystalString *, converts it into a local of the C++ type, passes that to the method, and converts the local back through the pointer afterwards. The local is moved into the from_cpp conversion, so a conversion keeping a temporary's data, like the std::string one, copies it. A pointer argument is out-only: the local starts out value-initialized.

Source
to_cpp(type : Parser::Type) : Call::Result

Computes a result for passing type from Crystal to C++.

The primary job of this method is to figure out how to pass something of type over to C++. It doesn't matter if this is a result from a method or an argument for this. It also signals how a value of this type shall be handled by the receiver, e.g., if conversions apply (Which?).

The method responsible for the opposite direction is #to_crystal.

Pass rules:

  1. The type is a value-type and passed by-value a. The type is copied? Then pass by-value. b. Else, pass by-reference.
  2. The type is passed by-reference a. Pass by-reference
  3. The type is passed by-pointer a. Pass by-pointer
Source
to_crystal(type : Parser::Type, is_constructor = false) : Call::Result

Also see #pass_to_cpp for the reverse direction. See #passthrough_to_crystal to call Crystal from C++.

Set is_constructor to true if this is a return-result of a method and this method is a constructor.

Pass rules:

  1. If is_constructor and the type is copied a. Then pass by-value. (See MethodName#generate too)
  2. If pass by-reference a. Invoke the types copy-constructor and pass by-pointer.
  3. If pass by-value but the type is not copied a. Invoke the types copy-constructor and pass by-pointer.
  4. In all other cases a. Pass by-reference or by-pointer as defined by type.
Source
type_name_base(type : Parser::Type) : String

Returns the type name of type, ignoring conversion templates.

Source