Merge branch 'master' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore

This commit is contained in:
Martin Plümicke 2014-09-02 09:44:57 +02:00
commit 60c515a40d
38 changed files with 310 additions and 87 deletions

8
bin/.gitignore vendored
View File

@ -1,8 +1,8 @@
/mycompiler
/typinferenz
/userinterface
/bytecode
/myJvmDisassembler /myJvmDisassembler
/mycompiler
/parser /parser
/plugindevelopment /plugindevelopment
/syntaxTree /syntaxTree
/typinferenz
/userinterface
/bytecode

View File

@ -16,6 +16,7 @@ import mycompiler.myclass.Class;
import mycompiler.myclass.Constructor; import mycompiler.myclass.Constructor;
import mycompiler.myclass.Field; import mycompiler.myclass.Field;
import mycompiler.myclass.FieldDeclaration; import mycompiler.myclass.FieldDeclaration;
import mycompiler.myclass.FormalParameter;
import mycompiler.myclass.ImportDeclarations; import mycompiler.myclass.ImportDeclarations;
import mycompiler.myclass.UsedId; import mycompiler.myclass.UsedId;
import mycompiler.myexception.CTypeReconstructionException; import mycompiler.myexception.CTypeReconstructionException;
@ -737,7 +738,7 @@ public class SourceFile
if(t!=null && (t instanceof RefType)&& if(t!=null && (t instanceof RefType)&&
!(t instanceof mycompiler.mytype.Void)){ !(t instanceof mycompiler.mytype.Void)){
Type replaceType = null; Type replaceType = null;
replaceType = globalAssumptions.getTypeFor((RefType)t); replaceType = globalAssumptions.getTypeFor((RefType)t, null);
if(!(replaceType == null))p.TA1 = replaceType; if(!(replaceType == null))p.TA1 = replaceType;
} }
t = p.TA2; t = p.TA2;
@ -745,7 +746,7 @@ public class SourceFile
if(t!=null && (t instanceof RefType)&& if(t!=null && (t instanceof RefType)&&
!(t instanceof mycompiler.mytype.Void)){ !(t instanceof mycompiler.mytype.Void)){
Type replaceType = null; Type replaceType = null;
replaceType = globalAssumptions.getTypeFor((RefType)t); replaceType = globalAssumptions.getTypeFor((RefType)t, null);
if(!(replaceType == null))p.TA2 = replaceType; if(!(replaceType == null))p.TA2 = replaceType;
} }
} }
@ -1216,16 +1217,21 @@ public class SourceFile
for(int j=0;j<constructors.length;j++){ for(int j=0;j<constructors.length;j++){
if(java.lang.reflect.Modifier.isPublic(constructors[j].getModifiers())){ if(java.lang.reflect.Modifier.isPublic(constructors[j].getModifiers())){
String methodName="<init>"; String methodName=className;
CMethodTypeAssumption constructor = new CMethodTypeAssumption(new RefType(className, 0), methodName, new RefType(className,-1), constructors[j].getParameterTypes().length,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null); CMethodTypeAssumption constructor = new CMethodTypeAssumption(new RefType(className, 0), methodName, new RefType(className,-1), constructors[j].getParameterTypes().length,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
ParameterList paraList = new ParameterList();
for(int k=0;k<constructors[j].getParameterTypes().length;k++){ for(int k=0;k<constructors[j].getParameterTypes().length;k++){
String paraType=constructors[j].getParameterTypes()[k].getName(); String paraType=constructors[j].getParameterTypes()[k].getName();
//String paraType=constructors[j].getParameterTypes()[k].getSimpleName(); //String paraType=constructors[j].getParameterTypes()[k].getSimpleName();
// Fixme HOTI beachte overloaded id // Fixme HOTI beachte overloaded id
FormalParameter fpara = new FormalParameter(new DeclId("p"+k));
fpara.setType(new RefType(paraType,-1));
paraList.formalparameter.add(fpara);
constructor.addParaAssumption(new CParaTypeAssumption(className, methodName, constructors[j].getParameterTypes().length,0,paraType, new RefType(paraType,-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>())); constructor.addParaAssumption(new CParaTypeAssumption(className, methodName, constructors[j].getParameterTypes().length,0,paraType, new RefType(paraType,-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>()));
} }
//basicAssumptions.addMethodIntersectionType(new CIntersectionType(constructor)); //basicAssumptions.addMethodIntersectionType(new CIntersectionType(constructor));
Method constructorMethod = mycompiler.myclass.Method.createEmptyMethod(methodName, parentClass); Method constructorMethod = mycompiler.myclass.Method.createEmptyMethod(methodName, parentClass);
constructorMethod.parameterlist = paraList;
parentClass.addField(new Constructor(constructorMethod)); parentClass.addField(new Constructor(constructorMethod));
} }
} }
@ -1234,7 +1240,6 @@ public class SourceFile
basicAssumptions.addClassAssumption(new ClassAssumption(parentClass)); basicAssumptions.addClassAssumption(new ClassAssumption(parentClass));
imports.removeElement(importDecl); imports.removeElement(importDecl);
doneImports.addElement(importDecl); doneImports.addElement(importDecl);
} }
imports.addAll(doneImports); imports.addAll(doneImports);
return basicAssumptions; return basicAssumptions;

View File

@ -128,7 +128,8 @@ public class FieldDeclaration extends Field{
} }
@Override @Override
public ConstraintsSet TYPE(TypeAssumptions publicAssumptions) { 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(); ConstraintsSet ret = new ConstraintsSet();
TypeAssumptions localAssumptions = publicAssumptions.clone(); TypeAssumptions localAssumptions = publicAssumptions.clone();

View File

@ -60,7 +60,7 @@ public class FormalParameter extends SyntaxTreeNode implements ITypeReplacementL
@Override @Override
public boolean equals(Object object) { 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; if(!(object instanceof FormalParameter))return false;
FormalParameter equals = (FormalParameter)object; FormalParameter equals = (FormalParameter)object;
if((this.type==null)!=(equals.type == null))return false; if((this.type==null)!=(equals.type == null))return false;

View File

@ -67,11 +67,11 @@ public abstract class AddOp extends Operator
@Override @Override
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) { public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
HashMap<Type,Type> ret = new HashMap<Type,Type>(); HashMap<Type,Type> ret = new HashMap<Type,Type>();
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.Integer",-1), this), ass.getTypeFor(new RefType("java.lang.Integer",-1),this));
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.Double",-1), this), ass.getTypeFor(new RefType("java.lang.Double",-1),this));
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.Float",-1), this), ass.getTypeFor(new RefType("java.lang.Float",-1),this));
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.Long",-1), this), ass.getTypeFor(new RefType("java.lang.Long",-1),this));
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.String",-1),this), ass.getTypeFor(new RefType("java.lang.String",-1),this));
return ret; return ret;
} }

