ConstraintType entfernt. Constructor erbt jetzt von Methode. Fehler in Constructor.pareserPostProcessing behoben

This commit is contained in:
JanUlrich 2015-06-16 22:08:17 +02:00
parent 302d7d05f3
commit 2c4f735935
28 changed files with 82 additions and 416 deletions

View File

@ -33,8 +33,6 @@ import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
import de.dhbwstuttgart.syntaxtree.type.Void;
public class Constructor extends Method {
private Method methode;
/**
* Parser kann nicht zwischen einem Konstruktor und einer Methode unterscheiden.
* Diese Klasse beherbegt den als Methode geparsten Konstruktor und wandelt sein verhalten zu dem eines Konstruktors ab.
@ -62,9 +60,9 @@ public class Constructor extends Method {
//TODO: Alles dynamisch gestalten
//init darf nur drin stehen, wenn Konstruktor;
methode.method = new MethodGen(Constants.ACC_PUBLIC, org.apache.bcel.generic.Type.getReturnType(methode.getType().get_Name()), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp);
this.method = new MethodGen(Constants.ACC_PUBLIC, org.apache.bcel.generic.Type.getReturnType(this.getType().get_Name()), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp);
methode.genByteCode(cg); //Aufrufen um Iteration <EFBFBD>ber Block zu starten
super.genByteCode(cg); //Aufrufen um Iteration <EFBFBD>ber Block zu starten
}
// super statement muss drin sein
@ -76,6 +74,7 @@ public class Constructor extends Method {
@Override
public void parserPostProcessing(SyntaxTreeNode parent){
super.parserPostProcessing(parent);
if(this.parameterlist != null){
for(FormalParameter fp : this.parameterlist){
fp.parserPostProcessing(this);
@ -106,321 +105,12 @@ public class Constructor extends Method {
this.methode.setType(this.methode.getParentClass().getType());
}*/
@Override
public Menge<GenericTypeVar> getGenericParameter() {
return this.methode.getGenericParameter();
}
@Override
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
ResultSet resultSet) {
return this.methode.createTypeInsertPoint(tph, resultSet);
}
@Override
public boolean isPublic() {
return this.methode.isPublic();
}
@Override
public String getGenericVarDeclarationString(String genericVarDeclaration) {
return this.methode.getGenericVarDeclarationString(genericVarDeclaration);
}
@Override
public int getGenericVarDeclarationOffset() {
return this.methode.getGenericVarDeclarationOffset();
}
@Override
public void setGenericParameter(GenericDeclarationList params) {
this.methode.setGenericParameter(params);
}
@Override
public GTVDeclarationContext getGTVDeclarationContext() {
return this;
}
@Override
public void addTypeInsertPoints(TypeInsertSet insertSet, ResultSet result) {
this.methode.addTypeInsertPoints(insertSet, result);
}
@Override
public boolean seesType(Type tA2) {
return this.methode.seesType(tA2);
}
@Override
public JavaClassName getTypeName() {
return this.getType().getName();
}
@Override
public Block get_Block() {
return this.methode.get_Block();
}
@Override
public void set_Block(Block blo) {
this.methode.set_Block(blo);
}
@Override
public void set_Modifiers(Modifiers modif) {
this.methode.set_Modifiers(modif);
}
@Override
public void set_ExceptionList(ExceptionList exlist) {
this.methode.set_ExceptionList(exlist);
}
@Override
public void setParameterList(ParameterList paralist) {
this.methode.setParameterList(paralist);
}
@Override
public ParameterList getParameterList() {
return this.methode.getParameterList();
}
@Override
public int getParameterCount() {
return this.methode.getParameterCount();
}
@Override
public ExceptionList get_ExceptionList() {
return this.methode.get_ExceptionList();
}
@Override
public int getOverloadedID() {
return this.methode.getOverloadedID();
}
@Override
public void setOverloadedID(int overloadedID) {
this.methode.setOverloadedID(overloadedID);
}
/*@Override
public String get_codegen_Param_Type(Menge paralist) {
return this.methode.get_codegen_Param_Type(paralist);
}*/
@Override
public String get_Method_Name() {
return this.methode.get_Method_Name();
}
@Override
public Menge get_Type_Paralist() {
return this.methode.get_Type_Paralist();
}
/*@Override
public void codegen(ClassFile classfile, Menge paralist)
throws JVMCodeException {
this.methode.codegen(classfile, paralist);
}*/
@Override
public int getLineNumber() {
return this.methode.getLineNumber();
}
@Override
public void setLineNumber(int lineNumber) {
this.methode.setLineNumber(lineNumber);
}
@Override
public int getOffset() {
return this.methode.getOffset();
}
@Override
public int getVariableLength() {
return this.methode.getVariableLength();
}
@Override
public void setOffset(int Offset) {
this.methode.setOffset(Offset);
}
@Override
public int getTypeLineNumber() {
return this.methode.getTypeLineNumber();
}
@Override
public String toString() {
return this.methode.toString();
}
@Override
public void setAbstract(boolean b) {
this.methode.setAbstract(b);
}
@Override
public boolean isAbstract() {
return this.methode.isAbstract();
}
@Override
public void wandleRefTypeAttributes2GenericAttributes(Menge<Type> paralist) {
this.methode.wandleRefTypeAttributes2GenericAttributes(paralist);
}
@Override
public void set_Method_Name(String string) {
this.methode.set_Method_Name(string);
}
/*public ConstraintsSet TYPE(TypeAssumptions ass) {
ConstraintsSet ret = new ConstraintsSet();
ret.add(this.methode.get_Block().TYPEStmt(ass));
return ret;
}*/
@Override
public String getTypeInformation() {
return this.methode.getTypeInformation();
}
@Override
public JavaCodeResult printJavaCode(ResultSet resultSet) {
return this.methode.printJavaCode(resultSet);
}
/*@Override
public TypeAssumptions createTypeAssumptions(Class classmember) {
Class parentClass = this.getParentClass();
TypeAssumptions ret = new TypeAssumptions();
ret.addAssumption(new ConstructorAssumption(this, parentClass));
return ret;
}*/
@Override
public SyntaxTreeNode getParent(){
return this.methode.getParent();
}
/*@Override
public void parserPostProcessing(SyntaxTreeNode parent) {
this.methode.parserPostProcessing(parent);
}*/
@Override
public Menge<SyntaxTreeNode> getChildren() {
return this.methode.getChildren();
}
/*@Override
public void setType(Type t) {
throw new TypeinferenceException("Einem Konstruktor kann kein Typ zugewiesen werden", this);
//this.methode.setType(t);
}*/
@Override
public Type getType() {
return this.methode.getType();
}
@Override
public boolean equals(Object obj) {
return this.methode.equals(obj);
}
@Override
public void set_DeclId(DeclId did) {
this.methode.set_DeclId(did);
}
@Override
public Menge<DeclId> get_Name() {
return this.methode.get_Name();
}
@Override
public Menge<DeclId> getDeclIdMenge() {
return this.methode.getDeclIdMenge();
}
@Override
public void setDeclIdMenge(Menge<DeclId> vDeclId) {
this.methode.setDeclIdMenge(vDeclId);
}
@Override
public String getIdentifier() {
return this.methode.getIdentifier();
}
@Override
public String getDescription() {
return this.methode.getDescription();
}
@Override
public Class getParentClass() {
return this.methode.getParentClass();
}
}

