misc. cleanups
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2044 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
92499cf576
commit
a8b61ccb17
|
@ -1,27 +1,43 @@
|
||||||
package com.ibm.wala.cast.ir.translator;
|
package com.ibm.wala.cast.ir.translator;
|
||||||
|
|
||||||
import com.ibm.wala.cast.ir.translator.NativeBridge;
|
import java.io.File;
|
||||||
import com.ibm.wala.cast.tree.*;
|
import java.io.FileInputStream;
|
||||||
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
|
import java.io.IOException;
|
||||||
import com.ibm.wala.cast.tree.impl.*;
|
import java.io.InputStream;
|
||||||
import com.ibm.wala.cast.tree.visit.*;
|
import java.net.URL;
|
||||||
import com.ibm.wala.cast.util.*;
|
import java.util.Collection;
|
||||||
import com.ibm.wala.util.collections.*;
|
import java.util.Collections;
|
||||||
import com.ibm.wala.util.debug.*;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import java.io.*;
|
import com.ibm.wala.cast.tree.CAst;
|
||||||
import java.net.*;
|
import com.ibm.wala.cast.tree.CAstControlFlowMap;
|
||||||
import java.util.*;
|
import com.ibm.wala.cast.tree.CAstEntity;
|
||||||
|
import com.ibm.wala.cast.tree.CAstNode;
|
||||||
|
import com.ibm.wala.cast.tree.CAstNodeTypeMap;
|
||||||
|
import com.ibm.wala.cast.tree.CAstQualifier;
|
||||||
|
import com.ibm.wala.cast.tree.CAstSourcePositionMap;
|
||||||
|
import com.ibm.wala.cast.tree.CAstType;
|
||||||
|
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
|
||||||
|
import com.ibm.wala.cast.tree.impl.AbstractSourcePosition;
|
||||||
|
import com.ibm.wala.cast.tree.impl.CAstControlFlowRecorder;
|
||||||
|
import com.ibm.wala.cast.tree.impl.CAstNodeTypeMapRecorder;
|
||||||
|
import com.ibm.wala.cast.tree.impl.CAstSourcePositionRecorder;
|
||||||
|
import com.ibm.wala.util.collections.EmptyIterator;
|
||||||
|
import com.ibm.wala.util.collections.HashMapFactory;
|
||||||
|
import com.ibm.wala.util.collections.HashSetFactory;
|
||||||
|
import com.ibm.wala.util.debug.Assertions;
|
||||||
|
|
||||||
public abstract class NativeTranslatorToCAst extends NativeBridge {
|
public abstract class NativeTranslatorToCAst extends NativeBridge {
|
||||||
|
|
||||||
protected abstract class NativeEntity implements CAstEntity {
|
protected abstract class NativeEntity implements CAstEntity {
|
||||||
private Position sourcePosition;
|
private Position sourcePosition;
|
||||||
|
|
||||||
private final Map scopedEntities =
|
|
||||||
new HashMap();
|
|
||||||
|
|
||||||
public Map getAllScopedEntities() {
|
private final Map<CAstNode, Collection<CAstEntity>> scopedEntities = HashMapFactory.make();
|
||||||
|
|
||||||
|
public Map<CAstNode, Collection<CAstEntity>> getAllScopedEntities() {
|
||||||
return scopedEntities;
|
return scopedEntities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,30 +54,30 @@ public abstract class NativeTranslatorToCAst extends NativeBridge {
|
||||||
return sourcePosition;
|
return sourcePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator getScopedEntities(CAstNode construct) {
|
public Iterator<?> getScopedEntities(CAstNode construct) {
|
||||||
if (scopedEntities.containsKey(construct)) {
|
if (scopedEntities.containsKey(construct)) {
|
||||||
return ((Set)scopedEntities.get(construct)).iterator();
|
return scopedEntities.get(construct).iterator();
|
||||||
} else {
|
} else {
|
||||||
return EmptyIterator.instance();
|
return EmptyIterator.instance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private void addScopedEntity(CAstNode construct, CAstEntity child) {
|
private void addScopedEntity(CAstNode construct, CAstEntity child) {
|
||||||
if (!scopedEntities.containsKey(construct)) {
|
if (!scopedEntities.containsKey(construct)) {
|
||||||
scopedEntities.put(construct, new HashSet(1));
|
Collection<CAstEntity> set = HashSetFactory.make(1);
|
||||||
|
scopedEntities.put(construct, set);
|
||||||
}
|
}
|
||||||
|
scopedEntities.get(construct).add(child);
|
||||||
((Set)scopedEntities.get(construct)).add( child );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract class NativeCodeEntity extends NativeEntity {
|
protected abstract class NativeCodeEntity extends NativeEntity {
|
||||||
protected final CAstSourcePositionRecorder src =
|
protected final CAstSourcePositionRecorder src = new CAstSourcePositionRecorder();
|
||||||
new CAstSourcePositionRecorder();
|
|
||||||
protected final CAstControlFlowRecorder cfg =
|
protected final CAstControlFlowRecorder cfg = new CAstControlFlowRecorder(src);
|
||||||
new CAstControlFlowRecorder(src);
|
|
||||||
protected final CAstNodeTypeMapRecorder types =
|
protected final CAstNodeTypeMapRecorder types = new CAstNodeTypeMapRecorder();
|
||||||
new CAstNodeTypeMapRecorder();
|
|
||||||
|
|
||||||
protected final CAstType type;
|
protected final CAstType type;
|
||||||
|
|
||||||
|
@ -96,11 +112,11 @@ public abstract class NativeTranslatorToCAst extends NativeBridge {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLabelledGotoTarget(CAstNode from, CAstNode to, Object label) {
|
public void setLabelledGotoTarget(CAstNode from, CAstNode to, Object label) {
|
||||||
if (! cfg.isMapped(from)) {
|
if (!cfg.isMapped(from)) {
|
||||||
cfg.map(from, from);
|
cfg.map(from, from);
|
||||||
}
|
}
|
||||||
if (! cfg.isMapped(to)) {
|
if (!cfg.isMapped(to)) {
|
||||||
cfg.map(to, to);
|
cfg.map(to, to);
|
||||||
}
|
}
|
||||||
cfg.add(from, to, label);
|
cfg.add(from, to, label);
|
||||||
}
|
}
|
||||||
|
@ -146,19 +162,21 @@ public abstract class NativeTranslatorToCAst extends NativeBridge {
|
||||||
|
|
||||||
protected class NativeFieldEntity extends NativeDataEntity {
|
protected class NativeFieldEntity extends NativeDataEntity {
|
||||||
private final String name;
|
private final String name;
|
||||||
private final Set modifiers;
|
|
||||||
|
private final Set<CAstQualifier> modifiers;
|
||||||
|
|
||||||
private final CAstEntity declaringClass;
|
private final CAstEntity declaringClass;
|
||||||
|
|
||||||
public NativeFieldEntity(String name, Set modifiers, boolean isStatic, CAstEntity declaringClass) {
|
public NativeFieldEntity(String name, Set<CAstQualifier> modifiers, boolean isStatic, CAstEntity declaringClass) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.declaringClass = declaringClass;
|
this.declaringClass = declaringClass;
|
||||||
|
|
||||||
this.modifiers = new HashSet();
|
this.modifiers = new HashSet<CAstQualifier>();
|
||||||
if (modifiers != null) {
|
if (modifiers != null) {
|
||||||
this.modifiers.addAll(modifiers);
|
this.modifiers.addAll(modifiers);
|
||||||
}
|
}
|
||||||
if (isStatic) {
|
if (isStatic) {
|
||||||
this.modifiers.add(CAstQualifier.STATIC);
|
this.modifiers.add(CAstQualifier.STATIC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +197,7 @@ public abstract class NativeTranslatorToCAst extends NativeBridge {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection getQualifiers() {
|
public Collection<CAstQualifier> getQualifiers() {
|
||||||
return modifiers;
|
return modifiers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,11 +225,11 @@ public abstract class NativeTranslatorToCAst extends NativeBridge {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection getQualifiers() {
|
public Collection<CAstQualifier> getQualifiers() {
|
||||||
return type.getQualifiers();
|
return type.getQualifiers();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
protected class NativeScriptEntity extends NativeCodeEntity {
|
protected class NativeScriptEntity extends NativeCodeEntity {
|
||||||
private final File file;
|
private final File file;
|
||||||
|
|
||||||
|
@ -237,7 +255,7 @@ public abstract class NativeTranslatorToCAst extends NativeBridge {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getArgumentNames() {
|
public String[] getArgumentNames() {
|
||||||
return new String[]{ "script object" };
|
return new String[] { "script object" };
|
||||||
}
|
}
|
||||||
|
|
||||||
public CAstNode[] getArgumentDefaults() {
|
public CAstNode[] getArgumentDefaults() {
|
||||||
|
@ -248,10 +266,10 @@ public abstract class NativeTranslatorToCAst extends NativeBridge {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection getQualifiers() {
|
public Collection<CAstQualifier> getQualifiers() {
|
||||||
return Collections.EMPTY_SET;
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
return file.getAbsolutePath();
|
return file.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
@ -261,43 +279,56 @@ public abstract class NativeTranslatorToCAst extends NativeBridge {
|
||||||
|
|
||||||
protected final String sourceFileName;
|
protected final String sourceFileName;
|
||||||
|
|
||||||
protected NativeTranslatorToCAst(CAst Ast,
|
protected NativeTranslatorToCAst(CAst Ast, URL sourceURL, String sourceFileName) {
|
||||||
URL sourceURL,
|
|
||||||
String sourceFileName)
|
|
||||||
{
|
|
||||||
super(Ast);
|
super(Ast);
|
||||||
this.sourceURL = sourceURL;
|
this.sourceURL = sourceURL;
|
||||||
this.sourceFileName = sourceFileName;
|
this.sourceFileName = sourceFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private String getLocalFile() {
|
private String getLocalFile() {
|
||||||
return sourceFileName;
|
return sourceFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private String getFile() {
|
private String getFile() {
|
||||||
return sourceURL.getFile();
|
return sourceURL.getFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Position makeLocation(final int fl,
|
@SuppressWarnings("unused")
|
||||||
final int fc,
|
private Position makeLocation(final int fl, final int fc, final int ll, final int lc) {
|
||||||
final int ll,
|
|
||||||
final int lc)
|
|
||||||
{
|
|
||||||
return new AbstractSourcePosition() {
|
return new AbstractSourcePosition() {
|
||||||
public int getFirstLine() { return fl; }
|
public int getFirstLine() {
|
||||||
public int getLastLine() { return ll; }
|
return fl;
|
||||||
public int getFirstCol() { return fc; }
|
}
|
||||||
public int getLastCol() { return lc; }
|
|
||||||
public URL getURL() { return sourceURL; }
|
public int getLastLine() {
|
||||||
public InputStream getInputStream() throws IOException {
|
return ll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFirstCol() {
|
||||||
|
return fc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastCol() {
|
||||||
|
return lc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL getURL() {
|
||||||
|
return sourceURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream getInputStream() throws IOException {
|
||||||
return new FileInputStream(sourceFileName);
|
return new FileInputStream(sourceFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String urlString = sourceURL.toString();
|
String urlString = sourceURL.toString();
|
||||||
if (urlString.lastIndexOf( File.separator ) == -1)
|
if (urlString.lastIndexOf(File.separator) == -1)
|
||||||
return "["+fl+":"+fc+"]->["+ll+":"+lc+"]";
|
return "[" + fl + ":" + fc + "]->[" + ll + ":" + lc + "]";
|
||||||
else
|
else
|
||||||
return urlString.substring(urlString.lastIndexOf(File.separator)+1)+"@["+fl+":"+fc+"]->["+ll+":"+lc+"]";
|
return urlString.substring(urlString.lastIndexOf(File.separator) + 1) + "@[" + fl + ":" + fc + "]->[" + ll + ":" + lc
|
||||||
|
+ "]";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,7 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package com.ibm.wala.cast.ir.translator;
|
package com.ibm.wala.cast.ir.translator;
|
||||||
|
|
||||||
import java.io.IOException;
|
import com.ibm.wala.cast.tree.CAstEntity;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.ibm.wala.cast.tree.*;
|
|
||||||
|
|
||||||
public interface TranslatorToIR {
|
public interface TranslatorToIR {
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ public interface CAstType {
|
||||||
public interface Class extends Reference {
|
public interface Class extends Reference {
|
||||||
boolean isInterface();
|
boolean isInterface();
|
||||||
|
|
||||||
Collection getQualifiers();
|
Collection<CAstQualifier> getQualifiers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Array extends Reference {
|
public interface Array extends Reference {
|
||||||
|
|
|
@ -21,7 +21,7 @@ import com.ibm.wala.util.graph.traverse.DFSDiscoverTimeIterator;
|
||||||
|
|
||||||
public class CAstFunctions {
|
public class CAstFunctions {
|
||||||
|
|
||||||
public static CAstNode findIf(CAstNode tree, Filter f) {
|
public static CAstNode findIf(CAstNode tree, Filter<CAstNode> f) {
|
||||||
if (f.accepts(tree)) {
|
if (f.accepts(tree)) {
|
||||||
return tree;
|
return tree;
|
||||||
} else {
|
} else {
|
||||||
|
@ -73,7 +73,7 @@ public class CAstFunctions {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Iterator findAll(CAstNode tree, Filter f) {
|
public static Iterator<CAstNode> findAll(CAstNode tree, Filter<?> f) {
|
||||||
return new FilterIterator<CAstNode>(iterateNodes(tree), f);
|
return new FilterIterator<CAstNode>(iterateNodes(tree), f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue