Class CAstRewriter<C extends CAstRewriter.RewriteContext<K>,K extends CAstRewriter.CopyKey<K>>
java.lang.Object
com.ibm.wala.cast.tree.rewrite.CAstRewriter<C,K>
- Type Parameters:
C
- type of the RewriteContext used when traversing the original CAst during the rewrite operationK
- a key used to ease cloning of partial ASTs. When rewriting an AST, sub-classes maintain a mapping from (original node, key) pairs (where key is of type K) to new nodes; seecopyNodes(com.ibm.wala.cast.tree.CAstNode, com.ibm.wala.cast.tree.CAstControlFlowMap, C, java.util.Map<com.ibm.wala.util.collections.Pair<com.ibm.wala.cast.tree.CAstNode, K>, com.ibm.wala.cast.tree.CAstNode>)
- Direct Known Subclasses:
AstLoopUnwinder
,CAstBasicRewriter
,CAstRewriterExt
,PropertyReadExpander
,SynchronizedBlockDuplicator
public abstract class CAstRewriter<C extends CAstRewriter.RewriteContext<K>,K extends CAstRewriter.CopyKey<K>>
extends Object
Abstract superclass for types performing a rewrite operation on a CAst. The CAst is not mutated;
instead, a new CAst is created which delegates to the original CAst where no transformation was
performed.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
CAstRewriter.CopyKey<Self extends CAstRewriter.CopyKey<Self>>
interface to be implemented by keys used for cloning sub-trees during the rewritestatic interface
represents a rewritten CAststatic interface
CAstRewriter.RewriteContext<K extends CAstRewriter.CopyKey<K>>
interface to be implemented by contexts used while traversing the AST -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected Map
<CAstNode, Collection<CAstEntity>> copyChildren
(CAstNode root, Map<Pair<CAstNode, K>, CAstNode> nodeMap, Map<CAstNode, Collection<CAstEntity>> children) copyChildrenArray
(CAstNode n, CAstControlFlowMap cfg, C context, Map<Pair<CAstNode, K>, CAstNode> nodeMap) copyChildrenArrayAndTargets
(CAstNode n, CAstControlFlowMap cfg, C context, Map<Pair<CAstNode, K>, CAstNode> nodeMap) protected CAstControlFlowMap
copyFlow
(Map<Pair<CAstNode, K>, CAstNode> nodeMap, CAstControlFlowMap orig, CAstSourcePositionMap newSrc) create a control-flow map for the rewritten tree, given the mapping from (original node, copy key) pairs ot new nodes and the original control-flow map.protected abstract CAstNode
rewrite the CAst rooted at root under some context, returning the node at the root of the rewritten tree.protected CAstSourcePositionMap
copySource
(Map<Pair<CAstNode, K>, CAstNode> nodeMap, CAstSourcePositionMap orig) protected CAstNode
copySubtreesIntoNewNode
(CAstNode n, CAstControlFlowMap cfg, C c, Map<Pair<CAstNode, K>, CAstNode> nodeMap) protected CAstNode
copySubtreesIntoNewNode
(CAstNode n, CAstControlFlowMap cfg, C c, Map<Pair<CAstNode, K>, CAstNode> nodeMap, Pair<CAstNode, K> pairKey) protected CAstNodeTypeMap
protected CAstNode
flowOutTo
(Map<Pair<CAstNode, K>, CAstNode> nodeMap, CAstNode oldSource, Object label, CAstNode oldTarget, CAstControlFlowMap orig, CAstSourcePositionMap src) incopyFlow(Map, CAstControlFlowMap, CAstSourcePositionMap)
, if the source of some original CFG edge is replicated, but we find no replica for the target, what node should be the target of the CFG edge in the rewritten AST? By default, just uses the original target.rewrite
(CAstEntity root) perform the rewrite on aCAstEntity
, returning the newCAstEntity
as the resultrewrite
(CAstNode root, CAstControlFlowMap cfg, CAstSourcePositionMap pos, CAstNodeTypeMap types, Map<CAstNode, Collection<CAstEntity>> children, CAstNode[] defaults) rewrite the CAst sub-tree rooted at root
-
Field Details
-
DEBUG
protected static final boolean DEBUG- See Also:
-
Ast
-
recursive
protected final boolean recursivefor CAstEntity nodes r s.t. r.getAst() == null, should the scoped entities of r be rewritten? -
rootContext
-
-
Constructor Details
-
CAstRewriter
-
-
Method Details
-
copyNodes
protected abstract CAstNode copyNodes(CAstNode root, CAstControlFlowMap cfg, C context, Map<Pair<CAstNode, K>, CAstNode> nodeMap) rewrite the CAst rooted at root under some context, returning the node at the root of the rewritten tree. mutate nodeMap in the process, indicating how (original node, copy key) pairs are mapped to nodes in the rewritten tree. -
copySubtreesIntoNewNode
-
copySubtreesIntoNewNode
-
copyChildrenArray
-
copyChildrenArrayAndTargets
-
flowOutTo
protected CAstNode flowOutTo(Map<Pair<CAstNode, K>, CAstNode> nodeMap, CAstNode oldSource, Object label, CAstNode oldTarget, CAstControlFlowMap orig, CAstSourcePositionMap src) incopyFlow(Map, CAstControlFlowMap, CAstSourcePositionMap)
, if the source of some original CFG edge is replicated, but we find no replica for the target, what node should be the target of the CFG edge in the rewritten AST? By default, just uses the original target. -
copyFlow
protected CAstControlFlowMap copyFlow(Map<Pair<CAstNode, K>, CAstNode> nodeMap, CAstControlFlowMap orig, CAstSourcePositionMap newSrc) create a control-flow map for the rewritten tree, given the mapping from (original node, copy key) pairs ot new nodes and the original control-flow map. -
copySource
protected CAstSourcePositionMap copySource(Map<Pair<CAstNode, K>, CAstNode> nodeMap, CAstSourcePositionMap orig) -
copyTypes
-
copyChildren
protected Map<CAstNode,Collection<CAstEntity>> copyChildren(CAstNode root, Map<Pair<CAstNode, K>, CAstNode> nodeMap, Map<CAstNode, Collection<CAstEntity>> children) -
rewrite
public CAstRewriter.Rewrite rewrite(CAstNode root, CAstControlFlowMap cfg, CAstSourcePositionMap pos, CAstNodeTypeMap types, Map<CAstNode, Collection<CAstEntity>> children, CAstNode[] defaults) rewrite the CAst sub-tree rooted at root -
rewrite
perform the rewrite on aCAstEntity
, returning the newCAstEntity
as the result
-