Modifikation am Parser. Auch Felder sind Generisc.
This commit is contained in:
parent
1005dabacb
commit
258c172f80
@ -906,6 +906,12 @@ fielddeclaration : fielddeclarator ';'
|
||||
$2.setType($1);
|
||||
$$=$2;
|
||||
}
|
||||
| '<' boundedMethodParameters '>' type fielddeclarator
|
||||
{//angefügt von Andreas Stadelmeier
|
||||
$5.setGenericParameter($2);
|
||||
$5.setType($4);
|
||||
$$=$5;
|
||||
}
|
||||
|
|
||||
variabledeclarators ';'
|
||||
{
|
||||
@ -1022,8 +1028,8 @@ boundedMethodParameter : IDENTIFIER
|
||||
}
|
||||
| IDENTIFIER EXTENDS boundedclassidentifierlist
|
||||
{
|
||||
BoundedGenericTypeVar gtv=new BoundedGenericTypeVar($1.getLexem(),$1.getOffset());
|
||||
gtv.setBounds($3);
|
||||
BoundedGenericTypeVar gtv=new BoundedGenericTypeVar($1.getLexem(),$3,$1.getOffset());
|
||||
//gtv.setBounds($3);
|
||||
$$=gtv;
|
||||
}
|
||||
// returns Vector<Type>
|
||||
|
@ -18,7 +18,7 @@ import typinferenz.Typeable;
|
||||
import typinferenz.TypeInsertable;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
|
||||
public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Typeable{
|
||||
public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Typeable, Generic{
|
||||
|
||||
protected Vector<DeclId> declid = new Vector<DeclId>(); // Vector, da 'int a, b, c, ...' auch eingeparst werden muss
|
||||
|
||||
|
@ -30,6 +30,7 @@ public class FieldDeclaration extends Field{
|
||||
|
||||
private Expr wert;
|
||||
//private Type type;
|
||||
private Vector<GenericTypeVar> parameter;
|
||||
|
||||
/**
|
||||
* Dieser Konstruktor der FieldDeclaration erstellt den Syntaxknoten vollständig.
|
||||
@ -160,4 +161,9 @@ public class FieldDeclaration extends Field{
|
||||
if(this.getWert()!=null)this.getWert().wandleRefTypeAttributes2GenericAttributes(paralist, new Vector<GenericTypeVar>()); //FieldDeclaration hat keine Generischen Variablen, daher leere Liste übergeben
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGenericParameter(Vector<GenericTypeVar> params) {
|
||||
this.parameter = params;
|
||||
}
|
||||
|
||||
}
|
||||
|
14
src/mycompiler/myclass/Generic.java
Normal file
14
src/mycompiler/myclass/Generic.java
Normal file
@ -0,0 +1,14 @@
|
||||
package mycompiler.myclass;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import mycompiler.mytype.GenericTypeVar;
|
||||
|
||||
/**
|
||||
* Wird von allen Klassen implementiert, welche generische Parameter halten können. (Class, Method und Field)
|
||||
* @author janulrich
|
||||
*
|
||||
*/
|
||||
public interface Generic {
|
||||
public void setGenericParameter(Vector<GenericTypeVar> params);
|
||||
}
|
@ -736,6 +736,11 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGenericParameter(Vector<GenericTypeVar> params) {
|
||||
this.genericMethodParameters = params;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -906,6 +906,12 @@ fielddeclaration : fielddeclarator ';'
|
||||
$2.setType($1);
|
||||
$$=$2;
|
||||
}
|
||||
| '<' boundedMethodParameters '>' type fielddeclarator
|
||||
{//angefügt von Andreas Stadelmeier
|
||||
$5.setGenericParameter($2);
|
||||
$5.setType($4);
|
||||
$$=$5;
|
||||
}
|
||||
|
|
||||
variabledeclarators ';'
|
||||
{
|
||||
@ -1022,8 +1028,8 @@ boundedMethodParameter : IDENTIFIER
|
||||
}
|
||||
| IDENTIFIER EXTENDS boundedclassidentifierlist
|
||||
{
|
||||
BoundedGenericTypeVar gtv=new BoundedGenericTypeVar($1.getLexem(),$1.getOffset());
|
||||
gtv.setBounds($3);
|
||||
BoundedGenericTypeVar gtv=new BoundedGenericTypeVar($1.getLexem(),$3,$1.getOffset());
|
||||
//gtv.setBounds($3);
|
||||
$$=gtv;
|
||||
}
|
||||
// returns Vector<Type>
|
||||
|
@ -36,7 +36,7 @@ public class BoundedGenericTypeVar extends GenericTypeVar
|
||||
// ino.end
|
||||
|
||||
// ino.method.BoundedGenericTypeVar.26471.definition
|
||||
public BoundedGenericTypeVar(String s, int offset)
|
||||
public BoundedGenericTypeVar(String s, int offset, Vector<Type> t)
|
||||
// ino.end
|
||||
// ino.method.BoundedGenericTypeVar.26471.body
|
||||
{
|
||||
@ -51,8 +51,9 @@ public class BoundedGenericTypeVar extends GenericTypeVar
|
||||
// ino.method.BoundedGenericTypeVar.29409.body
|
||||
{
|
||||
super(s, offset);
|
||||
if(bounds.size()>1)throw new NotImplementedException();
|
||||
this.genericTypeVar = new Pair(new RefType(s,offset),bounds.elementAt(0));
|
||||
this.bounds = bounds;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@ -70,6 +71,7 @@ public class BoundedGenericTypeVar extends GenericTypeVar
|
||||
// ino.end
|
||||
// ino.method.setBounds.26477.body
|
||||
{
|
||||
|
||||
this.bounds=types;
|
||||
}
|
||||
// ino.end
|
||||
|
@ -64,7 +64,9 @@ public class TypeInsertSet {
|
||||
//Das additional Offset noch nicht korrigieren, da die generischen Parameter noch vor den Typ müssen.
|
||||
|
||||
//Jetzt sind die übriggebliebenen TPHs bekannt und die benötigten Generischen Variablen können berechnet werden.
|
||||
Iterator<Pair> it = p.getResultSet().getConstraintsFor(insertCode.getUnresolvedTPH()).iterator();
|
||||
Vector<Pair> unresolvedPairs = p.getResultSet().getConstraintsFor(insertCode.getUnresolvedTPH());
|
||||
if(unresolvedPairs.size()>0){ //Nur falls es wirklich was zum Einsetzen gibt:
|
||||
Iterator<Pair> it = unresolvedPairs.iterator();
|
||||
String genericTypeParameters = "<";
|
||||
while(it.hasNext()){
|
||||
genericTypeParameters += new GenericTypeVar(it.next(), 0).printJavaCode(p.getResultSet());
|
||||
@ -76,6 +78,7 @@ public class TypeInsertSet {
|
||||
ret = tip.insertType(insertCode.toString(), additionalOffset).toString();
|
||||
//Jetzt das gesamte Offset korrigieren:
|
||||
additionalOffset += tip.getInsertLength();
|
||||
}
|
||||
additionalOffset += p.getInsertLength();
|
||||
|
||||
}
|
||||
|
3
test/parser/BoundedParameter.jav
Normal file
3
test/parser/BoundedParameter.jav
Normal file
@ -0,0 +1,3 @@
|
||||
class Matrix{
|
||||
<AH extends AL, AI extends AH, B extends AK, B extends AK, AI extends AH, AH extends AL> Fun1<Fun1<AL, Fun2<AI, Matrix, AK>>, B> op = (m) -> ( f) -> f.apply(this, m);
|
||||
}
|
@ -28,8 +28,9 @@ public class GeneralParserTest{
|
||||
@Test
|
||||
public void run(){
|
||||
Vector<String> filenames = new Vector<String>();
|
||||
filenames.add("FieldInitializationTest.jav");
|
||||
filenames.add("ImportTest.jav");
|
||||
//filenames.add("FieldInitializationTest.jav");
|
||||
//filenames.add("ImportTest.jav");
|
||||
filenames.add("BoundedParameter.jav");
|
||||
MyCompilerAPI compiler = MyCompiler.getAPI();
|
||||
try{
|
||||
for(String filename : filenames)
|
||||
|
@ -108,7 +108,7 @@ class TestNode implements TypeInsertable{
|
||||
@Override
|
||||
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
|
||||
ResultSet resultSet) {
|
||||
return new TypeInsertPoint(tph, this, resultSet.getTypeEqualTo(tph), resultSet);
|
||||
return new TypeInsertPoint( this, resultSet.getTypeEqualTo(tph), resultSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
12171
tools/y.output
12171
tools/y.output
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user