Class: Rubex::AST::Statement::CStructOrUnionDef

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

Instance Attribute Summary collapse

Attributes inherited from Base

#location

Instance Method Summary collapse

Methods inherited from Base

#==, #statement?

Constructor Details

#initialize(kind, name, declarations, location) ⇒ CStructOrUnionDef

Returns a new instance of CStructOrUnionDef.



7
8
9
10
11
12
13
14
15
16
# File 'lib/rubex/ast/statement/c_struct_or_union_def.rb', line 7

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

Instance Attribute Details

#declarationsObject (readonly)

Returns the value of attribute declarations.



5
6
7
# File 'lib/rubex/ast/statement/c_struct_or_union_def.rb', line 5

def declarations
  @declarations
end

#entryObject (readonly)

Returns the value of attribute entry.



5
6
7
# File 'lib/rubex/ast/statement/c_struct_or_union_def.rb', line 5

def entry
  @entry
end

#kindObject (readonly)

Returns the value of attribute kind.



5
6
7
# File 'lib/rubex/ast/statement/c_struct_or_union_def.rb', line 5

def kind
  @kind
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/rubex/ast/statement/c_struct_or_union_def.rb', line 5

def name
  @name
end

#scopeObject (readonly)

Returns the value of attribute scope.



5
6
7
# File 'lib/rubex/ast/statement/c_struct_or_union_def.rb', line 5

def scope
  @scope
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/rubex/ast/statement/c_struct_or_union_def.rb', line 5

def type
  @type
end

Instance Method Details

#analyse_statement(outer_scope, extern: false) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rubex/ast/statement/c_struct_or_union_def.rb', line 18

def analyse_statement(outer_scope, extern: false)
  @scope = Rubex::SymbolTable::Scope::StructOrUnion.new(
    @name, outer_scope
  )
  c_name = if extern
             @kind.to_s + " " + @name
           else
             Rubex::TYPE_PREFIX + @scope.klass_name + "_" + @name
           end
  @type = Rubex::DataType::CStructOrUnion.new(@kind, @name, c_name,
                                              @scope)

  @declarations.each do |decl|
    decl.analyse_statement @scope, extern: extern
  end
  Rubex::CUSTOM_TYPES[@name] = @type
  @entry = outer_scope.declare_sue(name: @name, c_name: c_name,
                                   type: @type, extern: extern)
end

#generate_code(code, local_scope = nil) ⇒ Object



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

def generate_code(code, local_scope = nil); end

#rescan_declarations(_local_scope) ⇒ Object



40
41
42
43
44
45
# File 'lib/rubex/ast/statement/c_struct_or_union_def.rb', line 40

def rescan_declarations(_local_scope)
  @declarations.each do |decl|
    decl.respond_to?(:rescan_declarations) &&
      decl.rescan_declarations(@scope)
  end
end