Class: Idl::MultiVariableDeclarationAst

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

Overview

represents the declaration of multiple variables

for example:

Bits<64> a, b;
Bits<64> a, b, c, d;

Instance Method Summary collapse

Constructor Details

#initialize(input, interval, type_name, var_names) ⇒ MultiVariableDeclarationAst

Returns a new instance of MultiVariableDeclarationAst.



2178
2179
2180
2181
2182
# File 'lib/idl/ast.rb', line 2178

def initialize(input, interval, type_name, var_names)
  super(input, interval, [type_name] + var_names)

  @global = false
end

Instance Method Details

#add_symbol(symtab) ⇒ Object

Add symbol(s) at the outermost scope of the symbol table

Parameters:

  • symtab (SymbolTable)

    Symbol table at the scope that the symbol(s) will be inserted



2211
2212
2213
2214
2215
# File 'lib/idl/ast.rb', line 2211

def add_symbol(symtab)
  var_name_nodes.each do |vname|
    symtab.add(vname.text_value, Var.new(vname.text_value, type(symtab), type(symtab).default))
  end
end

#make_globalObject

mark this declaration as being in global scope



2185
2186
2187
# File 'lib/idl/ast.rb', line 2185

def make_global
  @global = true
end

#to_idlString

Return valid IDL representation of the node (and its subtree)

Returns:

  • (String)

    IDL code for the node



2218
# File 'lib/idl/ast.rb', line 2218

def to_idl = "#{type_name.to_idl} #{var_name_nodes.map(&:to_idl).join(', ')}"

#type(symtab) ⇒ Type

Given a specific symbol table, return the type of this node.

Should not be called until #type_check is called with the same arguments

Parameters:

Returns:

  • (Type)

    The type of the node

Raises:



2202
2203
2204
2205
2206
2207
2208
# File 'lib/idl/ast.rb', line 2202

def type(symtab)
  if @global
    type_name.type(symtab).clone.make_global
  else
    type_name.type(symtab)
  end
end

#type_check(symtab) ⇒ 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:



2195
2196
2197
2198
2199
# File 'lib/idl/ast.rb', line 2195

def type_check(symtab)
  type_name.type_check(symtab)

  add_symbol(symtab)
end

#type_nameAstNode

Returns Declared type.

Returns:



2173
# File 'lib/idl/ast.rb', line 2173

def type_name = @children[0]

#var_name_nodesArray<AstNode>

Returns Variable names.

Returns:

  • (Array<AstNode>)

    Variable names



2176
# File 'lib/idl/ast.rb', line 2176

def var_name_nodes = @children[1..]

#var_namesArray<String>

Returns Variables being declared.

Returns:

  • (Array<String>)

    Variables being declared



2190
2191
2192
# File 'lib/idl/ast.rb', line 2190

def var_names
  var_name_nodes.map(&:text_value)
end