Class: Idl::BuiltinEnumDefinitionAst

Inherits:
AstNode
  • Object
show all
Includes:
Declaration
Defined in:
lib/idlc/ast.rb

Overview

represents a builtin (auto-generated from config) enum definition

# this will result in a BuiltinEnumDefinitionAst
generated enum ExtensionName

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 Declaration

#declaration?

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_adoc, #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, user_type) ⇒ BuiltinEnumDefinitionAst

Returns a new instance of BuiltinEnumDefinitionAst.



2055
2056
2057
2058
# File 'lib/idlc/ast.rb', line 2055

def initialize(input, interval, user_type)
  super(input, interval, [user_type])
  @user_type = user_type
end

Class Method Details

.from_h(yaml, source_mapper) ⇒ Object



2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
# File 'lib/idlc/ast.rb', line 2101

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

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

Instance Method Details

#add_symbol(symtab) ⇒ Object

Add symbol(s) at the outermost scope of the symbol table

Parameters:

  • symtab (SymbolTable)

    Symbol table at the scope that the symbol(s) will be inserted



2082
2083
2084
# File 'lib/idlc/ast.rb', line 2082

def add_symbol(symtab)
  # doesn't actually do anything since the type has already been added to the symbol table
end

#const_eval?(symtab) ⇒ Boolean

Returns:

  • (Boolean)


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

def const_eval?(symtab) = true

#element_names(symtab) ⇒ Object



2068
2069
2070
# File 'lib/idlc/ast.rb', line 2068

def element_names(symtab)
  type(symtab).element_names
end

#element_values(symtab) ⇒ Object



2072
2073
2074
# File 'lib/idlc/ast.rb', line 2072

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

#nameString

Returns name of the enum class.

Returns:

  • (String)

    name of the enum class



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

def name = @user_type.text_value

#to_hObject



2094
2095
2096
2097
2098
# File 'lib/idlc/ast.rb', line 2094

def to_h = {
  "kind" => "builtin_enum_decl",
  "name" => @user_type.to_h,
  "source" => source_yaml
}

#to_idlObject



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

def to_idl = "generated enum #{@user_type.text_value}"

#type(symtab) ⇒ Type

Given a specific symbol table, return the type of this node.

Should not be called until #type_check is called with the same arguments

Parameters:

Returns:

  • (Type)

    The type of the node

Raises:



2077
2078
2079
# File 'lib/idlc/ast.rb', line 2077

def type(symtab)
  symtab.get(@user_type.text_value)
end

#type_check(symtab, strict:) ⇒ Object



2061
2062
2063
2064
2065
2066
# File 'lib/idlc/ast.rb', line 2061

def type_check(symtab, strict:)
  sym = symtab.get(@user_type.text_value)
  type_error "Builtin enum #{@user_type.text_value} is not defined" if sym.nil?
  type_error "#{@user_type.text_value} is not an enum" unless sym.is_a?(EnumerationType)
  type_error "#{@user_type.text_value} is not a builtin enum" unless sym.builtin?
end