struct Bindgen::Cpp::Pass

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.cr

Constructors

Instance Method Summary

Instance methods inherited from module Bindgen::TypeHelper

passthrough(type : Parser::Type) passthrough, reconfigure_pass_type(pass_by, is_ref, ptr) reconfigure_pass_type, type_copied?(type) : Bool type_copied?, type_pointer_depth(type : Parser::Type) : Int32 type_pointer_depth, variadic_argument : Call::VariadicArgument variadic_argument

Constructor Detail

def self.new(db : TypeDatabase) #

[View source]

Instance Method Detail

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

Turns the list of arguments into a list of Call::Arguments.


[View source]
def arguments_to_cpp(list : Enumerable(Parser::Argument)) #

Turns the list of arguments into a list of Call::Arguments.


[View source]
def crystal_proc_name(proc_type : Parser::Type) : String #

Returns the type name of proc_type.


[View source]
def 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.


[View source]
def through(type : Parser::Type) #

Passes the type through without changes.


[View source]
def through_arguments(list : Enumerable(Parser::Argument)) #

Turns the list of arguments into a list of Call::Arguments.


[View source]
def 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

[View source]
def to_crystal(type : Parser::Type, is_constructor = false) : Call::Result #

Computes a result for passing type from C++ to Crystal. 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.

[View source]