public final class CfgUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
addAsSink(java.util.Collection<CfgNode> nodes,
CfgNode node)
Substitutes internal sink node by the specified node and adds it to the specified collection.
|
static void |
addAsSource(java.util.Collection<CfgNode> nodes,
CfgNode node)
Substitutes internal source node by the specified node and adds it to the specified collection.
|
static CfgNode |
getFirstNode(java.util.Collection<CfgNode> nodes,
java.lang.String nodeId)
Returns first node in the specified collection with the specified identifier.
|
static CfgNode |
getLastNode(java.util.List<CfgNode> list,
CfgNodeType type)
Returns last node in the specified list with the specified type.
|
static <T> T |
getNode(java.util.Collection<T> collection,
CfgNodeType type)
Returns node of the specified type that is in the specified collection.
|
static java.util.List<CfgNode> |
getPath(CfgNode begin,
CfgNode end)
Constructs a sequence of connected nodes
between the specified begin and end nodes.
|
static Sink |
getSink(java.util.Collection<CfgNode> nodes)
Returns sink node if it exists in the specified collection.
|
static Source |
getSource(java.util.Collection<CfgNode> nodes)
Returns source node if it exists in the specified collection.
|
static VariableContainer |
getVariableContainer(CfgModelNode node,
java.lang.String name)
Returns node that contains a declaration of variable with the specified name.
|
static boolean |
isType(CfgNodeType type,
CfgModelNode... nodes)
Checks whether the specified nodes are of the specified type.
|
static java.util.List<CfgNode> |
substitute(java.util.List<CfgNode> 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 Source getSource(java.util.Collection<CfgNode> nodes)
nodes
- nodesSource
node if the specified collection contains it,
null
otherwise.public static Sink getSink(java.util.Collection<CfgNode> nodes)
nodes
- nodesSink
node if the specified collection contains it,
null
otherwise.public static <T> T getNode(java.util.Collection<T> collection, CfgNodeType type)
T
- type of collection elementscollection
- nodes collectiontype
- node typeCfgModelNode
,
null
otherwisepublic static CfgNode getFirstNode(java.util.Collection<CfgNode> nodes, java.lang.String nodeId)
Returns node with the specified identifier and with minimal index in the specified collection.
nodes
- collection of nodesnodeId
- node identifiernull
otherwise.public static CfgNode getLastNode(java.util.List<CfgNode> list, CfgNodeType type)
Returns node with the specified identifier and with maximal index in the specified list.
list
- nodestype
- type of target nodenull
if there is no such node.public static void addAsSource(java.util.Collection<CfgNode> nodes, CfgNode node)
Previous Source
node (it MUST exist) will be removed
from the specified collection. Method does not add the specified
node if the specified collection already contains it.
nodes
- collection that is to be modifiednode
- node to be added as the new sourcejava.lang.IllegalArgumentException
- when argument is null
.java.lang.IllegalStateException
- when this object does not contain Source
node.public static void addAsSink(java.util.Collection<CfgNode> nodes, CfgNode node)
Previous Sink
node (it MUST exist) will be removed from the collection.
Method does not add the specified node if the specified collection already contains it.
nodes
- collection that is to be modifiednode
- node to be added as the new sinkjava.lang.IllegalArgumentException
- when argument is null
.java.lang.IllegalStateException
- when the specified collection
does not contains Sink
node.public static java.util.List<CfgNode> getPath(CfgNode begin, CfgNode end)
Constructs a nodes sequence, to which control flow goes through the specified start node and from which it goes through the specified end node. The path does not contain copies of the specified begin and end nodes.
begin
- the before-first node of the pathend
- the after-last node of the pathpublic static java.util.List<CfgNode> substitute(java.util.List<CfgNode> 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(CfgNodeType type, CfgModelNode... 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 VariableContainer getVariableContainer(CfgModelNode 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
.