Problem mit der Umwandlung von generischen Variablen zu TPH behoben (noch nicht vollständig)

This commit is contained in:
JanUlrich 2014-09-18 16:26:02 +02:00
parent 7abb1f8ad6
commit d636d29ab5
16 changed files with 141 additions and 73 deletions

View File

@ -85,7 +85,7 @@ class EvalVisitor extends Java8BaseVisitor<SyntaxTreeNode> {
@Override @Override
public GenericTypeVar visitTypeParameter(TypeParameterContext ctx) { public GenericTypeVar visitTypeParameter(TypeParameterContext ctx) {
GenericTypeVar ret = new GenericTypeVar(name, parent, offset); GenericTypeVar ret = null;//new GenericTypeVar(name, parent, offset);
return ret; return ret;
} }

View File

@ -15,11 +15,15 @@ import org.apache.log4j.Logger;
import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.Interface; import de.dhbwstuttgart.syntaxtree.Interface;
import de.dhbwstuttgart.syntaxtree.misc.UsedId; import de.dhbwstuttgart.syntaxtree.misc.UsedId;
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
// ino.class.AClassOrInterface.21186.description type=javadoc // ino.class.AClassOrInterface.21186.description type=javadoc
/** /**
@ -37,8 +41,8 @@ public interface AClassOrInterface
{ {
public JavaClassName getName(); public JavaClassName getName();
public Vector<Interface> getSuperInterfaces(); public Vector<Type> getSuperInterfaces();
public void setSuperInterfaces(Vector<Interface> vector); public void setSuperInterfaces(Vector<Type> vector);
/* /*
// ino.attribute.inferencelog.21189.decldescription type=javadoc // ino.attribute.inferencelog.21189.decldescription type=javadoc

View File

@ -7,6 +7,8 @@ import java.util.Vector;
import de.dhbwstuttgart.syntaxtree.Interface; import de.dhbwstuttgart.syntaxtree.Interface;
import de.dhbwstuttgart.syntaxtree.misc.UsedId; import de.dhbwstuttgart.syntaxtree.misc.UsedId;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
// ino.class.InterfaceList.24383.description type=javadoc // ino.class.InterfaceList.24383.description type=javadoc
/** /**
@ -36,13 +38,13 @@ public class InterfaceList
// ino.end // ino.end
// ino.method.getVector.24392.definition // ino.method.getVector.24392.definition
public Vector<Interface> getVector() public Vector<Type> getTypeVector()
// ino.end // ino.end
// ino.method.getVector.24392.body // ino.method.getVector.24392.body
{ {
Vector<Interface> ret = new Vector<>(); Vector<Type> ret = new Vector<>();
for(UsedId name : superif){ for(UsedId name : superif){
ret.add(new Interface(name.get_Name_1Element(), name.getOffset())); ret.add(new Interface(name.get_Name_1Element(), name.getOffset()).getType());
} }
return ret; return ret;
} }

View File

@ -281,8 +281,8 @@ public Vector<Pair> testPair = new Vector<Pair>();
//t "fielddeclarator : variabledeclarator '=' expression", //t "fielddeclarator : variabledeclarator '=' expression",
//t "fielddeclarator : variabledeclarator", //t "fielddeclarator : variabledeclarator",
//t "genericdeclarationlist : '<' boundedMethodParameters '>'", //t "genericdeclarationlist : '<' boundedMethodParameters '>'",
//t "fielddeclaration : fielddeclarator ';'",
//t "fielddeclaration : type fielddeclarator ';'", //t "fielddeclaration : type fielddeclarator ';'",
//t "fielddeclaration : fielddeclarator ';'",
//t "fielddeclaration : genericdeclarationlist type fielddeclarator ';'", //t "fielddeclaration : genericdeclarationlist type fielddeclarator ';'",
//t "fielddeclaration : variabledeclarators ';'", //t "fielddeclaration : variabledeclarators ';'",
//t "fielddeclaration : type variabledeclarators ';'", //t "fielddeclaration : type variabledeclarators ';'",
@ -833,7 +833,7 @@ case 20:
/* Vector<UsedId> SuperInterfaces, */ /* Vector<UsedId> SuperInterfaces, */
/* Vector<Type> Parameterliste*/ /* Vector<Type> Parameterliste*/
yyVal = new Class(((ClassAndParameter)yyVals[-1+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, null, null, ((ClassAndParameter)yyVals[-1+yyTop]).getParaVector(), ((Token)yyVals[-2+yyTop]).getOffset()); yyVal = new Class(((ClassAndParameter)yyVals[-1+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes, null, ((ClassAndParameter)yyVals[-1+yyTop]).getParaVector(), ((Token)yyVals[-2+yyTop]).getOffset());
this.initContainedTypes(); this.initContainedTypes();
this.initUsedIdsToCheck(); this.initUsedIdsToCheck();
} }
@ -841,7 +841,7 @@ case 20:
case 21: case 21:
// line 376 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" // line 376 "./../src/de/dhbwstuttgart/parser/JavaParser.jay"
{ {
yyVal = new Class(((ClassAndParameter)yyVals[-1+yyTop]).getName(), ((Modifiers)yyVals[-3+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes,usedIdsToCheck, null, null, ((ClassAndParameter)yyVals[-1+yyTop]).getParaVector(), ((Token)yyVals[-2+yyTop]).getOffset()); yyVal = new Class(((ClassAndParameter)yyVals[-1+yyTop]).getName(), ((Modifiers)yyVals[-3+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, null, ((ClassAndParameter)yyVals[-1+yyTop]).getParaVector(), ((Token)yyVals[-2+yyTop]).getOffset());
this.initContainedTypes(); this.initContainedTypes();
this.initUsedIdsToCheck(); this.initUsedIdsToCheck();
} }
@ -849,7 +849,7 @@ case 21:
case 22: case 22:
// line 382 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" // line 382 "./../src/de/dhbwstuttgart/parser/JavaParser.jay"
{ {
yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes,usedIdsToCheck, ((UsedId)yyVals[-1+yyTop]), null, ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector(), ((Token)yyVals[-3+yyTop]).getOffset()); yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes, ((UsedId)yyVals[-1+yyTop]), null, ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector(), ((Token)yyVals[-3+yyTop]).getOffset());
this.initContainedTypes(); this.initContainedTypes();
this.initUsedIdsToCheck(); this.initUsedIdsToCheck();
} }
@ -857,7 +857,7 @@ case 22:
case 23: case 23:
// line 388 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" // line 388 "./../src/de/dhbwstuttgart/parser/JavaParser.jay"
{ {
yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), ((Modifiers)yyVals[-4+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, ((UsedId)yyVals[-1+yyTop]), null, ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector(), ((Token)yyVals[-3+yyTop]).getOffset()); yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), ((Modifiers)yyVals[-4+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, ((UsedId)yyVals[-1+yyTop]), null, ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector(), ((Token)yyVals[-3+yyTop]).getOffset());
this.initContainedTypes(); this.initContainedTypes();
this.initUsedIdsToCheck(); this.initUsedIdsToCheck();
} }
@ -865,7 +865,7 @@ case 23:
case 24: case 24:
// line 395 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" // line 395 "./../src/de/dhbwstuttgart/parser/JavaParser.jay"
{ {
yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, null, ((InterfaceList)yyVals[-1+yyTop]).getVector(), ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector(), ((Token)yyVals[-3+yyTop]).getOffset()); yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes, ((InterfaceList)yyVals[-1+yyTop]).getTypeVector(), ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector(), ((Token)yyVals[-3+yyTop]).getOffset());
this.initContainedTypes(); this.initContainedTypes();
this.initUsedIdsToCheck(); this.initUsedIdsToCheck();
} }
@ -873,7 +873,7 @@ case 24:
case 25: case 25:
// line 401 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" // line 401 "./../src/de/dhbwstuttgart/parser/JavaParser.jay"
{ {
yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), ((Modifiers)yyVals[-4+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, null, ((InterfaceList)yyVals[-1+yyTop]).getVector(), ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector(), ((Token)yyVals[-3+yyTop]).getOffset()); yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), ((Modifiers)yyVals[-4+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, ((InterfaceList)yyVals[-1+yyTop]).getTypeVector(), ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector(), ((Token)yyVals[-3+yyTop]).getOffset());
this.initContainedTypes(); this.initContainedTypes();
this.initUsedIdsToCheck(); this.initUsedIdsToCheck();
} }
@ -881,7 +881,7 @@ case 25:
case 26: case 26:
// line 407 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" // line 407 "./../src/de/dhbwstuttgart/parser/JavaParser.jay"
{ {
yyVal = new Class(((ClassAndParameter)yyVals[-3+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes,usedIdsToCheck, ((UsedId)yyVals[-2+yyTop]), ((InterfaceList)yyVals[-1+yyTop]).getVector(), ((ClassAndParameter)yyVals[-3+yyTop]).getParaVector(), ((Token)yyVals[-4+yyTop]).getOffset()); yyVal = new Class(((ClassAndParameter)yyVals[-3+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes, ((UsedId)yyVals[-2+yyTop]), ((InterfaceList)yyVals[-1+yyTop]).getTypeVector(), ((ClassAndParameter)yyVals[-3+yyTop]).getParaVector(), ((Token)yyVals[-4+yyTop]).getOffset());
this.initContainedTypes(); this.initContainedTypes();
this.initUsedIdsToCheck(); this.initUsedIdsToCheck();
} }
@ -889,7 +889,7 @@ case 26:
case 27: case 27:
// line 413 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" // line 413 "./../src/de/dhbwstuttgart/parser/JavaParser.jay"
{ {
yyVal = new Class(((ClassAndParameter)yyVals[-3+yyTop]).getName(), ((Modifiers)yyVals[-5+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, ((UsedId)yyVals[-2+yyTop]), ((InterfaceList)yyVals[-1+yyTop]).getVector(), ((ClassAndParameter)yyVals[-3+yyTop]).getParaVector(), ((Token)yyVals[-4+yyTop]).getOffset()); yyVal = new Class(((ClassAndParameter)yyVals[-3+yyTop]).getName(), ((Modifiers)yyVals[-5+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, ((UsedId)yyVals[-2+yyTop]), ((InterfaceList)yyVals[-1+yyTop]).getTypeVector(), ((ClassAndParameter)yyVals[-3+yyTop]).getParaVector(), ((Token)yyVals[-4+yyTop]).getOffset());
this.initContainedTypes(); this.initContainedTypes();
this.initUsedIdsToCheck(); this.initUsedIdsToCheck();
} }
@ -1396,13 +1396,13 @@ case 89:
case 90: case 90:
// line 854 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" // line 854 "./../src/de/dhbwstuttgart/parser/JavaParser.jay"
{ {
((FieldDeclaration)yyVals[-1+yyTop]).setType(((Type)yyVals[-2+yyTop]));
yyVal=((FieldDeclaration)yyVals[-1+yyTop]); yyVal=((FieldDeclaration)yyVals[-1+yyTop]);
} }
break; break;
case 91: case 91:
// line 858 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" // line 859 "./../src/de/dhbwstuttgart/parser/JavaParser.jay"
{ {
((FieldDeclaration)yyVals[-1+yyTop]).setType(((Type)yyVals[-2+yyTop]));
yyVal=((FieldDeclaration)yyVals[-1+yyTop]); yyVal=((FieldDeclaration)yyVals[-1+yyTop]);
} }
break; break;
@ -3209,8 +3209,8 @@ case 289:
3, 2, 3, 2, 3, 1, 2, 1, 1, 1, 3, 2, 3, 2, 3, 1, 2, 1, 1, 1,
1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1,
2, 1, 3, 3, 1, 0, 3, 1, 1, 1, 2, 1, 3, 3, 1, 0, 3, 1, 1, 1,
1, 2, 2, 3, 6, 2, 3, 1, 3, 2, 1, 2, 2, 3, 6, 2, 3, 1, 3, 3,
3, 4, 2, 3, 4, 2, 2, 3, 3, 4, 2, 4, 2, 3, 4, 2, 2, 3, 3, 4,
2, 3, 3, 4, 2, 1, 1, 3, 1, 3, 2, 3, 3, 4, 2, 1, 1, 3, 1, 3,
1, 3, 1, 3, 3, 2, 3, 4, 3, 4, 1, 3, 1, 3, 3, 2, 3, 4, 3, 4,
4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5,
@ -3248,7 +3248,7 @@ case 289:
34, 0, 0, 0, 77, 21, 0, 0, 33, 0, 34, 0, 0, 0, 77, 21, 0, 0, 33, 0,
0, 0, 31, 0, 82, 0, 0, 0, 113, 0, 0, 0, 31, 0, 82, 0, 0, 0, 113, 0,
0, 132, 0, 142, 96, 0, 134, 46, 57, 0, 0, 132, 0, 142, 96, 0, 134, 46, 57, 0,
93, 90, 0, 0, 0, 0, 0, 0, 0, 0, 93, 91, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 83, 26, 51, 29, 53, 66, 0, 0, 0, 0, 83, 26, 51, 29, 53, 66,
0, 86, 0, 55, 43, 44, 73, 74, 23, 0, 0, 86, 0, 55, 43, 44, 73, 74, 23, 0,
25, 35, 111, 0, 108, 0, 0, 0, 254, 0, 25, 35, 111, 0, 108, 0, 0, 0, 254, 0,
@ -3261,7 +3261,7 @@ case 289:
165, 141, 0, 0, 0, 0, 0, 0, 0, 245, 165, 141, 0, 0, 0, 0, 0, 0, 0, 245,
286, 0, 0, 276, 0, 0, 0, 0, 0, 0, 286, 0, 0, 276, 0, 0, 0, 0, 0, 0,
0, 194, 173, 87, 241, 242, 248, 249, 174, 195, 0, 194, 173, 87, 241, 242, 248, 249, 174, 195,
255, 259, 99, 0, 119, 94, 91, 0, 0, 0, 255, 259, 99, 0, 119, 94, 90, 0, 0, 0,
135, 0, 0, 84, 0, 101, 0, 0, 0, 27, 135, 0, 0, 84, 0, 101, 0, 0, 0, 27,
0, 0, 0, 198, 0, 0, 0, 229, 230, 219, 0, 0, 0, 198, 0, 0, 0, 229, 230, 219,
0, 0, 0, 98, 144, 167, 216, 0, 0, 231, 0, 0, 0, 98, 144, 167, 216, 0, 0, 231,

View File

@ -368,50 +368,50 @@ classdeclaration : CLASS classidentifier classbody
// Vector<UsedId> SuperInterfaces, // Vector<UsedId> SuperInterfaces,
// Vector<Type> Parameterliste // Vector<Type> Parameterliste
$$ = new Class($2.getName(), null, $3, containedTypes, usedIdsToCheck, null, null, $2.getParaVector(), $1.getOffset()); $$ = new Class($2.getName(), null, $3, containedTypes, null, $2.getParaVector(), $1.getOffset());
this.initContainedTypes(); this.initContainedTypes();
this.initUsedIdsToCheck(); this.initUsedIdsToCheck();
} }
| modifiers CLASS classidentifier classbody | modifiers CLASS classidentifier classbody
{ {
$$ = new Class($3.getName(), $1, $4, containedTypes,usedIdsToCheck, null, null, $3.getParaVector(), $2.getOffset()); $$ = new Class($3.getName(), $1, $4, containedTypes, null, $3.getParaVector(), $2.getOffset());
this.initContainedTypes(); this.initContainedTypes();
this.initUsedIdsToCheck(); this.initUsedIdsToCheck();
} }
| CLASS classidentifier super classbody | CLASS classidentifier super classbody
{ {
$$ = new Class($2.getName(), null, $4, containedTypes,usedIdsToCheck, $3, null, $2.getParaVector(), $1.getOffset()); $$ = new Class($2.getName(), null, $4, containedTypes, $3, null, $2.getParaVector(), $1.getOffset());
this.initContainedTypes(); this.initContainedTypes();
this.initUsedIdsToCheck(); this.initUsedIdsToCheck();
} }
| modifiers CLASS classidentifier super classbody | modifiers CLASS classidentifier super classbody
{ {
$$ = new Class($3.getName(), $1, $5, containedTypes, usedIdsToCheck, $4, null, $3.getParaVector(), $2.getOffset()); $$ = new Class($3.getName(), $1, $5, containedTypes, $4, null, $3.getParaVector(), $2.getOffset());
this.initContainedTypes(); this.initContainedTypes();
this.initUsedIdsToCheck(); this.initUsedIdsToCheck();
} }
///* auskommentiert von Andreas Stadelmeier A10023 ///* auskommentiert von Andreas Stadelmeier A10023
| CLASS classidentifier interfaces classbody | CLASS classidentifier interfaces classbody
{ {
$$ = new Class($2.getName(), null, $4, containedTypes, usedIdsToCheck, null, $3.getVector(), $2.getParaVector(), $1.getOffset()); $$ = new Class($2.getName(), null, $4, containedTypes, $3.getTypeVector(), $2.getParaVector(), $1.getOffset());
this.initContainedTypes(); this.initContainedTypes();
this.initUsedIdsToCheck(); this.initUsedIdsToCheck();
} }
| modifiers CLASS classidentifier interfaces classbody | modifiers CLASS classidentifier interfaces classbody
{ {
$$ = new Class($3.getName(), $1, $5, containedTypes, usedIdsToCheck, null, $4.getVector(), $3.getParaVector(), $2.getOffset()); $$ = new Class($3.getName(), $1, $5, containedTypes, $4.getTypeVector(), $3.getParaVector(), $2.getOffset());
this.initContainedTypes(); this.initContainedTypes();
this.initUsedIdsToCheck(); this.initUsedIdsToCheck();
} }
| CLASS classidentifier super interfaces classbody | CLASS classidentifier super interfaces classbody
{ {
$$ = new Class($2.getName(), null, $5, containedTypes,usedIdsToCheck, $3, $4.getVector(), $2.getParaVector(), $1.getOffset()); $$ = new Class($2.getName(), null, $5, containedTypes, $3, $4.getTypeVector(), $2.getParaVector(), $1.getOffset());
this.initContainedTypes(); this.initContainedTypes();
this.initUsedIdsToCheck(); this.initUsedIdsToCheck();
} }
| modifiers CLASS classidentifier super interfaces classbody | modifiers CLASS classidentifier super interfaces classbody
{ {
$$ = new Class($3.getName(), $1, $6, containedTypes, usedIdsToCheck, $4, $5.getVector(), $3.getParaVector(), $2.getOffset()); $$ = new Class($3.getName(), $1, $6, containedTypes, $4, $5.getTypeVector(), $3.getParaVector(), $2.getOffset());
this.initContainedTypes(); this.initContainedTypes();
this.initUsedIdsToCheck(); this.initUsedIdsToCheck();
} }
@ -850,15 +850,15 @@ genericdeclarationlist : '<' boundedMethodParameters '>'
} }
fielddeclaration : fielddeclarator ';' fielddeclaration : type fielddeclarator ';'
{
$$=$1;
}
| type fielddeclarator ';'
{ {
$2.setType($1); $2.setType($1);
$$=$2; $$=$2;
} }
| fielddeclarator ';'
{
$$=$1;
}
| genericdeclarationlist type fielddeclarator ';' | genericdeclarationlist type fielddeclarator ';'
{//angefügt von Andreas Stadelmeier {//angefügt von Andreas Stadelmeier
$3.setType($2); $3.setType($2);

View File

@ -51,7 +51,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
protected Modifiers modifiers; protected Modifiers modifiers;
protected String name; protected String name;
private Vector<Interface> superif = new Vector<Interface>(); private Vector<Type> superif = new Vector<Type>();
public UsedId getPackageName() public UsedId getPackageName()
{ {
@ -89,12 +89,13 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
return ret; return ret;
} }
public Vector<Interface> getSuperInterfaces() public Vector<Type> getSuperInterfaces()
{ {
return superif; return superif;
} }
public void setSuperInterfaces(Vector<Interface> superif) @Override
public void setSuperInterfaces(Vector<Type> superif)
{ {
this.superif = superif; this.superif = superif;
} }
@ -144,7 +145,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
private Vector<Field> fielddecl = new Vector<Field>(); private Vector<Field> fielddecl = new Vector<Field>();
private GenericDeclarationList genericClassParameters; private GenericDeclarationList genericClassParameters;
private int offset; private int offset;
private Class superClass; private Type superClass;
// ino.method.Class.23041.definition // ino.method.Class.23041.definition
@ -158,11 +159,11 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
} }
this.offset = offset; this.offset = offset;
if(!name.equals("Object"))//Alle Klassen außer Object erben von Object: if(!name.equals("Object"))//Alle Klassen außer Object erben von Object:
this.superClass = new Class("Object", -1); this.superClass = new Class("Object", -1).getType();
} }
// ino.end // ino.end
public Class(String name, Class superClass, int offset){ public Class(String name, RefType superClass, int offset){
this(name,offset); this(name,offset);
this.superClass = superClass; this.superClass = superClass;
} }
@ -177,15 +178,44 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
} }
// ino.end // ino.end
// ino.method.Class.23047.defdescription type=javadoc public Class(String name, Modifiers mod, ClassBody cb, Vector<Type> ct, Vector<UsedId> usedIdsToCheck,
UsedId superclass, Vector<UsedId> superif, Vector<Type> paralist, int offset){
this(name, mod, cb, ct, usedIdToRefType(superclass),usedIdToRefType(superif),paralist,offset);
}
public Class(String name, ClassBody cb, Vector<Type> ct,
UsedId superclass, Vector<Type> superif, Vector<Type> paralist, int offset) {
this(name,null,cb,ct,usedIdToRefType(superclass),superif,paralist,offset);
}
public Class(String name2, Modifiers modifiers2, ClassBody classBody,
Vector<Type> containedTypes2, UsedId usedId,
Vector<Type> typeVector, Vector<Type> paraVector, int offset2) {
this(name2, modifiers2, classBody, containedTypes2, usedIdToRefType(usedId),typeVector, paraVector, offset2);
}
public Class(String name2, Modifiers object, ClassBody classBody,
Vector<Type> containedTypes2, Vector<Type> typeVector,
Vector<Type> paraVector, int offset2) {
this(name2, object, classBody, containedTypes2,(Type)null, typeVector, paraVector, offset2);
}
private static Vector<Type> usedIdToRefType(Vector<UsedId> superif2) {
Vector<Type> ret = new Vector<>();
for(UsedId id : superif2)ret.add(usedIdToRefType(id));
return ret;
}
private static Type usedIdToRefType(UsedId superclass2) {
RefType ret = new RefType(superclass2.getSimpleName(), null, superclass2.getOffset());
ret.set_ParaList(superclass2.get_ParaList());
return ret;
}
// ino.method.Class.23047.defdescription type=javadoc
/** /**
* Konstruktor, der die Angabe aller Parameter ermoeglicht. * Konstruktor, der die Angabe aller Parameter ermoeglicht.
* Zur Uebersichtlichkeit in der Grammatik. * Zur Uebersichtlichkeit in der Grammatik.
*/ */
// ino.end // ino.end
// ino.method.Class.23047.definition // ino.method.Class.23047.definition
public Class(String name, Modifiers mod, ClassBody cb, Vector<Type> ct, Vector<UsedId> usedIdsToCheck, public Class(String name, Modifiers mod, ClassBody cb, Vector<Type> ct,
UsedId superclass, Vector<Interface> superif, Vector<Type> paralist, int offset) Type superclass, Vector<Type> vector, Vector<Type> paralist, int offset)
// ino.end // ino.end
// ino.method.Class.23047.body // ino.method.Class.23047.body
{ {
@ -194,9 +224,9 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
if (cb != null) set_ClassBody(cb); if (cb != null) set_ClassBody(cb);
if (ct != null) setContainedTypes(ct); if (ct != null) setContainedTypes(ct);
if (superclass != null){ if (superclass != null){
this.superClass = new Class(superClass.getName().toString(),-1); this.superClass = superclass;
} }
if (superif != null) setSuperInterfaces(superif); if (vector != null) setSuperInterfaces(vector);
if (paralist != null){ if (paralist != null){
this.set_ParaList(paralist); this.set_ParaList(paralist);
} }
@ -214,7 +244,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
} }
// ino.end // ino.end
public Vector<Field> getFields() public Vector<Field> getFields()
{ {
return fielddecl; return fielddecl;
@ -1097,6 +1127,9 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
for(Field f : this.getFields()){ for(Field f : this.getFields()){
if(f.isPublic())ret.add(f.createTypeAssumptions(this)); if(f.isPublic())ret.add(f.createTypeAssumptions(this));
} }
for(GenericTypeVar gtv : this.getGenericParameter()){
ret.add(gtv.createAssumptions());
}
return ret; return ret;
} }
@ -1225,7 +1258,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
* Die Super Klasse dieser Klasse. * Die Super Klasse dieser Klasse.
* @return null für Klasse Object * @return null für Klasse Object
*/ */
public Class getSuperClass(){ public Type getSuperClass(){
return this.superClass; return this.superClass;
} }
} }

