Package com.tonic.analysis.cpg.node
Class CPGNode
- java.lang.Object
-
- com.tonic.analysis.cpg.node.CPGNode
-
- Direct Known Subclasses:
BlockNode,CallSiteNode,InstructionNode,MethodNode
public abstract class CPGNode extends Object
Base class for CPG nodes: an id, a node type, a property map, and the incident edges; identity is the id alone.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddIncomingEdge(CPGEdge edge)Registers an edge entering this node.voidaddOutgoingEdge(CPGEdge edge)Registers an edge leaving this node.List<CPGNode>astChildren()Follows outgoing AST child edges.Optional<CPGNode>astParent()Follows the incoming AST child edge to the parent.List<CPGNode>cfgPredecessors()Follows incoming control-flow edges.List<CPGNode>cfgSuccessors()Follows outgoing control-flow edges.Set<CPGNode>controlDependencies()Follows incoming control-dependence edges to the nodes controlling this one.Set<CPGNode>dataDependencies()Follows incoming data-flow edges to the values this node depends on.booleanequals(Object o)Set<CPGEdge>getEdges(CPGEdgeType type)Collects incident edges of one type in either direction.longgetId()Set<CPGEdge>getIncomingEdges()Set<CPGEdge>getIncomingEdges(CPGEdgeType type)Collects incoming edges of one type.intgetInDegree()abstract StringgetLabel()CPGNodeTypegetNodeType()intgetOutDegree()Set<CPGEdge>getOutgoingEdges()Set<CPGEdge>getOutgoingEdges(CPGEdgeType type)Collects outgoing edges of one type.Map<String,Object>getProperties()ObjectgetProperty(String key)Reads a property value.StringgetTaintLabel()abstract <T> TgetUnderlying()inthashCode()booleanhasProperty(String key)Tests whether a property is present.booleanisTainted()voidremoveIncomingEdge(CPGEdge edge)Unregisters an edge entering this node.voidremoveOutgoingEdge(CPGEdge edge)Unregisters an edge leaving this node.voidremoveProperty(String key)Removes a property.voidsetProperty(String key, Object value)Sets a property value.voidsetTainted(boolean tainted)Marks or clears this node as taint-reached.voidsetTaintLabel(String taintLabel)Records which taint source reached this node.StringtoString()
-
-
-
Method Detail
-
getId
public long getId()
- Returns:
- the id
-
getNodeType
public CPGNodeType getNodeType()
- Returns:
- the node type
-
isTainted
public boolean isTainted()
- Returns:
- whether tainted
-
getTaintLabel
public String getTaintLabel()
- Returns:
- the taint label
-
setTainted
public void setTainted(boolean tainted)
Marks or clears this node as taint-reached.- Parameters:
tainted- whether the node is tainted
-
setTaintLabel
public void setTaintLabel(String taintLabel)
Records which taint source reached this node.- Parameters:
taintLabel- the taint label
-
getLabel
public abstract String getLabel()
- Returns:
- a short human-readable display label
-
getUnderlying
public abstract <T> T getUnderlying()
- Type Parameters:
T- the expected underlying type- Returns:
- the wrapped IR or analysis object
-
getProperty
public Object getProperty(String key)
Reads a property value.- Parameters:
key- the property key- Returns:
- the value, or null if absent
-
setProperty
public void setProperty(String key, Object value)
Sets a property value.- Parameters:
key- the property keyvalue- the value to store
-
hasProperty
public boolean hasProperty(String key)
Tests whether a property is present.- Parameters:
key- the property key- Returns:
- whether the property exists
-
removeProperty
public void removeProperty(String key)
Removes a property.- Parameters:
key- the property key
-
addOutgoingEdge
public void addOutgoingEdge(CPGEdge edge)
Registers an edge leaving this node.- Parameters:
edge- the edge to add
-
addIncomingEdge
public void addIncomingEdge(CPGEdge edge)
Registers an edge entering this node.- Parameters:
edge- the edge to add
-
removeOutgoingEdge
public void removeOutgoingEdge(CPGEdge edge)
Unregisters an edge leaving this node.- Parameters:
edge- the edge to remove
-
removeIncomingEdge
public void removeIncomingEdge(CPGEdge edge)
Unregisters an edge entering this node.- Parameters:
edge- the edge to remove
-
getEdges
public Set<CPGEdge> getEdges(CPGEdgeType type)
Collects incident edges of one type in either direction.- Parameters:
type- the edge type- Returns:
- the matching edges
-
getOutgoingEdges
public Set<CPGEdge> getOutgoingEdges(CPGEdgeType type)
Collects outgoing edges of one type.- Parameters:
type- the edge type- Returns:
- the matching edges
-
getIncomingEdges
public Set<CPGEdge> getIncomingEdges(CPGEdgeType type)
Collects incoming edges of one type.- Parameters:
type- the edge type- Returns:
- the matching edges
-
cfgSuccessors
public List<CPGNode> cfgSuccessors()
Follows outgoing control-flow edges.- Returns:
- the CFG successor nodes
-
cfgPredecessors
public List<CPGNode> cfgPredecessors()
Follows incoming control-flow edges.- Returns:
- the CFG predecessor nodes
-
astParent
public Optional<CPGNode> astParent()
Follows the incoming AST child edge to the parent.- Returns:
- the AST parent node, if any
-
astChildren
public List<CPGNode> astChildren()
Follows outgoing AST child edges.- Returns:
- the AST child nodes
-
dataDependencies
public Set<CPGNode> dataDependencies()
Follows incoming data-flow edges to the values this node depends on.- Returns:
- the data dependency sources
-
controlDependencies
public Set<CPGNode> controlDependencies()
Follows incoming control-dependence edges to the nodes controlling this one.- Returns:
- the control dependency sources
-
getInDegree
public int getInDegree()
- Returns:
- the number of incoming edges
-
getOutDegree
public int getOutDegree()
- Returns:
- the number of outgoing edges
-
-