Merge branch 'bytecode2' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecode2
This commit is contained in:
commit
32d12677bf
@ -61,7 +61,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
||||
assign.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(assign.getType()));
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(assign.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@ -70,9 +70,9 @@ public class ArgumentVisitor implements StatementVisitor {
|
||||
binary.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0)) {
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(binary.getType()));
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(binary.getType()));
|
||||
} else {
|
||||
bytecodeGenMethod.doBoxing(bytecodeGenMethod.getResolvedType(binary.getType()));
|
||||
bytecodeGenMethod.doBoxing(bytecodeGenMethod.getResolver().getResolvedType(binary.getType()));
|
||||
}
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
@ -88,7 +88,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
||||
castExpr.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(castExpr.getType()));
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(castExpr.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
||||
fieldVar.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(fieldVar.getType()));
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(fieldVar.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
||||
instanceOf.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(instanceOf.getType()));
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(instanceOf.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
||||
localVar.accept(bytecodeGenMethod);
|
||||
if(!bytecodeGenMethod.isBinaryExp) {
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(localVar.getType()));
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(localVar.getType()));
|
||||
}
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
@ -149,7 +149,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
||||
methodCall.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(methodCall.getType()));
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(methodCall.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
||||
methodCall.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(methodCall.getType()));
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(methodCall.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@ -197,7 +197,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
||||
aThis.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(aThis.getType()));
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(aThis.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@ -242,7 +242,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
||||
unaryExpr.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(unaryExpr.getType()));
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(unaryExpr.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
@ -251,7 +251,7 @@ public class ArgumentVisitor implements StatementVisitor {
|
||||
literal.accept(bytecodeGenMethod);
|
||||
|
||||
if(argListMethCall.get(0))
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolvedType(literal.getType()));
|
||||
bytecodeGenMethod.doUnboxing(bytecodeGenMethod.getResolver().getResolvedType(literal.getType()));
|
||||
argListMethCall.remove(0);
|
||||
}
|
||||
|
||||
|
@ -353,7 +353,7 @@ public class BytecodeGen implements ASTVisitor {
|
||||
}
|
||||
String sig = null;
|
||||
if (hasGen) {
|
||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(field.name, tphExtractor,
|
||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(field, tphExtractor,
|
||||
tphsClass);
|
||||
Signature signature = new Signature(field, genericsAndBounds, methodParamsAndTypes, resultSet, constraints);
|
||||
sig = signature.toString();
|
||||
@ -446,7 +446,7 @@ public class BytecodeGen implements ASTVisitor {
|
||||
System.out.println("ALL CONST: " + tphExtractor.allCons.size());
|
||||
tphExtractor.allCons.forEach(c -> System.out.println(c.toString()));
|
||||
System.out.println("----------------");
|
||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(method.name,
|
||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(method,
|
||||
tphExtractor, tphsClass);
|
||||
// ArrayList<GenericInsertPair> pairs = simplifyPairs(method.name,tphExtractor.allPairs,tphExtractor.allCons);
|
||||
Signature signature = new Signature(method, genericsAndBoundsMethod, genericsAndBounds,
|
||||
|
@ -42,6 +42,7 @@ import de.dhbwstuttgart.bytecode.utilities.KindOfLambda;
|
||||
import de.dhbwstuttgart.bytecode.utilities.Lambda;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodCallHelper;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
|
||||
import de.dhbwstuttgart.bytecode.utilities.Resolver;
|
||||
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
@ -58,6 +59,7 @@ import javassist.NotFoundException;
|
||||
|
||||
public class BytecodeGenMethod implements StatementVisitor {
|
||||
|
||||
private Resolver resolver;
|
||||
private Method m;
|
||||
private MethodVisitor mv;
|
||||
private HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
||||
@ -101,6 +103,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
this.className = className;
|
||||
this.superClass = superClass;
|
||||
this.resultSet = resultSet;
|
||||
this.resolver = new Resolver(resultSet);
|
||||
this.m = m;
|
||||
this.mv = mv;
|
||||
this.paramsAndLocals = paramsAndLocals;
|
||||
@ -126,6 +129,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
this.className = className;
|
||||
this.superClass = superClass;
|
||||
this.resultSet = resultSet;
|
||||
this.resolver = new Resolver(resultSet);
|
||||
this.m = m;
|
||||
this.mv = mv;
|
||||
this.paramsAndLocals = paramsAndLocals;
|
||||
@ -147,6 +151,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
HashMap<String, String> genericsAndBounds) {
|
||||
|
||||
this.resultSet = resultSet;
|
||||
this.resolver = new Resolver(resultSet);
|
||||
this.mv = mv;
|
||||
this.isInterface = isInterface;
|
||||
this.classFiles = classFiles;
|
||||
@ -172,20 +177,21 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
lambdaExpression.methodBody.accept(this);
|
||||
}
|
||||
|
||||
public Resolver getResolver() {
|
||||
return resolver;
|
||||
}
|
||||
|
||||
public void isBinary(boolean isBinary) {
|
||||
this.isBinaryExp =isBinary;
|
||||
}
|
||||
|
||||
public String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||
return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Block block) {
|
||||
for (Statement stmt : block.getStatements()) {
|
||||
stmt.accept(this);
|
||||
if(stmt instanceof MethodCall) {
|
||||
String ret = getResolvedType(((MethodCall) stmt).getType());
|
||||
String ret = resolver.getResolvedType(((MethodCall) stmt).getType());
|
||||
if(!ret.equals("void"))
|
||||
mv.visitInsn(Opcodes.POP);
|
||||
}
|
||||
@ -220,7 +226,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
mv.visitVarInsn(Opcodes.ALOAD, paramsAndLocals.get(localVar.name));
|
||||
|
||||
if (isBinaryExp) {
|
||||
doUnboxing(getResolvedType(localVar.getType()));
|
||||
doUnboxing(resolver.getResolvedType(localVar.getType()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -254,13 +260,13 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
|
||||
if (isBinaryExp) {
|
||||
BinaryExpr binary = (BinaryExpr) assign.rightSide;
|
||||
String binaryType = getResolvedType(binary.getType());
|
||||
String binaryType = resolver.getResolvedType(binary.getType());
|
||||
doBoxing(binaryType);
|
||||
isBinaryExp = false;
|
||||
}
|
||||
|
||||
System.out.println("ASSIGN TYPE R: " + getResolvedType(assign.rightSide.getType()));
|
||||
String typeOfRightSide = getResolvedType(assign.rightSide.getType());
|
||||
System.out.println("ASSIGN TYPE R: " + resolver.getResolvedType(assign.rightSide.getType()));
|
||||
String typeOfRightSide = resolver.getResolvedType(assign.rightSide.getType());
|
||||
if(typeOfRightSide.contains("<")) {
|
||||
mv.visitTypeInsn(Opcodes.CHECKCAST, typeOfRightSide.substring(0, typeOfRightSide.indexOf('<')));
|
||||
}
|
||||
@ -272,11 +278,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
@Override
|
||||
public void visit(BinaryExpr binary) {
|
||||
isParentBinary = true;
|
||||
String lexpType = getResolvedType(binary.lexpr.getType());
|
||||
String rexpType = getResolvedType(binary.rexpr.getType());
|
||||
String lexpType = resolver.getResolvedType(binary.lexpr.getType());
|
||||
String rexpType = resolver.getResolvedType(binary.rexpr.getType());
|
||||
|
||||
String largerType = getLargerType(lexpType, rexpType);
|
||||
String typeOfBinary = getResolvedType(binary.getType());
|
||||
String typeOfBinary = resolver.getResolvedType(binary.getType());
|
||||
|
||||
if (typeOfBinary.equals(Type.getInternalName(String.class))) {
|
||||
mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(StringBuilder.class));
|
||||
@ -649,7 +655,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
}
|
||||
|
||||
for(int i=pos;i<kindOfLambda.getArgumentList().size();i++) {
|
||||
String t = "L" + getResolvedType(kindOfLambda.getArgumentList().get(i)) + ";";
|
||||
String t = "L" + resolver.getResolvedType(kindOfLambda.getArgumentList().get(i)) + ";";
|
||||
newDesc += t;
|
||||
}
|
||||
newDesc += lamDesc.substring(1);
|
||||
@ -746,11 +752,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
fieldVar.receiver.accept(this);
|
||||
// test (if)
|
||||
if (!fieldVar.receiver.getClass().equals(StaticClassName.class)) {
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, getResolvedType(fieldVar.receiver.getType()), fieldName, fieldDesc);
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, resolver.getResolvedType(fieldVar.receiver.getType()), fieldName, fieldDesc);
|
||||
}
|
||||
|
||||
if (isBinaryExp) {
|
||||
doUnboxing(getResolvedType(fieldVar.getType()));
|
||||
doUnboxing(resolver.getResolvedType(fieldVar.getType()));
|
||||
}
|
||||
// mv.visitFieldInsn(Opcodes.GETSTATIC,
|
||||
// fieldVar.receiver.getType().toString().replace(".", "/"),
|
||||
@ -769,7 +775,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
isBinaryExp = statement.isExprBinary();
|
||||
ifStmt.expr.accept(this);
|
||||
if(!(ifStmt.expr instanceof BinaryExpr)) {
|
||||
doUnboxing(getResolvedType(ifStmt.expr.getType()));
|
||||
doUnboxing(resolver.getResolvedType(ifStmt.expr.getType()));
|
||||
Label branchLabel = new Label();
|
||||
Label endLabel = new Label();
|
||||
mv.visitJumpInsn(Opcodes.IFEQ, branchLabel);
|
||||
@ -787,7 +793,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
public void visit(MethodCall methodCall) {
|
||||
boolean parentBinary = isParentBinary;
|
||||
System.out.println("In MethodCall = " + methodCall.name);
|
||||
String receiverName = getResolvedType(methodCall.receiver.getType());
|
||||
String receiverName = resolver.getResolvedType(methodCall.receiver.getType());
|
||||
System.out.println("Methods of " + receiverName + " ");
|
||||
java.lang.reflect.Method methodRefl = null;
|
||||
String clazz = receiverName.replace("/", ".");
|
||||
@ -927,7 +933,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
helper.createCheckCast(methodCall,mv);
|
||||
}
|
||||
if(isBinaryExp) {
|
||||
doUnboxing(getResolvedType(methodCall.getType()));
|
||||
doUnboxing(resolver.getResolvedType(methodCall.getType()));
|
||||
|
||||
}
|
||||
} else if(receiverName.contains("$$") && !methCallType.equals(Type.getInternalName(Object.class))) {
|
||||
@ -936,7 +942,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
System.out.println("ISParent Binary = "+isParentBinary +" -> " + parentBinary);
|
||||
if(methodRefl == null && (parentBinary || !isReturnStmt)) {
|
||||
if(isBinaryExp)
|
||||
doUnboxing(getResolvedType(methodCall.getType()));
|
||||
doUnboxing(resolver.getResolvedType(methodCall.getType()));
|
||||
}
|
||||
|
||||
}
|
||||
@ -958,7 +964,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
private String[] getTypes(List<Expression> arguments) {
|
||||
String[] types = new String[arguments.size()];
|
||||
for(int i = 0; i<arguments.size(); ++i) {
|
||||
String t = getResolvedType(arguments.get(i).getType());
|
||||
String t = resolver.getResolvedType(arguments.get(i).getType());
|
||||
types[i] = t;
|
||||
}
|
||||
return types;
|
||||
@ -1063,7 +1069,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
methodCall.arglist.accept(this);
|
||||
String d = "(";
|
||||
for (Expression e : methodCall.arglist.getArguments()) {
|
||||
d = d + "L" + getResolvedType(e.getType()) + ";";
|
||||
d = d + "L" + resolver.getResolvedType(e.getType()) + ";";
|
||||
}
|
||||
d += ")V";
|
||||
|
||||
@ -1086,7 +1092,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
unaryExpr.expr.accept(this);
|
||||
Operation op = unaryExpr.operation;
|
||||
|
||||
String typeOfUnary = getResolvedType(unaryExpr.getType());
|
||||
String typeOfUnary = resolver.getResolvedType(unaryExpr.getType());
|
||||
|
||||
boolean isIncOrDec = false;
|
||||
|
||||
@ -1180,7 +1186,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
|
||||
if (isBinary) {
|
||||
BinaryExpr binary = (BinaryExpr) aReturn.retexpr;
|
||||
doBoxing(getResolvedType(binary.getType()));
|
||||
doBoxing(resolver.getResolvedType(binary.getType()));
|
||||
// isBinaryExp = false;
|
||||
}
|
||||
|
||||
@ -1236,7 +1242,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
@Override
|
||||
public void visit(Literal literal) {
|
||||
Object value = literal.value;
|
||||
String typeOfLiteral = getResolvedType(literal.getType());
|
||||
String typeOfLiteral = resolver.getResolvedType(literal.getType());
|
||||
System.out.println("typeOfLiteral :=> "+ typeOfLiteral);
|
||||
// Der Wert des Literals wird auf den Stack geladen und
|
||||
// geboxt, wenn es nötig ist.
|
||||
@ -1467,7 +1473,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
//TODO: teste, ob man das für unary braucht
|
||||
if (isBinaryExp) {
|
||||
BinaryExpr binary = (BinaryExpr) al;
|
||||
String binaryType = getResolvedType(binary.getType());
|
||||
String binaryType = resolver.getResolvedType(binary.getType());
|
||||
doBoxing(binaryType);
|
||||
}
|
||||
statement = null;
|
||||
@ -1493,8 +1499,8 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
fDesc +=";";
|
||||
|
||||
|
||||
System.out.println("Receiver = " + getResolvedType(assignLeftSide.field.receiver.getType()));
|
||||
mv.visitFieldInsn(Opcodes.PUTFIELD, getResolvedType(assignLeftSide.field.receiver.getType()),
|
||||
System.out.println("Receiver = " + resolver.getResolvedType(assignLeftSide.field.receiver.getType()));
|
||||
mv.visitFieldInsn(Opcodes.PUTFIELD, resolver.getResolvedType(assignLeftSide.field.receiver.getType()),
|
||||
assignLeftSide.field.fieldVarName, fDesc);
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,8 @@ import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodUtility;
|
||||
import de.dhbwstuttgart.bytecode.utilities.Resolver;
|
||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
@ -48,6 +50,7 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> allPairs = new ArrayList<>();
|
||||
public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
||||
private ResultSet resultSet;
|
||||
private Resolver resolver;
|
||||
|
||||
public TPHExtractor() {
|
||||
|
||||
@ -55,6 +58,11 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
|
||||
public void setResultSet(ResultSet resultSet) {
|
||||
this.resultSet = resultSet;
|
||||
this.resolver = new Resolver(resultSet);
|
||||
}
|
||||
|
||||
public Resolver getResolver() {
|
||||
return resolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -153,7 +161,8 @@ public class TPHExtractor extends AbstractASTWalker {
|
||||
@Override
|
||||
public void visit(Method method) {
|
||||
inMethod = true;
|
||||
methodAndTph = new MethodAndTPH(method.name);
|
||||
String id = MethodUtility.createID(resolver,method);
|
||||
methodAndTph = new MethodAndTPH(id);
|
||||
super.visit(method);
|
||||
inMethod = false;
|
||||
ListOfMethodsAndTph.add(methodAndTph);
|
||||
|
@ -9,7 +9,7 @@ import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||
|
||||
public class MethodAndTPH {
|
||||
|
||||
private String name;
|
||||
private String id;
|
||||
private final ArrayList<String> tphs = new ArrayList<>();
|
||||
//private final ArrayList<GenericInsertPair> pairs = new ArrayList<>();
|
||||
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> pairs = new ArrayList<>();
|
||||
@ -17,7 +17,7 @@ public class MethodAndTPH {
|
||||
private final ArrayList<String> localTphs = new ArrayList<>();
|
||||
|
||||
public MethodAndTPH(String name) {
|
||||
this.name = name;
|
||||
this.id = name;
|
||||
}
|
||||
|
||||
public ArrayList<String> getTphs() {
|
||||
@ -31,8 +31,8 @@ public class MethodAndTPH {
|
||||
return pairs;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public ArrayList<String> getLocalTphs() {
|
||||
|
@ -0,0 +1,34 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.dhbwstuttgart.bytecode.utilities;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
|
||||
/**
|
||||
* @author fayez
|
||||
*
|
||||
*/
|
||||
public class MethodUtility {
|
||||
/**
|
||||
* Creates an ID for a method
|
||||
*
|
||||
* @param resolver type Resolver
|
||||
* @param method for which the ID will be generated
|
||||
* @return ID for the given method.
|
||||
* ID = ReturntypeMethodname(Parametertypes)
|
||||
*/
|
||||
public static String createID(Resolver resolver, Method method) {
|
||||
String id = resolver.getResolvedType(method.getReturnType()) + method.name + "(";
|
||||
Iterator<FormalParameter> itr = method.getParameterList().iterator();
|
||||
while (itr.hasNext()) {
|
||||
FormalParameter fp = itr.next();
|
||||
id += resolver.getResolvedType(fp.getType());
|
||||
}
|
||||
id += ")";
|
||||
return id;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package de.dhbwstuttgart.bytecode.utilities;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
/**
|
||||
* @author fayez
|
||||
*
|
||||
*/
|
||||
public class Resolver {
|
||||
|
||||
private ResultSet resultSet;
|
||||
|
||||
/**
|
||||
* @param resultSet
|
||||
*/
|
||||
public Resolver(ResultSet resultSet) {
|
||||
this.resultSet = resultSet;
|
||||
}
|
||||
|
||||
public String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||
return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor());
|
||||
}
|
||||
}
|
@ -14,11 +14,12 @@ import de.dhbwstuttgart.bytecode.constraint.EqualConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
public class Simplify {
|
||||
|
||||
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraints(String name, TPHExtractor tphExtractor,
|
||||
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraints(Method method, TPHExtractor tphExtractor,
|
||||
ArrayList<String> tphsClass) {
|
||||
// 1. check if there are any simple cycles like L<R and R<L:
|
||||
// a) yes => set L=R and:
|
||||
@ -45,11 +46,12 @@ public class Simplify {
|
||||
}
|
||||
ArrayList<TPHConstraint> consToRemove = new ArrayList<>();
|
||||
|
||||
String id = MethodUtility.createID(tphExtractor.getResolver(), method);
|
||||
// get all tph of the method
|
||||
ArrayList<String> methodTphs = new ArrayList<>();
|
||||
ArrayList<String> localTphs = new ArrayList<>();
|
||||
for (MethodAndTPH m : tphExtractor.ListOfMethodsAndTph) {
|
||||
if (m.getName().equals(name)) {
|
||||
if (m.getId().equals(id)) {
|
||||
methodTphs = m.getTphs();
|
||||
localTphs = m.getLocalTphs();
|
||||
break;
|
||||
|
@ -1,77 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package bytecode.simplifyalgo;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
||||
|
||||
/**
|
||||
* @author Fayez Abu Alia
|
||||
*
|
||||
*/
|
||||
public class CycleTest {
|
||||
|
||||
private static TPHExtractor tphExtractor;
|
||||
private static String methName;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
tphExtractor = new TPHExtractor();
|
||||
// A < B
|
||||
TPHConstraint c1 = new ExtendsConstraint("A", "B", Relation.EXTENDS);
|
||||
// B < C
|
||||
TPHConstraint c2 = new ExtendsConstraint("B", "C", Relation.EXTENDS);
|
||||
// C < D
|
||||
TPHConstraint c3 = new ExtendsConstraint("C", "D", Relation.EXTENDS);
|
||||
// D < A
|
||||
TPHConstraint c4 = new ExtendsConstraint("D", "A", Relation.EXTENDS);
|
||||
// name
|
||||
methName = "m";
|
||||
MethodAndTPH mtph = new MethodAndTPH("m");
|
||||
mtph.getTphs().add("A");
|
||||
mtph.getTphs().add("B");
|
||||
mtph.getTphs().add("C");
|
||||
mtph.getTphs().add("D");
|
||||
tphExtractor.ListOfMethodsAndTph.add(mtph);
|
||||
tphExtractor.allCons.add(c1);
|
||||
tphExtractor.allCons.add(c2);
|
||||
tphExtractor.allCons.add(c3);
|
||||
tphExtractor.allCons.add(c4);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
HashMap<TPHConstraint, HashSet<String>> result = new HashMap<>();
|
||||
HashSet<String> equals = new HashSet<>();
|
||||
equals.add("A");
|
||||
equals.add("B");
|
||||
equals.add("C");
|
||||
equals.add("D");
|
||||
TPHConstraint k = new ExtendsConstraint("A", Type.getInternalName(Object.class), Relation.EXTENDS);
|
||||
result.put(k, equals);
|
||||
|
||||
HashMap<TPHConstraint, HashSet<String>> sim = Simplify.simplifyConstraints(methName, tphExtractor,new ArrayList<>());
|
||||
boolean areEquals = SimpleCycle.areMapsEqual(result, sim);
|
||||
assertTrue(areEquals);
|
||||
}
|
||||
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package bytecode.simplifyalgo;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.utilities.ConstraintsFinder;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertPlacer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Fayez Abu Alia
|
||||
*
|
||||
*/
|
||||
public class FinderTest {
|
||||
|
||||
@Test
|
||||
public void testM1() {
|
||||
List<TPHConstraint> allCons = new ArrayList<>();
|
||||
// L < M
|
||||
TPHConstraint c1 = new ExtendsConstraint("L", "M", Relation.EXTENDS);
|
||||
// L < N
|
||||
TPHConstraint c2 = new ExtendsConstraint("L", "N", Relation.EXTENDS);
|
||||
// M < O
|
||||
TPHConstraint c3 = new ExtendsConstraint("M", "O", Relation.EXTENDS);
|
||||
// M < P
|
||||
TPHConstraint c4 = new ExtendsConstraint("M", "P", Relation.EXTENDS);
|
||||
|
||||
allCons.add(c1);
|
||||
allCons.add(c2);
|
||||
allCons.add(c3);
|
||||
allCons.add(c4);
|
||||
List<List<TPHConstraint>> res = new ArrayList<>();
|
||||
List<TPHConstraint> l1 = new ArrayList<>();
|
||||
List<TPHConstraint> l2 = new ArrayList<>();
|
||||
|
||||
l1.add(c1);
|
||||
l1.add(c2);
|
||||
|
||||
l2.add(c3);
|
||||
l2.add(c4);
|
||||
|
||||
res.add(l1);
|
||||
res.add(l2);
|
||||
|
||||
ConstraintsFinder finder = new ConstraintsFinder(allCons);
|
||||
|
||||
assertEquals(finder.findConstraints(), res);
|
||||
}
|
||||
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
package bytecode.simplifyalgo;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertPlacer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Fayez Abu Alia
|
||||
*
|
||||
*/
|
||||
public class SameLeftSide {
|
||||
// Typeplaceholders können nicht definiert werden, da die Konstruktor
|
||||
// private ist => Test geht nicht
|
||||
private static TPHExtractor tphExtractor;
|
||||
private static String methName;
|
||||
private static String methName2;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
tphExtractor = new TPHExtractor();
|
||||
// A < B
|
||||
TPHConstraint c1 = new ExtendsConstraint("A", "B", Relation.EXTENDS);
|
||||
// A < C
|
||||
TPHConstraint c2 = new ExtendsConstraint("A", "C", Relation.EXTENDS);
|
||||
// B < D
|
||||
TPHConstraint c3 = new ExtendsConstraint("B", "D", Relation.EXTENDS);
|
||||
// C < E
|
||||
TPHConstraint c4 = new ExtendsConstraint("C", "E", Relation.EXTENDS);
|
||||
// name
|
||||
methName = "m1";
|
||||
MethodAndTPH m1 = new MethodAndTPH("m1");
|
||||
|
||||
methName2 = "m2";
|
||||
MethodAndTPH m2 = new MethodAndTPH("m2");
|
||||
|
||||
m1.getTphs().add("A");
|
||||
m1.getTphs().add("B");
|
||||
m1.getTphs().add("D");
|
||||
|
||||
m2.getTphs().add("C");
|
||||
m2.getTphs().add("E");
|
||||
|
||||
tphExtractor.ListOfMethodsAndTph.add(m1);
|
||||
tphExtractor.ListOfMethodsAndTph.add(m2);
|
||||
|
||||
tphExtractor.allCons.add(c1);
|
||||
tphExtractor.allCons.add(c2);
|
||||
tphExtractor.allCons.add(c3);
|
||||
tphExtractor.allCons.add(c4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testM1() {
|
||||
HashMap<TPHConstraint, HashSet<String>> result = new HashMap<>();
|
||||
|
||||
TPHConstraint d = new ExtendsConstraint("D", Type.getInternalName(Object.class), Relation.EXTENDS);
|
||||
TPHConstraint a = new ExtendsConstraint("A", "D", Relation.EXTENDS);
|
||||
TPHConstraint b = new ExtendsConstraint("B", "D", Relation.EXTENDS);
|
||||
result.put(d, new HashSet<>());
|
||||
result.put(a, new HashSet<>());
|
||||
HashSet<String> hs = new HashSet<>();
|
||||
|
||||
result.put(b, hs);
|
||||
|
||||
HashMap<TPHConstraint, HashSet<String>> sim = Simplify.simplifyConstraints(methName, tphExtractor,new ArrayList<>());
|
||||
boolean areEquals = SimpleCycle.areMapsEqual(result, sim);
|
||||
assertTrue(areEquals);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testM2() {
|
||||
HashMap<TPHConstraint, HashSet<String>> result = new HashMap<>();
|
||||
|
||||
TPHConstraint e = new ExtendsConstraint("E", Type.getInternalName(Object.class), Relation.EXTENDS);
|
||||
TPHConstraint c = new ExtendsConstraint("C", "E", Relation.EXTENDS);
|
||||
|
||||
result.put(e, new HashSet<>());
|
||||
HashSet<String> hs = new HashSet<>();
|
||||
hs.add("B");
|
||||
result.put(c, hs);
|
||||
|
||||
HashMap<TPHConstraint, HashSet<String>> sim = Simplify.simplifyConstraints(methName2, tphExtractor,new ArrayList<>());
|
||||
boolean areEquals = SimpleCycle.areMapsEqual(result, sim);
|
||||
assertTrue(areEquals);
|
||||
}
|
||||
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
package bytecode.simplifyalgo;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
||||
/**
|
||||
*
|
||||
* @author Fayez Abu Alia
|
||||
*
|
||||
*/
|
||||
public class SimpleCycle {
|
||||
private static TPHExtractor tphExtractor;
|
||||
private static String methName;
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
tphExtractor = new TPHExtractor();
|
||||
// A < B
|
||||
TPHConstraint c1 = new ExtendsConstraint("A", "B", Relation.EXTENDS);
|
||||
// B < A
|
||||
TPHConstraint c2 = new ExtendsConstraint("B", "A", Relation.EXTENDS);
|
||||
// name
|
||||
methName = "m";
|
||||
tphExtractor.allCons.add(c1);
|
||||
tphExtractor.allCons.add(c2);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
HashMap<TPHConstraint, HashSet<String>> result = new HashMap<>();
|
||||
HashSet<String> equals = new HashSet<>();
|
||||
equals.add("A");
|
||||
equals.add("B");
|
||||
TPHConstraint k = new ExtendsConstraint("B", Type.getInternalName(Object.class), Relation.EXTENDS);
|
||||
result.put(k, equals);
|
||||
|
||||
HashMap<TPHConstraint, HashSet<String>> sim = Simplify.simplifyConstraints(methName, tphExtractor,new ArrayList<>());
|
||||
boolean areEquals = areMapsEqual(result, sim);
|
||||
assertTrue(areEquals);
|
||||
}
|
||||
|
||||
public static boolean areMapsEqual(HashMap<TPHConstraint, HashSet<String>> m1, HashMap<TPHConstraint, HashSet<String>> m2) {
|
||||
|
||||
for(TPHConstraint c : m1.keySet()) {
|
||||
for(TPHConstraint c2 : m2.keySet()) {
|
||||
if(c.getLeft().equals(c2.getLeft()) && c.getRight().equals(c2.getRight()) && c.getRel()==c2.getRel()) {
|
||||
HashSet<String> eq1 = m1.get(c);
|
||||
HashSet<String> eq2 = m2.get(c2);
|
||||
|
||||
if((eq1 == null && eq2 != null) || (eq1 != null && eq2 == null))
|
||||
return false;
|
||||
if(eq1 != null) {
|
||||
if(eq1.size() != eq2.size())
|
||||
return false;
|
||||
|
||||
for(String tph:eq1) {
|
||||
if(!eq2.contains(tph))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -13,12 +13,12 @@ public class OL {
|
||||
|
||||
// if the class contains just this method, then correct BC will be generated.
|
||||
// But if another methods are contained then the generated BC is not correct
|
||||
/* m(x) {
|
||||
m(x) {
|
||||
//x.add(1);
|
||||
x.addAll(x);
|
||||
return x;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
public class OLMain {
|
||||
|
Loading…
Reference in New Issue
Block a user