Class: Idl::EnumArrayCastAst

Inherits:
AstNode
  • Object
show all
Includes:
Rvalue
Defined in:
lib/idlc/ast.rb,
lib/idlc/passes/gen_adoc.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]

Constant Summary

Constants inherited from AstNode

AstNode::Bits1Type, AstNode::Bits32Type, AstNode::Bits64Type, AstNode::BoolType, AstNode::ConstBoolType, AstNode::PossiblyUnknownBits1Type, AstNode::PossiblyUnknownBits32Type, AstNode::PossiblyUnknownBits64Type, AstNode::ReachableFunctionCacheType, AstNode::StringType, AstNode::VoidType

Instance Attribute Summary

Attributes inherited from AstNode

#children, #input, #interval, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rvalue

#max_value, #min_value, #truncate, #values

Methods inherited from AstNode

#always_terminates?, #declaration?, #executable?, extract_base_var_name, #find_ancestor, #find_dst_registers, #find_referenced_csrs, #find_src_registers, #freeze_tree, #gen_option_adoc, #input_file, input_from_source_yaml, #inspect, #internal_error, interval_from_source_yaml, #lineno, #lines_around, #nullify_assignments, #pass_find_return_values, #path, #print_ast, #prune, #reachable_exceptions, #reachable_functions, #set_input_file, #set_input_file_unless_already_set, #source_line_file_offsets, #source_starting_offset, #source_yaml, #starting_line, #text_value, #truncation_warn, #type_error, #unindent, value_else, #value_else, value_error, #value_error, value_try, #value_try, write_back_nested

Constructor Details

#initialize(input, interval, enum_class_name) ⇒ EnumArrayCastAst

Returns a new instance of EnumArrayCastAst.



1831
1832
1833
1834
# File 'lib/idlc/ast.rb', line 1831

def initialize(input, interval, enum_class_name)
  user_type_name = enum_class_name.is_a?(UserTypeNameAst) ? enum_class_name : UserTypeNameAst.new(enum_class_name.input, enum_class_name.interval, enum_class_name.name)
  super(input, interval, [user_type_name])
end

Class Method Details

.from_h(yaml, source_mapper) ⇒ Object



1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
# File 'lib/idlc/ast.rb', line 1864

def self.from_h(yaml, source_mapper)
  raise "Bad YAML" unless yaml.key?("kind") && yaml.fetch("kind") == "enum_to_array_cast"

  input = input_from_source_yaml(yaml.fetch("source"), source_mapper)
  interval = interval_from_source_yaml(yaml.fetch("source"))
  EnumArrayCastAst.new(
    input, interval,
    T.cast(AstNode.from_h(yaml.fetch("enum_class_name"), source_mapper), UserTypeNameAst)
  )
end

Instance Method Details

#const_eval?(symtab) ⇒ Boolean

Returns:

  • (Boolean)


1828
# File 'lib/idlc/ast.rb', line 1828

def const_eval?(symtab) = true

#enum_classObject



1825
# File 'lib/idlc/ast.rb', line 1825

def enum_class = children.fetch(0)

#gen_adoc(indent, indent_spaces: 2) ⇒ Object



137
138
139
# File 'lib/idlc/passes/gen_adoc.rb', line 137

def gen_adoc(indent, indent_spaces: 2)
  "#{' ' * indent}$enum_to_a(#{enum_class.gen_adoc(0, indent_spaces:)})"
end

#to_hObject



1857
1858
1859
1860
1861
# File 'lib/idlc/ast.rb', line 1857

def to_h = {
  "kind" => "enum_to_array_cast",
  "enum_class_name" => enum_class.to_h,
  "source" => source_yaml
}

#to_idlObject



1854
# File 'lib/idlc/ast.rb', line 1854

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

#type(symtab) ⇒ Object



1840
1841
1842
1843
1844
1845
1846
1847
# File 'lib/idlc/ast.rb', line 1840

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, :known]),
    qualifiers: [:const]
  )
end

#type_check(symtab, strict:) ⇒ Object



1836
1837
1838
# File 'lib/idlc/ast.rb', line 1836

def type_check(symtab, strict:)
  enum_class.type_check(symtab, strict:)
end

#value(symtab) ⇒ Object



1849
1850
1851
# File 'lib/idlc/ast.rb', line 1849

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