Class: Idl::EnumCastAst
- Includes:
- Rvalue
- Defined in:
- lib/idl/ast.rb
Instance Method Summary collapse
-
#enum_name ⇒ UserTypeAst
Enum name.
-
#expression ⇒ Rvalue
Value expression.
-
#initialize(input, interval, user_type_name, expression) ⇒ EnumCastAst
constructor
A new instance of EnumCastAst.
- #to_idl ⇒ Object
- #type(symtab) ⇒ Object
- #type_check(symtab) ⇒ Object
- #value(symtab) ⇒ Object
-
#values(symtab) ⇒ Array<Integer>, ...
included
from 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.
Constructor Details
#initialize(input, interval, user_type_name, expression) ⇒ EnumCastAst
Returns a new instance of EnumCastAst.
896 897 898 |
# File 'lib/idl/ast.rb', line 896 def initialize(input, interval, user_type_name, expression) super(input, interval, [user_type_name, expression]) end |
Instance Method Details
#enum_name ⇒ UserTypeAst
Returns Enum name.
891 |
# File 'lib/idl/ast.rb', line 891 def enum_name = @children[0] |
#expression ⇒ Rvalue
Returns Value expression.
894 |
# File 'lib/idl/ast.rb', line 894 def expression = @children[1] |
#to_idl ⇒ Object
925 |
# File 'lib/idl/ast.rb', line 925 def to_idl = "$enum(#{enum_name.to_idl}, #{expression.to_idl})" |
#type(symtab) ⇒ Object
918 919 920 921 |
# File 'lib/idl/ast.rb', line 918 def type(symtab) enum_def_type = symtab.get(enum_name.text_value) Type.new(:enum_ref, enum_class: enum_def_type) end |
#type_check(symtab) ⇒ Object
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 |
# File 'lib/idl/ast.rb', line 900 def type_check(symtab) enum_name.type_check(symtab) expression.type_check(symtab) if expression.type(symtab).kind != :bits type_error "Can only cast from Bits<N> to enum" end enum_def_type = symtab.get(enum_name.text_value) type_error "No enum named #{enum_name.text_value}" if enum_def_type.nil? value_try do unless enum_def_type.element_values.include?(expression.value(symtab)) type_error "#{expression.value(symtab)} is not a value in enum #{enum_name.text_value}" end end end |
#value(symtab) ⇒ Object
923 |
# File 'lib/idl/ast.rb', line 923 def value(symtab) = expression.value(symtab) |
#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