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)
public abstract class CAstRewriter<C extends CAstRewriter.RewriteContext<K>,K extends CAstRewriter.CopyKey<K>> extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
CAstRewriter.CopyKey<Self extends CAstRewriter.CopyKey>
interface to be implemented by keys used for cloning sub-trees during the
rewrite
|
static interface |
CAstRewriter.Rewrite
represents a rewritten CAst
|
static interface |
CAstRewriter.RewriteContext<K extends CAstRewriter.CopyKey>
interface to be implemented by contexts used while traversing the AST
|
Modifier and Type | Field and Description |
---|---|
protected CAst |
Ast |
protected static boolean |
DEBUG |
protected boolean |
recursive
for CAstEntity nodes r s.t.
|
protected C |
rootContext |
Constructor and Description |
---|
CAstRewriter(CAst Ast,
boolean recursive,
C rootContext) |
Modifier and Type | Method and 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)
in
copyFlow(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 a
CAstEntity , returning the new
CAstEntity as the result |
CAstRewriter.Rewrite |
rewrite(CAstNode root,
CAstControlFlowMap cfg,
CAstSourcePositionMap pos,
CAstNodeTypeMap types,
Map<CAstNode,Collection<CAstEntity>> children)
rewrite the CAst sub-tree rooted at root
|
protected static final boolean DEBUG
protected final CAst Ast
protected final boolean recursive
protected final C extends CAstRewriter.RewriteContext<K> rootContext
protected abstract CAstNode copyNodes(CAstNode root, CAstControlFlowMap cfg, C context, Map<Pair<CAstNode,K>,CAstNode> nodeMap)
protected CAstNode flowOutTo(Map<Pair<CAstNode,K>,CAstNode> nodeMap, CAstNode oldSource, Object label, CAstNode oldTarget, CAstControlFlowMap orig, CAstSourcePositionMap src)
copyFlow(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.protected CAstControlFlowMap copyFlow(Map<Pair<CAstNode,K>,CAstNode> nodeMap, CAstControlFlowMap orig, CAstSourcePositionMap newSrc)
protected CAstSourcePositionMap copySource(Map<Pair<CAstNode,K>,CAstNode> nodeMap, CAstSourcePositionMap orig)
protected CAstNodeTypeMap copyTypes(Map<Pair<CAstNode,K>,CAstNode> nodeMap, CAstNodeTypeMap orig)
protected Map<CAstNode,Collection<CAstEntity>> copyChildren(CAstNode root, Map<Pair<CAstNode,K>,CAstNode> nodeMap, Map<CAstNode,Collection<CAstEntity>> children)
public CAstRewriter.Rewrite rewrite(CAstNode root, CAstControlFlowMap cfg, CAstSourcePositionMap pos, CAstNodeTypeMap types, Map<CAstNode,Collection<CAstEntity>> children)
public CAstEntity rewrite(CAstEntity root)
CAstEntity
, returning the new
CAstEntity
as the result