forked from JavaTX/JavaCompilerCore
Aufräumen
This commit is contained in:
parent
717fd5d53e
commit
c1cbb78fe5
@ -18,11 +18,10 @@ public class JavaClassName {
|
||||
private PackageName packageName;
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO: JavaClassName sollten aus den Assumptions generiert werden.
|
||||
* Diese wissen, welche Typen und Typnamen existieren und können direkt auf Korrektheit prüfen.
|
||||
*/
|
||||
private JavaClassName(String name){
|
||||
JavaClassName(String name){
|
||||
if(name == null)throw new NullPointerException();
|
||||
|
||||
String[] names = name.split("[.]");
|
||||
|
18
src/de/dhbwstuttgart/parser/JavaClassRegistry.java
Normal file
18
src/de/dhbwstuttgart/parser/JavaClassRegistry.java
Normal file
@ -0,0 +1,18 @@
|
||||
package de.dhbwstuttgart.parser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Speichert die Klassen im aktuellen Projektscope
|
||||
*/
|
||||
public class JavaClassRegistry {
|
||||
public List<JavaClassName> existingClasses = new ArrayList<>();
|
||||
|
||||
public JavaClassName getName(String className) {
|
||||
for(JavaClassName name : existingClasses){
|
||||
if(name.toString().equals(className))return name;
|
||||
}
|
||||
throw new TypeNotPresentException(className, new Throwable());
|
||||
}
|
||||
}
|
@ -1,16 +1,4 @@
|
||||
// ino.module.Class.8553.package
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
// ino.end
|
||||
// ino.module.Class.8553.import
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.lang.model.element.Modifier;
|
||||
|
||||
import org.apache.bcel.generic.ClassGen;
|
||||
import org.apache.bcel.generic.ConstantPoolGen;
|
||||
@ -35,25 +23,13 @@ import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
||||
import de.dhbwstuttgart.typeinference.*;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
|
||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
|
||||
|
||||
import org.apache.bcel.generic.*;
|
||||
import org.apache.bcel.classfile.*;
|
||||
import org.apache.bcel.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
||||
@ -61,7 +37,7 @@ import java.io.*;
|
||||
public class Class extends GTVDeclarationContext implements IItemWithOffset, Generic, GenericTypeInsertable
|
||||
{
|
||||
/**
|
||||
* Log4j - Loggerinstanzen
|
||||
* Loggerinstanzen
|
||||
*/
|
||||
protected static Logger inferencelog = Logger.getLogger("inference");
|
||||
protected static Logger codegenlog = Logger.getLogger("codegen");
|
||||
@ -70,18 +46,17 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen
|
||||
|
||||
protected Modifiers modifiers;
|
||||
protected JavaClassName name;
|
||||
|
||||
private Block class_block;
|
||||
|
||||
private Menge<Field> fielddecl = new Menge<Field>();
|
||||
private List<Field> fielddecl = new ArrayList<>();
|
||||
private GenericDeclarationList genericClassParameters;
|
||||
private int offset;
|
||||
private RefType superClass;
|
||||
protected boolean isInterface;
|
||||
private List<RefType> implementedInterfaces;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// TypeReconstructionAlgorithmus
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// ino.method.TRProg.23110.defdescription type=javadoc
|
||||
/**
|
||||
* Ausgangspunkt f�r den Typrekonstruktionsalgorithmus. Hier werden zun�chst
|
||||
* die Mengen von Typannahmen V_fields_methods und V_i erstellt, die als Eingabe
|
||||
@ -208,45 +183,6 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen
|
||||
return new JavaCodeResult(stringReturn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Errechnet die Generischen Parameter der Klasse für diese Klasse.
|
||||
* Die berechneten Variablen werden anschlieÃend in die this.genericTypeVars eingesetzt. Dabei werden alte genericTypeVars überschrieben.
|
||||
* @param tphs : Alle übriggebliebenen TypePLaceholder
|
||||
|
||||
private void createGenericTypeVars(Menge<TypePlaceholder> tphs){
|
||||
this.genericClassParameters = new GenericDeclarationList(new Menge<GenericTypeVar>());
|
||||
for(TypePlaceholder tph : tphs){
|
||||
GenericTypeVar toAdd = new GenericTypeVar(tph,this.getOffset());
|
||||
if(!this.genericClassParameters.contains(toAdd))this.genericClassParameters.add(toAdd);
|
||||
}
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* Errechnet die Generischen Parameter der Klasse für diese Klasse.
|
||||
* Die berechneten Variablen werden anschlieÃend in die this.genericTypeVars eingesetzt. Dabei werden alte genericTypeVars überschrieben.
|
||||
* @param reconstructionResult
|
||||
|
||||
public void createGenericTypeVars(TypeinferenceResultSet reconstructionResult){
|
||||
this.genericClassParameters = new Menge<GenericTypeVar>();
|
||||
for(Pair pair : reconstructionResult.getUnifiedConstraints()){
|
||||
if(pair.TA2 instanceof TypePlaceholder && pair.TA1 instanceof TypePlaceholder){// if(pair.OperatorSmallerExtends() || pair.OperatorSmaller()){
|
||||
Type ta1=reconstructionResult.getUnifiedConstraints().getTypeEqualTo(pair.TA1);
|
||||
Type ta2=reconstructionResult.getUnifiedConstraints().getTypeEqualTo(pair.TA2);
|
||||
this.genericClassParameters.add(new GenericTypeVar(new Pair(ta1,ta2),this.getOffset()));
|
||||
}
|
||||
}
|
||||
|
||||
for(Pair pair : reconstructionResult.getConstraints()){
|
||||
if( ! reconstructionResult.getUnifiedConstraints().contains(pair.TA1)){
|
||||
this.genericClassParameters.add(new GenericTypeVar(pair.TA1,this.getOffset()));
|
||||
}
|
||||
if( ! reconstructionResult.getUnifiedConstraints().contains(pair.TA2)){
|
||||
this.genericClassParameters.add(new GenericTypeVar(pair.TA2, this.getOffset()));
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public int getOffset(){
|
||||
return this.offset;
|
||||
}
|
||||
@ -257,12 +193,6 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen
|
||||
* @return
|
||||
*/
|
||||
public RefType getType() {
|
||||
/*
|
||||
Menge<Type> parameter = new Menge<Type>();
|
||||
for(Type param : this.get_ParaList()){
|
||||
parameter.add(((GenericTypeVar)param).getTypePlaceHolder());//(TypePlaceholder.fresh()); //Hier ist kein ReplacementListener notwendig. Der Typ soll nie eingesetzt werden. Der TPH wird nur gebraucht, damit das Unifizieren funktioniert.
|
||||
}
|
||||
*/
|
||||
return new RefType(this.getName().toString(), this.get_ParaList(),this, 0);
|
||||
}
|
||||
|
||||
@ -284,23 +214,6 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SyntaxTreeNode getParent() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Menge<SyntaxTreeNode> getChildren() {
|
||||
Menge<SyntaxTreeNode> ret = new Menge<SyntaxTreeNode>();
|
||||
//for(Field f : this.getFields()){
|
||||
// ret.add(f);
|
||||
//}
|
||||
ret.addAll(this.getFields());
|
||||
ret.addAll(this.get_ParaList());
|
||||
ret.addAll(this.getGenericParameter().getGTVList());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
if(!(obj instanceof Class))return false;
|
||||
@ -356,70 +269,7 @@ public class Class extends GTVDeclarationContext implements IItemWithOffset, Gen
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean isInterface;
|
||||
public boolean isInterface(){
|
||||
return isInterface;
|
||||
}
|
||||
/*
|
||||
private Collection<? extends ByteCodeResult> getGenericClasses() {
|
||||
Collection<ByteCodeResult> results = new Menge<>();
|
||||
|
||||
for(Field field : this.fielddecl){
|
||||
Type type = field.getType();
|
||||
//Der Type des Feldes
|
||||
if(type instanceof RefType){
|
||||
RefType refType = (RefType) type;
|
||||
|
||||
if(!refType.getCombinedType(null).equals(refType.get_Name().replace(".", "%"))){
|
||||
results.addAll(generateGenericClass(refType.getCombinedType(null), new Class("java/util/Vector",-1)));
|
||||
}
|
||||
}
|
||||
|
||||
if(field instanceof Method){
|
||||
Method method = (Method) field;
|
||||
ParameterList parameterList = method.getParameterList();
|
||||
|
||||
//Die Typen der Methodenparameter
|
||||
for(FormalParameter parameter: parameterList){
|
||||
Type parameterType = parameter.getType();
|
||||
|
||||
if(parameterType instanceof RefType){
|
||||
RefType refType = (RefType) parameterType;
|
||||
|
||||
if(!refType.getCombinedType(null).equals(refType.get_Name().replace(".", "%"))){
|
||||
results.addAll(generateGenericClass(refType.getCombinedType(null), new Class("java/util/Vector",-1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
private Menge<ByteCodeResult> generateGenericClass(String name, Class superClass){
|
||||
//TODO: bytecode -- Generics hinzuf<EFBFBD>gen
|
||||
//Type superClassType = superClass.getType();
|
||||
|
||||
//TODO: bytecode
|
||||
//ClassGenerator genericClassGenerator = new ClassGenerator(name, superClassType, name + ".java", Constants.ACC_PUBLIC , new String[] { }, new TypeinferenceResultSet(null, null, null));
|
||||
|
||||
//TODO: bytecode -- Namen der neuen Klasse
|
||||
Class generatedClass = new Class(name, 0);
|
||||
|
||||
//TODO: bytecode -- alle Konstruktoren generieren
|
||||
Block konstruktorBlock = new Block();
|
||||
konstruktorBlock.setType(new de.dhbwstuttgart.syntaxtree.type.Void(konstruktorBlock, 0));
|
||||
konstruktorBlock.statements.add(new SuperCall(konstruktorBlock));
|
||||
Constructor standardKonstruktor = new Constructor(Method.createEmptyMethod(konstruktorBlock, name, superClass), superClass);
|
||||
standardKonstruktor.parserPostProcessing(generatedClass);
|
||||
|
||||
generatedClass.addField(standardKonstruktor);
|
||||
|
||||
return generatedClass.genByteCode(new TypeinferenceResultSet(generatedClass, new Menge<>(), new ResultSet()));
|
||||
}
|
||||
*/
|
||||
}
|
||||
// ino.end
|
||||
|
@ -1,47 +0,0 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Receiver;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
|
||||
/**
|
||||
* Diese Klasse stellt den this()-Aufruf dar.
|
||||
* @author janulrich
|
||||
*
|
||||
*/
|
||||
public class ConstructorCall extends MethodCall
|
||||
{
|
||||
public ConstructorCall(Receiver receiver, String methodName, ArgumentList argumentList, int offset){
|
||||
super(receiver, methodName, argumentList,offset);
|
||||
//this.set_Receiver(receiver);
|
||||
//this.set_Name(methodName);
|
||||
//this.set_ArgumentList(argumentList);
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
||||
throw new TypeinferenceException("this(...)-Aufruf kann nicht als Ausdruck verwendet werden",this);
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public ConstraintsSet overloading(TypeAssumptions assumptions){
|
||||
ConstraintsSet ret = new ConstraintsSet();
|
||||
ConstructorAssumption cAss = assumptions.getConstructorAssumption(this.get_Name(), this.getArgumentList().size());
|
||||
if(cAss == null)throw new TypeinferenceException("Kein Konstruktor mit passender Parameteranzahl vorhanden",this);
|
||||
|
||||
ret.add(constraintsFromMethodAssumption(cAss, assumptions));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||||
super.parserPostProcessing(parent);
|
||||
}
|
||||
|
||||
}
|
@ -1,35 +1,14 @@
|
||||
// ino.module.ExceptionList.8559.package
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
// ino.end
|
||||
// ino.module.ExceptionList.8559.import
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
// ino.class.ExceptionList.23358.declaration
|
||||
public class ExceptionList
|
||||
// ino.end
|
||||
// ino.class.ExceptionList.23358.body
|
||||
{
|
||||
// ino.attribute.reftype.23361.declaration
|
||||
private Menge<RefType> reftype = new Menge<RefType>();
|
||||
// ino.end
|
||||
private List<RefType> exceptions;
|
||||
|
||||
|
||||
|
||||
// ino.method.set_addElem.23364.definition
|
||||
public void set_addElem(RefType rety)
|
||||
// ino.end
|
||||
// ino.method.set_addElem.23364.body
|
||||
{
|
||||
reftype.addElement(rety);
|
||||
public ExceptionList(List<RefType> exceptions){
|
||||
this.exceptions = exceptions;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -11,7 +11,5 @@ import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||
*
|
||||
*/
|
||||
public interface Generic {
|
||||
public void setGenericParameter(GenericDeclarationList params);
|
||||
public Iterable<GenericTypeVar> getGenericParameter();
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
/**
|
||||
* Dieser SyntaxTreeNode kann anstelle von null in einem Syntaxbaum eingesetzt werden.
|
||||
* Vorsicht: Als Offset wird dann immer 0 zurück gegeben.
|
||||
*/
|
||||
public class NullSyntaxTreeNode extends SyntaxTreeNode {
|
||||
|
||||
@Override
|
||||
public int getOffset() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVariableLength() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Menge<? extends SyntaxTreeNode> getChildren() {
|
||||
return new Menge<>();
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
// ino.module.ParameterList.8565.package
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
// ino.end
|
||||
// ino.module.ParameterList.8565.import
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
|
||||
@ -18,22 +16,17 @@ import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
public class ParameterList extends SyntaxTreeNode implements Iterable<FormalParameter>
|
||||
{
|
||||
public List<FormalParameter> formalparameter = new Menge<FormalParameter>();
|
||||
// ino.end
|
||||
|
||||
public ParameterList(List<FormalParameter> params){
|
||||
this.formalparameter = params;
|
||||
}
|
||||
|
||||
// ino.method.getParameterAt.23632.definition
|
||||
public FormalParameter getParameterAt(int i)
|
||||
// ino.end
|
||||
// ino.method.getParameterAt.23632.body
|
||||
{
|
||||
if (i >= formalparameter.size() ) return null;
|
||||
|
||||
return formalparameter.get(i);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
public List<FormalParameter> sc_get_Formalparalist()
|
||||
@ -50,18 +43,6 @@ public class ParameterList extends SyntaxTreeNode implements Iterable<FormalPara
|
||||
return formalparameter.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Andreas Stadelmeier, a10023
|
||||
* @return Die Typinformationen der Parameter in der Parameterliste
|
||||
*/
|
||||
public String getTypeInformation() {
|
||||
String ret = "";
|
||||
for(FormalParameter param : this.formalparameter){
|
||||
ret += param.getTypeInformation();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
if(formalparameter == null)return "[]"; //"Leere Parameterliste";
|
||||
//String ret = "ParameterListe, "+formalparameter.size()+" Einträge [ ";
|
||||
@ -107,11 +88,6 @@ public class ParameterList extends SyntaxTreeNode implements Iterable<FormalPara
|
||||
return formalparameter.get(0).getOffset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVariableLength() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends SyntaxTreeNode> getChildren() {
|
||||
return formalparameter;
|
||||
@ -142,4 +118,3 @@ public class ParameterList extends SyntaxTreeNode implements Iterable<FormalPara
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -1,8 +1,4 @@
|
||||
// ino.module.SourceFile.8722.package
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
// ino.end
|
||||
|
||||
// ino.module.SourceFile.8722.import
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
@ -52,118 +48,25 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||
|
||||
|
||||
|
||||
public class SourceFile
|
||||
extends SyntaxTreeNode
|
||||
public class SourceFile extends SyntaxTreeNode
|
||||
{
|
||||
// ino.attribute.LOAD_BASIC_ASSUMPTIONS_FROM_JRE.21358.decldescription type=javadoc
|
||||
/**
|
||||
* @autor HOTI
|
||||
* Dieses Flag bestimmt, ob die basicAssumptions (Integer, Menge, ...) direkt von
|
||||
* der Java-Laufzeitumgebung anhand der Imports oder von den "Fixed Hacks" geladen
|
||||
* werden (Mit Fixed Hacks sind die von Hand eingetragene Basetypes gemeint)
|
||||
*/
|
||||
// ino.end
|
||||
// ino.attribute.LOAD_BASIC_ASSUMPTIONS_FROM_JRE.21358.declaration
|
||||
private static final boolean LOAD_BASIC_ASSUMPTIONS_FROM_JRE = true;
|
||||
// ino.end
|
||||
|
||||
// ino.attribute.READ_OBJECT_SUPERCLASSES_FROM_JRE.21361.decldescription type=javadoc
|
||||
/**
|
||||
* @autor HOTI
|
||||
* Wenn dieses Flag auf <b>true</b> gesetzt ist, wird immer als Superklasse Object
|
||||
* mit rein geladen. Dies hat natürlich zur Folge, dass man in der GUI jeden Typ
|
||||
* auswählen muss, weil ALLES in Java von Object erbt. Sobald die GUI das über eine
|
||||
* Checkbox o.ä. ausblendbar macht kann es aktiviert werden. Ebenso beeinflusst es
|
||||
* die superclass von allen Class-Objekten. (Wenn true ist jede Class automatisch
|
||||
* wenn nicht anders eingegeben Subclass von Object (Wie es sein muss))
|
||||
*/
|
||||
// ino.end
|
||||
// ino.attribute.READ_OBJECT_SUPERCLASSES_FROM_JRE.21361.declaration
|
||||
public static final boolean READ_OBJECT_SUPERCLASSES_FROM_JRE = false;
|
||||
// ino.end
|
||||
|
||||
// ino.attribute.READ_BASE_TYPE_SUPERCLASSES_FROM_JRE.21364.decldescription type=javadoc
|
||||
/**
|
||||
* Wenn dieses Flag auf <b>false</b> ist, werden für alle Basisklassen (definiert
|
||||
* durch die Hashtable baseTypeTranslationTable) KEINE Superklassen geladen. D.h.
|
||||
* Integer hat bspw. nicht die Superklasse Number sondern OBJECT.
|
||||
* Dies verursacht bei den Int-Operationen ein Problem
|
||||
* (+,-,*,/,<,>,...)
|
||||
*/
|
||||
// ino.end
|
||||
// ino.attribute.READ_BASE_TYPE_SUPERCLASSES_FROM_JRE.21364.declaration
|
||||
private static final boolean READ_BASE_TYPE_SUPERCLASSES_FROM_JRE = false;
|
||||
// ino.end
|
||||
|
||||
/**
|
||||
* @autor PL
|
||||
* Wenn dieses Flag auf <b>false</b> ist, werden für alle importierten Klassen
|
||||
* KEINE Superklassen geladen.
|
||||
*/
|
||||
private static final boolean READ_IMPORTED_SUPERCLASSES_FROM_JRE = false;
|
||||
|
||||
protected static Logger codegenlog = Logger.getLogger("codegen");
|
||||
protected static Logger inferencelog = Logger.getLogger("inference");
|
||||
|
||||
private String pkgName;
|
||||
|
||||
public Menge<Class> KlassenVektor = new Menge<Class>();
|
||||
public List<Class> KlassenVektor = new Menge<Class>();
|
||||
private List<JavaClassName> imports;
|
||||
|
||||
/**
|
||||
* Die SourceFile repräsntiert eine zu einem Syntaxbaum eingelesene Java-Datei.
|
||||
* SourceFile stellt dabei den Wurzelknoten des Syntaxbaumes dar.
|
||||
*/
|
||||
public SourceFile(){
|
||||
// HOTI 4.5.06
|
||||
// Base-Type-Translations anlegen (siehe kommentar BaseTypeTranslationTable)
|
||||
baseTypeTranslationTable=new Hashtable<String,String>();
|
||||
baseTypeTranslationTable.put("int","java.lang.Integer");
|
||||
baseTypeTranslationTable.put("char","java.lang.Character");
|
||||
baseTypeTranslationTable.put("boolean","java.lang.Boolean");
|
||||
baseTypeTranslationTable.put("double","java.lang.Double");
|
||||
baseTypeTranslationTable.put("long","java.lang.Long");
|
||||
baseTypeTranslationTable.put("float","java.lang.Float");
|
||||
//baseTypeTranslationTable.put("this.is.a.temporary.entry","de.dhbwstuttgart.typeinference.Menge"); auskommentiert PL 07-08-11
|
||||
|
||||
//this.imports=new ImportDeclarations();
|
||||
|
||||
this.imports.add(new JavaClassName("java.lang.Integer"));
|
||||
this.imports.add(new JavaClassName("java.lang.String"));
|
||||
this.imports.add(new JavaClassName("java.lang.Character"));
|
||||
this.imports.add(new JavaClassName("java.lang.Boolean"));
|
||||
this.imports.add(new JavaClassName("java.lang.Double"));
|
||||
this.imports.add(new JavaClassName("java.lang.Float"));
|
||||
this.imports.add(new JavaClassName("java.lang.Long"));
|
||||
//this.imports.add(UsedId.createFromQualifiedName("java.lang.Byte"));
|
||||
|
||||
// HOTI 4.5.06 Wenn die Klassen immer als "Daddy" Object haben,
|
||||
// muss das der JCC auch kennen
|
||||
if(READ_OBJECT_SUPERCLASSES_FROM_JRE){
|
||||
this.imports.add(new JavaClassName("java.lang.Object"));
|
||||
}
|
||||
}
|
||||
|
||||
public SourceFile(Menge<Class> classDefinitions) {
|
||||
this.KlassenVektor = classDefinitions;
|
||||
public SourceFile(List<Class> classDefinitions) {
|
||||
this.KlassenVektor = classDefinitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* HOTI 4.5.06
|
||||
* Beinhaltet alle Imports des aktuell geparsten Files
|
||||
* in Form einer UsedId
|
||||
*/
|
||||
private List<JavaClassName> imports;
|
||||
|
||||
/**
|
||||
* Table zum Ãbersetzen der nicht implementierten Base-Types:
|
||||
* Ãberall im Compiler wird statt bspw. int Integer verwendet
|
||||
* d.h. 1+2 liefert ein Integer
|
||||
* Deshalb benötigen wir hier eine Tabelle, mit der man die von
|
||||
* der JRE gelieferten Base-Typen (int,char, etc) und die Objekt-
|
||||
* Typen umwandeln können
|
||||
*/
|
||||
private Hashtable<String,String> baseTypeTranslationTable;
|
||||
|
||||
/**
|
||||
* PL 2014-10-25
|
||||
* schnitt1 checkt ob die Typeplaceholders aus in den Elemeneten aus vars enthalten sind
|
||||
@ -283,7 +186,6 @@ public class SourceFile
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// TypeReconstructionAlgorithmus
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// ino.method.typeReconstruction.21406.defdescription type=javadoc
|
||||
/**
|
||||
* Tyrekonstruktionsalgorithmus: ruft f�r jede Klasse den Algorithmus TRProg auf.
|
||||
* Dessen Ergebnismenge A, die Menge aller Typannahmen, f�r eine Klasse dient als
|
||||
@ -293,11 +195,7 @@ public class SourceFile
|
||||
* @return Liste aller m�glichen Typkombinationen
|
||||
* @throws CTypeReconstructionException Wenn was schief l�uft
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.typeReconstruction.21406.definition
|
||||
public Menge<TypeinferenceResultSet> typeReconstruction(TypeAssumptions globalAssumptions)
|
||||
// ino.end
|
||||
// ino.method.typeReconstruction.21406.body
|
||||
{
|
||||
Menge<TypeinferenceResultSet> ret = new Menge<TypeinferenceResultSet>();
|
||||
|
||||
@ -431,173 +329,7 @@ public class SourceFile
|
||||
// ino.end
|
||||
// ino.method.makeBasicAssumptionsFromJRE.21409.body
|
||||
{
|
||||
//return null;
|
||||
///*
|
||||
List<JavaClassName> doneImports=new Menge<>();
|
||||
|
||||
//TypeinferenceResultSet basicAssumptions = new TypeinferenceResultSet(null);
|
||||
TypeAssumptions basicAssumptions = new TypeAssumptions();
|
||||
|
||||
Modifiers mod = new Modifiers();
|
||||
mod.addModifier(new Public());
|
||||
|
||||
//Für Object:
|
||||
imports.add(new JavaClassName("java.lang.Object"));
|
||||
|
||||
// Für jede einzelne Klasse
|
||||
while (imports.size()>0) {
|
||||
JavaClassName importDecl = imports.get(0);
|
||||
|
||||
// Properties laden
|
||||
java.lang.Class<?> x;
|
||||
try {
|
||||
x = java.lang.Class.forName(importDecl.toString());
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new TypeinferenceException("Fehlerhafte Import-Declaration: "+e.getMessage(),this);
|
||||
}
|
||||
|
||||
java.lang.reflect.Field[] fields=x.getDeclaredFields();
|
||||
java.lang.reflect.Method[] methods=x.getDeclaredMethods();
|
||||
java.lang.reflect.Constructor[] constructors=x.getConstructors();
|
||||
java.lang.reflect.TypeVariable[] tvs=x.getTypeParameters();
|
||||
//String className=x.getSimpleName();
|
||||
String className=x.getName();
|
||||
|
||||
//Ermittle die Superklasse:
|
||||
//Class sClass = new Class("Object",0);
|
||||
if(withSubtypes)sClass = getSuperClassOfJREClass(x, basicAssumptions);
|
||||
|
||||
// Namen von Generische Typen erzeugen
|
||||
Hashtable<String,GenericTypeVar> jreSpiderRegistry=new Hashtable<String,GenericTypeVar>();
|
||||
Menge<String> typeGenPara = new Menge<String>();
|
||||
for(int j=0;j<tvs.length;j++){
|
||||
//GenericTypeVar gtv=new GenericTypeVar(tvs[j].getName(), parentClass,-1);
|
||||
typeGenPara.addElement(tvs[j].getName());
|
||||
//jreSpiderRegistry.put(tvs[j].getName(),gtv);
|
||||
}
|
||||
|
||||
|
||||
//BasicAssumptionClass myCl = new BasicAssumptionClass(className, mod);
|
||||
|
||||
for(GenericTypeVar classParam : parentClass.getGenericParameter()){
|
||||
jreSpiderRegistry.put(classParam.getName().toString(),classParam);
|
||||
}
|
||||
|
||||
if(typeGenPara.size()>0){
|
||||
//auskommentiert von Andreas Stadelmeier:
|
||||
//basicAssumptions.addGenericTypeVars(className, typeGenPara);
|
||||
//parentClass.set_ParaList((Menge)typeGenPara);//myCl.set_ParaList((Menge)typeGenPara);
|
||||
}
|
||||
|
||||
|
||||
if(x.getSuperclass()!=null){
|
||||
//boolean isObject=x.getSuperclass().getSimpleName().equalsIgnoreCase("Object");
|
||||
boolean isObject=x.getSuperclass().getName().equalsIgnoreCase("java.lang.Object");
|
||||
boolean isBaseType=isBaseType(className);
|
||||
|
||||
//if((!isObject || READ_OBJECT_SUPERCLASSES_FROM_JRE) && (!isBaseType|| READ_BASE_TYPE_SUPERCLASSES_FROM_JRE))
|
||||
if (((!isObject || READ_OBJECT_SUPERCLASSES_FROM_JRE) && READ_IMPORTED_SUPERCLASSES_FROM_JRE) //eingefuegt 07-08-11
|
||||
|| (isBaseType && READ_BASE_TYPE_SUPERCLASSES_FROM_JRE))
|
||||
{
|
||||
String superclassFullyQualifiedName = x.getSuperclass().getCanonicalName();
|
||||
//Andere Methode, da Menge.contains bei Strings nicht richtig vergleicht.
|
||||
if(!containsString(imports,superclassFullyQualifiedName) && !containsString(doneImports,superclassFullyQualifiedName)){
|
||||
imports.addElement(UsedId.createFromQualifiedName(superclassFullyQualifiedName,-1));
|
||||
}
|
||||
//UsedId ui = new UsedId();
|
||||
//ui.set_Name(x.getSuperclass().getSimpleName());
|
||||
String ui= x.getSuperclass().getName();
|
||||
java.lang.Class superClass=x.getSuperclass();
|
||||
java.lang.reflect.TypeVariable[] superclassTVS=superClass.getTypeParameters();
|
||||
Menge<Type> supertypeGenPara = new Menge<Type>();
|
||||
for(int tvi=0;tvi<superclassTVS.length;tvi++){
|
||||
GenericTypeVar newGTV=new GenericTypeVar(superclassTVS[tvi].getName(),parentClass,-1);
|
||||
supertypeGenPara.addElement(newGTV);
|
||||
}
|
||||
|
||||
if(supertypeGenPara.size()==0){
|
||||
supertypeGenPara=null;
|
||||
}
|
||||
//ui.set_ParaList(supertypeGenPara);
|
||||
//ui.vParaOrg=supertypeGenPara;
|
||||
parentClass.set_UsedId(ui);
|
||||
}
|
||||
}
|
||||
|
||||
//auskommentiert von Andreas Stadelmeier
|
||||
//this.addElement(myCl);
|
||||
//basicAssumptions.addClassName(className);
|
||||
|
||||
for(int j=0;j<fields.length;j++){
|
||||
if(java.lang.reflect.Modifier.isPublic(fields[j].getModifiers())){
|
||||
parentClass.addField(new FieldDeclaration(fields[j].getName(),new RefType(fields[j].getType().getName(),parentClass,-1)));
|
||||
}
|
||||
}
|
||||
for(int j=0;j<methods.length;j++){
|
||||
if(java.lang.reflect.Modifier.isPublic(methods[j].getModifiers())){
|
||||
String methodName=methods[j].getName();
|
||||
//if(methodName.equals("add")){
|
||||
|
||||
java.lang.reflect.Type genericReturnType=methods[j].getGenericReturnType();
|
||||
Type returnType=createTypeFromJavaGenericType(genericReturnType,methods[j].getReturnType(),jreSpiderRegistry, parentClass);
|
||||
|
||||
java.lang.reflect.Type[] gpt=methods[j].getGenericParameterTypes();
|
||||
java.lang.Class[] pt=methods[j].getParameterTypes();
|
||||
|
||||
//CMethodTypeAssumption method = new CMethodTypeAssumption(new RefType(className, 0), methodName, returnType, pt.length,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>(),null);
|
||||
Method method = de.dhbwstuttgart.syntaxtree.Method.createEmptyMethod(methodName, parentClass);
|
||||
method.setType(returnType);
|
||||
ParameterList parameterList = new ParameterList();
|
||||
|
||||
for(int k=0;k<gpt.length;k++){
|
||||
Type type=createTypeFromJavaGenericType(gpt[k],pt[k],jreSpiderRegistry, parentClass);
|
||||
// Fixme HOTI beachte overloaded id
|
||||
//method.addParaAssumption(new CParaTypeAssumption(className, methodName, pt.length,0,type.getName(), type, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>()));
|
||||
FormalParameter parameter = new FormalParameter(new DeclId(type.get_Name()));
|
||||
parameter.setType(type);
|
||||
parameterList.formalparameter.add(parameter);
|
||||
}
|
||||
method.setParameterList(parameterList);
|
||||
//basicAssumptions.addMethodIntersectionType(new CIntersectionType(method));
|
||||
|
||||
parentClass.addField(method);
|
||||
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
for(int j=0;j<constructors.length;j++){
|
||||
String methodName=className;
|
||||
Method constructorMethod = de.dhbwstuttgart.syntaxtree.Method.createEmptyMethod(methodName, parentClass);
|
||||
|
||||
if(java.lang.reflect.Modifier.isPublic(constructors[j].getModifiers())){
|
||||
ParameterList paraList = new ParameterList();
|
||||
for(int k=0;k<constructors[j].getParameterTypes().length;k++){
|
||||
String paraType=constructors[j].getParameterTypes()[k].getName();
|
||||
//String paraType=constructors[j].getParameterTypes()[k].getSimpleName();
|
||||
// Fixme HOTI beachte overloaded id
|
||||
FormalParameter fpara = new FormalParameter(new DeclId("p"+k));
|
||||
fpara.setType(new RefType(paraType,constructorMethod,-1));
|
||||
paraList.formalparameter.add(fpara);
|
||||
}
|
||||
//basicAssumptions.addMethodIntersectionType(new CIntersectionType(constructor));
|
||||
constructorMethod.parameterlist = paraList;
|
||||
Constructor constructor = new Constructor(constructorMethod, parentClass);
|
||||
constructor.parserPostProcessing(parentClass);
|
||||
parentClass.addField(constructor);
|
||||
}
|
||||
}
|
||||
|
||||
Class parentClass = new Class(className, sClass.getType(),mod, typeGenPara);
|
||||
|
||||
basicAssumptions.add(parentClass.getPublicFieldAssumptions());
|
||||
basicAssumptions.addClassAssumption(new ClassAssumption(parentClass));
|
||||
imports.removeElement(importDecl);
|
||||
doneImports.addElement(importDecl);
|
||||
}
|
||||
imports.addAll(doneImports);
|
||||
return basicAssumptions;
|
||||
//*/
|
||||
return null;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
@ -53,15 +53,6 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
|
||||
|
||||
public abstract List<? extends SyntaxTreeNode> getChildren();
|
||||
|
||||
/*
|
||||
public Class getParentClass(){
|
||||
SyntaxTreeNode parent = this.getParent();
|
||||
if(parent instanceof Class)return (Class)parent;
|
||||
if(parent == null)
|
||||
throw new DebugException("Das Wurzelelement eines Syntaxbaumes muss Class sein");
|
||||
return parent.getParentClass();
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* Eine Beschreibung/Name des SyntaxTree-Nodes
|
||||
* Hat nichts mit der Description im Bytecode zu tun,
|
||||
@ -122,11 +113,6 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
|
||||
|
||||
}
|
||||
|
||||
public boolean seesType(Type tA2) {
|
||||
//TODO: Implementieren. Hier sollte ein Lookup in die Assumptions dieses Knotens erfolgen
|
||||
return false;
|
||||
}
|
||||
|
||||
public SyntaxTreeNode getMatchingParentNode(SyntaxTreeNode inNode) {
|
||||
SyntaxTreeNode node = inNode;
|
||||
while(node!=null){
|
||||
|
@ -1,33 +1,14 @@
|
||||
package de.dhbwstuttgart.syntaxtree.factory;
|
||||
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.lang.model.element.Modifier;
|
||||
|
||||
=======
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
>>>>>>> refactoring
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.parser.JavaClassName;
|
||||
import de.dhbwstuttgart.parser.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
<<<<<<< HEAD
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
=======
|
||||
>>>>>>> refactoring
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
|
||||
import de.dhbwstuttgart.syntaxtree.modifier.Public;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
@ -36,13 +17,21 @@ import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
|
||||
public class ASTFactory {
|
||||
|
||||
/**
|
||||
* Anmerkung:
|
||||
* Die ASTFactory Methoden, welche ASTBäume aus java.lang.Class Objekten generieren, können davon ausgehen,
|
||||
* dass alle Imports und Typnamen korrekt sind und müssen diese nicht überprüfen.
|
||||
*/
|
||||
//private JavaClassRegistry names;
|
||||
|
||||
public ASTFactory(JavaClassRegistry scope){
|
||||
names = scope;
|
||||
}
|
||||
|
||||
public static Method createEmptyMethod(String withSignature, Class parent) {
|
||||
return ASTFactory.createMethod(withSignature, new ParameterList(), new Block(), parent);
|
||||
}
|
||||
@ -79,31 +68,45 @@ public class ASTFactory {
|
||||
return createClass(java.lang.Object.class);
|
||||
}
|
||||
|
||||
public static Class createClass(java.lang.Class jreClass){
|
||||
JavaClassName name = new JavaClassName(jreClass.getName());
|
||||
/**
|
||||
*
|
||||
* @param jreClass
|
||||
* @return
|
||||
*/
|
||||
public Class createClass(java.lang.Class jreClass){
|
||||
JavaClassName name = names.getName(jreClass.getName());
|
||||
List<Method> methoden = new ArrayList<>();
|
||||
for(java.lang.reflect.Constructor constructor : jreClass.getConstructors()){
|
||||
|
||||
}
|
||||
for(java.lang.reflect.Method method : jreClass.getMethods()){
|
||||
methoden.add(createMethod(method));
|
||||
methoden.add(createMethod(method, jreClass));
|
||||
}
|
||||
List<Field> felder = new ArrayList<>();
|
||||
Modifiers modifier = new Modifiers();
|
||||
modifier.addModifier(new Public());
|
||||
boolean isInterface = jreClass.isInterface();
|
||||
java.lang.Class superjreClass = jreClass.getSuperclass();
|
||||
RefType superClass;
|
||||
RefType superClass = null;
|
||||
if(superjreClass != null){
|
||||
superjreClass.getName()
|
||||
}else{//Jede Klasse und jedes Interface erbt von Object:
|
||||
superClass = createType(superjreClass);
|
||||
}else{//Jede Klasse und jedes Interface erbt von Object: (auch Object selbst!)
|
||||
superClass = createType(java.lang.Object.class);
|
||||
}
|
||||
List<RefType> implementedInterfaces = new ArrayList<>();
|
||||
for(java.lang.Class jreInterface : jreClass.getInterfaces()){
|
||||
implementedInterfaces.add(createType(jreInterface));
|
||||
}
|
||||
int offset = 0; //Braucht keinen Offset, da diese Klasse nicht aus einem Quellcode geparst wurde
|
||||
return new Class(name, methoden, felder, modifier, isInterface, superClass, implementedInterfaces, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wandelt eine Methode aus der JRE in eine Methode für unseren AST um.
|
||||
* @param jreMethod
|
||||
* @param inClass
|
||||
* @return
|
||||
*/
|
||||
public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass){
|
||||
String name = jreMethod.getName();
|
||||
Type returnType = createType(jreMethod.getReturnType());
|
||||
@ -126,7 +129,7 @@ public class ASTFactory {
|
||||
return new Method(name, returnType, parameterList, block, gtvDeclarations, offset);
|
||||
}
|
||||
|
||||
public static RefType createType(java.lang.Class jreClass){
|
||||
public RefType createType(java.lang.Class jreClass){
|
||||
for(TypeVariable jreTV : jreClass.getTypeParameters()){
|
||||
GenericTypeVar gtv = createGeneric(jreTV, jreClass);
|
||||
gtvs.add(gtv);
|
||||
@ -138,10 +141,14 @@ public class ASTFactory {
|
||||
/**
|
||||
* Erstellt eine GenericTypeVar oder eine BoundedGenericTypeVar
|
||||
* Um die Variablen korrekt zu generieren, muss die Klasse inClass übergeben werden, in der dieser Generic auftaucht
|
||||
* TODO: Warum?
|
||||
* Wird der AST von JREClass erzeugt, so kann davon ausgegangen werden, dass die Generics korrekt sind.
|
||||
* Unser AST ist immutable und nicht im Kreis verzeigert. Generics die gleich heißen und gleiche Bounds haben, sind auch gleich. Müssen nicht die selben Instanzen sein.
|
||||
* @param jreTypeVar
|
||||
* @param inClass Die Klasse in der der Typ auftritt
|
||||
* @return
|
||||
public static GenericTypeVar createGeneric(TypeVariable jreTypeVar, java.lang.Class inClass){
|
||||
*/
|
||||
public GenericTypeVar createGeneric(TypeVariable jreTypeVar, java.lang.Class inClass){
|
||||
//TODO: Bei den Namen der Parameter des Generishen Typs nachschauen, ob er in der Klasse als Generic deklariert wurde
|
||||
String name = jreTypeVar.getTypeName();
|
||||
java.lang.reflect.Type[] bounds = jreTypeVar.getBounds();
|
||||
@ -154,7 +161,6 @@ public class ASTFactory {
|
||||
return new GenericTypeVar();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
public static Class createInterface(String className, RefType superClass, Modifiers modifiers,
|
||||
Menge supertypeGenPara, SourceFile parent){
|
||||
|
@ -3,29 +3,23 @@ package de.dhbwstuttgart.syntaxtree.factory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.NullSyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.FunN;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ObjectType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.EinzelElement;
|
||||
import de.dhbwstuttgart.typeinference.KomplexeMenge;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.OderConstraint;
|
||||
import de.dhbwstuttgart.typeinference.OderMenge;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.UndConstraint;
|
||||
import de.dhbwstuttgart.typeinference.UndMenge;
|
||||
import de.dhbwstuttgart.typeinference.UnifyConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.UnifyOderConstraint;
|
||||
import de.dhbwstuttgart.typeinference.UnifyUndConstraint;
|
||||
|
@ -2,30 +2,21 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
// ino.end
|
||||
// ino.module.This.8654.import
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.apache.bcel.Constants;
|
||||
import org.apache.bcel.generic.ClassGen;
|
||||
import org.apache.bcel.generic.InstructionFactory;
|
||||
import org.apache.bcel.generic.InstructionHandle;
|
||||
import org.apache.bcel.generic.InstructionList;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.bytecode.ClassGenerator;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
import de.dhbwstuttgart.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.ConstructorCall;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
|
||||
|
@ -2,17 +2,9 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
// ino.end
|
||||
// ino.module.This.8654.import
|
||||
import java.util.Hashtable;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
import de.dhbwstuttgart.syntaxtree.Class;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.ConstructorCall;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.JavaCodeResult;
|
||||
@ -25,14 +17,10 @@ import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
|
||||
public class ThisCall extends MethodCall
|
||||
{
|
||||
public ThisCall(int offset,int variableLength)
|
||||
public ThisCall(Receiver receiver, ArgumentList arglist, int offset)
|
||||
{
|
||||
super(offset,variableLength);
|
||||
}
|
||||
super(offset);
|
||||
|
||||
public ThisCall(SyntaxTreeNode parent){
|
||||
this(0,0);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public ArgumentList arglist;
|
||||
@ -56,8 +44,7 @@ public class ThisCall extends MethodCall
|
||||
* This kann auch als Konstruktoraufruf in einem Konstruktor-Block vorkommen.
|
||||
*/
|
||||
@Override
|
||||
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) {
|
||||
String className = this.getParentClass().getName().toString();
|
||||
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions, Class parentClass) {
|
||||
ConstraintsSet ret = new ConstraintsSet();
|
||||
this.setType(new Void(this,this.getOffset()));
|
||||
//Kontrollieren, dass sich this(...) in einem Konstruktor und dort als erstes Statement befindet:
|
||||
@ -65,9 +52,7 @@ public class ThisCall extends MethodCall
|
||||
if(p instanceof Constructor &&
|
||||
((Constructor)p).get_Block().statements.firstElement().equals(this)){
|
||||
//Constraints generieren:
|
||||
|
||||
ConstructorCall constructorCall = new ConstructorCall(new Receiver(new This(this)), className, arglist, this.getOffset());
|
||||
ret.add(constructorCall.TYPEStmt(assumptions));
|
||||
ret.add(super.TYPEStmt(assumptions, parentClass));
|
||||
return ret;
|
||||
}else{
|
||||
//Ansonsten Fehler ausgeben:
|
||||
@ -75,9 +60,18 @@ public class ThisCall extends MethodCall
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstraintsSet overloading(TypeAssumptions assumptions){
|
||||
ConstraintsSet ret = new ConstraintsSet();
|
||||
ConstructorAssumption cAss = assumptions.getConstructorAssumption(this.get_Name(), this.getArgumentList().size());
|
||||
if(cAss == null)throw new TypeinferenceException("Kein Konstruktor mit passender Parameteranzahl vorhanden",this);
|
||||
|
||||
ret.add(constraintsFromMethodAssumption(cAss, assumptions));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
//return receiver/*.toString()*/ + " " + usedid.toString();
|
||||
return "(" + "this" +"(" + this.getArgumentList() + "))";
|
||||
}
|
||||
|
||||
@ -85,14 +79,6 @@ public class ThisCall extends MethodCall
|
||||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
return new JavaCodeResult("this("+this.getArgumentList().printJavaCode(resultSet)+")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Menge<SyntaxTreeNode> getChildren() {
|
||||
Menge<SyntaxTreeNode> ret = new Menge<SyntaxTreeNode>();
|
||||
if(arglist != null)ret.add(arglist);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,9 +1,5 @@
|
||||
|
||||
// ino.module.BoundedGenericTypeVar.8669.package
|
||||
package de.dhbwstuttgart.syntaxtree.type;
|
||||
// ino.end
|
||||
|
||||
// ino.module.BoundedGenericTypeVar.8669.import
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.Class;
|
||||
@ -12,7 +8,6 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
|
||||
// ino.class.BoundedGenericTypeVar.26464.description type=javadoc
|
||||
/**
|
||||
* Entspricht einem GenericTypeVar, jedoch mit Bounds
|
||||
* (d.h. vorgaben, von welchem Typ die Typevar sein darf
|
||||
@ -22,39 +17,16 @@ import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
|
||||
* @author hoti 4.5.06
|
||||
*
|
||||
*/
|
||||
// ino.end
|
||||
// ino.class.BoundedGenericTypeVar.26464.declaration
|
||||
public class BoundedGenericTypeVar extends GenericTypeVar
|
||||
// ino.end
|
||||
// ino.class.BoundedGenericTypeVar.26464.body
|
||||
{
|
||||
|
||||
// ino.attribute.bounds.26468.decldescription type=javadoc
|
||||
/**
|
||||
* Hier sind die Bounds in Form von Type-Objekten abgespeichert
|
||||
*/
|
||||
// ino.end
|
||||
// ino.attribute.bounds.26468.declaration
|
||||
Menge<ObjectType> bounds=new Menge<ObjectType>();
|
||||
// ino.end
|
||||
private int endOffset;
|
||||
|
||||
/*
|
||||
// ino.method.BoundedGenericTypeVar.26471.definition
|
||||
public BoundedGenericTypeVar(String s, int offset, Menge<Type> t, int endOffset)
|
||||
// ino.end
|
||||
// ino.method.BoundedGenericTypeVar.26471.body
|
||||
{
|
||||
super(s, offset);
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
// ino.end
|
||||
*/
|
||||
|
||||
// ino.method.BoundedGenericTypeVar.29409.definition
|
||||
public BoundedGenericTypeVar(String s, Menge<ObjectType> bounds, int offset, int endOffset)
|
||||
// ino.end
|
||||
// ino.method.BoundedGenericTypeVar.29409.body
|
||||
{
|
||||
super(s, offset);
|
||||
if(bounds != null)for(Type t : bounds){
|
||||
@ -64,7 +36,6 @@ public class BoundedGenericTypeVar extends GenericTypeVar
|
||||
this.bounds = bounds;
|
||||
this.endOffset = endOffset;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
public int getEndOffset(){
|
||||
@ -98,24 +69,15 @@ public class BoundedGenericTypeVar extends GenericTypeVar
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ino.method.clone.26483.definition
|
||||
public BoundedGenericTypeVar clone()
|
||||
// ino.end
|
||||
// ino.method.clone.26483.body
|
||||
{
|
||||
return new BoundedGenericTypeVar(this.getName().toString(), this.getBounds(), getOffset(), this.getEndOffset());
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.toString.26486.definition
|
||||
public String toString()
|
||||
// ino.end
|
||||
// ino.method.toString.26486.body
|
||||
{
|
||||
return "BoGTV " + this.getName();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
@Override
|
||||
public Menge<SyntaxTreeNode> getChildren() {
|
||||
@ -125,4 +87,3 @@ public class BoundedGenericTypeVar extends GenericTypeVar
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -42,9 +42,7 @@ public class GenericTypeVar extends ObjectType
|
||||
* Ihre Superklasse ersetzt werden m�ssen. Siehe "Type Erasure" in Sun Spezifikation.
|
||||
* <br/>Autor: J�rg B�uerle
|
||||
*/
|
||||
// ino.method.GenericTypeVar.26509.defdescription type=line
|
||||
// private Hashtable<String, Menge<GenericTypeVar>> m_TypeErasureList;
|
||||
// ino.end
|
||||
private static HashMap<String,TypePlaceholder> tph = new HashMap<>();
|
||||
|
||||
/**
|
||||
@ -62,31 +60,22 @@ public class GenericTypeVar extends ObjectType
|
||||
}
|
||||
*/
|
||||
|
||||
// ino.method.GenericTypeVar.26509.definition
|
||||
public GenericTypeVar(String s, int offset)
|
||||
// ino.end
|
||||
// ino.method.GenericTypeVar.26509.body
|
||||
{
|
||||
super(s,offset);
|
||||
this.name = new JavaClassName(s);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
/*
|
||||
public GenericTypeVar(Type tA1, int offset) {
|
||||
this(new Pair(tA1,null),offset);
|
||||
}
|
||||
*/
|
||||
// ino.method.clone.26512.defdescription type=javadoc
|
||||
/**
|
||||
* <br>Author: J�rg B�uerle
|
||||
* @return
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.clone.26512.definition
|
||||
public GenericTypeVar clone()
|
||||
// ino.end
|
||||
// ino.method.clone.26512.body
|
||||
{
|
||||
return new GenericTypeVar(this.getName().toString(), getOffset());
|
||||
}
|
||||
@ -96,26 +85,15 @@ public class GenericTypeVar extends ObjectType
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.equals.26515.definition
|
||||
public boolean equals(Object obj)
|
||||
// ino.end
|
||||
// ino.method.equals.26515.body
|
||||
{
|
||||
return super.equals(obj) && (obj instanceof GenericTypeVar);
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
// ino.method.toString.26518.definition
|
||||
public String toString()
|
||||
// ino.end
|
||||
// ino.method.toString.26518.body
|
||||
{
|
||||
return "GTV " + this.getName();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
@ -133,12 +111,9 @@ public class GenericTypeVar extends ObjectType
|
||||
}
|
||||
|
||||
public String getSignatureType(Menge paralist)
|
||||
// ino.end
|
||||
// ino.method.getSignatureType.26524.body
|
||||
{
|
||||
return "T" + name + ";";
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
@ -237,5 +212,4 @@ public class GenericTypeVar extends ObjectType
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
@ -6,8 +6,6 @@ import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.NullSyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.FunN;
|
||||
|
Loading…
Reference in New Issue
Block a user