class AdLint::Cc1::ValueDomainNarrowing
Attributes
narrowed_values[R]
node[R]
original_values[R]
result[R]
Public Class Methods
new(manip, node, *children)
click to toggle source
# File lib/adlint/cc1/ctrlexpr.rb, line 567 def initialize(manip, node, *children) @manipulator = manip @node = node @children = children @original_values = {} @narrowed_values = {} @result = nil end
Public Instance Methods
ensure_result_equal_to(val)
click to toggle source
# File lib/adlint/cc1/ctrlexpr.rb, line 599 def ensure_result_equal_to(val) if @result.variable? && @result.designated_by_lvalue? if @result.value.scalar? && val.scalar? ensure_relation(@result, Operator::EQ, val) end end end
execute!()
click to toggle source
# File lib/adlint/cc1/ctrlexpr.rb, line 585 def execute! @result = do_narrowing @children.each do |manip| @narrowed_values = manip.narrowed_values.merge(@narrowed_values) end ensure if @result && @result.variable? notify_variable_value_referred(node, @result) end if seqp = node.subsequent_sequence_point notify_sequence_point_reached(seqp) end end
load_original_values!(manip)
click to toggle source
# File lib/adlint/cc1/ctrlexpr.rb, line 580 def load_original_values!(manip) @original_values = manip.narrowed_values @children.each { |child| child.load_original_values!(manip) } end
Private Instance Methods
do_logical_arithmetic_conversion(node, lhs_var, rhs_var)
click to toggle source
# File lib/adlint/cc1/ctrlexpr.rb, line 615 def do_logical_arithmetic_conversion(node, lhs_var, rhs_var) lhs_conved, rhs_conved = do_usual_arithmetic_conversion(lhs_var, rhs_var) unless lhs_conved == lhs_var notify_implicit_conv_performed(node.lhs_operand, lhs_var, lhs_conved) end unless rhs_conved == rhs_var notify_implicit_conv_performed(node.rhs_operand, rhs_var, rhs_conved) end return lhs_conved, rhs_conved end
do_narrowing()
click to toggle source
# File lib/adlint/cc1/ctrlexpr.rb, line 611 def do_narrowing subclass_responsibility end
ensure_relation(var, op, val)
click to toggle source
# File lib/adlint/cc1/ctrlexpr.rb, line 629 def ensure_relation(var, op, val) # NOTE: To avoid over-narrowing. if val.definite? or var.value.contain?(val) && !val.contain?(var.value) target_val = save_original_value(var).dup target_val.narrow_domain!(op, val) update_narrowed_value(var, target_val) end end
interpret(node)
click to toggle source
# File lib/adlint/cc1/ctrlexpr.rb, line 678 def interpret(node) case node when ObjectSpecifier if safely_evaluable_object_specifier?(node) _orig_interpret(node) else # NOTE: Nothing to do with an undeclared object. create_tmpvar end else _orig_interpret(node) end end
Also aliased as: _orig_interpret
narrowing_merge!(lhs_manip, rhs_manip)
click to toggle source
# File lib/adlint/cc1/ctrlexpr.rb, line 650 def narrowing_merge!(lhs_manip, rhs_manip) lhs_vals = lhs_manip.narrowed_values rhs_vals = rhs_manip.narrowed_values @narrowed_values = lhs_vals.merge(rhs_vals) { |key, lhs_val, rhs_val| rslt_val = lhs_val.dup rslt_val.narrow_domain!(Operator::EQ, rhs_val) rslt_val } end
original_value_of(var)
click to toggle source
# File lib/adlint/cc1/ctrlexpr.rb, line 642 def original_value_of(var) @original_values[var.to_named_variable] end
safely_evaluable_object_specifier?(obj_spec)
click to toggle source
# File lib/adlint/cc1/ctrlexpr.rb, line 692 def safely_evaluable_object_specifier?(obj_spec) variable_named(obj_spec.identifier.value) || function_named(obj_spec.identifier.value) || enumerator_named(obj_spec.identifier.value) end
save_original_value(var)
click to toggle source
# File lib/adlint/cc1/ctrlexpr.rb, line 638 def save_original_value(var) @original_values[var.to_named_variable] ||= var.value.dup end
update_narrowed_value(var, new_val)
click to toggle source
# File lib/adlint/cc1/ctrlexpr.rb, line 646 def update_narrowed_value(var, new_val) @narrowed_values[var.to_named_variable] = new_val end
widening_merge!(lhs_manip, rhs_manip)
click to toggle source
# File lib/adlint/cc1/ctrlexpr.rb, line 661 def widening_merge!(lhs_manip, rhs_manip) lhs_vals = lhs_manip.narrowed_values rhs_vals = rhs_manip.narrowed_values @narrowed_values = lhs_vals.merge(rhs_vals) { |key, lhs_val, rhs_val| rslt_val = lhs_val.dup rslt_val.widen_domain!(Operator::EQ, rhs_val) rslt_val } end