Class: Idl::EnumRefAst
- Inherits:
-
AstNode
show all
- Includes:
- Rvalue
- Defined in:
- lib/idlc/ast.rb,
lib/idlc/passes/prune.rb,
lib/idlc/passes/gen_adoc.rb,
lib/idlc/passes/gen_option_adoc.rb
Overview
represents an enum reference
for example:
ExtensionName::C
PrivilegeMode::M
Defined Under Namespace
Classes: Memo
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, #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, #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, class_name, member_name) ⇒ EnumRefAst
Returns a new instance of EnumRefAst.
6122
6123
6124
6125
6126
6127
6128
|
# File 'lib/idlc/ast.rb', line 6122
def initialize(input, interval, class_name, member_name)
super(input, interval, EMPTY_ARRAY)
@enum_class_name = class_name
@member_name = member_name
@memo = Memo.new
end
|
Class Method Details
.from_h(yaml, source_mapper) ⇒ Object
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
|
# File 'lib/idlc/ast.rb', line 6174
def self.from_h(yaml, source_mapper)
raise "Bad YAML" unless yaml.key?("kind") && yaml.fetch("kind") == "enum_reference_expr"
input = input_from_source_yaml(yaml.fetch("source"), source_mapper)
interval = interval_from_source_yaml(yaml.fetch("source"))
EnumRefAst.new(
input, interval,
yaml.fetch("enum_class"),
yaml.fetch("member_name"),
)
end
|
Instance Method Details
#class_name ⇒ Object
6119
|
# File 'lib/idlc/ast.rb', line 6119
def class_name = @enum_class_name
|
#const_eval?(symtab) ⇒ Boolean
6117
|
# File 'lib/idlc/ast.rb', line 6117
def const_eval?(symtab) = true
|
#enum_def_type(symtab) ⇒ Object
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
|
# File 'lib/idlc/ast.rb', line 6130
def enum_def_type(symtab)
@memo.enum_def_type[symtab.name] ||=
begin
t = symtab.get(@enum_class_name)
if t.nil? || t.kind != :enum
type_error "#{@enum_class_name} is not a defined Enum"
end
t
end
end
|
#gen_adoc(indent, indent_spaces: 2) ⇒ Object
122
123
124
|
# File 'lib/idlc/passes/gen_adoc.rb', line 122
def gen_adoc(indent, indent_spaces: 2)
"#{' ' * indent}#{class_name}::#{member_name}"
end
|
#gen_option_adoc ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/idlc/passes/gen_option_adoc.rb', line 148
def gen_option_adoc
if class_name == "CsrFieldType"
case member_name
when "RW", "RO"
member_name
when "ROH"
"RO-H"
when "RWR"
"RW-R"
when "RWH"
"RW-H"
when "RWRH"
"RW-RH"
else
raise "unexpected"
end
else
raise "Unexpected"
end
end
|
#member_name ⇒ Object
6120
|
# File 'lib/idlc/ast.rb', line 6120
def member_name = @member_name
|
#prune(symtab, forced_type: nil) ⇒ Object
857
858
859
860
861
862
863
864
865
|
# File 'lib/idlc/passes/prune.rb', line 857
def prune(symtab, forced_type: nil)
value_result = value_try do
v = value(symtab)
return PruneHelpers.create_literal(symtab, v, type(symtab), forced_type: forced_type || type(symtab))
end
value_else(value_result) do
dup
end
end
|
#to_h ⇒ Object
6166
6167
6168
6169
6170
6171
|
# File 'lib/idlc/ast.rb', line 6166
def to_h = {
"kind" => "enum_reference_expr",
"enum_class" => @enum_class_name,
"member_name" => @member_name,
"source" => source_yaml
}
|
#to_idl ⇒ Object
6163
|
# File 'lib/idlc/ast.rb', line 6163
def to_idl = "#{@enum_class_name}::#{@member_name}"
|
#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
6150
6151
6152
6153
6154
|
# File 'lib/idlc/ast.rb', line 6150
def type(symtab)
type_error "No enum named #{@enum_class_name}" if enum_def_type(symtab).nil?
enum_def_type(symtab).ref_type
end
|
#type_check(symtab, strict:) ⇒ void
This method returns an undefined value.
type check this node and all children
Calls to #type and/or #value may depend on type_check being called first with the same symtab. If not, those functions may raise an AstNode::InternalError
6142
6143
6144
6145
6146
6147
|
# File 'lib/idlc/ast.rb', line 6142
def type_check(symtab, strict:)
type_error "No symbol #{@enum_class_name} has been defined" if enum_def_type(symtab).nil?
type_error "#{@enum_class_name} is not an enum type" unless enum_def_type(symtab).is_a?(EnumerationType)
type_error "#{@enum_class_name} has no member '#{@member_name}'" if enum_def_type(symtab).value(@member_name).nil?
end
|
#value(symtab) ⇒ Object
6157
6158
6159
|
# File 'lib/idlc/ast.rb', line 6157
def value(symtab)
enum_def_type(symtab).value(@member_name)
end
|