Merge mit master. LocalVarDecl.declType entfernt

This commit is contained in:
JanUlrich 2014-03-19 15:53:02 +01:00
commit 5b141bbb5d
53 changed files with 8140 additions and 7432 deletions

View File

@ -867,7 +867,15 @@ Beispiel: var = 2;
Bei einer lokalen Variable lässt sich hier nicht ermitteln ob die Variable deklariert werden soll oder bereits deklariert wurde und ihr nur ein Wert zugewiesen werden soll.
Dieses Problem ist bei Feldern nicht der Fall.
*/
fielddeclarator : variabledeclarator '=' expression
fielddeclarator : type variabledeclarator '=' expression
{
FieldDeclaration ret = new FieldDeclaration($2.getOffset());
ret.setType($1);
ret.set_DeclId($2);
ret.setWert($4);
$$=ret;
}
| variabledeclarator '=' expression
{
FieldDeclaration ret = new FieldDeclaration($1.getOffset());
ret.set_DeclId($1);
@ -1361,9 +1369,9 @@ blockstatement :localvariabledeclarationstatement
formalparameter : type variabledeclaratorid
{
FormalParameter FP = new FormalParameter();
FormalParameter FP = new FormalParameter($2);
FP.setType($1);
FP.set_DeclId($2);
//FP.set_DeclId($2);
$$=FP;
}
@ -1375,9 +1383,9 @@ formalparameter : type variabledeclaratorid
Parameterliste setzen
$5.set_Paratyp($3.get_ParaList());
FormalParameter FP = new FormalParameter();
FormalParameter FP = new FormalParameter($5);
FP.setType($1);
FP.set_DeclId($5);
//FP.set_DeclId($5);
$$=FP;
org.apache.log4j.Logger.getLogger("parser").debug("P->Polymorphes Methodenargument hinzugefuegt: Name = " + $5.get_Name() + " Typ = " + $1.getName());
@ -1388,7 +1396,7 @@ formalparameter : type variabledeclaratorid
{
org.apache.log4j.Logger.getLogger("parser").debug("\nFunktionsdeklaration mit typlosen Parametern: " + $1.name);
FormalParameter FP = new FormalParameter();
FormalParameter FP = new FormalParameter($1);
// #JB# 31.03.2005
// ###########################################################
@ -1398,7 +1406,7 @@ formalparameter : type variabledeclaratorid
//org.apache.log4j.Logger.getLogger("parser").debug("\n--> berechneter Name: " + T.getName());
//auskommentiert von Andreas Stadelmeier (a10023) FP.setType( T );
FP.set_DeclId($1);
//FP.set_DeclId($1);
$$=FP;
}

View File

@ -44,9 +44,10 @@ import com.sun.corba.se.spi.orbutil.fsm.Guard.Result;
import com.sun.org.apache.xerces.internal.impl.xs.identity.Field;
import typinferenz.ResultSet;
import typinferenz.TypinferenzException;
// ino.end
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.ParserException;
import typinferenz.exceptions.TypinferenzException;
@ -485,14 +486,16 @@ public class MyCompiler implements MyCompilerAPI
*/
// ino.end
// ino.method.parse.21298.definition
public void parse(File file)
public SourceFile parse(File file)
throws FileNotFoundException, IOException, JavaParser.yyException
// ino.end
// ino.method.parse.21298.body
{
FileReader fr = new FileReader(file);
this.m_AbstractSyntaxTree.add(this.parse2SyntaxTree(fr));
SourceFile ret = this.parse2SyntaxTree(fr);
this.m_AbstractSyntaxTree.add(ret);
fr.close();
return ret;
}
// ino.end
@ -752,8 +755,8 @@ public class MyCompiler implements MyCompilerAPI
try {
srcFile = (SourceFile) parser.yyparse( scanner );
} catch (IOException | yyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
if(e instanceof yyException)throw new ParserException((yyException)e);
}
//////////////////////////////////////
// Postprocessing:
@ -786,7 +789,6 @@ public class MyCompiler implements MyCompilerAPI
}
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@ -812,7 +814,6 @@ public class MyCompiler implements MyCompilerAPI
reader.close();
gesamterSrc += fileData.toString() + "\n"; // Alle Dateien nacheinander hintereinander anhängen...
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new TypinferenzException("Die übergebenen Dateien konnten nicht zum Parsen eingelesen werden.");
}

View File

@ -53,7 +53,7 @@ public interface MyCompilerAPI
*/
// ino.end
// ino.method.parse.21334.declaration
public void parse(File file)
public SourceFile parse(File file)
throws FileNotFoundException, IOException, JavaParser.yyException;
// ino.end

View File

