Class: Rubex::AST::Statement::CPtrDecl
- Defined in:
- lib/rubex/ast/statement/c_ptr_decl.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#entry ⇒ Object
readonly
Returns the value of attribute entry.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from Base
Instance Method Summary collapse
- #analyse_statement(local_scope, extern: false) ⇒ Object
- #generate_code(code, local_scope) ⇒ Object
-
#initialize(type, name, value, ptr_level, location) ⇒ CPtrDecl
constructor
A new instance of CPtrDecl.
- #rescan_declarations(local_scope) ⇒ Object
Methods inherited from Base
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
#entry ⇒ Object (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 |
#type ⇒ Object (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 |