Class: Idl::GlobalWithInitializationAst

Inherits:
AstNode
  • Object
show all
Includes:
Declaration, Executable
Defined in:
lib/idlc/ast.rb

Overview

global variable declared with an initializer,

e.g.,

Bits<65> UNDEFINED_LEGAL = 65’h10000000000000000; Bits<FLEN> f = [0, 0, 0, 0, 0, 0, 0, 0,

0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0];

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 Declaration

#declaration?

Methods included from Executable

#executable?

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, var_decl_with_init) ⇒ GlobalWithInitializationAst

Returns a new instance of GlobalWithInitializationAst.



1230
1231
1232
1233
# File 'lib/idlc/ast.rb', line 1230

def initialize(input, interval, var_decl_with_init)
  super(input, interval, [var_decl_with_init])
  var_decl_with_init.make_global
end

Class Method Details

.from_h(yaml, source_mapper) ⇒ Object



1275
1276
1277
1278
1279
1280
1281
1282
1283
# File 'lib/idlc/ast.rb', line 1275

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

  input = input_from_source_yaml(yaml.fetch("source"), source_mapper)
  interval = interval_from_source_yaml(yaml.fetch("source"))
  GlobalWithInitializationAst.new(
    input, interval, VariableDeclarationWithInitializationAst.from_h(yaml.fetch("decl"), source_mapper)
  )
end

Instance Method Details

#add_symbol(symtab) ⇒ Object



1254
1255
1256
1257
1258
1259
# File 'lib/idlc/ast.rb', line 1254

def add_symbol(symtab)
  raise "Symtab should be at global scope" unless symtab.levels == 1

  # globals never have a compile-time value
  var_decl_with_init.add_symbol(symtab)
end

#const_eval?(symtab) ⇒ Boolean

Returns:

  • (Boolean)


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

def const_eval?(symtab) = var_decl_with_init.lhs.const? && var_decl_with_init.rhs.const_eval?(symtab)

#execute(symtab) ⇒ Object



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

def execute(symtab) = var_decl_with_init.execute(symtab)

#idObject



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

def id = var_decl_with_init.id

#rhsObject



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

def rhs = var_decl_with_init.rhs

#to_hObject



1268
1269
1270
1271
1272
# File 'lib/idlc/ast.rb', line 1268

def to_h = {
  "kind" => "global_var_decl_with_init",
  "decl" => var_decl_with_init.to_h,
  "source" => source_yaml
}

#to_idlObject



1263
1264
1265
# File 'lib/idlc/ast.rb', line 1263

def to_idl
  var_decl_with_init.to_idl
end

#type(symtab) ⇒ Object



1241
1242
1243
# File 'lib/idlc/ast.rb', line 1241

def type(symtab)
  var_decl_with_init.lhs_type(symtab)
end

#type_check(symtab, strict:) ⇒ Object



1236
1237
1238
# File 'lib/idlc/ast.rb', line 1236

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

#value(symtab) ⇒ Object



1246
1247
1248
# File 'lib/idlc/ast.rb', line 1246

def value(symtab)
  var_decl_with_init.value(symtab)
end

#var_decl_with_initVariableDeclarationWithInitializationAst

Returns The initializer.

Returns:



1226
1227
1228
# File 'lib/idlc/ast.rb', line 1226

def var_decl_with_init
  @children[0]
end