Class: RLTK::CG::FunctionType
Overview
A type representing the return an argument types for a function.
Instance Attribute Summary
Attributes included from BindingClass
Instance Method Summary collapse
-
#argument_types ⇒ Array<Type>
(also: #arg_types)
Types of this function type’s arguments.
-
#initialize(overloaded, arg_types = nil, varargs = false) ⇒ FunctionType
constructor
Create a new function type from a pointer or description of the return type and argument types.
-
#return_type ⇒ Type
The return type of this function type.
Methods inherited from Type
#allignment, #context, from_ptr, #hash, #kind, #size
Methods included from AbstractClass
Methods included from BindingClass
Constructor Details
#initialize(overloaded, arg_types = nil, varargs = false) ⇒ FunctionType
Create a new function type from a pointer or description of the return type and argument types.
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/rltk/cg/type.rb', line 318 def initialize(overloaded, arg_types = nil, varargs = false) @ptr = case overloaded when FFI::Pointer overloaded else @return_type = check_cg_type(overloaded, Type, 'return_type') @arg_types = check_cg_array_type(arg_types, Type, 'arg_types').freeze arg_types_ptr = FFI::MemoryPointer.new(:pointer, @arg_types.length) arg_types_ptr.write_array_of_pointer(@arg_types) Bindings.function_type(@return_type, arg_types_ptr, @arg_types.length, varargs.to_i) end end |
Instance Method Details
#argument_types ⇒ Array<Type> Also known as: arg_types
Returns Types of this function type’s arguments.
335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/rltk/cg/type.rb', line 335 def argument_types @arg_types ||= begin num_elements = Bindings.count_param_types(@ptr) ret_ptr = FFI::MemoryPointer.new(:pointer) Bindings.get_param_types(@ptr, ret_ptr) types_ptr = ret_ptr.get_pointer(0) types_ptr.get_array_of_pointer(0, num_elements).map { |ptr| Type.from_ptr(ptr) } end end |
#return_type ⇒ Type
Returns The return type of this function type.
351 352 353 |
# File 'lib/rltk/cg/type.rb', line 351 def return_type @return_type ||= Type.from_ptr(Bindings.get_return_type(@ptr)) end |