forked from JavaTX/JavaCompilerCore
Kleine Verbesserungen
This commit is contained in:
parent
0aa5c06b73
commit
e7034f82ce
@ -737,7 +737,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 +745,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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()));
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -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));
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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());
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
test/plugindevelopment/TypeInsertTests/LambdaTest22.jav
Normal file
25
test/plugindevelopment/TypeInsertTests/LambdaTest22.jav
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
class Matrix extends Vector<Vector<Integer>> {
|
||||||
|
|
||||||
|
mvmul(Test v) {
|
||||||
|
i;
|
||||||
|
ele;
|
||||||
|
v.add(i);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Test{
|
||||||
|
|
||||||
|
void add(Integer i){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
elementAt(Integer i){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
size(){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
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…
x
Reference in New Issue
Block a user