View File

@ -252,7 +252,7 @@ public class SourceFile
*/ */
// ino.end // ino.end
// ino.method.createPairFromClassAndSuperclass.21400.definition // ino.method.createPairFromClassAndSuperclass.21400.definition
private Pair createPairFromClassAndSuperclass(Class baseClass, Class superclass, Vector classParaOrg, Vector superclassParaOrg) private Pair createPairFromClassAndSuperclass(Class baseClass, Type superclass, Vector classParaOrg, Vector superclassParaOrg, TypeAssumptions ass)
// ino.end // ino.end
// ino.method.createPairFromClassAndSuperclass.21400.body // ino.method.createPairFromClassAndSuperclass.21400.body
{ {
@ -269,10 +269,12 @@ public class SourceFile
new RefType( superclassName.toString(), superclassParaOrg,-1) new RefType( superclassName.toString(), superclassParaOrg,-1)
); );
*/ */
Pair P = new Pair(baseClass.getType(), superclass.getType()); Pair P = new Pair(baseClass.getType().TYPE(ass, baseClass).getType(), superclass.TYPE(ass, baseClass).getType());
//PL 04-12-29 freshe Variablen ANFANG //PL 04-12-29 freshe Variablen ANFANG
RefType r1 = (RefType)P.getTA1Copy(); RefType r1 = (RefType)P.getTA1Copy();
RefType r2 = (RefType)P.getTA2Copy(); RefType r2 = (RefType)P.getTA2Copy();
r1 = (RefType) r1.TYPE(ass, baseClass).getType();
r2 = (RefType) r2.TYPE(ass, baseClass).getType();
// #JB# 05.04.2005 // #JB# 05.04.2005
// ########################################################### // ###########################################################
Hashtable<JavaClassName,Type> substHash = new Hashtable<JavaClassName,Type>(); //fuer jedes Paar komplett neue Variablen Hashtable<JavaClassName,Type> substHash = new Hashtable<JavaClassName,Type>(); //fuer jedes Paar komplett neue Variablen
@ -305,7 +307,8 @@ public class SourceFile
// Menge FC bilden // Menge FC bilden
Vector<Pair> vFC = new Vector<Pair>(); // Menge FC Vector<Pair> vFC = new Vector<Pair>(); // Menge FC
TypeAssumptions globalAssumptions = this.makeBasicAssumptionsFromJRE(imports);
globalAssumptions.add(this.getPublicFieldAssumptions());
// 1. Menge <= in FC aufnehmen --> Iteration ueber alle Klassen // 1. Menge <= in FC aufnehmen --> Iteration ueber alle Klassen
for( int i = 0; i < KlassenVektor.size(); i++ ) for( int i = 0; i < KlassenVektor.size(); i++ )
@ -314,14 +317,14 @@ public class SourceFile
inferencelog.debug("Verarbeite "+tempKlasse.getName()); inferencelog.debug("Verarbeite "+tempKlasse.getName());
//TODO: SuperKlasse erstellen, dies sollte am besten beim Konstruktoraufruf von Class geschehen. Diese kann dann mit getSuperClass abgefragt werden. //TODO: SuperKlasse erstellen, dies sollte am besten beim Konstruktoraufruf von Class geschehen. Diese kann dann mit getSuperClass abgefragt werden.
if( tempKlasse.superclassid != null ) { // Klasse hat Superklasse if( tempKlasse.superclassid != null ) { // Klasse hat Superklasse
Pair P=createPairFromClassAndSuperclass(tempKlasse,tempKlasse.getSuperClass(),tempKlasse.get_ParaList(),tempKlasse.superclassid.get_ParaList()); Pair P=createPairFromClassAndSuperclass(tempKlasse,tempKlasse.getSuperClass(),tempKlasse.get_ParaList(),tempKlasse.superclassid.get_ParaList(), globalAssumptions);
vFC.add( P ); vFC.add( P );
} }
if(tempKlasse.getSuperInterfaces()!=null){ if(tempKlasse.getSuperInterfaces()!=null){
Iterator<Interface> interfaceIterator=tempKlasse.getSuperInterfaces().iterator(); Iterator<Type> interfaceIterator=tempKlasse.getSuperInterfaces().iterator();
while(interfaceIterator.hasNext()){ while(interfaceIterator.hasNext()){
Interface intf=interfaceIterator.next(); RefType intf=(RefType) interfaceIterator.next();
Pair P=createPairFromClassAndSuperclass(tempKlasse,intf,tempKlasse.get_ParaList(),intf.get_ParaList()); Pair P=createPairFromClassAndSuperclass(tempKlasse,intf,tempKlasse.get_ParaList(),intf.get_ParaList(),globalAssumptions);
vFC.add( P ); vFC.add( P );
} }
@ -330,10 +333,10 @@ public class SourceFile
for(int i=0; i<InterfaceVektor.size();i++){ for(int i=0; i<InterfaceVektor.size();i++){
Interface intf= InterfaceVektor.get(i); Interface intf= InterfaceVektor.get(i);
if(intf.getSuperInterfaces()!=null){ if(intf.getSuperInterfaces()!=null){
Iterator<Interface> interfaceIterator=intf.getSuperInterfaces().iterator(); Iterator<Type> interfaceIterator=intf.getSuperInterfaces().iterator();
while(interfaceIterator.hasNext()){ while(interfaceIterator.hasNext()){
Interface superintf=interfaceIterator.next(); RefType superintf=(RefType) interfaceIterator.next();
Pair P=createPairFromClassAndSuperclass(intf,superintf,intf.getParaList(), superintf.get_ParaList()); Pair P=createPairFromClassAndSuperclass(intf,superintf,intf.getParaList(), superintf.get_ParaList(),globalAssumptions);
vFC.add( P ); vFC.add( P );
} }

View File

@ -44,7 +44,7 @@ public class GenericTypeVar extends Type
// ino.method.GenericTypeVar.26509.defdescription type=line // ino.method.GenericTypeVar.26509.defdescription type=line
// private Hashtable<String, Vector<GenericTypeVar>> m_TypeErasureList; // private Hashtable<String, Vector<GenericTypeVar>> m_TypeErasureList;
// ino.end // ino.end
private static HashMap<GenericTypeVar,TypePlaceholder> tph = new HashMap<GenericTypeVar,TypePlaceholder>(); private static HashMap<String,TypePlaceholder> tph = new HashMap<>();
/** /**
* *
@ -170,12 +170,14 @@ public class GenericTypeVar extends Type
*/ */
return new JavaCodeResult(this.name.toString()); return new JavaCodeResult(this.name.toString());
} }
public TypePlaceholder getTypePlaceHolder() { public TypePlaceholder getTypePlaceHolder(SyntaxTreeNode environment) {
if(!GenericTypeVar.tph.containsKey(this)){ String hashValue = this.getName().toString()+environment.hashCode();
GenericTypeVar.tph.put(this, TypePlaceholder.fresh(this.getName().toString(),this)); if(!GenericTypeVar.tph.containsKey(hashValue)){
GenericTypeVar.tph.put(hashValue, TypePlaceholder.fresh(hashValue,this));
} }
return GenericTypeVar.tph.get(this); return GenericTypeVar.tph.get(hashValue);
//return TypePlaceholder.fresh(this.getParent());
//if(this.tph == null)this.tph = TypePlaceholder.fresh(); //if(this.tph == null)this.tph = TypePlaceholder.fresh();
//return this.tph; //return this.tph;
} }

View File

@ -212,12 +212,12 @@ public class RefType extends Type implements IMatchable
* Wandelt die Parameter des RefTypes in TPHs um, sofern es sich um Generische Variablen handelt. * Wandelt die Parameter des RefTypes in TPHs um, sofern es sich um Generische Variablen handelt.
* @return * @return
*/ */
public void GTV2TPH(){ public void GTV2TPH(SyntaxTreeNode environment){
Vector<Type> paralist = new Vector<Type>(); Vector<Type> paralist = new Vector<Type>();
if(this.get_ParaList()!=null)for(Type t : this.get_ParaList()){ if(this.get_ParaList()!=null)for(Type t : this.get_ParaList()){
if(t instanceof GenericTypeVar)paralist.add(((GenericTypeVar)t).getTypePlaceHolder()); if(t instanceof GenericTypeVar)paralist.add(((GenericTypeVar)t).getTypePlaceHolder(environment));
else{ else{
if(t instanceof RefType)((RefType) t).GTV2TPH(); if(t instanceof RefType)((RefType) t).GTV2TPH(environment);
paralist.add(t); paralist.add(t);
} }
} }

View File

@ -298,7 +298,7 @@ public class Type extends SyntaxTreeNode implements IItemWithOffset
*/ */
//TODO: checkType wird nicht mehr gebraucht. TYPE übernimmt dessen Aufgabe. Es muss nur sichergestellt werden, dass jeder Typ in den Constraints landet, dadurch wird für jeden Typ die Methode TYPE aufgerufen. //TODO: checkType wird nicht mehr gebraucht. TYPE übernimmt dessen Aufgabe. Es muss nur sichergestellt werden, dass jeder Typ in den Constraints landet, dadurch wird für jeden Typ die Methode TYPE aufgerufen.
public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent){ public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent){
ConstraintType t = ass.getTypeFor(this, this); ConstraintType t = ass.getTypeFor(this, parent);
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

@ -311,13 +311,28 @@ public class TypeAssumptions {
if(ass.getIdentifier().equals(t.getName())){ if(ass.getIdentifier().equals(t.getName())){
if(! ass.getAssumedType().getParentClass().getName().equals(this.thisClassName)){ if(! ass.getAssumedType().getParentClass().getName().equals(this.thisClassName)){
//Ist die Generische Variable nicht aus dieser Klasse, so muss sie zu einem TPH umgewandelt werden: //Ist die Generische Variable nicht aus dieser Klasse, so muss sie zu einem TPH umgewandelt werden:
return new ConstraintType(ass.getAssumedType().getTypePlaceHolder()); return new ConstraintType(ass.getAssumedType().getTypePlaceHolder(inNode));
} }
return new ConstraintType(ass.getAssumedType()); return new ConstraintType(ass.getAssumedType());
} }
} }
//Spezialfälle bei char, int, boolean, .... //Spezialfälle bei char, int, boolean, ....
//TODO String name = t.getName().toString();
switch(name){
case "int":
return new ConstraintType(new RefType("java.lang.Integer",t.getParent(),t.getOffset()));
case "boolean":
return new ConstraintType(new RefType("java.lang.Boolean",t.getParent(),t.getOffset()));
case "double":
return new ConstraintType(new RefType("java.lang.Double",t.getParent(),t.getOffset()));
case "float":
return new ConstraintType(new RefType("java.lang.Float",t.getParent(),t.getOffset()));
case "long":
return new ConstraintType(new RefType("java.lang.Long",t.getParent(),t.getOffset()));
case "char":
return new ConstraintType(new RefType("java.lang.Character",t.getParent(),t.getOffset()));
}
throw new TypeinferenceException("Der Typ "+t.getName()+" ist nicht korrekt",inNode); throw new TypeinferenceException("Der Typ "+t.getName()+" ist nicht korrekt",inNode);
} }

View File

@ -1 +1,6 @@
class Test{} class Test{
method(){
if(true)i++;
if(true)i--;
else i++;
}}

View File

@ -0,0 +1,3 @@
class Test<Typ>{
Typ a;
}

View File

@ -33,6 +33,7 @@ public class GeneralParserTest{
filenames.add("ImportTest.jav"); filenames.add("ImportTest.jav");
filenames.add("BoundedParameter.jav"); filenames.add("BoundedParameter.jav");
filenames.add("GenericFieldVarTest.jav"); filenames.add("GenericFieldVarTest.jav");
filenames.add("FieldVarTest.jav");
MyCompilerAPI compiler = MyCompiler.getAPI(); MyCompilerAPI compiler = MyCompiler.getAPI();
try{ try{
for(String filename : filenames) for(String filename : filenames)

View File

@ -8,4 +8,4 @@ methode(){
class GTVTest2<GTV2>{ class GTVTest2<GTV2>{
GTV2 var2; GTV2 var2;
} }

View File

@ -1,8 +1,8 @@
class GTVTest<GTV1>{ class GTVTest<GTV1>{
GTVTest2<String> var; GTVTest2<String> var;
var2;
methode(){ methode(){
var2;
return var.test(var2); return var.test(var2);
} }
} }