Class: Idl::EnumSizeAst
Overview
represents the builtin that returns the nymber of elements in an enum class
$enum_size(XRegWidth) #=> 2
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) ⇒ EnumSizeAst
Returns a new instance of EnumSizeAst.
1647
1648
1649
1650
|
# File 'lib/idlc/ast.rb', line 1647
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
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
|
# File 'lib/idlc/ast.rb', line 1679
def self.from_h(yaml, source_mapper)
raise "Bad YAML" unless yaml.key?("kind") && yaml.fetch("kind") == "enum_size_funcall"
input = input_from_source_yaml(yaml.fetch("source"), source_mapper)
interval = interval_from_source_yaml(yaml.fetch("source"))
EnumSizeAst.new(
input, interval,
T.cast(AstNode.from_h(yaml.fetch("enum_class_name"), source_mapper), UserTypeNameAst)
)
end
|
Instance Method Details
#const_eval?(symtab) ⇒ Boolean
1644
|
# File 'lib/idlc/ast.rb', line 1644
def const_eval?(symtab) = true
|
#enum_class ⇒ Object
1641
|
# File 'lib/idlc/ast.rb', line 1641
def enum_class = children.fetch(0)
|
#gen_adoc(indent, indent_spaces: 2) ⇒ Object
127
128
129
|
# File 'lib/idlc/passes/gen_adoc.rb', line 127
def gen_adoc(indent, indent_spaces: 2)
"#{' ' * indent}$enum_size(#{enum_class.gen_adoc(0, indent_spaces:)})"
end
|
#to_h ⇒ Object
1672
1673
1674
1675
1676
|
# File 'lib/idlc/ast.rb', line 1672
def to_h = {
"kind" => "enum_size_funcall",
"enum_class_name" => enum_class.to_h,
"source" => source_yaml
}
|
#to_idl ⇒ Object
1669
|
# File 'lib/idlc/ast.rb', line 1669
def to_idl = "$enum_size(#{enum_class.to_idl})"
|
#type(symtab) ⇒ Object
1656
1657
1658
1659
1660
1661
1662
|
# File 'lib/idlc/ast.rb', line 1656
def type(symtab)
Type.new(
:bits,
width: enum_class.type(symtab).element_names.size.bit_length,
qualifiers: [:const, :known]
)
end
|
#type_check(symtab, strict:) ⇒ Object
1652
1653
1654
|
# File 'lib/idlc/ast.rb', line 1652
def type_check(symtab, strict:)
enum_class.type_check(symtab, strict:)
end
|
#value(symtab) ⇒ Object
1664
1665
1666
|
# File 'lib/idlc/ast.rb', line 1664
def value(symtab)
enum_class.type(symtab).element_names.size
end
|