View File

@ -10,7 +10,6 @@ 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.ConstraintType;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.OderConstraint;
@ -130,8 +129,8 @@ public class FieldDeclaration extends Field{
*/
//TypeCheck, falls es sich um einen RefType handelt:
ConstraintType thisType = this.getType().TYPE(localAssumptions, this);
this.setType(thisType.getType());
Type thisType = this.getType().TYPE(localAssumptions, this);
this.setType(thisType);
/*
if(this.getType()!=null && (this.getType() instanceof RefType)){
Type replaceType = null;

View File

@ -267,12 +267,12 @@ public class SourceFile
new RefType( superclassName.toString(), superclassParaOrg,-1)
);
*/
Pair P = new Pair(baseClass.getType().TYPE(ass, baseClass).getType(), superclass.TYPE(ass, baseClass).getType());
Pair P = new Pair(baseClass.getType().TYPE(ass, baseClass), superclass.TYPE(ass, baseClass));
//PL 04-12-29 freshe Variablen ANFANG
RefType r1 = (RefType)P.getTA1Copy();
RefType r2 = (RefType)P.getTA2Copy();
r1 = (RefType) r1.TYPE(ass, baseClass).getType();
r2 = (RefType) r2.TYPE(ass, baseClass).getType();
r1 = (RefType) r1.TYPE(ass, baseClass);
r2 = (RefType) r2.TYPE(ass, baseClass);
// #JB# 05.04.2005
// ###########################################################
Hashtable<JavaClassName,Type> substHash = new Hashtable<JavaClassName,Type>(); //fuer jedes Paar komplett neue Variablen
@ -310,12 +310,12 @@ public class SourceFile
// 1. Menge <= in FC aufnehmen --> Iteration ueber alle Klassen
Menge<Type> ignoreTypes = new Menge<>(); //Enthält die Typen, welche nicht in der FC als Supertypen enthalten sein sollen.
ignoreTypes.add(new RefType("Long",null,-1).TYPE(globalAssumptions, parent).getType());
ignoreTypes.add(new RefType("Float",null,-1).TYPE(globalAssumptions, parent).getType());
ignoreTypes.add(new RefType("Double",null,-1).TYPE(globalAssumptions, parent).getType());
ignoreTypes.add(new RefType("String",null,-1).TYPE(globalAssumptions, parent).getType());
ignoreTypes.add(new RefType("Integer",null,-1).TYPE(globalAssumptions, parent).getType());
ignoreTypes.add(new RefType("Object",null,-1).TYPE(globalAssumptions, parent).getType());
ignoreTypes.add(new RefType("Long",null,-1).TYPE(globalAssumptions, parent));
ignoreTypes.add(new RefType("Float",null,-1).TYPE(globalAssumptions, parent));
ignoreTypes.add(new RefType("Double",null,-1).TYPE(globalAssumptions, parent));
ignoreTypes.add(new RefType("String",null,-1).TYPE(globalAssumptions, parent));
ignoreTypes.add(new RefType("Integer",null,-1).TYPE(globalAssumptions, parent));
ignoreTypes.add(new RefType("Object",null,-1).TYPE(globalAssumptions, parent));
Menge<Class> basicAssumptionsClassMenge = new Menge<>(); //die Klassen aus den BasicAssumptions und den Importierten Klassen
for(ClassAssumption cAss : ass.getClassAssumptions()){
@ -324,7 +324,7 @@ public class SourceFile
Pair p = new Pair(t1, t2);
//System.out.println("FCPair: "+p);
if(! t1.equals(t2)){//Um FC_TTO darf kein T <. T stehen.
Type superTypeFromAssumptions = ass.getTypeFor(t2, t2).getType(); //In den Assumptions den SuperTyp nachschlagen
Type superTypeFromAssumptions = ass.getTypeFor(t2, t2); //In den Assumptions den SuperTyp nachschlagen
if(superTypeFromAssumptions != null && ! ignoreTypes.contains(superTypeFromAssumptions)){//Die Superklasse eines Typs nur anfügen, wenn er auch in den Assumptions vorkommt.
vFC.add(p);
}

View File

@ -13,7 +13,6 @@ import de.dhbwstuttgart.syntaxtree.statement.Binary;
import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.SingleConstraint;
@ -52,8 +51,8 @@ public abstract class AddOp extends Operator
}
@Override
public HashMap<ConstraintType,ConstraintType> getReturnTypes(TypeAssumptions ass) {
HashMap<ConstraintType,ConstraintType> ret = new HashMap<ConstraintType,ConstraintType>();
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
HashMap<Type,Type> ret = new HashMap<Type,Type>();
ret.put(new RefType("java.lang.Integer",this,-1).TYPE(ass, this), new RefType("java.lang.Integer",this,-1).TYPE(ass, this));
ret.put(new RefType("java.lang.Double",this,-1).TYPE(ass, this), new RefType("java.lang.Double",this,-1).TYPE(ass, this));
ret.put(new RefType("java.lang.Float",this,-1).TYPE(ass, this), new RefType("java.lang.Float",this,-1).TYPE(ass, this));

View File

@ -16,7 +16,6 @@ import de.dhbwstuttgart.syntaxtree.statement.Null;
import de.dhbwstuttgart.syntaxtree.statement.Statement;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.SingleConstraint;
@ -54,8 +53,8 @@ public abstract class LogOp extends Operator
}
@Override
public HashMap<ConstraintType,ConstraintType> getReturnTypes(TypeAssumptions ass) {
HashMap<ConstraintType,ConstraintType> ret = new HashMap<>();
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
HashMap<Type,Type> ret = new HashMap<>();
ret.put(new RefType("java.lang.Boolean",this,-1).TYPE(ass, this), new RefType("java.lang.Boolean",this,-1).TYPE(ass, this));
return ret;

View File

@ -12,7 +12,6 @@ import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.syntaxtree.statement.Binary;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
@ -41,8 +40,8 @@ public abstract class MulOp extends Operator
}
@Override
public HashMap<ConstraintType,ConstraintType> getReturnTypes(TypeAssumptions ass) {
HashMap<ConstraintType,ConstraintType> ret = new HashMap<>();
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
HashMap<Type,Type> ret = new HashMap<>();
ret.put(new RefType("java.lang.Integer",this,-1).TYPE(ass, this), new RefType("java.lang.Integer",this,-1).TYPE(ass, this));
ret.put(new RefType("java.lang.Double",this,-1).TYPE(ass, this), new RefType("java.lang.Double",this,-1).TYPE(ass, this));
ret.put(new RefType("java.lang.Float",this,-1).TYPE(ass, this), new RefType("java.lang.Float",this,-1).TYPE(ass, this));

View File

@ -16,7 +16,6 @@ import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.Pair;
@ -85,7 +84,7 @@ public abstract class Operator extends SyntaxTreeNode
* @param ass
* @return
*/
public abstract HashMap<ConstraintType,ConstraintType> getReturnTypes(TypeAssumptions ass);
public abstract HashMap<Type,Type> getReturnTypes(TypeAssumptions ass);
@Override

View File

@ -13,7 +13,6 @@ import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.syntaxtree.statement.Binary;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
@ -45,8 +44,8 @@ public abstract class RelOp extends Operator
}
@Override
public HashMap<ConstraintType,ConstraintType> getReturnTypes(TypeAssumptions ass) {
HashMap<ConstraintType,ConstraintType> ret = new HashMap<>();
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
HashMap<Type,Type> ret = new HashMap<>();
ret.put(new RefType("java.lang.Boolean",this,-1).TYPE(ass, this), new RefType("java.lang.Integer",this,-1).TYPE(ass, this));
ret.put(new RefType("java.lang.Boolean",this,-1).TYPE(ass, this), new RefType("java.lang.Double",this,-1).TYPE(ass, this));
ret.put(new RefType("java.lang.Boolean",this,-1).TYPE(ass, this), new RefType("java.lang.Float",this,-1).TYPE(ass, this));

View File

@ -25,7 +25,6 @@ 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.ConstraintType;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.OderConstraint;
@ -179,8 +178,8 @@ public class Binary extends BinaryExpr
*/
if(this.getType()==null)this.set_Type(TypePlaceholder.fresh(this));
OderConstraint oderCons = new OderConstraint();
HashMap<ConstraintType,ConstraintType> rMap = this.op.getReturnTypes(assumptions);
for(ConstraintType rT : rMap.keySet()){
HashMap<Type,Type> rMap = this.op.getReturnTypes(assumptions);
for(Type rT : rMap.keySet()){
UndConstraint c = new UndConstraint();
c.addConstraint(this.getType().TYPE(assumptions, this),rT);
c.addConstraint(this.expr1.getType().TYPE(assumptions, this), rMap.get(rT));

View File

@ -186,8 +186,8 @@ public class Block extends Statement
}
else {
TypePlaceholder tph = TypePlaceholder.fresh(this);
ret.add(new SingleConstraint(this.getType().TYPE(assumptions, this), new ConstraintType(tph)));
ret.add(new SingleConstraint(stmt.getType().TYPE(assumptions, this), new ConstraintType(tph)));
ret.add(new SingleConstraint(this.getType().TYPE(assumptions, this), tph));
ret.add(new SingleConstraint(stmt.getType().TYPE(assumptions, this), tph));
this.setType(tph);
}
}

View File

@ -29,6 +29,7 @@ import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.assumptions.LocalVarAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -367,6 +368,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable
this.setType(replaceType);
}
assumptions.addAssumption(new LocalVarAssumption(this, this.getType())); //Bevor der Typ auf Void gesetzt wird.
//if(this.getType() == null)throw new DebugException("Parser Post Processing nicht aufgerufen");
ret.add(new SingleConstraint(this.getType().TYPE(assumptions, this), this.getType().TYPE(assumptions, this)));
//assumptions.remove(null); // falls Variable mit diesem Namen bereits vorhanden.
this.setReturnType(new Void(this,0)); //Return typ einer Variablendeklaration ist Void
@ -381,7 +383,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable
}
@Override
public void parserPostProcessing(SyntaxTreeNode parent) {
public void parserPostProcessing(SyntaxTreeNode parent) {
super.parserPostProcessing(parent);
if(this.getType()==null || this.getType() instanceof TypePlaceholder)this.setType(TypePlaceholder.fresh(this));
}

View File

@ -16,7 +16,6 @@ import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.OderConstraint;
@ -254,8 +253,8 @@ public class MethodCall extends Expr
//Ein Constraint ¼r die Parameter der Methode...
for(int i=0; i<methodAssumption.getParaCount();i++){
//Type der Argument Expressions <. AssumedType der Parameter
ConstraintType ct1 = this.getArgumentList().argumentAt(i).getType().TYPE(assumptions, this);
ConstraintType ct2 = methodAssumption.getParameterType(i).TYPE(assumptions, this);
Type ct1 = this.getArgumentList().argumentAt(i).getType().TYPE(assumptions, this);
Type ct2 = methodAssumption.getParameterType(i).TYPE(assumptions, this);
methodConstraint.addConstraint(ct1 , ct2);
}
//Ein Constraint ¼r den Receiver der Methode (falls vorhanden)...

View File

@ -8,7 +8,6 @@ import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -91,11 +90,11 @@ public class BoundedGenericTypeVar extends GenericTypeVar
Menge<ObjectType> tempBounds = new Menge<>();
if(this.bounds != null){
for(ObjectType ev : this.bounds){
ConstraintType extendsType = ev.TYPE(ass, this);
Type extendsType = ev.TYPE(ass, this);
if(extendsType == null)throw new TypeinferenceException("Der Typ "+ev.getName()+" ist nicht korrekt", this);
//TODO: ??? stimmt der Cast???
tempBounds.add((ObjectType)extendsType.getType());
tempBounds.add((ObjectType)extendsType);
//ret.add(new SingleConstraint(ass.getTypeFor(this, this), extendsType ));
}
}

View File

@ -4,7 +4,6 @@ import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -152,9 +151,9 @@ public class ExtendsWildcardType extends WildcardType implements ITypeContainer,
}
@Override
public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent) {
public Type TYPE(TypeAssumptions ass, SyntaxTreeNode parent) {
//Folgender TypeCast ist sicher. Wird ein ObjectType in einen ConstraintType umgewandelt und wieder zurück, kann kein Fehler auftreten.
this.innerType = (ObjectType) this.innerType.TYPE(ass, parent).getType();
this.innerType = (ObjectType) this.innerType.TYPE(ass, parent);
return super.TYPE(ass, parent);
}
}

