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.
This commit is contained in:
pl@gohorb.ba-horb.de 2020-02-07 17:46:11 +01:00
parent 5c97d80eb0
commit 98997d686f
9 changed files with 62 additions and 21 deletions

View File

@ -177,6 +177,7 @@ public class BytecodeGenMethod implements StatementVisitor {
@Override
public void visit(Block block) {
HashMap<String, Integer> 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

View File

@ -20,7 +20,8 @@ public class TypeToDescriptor implements TypeVisitor<String>{
@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<String>{
@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();
}

View File

@ -480,11 +480,11 @@ public class JavaTXCompiler {
final ConstraintSet<Pair> cons = getConstraints();
Set<Set<UnifyPair>> 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<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);

View File

@ -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<RefTypeOrTPHOrWildcardOrGeneric> 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<RefTypeOrTPHOrWildcardOrGeneric> 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,7 +788,11 @@ 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<RefTypeOrTPHOrWildcardOrGeneric> 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());
}
}
@ -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<RefTypeOrTPHOrWildcardOrGeneric> 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<RefTypeOrTPHOrWildcardOrGeneric> 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;
}

View File

@ -27,7 +27,7 @@ public class Constructor extends Method {
*/
protected static Block prepareBlock(Block constructorBlock /*, List<Statement> fieldInitializations new ArrayList<>() geloescht PL 2018-11-24 */){
List<Statement> 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());
}

View File

@ -21,13 +21,24 @@ public class MethodCall extends Statement
{
public final String name;
public final Receiver receiver;
public final ArgumentList arglist;
public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList, Token offset){
/*
* noetig fuer Bytecodegenerierung
*/
public RefTypeOrTPHOrWildcardOrGeneric receiverType;
public final ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes;
public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList,
RefTypeOrTPHOrWildcardOrGeneric receiverType, ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){
super(retType,offset);
this.arglist = argumentList;
this.name = methodName;
this.receiver = receiver;
this.receiverType = receiverType;
this.argTypes = argTypes;
}
@Override

View File

@ -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<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token start) {
super(newClass, new ExpressionReceiver(new EmptyStmt(start)), newClass.getName().toString(),
args, receiverType, argTypes, start);
}
@Override

View File

@ -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<Expression>(), offset),offset);
public SuperCall(RefTypeOrTPHOrWildcardOrGeneric receiverType,
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){
this(new ArgumentList(new ArrayList<Expression>(), offset), receiverType, argTypes, offset);
}
public SuperCall(ArgumentList argumentList, Token offset){
super(new Void(offset), new ExpressionReceiver(new This(offset)), "<init>", argumentList, offset);
public SuperCall(ArgumentList argumentList, RefTypeOrTPHOrWildcardOrGeneric receiverType,
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){
super(new Void(offset), new ExpressionReceiver(new This(offset)), "<init>", argumentList, receiverType, argTypes, offset);
}

View File

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