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;
|
String desc = null;
|
||||||
boolean hasGen = false;
|
boolean hasGen = false;
|
||||||
|
|
||||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||||
genericsAndBounds.containsKey(paramName);
|
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
|
||||||
hasGen = true;
|
if(genericsAndBounds.containsKey(typeOfParam)) {
|
||||||
|
hasGen = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
String sig = null;
|
String sig = null;
|
||||||
if(hasGen) {
|
if(hasGen) {
|
||||||
@ -166,7 +170,8 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
boolean hasGenInParameterList = genericsAndBounds.containsKey(method.getReturnType().acceptTV(new TypeToDescriptor()));
|
boolean hasGenInParameterList = genericsAndBounds.containsKey(method.getReturnType().acceptTV(new TypeToDescriptor()));
|
||||||
if(!hasGenInParameterList) {
|
if(!hasGenInParameterList) {
|
||||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||||
if(genericsAndBounds.containsKey(paramName)) {
|
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
|
||||||
|
if(genericsAndBounds.containsKey(typeOfParam)) {
|
||||||
hasGenInParameterList = true;
|
hasGenInParameterList = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -174,15 +179,9 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
}
|
}
|
||||||
String sig = null;
|
String sig = null;
|
||||||
boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList;
|
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 has generics or return type is TPH, create signature */
|
||||||
// if(method.getReturnType().acceptTV(new TypeToString()).equals("TPH")) {
|
if(hasGen||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) {
|
|
||||||
// resultset hier zum testen
|
// resultset hier zum testen
|
||||||
Signature signature = new Signature(method, genericsAndBoundsMethod, methodParamsAndTypes,resultSet);
|
Signature signature = new Signature(method, genericsAndBoundsMethod, methodParamsAndTypes,resultSet);
|
||||||
sig = signature.toString();
|
sig = signature.toString();
|
||||||
|
@ -170,7 +170,7 @@ public class BytecodeGenMethod implements StatementVisitor{
|
|||||||
this.lamCounter++;
|
this.lamCounter++;
|
||||||
|
|
||||||
System.out.println("Lam Hs Gens: " + lambdaExpression.getGenerics().iterator().hasNext());
|
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);
|
Lambda lam = new Lambda(lambdaExpression);
|
||||||
String lamDesc = lam.accept(new DescriptorToString(resultSet));
|
String lamDesc = lam.accept(new DescriptorToString(resultSet));
|
||||||
//Call site, which, when invoked, returns an instance of the functional interface to which
|
//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",
|
Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory",
|
||||||
"metafactory", mt.toMethodDescriptorString(), false);
|
"metafactory", mt.toMethodDescriptorString(), false);
|
||||||
String methodName = "lambda$new$" + this.lamCounter;
|
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 erasure
|
||||||
// Type arg1 = Type.getMethodType(typeErasure);
|
Type arg1 = Type.getMethodType(typeErasure);
|
||||||
Type arg1 = Type.getMethodType(lamDesc);
|
// Type arg1 = Type.getMethodType(lamDesc);
|
||||||
// real Type
|
// real Type
|
||||||
Type arg3 = Type.getMethodType(lamDesc);
|
Type arg3 = Type.getMethodType(lamDesc);
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import de.dhbwstuttgart.syntaxtree.Constructor;
|
|||||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
@ -96,16 +97,17 @@ public class Signature {
|
|||||||
}
|
}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "RT":
|
case "RT":
|
||||||
sv.visitClassType(t.acceptTV(new TypeToDescriptor()));
|
// sv.visitClassType(t.acceptTV(new TypeToDescriptor()));
|
||||||
|
sv.visitClassType(t.acceptTV(new TypeToSignature()));
|
||||||
break;
|
break;
|
||||||
case "GRT":
|
case "GRT":
|
||||||
GenericRefType g = (GenericRefType) t;
|
GenericRefType g = (GenericRefType) t;
|
||||||
sv.visitTypeVariable(g.getParsedName());
|
// sv.visitTypeVariable(g.getParsedName());
|
||||||
|
sv.visitTypeVariable(g.acceptTV(new TypeToSignature()));
|
||||||
break;
|
break;
|
||||||
case "TPH":
|
case "TPH":
|
||||||
System.out.println(resultSet.resolveType(t).resolvedType.acceptTV(new TypeToDescriptor()));
|
RefType r = (RefType) resultSet.resolveType(t).resolvedType;
|
||||||
// sv.visitInterface().visitClassType(resultSet.resolveType(t).resolvedType.acceptTV(new TypeToDescriptor())+"<Ljava/lang/Integer;Ljava/lang/Integer;>;");
|
sv.visitInterface().visitClassType(r.acceptTV(new TypeToSignature()));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if(!isParameterType)
|
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