View File

@ -237,7 +237,7 @@ public abstract class LogOp extends Operator
@Override @Override
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) { public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
HashMap<Type,Type> ret = new HashMap<Type,Type>(); HashMap<Type,Type> ret = new HashMap<Type,Type>();
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; return ret;
} }

View File

@ -48,10 +48,10 @@ public abstract class MulOp extends Operator
@Override @Override
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) { public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
HashMap<Type,Type> ret = new HashMap<Type,Type>(); HashMap<Type,Type> ret = new HashMap<Type,Type>();
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.Integer",-1), this), ass.getTypeFor(new RefType("java.lang.Integer",-1), this));
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.Double",-1), this), ass.getTypeFor(new RefType("java.lang.Double",-1), this));
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.Float",-1), this), ass.getTypeFor(new RefType("java.lang.Float",-1), this));
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.Long",-1), this), ass.getTypeFor(new RefType("java.lang.Long",-1), this));
return ret; return ret;
} }

View File

@ -60,10 +60,10 @@ public abstract class RelOp extends Operator
@Override @Override
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) { public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
HashMap<Type,Type> ret = new HashMap<Type,Type>(); HashMap<Type,Type> ret = new HashMap<Type,Type>();
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), this), ass.getTypeFor(new RefType("java.lang.Integer",-1), this));
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), this), ass.getTypeFor(new RefType("java.lang.Double",-1), this));
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), this), ass.getTypeFor(new RefType("java.lang.Float",-1), this));
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.Long",-1), this));
return ret; return ret;
} }

View File