View File

@ -7,7 +7,6 @@ import java.util.HashMap;
import java.util.Iterator;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair;
@ -211,7 +210,7 @@ public class GenericTypeVar extends ObjectType
}
@Override
public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent) {
public Type TYPE(TypeAssumptions ass, SyntaxTreeNode parent) {
ass.addGenericVarAssumption(this); //Eine GenericTypeVar kann nur an Stellen vorkommen, an denen sie auch ¼ltig ist. Daher kann sie den Assumptions hinzugefügt werden.
return super.TYPE(ass, parent);
}

View File

@ -14,7 +14,6 @@ import de.dhbwstuttgart.myexception.SCException;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable;
@ -783,8 +782,8 @@ public class RefType extends ObjectType implements IMatchable
}
@Override
public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent){
ConstraintType t = super.TYPE(ass,parent);
public Type TYPE(TypeAssumptions ass, SyntaxTreeNode parent){
Type t = super.TYPE(ass,parent);
//((RefType)t.getType()).set_ParaList(this.get_ParaList());
return t;
}

View File

@ -3,7 +3,6 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -149,8 +148,8 @@ public class SuperWildcardType extends WildcardType implements ITypeContainer, I
}
@Override
public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent) {
this.innerType = (ObjectType) this.innerType.TYPE(ass, parent).getType();
public Type TYPE(TypeAssumptions ass, SyntaxTreeNode parent) {
this.innerType = (ObjectType) this.innerType.TYPE(ass, parent);
return super.TYPE(ass, parent);
}

View File

@ -9,7 +9,6 @@ import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -280,8 +279,8 @@ public abstract class Type extends SyntaxTreeNode implements IItemWithOffset
}
*/
//TODO: checkType wird nicht mehr gebraucht. TYPE übernimmt dessen Aufgabe. Es muss nur sichergestellt werden, dass jeder Typ in den Constraints landet, dadurch wird ¼r jeden Typ die Methode TYPE aufgerufen.
public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent){
ConstraintType t = ass.getTypeFor(this, parent);
public Type TYPE(TypeAssumptions ass, SyntaxTreeNode parent){
Type t = ass.getTypeFor(this, parent);
if(t==null)
throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent);
return t;

View File

@ -11,7 +11,6 @@ import de.dhbwstuttgart.logger.*;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable;
@ -44,8 +43,8 @@ public class TypePlaceholder extends ObjectType
@Override
public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent) {
return new ConstraintType(this);
public Type TYPE(TypeAssumptions ass, SyntaxTreeNode parent) {
return this;
}
// ino.method.TypePlaceholder.26794.defdescription type=javadoc

View File

@ -4,7 +4,6 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
@ -71,8 +70,8 @@ public class Void extends RefType
// ino.end
@Override
public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent){
return new ConstraintType(this);
public Type TYPE(TypeAssumptions ass, SyntaxTreeNode parent){
return this;
}
@Override

View File

@ -3,7 +3,6 @@ package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -83,9 +82,9 @@ public class WildcardType extends Type{
}
@Override
public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent) {
this.innerType = (ObjectType) innerType.TYPE(ass, this).getType();
return new ConstraintType(this);
public Type TYPE(TypeAssumptions ass, SyntaxTreeNode parent) {
this.innerType = (ObjectType) innerType.TYPE(ass, this);
return this;
}
public boolean equals(Object obj)

View File

@ -1,9 +0,0 @@
package de.dhbwstuttgart.typeinference;
public class ConstraintPair extends Pair{
public ConstraintPair(ConstraintType t1, ConstraintType t2){
super(t1.getType(), t2.getType());
}
}

View File

@ -18,13 +18,14 @@ public class OderConstraint extends OderMenge<Pair>{
* Erstellt ein neues Oder Constraint und f<EFBFBD>gt bereits ein Constraint hinzu.
* @param p1
* @param p2
*/
public OderConstraint(ConstraintType p1, ConstraintType p2){
public OderConstraint(Pair p1, Pair p2){
if(p1 == null || p2 == null)throw new NullPointerException();
ConstraintPair constraintPair = new ConstraintPair(p1,p2);
Pair constraintPair = new Pair(p1,p2);
oderConstraintPairs = new Menge<UndConstraint>();
this.addConstraint(constraintPair);
}
*/
public OderConstraint(){
oderConstraintPairs = new Menge<UndConstraint>();
@ -48,15 +49,15 @@ public class OderConstraint extends OderMenge<Pair>{
* @param p1
* @param p2
*/
public void addConstraint(ConstraintType p1, ConstraintType p2){
addConstraint(new ConstraintPair(p1,p2));
public void addConstraint(Type p1, Type p2){
addConstraint(new Pair(p1,p2));
}
/**
* Falls die Type des toAdd-Pairs nicht vom Typ RefType bzw. TypePlaceholder sind, so werden sie in einen RefType umgewandelt.
* @param toAdd
*/
public void addConstraint(ConstraintPair toAdd){
public void addConstraint(Pair toAdd){
oderConstraintPairs.add(new SingleConstraint(toAdd));
}

View File

@ -25,9 +25,10 @@ public class SingleConstraint extends UndConstraint{
private Pair constraintPair; //entspricht θ condition θ'
//private R condition; //entspricht der condition (R)
public SingleConstraint(ConstraintType p1, ConstraintType p2){
public SingleConstraint(Type p1, Type p2){
//super(p1,p2);
ConstraintPair constraintPair = new ConstraintPair(p1,p2);//super.getConstraintPairs().firstElement();
if(p1 == null || p2 == null)throw new NullPointerException();
Pair constraintPair = new Pair(p1,p2);//super.getConstraintPairs().firstElement();
this.addConstraint(constraintPair);
}
@ -38,7 +39,7 @@ public class SingleConstraint extends UndConstraint{
return ret;
}
public SingleConstraint(ConstraintPair toAdd) {
public SingleConstraint(Pair toAdd) {
this.addConstraint(toAdd);
}
@ -53,7 +54,7 @@ public class SingleConstraint extends UndConstraint{
return ret;
}
public void addConstraint(ConstraintPair toAdd){
public void addConstraint(Pair toAdd){
if(constraintPair != null)throw new DebugException("Ein Constraint darf nur aus einem ConstraintPair bestehen. Das hinzufügen von "+ toAdd + " ist nicht möglich.");
Type p1 = toAdd.TA1;

View File

@ -30,8 +30,8 @@ public class UndConstraint extends UndMenge<Pair> {
return ret.firstElement();
}
public void addConstraint(ConstraintType type, ConstraintType rT) {
Pair p = new ConstraintPair(type, rT);
public void addConstraint(Type type, Type rT) {
Pair p = new Pair(type, rT);
this.set.add(new EinzelElement<Pair>(p));
}

View File

@ -15,7 +15,6 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
import de.dhbwstuttgart.typeinference.ConstraintType;
import de.dhbwstuttgart.typeinference.FunN;
import de.dhbwstuttgart.typeinference.FunNInterface;
import de.dhbwstuttgart.typeinference.FunNMethod;
@ -284,7 +283,7 @@ public class TypeAssumptions {
* @param t
* @return null, falls der Typ nicht vorhanden ist.
*/
public ConstraintType getTypeFor(Type t, SyntaxTreeNode inNode){
public Type getTypeFor(Type t, SyntaxTreeNode inNode){
/*
if(t instanceof WildcardType){
WildcardType wt = (WildcardType)t;
@ -315,12 +314,12 @@ public class TypeAssumptions {
//Der RefType muss zusätzlich seine Parameter prüfen.
Menge<Type> parameterList = new Menge<>();
if(ret.get_ParaList()!=null)for(Type param : ret.get_ParaList()){
ConstraintType ct = param.TYPE(this, inNode);
parameterList.add(ct.getType());
Type ct = param.TYPE(this, inNode);
parameterList.add(ct);
}
ret.set_ParaList(parameterList);
return new ConstraintType(ret);
return ret;
}
}
//Auch die generischen Variablen durchsuchen:
@ -343,11 +342,11 @@ public class TypeAssumptions {
if(sameContext){
TypeAssumptions.log.debug(t+" ist in Klasse: "+ass.getAssumedType().getParentClass(), Section.ASSUMPTIONS);
return new ConstraintType(ass.getAssumedType());
return ass.getAssumedType();
}else{
TypeAssumptions.log.debug(t+" ist NICHT in Klasse: "+ass.getAssumedType().getParentClass(), Section.ASSUMPTIONS);
//Ist die Generische Variable nicht aus dieser Klasse, so muss sie zu einem TPH umgewandelt werden:
return new ConstraintType(ass.getAssumedType().getTypePlaceHolder(inNode));
return ass.getAssumedType().getTypePlaceHolder(inNode);
}
}
}
@ -357,17 +356,17 @@ public class TypeAssumptions {
String name = t.getName().toString();
switch(name){
case "int":
return new ConstraintType(new RefType("java.lang.Integer",t.getParent(),t.getOffset()));
return new RefType("java.lang.Integer",t.getParent(),t.getOffset());
case "boolean":
return new ConstraintType(new RefType("java.lang.Boolean",t.getParent(),t.getOffset()));
return new RefType("java.lang.Boolean",t.getParent(),t.getOffset());
case "double":
return new ConstraintType(new RefType("java.lang.Double",t.getParent(),t.getOffset()));
return new RefType("java.lang.Double",t.getParent(),t.getOffset());
case "float":
return new ConstraintType(new RefType("java.lang.Float",t.getParent(),t.getOffset()));
return new RefType("java.lang.Float",t.getParent(),t.getOffset());
case "long":
return new ConstraintType(new RefType("java.lang.Long",t.getParent(),t.getOffset()));
return new RefType("java.lang.Long",t.getParent(),t.getOffset());
case "char":
return new ConstraintType(new RefType("java.lang.Character",t.getParent(),t.getOffset()));
return new RefType("java.lang.Character",t.getParent(),t.getOffset());
}
throw new TypeinferenceException("Der Typ "+t.getName()+" ist nicht korrekt",inNode);
@ -410,9 +409,9 @@ public class TypeAssumptions {
}
public Type checkType(RefType type, SyntaxTreeNode parent) {
ConstraintType t = this.getTypeFor(type, parent); //Richtigkeit des Typnahmensprüfen
type.setName(t.getType().getName()); //Und diesen auf den Typ anwenden
return t.getType();
Type t = this.getTypeFor(type, parent); //Richtigkeit des Typnahmensprüfen
type.setName(t.getName()); //Und diesen auf den Typ anwenden
return t;
}
/**

View File

@ -74,8 +74,8 @@ public class FC_TTO
public void generateFullyNamedTypes(TypeAssumptions ass) {
for(Pair p : this.FC){
p.TA1 = p.TA1.TYPE(ass, p.TA1.getParent()).getType();//ass.getTypeFor(p.TA1, p.TA1.getParent()).getType();
p.TA2 = p.TA2.TYPE(ass, p.TA2.getParent()).getType();//ass.getTypeFor(p.TA2, p.TA2.getParent()).getType();
p.TA1 = p.TA1.TYPE(ass, p.TA1.getParent());//ass.getTypeFor(p.TA1, p.TA1.getParent()).getType();
p.TA2 = p.TA2.TYPE(ass, p.TA2.getParent());//ass.getTypeFor(p.TA2, p.TA2.getParent()).getType();
}
}
}

View File

@ -33,7 +33,6 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.ObjectType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
import de.dhbwstuttgart.typeinference.ConstraintPair;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.Pair;