Assumptions erweitern

This commit is contained in:
JanUlrich 2016-04-11 18:35:18 +02:00
parent d63f08bf33
commit de238b90df
6 changed files with 39 additions and 31 deletions

View File

@ -2298,7 +2298,7 @@ case 199:
{
de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("\nParser --> Zuweisung1!\n", Section.PARSER);
Assign Ass = new Assign(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength());
LocalOrFieldVar LOFV = new LocalOrFieldVar(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength());
LocalOrFieldVarOrClassname LOFV = new LocalOrFieldVarOrClassname(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength());
LOFV.set_UsedId(((UsedId)yyVals[-2+yyTop]));
/*auskommentiert von Andreas Stadelmeier (a10023) LOFV.setType(TypePlaceholder.fresh());*/
/*auskommentiert von Andreas Stadelmeier (a10023) Ass.setType(TypePlaceholder.fresh());*/
@ -2324,7 +2324,7 @@ case 200:
// line 1718 "./../src/de/dhbwstuttgart/parser/JavaParser.jay"
{
Assign Ass =new Assign(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength());
LocalOrFieldVar LOFV = new LocalOrFieldVar(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength());
LocalOrFieldVarOrClassname LOFV = new LocalOrFieldVarOrClassname(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength());
LOFV.set_UsedId(((UsedId)yyVals[-2+yyTop]));
/*auskommentiert von Andreas Stadelmeier (a10023) LOFV.setType(TypePlaceholder.fresh());*/
/*auskommentiert von Andreas Stadelmeier (a10023) Ass.setType(TypePlaceholder.fresh());*/
@ -2561,7 +2561,7 @@ case 228:
rec = new Receiver(INSTVA);
}
else if (((UsedId)yyVals[-2+yyTop]).get_Name().size() == 2) {
LocalOrFieldVar LOFV = new LocalOrFieldVar(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength());
LocalOrFieldVarOrClassname LOFV = new LocalOrFieldVarOrClassname(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength());
((UsedId)yyVals[-2+yyTop]).removeLast();
LOFV.set_UsedId(((UsedId)yyVals[-2+yyTop]));
/*auskommentiert von Andreas Stadelmeier (a10023) LOFV.setType(TypePlaceholder.fresh());*/
@ -2593,7 +2593,7 @@ case 229:
rec = new Receiver(INSTVA);
}
else if (((UsedId)yyVals[-3+yyTop]).get_Name().size() == 2) {
LocalOrFieldVar LOFV = new LocalOrFieldVar(((UsedId)yyVals[-3+yyTop]).getOffset(),((UsedId)yyVals[-3+yyTop]).getVariableLength());
LocalOrFieldVarOrClassname LOFV = new LocalOrFieldVarOrClassname(((UsedId)yyVals[-3+yyTop]).getOffset(),((UsedId)yyVals[-3+yyTop]).getVariableLength());
((UsedId)yyVals[-3+yyTop]).removeLast();
LOFV.set_UsedId(((UsedId)yyVals[-3+yyTop]));
/*auskommentiert von Andreas Stadelmeier (a10023) LOFV.setType(TypePlaceholder.fresh());*/
@ -2744,7 +2744,7 @@ case 242:
yyVal = INSTVA;
}
else {
LocalOrFieldVar Postincexpr = new LocalOrFieldVar(((UsedId)yyVals[0+yyTop]).getOffset(),((UsedId)yyVals[0+yyTop]).getVariableLength());
LocalOrFieldVarOrClassname Postincexpr = new LocalOrFieldVarOrClassname(((UsedId)yyVals[0+yyTop]).getOffset(),((UsedId)yyVals[0+yyTop]).getVariableLength());
Postincexpr.set_UsedId(((UsedId)yyVals[0+yyTop]));
/*auskommentiert von Andreas Stadelmeier (a10023) Postincexpr.setType(TypePlaceholder.fresh());*/
yyVal=Postincexpr;

View File

@ -16,7 +16,7 @@ import de.dhbwstuttgart.syntaxtree.statement.Assign;
import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.statement.ExprStmt;
import de.dhbwstuttgart.syntaxtree.statement.InstVar;
import de.dhbwstuttgart.syntaxtree.statement.LocalOrFieldVar;
import de.dhbwstuttgart.syntaxtree.statement.LocalOrFieldVarOrClassname;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;

View File

@ -93,7 +93,7 @@ public class InstVar extends Expr
{
super(offset,variableLength);
Iterator namen = ui.get_Name().iterator();
LocalOrFieldVar innerLOFV = new LocalOrFieldVar((String)namen.next(),getOffset());
LocalOrFieldVarOrClassname innerLOFV = new LocalOrFieldVarOrClassname((String)namen.next(),getOffset());
//innerLOFV.setType(TypePlaceholder.fresh(this));
InstVar INSTVA = new InstVar(innerLOFV, (String)namen.next(),offset);
//INSTVA.setType(TypePlaceholder.fresh(this));
@ -166,25 +166,16 @@ public class InstVar extends Expr
* <br/>Author: Martin Pl�micke
* @return
*/
// ino.end
// ino.method.toString.25441.definition
public String toString()
// ino.end
// ino.method.toString.25441.body
{
String superType = "";
if(super.type != null)superType += super.type.toString();
return superType + " " + usedid.toString();
}
// ino.end
// ino.method.wandleRefTypeAttributes2GenericAttributes.25444.definition
public void wandleRefTypeAttributes2GenericAttributes(Menge<Type> paralist, Menge<GenericTypeVar> genericMethodParameters)
// ino.end
// ino.method.wandleRefTypeAttributes2GenericAttributes.25444.body
{
}
// ino.end
@Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {

View File

@ -30,6 +30,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
@ -39,7 +40,7 @@ import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
// ino.class.LocalOrFieldVar.25503.declaration
public class LocalOrFieldVar extends Expr
public class LocalOrFieldVarOrClassname extends Expr
// ino.end
// ino.class.LocalOrFieldVar.25503.body
{
@ -48,9 +49,10 @@ public class LocalOrFieldVar extends Expr
protected static Logger parserlog = Logger.getLogger("parser");
// ino.end
private boolean isFieldAccess = false;
private boolean isClassAccess = false;
// ino.method.LocalOrFieldVar.25510.definition
public LocalOrFieldVar(int offset, int variableLength)
public LocalOrFieldVarOrClassname(int offset, int variableLength)
// ino.end
// ino.method.LocalOrFieldVar.25510.body
{
@ -59,7 +61,7 @@ public class LocalOrFieldVar extends Expr
// ino.end
// ino.method.LocalOrFieldVar.25513.definition
public LocalOrFieldVar(String n, int offset)
public LocalOrFieldVarOrClassname(String n, int offset)
// ino.end
// ino.method.LocalOrFieldVar.25513.body
{
@ -121,14 +123,23 @@ public class LocalOrFieldVar extends Expr
ConstraintsSet ret = new ConstraintsSet();
//gibt es eine Assumption ¼r den die LocalOrFieldVar-Variablen, dann folgendes ausführen:
Type thisTypeAssumption = assumptions.getVarType(this.get_Name(), this.getParentClass());
if(thisTypeAssumption == null)throw new TypeinferenceException("Eine Variable "+this.get_Name()+" ist in den Assumptions nicht vorhanden",this);
Type thisType = thisTypeAssumption.checkTYPE(assumptions, this);
this.setType(thisType);
//ret.add(new Constraint(thisTypeAssumption, this.getTypeVariable()));
//Rausfinden, ob es Feld oder Locale Variable ist:
for(FieldAssumption fAss : assumptions.getFieldVars(this.get_Name())){
if(this.getParentClass().equals(fAss.getParentClass()))this.isFieldAccess = true;
};
if(thisTypeAssumption == null){//Es ist keine Variable oder Feld
//Testen ob es ein Klassenname ist:
ClassAssumption cAss = assumptions.getClass(this.get_Name());
if(cAss == null)throw new TypeinferenceException("Weder eine Variable noch eine Klasse "+this.get_Name()+" ist in den Assumptions nicht vorhanden",this);
thisTypeAssumption = cAss.getAssumedClass().getType();
this.set_Type(thisTypeAssumption);
this.isClassAccess = true;
}else{
Type thisType = thisTypeAssumption.checkTYPE(assumptions, this);
this.setType(thisType);
//ret.add(new Constraint(thisTypeAssumption, this.getTypeVariable()));
//Rausfinden, ob es Feld oder Locale Variable ist:
for(FieldAssumption fAss : assumptions.getFieldVars(this.get_Name())){
if(this.getParentClass().equals(fAss.getParentClass()))this.isFieldAccess = true;
};
}
return ret;
}

View File

@ -111,6 +111,8 @@ public class Receiver
throw new TypeinferenceException("Typ des Receivers nicht eindeutig",this.get_Expr());
}
ClassAssumption receiverClassAssumption = typeAssumptions.getClassAssumptionFor((RefType)receiverType);
if(receiverClassAssumption == null)
throw new TypeinferenceException("Die Klasse für den Typ "+receiverType+" ist nicht in den Assumptions vorhanden", receiverType);
de.dhbwstuttgart.syntaxtree.Class receiverCl = receiverClassAssumption.getAssumedClass();
return receiverCl;
}

View File

@ -170,8 +170,8 @@ public class TypeAssumptions {
}
}
//Wird keine Assumption gefunden, muss ein Fehler vorliegen:
throw new TypeinferenceException("Eine Variable "+variableName+" ist in den Assumptions nicht vorhanden", inScope);
//return null;
//throw new TypeinferenceException("Eine Variable "+variableName+" ist in den Assumptions nicht vorhanden", inScope);
return null;
}
/**
@ -409,11 +409,15 @@ public class TypeAssumptions {
}
public ClassAssumption getClassAssumptionFor(RefType t){
return this.getClass(t.get_Name());
}
public ClassAssumption getClass(String withName){
for(ClassAssumption cA : this.getClassAssumptions()){
RefType classType = cA.getAssumedClass().getType();
if(classType.get_Name().equals(t.get_Name()))return cA;
if(classType.getName().equals(withName))return cA;
}
throw new TypeinferenceException("Die Klasse für den Typ "+t+" ist nicht in den Assumptions vorhanden", t);
return null;
}
public Type checkType(RefType type, SyntaxTreeNode parent) {