Class: Rubex::AST::Expression::ArgDeclaration

Inherits:
Base
  • Object
show all
Defined in:
lib/rubex/ast/expression/arg_declaration.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#entry, #type, #typecast

Instance Method Summary collapse

Methods inherited from Base

#allocate_temp, #allocate_temps, #analyse_for_target_type, #c_code, #expression?, #from_ruby_object, #generate_and_dispose_subexprs, #generate_assignment_code, #generate_disposal_code, #generate_evaluation_code, #has_temp, #possible_typecast, #release_temp, #release_temps, #to_ruby_object

Constructor Details

#initialize(data_hash) ⇒ ArgDeclaration

Returns a new instance of ArgDeclaration.



8
9
10
# File 'lib/rubex/ast/expression/arg_declaration.rb', line 8

def initialize(data_hash)
  @data_hash = data_hash
end

Instance Attribute Details

#data_hashObject (readonly)

Keep data_hash attr_reader because this node is coerced into specialized ArgDecl nodes in the parser.



7
8
9
# File 'lib/rubex/ast/expression/arg_declaration.rb', line 7

def data_hash
  @data_hash
end

Instance Method Details

#analyse_types(local_scope, extern: false) ⇒ Object

TODO: Support array of function pointers and array in arguments.



13
14
15
16
17
18
19
20
21
# File 'lib/rubex/ast/expression/arg_declaration.rb', line 13

def analyse_types(local_scope, extern: false)
  var, dtype, ident, ptr_level, value = fetch_data
  name = ident
  c_name = Rubex::ARG_PREFIX + ident
  @type = Helpers.determine_dtype(dtype, ptr_level)
  value&.analyse_types(local_scope)
  add_arg_to_symbol_table name, c_name, value, extern, local_scope
  @has_temp = true if @type.object?
end