Class: AdLint::Cc1::Interpreter
- Inherits:
-
Object
- Object
- AdLint::Cc1::Interpreter
- Extended by:
- Pluggable, Forwardable
- Includes:
- BranchOptions, Conversion, InterpreterMediator, InterpreterOptions
- Defined in:
- lib/adlint/cc1/interp.rb
Constant Summary
Constants included from BranchOptions
BranchOptions::COMPLEMENTAL, BranchOptions::FINAL, BranchOptions::FIRST, BranchOptions::IMPLICIT_COND, BranchOptions::NARROWING, BranchOptions::SMOTHER_BREAK, BranchOptions::WIDENING
Constants included from InterpreterOptions
AdLint::Cc1::InterpreterOptions::QUIET, AdLint::Cc1::InterpreterOptions::WITHOUT_SIDE_EFFECTS
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#type_resolver ⇒ Object
readonly
Returns the value of attribute type_resolver.
Instance Method Summary collapse
- #_active_function ⇒ Object
- #_enter_function(fun_def) ⇒ Object
- #_leave_function ⇒ Object
- #_quiet=(quiet) ⇒ Object
- #_without_side_effects=(without_side_effects) ⇒ Object
- #execute(node, *opts) ⇒ Object
-
#initialize(type_tbl, env = nil) ⇒ Interpreter
constructor
A new instance of Interpreter.
- #quiet? ⇒ Boolean
- #without_side_effects? ⇒ Boolean
Methods included from Pluggable
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
Methods included from InterpObjectBridge
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
Constructor Details
#initialize(type_tbl, env = nil) ⇒ Interpreter
Returns a new instance of Interpreter.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/adlint/cc1/interp.rb', line 77 def initialize(type_tbl, env = nil) @type_table = type_tbl @environment = env || Environment.new(type_tbl) @type_resolver = DynamicTypeResolver.new(type_tbl, self) @sub_interpreters = [ DeclarationInterpreter.new(self), ParameterDefinitionInterpreter.new(self), FunctionInterpreter.new(self), SwitchStatementInterpreter.new(self), StatementInterpreter.new(self), ExpressionInterpreter.new(self) ] = [] # NOTE: Active (executing) function may be nested if the nested # function-definition of the GCC extension is used. @active_function_stack = [] end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
98 99 100 |
# File 'lib/adlint/cc1/interp.rb', line 98 def environment @environment end |
#type_resolver ⇒ Object (readonly)
Returns the value of attribute type_resolver.
99 100 101 |
# File 'lib/adlint/cc1/interp.rb', line 99 def type_resolver @type_resolver end |
Instance Method Details
#_active_function ⇒ Object
497 498 499 500 501 502 503 |
# File 'lib/adlint/cc1/interp.rb', line 497 def _active_function # NOTE: This method is called only from # StatementInterpreter#visit_return_statement. # NOTE: To convert returning object, StatementInterpreter must have # knowledge about conversion destination type. @active_function_stack.last end |
#_enter_function(fun_def) ⇒ Object
505 506 507 508 |
# File 'lib/adlint/cc1/interp.rb', line 505 def _enter_function(fun_def) # NOTE: This method is called only from FunctionInterpreter. @active_function_stack.push(fun_def) end |
#_leave_function ⇒ Object
510 511 512 513 |
# File 'lib/adlint/cc1/interp.rb', line 510 def _leave_function(*) # NOTE: This method is called only from FunctionInterpreter. @active_function_stack.pop end |
#_quiet=(quiet) ⇒ Object
475 476 477 478 479 480 481 482 |
# File 'lib/adlint/cc1/interp.rb', line 475 def _quiet=(quiet) # NOTE: This method is called only from ControllingExpression. if quiet cur_opts.add(QUIET) else cur_opts.delete(QUIET) end end |
#_without_side_effects=(without_side_effects) ⇒ Object
488 489 490 491 492 493 494 495 |
# File 'lib/adlint/cc1/interp.rb', line 488 def _without_side_effects=(without_side_effects) # NOTE: This method is called only from ExpressionEvaluator. if without_side_effects cur_opts.add(WITHOUT_SIDE_EFFECTS) else cur_opts.delete(WITHOUT_SIDE_EFFECTS) end end |
#execute(node, *opts) ⇒ Object
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/adlint/cc1/interp.rb', line 454 def execute(node, *opts) .push(cur_opts + opts) if without_side_effects? rslt = nil branched_eval(nil, FINAL) do rslt = node.accept(interpreter_for(node)) # NOTE: To rollback latest variable value versions. BreakEvent.of_return.throw end else rslt = node.accept(interpreter_for(node)) end rslt ensure .pop end |
#quiet? ⇒ Boolean
471 472 473 |
# File 'lib/adlint/cc1/interp.rb', line 471 def quiet? cur_opts.include?(QUIET) end |
#without_side_effects? ⇒ Boolean
484 485 486 |
# File 'lib/adlint/cc1/interp.rb', line 484 def without_side_effects? cur_opts.include?(WITHOUT_SIDE_EFFECTS) end |