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) #

[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 base_name : String #

[View source]
def builtin? : Bool #

[View source]
def const? : Bool #

[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 #const?, remove const (const int & -> int &)
  2. If #reference?, pointer-ize (int & -> int *)
  3. If #pointer > 0, remove one (int * -> int)
  4. Else, it's the base-type already. Return nil.

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

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


[View source]
def full_name : String #

[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 #

[View source]
def nilable? : Bool #

[View source]
def pointer : Int32 #

Total number of indirections from pointers and lvalue references.


[View source]
def pure_void? #

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


[View source]
def reference? : Bool #

[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 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 #

[View source]