Package com.ibm.wala.cast.tree.rewrite
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; see#copyNodes(CAstNode, RewriteContext, Map)
- Direct Known Subclasses:
AstLoopUnwinder
,CAstBasicRewriter
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
Nested Classes Modifier and Type Class Description static interface
CAstRewriter.CopyKey<Self extends CAstRewriter.CopyKey>
interface to be implemented by keys used for cloning sub-trees during the rewritestatic interface
CAstRewriter.Rewrite
represents a rewritten CAststatic interface
CAstRewriter.RewriteContext<K extends CAstRewriter.CopyKey>
interface to be implemented by contexts used while traversing the AST
-
Constructor Summary
Constructors Constructor Description CAstRewriter(CAst Ast, boolean recursive, C rootContext)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected Map<CAstNode,Collection<CAstEntity>>
copyChildren(CAstNode root, Map<Pair<CAstNode,K>,CAstNode> nodeMap, Map<CAstNode,Collection<CAstEntity>> children)
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
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.protected CAstSourcePositionMap
copySource(Map<Pair<CAstNode,K>,CAstNode> nodeMap, CAstSourcePositionMap orig)
protected CAstNodeTypeMap
copyTypes(Map<Pair<CAstNode,K>,CAstNode> nodeMap, CAstNodeTypeMap orig)
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.CAstEntity
rewrite(CAstEntity root)
perform the rewrite on aCAstEntity
, returning the newCAstEntity
as the resultCAstRewriter.Rewrite
rewrite(CAstNode root, CAstControlFlowMap cfg, CAstSourcePositionMap pos, CAstNodeTypeMap types, Map<CAstNode,Collection<CAstEntity>> children)
rewrite the CAst sub-tree rooted at root
-
-
-
Field Detail
-
DEBUG
protected static final boolean DEBUG
- See Also:
- Constant Field Values
-
Ast
protected final CAst Ast
-
recursive
protected final boolean recursive
for CAstEntity nodes r s.t. r.getAst() == null, should the scoped entities of r be rewritten?
-
rootContext
protected final C extends CAstRewriter.RewriteContext<K> rootContext
-
-
Method Detail
-
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.
-
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
protected CAstNodeTypeMap copyTypes(Map<Pair<CAstNode,K>,CAstNode> nodeMap, CAstNodeTypeMap orig)
-
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)
rewrite the CAst sub-tree rooted at root
-
rewrite
public CAstEntity rewrite(CAstEntity root)
perform the rewrite on aCAstEntity
, returning the newCAstEntity
as the result
-
-