@ -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<String> packageNames = new Vector<String>();
for(int i = 0; i<names.length-1;i++){
packageNames.add(names[i]);
}
packageName = new PackageName(packageNames);
this.name = names[names.length-1];
}
}
//Auto-generated hashCode:
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result
+ ((packageName == null) ? 0 : packageName.hashCode());
return result;
}
/**
* Namen sind nur gleich, wenn bei den beiden zu vergleichenden JavaClassNames auch das Package angegeben ist
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if(obj instanceof String)
return this.toString().equals(obj) || this.name != null && this.name.equals(obj); //Auch mit Strings als Klassennamen kompatibel TODO: sollte bald obsolet sein
if (getClass() != obj.getClass())
return false;
JavaClassName other = (JavaClassName) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (packageName == null) {
if (other.packageName != null)
return false;
} else if (!packageName.equals(other.packageName))
return false;
return true;
}
@Override
public String toString() {
return packageName.toString() + name;
}
}
class PackageName{
Vector<String> names = new Vector<String>();
public PackageName(Vector<String> 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;
}
}

View File

@ -180,7 +180,7 @@ public class BoolLiteral extends Literal
@Override @Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { 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(); return new ConstraintsSet();
} }

View File

@ -205,7 +205,7 @@ public class DoubleLiteral extends Literal
@Override @Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { 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(); return new ConstraintsSet();
} }

View File

@ -389,7 +389,7 @@ public class IfStmt extends Statement
ret.add(this.else_block.TYPEStmt(assumptions)); ret.add(this.else_block.TYPEStmt(assumptions));
if(!(else_block.getType() instanceof Void))ret.add(new SingleConstraint(else_block.getType(),this.getType())); 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))ret.add(new SingleConstraint(then_block.getType(),this.getType()));
if(then_block.getType() instanceof Void && if(then_block.getType() instanceof Void &&
(else_block == null || else_block.getType() instanceof Void))this.setType(new Void(this.getOffset())); (else_block == null || else_block.getType() instanceof Void))this.setType(new Void(this.getOffset()));

View File

@ -207,7 +207,7 @@ public class IntLiteral extends Literal
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
ConstraintsSet ret = new ConstraintsSet(); ConstraintsSet ret = new ConstraintsSet();
//this.setType(new IntegerType()); //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; return ret;
} }

View File

@ -470,7 +470,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable
ConstraintsSet ret = new ConstraintsSet(); ConstraintsSet ret = new ConstraintsSet();
if((this.getType() instanceof RefType)){ if((this.getType() instanceof RefType)){
Type replaceType = null; Type replaceType = null;
replaceType = assumptions.getTypeFor((RefType)this.getType()); replaceType = assumptions.getTypeFor((RefType)this.getType(), this);
if(replaceType == null) if(replaceType == null)
throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",this); throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",this);
this.setType(replaceType); this.setType(replaceType);

View File

@ -255,7 +255,7 @@ public class NewClass extends Expr
// ret.add(arg.TYPEExpr(assumptions)); // 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));
/* /*

View File

@ -54,9 +54,6 @@ public class PostDecExpr extends UnaryExpr
super(offset,variableLength); super(offset,variableLength);
} }
// ino.end // ino.end
// ino.attribute.expr.25994.declaration
public Expr expr;
// ino.end
// ino.attribute.parserlog.25997.declaration // ino.attribute.parserlog.25997.declaration
protected static Logger parserlog = Logger.getLogger("parser"); protected static Logger parserlog = Logger.getLogger("parser");
// ino.end // ino.end
@ -172,12 +169,6 @@ public class PostDecExpr extends UnaryExpr
expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable);
} }
@Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
// TODO Auto-generated method stub
return null;
}
@Override @Override
public JavaCodeResult printJavaCode(ResultSet resultSet) { public JavaCodeResult printJavaCode(ResultSet resultSet) {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View File

@ -19,6 +19,7 @@ import mycompiler.mytype.GenericTypeVar;
import mycompiler.mytype.Pair; import mycompiler.mytype.Pair;
import mycompiler.mytype.RefType; import mycompiler.mytype.RefType;
import mycompiler.mytype.Type; import mycompiler.mytype.Type;
import mycompiler.mytype.TypePlaceholder;
import mycompiler.mytype.Void; import mycompiler.mytype.Void;
import mycompiler.mytypereconstruction.CSupportData; import mycompiler.mytypereconstruction.CSupportData;
import mycompiler.mytypereconstruction.CTriple; import mycompiler.mytypereconstruction.CTriple;
@ -33,9 +34,14 @@ import org.apache.log4j.Logger;
import typinferenz.ConstraintsSet; import typinferenz.ConstraintsSet;
import typinferenz.JavaCodeResult; import typinferenz.JavaCodeResult;
import typinferenz.OderConstraint;
import typinferenz.ResultSet; import typinferenz.ResultSet;
import typinferenz.UndConstraint;
import typinferenz.assumptions.TypeAssumptions; import typinferenz.assumptions.TypeAssumptions;
@ -54,9 +60,7 @@ public class PostIncExpr extends UnaryExpr
super(offset,variableLength); super(offset,variableLength);
} }
// ino.end // ino.end
// ino.attribute.expr.26028.declaration
public Expr expr;
// ino.end
// ino.attribute.parserlog.26031.declaration // ino.attribute.parserlog.26031.declaration
protected static Logger parserlog = Logger.getLogger("parser"); protected static Logger parserlog = Logger.getLogger("parser");
// ino.end // ino.end
@ -172,16 +176,12 @@ public class PostIncExpr extends UnaryExpr
expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable);
} }
@Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
// TODO Auto-generated method stub
return null;
}
@Override @Override
public JavaCodeResult printJavaCode(ResultSet resultSet) { public JavaCodeResult printJavaCode(ResultSet resultSet) {
// TODO Auto-generated method stub JavaCodeResult ret = new JavaCodeResult();
return null; ret.attach(this.expr.printJavaCode(resultSet));
ret.attach("++");
return ret;
} }
@Override @Override

View File

@ -55,9 +55,6 @@ public class PreDecExpr extends UnaryExpr
} }
// ino.end // ino.end
// ino.attribute.expr.26062.declaration
public Expr expr;
// ino.end
// ino.attribute.parserlog.26065.declaration // ino.attribute.parserlog.26065.declaration
protected static Logger parserlog = Logger.getLogger("parser"); protected static Logger parserlog = Logger.getLogger("parser");
// ino.end // ino.end
@ -171,11 +168,7 @@ public class PreDecExpr extends UnaryExpr
{ {
expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable);
} }
@Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
// TODO Auto-generated method stub
return null;
}
@Override @Override
public JavaCodeResult printJavaCode(ResultSet resultSet) { public JavaCodeResult printJavaCode(ResultSet resultSet) {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View File

@ -54,9 +54,6 @@ public class PreIncExpr extends UnaryExpr
super(offset,variableLength); super(offset,variableLength);
} }
// ino.end // ino.end
// ino.attribute.expr.26096.declaration
public Expr expr;
// ino.end
// ino.attribute.parserlog.26099.declaration // ino.attribute.parserlog.26099.declaration
protected static Logger parserlog = Logger.getLogger("parser"); protected static Logger parserlog = Logger.getLogger("parser");
// ino.end // ino.end
@ -173,12 +170,6 @@ public class PreIncExpr extends UnaryExpr
expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable); expr.addOffsetsToExpression(localAssumption,NameVariable,isMemberVariable);
} }
@Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
// TODO Auto-generated method stub
return null;
}
@Override @Override
public JavaCodeResult printJavaCode(ResultSet resultSet) { public JavaCodeResult printJavaCode(ResultSet resultSet) {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View File

@ -139,7 +139,7 @@ public class StringLiteral extends Literal
@Override @Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { 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); if(this.getType() == null)throw new TypeinferenceException("java.lang.String nicht importiert",this);
return new ConstraintsSet(); return new ConstraintsSet();
} }

View File

@ -3,10 +3,17 @@ package mycompiler.mystatement;
// ino.end // ino.end
// ino.module.UnaryExpr.8655.import // ino.module.UnaryExpr.8655.import
import java.util.Vector; import java.util.Vector;
import typinferenz.ConstraintsSet;
import typinferenz.OderConstraint;
import typinferenz.UndConstraint;
import typinferenz.assumptions.TypeAssumptions;
import mycompiler.mybytecode.ClassFile; import mycompiler.mybytecode.ClassFile;
import mycompiler.mybytecode.CodeAttribute; import mycompiler.mybytecode.CodeAttribute;
import mycompiler.myexception.JVMCodeException; import mycompiler.myexception.JVMCodeException;
// ino.end // ino.end
import mycompiler.mytype.RefType;
import mycompiler.mytype.TypePlaceholder;
@ -16,7 +23,9 @@ public abstract class UnaryExpr extends Expr
// ino.end // ino.end
// ino.class.UnaryExpr.26298.body // ino.class.UnaryExpr.26298.body
{ {
// ino.method.UnaryExpr.26302.definition public Expr expr;
// ino.method.UnaryExpr.26302.definition
public UnaryExpr(int offset,int variableLength) public UnaryExpr(int offset,int variableLength)
// ino.end // ino.end
// ino.method.UnaryExpr.26302.body // 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) public abstract void codegen(ClassFile classfile, CodeAttribute code, Vector paralist)
throws JVMCodeException; throws JVMCodeException;
// ino.end // ino.end
private Vector<RefType> getNumericTypes(){
Vector<RefType> 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 // ino.end

View File

@ -182,7 +182,7 @@ public class WhileStmt extends Statement
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) { public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) {
ConstraintsSet ret = new ConstraintsSet(); ConstraintsSet ret = new ConstraintsSet();
ret.add(expr.TYPEExpr(assumptions)); 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(exprMustBeBool);
ret.add(this.loop_block.TYPEStmt(assumptions)); ret.add(this.loop_block.TYPEStmt(assumptions));
this.setType(loop_block.getType()); this.setType(loop_block.getType());

View File

@ -89,9 +89,9 @@ public class BoundedGenericTypeVar extends GenericTypeVar
//Die Type methode der BoundedGenericTypeVar schreibt zusätzlich noch die Constraints für die bounds //Die Type methode der BoundedGenericTypeVar schreibt zusätzlich noch die Constraints für die bounds
if(this.bounds != null){ if(this.bounds != null){
for(Type ev : this.bounds){ 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); 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; return ret;

View File

@ -91,6 +91,7 @@ public class RefType extends Type implements IMatchable
@Override @Override
public int hashCode() { public int hashCode() {
int hash = 0; int hash = 0;
hash += super.hashCode();
hash += this.name.hashCode();//Nur den Name hashen. Sorgt für langsame, aber funktionierende HashMaps hash += this.name.hashCode();//Nur den Name hashen. Sorgt für langsame, aber funktionierende HashMaps
return hash; return hash;
} }

View File

@ -286,7 +286,7 @@ public class Type implements IItemWithOffset
* @param ass - Die Assumptions für den jeweiligen Kontext in dem sich der Typ befindet. * @param ass - Die Assumptions für den jeweiligen Kontext in dem sich der Typ befindet.
*/ */
public Type checkType(TypeAssumptions ass, IItemWithOffset parent){ public Type checkType(TypeAssumptions ass, IItemWithOffset parent){
Type t = ass.getTypeFor(this); Type t = ass.getTypeFor(this, this);
if(t==null) if(t==null)
throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent); throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent);
return t; return t;

