2007-02-02 17:17:13 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 IBM Corporation.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* IBM Corporation - initial API and implementation
|
|
|
|
*****************************************************************************/
|
|
|
|
package com.ibm.wala.cast.tree.impl;
|
|
|
|
|
2007-04-24 14:10:57 +00:00
|
|
|
import java.util.Collection;
|
2007-04-19 13:48:01 +00:00
|
|
|
import java.util.Map;
|
2007-02-02 17:17:13 +00:00
|
|
|
|
2007-08-01 15:36:40 +00:00
|
|
|
import com.ibm.wala.cast.tree.*;
|
|
|
|
import com.ibm.wala.util.collections.*;
|
2007-07-06 22:09:29 +00:00
|
|
|
import com.ibm.wala.util.debug.Assertions;
|
2007-04-24 14:10:57 +00:00
|
|
|
|
2007-08-01 15:36:40 +00:00
|
|
|
public class CAstCloner extends CAstBasicRewriter {
|
2007-02-02 17:17:13 +00:00
|
|
|
|
|
|
|
public CAstCloner(CAst Ast) {
|
2007-08-01 15:36:40 +00:00
|
|
|
super(Ast, false);
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
|
2007-04-19 13:48:01 +00:00
|
|
|
protected CAstNode copyNodes(CAstNode root,
|
2007-08-01 15:36:40 +00:00
|
|
|
NonCopyingContext c,
|
|
|
|
Map nodeMap)
|
2007-04-19 13:48:01 +00:00
|
|
|
{
|
2007-02-02 17:17:13 +00:00
|
|
|
if (root instanceof CAstOperator) {
|
2007-08-31 23:19:52 +00:00
|
|
|
nodeMap.put(Pair.make(root, c.key()), root);
|
2007-02-02 17:17:13 +00:00
|
|
|
return root;
|
|
|
|
} else if (root.getValue() != null) {
|
|
|
|
CAstNode copy = Ast.makeConstant( root.getValue() );
|
2007-06-25 20:08:56 +00:00
|
|
|
Assertions._assert(! nodeMap.containsKey(root));
|
2007-08-31 23:19:52 +00:00
|
|
|
nodeMap.put(Pair.make(root, c.key()), copy);
|
2007-02-02 17:17:13 +00:00
|
|
|
return copy;
|
|
|
|
} else {
|
|
|
|
CAstNode newChildren[] = new CAstNode[ root.getChildCount() ];
|
|
|
|
|
|
|
|
for(int i = 0; i < root.getChildCount(); i++) {
|
2007-08-01 15:36:40 +00:00
|
|
|
newChildren[i] = copyNodes(root.getChild(i), c, nodeMap);
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CAstNode copy = Ast.makeNode(root.getKind(), newChildren);
|
2007-06-25 20:08:56 +00:00
|
|
|
Assertions._assert(! nodeMap.containsKey(root));
|
2007-08-31 23:19:52 +00:00
|
|
|
nodeMap.put(Pair.make(root, c.key()), copy);
|
2007-02-02 17:17:13 +00:00
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-19 13:48:01 +00:00
|
|
|
public Rewrite copy(CAstNode root,
|
|
|
|
final CAstControlFlowMap cfg,
|
|
|
|
final CAstSourcePositionMap pos,
|
|
|
|
final CAstNodeTypeMap types,
|
2007-04-24 14:10:57 +00:00
|
|
|
final Map<CAstNode,Collection<CAstEntity>> children)
|
2007-02-02 17:17:13 +00:00
|
|
|
{
|
2007-04-19 13:48:01 +00:00
|
|
|
return rewrite(root, cfg, pos, types, children);
|
2007-02-02 17:17:13 +00:00
|
|
|
}
|
|
|
|
}
|