merge of development on internal branch. Support for cross-building JNI code for Windows, and refactoring of abstract loader support.
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3242 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
aad54f7abc
commit
3e198f8244
|
@ -35,7 +35,7 @@ CAPA_SOURCES = $(notdir $(wildcard jni/*.cpp))
|
|||
CAPA_OBJECTS = $(patsubst %.cpp,$(C_GENERATED)%.o,$(CAPA_SOURCES))
|
||||
|
||||
ifeq ($(PLATFORM),windows)
|
||||
ALL_FLAGS = -gstabs+ $(TRACE) $(INCLUDES)
|
||||
ALL_FLAGS = -gstabs+ $(TRACE) $(INCLUDES) -DBUILD_CAST_DLL
|
||||
DLLEXT = dll
|
||||
else
|
||||
ifeq ($(PLATFORM),Darwin)
|
||||
|
@ -48,7 +48,7 @@ endif
|
|||
endif
|
||||
|
||||
ifeq ($(PLATFORM),windows)
|
||||
CC_LDFLAGS = -shared -Wl,--add-stdcall-alias
|
||||
CC_LDFLAGS = -shared -Wl,--add-stdcall-alias -Wl,-export-all-symbols
|
||||
LIBPREFIX =
|
||||
else
|
||||
ifeq ($(PLATFORM),Darwin)
|
||||
|
@ -83,5 +83,5 @@ $(DOMO_AST_BIN)$(LIBPREFIX)cast.$(DLLEXT): $(CAPA_OBJECTS)
|
|||
$(CC) $(CC_LDFLAGS) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(DOMO_AST_BIN)$(LIBPREFIX)cast.$(DLLEXT) $(C_GENERATED) hs_err_pid*
|
||||
rm -rf $(C_GENERATED) hs_err_pid*
|
||||
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
#
|
||||
|
||||
# The root of the java SDK to use (must end in /)
|
||||
JAVA_SDK = /opt/sun-jdk-1.5.0.08/
|
||||
JAVA_SDK = /System/Library/Frameworks/JavaVM.framework/Home/
|
||||
|
||||
# Path .class files of the com.ibm.domo.ast Java code (must end in /)
|
||||
DOMO_AST_BIN = /my/workspace/path/com.ibm.domo.ast/bin/
|
||||
DOMO_AST_BIN = /SednaWorkspace/com.ibm.wala.cast/bin/
|
||||
|
||||
# Extra stuff needed in the classpath of javah (must start with path separator)
|
||||
JAVAH_CLASS_PATH = :/my/workspace/path/com.ibm.capa.ast/bin/
|
||||
JAVAH_CLASS_PATH = :/SednaWorkspace/com.ibm.wala.cast/bin/
|
||||
|
||||
# enable debugging flags
|
||||
TRACE =
|
||||
|
|
|
@ -16,7 +16,7 @@ using namespace std;
|
|||
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if __WIN32__
|
||||
#ifdef BUILD_CAST_DLL
|
||||
#define DLLEXPORT __declspec(dllexport)
|
||||
#else
|
||||
|
@ -46,6 +46,7 @@ protected:
|
|||
jmethodID linkedListInit;
|
||||
jmethodID linkedListAdd;
|
||||
jfieldID astField;
|
||||
jclass AbstractScriptEntity;
|
||||
|
||||
private:
|
||||
jclass CAstNode;
|
||||
|
@ -55,6 +56,7 @@ private:
|
|||
jclass NativeEntity;
|
||||
jclass NativeCodeEntity;
|
||||
jclass NativeFieldEntity;
|
||||
jclass NativeGlobalEntity;
|
||||
jclass NativeBridge;
|
||||
jclass NativeTranslatorToCAst;
|
||||
jmethodID castPrint;
|
||||
|
@ -90,6 +92,7 @@ private:
|
|||
jmethodID addScopedEntity;
|
||||
jmethodID entityGetType;
|
||||
jmethodID fieldEntityInit;
|
||||
jmethodID globalEntityInit;
|
||||
jmethodID _makeLocation;
|
||||
jmethodID setNodePosition;
|
||||
jmethodID setNodeType;
|
||||
|
@ -220,6 +223,8 @@ public:
|
|||
|
||||
jobject makeFieldEntity(jobject, jobject, bool, list<jobject> *);
|
||||
|
||||
jobject makeGlobalEntity(char *, list<jobject> *);
|
||||
|
||||
jobject getEntityAst(jobject);
|
||||
|
||||
virtual void setEntityAst(jobject, jobject);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define EXCEPTIONS_H
|
||||
|
||||
/**
|
||||
* The combination of the macros and the Exceptions class declared
|
||||
* The combination of the macroes and the Exceptions class declared
|
||||
* in this file is used to provide a (shaky) veneer of exception handling
|
||||
* to JNI code.
|
||||
*
|
||||
|
@ -45,7 +45,7 @@ extern "C" {
|
|||
#define THROW_ANY_EXCEPTION(CPP_EXP_NAME) \
|
||||
(CPP_EXP_NAME).throwAnyException(__FILE__, __LINE__)
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if __WIN32__
|
||||
#ifdef BUILD_CAST_DLL
|
||||
#define DLLEXPORT __declspec(dllexport)
|
||||
#else
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#undef VOID
|
||||
#undef CONST
|
||||
#undef ERROR
|
||||
#undef THIS
|
||||
#endif
|
||||
|
||||
_CAstNodeType(ASSERT)
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#define _CAstQualifier( __id ) \
|
||||
{ \
|
||||
jfieldID f##__id = env->GetStaticFieldID(CAstQualifier, #__id, "Lcom/ibm/wala/cast/tree/CAstQualifier;"); \
|
||||
jobject o##__id = env->GetStaticObjectField(CAstNode, f##__id); \
|
||||
jobject o##__id = env->GetStaticObjectField(CAstQualifier, f##__id); \
|
||||
CAstWrapper::__id = env->NewGlobalRef(o##__id); \
|
||||
THROW_ANY_EXCEPTION(exp); \
|
||||
}
|
||||
|
|
|
@ -54,14 +54,13 @@ static const char *objectSig = "(" __OBJS ")" __CNS;
|
|||
|
||||
#define XLATOR_CLS_NAME "NativeTranslatorToCAst"
|
||||
|
||||
#define XLATOR_CLS(cls) XLATOR_PKG XLATOR_CLS_NAME "$" cls
|
||||
|
||||
static const char *XlatorCls = XLATOR_PKG XLATOR_CLS_NAME;
|
||||
|
||||
static const char *EntityCls = XLATOR_CLS("NativeEntity");
|
||||
static const char *CodeEntityCls = XLATOR_CLS("NativeCodeEntity");
|
||||
static const char *ScriptCls = XLATOR_CLS("NativeScriptEntity");
|
||||
static const char *FieldCls = XLATOR_CLS("NativeFieldEntity");
|
||||
static const char *EntityCls = XLATOR_PKG "AbstractEntity";
|
||||
static const char *CodeEntityCls = XLATOR_PKG "AbstractCodeEntity";
|
||||
static const char *ScriptCls = XLATOR_PKG "AbstractScriptEntity";
|
||||
static const char *FieldCls = XLATOR_PKG "AbstractFieldEntity";
|
||||
static const char *GlobalCls = XLATOR_PKG "AbstractGlobalEntity";
|
||||
|
||||
CAstWrapper::CAstWrapper(JNIEnv *env, Exceptions &ex, jobject xlator)
|
||||
: java_ex(ex), env(env), xlator(xlator)
|
||||
|
@ -83,43 +82,84 @@ CAstWrapper::CAstWrapper(JNIEnv *env, Exceptions &ex, jobject xlator)
|
|||
THROW_ANY_EXCEPTION(java_ex);
|
||||
|
||||
this->NativeEntity = env->FindClass(EntityCls);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->addScopedEntity = env->GetMethodID(NativeEntity, "addScopedEntity", "(Lcom/ibm/wala/cast/tree/CAstNode;Lcom/ibm/wala/cast/tree/CAstEntity;)V");
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->entityGetType = env->GetMethodID(NativeEntity, "getType", "()Lcom/ibm/wala/cast/tree/CAstType;");
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
|
||||
this->NativeCodeEntity = env->FindClass(CodeEntityCls);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->astField = env->GetFieldID(NativeCodeEntity, "Ast", "Lcom/ibm/wala/cast/tree/CAstNode;");
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->codeSetGotoTarget = env->GetMethodID(NativeCodeEntity, "setGotoTarget", "(Lcom/ibm/wala/cast/tree/CAstNode;Lcom/ibm/wala/cast/tree/CAstNode;)V");
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->codeSetLabelledGotoTarget = env->GetMethodID(NativeCodeEntity, "setLabelledGotoTarget", "(Lcom/ibm/wala/cast/tree/CAstNode;Lcom/ibm/wala/cast/tree/CAstNode;Ljava/lang/Object;)V");
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->setNodePosition = env->GetMethodID(NativeCodeEntity, "setNodePosition", "(Lcom/ibm/wala/cast/tree/CAstNode;Lcom/ibm/wala/cast/tree/CAstSourcePositionMap$Position;)V");
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->setNodeType = env->GetMethodID(NativeCodeEntity, "setNodeType", "(Lcom/ibm/wala/cast/tree/CAstNode;Lcom/ibm/wala/cast/tree/CAstType;)V");
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->setPosition = env->GetMethodID(NativeEntity, "setPosition", "(Lcom/ibm/wala/cast/tree/CAstSourcePositionMap$Position;)V");
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
|
||||
this->NativeFieldEntity = env->FindClass(FieldCls);
|
||||
this->fieldEntityInit = env->GetMethodID(NativeFieldEntity, "<init>", "(Lcom/ibm/wala/cast/ir/translator/NativeTranslatorToCAst;Ljava/lang/String;Ljava/util/Set;Z" __CES ")V");
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->fieldEntityInit = env->GetMethodID(NativeFieldEntity, "<init>", "(Ljava/lang/String;Ljava/util/Set;Z" __CES ")V");
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
|
||||
this->NativeGlobalEntity = env->FindClass(GlobalCls);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->globalEntityInit = env->GetMethodID(NativeGlobalEntity, "<init>", "(Ljava/lang/String;Ljava/util/Set;)V");
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
|
||||
this->AbstractScriptEntity = env->FindClass(ScriptCls);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
|
||||
this->makeNode0 = env->GetMethodID(CAstInterface, __MN, zeroSig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->makeNode1 = env->GetMethodID(CAstInterface, __MN, oneSig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->makeNode2 = env->GetMethodID(CAstInterface, __MN, twoSig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->makeNode3 = env->GetMethodID(CAstInterface, __MN, threeSig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->makeNode4 = env->GetMethodID(CAstInterface, __MN, fourSig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->makeNode5 = env->GetMethodID(CAstInterface, __MN, fiveSig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->makeNode6 = env->GetMethodID(CAstInterface, __MN, sixSig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->makeNodeNary = env->GetMethodID(CAstInterface, __MN, narySig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->makeNode1Nary = env->GetMethodID(CAstInterface, __MN, oneNarySig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
|
||||
this->makeBool = env->GetMethodID(CAstInterface, __MC, boolSig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->makeChar = env->GetMethodID(CAstInterface, __MC, charSig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->makeShort = env->GetMethodID(CAstInterface, __MC, shortSig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->makeInt = env->GetMethodID(CAstInterface, __MC, intSig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->makeLong = env->GetMethodID(CAstInterface, __MC, longSig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->makeDouble = env->GetMethodID(CAstInterface, __MC, doubleSig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->makeFloat = env->GetMethodID(CAstInterface, __MC, floatSig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->makeObject = env->GetMethodID(CAstInterface, __MC, objectSig);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
|
||||
this->getChild = env->GetMethodID(CAstNode, "getChild", "(I)" __CNS);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->_getChildCount = env->GetMethodID(CAstNode, "getChildCount", "()I");
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->getValue = env->GetMethodID(CAstNode, "getValue", "()" __OBJS);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
this->_getKind = env->GetMethodID(CAstNode, "getKind", "()I");
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
|
||||
jclass CAstMemberReference = env->FindClass( __CRN );
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
|
@ -493,7 +533,7 @@ jobject CAstWrapper::makeSet(list<jobject> *elts) {
|
|||
if (elts == NULL) return set;
|
||||
|
||||
for(list<jobject>::iterator it=elts->begin(); it!=elts->end(); it++) {
|
||||
env->CallVoidMethod(set, hashSetAdd, *it);
|
||||
env->CallBooleanMethod(set, hashSetAdd, *it);
|
||||
}
|
||||
|
||||
return set;
|
||||
|
@ -506,7 +546,7 @@ jobject CAstWrapper::makeList(list<jobject> *elts) {
|
|||
if (elts == NULL) return set;
|
||||
|
||||
for(list<jobject>::iterator it=elts->begin(); it!=elts->end(); it++) {
|
||||
env->CallVoidMethod(set, linkedListAdd, *it);
|
||||
env->CallBooleanMethod(set, linkedListAdd, *it);
|
||||
}
|
||||
|
||||
return set;
|
||||
|
@ -629,12 +669,24 @@ jobject CAstWrapper::makeLocation(int fl, int fc, int ll, int lc) {
|
|||
|
||||
jobject CAstWrapper::makeFieldEntity(jobject declaringClass, jobject name, bool isStatic, list<jobject> *modifiers) {
|
||||
|
||||
jobject entity = env->NewObject(NativeFieldEntity, fieldEntityInit, xlator, getConstantValue(name), makeSet(modifiers), isStatic, declaringClass);
|
||||
jobject entity = env->NewObject(NativeFieldEntity, fieldEntityInit, getConstantValue(name), makeSet(modifiers), isStatic, declaringClass);
|
||||
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
return entity;
|
||||
}
|
||||
|
||||
jobject CAstWrapper::makeGlobalEntity(char *name, list<jobject> *modifiers) {
|
||||
char *safeData = strdup(name);
|
||||
jobject val = env->NewStringUTF( safeData );
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
delete safeData;
|
||||
|
||||
jobject entity = env->NewObject(NativeGlobalEntity, globalEntityInit, val, makeSet(modifiers));
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
jobject CAstWrapper::getEntityAst(jobject entity) {
|
||||
jobject result = env->GetObjectField(entity, astField);
|
||||
THROW_ANY_EXCEPTION(java_ex);
|
||||
|
|
|
@ -5,14 +5,13 @@
|
|||
#include "Exceptions.h"
|
||||
#include "com_ibm_wala_cast_ir_translator_NativeBridge.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_ibm_wala_cast_ir_translator_NativeBridge_initialize(
|
||||
JNIEnv *env,
|
||||
jclass cls)
|
||||
{
|
||||
|
||||
fprintf(stderr, "got here\n");
|
||||
|
||||
TRY(exp, env)
|
||||
|
||||
jclass CAstNode = env->FindClass( "com/ibm/wala/cast/tree/CAstNode" );
|
||||
|
@ -39,4 +38,4 @@ Java_com_ibm_wala_cast_ir_translator_NativeBridge_initialize(
|
|||
CATCH()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,127 +1,127 @@
|
|||
package com.ibm.wala.cast.ir.ssa;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.ssa.SymbolTable;
|
||||
import com.ibm.wala.types.FieldReference;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
||||
public class AstIsDefinedInstruction extends SSAInstruction {
|
||||
private final FieldReference fieldRef;
|
||||
|
||||
private final int fieldVal;
|
||||
|
||||
private final int rval;
|
||||
|
||||
private final int lval;
|
||||
|
||||
private AstIsDefinedInstruction(int lval, int rval, int fieldVal, FieldReference fieldRef) {
|
||||
this.lval = lval;
|
||||
this.rval = rval;
|
||||
this.fieldVal = fieldVal;
|
||||
this.fieldRef = fieldRef;
|
||||
}
|
||||
|
||||
public AstIsDefinedInstruction(int lval, int rval, FieldReference fieldRef) {
|
||||
this.lval = lval;
|
||||
this.rval = rval;
|
||||
this.fieldVal = -1;
|
||||
this.fieldRef = fieldRef;
|
||||
}
|
||||
|
||||
public AstIsDefinedInstruction(int lval, int rval, int fieldVal) {
|
||||
this.lval = lval;
|
||||
this.rval = rval;
|
||||
this.fieldVal = fieldVal;
|
||||
this.fieldRef = null;
|
||||
}
|
||||
|
||||
public AstIsDefinedInstruction(int lval, int rval) {
|
||||
this.lval = lval;
|
||||
this.rval = rval;
|
||||
this.fieldVal = -1;
|
||||
this.fieldRef = null;
|
||||
}
|
||||
|
||||
public SSAInstruction copyForSSA(int[] defs, int[] uses) {
|
||||
if (Assertions.verifyAssertions) {
|
||||
Assertions._assert(fieldVal == -1 || fieldRef == null);
|
||||
}
|
||||
|
||||
return new AstIsDefinedInstruction((defs == null) ? lval : defs[0], (uses == null) ? rval : uses[0],
|
||||
(uses == null || fieldVal == -1) ? fieldVal : uses[1], fieldRef);
|
||||
}
|
||||
|
||||
public String toString(SymbolTable symbolTable) {
|
||||
if (fieldVal == -1 && fieldRef == null) {
|
||||
return getValueString(symbolTable, lval) + " = isDefined(" + getValueString(symbolTable, rval) + ")";
|
||||
} else if (fieldVal == -1) {
|
||||
return getValueString(symbolTable, lval) + " = isDefined(" + getValueString(symbolTable, rval) + "," + fieldRef.getName()
|
||||
+ ")";
|
||||
} else if (fieldRef == null) {
|
||||
return getValueString(symbolTable, lval) + " = isDefined(" + getValueString(symbolTable, rval) + ","
|
||||
+ getValueString(symbolTable, fieldVal) + ")";
|
||||
} else {
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void visit(IVisitor v) {
|
||||
((AstInstructionVisitor) v).visitIsDefined(this);
|
||||
}
|
||||
|
||||
public Collection<TypeReference> getExceptionTypes() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
public boolean hasDef() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getDef() {
|
||||
return lval;
|
||||
}
|
||||
|
||||
public int getDef(int i) {
|
||||
if (Assertions.verifyAssertions) {
|
||||
Assertions._assert(i == 0);
|
||||
}
|
||||
|
||||
return lval;
|
||||
}
|
||||
|
||||
public int getNumberOfDefs() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int getNumberOfUses() {
|
||||
return (fieldVal == -1) ? 1 : 2;
|
||||
}
|
||||
|
||||
public int getUse(int j) {
|
||||
if (j == 0) {
|
||||
return rval;
|
||||
} else if (j == 1 && fieldVal != -1) {
|
||||
return fieldVal;
|
||||
} else {
|
||||
Assertions.UNREACHABLE();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFallThrough() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return 3077 * fieldVal * rval;
|
||||
}
|
||||
|
||||
public FieldReference getFieldRef() {
|
||||
return fieldRef;
|
||||
}
|
||||
}
|
||||
package com.ibm.wala.cast.ir.ssa;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import com.ibm.wala.ssa.SSAInstruction;
|
||||
import com.ibm.wala.ssa.SymbolTable;
|
||||
import com.ibm.wala.types.FieldReference;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
||||
public class AstIsDefinedInstruction extends SSAInstruction {
|
||||
private final FieldReference fieldRef;
|
||||
|
||||
private final int fieldVal;
|
||||
|
||||
private final int rval;
|
||||
|
||||
private final int lval;
|
||||
|
||||
private AstIsDefinedInstruction(int lval, int rval, int fieldVal, FieldReference fieldRef) {
|
||||
this.lval = lval;
|
||||
this.rval = rval;
|
||||
this.fieldVal = fieldVal;
|
||||
this.fieldRef = fieldRef;
|
||||
}
|
||||
|
||||
public AstIsDefinedInstruction(int lval, int rval, FieldReference fieldRef) {
|
||||
this.lval = lval;
|
||||
this.rval = rval;
|
||||
this.fieldVal = -1;
|
||||
this.fieldRef = fieldRef;
|
||||
}
|
||||
|
||||
public AstIsDefinedInstruction(int lval, int rval, int fieldVal) {
|
||||
this.lval = lval;
|
||||
this.rval = rval;
|
||||
this.fieldVal = fieldVal;
|
||||
this.fieldRef = null;
|
||||
}
|
||||
|
||||
public AstIsDefinedInstruction(int lval, int rval) {
|
||||
this.lval = lval;
|
||||
this.rval = rval;
|
||||
this.fieldVal = -1;
|
||||
this.fieldRef = null;
|
||||
}
|
||||
|
||||
public SSAInstruction copyForSSA(int[] defs, int[] uses) {
|
||||
if (Assertions.verifyAssertions) {
|
||||
Assertions._assert(fieldVal == -1 || fieldRef == null);
|
||||
}
|
||||
|
||||
return new AstIsDefinedInstruction((defs == null) ? lval : defs[0], (uses == null) ? rval : uses[0],
|
||||
(uses == null || fieldVal == -1) ? fieldVal : uses[1], fieldRef);
|
||||
}
|
||||
|
||||
public String toString(SymbolTable symbolTable) {
|
||||
if (fieldVal == -1 && fieldRef == null) {
|
||||
return getValueString(symbolTable, lval) + " = isDefined(" + getValueString(symbolTable, rval) + ")";
|
||||
} else if (fieldVal == -1) {
|
||||
return getValueString(symbolTable, lval) + " = isDefined(" + getValueString(symbolTable, rval) + "," + fieldRef.getName()
|
||||
+ ")";
|
||||
} else if (fieldRef == null) {
|
||||
return getValueString(symbolTable, lval) + " = isDefined(" + getValueString(symbolTable, rval) + ","
|
||||
+ getValueString(symbolTable, fieldVal) + ")";
|
||||
} else {
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void visit(IVisitor v) {
|
||||
((AstInstructionVisitor) v).visitIsDefined(this);
|
||||
}
|
||||
|
||||
public Collection<TypeReference> getExceptionTypes() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
public boolean hasDef() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getDef() {
|
||||
return lval;
|
||||
}
|
||||
|
||||
public int getDef(int i) {
|
||||
if (Assertions.verifyAssertions) {
|
||||
Assertions._assert(i == 0);
|
||||
}
|
||||
|
||||
return lval;
|
||||
}
|
||||
|
||||
public int getNumberOfDefs() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int getNumberOfUses() {
|
||||
return (fieldVal == -1) ? 1 : 2;
|
||||
}
|
||||
|
||||
public int getUse(int j) {
|
||||
if (j == 0) {
|
||||
return rval;
|
||||
} else if (j == 1 && fieldVal != -1) {
|
||||
return fieldVal;
|
||||
} else {
|
||||
Assertions.UNREACHABLE();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFallThrough() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return 3077 * fieldVal * rval;
|
||||
}
|
||||
|
||||
public FieldReference getFieldRef() {
|
||||
return fieldRef;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.ibm.wala.cast.ir.translator;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.ibm.wala.cast.tree.CAstQualifier;
|
||||
import com.ibm.wala.cast.tree.CAstType;
|
||||
|
||||
public class AbstractClassEntity extends AbstractDataEntity {
|
||||
private final CAstType.Class type;
|
||||
|
||||
public AbstractClassEntity(CAstType.Class type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "class " + type.getName();
|
||||
}
|
||||
|
||||
public int getKind() {
|
||||
return TYPE_ENTITY;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return type.getName();
|
||||
}
|
||||
|
||||
public CAstType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Collection<CAstQualifier> getQualifiers() {
|
||||
return type.getQualifiers();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.ibm.wala.cast.ir.translator;
|
||||
|
||||
import com.ibm.wala.cast.tree.CAstControlFlowMap;
|
||||
import com.ibm.wala.cast.tree.CAstNode;
|
||||
import com.ibm.wala.cast.tree.CAstNodeTypeMap;
|
||||
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.CAstControlFlowRecorder;
|
||||
import com.ibm.wala.cast.tree.impl.CAstNodeTypeMapRecorder;
|
||||
import com.ibm.wala.cast.tree.impl.CAstSourcePositionRecorder;
|
||||
|
||||
public abstract class AbstractCodeEntity extends AbstractEntity {
|
||||
protected final CAstSourcePositionRecorder src = new CAstSourcePositionRecorder();
|
||||
|
||||
protected final CAstControlFlowRecorder cfg = new CAstControlFlowRecorder(src);
|
||||
|
||||
protected final CAstNodeTypeMapRecorder types = new CAstNodeTypeMapRecorder();
|
||||
|
||||
protected final CAstType type;
|
||||
|
||||
protected CAstNode Ast;
|
||||
|
||||
protected AbstractCodeEntity(CAstType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public CAstNode getAST() {
|
||||
return Ast;
|
||||
}
|
||||
|
||||
public CAstType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public CAstControlFlowMap getControlFlow() {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public CAstSourcePositionMap getSourceMap() {
|
||||
return src;
|
||||
}
|
||||
|
||||
public CAstNodeTypeMap getNodeTypeMap() {
|
||||
return types;
|
||||
}
|
||||
|
||||
public void setGotoTarget(CAstNode from, CAstNode to) {
|
||||
setLabelledGotoTarget(from, to, null);
|
||||
}
|
||||
|
||||
public void setLabelledGotoTarget(CAstNode from, CAstNode to, Object label) {
|
||||
if (!cfg.isMapped(from)) {
|
||||
cfg.map(from, from);
|
||||
}
|
||||
if (!cfg.isMapped(to)) {
|
||||
cfg.map(to, to);
|
||||
}
|
||||
cfg.add(from, to, label);
|
||||
}
|
||||
|
||||
public void setNodePosition(CAstNode n, Position pos) {
|
||||
src.setPosition(n, pos);
|
||||
}
|
||||
|
||||
public void setNodeType(CAstNode n, CAstType type) {
|
||||
types.add(n, type);
|
||||
}
|
||||
|
||||
public void setAst(CAstNode Ast) {
|
||||
this.Ast = Ast;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.ibm.wala.cast.ir.translator;
|
||||
|
||||
import com.ibm.wala.cast.tree.CAstControlFlowMap;
|
||||
import com.ibm.wala.cast.tree.CAstNode;
|
||||
import com.ibm.wala.cast.tree.CAstNodeTypeMap;
|
||||
import com.ibm.wala.cast.tree.CAstSourcePositionMap;
|
||||
|
||||
abstract class AbstractDataEntity extends AbstractEntity {
|
||||
public CAstNode getAST() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public CAstControlFlowMap getControlFlow() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public CAstSourcePositionMap getSourceMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public CAstNodeTypeMap getNodeTypeMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String[] getArgumentNames() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
public CAstNode[] getArgumentDefaults() {
|
||||
return new CAstNode[0];
|
||||
}
|
||||
|
||||
public int getArgumentCount() {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.ibm.wala.cast.ir.translator;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import com.ibm.wala.cast.tree.CAstEntity;
|
||||
import com.ibm.wala.cast.tree.CAstNode;
|
||||
import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
|
||||
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 AbstractEntity implements CAstEntity {
|
||||
private Position sourcePosition;
|
||||
|
||||
private final Map<CAstNode, Collection<CAstEntity>> scopedEntities = HashMapFactory.make();
|
||||
|
||||
public Map<CAstNode, Collection<CAstEntity>> getAllScopedEntities() {
|
||||
return scopedEntities;
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setPosition(Position pos) {
|
||||
sourcePosition = pos;
|
||||
}
|
||||
|
||||
public Position getPosition() {
|
||||
return sourcePosition;
|
||||
}
|
||||
|
||||
public Iterator<?> getScopedEntities(CAstNode construct) {
|
||||
if (scopedEntities.containsKey(construct)) {
|
||||
return scopedEntities.get(construct).iterator();
|
||||
} else {
|
||||
return EmptyIterator.instance();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void addScopedEntity(CAstNode construct, CAstEntity child) {
|
||||
if (!scopedEntities.containsKey(construct)) {
|
||||
Collection<CAstEntity> set = HashSetFactory.make(1);
|
||||
scopedEntities.put(construct, set);
|
||||
}
|
||||
scopedEntities.get(construct).add(child);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.ibm.wala.cast.ir.translator;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.cast.tree.CAstEntity;
|
||||
import com.ibm.wala.cast.tree.CAstQualifier;
|
||||
import com.ibm.wala.cast.tree.CAstType;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
||||
class AbstractFieldEntity extends AbstractDataEntity {
|
||||
private final String name;
|
||||
|
||||
private final Set<CAstQualifier> modifiers;
|
||||
|
||||
private final CAstEntity declaringClass;
|
||||
|
||||
public AbstractFieldEntity(String name, Set<CAstQualifier> modifiers, boolean isStatic, CAstEntity declaringClass) {
|
||||
this.name = name;
|
||||
this.declaringClass = declaringClass;
|
||||
|
||||
this.modifiers = new HashSet<CAstQualifier>();
|
||||
if (modifiers != null) {
|
||||
this.modifiers.addAll(modifiers);
|
||||
}
|
||||
if (isStatic) {
|
||||
this.modifiers.add(CAstQualifier.STATIC);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "field " + name + " of " + declaringClass.getName();
|
||||
}
|
||||
|
||||
public int getKind() {
|
||||
return FIELD_ENTITY;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public CAstType getType() {
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Collection<CAstQualifier> getQualifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.ibm.wala.cast.ir.translator;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.cast.tree.CAstQualifier;
|
||||
import com.ibm.wala.cast.tree.CAstType;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
||||
public class AbstractGlobalEntity extends AbstractDataEntity {
|
||||
private final String name;
|
||||
|
||||
private final Set<CAstQualifier> modifiers;
|
||||
|
||||
public AbstractGlobalEntity(String name, Set<CAstQualifier> modifiers) {
|
||||
this.name = name;
|
||||
this.modifiers = new HashSet<CAstQualifier>();
|
||||
if (modifiers != null) {
|
||||
this.modifiers.addAll(modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "global " + name;
|
||||
}
|
||||
|
||||
public int getKind() {
|
||||
return GLOBAL_ENTITY;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public CAstType getType() {
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Collection<CAstQualifier> getQualifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package com.ibm.wala.cast.ir.translator;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import com.ibm.wala.cast.tree.CAstNode;
|
||||
import com.ibm.wala.cast.tree.CAstQualifier;
|
||||
import com.ibm.wala.cast.tree.CAstType;
|
||||
|
||||
public class AbstractScriptEntity extends AbstractCodeEntity {
|
||||
private final File file;
|
||||
|
||||
public AbstractScriptEntity(File file, CAstType type) {
|
||||
super(type);
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public AbstractScriptEntity(String file, CAstType type) {
|
||||
this(new File(file), type);
|
||||
}
|
||||
|
||||
public int getKind() {
|
||||
return SCRIPT_ENTITY;
|
||||
}
|
||||
|
||||
protected File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "script " + file.getName();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "script " + file.getName();
|
||||
}
|
||||
|
||||
public String[] getArgumentNames() {
|
||||
return new String[] { "script object" };
|
||||
}
|
||||
|
||||
public CAstNode[] getArgumentDefaults() {
|
||||
return new CAstNode[0];
|
||||
}
|
||||
|
||||
public int getArgumentCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public Collection<CAstQualifier> getQualifiers() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
}
|
|
@ -30,7 +30,6 @@ import com.ibm.wala.shrikeBT.BinaryOpInstruction;
|
|||
import com.ibm.wala.shrikeBT.ConditionalBranchInstruction;
|
||||
import com.ibm.wala.shrikeBT.IBinaryOpInstruction;
|
||||
import com.ibm.wala.shrikeBT.IConditionalBranchInstruction;
|
||||
import com.ibm.wala.shrikeBT.IInstruction;
|
||||
import com.ibm.wala.shrikeBT.IUnaryOpInstruction;
|
||||
import com.ibm.wala.shrikeBT.ShiftInstruction;
|
||||
import com.ibm.wala.ssa.*;
|
||||
|
@ -38,11 +37,9 @@ import com.ibm.wala.types.FieldReference;
|
|||
import com.ibm.wala.types.TypeName;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
import com.ibm.wala.util.collections.MapIterator;
|
||||
import com.ibm.wala.util.collections.Pair;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
import com.ibm.wala.util.functions.Function;
|
||||
import com.ibm.wala.util.graph.INodeWithNumber;
|
||||
import com.ibm.wala.util.graph.impl.SparseNumberedGraph;
|
||||
import com.ibm.wala.util.intset.IntSet;
|
||||
|
@ -2319,6 +2316,16 @@ public abstract class AstTranslator extends CAstVisitor implements ArrayOpHandle
|
|||
defineField(topEntity, (WalkContext) context, n);
|
||||
}
|
||||
|
||||
protected boolean visitGlobalEntity(CAstEntity n, Context context, CAstVisitor visitor) { /* empty */
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void leaveGlobalEntity(CAstEntity n, Context context, CAstVisitor visitor) {
|
||||
// Define a new field in the enclosing type, if the language we're
|
||||
// processing allows such.
|
||||
getGlobalScope().declare(new CAstSymbolImpl(n.getName()));
|
||||
}
|
||||
|
||||
protected boolean visitTypeEntity(CAstEntity n, Context context, Context typeContext, CAstVisitor visitor) {
|
||||
defineType(n, (WalkContext) context);
|
||||
return false;
|
||||
|
@ -2396,7 +2403,7 @@ public abstract class AstTranslator extends CAstVisitor implements ArrayOpHandle
|
|||
|
||||
private final Stack<Position> positions = new Stack<Position>();
|
||||
|
||||
protected Context makeLocalContext(Context context, CAstNode n) {
|
||||
protected Context makeLocalContext(Context context, CAstNode n) {
|
||||
return new LocalContext((WalkContext) context, makeLocalScope(n, ((WalkContext) context).currentScope()));
|
||||
}
|
||||
|
||||
|
@ -2420,7 +2427,7 @@ public abstract class AstTranslator extends CAstVisitor implements ArrayOpHandle
|
|||
}
|
||||
|
||||
context.cfg().setCurrentPosition(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (popPosition)
|
||||
|
@ -3458,17 +3465,23 @@ public abstract class AstTranslator extends CAstVisitor implements ArrayOpHandle
|
|||
wc.cfg().addInstruction(new AstEchoInstruction(rvals));
|
||||
}
|
||||
|
||||
protected void leaveInclude(final CAstNode n, Context c, CAstVisitor visitor) {
|
||||
WalkContext wc = (WalkContext) c;
|
||||
|
||||
CAstEntity included;
|
||||
public CAstEntity getIncludedEntity(CAstNode n) {
|
||||
if (n.getChild(0).getKind() == CAstNode.NAMED_ENTITY_REF) {
|
||||
assert namedEntityResolver != null;
|
||||
included = (CAstEntity) namedEntityResolver.get(n.getChild(0).getChild(0).getValue());
|
||||
return (CAstEntity) namedEntityResolver.get(n.getChild(0).getChild(0).getValue());
|
||||
} else {
|
||||
included = (CAstEntity) n.getChild(0).getValue();
|
||||
return (CAstEntity) n.getChild(0).getValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void leaveInclude(final CAstNode n,
|
||||
Context c,
|
||||
CAstVisitor visitor)
|
||||
{
|
||||
WalkContext wc = (WalkContext) c;
|
||||
|
||||
CAstEntity included = getIncludedEntity(n);
|
||||
|
||||
if (included == null) {
|
||||
Trace.println("cannot find include for " + CAstPrinter.print(n));
|
||||
Trace.println("from:\n" + namedEntityResolver);
|
||||
|
@ -3531,7 +3544,7 @@ public abstract class AstTranslator extends CAstVisitor implements ArrayOpHandle
|
|||
visitEntities(N, c, this);
|
||||
}
|
||||
|
||||
public static final class DefaultContext implements WalkContext {
|
||||
public final class DefaultContext implements WalkContext {
|
||||
private final AstTranslator t;
|
||||
|
||||
private final CAstEntity N;
|
||||
|
@ -3564,6 +3577,10 @@ public abstract class AstTranslator extends CAstVisitor implements ArrayOpHandle
|
|||
return N.getSourceMap();
|
||||
}
|
||||
|
||||
public CAstSourcePositionMap getInlinedSourceMap() {
|
||||
return inlinedSourceMap;
|
||||
}
|
||||
|
||||
public CAstControlFlowMap getControlFlow() {
|
||||
return N.getControlFlow();
|
||||
}
|
||||
|
@ -3594,9 +3611,12 @@ public abstract class AstTranslator extends CAstVisitor implements ArrayOpHandle
|
|||
public void translate(final CAstEntity N, final String nm) {
|
||||
if (DEBUG_TOP)
|
||||
Trace.println("translating " + nm);
|
||||
this.inlinedSourceMap = inlinedSourceMap;
|
||||
walkEntities(N, new DefaultContext(this, N, nm));
|
||||
}
|
||||
|
||||
private CAstSourcePositionMap inlinedSourceMap;
|
||||
|
||||
private final Scope globalScope = makeGlobalScope();
|
||||
|
||||
protected Scope getGlobalScope() {
|
||||
|
|
|
@ -10,25 +10,38 @@
|
|||
*****************************************************************************/
|
||||
package com.ibm.wala.cast.ir.translator;
|
||||
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
|
||||
import com.ibm.wala.cast.tree.CAst;
|
||||
|
||||
public class NativeBridge {
|
||||
|
||||
protected final CAst Ast;
|
||||
|
||||
protected static boolean isInitialized;
|
||||
|
||||
protected NativeBridge(CAst Ast) {
|
||||
this.Ast = Ast;
|
||||
}
|
||||
|
||||
protected static native void initialize();
|
||||
|
||||
/*
|
||||
* trying to modularize shared library loading like this seems to
|
||||
* cause trouble on certain VMs. (guess which? :)
|
||||
*
|
||||
static {
|
||||
System.loadLibrary("cast");
|
||||
initialize();
|
||||
private static boolean amRunningInEclipse() {
|
||||
try {
|
||||
return ResourcesPlugin.getWorkspace() != null;
|
||||
} catch (IllegalStateException e) {
|
||||
return false;
|
||||
} catch (Error e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
isInitialized = false;
|
||||
if (amRunningInEclipse()) {
|
||||
System.loadLibrary("cast");
|
||||
initialize();
|
||||
isInitialized = true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -5,279 +5,16 @@ import java.io.FileInputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ibm.wala.cast.tree.CAst;
|
||||
import com.ibm.wala.cast.tree.CAstControlFlowMap;
|
||||
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 {
|
||||
|
||||
protected abstract class NativeEntity implements CAstEntity {
|
||||
private Position sourcePosition;
|
||||
|
||||
private final Map<CAstNode, Collection<CAstEntity>> scopedEntities = HashMapFactory.make();
|
||||
|
||||
public Map<CAstNode, Collection<CAstEntity>> getAllScopedEntities() {
|
||||
return scopedEntities;
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setPosition(Position pos) {
|
||||
sourcePosition = pos;
|
||||
}
|
||||
|
||||
public Position getPosition() {
|
||||
return sourcePosition;
|
||||
}
|
||||
|
||||
public Iterator<?> getScopedEntities(CAstNode construct) {
|
||||
if (scopedEntities.containsKey(construct)) {
|
||||
return scopedEntities.get(construct).iterator();
|
||||
} else {
|
||||
return EmptyIterator.instance();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void addScopedEntity(CAstNode construct, CAstEntity child) {
|
||||
if (!scopedEntities.containsKey(construct)) {
|
||||
Collection<CAstEntity> set = HashSetFactory.make(1);
|
||||
scopedEntities.put(construct, set);
|
||||
}
|
||||
scopedEntities.get(construct).add(child);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract class NativeCodeEntity extends NativeEntity {
|
||||
protected final CAstSourcePositionRecorder src = new CAstSourcePositionRecorder();
|
||||
|
||||
protected final CAstControlFlowRecorder cfg = new CAstControlFlowRecorder(src);
|
||||
|
||||
protected final CAstNodeTypeMapRecorder types = new CAstNodeTypeMapRecorder();
|
||||
|
||||
protected final CAstType type;
|
||||
|
||||
protected CAstNode Ast;
|
||||
|
||||
protected NativeCodeEntity(CAstType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public CAstNode getAST() {
|
||||
return Ast;
|
||||
}
|
||||
|
||||
public CAstType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public CAstControlFlowMap getControlFlow() {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public CAstSourcePositionMap getSourceMap() {
|
||||
return src;
|
||||
}
|
||||
|
||||
public CAstNodeTypeMap getNodeTypeMap() {
|
||||
return types;
|
||||
}
|
||||
|
||||
public void setGotoTarget(CAstNode from, CAstNode to) {
|
||||
setLabelledGotoTarget(from, to, null);
|
||||
}
|
||||
|
||||
public void setLabelledGotoTarget(CAstNode from, CAstNode to, Object label) {
|
||||
if (!cfg.isMapped(from)) {
|
||||
cfg.map(from, from);
|
||||
}
|
||||
if (!cfg.isMapped(to)) {
|
||||
cfg.map(to, to);
|
||||
}
|
||||
cfg.add(from, to, label);
|
||||
}
|
||||
|
||||
public void setNodePosition(CAstNode n, Position pos) {
|
||||
src.setPosition(n, pos);
|
||||
}
|
||||
|
||||
public void setNodeType(CAstNode n, CAstType type) {
|
||||
types.add(n, type);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract class NativeDataEntity extends NativeEntity {
|
||||
public CAstNode getAST() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public CAstControlFlowMap getControlFlow() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public CAstSourcePositionMap getSourceMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public CAstNodeTypeMap getNodeTypeMap() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String[] getArgumentNames() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
public CAstNode[] getArgumentDefaults() {
|
||||
return new CAstNode[0];
|
||||
}
|
||||
|
||||
public int getArgumentCount() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected class NativeFieldEntity extends NativeDataEntity {
|
||||
private final String name;
|
||||
|
||||
private final Set<CAstQualifier> modifiers;
|
||||
|
||||
private final CAstEntity declaringClass;
|
||||
|
||||
public NativeFieldEntity(String name, Set<CAstQualifier> modifiers, boolean isStatic, CAstEntity declaringClass) {
|
||||
this.name = name;
|
||||
this.declaringClass = declaringClass;
|
||||
|
||||
this.modifiers = new HashSet<CAstQualifier>();
|
||||
if (modifiers != null) {
|
||||
this.modifiers.addAll(modifiers);
|
||||
}
|
||||
if (isStatic) {
|
||||
this.modifiers.add(CAstQualifier.STATIC);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "field " + name + " of " + declaringClass.getName();
|
||||
}
|
||||
|
||||
public int getKind() {
|
||||
return FIELD_ENTITY;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public CAstType getType() {
|
||||
Assertions.UNREACHABLE();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Collection<CAstQualifier> getQualifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
}
|
||||
|
||||
protected class NativeClassEntity extends NativeDataEntity {
|
||||
private final CAstType.Class type;
|
||||
|
||||
public NativeClassEntity(CAstType.Class type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "class " + type.getName();
|
||||
}
|
||||
|
||||
public int getKind() {
|
||||
return TYPE_ENTITY;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return type.getName();
|
||||
}
|
||||
|
||||
public CAstType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Collection<CAstQualifier> getQualifiers() {
|
||||
return type.getQualifiers();
|
||||
}
|
||||
};
|
||||
|
||||
protected class NativeScriptEntity extends NativeCodeEntity {
|
||||
private final File file;
|
||||
|
||||
public NativeScriptEntity(File file, CAstType type) {
|
||||
super(type);
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public NativeScriptEntity(String file, CAstType type) {
|
||||
this(new File(file), type);
|
||||
}
|
||||
|
||||
public int getKind() {
|
||||
return SCRIPT_ENTITY;
|
||||
}
|
||||
|
||||
protected File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "script " + file.getName();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "script " + file.getName();
|
||||
}
|
||||
|
||||
public String[] getArgumentNames() {
|
||||
return new String[] { "script object" };
|
||||
}
|
||||
|
||||
public CAstNode[] getArgumentDefaults() {
|
||||
return new CAstNode[0];
|
||||
}
|
||||
|
||||
public int getArgumentCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public Collection<CAstQualifier> getQualifiers() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
};
|
||||
public abstract class NativeTranslatorToCAst
|
||||
extends NativeBridge
|
||||
implements TranslatorToCAst
|
||||
{
|
||||
|
||||
protected final URL sourceURL;
|
||||
|
||||
|
@ -295,7 +32,7 @@ public abstract class NativeTranslatorToCAst extends NativeBridge {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String getFile() {
|
||||
protected String getFile() {
|
||||
return sourceURL.getFile();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package com.ibm.wala.cast.ir.translator;
|
||||
|
||||
import com.ibm.wala.cast.tree.CAstEntity;
|
||||
|
||||
public interface TranslatorToCAst {
|
||||
|
||||
public CAstEntity translateToCAst();
|
||||
|
||||
}
|
|
@ -76,6 +76,10 @@ abstract public class AstFunctionClass implements IClass, ClassConstants {
|
|||
public boolean isPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isStatic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getModifiers() {
|
||||
return ACC_PUBLIC;
|
||||
|
|
|
@ -75,7 +75,7 @@ public abstract class CAstAbstractLoader implements IClassLoader {
|
|||
return parent;
|
||||
}
|
||||
|
||||
public void removeAll(Collection toRemove) {
|
||||
public void removeAll(Collection<IClass> toRemove) {
|
||||
Set<TypeName> keys = HashSetFactory.make();
|
||||
|
||||
for (Iterator<Map.Entry<TypeName,IClass>> EE = types.entrySet().iterator(); EE.hasNext();) {
|
||||
|
|
|
@ -0,0 +1,153 @@
|
|||
package com.ibm.wala.cast.loader;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
import com.ibm.wala.cast.ir.translator.NativeTranslatorToCAst;
|
||||
import com.ibm.wala.cast.ir.translator.TranslatorToCAst;
|
||||
import com.ibm.wala.cast.ir.translator.TranslatorToIR;
|
||||
import com.ibm.wala.cast.tree.CAst;
|
||||
import com.ibm.wala.cast.tree.CAstEntity;
|
||||
import com.ibm.wala.cast.tree.impl.CAstImpl;
|
||||
import com.ibm.wala.cast.util.CAstPrinter;
|
||||
import com.ibm.wala.cast.util.TemporaryFile;
|
||||
import com.ibm.wala.classLoader.IClass;
|
||||
import com.ibm.wala.classLoader.IClassLoader;
|
||||
import com.ibm.wala.classLoader.Module;
|
||||
import com.ibm.wala.classLoader.ModuleEntry;
|
||||
import com.ibm.wala.classLoader.SourceFileModule;
|
||||
import com.ibm.wala.classLoader.SourceURLModule;
|
||||
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
||||
import com.ibm.wala.types.TypeName;
|
||||
import com.ibm.wala.util.collections.Pair;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
|
||||
public abstract class CAstAbstractModuleLoader extends CAstAbstractLoader {
|
||||
|
||||
public CAstAbstractModuleLoader(IClassHierarchy cha, IClassLoader parent) {
|
||||
super(cha, parent);
|
||||
}
|
||||
|
||||
public CAstAbstractModuleLoader(IClassHierarchy cha) {
|
||||
this(cha, null);
|
||||
}
|
||||
|
||||
protected abstract TranslatorToCAst
|
||||
getTranslatorToCAst(CAst ast, URL sourceURL, String localFileName);
|
||||
|
||||
protected abstract boolean shouldTranslate(CAstEntity entity);
|
||||
|
||||
protected abstract TranslatorToIR initTranslator();
|
||||
|
||||
protected void finishTranslation() {
|
||||
|
||||
}
|
||||
|
||||
public void init(final List<Module> modules) {
|
||||
final CAst ast = new CAstImpl();
|
||||
|
||||
final Set topLevelEntities = new LinkedHashSet();
|
||||
|
||||
final TranslatorToIR xlatorToIR = initTranslator();
|
||||
|
||||
class TranslatorNestingHack {
|
||||
|
||||
private void init(ModuleEntry moduleEntry) {
|
||||
if (moduleEntry.isModuleFile()) {
|
||||
init(moduleEntry.asModule());
|
||||
} else if (moduleEntry instanceof SourceFileModule) {
|
||||
File f = ((SourceFileModule) moduleEntry).getFile();
|
||||
String fn = f.toString();
|
||||
|
||||
try {
|
||||
TranslatorToCAst xlatorToCAst =
|
||||
getTranslatorToCAst(ast, new URL("file://" + f), fn);
|
||||
|
||||
CAstEntity fileEntity = xlatorToCAst.translateToCAst();
|
||||
|
||||
if (fileEntity != null) {
|
||||
CAstPrinter.printTo(fileEntity, Trace.getTraceWriter());
|
||||
|
||||
topLevelEntities.add(Pair.make(fileEntity, fn));
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
Trace.println("unpected problems with " + f);
|
||||
e.printStackTrace( Trace.getTraceStream() );
|
||||
Assertions.UNREACHABLE();
|
||||
} catch (RuntimeException e) {
|
||||
Trace.println("unpected problems with " + f);
|
||||
e.printStackTrace( Trace.getTraceStream() );
|
||||
}
|
||||
|
||||
} else if (moduleEntry instanceof SourceURLModule) {
|
||||
java.net.URL url = ((SourceURLModule) moduleEntry).getURL();
|
||||
String fileName = ((SourceURLModule) moduleEntry).getName();
|
||||
String localFileName = fileName.replace('/', '_');
|
||||
|
||||
try {
|
||||
File F = TemporaryFile.streamToFile(localFileName,
|
||||
((SourceURLModule) moduleEntry).getInputStream());
|
||||
|
||||
final TranslatorToCAst xlatorToCAst =
|
||||
getTranslatorToCAst(ast, url, localFileName);
|
||||
|
||||
CAstEntity fileEntity = xlatorToCAst.translateToCAst();
|
||||
|
||||
if (fileEntity != null) {
|
||||
Trace.println(CAstPrinter.print(fileEntity));
|
||||
|
||||
topLevelEntities.add(Pair.make(fileEntity, fileName));
|
||||
}
|
||||
|
||||
F.delete();
|
||||
} catch (IOException e) {
|
||||
Trace.println("unexpected problems with " + fileName);
|
||||
e.printStackTrace( Trace.getTraceStream() );
|
||||
Assertions.UNREACHABLE();
|
||||
} catch (RuntimeException e) {
|
||||
Trace.println("unexpected problems with " + fileName);
|
||||
e.printStackTrace( Trace.getTraceStream() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void init(Module module) {
|
||||
for (Iterator mes = module.getEntries(); mes.hasNext();) {
|
||||
init((ModuleEntry) mes.next());
|
||||
}
|
||||
}
|
||||
|
||||
private void init() {
|
||||
for (Iterator mes = modules.iterator(); mes.hasNext();) {
|
||||
init((Module) mes.next());
|
||||
}
|
||||
|
||||
for(Iterator tles = topLevelEntities.iterator(); tles.hasNext(); ) {
|
||||
Pair p = (Pair)tles.next();
|
||||
if (shouldTranslate((CAstEntity)p.fst)) {
|
||||
xlatorToIR.translate((CAstEntity)p.fst, (String)p.snd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(new TranslatorNestingHack()).init();
|
||||
|
||||
for (Iterator ts = types.keySet().iterator(); ts.hasNext();) {
|
||||
TypeName tn = (TypeName) ts.next();
|
||||
try {
|
||||
Trace.println("found type " + tn + " : " + types.get(tn) + " < "
|
||||
+ ((IClass) types.get(tn)).getSuperclass());
|
||||
} catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
finishTranslation();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,143 +0,0 @@
|
|||
package com.ibm.wala.cast.loader;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
import com.ibm.wala.cast.ir.translator.NativeTranslatorToCAst;
|
||||
import com.ibm.wala.cast.ir.translator.TranslatorToIR;
|
||||
import com.ibm.wala.cast.tree.CAst;
|
||||
import com.ibm.wala.cast.tree.CAstEntity;
|
||||
import com.ibm.wala.cast.tree.impl.CAstImpl;
|
||||
import com.ibm.wala.cast.util.CAstPrinter;
|
||||
import com.ibm.wala.cast.util.TemporaryFile;
|
||||
import com.ibm.wala.classLoader.IClass;
|
||||
import com.ibm.wala.classLoader.IClassLoader;
|
||||
import com.ibm.wala.classLoader.Module;
|
||||
import com.ibm.wala.classLoader.ModuleEntry;
|
||||
import com.ibm.wala.classLoader.SourceFileModule;
|
||||
import com.ibm.wala.classLoader.SourceURLModule;
|
||||
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
||||
import com.ibm.wala.types.TypeName;
|
||||
import com.ibm.wala.util.collections.Pair;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
|
||||
public abstract class CAstAbstractNativeLoader extends CAstAbstractLoader {
|
||||
|
||||
public CAstAbstractNativeLoader(IClassHierarchy cha, IClassLoader parent) {
|
||||
super(cha, parent);
|
||||
}
|
||||
|
||||
public CAstAbstractNativeLoader(IClassHierarchy cha) {
|
||||
this(cha, null);
|
||||
}
|
||||
|
||||
protected abstract NativeTranslatorToCAst getTranslatorToCAst(CAst ast, URL sourceURL, String localFileName);
|
||||
|
||||
protected abstract TranslatorToIR initTranslator();
|
||||
|
||||
protected void finishTranslation() {
|
||||
|
||||
}
|
||||
|
||||
public void init(final List modules) {
|
||||
final CAst ast = new CAstImpl();
|
||||
|
||||
final Set<Pair> topLevelEntities = new LinkedHashSet<Pair>();
|
||||
|
||||
final TranslatorToIR xlatorToIR = initTranslator();
|
||||
|
||||
class TranslatorNestingHack {
|
||||
|
||||
private void init(ModuleEntry moduleEntry) {
|
||||
if (moduleEntry.isModuleFile()) {
|
||||
init(moduleEntry.asModule());
|
||||
} else if (moduleEntry instanceof SourceFileModule) {
|
||||
File f = ((SourceFileModule) moduleEntry).getFile();
|
||||
String fn = f.toString();
|
||||
|
||||
try {
|
||||
NativeTranslatorToCAst xlatorToCAst = getTranslatorToCAst(ast, new URL("file://" + f), fn);
|
||||
|
||||
CAstEntity fileEntity = xlatorToCAst.translateToCAst();
|
||||
|
||||
if (fileEntity != null) {
|
||||
Trace.println(CAstPrinter.print(fileEntity));
|
||||
|
||||
topLevelEntities.add(Pair.make(fileEntity, fn));
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
Trace.println("unexpected problems (MalformedURLException) with " + f);
|
||||
e.printStackTrace(Trace.getTraceStream());
|
||||
Assertions.UNREACHABLE();
|
||||
} catch (RuntimeException e) {
|
||||
Trace.println("unexpected problems (RuntimeException) with " + f);
|
||||
e.printStackTrace(Trace.getTraceStream());
|
||||
}
|
||||
|
||||
} else if (moduleEntry instanceof SourceURLModule) {
|
||||
java.net.URL url = ((SourceURLModule) moduleEntry).getURL();
|
||||
String fileName = ((SourceURLModule) moduleEntry).getName();
|
||||
String localFileName = fileName.replace('/', '_');
|
||||
|
||||
try {
|
||||
File F = TemporaryFile.streamToFile(localFileName, ((SourceURLModule) moduleEntry).getInputStream());
|
||||
|
||||
final NativeTranslatorToCAst xlatorToCAst = getTranslatorToCAst(ast, url, localFileName);
|
||||
|
||||
CAstEntity fileEntity = xlatorToCAst.translateToCAst();
|
||||
|
||||
if (fileEntity != null) {
|
||||
Trace.println(CAstPrinter.print(fileEntity));
|
||||
|
||||
topLevelEntities.add(Pair.make(fileEntity, fileName));
|
||||
}
|
||||
|
||||
F.delete();
|
||||
} catch (IOException e) {
|
||||
Trace.println("unexpected problems with " + fileName);
|
||||
e.printStackTrace(Trace.getTraceStream());
|
||||
Assertions.UNREACHABLE();
|
||||
} catch (RuntimeException e) {
|
||||
Trace.println("unexpected problems with " + fileName);
|
||||
e.printStackTrace(Trace.getTraceStream());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void init(Module module) {
|
||||
for (Iterator mes = module.getEntries(); mes.hasNext();) {
|
||||
init((ModuleEntry) mes.next());
|
||||
}
|
||||
}
|
||||
|
||||
private void init() {
|
||||
for (Iterator mes = modules.iterator(); mes.hasNext();) {
|
||||
init((Module) mes.next());
|
||||
}
|
||||
|
||||
for (Iterator tles = topLevelEntities.iterator(); tles.hasNext();) {
|
||||
Pair p = (Pair) tles.next();
|
||||
xlatorToIR.translate((CAstEntity) p.fst, (String) p.snd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(new TranslatorNestingHack()).init();
|
||||
|
||||
for (Iterator ts = types.keySet().iterator(); ts.hasNext();) {
|
||||
TypeName tn = (TypeName) ts.next();
|
||||
try {
|
||||
Trace.println("found type " + tn + " : " + types.get(tn) + " < " + ((IClass) types.get(tn)).getSuperclass());
|
||||
} catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
finishTranslation();
|
||||
}
|
||||
|
||||
}
|
|
@ -52,8 +52,7 @@ public interface CAstEntity {
|
|||
public static int FIELD_ENTITY = 4;
|
||||
|
||||
/** This entity is a source file (i.e. a compilation unit).
|
||||
* Children: in JavaScript, nothing(doesn't occur?); in Java, TYPE_ENTITY's.
|
||||
**/
|
||||
*/
|
||||
public static int FILE_ENTITY = 5;
|
||||
|
||||
/** This entity represents a rule in a logic language.
|
||||
|
@ -65,6 +64,12 @@ public interface CAstEntity {
|
|||
**/
|
||||
public static int MACRO_ENTITY = 7;
|
||||
|
||||
/**
|
||||
* This entity represents a global varible
|
||||
*/
|
||||
public static int GLOBAL_ENTITY = 8;
|
||||
|
||||
|
||||
/**
|
||||
* Languages that introduce new kinds of CAstEntity should use this
|
||||
* number as the base of integers chosen to denote the new entity
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
/******************************************************************************
|
||||
* 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
/**
|
||||
* Encapsulates a translator from source files to CAstEntities. This
|
||||
* interface is meant ease the creation of CAst consumers that can
|
||||
* take asts from multiple sources.
|
||||
*
|
||||
* @author Julian Dolby (dolby@us.ibm.com)
|
||||
*/
|
||||
public interface TranslatorToCAst {
|
||||
|
||||
CAstEntity translate(Reader file, String fileName) throws IOException;
|
||||
|
||||
}
|
|
@ -56,6 +56,7 @@ public class CAstControlFlowRecorder implements CAstControlFlowMap {
|
|||
private final Object from;
|
||||
|
||||
Key(Object label, Object from) {
|
||||
assert from != null;
|
||||
this.from = from;
|
||||
this.label = label;
|
||||
}
|
||||
|
|
|
@ -146,6 +146,12 @@ public abstract class CAstVisitor {
|
|||
visitor.leaveFieldEntity(n, context, visitor);
|
||||
break;
|
||||
}
|
||||
case CAstEntity.GLOBAL_ENTITY: {
|
||||
if (visitor.visitGlobalEntity(n, context, visitor))
|
||||
break;
|
||||
visitor.leaveGlobalEntity(n, context, visitor);
|
||||
break;
|
||||
}
|
||||
case CAstEntity.TYPE_ENTITY: {
|
||||
Context typeContext = visitor.makeTypeContext(context, n);
|
||||
if (visitor.visitTypeEntity(n, context, typeContext, visitor))
|
||||
|
@ -260,6 +266,19 @@ public abstract class CAstVisitor {
|
|||
*/
|
||||
protected void leaveFieldEntity(CAstEntity n, Context context, CAstVisitor visitor) { visitor.leaveEntity(n, context, visitor); }
|
||||
/**
|
||||
* Visit a Field entity.
|
||||
* @param n the entity to process
|
||||
* @param context a visitor-specific context
|
||||
* @return true if no further processing is needed
|
||||
*/
|
||||
protected boolean visitGlobalEntity(CAstEntity n, Context context, CAstVisitor visitor) { return visitor.visitEntity(n, context, visitor); }
|
||||
/**
|
||||
* Leave a Field entity.
|
||||
* @param n the entity to process
|
||||
* @param context a visitor-specific context
|
||||
*/
|
||||
protected void leaveGlobalEntity(CAstEntity n, Context context, CAstVisitor visitor) { visitor.leaveEntity(n, context, visitor); }
|
||||
/**
|
||||
* Visit a Type entity.
|
||||
* @param n the entity to process
|
||||
* @param context a visitor-specific context
|
||||
|
|
|
@ -252,6 +252,8 @@ public class CAstPrinter {
|
|||
}
|
||||
|
||||
public static void printTo(CAstEntity e, Writer w) {
|
||||
//anca: check if the writer is null
|
||||
if(w != null)
|
||||
instance.doPrintTo(e, w);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue