From 98997d686ff2a0c5a7dfcbfac2f6160950fa2b7b Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 7 Feb 2020 17:46:11 +0100 Subject: [PATCH] modified: ../../../main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java Lokale Variablen eingefuegt Wildcards korrigiert logFiule off modified: ../../../main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java modified: ../../../main/java/de/dhbwstuttgart/syntaxtree/Constructor.java modified: ../../../main/java/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java modified: ../../../main/java/de/dhbwstuttgart/syntaxtree/statement/NewClass.java modified: ../../../main/java/de/dhbwstuttgart/syntaxtree/statement/SuperCall.java modified: ../../../main/java/de/dhbwstuttgart/syntaxtree/statement/ThisCall.java Typeargumente von Receiver und Argumenten in Methodcall eingefuegt. --- .../bytecode/BytecodeGenMethod.java | 4 ++- .../bytecode/descriptor/TypeToDescriptor.java | 6 ++-- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 6 ++-- .../StatementGenerator.java | 33 +++++++++++++++---- .../dhbwstuttgart/syntaxtree/Constructor.java | 2 +- .../syntaxtree/statement/MethodCall.java | 13 +++++++- .../syntaxtree/statement/NewClass.java | 6 ++-- .../syntaxtree/statement/SuperCall.java | 11 ++++--- .../syntaxtree/statement/ThisCall.java | 2 +- 9 files changed, 62 insertions(+), 21 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index 54f4ab1e..00b1fb6e 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -177,6 +177,7 @@ public class BytecodeGenMethod implements StatementVisitor { @Override public void visit(Block block) { + HashMap paramsAndLocalsOld = new HashMap<>(paramsAndLocals); for (Statement stmt : block.getStatements()) { stmt.accept(this); if(stmt instanceof MethodCall) { @@ -185,6 +186,7 @@ public class BytecodeGenMethod implements StatementVisitor { mv.visitInsn(Opcodes.POP); } } + paramsAndLocals = paramsAndLocalsOld; } @Override @@ -222,7 +224,7 @@ public class BytecodeGenMethod implements StatementVisitor { // ?? @Override public void visit(LocalVarDecl localVarDecl) { - + paramsAndLocals.put(localVarDecl.getName(), paramsAndLocals.size()+1); } @Override diff --git a/src/main/java/de/dhbwstuttgart/bytecode/descriptor/TypeToDescriptor.java b/src/main/java/de/dhbwstuttgart/bytecode/descriptor/TypeToDescriptor.java index 8ee84328..aa3db5b1 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/descriptor/TypeToDescriptor.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/descriptor/TypeToDescriptor.java @@ -20,7 +20,8 @@ public class TypeToDescriptor implements TypeVisitor{ @Override public String visit(SuperWildcardType superWildcardType) { System.out.println("\nWILDCARD ="+superWildcardType.getInnerType().toString().replace(".", "/")); - return superWildcardType.getInnerType().toString().replace(".", "/"); + //return superWildcardType.getInnerType().toString().replace(".", "/"); + return superWildcardType.getInnerType().acceptTV(new TypeToDescriptor()); //throw new NotImplementedException(); } @@ -32,7 +33,8 @@ public class TypeToDescriptor implements TypeVisitor{ @Override public String visit(ExtendsWildcardType extendsWildcardType) { System.out.println("\nWILDCARD extends ="+extendsWildcardType.getInnerType().toString().replace(".", "/")); - return extendsWildcardType.getInnerType().toString().replace(".", "/"); + //return extendsWildcardType.getInnerType().toString().replace(".", "/"); + return extendsWildcardType.getInnerType().acceptTV(new TypeToDescriptor()); //throw new NotImplementedException(); } diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 989c100d..5f510946 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -480,11 +480,11 @@ public class JavaTXCompiler { final ConstraintSet cons = getConstraints(); Set> results = new HashSet<>(); try { - Writer logFile = //new OutputStreamWriter(new NullOutputStream()); + Writer logFile = new OutputStreamWriter(new NullOutputStream()); // new FileWriter(new // File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); - new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_" - + sourceFiles.keySet().iterator().next().getName())); + //new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_" + // + sourceFiles.keySet().iterator().next().getName())); IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader); System.out.println(finiteClosure); ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index 9305310d..c4625a7a 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -17,6 +17,7 @@ import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.tree.TerminalNode; import java.util.*; +import java.util.stream.Collectors; public class StatementGenerator { @@ -209,7 +210,12 @@ public class StatementGenerator { }else throw new NotImplementedException(); ArgumentList argumentList = convert(methodInvocationContext.argumentList()); - MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), getReceiver(receiver), name, argumentList, methodInvocationContext.getStart()); + ArrayList argTypes = argumentList.getArguments().stream() + .map(x -> TypePlaceholder.fresh(methodInvocationContext.getStart())) + .collect(Collectors.toCollection(ArrayList::new)); + MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), + getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()), + argTypes, methodInvocationContext.getStart()); return ret; } @@ -293,7 +299,10 @@ public class StatementGenerator { RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(),genericArgs,identifier.getSymbol(),reg,generics); ArgumentList args = convert(newExpression.argumentList()); - return new NewClass(newClass, args, newExpression.getStart()); + ArrayList argTypes = args.getArguments().stream() + .map(x -> TypePlaceholder.fresh(newExpression.getStart())) + .collect(Collectors.toCollection(ArrayList::new)); + return new NewClass(newClass, args, null, argTypes, newExpression.getStart()); } private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) { @@ -779,10 +788,14 @@ 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()), getReceiver(expr), methodName, convert(ctxt.argumentList()), e.getStart()); + ArrayList argTypes = ctxt.argumentList().expression().stream() + .map(x -> TypePlaceholder.fresh(e.getStart())) + .collect(Collectors.toCollection(ArrayList::new)); + return new MethodCall(TypePlaceholder.fresh(e.getStart()), getReceiver(expr), methodName, + convert(ctxt.argumentList()), TypePlaceholder.fresh(e.getStart()), argTypes, e.getStart()); } } - + private Expression convert(Java8Parser.ArrayCreationExpressionContext expression) { throw new NotImplementedException(); } @@ -833,7 +846,10 @@ public class StatementGenerator { RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(),genericArgs,identifier.getSymbol(),reg,generics); ArgumentList args = convert(newExpression.argumentList()); - return new NewClass(newClass, args, newExpression.getStart()); + ArrayList argTypes = args.getArguments().stream() + .map(x -> TypePlaceholder.fresh(newExpression.getStart())) + .collect(Collectors.toCollection(ArrayList::new)); + return new NewClass(newClass, args, null, argTypes, newExpression.getStart()); } private Expression convert(Java8Parser.LiteralContext literal) { @@ -891,7 +907,12 @@ public class StatementGenerator { } ArgumentList argumentList = convert(methodInvocationContext.argumentList()); - MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), getReceiver(receiver), name, argumentList, methodInvocationContext.getStart()); + ArrayList argTypes = argumentList.getArguments().stream() + .map(x -> TypePlaceholder.fresh(methodInvocationContext.getStart())) + .collect(Collectors.toCollection(ArrayList::new)); + MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), + getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()), + argTypes, methodInvocationContext.getStart()); return ret; } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/Constructor.java b/src/main/java/de/dhbwstuttgart/syntaxtree/Constructor.java index 8be687f8..24b3bb81 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/Constructor.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/Constructor.java @@ -27,7 +27,7 @@ public class Constructor extends Method { */ protected static Block prepareBlock(Block constructorBlock /*, List fieldInitializations new ArrayList<>() geloescht PL 2018-11-24 */){ List statements = constructorBlock.getStatements(); - statements.add(0, new SuperCall(constructorBlock.getOffset())); + statements.add(0, new SuperCall(null, null, constructorBlock.getOffset())); /* statements.addAll(fieldInitializations); geloescht PL 2018-11-24 */ return new Block(statements, constructorBlock.getOffset()); } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java index f6307f1e..75267619 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java @@ -21,13 +21,24 @@ public class MethodCall extends Statement { public final String name; public final Receiver receiver; + public final ArgumentList arglist; + + /* + * noetig fuer Bytecodegenerierung + */ + public RefTypeOrTPHOrWildcardOrGeneric receiverType; + public final ArrayList argTypes; + - public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList, Token offset){ + public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList, + RefTypeOrTPHOrWildcardOrGeneric receiverType, ArrayList argTypes, Token offset){ super(retType,offset); this.arglist = argumentList; this.name = methodName; this.receiver = receiver; + this.receiverType = receiverType; + this.argTypes = argTypes; } @Override diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/NewClass.java b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/NewClass.java index d29f3d53..f27bc3e8 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/NewClass.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/NewClass.java @@ -29,8 +29,10 @@ public class NewClass extends MethodCall * @param args Argumente mit denen der New-Call aufgerufen wurde * @param start */ - public NewClass(RefType newClass, ArgumentList args, Token start) { - super(newClass, new ExpressionReceiver(new EmptyStmt(start)), newClass.getName().toString(), args, start); + public NewClass(RefType newClass, ArgumentList args, RefTypeOrTPHOrWildcardOrGeneric receiverType, + ArrayList argTypes, Token start) { + super(newClass, new ExpressionReceiver(new EmptyStmt(start)), newClass.getName().toString(), + args, receiverType, argTypes, start); } @Override diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/SuperCall.java b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/SuperCall.java index 42cfb8ee..3b7eebbf 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/SuperCall.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/SuperCall.java @@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.StatementVisitor; import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.Void; import org.antlr.v4.runtime.Token; @@ -12,12 +13,14 @@ import java.util.ArrayList; public class SuperCall extends MethodCall { - public SuperCall(Token offset){ - this(new ArgumentList(new ArrayList(), offset),offset); + public SuperCall(RefTypeOrTPHOrWildcardOrGeneric receiverType, + ArrayList argTypes, Token offset){ + this(new ArgumentList(new ArrayList(), offset), receiverType, argTypes, offset); } - public SuperCall(ArgumentList argumentList, Token offset){ - super(new Void(offset), new ExpressionReceiver(new This(offset)), "", argumentList, offset); + public SuperCall(ArgumentList argumentList, RefTypeOrTPHOrWildcardOrGeneric receiverType, + ArrayList argTypes, Token offset){ + super(new Void(offset), new ExpressionReceiver(new This(offset)), "", argumentList, receiverType, argTypes, offset); } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/ThisCall.java b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/ThisCall.java index e82405c0..26579d2f 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/statement/ThisCall.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/statement/ThisCall.java @@ -8,7 +8,7 @@ public class ThisCall extends MethodCall { public ThisCall(Receiver receiver, ArgumentList arglist, int offset) { - super(null, null, null, null, null); + super(null, null, null, null, null, null, null); }