Class: Idl::FieldAccessExpressionAst
- Includes:
- Rvalue
- Defined in:
- lib/idl/ast.rb
Overview
represents a bitfield or struct field access (rvalue)
for example:
entry.PPN
Instance Method Summary collapse
-
#initialize(input, interval, bitfield, field_name) ⇒ FieldAccessExpressionAst
constructor
A new instance of FieldAccessExpressionAst.
- #kind(symtab) ⇒ Object
- #obj ⇒ Object
-
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree).
-
#type(symtab) ⇒ Type
Given a specific symbol table, return the type of this node.
- #type_check(symtab) ⇒ Object
-
#value(symtab) ⇒ Object
Return the compile-time-known value of the node.
-
#values(symtab) ⇒ Array<Integer>, ...
included
from Rvalue
Return a complete list of possible compile-time-known values of the node, or raise a ValueError if the full list cannot be determined.
Constructor Details
#initialize(input, interval, bitfield, field_name) ⇒ FieldAccessExpressionAst
Returns a new instance of FieldAccessExpressionAst.
3367 3368 3369 3370 3371 |
# File 'lib/idl/ast.rb', line 3367 def initialize(input, interval, bitfield, field_name) super(input, interval, [bitfield]) @field_name = field_name end |
Instance Method Details
#kind(symtab) ⇒ Object
[View source]
3373 3374 3375 |
# File 'lib/idl/ast.rb', line 3373 def kind(symtab) obj.type(symtab).kind end |
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree)
3420 |
# File 'lib/idl/ast.rb', line 3420 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
3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 |
# File 'lib/idl/ast.rb', line 3378 def type(symtab) obj_type = obj.type(symtab) if obj_type.kind == :bitfield Type.new(:bits, width: obj_type.range(@field_name).size) elsif obj_type.kind == :struct obj_type.member_type(@field_name) else internal_error "huh? #{obj.text_value} #{obj_type.kind}" end end |
#type_check(symtab) ⇒ Object
[View source]
3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 |
# File 'lib/idl/ast.rb', line 3390 def type_check(symtab) obj.type_check(symtab) obj_type = obj.type(symtab) if obj_type.kind == :bitfield internal_error "#{bitfield.text_value} Not a BitfieldType (is a #{obj_type.class.name})" unless obj_type.respond_to?(:field_names) unless obj_type.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 obj_type.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
3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 |
# File 'lib/idl/ast.rb', line 3408 def value(symtab) if kind(symtab) == :bitfield range = obj.type(symtab).range(@field_name) (obj.value(symtab) >> range.first) & ((1 << range.size) - 1) elsif kind(symtab) == :struct obj.value(symtab)[@field_name] else type_error "#{obj.text_value} is Not a bitfield." end end |
#values(symtab) ⇒ Array<Integer>, ... Originally defined in module Rvalue
Return a complete list of possible compile-time-known values of the node, or raise a ValueError if the full list cannot be determined
For most AstNodes, this will just be a single-entry array