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, #dump, from_ptr, #hash, #kind, #size, #to_s
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.
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/rltk/cg/type.rb', line 362 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.
379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/rltk/cg/type.rb', line 379 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.
395 396 397 |
# File 'lib/rltk/cg/type.rb', line 395 def return_type @return_type ||= Type.from_ptr(Bindings.get_return_type(@ptr)) end |