Class: Idl::MultiVariableDeclarationAst
- 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
-
#add_symbol(symtab) ⇒ Object
Add symbol(s) at the outermost scope of the symbol table.
-
#initialize(input, interval, type_name, var_names) ⇒ MultiVariableDeclarationAst
constructor
A new instance of MultiVariableDeclarationAst.
-
#make_global ⇒ Object
mark this declaration as being in global scope.
-
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree).
-
#type(symtab) ⇒ Type
Given a specific symbol table, return the type of this node.
-
#type_check(symtab) ⇒ void
type check this node and all children.
-
#type_name ⇒ AstNode
Declared type.
-
#var_name_nodes ⇒ Array<AstNode>
Variable names.
-
#var_names ⇒ Array<String>
Variables being declared.
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
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_global ⇒ Object
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_idl ⇒ String
Return valid IDL representation of the node (and its subtree)
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
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
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_name ⇒ AstNode
Returns Declared type.
2173 |
# File 'lib/idl/ast.rb', line 2173 def type_name = @children[0] |
#var_name_nodes ⇒ Array<AstNode>
Returns Variable names.
2176 |
# File 'lib/idl/ast.rb', line 2176 def var_name_nodes = @children[1..] |
#var_names ⇒ Array<String>
Returns Variables being declared.
2190 2191 2192 |
# File 'lib/idl/ast.rb', line 2190 def var_names var_name_nodes.map(&:text_value) end |