@ -45,9 +45,9 @@ import sun.reflect.generics.reflectiveObjects.TypeVariableImpl;
import typinferenz.ConstraintsSet;
import typinferenz.FunN;
import typinferenz.ResultSet;
import typinferenz.TypinferenzException;
import typinferenz.UndConstraint;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;
@ -650,89 +650,96 @@ public class SourceFile
globalAssumptions.add(klasse.getPublicFieldAssumptions());
}
ConstraintsSet oderConstraints = new ConstraintsSet();
//Alle Constraints der in dieser SourceFile enthaltenen Klassen sammeln:
for(Class klasse : KlassenVektor){
ConstraintsSet oderConstraints = klasse.typeReconstruction(finiteClosure, globalAssumptions);
//Die Constraints in Pair's umwandeln (Karthesisches Produkt bilden):
Vector<Vector<Pair>> xConstraints = new Vector<Vector<Pair>>();// = oderConstraints.getConstraints();
for(Vector<UndConstraint> uC:oderConstraints.getConstraints()){ //mit dem getConstraints-Aufruf wird das Karthesische Produkt erzeugt.
Vector<Pair> cons = new Vector<Pair>();
for(UndConstraint undCons:uC){
cons.addAll(undCons.getConstraintPairs());
}
xConstraints.add(cons);
}
typinferenzLog.debug("Karthesisches Produkt der Constraints: "+xConstraints);
//////////////////////////////
// Unifizierung der Constraints:
//////////////////////////////
for(Vector<Pair> constraints : xConstraints){
//Alle durch das Karthesische Produkt entstandenen Möglichkeiten durchgehen:
Vector<Vector<Pair>> result = new Vector<Vector<Pair>>();
//Alle FunN-Typen werden per clone-methode in RefTypes verwandelt. (Die clone Methode in FunN darf nicht überschrieben werden.
for(Pair p : constraints){
if(p.TA1 instanceof FunN){
p.TA1 = p.TA1.clone();
}
if(p.TA2 instanceof FunN){
p.TA2 = p.TA2.clone();
}
}
//Erst die Unifizierung erstellen:
Vector<Pair> constraintsClone = (Vector<Pair>)constraints.clone();
Vector<Vector<Pair>> unifyResult = Unify.unify(constraintsClone, finiteClosure);
//Dann den Ergebnissen anfügen
result.addAll(unifyResult);
// Debugoutput:Vector<Vector<Pair>>
typinferenzLog.debug("Unifiziertes Ergebnis: "+result);
/*
// Prüfe ob eindeutige Lösung:
if(result.size()>1 && !Unify.hasSolvedForm(result.elementAt(0))){
typinferenzLog.debug("Keine eindeutige Lösung!");
}else if(result.size()>1){
//Replace TPH:
for(Pair res : result.elementAt(0)){
if(res.OperatorEqual()){
if(res.TA1 instanceof TypePlaceholder)((TypePlaceholder)res.TA1).fireReplaceTypeEvent(new CReplaceTypeEvent(res.TA1, res.TA2));
}
}
}
*/
//typinferenzLog.debug();
//typinferenzLog.debug(supportData.getFiniteClosure());
//typinferenzLog.debug("Typinformationen: \n"+this.getTypeInformation(this.getMethodList(), fieldInitializers));
typinferenzLog.debug("\nJavaFiles:\n");
//typinferenzLog.debug(this.printJavaCode(new ResultSet(new Vector<Pair>())));
//Der Unifikationsalgorithmus kann wiederum auch mehrere Lösungen errechnen, diese werden im folgenden durchlaufen:
for(Vector<Pair> resultSet : result){
//Add Result set as a new ReconstructionResult to ret:
TypeinferenceResultSet reconstructionResult = new TypeinferenceResultSet(klasse, constraints, new ResultSet(resultSet));
ret.add(reconstructionResult);
//ResultSet res = new ResultSet(resultSet);
typinferenzLog.debug("JavaFile für ResultSet "+reconstructionResult+"\n");
typinferenzLog.debug(klasse.printJavaCode(reconstructionResult));
}
}
oderConstraints.add(klasse.typeReconstruction(finiteClosure, globalAssumptions));
}
////////////////
//Karthesisches Produkt bilden:
////////////////
//Die Constraints in Pair's umwandeln (Karthesisches Produkt bilden):
Vector<Vector<Pair>> xConstraints = new Vector<Vector<Pair>>();// = oderConstraints.getConstraints();
for(Vector<UndConstraint> uC:oderConstraints.getConstraints()){ //mit dem getConstraints-Aufruf wird das Karthesische Produkt erzeugt.
Vector<Pair> cons = new Vector<Pair>();
for(UndConstraint undCons:uC){
cons.addAll(undCons.getConstraintPairs());
}
xConstraints.add(cons);
}
typinferenzLog.debug("Karthesisches Produkt der Constraints: "+xConstraints);
//////////////////////////////
// Unifizierung der Constraints:
//////////////////////////////
for(Vector<Pair> constraints : xConstraints){
//Alle durch das Karthesische Produkt entstandenen Möglichkeiten durchgehen:
Vector<Vector<Pair>> result = new Vector<Vector<Pair>>();
//Alle FunN-Typen werden per clone-methode in RefTypes verwandelt. (Die clone Methode in FunN darf nicht überschrieben werden.
for(Pair p : constraints){
if(p.TA1 instanceof FunN){
p.TA1 = p.TA1.clone();
}
if(p.TA2 instanceof FunN){
p.TA2 = p.TA2.clone();
}
}
//Erst die Unifizierung erstellen:
Vector<Pair> constraintsClone = (Vector<Pair>)constraints.clone();
Vector<Vector<Pair>> unifyResult = Unify.unify(constraintsClone, finiteClosure);
//Dann den Ergebnissen anfügen
result.addAll(unifyResult);
// Debugoutput:Vector<Vector<Pair>>
typinferenzLog.debug("Unifiziertes Ergebnis: "+result);
/*
// Prüfe ob eindeutige Lösung:
if(result.size()>1 && !Unify.hasSolvedForm(result.elementAt(0))){
typinferenzLog.debug("Keine eindeutige Lösung!");
}else if(result.size()>1){
//Replace TPH:
for(Pair res : result.elementAt(0)){
if(res.OperatorEqual()){
if(res.TA1 instanceof TypePlaceholder)((TypePlaceholder)res.TA1).fireReplaceTypeEvent(new CReplaceTypeEvent(res.TA1, res.TA2));
}
}
}
*/
//typinferenzLog.debug();
//typinferenzLog.debug(supportData.getFiniteClosure());
//typinferenzLog.debug("Typinformationen: \n"+this.getTypeInformation(this.getMethodList(), fieldInitializers));
typinferenzLog.debug("\nJavaFiles:\n");
//typinferenzLog.debug(this.printJavaCode(new ResultSet(new Vector<Pair>())));
//Für jede Klasse in diesem SourceFile gilt das selbe ResultSet:
for(Class klasse : this.KlassenVektor){
//Der Unifikationsalgorithmus kann wiederum auch mehrere Lösungen errechnen, diese werden im folgenden durchlaufen:
for(Vector<Pair> resultSet : result){
//Add Result set as a new ReconstructionResult to ret:
TypeinferenceResultSet reconstructionResult = new TypeinferenceResultSet(klasse, constraints, new ResultSet(resultSet));
ret.add(reconstructionResult);
//ResultSet res = new ResultSet(resultSet);
typinferenzLog.debug("JavaFile für ResultSet "+reconstructionResult+"\n");
typinferenzLog.debug(klasse.printJavaCode(reconstructionResult));
}
}
}
return ret;
/*
// HOTI: Nur zur Info.Ich habe den Loglevel auf Info geschaltet, damit
@ -745,7 +752,7 @@ public class SourceFile
TypeAssumptions basics;
basics = this.makeBasicAssumptions(); //TODO: Diese Funktion ändern, dass nur noch TypeAssumptions zurückgegeben werden. Diese sind wichtig, da hier die Standard-Library von Java als Assumptions generiert wird.
basics = this.makeBasicAssumptions();
//A.addElement(basics); //auskommentiert von Andreas Stadelmeier
@ -1380,7 +1387,9 @@ public class SourceFile
return foo;
*/
return new TypeAssumptions(null); //TODO: Diese TypeAssumptions mit basic-Assumptions füllen
TypeAssumptions ret = new TypeAssumptions();
return ret; //TODO: Diese TypeAssumptions mit basic-Assumptions füllen
}
// ino.end
@ -1519,7 +1528,6 @@ public class SourceFile
@Override
public SyntaxTreeNode getParent() {
// TODO Auto-generated method stub
return null;
}
@ -1543,6 +1551,5 @@ public class SourceFile
//this.filename = filename;
}
}
// ino.end

View File

