Class: Idl::EnumSizeAst

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

Overview

represents the builtin that returns the nymber of elements in an enum class

$enum_size(XRegWidth) #=> 2

Instance Method Summary collapse

Constructor Details

#initialize(input, interval, enum_class_name) ⇒ EnumSizeAst

Returns a new instance of EnumSizeAst.



829
830
831
# File 'lib/idl/ast.rb', line 829

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

Instance Method Details

#enum_classObject



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

def enum_class = children[0]

#to_idlObject



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

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

#type(symtab) ⇒ Object



837
838
839
840
841
842
843
# File 'lib/idl/ast.rb', line 837

def type(symtab)
  Type.new(
    :bits,
    width: enum_class.type(symtab).element_names.size.bit_length,
    qualifiers: [:const]
  )
end

#type_check(symtab) ⇒ Object



833
834
835
# File 'lib/idl/ast.rb', line 833

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

#value(symtab) ⇒ Object



845
846
847
# File 'lib/idl/ast.rb', line 845

def value(symtab)
  enum_class.type(symtab).element_names.size
end