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.



942
943
944
# File 'lib/idl/ast.rb', line 942

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

Instance Method Details

#enum_classObject



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

def enum_class = children[0]

#to_idlObject



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

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

#type(symtab) ⇒ Object



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

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



946
947
948
# File 'lib/idl/ast.rb', line 946

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

#value(symtab) ⇒ Object



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

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