@ -2,7 +2,7 @@ package mycompiler;
import java.util.Vector;
import typinferenz.TypinferenzException;
import typinferenz.exceptions.TypinferenzException;
import mycompiler.myclass.Class;
public abstract class SyntaxTreeNode {
@ -41,4 +41,14 @@ public abstract class SyntaxTreeNode {
public String getDescription(){
return this.toString();
}
@Override
public boolean equals(Object object){
if(!(object instanceof SyntaxTreeNode))return false;
SyntaxTreeNode equal = (SyntaxTreeNode)object;
if(!equal.getDescription().equals(this.getDescription()))return false;
if(this.getParent()!=null)
if(!this.getParent().equals(equal.getParent()))return false; //auch das Elternelement überprüfen.
return true;
}
}

View File

@ -57,15 +57,16 @@ import org.apache.log4j.Logger;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.ConstraintsSet;
import typinferenz.JavaCodeResult;
import typinferenz.OderConstraint;
import typinferenz.ResultSet;
import typinferenz.TypinferenzException;
import typinferenz.UndConstraint;
import typinferenz.FunN;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;
@ -639,10 +640,11 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface
// @author A10023 - Andreas Stadelmeier:
//////////////////////////////
//Erzeuge Assumptions:
TypeAssumptions assumptions = this.getTypeAssumptions();
//--
TypeAssumptions assumptions = this.getPrivateFieldAssumptions();
//Globale Assumptions anfügen:
assumptions.add(globalAssumptions);
typinferenzLog.debug("Erstellte Assumptions: "+assumptions);
/*
//Generiere Liste mit Expressions, welche zur Initialisierung von Feldern verwendet werden.
Vector<Expr> fieldInitializers = new Vector<Expr>();
@ -825,11 +827,11 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface
*/
/**
* Die Funktion ist erst nach dem Aufruf von getMethodList() nutzbar.
* Ermittelt alle Felder und Methoden der Klasse und Erstellt eine Assumption für diese.
* Ermittelt alle privaten Felder und Methoden der Klasse und Erstellt eine Assumption für diese.
* Bemerkung: Momentan werden noch alle Felder dieser Klasse zurückgegeben.
* @return Die erstellten TypeAssumptions
*/
private TypeAssumptions getTypeAssumptions() {
private TypeAssumptions getPrivateFieldAssumptions() {
if(this.typeAssumptions != null)return this.typeAssumptions; //Das sorgt dafür, dass die Assumptions nur einmalig generiert werden.
TypeAssumptions assumptions = new TypeAssumptions(this.getName());
//this.getMethodList(); //Diese Funktion muss zuerst ausgeführt werden.
@ -848,9 +850,6 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface
// assumptions.addMethodAssumption(new RefType(this.getName(),0), "<init>", new RefType(this.getName(),0), new Vector<CParaTypeAssumption>());
//}
typinferenzLog.debug("Erstellte Assumptions: "+assumptions);
this.typeAssumptions = assumptions; //Diese müssen anschließend nicht wieder generiert werden.
return assumptions;
}
@ -1166,11 +1165,6 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface
JavaCodeResult classBodyCode = new JavaCodeResult();
if(this.modifiers!=null)classBodyCode.attach(this.modifiers.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach(" ");
if(superclassid == null || superclassid.get_Name().size()<1){
int superclassidOffset = superclassid == null ? 0 : superclassid.getOffset();
superclassid = new UsedId("Object", superclassidOffset);
}
classBodyCode.attach(this.name + " extends ").attach(superclassid.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach("\n");
@ -1261,7 +1255,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface
* @return
*/
public TypeAssumptions getPublicFieldAssumptions() {
TypeAssumptions ret = this.getTypeAssumptions();
TypeAssumptions ret = this.getPrivateFieldAssumptions();
for(Field f : this.getFields()){
ret.add(f.createTypeAssumptions(this));
}
@ -1272,6 +1266,12 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface
public void parserPostProcessing(SyntaxTreeNode parent) {
super.parserPostProcessing(parent);
//Wenn keine Superklasse, dann erbt die Klasse zwangsweise von Object:
if(superclassid == null || superclassid.get_Name().size()<1){
int superclassidOffset = superclassid == null ? 0 : superclassid.getOffset();
superclassid = new UsedId("Object", superclassidOffset);
}
//Alle Methoden auf Konstruktoren durchsuchen und diese umwandeln:
Vector<Field> tempFields = new Vector<Field>();
for(Field f : this.getFields()){

View File

@ -15,8 +15,10 @@ import typinferenz.ConstraintsSet;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
import typinferenz.SingleConstraint;
import typinferenz.TypinferenzException;
import typinferenz.assumptions.ConstructorAssumption;
import typinferenz.assumptions.MethodAssumption;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;
public class Constructor extends Method {
private Method methode;
@ -238,10 +240,17 @@ public class Constructor extends Method {
@Override
public TypeAssumptions createTypeAssumptions(Class classmember) {
return this.methode.createTypeAssumptions(classmember);
Class parentClass = this.getParentClass();
TypeAssumptions ret = new TypeAssumptions();
ret.addConstructorAssumption(new ConstructorAssumption(this, parentClass));
return ret;
}
@Override
public SyntaxTreeNode getParent(){
return this.methode.getParent();
}
@Override
public void parserPostProcessing(SyntaxTreeNode parent) {
@ -264,6 +273,54 @@ public class Constructor extends Method {
public Type getType() {
return this.methode.getType();
}
@Override
public boolean equals(Object obj) {
return this.methode.equals(obj);
}
@Override
public void set_DeclId(DeclId did) {
this.methode.set_DeclId(did);
}
@Override
public Vector<DeclId> get_Name() {
return this.methode.get_Name();
}
@Override
public Vector<DeclId> getDeclIdVector() {
return this.methode.getDeclIdVector();
}
@Override
public void setDeclIdVector(Vector<DeclId> vDeclId) {
this.methode.setDeclIdVector(vDeclId);
}
@Override
public String getIdentifier() {
return this.methode.getIdentifier();
}
@Override
public String getDescription() {
return this.methode.getDescription();
}
@Override
public Class getParentClass() {
return this.methode.getParentClass();
}
}

View File

@ -7,9 +7,9 @@ import typinferenz.JavaCodeResult;
import typinferenz.OderConstraint;
import typinferenz.ResultSet;
import typinferenz.SingleConstraint;
import typinferenz.TypinferenzException;
import typinferenz.assumptions.FieldAssumption;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;
import mycompiler.SyntaxTreeNode;
import mycompiler.mybytecode.ClassFile;
import mycompiler.myexception.JVMCodeException;
@ -54,7 +54,8 @@ public class FieldDeclaration extends Field{
@Override
public String toString()
{
return super.toString() + "=" + getWert().toString();
if(getWert()!=null)return super.toString() + "=" + getWert().toString();
return super.toString();
}
@ -74,7 +75,7 @@ public class FieldDeclaration extends Field{
//////////////////////////////
TypeAssumptions assumptions = new TypeAssumptions();
/*
* TODO: Der Feld-Assumption muss ein TPH als Typ hinzugefügt werden, falls er Typlos initialisiert wurde. Dies kann auch der Type-Algorithmus der Inst/FieldVar - Klasse machen.
* Der Feld-Assumption muss ein TPH als Typ hinzugefügt werden, falls er Typlos initialisiert wurde. Dies kann auch der Type-Algorithmus der Inst/FieldVar - Klasse machen.
* Wird das Feld mit einem Typ initialisiert so muss dieser auch in die Assumptions.
*/
if(this.getType() == null)throw new TypinferenzException("Der Typ eines Feldes darf nicht null sein");

View File

@ -3,6 +3,9 @@ package mycompiler.myclass;
// ino.end
// ino.module.FormalParameter.8561.import
import java.util.Vector;
import mycompiler.SyntaxTreeNode;
import mycompiler.mybytecode.ClassFile;
import mycompiler.mybytecode.CodeAttribute;
import mycompiler.mytype.Type;
@ -16,14 +19,19 @@ import org.apache.log4j.Logger;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
import typinferenz.Typeable;
import typinferenz.TypeInsertable;
import typinferenz.exceptions.TypinferenzException;
// ino.class.FormalParameter.23391.declaration
public class FormalParameter implements ITypeReplacementListener, Typeable, TypeInsertable
public class FormalParameter extends SyntaxTreeNode implements ITypeReplacementListener, Typeable, TypeInsertable
// ino.end
// ino.class.FormalParameter.23391.body
{
@ -37,6 +45,9 @@ public class FormalParameter implements ITypeReplacementListener, Typeable, Type
protected static Logger inferencelog = Logger.getLogger("inference");
// ino.end
public FormalParameter(DeclId name){
this.set_DeclId(name);
}
// ino.method.setType.23404.defdescription type=javadoc
@ -68,6 +79,7 @@ public class FormalParameter implements ITypeReplacementListener, Typeable, Type
// ino.end
// ino.method.set_DeclId.23407.body
{
if(did == null)throw new NullPointerException();
this.declid = did;
}
// ino.end
@ -213,5 +225,20 @@ public class FormalParameter implements ITypeReplacementListener, Typeable, Type
}
@Override
public Vector<SyntaxTreeNode> getChildren() {
return new Vector<SyntaxTreeNode>();
}
@Override
public void parserPostProcessing(SyntaxTreeNode parent) {
super.parserPostProcessing(parent);
if(this.type==null)this.type = TypePlaceholder.fresh(this);
}
}
// ino.end

View File

@ -59,7 +59,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
private Block block;
// ino.end
// ino.attribute.parameterlist.23491.declaration
public ParameterList parameterlist = null;
public ParameterList parameterlist = new ParameterList();
// ino.end
// ino.attribute.exceptionlist.23494.declaration
private ExceptionList exceptionlist;
@ -563,7 +563,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
@Override
public JavaCodeResult printJavaCode(ResultSet resultSet) {
JavaCodeResult ret = new JavaCodeResult();
ret.attach(this.getType().printJavaCode(resultSet)).attach(" ").attach(this.get_Method_Name()).attach("()\n"); //TODO: hier müssen auch noch die Parameter ausgegeben werden!
ret.attach(this.getType().printJavaCode(resultSet)).attach(" ").attach(this.get_Method_Name()).attach("(").attach(this.getParameterList().printJavaCode(resultSet)).attach(")\n");
ret.attach(this.block.printJavaCode(resultSet));
return ret;
@ -668,6 +668,9 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
public Vector<SyntaxTreeNode> getChildren() {
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
ret.add(this.block);
for(FormalParameter param : this.parameterlist){
ret.add(param);
}
return ret;
}
@ -699,5 +702,14 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
return ret;
}
@Override
public boolean equals(Object obj){
if(!(obj instanceof Method))return false;
Method equals = (Method) obj;
if(!this.returntype.equals(equals.returntype))return false;
if(!this.parameterlist.equals(equals.parameterlist))return false;
return super.equals(obj);
}
}
// ino.end

View File

@ -7,7 +7,7 @@ import java.util.Vector;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
import typinferenz.TypinferenzException;
import typinferenz.exceptions.TypinferenzException;
import mycompiler.IItemWithOffset;
import mycompiler.mybytecode.JVMCode;
import mycompiler.mytype.Type;

File diff suppressed because it is too large Load Diff

View File

@ -867,7 +867,15 @@ Beispiel: var = 2;
Bei einer lokalen Variable lässt sich hier nicht ermitteln ob die Variable deklariert werden soll oder bereits deklariert wurde und ihr nur ein Wert zugewiesen werden soll.
Dieses Problem ist bei Feldern nicht der Fall.
*/
fielddeclarator : variabledeclarator '=' expression
fielddeclarator : type variabledeclarator '=' expression
{
FieldDeclaration ret = new FieldDeclaration($2.getOffset());
ret.setType($1);
ret.set_DeclId($2);
ret.setWert($4);
$$=ret;
}
| variabledeclarator '=' expression
{
FieldDeclaration ret = new FieldDeclaration($1.getOffset());
ret.set_DeclId($1);
@ -1361,9 +1369,9 @@ blockstatement :localvariabledeclarationstatement
formalparameter : type variabledeclaratorid
{
FormalParameter FP = new FormalParameter();
FormalParameter FP = new FormalParameter($2);
FP.setType($1);
FP.set_DeclId($2);
//FP.set_DeclId($2);
$$=FP;
}
@ -1375,9 +1383,9 @@ formalparameter : type variabledeclaratorid
Parameterliste setzen
$5.set_Paratyp($3.get_ParaList());
FormalParameter FP = new FormalParameter();
FormalParameter FP = new FormalParameter($5);
FP.setType($1);
FP.set_DeclId($5);
//FP.set_DeclId($5);
$$=FP;
org.apache.log4j.Logger.getLogger("parser").debug("P->Polymorphes Methodenargument hinzugefuegt: Name = " + $5.get_Name() + " Typ = " + $1.getName());
@ -1388,7 +1396,7 @@ formalparameter : type variabledeclaratorid
{
org.apache.log4j.Logger.getLogger("parser").debug("\nFunktionsdeklaration mit typlosen Parametern: " + $1.name);
FormalParameter FP = new FormalParameter();
FormalParameter FP = new FormalParameter($1);
// #JB# 31.03.2005
// ###########################################################
@ -1398,7 +1406,7 @@ formalparameter : type variabledeclaratorid
//org.apache.log4j.Logger.getLogger("parser").debug("\n--> berechneter Name: " + T.getName());
//auskommentiert von Andreas Stadelmeier (a10023) FP.setType( T );
FP.set_DeclId($1);
//FP.set_DeclId($1);
$$=FP;
}

View File

@ -32,14 +32,15 @@ import org.apache.log4j.Logger;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.JavaCodeResult;
import typinferenz.SingleConstraint;
import typinferenz.ConstraintsSet;
import typinferenz.FreshTypeVariable;
import typinferenz.ResultSet;
import typinferenz.TypinferenzException;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;
@ -308,5 +309,10 @@ public class Block extends Statement
}
return ret;
}
@Override
public String getDescription(){
return "Block";
}
}
// ino.end

View File

@ -5,6 +5,7 @@ package mycompiler.mystatement;
import java.util.Hashtable;
import java.util.Vector;
import mycompiler.SyntaxTreeNode;
import mycompiler.mybytecode.ClassFile;
import mycompiler.mybytecode.CodeAttribute;
import mycompiler.myclass.Class;
@ -23,6 +24,7 @@ import org.apache.log4j.Logger;
// ino.end
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.ConstraintsSet;
import typinferenz.JavaCodeResult;
@ -111,5 +113,6 @@ public class EmptyStmt extends Statement
public JavaCodeResult printJavaCode(ResultSet resultSet) {
return new JavaCodeResult("");
}
}
// ino.end

View File

@ -10,9 +10,9 @@ import typinferenz.FreshTypeVariable;
import typinferenz.FunN;
import typinferenz.ResultSet;
import typinferenz.Typeable;
import typinferenz.TypinferenzException;
import typinferenz.assumptions.ParameterAssumption;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;
import mycompiler.SyntaxTreeNode;
import mycompiler.mybytecode.ClassFile;
import mycompiler.mybytecode.CodeAttribute;
@ -124,7 +124,7 @@ public class LambdaExpression extends Expr{
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
ConstraintsSet ret = new ConstraintsSet();
//Die Assumptions für die Parameter der LambdaExpression
TypeAssumptions ArgumentAssumptions = new TypeAssumptions(assumptions.getThisValue().getName());
TypeAssumptions ArgumentAssumptions = new TypeAssumptions(this.getParentClass().getName());
Vector<Type> paramTypes = new Vector<Type>();
for(FormalParameter param : params.formalparameter){

View File

@ -86,33 +86,6 @@ public class LocalVarDecl extends Statement implements TypeInsertable
public Block block;
// ino.end
// ino.method.setType.25569.definition
public void setDeclType(Type t)
// ino.end
// ino.method.setType.25569.body
{
if(this.declType instanceof TypePlaceholder){
((TypePlaceholder)this.declType).removeReplacementListener(this);
}
if(t instanceof TypePlaceholder){
((TypePlaceholder)t).addReplacementListener(this);
}
this.declType=t;
}
// ino.end
// ino.method.getType.25572.definition
public Type getDeclType()
// ino.end
// ino.method.getType.25572.body
{
return this.declType;
}
// ino.end
// ino.method.set_DeclId.25575.definition
public void set_DeclId(DeclId did)
// ino.end
@ -299,7 +272,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable
{
if(declid != null)
for(int i = 0; i < declid.size(); i++)
declid.elementAt(i).codegen_LocalVarDecl(classfile, code, this.getDeclType(), paralist);
declid.elementAt(i).codegen_LocalVarDecl(classfile, code, this.getType(), paralist);
}
// ino.end
// ino.method.getDeclidVector.25596.definition
@ -376,12 +349,12 @@ public class LocalVarDecl extends Statement implements TypeInsertable
}
this.setType(e.getNewType());
}
if(e.getOldType().equals(this.getDeclType())){
if(e.getOldType().equals(this.getType())){
inferencelog.debug("Ersetze Typ in LocalVarDecl \""+this.get_Name()+"\"\n");
if(declType instanceof TypePlaceholder){
((TypePlaceholder)declType).removeReplacementListener(this);
}
this.setDeclType(e.getNewType());
this.setType(e.getNewType());
}
}
// ino.end
@ -419,7 +392,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable
CTripleSet resultSet = new CTripleSet();
V = V.shallowCopy();
CTypeAssumptionSet localSet = new CTypeAssumptionSet();
CLocalVarTypeAssumption varAssum = new CLocalVarTypeAssumption(supportData.getCurrentClass(), supportData.getCurrentMethod(), supportData.getCurrentMethodParaCount(), supportData.getCurrentMethodOverloadedID(), supportData.getCurrentBlockId(), this.get_Name() ,this.getDeclType(), this.getLineNumber(),this.getOffset(),new Vector<Integer>());
CLocalVarTypeAssumption varAssum = new CLocalVarTypeAssumption(supportData.getCurrentClass(), supportData.getCurrentMethod(), supportData.getCurrentMethodParaCount(), supportData.getCurrentMethodOverloadedID(), supportData.getCurrentBlockId(), this.get_Name() ,this.getType(), this.getLineNumber(),this.getOffset(),new Vector<Integer>());
Class.isFirstLocalVarDecl=true;
if(this.block != null)
@ -453,7 +426,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable
// ino.method.wandleRefTypeAttributes2GenericAttributes.25620.body
{
Type fpType=getDeclType();
Type fpType=getType();
// Nur wenn es sich um ein RefType-Field handelt
GenericTypeVar pendantPara=ClassHelper.findGenericType(fpType,paralist,genericMethodParameters);
if(pendantPara!=null){ //Wenn generisch, dann modifizieren
@ -488,7 +461,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable
@Override
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) {
ConstraintsSet ret = new ConstraintsSet();
if(this.getDeclType()==null || this.getDeclType() instanceof TypePlaceholder)this.setDeclType(TypePlaceholder.fresh(this));
if(this.getType()==null || this.getType() instanceof TypePlaceholder)this.setType(TypePlaceholder.fresh(this));
assumptions.addLocalVarAssumption(new LocalVarAssumption(this));
//assumptions.remove(null); // falls Variable mit diesem Namen bereits vorhanden.
this.setType(new Void(0)); //Return typ einer Variablendeklaration ist Void
@ -498,14 +471,14 @@ public class LocalVarDecl extends Statement implements TypeInsertable
@Override
public String getTypeInformation(){
String ret = "VarDeclaration ";
if(this.getDeclType()!=null)ret+= this.getDeclType().toString()+" ";
if(this.getType()!=null)ret+= this.getType().toString()+" ";
ret+=this.get_Name();
return ret;
}
@Override
public JavaCodeResult printJavaCode(ResultSet resultSet) {
return new JavaCodeResult().attach(getDeclType().printJavaCode(resultSet)) .attach( " "+this.get_Name()+";");
return new JavaCodeResult().attach(getType().printJavaCode(resultSet)) .attach( " "+this.get_Name()+";");
}
@Override

View File

@ -664,7 +664,6 @@ public class MethodCall extends Expr
*/
@Override
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
//TODO hier muss unterschieden werden zwischen einem Konstruktor und einer Methode.
//Hier der Ablauf für einen Methodenaufruf:
ConstraintsSet ret = new ConstraintsSet();
//Der Return-Type des MEthodenaufrufs ist zunächst unbekannt:

View File

@ -5,6 +5,7 @@ package mycompiler.mystatement;
import java.util.Hashtable;
import java.util.Vector;
import mycompiler.SyntaxTreeNode;
import mycompiler.mybytecode.ClassFile;
import mycompiler.mybytecode.CodeAttribute;
import mycompiler.mybytecode.JVMCode;
@ -25,6 +26,7 @@ import org.apache.log4j.Logger;
// ino.end
import typinferenz.ConstraintsSet;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
@ -120,5 +122,10 @@ public class Null extends Literal
return new JavaCodeResult("null");
}
@Override
public Vector<SyntaxTreeNode> getChildren() {
return new Vector<SyntaxTreeNode>();
}
}
// ino.end

View File

@ -145,5 +145,10 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse
public abstract JavaCodeResult printJavaCode(ResultSet resultSet);
@Override
public String getDescription(){
return this.printJavaCode(new ResultSet(new Vector<Pair>())).toString();
}
}
// ino.end

View File

@ -152,6 +152,5 @@ public class StringLiteral extends Literal
return ret;
}
}
// ino.end

View File

@ -170,7 +170,8 @@ public class This extends Expr
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
ConstraintsSet ret = new ConstraintsSet();
//this.set_Type(new);
this.setType(assumptions.getThisValue());//Die Assumption für this als TypeVariable setzen.
//this.setType(assumptions.getThisValue());//Die Assumption für this als TypeVariable setzen.
this.setType(new RefType(this.getParentClass().getName(),0));
return ret;
}
@ -192,6 +193,6 @@ public class This extends Expr
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
return ret;
}
}
// ino.end

View File

@ -15,8 +15,8 @@ import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.SimpleLayout;
import typinferenz.TypinferenzException;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;
import mycompiler.MyCompiler;
import mycompiler.MyCompilerAPI;
import mycompiler.mytype.Type;

View File

@ -6,6 +6,7 @@ package mycompiler.mytype;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import java.util.logging.Logger;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
@ -512,6 +513,16 @@ public class TypePlaceholder extends Type implements IReplaceTypeEventProvider
return equalType.printJavaCode(resultSet);
}
/**
* Berechnet die InsertPoints dieses TypePlaceholders.
* Alle an diesem TypePlaceholder registrierten ITypeReplacementListener werden darauf kontrolliert,
* ob sie von TypeInsertable erben.
* Diese ergeben zusammen mit den Informationen aus dem übergebenen ResultSet einen TypeInsertPoint.
* Mehrere TypeInsertPoint's ergeben ein TypeInsertSet.
* @param result Das ResultSet das den einzusetzenden Typ für diesen TPH enthält.
* @return
* @see TypeInsertPoint
*/
public TypeInsertSet getTypeInsertPoints(ResultSet result) {
TypeInsertSet ret = new TypeInsertSet();
for(ITypeReplacementListener ti : this.m_ReplacementListeners){

View File

@ -11,8 +11,8 @@ import typinferenz.ConstraintsSet;
import typinferenz.ResultSet;
import typinferenz.TypeInsertPoint;
import typinferenz.TypeInsertSet;
import typinferenz.TypinferenzException;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;
import mycompiler.mytype.GenericTypeVar;
import mycompiler.mytype.Pair;
import mycompiler.mytype.RefType;
@ -29,7 +29,7 @@ import mycompiler.mytypereconstruction.typeassumptionkey.CTypeAssumptionKey;
// ino.class.CTypeReconstructionResult.27238.description type=javadoc
/**
* Diese Container-Klasse kapselt alle Ergebniswerte f<EFBFBD>r eine m<EFBFBD>gliche
* Typkombination aller Klassen und deren Methoden sowie lokalen Variablen. Eine
* Typkombination einer Klasse und deren Methoden sowie lokalen Variablen. Eine
* Instanz dieser Klasse steht f<EFBFBD>r genau eine m<EFBFBD>gliche Typkombination.<br/>
* Objekte dieser Klasse werden vom Typrekonstruktionsalgorithmus <EFBFBD>ber die
* Compiler-API zur<EFBFBD>ckgegeben.

View File

@ -17,10 +17,10 @@ public class FunNMethod extends Method{
ParameterList pl = new ParameterList();
Vector<FormalParameter> fpList = new Vector<FormalParameter>();
for(int i = 0;i<N;i++){
FormalParameter parameter = new FormalParameter();
parameter.setType(TypePlaceholder.fresh(parameter));
DeclId paramName = new DeclId("T"+i);
parameter.set_DeclId(paramName);
FormalParameter parameter = new FormalParameter(paramName);
parameter.setType(TypePlaceholder.fresh(parameter));
//parameter.set_DeclId(paramName);
fpList.add(parameter);
}
pl.formalparameter = fpList;

View File

@ -59,8 +59,8 @@ public class OderConstraint{
@Override
public String toString(){
String ret = "[";
for(Pair p : this.getConstraintPairs()){
ret += p.toString()+ ", ";
for(UndConstraint p : this.getUndConstraints()){
ret += p.toString()+ "| ";
}
return ret+"]";
}

View File

@ -2,6 +2,7 @@ package typinferenz;
import java.util.Vector;
import typinferenz.exceptions.TypinferenzException;
import mycompiler.mytype.Pair;
import mycompiler.mytype.RefType;
import mycompiler.mytype.Type;

View File

@ -51,4 +51,23 @@ public class TypeInsertPoint {
String ret = type.printJavaCode(this.resultSet).toString()+" ";
return ret;
}
/**
* @return - Der Punkt (Knoten) im Syntaxbaum, für den dieser TypeInsertPoint gilt.
*/
public TypeInsertable getInsertNode(){
return this.point;
}
@Override
public boolean equals(Object obj){
if(! (obj instanceof TypeInsertPoint))return false;
TypeInsertPoint equals = (TypeInsertPoint) obj;
if(!(equals.point.equals(this.point)))return false;
if(!(equals.tph.equals(this.tph)))return false;
if(!(equals.resultSet.equals(this.resultSet)))return false;
if(!(equals.type.equals(this.type)))return false;
return true;
}
}

View File

@ -2,6 +2,8 @@ package typinferenz;
import java.util.Vector;
import mycompiler.SyntaxTreeNode;
/**
* Bündelt ein Set von TypeInsertPoints, die alle zu einem TypePlaceholder gehören.
* Diese müssen gemeinsam eingesetzt werden.
@ -38,4 +40,30 @@ public class TypeInsertSet {
return ret;
}
/**
*
* @param node
* @return - null, falls kein InsertPoint für node vorhanden.
*/
public TypeInsertPoint getInsertPointFor(TypeInsertable node){
for(TypeInsertPoint point : points){
if(point.getInsertNode().equals(node))return point;
}
return null;
}
@Override
public boolean equals(Object obj){
if(! (obj instanceof TypeInsertSet))return false;
TypeInsertSet equals = (TypeInsertSet) obj;
for(TypeInsertPoint point : points){
//Jeder TypeInsertPoint muss auch in equals vorkommen:
if(!equals.points.contains(point))return false;
//... aber nicht öfter als 1x :
if(equals.points.lastIndexOf(point)!=equals.points.indexOf(point))return false;
}
return true;
}
}

