Unterschied zwischen Expr-Receiver und Classname-Receiver

This commit is contained in:
JanUlrich 2017-10-26 21:45:04 +02:00
parent bfa106913b
commit 934e5f85f8
14 changed files with 67 additions and 128 deletions

View File

@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import de.dhbwstuttgart.syntaxtree.statement.*;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
@ -12,33 +13,6 @@ import org.objectweb.asm.Opcodes;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
import de.dhbwstuttgart.syntaxtree.statement.Assign;
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
import de.dhbwstuttgart.syntaxtree.statement.Binary;
import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt;
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
import de.dhbwstuttgart.syntaxtree.statement.ForStmt;
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
import de.dhbwstuttgart.syntaxtree.statement.InstanceOf;
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
import de.dhbwstuttgart.syntaxtree.statement.NewArray;
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
import de.dhbwstuttgart.syntaxtree.statement.Receiver;
import de.dhbwstuttgart.syntaxtree.statement.Return;
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
import de.dhbwstuttgart.syntaxtree.statement.Super;
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
import de.dhbwstuttgart.syntaxtree.statement.This;
import de.dhbwstuttgart.syntaxtree.statement.UnaryPlus;
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
@ -281,12 +255,6 @@ public class BytecodeGen implements ASTVisitor {
}
@Override
public void visit(Receiver receiver) {
// TODO Auto-generated method stub
}
@Override
public void visit(Return aReturn) {
// TODO Auto-generated method stub
@ -379,6 +347,11 @@ public class BytecodeGen implements ASTVisitor {
@Override
public void visit(SuperCall superCall) {
}
@Override
public void visit(ExpressionReceiver expressionReceiver) {
// TODO Auto-generated method stub
}

View File

@ -1,36 +1,10 @@
package de.dhbwstuttgart.bytecode;
import de.dhbwstuttgart.syntaxtree.statement.*;
import org.objectweb.asm.MethodVisitor;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
import de.dhbwstuttgart.syntaxtree.statement.Assign;
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
import de.dhbwstuttgart.syntaxtree.statement.Binary;
import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt;
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
import de.dhbwstuttgart.syntaxtree.statement.ForStmt;
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
import de.dhbwstuttgart.syntaxtree.statement.InstanceOf;
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
import de.dhbwstuttgart.syntaxtree.statement.NewArray;
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
import de.dhbwstuttgart.syntaxtree.statement.Receiver;
import de.dhbwstuttgart.syntaxtree.statement.Return;
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
import de.dhbwstuttgart.syntaxtree.statement.Super;
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
import de.dhbwstuttgart.syntaxtree.statement.This;
import de.dhbwstuttgart.syntaxtree.statement.UnaryPlus;
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
@ -142,7 +116,7 @@ public class BytecodeGenLambda implements StatementVisitor{
}
@Override
public void visit(Receiver receiver) {
public void visit(ExpressionReceiver receiver) {
// TODO Auto-generated method stub
}

View File

@ -8,6 +8,7 @@ import java.lang.invoke.MethodType;
import java.security.GeneralSecurityException;
import java.util.HashMap;
import de.dhbwstuttgart.syntaxtree.statement.*;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Handle;
import org.objectweb.asm.MethodVisitor;
@ -17,35 +18,6 @@ import org.objectweb.asm.Type;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
import de.dhbwstuttgart.syntaxtree.statement.Assign;
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
import de.dhbwstuttgart.syntaxtree.statement.Binary;
import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt;
import de.dhbwstuttgart.syntaxtree.statement.Expression;
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
import de.dhbwstuttgart.syntaxtree.statement.ForStmt;
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
import de.dhbwstuttgart.syntaxtree.statement.InstanceOf;
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
import de.dhbwstuttgart.syntaxtree.statement.NewArray;
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
import de.dhbwstuttgart.syntaxtree.statement.Receiver;
import de.dhbwstuttgart.syntaxtree.statement.Return;
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
import de.dhbwstuttgart.syntaxtree.statement.Statement;
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
import de.dhbwstuttgart.syntaxtree.statement.Super;
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
import de.dhbwstuttgart.syntaxtree.statement.This;
import de.dhbwstuttgart.syntaxtree.statement.UnaryPlus;
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
@ -230,14 +202,19 @@ public class BytecodeGenMethod implements StatementVisitor{
@Override
public void visit(MethodCall methodCall) {
System.out.println(" In Methodcall: (" +methodCall.name+")" );
System.out.println(" Method-Receiver: "+methodCall.receiver.expr);
System.out.print(" Method-Receiver: ");
if(methodCall.receiver instanceof ExpressionReceiver){
System.out.print(((ExpressionReceiver) methodCall.receiver).expr + "\n");
}else{
System.out.print(((StaticClassName) methodCall.receiver).getType().toString() + "\n");
}
methodCall.receiver.accept(this);
methodCall.arglist.accept(this);
Descriptor mDesc = new Descriptor(methodCall.arglist, methodCall.getType());
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, methodCall.receiver.expr.getType().toString(),
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, methodCall.receiver.getType().toString(),
methodCall.name, mDesc.getDesc(), false);
// test
if(!methodCall.getType().toString().equals("V")) {
@ -270,7 +247,7 @@ public class BytecodeGenMethod implements StatementVisitor{
}
@Override
public void visit(Receiver receiver) {
public void visit(ExpressionReceiver receiver) {
System.out.println(" in Receiver");
System.out.println(" expr : " + receiver.expr);
receiver.expr.accept(this);

View File

@ -179,6 +179,14 @@ public class StatementGenerator {
}else throw new NotImplementedException();
}
public Receiver getReceiver(Expression expr){
if(expr instanceof StaticClassName){
return (Receiver) expr;
}else {
return new ExpressionReceiver(expr);
}
}
private Statement convert(Java8Parser.MethodInvocationContext methodInvocationContext) {
String name;
if(methodInvocationContext.methodName()!=null){
@ -200,7 +208,7 @@ public class StatementGenerator {
}else throw new NotImplementedException();
ArgumentList argumentList = convert(methodInvocationContext.argumentList());
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()),new Receiver(receiver), name, argumentList, methodInvocationContext.getStart());
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), getReceiver(receiver), name, argumentList, methodInvocationContext.getStart());
return ret;
}
@ -701,7 +709,7 @@ public class StatementGenerator {
}else {
Java8Parser.MethodInvocation_lf_primaryContext ctxt = e.methodInvocation_lf_primary();
String methodName = ctxt.Identifier().toString();
return new MethodCall(TypePlaceholder.fresh(e.getStart()), new Receiver(expr), methodName, convert(ctxt.argumentList()), e.getStart());
return new MethodCall(TypePlaceholder.fresh(e.getStart()), getReceiver(expr), methodName, convert(ctxt.argumentList()), e.getStart());
}
}
@ -809,7 +817,7 @@ public class StatementGenerator {
}
ArgumentList argumentList = convert(methodInvocationContext.argumentList());
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), new Receiver(receiver), name, argumentList, methodInvocationContext.getStart());
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), getReceiver(receiver), name, argumentList, methodInvocationContext.getStart());
return ret;
}

