xrel.parser
Class SymElement

java.lang.Object
  |
  +--xrel.parser.SymElement

public class SymElement
extends java.lang.Object

This class is a symbol table element. A symbol table element can be a type name, a pattern, a variable or an expression (expressions are the parameters of printf statements).

Author:
Fabrizio Bisi

Constructor Summary
SymElement(SymTable st, int scope, java.lang.String nm, int k, SimpleNode nd)
          This is the only constructor you can use to initialize an object of the symbol table.
 
Method Summary
 java.lang.String getAutomatonName()
           
 int getCode()
          Returns the code for the element.
 TASimple getElementAutomaton(int BuildPhases, boolean debug)
          Gets the internal automaton associated to the element and if it doesn't exist it creates it.
 TA getInferredType()
           
 int getKind()
          Gets the kind of the element.
 java.lang.String getName()
          Gets the name of the element.
 SimpleNode getNode()
          Gets the subtree of the syntax tree associated to the element.
 int getScope()
          Gets the scope of the element.
 java.lang.String getScopeStr()
          Gets the name of the scope, that is "document" for the import statement and "case n" for the n-th clause in the typeswitch instruction.
 java.lang.String getUniqueName()
          For variables returns the name with a unique identifier.
 SimpleNode getValue()
          Gets the value associated to this variable after a binding.
 boolean hasAutomaton()
           
 void setInferredType(TA aut)
           
 void setNode(SimpleNode n)
          Sets the subtree associated to the element.
 void setValue(SimpleNode v)
          Sets the value associated to this variable as a result of a binding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SymElement

public SymElement(SymTable st,
                  int scope,
                  java.lang.String nm,
                  int k,
                  SimpleNode nd)
This is the only constructor you can use to initialize an object of the symbol table. Usually the symbol elements are built from the parser when it builds the symbol table, however there are a few functions that manipulate the expression trees and that use this constructor. Name is always computed for expressions so that the given name is ignored, therefore it's possible to pass a null pointer. For patterns if the caller gives a null name the name is computed, otherwise is used the given name. The name of types and variables is always specified by the caller and it can't be null.
Parameters:
st - the symbol table
scope - the integer representing the scope of the element
nm - the name of the element
k - the kind of the element (type, variable, pattern, expression)
nd - the root of the subtree associated to the element
Method Detail

getName

public java.lang.String getName()
Gets the name of the element.
Returns:
the name

getCode

public int getCode()

Returns the code for the element.

It's an incremental number for patterns and variables.

Returns:
the unique identifier code for the element

getUniqueName

public java.lang.String getUniqueName()
For variables returns the name with a unique identifier. For other elements is the same as getName();
Returns:
the unique name of the element

getNode

public SimpleNode getNode()
Gets the subtree of the syntax tree associated to the element.
Returns:
the root node of the subtree

setNode

public void setNode(SimpleNode n)
Sets the subtree associated to the element.
Parameters:
n - the new root node for the variable

getValue

public SimpleNode getValue()
Gets the value associated to this variable after a binding.
Returns:
the root node of the value or null

setValue

public void setValue(SimpleNode v)
Sets the value associated to this variable as a result of a binding.
Returns:
the root node of the value or null

getKind

public int getKind()
Gets the kind of the element. It can be VARIABLE, TYPE, PATTERN or EXPRESSION.
Returns:
an integer that represents the kind of the element

getScope

public int getScope()
Gets the scope of the element. The scope of an element is the piece of the code where you can use the element and in this simple language is represented by an integer: always 0 (global) for types, for variables is the number of the "case" (from 1) where they're defined (0 if they're defined in the import statement). The scope value of a pattern and of an expression identifies the pattern or the expression itself and it has the same numeration conventions as variables (therefore the expression with scope 0 doesn't exist as the first clause has scope 1).
Returns:
an integer that represents the scope of a variable or 0 for a type or an identifier for a pattern or an expression

getScopeStr

public java.lang.String getScopeStr()
Gets the name of the scope, that is "document" for the import statement and "case n" for the n-th clause in the typeswitch instruction.
Returns:
the name of the scope

getInferredType

public TA getInferredType()

setInferredType

public void setInferredType(TA aut)

getAutomatonName

public java.lang.String getAutomatonName()

hasAutomaton

public boolean hasAutomaton()

getElementAutomaton

public TASimple getElementAutomaton(int BuildPhases,
                                    boolean debug)
Gets the internal automaton associated to the element and if it doesn't exist it creates it. If this method is invoked on a symbol table element that can't have an automaton it returns null.
Returns:
the automaton of a symbol table element or null