View File

@ -27,9 +27,15 @@ public class UndConstraint extends OderConstraint {
return ret;
}
@Override
public String toString(){
String ret = super.toString();
return ret.replace(',', '|');
//String ret = super.toString();
//return ret.replace('|', ',');
String ret = "[";
for(Pair p : this.getConstraintPairs()){
ret += p.toString()+ ", ";
}
return ret+"]";
}
}

View File

@ -0,0 +1,14 @@
package typinferenz.assumptions;
import mycompiler.myclass.Class;
import mycompiler.myclass.Field;
import mycompiler.myclass.Method;
public class ConstructorAssumption extends MethodAssumption{
public ConstructorAssumption(Method assumedMethod, Class parentClass) {
super(assumedMethod, parentClass);
}
}

View File

@ -5,7 +5,7 @@ import java.util.Vector;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.FunN;
import typinferenz.TypinferenzException;
import typinferenz.exceptions.TypinferenzException;
import mycompiler.mytype.GenericTypeVar;
import mycompiler.mytype.RefType;
import mycompiler.mytype.Type;
@ -155,6 +155,7 @@ public class CopyOfTypeAssumptions implements Iterable<CTypeAssumption> {
}
//TODO: Dann die lokalen Variablen
// ... (noch nicht implementiert)
//und zuletzt die Felder der Klasse in dessen Namensraum sich dieses AssumptionSet befindet.
for(CTypeAssumption ass : this.getInstVarAssumptions()){
if(ass.getIdentifier().equals(variableName))return ass.getAssumedType();

View File

@ -14,6 +14,6 @@ public class LocalVarAssumption extends Assumption {
@Override
public Type getAssumedType() {
return this.localVar.getDeclType();
return this.localVar.getType();
}
}

View File

@ -43,4 +43,16 @@ public class MethodAssumption extends FieldAssumption {
return "MethodAssumption: "+this.method.toString();
}
@Override
public boolean equals(Object obj){
if(!(obj instanceof MethodAssumption))return false;
MethodAssumption equals = (MethodAssumption)obj;
if(equals.method==null)return false;
if(equals.parentClass==null)return false;
if(!(equals.method.equals(this.method)))return false;
if(!(equals.parentClass.equals(this.parentClass)))return false;
return true;
}
}

