public final class SymbolTools
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static void |
addSymbols(SymbolTable table,
Declaration decl)
Adds symbols to a symbol table and checks for duplicates.
|
static boolean |
containsSpecifier(Symbol symbol,
Specifier spec)
Checks if the specified symbol object contains the given specifier.
|
static java.util.List<Symbol> |
exprsToSymbols(java.util.List<Expression> exprs)
Returns a list of symbols by taking symbol object out of the expressions
in the given list.
|
static Declaration |
findSymbol(SymbolTable table,
IDExpression name)
Searches for a symbol by name in the table.
|
static Declaration |
findSymbol(SymbolTable table,
java.lang.String sname)
Searches for a symbol by String sname in the table.
|
static java.util.Set<Symbol> |
getAccessedSymbols(Traversable t)
Returns the set of symbols accessed in the traversable object.
|
static Identifier |
getArrayTemp(Traversable where,
java.util.List specs,
ArraySpecifier aspec,
java.lang.String name)
Returns a new identifier derived from the given IR object, type list,
array specifier and name.
|
static Identifier |
getArrayTemp(Traversable where,
java.util.List specs,
java.util.List aspecs,
java.lang.String name)
Returns a new identifier derived from the given IR object, type list,
array specifiers and name.
|
static ClassDeclaration |
getClassDeclaration(Symbol symbol,
Traversable tr)
Returns the user-defined class declaration for the given symbol.
|
static java.util.List<Specifier> |
getExactExpressionType(Expression e)
Returns the exact type of the given expression, tracking all specifiers
relevant to the expression.
|
static java.util.List |
getExpressionType(Expression e)
Returns a list of specifiers of the given expression.
|
static java.util.Set<Symbol> |
getGlobalSymbols(Traversable t)
Returns the set of Symbol objects that are global variables
of the File scope
|
static java.util.Set<Symbol> |
getLocalSymbols(Traversable t)
Returns the set of symbols declared within the specified traversable
object.
|
static java.util.List |
getNativeSpecifiers(Traversable t,
Symbol symbol)
Returns C-native specifiers for the given symbol.
|
static NameID |
getNewName(java.lang.String name,
Traversable tr)
Returns a new name id with the given name suggestion and scope.
|
static Identifier |
getOrphanID(java.lang.String name)
Returns an incomplete Identifier whose relevant symbol is not defined.
|
static java.util.Set<Symbol> |
getParameterSymbols(Procedure proc)
Returns the set of Symbol objects that are formal parameters of
the given Procedure
|
static Identifier |
getPointerTemp(Traversable where,
Identifier refID)
Returns a new, pointer-type identifier derived from the given IR object.
|
static Identifier |
getPointerTemp(Traversable where,
java.util.List specs,
java.util.List pspecs,
java.lang.String name)
Returns a new, pointer-type identifier derived from the given IR object.
|
static Identifier |
getPointerTemp(Traversable where,
java.util.List specs,
java.lang.String name)
Returns a new, pointer-type identifier derived from the given IR object.
|
static java.util.Set<Symbol> |
getSideEffectSymbols(FunctionCall fc) |
static Symbol |
getSymbolOf(Expression e)
Returns the symbol of the expression if it represents an lvalue.
|
static Symbol |
getSymbolOfName(java.lang.String name,
Traversable tr)
Returns the symbol object having the specified string name.
|
static java.util.Set<Symbol> |
getSymbols(SymbolTable st)
Returns the set of Symbol objects contained in the given SymbolTable
object.
|
static Identifier |
getTemp(Identifier id)
Returns a new identifier derived from the given identifier.
|
static Identifier |
getTemp(Identifier id,
java.lang.String name)
Returns a new identifier derived from the given identifier and name.
|
static Identifier |
getTemp(Traversable where,
Identifier id)
Returns a new identifier derived from the given IR object and identifier.
|
static Identifier |
getTemp(Traversable where,
java.util.List specs,
java.lang.String name)
Returns a new identifier derived from the given IR object, type list, and
name.
|
static Identifier |
getTemp(Traversable where,
Specifier spec,
java.lang.String name)
Returns a new identifier derived from the given IR object, type, and name.
|
static IDExpression |
getUnusedID(SymbolTable table)
Returns a randomly-generated name that is not found in the table.
|
static java.util.Set<Symbol> |
getVariableSymbols(SymbolTable st)
Returns the set of Symbol objects contained in the given SymbolTable
object excluding Procedures.
|
static java.util.LinkedList |
getVariableType(Expression e)
Returns a list of specifiers of the expression.
|
static boolean |
isArray(Symbol symbol)
Checks if the symbol is an array variable.
|
static boolean |
isFormal(Symbol symbol)
Checks if the given symbol is declared as a formal variable.
|
static boolean |
isFormal(Symbol symbol,
Procedure proc)
Checks if the given symbol is declared as a formal variable.
|
static boolean |
isGlobal(Symbol symbol)
Checks if the given symbol is declared as a global variable.
|
static boolean |
isGlobal(Symbol symbol,
Traversable t)
Checks if the symbol is a global variable to the procedure containing the
given traversable object.
|
static boolean |
isInteger(java.util.List specifiers) |
static boolean |
isInteger(Symbol symbol)
Checks if the symbol is an interger type variable.
|
static boolean |
isLocal(Symbol symbol)
Checks if the given symbol is declared as a local variable.
|
static boolean |
isOrphan(Symbol symbol)
Checks if the given symbol does not belong to the IR tree.
|
static boolean |
isPointer(Expression e)
Checks if the symbol is a pointer type variable.
|
static boolean |
isPointer(Symbol symbol)
Checks if the symbol is a pointer type variable.
|
static boolean |
isPointerParameter(Symbol param)
Checks if the given symbol is a parameter and a pointer-compatible symbol.
|
static boolean |
isScalar(Symbol symbol)
Checks if the symbol is a scalar variable.
|
static boolean |
isStruct(Symbol symbol,
Traversable tr)
Checks if the given symbol is a user-defined struct type.
|
static void |
linkSymbol(Traversable t)
Makes links from all
IDExpression objects in the program to
their corresponding declarators while generating warnings if there is
any undeclared variables or functions. |
static void |
setSymbolName(Symbol symbol,
java.lang.String name,
SymbolTable symtab)
Renames the specified symbol within the given symbol table object.
|
public static void linkSymbol(Traversable t)
IDExpression objects in the program to
their corresponding declarators while generating warnings if there is
any undeclared variables or functions. This method is called with the
whole program, before any Cetus passes by default and provides a short cut
to the declaration point, which enables faster access to the declaration
when necessary. Pass writers can call this routine after changing a
certain part of the program, e.g., a specific program section within a
scope, to reflect the change due to new insertion of declaration.t - the input cetus IR.public static boolean isGlobal(Symbol symbol)
symbol - the symbol of the variable.public static boolean isLocal(Symbol symbol)
symbol - the symbol of the variable.public static boolean isOrphan(Symbol symbol)
symbol - the symbol of the variable.public static boolean isFormal(Symbol symbol, Procedure proc)
symbol - the symbol of the variable.public static boolean isFormal(Symbol symbol)
symbol - the symbol to be checked.public static java.util.List<Symbol> exprsToSymbols(java.util.List<Expression> exprs)
exprs - the list of requested expressions.public static boolean isPointerParameter(Symbol param)
param - the parameter symbol to be checked.param is pointer-compatible.public static java.util.List getNativeSpecifiers(Traversable t, Symbol symbol)
t - the traversable object where search starts from.symbol - the symbol object of interest.public static boolean isStruct(Symbol symbol, Traversable tr)
symbol - the symbol object to be checked.tr - the traversable object to be searched.public static ClassDeclaration getClassDeclaration(Symbol symbol, Traversable tr)
symbol - the symbol object to be checked.tr - the traversable object to be searched.public static Identifier getOrphanID(java.lang.String name)
public static void addSymbols(SymbolTable table, Declaration decl)
table - The symbol table to add the symbols to.decl - The declaration of the symbols.
symbols in the table.public static Declaration findSymbol(SymbolTable table, IDExpression name)
table - The initial table to search.name - The name of the symbol to locate.public static IDExpression getUnusedID(SymbolTable table)
table - The table to search.public static Identifier getTemp(Identifier id)
getTemp(Identifier, String).id - the identifier from which type and scope are derived.public static Identifier getTemp(Traversable where, Identifier id)
getTemp(Traversable, List, String).where - the IR object from which scope is derived.id - the identifier from which type is derived.public static Identifier getTemp(Identifier id, java.lang.String name)
getTemp(Traversable, List, String).id - the identifier from which scope is derived.name - the string from which name is derived.public static Identifier getTemp(Traversable where, Specifier spec, java.lang.String name)
getTemp(Traversable, List, String).where - the IR object from which scope is derived.spec - the type specifier.name - the string from which name is derived.public static Identifier getTemp(Traversable where, java.util.List specs, java.lang.String name)
getArrayTemp(Traversable, List, List, String).where - the IR object from which scope is derived.specs - the type specifiers.name - the string from which name is derived.public static Identifier getArrayTemp(Traversable where, java.util.List specs, ArraySpecifier aspec, java.lang.String name)
getArrayTemp(Traversable, List, List, String).where - the IR object from which scope is derived.specs - the type specifiers.aspec - the array specifier.name - the string from which name is derived.public static Identifier getArrayTemp(Traversable where, java.util.List specs, java.util.List aspecs, java.lang.String name)
specs contains any pointer
specifiers, they are automatically separated and inserted into the list
of specifiers that belong to the new VariableDeclarator object.where - the IR object from which scope is derived.specs - the type specifiers.aspecs - the array specifier.name - the string from which name is derived.public static Identifier getPointerTemp(Traversable where, Identifier refID)
where - the IR object from which scope is derived.refID - the identifier from which type and name are derived.public static Identifier getPointerTemp(Traversable where, java.util.List specs, java.lang.String name)
where - the IR object from which scope is derived.specs - the type specifiers.name - the string from which name is derived.public static Identifier getPointerTemp(Traversable where, java.util.List specs, java.util.List pspecs, java.lang.String name)
where - the IR object from which scope is derived.specs - the type specifiers.pspecs - the pointer-type specifiers.name - the string from which name is derived.public static NameID getNewName(java.lang.String name, Traversable tr)
name - the name suggestion given by user.tr - the traversable object which scope is derived from.public static java.util.Set<Symbol> getSymbols(SymbolTable st)
st - the symbol table being searched.public static java.util.Set<Symbol> getVariableSymbols(SymbolTable st)
st - the symbol table being searched.public static java.util.Set<Symbol> getGlobalSymbols(Traversable t)
public static java.util.Set<Symbol> getParameterSymbols(Procedure proc)
public static java.util.Set<Symbol> getSideEffectSymbols(FunctionCall fc)
public static java.util.Set<Symbol> getAccessedSymbols(Traversable t)
t - the traversable object.public static java.util.Set<Symbol> getLocalSymbols(Traversable t)
t - the traversable object.public static Symbol getSymbolOfName(java.lang.String name, Traversable tr)
name - the name to be searched for.tr - the IR location where searching starts.public static Symbol getSymbolOf(Expression e)
e - the input expression.public static boolean isGlobal(Symbol symbol, Traversable t)
symbol - The symbol objectt - The traversable objectpublic static boolean isScalar(Symbol symbol)
symbol - The symbolpublic static boolean isArray(Symbol symbol)
symbol - The symbolpublic static boolean isPointer(Symbol symbol)
symbol - The symbolpublic static boolean isPointer(Expression e)
e - the expression to be tested.public static boolean isInteger(Symbol symbol)
symbol - the symbol.public static boolean isInteger(java.util.List specifiers)
public static java.util.List<Specifier> getExactExpressionType(Expression e)
e - the expression to be examined.public static java.util.List getExpressionType(Expression e)
e - the given expression.public static Declaration findSymbol(SymbolTable table, java.lang.String sname)
table - The initial table to search.sname - The String name of the symbol (Symbol.getSymbolName()) to
locate.public static java.util.LinkedList getVariableType(Expression e)
public static void setSymbolName(Symbol symbol, java.lang.String name, SymbolTable symtab)
symbol - the symbol object to be renamed.name - the new name of the specified symbol.symtab - the symbol table object that contains symbol.public static boolean containsSpecifier(Symbol symbol, Specifier spec)
Symbol.getTypeSpecifiers() or Symbol.getArraySpecifiers() but
they consume extra memory for the returned list.symbol - the symbol to be checked.spec - the specifier to be searched for.