Class: Idl::PostDecrementExpressionAst
- Inherits:
-
AstNode
- Object
- AstNode
- Idl::PostDecrementExpressionAst
show all
- 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-decrement 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
Methods included from Executable
#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
Returns a new instance of PostDecrementExpressionAst.
5660
5661
5662
|
# File 'lib/idlc/ast.rb', line 5660
def initialize(input, interval, rval)
super(input, interval, [rval])
end
|
Class Method Details
.from_h(yaml, source_mapper) ⇒ Object
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
|
# File 'lib/idlc/ast.rb', line 5703
def self.from_h(yaml, source_mapper)
raise "Bad YAML" unless yaml.key?("kind") && yaml.fetch("kind") == "post_decrement_expr"
input = input_from_source_yaml(yaml.fetch("source"), source_mapper)
interval = interval_from_source_yaml(yaml.fetch("source"))
PostDecrementExpressionAst.new(
input, interval,
AstNode.from_h(yaml.fetch("expr"), source_mapper)
)
end
|
Instance Method Details
#const_eval?(symtab) ⇒ Boolean
5655
|
# File 'lib/idlc/ast.rb', line 5655
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
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
|
# File 'lib/idlc/ast.rb', line 5677
def execute(symtab)
var = symtab.get(rval.text_value)
value_result = value_try do
internal_error "No symbol #{rval.text_value}" if var.nil?
value_error "value of variable '#{rval.text_value}' not know" if var.value.nil?
var.value = var.value - 1
end
value_else(value_result) do
var.value = nil
value_error "value of variable '#{rval.text_value}' not know"
end
end
|
#gen_adoc(indent, indent_spaces: 2) ⇒ Object
55
56
57
|
# File 'lib/idlc/passes/gen_adoc.rb', line 55
def gen_adoc(indent, indent_spaces: 2)
"#{' ' * indent}#{rval.gen_adoc(indent, indent_spaces:)}--"
end
|
#nullify_assignments(symtab) ⇒ Object
199
200
201
202
|
# File 'lib/idlc/passes/prune.rb', line 199
def nullify_assignments(symtab)
var = symtab.get(rval.text_value)
var.value = nil unless var.nil?
end
|
#prune(symtab, forced_type: nil) ⇒ Object
972
973
974
975
976
977
978
979
|
# File 'lib/idlc/passes/prune.rb', line 972
def prune(symtab, forced_type: nil)
new_ast = PostDecrementExpressionAst.new(input, interval, rval.dup)
value_try do
new_ast.execute(symtab)
end
new_ast
end
|
#to_h ⇒ Object
5696
5697
5698
5699
5700
|
# File 'lib/idlc/ast.rb', line 5696
def to_h = {
"kind" => "post_decrement_expr",
"expr" => rval.to_h,
"source" => source_yaml
}
|
#to_idl ⇒ Object
5693
|
# File 'lib/idlc/ast.rb', line 5693
def to_idl = "#{rval.to_idl}--"
|
#type(symtab) ⇒ Object
5672
5673
5674
|
# File 'lib/idlc/ast.rb', line 5672
def type(symtab)
rval.type(symtab)
end
|
#type_check(symtab, strict:) ⇒ Object
5664
5665
5666
5667
5668
5669
5670
|
# File 'lib/idlc/ast.rb', line 5664
def type_check(symtab, strict:)
rval.type_check(symtab, strict:)
rval_immutable =
rval.is_a?(IdAst) && (rval.type(symtab).const? && !symtab.get(T.cast(rval, IdAst).name).for_loop_iter?)
type_error "Cannot decrement a const variable" if rval_immutable
type_error "Post decement must be integral" unless rval.type(symtab).integral?
end
|