Class: Idl::AryAccessSyntaxNode

Inherits:
Treetop::Runtime::SyntaxNode show all
Defined in:
lib/idl/ast.rb

Overview

this is not used as an AST node; we use it split chained array accesses

For example, it helps us represent

X[rs1][31:0]

Instance Method Summary collapse

Instance Method Details

#to_astAstNode

fix up left recursion

Returns:

  • (AstNode)

    New tree rooted at the array access



1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
# File 'lib/idl/ast.rb', line 1462

def to_ast
  var = a.to_ast
  brackets.elements.each do |bracket|
    var =
      if bracket.msb.empty?
        AryElementAccessAst.new(input, interval, var, bracket.lsb.to_ast)
      else
        AryRangeAccessAst.new(input, interval, var,
                              bracket.msb.expression.to_ast, bracket.lsb.to_ast)
      end
  end

  var
end

#to_idlString

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

Returns:

  • (String)

    IDL code for the node



1478
1479
1480
1481
1482
1483
1484
# File 'lib/idl/ast.rb', line 1478

def to_idl
  if bracket.msb.empty?
    "#{a.to_idl}[#{brackets.lsb.to_idl}]"
  else
    "#{a.to_idl}[#{brackets.msb.to_idl}:#{brackets.lsb.to_idl}]"
  end
end