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:
parent
5c97d80eb0
commit
98997d686f
@ -177,6 +177,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(Block block) {
|
public void visit(Block block) {
|
||||||
|
HashMap<String, Integer> paramsAndLocalsOld = new HashMap<>(paramsAndLocals);
|
||||||
for (Statement stmt : block.getStatements()) {
|
for (Statement stmt : block.getStatements()) {
|
||||||
stmt.accept(this);
|
stmt.accept(this);
|
||||||
if(stmt instanceof MethodCall) {
|
if(stmt instanceof MethodCall) {
|
||||||
@ -185,6 +186,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
mv.visitInsn(Opcodes.POP);
|
mv.visitInsn(Opcodes.POP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
paramsAndLocals = paramsAndLocalsOld;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -222,7 +224,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
// ??
|
// ??
|
||||||
@Override
|
@Override
|
||||||
public void visit(LocalVarDecl localVarDecl) {
|
public void visit(LocalVarDecl localVarDecl) {
|
||||||
|
paramsAndLocals.put(localVarDecl.getName(), paramsAndLocals.size()+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,7 +20,8 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
|||||||
@Override
|
@Override
|
||||||
public String visit(SuperWildcardType superWildcardType) {
|
public String visit(SuperWildcardType superWildcardType) {
|
||||||
System.out.println("\nWILDCARD ="+superWildcardType.getInnerType().toString().replace(".", "/"));
|
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();
|
//throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +33,8 @@ public class TypeToDescriptor implements TypeVisitor<String>{
|
|||||||
@Override
|
@Override
|
||||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||||
System.out.println("\nWILDCARD extends ="+extendsWildcardType.getInnerType().toString().replace(".", "/"));
|
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();
|
//throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,11 +480,11 @@ public class JavaTXCompiler {
|
|||||||
final ConstraintSet<Pair> cons = getConstraints();
|
final ConstraintSet<Pair> cons = getConstraints();
|
||||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||||
try {
|
try {
|
||||||
Writer logFile = //new OutputStreamWriter(new NullOutputStream());
|
Writer logFile = new OutputStreamWriter(new NullOutputStream());
|
||||||
// new FileWriter(new
|
// new FileWriter(new
|
||||||
// File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
|
// 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_"
|
//new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_"
|
||||||
+ sourceFiles.keySet().iterator().next().getName()));
|
// + sourceFiles.keySet().iterator().next().getName()));
|
||||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader);
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader);
|
||||||
System.out.println(finiteClosure);
|
System.out.println(finiteClosure);
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||||
|
@ -17,6 +17,7 @@ import org.antlr.v4.runtime.Token;
|
|||||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class StatementGenerator {
|
public class StatementGenerator {
|
||||||
|
|
||||||
@ -209,7 +210,12 @@ public class StatementGenerator {
|
|||||||
}else throw new NotImplementedException();
|
}else throw new NotImplementedException();
|
||||||
|
|
||||||
ArgumentList argumentList = convert(methodInvocationContext.argumentList());
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,7 +299,10 @@ public class StatementGenerator {
|
|||||||
RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(),genericArgs,identifier.getSymbol(),reg,generics);
|
RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(),genericArgs,identifier.getSymbol(),reg,generics);
|
||||||
|
|
||||||
ArgumentList args = convert(newExpression.argumentList());
|
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) {
|
private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) {
|
||||||
@ -779,10 +788,14 @@ public class StatementGenerator {
|
|||||||
}else {
|
}else {
|
||||||
Java8Parser.MethodInvocation_lf_primaryContext ctxt = e.methodInvocation_lf_primary();
|
Java8Parser.MethodInvocation_lf_primaryContext ctxt = e.methodInvocation_lf_primary();
|
||||||
String methodName = ctxt.Identifier().toString();
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Expression convert(Java8Parser.ArrayCreationExpressionContext expression) {
|
private Expression convert(Java8Parser.ArrayCreationExpressionContext expression) {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@ -833,7 +846,10 @@ public class StatementGenerator {
|
|||||||
RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(),genericArgs,identifier.getSymbol(),reg,generics);
|
RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(),genericArgs,identifier.getSymbol(),reg,generics);
|
||||||
|
|
||||||
ArgumentList args = convert(newExpression.argumentList());
|
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) {
|
private Expression convert(Java8Parser.LiteralContext literal) {
|
||||||
@ -891,7 +907,12 @@ public class StatementGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArgumentList argumentList = convert(methodInvocationContext.argumentList());
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 */){
|
protected static Block prepareBlock(Block constructorBlock /*, List<Statement> fieldInitializations new ArrayList<>() geloescht PL 2018-11-24 */){
|
||||||
List<Statement> statements = constructorBlock.getStatements();
|
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 */
|
/* statements.addAll(fieldInitializations); geloescht PL 2018-11-24 */
|
||||||
return new Block(statements, constructorBlock.getOffset());
|
return new Block(statements, constructorBlock.getOffset());
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,24 @@ public class MethodCall extends Statement
|
|||||||
{
|
{
|
||||||
public final String name;
|
public final String name;
|
||||||
public final Receiver receiver;
|
public final Receiver receiver;
|
||||||
|
|
||||||
public final ArgumentList arglist;
|
public final ArgumentList arglist;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* noetig fuer Bytecodegenerierung
|
||||||
|
*/
|
||||||
|
public RefTypeOrTPHOrWildcardOrGeneric receiverType;
|
||||||
|
public final ArrayList<RefTypeOrTPHOrWildcardOrGeneric> 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<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){
|
||||||
super(retType,offset);
|
super(retType,offset);
|
||||||
this.arglist = argumentList;
|
this.arglist = argumentList;
|
||||||
this.name = methodName;
|
this.name = methodName;
|
||||||
this.receiver = receiver;
|
this.receiver = receiver;
|
||||||
|
this.receiverType = receiverType;
|
||||||
|
this.argTypes = argTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,8 +29,10 @@ public class NewClass extends MethodCall
|
|||||||
* @param args Argumente mit denen der New-Call aufgerufen wurde
|
* @param args Argumente mit denen der New-Call aufgerufen wurde
|
||||||
* @param start
|
* @param start
|
||||||
*/
|
*/
|
||||||
public NewClass(RefType newClass, ArgumentList args, Token start) {
|
public NewClass(RefType newClass, ArgumentList args, RefTypeOrTPHOrWildcardOrGeneric receiverType,
|
||||||
super(newClass, new ExpressionReceiver(new EmptyStmt(start)), newClass.getName().toString(), args, start);
|
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token start) {
|
||||||
|
super(newClass, new ExpressionReceiver(new EmptyStmt(start)), newClass.getName().toString(),
|
||||||
|
args, receiverType, argTypes, start);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,6 +2,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
@ -12,12 +13,14 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class SuperCall extends MethodCall
|
public class SuperCall extends MethodCall
|
||||||
{
|
{
|
||||||
public SuperCall(Token offset){
|
public SuperCall(RefTypeOrTPHOrWildcardOrGeneric receiverType,
|
||||||
this(new ArgumentList(new ArrayList<Expression>(), offset),offset);
|
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){
|
||||||
|
this(new ArgumentList(new ArrayList<Expression>(), offset), receiverType, argTypes, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SuperCall(ArgumentList argumentList, Token offset){
|
public SuperCall(ArgumentList argumentList, RefTypeOrTPHOrWildcardOrGeneric receiverType,
|
||||||
super(new Void(offset), new ExpressionReceiver(new This(offset)), "<init>", argumentList, offset);
|
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){
|
||||||
|
super(new Void(offset), new ExpressionReceiver(new This(offset)), "<init>", argumentList, receiverType, argTypes, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ public class ThisCall extends MethodCall
|
|||||||
{
|
{
|
||||||
public ThisCall(Receiver receiver, ArgumentList arglist, int offset)
|
public ThisCall(Receiver receiver, ArgumentList arglist, int offset)
|
||||||
{
|
{
|
||||||
super(null, null, null, null, null);
|
super(null, null, null, null, null, null, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user