createTypeInsertPoint-Methode eingeführt

This commit is contained in:
JanUlrich 2014-03-25 04:41:07 +01:00
parent c738e5c0de
commit 0e19e996c1
16 changed files with 393 additions and 328 deletions

View File

@ -1371,7 +1371,7 @@ formalparameter : type variabledeclaratorid
{ {
FormalParameter FP = new FormalParameter($2); FormalParameter FP = new FormalParameter($2);
FP.setType($1); FP.setType($1);
//FP.set_DeclId($2); //FP.set_DeclId($2); //auskommentiert von Andreas Stadelmeier. DeclId wird nun dem Konstruktor von FormalParameter übergeben.
$$=FP; $$=FP;
} }

View File

@ -2,7 +2,6 @@
package mycompiler.mybytecode; package mycompiler.mybytecode;
// ino.end // ino.end
// ino.module.CONSTANT_Float_info.8536.import // ino.module.CONSTANT_Float_info.8536.import
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
// ino.end // ino.end
import java.io.OutputStream; import java.io.OutputStream;

View File

@ -6,10 +6,12 @@ import mycompiler.SyntaxTreeNode;
import mycompiler.mybytecode.ClassFile; import mycompiler.mybytecode.ClassFile;
import mycompiler.myexception.JVMCodeException; import mycompiler.myexception.JVMCodeException;
import mycompiler.mytype.Type; import mycompiler.mytype.Type;
import mycompiler.mytype.TypePlaceholder;
import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent;
import typinferenz.ConstraintsSet; import typinferenz.ConstraintsSet;
import typinferenz.JavaCodeResult; import typinferenz.JavaCodeResult;
import typinferenz.ResultSet; import typinferenz.ResultSet;
import typinferenz.TypeInsertPoint;
import typinferenz.Typeable; import typinferenz.Typeable;
import typinferenz.TypeInsertable; import typinferenz.TypeInsertable;
import typinferenz.assumptions.TypeAssumptions; import typinferenz.assumptions.TypeAssumptions;
@ -95,4 +97,11 @@ public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Ty
public String getDescription(){ public String getDescription(){
return this.getIdentifier(); return this.getIdentifier();
} }
@Override
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
ResultSet resultSet) {
return new TypeInsertPoint(tph, this, resultSet.getTypeEqualTo(tph), resultSet);
}
} }

View File

@ -23,9 +23,12 @@ import org.apache.log4j.Logger;
import sun.reflect.generics.reflectiveObjects.NotImplementedException; import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.JavaCodeResult; import typinferenz.JavaCodeResult;
import typinferenz.ResultSet; import typinferenz.ResultSet;
import typinferenz.TypeInsertPoint;
import typinferenz.Typeable; import typinferenz.Typeable;
import typinferenz.TypeInsertable; import typinferenz.TypeInsertable;
import typinferenz.exceptions.TypinferenzException; import typinferenz.exceptions.TypinferenzException;
@ -240,5 +243,13 @@ public class FormalParameter extends SyntaxTreeNode implements ITypeReplacementL
} }
@Override
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
ResultSet resultSet) {
if(this.getOffset()<=0)return null;
return new TypeInsertPoint(tph, this, resultSet.getTypeEqualTo(tph), resultSet);
}
} }
// ino.end // ino.end

View File

@ -36,6 +36,7 @@ import typinferenz.JavaCodeResult;
import typinferenz.SingleConstraint; import typinferenz.SingleConstraint;
import typinferenz.ConstraintsSet; import typinferenz.ConstraintsSet;
import typinferenz.ResultSet; import typinferenz.ResultSet;
import typinferenz.TypeInsertPoint;
import typinferenz.TypeInsertable; import typinferenz.TypeInsertable;
import typinferenz.assumptions.MethodAssumption; import typinferenz.assumptions.MethodAssumption;
import typinferenz.assumptions.ParameterAssumption; import typinferenz.assumptions.ParameterAssumption;
@ -711,5 +712,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
return super.equals(obj); return super.equals(obj);
} }
} }
// ino.end // ino.end

View File

