Merge branch 'bytecode2' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecode2

This commit is contained in:
Martin Plümicke 2018-09-19 22:22:36 +02:00
commit f46d26e53f
8 changed files with 103 additions and 23 deletions

24
doc/parser.md Normal file
View File

@ -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

View File

@ -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

View File

@ -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);
}
}

View File

@ -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));

View File

@ -34,9 +34,9 @@ public class TypeToSignature implements TypeVisitor<String> {
// params += "L"+param.toString().replace(".", "/");
// }
params += param.acceptTV(new TypeToSignature());
if(!(param instanceof RefType))
if(param instanceof TypePlaceholder)
params += ";";
// if(it.hasNext())params += ";";
}
params += ">";
}

View File

@ -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);
}

View File

@ -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 == 1) {
return x;
}
else {
return x * m(x-1);
}
}
}

View File

@ -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; }
}