forked from JavaTX/JavaCompilerCore
Merge branch 'master' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore
This commit is contained in:
commit
60c515a40d
8
bin/.gitignore
vendored
8
bin/.gitignore
vendored
@ -1,8 +1,8 @@
|
||||
/mycompiler
|
||||
/typinferenz
|
||||
/userinterface
|
||||
/bytecode
|
||||
/myJvmDisassembler
|
||||
/mycompiler
|
||||
/parser
|
||||
/plugindevelopment
|
||||
/syntaxTree
|
||||
/typinferenz
|
||||
/userinterface
|
||||
/bytecode
|
||||
|
@ -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<constructors.length;j++){
|
||||
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);
|
||||
ParameterList paraList = new ParameterList();
|
||||
for(int k=0;k<constructors[j].getParameterTypes().length;k++){
|
||||
String paraType=constructors[j].getParameterTypes()[k].getName();
|
||||
//String paraType=constructors[j].getParameterTypes()[k].getSimpleName();
|
||||
// Fixme HOTI beachte overloaded id
|
||||
// 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>()));
|
||||
}
|
||||
//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;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
|
@ -67,11 +67,11 @@ public abstract class AddOp extends Operator
|
||||
@Override
|
||||
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
|
||||
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.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;
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ public abstract class LogOp extends Operator
|
||||
@Override
|
||||
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
|
||||
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;
|
||||
}
|
||||
|
@ -48,10 +48,10 @@ public abstract class MulOp extends Operator
|
||||
@Override
|
||||
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
|
||||
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.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;
|
||||
}
|
||||
|
@ -60,10 +60,10 @@ public abstract class RelOp extends Operator
|
||||
@Override
|
||||
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
|
||||
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)), 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;
|
||||
}
|
||||
|
124
src/mycompiler/myparser/JavaClassName.java
Normal file
124
src/mycompiler/myparser/JavaClassName.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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()));
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
|
||||
|
||||
/*
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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<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
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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(){
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ interface RR extends BB<String> {
|
||||
class BoundedType1 {
|
||||
|
||||
|
||||
<T1 extends Boolean & Number & AA & RR> m1(AA a) {
|
||||
<T1 extends Boolean & Integer & AA & RR> m1(AA a) {
|
||||
T1 b;
|
||||
a.AAm(b);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
class BoundedType {
|
||||
<T extends Boolean & Number> m(T x) {
|
||||
<T extends Boolean & Integer> m(T x) {
|
||||
r;
|
||||
r=x;
|
||||
return r;
|
||||
|
@ -1,3 +1,3 @@
|
||||
class Plus1_Float_Double {
|
||||
op = (x) -> x+1.0;
|
||||
op = (x) -> x + 1.0;
|
||||
}
|
@ -54,9 +54,9 @@ public class Tester extends TypeInsertTester{
|
||||
Vector<String> testFiles = new Vector<String>();
|
||||
//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");
|
||||
|
35
test/plugindevelopment/TypeInsertTests/LambdaTest22.jav
Normal file
35
test/plugindevelopment/TypeInsertTests/LambdaTest22.jav
Normal 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;
|
||||
}
|
||||
|
||||
}
|
16
test/plugindevelopment/TypeInsertTests/LambdaTest22.java
Normal file
16
test/plugindevelopment/TypeInsertTests/LambdaTest22.java
Normal 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);
|
||||
}
|
||||
}
|
3
test/plugindevelopment/TypeInsertTests/RelOpTest.jav
Normal file
3
test/plugindevelopment/TypeInsertTests/RelOpTest.jav
Normal file
@ -0,0 +1,3 @@
|
||||
class RelOpTest{
|
||||
i = 1 < 1;
|
||||
}
|
16
test/plugindevelopment/TypeInsertTests/RelOpTest.java
Normal file
16
test/plugindevelopment/TypeInsertTests/RelOpTest.java
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user