Class: Idl::BitfieldFieldDefinitionAst
- Defined in:
- lib/idlc/ast.rb
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 collapse
-
#name ⇒ String
readonly
The field name.
Attributes inherited from AstNode
#children, #input, #interval, #parent
Class Method Summary collapse
Instance Method Summary collapse
- #const_eval?(symtab) ⇒ Boolean
-
#initialize(input, interval, name, msb, lsb) ⇒ BitfieldFieldDefinitionAst
constructor
A new instance of BitfieldFieldDefinitionAst.
-
#range(symtab) ⇒ Object
Range The field’s location in the bitfield.
- #to_h ⇒ Object
- #to_idl ⇒ Object
-
#type_check(symtab, strict:) ⇒ void
type check this node and all children.
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_adoc, #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, #prune, #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, name, msb, lsb) ⇒ BitfieldFieldDefinitionAst
Returns a new instance of BitfieldFieldDefinitionAst.
2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 |
# File 'lib/idlc/ast.rb', line 2120 def initialize(input, interval, name, msb, lsb) if lsb.nil? super(input, interval, [msb]) else super(input, interval, [msb, lsb]) end @name = name @lsb = lsb @msb = msb end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns The field name.
2115 2116 2117 |
# File 'lib/idlc/ast.rb', line 2115 def name @name end |
Class Method Details
.from_h(yaml, source_mapper) ⇒ Object
2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 |
# File 'lib/idlc/ast.rb', line 2186 def self.from_h(yaml, source_mapper) raise "Bad YAML" unless yaml.key?("kind") && yaml.fetch("kind") == "bitfield_field_decl" input = input_from_source_yaml(yaml.fetch("source"), source_mapper) interval = interval_from_source_yaml(yaml.fetch("source")) BitfieldFieldDefinitionAst.new( input, interval, yaml.fetch("name"), AstNode.from_h(yaml.fetch("range").fetch("msb"), source_mapper), AstNode.from_h(yaml.fetch("range").fetch("lsb"), source_mapper) ) end |
Instance Method Details
#const_eval?(symtab) ⇒ Boolean
2118 |
# File 'lib/idlc/ast.rb', line 2118 def const_eval?(symtab) = true |
#range(symtab) ⇒ Object
Returns Range The field’s location in the bitfield.
2156 2157 2158 2159 2160 2161 2162 2163 |
# File 'lib/idlc/ast.rb', line 2156 def range(symtab) if @lsb.nil? msb_val = @msb.value(symtab) msb_val..msb_val else @lsb.value(symtab)..@msb.value(symtab) end end |
#to_h ⇒ Object
2175 2176 2177 2178 2179 2180 2181 2182 2183 |
# File 'lib/idlc/ast.rb', line 2175 def to_h = { "kind" => "bitfield_field_decl", "name" => name, "range" => { "lsb" => @lsb.nil? ? @msb.to_h : @lsb.to_h, "msb" => @msb.to_h }, "source" => source_yaml } |
#to_idl ⇒ Object
2166 2167 2168 2169 2170 2171 2172 |
# File 'lib/idlc/ast.rb', line 2166 def to_idl if @lsb.nil? "#{@name} #{@msb.to_idl}" else "#{@name} #{@msb.to_idl}-#{@lsb.to_idl}" end 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
2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 |
# File 'lib/idlc/ast.rb', line 2133 def type_check(symtab, strict:) type_error "Cannot use reserved word '#{@name}' as field name" if ReservedWords::RESERVED.include?(@name) @msb.type_check(symtab, strict:) value_result = value_try do @msb.value(symtab) end value_else(value_result) do @msb.type_error "Bitfield position must be compile-time-known" end return if @lsb.nil? @lsb.type_check(symtab, strict:) value_result = value_try do @lsb.value(symtab) end value_else(value_result) do @lsb.type_error "Bitfield position must be compile-time-known" end end |