Class: Idl::EnumElementSizeAst
Overview
represents the builtin that returns the bitwidth of an element in an enum class
$enum_element_size(PrivilegeMode) #=> 3
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) ⇒ EnumElementSizeAst
Returns a new instance of EnumElementSizeAst.
1703
1704
1705
1706
|
# File 'lib/idlc/ast.rb', line 1703
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
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
|
# File 'lib/idlc/ast.rb', line 1731
def self.from_h(yaml, source_mapper)
raise "Bad YAML" unless yaml.key?("kind") && yaml.fetch("kind") == "enum_element_size_funcall"
input = input_from_source_yaml(yaml.fetch("source"), source_mapper)
interval = interval_from_source_yaml(yaml.fetch("source"))
EnumElementSizeAst.new(
input, interval,
T.cast(AstNode.from_h(yaml.fetch("enum_class_name"), source_mapper), UserTypeNameAst)
)
end
|
Instance Method Details
#const_eval?(symtab) ⇒ Boolean
1700
|
# File 'lib/idlc/ast.rb', line 1700
def const_eval?(symtab) = true
|
#enum_class ⇒ Object
1697
|
# File 'lib/idlc/ast.rb', line 1697
def enum_class = children[0]
|
#gen_adoc(indent, indent_spaces: 2) ⇒ Object
132
133
134
|
# File 'lib/idlc/passes/gen_adoc.rb', line 132
def gen_adoc(indent, indent_spaces: 2)
"#{' ' * indent}$enum_element_size(#{enum_class.gen_adoc(0, indent_spaces:)})"
end
|
#to_h ⇒ Object
1724
1725
1726
1727
1728
|
# File 'lib/idlc/ast.rb', line 1724
def to_h = {
"kind" => "enum_element_size_funcall",
"enum_class_name" => enum_class.to_h,
"source" => source_yaml
}
|
#to_idl ⇒ Object
1721
|
# File 'lib/idlc/ast.rb', line 1721
def to_idl = "$enum_element_size(#{enum_class.to_idl})"
|
#type(symtab) ⇒ Object
1712
1713
1714
|
# File 'lib/idlc/ast.rb', line 1712
def type(symtab)
Type.new(:bits, width: enum_class.type(symtab).width, qualifiers: [:const, :known])
end
|
#type_check(symtab, strict:) ⇒ Object
1708
1709
1710
|
# File 'lib/idlc/ast.rb', line 1708
def type_check(symtab, strict:)
enum_class.type_check(symtab, strict:)
end
|
#value(symtab) ⇒ Object
1716
1717
1718
|
# File 'lib/idlc/ast.rb', line 1716
def value(symtab)
enum_class.type(symtab).width
end
|