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.



3421
3422
3423
3424
3425
3426
3427
# File 'lib/idl/ast.rb', line 3421

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



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

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



3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
# File 'lib/idl/ast.rb', line 3430

def freeze_tree(global_symtab)
  return if frozen?

  enum_def_ast = global_symtab.archdef.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



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

def member_name = @member_name

#to_idlString

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

Returns:

  • (String)

    IDL code for the node



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

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

#type(symtab) ⇒ Object



3456
3457
3458
3459
3460
3461
# File 'lib/idl/ast.rb', line 3456

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:



3446
3447
3448
3449
3450
3451
3452
3453
# File 'lib/idl/ast.rb', line 3446

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



3464
3465
3466
3467
3468
# File 'lib/idl/ast.rb', line 3464

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 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