Class: Rubex::AST::Statement::Alias

Inherits:
Base
  • Object
show all
Defined in:
lib/rubex/ast/statement/alias.rb

Instance Attribute Summary

Attributes inherited from Base

#location

Instance Method Summary collapse

Methods inherited from Base

#==, #statement?

Constructor Details

#initialize(new_name, old_name, location) ⇒ Alias

Returns a new instance of Alias.



5
6
7
8
9
10
# File 'lib/rubex/ast/statement/alias.rb', line 5

def initialize(new_name, old_name, location)
  super(location)
  @new_name = new_name
  @old_name = old_name
  Rubex::CUSTOM_TYPES[@new_name] = @new_name
end

Instance Method Details

#analyse_statement(local_scope, extern: false) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rubex/ast/statement/alias.rb', line 12

def analyse_statement(local_scope, extern: false)
  original  = @old_name[:dtype].gsub('struct ', '').gsub('union ', '')
  var       = @old_name[:variables][0]
  ident     = var[:ident]
  ptr_level = var[:ptr_level]

  base_type =
    if ident.is_a?(Hash) # function pointer
      cfunc_return_type = Helpers.determine_dtype(original,
                                                  ident[:return_ptr_level])
      arg_list = ident[:arg_list].analyse_statement(local_scope)
      ptr_level = '*' if ptr_level.empty?

      Helpers.determine_dtype(
        DataType::CFunction.new(nil, nil, arg_list, cfunc_return_type, nil),
        ptr_level
      )
    else
      Helpers.determine_dtype(original, ptr_level)
    end

  @type = Rubex::DataType::TypeDef.new(base_type, @new_name, base_type)
  Rubex::CUSTOM_TYPES[@new_name] = @type
  local_scope.declare_type(type: @type, extern: extern) if original != @new_name
end

#generate_code(code, local_scope) ⇒ Object



38
# File 'lib/rubex/ast/statement/alias.rb', line 38

def generate_code(code, local_scope); end