Class: Idl::StatementAst
- Includes:
- Executable
- Defined in:
- lib/idlc/ast.rb,
lib/idlc/passes/prune.rb,
lib/idlc/passes/gen_adoc.rb,
lib/idlc/passes/gen_option_adoc.rb,
lib/idlc/passes/reachable_functions.rb,
lib/idlc/passes/reachable_exceptions.rb
Overview
represents a simple, one-line statement
for example:
Bits<64> new_variable;
new_variable = 4;
func();
Constant Summary
Constants inherited from AstNode
AstNode::Bits1Type, AstNode::Bits32Type, AstNode::Bits64Type, AstNode::BoolType, AstNode::ConstBoolType, AstNode::PossiblyUnknownBits1Type, AstNode::PossiblyUnknownBits32Type, AstNode::PossiblyUnknownBits64Type, AstNode::ReachableFunctionCacheType, AstNode::StringType, AstNode::VoidType
Instance Attribute Summary
Attributes inherited from AstNode
#children, #input, #interval, #parent
Class Method Summary collapse
Instance Method Summary collapse
- #action ⇒ Object
- #always_terminates? ⇒ Boolean
- #const_eval?(symtab) ⇒ Boolean
-
#execute(symtab) ⇒ void
“execute” the statement by updating the variables in the symbol table.
- #gen_adoc(indent = 0, indent_spaces: 2) ⇒ Object
- #gen_option_adoc ⇒ Object
-
#initialize(input, interval, action) ⇒ StatementAst
constructor
A new instance of StatementAst.
- #prune(symtab, forced_type: nil) ⇒ Object
- #reachable_exceptions(symtab, cache = {}) ⇒ Object
- #reachable_functions(symtab, cache = T.let({}, ReachableFunctionCacheType)) ⇒ Object
- #to_h ⇒ Object
- #to_idl ⇒ Object
-
#type_check(symtab, strict:) ⇒ void
type check this node and all children.
Methods included from Executable
Methods inherited from AstNode
#declaration?, #executable?, extract_base_var_name, #find_ancestor, #find_dst_registers, #find_referenced_csrs, #find_src_registers, #freeze_tree, #input_file, input_from_source_yaml, #inspect, #internal_error, interval_from_source_yaml, #lineno, #lines_around, #nullify_assignments, #pass_find_return_values, #path, #print_ast, #set_input_file, #set_input_file_unless_already_set, #source_line_file_offsets, #source_starting_offset, #source_yaml, #starting_line, #text_value, #truncation_warn, #type_error, #unindent, value_else, #value_else, value_error, #value_error, value_try, #value_try, write_back_nested
Constructor Details
#initialize(input, interval, action) ⇒ StatementAst
Returns a new instance of StatementAst.
6589 6590 6591 |
# File 'lib/idlc/ast.rb', line 6589 def initialize(input, interval, action) super(input, interval, [action]) end |
Class Method Details
.from_h(yaml, source_mapper) ⇒ Object
6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 |
# File 'lib/idlc/ast.rb', line 6620 def self.from_h(yaml, source_mapper) raise "Bad YAML" unless yaml.key?("kind") && yaml.fetch("kind") == "stmt" input = input_from_source_yaml(yaml.fetch("source"), source_mapper) interval = interval_from_source_yaml(yaml.fetch("source")) StatementAst.new( input, interval, AstNode.from_h(yaml.fetch("expr"), source_mapper) ) end |
Instance Method Details
#action ⇒ Object
6587 |
# File 'lib/idlc/ast.rb', line 6587 def action = @children[0] |
#always_terminates? ⇒ Boolean
375 376 377 |
# File 'lib/idlc/passes/prune.rb', line 375 def always_terminates? action.is_a?(FunctionCallExpressionAst) && action.name == "raise" end |
#const_eval?(symtab) ⇒ Boolean
6585 |
# File 'lib/idlc/ast.rb', line 6585 def const_eval?(symtab) = action.const_eval?(symtab) |
#execute(symtab) ⇒ void
This method returns an undefined value.
“execute” the statement by updating the variables in the symbol table
6599 6600 6601 6602 6603 6604 6605 6606 |
# File 'lib/idlc/ast.rb', line 6599 def execute(symtab) if action.declaration? action.add_symbol(symtab) end if action.executable? action.execute(symtab) end end |
#gen_adoc(indent = 0, indent_spaces: 2) ⇒ Object
264 265 266 |
# File 'lib/idlc/passes/gen_adoc.rb', line 264 def gen_adoc(indent = 0, indent_spaces: 2) "#{' ' * indent}#{action.gen_adoc(0, indent_spaces:)};" end |
#gen_option_adoc ⇒ Object
83 84 85 |
# File 'lib/idlc/passes/gen_option_adoc.rb', line 83 def gen_option_adoc action.gen_option_adoc end |
#prune(symtab, forced_type: nil) ⇒ Object
379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/idlc/passes/prune.rb', line 379 def prune(symtab, forced_type: nil) pruned_action = action.prune(symtab) new_stmt = StatementAst.new(input, interval, pruned_action) # pruned_action.freeze_tree(symtab) unless pruned_action.frozen? pruned_action.add_symbol(symtab) if pruned_action.declaration? # action#prune already handles symtab update (execute) new_stmt end |
#reachable_exceptions(symtab, cache = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/idlc/passes/reachable_exceptions.rb', line 75 def reachable_exceptions(symtab, cache = {}) mask = # if action.is_a?(FunctionCallExpressionAst) action.reachable_exceptions(symtab, cache) # else # 0 # end action.add_symbol(symtab) if action.declaration? if action.executable? value_try do action.execute(symtab) end end # ok mask end |
#reachable_functions(symtab, cache = T.let({}, ReachableFunctionCacheType)) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/idlc/passes/reachable_functions.rb', line 82 def reachable_functions(symtab, cache = T.let({}, ReachableFunctionCacheType)) fns = action.reachable_functions(symtab, cache) action.add_symbol(symtab) if action.declaration? value_try do action.execute(symtab) if action.executable? rescue SystemStackError type_error "Detected unbounded recursion during compile-time constant evaluation at #{input_file}:#{input_line}.. This recursion cannot be represented or validated." end # ok fns end |
#to_h ⇒ Object
6613 6614 6615 6616 6617 |
# File 'lib/idlc/ast.rb', line 6613 def to_h = { "kind" => "stmt", "expr" => action.to_h, "source" => source_yaml } |
#to_idl ⇒ Object
6610 |
# File 'lib/idlc/ast.rb', line 6610 def to_idl = "#{action.to_idl};" |
#type_check(symtab, strict:) ⇒ void
This method returns an undefined value.
type check this node and all children
Calls to #type and/or #value may depend on type_check being called first with the same symtab. If not, those functions may raise an AstNode::InternalError
6594 6595 6596 |
# File 'lib/idlc/ast.rb', line 6594 def type_check(symtab, strict:) action.type_check(symtab, strict:) end |