struct
Bindgen::Cpp::Pass
- Bindgen::Cpp::Pass
- Struct
- Value
- Object
Overview
Methods for passing data from and to C++.
This is a helper struct: Cheap to create and to pass around.
Included Modules
Defined in:
bindgen/cpp/pass.crConstructors
Instance Method Summary
-
#arguments_from_cpp(list : Enumerable(Parser::Argument))
Builds the out argument arg of a C++ wrapper function, see
TypeDatabase#converted_out_argument?. -
#arguments_to_cpp(list : Enumerable(Parser::Argument))
Turns the list of arguments into a list of
Call::Arguments. -
#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.
-
#through(type : Parser::Type)
Passes the type through without changes.
-
#through_arguments(list : Enumerable(Parser::Argument))
Builds the out argument arg of a C++ wrapper function, see
TypeDatabase#converted_out_argument?. -
#to_cpp(type : Parser::Type) : Call::Result
Computes a result for passing type from Crystal to C++.
-
#to_crystal(type : Parser::Type, is_constructor = false) : Call::Result
Also see
#pass_to_cppfor the reverse direction. -
#type_name_base(type : Parser::Type) : String
Returns the type name of type, ignoring conversion templates.
Instance methods inherited from module Bindgen::TypeHelper
cpp_class_name(class_name : String) : String
cpp_class_name,
passthrough(type : Parser::Type)
passthrough,
proc_by_pointer?(type : Parser::Type) : Bool
proc_by_pointer?,
reconfigure_pass_type(pass_by, is_ref, ptr)
reconfigure_pass_type,
structure_hosted?(rules : TypeDatabase::TypeConfig) : Bool
structure_hosted?,
type_copied?(type) : Bool
type_copied?,
type_pointer_depth(type : Parser::Type) : Int32
type_pointer_depth,
variadic_argument : Call::VariadicArgument
variadic_argument
Constructor Detail
Instance Method Detail
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.
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.
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.
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.
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:
- The type is a value-type and passed by-value a. The type is copied? Then pass by-value. b. Else, pass by-reference.
- The type is passed by-reference a. Pass by-reference
- The type is passed by-pointer a. Pass by-pointer
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:
- If is_constructor and the type is copied
a. Then pass by-value. (See
MethodName#generatetoo) - If pass by-reference a. Invoke the types copy-constructor and pass by-pointer.
- If pass by-value but the type is not copied a. Invoke the types copy-constructor and pass by-pointer.
- In all other cases a. Pass by-reference or by-pointer as defined by type.
Returns the type name of type, ignoring conversion templates.