Class: TPPlus::Nodes::AssignmentNode

Inherits:
Object
  • Object
show all
Defined in:
lib/tp_plus/nodes/assignment_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, assignable) ⇒ AssignmentNode

Returns a new instance of AssignmentNode.



5
6
7
8
# File 'lib/tp_plus/nodes/assignment_node.rb', line 5

def initialize(identifier,assignable)
  @identifier = identifier
  @assignable = assignable
end

Instance Attribute Details

#assignableObject (readonly)

Returns the value of attribute assignable.



4
5
6
# File 'lib/tp_plus/nodes/assignment_node.rb', line 4

def assignable
  @assignable
end

#identifierObject (readonly)

Returns the value of attribute identifier.



4
5
6
# File 'lib/tp_plus/nodes/assignment_node.rb', line 4

def identifier
  @identifier
end

Instance Method Details

#assignable_string(context, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tp_plus/nodes/assignment_node.rb', line 10

def assignable_string(context,options={})
  if @assignable.is_a?(ExpressionNode)
    options[:mixed_logic] = true if @assignable.contains_expression?
    options[:mixed_logic] = true if @assignable.op.requires_mixed_logic?(context)
    options[:mixed_logic] = true if @assignable.op.boolean?
    options[:mixed_logic] = true if @assignable.boolean_result?
  else
    options[:mixed_logic] = true if @assignable.requires_mixed_logic?(context)
    options[:mixed_logic] = true if @identifier.requires_mixed_logic?(context)
  end

  if options[:mixed_logic]
    "(#{@assignable.eval(context)})"
  else
    @assignable.eval(context)
  end
end

#can_be_inlined?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/tp_plus/nodes/assignment_node.rb', line 32

def can_be_inlined?
  true
end

#eval(context, options = {}) ⇒ Object



40
41
42
# File 'lib/tp_plus/nodes/assignment_node.rb', line 40

def eval(context,options={})
  "#{identifier_string(context)}=#{assignable_string(context,options)}"
end

#identifier_string(context) ⇒ Object



36
37
38
# File 'lib/tp_plus/nodes/assignment_node.rb', line 36

def identifier_string(context)
  @identifier.eval(context)
end

#requires_mixed_logic?(context) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/tp_plus/nodes/assignment_node.rb', line 28

def requires_mixed_logic?(context)
  true
end