diff --git a/src/de/dhbwstuttgart/syntaxtree/Constructor.java b/src/de/dhbwstuttgart/syntaxtree/Constructor.java index e56619a7..cb5914ad 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Constructor.java +++ b/src/de/dhbwstuttgart/syntaxtree/Constructor.java @@ -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[] { }, "", 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[] { }, "", parentClass.name, il, _cp); - methode.genByteCode(cg); //Aufrufen um Iteration �ber Block zu starten + super.genByteCode(cg); //Aufrufen um Iteration �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 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 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 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 get_Name() { - return this.methode.get_Name(); - } - - - @Override - public Menge getDeclIdMenge() { - return this.methode.getDeclIdMenge(); - } - - - @Override - public void setDeclIdMenge(Menge 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(); - } - } diff --git a/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java b/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java index 8d321a04..99f00a94 100644 --- a/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java +++ b/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java @@ -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; diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 8d9a0d4d..7dbc0864 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -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 substHash = new Hashtable(); //fuer jedes Paar komplett neue Variablen @@ -310,12 +310,12 @@ public class SourceFile // 1. Menge <= in FC aufnehmen --> Iteration ueber alle Klassen Menge 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 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); } diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/AddOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/AddOp.java index f7bf8281..c9e95ee3 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/AddOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/AddOp.java @@ -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 getReturnTypes(TypeAssumptions ass) { - HashMap ret = new HashMap(); + public HashMap getReturnTypes(TypeAssumptions ass) { + HashMap 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)); diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/LogOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/LogOp.java index a497feb4..afea3229 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/LogOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/LogOp.java @@ -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 getReturnTypes(TypeAssumptions ass) { - HashMap ret = new HashMap<>(); + public HashMap getReturnTypes(TypeAssumptions ass) { + HashMap 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; diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/MulOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/MulOp.java index b25c8044..d031b647 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/MulOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/MulOp.java @@ -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 getReturnTypes(TypeAssumptions ass) { - HashMap ret = new HashMap<>(); + public HashMap getReturnTypes(TypeAssumptions ass) { + HashMap 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)); diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/Operator.java b/src/de/dhbwstuttgart/syntaxtree/operator/Operator.java index dd1559ec..8639bb8f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/Operator.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/Operator.java @@ -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 getReturnTypes(TypeAssumptions ass); + public abstract HashMap getReturnTypes(TypeAssumptions ass); @Override diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java index 64a07c17..eb9178d7 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java @@ -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 getReturnTypes(TypeAssumptions ass) { - HashMap ret = new HashMap<>(); + public HashMap getReturnTypes(TypeAssumptions ass) { + HashMap 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)); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java index c71fbe04..9e7d1acf 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java @@ -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 rMap = this.op.getReturnTypes(assumptions); - for(ConstraintType rT : rMap.keySet()){ + HashMap 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)); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Block.java b/src/de/dhbwstuttgart/syntaxtree/statement/Block.java index 348e0724..ab311454 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Block.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Block.java @@ -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); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java index 464a692a..494bffd5 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java @@ -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)); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java index 3815d88b..e1b03479 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java @@ -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 für die Parameter der Methode... for(int i=0; i 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 )); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java index a48046b0..f91d6179 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/ExtendsWildcardType.java @@ -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); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java b/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java index 331c8831..f97dc6dd 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java @@ -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 gültig ist. Daher kann sie den Assumptions hinzugefügt werden. return super.TYPE(ass, parent); } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index e4cb9869..a4ce2738 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -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; } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java index 5c97ea97..50f2d7d5 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java @@ -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); } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/Type.java b/src/de/dhbwstuttgart/syntaxtree/type/Type.java index ccb0a626..7b577602 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/Type.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/Type.java @@ -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 fü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; diff --git a/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java b/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java index 8ea21928..d93160b9 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java @@ -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 diff --git a/src/de/dhbwstuttgart/syntaxtree/type/Void.java b/src/de/dhbwstuttgart/syntaxtree/type/Void.java index 77b3234f..773a5fe8 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/Void.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/Void.java @@ -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 diff --git a/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java index a6e4566d..8fc40804 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java @@ -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) diff --git a/src/de/dhbwstuttgart/typeinference/ConstraintPair.java b/src/de/dhbwstuttgart/typeinference/ConstraintPair.java deleted file mode 100644 index 220e5673..00000000 --- a/src/de/dhbwstuttgart/typeinference/ConstraintPair.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.dhbwstuttgart.typeinference; - -public class ConstraintPair extends Pair{ - - public ConstraintPair(ConstraintType t1, ConstraintType t2){ - super(t1.getType(), t2.getType()); - } - -} diff --git a/src/de/dhbwstuttgart/typeinference/OderConstraint.java b/src/de/dhbwstuttgart/typeinference/OderConstraint.java index 0c631095..686a3eb9 100755 --- a/src/de/dhbwstuttgart/typeinference/OderConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/OderConstraint.java @@ -18,13 +18,14 @@ public class OderConstraint extends OderMenge{ * Erstellt ein neues Oder Constraint und f�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(); this.addConstraint(constraintPair); } + */ public OderConstraint(){ oderConstraintPairs = new Menge(); @@ -48,15 +49,15 @@ public class OderConstraint extends OderMenge{ * @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)); } diff --git a/src/de/dhbwstuttgart/typeinference/SingleConstraint.java b/src/de/dhbwstuttgart/typeinference/SingleConstraint.java index f405b9ee..b8714689 100755 --- a/src/de/dhbwstuttgart/typeinference/SingleConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/SingleConstraint.java @@ -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; diff --git a/src/de/dhbwstuttgart/typeinference/UndConstraint.java b/src/de/dhbwstuttgart/typeinference/UndConstraint.java index a204b426..a6deb253 100755 --- a/src/de/dhbwstuttgart/typeinference/UndConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/UndConstraint.java @@ -30,8 +30,8 @@ public class UndConstraint extends UndMenge { 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(p)); } diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java index 1f7043d2..2fea0a02 100755 --- a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java @@ -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 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; } /** diff --git a/src/de/dhbwstuttgart/typeinference/unify/FC_TTO.java b/src/de/dhbwstuttgart/typeinference/unify/FC_TTO.java index 56cf9176..f27119a6 100755 --- a/src/de/dhbwstuttgart/typeinference/unify/FC_TTO.java +++ b/src/de/dhbwstuttgart/typeinference/unify/FC_TTO.java @@ -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(); } } } diff --git a/src/de/dhbwstuttgart/typeinference/unify/Unify.java b/src/de/dhbwstuttgart/typeinference/unify/Unify.java index 6569360f..8e54398a 100755 --- a/src/de/dhbwstuttgart/typeinference/unify/Unify.java +++ b/src/de/dhbwstuttgart/typeinference/unify/Unify.java @@ -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;