Class: AdLint::Cc1::InitializerInterpreter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Conversion, InterpreterMediator, NotifierMediator, MonitorUtil
Defined in:
lib/adlint/cc1/interp.rb

Instance Method Summary collapse

Methods included from MonitorUtil

#checkpoint, #monitored_region

Methods included from Conversion

#do_conversion, #do_default_argument_promotion, #do_integer_promotion, #do_usual_arithmetic_conversion, #untyped_pointer_conversion?

Methods included from InterpreterMediator

#constant_expression?, #current_branch, #interpret, #object_to_pointer, #object_to_variable, #pointer_value_of, #reset_environment, #scalar_value_of, #scalar_value_of_arbitrary, #scalar_value_of_false, #scalar_value_of_null, #scalar_value_of_true, #value_of

Methods included from InterpSyntaxBridge

#_interp_syntax_bridge_

Methods included from InterpObjectBridge

#_interp_object_bridge_

Methods included from ArithmeticAccessor

#arithmetic, #logical_right_shift?

Methods included from FunctionTableMediator

#declare_explicit_function, #declare_implicit_function, #define_anonymous_function, #define_explicit_function

Methods included from VariableTableMediator

#create_tmpvar, #local_variables

Methods included from MemoryPoolMediator

#pointee_of

Constructor Details

#initialize(interp) ⇒ InitializerInterpreter

Returns a new instance of InitializerInterpreter.



724
725
726
# File 'lib/adlint/cc1/interp.rb', line 724

def initialize(interp)
  @interpreter = interp
end

Instance Method Details

#execute(var_def) ⇒ Object



728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
# File 'lib/adlint/cc1/interp.rb', line 728

def execute(var_def)
  checkpoint(var_def.initializer.location)

  case
  when expr = var_def.initializer.expression
    # NOTE: An implicit conversion is already notified in
    #       #evaluate_expression.
    return evaluate_expression(expr, var_def.type)
  when inits = var_def.initializer.initializers
    var = evaluate_initializers(inits, var_def.type)

    # NOTE: Size deduction of an incomplete array type have been done by
    #       #evaluate_initializers.
    if var_def.type.array? && var.type.array?
      var_def.type = var.type unless var_def.type.length
    end

    if var.type.same_as?(var_def.type)
      conved = var
    else
      conved = do_conversion(var, var_def.type) ||
               create_tmpvar(var_def.type)
      notify_implicit_conv_performed(inits, var, conved)
    end
  else
    var = conved = create_tmpvar(var_def.type)
  end

  return var, conved
end