diff --git a/bin/.gitignore b/bin/.gitignore index 5774d208a..acd086ea2 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,8 +1,8 @@ -/mycompiler -/typinferenz -/userinterface -/bytecode /myJvmDisassembler +/mycompiler /parser /plugindevelopment /syntaxTree +/typinferenz +/userinterface +/bytecode diff --git a/src/mycompiler/SourceFile.java b/src/mycompiler/SourceFile.java index 2697eb23b..1a4f26858 100755 --- a/src/mycompiler/SourceFile.java +++ b/src/mycompiler/SourceFile.java @@ -16,6 +16,7 @@ import mycompiler.myclass.Class; import mycompiler.myclass.Constructor; import mycompiler.myclass.Field; import mycompiler.myclass.FieldDeclaration; +import mycompiler.myclass.FormalParameter; import mycompiler.myclass.ImportDeclarations; import mycompiler.myclass.UsedId; import mycompiler.myexception.CTypeReconstructionException; @@ -737,7 +738,7 @@ public class SourceFile if(t!=null && (t instanceof RefType)&& !(t instanceof mycompiler.mytype.Void)){ Type replaceType = null; - replaceType = globalAssumptions.getTypeFor((RefType)t); + replaceType = globalAssumptions.getTypeFor((RefType)t, null); if(!(replaceType == null))p.TA1 = replaceType; } t = p.TA2; @@ -745,7 +746,7 @@ public class SourceFile if(t!=null && (t instanceof RefType)&& !(t instanceof mycompiler.mytype.Void)){ Type replaceType = null; - replaceType = globalAssumptions.getTypeFor((RefType)t); + replaceType = globalAssumptions.getTypeFor((RefType)t, null); if(!(replaceType == null))p.TA2 = replaceType; } } @@ -1216,16 +1217,21 @@ public class SourceFile for(int j=0;j(),null); + ParameterList paraList = new ParameterList(); for(int k=0;k())); } //basicAssumptions.addMethodIntersectionType(new CIntersectionType(constructor)); Method constructorMethod = mycompiler.myclass.Method.createEmptyMethod(methodName, parentClass); + constructorMethod.parameterlist = paraList; parentClass.addField(new Constructor(constructorMethod)); } } @@ -1234,7 +1240,6 @@ public class SourceFile basicAssumptions.addClassAssumption(new ClassAssumption(parentClass)); imports.removeElement(importDecl); doneImports.addElement(importDecl); - } imports.addAll(doneImports); return basicAssumptions; diff --git a/src/mycompiler/myclass/FieldDeclaration.java b/src/mycompiler/myclass/FieldDeclaration.java index 694c9e353..91ef8382b 100644 --- a/src/mycompiler/myclass/FieldDeclaration.java +++ b/src/mycompiler/myclass/FieldDeclaration.java @@ -128,7 +128,8 @@ public class FieldDeclaration extends Field{ } @Override public ConstraintsSet TYPE(TypeAssumptions publicAssumptions) { - if(this.wert == null)throw new TypeinferenceException("Typlose Felder müssen mit Wert initialisiert werden", this); + if(this.wert == null && (this.getType() == null || this.getType() instanceof TypePlaceholder)) + throw new TypeinferenceException("Typlose Felder müssen mit Wert initialisiert werden", this); ConstraintsSet ret = new ConstraintsSet(); TypeAssumptions localAssumptions = publicAssumptions.clone(); diff --git a/src/mycompiler/myclass/FormalParameter.java b/src/mycompiler/myclass/FormalParameter.java index c3ef09f7c..cef327a54 100755 --- a/src/mycompiler/myclass/FormalParameter.java +++ b/src/mycompiler/myclass/FormalParameter.java @@ -60,7 +60,7 @@ public class FormalParameter extends SyntaxTreeNode implements ITypeReplacementL @Override public boolean equals(Object object) { - if(!super.equals(object))return false; + //if(!super.equals(object))return false; //Nicht die Position im SyntaxBaum prüfen. if(!(object instanceof FormalParameter))return false; FormalParameter equals = (FormalParameter)object; if((this.type==null)!=(equals.type == null))return false; diff --git a/src/mycompiler/myoperator/AddOp.java b/src/mycompiler/myoperator/AddOp.java index e81767423..c472c504b 100755 --- a/src/mycompiler/myoperator/AddOp.java +++ b/src/mycompiler/myoperator/AddOp.java @@ -67,11 +67,11 @@ public abstract class AddOp extends Operator @Override public HashMap getReturnTypes(TypeAssumptions ass) { HashMap ret = new HashMap(); - ret.put(ass.getTypeFor(new RefType("java.lang.Integer",-1)), ass.getTypeFor(new RefType("java.lang.Integer",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Double",-1)), ass.getTypeFor(new RefType("java.lang.Double",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Float",-1)), ass.getTypeFor(new RefType("java.lang.Float",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Long",-1)), ass.getTypeFor(new RefType("java.lang.Long",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.String",-1)), ass.getTypeFor(new RefType("java.lang.String",-1))); + ret.put(ass.getTypeFor(new RefType("java.lang.Integer",-1), this), ass.getTypeFor(new RefType("java.lang.Integer",-1),this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Double",-1), this), ass.getTypeFor(new RefType("java.lang.Double",-1),this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Float",-1), this), ass.getTypeFor(new RefType("java.lang.Float",-1),this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Long",-1), this), ass.getTypeFor(new RefType("java.lang.Long",-1),this)); + ret.put(ass.getTypeFor(new RefType("java.lang.String",-1),this), ass.getTypeFor(new RefType("java.lang.String",-1),this)); return ret; } diff --git a/src/mycompiler/myoperator/LogOp.java b/src/mycompiler/myoperator/LogOp.java index c59fc4c82..13a52c997 100755 --- a/src/mycompiler/myoperator/LogOp.java +++ b/src/mycompiler/myoperator/LogOp.java @@ -237,7 +237,7 @@ public abstract class LogOp extends Operator @Override public HashMap getReturnTypes(TypeAssumptions ass) { HashMap ret = new HashMap(); - ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1)), ass.getTypeFor(new RefType("java.lang.Boolean",-1))); + ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1), this), ass.getTypeFor(new RefType("java.lang.Boolean",-1), this)); return ret; } diff --git a/src/mycompiler/myoperator/MulOp.java b/src/mycompiler/myoperator/MulOp.java index 8781b4a6d..40d160f3a 100755 --- a/src/mycompiler/myoperator/MulOp.java +++ b/src/mycompiler/myoperator/MulOp.java @@ -48,10 +48,10 @@ public abstract class MulOp extends Operator @Override public HashMap getReturnTypes(TypeAssumptions ass) { HashMap ret = new HashMap(); - ret.put(ass.getTypeFor(new RefType("java.lang.Integer",-1)), ass.getTypeFor(new RefType("java.lang.Integer",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Double",-1)), ass.getTypeFor(new RefType("java.lang.Double",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Float",-1)), ass.getTypeFor(new RefType("java.lang.Float",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Long",-1)), ass.getTypeFor(new RefType("java.lang.Long",-1))); + ret.put(ass.getTypeFor(new RefType("java.lang.Integer",-1), this), ass.getTypeFor(new RefType("java.lang.Integer",-1), this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Double",-1), this), ass.getTypeFor(new RefType("java.lang.Double",-1), this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Float",-1), this), ass.getTypeFor(new RefType("java.lang.Float",-1), this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Long",-1), this), ass.getTypeFor(new RefType("java.lang.Long",-1), this)); return ret; } diff --git a/src/mycompiler/myoperator/RelOp.java b/src/mycompiler/myoperator/RelOp.java index aa5f54b29..1b9e9f24b 100755 --- a/src/mycompiler/myoperator/RelOp.java +++ b/src/mycompiler/myoperator/RelOp.java @@ -60,10 +60,10 @@ public abstract class RelOp extends Operator @Override public HashMap getReturnTypes(TypeAssumptions ass) { HashMap ret = new HashMap(); - ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1)), ass.getTypeFor(new RefType("java.lang.Integer",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1)), ass.getTypeFor(new RefType("java.lang.Double",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1)), ass.getTypeFor(new RefType("java.lang.Float",-1))); - ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1)), ass.getTypeFor(new RefType("java.lang.Long",-1))); + ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1), this), ass.getTypeFor(new RefType("java.lang.Integer",-1), this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1), this), ass.getTypeFor(new RefType("java.lang.Double",-1), this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1), this), ass.getTypeFor(new RefType("java.lang.Float",-1), this)); + ret.put(ass.getTypeFor(new RefType("java.lang.Boolean",-1), this), ass.getTypeFor(new RefType("java.lang.Long",-1), this)); return ret; } diff --git a/src/mycompiler/myparser/JavaClassName.java b/src/mycompiler/myparser/JavaClassName.java new file mode 100644 index 000000000..adf9b0549 --- /dev/null +++ b/src/mycompiler/myparser/JavaClassName.java @@ -0,0 +1,124 @@ +package mycompiler.myparser; + +import java.util.Vector; + +import mycompiler.mytype.RefType; + +/** + * Stellt den Namen einer Java Klasse dar. + * Dieser kann auch den Packagenamen mit beinhalten: java.util.Vector + * + * @author janulrich + * + */ +public class JavaClassName { + + private String name; + private PackageName packageName; + + public JavaClassName(String name){ + String[] names = name.split("[.]"); + boolean match = true; + if(names.length == 1){ + packageName = new PackageName(); + this.name = name; + }else { + name = names[names.length-1]; + Vector packageNames = new Vector(); + for(int i = 0; i names = new Vector(); + + public PackageName(Vector packageNames) { + names = packageNames; + } + + public PackageName() { + //Do nothing + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((names == null) ? 0 : names.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PackageName other = (PackageName) obj; + if (names == null) { + if (other.names != null) + return false; + } else if (!names.equals(other.names)) + return false; + return true; + } + + @Override + public String toString() { + String ret = ""; + if(names == null)return ""; + for(String n : names)ret+=n+"."; + return ret; + } +} diff --git a/src/mycompiler/mystatement/BoolLiteral.java b/src/mycompiler/mystatement/BoolLiteral.java index 7c4c9a373..bdc1bb799 100755 --- a/src/mycompiler/mystatement/BoolLiteral.java +++ b/src/mycompiler/mystatement/BoolLiteral.java @@ -180,7 +180,7 @@ public class BoolLiteral extends Literal @Override public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - this.type = assumptions.getTypeFor(new RefType("java.lang.Boolean",-1)); + this.type = assumptions.getTypeFor(new RefType("java.lang.Boolean",-1), this); return new ConstraintsSet(); } diff --git a/src/mycompiler/mystatement/DoubleLiteral.java b/src/mycompiler/mystatement/DoubleLiteral.java index 7a80f1c13..b3188d7ad 100755 --- a/src/mycompiler/mystatement/DoubleLiteral.java +++ b/src/mycompiler/mystatement/DoubleLiteral.java @@ -205,7 +205,7 @@ public class DoubleLiteral extends Literal @Override public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - this.setType(assumptions.getTypeFor(new RefType("Double",this.getOffset()))); + this.setType(assumptions.getTypeFor(new RefType("Double",this.getOffset()), this)); return new ConstraintsSet(); } diff --git a/src/mycompiler/mystatement/IfStmt.java b/src/mycompiler/mystatement/IfStmt.java index 202cb6d15..421323af0 100755 --- a/src/mycompiler/mystatement/IfStmt.java +++ b/src/mycompiler/mystatement/IfStmt.java @@ -389,7 +389,7 @@ public class IfStmt extends Statement ret.add(this.else_block.TYPEStmt(assumptions)); if(!(else_block.getType() instanceof Void))ret.add(new SingleConstraint(else_block.getType(),this.getType())); } - ret.add(new SingleConstraint(expr.getType(),assumptions.getTypeFor(new RefType("Boolean",0)))); //(expressionDesIfStmt)<.boolean + ret.add(new SingleConstraint(expr.getType(),assumptions.getTypeFor(new RefType("Boolean",0), this))); //(expressionDesIfStmt)<.boolean if(!(then_block.getType() instanceof Void))ret.add(new SingleConstraint(then_block.getType(),this.getType())); if(then_block.getType() instanceof Void && (else_block == null || else_block.getType() instanceof Void))this.setType(new Void(this.getOffset())); diff --git a/src/mycompiler/mystatement/IntLiteral.java b/src/mycompiler/mystatement/IntLiteral.java index 4a71809da..4b486986f 100755 --- a/src/mycompiler/mystatement/IntLiteral.java +++ b/src/mycompiler/mystatement/IntLiteral.java @@ -207,7 +207,7 @@ public class IntLiteral extends Literal public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { ConstraintsSet ret = new ConstraintsSet(); //this.setType(new IntegerType()); - this.set_Type(assumptions.getTypeFor(new RefType("java.lang.Integer",-1))); + this.set_Type(assumptions.getTypeFor(new RefType("java.lang.Integer",-1), this)); return ret; } diff --git a/src/mycompiler/mystatement/LocalVarDecl.java b/src/mycompiler/mystatement/LocalVarDecl.java index bbf420e6e..76b19cd6a 100755 --- a/src/mycompiler/mystatement/LocalVarDecl.java +++ b/src/mycompiler/mystatement/LocalVarDecl.java @@ -470,7 +470,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable ConstraintsSet ret = new ConstraintsSet(); if((this.getType() instanceof RefType)){ Type replaceType = null; - replaceType = assumptions.getTypeFor((RefType)this.getType()); + replaceType = assumptions.getTypeFor((RefType)this.getType(), this); if(replaceType == null) throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",this); this.setType(replaceType); diff --git a/src/mycompiler/mystatement/NewClass.java b/src/mycompiler/mystatement/NewClass.java index dddfb35d3..9f250fff6 100755 --- a/src/mycompiler/mystatement/NewClass.java +++ b/src/mycompiler/mystatement/NewClass.java @@ -255,7 +255,7 @@ public class NewClass extends Expr // ret.add(arg.TYPEExpr(assumptions)); //} - this.setType(assumptions.getTypeFor(new RefType(this.get_Name(),0))); + this.setType(assumptions.getTypeFor(new RefType(this.get_Name(),0), this)); /* diff --git a/src/mycompiler/mystatement/PostDecExpr.java b/src/mycompiler/mystatement/PostDecExpr.java index 2e9a10946..91c0f37c6 100755 --- a/src/mycompiler/mystatement/PostDecExpr.java +++ b/src/mycompiler/mystatement/PostDecExpr.java @@ -54,9 +54,6 @@ public class PostDecExpr extends UnaryExpr super(offset,variableLength); } // ino.end - // ino.attribute.expr.25994.declaration - public Expr expr; - // ino.end // ino.attribute.parserlog.25997.declaration protected static Logger parserlog = Logger.getLogger("parser"); // ino.end @@ -172,12 +169,6 @@ public class PostDecExpr extends UnaryExpr expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); } - @Override - public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - // TODO Auto-generated method stub - return null; - } - @Override public JavaCodeResult printJavaCode(ResultSet resultSet) { // TODO Auto-generated method stub diff --git a/src/mycompiler/mystatement/PostIncExpr.java b/src/mycompiler/mystatement/PostIncExpr.java index ae6ddbf54..c17300d04 100755 --- a/src/mycompiler/mystatement/PostIncExpr.java +++ b/src/mycompiler/mystatement/PostIncExpr.java @@ -19,6 +19,7 @@ import mycompiler.mytype.GenericTypeVar; import mycompiler.mytype.Pair; import mycompiler.mytype.RefType; import mycompiler.mytype.Type; +import mycompiler.mytype.TypePlaceholder; import mycompiler.mytype.Void; import mycompiler.mytypereconstruction.CSupportData; import mycompiler.mytypereconstruction.CTriple; @@ -33,9 +34,14 @@ import org.apache.log4j.Logger; + + + import typinferenz.ConstraintsSet; import typinferenz.JavaCodeResult; +import typinferenz.OderConstraint; import typinferenz.ResultSet; +import typinferenz.UndConstraint; import typinferenz.assumptions.TypeAssumptions; @@ -54,9 +60,7 @@ public class PostIncExpr extends UnaryExpr super(offset,variableLength); } // ino.end - // ino.attribute.expr.26028.declaration - public Expr expr; - // ino.end + // ino.attribute.parserlog.26031.declaration protected static Logger parserlog = Logger.getLogger("parser"); // ino.end @@ -172,16 +176,12 @@ public class PostIncExpr extends UnaryExpr expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); } - @Override - public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - // TODO Auto-generated method stub - return null; - } - @Override public JavaCodeResult printJavaCode(ResultSet resultSet) { - // TODO Auto-generated method stub - return null; + JavaCodeResult ret = new JavaCodeResult(); + ret.attach(this.expr.printJavaCode(resultSet)); + ret.attach("++"); + return ret; } @Override diff --git a/src/mycompiler/mystatement/PreDecExpr.java b/src/mycompiler/mystatement/PreDecExpr.java index 0576c46de..5f0c07183 100755 --- a/src/mycompiler/mystatement/PreDecExpr.java +++ b/src/mycompiler/mystatement/PreDecExpr.java @@ -55,9 +55,6 @@ public class PreDecExpr extends UnaryExpr } // ino.end - // ino.attribute.expr.26062.declaration - public Expr expr; - // ino.end // ino.attribute.parserlog.26065.declaration protected static Logger parserlog = Logger.getLogger("parser"); // ino.end @@ -171,11 +168,7 @@ public class PreDecExpr extends UnaryExpr { expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); } - @Override - public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - // TODO Auto-generated method stub - return null; - } + @Override public JavaCodeResult printJavaCode(ResultSet resultSet) { // TODO Auto-generated method stub diff --git a/src/mycompiler/mystatement/PreIncExpr.java b/src/mycompiler/mystatement/PreIncExpr.java index 839b154fc..de1e4de5e 100755 --- a/src/mycompiler/mystatement/PreIncExpr.java +++ b/src/mycompiler/mystatement/PreIncExpr.java @@ -54,9 +54,6 @@ public class PreIncExpr extends UnaryExpr super(offset,variableLength); } // ino.end - // ino.attribute.expr.26096.declaration - public Expr expr; - // ino.end // ino.attribute.parserlog.26099.declaration protected static Logger parserlog = Logger.getLogger("parser"); // ino.end @@ -173,12 +170,6 @@ public class PreIncExpr extends UnaryExpr expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); } - @Override - public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - // TODO Auto-generated method stub - return null; - } - @Override public JavaCodeResult printJavaCode(ResultSet resultSet) { // TODO Auto-generated method stub diff --git a/src/mycompiler/mystatement/StringLiteral.java b/src/mycompiler/mystatement/StringLiteral.java index 247f8483c..9e56bc8aa 100755 --- a/src/mycompiler/mystatement/StringLiteral.java +++ b/src/mycompiler/mystatement/StringLiteral.java @@ -139,7 +139,7 @@ public class StringLiteral extends Literal @Override public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - this.set_Type(assumptions.getTypeFor(new RefType("String",0))); + this.set_Type(assumptions.getTypeFor(new RefType("String",0), this)); if(this.getType() == null)throw new TypeinferenceException("java.lang.String nicht importiert",this); return new ConstraintsSet(); } diff --git a/src/mycompiler/mystatement/UnaryExpr.java b/src/mycompiler/mystatement/UnaryExpr.java index 6b990df1b..86b32dd3b 100755 --- a/src/mycompiler/mystatement/UnaryExpr.java +++ b/src/mycompiler/mystatement/UnaryExpr.java @@ -3,10 +3,17 @@ package mycompiler.mystatement; // ino.end // ino.module.UnaryExpr.8655.import import java.util.Vector; + +import typinferenz.ConstraintsSet; +import typinferenz.OderConstraint; +import typinferenz.UndConstraint; +import typinferenz.assumptions.TypeAssumptions; import mycompiler.mybytecode.ClassFile; import mycompiler.mybytecode.CodeAttribute; import mycompiler.myexception.JVMCodeException; // ino.end +import mycompiler.mytype.RefType; +import mycompiler.mytype.TypePlaceholder; @@ -16,7 +23,9 @@ public abstract class UnaryExpr extends Expr // ino.end // ino.class.UnaryExpr.26298.body { - // ino.method.UnaryExpr.26302.definition + public Expr expr; + + // ino.method.UnaryExpr.26302.definition public UnaryExpr(int offset,int variableLength) // ino.end // ino.method.UnaryExpr.26302.body @@ -29,5 +38,37 @@ public abstract class UnaryExpr extends Expr public abstract void codegen(ClassFile classfile, CodeAttribute code, Vector paralist) throws JVMCodeException; // ino.end + + private Vector getNumericTypes(){ + Vector ret = new Vector<>(); + ret.add(new RefType("Integer",-1)); + ret.add(new RefType("Long",-1)); + ret.add(new RefType("Double",-1)); + return ret ; + } + + @Override + public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { + if(this.getType() == null)this.setType(TypePlaceholder.fresh(this)); + ConstraintsSet ret = new ConstraintsSet(); + OderConstraint oderConstraint = new OderConstraint(); + ret.add(this.expr.TYPEExpr(assumptions)); + for(RefType t : getNumericTypes()){ + UndConstraint undConstraint = new UndConstraint(); + undConstraint.addConstraint(this.getType(), t); + undConstraint.addConstraint(this.expr.getType(), t); + + oderConstraint.addConstraint(undConstraint); + } + ret.add(oderConstraint); + return ret; + } + + @Override + public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) { + return this.TYPEExpr(assumptions); + } + + } // ino.end diff --git a/src/mycompiler/mystatement/WhileStmt.java b/src/mycompiler/mystatement/WhileStmt.java index aa3824477..ee4e880df 100755 --- a/src/mycompiler/mystatement/WhileStmt.java +++ b/src/mycompiler/mystatement/WhileStmt.java @@ -182,7 +182,7 @@ public class WhileStmt extends Statement public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) { ConstraintsSet ret = new ConstraintsSet(); ret.add(expr.TYPEExpr(assumptions)); - SingleConstraint exprMustBeBool = new SingleConstraint(expr.getType(), assumptions.getTypeFor(new RefType("Boolean", 0))); // while(expr){}; expr <. boolean + SingleConstraint exprMustBeBool = new SingleConstraint(expr.getType(), assumptions.getTypeFor(new RefType("Boolean", 0), this)); // while(expr){}; expr <. boolean ret.add(exprMustBeBool); ret.add(this.loop_block.TYPEStmt(assumptions)); this.setType(loop_block.getType()); diff --git a/src/mycompiler/mytype/BoundedGenericTypeVar.java b/src/mycompiler/mytype/BoundedGenericTypeVar.java index fee474b7b..80632722c 100755 --- a/src/mycompiler/mytype/BoundedGenericTypeVar.java +++ b/src/mycompiler/mytype/BoundedGenericTypeVar.java @@ -89,9 +89,9 @@ public class BoundedGenericTypeVar extends GenericTypeVar //Die Type methode der BoundedGenericTypeVar schreibt zusätzlich noch die Constraints für die bounds if(this.bounds != null){ for(Type ev : this.bounds){ - Type extendsType = ass.getTypeFor(ev); + Type extendsType = ass.getTypeFor(ev, this); if(extendsType == null)throw new TypeinferenceException("Der Typ "+ev.getName()+" ist nicht korrekt", this); - ret.add(new SingleConstraint(ass.getTypeFor(this), extendsType )); + ret.add(new SingleConstraint(ass.getTypeFor(this, this), extendsType )); } } return ret; diff --git a/src/mycompiler/mytype/RefType.java b/src/mycompiler/mytype/RefType.java index 72810d735..6cc1a93a7 100755 --- a/src/mycompiler/mytype/RefType.java +++ b/src/mycompiler/mytype/RefType.java @@ -91,6 +91,7 @@ public class RefType extends Type implements IMatchable @Override public int hashCode() { int hash = 0; + hash += super.hashCode(); hash += this.name.hashCode();//Nur den Name hashen. Sorgt für langsame, aber funktionierende HashMaps return hash; } diff --git a/src/mycompiler/mytype/Type.java b/src/mycompiler/mytype/Type.java index e95ed21ed..d5f7dcc05 100755 --- a/src/mycompiler/mytype/Type.java +++ b/src/mycompiler/mytype/Type.java @@ -286,7 +286,7 @@ public class Type implements IItemWithOffset * @param ass - Die Assumptions für den jeweiligen Kontext in dem sich der Typ befindet. */ public Type checkType(TypeAssumptions ass, IItemWithOffset parent){ - Type t = ass.getTypeFor(this); + Type t = ass.getTypeFor(this, this); if(t==null) throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent); return t; diff --git a/src/typinferenz/assumptions/Assumption.java b/src/typinferenz/assumptions/Assumption.java index d370d85f3..1d52b9d15 100644 --- a/src/typinferenz/assumptions/Assumption.java +++ b/src/typinferenz/assumptions/Assumption.java @@ -2,6 +2,7 @@ package typinferenz.assumptions; import typinferenz.TypeInsertable; import typinferenz.Typeable; +import mycompiler.myparser.JavaClassName; import mycompiler.mytype.*; import mycompiler.myclass.Class; @@ -23,8 +24,8 @@ public class Assumption { return this.typable.getType(); } - public String getIdentifier(){ - return typable.getIdentifier(); + public JavaClassName getIdentifier(){ + return new JavaClassName(typable.getIdentifier()); } } diff --git a/src/typinferenz/assumptions/FieldAssumption.java b/src/typinferenz/assumptions/FieldAssumption.java index 8e36d20de..46243e71b 100644 --- a/src/typinferenz/assumptions/FieldAssumption.java +++ b/src/typinferenz/assumptions/FieldAssumption.java @@ -2,6 +2,7 @@ package typinferenz.assumptions; import mycompiler.myclass.Field; import mycompiler.myclass.Class; +import mycompiler.myparser.JavaClassName; import mycompiler.mytype.RefType; public class FieldAssumption extends Assumption { @@ -19,8 +20,8 @@ public class FieldAssumption extends Assumption { return this.parentClass; } - public String getIdentifier(){ - return this.field.getIdentifier(); + public JavaClassName getIdentifier(){ + return new JavaClassName(this.field.getIdentifier()); } @Override diff --git a/src/typinferenz/assumptions/GenericVarAssumption.java b/src/typinferenz/assumptions/GenericVarAssumption.java index b2fb25971..c564878a4 100644 --- a/src/typinferenz/assumptions/GenericVarAssumption.java +++ b/src/typinferenz/assumptions/GenericVarAssumption.java @@ -1,5 +1,6 @@ package typinferenz.assumptions; +import mycompiler.myparser.JavaClassName; import mycompiler.mystatement.LocalVarDecl; import mycompiler.mytype.GenericTypeVar; import mycompiler.mytype.RefType; @@ -18,8 +19,8 @@ public class GenericVarAssumption extends Assumption{ return genericVar;//new RefType(this.getIdentifier(), -1); } - public String getIdentifier(){ - return genericVar.getName(); + public JavaClassName getIdentifier(){ + return new JavaClassName(genericVar.getName()); } public String toString(){ diff --git a/src/typinferenz/assumptions/TypeAssumptions.java b/src/typinferenz/assumptions/TypeAssumptions.java index 1509f6edb..e2df73abd 100755 --- a/src/typinferenz/assumptions/TypeAssumptions.java +++ b/src/typinferenz/assumptions/TypeAssumptions.java @@ -295,7 +295,7 @@ public class TypeAssumptions { * @param t * @return null, falls der Typ nicht vorhanden ist. */ - public Type getTypeFor(Type t){ + public Type getTypeFor(Type t, IItemWithOffset inNode){ if(t instanceof TypePlaceholder) return t; //Handelt es sich um einen TypePlaceholder kann dieser nicht in den Assumptions vorkommen. @@ -327,7 +327,8 @@ public class TypeAssumptions { if(ass.getIdentifier().equals(t.getName()))return ass.getAssumedType(); } - return null; + //return null; + throw new TypeinferenceException("Der Typ "+t.getName()+" ist nicht korrekt",inNode); } /** @@ -349,6 +350,7 @@ public class TypeAssumptions { */ public ConstructorAssumption getConstructorAssumption(String name, int size) { for(ConstructorAssumption ca : this.constructorAssumptions){ + System.out.println(ca.getIdentifier().toString() + ca.getParaCount()); if(ca.getParaCount()==size && ca.getIdentifier().equals(name))return ca; } return null; diff --git a/src/typinferenz/exceptions/TypeinferenceException.java b/src/typinferenz/exceptions/TypeinferenceException.java index ef5d6c6fa..2fe6897e7 100755 --- a/src/typinferenz/exceptions/TypeinferenceException.java +++ b/src/typinferenz/exceptions/TypeinferenceException.java @@ -21,6 +21,7 @@ public class TypeinferenceException extends RuntimeException { { super(message); this.message=message; + if(problemSource == null)throw new DebugException("TypinferenzException ohne Offset: "+this.message); this.offset=problemSource.getOffset(); } diff --git a/test/plugindevelopment/MartinTestCases/BoundedType1.jav b/test/plugindevelopment/MartinTestCases/BoundedType1.jav index af71bfa73..f56a643e0 100755 --- a/test/plugindevelopment/MartinTestCases/BoundedType1.jav +++ b/test/plugindevelopment/MartinTestCases/BoundedType1.jav @@ -9,7 +9,7 @@ interface RR extends BB { class BoundedType1 { - m1(AA a) { + m1(AA a) { T1 b; a.AAm(b); } diff --git a/test/plugindevelopment/MartinTestCases/BoundedType2.jav b/test/plugindevelopment/MartinTestCases/BoundedType2.jav index 47602aba5..ccb0d6a2f 100755 --- a/test/plugindevelopment/MartinTestCases/BoundedType2.jav +++ b/test/plugindevelopment/MartinTestCases/BoundedType2.jav @@ -1,5 +1,5 @@ class BoundedType { - m(T x) { + m(T x) { r; r=x; return r; diff --git a/test/plugindevelopment/MartinTestCases/Plus1_Float_Double.jav b/test/plugindevelopment/MartinTestCases/Plus1_Float_Double.jav index 75c3baad7..5291001cd 100644 --- a/test/plugindevelopment/MartinTestCases/Plus1_Float_Double.jav +++ b/test/plugindevelopment/MartinTestCases/Plus1_Float_Double.jav @@ -1,3 +1,3 @@ class Plus1_Float_Double { - op = (x) -> x+1.0; + op = (x) -> x + 1.0; } \ No newline at end of file diff --git a/test/plugindevelopment/MartinTestCases/Tester.java b/test/plugindevelopment/MartinTestCases/Tester.java index 2f9778e06..ddea7b3b8 100644 --- a/test/plugindevelopment/MartinTestCases/Tester.java +++ b/test/plugindevelopment/MartinTestCases/Tester.java @@ -54,9 +54,9 @@ public class Tester extends TypeInsertTester{ Vector testFiles = new Vector(); //testFiles.add("OL3.jav"); testFiles.add("Plus1_Float_Double.jav"); - /* + ///* testFiles.add("AchimTest1.jav"); - testFiles.add("MatrixWhile.jav"); + //testFiles.add("MatrixWhile.jav"); //testFiles.add("BoundedType1.jav"); testFiles.add("BoundedType2.jav"); testFiles.add("BoundedType.jav"); diff --git a/test/plugindevelopment/TypeInsertTests/LambdaTest22.jav b/test/plugindevelopment/TypeInsertTests/LambdaTest22.jav new file mode 100644 index 000000000..001e3d5bb --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/LambdaTest22.jav @@ -0,0 +1,35 @@ +import java.util.Vector; + +class Matrix extends Vector> { + + Matrix mul(m){ + Vector> ret; + ret = new Matrix(); + i; + i = 0; + while(i < this.size()) { + v1; + v2; + v1 = this.elementAt(i); + v2 = new Vector(); + j; + j = 0; + while(j < v1.size()) { + erg; + erg = 0; + k; + k = 0; + while(k < v1.size()) { + erg = erg + v1.elementAt(k).intValue() * m.elementAt(k).elementAt(j).intValue(); + k++; + } + v2.addElement(new Integer(erg)); + j++; + } + ret.addElement(v2); + i++; + } + return ret; + } + +} \ No newline at end of file diff --git a/test/plugindevelopment/TypeInsertTests/LambdaTest22.java b/test/plugindevelopment/TypeInsertTests/LambdaTest22.java new file mode 100644 index 000000000..569bfb2f8 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/LambdaTest22.java @@ -0,0 +1,16 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class LambdaTest22 { + private static final String TEST_FILE = "LambdaTest22.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + mustContain.add("TestIfStmt var"); + MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain); + } +} diff --git a/test/plugindevelopment/TypeInsertTests/RelOpTest.jav b/test/plugindevelopment/TypeInsertTests/RelOpTest.jav new file mode 100644 index 000000000..a481747d5 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/RelOpTest.jav @@ -0,0 +1,3 @@ +class RelOpTest{ + i = 1 < 1; +} \ No newline at end of file diff --git a/test/plugindevelopment/TypeInsertTests/RelOpTest.java b/test/plugindevelopment/TypeInsertTests/RelOpTest.java new file mode 100644 index 000000000..76e264c02 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/RelOpTest.java @@ -0,0 +1,16 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class RelOpTest { + private static final String TEST_FILE = "RelOpTest.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + mustContain.add("Boolean i"); + MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain); + } +}