Class: Rubex::AST::Expression::Base
- Inherits:
-
Object
- Object
- Rubex::AST::Expression::Base
show all
- Defined in:
- lib/rubex/ast/expression.rb
Direct Known Subclasses
ActualArgList, AnalysedElementRef, ArgDeclaration, Binary, BlockGiven, CoerceObject, Colon2, CommandCall, ElementRef, Empty, InstanceVar, Literal::Base, MethodCall, Name, Print, Require, RubyConstant, Self, SizeOf, Typecast, Unary, UnaryBase, Yield
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#allocate_temp(local_scope, type) ⇒ Object
-
#allocate_temps(local_scope) ⇒ Object
-
#analyse_for_target_type(target_type, local_scope) ⇒ Object
In case an expr has to be of a certain type, like a string literal assigned to a char*, this method will analyse the literal in context to the target dtype.
-
#analyse_types(local_scope, extern: false) ⇒ Object
If the typecast exists, the typecast is made the overall type of the expression.
-
#c_code(local_scope) ⇒ Object
-
#expression? ⇒ Boolean
-
#from_ruby_object(from_node) ⇒ Object
-
#generate_and_dispose_subexprs(code, local_scope, &block) ⇒ Object
-
#generate_assignment_code(rhs, code, local_scope) ⇒ Object
-
#generate_disposal_code(code) ⇒ Object
-
#generate_evaluation_code(code, local_scope) ⇒ Object
-
#has_temp ⇒ Object
-
#possible_typecast(code, local_scope) ⇒ Object
-
#release_temp(local_scope) ⇒ Object
-
#release_temps(local_scope) ⇒ Object
-
#to_ruby_object ⇒ Object
Instance Attribute Details
#entry ⇒ Object
Returns the value of attribute entry.
5
6
7
|
# File 'lib/rubex/ast/expression.rb', line 5
def entry
@entry
end
|
#type ⇒ Object
Returns the value of attribute type.
5
6
7
|
# File 'lib/rubex/ast/expression.rb', line 5
def type
@type
end
|
#typecast ⇒ Object
Returns the value of attribute typecast.
6
7
8
|
# File 'lib/rubex/ast/expression.rb', line 6
def typecast
@typecast
end
|
Instance Method Details
#allocate_temp(local_scope, type) ⇒ Object
50
51
52
53
54
|
# File 'lib/rubex/ast/expression.rb', line 50
def allocate_temp local_scope, type
if @has_temp
@c_code = local_scope.allocate_temp(type)
end
end
|
#allocate_temps(local_scope) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/rubex/ast/expression.rb', line 56
def allocate_temps local_scope
if @subexprs
@subexprs.each { |expr| expr.allocate_temps(local_scope) }
end
allocate_temp local_scope, @type
end
|
#analyse_for_target_type(target_type, local_scope) ⇒ Object
In case an expr has to be of a certain type, like a string literal
assigned to a char*, this method will analyse the literal in context
to the target dtype.
11
12
13
|
# File 'lib/rubex/ast/expression.rb', line 11
def analyse_for_target_type target_type, local_scope
analyse_types local_scope
end
|
#analyse_types(local_scope, extern: false) ⇒ Object
If the typecast exists, the typecast is made the overall type of the expression.
17
18
19
20
21
22
|
# File 'lib/rubex/ast/expression.rb', line 17
def analyse_types local_scope, extern: false
if @typecast
@typecast.analyse_types(local_scope)
@type = @typecast.type
end
end
|
#c_code(local_scope) ⇒ Object
30
31
32
|
# File 'lib/rubex/ast/expression.rb', line 30
def c_code local_scope
@typecast ? @typecast.c_code(local_scope) : ""
end
|
#expression? ⇒ Boolean
24
|
# File 'lib/rubex/ast/expression.rb', line 24
def expression?; true; end
|
#from_ruby_object(from_node) ⇒ Object
42
43
44
|
# File 'lib/rubex/ast/expression.rb', line 42
def from_ruby_object from_node
FromRubyObject.new self, from_node
end
|
#generate_and_dispose_subexprs(code, local_scope, &block) ⇒ Object
81
82
83
84
85
86
87
88
89
|
# File 'lib/rubex/ast/expression.rb', line 81
def generate_and_dispose_subexprs(code, local_scope, &block)
@subexprs.each do |s|
s.generate_evaluation_code code, local_scope
end
block.call if block_given?
@subexprs.each do |s|
s.generate_disposal_code code
end
end
|
#generate_assignment_code(rhs, code, local_scope) ⇒ Object
79
|
# File 'lib/rubex/ast/expression.rb', line 79
def generate_assignment_code(rhs, code, local_scope); end
|
#generate_disposal_code(code) ⇒ Object
72
73
74
75
76
77
|
# File 'lib/rubex/ast/expression.rb', line 72
def generate_disposal_code(code)
if @has_temp
code << "#{@c_code} = 0;"
code.nl
end
end
|
#generate_evaluation_code(code, local_scope) ⇒ Object
70
|
# File 'lib/rubex/ast/expression.rb', line 70
def generate_evaluation_code(code, local_scope); end
|
#has_temp ⇒ Object
26
27
28
|
# File 'lib/rubex/ast/expression.rb', line 26
def has_temp
@has_temp
end
|
#possible_typecast(code, local_scope) ⇒ Object
34
35
36
|
# File 'lib/rubex/ast/expression.rb', line 34
def possible_typecast code, local_scope
@typecast ? @typecast.c_code(local_scope) : ""
end
|
#release_temp(local_scope) ⇒ Object
46
47
48
|
# File 'lib/rubex/ast/expression.rb', line 46
def release_temp local_scope
local_scope.release_temp(@c_code) if @has_temp
end
|
#release_temps(local_scope) ⇒ Object
63
64
65
66
67
68
|
# File 'lib/rubex/ast/expression.rb', line 63
def release_temps local_scope
if @subexprs
@subexprs.each { |expr| expr.release_temps(local_scope) }
end
release_temp local_scope
end
|
#to_ruby_object ⇒ Object
38
39
40
|
# File 'lib/rubex/ast/expression.rb', line 38
def to_ruby_object
ToRubyObject.new self
end
|