View File

@ -2,6 +2,7 @@ package typinferenz.assumptions;
import typinferenz.TypeInsertable; import typinferenz.TypeInsertable;
import typinferenz.Typeable; import typinferenz.Typeable;
import mycompiler.myparser.JavaClassName;
import mycompiler.mytype.*; import mycompiler.mytype.*;
import mycompiler.myclass.Class; import mycompiler.myclass.Class;
@ -23,8 +24,8 @@ public class Assumption {
return this.typable.getType(); return this.typable.getType();
} }
public String getIdentifier(){ public JavaClassName getIdentifier(){
return typable.getIdentifier(); return new JavaClassName(typable.getIdentifier());
} }
} }

View File

@ -2,6 +2,7 @@ package typinferenz.assumptions;
import mycompiler.myclass.Field; import mycompiler.myclass.Field;
import mycompiler.myclass.Class; import mycompiler.myclass.Class;
import mycompiler.myparser.JavaClassName;
import mycompiler.mytype.RefType; import mycompiler.mytype.RefType;
public class FieldAssumption extends Assumption { public class FieldAssumption extends Assumption {
@ -19,8 +20,8 @@ public class FieldAssumption extends Assumption {
return this.parentClass; return this.parentClass;
} }
public String getIdentifier(){ public JavaClassName getIdentifier(){
return this.field.getIdentifier(); return new JavaClassName(this.field.getIdentifier());
} }
@Override @Override

View File

@ -1,5 +1,6 @@
package typinferenz.assumptions; package typinferenz.assumptions;
import mycompiler.myparser.JavaClassName;
import mycompiler.mystatement.LocalVarDecl; import mycompiler.mystatement.LocalVarDecl;
import mycompiler.mytype.GenericTypeVar; import mycompiler.mytype.GenericTypeVar;
import mycompiler.mytype.RefType; import mycompiler.mytype.RefType;
@ -18,8 +19,8 @@ public class GenericVarAssumption extends Assumption{
return genericVar;//new RefType(this.getIdentifier(), -1); return genericVar;//new RefType(this.getIdentifier(), -1);
} }
public String getIdentifier(){ public JavaClassName getIdentifier(){
return genericVar.getName(); return new JavaClassName(genericVar.getName());
} }
public String toString(){ public String toString(){

View File

@ -295,7 +295,7 @@ public class TypeAssumptions {
* @param t * @param t
* @return null, falls der Typ nicht vorhanden ist. * @return null, falls der Typ nicht vorhanden ist.
*/ */
public Type getTypeFor(Type t){ public Type getTypeFor(Type t, IItemWithOffset inNode){
if(t instanceof TypePlaceholder) if(t instanceof TypePlaceholder)
return t; //Handelt es sich um einen TypePlaceholder kann dieser nicht in den Assumptions vorkommen. 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(); 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) { public ConstructorAssumption getConstructorAssumption(String name, int size) {
for(ConstructorAssumption ca : this.constructorAssumptions){ for(ConstructorAssumption ca : this.constructorAssumptions){
System.out.println(ca.getIdentifier().toString() + ca.getParaCount());
if(ca.getParaCount()==size && ca.getIdentifier().equals(name))return ca; if(ca.getParaCount()==size && ca.getIdentifier().equals(name))return ca;
} }
return null; return null;

View File

@ -21,6 +21,7 @@ public class TypeinferenceException extends RuntimeException {
{ {
super(message); super(message);
this.message=message; this.message=message;
if(problemSource == null)throw new DebugException("TypinferenzException ohne Offset: "+this.message);
this.offset=problemSource.getOffset(); this.offset=problemSource.getOffset();
} }

View File

@ -9,7 +9,7 @@ interface RR extends BB<String> {
class BoundedType1 { class BoundedType1 {
<T1 extends Boolean & Number & AA & RR> m1(AA a) { <T1 extends Boolean & Integer & AA & RR> m1(AA a) {
T1 b; T1 b;
a.AAm(b); a.AAm(b);
} }

View File

@ -1,5 +1,5 @@
class BoundedType { class BoundedType {
<T extends Boolean & Number> m(T x) { <T extends Boolean & Integer> m(T x) {
r; r;
r=x; r=x;
return r; return r;

View File

@ -1,3 +1,3 @@
class Plus1_Float_Double { class Plus1_Float_Double {
op = (x) -> x+1.0; op = (x) -> x + 1.0;
} }

View File

@ -54,9 +54,9 @@ public class Tester extends TypeInsertTester{
Vector<String> testFiles = new Vector<String>(); Vector<String> testFiles = new Vector<String>();
//testFiles.add("OL3.jav"); //testFiles.add("OL3.jav");
testFiles.add("Plus1_Float_Double.jav"); testFiles.add("Plus1_Float_Double.jav");
/* ///*
testFiles.add("AchimTest1.jav"); testFiles.add("AchimTest1.jav");
testFiles.add("MatrixWhile.jav"); //testFiles.add("MatrixWhile.jav");
//testFiles.add("BoundedType1.jav"); //testFiles.add("BoundedType1.jav");
testFiles.add("BoundedType2.jav"); testFiles.add("BoundedType2.jav");
testFiles.add("BoundedType.jav"); testFiles.add("BoundedType.jav");

View File

@ -0,0 +1,35 @@
import java.util.Vector;
class Matrix extends Vector<Vector<Integer>> {
Matrix mul(m){
Vector<Vector<Integer>> ret;
ret = new Matrix();
i;
i = 0;
while(i < this.size()) {
v1;
v2;
v1 = this.elementAt(i);
v2 = new Vector<Integer>();
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;
}
}

View File

@ -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<String> mustContain = new Vector<String>();
mustContain.add("TestIfStmt var");
MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain);
}
}

View File

@ -0,0 +1,3 @@
class RelOpTest{
i = 1 < 1;
}

View File

@ -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<String> mustContain = new Vector<String>();
mustContain.add("Boolean i");
MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain);
}
}