forked from JavaTX/JavaCompilerCore
bytecode für Generics: LamAssignTest funktioniert richtig
This commit is contained in:
parent
b1b1cfdc54
commit
7b24e2d83f
@ -125,9 +125,13 @@ public class BytecodeGen implements ASTVisitor {
|
||||
|
||||
String desc = null;
|
||||
boolean hasGen = false;
|
||||
|
||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||
genericsAndBounds.containsKey(paramName);
|
||||
hasGen = true;
|
||||
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
|
||||
if(genericsAndBounds.containsKey(typeOfParam)) {
|
||||
hasGen = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String sig = null;
|
||||
if(hasGen) {
|
||||
@ -166,7 +170,8 @@ public class BytecodeGen implements ASTVisitor {
|
||||
boolean hasGenInParameterList = genericsAndBounds.containsKey(method.getReturnType().acceptTV(new TypeToDescriptor()));
|
||||
if(!hasGenInParameterList) {
|
||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||
if(genericsAndBounds.containsKey(paramName)) {
|
||||
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
|
||||
if(genericsAndBounds.containsKey(typeOfParam)) {
|
||||
hasGenInParameterList = true;
|
||||
break;
|
||||
}
|
||||
@ -174,15 +179,9 @@ public class BytecodeGen implements ASTVisitor {
|
||||
}
|
||||
String sig = null;
|
||||
boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList;
|
||||
// Wenn ReturnType has Generics?? Fun1<...> wie testet man das generic hat??
|
||||
System.out.println(method.getReturnType().acceptTV(new TypeToString()));
|
||||
// if(method.getReturnType().acceptTV(new TypeToString()).equals("TPH")) {
|
||||
// Signature signature = new Signature(method, genericsAndBoundsMethod, methodParamsAndTypes,resultSet);
|
||||
// sig = signature.toString();
|
||||
// System.out.println(sig);
|
||||
// }
|
||||
/* if method has generics, create signature */
|
||||
if(hasGen) {
|
||||
|
||||
/* if method has generics or return type is TPH, create signature */
|
||||
if(hasGen||method.getReturnType().acceptTV(new TypeToString()).equals("TPH")) {
|
||||
// resultset hier zum testen
|
||||
Signature signature = new Signature(method, genericsAndBoundsMethod, methodParamsAndTypes,resultSet);
|
||||
sig = signature.toString();
|
||||
|
@ -170,7 +170,7 @@ public class BytecodeGenMethod implements StatementVisitor{
|
||||
this.lamCounter++;
|
||||
|
||||
System.out.println("Lam Hs Gens: " + lambdaExpression.getGenerics().iterator().hasNext());
|
||||
System.out.println("Lam Hs Gens: " + lambdaExpression.getReturnType().acceptTV(new TypeToString()));
|
||||
System.out.println("Lam Hs Gens: " + resultSet.resolveType(lambdaExpression.getReturnType()).resolvedType.acceptTV(new TypeToSignature()));
|
||||
Lambda lam = new Lambda(lambdaExpression);
|
||||
String lamDesc = lam.accept(new DescriptorToString(resultSet));
|
||||
//Call site, which, when invoked, returns an instance of the functional interface to which
|
||||
@ -182,10 +182,19 @@ public class BytecodeGenMethod implements StatementVisitor{
|
||||
Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory",
|
||||
"metafactory", mt.toMethodDescriptorString(), false);
|
||||
String methodName = "lambda$new$" + this.lamCounter;
|
||||
// String typeErasure = "(Ljava/lang/Object;)Ljava/lang/Object;";
|
||||
|
||||
String typeErasure = "(";
|
||||
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
||||
while(itr.hasNext()) {
|
||||
itr.next();
|
||||
typeErasure += "L"+Type.getInternalName(Object.class) + ";";
|
||||
}
|
||||
|
||||
System.out.println("LamReturnType: "+lambdaExpression.getReturnType().acceptTV(new TypeToString()));
|
||||
typeErasure += ")L"+Type.getInternalName(Object.class) + ";";
|
||||
// Type erasure
|
||||
// Type arg1 = Type.getMethodType(typeErasure);
|
||||
Type arg1 = Type.getMethodType(lamDesc);
|
||||
Type arg1 = Type.getMethodType(typeErasure);
|
||||
// Type arg1 = Type.getMethodType(lamDesc);
|
||||
// real Type
|
||||
Type arg3 = Type.getMethodType(lamDesc);
|
||||
|
||||
|
@ -11,6 +11,7 @@ import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
@ -96,16 +97,17 @@ public class Signature {
|
||||
}
|
||||
switch (type) {
|
||||
case "RT":
|
||||
sv.visitClassType(t.acceptTV(new TypeToDescriptor()));
|
||||
// sv.visitClassType(t.acceptTV(new TypeToDescriptor()));
|
||||
sv.visitClassType(t.acceptTV(new TypeToSignature()));
|
||||
break;
|
||||
case "GRT":
|
||||
GenericRefType g = (GenericRefType) t;
|
||||
sv.visitTypeVariable(g.getParsedName());
|
||||
// sv.visitTypeVariable(g.getParsedName());
|
||||
sv.visitTypeVariable(g.acceptTV(new TypeToSignature()));
|
||||
break;
|
||||
case "TPH":
|
||||
System.out.println(resultSet.resolveType(t).resolvedType.acceptTV(new TypeToDescriptor()));
|
||||
// sv.visitInterface().visitClassType(resultSet.resolveType(t).resolvedType.acceptTV(new TypeToDescriptor())+"<Ljava/lang/Integer;Ljava/lang/Integer;>;");
|
||||
|
||||
RefType r = (RefType) resultSet.resolveType(t).resolvedType;
|
||||
sv.visitInterface().visitClassType(r.acceptTV(new TypeToSignature()));
|
||||
break;
|
||||
default:
|
||||
if(!isParameterType)
|
||||
|
53
src/de/dhbwstuttgart/bytecode/TypeToSignature.java
Normal file
53
src/de/dhbwstuttgart/bytecode/TypeToSignature.java
Normal file
@ -0,0 +1,53 @@
|
||||
package de.dhbwstuttgart.bytecode;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypeVisitor;
|
||||
|
||||
public class TypeToSignature implements TypeVisitor<String> {
|
||||
|
||||
@Override
|
||||
public String visit(RefType refType) {
|
||||
// return refType.toString().replace(".", "/");
|
||||
String params = "";
|
||||
if(refType.getParaList().size()>0){
|
||||
params += "<";
|
||||
Iterator<RefTypeOrTPHOrWildcardOrGeneric> it = refType.getParaList().iterator();
|
||||
while(it.hasNext()){
|
||||
RefTypeOrTPHOrWildcardOrGeneric param = it.next();
|
||||
params += "L"+param.toString().replace(".", "/");
|
||||
if(it.hasNext())params += ";";
|
||||
}
|
||||
params += ";>;";
|
||||
}
|
||||
return refType.getName().toString().replace(".", "/") + params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(SuperWildcardType superWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(TypePlaceholder typePlaceholder) {
|
||||
return typePlaceholder.toString().replace(".", "/");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(ExtendsWildcardType extendsWildcardType) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visit(GenericRefType genericRefType) {
|
||||
return genericRefType.getParsedName().replace(".", "/");
|
||||
}
|
||||
|
||||
}
|
7
test/bytecode/DuMethodTest.java
Normal file
7
test/bytecode/DuMethodTest.java
Normal file
@ -0,0 +1,7 @@
|
||||
package bytecode;
|
||||
|
||||
public class DuMethodTest extends JavaTXCompilerTest{
|
||||
public DuMethodTest() {
|
||||
this.fileName = "DuMethod";
|
||||
}
|
||||
}
|
3
test/bytecode/Exceptions.jav
Normal file
3
test/bytecode/Exceptions.jav
Normal file
@ -0,0 +1,3 @@
|
||||
public class Exceptions {
|
||||
// m(Integer i) throws
|
||||
}
|
7
test/bytecode/TestIfTest.java
Normal file
7
test/bytecode/TestIfTest.java
Normal file
@ -0,0 +1,7 @@
|
||||
package bytecode;
|
||||
|
||||
public class TestIfTest extends JavaTXCompilerTest{
|
||||
public TestIfTest() {
|
||||
this.fileName = "IfTest";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user