@ -1962,7 +1962,7 @@ case 149:
{ {
FormalParameter FP = new FormalParameter(((DeclId)yyVals[0+yyTop])); FormalParameter FP = new FormalParameter(((DeclId)yyVals[0+yyTop]));
FP.setType(((Type)yyVals[-1+yyTop])); FP.setType(((Type)yyVals[-1+yyTop]));
/*FP.set_DeclId($2);*/ /*FP.set_DeclId($2); //auskommentiert von Andreas Stadelmeier. DeclId wird nun dem Konstruktor von FormalParameter übergeben.*/
yyVal=FP; yyVal=FP;
} }
break; break;

View File

@ -1371,7 +1371,7 @@ formalparameter : type variabledeclaratorid
{ {
FormalParameter FP = new FormalParameter($2); FormalParameter FP = new FormalParameter($2);
FP.setType($1); FP.setType($1);
//FP.set_DeclId($2); //FP.set_DeclId($2); //auskommentiert von Andreas Stadelmeier. DeclId wird nun dem Konstruktor von FormalParameter übergeben.
$$=FP; $$=FP;
} }

View File

@ -527,7 +527,9 @@ public class TypePlaceholder extends Type implements IReplaceTypeEventProvider
TypeInsertSet ret = new TypeInsertSet(); TypeInsertSet ret = new TypeInsertSet();
for(ITypeReplacementListener ti : this.m_ReplacementListeners){ for(ITypeReplacementListener ti : this.m_ReplacementListeners){
if(ti instanceof TypeInsertable){ if(ti instanceof TypeInsertable){
ret.add(new TypeInsertPoint(this, (TypeInsertable)ti, result.getTypeEqualTo(this), result)); TypeInsertPoint toAdd = ((TypeInsertable) ti).createTypeInsertPoint(this, result);
if(toAdd != null)ret.add(toAdd);
//ret.add(new TypeInsertPoint(this, (TypeInsertable)ti, result.getTypeEqualTo(this), result));
} }
} }
return ret; return ret;

View File

@ -6,7 +6,6 @@ import mycompiler.myclass.*;
import mycompiler.mytype.TypePlaceholder; import mycompiler.mytype.TypePlaceholder;
public class FunNMethod extends Method{ public class FunNMethod extends Method{
/** /**
* *
* @param N - Anzahl der Parameter (Beispiel: Fun2<R, T1, T2>) * @param N - Anzahl der Parameter (Beispiel: Fun2<R, T1, T2>)
@ -14,6 +13,7 @@ public class FunNMethod extends Method{
public FunNMethod(int N){ public FunNMethod(int N){
super(0); //Hat keinen Offset, da nur theoretisch gedachte Methode super(0); //Hat keinen Offset, da nur theoretisch gedachte Methode
this.setType(TypePlaceholder.fresh(this)); this.setType(TypePlaceholder.fresh(this));
this.set_DeclId(new DeclId("Fun"+N));
ParameterList pl = new ParameterList(); ParameterList pl = new ParameterList();
Vector<FormalParameter> fpList = new Vector<FormalParameter>(); Vector<FormalParameter> fpList = new Vector<FormalParameter>();
for(int i = 0;i<N;i++){ for(int i = 0;i<N;i++){
@ -27,4 +27,10 @@ public class FunNMethod extends Method{
this.parameterlist = pl; this.parameterlist = pl;
} }
@Override
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
ResultSet resultSet) {
return null;
}
} }

View File

@ -4,7 +4,7 @@ import mycompiler.mytype.*;
import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener; import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener;
public class TypeInsertPoint { public class TypeInsertPoint implements Comparable<TypeInsertPoint>{
private TypePlaceholder tph; private TypePlaceholder tph;
private TypeInsertable point; private TypeInsertable point;
@ -70,4 +70,9 @@ public class TypeInsertPoint {
return true; return true;
} }
@Override
public int compareTo(TypeInsertPoint arg0) {
return new Integer(this.getOffset()).compareTo(new Integer(arg0.getOffset()));
}
} }

View File

@ -1,5 +1,6 @@
package typinferenz; package typinferenz;
import java.util.Collections;
import java.util.Vector; import java.util.Vector;
import mycompiler.SyntaxTreeNode; import mycompiler.SyntaxTreeNode;
@ -33,6 +34,7 @@ public class TypeInsertSet {
public String insertAllTypes(String fileContent) { public String insertAllTypes(String fileContent) {
int additionalOffset = 0; int additionalOffset = 0;
String ret = fileContent; String ret = fileContent;
Collections.sort(points);
for(TypeInsertPoint p : points){ for(TypeInsertPoint p : points){
ret = p.insertType(ret, additionalOffset); ret = p.insertType(ret, additionalOffset);
additionalOffset += p.getInsertLength(); additionalOffset += p.getInsertLength();

View File

@ -1,5 +1,6 @@
package typinferenz; package typinferenz;
import mycompiler.mytype.TypePlaceholder;
import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener; import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener;
public interface TypeInsertable extends ITypeReplacementListener, Typeable { public interface TypeInsertable extends ITypeReplacementListener, Typeable {
@ -8,4 +9,13 @@ public interface TypeInsertable extends ITypeReplacementListener, Typeable {
public void setOffset(int offset); public void setOffset(int offset);
public String getIdentifier(); public String getIdentifier();
/**
* Errechnet den TypeInsertPoint für das TypeInsertable.
* TypeInsertPoints sollten nur über diese Funktion erstellt werden.
* @param tph
* @param resultSet
* @return - kann auch null zurückgeben.
*/
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph, ResultSet resultSet);
} }

