From aeb8bb92ed78aee9718a5f078826b5d692dc30be Mon Sep 17 00:00:00 2001 From: Fayez Abu Alia Date: Wed, 19 Sep 2018 13:05:00 +0200 Subject: [PATCH 1/4] Bug 108 gefixt --- .../bytecode/signature/Signature.java | 2 -- .../bytecode/signature/TypeToSignature.java | 4 ++-- test/bytecode/Tph5Test.java | 5 +++-- test/bytecode/javFiles/Tph5.jav | 14 ++++++++++---- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/de/dhbwstuttgart/bytecode/signature/Signature.java b/src/de/dhbwstuttgart/bytecode/signature/Signature.java index 4daf3ded..60023895 100644 --- a/src/de/dhbwstuttgart/bytecode/signature/Signature.java +++ b/src/de/dhbwstuttgart/bytecode/signature/Signature.java @@ -178,7 +178,6 @@ public class Signature { if(hasTPHs(ref)) createSignatureForParameterizedType(ref); - System.out.println("HAS WC = " + hasWC(ref)); if(hasWC(ref)) createSigForParamTypeWithWC(ref); } @@ -234,7 +233,6 @@ public class Signature { if(p instanceof WildcardType) { if(((WildcardType) p).getInnerType() instanceof GenericRefType) { String name = new TypeToSignature().visit((GenericRefType)((WildcardType) p).getInnerType()); - System.out.println("NAME WC = " + name); if(!genericsAndBoundsMethod.containsKey(name) && !genericsAndBounds.containsKey(name)) { sw.visitFormalTypeParameter(name); sw.visitClassBound().visitClassType(Type.getInternalName(Object.class)); diff --git a/src/de/dhbwstuttgart/bytecode/signature/TypeToSignature.java b/src/de/dhbwstuttgart/bytecode/signature/TypeToSignature.java index 6e73d8ee..7d47406d 100644 --- a/src/de/dhbwstuttgart/bytecode/signature/TypeToSignature.java +++ b/src/de/dhbwstuttgart/bytecode/signature/TypeToSignature.java @@ -34,9 +34,9 @@ public class TypeToSignature implements TypeVisitor { // params += "L"+param.toString().replace(".", "/"); // } params += param.acceptTV(new TypeToSignature()); - if(!(param instanceof RefType)) + + if(param instanceof TypePlaceholder) params += ";"; -// if(it.hasNext())params += ";"; } params += ">"; } diff --git a/test/bytecode/Tph5Test.java b/test/bytecode/Tph5Test.java index 7d44e5e5..4107cca2 100644 --- a/test/bytecode/Tph5Test.java +++ b/test/bytecode/Tph5Test.java @@ -36,8 +36,9 @@ public class Tph5Test { @Test public void test() throws Exception { - Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class, Object.class); - Object result = m.invoke(instanceOfClass, "xx",2,3); +// Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class, Object.class); + Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class); +// Object result = m.invoke(instanceOfClass, "xx",2,3); //assertEquals(2,result); } diff --git a/test/bytecode/javFiles/Tph5.jav b/test/bytecode/javFiles/Tph5.jav index 1772b7ce..e73cfa2c 100644 --- a/test/bytecode/javFiles/Tph5.jav +++ b/test/bytecode/javFiles/Tph5.jav @@ -1,7 +1,13 @@ public class Tph5 { - m(a,b,c){ - a = c; - b = c; - return a; +// m(a,b,c){ +// a = c; +// b = c; +// return a; +// } + + m(x,y){ + x = m2(y); } + + m2(y) { return y; } } From d165260be0fb1bd8b80773e13cdac26207ad66b9 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 19 Sep 2018 14:37:40 +0200 Subject: [PATCH 2/4] Beginnen mit Parser Dokumentation --- doc/parser.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 doc/parser.md diff --git a/doc/parser.md b/doc/parser.md new file mode 100644 index 00000000..b8263623 --- /dev/null +++ b/doc/parser.md @@ -0,0 +1,24 @@ +# Dateien +* sämtliche Datein im Ordner de.dhbwstuttgart.parser gehören zum Parser +* Auch zu beachten: pom.xml + * Ein Teil der pom.xml instruiert maven zur Kompilierung der Java8.g4 Datei + * VORSICHT! Wird nicht zwangsläufig von der IDE ausgeführt + * siehe Kapitel "Grammatik -> Parser" + + +## Unterordner antlr +* Java8.g4 + * die eigentliche Java Grammatik + * hier wurden Anpassungen vorgenommen, damit sie auch typloses Java annimmt +* alle anderen Dateien in diesem Ordner sind vom ANTLR-Parsergenerator autogeneriert + +## Unterordner SyntaxTreeGenerator +* SyntaxTreeGenerator +* TODO + +# Grammatik -> Parser +* Die Antlr-Grammatik (Java8.g4) wandelt +* Folgende Stellen sind relevant + * TODO + + From 673c249b680b9720014e0cc1d853400a0c0e9f97 Mon Sep 17 00:00:00 2001 From: Fayez Abu Alia Date: Wed, 19 Sep 2018 15:52:29 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=09modified:=20=20=20src/de/dhbwstuttgart/b?= =?UTF-8?q?ytecode/BytecodeGenMethod.java=20=09new=20file:=20=20=20src/de/?= =?UTF-8?q?dhbwstuttgart/bytecode/IfStatement.java=20Bytecode=20f=C3=BCr?= =?UTF-8?q?=20If=20statement=20wir=20erzeugt=20aber=20noch=20nicht=20volls?= =?UTF-8?q?t=C3=A4ndig.=20=09modified:=20=20=20test/bytecode/javFiles/Facu?= =?UTF-8?q?lty.jav=20Test=20angepasst.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bytecode/BytecodeGenMethod.java | 9 ++++- .../dhbwstuttgart/bytecode/IfStatement.java | 31 ++++++++++++++++ test/bytecode/javFiles/Faculty.jav | 37 +++++++++++++------ 3 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 src/de/dhbwstuttgart/bytecode/IfStatement.java diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index 643e98d5..2714965b 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -223,7 +223,7 @@ public class BytecodeGenMethod implements StatementVisitor { } Label endLabel = new Label(); - // this case for while loops + // this case for while loops and If statements if (statement instanceof LoopStmt) mv.visitLabel(endLabel); @@ -270,6 +270,8 @@ public class BytecodeGenMethod implements StatementVisitor { case LESSEQUAL: case BIGGERTHAN: case BIGGEREQUAL: + case EQUAL: + case NOTEQUAL: Label branchLabel = new Label(); doVisitRelOpInsn(op, largerType, branchLabel, endLabel); break; @@ -644,7 +646,10 @@ public class BytecodeGenMethod implements StatementVisitor { @Override public void visit(IfStmt ifStmt) { - System.out.println("If"); + statement = new IfStatement(ifStmt.expr, ifStmt.then_block, ifStmt.else_block); + isBinaryExp = statement.isExprBinary(); + ifStmt.expr.accept(this); + statement = null; } @Override diff --git a/src/de/dhbwstuttgart/bytecode/IfStatement.java b/src/de/dhbwstuttgart/bytecode/IfStatement.java new file mode 100644 index 00000000..6b11cc96 --- /dev/null +++ b/src/de/dhbwstuttgart/bytecode/IfStatement.java @@ -0,0 +1,31 @@ +package de.dhbwstuttgart.bytecode; + +import org.objectweb.asm.Label; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + +import de.dhbwstuttgart.syntaxtree.statement.Expression; +import de.dhbwstuttgart.syntaxtree.statement.Statement; + +public class IfStatement extends AStatement{ + + private Statement then_block; + private Statement else_block; + + public IfStatement(Expression expr, Statement then_block, Statement else_block) { + super(expr); + this.then_block = then_block; + this.else_block = else_block; + } + + @Override + public void genBCForRelOp(MethodVisitor mv,Label branchLabel, Label endLabel, BytecodeGenMethod bytecodeGenMethod) { + bytecodeGenMethod.isBinary(false); + this.then_block.accept(bytecodeGenMethod); + + mv.visitLabel(branchLabel); + this.else_block.accept(bytecodeGenMethod); +// mv.visitLabel(endLabel); +// mv.visitJumpInsn(Opcodes.GOTO, endLabel); + } +} diff --git a/test/bytecode/javFiles/Faculty.jav b/test/bytecode/javFiles/Faculty.jav index d2bdcf91..1bcddc51 100644 --- a/test/bytecode/javFiles/Faculty.jav +++ b/test/bytecode/javFiles/Faculty.jav @@ -1,17 +1,32 @@ import java.lang.Integer; -class Faculty { +public class Faculty { - m () { + m (x) { - var fact = (x) -> { - if (x == 1) { - return x; - } - else { - return x * (fact.apply(x-1)); - } - }; - return fact; +// var fact = (x) -> { +// if (x == 1) { +// return x; +// } +// else { +// return x * (fact.apply(x-1)); +// } +// }; +// return fact; +// var x = 13; +// if(x>22) { +// return 0; +// }else if(x <1){ +// return x; +// }else { +// return 1; +// } + + if (x < 2) { + return x; + } + else { + return x * m(x-1); + } } } From ea3ff690471b9fe6193318f225222dd17d371c97 Mon Sep 17 00:00:00 2001 From: Fayez Abu Alia Date: Wed, 19 Sep 2018 16:00:55 +0200 Subject: [PATCH 4/4] Faculty.jav geaendert --- test/bytecode/javFiles/Faculty.jav | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bytecode/javFiles/Faculty.jav b/test/bytecode/javFiles/Faculty.jav index 1bcddc51..794022ab 100644 --- a/test/bytecode/javFiles/Faculty.jav +++ b/test/bytecode/javFiles/Faculty.jav @@ -22,7 +22,7 @@ public class Faculty { // return 1; // } - if (x < 2) { + if (x == 1) { return x; } else {