Class: Idl::EnumArrayCastAst

Inherits:
AstNode
  • Object
show all
Defined in:
lib/idl/ast.rb

Overview

represents the builtin that returns an array with all elements of an Enum type

$enum_to_a(PrivilegeMode) #=> [3, 1, 1, 0, 5, 4]

Instance Method Summary collapse

Constructor Details

#initialize(input, interval, enum_class_name) ⇒ EnumArrayCastAst

Returns a new instance of EnumArrayCastAst.



940
941
942
# File 'lib/idl/ast.rb', line 940

def initialize(input, interval, enum_class_name)
  super(input, interval, [enum_class_name])
end

Instance Method Details

#enum_classObject



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

def enum_class = children[0]

#to_idlObject



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

def to_idl = "$enum_to_a(#{enum_class.to_idl})"

#type(symtab) ⇒ Object



948
949
950
951
952
953
954
955
# File 'lib/idl/ast.rb', line 948

def type(symtab)
  Type.new(
    :array,
    width: enum_class.type(symtab).element_values.size,
    sub_type: Type.new(:bits, width: enum_class.type(symtab).width, qualifiers: [:const]),
    qualifiers: [:const]
  )
end

#type_check(symtab) ⇒ Object



944
945
946
# File 'lib/idl/ast.rb', line 944

def type_check(symtab)
  enum_class.type_check(symtab)
end

#value(symtab) ⇒ Object



957
958
959
# File 'lib/idl/ast.rb', line 957

def value(symtab)
  enum_class.type(symtab).element_values
end