Class: Idl::FieldAccessExpressionAst
- Includes:
- Rvalue
- Defined in:
- lib/idlc/ast.rb,
lib/idlc/passes/prune.rb,
lib/idlc/passes/gen_adoc.rb
Overview
represents a bitfield or struct field access (rvalue)
for example:
entry.PPN
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
- #gen_adoc(indent, indent_spaces: 2) ⇒ Object
-
#initialize(input, interval, bitfield, field_name) ⇒ FieldAccessExpressionAst
constructor
A new instance of FieldAccessExpressionAst.
- #kind(symtab) ⇒ Object
- #obj ⇒ Object
- #prune(symtab, forced_type: nil) ⇒ 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:) ⇒ Object
-
#value(symtab) ⇒ Object
Return the compile-time-known value of the node.
Methods included from Rvalue
#max_value, #min_value, #truncate, #values
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, #nullify_assignments, #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, bitfield, field_name) ⇒ FieldAccessExpressionAst
Returns a new instance of FieldAccessExpressionAst.
6018 6019 6020 6021 6022 |
# File 'lib/idlc/ast.rb', line 6018 def initialize(input, interval, bitfield, field_name) super(input, interval, [bitfield]) @field_name = field_name end |
Class Method Details
.from_h(yaml, source_mapper) ⇒ Object
6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 |
# File 'lib/idlc/ast.rb', line 6085 def self.from_h(yaml, source_mapper) raise "Bad YAML" unless yaml.key?("kind") && yaml.fetch("kind") == "field_access_expr" input = input_from_source_yaml(yaml.fetch("source"), source_mapper) interval = interval_from_source_yaml(yaml.fetch("source")) FieldAccessExpressionAst.new( input, interval, T.cast(AstNode.from_h(yaml.fetch("expr"), source_mapper), RvalueAst), yaml.fetch("field_name") ) end |
Instance Method Details
#const_eval?(symtab) ⇒ Boolean
6012 |
# File 'lib/idlc/ast.rb', line 6012 def const_eval?(symtab) = obj.const_eval?(symtab) |
#gen_adoc(indent, indent_spaces: 2) ⇒ Object
92 93 94 |
# File 'lib/idlc/passes/gen_adoc.rb', line 92 def gen_adoc(indent, indent_spaces: 2) "#{' ' * indent}#{obj.gen_adoc(indent, indent_spaces:)}.#{@field_name}" end |
#kind(symtab) ⇒ Object
6024 6025 6026 |
# File 'lib/idlc/ast.rb', line 6024 def kind(symtab) obj.type(symtab).kind end |
#obj ⇒ Object
6015 |
# File 'lib/idlc/ast.rb', line 6015 def obj = T.cast(@children.fetch(0), RvalueAst) |
#prune(symtab, forced_type: nil) ⇒ Object
840 841 842 843 844 845 846 847 848 849 850 851 852 853 |
# File 'lib/idlc/passes/prune.rb', line 840 def prune(symtab, forced_type: nil) value_result = value_try do v = value(symtab) if type(symtab).kind == :bits if type(symtab).width == :unknown value_error "Unknown width" end end return PruneHelpers.create_literal(symtab, v, type(symtab), forced_type: forced_type || type(symtab)) end value_else(value_result) do FieldAccessExpressionAst.new(input, interval, obj.prune(symtab), @field_name) end end |
#to_h ⇒ Object
6077 6078 6079 6080 6081 6082 |
# File 'lib/idlc/ast.rb', line 6077 def to_h = { "kind" => "field_access_expr", "expr" => obj.to_h, "field_name" => @field_name, "source" => source_yaml } |
#to_idl ⇒ Object
6074 |
# File 'lib/idlc/ast.rb', line 6074 def to_idl = "#{obj.to_idl}.#{@field_name}" |
#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
6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 |
# File 'lib/idlc/ast.rb', line 6029 def type(symtab) obj_type = obj.type(symtab) if obj_type.kind == :bitfield Type.new(:bits, width: T.cast(obj_type, BitfieldType).range(@field_name).size) elsif obj_type.kind == :struct T.cast(obj_type, StructType).member_type(@field_name) else internal_error "huh? #{obj.text_value} #{obj_type.kind}" end end |
#type_check(symtab, strict:) ⇒ Object
6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 |
# File 'lib/idlc/ast.rb', line 6041 def type_check(symtab, strict:) obj.type_check(symtab, strict:) obj_type = obj.type(symtab) if obj_type.kind == :bitfield internal_error "#{obj.text_value} Not a BitfieldType (is a #{obj_type.class.name})" unless obj_type.respond_to?(:field_names) unless T.cast(obj_type, BitfieldType).field_names.include?(@field_name) type_error "#{@field_name} is not a member of #{obj_type}" end elsif obj_type.kind == :struct type_error "#{@field_name} is not a member of #{obj_type}" unless T.cast(obj_type, StructType).member?(@field_name) else type_error "#{obj.text_value} is not a bitfield (is #{obj.type(symtab)})" end end |
#value(symtab) ⇒ Object
Return the compile-time-known value of the node
6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 |
# File 'lib/idlc/ast.rb', line 6059 def value(symtab) if kind(symtab) == :bitfield range = T.cast(obj.type(symtab), BitfieldType).range(@field_name) (T.cast(obj.value(symtab), Integer) >> range.first) & ((1 << range.size) - 1) elsif kind(symtab) == :struct field_val = T.cast(obj.value(symtab), T::Hash[String, BasicValueRbType])[@field_name] value_error "#{@field_name} is not known at compile-time" if field_val.nil? field_val else type_error "#{obj.text_value} is Not a bitfield." end end |