Class: Rubex::AST::Statement::ForwardDecl

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

Instance Attribute Summary

Attributes inherited from Base

#location

Instance Method Summary collapse

Methods inherited from Base

#==, #statement?

Constructor Details

#initialize(kind, name, location) ⇒ ForwardDecl

Returns a new instance of ForwardDecl.



5
6
7
8
9
10
11
12
13
14
# File 'lib/rubex/ast/statement/forward_decl.rb', line 5

def initialize(kind, name, location)
  super(location)
  @name = name
  if /struct/.match kind
    @kind = :struct
  elsif /union/.match kind
    @kind = :union
  end
  Rubex::CUSTOM_TYPES[@name] = @name
end

Instance Method Details

#analyse_statement(local_scope, extern: false) ⇒ Object



16
17
18
19
20
# File 'lib/rubex/ast/statement/forward_decl.rb', line 16

def analyse_statement(local_scope, extern: false)
  @c_name = Rubex::TYPE_PREFIX + local_scope.klass_name + '_' + @name
  @type = Rubex::DataType::TypeDef.new("#{@kind} #{@name}", @c_name, @type)
  local_scope.declare_type type: @type, extern: extern
end

#generate_code(code, local_scope) ⇒ Object



27
# File 'lib/rubex/ast/statement/forward_decl.rb', line 27

def generate_code(code, local_scope); end

#rescan_declarations(_local_scope) ⇒ Object



22
23
24
25
# File 'lib/rubex/ast/statement/forward_decl.rb', line 22

def rescan_declarations(_local_scope)
  @type = Rubex::DataType::TypeDef.new("#{@kind} #{@name}", @c_name,
                                       Rubex::CUSTOM_TYPES[@name])
end