Class: Idl::EnumRefAst

Inherits:
AstNode show all
Includes:
Rvalue
Defined in:
lib/idl/ast.rb

Overview

represents an enum reference

for example:

ExtensionName::C
PrivilegeMode::M

Instance Method Summary collapse

Constructor Details

#initialize(input, interval, class_name, member_name) ⇒ EnumRefAst

Returns a new instance of EnumRefAst.



3440
3441
3442
3443
3444
3445
3446
# File 'lib/idl/ast.rb', line 3440

def initialize(input, interval, class_name, member_name)
  super(input, interval, EMPTY_ARRAY)

  @enum_class_name = class_name
  @member_name = member_name
  @enum_def_type = nil
end

Instance Method Details

#class_nameObject



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

def class_name = @enum_class_name

#freeze_tree(global_symtab) ⇒ Object

freeze the entire tree from further modification This is also an opportunity to pre-calculate anything that only needs global symbols

Parameters:

  • global_symtab (SymbolTable)

    Symbol table with global scope populated



3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
# File 'lib/idl/ast.rb', line 3449

def freeze_tree(global_symtab)
  return if frozen?

  enum_def_ast = global_symtab.cfg_arch.global_ast.enums.find { |e| e.name == @enum_class_name }

  @enum_def_type =
    if enum_def_ast.is_a?(BuiltinEnumDefinitionAst)
      enum_def_ast&.type(global_symtab)
    else
      enum_def_ast&.type(nil)
    end

  freeze
end

#member_nameObject



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

def member_name = @member_name

#to_idlString

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

Returns:

  • (String)

    IDL code for the node



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

def to_idl = "#{@enum_class_name}::#{@member_name}"

#type(symtab) ⇒ Object



3475
3476
3477
3478
3479
3480
# File 'lib/idl/ast.rb', line 3475

def type(symtab)
  internal_error "Not frozen?" unless frozen?
  type_error "No enum named #{@enum_class_name}" if @enum_def_type.nil?

  @enum_def_type.ref_type
end

#type_check(symtab) ⇒ 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

Parameters:

Raises:



3465
3466
3467
3468
3469
3470
3471
3472
# File 'lib/idl/ast.rb', line 3465

def type_check(symtab)
  enum_def_type = @enum_def_type

  type_error "No symbol #{@enum_class_name} has been defined" if enum_def_type.nil?

  type_error "#{@enum_class_name} is not an enum type" unless enum_def_type.is_a?(EnumerationType)
  type_error "#{@enum_class_name} has no member '#{@member_name}'" if enum_def_type.value(@member_name).nil?
end

#value(symtab) ⇒ Object



3483
3484
3485
3486
3487
# File 'lib/idl/ast.rb', line 3483

def value(symtab)
  internal_error "Must call type_check first" if @enum_def_type.nil?

  @enum_def_type.value(@member_name)
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 evaluation

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