File diff suppressed because one or more lines are too long

View File

@ -21,6 +21,7 @@ import mycompiler.mytype.TypePlaceholder;
import mycompiler.mytypereconstruction.TypeinferenceResultSet; import mycompiler.mytypereconstruction.TypeinferenceResultSet;
import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent;
import typinferenz.ResultSet; import typinferenz.ResultSet;
import typinferenz.TypeInsertPoint;
import typinferenz.TypeInsertSet; import typinferenz.TypeInsertSet;
import typinferenz.TypeInsertable; import typinferenz.TypeInsertable;
@ -43,7 +44,7 @@ public class TRMEqualTest {
addTestNode("Typ1"); addTestNode("Typ1");
assertTrue("Nach dem Anfügen eines Type muss das Set 1 Element enthalten",replaceSet.size()==1); assertTrue("Nach dem Anfügen eines Type muss das Set 1 Element enthalten",replaceSet.size()==1);
addTestNode("Typ2"); addTestNode("Typ2");
assertTrue("Nach dem Anfügen eines weiteren Typs muss das Set 2 Elemente enthalten",replaceSet.size()==2); assertTrue("Nach dem Anfügen eines weiteren Typs muss das Set 2 Elemente enthalten und nicht "+replaceSet.size(),replaceSet.size()==2);
addTestNode("Typ1"); addTestNode("Typ1");
assertTrue("Nach dem Anfügen des selben Typs wie zuvor muss das Set immer noch 2 Element enthalten. Und nicht "+replaceSet.size(),replaceSet.size()==2); assertTrue("Nach dem Anfügen des selben Typs wie zuvor muss das Set immer noch 2 Element enthalten. Und nicht "+replaceSet.size(),replaceSet.size()==2);
} }
@ -104,5 +105,11 @@ class TestNode implements TypeInsertable{
return null; return null;
} }
@Override
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
ResultSet resultSet) {
return new TypeInsertPoint(tph, this, resultSet.getTypeEqualTo(tph), resultSet);
}
} }

View File

@ -7,6 +7,7 @@ import org.junit.Test;
public class MutlitpleTestCases { public class MutlitpleTestCases {
private static final String TEST_FILE = "Test1.jav"; private static final String TEST_FILE = "Test1.jav";
private static final String TEST_FILE2 = "Test2.jav";
@Test @Test
public void test1(){ public void test1(){
@ -15,4 +16,10 @@ public class MutlitpleTestCases {
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain); MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
} }
@Test
public void test2(){
Vector<String> mustContain = new Vector<String>();
MultipleTypesInsertTester.test(this.TEST_FILE2, mustContain);
}
} }

View File

@ -0,0 +1,4 @@
public class Matrix{
op = (m) -> (f) -> f.apply(this, m);
}