2013-05-22 22:39:19 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2013 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
|
|
|
|
*******************************************************************************/
|
2012-10-03 14:53:04 +00:00
|
|
|
package com.ibm.wala.cast.tree.rewrite;
|
2007-08-01 15:37:46 +00:00
|
|
|
|
2007-11-16 20:57:45 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2007-08-01 15:37:46 +00:00
|
|
|
|
2007-11-16 20:57:45 +00:00
|
|
|
import com.ibm.wala.cast.tree.CAst;
|
2012-01-27 20:15:33 +00:00
|
|
|
import com.ibm.wala.cast.tree.CAstControlFlowMap;
|
2011-04-04 15:00:43 +00:00
|
|
|
import com.ibm.wala.cast.tree.CAstNode;
|
|
|
|
import com.ibm.wala.util.collections.Pair;
|
2007-11-16 20:57:45 +00:00
|
|
|
import com.ibm.wala.util.debug.Assertions;
|
2007-08-01 15:37:46 +00:00
|
|
|
|
2011-04-26 18:44:49 +00:00
|
|
|
/**
|
|
|
|
* abstract base class for {@link CAstRewriter}s that do no cloning of nodes
|
|
|
|
*
|
|
|
|
*/
|
2018-04-28 10:05:49 +00:00
|
|
|
public abstract class CAstBasicRewriter<T extends CAstBasicRewriter.NonCopyingContext>
|
|
|
|
extends CAstRewriter<T,
|
2007-08-01 15:37:46 +00:00
|
|
|
CAstBasicRewriter.NoKey>
|
|
|
|
{
|
|
|
|
|
2011-04-26 18:44:49 +00:00
|
|
|
/**
|
|
|
|
* context indicating that no cloning is being performed
|
|
|
|
*/
|
2007-08-01 15:37:46 +00:00
|
|
|
public static class NonCopyingContext implements CAstRewriter.RewriteContext<NoKey> {
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
private final Map<Object, Object> nodeMap = new HashMap<>();
|
2007-08-01 15:37:46 +00:00
|
|
|
|
Fix nearly all Eclipse warnings about using raw types
Along the way, I also converted many "for (;;)" loops into modern
"for (:)" loops. I didn't systematically look for all opportunities
to do this, though. I merely made this change where I was already
converting raw Iterator uses into modern Iterator<...> uses.
Better use of generics also allowed many casts to become statically
redundant. I have removed all such redundant casts.
Only three raw-types warnings remain after this batch of fixes. All
three involve raw uses of CallGraphBuilder. I've tried to fix these
too, but it quickly snowballs into a cascade of changes that may or
may not eventually reach a statically-type-save fixed point. I may
give these last few problem areas another go in the future. For now,
though, the hundreds of other fixes seem worth keeping even if there
are a few stragglers.
This commit may change some public APIs, but only by making weaker
type signatures stronger by replacing raw types with generic types.
For example, we may change something like "Set" into "Set<String>",
but we're not adding new arguments, changing any
underlying (post-generics-erasure) types, etc.
2017-07-09 18:38:35 +00:00
|
|
|
public Map<Object, Object> nodeMap() {
|
2007-08-01 15:37:46 +00:00
|
|
|
return nodeMap;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-08-01 15:37:46 +00:00
|
|
|
public NoKey key() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-04-26 18:44:49 +00:00
|
|
|
/**
|
|
|
|
* key indicating that no duplication is being performed
|
|
|
|
*/
|
2007-08-01 15:37:46 +00:00
|
|
|
public static class NoKey implements CAstRewriter.CopyKey<NoKey> {
|
|
|
|
private NoKey() {
|
|
|
|
Assertions.UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-08-01 15:37:46 +00:00
|
|
|
public int hashCode() {
|
|
|
|
return System.identityHashCode(this);
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-08-01 15:37:46 +00:00
|
|
|
public boolean equals(Object o) {
|
|
|
|
return o == this;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2007-08-01 15:37:46 +00:00
|
|
|
public NoKey parent() {
|
|
|
|
return null;
|
|
|
|
}
|
2017-07-12 23:54:57 +00:00
|
|
|
}
|
2007-08-01 15:37:46 +00:00
|
|
|
|
2018-04-28 10:05:49 +00:00
|
|
|
protected CAstBasicRewriter(CAst Ast, T context, boolean recursive) {
|
|
|
|
super(Ast, recursive, context);
|
2007-08-01 15:37:46 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:57:37 +00:00
|
|
|
@Override
|
2018-04-28 10:05:49 +00:00
|
|
|
protected abstract CAstNode copyNodes(CAstNode root, final CAstControlFlowMap cfg, T context, Map<Pair<CAstNode,NoKey>, CAstNode> nodeMap);
|
2011-04-04 15:00:43 +00:00
|
|
|
|
2017-02-03 01:33:27 +00:00
|
|
|
}
|