Class: Rubex::AST::Statement::CPtrDecl

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

Direct Known Subclasses

CPtrFuncDecl

Instance Attribute Summary collapse

Attributes inherited from Base

#location

Instance Method Summary collapse

Methods inherited from Base

#==, #statement?

Constructor Details

#initialize(type, name, value, ptr_level, location) ⇒ CPtrDecl

Returns a new instance of CPtrDecl.



7
8
9
10
11
12
13
# File 'lib/rubex/ast/statement/c_ptr_decl.rb', line 7

def initialize(type, name, value, ptr_level, location)
  super(location)
  @name = name
  @type = type
  @value = value
  @ptr_level = ptr_level
end

Instance Attribute Details

#entryObject (readonly)

Returns the value of attribute entry.



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

def entry
  @entry
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#analyse_statement(local_scope, extern: false) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rubex/ast/statement/c_ptr_decl.rb', line 15

def analyse_statement(local_scope, extern: false)
  cptr_cname extern
  @type = Helpers.determine_dtype @type, @ptr_level
  if @value
    @value.analyse_for_target_type(@type, local_scope)
    @value.allocate_temps(local_scope)
    @value = Helpers.to_lhs_type(self, @value)
    @value.release_temps(local_scope)
  end

  @entry = local_scope.declare_var name: @name, c_name: @c_name,
                                   type: @type, value: @value, extern: extern
end

#generate_code(code, local_scope) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/rubex/ast/statement/c_ptr_decl.rb', line 37

def generate_code(code, local_scope)
  if @value
    @value.generate_evaluation_code code, local_scope
    code << "#{local_scope.find(@name).c_name} = #{@value.c_code(local_scope)};"
    code.nl
    @value.generate_disposal_code code
  end
end

#rescan_declarations(local_scope) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/rubex/ast/statement/c_ptr_decl.rb', line 29

def rescan_declarations(local_scope)
  base_type = @entry.type.base_type
  if base_type.is_a? String
    type = Helpers.determine_dtype base_type, @ptr_level
    local_scope[@name].type = type
  end
end