View File

@ -200,7 +200,7 @@ public abstract class AbstractASTWalker implements ASTVisitor{
}
@Override
public void visit(Receiver receiver) {
public void visit(ExpressionReceiver receiver) {
receiver.expr.accept(this);
}

View File

@ -40,8 +40,6 @@ public interface StatementVisitor {
void visit(NewArray newArray);
void visit(Receiver receiver);
void visit(Return aReturn);
void visit(ReturnVoid aReturn);
@ -67,4 +65,6 @@ public interface StatementVisitor {
void visit(AssignToLocal assignLeftSide);
void visit(SuperCall superCall);
void visit(ExpressionReceiver expressionReceiver);
}

View File

@ -0,0 +1,21 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import org.antlr.v4.runtime.Token;
public class ExpressionReceiver extends Receiver
{
public final Expression expr;
public ExpressionReceiver(Expression expr)
{
super(expr.getType(), expr.getOffset());
this.expr = expr;
}
@Override
public void accept(StatementVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -31,7 +31,7 @@ public class NewClass extends MethodCall
* @param start
*/
public NewClass(RefType newClass, ArgumentList args, Token start) {
super(newClass, new Receiver(new EmptyStmt(start)), newClass.getName().toString(), args, start);
super(newClass, new ExpressionReceiver(new EmptyStmt(start)), newClass.getName().toString(), args, start);
}
@Override

View File

@ -1,26 +1,12 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import org.antlr.v4.runtime.Token;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
public class Receiver extends Expression
public abstract class Receiver extends Expression
{
public Expression expr;
/**
* Autor: ¯Â¿Â½rg ¯Â¿Â½uerle
* @param expr
*/
public Receiver(Expression expr)
public Receiver(RefTypeOrTPHOrWildcardOrGeneric type, Token offset)
{
super(expr.getType(), expr.getOffset());
this.expr = expr;
}
@Override
public void accept(StatementVisitor visitor) {
visitor.visit(this);
super(type, offset);
}
}

View File

@ -8,7 +8,7 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
import org.antlr.v4.runtime.Token;
public class StaticClassName extends Expression {
public class StaticClassName extends Receiver {
public StaticClassName(JavaClassName className, Token offset) {
super(new RefType(className, offset), offset);
}

View File

@ -17,7 +17,7 @@ public class SuperCall extends MethodCall
}
public SuperCall(ArgumentList argumentList, Token offset){
super(new Void(offset), new Receiver(new This(offset)), "<init>", argumentList, offset);
super(new Void(offset), new ExpressionReceiver(new This(offset)), "<init>", argumentList, offset);
}

View File

@ -270,11 +270,6 @@ public class OutputGenerator implements ASTVisitor {
}
@Override
public void visit(Receiver receiver) {
receiver.expr.accept(this);
}
@Override
public void visit(Return aReturn) {
out.append("return ");
@ -349,4 +344,9 @@ public class OutputGenerator implements ASTVisitor {
superCall.arglist.accept(this);
out.append(")");
}
@Override
public void visit(ExpressionReceiver receiver) {
receiver.expr.accept(this);
}
}

View File

@ -181,7 +181,7 @@ public class TypeOutputGenerator extends OutputGenerator {
}
@Override
public void visit(Receiver receiver) {
public void visit(ExpressionReceiver receiver) {
super.visit(receiver);
}

View File

@ -184,7 +184,7 @@ public class TYPEStmt implements StatementVisitor{
}
@Override
public void visit(Receiver receiver) {
public void visit(ExpressionReceiver receiver) {
receiver.expr.accept(this);
}