public final class CfgUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static ru.ispras.fortress.expression.Node |
getExpression(CfgCaseStatement caseNode,
CfgSwitchStatement switchNode)
Constructs an expression from the expression of the specified switch
CfgSwitchStatement node and it's possible values
in the specified case CfgCaseStatement node. |
static CfgDeclarationStatement |
getNearVariableContainer(CfgStatement statement)
Returns variable declaration container that is closest to the specified statement.
|
static CfgDeclarationStatement |
getNearVariableContainer(CfgStatement statement,
CfgStatementType containerType)
Returns closest declaration container of the specified type to the specified statement.
|
static java.util.Collection<CfgStatement> |
getSuccessors(CfgStatement statement)
Returns statements that go after the specified statement.
|
static CfgDeclarationStatement |
getVariableContainer(CfgStatement node,
java.lang.String name)
Returns node that contains a declaration of variable with the specified name.
|
static boolean |
hasSuccessors(CfgStatement statement)
Checks whether the specified statement has successors or not.
|
static boolean |
isType(CfgStatementType type,
CfgStatement... nodes)
Checks whether the specified nodes are of the specified type.
|
static void |
replace(CfgStatement one,
CfgStatement another)
Replaces the first statement by the second statement.
|
static java.util.List<CfgStatement> |
substitute(java.util.List<CfgStatement> list,
java.lang.String name,
ru.ispras.fortress.expression.Node node)
Substitutes usages of variable with the specified name
by the specified expression in all the elements of the specified collection.
|
public static java.util.List<CfgStatement> substitute(java.util.List<CfgStatement> list, java.lang.String name, ru.ispras.fortress.expression.Node node)
Substitutes usages of variable with the specified String
name
by the specified Node
expression
in all the elements of the specified collection. The resulting collection
consists of node copies of the specified collection. In which node the every
usage of the variable with the specified name will be substituted by the
specified expression.
list
- collection which nodes will be copied and transformedname
- variable namenode
- expressionpublic static boolean isType(CfgStatementType type, CfgStatement... nodes)
type
- node typenodes
- nodes to be checkedtrue
if all the specified nodes are of the specified type,
false
otherwise.java.lang.IllegalArgumentException
- when either the specified type is null
or the specified array of nodes is empty.public static CfgDeclarationStatement getVariableContainer(CfgStatement node, java.lang.String name)
node
- root node which and which child nodes are checkedname
- variable namenull
when the specified node and all the it's children
do not contain such declarationjava.lang.IllegalArgumentException
- when any of arguments is null
.public static CfgDeclarationStatement getNearVariableContainer(CfgStatement statement)
statement
- statement that is included in some degree to the resulting containerpublic static CfgDeclarationStatement getNearVariableContainer(CfgStatement statement, CfgStatementType containerType)
Closest container is in terms of statement inclusion. For example, we have a
CfgModule
object x
that includes CfgProcess
object y
that
includes some statement. For that statement the closest declaration container of the
CfgStatementType.MODULE
type is an x
object.
statement
- statement that is included in some degree to the resulting containercontainerType
- type of the returned objectnull
if there is no such.RetrascopeRuntimeException
- when there is no variable declaration container
of the specified type among parents of the specified statement.public static java.util.Collection<CfgStatement> getSuccessors(CfgStatement statement)
statement
- statement which successors are returnedjava.lang.IllegalArgumentException
- when argument is null
.public static boolean hasSuccessors(CfgStatement statement)
statement
- statement that is checkedtrue
when the specified statement has successors, false
otherwisepublic static void replace(CfgStatement one, CfgStatement another)
Finds parent statement for the specified first statement and substitutes it by the second statement.
one
- statement to be replacedanother
- statement that substitutes the first argumentjava.lang.IllegalArgumentException
- when any of arguments is null
java.lang.IllegalArgumentException
- when first argument does not have parent statement.public static ru.ispras.fortress.expression.Node getExpression(CfgCaseStatement caseNode, CfgSwitchStatement switchNode)
CfgSwitchStatement
node and it's possible values
in the specified case CfgCaseStatement
node.caseNode
- case nodeswitchNode
- switch node