Class: Idl::PostIncrementExpressionAst
- Includes:
- Executable
- Defined in:
- lib/idlc/ast.rb,
lib/idlc/passes/prune.rb,
lib/idlc/passes/prune.rb,
lib/idlc/passes/gen_adoc.rb
Overview
represents a post-increment expression
for example:
i++
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
- #const_eval?(symtab) ⇒ Boolean
-
#execute(symtab) ⇒ void
"execute" the statement by updating the variables in the symbol table.
- #gen_adoc(indent, indent_spaces: 2) ⇒ Object
-
#initialize(input, interval, rval) ⇒ PostIncrementExpressionAst
constructor
A new instance of PostIncrementExpressionAst.
- #nullify_assignments(symtab) ⇒ Object
- #prune(symtab, forced_type: nil) ⇒ Object
- #rval ⇒ Object
- #to_h ⇒ Object
- #to_idl ⇒ Object
-
#type(symtab) ⇒ Type
Given a specific symbol table, return the type of this node.
-
#type_check(symtab, strict:) ⇒ void
type check this node and all children.
Methods included from Executable
Methods inherited from AstNode
#always_terminates?, #declaration?, #executable?, extract_base_var_name, #find_ancestor, #find_dst_registers, #find_referenced_csrs, #find_src_registers, #freeze_tree, #gen_option_adoc, #input_file, input_from_source_yaml, #inspect, #internal_error, interval_from_source_yaml, #lineno, #lines_around, #pass_find_return_values, #path, #print_ast, #reachable_exceptions, #reachable_functions, #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, rval) ⇒ PostIncrementExpressionAst
Returns a new instance of PostIncrementExpressionAst.
5923 5924 5925 |
# File 'lib/idlc/ast.rb', line 5923 def initialize(input, interval, rval) super(input, interval, [rval]) end |
Class Method Details
.from_h(yaml, source_mapper) ⇒ Object
5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 |
# File 'lib/idlc/ast.rb', line 5971 def self.from_h(yaml, source_mapper) raise "Bad YAML" unless yaml.key?("kind") && yaml.fetch("kind") == "post_increment_expr" input = input_from_source_yaml(yaml.fetch("source"), source_mapper) interval = interval_from_source_yaml(yaml.fetch("source")) PostIncrementExpressionAst.new( input, interval, AstNode.from_h(yaml.fetch("expr"), source_mapper) ) end |
Instance Method Details
#const_eval?(symtab) ⇒ Boolean
5919 |
# File 'lib/idlc/ast.rb', line 5919 def const_eval?(symtab) = rval.const_eval?(symtab) |
#execute(symtab) ⇒ void
This method returns an undefined value.
"execute" the statement by updating the variables in the symbol table
5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 |
# File 'lib/idlc/ast.rb', line 5943 def execute(symtab) var = symtab.get(rval.text_value) value_result = value_try do internal_error "No symbol named '#{rval.text_value}'" if var.nil? value_error "#{rval.text_value} is not compile-time-known" if var.value.nil? var.value = var.value + 1 end value_else(value_result) do var.value = nil value_error "#{rval.text_value} is not compile-time-known" if var.value.nil? end end |
#gen_adoc(indent, indent_spaces: 2) ⇒ Object
50 51 52 |
# File 'lib/idlc/passes/gen_adoc.rb', line 50 def gen_adoc(indent, indent_spaces: 2) "#{' ' * indent}#{rval.gen_adoc(indent, indent_spaces:)}++" end |
#nullify_assignments(symtab) ⇒ Object
193 194 195 196 |
# File 'lib/idlc/passes/prune.rb', line 193 def nullify_assignments(symtab) var = symtab.get(rval.text_value) var.value = nil unless var.nil? end |
#prune(symtab, forced_type: nil) ⇒ Object
961 962 963 964 965 966 967 968 |
# File 'lib/idlc/passes/prune.rb', line 961 def prune(symtab, forced_type: nil) new_ast = PostIncrementExpressionAst.new(input, interval, rval.dup) value_try do new_ast.execute(symtab) end # value_else: execute already sets nil on failure, nothing more to do new_ast end |
#rval ⇒ Object
5921 |
# File 'lib/idlc/ast.rb', line 5921 def rval = @children[0] |
#to_h ⇒ Object
5964 5965 5966 5967 5968 |
# File 'lib/idlc/ast.rb', line 5964 def to_h = { "kind" => "post_increment_expr", "expr" => rval.to_h, "source" => source_yaml } |
#to_idl ⇒ Object
5961 |
# File 'lib/idlc/ast.rb', line 5961 def to_idl = "#{rval.to_idl}++" |
#type(symtab) ⇒ Type
Given a specific symbol table, return the type of this node.
Should not be called until #type_check is called with the same arguments
5938 5939 5940 |
# File 'lib/idlc/ast.rb', line 5938 def type(symtab) rval.type(symtab) end |
#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
5928 5929 5930 5931 5932 5933 5934 5935 |
# File 'lib/idlc/ast.rb', line 5928 def type_check(symtab, strict:) rval.type_check(symtab, strict:) var = symtab.get(rval.text_value) rval_immutable = rval.is_a?(IdAst) && (rval.type(symtab).const? && !var.for_loop_iter?) type_error "Cannot increment a const variable" if rval_immutable type_error "Post increment variable must be integral" unless var.type.integral? end |