Class: Idl::FieldAccessExpressionAst

Inherits:
AstNode
  • Object
show all
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

Constructor Details

#initialize(input, interval, bitfield, field_name) ⇒ FieldAccessExpressionAst

Returns a new instance of FieldAccessExpressionAst.



3348
3349
3350
3351
3352
# File 'lib/idl/ast.rb', line 3348

def initialize(input, interval, bitfield, field_name)
  super(input, interval, [bitfield])

  @field_name = field_name
end

Instance Method Details

#kind(symtab) ⇒ Object



3354
3355
3356
# File 'lib/idl/ast.rb', line 3354

def kind(symtab)
  obj.type(symtab).kind
end

#objObject



3346
# File 'lib/idl/ast.rb', line 3346

def obj = @children[0]

#to_idlString

Return valid IDL representation of the node (and its subtree)

Returns:

  • (String)

    IDL code for the node



3401
# File 'lib/idl/ast.rb', line 3401

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

Parameters:

Returns:

  • (Type)

    The type of the node

Raises:



3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
# File 'lib/idl/ast.rb', line 3359

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



3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
# File 'lib/idl/ast.rb', line 3371

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



3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
# File 'lib/idl/ast.rb', line 3389

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

Parameters:

  • symtab (SymbolTable)

    The context for the evaulation

Returns:

  • (Array<Integer>)

    The complete list of compile-time-known values, when they are integral

  • (Array<Boolean>)

    The complete list of compile-time-known values, when they are booleans

  • (AstNode::ValueError)

    if the list of values is not knowable at compile time