From 49917239c1a996f0862e6d8d7e5d537fd11d514d Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 16 Sep 2014 17:34:04 +0200 Subject: [PATCH 01/16] GenericVarDeclarationList extends SyntaxTreeNode --- src/de/dhbwstuttgart/antlr/VisitorTest.java | 25 ++++++++++ src/de/dhbwstuttgart/syntaxtree/Class.java | 2 +- src/de/dhbwstuttgart/syntaxtree/Field.java | 2 +- .../syntaxtree/GenericDeclarationList.java | 49 ++++++++++++++++++- .../assumptions/TypeAssumptions.java | 3 +- 5 files changed, 76 insertions(+), 5 deletions(-) diff --git a/src/de/dhbwstuttgart/antlr/VisitorTest.java b/src/de/dhbwstuttgart/antlr/VisitorTest.java index e3cf519a..eeaf4478 100644 --- a/src/de/dhbwstuttgart/antlr/VisitorTest.java +++ b/src/de/dhbwstuttgart/antlr/VisitorTest.java @@ -12,9 +12,13 @@ import org.junit.Test; import de.dhbwstuttgart.antlr.Java8Parser.ClassDeclarationContext; import de.dhbwstuttgart.antlr.Java8Parser.CompilationUnitContext; import de.dhbwstuttgart.antlr.Java8Parser.TypeDeclarationContext; +import de.dhbwstuttgart.antlr.Java8Parser.TypeParameterContext; +import de.dhbwstuttgart.antlr.Java8Parser.TypeParametersContext; +import de.dhbwstuttgart.syntaxtree.GenericDeclarationList; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.Class; +import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; public class VisitorTest { @@ -62,7 +66,28 @@ class EvalVisitor extends Java8BaseVisitor { public Class visitClassDeclaration(ClassDeclarationContext ctx) { String name = ctx.Identifier().getText(); int offset = ctx.Identifier().getSymbol().getStartIndex(); + TypeParametersContext tpctx = ctx.typeParameters(); + GenericDeclarationList gtvList = (GenericDeclarationList) visit(tpctx); + return new Class(name, offset); } + @Override + public GenericDeclarationList visitTypeParameters(TypeParametersContext ctx) { + Vector list = new Vector<>(); + int endOffset = 0; + for(TypeParameterContext tpctx : ctx.typeParameter()){ + tpctx.Identifier(); + } + GenericDeclarationList ret = new GenericDeclarationList(list, endOffset); + return ret; + } + + @Override + public GenericTypeVar visitTypeParameter(TypeParameterContext ctx) { + GenericTypeVar ret = new GenericTypeVar(name, parent, offset); + return ret; + } + + } diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index 10b46807..7becd842 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -1184,7 +1184,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit @Override public Vector getGenericParameter() { if(this.genericClassParameters == null)return new Vector(); - return this.genericClassParameters; + return this.genericClassParameters.getVector(); } @Override diff --git a/src/de/dhbwstuttgart/syntaxtree/Field.java b/src/de/dhbwstuttgart/syntaxtree/Field.java index 51766f7a..2ba3ce6b 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Field.java +++ b/src/de/dhbwstuttgart/syntaxtree/Field.java @@ -57,7 +57,7 @@ public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Ty public Vector getGenericParameter() { Vector ret = new Vector<>(); if(this.genericParameters == null)return ret; - ret.addAll(this.genericParameters); + ret.addAll(this.genericParameters.getVector()); return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java b/src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java index 115e60e3..9a722981 100644 --- a/src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java +++ b/src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java @@ -1,5 +1,9 @@ package de.dhbwstuttgart.syntaxtree; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; import java.util.Vector; import de.dhbwstuttgart.parser.GenericVarDeclarationList; @@ -12,16 +16,57 @@ import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; * @author janulrich * */ -public class GenericDeclarationList extends Vector{ +public class GenericDeclarationList extends SyntaxTreeNode implements Iterable{ private int offsetOfLastElement; - + private Vector gtvs = new Vector<>(); + public GenericDeclarationList(Vector values, int endOffset) { this.addAll(values); this.offsetOfLastElement = endOffset; } + private void addAll(Vector values) { + this.gtvs.addAll(values); + } + public int getEndOffset(){ return offsetOfLastElement; } + + @Override + public int getOffset() { + return getEndOffset(); + } + + @Override + public int getVariableLength() { + return 0; + } + + @Override + public Iterator iterator() { + return this.gtvs.iterator(); + } + + @Override + public Vector getChildren() { + Vector ret = new Vector<>(); + for(GenericTypeVar gtv : gtvs){ + ret.add(gtv); + } + return ret; + } + + public int size() { + return gtvs.size(); + } + + public Vector getVector() { + return this.gtvs; + } + + public void add(GenericTypeVar t) { + this.gtvs.add(t); + } } diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java index befd8000..22759260 100755 --- a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java @@ -316,7 +316,8 @@ public class TypeAssumptions { return new ConstraintType(ass.getAssumedType()); } } - //return null; + //Spezialfälle bei char, int, boolean, .... + //TODO throw new TypeinferenceException("Der Typ "+t.getName()+" ist nicht korrekt",inNode); } From 7abb1f8ad65d7654611210f6c759a3fe2d818437 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 16 Sep 2014 17:34:26 +0200 Subject: [PATCH 02/16] =?UTF-8?q?Antlr=20Test=20angef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/parser/AntlrTest.jav | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/parser/AntlrTest.jav diff --git a/test/parser/AntlrTest.jav b/test/parser/AntlrTest.jav new file mode 100644 index 00000000..43c1c252 --- /dev/null +++ b/test/parser/AntlrTest.jav @@ -0,0 +1 @@ +class Test{} \ No newline at end of file From d636d29ab59f23adc2a28cc26c8a8d48b8768f9e Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 18 Sep 2014 16:26:02 +0200 Subject: [PATCH 03/16] =?UTF-8?q?Problem=20mit=20der=20Umwandlung=20von=20?= =?UTF-8?q?generischen=20Variablen=20zu=20TPH=20behoben=20(noch=20nicht=20?= =?UTF-8?q?vollst=C3=A4ndig)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/de/dhbwstuttgart/antlr/VisitorTest.java | 2 +- .../dhbwstuttgart/core/AClassOrInterface.java | 8 ++- .../dhbwstuttgart/parser/InterfaceList.java | 8 ++- src/de/dhbwstuttgart/parser/JavaParser.java | 30 +++++----- src/de/dhbwstuttgart/parser/JavaParser.jay | 26 ++++---- src/de/dhbwstuttgart/syntaxtree/Class.java | 59 +++++++++++++++---- .../dhbwstuttgart/syntaxtree/SourceFile.java | 25 ++++---- .../syntaxtree/type/GenericTypeVar.java | 14 +++-- .../syntaxtree/type/RefType.java | 6 +- .../dhbwstuttgart/syntaxtree/type/Type.java | 2 +- .../assumptions/TypeAssumptions.java | 19 +++++- test/parser/AntlrTest.jav | 7 ++- test/parser/FieldVarTest.jav | 3 + test/parser/GeneralParserTest.java | 1 + .../TypeInsertTests/GenericTypeVarTest.jav | 2 +- .../TypeInsertTests/GenericTypeVarTest2.jav | 2 +- 16 files changed, 141 insertions(+), 73 deletions(-) create mode 100644 test/parser/FieldVarTest.jav diff --git a/src/de/dhbwstuttgart/antlr/VisitorTest.java b/src/de/dhbwstuttgart/antlr/VisitorTest.java index eeaf4478..2effc93d 100644 --- a/src/de/dhbwstuttgart/antlr/VisitorTest.java +++ b/src/de/dhbwstuttgart/antlr/VisitorTest.java @@ -85,7 +85,7 @@ class EvalVisitor extends Java8BaseVisitor { @Override public GenericTypeVar visitTypeParameter(TypeParameterContext ctx) { - GenericTypeVar ret = new GenericTypeVar(name, parent, offset); + GenericTypeVar ret = null;//new GenericTypeVar(name, parent, offset); return ret; } diff --git a/src/de/dhbwstuttgart/core/AClassOrInterface.java b/src/de/dhbwstuttgart/core/AClassOrInterface.java index 16a6f16f..ab9f8a06 100755 --- a/src/de/dhbwstuttgart/core/AClassOrInterface.java +++ b/src/de/dhbwstuttgart/core/AClassOrInterface.java @@ -15,11 +15,15 @@ import org.apache.log4j.Logger; + + import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.Interface; import de.dhbwstuttgart.syntaxtree.misc.UsedId; 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 /** @@ -37,8 +41,8 @@ public interface AClassOrInterface { public JavaClassName getName(); - public Vector getSuperInterfaces(); - public void setSuperInterfaces(Vector vector); + public Vector getSuperInterfaces(); + public void setSuperInterfaces(Vector vector); /* // ino.attribute.inferencelog.21189.decldescription type=javadoc diff --git a/src/de/dhbwstuttgart/parser/InterfaceList.java b/src/de/dhbwstuttgart/parser/InterfaceList.java index e7438067..a3b8b82d 100755 --- a/src/de/dhbwstuttgart/parser/InterfaceList.java +++ b/src/de/dhbwstuttgart/parser/InterfaceList.java @@ -7,6 +7,8 @@ import java.util.Vector; import de.dhbwstuttgart.syntaxtree.Interface; 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 /** @@ -36,13 +38,13 @@ public class InterfaceList // ino.end // ino.method.getVector.24392.definition - public Vector getVector() + public Vector getTypeVector() // ino.end // ino.method.getVector.24392.body { - Vector ret = new Vector<>(); + Vector ret = new Vector<>(); 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; } diff --git a/src/de/dhbwstuttgart/parser/JavaParser.java b/src/de/dhbwstuttgart/parser/JavaParser.java index 585e4cb8..4968adaf 100644 --- a/src/de/dhbwstuttgart/parser/JavaParser.java +++ b/src/de/dhbwstuttgart/parser/JavaParser.java @@ -281,8 +281,8 @@ public Vector testPair = new Vector(); //t "fielddeclarator : variabledeclarator '=' expression", //t "fielddeclarator : variabledeclarator", //t "genericdeclarationlist : '<' boundedMethodParameters '>'", -//t "fielddeclaration : fielddeclarator ';'", //t "fielddeclaration : type fielddeclarator ';'", +//t "fielddeclaration : fielddeclarator ';'", //t "fielddeclaration : genericdeclarationlist type fielddeclarator ';'", //t "fielddeclaration : variabledeclarators ';'", //t "fielddeclaration : type variabledeclarators ';'", @@ -833,7 +833,7 @@ case 20: /* Vector SuperInterfaces, */ /* Vector 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.initUsedIdsToCheck(); } @@ -841,7 +841,7 @@ case 20: case 21: // 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.initUsedIdsToCheck(); } @@ -849,7 +849,7 @@ case 21: case 22: // 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.initUsedIdsToCheck(); } @@ -857,7 +857,7 @@ case 22: case 23: // 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.initUsedIdsToCheck(); } @@ -865,7 +865,7 @@ case 23: case 24: // 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.initUsedIdsToCheck(); } @@ -873,7 +873,7 @@ case 24: case 25: // 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.initUsedIdsToCheck(); } @@ -881,7 +881,7 @@ case 25: case 26: // 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.initUsedIdsToCheck(); } @@ -889,7 +889,7 @@ case 26: case 27: // 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.initUsedIdsToCheck(); } @@ -1396,13 +1396,13 @@ case 89: case 90: // line 854 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { + ((FieldDeclaration)yyVals[-1+yyTop]).setType(((Type)yyVals[-2+yyTop])); yyVal=((FieldDeclaration)yyVals[-1+yyTop]); } break; 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]); } break; @@ -3209,8 +3209,8 @@ case 289: 3, 2, 3, 2, 3, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 3, 3, 1, 0, 3, 1, 1, 1, - 1, 2, 2, 3, 6, 2, 3, 1, 3, 2, - 3, 4, 2, 3, 4, 2, 2, 3, 3, 4, + 1, 2, 2, 3, 6, 2, 3, 1, 3, 3, + 2, 4, 2, 3, 4, 2, 2, 3, 3, 4, 2, 3, 3, 4, 2, 1, 1, 3, 1, 3, 1, 3, 1, 3, 3, 2, 3, 4, 3, 4, 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, 0, 0, 31, 0, 82, 0, 0, 0, 113, 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, 86, 0, 55, 43, 44, 73, 74, 23, 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, 286, 0, 0, 276, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 198, 0, 0, 0, 229, 230, 219, 0, 0, 0, 98, 144, 167, 216, 0, 0, 231, diff --git a/src/de/dhbwstuttgart/parser/JavaParser.jay b/src/de/dhbwstuttgart/parser/JavaParser.jay index e163827e..23de6cbf 100755 --- a/src/de/dhbwstuttgart/parser/JavaParser.jay +++ b/src/de/dhbwstuttgart/parser/JavaParser.jay @@ -368,50 +368,50 @@ classdeclaration : CLASS classidentifier classbody // Vector SuperInterfaces, // Vector 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.initUsedIdsToCheck(); } | 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.initUsedIdsToCheck(); } | 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.initUsedIdsToCheck(); } | 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.initUsedIdsToCheck(); } ///* auskommentiert von Andreas Stadelmeier A10023 | 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.initUsedIdsToCheck(); } | 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.initUsedIdsToCheck(); } | 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.initUsedIdsToCheck(); } | 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.initUsedIdsToCheck(); } @@ -850,15 +850,15 @@ genericdeclarationlist : '<' boundedMethodParameters '>' } -fielddeclaration : fielddeclarator ';' - { - $$=$1; - } - | type fielddeclarator ';' +fielddeclaration : type fielddeclarator ';' { $2.setType($1); $$=$2; } + | fielddeclarator ';' + { + $$=$1; + } | genericdeclarationlist type fielddeclarator ';' {//angefügt von Andreas Stadelmeier $3.setType($2); diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index 7becd842..a2554592 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -51,7 +51,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit protected Modifiers modifiers; protected String name; - private Vector superif = new Vector(); + private Vector superif = new Vector(); public UsedId getPackageName() { @@ -89,12 +89,13 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit return ret; } - public Vector getSuperInterfaces() + public Vector getSuperInterfaces() { return superif; } - public void setSuperInterfaces(Vector superif) + @Override + public void setSuperInterfaces(Vector superif) { this.superif = superif; } @@ -144,7 +145,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit private Vector fielddecl = new Vector(); private GenericDeclarationList genericClassParameters; private int offset; - private Class superClass; + private Type superClass; // ino.method.Class.23041.definition @@ -158,11 +159,11 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } this.offset = offset; 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 - public Class(String name, Class superClass, int offset){ + public Class(String name, RefType superClass, int offset){ this(name,offset); this.superClass = superClass; } @@ -177,15 +178,44 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } // ino.end - // ino.method.Class.23047.defdescription type=javadoc + public Class(String name, Modifiers mod, ClassBody cb, Vector ct, Vector usedIdsToCheck, + UsedId superclass, Vector superif, Vector paralist, int offset){ + this(name, mod, cb, ct, usedIdToRefType(superclass),usedIdToRefType(superif),paralist,offset); + } + public Class(String name, ClassBody cb, Vector ct, + UsedId superclass, Vector superif, Vector paralist, int offset) { + this(name,null,cb,ct,usedIdToRefType(superclass),superif,paralist,offset); + } + public Class(String name2, Modifiers modifiers2, ClassBody classBody, + Vector containedTypes2, UsedId usedId, + Vector typeVector, Vector paraVector, int offset2) { + this(name2, modifiers2, classBody, containedTypes2, usedIdToRefType(usedId),typeVector, paraVector, offset2); + } + public Class(String name2, Modifiers object, ClassBody classBody, + Vector containedTypes2, Vector typeVector, + Vector paraVector, int offset2) { + this(name2, object, classBody, containedTypes2,(Type)null, typeVector, paraVector, offset2); + } + private static Vector usedIdToRefType(Vector superif2) { + Vector 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. * Zur Uebersichtlichkeit in der Grammatik. */ // ino.end // ino.method.Class.23047.definition - public Class(String name, Modifiers mod, ClassBody cb, Vector ct, Vector usedIdsToCheck, - UsedId superclass, Vector superif, Vector paralist, int offset) + public Class(String name, Modifiers mod, ClassBody cb, Vector ct, + Type superclass, Vector vector, Vector paralist, int offset) // ino.end // ino.method.Class.23047.body { @@ -194,9 +224,9 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit if (cb != null) set_ClassBody(cb); if (ct != null) setContainedTypes(ct); 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){ this.set_ParaList(paralist); } @@ -214,7 +244,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } // ino.end - + public Vector getFields() { return fielddecl; @@ -1097,6 +1127,9 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit for(Field f : this.getFields()){ if(f.isPublic())ret.add(f.createTypeAssumptions(this)); } + for(GenericTypeVar gtv : this.getGenericParameter()){ + ret.add(gtv.createAssumptions()); + } return ret; } @@ -1225,7 +1258,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit * Die Super Klasse dieser Klasse. * @return null für Klasse Object */ - public Class getSuperClass(){ + public Type getSuperClass(){ return this.superClass; } } diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 4c7046f9..51387bd8 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -252,7 +252,7 @@ public class SourceFile */ // ino.end // 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.method.createPairFromClassAndSuperclass.21400.body { @@ -269,10 +269,12 @@ public class SourceFile 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 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 // ########################################################### Hashtable substHash = new Hashtable(); //fuer jedes Paar komplett neue Variablen @@ -305,7 +307,8 @@ public class SourceFile // Menge FC bilden Vector vFC = new Vector(); // Menge FC - + TypeAssumptions globalAssumptions = this.makeBasicAssumptionsFromJRE(imports); + globalAssumptions.add(this.getPublicFieldAssumptions()); // 1. Menge <= in FC aufnehmen --> Iteration ueber alle Klassen for( int i = 0; i < KlassenVektor.size(); i++ ) @@ -314,14 +317,14 @@ public class SourceFile inferencelog.debug("Verarbeite "+tempKlasse.getName()); //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 - 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 ); } if(tempKlasse.getSuperInterfaces()!=null){ - Iterator interfaceIterator=tempKlasse.getSuperInterfaces().iterator(); + Iterator interfaceIterator=tempKlasse.getSuperInterfaces().iterator(); while(interfaceIterator.hasNext()){ - Interface intf=interfaceIterator.next(); - Pair P=createPairFromClassAndSuperclass(tempKlasse,intf,tempKlasse.get_ParaList(),intf.get_ParaList()); + RefType intf=(RefType) interfaceIterator.next(); + Pair P=createPairFromClassAndSuperclass(tempKlasse,intf,tempKlasse.get_ParaList(),intf.get_ParaList(),globalAssumptions); vFC.add( P ); } @@ -330,10 +333,10 @@ public class SourceFile for(int i=0; i interfaceIterator=intf.getSuperInterfaces().iterator(); + Iterator interfaceIterator=intf.getSuperInterfaces().iterator(); while(interfaceIterator.hasNext()){ - Interface superintf=interfaceIterator.next(); - Pair P=createPairFromClassAndSuperclass(intf,superintf,intf.getParaList(), superintf.get_ParaList()); + RefType superintf=(RefType) interfaceIterator.next(); + Pair P=createPairFromClassAndSuperclass(intf,superintf,intf.getParaList(), superintf.get_ParaList(),globalAssumptions); vFC.add( P ); } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java b/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java index 405f84b5..229bfaeb 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java @@ -44,7 +44,7 @@ public class GenericTypeVar extends Type // ino.method.GenericTypeVar.26509.defdescription type=line // private Hashtable> m_TypeErasureList; // ino.end - private static HashMap tph = new HashMap(); + private static HashMap tph = new HashMap<>(); /** * @@ -170,12 +170,14 @@ public class GenericTypeVar extends Type */ return new JavaCodeResult(this.name.toString()); } - - public TypePlaceholder getTypePlaceHolder() { - if(!GenericTypeVar.tph.containsKey(this)){ - GenericTypeVar.tph.put(this, TypePlaceholder.fresh(this.getName().toString(),this)); + + public TypePlaceholder getTypePlaceHolder(SyntaxTreeNode environment) { + String hashValue = this.getName().toString()+environment.hashCode(); + 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(); //return this.tph; } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index 801eb60f..f010cef6 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -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. * @return */ - public void GTV2TPH(){ + public void GTV2TPH(SyntaxTreeNode environment){ Vector paralist = new Vector(); 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{ - if(t instanceof RefType)((RefType) t).GTV2TPH(); + if(t instanceof RefType)((RefType) t).GTV2TPH(environment); paralist.add(t); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/Type.java b/src/de/dhbwstuttgart/syntaxtree/type/Type.java index 13f22fd7..1c178f2b 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/Type.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/Type.java @@ -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. public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent){ - ConstraintType t = ass.getTypeFor(this, this); + ConstraintType t = ass.getTypeFor(this, parent); if(t==null) throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent); return t; diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java index 22759260..2a4d7521 100755 --- a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java @@ -311,13 +311,28 @@ public class TypeAssumptions { if(ass.getIdentifier().equals(t.getName())){ if(! ass.getAssumedType().getParentClass().getName().equals(this.thisClassName)){ //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()); } } //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); } diff --git a/test/parser/AntlrTest.jav b/test/parser/AntlrTest.jav index 43c1c252..31ab067d 100644 --- a/test/parser/AntlrTest.jav +++ b/test/parser/AntlrTest.jav @@ -1 +1,6 @@ -class Test{} \ No newline at end of file +class Test{ +method(){ + if(true)i++; + if(true)i--; + else i++; +}} \ No newline at end of file diff --git a/test/parser/FieldVarTest.jav b/test/parser/FieldVarTest.jav new file mode 100644 index 00000000..aeeecdbf --- /dev/null +++ b/test/parser/FieldVarTest.jav @@ -0,0 +1,3 @@ +class Test{ +Typ a; +} \ No newline at end of file diff --git a/test/parser/GeneralParserTest.java b/test/parser/GeneralParserTest.java index 7edd2fb8..6f0985db 100644 --- a/test/parser/GeneralParserTest.java +++ b/test/parser/GeneralParserTest.java @@ -33,6 +33,7 @@ public class GeneralParserTest{ filenames.add("ImportTest.jav"); filenames.add("BoundedParameter.jav"); filenames.add("GenericFieldVarTest.jav"); + filenames.add("FieldVarTest.jav"); MyCompilerAPI compiler = MyCompiler.getAPI(); try{ for(String filename : filenames) diff --git a/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest.jav b/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest.jav index 6c08eff5..772f649b 100644 --- a/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest.jav +++ b/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest.jav @@ -8,4 +8,4 @@ methode(){ class GTVTest2{ GTV2 var2; -} \ No newline at end of file +} diff --git a/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest2.jav b/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest2.jav index 30a9b171..c1fd0e50 100644 --- a/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest2.jav +++ b/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest2.jav @@ -1,8 +1,8 @@ class GTVTest{ GTVTest2 var; -var2; methode(){ + var2; return var.test(var2); } } From 4c9d6969054169d7891c12c78fe4224dedd9cbca Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 1 Oct 2014 17:12:16 +0200 Subject: [PATCH 04/16] =?UTF-8?q?FC=20enth=C3=A4lt=20superklassen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .classpath | 2 +- .settings/org.eclipse.jdt.core.prefs | 7 ++-- bin/.gitignore | 4 +- src/de/dhbwstuttgart/core/MyCompiler.java | 2 - src/de/dhbwstuttgart/syntaxtree/Class.java | 5 +-- .../dhbwstuttgart/syntaxtree/SourceFile.java | 42 ++++++++++++++----- .../typeinference/ConstraintsSet.java | 8 ++++ .../typeinference/OderConstraint.java | 13 ++++++ .../assumptions/TypeAssumptions.java | 4 ++ 9 files changed, 64 insertions(+), 23 deletions(-) diff --git a/.classpath b/.classpath index 11f44fce..822c05c8 100755 --- a/.classpath +++ b/.classpath @@ -3,7 +3,7 @@ - + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 794d6ee6..2e8ab188 100755 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,12 +1,13 @@ eclipse.preferences.version=1 instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/bin/.gitignore b/bin/.gitignore index 56a30e6a..8c252d62 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,6 +1,4 @@ -/bytecode/ /de/ /mycompiler/ -/parser/ -/plugindevelopment/ /syntaxTree/ +/plugindevelopment/ diff --git a/src/de/dhbwstuttgart/core/MyCompiler.java b/src/de/dhbwstuttgart/core/MyCompiler.java index dd384b93..f6f1c363 100755 --- a/src/de/dhbwstuttgart/core/MyCompiler.java +++ b/src/de/dhbwstuttgart/core/MyCompiler.java @@ -16,8 +16,6 @@ import java.util.Vector; import org.apache.log4j.Logger; import org.apache.log4j.xml.DOMConfigurator; -import com.sun.corba.se.spi.orbutil.fsm.Guard.Result; -import com.sun.org.apache.xerces.internal.impl.xs.identity.Field; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.myexception.CTypeReconstructionException; diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index a2554592..6bc3878f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -33,7 +33,6 @@ import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; import de.dhbwstuttgart.typeinference.unify.FC_TTO; import de.dhbwstuttgart.typeinference.unify.Unify; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; // ino.class.Class.23010.declaration @@ -163,8 +162,8 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } // ino.end - public Class(String name, RefType superClass, int offset){ - this(name,offset); + public Class(String name, RefType superClass, Modifiers mod, int offset){ + this(name,mod,offset); this.superClass = superClass; } diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 51387bd8..5ed9db31 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -46,8 +46,6 @@ import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.unify.FC_TTO; import de.dhbwstuttgart.typeinference.unify.Unify; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; -import sun.reflect.generics.reflectiveObjects.TypeVariableImpl; @@ -299,7 +297,7 @@ public class SourceFile */ // ino.end // ino.method.makeFC.21403.definition - public FC_TTO makeFC( ) + public FC_TTO makeFC( TypeAssumptions ass ) // ino.end // ino.method.makeFC.21403.body { @@ -311,6 +309,11 @@ public class SourceFile globalAssumptions.add(this.getPublicFieldAssumptions()); // 1. Menge <= in FC aufnehmen --> Iteration ueber alle Klassen + for(ClassAssumption cAss : ass.getClassAssumptions()){ + Pair p = new Pair(cAss.getAssumedClass().getType(), cAss.getAssumedClass().getSuperClass()); + vFC.add(p); + } + for( int i = 0; i < KlassenVektor.size(); i++ ) { Class tempKlasse = KlassenVektor.elementAt(i); @@ -650,9 +653,6 @@ public class SourceFile //Logger initialisieren: Logger typinferenzLog = Logger.getLogger("Typeinference"); - //FiniteClosure generieren: - FC_TTO finiteClosure = this.makeFC(); - //Alle Assumptions für diese SourceFile sammeln: for(Class klasse : this.KlassenVektor){ globalAssumptions.add(klasse.getPublicFieldAssumptions()); @@ -663,6 +663,11 @@ public class SourceFile globalAssumptions.add(importAssumptions); typinferenzLog.debug("Von JRE erstellte Assumptions: "+importAssumptions); + //FiniteClosure generieren: + FC_TTO finiteClosure = this.makeFC(globalAssumptions); + + System.out.println("FiniteClosure: \n"+finiteClosure); + ConstraintsSet oderConstraints = new ConstraintsSet(); //Alle Constraints der in dieser SourceFile enthaltenen Klassen sammeln: for(Class klasse : KlassenVektor){ @@ -672,6 +677,9 @@ public class SourceFile //////////////// //Karthesisches Produkt bilden: //////////////// + + //Unmögliche ConstraintsSets aussortieren durch Unifizierung + oderConstraints.filterWrongConstraints((pairs)->{return Unify.unify(pairs,finiteClosure);}); //Die Constraints in Pair's umwandeln (Karthesisches Produkt bilden): Vector> xConstraints = new Vector>();// = oderConstraints.getConstraints(); for(Vector uC:oderConstraints.getConstraints()){ //mit dem getConstraints-Aufruf wird das Karthesische Produkt erzeugt. @@ -1115,9 +1123,12 @@ public class SourceFile //String className=x.getSimpleName(); String className=x.getName(); + //Ermittle die Superklasse: + Class sClass; + sClass = getSuperClassOfJREClass(x, basicAssumptions); + Class parentClass = new Class(className, sClass.getType(),mod , 0); - Class parentClass = new Class(className, mod, 0); // Generische Typen erzeugen Hashtable jreSpiderRegistry=new Hashtable(); Vector typeGenPara = new Vector(); @@ -1242,9 +1253,16 @@ public class SourceFile } // ino.end + private Class getSuperClassOfJREClass(java.lang.Class x, TypeAssumptions ass) { + Class ret; + java.lang.Class s = x.getSuperclass(); + if(s == null)return new Class("java.lang.Object",new Modifiers(), 0); + Class ss = this.getSuperClassOfJREClass(s, ass); + ret = new Class(x.getName(),ss.getType(),new Modifiers(),0); + return ret; + } - - // ino.method.isBaseType.21412.definition + // ino.method.isBaseType.21412.definition private boolean isBaseType(String type) // ino.end // ino.method.isBaseType.21412.body @@ -1273,10 +1291,12 @@ public class SourceFile // ino.end // ino.method.createTypeFromJavaGenericType.21415.body { + /* auskommentiert, da die Klassen von Sun in der Open JDK 1.8 nicht unterstützt werden. if(type instanceof TypeVariableImpl){ - TypeVariableImpl tvi=((TypeVariableImpl)type); + TypeVariableImpl tvi=((TypeVariableImpl)type); return(new GenericTypeVar(jreSpiderRegistry.get(tvi.getName()).getName().toString(),parentClass,-1)); }else{ + */ //String jccNameForClass=baseTypeTranslationTable.get(cl.getSimpleName()); String jccNameForClass=baseTypeTranslationTable.get(cl.getName()); if(cl.getSimpleName().equalsIgnoreCase("void")){ @@ -1289,7 +1309,7 @@ public class SourceFile //return(new RefType(cl.getSimpleName())); return(new RefType(cl.getName(),parentClass,-1)); } - } + //} } // ino.end diff --git a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java index 889cf0a6..a3f44659 100755 --- a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java +++ b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java @@ -3,6 +3,8 @@ package de.dhbwstuttgart.typeinference; import java.util.Iterator; import java.util.Vector; +import de.dhbwstuttgart.typeinference.unify.Unifier; + public class ConstraintsSet implements Iterable{ private Vector constraintsSet; @@ -50,6 +52,12 @@ public class ConstraintsSet implements Iterable{ return constraintsSet.iterator(); } + public void filterWrongConstraints(Unifier unify) { + for(OderConstraint constraint : this){ + constraint.filterWrongConstraints(unify); + } + } + } diff --git a/src/de/dhbwstuttgart/typeinference/OderConstraint.java b/src/de/dhbwstuttgart/typeinference/OderConstraint.java index 62eb2096..47e21a0a 100755 --- a/src/de/dhbwstuttgart/typeinference/OderConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/OderConstraint.java @@ -5,6 +5,7 @@ import java.util.Vector; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.typeinference.unify.Unifier; public class OderConstraint{ private Vector oderConstraintPairs; @@ -78,5 +79,17 @@ public class OderConstraint{ public void addConstraint(UndConstraint methodConstraint) { oderConstraintPairs.add(methodConstraint); } + + public void filterWrongConstraints(Unifier unify) { + Vector filteredConstraints = new Vector<>(); + for(UndConstraint cons : this.getUndConstraints()){ + if(!unify.unify(cons.getConstraintPairs()).isEmpty()){ + filteredConstraints.add(cons); + }else{ + System.out.println("Ausgesondertes Constraint: "+cons); + } + } + this.oderConstraintPairs = filteredConstraints; + } } diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java index 2a4d7521..b733e110 100755 --- a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java @@ -371,6 +371,10 @@ public class TypeAssumptions { this.genericVarAssumptions.add(new GenericVarAssumption(genericTypeVar)); } + public Vector getClassAssumptions() { + return this.classAssumptions; + } + /** * Prüft einen Typ auf das vorhandensein in den BasicAssumptions. * Dabei werden alle Konstruktoren nach diesem Typ durchsucht. Denn jede Klasse hat einen Konstruktor und der muss in den TypeAssumptions vorhanden sein. From ab20e2c5e8b8b0d2546a3325a188cffc2a5fe185 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 1 Oct 2014 17:13:08 +0200 Subject: [PATCH 05/16] =?UTF-8?q?FC=20enth=C3=A4lt=20Supertklassen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../typeinference/unify/Unifier.java | 11 ++++++ .../TypeInsertTests/TypedMatrixTest.jav | 35 +++++++++++++++++++ .../TypeInsertTests/TypedMatrixTest.java | 16 +++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/de/dhbwstuttgart/typeinference/unify/Unifier.java create mode 100644 test/plugindevelopment/TypeInsertTests/TypedMatrixTest.jav create mode 100644 test/plugindevelopment/TypeInsertTests/TypedMatrixTest.java diff --git a/src/de/dhbwstuttgart/typeinference/unify/Unifier.java b/src/de/dhbwstuttgart/typeinference/unify/Unifier.java new file mode 100644 index 00000000..73478957 --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/unify/Unifier.java @@ -0,0 +1,11 @@ +package de.dhbwstuttgart.typeinference.unify; + +import java.util.Vector; + +import de.dhbwstuttgart.typeinference.Pair; + +public interface Unifier { + + public Vector> unify (Vector E); + +} diff --git a/test/plugindevelopment/TypeInsertTests/TypedMatrixTest.jav b/test/plugindevelopment/TypeInsertTests/TypedMatrixTest.jav new file mode 100644 index 00000000..f2c5c3f5 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/TypedMatrixTest.jav @@ -0,0 +1,35 @@ +import java.util.Vector; + +class Matrix extends Vector> { + + Matrix mul(Matrix m){ + Matrix ret; + ret = new Matrix(); + Integer i; + i = 0; + while(i < this.size()) { + Vector v1; + Vector v2; + v1 = this.elementAt(i); + v2 = new Vector(); + Integer j; + j = 0; + while(j < this.size()) { + erg; + erg = 0; + Integer k; + k = 0; + while(k < v1.size()) { + erg = erg + v1.elementAt(k).intValue() * m.elementAt(k).elementAt(j).intValue(); + k++; + } + v2.addElement(new Integer(erg)); + j++; + } + ret.addElement(v2); + i++; + } + return ret; + } + +} \ No newline at end of file diff --git a/test/plugindevelopment/TypeInsertTests/TypedMatrixTest.java b/test/plugindevelopment/TypeInsertTests/TypedMatrixTest.java new file mode 100644 index 00000000..810af999 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/TypedMatrixTest.java @@ -0,0 +1,16 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class TypedMatrixTest { + private static final String TEST_FILE = "TypedMatrixTest.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + mustContain.add("Integer erg;"); + MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain); + } +} From 37923779b1ea62c2751c3d258fa2e22d36336b29 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 7 Oct 2014 09:20:35 +0200 Subject: [PATCH 06/16] In der FC_TTO werden keine T <. T Constraints mehr aufgenommen --- src/de/dhbwstuttgart/syntaxtree/SourceFile.java | 6 ++++-- src/de/dhbwstuttgart/typeinference/ConstraintsSet.java | 3 --- src/de/dhbwstuttgart/typeinference/JavaCodeResult.java | 1 - 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 5ed9db31..41dc1589 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -310,8 +310,10 @@ public class SourceFile // 1. Menge <= in FC aufnehmen --> Iteration ueber alle Klassen for(ClassAssumption cAss : ass.getClassAssumptions()){ - Pair p = new Pair(cAss.getAssumedClass().getType(), cAss.getAssumedClass().getSuperClass()); - vFC.add(p); + Type t1 = cAss.getAssumedClass().getType(); + Type t2 = cAss.getAssumedClass().getType(); + Pair p = new Pair(t1, t2); + if(! t1.equals(t2))vFC.add(p); //Um FC_TTO darf kein T <. T stehen. } for( int i = 0; i < KlassenVektor.size(); i++ ) diff --git a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java index a3f44659..4a28b687 100755 --- a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java +++ b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java @@ -57,7 +57,4 @@ public class ConstraintsSet implements Iterable{ constraint.filterWrongConstraints(unify); } } - - - } diff --git a/src/de/dhbwstuttgart/typeinference/JavaCodeResult.java b/src/de/dhbwstuttgart/typeinference/JavaCodeResult.java index bd9c1978..fe902460 100755 --- a/src/de/dhbwstuttgart/typeinference/JavaCodeResult.java +++ b/src/de/dhbwstuttgart/typeinference/JavaCodeResult.java @@ -3,7 +3,6 @@ package de.dhbwstuttgart.typeinference; import java.util.Vector; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; public class JavaCodeResult{ From 3db9b069c77335050650e41942222b348cd02f7c Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 7 Oct 2014 10:47:52 +0200 Subject: [PATCH 07/16] makeBasicAssumptions verbessert. Nimmt auch nun die Superklassen der BasicAssumptions auf --- .../dhbwstuttgart/syntaxtree/SourceFile.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 41dc1589..50f7bdc2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -311,9 +311,14 @@ public class SourceFile for(ClassAssumption cAss : ass.getClassAssumptions()){ Type t1 = cAss.getAssumedClass().getType(); - Type t2 = cAss.getAssumedClass().getType(); + Type t2 = cAss.getAssumedClass().getSuperClass(); Pair p = new Pair(t1, t2); - if(! t1.equals(t2))vFC.add(p); //Um FC_TTO darf kein T <. T stehen. + System.out.println("FCPair: "+p); + if(! t1.equals(t2)){ + vFC.add(p); //Um FC_TTO darf kein T <. T stehen. + }else{ + System.out.println("Wurde nicht aufgenommen"); + } } for( int i = 0; i < KlassenVektor.size(); i++ ) @@ -668,7 +673,7 @@ public class SourceFile //FiniteClosure generieren: FC_TTO finiteClosure = this.makeFC(globalAssumptions); - System.out.println("FiniteClosure: \n"+finiteClosure); + typinferenzLog.debug("FiniteClosure: \n"+finiteClosure); ConstraintsSet oderConstraints = new ConstraintsSet(); //Alle Constraints der in dieser SourceFile enthaltenen Klassen sammeln: @@ -682,6 +687,7 @@ public class SourceFile //Unmögliche ConstraintsSets aussortieren durch Unifizierung oderConstraints.filterWrongConstraints((pairs)->{return Unify.unify(pairs,finiteClosure);}); + typinferenzLog.debug("Übriggebliebene Konstraints:\n"+oderConstraints+"\n"); //Die Constraints in Pair's umwandeln (Karthesisches Produkt bilden): Vector> xConstraints = new Vector>();// = oderConstraints.getConstraints(); for(Vector uC:oderConstraints.getConstraints()){ //mit dem getConstraints-Aufruf wird das Karthesische Produkt erzeugt. @@ -1258,9 +1264,15 @@ public class SourceFile private Class getSuperClassOfJREClass(java.lang.Class x, TypeAssumptions ass) { Class ret; java.lang.Class s = x.getSuperclass(); - if(s == null)return new Class("java.lang.Object",new Modifiers(), 0); + if(s == null){ + return new Class("java.lang.Object",new Modifiers(), 0); + } Class ss = this.getSuperClassOfJREClass(s, ass); - ret = new Class(x.getName(),ss.getType(),new Modifiers(),0); + ret = new Class(s.getName(),ss.getType(),new Modifiers(),0); + + ass.addClassAssumption(new ClassAssumption(ss)); //Die beiden SuperKlassen den Assumptions anfügen... + ass.addClassAssumption(new ClassAssumption(ret)); + return ret; } From 81416b8bf447b9a7ef22667a71208f2d11165057 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 7 Oct 2014 15:36:18 +0200 Subject: [PATCH 08/16] Richtiger Import von Generischen Typen aus der JRE --- src/de/dhbwstuttgart/syntaxtree/Class.java | 21 ++++++++++ .../dhbwstuttgart/syntaxtree/SourceFile.java | 39 ++++++++++++------- .../syntaxtree/statement/Binary.java | 1 - .../syntaxtree/statement/Block.java | 2 +- .../syntaxtree/statement/DoubleLiteral.java | 2 - .../syntaxtree/statement/EmptyStmt.java | 4 +- .../syntaxtree/statement/Expr.java | 2 +- .../syntaxtree/statement/ForStmt.java | 3 +- .../syntaxtree/statement/IfStmt.java | 2 +- .../syntaxtree/statement/IntLiteral.java | 1 - .../syntaxtree/statement/LocalOrFieldVar.java | 1 - .../syntaxtree/statement/LongLiteral.java | 2 - .../syntaxtree/statement/Return.java | 1 - .../syntaxtree/statement/Statement.java | 1 - .../syntaxtree/statement/WhileStmt.java | 2 +- .../exceptions/NotImplementedException.java | 5 +++ 16 files changed, 58 insertions(+), 31 deletions(-) create mode 100644 src/de/dhbwstuttgart/typeinference/exceptions/NotImplementedException.java diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index 6bc3878f..c2a9dc2f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -162,6 +162,26 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } // ino.end + /** + * Erstellt eine Klasse, welche nur für die Assumptions verwendet wird. + * Sie enthält keine unnötigen Informationen, wie Offset oder ClassBody. + * @param name + * @param superClass + * @param modifiers + * @param supertypeGenPara - Eine Liste von Namen, welche die Generischen Parameter der Klasse darstellen. + */ + public Class(String name, RefType superClass, Modifiers modifiers, + Vector supertypeGenPara) { + this(name,superClass,modifiers,0); + if(supertypeGenPara == null)return; + Vector gtvs = new Vector<>(); + for(String gname : supertypeGenPara){ + GenericTypeVar newGTV=new GenericTypeVar(gname,this,0); + gtvs.add(newGTV); + } + this.genericClassParameters = new GenericDeclarationList(gtvs,0); + } + public Class(String name, RefType superClass, Modifiers mod, int offset){ this(name,mod,offset); this.superClass = superClass; @@ -244,6 +264,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } // ino.end + public Vector getFields() { return fielddecl; diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 50f7bdc2..623a4ca4 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -1179,7 +1179,7 @@ public class SourceFile GenericTypeVar newGTV=new GenericTypeVar(superclassTVS[tvi].getName(),parentClass,-1); supertypeGenPara.addElement(newGTV); } - + if(supertypeGenPara.size()==0){ supertypeGenPara=null; } @@ -1267,9 +1267,17 @@ public class SourceFile if(s == null){ return new Class("java.lang.Object",new Modifiers(), 0); } + + Vector supertypeGenPara = new Vector<>();//Die Generischen Parameter für die Superklasse berechnen: + java.lang.reflect.TypeVariable[] superclassTVS=s.getTypeParameters(); + for(int tvi=0;tvi Date: Tue, 7 Oct 2014 17:47:23 +0200 Subject: [PATCH 09/16] NullPointerException in Unify beseitigt --- src/de/dhbwstuttgart/syntaxtree/type/RefType.java | 1 - .../typeinference/assumptions/TypeAssumptions.java | 1 - src/de/dhbwstuttgart/typeinference/unify/Unify.java | 4 ++++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index f010cef6..56060e9c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -24,7 +24,6 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.unify.CSubstitutionGenVar; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java index b733e110..9549e137 100755 --- a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java @@ -16,7 +16,6 @@ import de.dhbwstuttgart.typeinference.FunN; import de.dhbwstuttgart.typeinference.FunNInterface; import de.dhbwstuttgart.typeinference.FunNMethod; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; /** * Eine Sammlung von TypeAssumptions. diff --git a/src/de/dhbwstuttgart/typeinference/unify/Unify.java b/src/de/dhbwstuttgart/typeinference/unify/Unify.java index 3317cbea..7e3b8221 100755 --- a/src/de/dhbwstuttgart/typeinference/unify/Unify.java +++ b/src/de/dhbwstuttgart/typeinference/unify/Unify.java @@ -1068,6 +1068,10 @@ throws MatchException for(int i=0; i < FCtype.get_ParaList().size(); i++) { if (FCtype.get_ParaList().elementAt(i) instanceof GenericTypeVar) { inferencelog.debug("PUT"); + //TODO Auf Korrektheit prüfen: + if(tomatch.getParaList().size() != FCtype.getParaList().size()){ + throw new MatchException("Different Parameter Sizes!"); + }//Angefügt von Andreas Stadelmeier (ENDE) ht.put(((GenericTypeVar)FCtype.get_ParaList().elementAt(i)).getName(), tomatch.get_ParaList().elementAt(i)); } From 51e0d96174f2138e222fa537ad8475a91e54ab7f Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 7 Oct 2014 17:47:59 +0200 Subject: [PATCH 10/16] =?UTF-8?q?Reduziertes=20Testbeispiel=20angef=C3=BCg?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TypeInsertTests/TypedMatrixSimpleTest.jav | 24 +++++++++++++++++++ .../TypeInsertTests/ypedMatrixSimpleTest.java | 16 +++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 test/plugindevelopment/TypeInsertTests/TypedMatrixSimpleTest.jav create mode 100644 test/plugindevelopment/TypeInsertTests/ypedMatrixSimpleTest.java diff --git a/test/plugindevelopment/TypeInsertTests/TypedMatrixSimpleTest.jav b/test/plugindevelopment/TypeInsertTests/TypedMatrixSimpleTest.jav new file mode 100644 index 00000000..72d00877 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/TypedMatrixSimpleTest.jav @@ -0,0 +1,24 @@ +import java.util.Vector; + +class Matrix extends Vector> { + + Matrix mul(Matrix m){ + Matrix ret; + ret = new Matrix(); + Integer i; + i = 0; + while(i < this.size()) { + Vector v1; + Vector v2; + v1 = this.elementAt(i); + v2 = new Vector(); + Integer j; + j = 0; + + ret.addElement(v2); + i++; + } + return ret; + } + +} \ No newline at end of file diff --git a/test/plugindevelopment/TypeInsertTests/ypedMatrixSimpleTest.java b/test/plugindevelopment/TypeInsertTests/ypedMatrixSimpleTest.java new file mode 100644 index 00000000..d90e2627 --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/ypedMatrixSimpleTest.java @@ -0,0 +1,16 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class ypedMatrixSimpleTest { + private static final String TEST_FILE = "TypedMatrixSimpleTest.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + mustContain.add("Integer erg;"); + MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain); + } +} From 2b33576488baf251ccd8c351fc5f701e2b271008 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 8 Oct 2014 19:00:17 +0200 Subject: [PATCH 11/16] Finite Closure ohne Subtypes. checkType statt TYPE --- .../dhbwstuttgart/parser/JavaClassName.java | 1 + src/de/dhbwstuttgart/syntaxtree/Class.java | 34 +++++++---- .../syntaxtree/FormalParameter.java | 3 +- src/de/dhbwstuttgart/syntaxtree/Method.java | 4 +- .../dhbwstuttgart/syntaxtree/SourceFile.java | 56 ++++++++++++------- .../syntaxtree/statement/BoolLiteral.java | 2 +- .../syntaxtree/statement/DoubleLiteral.java | 2 +- .../syntaxtree/statement/IntLiteral.java | 2 +- .../syntaxtree/statement/LocalOrFieldVar.java | 3 +- .../syntaxtree/statement/LocalVarDecl.java | 2 +- .../syntaxtree/statement/NewClass.java | 44 +-------------- .../syntaxtree/statement/Null.java | 2 +- .../syntaxtree/statement/StringLiteral.java | 2 +- .../type/BoundedGenericTypeVar.java | 4 +- .../syntaxtree/type/FreshWildcardType.java | 2 +- .../syntaxtree/type/RefType.java | 19 ++++--- .../dhbwstuttgart/syntaxtree/type/Type.java | 12 ++-- .../syntaxtree/type/WildcardType.java | 3 +- .../typeinference/ConstraintType.java | 2 +- .../typeinference/FunNInterface.java | 19 ++++++- .../typeinference/FunNMethod.java | 2 +- .../typeinference/OderConstraint.java | 3 +- .../assumptions/TypeAssumptions.java | 27 +++++++-- .../typeinference/unify/FC_TTO.java | 4 +- .../TypeInsertTests/LambdaTest24.java | 2 +- ...leTest.java => TypedMatrixSimpleTest.java} | 2 +- .../TypeInsertTests/TypedMatrixTest.jav | 2 +- 27 files changed, 143 insertions(+), 117 deletions(-) rename test/plugindevelopment/TypeInsertTests/{ypedMatrixSimpleTest.java => TypedMatrixSimpleTest.java} (90%) diff --git a/src/de/dhbwstuttgart/parser/JavaClassName.java b/src/de/dhbwstuttgart/parser/JavaClassName.java index dbb87943..31609fe3 100644 --- a/src/de/dhbwstuttgart/parser/JavaClassName.java +++ b/src/de/dhbwstuttgart/parser/JavaClassName.java @@ -17,6 +17,7 @@ public class JavaClassName { private PackageName packageName; public JavaClassName(String name){ + if(name == null)throw new NullPointerException(); String[] names = name.split("[.]"); boolean match = true; if(names.length == 1){ diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index c2a9dc2f..a33f3d76 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -112,7 +112,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit private Block class_block; // ino.end // ino.attribute.paralist.23023.declaration - private Vector paralist = new Vector(); // Parameterliste 'class xy{}' wird gespeichert + //private Vector paralist = new Vector(); // Parameterliste 'class xy{}' wird gespeichert // ino.end // ino.attribute.parahash.23026.declaration private Hashtable parahash = new Hashtable(); // parametrisierten Attrib. werden mit den Paramet.aus paralist verk. @@ -184,7 +184,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit public Class(String name, RefType superClass, Modifiers mod, int offset){ this(name,mod,offset); - this.superClass = superClass; + if(superClass == null)this.superClass = new Class("Object",-1).getType(); } // ino.method.Class.23044.definition @@ -247,7 +247,15 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } if (vector != null) setSuperInterfaces(vector); if (paralist != null){ - this.set_ParaList(paralist); + //this.set_ParaList(paralist); + Vector gtvList = new Vector<>(); + int lastItemOffset = 0; + for(Type paraT : paralist){ + GenericTypeVar gtv = new GenericTypeVar(paraT.get_Name(),this, paraT.getOffset()); + gtvList.add(gtv); + lastItemOffset = paraT.getOffset() + paraT.get_Name().length(); + } + this.genericClassParameters = new GenericDeclarationList(gtvList, lastItemOffset); } if(usedIdsToCheck!=null) this.usedIdsToCheck=usedIdsToCheck; @@ -264,7 +272,6 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } // ino.end - public Vector getFields() { return fielddecl; @@ -308,7 +315,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } // ino.end - + /* // ino.method.complete_paralist.23062.definition public Vector complete_paralist(boolean ext) // ino.end @@ -327,7 +334,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit return this.paralist; } // ino.end - + */ /** @@ -478,6 +485,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } // ino.end + /* // ino.method.set_ParaList.23098.definition public void set_ParaList(Vector para) // ino.end @@ -486,13 +494,15 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit this.paralist = para; } // ino.end - + */ + // ino.method.get_ParaList.23101.definition - public Vector get_ParaList() + public Vector get_ParaList() // ino.end // ino.method.get_ParaList.23101.body { - return this.paralist; + //if(this.paralist == null)return new Vector(); + return this.getGenericParameter(); } // ino.end @@ -660,10 +670,10 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit ConstraintsSet oderConstraints = new ConstraintsSet(); - for(Type gparam : this.paralist){ + for(Type gparam : this.get_ParaList()){ if(gparam instanceof GenericTypeVar)assumptions.add(((GenericTypeVar)gparam).createAssumptions()); //Constraints für die Generischen Variablen erstellen und diese dem AssumptionsSet hinzufügen } - for(Type gparam : this.paralist){ + for(Type gparam : this.get_ParaList()){ if(gparam instanceof GenericTypeVar)oderConstraints.add(((GenericTypeVar)gparam).TYPE(assumptions)); //Constraints für die Generischen Variablen erstellen und diese dem AssumptionsSet hinzufügen } @@ -1193,10 +1203,12 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } if(this.genericClassParameters == null)this.setGenericParameter(new GenericDeclarationList(new Vector(), 0)); + /*//Nicht mehr notwendig, Generische Klassenparameter werden nun immer direkt in die genericClassParameters gespeichert. for(Type t : this.get_ParaList()){ if(t instanceof GenericTypeVar)this.genericClassParameters.add((GenericTypeVar)t); else this.genericClassParameters.add(new GenericTypeVar(t.get_Name(),this,-1)); } + */ for(Type t : this.get_ParaList()){ t.parserPostProcessing(this); } diff --git a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java index cb726848..47101ad5 100755 --- a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java +++ b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java @@ -6,6 +6,7 @@ package de.dhbwstuttgart.syntaxtree; import java.util.Vector; import org.apache.log4j.Logger; + import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; import de.dhbwstuttgart.syntaxtree.misc.DeclId; @@ -15,10 +16,10 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.TypeInsertable; import de.dhbwstuttgart.typeinference.Typeable; +import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; // ino.class.FormalParameter.23391.declaration public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeInsertable diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index db84fb99..9b0d5bba 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -527,7 +527,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable } //TypeCheck, falls es sich um einen RefType handelt: - this.returntype = this.returntype.TYPE(localAss, this).getType(); + this.returntype = this.returntype.checkTYPE(localAss, this); /* if(this.returntype!=null && (this.returntype instanceof RefType)&& !(this.returntype instanceof mycompiler.mytype.Void)){//Sonderfall der Methode: Ihr Typ darf Void definiert werden. @@ -540,7 +540,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable //Die Parameter zu den Assumptions hinzufügen: if(this.parameterlist!=null)for(FormalParameter param : this.parameterlist){ - param.setType(param.getType().TYPE(localAss, this).getType()); + param.setType(param.getType().checkTYPE(localAss, this)); /* if(param.getType() instanceof RefType) { diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 623a4ca4..f98cf230 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -305,19 +305,21 @@ public class SourceFile // Menge FC bilden Vector vFC = new Vector(); // Menge FC - TypeAssumptions globalAssumptions = this.makeBasicAssumptionsFromJRE(imports); + TypeAssumptions globalAssumptions = this.makeBasicAssumptionsFromJRE(imports, false); globalAssumptions.add(this.getPublicFieldAssumptions()); // 1. Menge <= in FC aufnehmen --> Iteration ueber alle Klassen + Vector basicAssumptionsClassVector = new Vector<>(); //die Klassen aus den BasicAssumptions for(ClassAssumption cAss : ass.getClassAssumptions()){ Type t1 = cAss.getAssumedClass().getType(); Type t2 = cAss.getAssumedClass().getSuperClass(); Pair p = new Pair(t1, t2); - System.out.println("FCPair: "+p); - if(! t1.equals(t2)){ - vFC.add(p); //Um FC_TTO darf kein T <. T stehen. + //System.out.println("FCPair: "+p); + if(! t1.equals(t2)){//Um FC_TTO darf kein T <. T stehen. + //vFC.add(p); //Wird momentan nicht hinzugefügt + basicAssumptionsClassVector.add(cAss.getAssumedClass());//Klasse ohne die Superklasse anfügen }else{ - System.out.println("Wurde nicht aufgenommen"); + //System.out.println("Wurde nicht aufgenommen"); } } @@ -621,10 +623,13 @@ public class SourceFile // printMenge( "nach trans: FC", vFC, 6 ); - FC_TTO fctto = new FC_TTO(vFC, tto,KlassenVektor); + Vector KlassenVektorunImportierteKlassen = new Vector<>(); + KlassenVektorunImportierteKlassen.addAll(basicAssumptionsClassVector); + KlassenVektorunImportierteKlassen.addAll(KlassenVektor); + + FC_TTO fctto = new FC_TTO(vFC, tto, KlassenVektorunImportierteKlassen); return fctto; } - // ino.end public TypeAssumptions getPublicFieldAssumptions(){ TypeAssumptions publicAssumptions = new TypeAssumptions(null); @@ -666,7 +671,7 @@ public class SourceFile } //Assumptions der importierten Klassen sammeln: - TypeAssumptions importAssumptions = this.makeBasicAssumptionsFromJRE(imports); + TypeAssumptions importAssumptions = this.makeBasicAssumptionsFromJRE(imports, true); globalAssumptions.add(importAssumptions); typinferenzLog.debug("Von JRE erstellte Assumptions: "+importAssumptions); @@ -1094,8 +1099,13 @@ public class SourceFile return ret; }*/ - // ino.method.makeBasicAssumptionsFromJRE.21409.definition - private TypeAssumptions makeBasicAssumptionsFromJRE(Vector imports) + /** + * Erstellt die Assumptions der standardmäßig importierten Packages (java.lang.) sowie der von imports übergebenen Klassen zusammen. + * @param imports + * @param withSuptypes - Gibt an, ob auch die subklassen der Packages den Assumptions angefügt werden sollen. + * @return + */ + private TypeAssumptions makeBasicAssumptionsFromJRE(Vector imports, boolean withSubtypes) // ino.end // ino.method.makeBasicAssumptionsFromJRE.21409.body { @@ -1132,26 +1142,30 @@ public class SourceFile String className=x.getName(); //Ermittle die Superklasse: - Class sClass; - sClass = getSuperClassOfJREClass(x, basicAssumptions); + Class sClass = new Class("Object",0); + if(withSubtypes)sClass = getSuperClassOfJREClass(x, basicAssumptions); - Class parentClass = new Class(className, sClass.getType(),mod , 0); - - // Generische Typen erzeugen + // Namen von Generische Typen erzeugen Hashtable jreSpiderRegistry=new Hashtable(); - Vector typeGenPara = new Vector(); + Vector typeGenPara = new Vector(); for(int j=0;j0){ //auskommentiert von Andreas Stadelmeier: //basicAssumptions.addGenericTypeVars(className, typeGenPara); - parentClass.set_ParaList((Vector)typeGenPara);//myCl.set_ParaList((Vector)typeGenPara); + //parentClass.set_ParaList((Vector)typeGenPara);//myCl.set_ParaList((Vector)typeGenPara); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java index 7516e1f2..7bbaf757 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java @@ -126,7 +126,7 @@ public class BoolLiteral extends Literal @Override public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - this.type = assumptions.getTypeFor(new RefType("java.lang.Boolean",this,-1), this).getType(); + this.type = assumptions.checkType(new RefType("java.lang.Boolean",this,-1), this); return new ConstraintsSet(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/DoubleLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/DoubleLiteral.java index b8fec59f..55a3d430 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/DoubleLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/DoubleLiteral.java @@ -162,7 +162,7 @@ public class DoubleLiteral extends Literal @Override public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - this.setType(assumptions.getTypeFor(new RefType("Double",this,this.getOffset()), this).getType()); + this.setType(assumptions.checkType(new RefType("Double",this,this.getOffset()), this)); return new ConstraintsSet(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/IntLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/IntLiteral.java index 7d9f5c85..d251cd7b 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/IntLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/IntLiteral.java @@ -160,7 +160,7 @@ public class IntLiteral extends Literal public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { ConstraintsSet ret = new ConstraintsSet(); //this.setType(new IntegerType()); - this.set_Type(assumptions.getTypeFor(new RefType("java.lang.Integer",this,-1), this).getType()); + this.set_Type(assumptions.checkType(new RefType("java.lang.Integer",this,-1), this)); return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java index 72907149..d773f48c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java @@ -177,7 +177,8 @@ public class LocalOrFieldVar extends Expr //gibt es eine Assumption für den die LocalOrFieldVar-Variablen, dann folgendes ausführen: Type thisTypeAssumption = assumptions.getVarType(this.get_Name(), this.getParentClass()); if(thisTypeAssumption == null)throw new TypeinferenceException("Eine Variable "+this.get_Name()+" ist in den Assumptions nicht vorhanden",this); - this.setType(thisTypeAssumption); + Type thisType = thisTypeAssumption.checkTYPE(assumptions, this); + this.setType(thisType); //ret.add(new Constraint(thisTypeAssumption, this.getTypeVariable())); return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java index 3da735a1..855f9dde 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java @@ -378,7 +378,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable ConstraintsSet ret = new ConstraintsSet(); if((this.getType() instanceof RefType)){ Type replaceType = null; - replaceType = assumptions.getTypeFor((RefType)this.getType(), this).getType(); + replaceType = assumptions.checkType((RefType)this.getType(), this); this.setType(replaceType); } assumptions.addAssumption(new LocalVarAssumption(this, this.getType())); //Bevor der Typ auf Void gesetzt wird. diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java index 8270ab74..d279ebff 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java @@ -88,46 +88,6 @@ public class NewClass extends Expr } // ino.end - // ino.method.sc_check.25852.definition - public void sc_check(Vector classname, Hashtable bh, Hashtable ch, boolean ext, Hashtable parach, Hashtable parabh) - throws SCStatementException - // ino.end - // ino.method.sc_check.25852.body - { - if(ext) - parserlog.debug(" ---NewClass---"); - Class cl; - String usedid = this.usedid.get_Name_1Element(); - String next = null; - for(Enumeration el = classname.elements(); el.hasMoreElements();) - { - cl = el.nextElement(); - next = (String)cl.getName().toString(); - if(ext) - parserlog.debug("Vergleiche "+usedid+" mit "+next); - if(usedid.equals(next)) - { - this.set_Type(new Type(next,this,getOffset())); - break; - } - else next = null; - } - if(next == null) - { - if(ext) - parserlog.error("Typfehler --> NewClass.sc_check()" ); - SCStatementException stex = new SCStatementException(); - SCExcept ex = new SCExcept(); - ex.set_error("Typfehler"); - ex.set_statement("NewClass: Klasse "+usedid+" existiert nicht im Vector classname."); - stex.addException(ex); - throw stex; - } - if(ext) - parserlog.debug("Klasse "+usedid+" im class-Vector gefunden"); - } - // ino.end - // ino.method.set_ArgumentList.25855.definition public void set_ArgumentList(ArgumentList al) // ino.end @@ -223,8 +183,8 @@ public class NewClass extends Expr //if(this.arglist != null && this.arglist.expr != null)for(Expr arg : this.arglist.expr){ // ret.add(arg.TYPEExpr(assumptions)); //} - - this.setType(assumptions.getTypeFor(new RefType(this.get_Name(),this,0), this).getType()); + Type thisT = assumptions.checkType(new RefType(this.get_Name(),this,0), (SyntaxTreeNode)this); + this.setType(thisT); /* diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Null.java b/src/de/dhbwstuttgart/syntaxtree/statement/Null.java index 66bc356c..a02121ac 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Null.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Null.java @@ -42,7 +42,7 @@ public class Null extends Literal // ino.method.Null.25926.body { super(-1,-1); - this.setType(new Type("__NULL__",this,getOffset())); + //this.setType(new Type("__NULL__",this,getOffset())); } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java index 56fbe6ac..a1ed579f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java @@ -121,7 +121,7 @@ public class StringLiteral extends Literal @Override public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) { - this.set_Type(assumptions.getTypeFor(new RefType("String",this,0), this).getType()); + this.set_Type(assumptions.checkType(new RefType("String",this,0), this)); return new ConstraintsSet(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java b/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java index d75715df..ebe21b0d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/BoundedGenericTypeVar.java @@ -13,8 +13,6 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; -// ino.end // ino.class.BoundedGenericTypeVar.26464.description type=javadoc /** @@ -93,7 +91,7 @@ public class BoundedGenericTypeVar extends GenericTypeVar if(this.bounds != null){ for(Type ev : this.bounds){ ConstraintType extendsType = ass.getTypeFor(ev, this); - if(extendsType == null)throw new TypeinferenceException("Der Typ "+ev.getName()+" ist nicht korrekt", this); + //if(extendsType == null)throw new TypeinferenceException("Der Typ "+ev.getName()+" ist nicht korrekt", this); ret.add(new SingleConstraint(ass.getTypeFor(this, this), extendsType )); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java index 364681db..829f0f40 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java @@ -6,7 +6,7 @@ import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; public class FreshWildcardType extends Type { diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index 56060e9c..ba8178dd 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -268,6 +268,7 @@ public class RefType extends Type implements IMatchable // ino.end public void setName( JavaClassName name ){ + if(name == null)throw new NullPointerException(); this.name = name; } @@ -800,16 +801,16 @@ public class RefType extends Type implements IMatchable @Override public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent){ - //Der RefType muss zusätzlich seine Parameter prüfen. - Vector parameterList = new Vector<>(); - Vector parameterList2 = new Vector<>(); - if(this.parameter!=null)for(Type param : this.parameter){ - ConstraintType ct = param.TYPE(ass, parent); - parameterList.add(ct); - parameterList2.add(ct.getType()); - } - this.parameter = parameterList2; ConstraintType t = super.TYPE(ass,parent); + //((RefType)t.getType()).set_ParaList(this.get_ParaList()); + return t; + } + + @Override + public Type checkTYPE(TypeAssumptions ass, SyntaxTreeNode method) { + Type t = ass.checkType(this, parent); + if(t==null) + throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent); return t; } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/Type.java b/src/de/dhbwstuttgart/syntaxtree/type/Type.java index 1c178f2b..ef26b1e7 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/Type.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/Type.java @@ -5,7 +5,6 @@ package de.dhbwstuttgart.syntaxtree.type; import java.util.ArrayList; import java.util.Vector; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; import de.dhbwstuttgart.bytecode.JVMCode; import de.dhbwstuttgart.core.IItemWithOffset; import de.dhbwstuttgart.parser.JavaClassName; @@ -19,9 +18,9 @@ import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; - +//TODO: Die Klasse Type muss abstract werden! // ino.class.Type.26716.declaration -public class Type extends SyntaxTreeNode implements IItemWithOffset +public abstract class Type extends SyntaxTreeNode implements IItemWithOffset // ino.end // ino.class.Type.26716.body { @@ -181,6 +180,7 @@ public class Type extends SyntaxTreeNode implements IItemWithOffset if(obj instanceof Type){ // String name2 = ((Type)obj).printJavaCode(new ResultSet()).toString(); //return printJavaCode(new ResultSet()).toString().equals(name2); + if(((Type)obj).name == null)return false; //Auch wenn der Name dieses Typs auch null ist. Typen sind nur gleich wenn sie einen gleichen Namen haben, welcher nicht null ist. return ((Type)obj).name.equals(name); } else{ @@ -200,7 +200,7 @@ public class Type extends SyntaxTreeNode implements IItemWithOffset // ino.end // ino.method.clone.26768.body { - return new Type(this.getName().toString(), this.getParent(),getOffset()); + return new RefType(this.getName().toString(), this.getParent(),getOffset()); } // ino.end @@ -317,6 +317,10 @@ public class Type extends SyntaxTreeNode implements IItemWithOffset public Vector getChildren() { return new Vector<>(); } + + public Type checkTYPE(TypeAssumptions ass, SyntaxTreeNode method){ + return this; + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java index 0a28db06..56312b90 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java @@ -3,7 +3,8 @@ package de.dhbwstuttgart.syntaxtree.type; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; +import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; +import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; /** * Stellt eine Wildcard in Java dar. diff --git a/src/de/dhbwstuttgart/typeinference/ConstraintType.java b/src/de/dhbwstuttgart/typeinference/ConstraintType.java index f4ff991a..09ccb730 100644 --- a/src/de/dhbwstuttgart/typeinference/ConstraintType.java +++ b/src/de/dhbwstuttgart/typeinference/ConstraintType.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.typeinference; import de.dhbwstuttgart.syntaxtree.type.*; +import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; public class ConstraintType{ @@ -18,5 +19,4 @@ public class ConstraintType{ public Type getType() { return t; } - } diff --git a/src/de/dhbwstuttgart/typeinference/FunNInterface.java b/src/de/dhbwstuttgart/typeinference/FunNInterface.java index c41c228c..fcc6b452 100644 --- a/src/de/dhbwstuttgart/typeinference/FunNInterface.java +++ b/src/de/dhbwstuttgart/typeinference/FunNInterface.java @@ -4,7 +4,9 @@ import java.util.Vector; import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.Class; +import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; +import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption; @@ -21,14 +23,15 @@ public class FunNInterface extends Class{ //TODO: getType muss einen Typ mit der ParameterListe zurückliefern. - private Vector gtvparalist; + //private Vector gtvparalist; /** * Ein FunN-Interface enthält nur eine Methode (namens apply). Ist also ein Funktionales Interface. * @param N - Die Anzahl der Parameter der apply-Methode. Beispiel N = 1 ergibt R apply(T1 par1); */ public FunNInterface(int N) { - super("Fun"+N, 0); + super("Fun"+N, null, new Modifiers(), FunNInterface.makeParaList(N)); + /* GenericTypeVar gtv; Vector paralist = new Vector<>(); gtv = new GenericTypeVar("R",this, 0); @@ -43,8 +46,18 @@ public class FunNInterface extends Class{ //paralist.add(TypePlaceholder.fresh()); } this.set_ParaList(paralist); + */ } + private static Vector makeParaList(int n) { + Vector ret = new Vector<>(); + ret.add("R"); + for(int i = 1; i<=n;i++){ + ret.add("T"+i); + } + return ret; + } + /** * @return Im Falle von einem FunN-Interface ist dies die apply-Methode */ @@ -54,7 +67,7 @@ public class FunNInterface extends Class{ TypeAssumptions ret = new TypeAssumptions(); ret.addAssumption(new MethodAssumption(this.getApplyFunction(), this)); ret.addClassAssumption(new ClassAssumption(this)); - for(GenericTypeVar gtv : this.gtvparalist)ret.addGenericVarAssumption(gtv); + for(GenericTypeVar gtv : this.getGenericParameter())ret.addGenericVarAssumption(gtv); return ret; } diff --git a/src/de/dhbwstuttgart/typeinference/FunNMethod.java b/src/de/dhbwstuttgart/typeinference/FunNMethod.java index 07b8acf8..cf056020 100644 --- a/src/de/dhbwstuttgart/typeinference/FunNMethod.java +++ b/src/de/dhbwstuttgart/typeinference/FunNMethod.java @@ -15,7 +15,7 @@ public class FunNMethod extends Method{ * * @param N - Anzahl der Parameter (Beispiel: Fun2) */ - public FunNMethod(Vector paralist){ + public FunNMethod(Vector paralist){ super(0); //Hat keinen Offset, da nur theoretisch gedachte Methode int N = paralist.size(); //In der paraliste ist der erste Parameter der Rückgabetyp this.setType(paralist.firstElement()); diff --git a/src/de/dhbwstuttgart/typeinference/OderConstraint.java b/src/de/dhbwstuttgart/typeinference/OderConstraint.java index 47e21a0a..53fd06bb 100755 --- a/src/de/dhbwstuttgart/typeinference/OderConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/OderConstraint.java @@ -2,6 +2,7 @@ package de.dhbwstuttgart.typeinference; import java.util.Vector; +import de.dhbwstuttgart.logger.TypinferenzLog; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; @@ -86,7 +87,7 @@ public class OderConstraint{ if(!unify.unify(cons.getConstraintPairs()).isEmpty()){ filteredConstraints.add(cons); }else{ - System.out.println("Ausgesondertes Constraint: "+cons); + TypinferenzLog.debug("Ausgesondertes Constraint: "+cons); } } this.oderConstraintPairs = filteredConstraints; diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java index 9549e137..0285a545 100755 --- a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java @@ -163,7 +163,7 @@ public class TypeAssumptions { } //Ebenso wie die Generischen Variablen: for(GenericVarAssumption ass : this.genericVarAssumptions){ - + if(ass.getIdentifier().equals(variableName))return ass.getAssumedType(); } //und zuletzt die Felder der Klasse in dessen Namensraum sich dieses AssumptionSet befindet. @@ -173,8 +173,8 @@ public class TypeAssumptions { } } //Wird keine Assumption gefunden, muss ein Fehler vorliegen: - //throw new TypeinferenceException("Eine Variable "+variableName+" ist in den Assumptions nicht vorhanden"); - return null; + throw new TypeinferenceException("Eine Variable "+variableName+" ist in den Assumptions nicht vorhanden", inScope); + //return null; } /** @@ -300,7 +300,20 @@ public class TypeAssumptions { if(match && t instanceof RefType){ RefType tr = (RefType)t; RefType ret = ass.getAssumedClass().getType(); //Dadurch erhält der RefType den vollen Namen (bsp. java.lang.Integer) - ret.set_ParaList(tr.getParaList()); + + //Falls der RefType mit Parametern angegeben wurde, so müssen diese erhalten bleiben: + if(tr.get_ParaList()!=null && tr.getParaList().size()>0){ + ret.set_ParaList(tr.getParaList()); + } + + //Der RefType muss zusätzlich seine Parameter prüfen. + Vector parameterList = new Vector<>(); + if(ret.get_ParaList()!=null)for(Type param : ret.get_ParaList()){ + ConstraintType ct = param.TYPE(this, inNode); + parameterList.add(ct.getType()); + } + ret.set_ParaList(parameterList); + return new ConstraintType(ret); } } @@ -374,6 +387,12 @@ public class TypeAssumptions { return this.classAssumptions; } + public Type checkType(RefType type, SyntaxTreeNode parent) { + ConstraintType t = this.getTypeFor(type, parent); //Richtigkeit des Typnahmensprüfen + type.setName(t.getType().getName()); //Und diesen auf den Typ anwenden + return t.getType(); + } + /** * Prüft einen Typ auf das vorhandensein in den BasicAssumptions. * Dabei werden alle Konstruktoren nach diesem Typ durchsucht. Denn jede Klasse hat einen Konstruktor und der muss in den TypeAssumptions vorhanden sein. diff --git a/src/de/dhbwstuttgart/typeinference/unify/FC_TTO.java b/src/de/dhbwstuttgart/typeinference/unify/FC_TTO.java index b1e8fe69..440bbd50 100755 --- a/src/de/dhbwstuttgart/typeinference/unify/FC_TTO.java +++ b/src/de/dhbwstuttgart/typeinference/unify/FC_TTO.java @@ -74,8 +74,8 @@ public class FC_TTO public void generateFullyNamedTypes(TypeAssumptions ass) { for(Pair p : this.FC){ - p.TA1 = ass.getTypeFor(p.TA1, null).getType(); - p.TA2 = ass.getTypeFor(p.TA2, null).getType(); + p.TA1 = ass.getTypeFor(p.TA1, p.TA1.getParent()).getType(); + p.TA2 = ass.getTypeFor(p.TA2, p.TA2.getParent()).getType(); } } } diff --git a/test/plugindevelopment/TypeInsertTests/LambdaTest24.java b/test/plugindevelopment/TypeInsertTests/LambdaTest24.java index 59de42e5..b3086da7 100644 --- a/test/plugindevelopment/TypeInsertTests/LambdaTest24.java +++ b/test/plugindevelopment/TypeInsertTests/LambdaTest24.java @@ -10,7 +10,7 @@ public class LambdaTest24 { @Test public void run(){ Vector mustContain = new Vector(); - //mustContain.add("Matrix ret"); + mustContain.add("Fun2"); MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain); } } diff --git a/test/plugindevelopment/TypeInsertTests/ypedMatrixSimpleTest.java b/test/plugindevelopment/TypeInsertTests/TypedMatrixSimpleTest.java similarity index 90% rename from test/plugindevelopment/TypeInsertTests/ypedMatrixSimpleTest.java rename to test/plugindevelopment/TypeInsertTests/TypedMatrixSimpleTest.java index d90e2627..2db27805 100644 --- a/test/plugindevelopment/TypeInsertTests/ypedMatrixSimpleTest.java +++ b/test/plugindevelopment/TypeInsertTests/TypedMatrixSimpleTest.java @@ -4,7 +4,7 @@ import java.util.Vector; import org.junit.Test; -public class ypedMatrixSimpleTest { +public class TypedMatrixSimpleTest { private static final String TEST_FILE = "TypedMatrixSimpleTest.jav"; @Test diff --git a/test/plugindevelopment/TypeInsertTests/TypedMatrixTest.jav b/test/plugindevelopment/TypeInsertTests/TypedMatrixTest.jav index f2c5c3f5..c9bbd601 100644 --- a/test/plugindevelopment/TypeInsertTests/TypedMatrixTest.jav +++ b/test/plugindevelopment/TypeInsertTests/TypedMatrixTest.jav @@ -15,7 +15,7 @@ class Matrix extends Vector> { Integer j; j = 0; while(j < this.size()) { - erg; + Integer erg; erg = 0; Integer k; k = 0; From 26f35cfeb6ef7a854ebbf5f221d949894285bf72 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 9 Oct 2014 12:01:16 +0200 Subject: [PATCH 12/16] =?UTF-8?q?Logger=20angef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .classpath | 1 - bin/.gitignore | 1 - bin/log4j.xml | 4 +- bin/log4jTesting.xml | 4 +- log4j.xml | 4 +- src/de/dhbwstuttgart/bytecode/Attribute.java | 3 +- src/de/dhbwstuttgart/bytecode/CPInfo.java | 3 +- src/de/dhbwstuttgart/bytecode/ClassFile.java | 4 +- .../dhbwstuttgart/bytecode/CodeAttribute.java | 1 - .../bytecode/ExceptionTable.java | 2 +- src/de/dhbwstuttgart/bytecode/FieldInfo.java | 2 +- src/de/dhbwstuttgart/bytecode/JVMCode.java | 2 +- src/de/dhbwstuttgart/bytecode/Key.java | 2 +- src/de/dhbwstuttgart/bytecode/MethodInfo.java | 2 +- .../dhbwstuttgart/bytecode/SignatureInfo.java | 2 +- .../dhbwstuttgart/core/AClassOrInterface.java | 2 +- .../dhbwstuttgart/core/ConsoleInterface.java | 5 +- src/de/dhbwstuttgart/core/MyCompiler.java | 3 +- src/de/dhbwstuttgart/logger/Logger.java | 59 +++++++++++++++++++ .../myexception/SCClassException.java | 2 +- .../dhbwstuttgart/myexception/SCExcept.java | 2 +- .../myexception/SCException.java | 2 +- src/de/dhbwstuttgart/parser/JavaLexer.java | 2 +- src/de/dhbwstuttgart/parser/JavaLexer.lex | 2 +- src/de/dhbwstuttgart/parser/JavaParser.java | 38 ++++++------ src/de/dhbwstuttgart/parser/JavaParser.jay | 40 ++++++------- src/de/dhbwstuttgart/syntaxtree/Class.java | 2 +- .../dhbwstuttgart/syntaxtree/ClassBody.java | 2 +- .../syntaxtree/FormalParameter.java | 2 +- src/de/dhbwstuttgart/syntaxtree/Method.java | 2 +- .../dhbwstuttgart/syntaxtree/SourceFile.java | 13 ++-- .../dhbwstuttgart/syntaxtree/misc/DeclId.java | 2 +- .../syntaxtree/statement/Assign.java | 2 +- .../syntaxtree/statement/Binary.java | 2 +- .../syntaxtree/statement/Block.java | 2 +- .../syntaxtree/statement/BoolLiteral.java | 2 +- .../syntaxtree/statement/CastExpr.java | 2 +- .../syntaxtree/statement/CharLiteral.java | 2 +- .../syntaxtree/statement/DoubleLiteral.java | 2 +- .../syntaxtree/statement/EmptyStmt.java | 2 +- .../syntaxtree/statement/ExprStmt.java | 2 +- .../syntaxtree/statement/FloatLiteral.java | 2 +- .../syntaxtree/statement/ForStmt.java | 2 +- .../syntaxtree/statement/IfStmt.java | 2 +- .../syntaxtree/statement/InstVar.java | 2 +- .../syntaxtree/statement/InstanceOf.java | 2 +- .../syntaxtree/statement/IntLiteral.java | 2 +- .../syntaxtree/statement/LocalOrFieldVar.java | 2 +- .../syntaxtree/statement/LocalVarDecl.java | 4 +- .../syntaxtree/statement/LongLiteral.java | 2 +- .../syntaxtree/statement/MethodCall.java | 2 +- .../syntaxtree/statement/NegativeExpr.java | 2 +- .../syntaxtree/statement/NewArray.java | 2 +- .../syntaxtree/statement/NewClass.java | 2 +- .../syntaxtree/statement/NotExpr.java | 2 +- .../syntaxtree/statement/Null.java | 2 +- .../syntaxtree/statement/PositivExpr.java | 2 +- .../syntaxtree/statement/PostDecExpr.java | 2 +- .../syntaxtree/statement/PostIncExpr.java | 2 +- .../syntaxtree/statement/PreDecExpr.java | 2 +- .../syntaxtree/statement/PreIncExpr.java | 2 +- .../syntaxtree/statement/Receiver.java | 2 +- .../syntaxtree/statement/Return.java | 2 +- .../syntaxtree/statement/StringLiteral.java | 2 +- .../syntaxtree/statement/This.java | 2 +- .../syntaxtree/statement/WhileStmt.java | 2 +- .../syntaxtree/type/ParaList.java | 2 +- .../syntaxtree/type/RefType.java | 2 +- .../dhbwstuttgart/syntaxtree/type/Void.java | 6 ++ .../typeinference/ConstraintsSet.java | 19 ++++++ .../typeinference/OderConstraint.java | 15 +++-- .../typeinference/UndConstraint.java | 10 ++++ .../typedeployment/TypeInsertSet.java | 2 +- .../typeinference/unify/CSubstitution.java | 2 +- .../typeinference/unify/Unifier.java | 2 +- .../typeinference/unify/Unify.java | 6 +- test/log4jTesting.xml | 4 +- test/mycompiler/test/AllTests.java | 2 +- test/mycompiler/test/Log4jWrapper.java | 2 +- .../TestInferenceOwnTypeByMethodCall.java | 2 +- .../typeReconstructionTest/TrMakeFCTest.java | 4 +- .../TrSubUnifyTest.java | 4 +- .../typeReconstructionTest/TrUnifyTest.java | 2 +- test/plugindevelopment/TypeInsertTester.java | 10 ++-- 84 files changed, 242 insertions(+), 141 deletions(-) create mode 100644 src/de/dhbwstuttgart/logger/Logger.java diff --git a/.classpath b/.classpath index 822c05c8..46d57734 100755 --- a/.classpath +++ b/.classpath @@ -4,7 +4,6 @@ - diff --git a/bin/.gitignore b/bin/.gitignore index 8c252d62..f1735d3a 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,4 +1,3 @@ /de/ /mycompiler/ -/syntaxTree/ /plugindevelopment/ diff --git a/bin/log4j.xml b/bin/log4j.xml index 41480fbd..64e7c5db 100755 --- a/bin/log4j.xml +++ b/bin/log4j.xml @@ -3,10 +3,10 @@ - + - + diff --git a/bin/log4jTesting.xml b/bin/log4jTesting.xml index 642079a3..dc30c245 100755 --- a/bin/log4jTesting.xml +++ b/bin/log4jTesting.xml @@ -3,10 +3,10 @@ - + - + diff --git a/log4j.xml b/log4j.xml index 41480fbd..64e7c5db 100755 --- a/log4j.xml +++ b/log4j.xml @@ -3,10 +3,10 @@ - + - + diff --git a/src/de/dhbwstuttgart/bytecode/Attribute.java b/src/de/dhbwstuttgart/bytecode/Attribute.java index 57998779..a7e33972 100755 --- a/src/de/dhbwstuttgart/bytecode/Attribute.java +++ b/src/de/dhbwstuttgart/bytecode/Attribute.java @@ -7,9 +7,10 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; -import org.apache.log4j.Logger; // ino.end + +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.JVMCodeException; // ino.class.Attribute.21446.declaration diff --git a/src/de/dhbwstuttgart/bytecode/CPInfo.java b/src/de/dhbwstuttgart/bytecode/CPInfo.java index a3591b64..425011a2 100755 --- a/src/de/dhbwstuttgart/bytecode/CPInfo.java +++ b/src/de/dhbwstuttgart/bytecode/CPInfo.java @@ -7,7 +7,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; + // ino.end // ino.class.CPInfo.22026.declaration diff --git a/src/de/dhbwstuttgart/bytecode/ClassFile.java b/src/de/dhbwstuttgart/bytecode/ClassFile.java index ba7de8e5..d5165110 100755 --- a/src/de/dhbwstuttgart/bytecode/ClassFile.java +++ b/src/de/dhbwstuttgart/bytecode/ClassFile.java @@ -12,8 +12,6 @@ import java.io.IOException; import java.io.OutputStream; import java.lang.reflect.Array; import java.util.Vector; - -import org.apache.log4j.Logger; // ino.end @@ -23,7 +21,9 @@ import org.apache.log4j.Logger; + import de.dhbwstuttgart.core.MyCompiler; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.Interface; import de.dhbwstuttgart.syntaxtree.ParameterList; diff --git a/src/de/dhbwstuttgart/bytecode/CodeAttribute.java b/src/de/dhbwstuttgart/bytecode/CodeAttribute.java index d8a6dfdf..6cff7bc5 100755 --- a/src/de/dhbwstuttgart/bytecode/CodeAttribute.java +++ b/src/de/dhbwstuttgart/bytecode/CodeAttribute.java @@ -16,7 +16,6 @@ import java.util.Vector; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.type.Type; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; // ino.class.CodeAttribute.21681.declaration public class CodeAttribute extends Attribute diff --git a/src/de/dhbwstuttgart/bytecode/ExceptionTable.java b/src/de/dhbwstuttgart/bytecode/ExceptionTable.java index 8c5dbe48..7d22e35f 100755 --- a/src/de/dhbwstuttgart/bytecode/ExceptionTable.java +++ b/src/de/dhbwstuttgart/bytecode/ExceptionTable.java @@ -7,7 +7,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; // ino.end // ino.class.ExceptionTable.22047.declaration diff --git a/src/de/dhbwstuttgart/bytecode/FieldInfo.java b/src/de/dhbwstuttgart/bytecode/FieldInfo.java index 9347bb60..1118e3ba 100755 --- a/src/de/dhbwstuttgart/bytecode/FieldInfo.java +++ b/src/de/dhbwstuttgart/bytecode/FieldInfo.java @@ -8,7 +8,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; // ino.end import de.dhbwstuttgart.myexception.JVMCodeException; diff --git a/src/de/dhbwstuttgart/bytecode/JVMCode.java b/src/de/dhbwstuttgart/bytecode/JVMCode.java index 1966ae88..24f9b23f 100755 --- a/src/de/dhbwstuttgart/bytecode/JVMCode.java +++ b/src/de/dhbwstuttgart/bytecode/JVMCode.java @@ -4,7 +4,7 @@ package de.dhbwstuttgart.bytecode; // ino.module.JVMCode.8547.import import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; // ino.end diff --git a/src/de/dhbwstuttgart/bytecode/Key.java b/src/de/dhbwstuttgart/bytecode/Key.java index 77df160e..6f4eee5b 100755 --- a/src/de/dhbwstuttgart/bytecode/Key.java +++ b/src/de/dhbwstuttgart/bytecode/Key.java @@ -6,7 +6,7 @@ package de.dhbwstuttgart.bytecode; import java.io.FileOutputStream; import java.io.OutputStream; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; // ino.end // ino.class.Key.22890.declaration diff --git a/src/de/dhbwstuttgart/bytecode/MethodInfo.java b/src/de/dhbwstuttgart/bytecode/MethodInfo.java index a083b106..ef2f9163 100755 --- a/src/de/dhbwstuttgart/bytecode/MethodInfo.java +++ b/src/de/dhbwstuttgart/bytecode/MethodInfo.java @@ -8,7 +8,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; // ino.end import de.dhbwstuttgart.myexception.JVMCodeException; diff --git a/src/de/dhbwstuttgart/bytecode/SignatureInfo.java b/src/de/dhbwstuttgart/bytecode/SignatureInfo.java index cb434597..c7fa7873 100755 --- a/src/de/dhbwstuttgart/bytecode/SignatureInfo.java +++ b/src/de/dhbwstuttgart/bytecode/SignatureInfo.java @@ -8,7 +8,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; // ino.end diff --git a/src/de/dhbwstuttgart/core/AClassOrInterface.java b/src/de/dhbwstuttgart/core/AClassOrInterface.java index ab9f8a06..cf3ba515 100755 --- a/src/de/dhbwstuttgart/core/AClassOrInterface.java +++ b/src/de/dhbwstuttgart/core/AClassOrInterface.java @@ -6,7 +6,7 @@ package de.dhbwstuttgart.core; // ino.module.AClassOrInterface.8526.import import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; // ino.end diff --git a/src/de/dhbwstuttgart/core/ConsoleInterface.java b/src/de/dhbwstuttgart/core/ConsoleInterface.java index 576077d7..742f0fe6 100755 --- a/src/de/dhbwstuttgart/core/ConsoleInterface.java +++ b/src/de/dhbwstuttgart/core/ConsoleInterface.java @@ -5,8 +5,7 @@ import static org.junit.Assert.fail; import java.util.*; -import org.apache.log4j.Logger; -import org.apache.log4j.varia.NullAppender; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; @@ -21,7 +20,7 @@ public class ConsoleInterface { for(String file : args){ filenames.add(file); } - Logger.getRootLogger().addAppender(new NullAppender()); // sämtliches Logging unterdrücken + Logger.setOutput(null); // sämtliches Logging unterdrücken run(filenames); } diff --git a/src/de/dhbwstuttgart/core/MyCompiler.java b/src/de/dhbwstuttgart/core/MyCompiler.java index f6f1c363..7ec12f3b 100755 --- a/src/de/dhbwstuttgart/core/MyCompiler.java +++ b/src/de/dhbwstuttgart/core/MyCompiler.java @@ -13,8 +13,7 @@ import java.io.Reader; import java.io.StringReader; import java.util.Vector; -import org.apache.log4j.Logger; -import org.apache.log4j.xml.DOMConfigurator; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; diff --git a/src/de/dhbwstuttgart/logger/Logger.java b/src/de/dhbwstuttgart/logger/Logger.java new file mode 100644 index 00000000..a640ae55 --- /dev/null +++ b/src/de/dhbwstuttgart/logger/Logger.java @@ -0,0 +1,59 @@ +package de.dhbwstuttgart.logger; + +import java.io.PrintStream; +import java.util.HashMap; + +public class Logger { + + private static PrintStream standardOutput; + private static final HashMap LOGGER_DIRECTORY = new HashMap<>(); + + private String name; + private PrintStream output; + + private Logger(String name, PrintStream output) { + this.name = name; + this.output = output; + } + + public void debug(String message){ + output(message); + } + + public static Logger getLogger(String name) { + Logger ret; + if(LOGGER_DIRECTORY.containsKey(name)){ + ret = LOGGER_DIRECTORY.get(name); + }else{ + ret = new Logger(name, standardOutput); + LOGGER_DIRECTORY.put(name, ret); + } + return ret; + } + + private void output(String msg){ + if(output != null){ + output.println(msg); + }else if(standardOutput != null){ + standardOutput.println(msg); + } + } + + public void info(String string) { + // TODO Auto-generated method stub + + } + + public void error(String string) { + // TODO Auto-generated method stub + + } + + /** + * wird hier null übergeben, so wird sämtliches Logging unterdrückt. + */ + public static void setStandardOutput(PrintStream outputStream) { + Logger.standardOutput = outputStream; + } + +} diff --git a/src/de/dhbwstuttgart/myexception/SCClassException.java b/src/de/dhbwstuttgart/myexception/SCClassException.java index 03ed35ee..c6d87741 100755 --- a/src/de/dhbwstuttgart/myexception/SCClassException.java +++ b/src/de/dhbwstuttgart/myexception/SCClassException.java @@ -4,7 +4,7 @@ package de.dhbwstuttgart.myexception; // ino.module.SCClassException.8576.import import java.util.Enumeration; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; // ino.end diff --git a/src/de/dhbwstuttgart/myexception/SCExcept.java b/src/de/dhbwstuttgart/myexception/SCExcept.java index fd5d6ba8..e8ad93d5 100755 --- a/src/de/dhbwstuttgart/myexception/SCExcept.java +++ b/src/de/dhbwstuttgart/myexception/SCExcept.java @@ -3,7 +3,7 @@ package de.dhbwstuttgart.myexception; // ino.end // ino.module.SCExcept.8577.import -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; // ino.end // ino.class.SCExcept.23838.declaration diff --git a/src/de/dhbwstuttgart/myexception/SCException.java b/src/de/dhbwstuttgart/myexception/SCException.java index d996cc66..9c96f2bd 100755 --- a/src/de/dhbwstuttgart/myexception/SCException.java +++ b/src/de/dhbwstuttgart/myexception/SCException.java @@ -4,7 +4,7 @@ package de.dhbwstuttgart.myexception; // ino.module.SCException.8578.import import java.util.Enumeration; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; // ino.end diff --git a/src/de/dhbwstuttgart/parser/JavaLexer.java b/src/de/dhbwstuttgart/parser/JavaLexer.java index 4c5ccab1..788641ac 100644 --- a/src/de/dhbwstuttgart/parser/JavaLexer.java +++ b/src/de/dhbwstuttgart/parser/JavaLexer.java @@ -1291,7 +1291,7 @@ public class JavaLexer { case -37: break; case 37: - {org.apache.log4j.Logger.getLogger("parser").debug("Kommentar: "+yytext());} + {de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("Kommentar: "+yytext());} case -38: break; case 38: diff --git a/src/de/dhbwstuttgart/parser/JavaLexer.lex b/src/de/dhbwstuttgart/parser/JavaLexer.lex index 60f3806e..9df37ace 100755 --- a/src/de/dhbwstuttgart/parser/JavaLexer.lex +++ b/src/de/dhbwstuttgart/parser/JavaLexer.lex @@ -167,7 +167,7 @@ null { //">>=" {this.token = new Token(JavaParser.SIGNEDSHIFTRIGHTEQUAL, yytext(), yyline, yychar);return true;} //">>>=" {this.token = new Token(JavaParser.UNSIGNEDSHIFTRIGHTEQUAL, yytext(), yyline, yychar);return true;} {ws}|\n { /* System.out.print(yytext()); */ } -\\.\n {org.apache.log4j.Logger.getLogger("parser").debug("Kommentar: "+yytext());} +\\.\n {de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("Kommentar: "+yytext());} "->" {this.token = new Token(JavaParser.LAMBDAASSIGNMENT, yytext(), yyline, yychar);return true;} diff --git a/src/de/dhbwstuttgart/parser/JavaParser.java b/src/de/dhbwstuttgart/parser/JavaParser.java index 4968adaf..8ab37814 100644 --- a/src/de/dhbwstuttgart/parser/JavaParser.java +++ b/src/de/dhbwstuttgart/parser/JavaParser.java @@ -978,7 +978,7 @@ case 36: pl.getParalist().addElement(new GenericTypeVar(((Token)yyVals[0+yyTop]).getLexem(),null, ((Token)yyVals[0+yyTop]).getOffset())); /*pl.getParalist().addElement( new TypePlaceholder($1.getLexem()) );*/ /* ########################################################### */ - org.apache.log4j.Logger.getLogger("parser").debug( "IDENTIFIER --> Paralist f�r " + ((Token)yyVals[0+yyTop]).getLexem() + " TV"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug( "IDENTIFIER --> Paralist f�r " + ((Token)yyVals[0+yyTop]).getLexem() + " TV"); yyVal = pl; } break; @@ -989,7 +989,7 @@ case 37: RefType t = new RefType( ((Token)yyVals[-3+yyTop]).getLexem(),null,((Token)yyVals[-3+yyTop]).getOffset() ); t.set_ParaList( ((ParaList)yyVals[-1+yyTop]).get_ParaList() ); pl.getParalist().addElement(t); - org.apache.log4j.Logger.getLogger("parser").debug( "IDENTIFIER '<' paralist '>' --> Paralist f�r " + ((Token)yyVals[-3+yyTop]).getLexem() + ": RefType"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug( "IDENTIFIER '<' paralist '>' --> Paralist f�r " + ((Token)yyVals[-3+yyTop]).getLexem() + ": RefType"); yyVal = pl; } break; @@ -1010,8 +1010,8 @@ case 39: ((ParaList)yyVals[-2+yyTop]).getParalist().addElement(new GenericTypeVar(((Token)yyVals[0+yyTop]).getLexem(), null,((Token)yyVals[0+yyTop]).getOffset())); /*$1.getParalist().addElement(new TypePlaceholder($3.getLexem()));*/ /* ########################################################### */ - org.apache.log4j.Logger.getLogger("parser").debug( "paralist ',' IDENTIFIER --> Paralist f�r " + ((Token)yyVals[0+yyTop]).getLexem() + ": TV"); - org.apache.log4j.Logger.getLogger("parser").debug( "paralist: " + ((ParaList)yyVals[-2+yyTop]).getParalist()); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug( "paralist ',' IDENTIFIER --> Paralist f�r " + ((Token)yyVals[0+yyTop]).getLexem() + ": TV"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug( "paralist: " + ((ParaList)yyVals[-2+yyTop]).getParalist()); yyVal=((ParaList)yyVals[-2+yyTop]); } break; @@ -1021,7 +1021,7 @@ case 40: RefType t = new RefType( ((Token)yyVals[-3+yyTop]).getLexem(),null ,((Token)yyVals[-3+yyTop]).getOffset() ); t.set_ParaList( ((ParaList)yyVals[-1+yyTop]).get_ParaList() ); ((ParaList)yyVals[-5+yyTop]).getParalist().addElement(t); - org.apache.log4j.Logger.getLogger("parser").debug( "paralist ',' IDENTIFIER '<' paralist '>' --> Paralist f�r " + ((Token)yyVals[-3+yyTop]).getLexem() + ": RefType"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug( "paralist ',' IDENTIFIER '<' paralist '>' --> Paralist f�r " + ((Token)yyVals[-3+yyTop]).getLexem() + ": RefType"); yyVal=((ParaList)yyVals[-5+yyTop]); } break; @@ -1423,7 +1423,7 @@ case 93: case 94: // line 875 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { - org.apache.log4j.Logger.getLogger("parser").debug("T->Parser->fielddeclaration ...: type " + ((Type)yyVals[-2+yyTop])); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("T->Parser->fielddeclaration ...: type " + ((Type)yyVals[-2+yyTop])); ((FieldDeclaration)yyVals[-1+yyTop]).setType(((Type)yyVals[-2+yyTop])); yyVal = ((FieldDeclaration)yyVals[-1+yyTop]); } @@ -1955,7 +1955,7 @@ case 155: case 156: // line 1316 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { - org.apache.log4j.Logger.getLogger("parser").debug("T->Parser->referenctype: " + ((UsedId)yyVals[0+yyTop])); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("T->Parser->referenctype: " + ((UsedId)yyVals[0+yyTop])); RefType RT = new RefType(null,((UsedId)yyVals[0+yyTop]).getOffset()); /*ausgetauscht PL 05-07-30*/ @@ -2002,7 +2002,7 @@ case 160: case 161: // line 1393 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { - org.apache.log4j.Logger.getLogger("parser").debug("\nFunktionsdeklaration mit typlosen Parametern: " + ((DeclId)yyVals[0+yyTop]).name); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("\nFunktionsdeklaration mit typlosen Parametern: " + ((DeclId)yyVals[0+yyTop]).name); FormalParameter FP = new FormalParameter(((DeclId)yyVals[0+yyTop])); @@ -2011,7 +2011,7 @@ case 161: /*Type T = TypePlaceholder.fresh(); //auskommentiert von Andreas Stadelmeier*/ /* Type T = new TypePlaceholder(""); /* otth: Name wird automatisch berechnet * /*/ /* ###########################################################*/ - /*org.apache.log4j.Logger.getLogger("parser").debug("\n--> berechneter Name: " + T.getName());*/ + /*de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("\n--> berechneter Name: " + T.getName());*/ /*auskommentiert von Andreas Stadelmeier (a10023) FP.setType( T );*/ /*FP.set_DeclId($1);*/ @@ -2132,7 +2132,7 @@ case 176: case 177: // line 1500 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { - org.apache.log4j.Logger.getLogger("parser").debug("P -> Lokale Variable angelegt!"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("P -> Lokale Variable angelegt!"); LocalVarDecl LVD = new LocalVarDecl(((Type)yyVals[-1+yyTop]).getOffset(),((Type)yyVals[-1+yyTop]).getVariableLength()); LVD.setType(((Type)yyVals[-1+yyTop])); LVD.setDeclidVector(((FieldDeclaration)yyVals[0+yyTop]).getDeclIdVector()); @@ -2142,7 +2142,7 @@ case 177: case 178: // line 1511 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { - org.apache.log4j.Logger.getLogger("parser").debug("P -> Lokale Variable angelegt!"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("P -> Lokale Variable angelegt!"); LocalVarDecl LVD = new LocalVarDecl(((FieldDeclaration)yyVals[0+yyTop]).getOffset(),((FieldDeclaration)yyVals[0+yyTop]).getVariableLength()); /*auskommentiert von Andreas Stadelmeier (a10023) LVD.setType(TypePlaceholder.fresh());*/ LVD.setDeclidVector(((FieldDeclaration)yyVals[0+yyTop]).getDeclIdVector()); @@ -2296,7 +2296,7 @@ case 193: case 194: // line 1650 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { - org.apache.log4j.Logger.getLogger("parser").debug("conditionalexpression"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("conditionalexpression"); yyVal=((Expr)yyVals[0+yyTop]); } break; @@ -2361,7 +2361,7 @@ case 203: case 204: // line 1703 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { - org.apache.log4j.Logger.getLogger("parser").debug("\nParser --> Zuweisung1!\n"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("\nParser --> Zuweisung1!\n"); Assign Ass = new Assign(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength()); LocalOrFieldVar LOFV = new LocalOrFieldVar(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength()); LOFV.set_UsedId(((UsedId)yyVals[-2+yyTop])); @@ -2369,7 +2369,7 @@ case 204: /*auskommentiert von Andreas Stadelmeier (a10023) Ass.setType(TypePlaceholder.fresh());*/ if( ((Operator)yyVals[-1+yyTop]) == null ) { - org.apache.log4j.Logger.getLogger("parser").debug("\nParser --> Zuweisung1 --> " + ((Expr)yyVals[0+yyTop]) + " \n"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("\nParser --> Zuweisung1 --> " + ((Expr)yyVals[0+yyTop]) + " \n"); Ass.set_Expr( LOFV,((Expr)yyVals[0+yyTop]) ); } else @@ -2378,7 +2378,7 @@ case 204: Bin.set_Expr1(LOFV); Bin.set_Operator(((Operator)yyVals[-1+yyTop])); Bin.set_Expr2(((Expr)yyVals[0+yyTop])); - org.apache.log4j.Logger.getLogger("parser").debug("\nParser --> Zuweisung1 --> Binary\n"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("\nParser --> Zuweisung1 --> Binary\n"); /*auskommentiert von Andreas Stadelmeier (a10023) Bin.setType(TypePlaceholder.fresh());*/ Ass.set_Expr( LOFV, Bin ); } @@ -2608,7 +2608,7 @@ case 232: case 233: // line 1933 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { - org.apache.log4j.Logger.getLogger("parser").debug("M1"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("M1"); MethodCall MC = new MethodCall(((UsedId)yyVals[-2+yyTop]).getOffset(),((UsedId)yyVals[-2+yyTop]).getVariableLength()); UsedId udidmeth = new UsedId(((UsedId)yyVals[-2+yyTop]).getOffset()); udidmeth.set_Name((String)((((UsedId)yyVals[-2+yyTop]).get_Name()).elementAt(((UsedId)yyVals[-2+yyTop]).get_Name().size()-1))); @@ -2640,7 +2640,7 @@ case 233: case 234: // line 1963 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { - org.apache.log4j.Logger.getLogger("parser").debug("M2"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("M2"); MethodCall MCarg = new MethodCall(((UsedId)yyVals[-3+yyTop]).getOffset(),((UsedId)yyVals[-3+yyTop]).getVariableLength()); UsedId udidmeth = new UsedId(((UsedId)yyVals[-3+yyTop]).getOffset()); udidmeth.set_Name((String)((((UsedId)yyVals[-3+yyTop]).get_Name()).elementAt(((UsedId)yyVals[-3+yyTop]).get_Name().size()-1))); @@ -2673,7 +2673,7 @@ case 234: case 235: // line 1994 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { - org.apache.log4j.Logger.getLogger("parser").debug("M3"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("M3"); MethodCall MCpr = new MethodCall(((Expr)yyVals[-4+yyTop]).getOffset(),((Expr)yyVals[-4+yyTop]).getVariableLength()); /* PL 05-08-21 primary ist kein UsedId*/ @@ -2694,7 +2694,7 @@ case 235: case 236: // line 2013 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { - org.apache.log4j.Logger.getLogger("parser").debug("M4"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("M4"); MethodCall MCPA = new MethodCall(((Expr)yyVals[-5+yyTop]).getOffset(),((Expr)yyVals[-5+yyTop]).getVariableLength()); /* PL 05-08-21 primary ist kein UsedId*/ diff --git a/src/de/dhbwstuttgart/parser/JavaParser.jay b/src/de/dhbwstuttgart/parser/JavaParser.jay index 23de6cbf..80d2bd39 100755 --- a/src/de/dhbwstuttgart/parser/JavaParser.jay +++ b/src/de/dhbwstuttgart/parser/JavaParser.jay @@ -486,7 +486,7 @@ paralist : IDENTIFIER pl.getParalist().addElement(new GenericTypeVar($1.getLexem(),null, $1.getOffset())); //pl.getParalist().addElement( new TypePlaceholder($1.getLexem()) ); /* ########################################################### */ - org.apache.log4j.Logger.getLogger("parser").debug( "IDENTIFIER --> Paralist f�r " + $1.getLexem() + " TV"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug( "IDENTIFIER --> Paralist f�r " + $1.getLexem() + " TV"); $$ = pl; } | IDENTIFIER '<' paralist '>' @@ -495,7 +495,7 @@ paralist : IDENTIFIER RefType t = new RefType( $1.getLexem(),null,$1.getOffset() ); t.set_ParaList( $3.get_ParaList() ); pl.getParalist().addElement(t); - org.apache.log4j.Logger.getLogger("parser").debug( "IDENTIFIER '<' paralist '>' --> Paralist f�r " + $1.getLexem() + ": RefType"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug( "IDENTIFIER '<' paralist '>' --> Paralist f�r " + $1.getLexem() + ": RefType"); $$ = pl; } | wildcardparameter @@ -512,8 +512,8 @@ paralist : IDENTIFIER $1.getParalist().addElement(new GenericTypeVar($3.getLexem(), null,$3.getOffset())); //$1.getParalist().addElement(new TypePlaceholder($3.getLexem())); /* ########################################################### */ - org.apache.log4j.Logger.getLogger("parser").debug( "paralist ',' IDENTIFIER --> Paralist f�r " + $3.getLexem() + ": TV"); - org.apache.log4j.Logger.getLogger("parser").debug( "paralist: " + $1.getParalist()); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug( "paralist ',' IDENTIFIER --> Paralist f�r " + $3.getLexem() + ": TV"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug( "paralist: " + $1.getParalist()); $$=$1; } @@ -522,7 +522,7 @@ paralist : IDENTIFIER RefType t = new RefType( $3.getLexem(),null ,$3.getOffset() ); t.set_ParaList( $5.get_ParaList() ); $1.getParalist().addElement(t); - org.apache.log4j.Logger.getLogger("parser").debug( "paralist ',' IDENTIFIER '<' paralist '>' --> Paralist f�r " + $3.getLexem() + ": RefType"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug( "paralist ',' IDENTIFIER '<' paralist '>' --> Paralist f�r " + $3.getLexem() + ": RefType"); $$=$1; } | paralist ',' wildcardparameter @@ -873,7 +873,7 @@ fielddeclaration : type fielddeclarator ';' | type variabledeclarators ';' { - org.apache.log4j.Logger.getLogger("parser").debug("T->Parser->fielddeclaration ...: type " + $1); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("T->Parser->fielddeclaration ...: type " + $1); $2.setType($1); $$ = $2; } @@ -1314,7 +1314,7 @@ referencelongtype : typename parameter referencetype :classorinterfacetype { - org.apache.log4j.Logger.getLogger("parser").debug("T->Parser->referenctype: " + $1); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("T->Parser->referenctype: " + $1); RefType RT = new RefType(null,$1.getOffset()); //ausgetauscht PL 05-07-30 @@ -1385,13 +1385,13 @@ formalparameter : type variabledeclaratorid //FP.set_DeclId($5); $$=FP; - org.apache.log4j.Logger.getLogger("parser").debug("P->Polymorphes Methodenargument hinzugefuegt: Name = " + $5.get_Name() + " Typ = " + $1.getName()); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("P->Polymorphes Methodenargument hinzugefuegt: Name = " + $5.get_Name() + " Typ = " + $1.getName()); } */ | variabledeclaratorid { - org.apache.log4j.Logger.getLogger("parser").debug("\nFunktionsdeklaration mit typlosen Parametern: " + $1.name); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("\nFunktionsdeklaration mit typlosen Parametern: " + $1.name); FormalParameter FP = new FormalParameter($1); @@ -1400,7 +1400,7 @@ formalparameter : type variabledeclaratorid //Type T = TypePlaceholder.fresh(); //auskommentiert von Andreas Stadelmeier // Type T = new TypePlaceholder(""); /* otth: Name wird automatisch berechnet */ // ########################################################### - //org.apache.log4j.Logger.getLogger("parser").debug("\n--> berechneter Name: " + T.getName()); + //de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("\n--> berechneter Name: " + T.getName()); //auskommentiert von Andreas Stadelmeier (a10023) FP.setType( T ); //FP.set_DeclId($1); @@ -1498,7 +1498,7 @@ integraltype :INT localvariabledeclaration : type variabledeclarators { - org.apache.log4j.Logger.getLogger("parser").debug("P -> Lokale Variable angelegt!"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("P -> Lokale Variable angelegt!"); LocalVarDecl LVD = new LocalVarDecl($1.getOffset(),$1.getVariableLength()); LVD.setType($1); LVD.setDeclidVector($2.getDeclIdVector()); @@ -1509,7 +1509,7 @@ localvariabledeclaration : type variabledeclarators /* ########################################################### */ |variabledeclarators { - org.apache.log4j.Logger.getLogger("parser").debug("P -> Lokale Variable angelegt!"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("P -> Lokale Variable angelegt!"); LocalVarDecl LVD = new LocalVarDecl($1.getOffset(),$1.getVariableLength()); //auskommentiert von Andreas Stadelmeier (a10023) LVD.setType(TypePlaceholder.fresh()); LVD.setDeclidVector($1.getDeclIdVector()); @@ -1648,7 +1648,7 @@ forstatement assignmentexpression : conditionalexpression { - org.apache.log4j.Logger.getLogger("parser").debug("conditionalexpression"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("conditionalexpression"); $$=$1; } | assignment @@ -1701,7 +1701,7 @@ conditionalexpression :conditionalorexpression assignment :lefthandside assignmentoperator assignmentexpression { - org.apache.log4j.Logger.getLogger("parser").debug("\nParser --> Zuweisung1!\n"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("\nParser --> Zuweisung1!\n"); Assign Ass = new Assign($1.getOffset(),$1.getVariableLength()); LocalOrFieldVar LOFV = new LocalOrFieldVar($1.getOffset(),$1.getVariableLength()); LOFV.set_UsedId($1); @@ -1709,7 +1709,7 @@ assignment :lefthandside assignmentoperator assignmentexpr //auskommentiert von Andreas Stadelmeier (a10023) Ass.setType(TypePlaceholder.fresh()); if( $2 == null ) { - org.apache.log4j.Logger.getLogger("parser").debug("\nParser --> Zuweisung1 --> " + $3 + " \n"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("\nParser --> Zuweisung1 --> " + $3 + " \n"); Ass.set_Expr( LOFV,$3 ); } else @@ -1718,7 +1718,7 @@ assignment :lefthandside assignmentoperator assignmentexpr Bin.set_Expr1(LOFV); Bin.set_Operator($2); Bin.set_Expr2($3); - org.apache.log4j.Logger.getLogger("parser").debug("\nParser --> Zuweisung1 --> Binary\n"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("\nParser --> Zuweisung1 --> Binary\n"); //auskommentiert von Andreas Stadelmeier (a10023) Bin.setType(TypePlaceholder.fresh()); Ass.set_Expr( LOFV, Bin ); } @@ -1931,7 +1931,7 @@ postdecrementexpression :postfixexpression DECREMENT methodinvocation: name '(' ')' { - org.apache.log4j.Logger.getLogger("parser").debug("M1"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("M1"); MethodCall MC = new MethodCall($1.getOffset(),$1.getVariableLength()); UsedId udidmeth = new UsedId($1.getOffset()); udidmeth.set_Name((String)(($1.get_Name()).elementAt($1.get_Name().size()-1))); @@ -1961,7 +1961,7 @@ methodinvocation: } | name '('argumentlist')' { - org.apache.log4j.Logger.getLogger("parser").debug("M2"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("M2"); MethodCall MCarg = new MethodCall($1.getOffset(),$1.getVariableLength()); UsedId udidmeth = new UsedId($1.getOffset()); udidmeth.set_Name((String)(($1.get_Name()).elementAt($1.get_Name().size()-1))); @@ -1992,7 +1992,7 @@ methodinvocation: } | primary '.' IDENTIFIER '(' ')' { - org.apache.log4j.Logger.getLogger("parser").debug("M3"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("M3"); MethodCall MCpr = new MethodCall($1.getOffset(),$1.getVariableLength()); // PL 05-08-21 primary ist kein UsedId @@ -2011,7 +2011,7 @@ methodinvocation: } | primary '.' IDENTIFIER '('argumentlist ')' { - org.apache.log4j.Logger.getLogger("parser").debug("M4"); + de.dhbwstuttgart.logger.Logger.getLogger("parser").debug("M4"); MethodCall MCPA = new MethodCall($1.getOffset(),$1.getVariableLength()); // PL 05-08-21 primary ist kein UsedId diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index a33f3d76..65f07318 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -9,7 +9,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.core.AClassOrInterface; import de.dhbwstuttgart.core.IItemWithOffset; diff --git a/src/de/dhbwstuttgart/syntaxtree/ClassBody.java b/src/de/dhbwstuttgart/syntaxtree/ClassBody.java index 3dd79b67..da24d8cd 100755 --- a/src/de/dhbwstuttgart/syntaxtree/ClassBody.java +++ b/src/de/dhbwstuttgart/syntaxtree/ClassBody.java @@ -6,7 +6,7 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java index 47101ad5..d3d67c87 100755 --- a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java +++ b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java @@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree; // ino.module.FormalParameter.8561.import import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index 9b0d5bba..6d8725b8 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -7,7 +7,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.core.IItemWithOffset; diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index f98cf230..d1f45761 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -10,8 +10,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; - +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.core.AClassOrInterface; import de.dhbwstuttgart.core.MyCompiler; @@ -45,6 +44,7 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.unify.FC_TTO; +import de.dhbwstuttgart.typeinference.unify.Unifier; import de.dhbwstuttgart.typeinference.unify.Unify; @@ -691,11 +691,16 @@ public class SourceFile //////////////// //Unmögliche ConstraintsSets aussortieren durch Unifizierung - oderConstraints.filterWrongConstraints((pairs)->{return Unify.unify(pairs,finiteClosure);}); + Unifier unifier = (pairs)->{ + Vector> retValue = new Vector<>(); + retValue = Unify.unify(pairs, finiteClosure); + return retValue;}; + oderConstraints.filterWrongConstraints(unifier); + oderConstraints.unifyUndConstraints(unifier); typinferenzLog.debug("Übriggebliebene Konstraints:\n"+oderConstraints+"\n"); //Die Constraints in Pair's umwandeln (Karthesisches Produkt bilden): Vector> xConstraints = new Vector>();// = oderConstraints.getConstraints(); - for(Vector uC:oderConstraints.getConstraints()){ //mit dem getConstraints-Aufruf wird das Karthesische Produkt erzeugt. + for(Vector uC : oderConstraints.getConstraints()){ //mit dem getConstraints-Aufruf wird das Karthesische Produkt erzeugt. Vector cons = new Vector(); for(UndConstraint undCons:uC){ cons.addAll(undCons.getConstraintPairs()); diff --git a/src/de/dhbwstuttgart/syntaxtree/misc/DeclId.java b/src/de/dhbwstuttgart/syntaxtree/misc/DeclId.java index 7142823c..111c0b53 100755 --- a/src/de/dhbwstuttgart/syntaxtree/misc/DeclId.java +++ b/src/de/dhbwstuttgart/syntaxtree/misc/DeclId.java @@ -4,7 +4,7 @@ package de.dhbwstuttgart.syntaxtree.misc; // ino.module.DeclId.8558.import import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java b/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java index 04bffdb1..96196a5a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java @@ -7,7 +7,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java index b062ff29..0e2934d5 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java @@ -7,7 +7,7 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Block.java b/src/de/dhbwstuttgart/syntaxtree/statement/Block.java index c6780c41..316b7bfe 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Block.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Block.java @@ -7,7 +7,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java index 7bbaf757..dcb75bad 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/BoolLiteral.java @@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; import de.dhbwstuttgart.bytecode.JVMCode; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java index 681a0354..3e087090 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java @@ -6,7 +6,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; import de.dhbwstuttgart.bytecode.JVMCode; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/CharLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/CharLiteral.java index a8b3e8f6..3790bbfc 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/CharLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/CharLiteral.java @@ -4,7 +4,7 @@ package de.dhbwstuttgart.syntaxtree.statement; // ino.module.CharLiteral.8628.import import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; import de.dhbwstuttgart.bytecode.JVMCode; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/DoubleLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/DoubleLiteral.java index 55a3d430..a9b87056 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/DoubleLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/DoubleLiteral.java @@ -6,7 +6,7 @@ import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/EmptyStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/EmptyStmt.java index 24fe0cb0..0d99f419 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/EmptyStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/EmptyStmt.java @@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java index 14451efd..40c30950 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java @@ -6,7 +6,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.core.MyCompiler; import de.dhbwstuttgart.syntaxtree.type.Type; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/FloatLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/FloatLiteral.java index b1e1bb2b..36d1dc5b 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/FloatLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/FloatLiteral.java @@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java index d103c6e8..e8e2e7a4 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java @@ -5,7 +5,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java index 59b31505..8b8ae046 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java @@ -7,7 +7,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java b/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java index 28fa843b..c98496c6 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java @@ -7,7 +7,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java b/src/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java index 79276d89..1f49be5d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java @@ -6,7 +6,7 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/IntLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/IntLiteral.java index d251cd7b..1e13b855 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/IntLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/IntLiteral.java @@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; import de.dhbwstuttgart.bytecode.JVMCode; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java index d773f48c..3266d67a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVar.java @@ -6,7 +6,7 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; import de.dhbwstuttgart.bytecode.JVMCode; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java index 855f9dde..5358a9e2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java @@ -6,7 +6,7 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; @@ -209,7 +209,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable throw ex; } else if(paralist==null && c.get_ParaList().size()>0){ - parserlog.debug(paralist); + parserlog.debug(paralist.toString()); parserlog.debug(c.getName()+" "+c.get_ParaList().size()); SCStatementException ex = new SCStatementException(); SCExcept e = new SCExcept(); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LongLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/LongLiteral.java index 7317255f..c35f333a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LongLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LongLiteral.java @@ -6,7 +6,7 @@ import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java index a2c418d0..d6e596c1 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java @@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java index c83cfe5a..108ec380 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java @@ -6,7 +6,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java b/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java index 94e9af5c..a1f03f3c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java @@ -6,7 +6,7 @@ import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; import de.dhbwstuttgart.bytecode.JVMCode; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java index d279ebff..ce586551 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java @@ -8,7 +8,7 @@ import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; import de.dhbwstuttgart.bytecode.JVMCode; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java index 0b7a2a55..e859441e 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java @@ -6,7 +6,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Null.java b/src/de/dhbwstuttgart/syntaxtree/statement/Null.java index a02121ac..b60060c4 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Null.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Null.java @@ -6,7 +6,7 @@ import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; import de.dhbwstuttgart.bytecode.JVMCode; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java index bea0c19d..4e2ff472 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java @@ -6,7 +6,7 @@ import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; import de.dhbwstuttgart.myexception.CTypeReconstructionException; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java index 99b83e51..2c224f97 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java @@ -6,7 +6,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java index 3837a3aa..02959a14 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java @@ -6,7 +6,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java index a40139a3..778f7491 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java @@ -6,7 +6,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java index 97a5bc0d..51553b2f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java @@ -6,7 +6,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java b/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java index bfe41dd7..8ed2da92 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java @@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Return.java b/src/de/dhbwstuttgart/syntaxtree/statement/Return.java index 865bf1da..d0c13f81 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Return.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Return.java @@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; import de.dhbwstuttgart.bytecode.JVMCode; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java index a1ed579f..63123426 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java @@ -6,7 +6,7 @@ import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; import de.dhbwstuttgart.bytecode.JVMCode; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/This.java b/src/de/dhbwstuttgart/syntaxtree/statement/This.java index 7733b5aa..e7c836fa 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/This.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/This.java @@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; import de.dhbwstuttgart.bytecode.JVMCode; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java index 7649743c..8d1e0ddc 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java @@ -7,7 +7,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.bytecode.CodeAttribute; diff --git a/src/de/dhbwstuttgart/syntaxtree/type/ParaList.java b/src/de/dhbwstuttgart/syntaxtree/type/ParaList.java index efa0b35f..6ac63a02 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/ParaList.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/ParaList.java @@ -3,7 +3,7 @@ package de.dhbwstuttgart.syntaxtree.type; // ino.end // ino.module.ParaList.8674.import import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index ba8178dd..85e4ba2f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -8,7 +8,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.bytecode.JVMCode; import de.dhbwstuttgart.core.IItemWithOffset; diff --git a/src/de/dhbwstuttgart/syntaxtree/type/Void.java b/src/de/dhbwstuttgart/syntaxtree/type/Void.java index 2ef1cd1c..1e58e564 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/Void.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/Void.java @@ -74,5 +74,11 @@ public class Void extends RefType public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent){ return new ConstraintType(this); } + + @Override + public Type checkTYPE(TypeAssumptions ass, SyntaxTreeNode method) { + return this;//VOID ist immer korrekt, das wird vom Parser geprüft + } + } // ino.end diff --git a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java index 4a28b687..13939320 100755 --- a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java +++ b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java @@ -57,4 +57,23 @@ public class ConstraintsSet implements Iterable{ constraint.filterWrongConstraints(unify); } } + + public void unifyUndConstraints(Unifier unifier) { + Vector uCons = this.filterUndConstraints(); + + } + + /** + * Aus dem ConstraintsSet [ u1, u2, ... (OderConstraint), ... uN ] werden alle + * UndConstraints, welche sich nicht innerhalb eines OderConstraints befinden, herausgefiltert + * @return [u1, ... , uN] + */ + private Vector filterUndConstraints() { + Vector ret = new Vector<>(); + for(OderConstraint con : constraintsSet){ + UndConstraint filtered = con.filterUndConstraints(); + if(filtered != null)ret.add(filtered); + } + return ret; + } } diff --git a/src/de/dhbwstuttgart/typeinference/OderConstraint.java b/src/de/dhbwstuttgart/typeinference/OderConstraint.java index 53fd06bb..84f59d6a 100755 --- a/src/de/dhbwstuttgart/typeinference/OderConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/OderConstraint.java @@ -2,7 +2,7 @@ package de.dhbwstuttgart.typeinference; import java.util.Vector; -import de.dhbwstuttgart.logger.TypinferenzLog; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; @@ -11,6 +11,8 @@ import de.dhbwstuttgart.typeinference.unify.Unifier; public class OderConstraint{ private Vector oderConstraintPairs; + private final static Logger logger = Logger.getLogger(OderConstraint.class.getName()); + /** * Erstellt ein neues Oder Constraint und fügt bereits ein Constraint hinzu. * @param p1 @@ -81,16 +83,21 @@ public class OderConstraint{ oderConstraintPairs.add(methodConstraint); } - public void filterWrongConstraints(Unifier unify) { + void filterWrongConstraints(Unifier unifier) { Vector filteredConstraints = new Vector<>(); for(UndConstraint cons : this.getUndConstraints()){ - if(!unify.unify(cons.getConstraintPairs()).isEmpty()){ + Vector> unifierResult = unifier.apply(cons.getConstraintPairs()); + if(!unifierResult.isEmpty()){ filteredConstraints.add(cons); }else{ - TypinferenzLog.debug("Ausgesondertes Constraint: "+cons); + logger.debug("Ausgesondertes Constraint: "+cons); } } this.oderConstraintPairs = filteredConstraints; } + + UndConstraint filterUndConstraints() { + return null; + } } diff --git a/src/de/dhbwstuttgart/typeinference/UndConstraint.java b/src/de/dhbwstuttgart/typeinference/UndConstraint.java index b8f6b9cc..6dd7ec14 100755 --- a/src/de/dhbwstuttgart/typeinference/UndConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/UndConstraint.java @@ -3,6 +3,7 @@ package de.dhbwstuttgart.typeinference; import java.util.Vector; import de.dhbwstuttgart.syntaxtree.type.Type; +import de.dhbwstuttgart.typeinference.unify.Unifier; /** * Stellt ein Constraint dar, welches aus mehreren Constraint-Paaren besteht. Diese gelten alle stets gleichzeitig / sind per "Und" miteinander verknüpft. @@ -36,5 +37,14 @@ public class UndConstraint extends OderConstraint { } return ret+"]"; } + + @Override + void filterWrongConstraints(Unifier unifier) { + //In einem UndConstraint gibt es keine falschen Constraints + } + @Override + UndConstraint filterUndConstraints(){ + return this; + } } diff --git a/src/de/dhbwstuttgart/typeinference/typedeployment/TypeInsertSet.java b/src/de/dhbwstuttgart/typeinference/typedeployment/TypeInsertSet.java index 671a560d..1a34a845 100644 --- a/src/de/dhbwstuttgart/typeinference/typedeployment/TypeInsertSet.java +++ b/src/de/dhbwstuttgart/typeinference/typedeployment/TypeInsertSet.java @@ -5,7 +5,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.core.IItemWithOffset; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; diff --git a/src/de/dhbwstuttgart/typeinference/unify/CSubstitution.java b/src/de/dhbwstuttgart/typeinference/unify/CSubstitution.java index 05cac78e..7e86182c 100755 --- a/src/de/dhbwstuttgart/typeinference/unify/CSubstitution.java +++ b/src/de/dhbwstuttgart/typeinference/unify/CSubstitution.java @@ -6,7 +6,7 @@ package de.dhbwstuttgart.typeinference.unify; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; // ino.end diff --git a/src/de/dhbwstuttgart/typeinference/unify/Unifier.java b/src/de/dhbwstuttgart/typeinference/unify/Unifier.java index 73478957..f51eb9b9 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/Unifier.java +++ b/src/de/dhbwstuttgart/typeinference/unify/Unifier.java @@ -6,6 +6,6 @@ import de.dhbwstuttgart.typeinference.Pair; public interface Unifier { - public Vector> unify (Vector E); + public Vector> apply (Vector E); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/Unify.java b/src/de/dhbwstuttgart/typeinference/unify/Unify.java index 7e3b8221..886226a5 100755 --- a/src/de/dhbwstuttgart/typeinference/unify/Unify.java +++ b/src/de/dhbwstuttgart/typeinference/unify/Unify.java @@ -7,7 +7,7 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import org.apache.log4j.Logger; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.core.MyCompiler; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.MatchException; @@ -128,7 +128,7 @@ public class Unify //WAS PASSIERT MIT EINE PAAR HIER DRIN BLEIBT??? Eq_12.addElement(P); printMenge("Eq_12", Eq_12, 6); - inferencelog.debug(P.OperatorEqual()); + //inferencelog.debug(P.OperatorEqual()); } else if (P.TA1 instanceof BoundedGenericTypeVar && P.TA2 instanceof RefType) { //PL 06-06-13 @@ -224,7 +224,7 @@ public class Unify else ready = false; sigma.addElement(new Pair(r1, r2)); } - inferencelog.debug(ready); + //inferencelog.debug(ready); if (!ready) { printMenge("Sigma", sigma, 6); diff --git a/test/log4jTesting.xml b/test/log4jTesting.xml index 642079a3..dc30c245 100755 --- a/test/log4jTesting.xml +++ b/test/log4jTesting.xml @@ -3,10 +3,10 @@ - + - + diff --git a/test/mycompiler/test/AllTests.java b/test/mycompiler/test/AllTests.java index c793951e..c4e1235a 100755 --- a/test/mycompiler/test/AllTests.java +++ b/test/mycompiler/test/AllTests.java @@ -13,7 +13,7 @@ import mycompiler.test.operators.AllTestsOperators; import mycompiler.test.primitiveTypes.AllTestsPrimitiveTypes; import mycompiler.test.trivial.AllTestsTrivial; -import org.apache.log4j.xml.DOMConfigurator; +import de.dhbwstuttgart.logger.xml.DOMConfigurator; public class AllTests { diff --git a/test/mycompiler/test/Log4jWrapper.java b/test/mycompiler/test/Log4jWrapper.java index 45692360..715dedb2 100755 --- a/test/mycompiler/test/Log4jWrapper.java +++ b/test/mycompiler/test/Log4jWrapper.java @@ -1,6 +1,6 @@ package mycompiler.test; -import org.apache.log4j.xml.DOMConfigurator; +import de.dhbwstuttgart.logger.xml.DOMConfigurator; /** * needed to assure one-time execution of configure script diff --git a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCall.java b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCall.java index fb2bf184..aac98c00 100755 --- a/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCall.java +++ b/test/mycompiler/test/inferenceByCharacteristic/TestInferenceOwnTypeByMethodCall.java @@ -1,6 +1,6 @@ package mycompiler.test.inferenceByCharacteristic; -import org.apache.log4j.xml.DOMConfigurator; +import de.dhbwstuttgart.logger.xml.DOMConfigurator; import de.dhbwstuttgart.syntaxtree.type.RefType; import mycompiler.test.AbstractInferenceTest; diff --git a/test/mycompiler/test/unittest/typeReconstructionTest/TrMakeFCTest.java b/test/mycompiler/test/unittest/typeReconstructionTest/TrMakeFCTest.java index 2863bf1c..ae4f48cd 100755 --- a/test/mycompiler/test/unittest/typeReconstructionTest/TrMakeFCTest.java +++ b/test/mycompiler/test/unittest/typeReconstructionTest/TrMakeFCTest.java @@ -4,8 +4,8 @@ import java.util.Vector; import junit.framework.TestCase; -import org.apache.log4j.Logger; -import org.apache.log4j.xml.DOMConfigurator; +import de.dhbwstuttgart.logger.Logger; +import de.dhbwstuttgart.logger.xml.DOMConfigurator; import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.ClassBody; diff --git a/test/mycompiler/test/unittest/typeReconstructionTest/TrSubUnifyTest.java b/test/mycompiler/test/unittest/typeReconstructionTest/TrSubUnifyTest.java index 537464c6..e9ea300f 100755 --- a/test/mycompiler/test/unittest/typeReconstructionTest/TrSubUnifyTest.java +++ b/test/mycompiler/test/unittest/typeReconstructionTest/TrSubUnifyTest.java @@ -5,8 +5,8 @@ import java.util.Vector; import junit.framework.TestCase; -import org.apache.log4j.Logger; -import org.apache.log4j.xml.DOMConfigurator; +import de.dhbwstuttgart.logger.Logger; +import de.dhbwstuttgart.logger.xml.DOMConfigurator; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; diff --git a/test/mycompiler/test/unittest/typeReconstructionTest/TrUnifyTest.java b/test/mycompiler/test/unittest/typeReconstructionTest/TrUnifyTest.java index 75765509..7a42c8d2 100755 --- a/test/mycompiler/test/unittest/typeReconstructionTest/TrUnifyTest.java +++ b/test/mycompiler/test/unittest/typeReconstructionTest/TrUnifyTest.java @@ -4,7 +4,7 @@ import java.util.Vector; import junit.framework.TestCase; -import org.apache.log4j.xml.DOMConfigurator; +import de.dhbwstuttgart.logger.xml.DOMConfigurator; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/test/plugindevelopment/TypeInsertTester.java b/test/plugindevelopment/TypeInsertTester.java index aba7e5b8..1b2df547 100644 --- a/test/plugindevelopment/TypeInsertTester.java +++ b/test/plugindevelopment/TypeInsertTester.java @@ -10,12 +10,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.Vector; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.FileAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.SimpleLayout; +import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.core.MyCompiler; import de.dhbwstuttgart.core.MyCompilerAPI; @@ -31,11 +26,14 @@ public class TypeInsertTester{ private static Logger inferencelog = Logger.getLogger("Typeinference"); static{ { + Logger.setStandardOutput(System.out); + /* // Ausgabeoptionen fuer die Logger ConsoleAppender logAppender = new ConsoleAppender(new SimpleLayout()); logAppender.setTarget("System.out"); logAppender.activateOptions(); inferencelog.addAppender(logAppender); //Bei den Tests wird der Log auch in System.out geschrieben. + */ } } static final String rootDirectory = System.getProperty("user.dir")+"/test/plugindevelopment/"; From 4e394ae12c6b2761329d146ce3e398b693071f12 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 9 Oct 2014 12:01:41 +0200 Subject: [PATCH 13/16] =?UTF-8?q?Neuer=20Testfall=20angef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TypeInsertTests/LambdaTest25.jav | 8 ++++++++ .../TypeInsertTests/LambdaTest25.java | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/plugindevelopment/TypeInsertTests/LambdaTest25.jav create mode 100644 test/plugindevelopment/TypeInsertTests/LambdaTest25.java diff --git a/test/plugindevelopment/TypeInsertTests/LambdaTest25.jav b/test/plugindevelopment/TypeInsertTests/LambdaTest25.jav new file mode 100644 index 00000000..a499b2bd --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/LambdaTest25.jav @@ -0,0 +1,8 @@ +import java.util.Vector; + +class ImportGeneric { + + m (Vector x) { + return x.elementAt(1); + } +} diff --git a/test/plugindevelopment/TypeInsertTests/LambdaTest25.java b/test/plugindevelopment/TypeInsertTests/LambdaTest25.java new file mode 100644 index 00000000..1737acee --- /dev/null +++ b/test/plugindevelopment/TypeInsertTests/LambdaTest25.java @@ -0,0 +1,16 @@ +package plugindevelopment.TypeInsertTests; + +import java.util.Vector; + +import org.junit.Test; + +public class LambdaTest25 { + private static final String TEST_FILE = "LambdaTest25.jav"; + + @Test + public void run(){ + Vector mustContain = new Vector(); + mustContain.add("Integer m"); + MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain); + } +} From efa79da5d509befca80a38ea76f512c9a881a3bd Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 9 Oct 2014 13:54:44 +0200 Subject: [PATCH 14/16] filterUndConstraints --- src/de/dhbwstuttgart/typeinference/ConstraintsSet.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java index 13939320..c7f052ca 100755 --- a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java +++ b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java @@ -60,6 +60,11 @@ public class ConstraintsSet implements Iterable{ public void unifyUndConstraints(Unifier unifier) { Vector uCons = this.filterUndConstraints(); + Vector alleUndConstraints = new Vector<>(); + for(UndConstraint undConstraint : uCons){ + alleUndConstraints.addAll(undConstraint.getConstraintPairs()); + } + Vector> unifyResult = unifier.apply(alleUndConstraints); } From 1141417c0be3e520100e80d8f86896567fbbd538 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 9 Oct 2014 17:38:10 +0200 Subject: [PATCH 15/16] Weitere Aussonderung von Constraints durch Unify --- bin/.gitignore | 2 + .../dhbwstuttgart/core/ConsoleInterface.java | 4 +- src/de/dhbwstuttgart/core/MyCompiler.java | 10 +++-- src/de/dhbwstuttgart/logger/Logger.java | 44 ++++++++++++++----- src/de/dhbwstuttgart/syntaxtree/Class.java | 18 ++++---- .../dhbwstuttgart/syntaxtree/SourceFile.java | 17 +++---- .../syntaxtree/type/RefType.java | 4 +- .../syntaxtree/type/TypePlaceholder.java | 4 +- .../typeinference/ConstraintsSet.java | 20 +++++++-- .../typeinference/OderConstraint.java | 6 ++- src/de/dhbwstuttgart/typeinference/Pair.java | 2 +- .../assumptions/TypeAssumptions.java | 10 ++--- test/plugindevelopment/TypeInsertTester.java | 2 +- 13 files changed, 92 insertions(+), 51 deletions(-) diff --git a/bin/.gitignore b/bin/.gitignore index f1735d3a..8ac1c637 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,3 +1,5 @@ /de/ /mycompiler/ /plugindevelopment/ +/bytecode/ +/parser/ diff --git a/src/de/dhbwstuttgart/core/ConsoleInterface.java b/src/de/dhbwstuttgart/core/ConsoleInterface.java index 742f0fe6..e453b0b1 100755 --- a/src/de/dhbwstuttgart/core/ConsoleInterface.java +++ b/src/de/dhbwstuttgart/core/ConsoleInterface.java @@ -11,7 +11,7 @@ import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; public class ConsoleInterface { private static final String directory = System.getProperty("user.dir"); - + private static final Logger log = Logger.getLogger( ConsoleInterface.class.getName() ); /** * @param args */ @@ -20,7 +20,7 @@ public class ConsoleInterface { for(String file : args){ filenames.add(file); } - Logger.setOutput(null); // sämtliches Logging unterdrücken + Logger.setStandardOutput(null); // sämtliches Logging unterdrücken run(filenames); } diff --git a/src/de/dhbwstuttgart/core/MyCompiler.java b/src/de/dhbwstuttgart/core/MyCompiler.java index 7ec12f3b..375cd684 100755 --- a/src/de/dhbwstuttgart/core/MyCompiler.java +++ b/src/de/dhbwstuttgart/core/MyCompiler.java @@ -66,13 +66,13 @@ public class MyCompiler implements MyCompilerAPI // Logger // ino.end // ino.attribute.codegenlog.21265.declaration - protected static Logger codegenlog = Logger.getLogger("codegen"); + //protected static Logger codegenlog = Logger.getLogger("codegen"); // ino.end // ino.attribute.inferencelog.21268.declaration - protected static Logger inferencelog = Logger.getLogger("inference"); + protected static Logger inferencelog = Logger.getLogger(MyCompiler.class.getName()); // ino.end // ino.attribute.parserlog.21271.declaration - protected static Logger parserlog = Logger.getLogger("parser"); + //protected static Logger parserlog = Logger.getLogger("parser"); // ino.end // ino.attribute.OutputDir.21274.declaration @@ -180,7 +180,7 @@ public class MyCompiler implements MyCompilerAPI } else { - parserlog.error( "SEMANTIK-CHECK-FEHLER: Parameter " + TempParameter.getName() + " muss weitere Parameter besitzen (laut Klassendefinition)" ); + //parserlog.error( "SEMANTIK-CHECK-FEHLER: Parameter " + TempParameter.getName() + " muss weitere Parameter besitzen (laut Klassendefinition)" ); //FIXME Throw exception instead of simple exit System.exit( 1 ); } @@ -512,6 +512,8 @@ public class MyCompiler implements MyCompilerAPI // ino.end // ino.method.typeReconstruction.21304.body { + Logger.setStandardOutput(System.out); //TODO: Hier noch das Log-Level richtig setzen (je nachdem ob debugt wird oder nicht) + if(m_AbstractSyntaxTree==null){ throw new NullPointerException("Es wurde noch kein Abstrakter Syntaxbaum erstellt!"); } diff --git a/src/de/dhbwstuttgart/logger/Logger.java b/src/de/dhbwstuttgart/logger/Logger.java index a640ae55..3003da8e 100644 --- a/src/de/dhbwstuttgart/logger/Logger.java +++ b/src/de/dhbwstuttgart/logger/Logger.java @@ -2,6 +2,7 @@ package de.dhbwstuttgart.logger; import java.io.PrintStream; import java.util.HashMap; +import java.util.logging.Level; public class Logger { @@ -9,17 +10,35 @@ public class Logger { private static final HashMap LOGGER_DIRECTORY = new HashMap<>(); private String name; - private PrintStream output; - + private final java.util.logging.Logger log; + private Logger(String name, PrintStream output) { this.name = name; - this.output = output; + this.log = java.util.logging.Logger.getLogger( name ); + if(output != null)log.addHandler(new OutputHandler(output)); + log.setLevel(Level.FINE); } - public void debug(String message){ - output(message); + /** + * Logt eine Debug Message, welche zusätzlich einer bestimmten Section zugewiesen wird. + * Dadurch lässt sich die DEBUG ausgabe übersichtlicher gestalten. + * @param message + * @param section + */ + public void debug(String message, Section section){ + output(message, Level.FINE); } + public void debug(String message){ + //output(message, Level.FINE); + } + + /** + * Liefert den Logger mit dem angegebenen Namen. + * Üblicherweise wird diese Methode mit dem Namen der Klasse aufgerufen, in welcher der Logger tätig ist. + * @param name - Name der Klasse ( Ermittelbar mittels .class.getName() ) + * @return + */ public static Logger getLogger(String name) { Logger ret; if(LOGGER_DIRECTORY.containsKey(name)){ @@ -31,22 +50,23 @@ public class Logger { return ret; } - private void output(String msg){ + private void output(String msg , Level logLevel){ + log.log(logLevel, msg); + /* if(output != null){ output.println(msg); }else if(standardOutput != null){ standardOutput.println(msg); } + */ } - public void info(String string) { - // TODO Auto-generated method stub - + public void info(String message) { + output(message, Level.INFO); } - public void error(String string) { - // TODO Auto-generated method stub - + public void error(String message) { + output(message, Level.WARNING); } /** diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index 65f07318..a23e235a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -10,7 +10,7 @@ import java.util.Iterator; import java.util.Vector; import de.dhbwstuttgart.logger.Logger; - +import de.dhbwstuttgart.logger.Section; import de.dhbwstuttgart.core.AClassOrInterface; import de.dhbwstuttgart.core.IItemWithOffset; import de.dhbwstuttgart.parser.JavaClassName; @@ -44,8 +44,8 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit * Log4j - Loggerinstanzen */ protected static Logger inferencelog = Logger.getLogger("inference"); - protected static Logger codegenlog = Logger.getLogger("codegen"); - protected static Logger parserlog = Logger.getLogger("parser"); + //protected static Logger codegenlog = Logger.getLogger("codegen"); + //protected static Logger parserlog = Logger.getLogger("parser"); protected UsedId pkgName; protected Modifiers modifiers; protected String name; @@ -137,9 +137,9 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit private TypeAssumptions typeAssumptions = null;//muss mit null Initialisiert werden. Darf nur über getTypeAssumptions abgerufen werden. // ino.attribute.parserlog.23038.declaration - protected Logger parselog = Logger.getLogger("parser"); + //protected Logger parselog = Logger.getLogger("parser"); // ino.end - protected Logger typinferenzLog = Logger.getLogger("Typeinference"); + protected Logger typinferenzLog = Logger.getLogger(Class.class.getName()); private SyntaxTreeNode parent; private Vector fielddecl = new Vector(); private GenericDeclarationList genericClassParameters; @@ -267,7 +267,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } - parserlog.debug("Neue Klasse: " + name); + //parserlog.debug("Neue Klasse: " + name); } // ino.end @@ -658,7 +658,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit ////////////////////////////// inferencelog.info("Rufe TRStart()..."); - typinferenzLog.debug("Erstellte FiniteClosure: "+supportData); + typinferenzLog.debug("Erstellte FiniteClosure: "+supportData, Section.TYPEINFERENCE); ////////////////////////////// // Ab hier ... // @author A10023 - Andreas Stadelmeier: @@ -677,7 +677,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit if(gparam instanceof GenericTypeVar)oderConstraints.add(((GenericTypeVar)gparam).TYPE(assumptions)); //Constraints für die Generischen Variablen erstellen und diese dem AssumptionsSet hinzufügen } - typinferenzLog.debug("Erstellte Assumptions: "+assumptions); + typinferenzLog.debug("Erstellte Assumptions: "+assumptions, Section.TYPEINFERENCE); /* //Generiere Liste mit Expressions, welche zur Initialisierung von Feldern verwendet werden. Vector fieldInitializers = new Vector(); @@ -696,7 +696,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit for(Field f:this.getFields()){ oderConstraints.add(f.TYPE(assumptions)); } - typinferenzLog.debug("Erstellte Constraints: "+oderConstraints); + typinferenzLog.debug("Erstellte Constraints: "+oderConstraints, Section.TYPEINFERENCE); return oderConstraints; diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index d1f45761..59482510 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -11,6 +11,7 @@ import java.util.Iterator; import java.util.Vector; import de.dhbwstuttgart.logger.Logger; +import de.dhbwstuttgart.logger.Section; import de.dhbwstuttgart.bytecode.ClassFile; import de.dhbwstuttgart.core.AClassOrInterface; import de.dhbwstuttgart.core.MyCompiler; @@ -673,12 +674,12 @@ public class SourceFile //Assumptions der importierten Klassen sammeln: TypeAssumptions importAssumptions = this.makeBasicAssumptionsFromJRE(imports, true); globalAssumptions.add(importAssumptions); - typinferenzLog.debug("Von JRE erstellte Assumptions: "+importAssumptions); + typinferenzLog.debug("Von JRE erstellte Assumptions: "+importAssumptions, Section.TYPEINFERENCE); //FiniteClosure generieren: FC_TTO finiteClosure = this.makeFC(globalAssumptions); - typinferenzLog.debug("FiniteClosure: \n"+finiteClosure); + typinferenzLog.debug("FiniteClosure: \n"+finiteClosure, Section.TYPEINFERENCE); ConstraintsSet oderConstraints = new ConstraintsSet(); //Alle Constraints der in dieser SourceFile enthaltenen Klassen sammeln: @@ -697,7 +698,7 @@ public class SourceFile return retValue;}; oderConstraints.filterWrongConstraints(unifier); oderConstraints.unifyUndConstraints(unifier); - typinferenzLog.debug("Übriggebliebene Konstraints:\n"+oderConstraints+"\n"); + typinferenzLog.debug("Übriggebliebene Konstraints:\n"+oderConstraints+"\n", Section.TYPEINFERENCE); //Die Constraints in Pair's umwandeln (Karthesisches Produkt bilden): Vector> xConstraints = new Vector>();// = oderConstraints.getConstraints(); for(Vector uC : oderConstraints.getConstraints()){ //mit dem getConstraints-Aufruf wird das Karthesische Produkt erzeugt. @@ -707,7 +708,7 @@ public class SourceFile } xConstraints.add(cons); } - typinferenzLog.debug("Karthesisches Produkt der Constraints: "+xConstraints); + typinferenzLog.debug("Karthesisches Produkt der Constraints: "+xConstraints, Section.TYPEINFERENCE); finiteClosure.generateFullyNamedTypes(globalAssumptions); @@ -781,7 +782,7 @@ public class SourceFile result.addAll(unifyResult); // Debugoutput:Vector> - typinferenzLog.debug("Unifiziertes Ergebnis: "+result); + typinferenzLog.debug("Unifiziertes Ergebnis: "+result, Section.TYPEINFERENCE); /* // Prüfe ob eindeutige Lösung: @@ -803,7 +804,7 @@ public class SourceFile //typinferenzLog.debug(supportData.getFiniteClosure()); //typinferenzLog.debug("Typinformationen: \n"+this.getTypeInformation(this.getMethodList(), fieldInitializers)); - typinferenzLog.debug("\nJavaFiles:\n"); + typinferenzLog.debug("\nJavaFiles:\n", Section.TYPEINFERENCE); //typinferenzLog.debug(this.printJavaCode(new ResultSet(new Vector()))); @@ -818,8 +819,8 @@ public class SourceFile ret.add(reconstructionResult); //ResultSet res = new ResultSet(resultSet); - typinferenzLog.debug("JavaFile für ResultSet "+reconstructionResult+"\n"); - typinferenzLog.debug(klasse.printJavaCode(reconstructionResult)); + typinferenzLog.debug("JavaFile für ResultSet "+reconstructionResult+"\n", Section.TYPEINFERENCE); + typinferenzLog.debug(klasse.printJavaCode(reconstructionResult), Section.TYPEINFERENCE); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index 85e4ba2f..af50be02 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -56,10 +56,10 @@ public class RefType extends Type implements IMatchable private boolean primitiveFlag=false; // ino.end // ino.attribute.parserlog.26628.declaration - protected static Logger parserlog = Logger.getLogger("parser"); + //protected static Logger parserlog = Logger.getLogger("parser"); // ino.end // ino.attribute.codegenlog.26631.declaration - protected static Logger codegenlog = Logger.getLogger("codegen"); + //protected static Logger codegenlog = Logger.getLogger("codegen"); // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java b/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java index b8b20c44..6f5fb6b3 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java @@ -6,7 +6,7 @@ package de.dhbwstuttgart.syntaxtree.type; import java.util.Hashtable; import java.util.Iterator; import java.util.Vector; -import java.util.logging.Logger; +import de.dhbwstuttgart.logger.*; import de.dhbwstuttgart.core.MyCompiler; import de.dhbwstuttgart.parser.JavaClassName; @@ -31,6 +31,7 @@ public class TypePlaceholder extends Type // ino.end // ino.class.TypePlaceholder.26780.body { + private static final Logger log = Logger.getLogger(TypePlaceholder.class.getName()); // ino.attribute.strNextName.26785.declaration private static String strNextName = "A"; // ino.end @@ -55,6 +56,7 @@ public class TypePlaceholder extends Type { super(parent, -1); this.name = new JavaClassName(typeName); + if(parent != null)log.debug("Erstelle TPH "+typeName+" für SyntaxTreeNode: "+parent, Section.TYPEINFERENCE); } // ino.end diff --git a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java index c7f052ca..f67fb6d0 100755 --- a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java +++ b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java @@ -2,10 +2,12 @@ package de.dhbwstuttgart.typeinference; import java.util.Iterator; import java.util.Vector; - +import de.dhbwstuttgart.logger.Logger; +import de.dhbwstuttgart.logger.*; import de.dhbwstuttgart.typeinference.unify.Unifier; public class ConstraintsSet implements Iterable{ + private static final Logger log = Logger.getLogger(ConstraintsSet.class.getName()); private Vector constraintsSet; public ConstraintsSet(){ @@ -58,14 +60,26 @@ public class ConstraintsSet implements Iterable{ } } + /** + * Nimmt alle UndConstraints und filtert mithilfe dieser die falschen Constraints aus den OderConstraints + * @param unifier + */ public void unifyUndConstraints(Unifier unifier) { Vector uCons = this.filterUndConstraints(); Vector alleUndConstraints = new Vector<>(); for(UndConstraint undConstraint : uCons){ alleUndConstraints.addAll(undConstraint.getConstraintPairs()); } - Vector> unifyResult = unifier.apply(alleUndConstraints); - + this.filterWrongConstraints( + (pairs)->{ + Vector undConstraintsUndPairs = new Vector<>(); + undConstraintsUndPairs.addAll(pairs); + undConstraintsUndPairs.addAll(alleUndConstraints); + log.debug("Versuche Pairs auszusondern:\n"+pairs, Section.TYPEINFERENCE); + log.debug("Unifiziere:\n"+undConstraintsUndPairs, Section.TYPEINFERENCE); + Vector> unifyResult = unifier.apply(undConstraintsUndPairs); + return unifyResult; + }); } /** diff --git a/src/de/dhbwstuttgart/typeinference/OderConstraint.java b/src/de/dhbwstuttgart/typeinference/OderConstraint.java index 84f59d6a..1f2762d4 100755 --- a/src/de/dhbwstuttgart/typeinference/OderConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/OderConstraint.java @@ -3,6 +3,7 @@ package de.dhbwstuttgart.typeinference; import java.util.Vector; import de.dhbwstuttgart.logger.Logger; +import de.dhbwstuttgart.logger.Section; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; @@ -90,13 +91,16 @@ public class OderConstraint{ if(!unifierResult.isEmpty()){ filteredConstraints.add(cons); }else{ - logger.debug("Ausgesondertes Constraint: "+cons); + logger.debug("Ausgesondertes Constraint: "+cons, Section.TYPEINFERENCE); } } this.oderConstraintPairs = filteredConstraints; } UndConstraint filterUndConstraints() { + if(this.oderConstraintPairs.size()==1){ + return this.oderConstraintPairs.firstElement(); + } return null; } diff --git a/src/de/dhbwstuttgart/typeinference/Pair.java b/src/de/dhbwstuttgart/typeinference/Pair.java index b3126aa4..114bc97e 100755 --- a/src/de/dhbwstuttgart/typeinference/Pair.java +++ b/src/de/dhbwstuttgart/typeinference/Pair.java @@ -121,7 +121,7 @@ public class Pair if(OperatorSmallerExtends()) Operator = " Date: Thu, 9 Oct 2014 17:38:29 +0200 Subject: [PATCH 16/16] =?UTF-8?q?Logger=20angef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dhbwstuttgart/logger/OutputHandler.java | 29 +++++++++++++++++++ src/de/dhbwstuttgart/logger/Section.java | 7 +++++ 2 files changed, 36 insertions(+) create mode 100644 src/de/dhbwstuttgart/logger/OutputHandler.java create mode 100644 src/de/dhbwstuttgart/logger/Section.java diff --git a/src/de/dhbwstuttgart/logger/OutputHandler.java b/src/de/dhbwstuttgart/logger/OutputHandler.java new file mode 100644 index 00000000..fc57d746 --- /dev/null +++ b/src/de/dhbwstuttgart/logger/OutputHandler.java @@ -0,0 +1,29 @@ +package de.dhbwstuttgart.logger; + +import java.io.PrintStream; +import java.util.logging.Handler; +import java.util.logging.LogRecord; + +public class OutputHandler extends Handler{ + + private PrintStream output; + + public OutputHandler(PrintStream output){ + this.output = output; + } + + @Override + public void publish(LogRecord record) { + output.println(record.getMessage()); + } + + @Override + public void flush() { + } + + @Override + public void close() throws SecurityException { + } + + +} diff --git a/src/de/dhbwstuttgart/logger/Section.java b/src/de/dhbwstuttgart/logger/Section.java new file mode 100644 index 00000000..9fb2c66c --- /dev/null +++ b/src/de/dhbwstuttgart/logger/Section.java @@ -0,0 +1,7 @@ +package de.dhbwstuttgart.logger; + +public enum Section { + TYPEINFERENCE, + PARSER, + CODEGEN; +}