class
Bindgen::Parser::Type
- Bindgen::Parser::Type
- Reference
- Object
Overview
Stores information about a specific C++ type.
Included Modules
- JSON::Serializable
Direct Known Subclasses
Defined in:
bindgen/parser/type.crbindgen/parser/type/cpp_type_parser.cr
Constant Summary
-
CRYSTAL_PROC =
"CrystalProc" -
Name of the
CrystalProcC++ and Crystal type. This type is a template type in C++, and astructin 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) -
Voidtype
Constructors
- .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)
- .new(pull : JSON::PullParser)
Class Method Summary
-
.builtin_type(cpp_name : String, pointer = 0, reference = false)
Returns a
Typeof a C++ built-in type cpp_name. -
.parse(type_name : String, pointer_depth = 0)
Returns a
Typeof a fully qualified C++ typename type_name. -
.proc(return_type : Type, arguments : Enumerable(Type))
Creates a
Typedescribing a CrystalProctype, which returns a return_type using arguments.
Instance Method Summary
-
#==(other : self)
Returns
trueif this reference is the same as other. -
#array_element : Type
Returns the element type of this C array, e.g.
-
#array_pointer : Int32
Pointer and reference indirections applying to the whole C array instead of its elements, outermost first.
-
#base_name : String
Unqualified base name for easier mapping to Crystal.
-
#builtin? : Bool
Is this type a C++ built-in type?
-
#builtin_array_pointer? : Bool
Is this a single pointer or reference to a complete C array of built-in types, like
int (*)[4]orconst float (&)[3][3]? These are passed as pointer to aStaticArray, or asSliceif it's a reference. -
#c_array?
Is this type a C array?
-
#c_complete_array?
Is this type a C array with known size?
-
#const? : Bool
Is this type constant?
-
#decayed : Type | Nil
Decays the type.
-
#dereferenced : Type
The value a single pointer or reference to it refers to:
TforT &orT *, neither const nor nilable. -
#desugared : String | Nil
The type the base type names if it is a typedef, like
QList<QFileInfo>forQFileInfoList. -
#equals_except_nil?(other : Type)
Checks if this type equals the other type, except for nil-ability.
-
#extents : Array(UInt64)
The array extents of this type.
-
#full_name : String
Fully qualified, full name, for the C++ bindings.
-
#function? : Bool
Is this a C++ function type, like the
void (int)ofstd::function<void (int)>? Then#templateholds its return type and parameter types, in this order. -
#hash(hasher)
See
Object#hash(hasher) -
#kind : Bindgen::Parser::Type::Kind
Type kind.
-
#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. -
#mangled_name
The mangled type name for C++ bindings.
-
#move? : Bool
Is this a C++ rvalue reference type?
-
#never_nil : Type
A copy of this type known to be non-null, see
#never_nil?. -
#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_resultsdoesn't apply to it. -
#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_resultsdoesn't apply to it. -
#nilable? : Bool
Is this type nilable? For compatibility with
Argument. -
#pointee_array : Type
Returns the C array this type points or refers to, e.g.
-
#pointer : Int32
Total number of indirections from pointers, lvalue references and C array extents.
-
#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, likeint (*[2])[4], which the clang tool reports with the inner array as base type. -
#pure_void?
Returns
trueif this type isvoid, and nothing else. -
#reference? : Bool
Is this a C++ lvalue reference type?
-
#reference_to_c_array? : Bool
Is this an lvalue reference to a C array, like
int (&)[4]? -
#remove_all_extents : Type
Returns a copy of this type with C array extents removed.
-
#std_function? : Bool
Is this a
std::functionturned into aKind::Functiontype, seeArgument#after_initialize? The#base_namestays the C++ type, thestd::function<...>or a typedef of one, so the C++ glue can build it from theCrystalProcit is passed. -
#substitute(name : String, with type : Type) : Type
Substitutes all uses of name with the given type.
-
#substitute(replacements : Hash(String, Type)) : Type
Performs type substitution with the given replacements.
-
#substitute(replacements : Tuple(String, Type)) : Type
Substitutes all uses of name with the given type.
-
#template : Template | Nil
Template information, if this type is a template type.
-
#template_arguments : Array(Type)
Returns the template arguments of this type.
-
#typedefs : Array(String) | Nil
The typedefs between the base type and
#desugared, outermost first, likestd::chrono::nanosecondsofQElapsedTimer::Duration: One with rules of its own wins over the canonical type. -
#uses_typename?(name : String)
Checks whether this type uses name in its base name or any of its template arguments.
-
#void? : Bool
Is it C++
void? Note thatvoid *is also void. -
#with_nilable(nilable : Bool) : self
A copy of this pointer type which is nilable, or known to be non-null (
#never_nil?) if not.
Constructor Detail
Class Method Detail
Returns a Type of a C++ built-in type cpp_name.
Returns a Type of a fully qualified C++ typename type_name. Extra
pointer indirections can be set by pointer_depth.
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.
Instance Method Detail
Returns true if this reference is the same as other. Invokes same?.
Returns the element type of this C array, e.g. int [3] for
int [4][3]. Only valid if #c_array?.
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.
Unqualified base name for easier mapping to Crystal.
E.g., the base name of const QWidget *& is QWidget.
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.
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.
- If
#pointer_to_c_array?, remove the outermost indirection (int (&)[4]->int (*)[4]->int [4]) - If
#c_array?, remove outermost extent (int [4][3]->int [3]) - If
#const?, remove const (const int &->int &) - If
#reference?, pointer-ize (int &->int *) - If
#pointer > 0, remove one (int *->int) - Else, it's the base-type already. Return
nil.
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?.
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.
Checks if this type equals the other type, except for nil-ability.
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.
If the type is a pointer and not a reference, returns a copy of this
type that is nilable, otherwise returns nil.
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.
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.
Returns the C array this type points or refers to, e.g. int [4] for
int (&)[4]. Only valid if #pointer_to_c_array?.
Total number of indirections from pointers, lvalue references and C array extents.
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.
Returns a copy of this type with C array extents removed.
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.
Substitutes all uses of name with the given 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.
Substitutes all uses of name with the given type.
Template information, if this type is a template type.
Returns the template arguments of this type. Only valid for template
types, like container instantiations or CrystalProcs.
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.
Checks whether this type uses name in its base name or any of its template arguments. Does not check for template names.
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.