View File

@ -1,14 +1,16 @@
package typinferenz.assumptions;
import java.util.Iterator;
import mycompiler.myclass.Class;
import java.util.Vector;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.FunN;
import typinferenz.FunNInterface;
import typinferenz.FunNMethod;
import typinferenz.TypinferenzException;
import typinferenz.exceptions.TypinferenzException;
import mycompiler.mytype.GenericTypeVar;
import mycompiler.mytype.RefType;
import mycompiler.mytype.Type;
@ -46,6 +48,7 @@ public class TypeAssumptions {
private Vector<MethodAssumption> methodAssumptions = new Vector<MethodAssumption>();
private Vector<ConstructorAssumption> constructorAssumptions = new Vector<ConstructorAssumption>();
private Vector<FieldAssumption> fieldAssumptions = new Vector<FieldAssumption>();
private Vector<LocalVarAssumption> localVarAssumptions = new Vector<LocalVarAssumption>();
private Vector<ParameterAssumption> parameterAssumptions = new Vector<ParameterAssumption>();
@ -65,9 +68,14 @@ public class TypeAssumptions {
}
public void addMethodAssumption(MethodAssumption mAss){
this.methodAssumptions.add(mAss);
if(!this.methodAssumptions.contains(mAss))this.methodAssumptions.add(mAss);
}
public void addConstructorAssumption(
ConstructorAssumption constructorAssumption) {
this.constructorAssumptions.add(constructorAssumption);
}
public void addFieldAssumption(FieldAssumption ass){
this.fieldAssumptions.add(ass);
}
@ -85,12 +93,14 @@ public class TypeAssumptions {
* @param withName
* @return
*/
public Vector<FieldAssumption> getFieldVars(String withName){
@Deprecated
public Vector<FieldAssumption> getFieldVars2(String withName){
//TODO: Implementieren
return null;
return new Vector<FieldAssumption>();
}
public Type getTypeOfFieldVar(String withName, Class inClass){
@Deprecated
public Type getTypeOfFieldVar2(String withName, Class inClass){
//TODO: Implementieren
return null;
}
@ -99,8 +109,10 @@ public class TypeAssumptions {
* @param withName
* @return
*/
public Vector<MethodAssumption> getMethods(String withName){
return null;
@Deprecated
public Vector<MethodAssumption> getMethods2(String withName){
//TODO: Implementieren
return new Vector<MethodAssumption>();
}
/**
@ -108,7 +120,9 @@ public class TypeAssumptions {
* @param withName
* @return
*/
public Type getTypeOfLocalVar(String withName){
@Deprecated
public Type getTypeOfLocalVar2(String withName){
//TODO: Implementieren
return null;
}
@ -243,9 +257,13 @@ public class TypeAssumptions {
return ret;
}
public Type getThisValue() {
@Deprecated
public Type getThisValue2() {
if(thisClassName == null)throw new TypinferenzException("Kein Wert für this vorhanden, in diesem Kontext");
return new RefType(thisClassName, 0);
}
}

View File

@ -0,0 +1,16 @@
package typinferenz.exceptions;
import mycompiler.myparser.JavaParser.yyException;
public class ParserException extends TypinferenzException {
public ParserException(String message) {
super(message);
}
public ParserException(yyException exc){
super("Parserfehler");
}
}

View File

@ -1,4 +1,4 @@
package typinferenz;
package typinferenz.exceptions;
/**
* Eine RuntimeException, welche bei einem Fehler während des Typinferenzalgorithmus ausgelöst wird.

View File

@ -8,7 +8,8 @@ import java.util.Vector;
import mycompiler.MyCompiler;
import mycompiler.MyCompilerAPI;
import mycompiler.mytypereconstruction.TypeinferenceResultSet;
import typinferenz.TypinferenzException;
import typinferenz.exceptions.TypinferenzException;
import java.util.*;
import org.apache.log4j.Logger;

View File

@ -2,7 +2,7 @@ class OverloadingTest{
var;
public Object clone(){
public clone(){
return this;
}
@ -14,7 +14,7 @@ class OverloadingTest{
class OverloadingTest2{
public Object clone(){
public clone(){
return this;
}

View File

@ -1,7 +1,7 @@
Class DEBUG [Typeinference] Erstellte Assumptions: this: MatrixMethod Assumptions:
[MethodAssumption: Matrix null { []]
[]
FieldVar Assumptions:
[typinferenz.assumptions.FieldAssumption@fefb1c0]
[typinferenz.assumptions.FieldAssumption@4e64fca0, typinferenz.assumptions.FieldAssumption@48059495, typinferenz.assumptions.FieldAssumption@4e64fca0, typinferenz.assumptions.FieldAssumption@48059495]
LocalVar Assumptions:
[]
Parameter Assumptions:
@ -9,26 +9,26 @@ Parameter Assumptions:
Block DEBUG [Typeinference] Prozessing statement: null Return null (( [ f, ]) -> null { [null Return null (f.apply( [ null (this(null)), m, ]))])
Block DEBUG [Typeinference] Prozessing statement: null Return null (f.apply( [ null (this(null)), m, ]))
Block DEBUG [Typeinference] Prozessing statement: TPH CJ Return TPH CF (f: TPH CD.apply( [ Matrix (this(null)), m: TPH CB, ]))
Block DEBUG [Typeinference] Prozessing statement: TPH CK Return TPH CE (( [ TPH CD f, ]) -> TPH CJ { [TPH CJ Return TPH CF (f: TPH CD.apply( [ Matrix (this(null)), m: TPH CB, ]))])
Class DEBUG [Typeinference] Erstellte Constraints: TPH BZ < TPH BZ
[(TPH CG <. TPH CF), (Matrix <. TPH CH), (TPH CB <. TPH CI), (TPH CD <. FunN), ]
TPH CF < TPH CJ
Fun1< TPH CJ, TPH CD > < TPH CE
TPH CE < TPH CK
Fun1< TPH CK, TPH CB > < TPH CC
TPH CC < TPH BZ
Block DEBUG [Typeinference] Prozessing statement: TPH BW Return TPH BS (f: TPH BQ.apply( [ Matrix (this(null)), m: TPH BO, ]))
Block DEBUG [Typeinference] Prozessing statement: TPH BX Return TPH BR (( [ TPH BQ f, ]) -> TPH BW { [TPH BW Return TPH BS (f: TPH BQ.apply( [ Matrix (this(null)), m: TPH BO, ]))])
Class DEBUG [Typeinference] Erstellte Constraints: TPH BM < TPH BM
[[(TPH BT <. TPH BS), (Matrix <. TPH BU), (TPH BO <. TPH BV), (TPH BQ <. FunN), ]| ]
TPH BS < TPH BW
Fun1< TPH BW, TPH BQ > < TPH BR
TPH BR < TPH BX
Fun1< TPH BX, TPH BO > < TPH BP
TPH BP < TPH BM
SourceFile DEBUG [Typeinference] Karthesisches Produkt der Constraints: [[(TPH BZ <. TPH BZ), (TPH CG <. TPH CF), (Matrix <. TPH CH), (TPH CB <. TPH CI), (TPH CD <. FunN), (TPH CF <. TPH CJ), (Fun1< TPH CJ, TPH CD > <. TPH CE), (TPH CE <. TPH CK), (Fun1< TPH CK, TPH CB > <. TPH CC), (TPH CC <. TPH BZ)]]
SourceFile DEBUG [Typeinference] Unifiziertes Ergebnis: [[(TPH CG <. TPH CF), (TPH CB <. TPH CI), (TPH CF <. TPH CJ), (TPH CK = Fun1< TPH CJ, FunN >), (TPH BZ = Fun1< Fun1< TPH CJ, FunN >, TPH CB >), (TPH CH = Matrix), (TPH CD = FunN), (TPH CE = Fun1< TPH CJ, FunN >), (TPH CC = Fun1< Fun1< TPH CJ, FunN >, TPH CB >)], [(TPH CG <. TPH CF), (TPH CB <. TPH CI), (TPH CF <. TPH CJ), (TPH CK = Fun1< TPH CJ, FunN >), (TPH BZ = Fun1< Fun1< TPH CJ, FunN >, TPH CB >), (TPH CH = Vector< Vector< GTV Integer > >), (TPH CD = FunN), (TPH CE = Fun1< TPH CJ, FunN >), (TPH CC = Fun1< Fun1< TPH CJ, FunN >, TPH CB >)], [(TPH CG <. TPH CF), (TPH CB <. TPH CI), (TPH CF <. TPH CJ), (TPH CK = Fun1< TPH CJ, FunN >), (TPH BZ = Fun1< Fun1< TPH CJ, FunN >, TPH CB >), (TPH CH = Vector< ? extends Vector< GTV Integer > >), (TPH CD = FunN), (TPH CE = Fun1< TPH CJ, FunN >), (TPH CC = Fun1< Fun1< TPH CJ, FunN >, TPH CB >)], [(TPH CG <. TPH CF), (TPH CB <. TPH CI), (TPH CF <. TPH CJ), (TPH CK = Fun1< TPH CJ, FunN >), (TPH BZ = Fun1< Fun1< TPH CJ, FunN >, TPH CB >), (TPH CH = Vector< ? extends Vector< ? extends GTV Integer > >), (TPH CD = FunN), (TPH CE = Fun1< TPH CJ, FunN >), (TPH CC = Fun1< Fun1< TPH CJ, FunN >, TPH CB >)], [(TPH CG <. TPH CF), (TPH CB <. TPH CI), (TPH CF <. TPH CJ), (TPH CK = Fun1< TPH CJ, FunN >), (TPH BZ = Fun1< Fun1< TPH CJ, FunN >, TPH CB >), (TPH CH = Vector< ? extends Vector< ? super GTV Integer > >), (TPH CD = FunN), (TPH CE = Fun1< TPH CJ, FunN >), (TPH CC = Fun1< Fun1< TPH CJ, FunN >, TPH CB >)], [(TPH CG <. TPH CF), (TPH CB <. TPH CI), (TPH CF <. TPH CJ), (TPH CK = Fun1< TPH CJ, FunN >), (TPH BZ = Fun1< Fun1< TPH CJ, FunN >, TPH CB >), (TPH CH = Vector< ? super Vector< GTV Integer > >), (TPH CD = FunN), (TPH CE = Fun1< TPH CJ, FunN >), (TPH CC = Fun1< Fun1< TPH CJ, FunN >, TPH CB >)], [(TPH CG <. TPH CF), (TPH CB <. TPH CI), (TPH CF <. TPH CJ), (TPH CK = Fun1< TPH CJ, FunN >), (TPH BZ = Fun1< Fun1< TPH CJ, FunN >, TPH CB >), (TPH CH = Vector< ? super Matrix >), (TPH CD = FunN), (TPH CE = Fun1< TPH CJ, FunN >), (TPH CC = Fun1< Fun1< TPH CJ, FunN >, TPH CB >)]]
SourceFile DEBUG [Typeinference] Karthesisches Produkt der Constraints: [[(TPH BM <. TPH BM), (TPH BT <. TPH BS), (Matrix <. TPH BU), (TPH BO <. TPH BV), (TPH BQ <. FunN), (TPH BS <. TPH BW), (Fun1< TPH BW, TPH BQ > <. TPH BR), (TPH BR <. TPH BX), (Fun1< TPH BX, TPH BO > <. TPH BP), (TPH BP <. TPH BM)]]
SourceFile DEBUG [Typeinference] Unifiziertes Ergebnis: [[(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Matrix), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)], [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< Vector< GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)], [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? extends Vector< GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)], [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? extends Vector< ? extends GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)], [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? extends Vector< ? super GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)], [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? super Vector< GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)], [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? super Matrix >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)]]
SourceFile DEBUG [Typeinference]
JavaFiles:
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH CG <. TPH CF), (TPH CB <. TPH CI), (TPH CF <. TPH CJ), (TPH CK = Fun1< TPH CJ, FunN >), (TPH BZ = Fun1< Fun1< TPH CJ, FunN >, TPH CB >), (TPH CH = Matrix), (TPH CD = FunN), (TPH CE = Fun1< TPH CJ, FunN >), (TPH CC = Fun1< Fun1< TPH CJ, FunN >, TPH CB >)]
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Matrix), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)]
SourceFile DEBUG [Typeinference] class <CJ, CB>Matrix extends Vector<Vector<Integer>>
SourceFile DEBUG [Typeinference] class <BW, BO>Matrix extends Vector<Vector<Integer>>
{
Fun1<Fun1<CJ, FunN>, CB> op = (CB m) -> {
Fun1<Fun1<BW, FunN>, BO> op = (BO m) -> {
return (FunN f) -> {
return f.apply(this, m);;
};
@ -38,11 +38,11 @@ Matrix Matrix()
}
}
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH CG <. TPH CF), (TPH CB <. TPH CI), (TPH CF <. TPH CJ), (TPH CK = Fun1< TPH CJ, FunN >), (TPH BZ = Fun1< Fun1< TPH CJ, FunN >, TPH CB >), (TPH CH = Vector< Vector< GTV Integer > >), (TPH CD = FunN), (TPH CE = Fun1< TPH CJ, FunN >), (TPH CC = Fun1< Fun1< TPH CJ, FunN >, TPH CB >)]
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< Vector< GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)]
SourceFile DEBUG [Typeinference] class <CJ, CB>Matrix extends Vector<Vector<Integer>>
SourceFile DEBUG [Typeinference] class <BW, BO>Matrix extends Vector<Vector<Integer>>
{
Fun1<Fun1<CJ, FunN>, CB> op = (CB m) -> {
Fun1<Fun1<BW, FunN>, BO> op = (BO m) -> {
return (FunN f) -> {
return f.apply(this, m);;
};
@ -52,11 +52,11 @@ Matrix Matrix()
}
}
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH CG <. TPH CF), (TPH CB <. TPH CI), (TPH CF <. TPH CJ), (TPH CK = Fun1< TPH CJ, FunN >), (TPH BZ = Fun1< Fun1< TPH CJ, FunN >, TPH CB >), (TPH CH = Vector< ? extends Vector< GTV Integer > >), (TPH CD = FunN), (TPH CE = Fun1< TPH CJ, FunN >), (TPH CC = Fun1< Fun1< TPH CJ, FunN >, TPH CB >)]
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? extends Vector< GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)]
SourceFile DEBUG [Typeinference] class <CJ, CB>Matrix extends Vector<Vector<Integer>>
SourceFile DEBUG [Typeinference] class <BW, BO>Matrix extends Vector<Vector<Integer>>
{
Fun1<Fun1<CJ, FunN>, CB> op = (CB m) -> {
Fun1<Fun1<BW, FunN>, BO> op = (BO m) -> {
return (FunN f) -> {
return f.apply(this, m);;
};
@ -66,11 +66,11 @@ Matrix Matrix()
}
}
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH CG <. TPH CF), (TPH CB <. TPH CI), (TPH CF <. TPH CJ), (TPH CK = Fun1< TPH CJ, FunN >), (TPH BZ = Fun1< Fun1< TPH CJ, FunN >, TPH CB >), (TPH CH = Vector< ? extends Vector< ? extends GTV Integer > >), (TPH CD = FunN), (TPH CE = Fun1< TPH CJ, FunN >), (TPH CC = Fun1< Fun1< TPH CJ, FunN >, TPH CB >)]
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? extends Vector< ? extends GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)]
SourceFile DEBUG [Typeinference] class <CJ, CB>Matrix extends Vector<Vector<Integer>>
SourceFile DEBUG [Typeinference] class <BW, BO>Matrix extends Vector<Vector<Integer>>
{
Fun1<Fun1<CJ, FunN>, CB> op = (CB m) -> {
Fun1<Fun1<BW, FunN>, BO> op = (BO m) -> {
return (FunN f) -> {
return f.apply(this, m);;
};
@ -80,11 +80,11 @@ Matrix Matrix()
}
}
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH CG <. TPH CF), (TPH CB <. TPH CI), (TPH CF <. TPH CJ), (TPH CK = Fun1< TPH CJ, FunN >), (TPH BZ = Fun1< Fun1< TPH CJ, FunN >, TPH CB >), (TPH CH = Vector< ? extends Vector< ? super GTV Integer > >), (TPH CD = FunN), (TPH CE = Fun1< TPH CJ, FunN >), (TPH CC = Fun1< Fun1< TPH CJ, FunN >, TPH CB >)]
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? extends Vector< ? super GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)]
SourceFile DEBUG [Typeinference] class <CJ, CB>Matrix extends Vector<Vector<Integer>>
SourceFile DEBUG [Typeinference] class <BW, BO>Matrix extends Vector<Vector<Integer>>
{
Fun1<Fun1<CJ, FunN>, CB> op = (CB m) -> {
Fun1<Fun1<BW, FunN>, BO> op = (BO m) -> {
return (FunN f) -> {
return f.apply(this, m);;
};
@ -94,11 +94,11 @@ Matrix Matrix()
}
}
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH CG <. TPH CF), (TPH CB <. TPH CI), (TPH CF <. TPH CJ), (TPH CK = Fun1< TPH CJ, FunN >), (TPH BZ = Fun1< Fun1< TPH CJ, FunN >, TPH CB >), (TPH CH = Vector< ? super Vector< GTV Integer > >), (TPH CD = FunN), (TPH CE = Fun1< TPH CJ, FunN >), (TPH CC = Fun1< Fun1< TPH CJ, FunN >, TPH CB >)]
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? super Vector< GTV Integer > >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)]
SourceFile DEBUG [Typeinference] class <CJ, CB>Matrix extends Vector<Vector<Integer>>
SourceFile DEBUG [Typeinference] class <BW, BO>Matrix extends Vector<Vector<Integer>>
{
Fun1<Fun1<CJ, FunN>, CB> op = (CB m) -> {
Fun1<Fun1<BW, FunN>, BO> op = (BO m) -> {
return (FunN f) -> {
return f.apply(this, m);;
};
@ -108,11 +108,11 @@ Matrix Matrix()
}
}
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH CG <. TPH CF), (TPH CB <. TPH CI), (TPH CF <. TPH CJ), (TPH CK = Fun1< TPH CJ, FunN >), (TPH BZ = Fun1< Fun1< TPH CJ, FunN >, TPH CB >), (TPH CH = Vector< ? super Matrix >), (TPH CD = FunN), (TPH CE = Fun1< TPH CJ, FunN >), (TPH CC = Fun1< Fun1< TPH CJ, FunN >, TPH CB >)]
SourceFile DEBUG [Typeinference] JavaFile für ResultSet Unified Constraints: [(TPH BT <. TPH BS), (TPH BO <. TPH BV), (TPH BS <. TPH BW), (TPH BX = Fun1< TPH BW, FunN >), (TPH BM = Fun1< Fun1< TPH BW, FunN >, TPH BO >), (TPH BU = Vector< ? super Matrix >), (TPH BQ = FunN), (TPH BR = Fun1< TPH BW, FunN >), (TPH BP = Fun1< Fun1< TPH BW, FunN >, TPH BO >)]
SourceFile DEBUG [Typeinference] class <CJ, CB>Matrix extends Vector<Vector<Integer>>
SourceFile DEBUG [Typeinference] class <BW, BO>Matrix extends Vector<Vector<Integer>>
{
Fun1<Fun1<CJ, FunN>, CB> op = (CB m) -> {
Fun1<Fun1<BW, FunN>, BO> op = (BO m) -> {
return (FunN f) -> {
return f.apply(this, m);;
};

View File

@ -7,9 +7,6 @@ import mycompiler.mytypereconstruction.typeassumption.CLocalVarTypeAssumption;
import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption;
/*TODO:
*/
public class TestAbstractInferenceTest extends AbstractInferenceTestOLD_2 {
private final static String TESTEDCLASSNAME="TestAbstractInferenceTest";

View File

@ -0,0 +1,3 @@
class FieldInitializationTest{
String var = "hallo";
}

View File

@ -0,0 +1,43 @@
package parser;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Vector;
import junit.framework.TestCase;
import mycompiler.MyCompiler;
import mycompiler.MyCompilerAPI;
import org.junit.Test;
/**
* Dieser Test prüft nur, ob .java-Dateien fehlerfrei geparst werden.
* Der dabei erstellte Syntaxbaum wird nicht kontrolliert.
* @author janulrich
*
*/
public class GeneralParserTest{
private static final String rootDirectory = System.getProperty("user.dir")+"/test/parser/";
@Test
public void run(){
Vector<String> filenames = new Vector<String>();
filenames.add("FieldInitializationTest.jav");
MyCompilerAPI compiler = MyCompiler.getAPI();
try{
for(String filename : filenames)
compiler.parse(new File(rootDirectory + filename));
}catch(Exception exc){
exc.printStackTrace();
fail();
}
assertTrue("Tests durchlaufen",filenames.size()>0);
}
}

View File

@ -0,0 +1,12 @@
class FunNInsertTest{
Object1 var1;
Object2 var2;
Object3 var3;
op = (a) -> (b) -> (c) -> {
var1 = a;
var2 = b;
var3 = c;
};
}

View File

@ -0,0 +1,18 @@
package plugindevelopment;
import java.util.Vector;
import org.junit.Test;
public class FunNInsertTest {
private static final String TEST_FILE = "FunNInsertTest.jav";
@Test
public void run(){
Vector<String> mustContain = new Vector<String>();
mustContain.add("Fun1<Fun1<Fun1<void, Object3>, Object2>, Object1> op");
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
}
}

View File

@ -0,0 +1,46 @@
package plugindevelopment;
import java.io.File;
import java.io.IOException;
import java.util.Vector;
import junit.framework.TestCase;
import mycompiler.MyCompiler;
import mycompiler.MyCompilerAPI;
import mycompiler.myparser.JavaParser.yyException;
import mycompiler.mytypereconstruction.TypeinferenceResultSet;
import typinferenz.TypeInsertSet;
public class MultipleTypesInsertTester {
public static void test(String sourceFileToInfere, Vector<String> mustContain){
String gesamterSrc = "";
String inferedSource = "";
MyCompilerAPI compiler = MyCompiler.getAPI();
try {
compiler.parse(new File(TypeInsertTester.rootDirectory + sourceFileToInfere));
Vector<TypeinferenceResultSet> results = compiler.typeReconstruction();
//TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1);
for(TypeinferenceResultSet result : results){
Vector<TypeInsertSet> points = result.getTypeInsertionPoints();
//TestCase.assertTrue("Es muss mindestens ein TypeInsertSet vorhanden sein", points.size()>0);
for(TypeInsertSet point : points){
//TestCase.assertTrue("Es muss mindestens ein TypeInsertPoint vorhanden sein", point.points.size()>0);
if(point.points.size()>0){
inferedSource = point.insertAllTypes(TypeInsertTester.getFileContent(TypeInsertTester.rootDirectory + sourceFileToInfere));
System.out.println(inferedSource);
gesamterSrc += inferedSource;
}
}
}
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
for(String containString : mustContain){
TestCase.assertTrue("\""+containString+"\" muss in den inferierten Lösungen vorkommen",gesamterSrc.contains(containString));
}
}
}

View File

@ -0,0 +1,20 @@
class OverloadingInsertTest{
var;
overload(){
return this;
}
}
class Overloading2{
var2;
methode(){
return var2.overload();
}
overload(){
return this;
}
}

View File

@ -0,0 +1,33 @@
package plugindevelopment;
import java.io.File;
import java.io.IOException;
import java.util.Vector;
import junit.framework.TestCase;
import mycompiler.MyCompiler;
import mycompiler.MyCompilerAPI;
import mycompiler.myparser.JavaParser.yyException;
import mycompiler.mytypereconstruction.TypeinferenceResultSet;
import org.junit.Test;
import typinferenz.TypeInsertSet;
public class OverloadingInsertTest {
private static final String TEST_FILE = "OverloadingInsertTest.jav";
@Test
public void run(){
Vector<String> mustContain = new Vector<String>();
mustContain.add("Overloading2 methode");
mustContain.add("Overloading2 overload");
mustContain.add("Overloading2 var2");
mustContain.add("OverloadingInsertTest methode");
mustContain.add("OverloadingInsertTest overload");
mustContain.add("OverloadingInsertTest var2");
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
}
}

View File

@ -39,7 +39,7 @@ public class TypeInsertTester{
inferencelog.addAppender(logAppender); //Bei den Tests wird der Log auch in System.out geschrieben.
}
}
private static final String rootDirectory = System.getProperty("user.dir")+"/test/plugindevelopment/";
static final String rootDirectory = System.getProperty("user.dir")+"/test/plugindevelopment/";
public static void test(String sourceFileToInfere, String solutionFile){
String inferedSource = "";
@ -47,7 +47,7 @@ public class TypeInsertTester{
try {
compiler.parse(new File(rootDirectory + sourceFileToInfere));
Vector<TypeinferenceResultSet> results = compiler.typeReconstruction();
TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben", results.size()==1);
TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1);
for(TypeinferenceResultSet result : results){
Vector<TypeInsertSet> points = result.getTypeInsertionPoints();
TestCase.assertTrue("Es muss mindestens ein TypeInsertSet vorhanden sein", points.size()>0);
@ -68,7 +68,7 @@ public class TypeInsertTester{
}
//Source: https://stackoverflow.com/questions/326390/how-to-create-a-java-string-from-the-contents-of-a-file
private static String getFileContent(String path)throws IOException
static String getFileContent(String path)throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return StandardCharsets.UTF_8.decode(ByteBuffer.wrap(encoded)).toString();

View File

@ -0,0 +1,9 @@
class NodeEqualTest {
String var1;
void methode1(){
var1 = "String";
}
String methode2(String test){
return test;
}
}

View File

@ -0,0 +1,56 @@
package syntaxTree;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import mycompiler.MyCompiler;
import mycompiler.MyCompilerAPI;
import mycompiler.SourceFile;
import mycompiler.SyntaxTreeNode;
import mycompiler.myparser.JavaParser.yyException;
import org.junit.Test;
import junit.framework.TestCase;
public class NodeEqualTest extends TestCase{
private static final String rootDirectory = System.getProperty("user.dir")+"/test/syntaxTree/";
private static final String testFile = "NodeEqualTest.jav";
@Test
public void test(){
MyCompilerAPI compiler = MyCompiler.getAPI();
MyCompilerAPI compiler2 = MyCompiler.getAPI();
SourceFile tree = null;
SourceFile tree2 = null;
try {
tree = compiler.parse(new File(rootDirectory + testFile));
tree2 = compiler2.parse(new File(rootDirectory + testFile));
} catch (IOException | yyException e) {
e.printStackTrace();
fail();
}
recursivlyCheckEqual(tree, tree2);
}
private void recursivlyCheckEqual(SyntaxTreeNode node1, SyntaxTreeNode node2){
for(SyntaxTreeNode n1 : node1.getChildren()){
int matches = 0;
for(SyntaxTreeNode n2 : node2.getChildren()){
if(n2.equals(n1)){
System.out.println(n2 + " == "+n1);
matches++;
this.recursivlyCheckEqual(n1, n2);
}else{
System.out.println(n2 + " != "+ n1);
}
}
System.out.println("");
assertTrue("Nur eines der Children darf gleich sein, nicht "+matches, matches == 1 && node2.getChildren().size()>0);
}
}
}

File diff suppressed because it is too large Load Diff