public final class IRTools
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
checkConsistency(Traversable t)
Checks the consistency of the IR subtree rooted at
t. |
static <T extends PragmaAnnotation> |
collectPragmas(Traversable t,
java.lang.Class<T> pragma_cls,
java.lang.String key)
Returns a list of pragma annotations that contain the specified string
keys and are attached to annotatable objects within the traversable object
t. |
static boolean |
containsBinary(Traversable t,
BinaryOperator op)
Checks if the traversable object contains the specified type of binary
operations.
|
static boolean |
containsClass(Traversable t,
java.lang.Class<? extends Traversable> type)
Checks if the traversable object contains the specified type of object.
|
static boolean |
containsClasses(Traversable t,
java.util.Set<java.lang.Class<? extends Traversable>> types)
Checks if the traversable object contains the specified types of object.
|
static boolean |
containsExpression(Traversable t,
Expression e)
Searches the IR tree beginning at
t for the Expression e. |
static boolean |
containsExpressions(Traversable t,
java.util.Collection<? extends Expression> es)
Searches the IR tree beginning at
t for any expressions in the
given collection of expressions. |
static boolean |
containsFunctionCall(Traversable t)
Returns true if there is a FunctionCall within the traversable.
|
static boolean |
containsSideEffect(Traversable t)
Returns true if the traversable contains any side effects that change the
program state.
|
static boolean |
containsSymbol(Traversable t,
Symbol var)
Checks if the specified traversable object contains any identifier
derived from the given symbol
var. |
static boolean |
containsSymbols(java.util.Set<Symbol> vars,
java.util.Set<Symbol> symbols)
Simple check method for existence of intersection between the two given
sets of symbols.
|
static boolean |
containsSymbols(Traversable t,
java.util.Set<Symbol> vars)
Checks if the specified traversable object contains any identifier
derived from the given set of symbols
vars. |
static boolean |
containsUnary(Traversable t,
UnaryOperator op)
Checks if the traversable object contains the specified type of unary
operations.
|
static int |
countExpressions(Traversable t,
Expression e)
Counts the number of times that the Expression
e appears in
the IR tree t. |
static Expression |
findExpression(Traversable t,
Expression e)
Finds the first instance of the Expression
e in the IR tree
t. |
static java.util.List<Expression> |
findExpressions(Traversable t,
Expression e)
Finds the list of instances of the Expression
e in the IR tree
t. |
static <T extends Traversable> |
getAncestorOfType(Traversable t,
java.lang.Class<T> type)
Returns the nearest ancestor object of the given traversable object
that has the specified type.
|
static <T extends Traversable> |
getDescendentsOfType(Traversable t,
java.lang.Class<T> type)
Returns a list of descendents of the traversable object
t with the
specified type type. |
static <T extends Expression> |
getExpressionsOfType(Traversable t,
java.lang.Class<T> type)
Returns a list of expressions having the specified type in the given
traversable object.
|
static Statement |
getFirstNonDeclarationStatement(Traversable t)
Returns the first non-DeclarationStatement of the given traverable object.
|
static java.util.List<FunctionCall> |
getFunctionCalls(Traversable t)
Returns a list of FunctionCall expressions within the traversable object.
|
static Declaration |
getLastDeclaration(Traversable t)
Returns the last declaration that belongs to the given traverable object.
|
static DeclarationStatement |
getLastDeclarationStatement(Traversable t)
Returns the last declaration statement that belongs to the given
traverable object.
|
static java.util.List<Statement> |
getLastStatements(Procedure proc)
Returns a list of the last Statements to be evaluated in the Procedure.
|
static Procedure |
getParentProcedure(Traversable t)
Returns the Procedure to which the input traversable
object belongs.
|
static TranslationUnit |
getParentTranslationUnit(Traversable t)
Returns the TranslationUnit to which the input traversable
object belongs.
|
static java.util.List<Procedure> |
getProcedureList(Program program)
Return a list of Procedures in a program.
|
static <T extends Statement> |
getStatementsOfType(Traversable t,
java.lang.Class<T> type)
Returns a list of statements having the specified type in the given
traversable object.
|
static java.util.List<UnaryExpression> |
getUnaryExpression(Traversable t,
UnaryOperator op)
Returns a list of unary expressions with the given unary operator.
|
static boolean |
isAncestorOf(Traversable anc,
Traversable des)
Checks if the specified traversable object
anc is an ancestor of
the other traversable object des in the IR tree. |
static boolean |
isDescendantOf(Traversable des,
Traversable anc)
Checks if the specified traversable object
des is a descendant of
the other traversable object anc in the IR tree. |
static void |
removeAnnotations(Traversable t,
java.lang.Class<? extends Annotation> type)
Removes all annotations with the specified type from the given traversable
object.
|
static void |
replaceAll(Traversable t,
Expression x,
Expression y)
Replaces all instances of expression x on the IR tree
beneath t by clones of expression y.
|
static Expression |
replaceSymbol(Expression e,
Symbol var,
Expression expr)
Replaces all occurrences of the specified variable
var with the
given expression expr in the input expression e. |
static void |
replaceSymbolIn(Traversable t,
Symbol var,
Expression e)
Replaces all occurrences of the specified variable
var with the
given expression e in the traversable object t in place. |
public static boolean containsExpression(Traversable t, Expression e)
t for the Expression e.t - the traversable object to be searched.e - the expression to be searched for.t contains e and false otherwise.public static boolean containsExpressions(Traversable t, java.util.Collection<? extends Expression> es)
t for any expressions in the
given collection of expressions.t - the traversable object to be searched.es - the collection of expressions to be searched for.t contains an expression in the collection
es.public static int countExpressions(Traversable t, Expression e)
e appears in
the IR tree t.t - the traversable object to be searched.e - the expression to be counted.e appears in t.public static Expression findExpression(Traversable t, Expression e)
e in the IR tree
t.t - the traversable object to be searched.e - the expression to be searched for.t that is equal to e.public static java.util.List<Expression> findExpressions(Traversable t, Expression e)
e in the IR tree
t.t - the traversable object to be searched.e - the expression to be searched for.public static boolean checkConsistency(Traversable t)
t.
It checks if every children of a parent node has a correct back link to
the parent node.t - the traversable object to be checked.public static void replaceAll(Traversable t, Expression x, Expression y)
t - The location at which to start the search.x - The expression to be replaced.y - The expression to substitute.public static Procedure getParentProcedure(Traversable t)
t - the traversable object to be searched from.t.public static TranslationUnit getParentTranslationUnit(Traversable t)
t - the traversable object to be searched from.t.public static Declaration getLastDeclaration(Traversable t)
t - the traversable object to be searched.public static DeclarationStatement getLastDeclarationStatement(Traversable t)
t - the traversable object to be searched.public static Statement getFirstNonDeclarationStatement(Traversable t)
t - the traversable object to be searched.public static Expression replaceSymbol(Expression e, Symbol var, Expression expr)
var with the
given expression expr in the input expression e. If the
traversable object is the specified variable it returns a copy of the
expression expr.e - the input expression.var - the variable to be replaced.expr - the expression to be substituted.public static void replaceSymbolIn(Traversable t, Symbol var, Expression e)
var with the
given expression e in the traversable object t in place.t - the traversable object to be modified.var - the variable to be replaced.e - the expression to be substituted.public static boolean containsSymbol(Traversable t, Symbol var)
var. This method only searches for
the derived identifier not the symbol itself.t - the traversable object to be searched.var - the symbol to be searched for.var, false
otherwise.public static boolean containsSymbols(Traversable t, java.util.Set<Symbol> vars)
vars. This method only
searches for the derived identifier not the symbol itself.t - the traversable object to be searched.vars - the set of symbols to be searched for.vars, false otherwise.public static boolean containsSymbols(java.util.Set<Symbol> vars, java.util.Set<Symbol> symbols)
vars - the first set of symbols.symbols - the second set of symbols.public static boolean containsClass(Traversable t, java.lang.Class<? extends Traversable> type)
t - the traversable object to be searched.type - the class to be searched for.t contains the type type.public static boolean containsClasses(Traversable t, java.util.Set<java.lang.Class<? extends Traversable>> types)
t - the traversable object to be searched.types - the classes to be searched for.t contains any of the set types.public static boolean containsBinary(Traversable t, BinaryOperator op)
t - The traversable object being searchedop - The binary operator being searched forpublic static boolean containsUnary(Traversable t, UnaryOperator op)
t - The traversable object being searchedop - The unary operator being searched forpublic static java.util.List<UnaryExpression> getUnaryExpression(Traversable t, UnaryOperator op)
t - the traversable object being searched.op - the unary operator being searched for.public static boolean containsSideEffect(Traversable t)
t - The traversable object being searchedpublic static <T extends Traversable> T getAncestorOfType(Traversable t, java.lang.Class<T> type)
t - the traversable object to be searched from.type - the IR type being searched for.t having the type type.public static <T extends Traversable> java.util.List<T> getDescendentsOfType(Traversable t, java.lang.Class<T> type)
t with the
specified type type.t - the traversable object to be searched.type - the IR type to be searched for.type.public static boolean isAncestorOf(Traversable anc, Traversable des)
anc is an ancestor of
the other traversable object des in the IR tree.anc - a possible ancestor of des.des - a possible descendant of anc.anc is an ancestor of des, false if not.public static boolean isDescendantOf(Traversable des, Traversable anc)
des is a descendant of
the other traversable object anc in the IR tree.des - a possible descendant of anc.anc - a possible ancestor of des.des is a descendant of anc, false if not.public static boolean containsFunctionCall(Traversable t)
t - traversable object to be searched.t contains a function call.public static java.util.List<FunctionCall> getFunctionCalls(Traversable t)
t - the traversable object to be searched.t.public static <T extends PragmaAnnotation> java.util.List<T> collectPragmas(Traversable t, java.lang.Class<T> pragma_cls, java.lang.String key)
t. For example, it can collect list of OpenMP pragmas having
a work-sharing directive for within a specific procedure.t - the traversable object to be searched.pragma_cls - the type of pragmas to be searched for.key - the keyword to be searched for.public static java.util.List<Statement> getLastStatements(Procedure proc)
public static <T extends Statement> java.util.List<T> getStatementsOfType(Traversable t, java.lang.Class<T> type)
t - the traversable object to be examined.type - the type of statements to be collected.type.public static <T extends Expression> java.util.List<T> getExpressionsOfType(Traversable t, java.lang.Class<T> type)
t - the traversable object to be examined.type - the type of expressions to be collected.type.public static java.util.List<Procedure> getProcedureList(Program program)
public static void removeAnnotations(Traversable t, java.lang.Class<? extends Annotation> type)
t - the traversable object to be searched.type - the annotation types to be removed.