Class: Idl::ArrayIncludesAst
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, ary, value) ⇒ ArrayIncludesAst
Returns a new instance of ArrayIncludesAst.
1519
1520
1521
|
# File 'lib/idlc/ast.rb', line 1519
def initialize(input, interval, ary, value)
super(input, interval, [ary, value])
end
|
Class Method Details
.from_h(yaml, source_mapper) ⇒ Object
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
|
# File 'lib/idlc/ast.rb', line 1561
def self.from_h(yaml, source_mapper)
raise "Bad YAML" unless yaml.key?("kind") && yaml.fetch("kind") == "array_includes_funcall"
input = input_from_source_yaml(yaml.fetch("source"), source_mapper)
interval = interval_from_source_yaml(yaml.fetch("source"))
ArrayIncludesAst.new(
input, interval,
T.cast(AstNode.from_h(yaml.fetch("array"), source_mapper), T.all(Rvalue, AstNode)),
T.cast(AstNode.from_h(yaml.fetch("expr"), source_mapper), T.all(Rvalue, AstNode))
)
end
|
Instance Method Details
#ary ⇒ Object
1513
|
# File 'lib/idlc/ast.rb', line 1513
def ary = T.cast(children[0], RvalueAst)
|
#const_eval?(symtab) ⇒ Boolean
1547
|
# File 'lib/idlc/ast.rb', line 1547
def const_eval?(symtab) = true
|
#expr ⇒ Object
1516
|
# File 'lib/idlc/ast.rb', line 1516
def expr = T.cast(children[1], RvalueAst)
|
#gen_adoc(indent = 0, indent_spaces: 2) ⇒ Object
307
308
309
|
# File 'lib/idlc/passes/gen_adoc.rb', line 307
def gen_adoc(indent = 0, indent_spaces: 2)
"#{' ' * indent}$array_includes?(#{ary.gen_adoc(0, indent_spaces:)}, #{expr.gen_adoc(0, indent_spaces:)})"
end
|
#to_h ⇒ Object
1553
1554
1555
1556
1557
1558
|
# File 'lib/idlc/ast.rb', line 1553
def to_h = {
"kind" => "array_includes_funcall",
"array" => ary.to_h,
"expr" => expr.to_h,
"source" => source_yaml
}
|
#to_idl ⇒ Object
1550
|
# File 'lib/idlc/ast.rb', line 1550
def to_idl = "$array_size(#{ary.to_idl}, #{expr.to_idl})"
|
#type(symtab) ⇒ Object
1537
1538
1539
|
# File 'lib/idlc/ast.rb', line 1537
def type(symtab)
BoolType
end
|
#type_check(symtab, strict:) ⇒ Object
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
|
# File 'lib/idlc/ast.rb', line 1524
def type_check(symtab, strict:)
ary.type_check(symtab, strict:)
ary_type = ary.type(symtab)
type_error "First argument of $array_includes? must be an array. Found #{ary_type}" unless ary_type.kind == :array
expr.type_check(symtab, strict:)
value_type = expr.type(symtab)
unless ary_type.width == 0 || value_type.comparable_to?(ary_type.sub_type)
type_error "Second argument of $array_includes? must be comparable to the array element type. Found #{ary_type.sub_type} and #{value_type}"
end
end
|
#value(symtab) ⇒ Object
1542
1543
1544
|
# File 'lib/idlc/ast.rb', line 1542
def value(symtab)
T.cast(ary.value(symtab), T::Array[T.untyped]).include?(expr.value(symtab))
end
|