Class: Idl::FetchAst

Inherits:
AstNode show all
Defined in:
lib/idlc/ast.rb,
lib/idlc/ast.rb

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 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_adoc, #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, body) ⇒ FetchAst

Returns a new instance of FetchAst.



8228
8229
8230
# File 'lib/idlc/ast.rb', line 8228

def initialize(input, interval, body)
  super(input, interval, [body])
end

Class Method Details

.from_h(yaml, source_mapper) ⇒ Object



8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
# File 'lib/idlc/ast.rb', line 8257

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

  input = input_from_source_yaml(yaml.fetch("source"), source_mapper)
  interval = interval_from_source_yaml(yaml.fetch("source"))
  FetchAst.new(
    input, interval,
    T.cast(AstNode.from_h(yaml.fetch("function_body"), source_mapper), FunctionBodyAst)
  )
end

Instance Method Details

#bodyObject



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

def body = @children[0]

#const_eval?(symtab) ⇒ Boolean

Returns:

  • (Boolean)


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

def const_eval?(symtab) = body.const_eval?(symtab)

#return_type(symtab) ⇒ Object



8236
8237
8238
# File 'lib/idlc/ast.rb', line 8236

def return_type(symtab)
  @ret_type = Type.new(:bits, width: symtab.get("INSTR_ENC_WIDTH").value)
end

#to_hObject



8250
8251
8252
8253
8254
# File 'lib/idlc/ast.rb', line 8250

def to_h = {
  "kind" => "fetch_decl",
  "function_body" => body.to_h,
  "source" => source_yaml
}

#to_idlObject



8241
8242
8243
8244
8245
8246
8247
# File 'lib/idlc/ast.rb', line 8241

def to_idl
  <<~IDL
    fetch {
      #{body.to_idl}
    }
  IDL
end

#type_check(symtab, strict:) ⇒ Object



8232
8233
8234
# File 'lib/idlc/ast.rb', line 8232

def type_check(symtab, strict:)
  body.type_check(symtab, strict:)
end