class Bindgen::TypeDatabase

Overview

Database of type mapping data for wrapper-code generation. Configuration for common (and built-in) C/C++ types is automatically loaded and added.

Defined in:

bindgen/type_database.cr

Constant Summary

BUFFER_BASE_TYPES = ["char", "wchar_t", "char8_t", "char16_t", "char32_t"] of ::String

The C++ types a method takes a buffer of by pointer, not a value to write.

BUILTIN_CONFIG_PATH = "/srv/crystaldoc.info/github-Papierkorb-bindgen-v0.16.2/src/bindgen/../../builtin_types.yml"

Path to the built-in type configuration. This file defines mappings for most-ish built-in (and other common) types in C++.

BYTE_BINDING_TYPES = ["UInt8", "Int8"] of ::String

The binding types of a byte: a pointer to one is a buffer too, like uchar * or quint8 *.

Log = ::Log.for(self)

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(config : Configuration, cookbook : String | Cpp::Cookbook, with_builtins = true) #

[View source]

Class Method Detail

def self.load_builtins : Configuration #

Helper method to read the built-in type configuration.


[View source]

Instance Method Detail

def [](type : String | Parser::Type) #

Look up type in the database. If type is a Parser::Type, the best match will be found by gradually decaying the type (See Parser::Type#decayed).

Prefer passing a Parser::Type over passing a String.

Also see #[]?.


[View source]
def []?(name : String) #

Look up type in the database with the given name. name is expected to be the base name of a C++ type. If you actually have a full type-name instead, use Parser::Type.parse first, and pass that instead.

Prefer passing a Parser::Type over passing a String.


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

Look up type in the database. The best match will be found by gradually decaying the type (See Parser::Type#decayed). This enables the user to write rules for int * and int without clashes.


[View source]
def add(name : String, rules : TypeConfig) #

Adds a type rules as name. Overwrites any old rules previously added to the same type name. name must not refer to an existing alias.

Also see #get_or_add to add rules from processors.


[View source]
def add(name : String, **rules) #

Quickly adds the rules to name. Used for testing purposes.

Also see #get_or_add to add rules from processors.


[View source]
def add_alias(name : String, alias_for aliased : String) #

Adds an alias name that refers to the aliased type. name must not refer to an existing type or a different alias. Raises if adding the given alias would result in a recursive alias loop.


[View source]
def add_sparse_type(cpp_name : String, crystal_name : String | Nil, kind) #

Adds a type configuration to the type database. If a configuration for this type was set by the user, it's updated - not replaced!


[View source]
def array_view?(type : Parser::Type) : Bool #

Is type a one-dimensional C array of a wrapped class by value? These are passed as Binding::CrystalArray, wrapped by BindgenHelper::ArrayView in Crystal.


[View source]
def buffer_argument?(type : Parser::Type) : Bool #

Is type a pointer to a byte or character type, like char *, uchar * or wchar_t *, or to void? A method writes a buffer through such a pointer, not a value, so it isn't an out argument unless an out_arguments entry says so, see Parser::Method#out_arguments. A reference to one, like char &, is a value.


[View source]
def builtin_out_argument?(type : Parser::Type) : Bool #

Is type a non-const lvalue reference or single pointer to a built-in type or an enum, like int & or bool *? Such an argument is passed as a pointer, and is an out argument too in a method with a converted one.


[View source]
def builtin_out_arguments=(builtin_out_arguments : Bool) #

Is every non-const reference or pointer to a built-in type or enum a method writes through an out argument? See Configuration#builtin_out_arguments? and Parser::Method#out_arguments.


[View source]
def builtin_out_arguments? : Bool #

Is every non-const reference or pointer to a built-in type or enum a method writes through an out argument? See Configuration#builtin_out_arguments? and Parser::Method#out_arguments.


[View source]
def c_array_supported?(type : Parser::Type) : Bool #

Can the complete C array type, or a single pointer or reference to one, be passed to Crystal? Its elements have to be built-in types, or enums, copied structures or wrapped classes by value. For the latter three only references to arrays are supported, and for wrapped classes only one-dimensional arrays. See #array_view?.


[View source]
def converted_out_argument?(type : Parser::Type) : Bool #

Is type a converted out argument: a non-const lvalue reference or single pointer to a type passed by value (pass_by: Value) and converted both ways by to_cpp and from_cpp, like QString & or QString *? Such a type only exists in C++ as a temporary made by its to_cpp template, so the C++ glue calls the method on a local and hands the changed value back, see Parser::Method#out_arguments.


[View source]
def cookbook : Cpp::Cookbook #

[View source]
def each(*args, **options) #

[View source]
def each(*args, **options, &) #

[View source]
def get_or_add(type : Parser::Type | String) : TypeConfig #

Returns the rules for type. If none are found, a new TypeConfig is inserted, and returned.

This is the method you want to use to add or change rules from within processors.

Important: If type is a Parser::Type, then its #base_name is used - not the #full_name. If you want to provide configuration for a specific type, pass the #full_name as string.


[View source]
def nilable_results=(nilable_results : Bool) #

Are pointers to wrapped classes returned as T?? See Configuration#nilable_results?.


[View source]
def nilable_results? : Bool #

Are pointers to wrapped classes returned as T?? See Configuration#nilable_results?.


[View source]
def object_argument?(arg : Parser::Argument) : Bool #

Is arg an instance of a wrapped class passed by pointer or reference? Wrappers of kind: Struct don't count, see #selected_object_arguments.


[View source]
def object_type?(type : Parser::Type) : Bool #

Is type a wrapped class passed by pointer or reference, like an object argument or a result handing an object back?


[View source]
def out_arguments_rule(method : Parser::Method) : Bool | Array(Int32) | Nil #

The out_arguments rule for the method: the first matching entry of its class, or of the nearest base class with one, see TypeConfig#out_arguments_for, so an override is wrapped like the method it overrides. nil without an entry.


[View source]
def resolve_aliases(type : Parser::Type | String) #

Resolves type aliases referred to by type or the name of a type. Returns a type without aliases.


[View source]
def selected_object_arguments(method : Parser::Method, rules : KeepAlive) : Array(Int32) #

Returns the indices of the arguments of method selected by rules, a keep_alive: or depends_on: configuration: Those of the patterns matching the method name, narrowed down to instances of wrapped classes passed by pointer or reference. Wrappers of kind: Struct are skipped, as they are Crystal structs and their pointer arguments stay pointers.


[View source]
def selects_all_arguments?(method : Parser::Method, rules : KeepAlive) : Bool #

Does a rule of rules matching the method select all of its arguments? release: releases the result of such a method too.


[View source]
def shadowed_overload?(method : Parser::Method, methods : Enumerable(Parser::Method)) : Bool #

Is method an overload shadowed by another of methods, see TypeConfig#shadowed_by? The other takes a shadowing type in place of each argument of a shadowed type, like QString for QStringView, and the same types otherwise: both would take the same Crystal arguments.


[View source]
def storage_reference?(type : Parser::Type) : Bool #

Is type a non-const reference or pointer to a copied structure passed by value (pass_by: Value) with a wrapper, like QPoint & or QPointF *? The wrapper passes a pointer to the structure's storage, so the method writes into it: into the object of a wrapper class hosting the structure (stream >> point), or into the Crystal struct of a kind: Struct wrapper, taken by pointer (stream >> pointerof(point)). A pointer may be null: nil.


[View source]
def struct_wrapper?(type : Parser::Type) : Bool #

Is the wrapper of type a Crystal struct, see #storage_reference??


[View source]
def try_or(type : Parser::Type | String, default, &) #

Helper, equivalent to calling #[type]?.try(&.x) || default


[View source]