Class: Idl::ArraySizeAst
Constant Summary
Constants inherited
from AstNode
Idl::AstNode::Bits1Type, Idl::AstNode::Bits32Type, Idl::AstNode::Bits64Type, Idl::AstNode::BoolType, Idl::AstNode::ConstBoolType, Idl::AstNode::PossiblyUnknownBits1Type, Idl::AstNode::PossiblyUnknownBits32Type, Idl::AstNode::PossiblyUnknownBits64Type, Idl::AstNode::ReachableFunctionCacheType, Idl::AstNode::StringType, Idl::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, expression) ⇒ ArraySizeAst
Returns a new instance of ArraySizeAst.
1583
1584
1585
|
# File 'lib/idlc/ast.rb', line 1583
def initialize(input, interval, expression)
super(input, interval, [expression])
end
|
Class Method Details
.from_h(yaml, source_mapper) ⇒ Object
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
|
# File 'lib/idlc/ast.rb', line 1622
def self.from_h(yaml, source_mapper)
raise "Bad YAML" unless yaml.key?("kind") && yaml.fetch("kind") == "array_size_funcall"
input = input_from_source_yaml(yaml.fetch("source"), source_mapper)
interval = interval_from_source_yaml(yaml.fetch("source"))
ArraySizeAst.new(
input, interval,
T.cast(AstNode.from_h(yaml.fetch("array"), source_mapper), T.all(Rvalue, AstNode))
)
end
|
Instance Method Details
#const_eval?(symtab) ⇒ Boolean
1581
|
# File 'lib/idlc/ast.rb', line 1581
def const_eval?(symtab) = true
|
Returns Array expression.
1578
|
# File 'lib/idlc/ast.rb', line 1578
def expression = children[0]
|
#gen_adoc(indent = 0, indent_spaces: 2) ⇒ Object
301
302
303
|
# File 'lib/idlc/passes/gen_adoc.rb', line 301
def gen_adoc(indent = 0, indent_spaces: 2)
"#{' ' * indent}$array_size(#{expression.gen_adoc(0, indent_spaces:)})"
end
|
#to_h ⇒ Object
1615
1616
1617
1618
1619
|
# File 'lib/idlc/ast.rb', line 1615
def to_h = {
"kind" => "array_size_funcall",
"array" => expression.to_h,
"source" => source_yaml
}
|
#to_idl ⇒ Object
1612
|
# File 'lib/idlc/ast.rb', line 1612
def to_idl = "$array_size(#{expression.to_idl})"
|
#type(symtab) ⇒ Object
1594
1595
1596
1597
1598
1599
1600
1601
1602
|
# File 'lib/idlc/ast.rb', line 1594
def type(symtab)
if expression.type(symtab).width == :unknown
Type.new(:bits, width: :unknown, qualifiers: [:const, :known])
else
len = expression.type(symtab).width.bit_length
len = len.zero? ? 1 : len
Type.new(:bits, width: len, qualifiers: [:const, :known])
end
end
|
#type_check(symtab, strict:) ⇒ Object
1587
1588
1589
1590
1591
1592
|
# File 'lib/idlc/ast.rb', line 1587
def type_check(symtab, strict:)
expression.type_check(symtab, strict:)
expression_type = expression.type(symtab)
type_error "#{expression.text_value} is not an array" unless expression_type.kind == :array
type_error "#{expression.text_value} must be a constant" unless expression_type.const?
end
|
#value(symtab) ⇒ Object
1605
1606
1607
1608
1609
|
# File 'lib/idlc/ast.rb', line 1605
def value(symtab)
w = expression.type(symtab).width
value_error "Width of the array is unknown" if w == :unknown
T.cast(w, Integer)
end
|