class Bindgen::Parser::Type

Overview

Stores information about a specific C++ type.

Included Modules

Direct Known Subclasses

Defined in:

bindgen/parser/type.cr
bindgen/parser/type/cpp_type_parser.cr

Constant Summary

CRYSTAL_PROC = "CrystalProc"

Name of the CrystalProc C++ and Crystal type. This type is a template type in C++, and a struct in Crystal.

EMPTY = new(const: false, move: false, reference: false, builtin: true, void: false, pointer: 0, base_name: "", full_name: "", template: nil, nilable: false)

Empty type, as is returned by the parser for constructors. Only valid as a return type of a constructor method.

VOID = new(const: false, move: false, reference: false, builtin: true, void: true, pointer: 0, base_name: "void", full_name: "void", template: nil, nilable: false)

Void type

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(base_name : String, full_name : String, const : Bool, reference : Bool, pointer : Int32, move : Bool = false, builtin : Bool = false, void : Bool = false, kind : Bindgen::Parser::Type::Kind = Kind::Class, template : Nil | Bindgen::Parser::Template = nil, nilable : Bool = false, extents : Array(UInt64) = Array(UInt64).new, array_pointer : Int32 = 0, desugared : Nil | String = nil, typedefs : Nil | Array(String) = nil, never_nil : Bool = false) #

[View source]
def self.new(pull : JSON::PullParser) #

[View source]

Class Method Detail

def self.builtin_type(cpp_name : String, pointer = 0, reference = false) #

Returns a Type of a C++ built-in type cpp_name.


[View source]
def self.parse(type_name : String, pointer_depth = 0) #

Returns a Type of a fully qualified C++ typename type_name. Extra pointer indirections can be set by pointer_depth.


[View source]
def self.proc(return_type : Type, arguments : Enumerable(Type)) #

Creates a Type describing a Crystal Proc type, which returns a return_type using arguments.

The generated type will be considered a built-in type.


[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

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


def array_element : Type #

Returns the element type of this C array, e.g. int [3] for int [4][3]. Only valid if #c_array?.


[View source]
def array_pointer : Int32 #

Pointer and reference indirections applying to the whole C array instead of its elements, outermost first. E.g. int (*)[4] has one, int *[4] none. Included in #pointer.


[View source]
def base_name : String #

Unqualified base name for easier mapping to Crystal.

E.g., the base name of const QWidget *& is QWidget.


[View source]
def builtin? : Bool #

Is this type a C++ built-in type?


[View source]
def builtin_array_pointer? : Bool #

Is this a single pointer or reference to a complete C array of built-in types, like int (*)[4] or const float (&)[3][3]? These are passed as pointer to a StaticArray, or as Slice if it's a reference.

TODO Support pointers to arrays of other types.


[View source]
def c_array? #

Is this type a C array?


[View source]
def c_complete_array? #

Is this type a C array with known size?


[View source]
def const? : Bool #

Is this type constant?


[View source]
def decayed : Type | Nil #

Decays the type. This means that a single "layer" of information is removed from this type. Each rule is tried in the following order. The first winning rule returns a new type.

  1. If #pointer_to_c_array?, remove the outermost indirection (int (&)[4] -> int (*)[4] -> int [4])
  2. If #c_array?, remove outermost extent (int [4][3] -> int [3])
  3. If #const?, remove const (const int & -> int &)
  4. If #reference?, pointer-ize (int & -> int *)
  5. If #pointer > 0, remove one (int * -> int)
  6. Else, it's the base-type already. Return nil.

[View source]
def dereferenced : Type #

The value a single pointer or reference to it refers to: T for T & or T *, neither const nor nilable. Used for out arguments, see TypeDatabase#converted_out_argument?.


[View source]
def desugared : String | Nil #

The type the base type names if it is a typedef, like QList<QFileInfo> for QFileInfoList. TypeDatabase#resolve_aliases looks through a typedef without rules of its own.


[View source]
def equals_except_nil?(other : Type) #

Checks if this type equals the other type, except for nil-ability.


[View source]
def extents : Array(UInt64) #

The array extents of this type. Not to be modified.


[View source]
def full_name : String #

Fully qualified, full name, for the C++ bindings.


[View source]
def function? : Bool #

Is this a C++ function type, like the void (int) of std::function<void (int)>? Then #template holds its return type and parameter types, in this order. See Argument#after_initialize.


[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


Type kind.


[View source]
def make_pointer_nilable : Type | Nil #

If the type is a pointer and not a reference, returns a copy of this type that is nilable, otherwise returns nil.


[View source]
def mangled_name #

The mangled type name for C++ bindings.


[View source]
def move? : Bool #

Is this a C++ rvalue reference type?


[View source]
def never_nil : Type #

A copy of this type known to be non-null, see #never_nil?.


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

Is this type known to be non-null, like the result of a cast or an element of a container? Then nilable_results doesn't apply to it.


[View source]
def never_nil? : Bool #

Is this type known to be non-null, like the result of a cast or an element of a container? Then nilable_results doesn't apply to it.


[View source]
def nilable? : Bool #

Is this type nilable? For compatibility with Argument.


[View source]
def pointee_array : Type #

Returns the C array this type points or refers to, e.g. int [4] for int (&)[4]. Only valid if #pointer_to_c_array?.


[View source]
def pointer : Int32 #

Total number of indirections from pointers, lvalue references and C array extents.


[View source]
def pointer_to_c_array? : Bool #

Is this a pointer or reference to a C array, like int (*)[4]? This includes types with a pointer between two extents, like int (*[2])[4], which the clang tool reports with the inner array as base type.


[View source]
def pure_void? #

Returns true if this type is void, and nothing else.


[View source]
def reference? : Bool #

Is this a C++ lvalue reference type?


[View source]
def reference_to_c_array? : Bool #

Is this an lvalue reference to a C array, like int (&)[4]?


[View source]
def remove_all_extents : Type #

Returns a copy of this type with C array extents removed.


[View source]
def std_function? : Bool #

Is this a std::function turned into a Kind::Function type, see Argument#after_initialize? The #base_name stays the C++ type, the std::function<...> or a typedef of one, so the C++ glue can build it from the CrystalProc it is passed. A Type.proc is named CrystalProc<...> instead.


[View source]
def substitute(name : String, with type : Type) : Type #

Substitutes all uses of name with the given type.


[View source]
def substitute(replacements : Hash(String, Type)) : Type #

Performs type substitution with the given replacements.

Substitution is performed if this type's base name is exactly one of the type arguments, but not if the type is a templated type of the same name. Substitution is applied recursively on template type arguments. All substitutions are applied simultaneously.


[View source]
def substitute(replacements : Tuple(String, Type)) : Type #

Substitutes all uses of name with the given type.


[View source]
def template : Template | Nil #

Template information, if this type is a template type.


[View source]
def template_arguments : Array(Type) #

Returns the template arguments of this type. Only valid for template types, like container instantiations or CrystalProcs.


[View source]
def typedefs : Array(String) | Nil #

The typedefs between the base type and #desugared, outermost first, like std::chrono::nanoseconds of QElapsedTimer::Duration: One with rules of its own wins over the canonical type.


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

Checks whether this type uses name in its base name or any of its template arguments. Does not check for template names.


[View source]
def void? : Bool #

Is it C++ void? Note that void * is also void. See also #pure_void?


[View source]
def with_nilable(nilable : Bool) : self #

A copy of this pointer type which is nilable, or known to be non-null (#never_nil?) if not. Used by the nilable: type rule.


[View source]