Class: Idl::ArrayLiteralAst

Inherits:
AstNode
  • Object
show all
Includes:
Rvalue
Defined in:
lib/idlc/ast.rb,
lib/idlc/passes/gen_adoc.rb

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, #initialize, #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

This class inherits a constructor from Idl::AstNode

Class Method Details

.from_h(yaml, source_mapper) ⇒ Object



5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
# File 'lib/idlc/ast.rb', line 5453

def self.from_h(yaml, source_mapper)
  raise "Bad YAML" unless yaml.key?("kind") && yaml.fetch("kind") == "array_literal"

  input = input_from_source_yaml(yaml.fetch("source"), source_mapper)
  interval = interval_from_source_yaml(yaml.fetch("source"))
  ArrayLiteralAst.new(
    input, interval,
    yaml.fetch("values").map { |v| AstNode.from_h(v, source_mapper) }
  )
end

Instance Method Details

#const_eval?(symtab) ⇒ Boolean

Returns:

  • (Boolean)


5411
# File 'lib/idlc/ast.rb', line 5411

def const_eval?(symtab) = element_nodes.all? { |enode| enode.const_eval?(symtab) }

#element_nodesObject



5415
5416
5417
# File 'lib/idlc/ast.rb', line 5415

def element_nodes
  entries
end

#entriesObject



5413
# File 'lib/idlc/ast.rb', line 5413

def entries = @children

#gen_adoc(indent = 0, indent_spaces: 2) ⇒ Object



25
26
27
# File 'lib/idlc/passes/gen_adoc.rb', line 25

def gen_adoc(indent = 0, indent_spaces: 2)
  "#{' ' * indent}[#{entries.map{ |e| e.gen_adoc(0) }.join(", ")}]"
end

#to_hObject



5446
5447
5448
5449
5450
# File 'lib/idlc/ast.rb', line 5446

def to_h = {
  "kind" => "array_literal",
  "values" => element_nodes.map(&:to_h),
  "source" => source_yaml
}

#to_idlObject



5443
# File 'lib/idlc/ast.rb', line 5443

def to_idl = "[#{element_nodes.map(&:to_idl).join(',')}]"

#type(symtab) ⇒ Object



5430
5431
5432
5433
5434
5435
5436
# File 'lib/idlc/ast.rb', line 5430

def type(symtab)
  if element_nodes.size > 0
    Type.new(:array, width: element_nodes.size, sub_type: element_nodes.fetch(0).type(symtab))
  else
    Type.new(:array, width: element_nodes.size, sub_type: nil)
  end
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

Parameters:

Raises:



5420
5421
5422
5423
5424
5425
5426
5427
5428
# File 'lib/idlc/ast.rb', line 5420

def type_check(symtab, strict:)
  entries.each do |node|
    node.type_check(symtab, strict:)
  end

  unless element_nodes.all? { |e| e.type(symtab).equal_to?(element_nodes.fetch(0).type(symtab)) }
    type_error "Array elements must be identical"
  end
end

#value(symtab) ⇒ Object



5438
5439
5440
# File 'lib/idlc/ast.rb', line 5438

def value(symtab)
  element_nodes.map { |e| e.value(symtab) }
end