Class: TPPlus::Nodes::AssignmentNode

Inherits:
BaseNode
  • 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
27
28
29
30
31
32
33
# 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?
    # this is a hack that fixes issue #12
    # PR[a]=PR[b]+PR[c]+PR[d] (no parens)
    if @identifier.is_a? VarNode
      options[:mixed_logic] = false if @identifier.target_node(context).is_a? PosregNode
    end
  elsif @assignable.is_a?(VarNode)
    options[:mixed_logic] = true if @assignable.target_node(context).is_a? IONode
  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)


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

def can_be_inlined?
  true
end

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



47
48
49
# File 'lib/tp_plus/nodes/assignment_node.rb', line 47

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

#identifier_string(context) ⇒ Object



43
44
45
# File 'lib/tp_plus/nodes/assignment_node.rb', line 43

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

#requires_mixed_logic?(context) ⇒ Boolean

Returns:

  • (Boolean)


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

def requires_mixed_logic?(context)
  true
end