Experimenteller Status. Änderungen an ClassSignatur Generierung
This commit is contained in:
parent
1371220249
commit
29dea524a5
4
notizen/stan/lambdaBytecode/Lambda2.java
Normal file
4
notizen/stan/lambdaBytecode/Lambda2.java
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
class Lambda2<A,R extends A> {
|
||||
Fun1<A, ? super Fun1<R, Integer>> op = (f) -> f.apply(new Integer(2));
|
||||
}
|
@ -51,8 +51,8 @@ public class ClassGenerator extends ClassGen{
|
||||
* @param toTPH
|
||||
* @return Es gilt dann "toTPH extends Type"
|
||||
*/
|
||||
public org.apache.commons.bcel6.generic.Type getNearestNonTPHType(TypePlaceholder toTPH){
|
||||
Type t = resolveTPH(toTPH);
|
||||
public org.apache.commons.bcel6.generic.Type getNearestUsedType(TypePlaceholder toTPH, Menge<TypePlaceholder> usedTypes){
|
||||
Type t = resolveTPH(toTPH, usedTypes);
|
||||
if(t == null){
|
||||
return this.getInstructionFactory().createObjectType();
|
||||
}else if(t instanceof TypePlaceholder){ //Es muss sich in diesem Fall um einen TPH handeln:
|
||||
@ -62,9 +62,16 @@ public class ClassGenerator extends ClassGen{
|
||||
return t.getBytecodeType(this);
|
||||
}
|
||||
}
|
||||
public org.apache.commons.bcel6.generic.Type getNearestUsedType(TypePlaceholder toTPH){
|
||||
return this.getNearestUsedType(toTPH, null);
|
||||
}
|
||||
|
||||
public Type resolveTPH(TypePlaceholder typePlaceholder) {
|
||||
return tiResult.getTypeOfPlaceholder(typePlaceholder);
|
||||
return resolveTPH(typePlaceholder, null);
|
||||
}
|
||||
|
||||
public Type resolveTPH(TypePlaceholder typePlaceholder, Menge<TypePlaceholder> toOneOfTheseTypes) {
|
||||
return tiResult.getTypeOfPlaceholder(typePlaceholder, toOneOfTheseTypes);
|
||||
}
|
||||
|
||||
public String createLambdaMethodName() {
|
||||
|
@ -387,8 +387,7 @@ public class TypePlaceholder extends ObjectType
|
||||
// Ende Spezialfunktionen
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
private JavaCodeResult printJavaCodePr(ResultSet resultSet) {
|
||||
Type equalType = resultSet.getTypeEqualTo(this);
|
||||
if(equalType == null || equalType.equals(this)){
|
||||
//Für den Fall das der TPH nicht aufgelöst werden konnte.
|
||||
@ -400,9 +399,10 @@ public class TypePlaceholder extends ObjectType
|
||||
|
||||
return equalType.printJavaCode(resultSet);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JavaCodeResult printJavaCode(ResultSet resultSet, boolean resolveTPHs){
|
||||
if(resolveTPHs)return printJavaCode(resultSet);
|
||||
if(resolveTPHs)return printJavaCodePr(resultSet);
|
||||
return new JavaCodeResult(this.get_Name());
|
||||
}
|
||||
/**
|
||||
@ -457,10 +457,14 @@ public class TypePlaceholder extends ObjectType
|
||||
@Override
|
||||
public String getClassSignature(ClassGenerator cg) {
|
||||
//Die Signaturen in der Klasse bauen sich für Generische Variabeln (also TPHs) folgendermaßen auf: "GVAR:SuperClass"
|
||||
String ret = this.getBytecodeSignature(cg);
|
||||
ret = ret.substring(1, ret.length()-1) + ":"; //";" mit ":" ersetzen
|
||||
org.apache.commons.bcel6.generic.Type nearestType = cg.getNearestNonTPHType(this);
|
||||
if(nearestType instanceof TypePlaceholderType){ //Handelt es sich um einen weiteren TPH als nächsten Typ, so ist es ein allgemeiner Typ und wir nehmen Object als Superklasse
|
||||
String ret = this.get_Name();//this.getBytecodeSignature(cg);
|
||||
//ret = ret.substring(1, ret.length()-1) + ":"; //";" mit ":" ersetzen
|
||||
ret+=":";
|
||||
Menge<TypePlaceholder> possibleTPHs = cg.getUsedTPH();
|
||||
possibleTPHs.remove(this);
|
||||
org.apache.commons.bcel6.generic.Type nearestType = cg.getNearestUsedType(this, possibleTPHs);
|
||||
//if(nearestType instanceof TypePlaceholderType){ //Handelt es sich um einen weiteren TPH als nächsten Typ, so ist es ein allgemeiner Typ und wir nehmen Object als Superklasse
|
||||
if(nearestType == null){
|
||||
ret += cg.getInstructionFactory().createObjectType().getSignature();
|
||||
}else{
|
||||
ret += nearestType.getSignature();
|
||||
|
@ -2,7 +2,7 @@ package de.dhbwstuttgart.typeinference;
|
||||
|
||||
import java.util.Iterator;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
|
||||
@ -38,23 +38,48 @@ public class ResultSet implements Iterable<Pair> {
|
||||
* @return
|
||||
*/
|
||||
public Type getTypeEqualTo(Type type) {
|
||||
return getTypeEqualTo(type,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Löst den übergebenen Typ auf. Rückgabetyp ist ein Reftype oder Void
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public Type getTypeEqualTo(Type type, Menge<TypePlaceholder> ofType) {
|
||||
Type res = type;
|
||||
Menge<Pair> modifiedResultPairs = (Menge<Pair>) resultPairs.clone();
|
||||
int i = findPairWithTypeEqualTo(type, modifiedResultPairs);
|
||||
while(i != -1){
|
||||
res = modifiedResultPairs.get(i).TA2;
|
||||
modifiedResultPairs.remove(i);
|
||||
i = findPairWithTypeEqualTo(res, modifiedResultPairs);
|
||||
Ret r = findPairWithTypeEqualTo(type, modifiedResultPairs);
|
||||
while(r.i != -1 && r.ret != null){
|
||||
res = r.ret;
|
||||
if(ofType != null){
|
||||
if(res instanceof RefType)return res;
|
||||
if(ofType.contains(res) && ! res.equals(type))return res;
|
||||
}
|
||||
modifiedResultPairs.remove(r.i);
|
||||
r = findPairWithTypeEqualTo(res, modifiedResultPairs);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private int findPairWithTypeEqualTo(Type type, Menge<Pair> inResultPairs){
|
||||
class Ret{
|
||||
int i;
|
||||
Type ret;
|
||||
private Ret(int i, Type ret){
|
||||
this.i = i;
|
||||
this.ret = ret;
|
||||
}
|
||||
}
|
||||
|
||||
private Ret findPairWithTypeEqualTo(Type type, Menge<Pair> inResultPairs){
|
||||
for(int i = 0; i<inResultPairs.size();i++){
|
||||
Pair p = inResultPairs.elementAt(i);
|
||||
if((p.OperatorEqual() || p.OperatorSmallerExtends()) && p.TA1.equals(type))return i;
|
||||
if((p.OperatorEqual() || p.OperatorSmaller() || p.OperatorSmallerExtends()) && p.TA1.equals(type))
|
||||
return new Ret(i,p.TA2);
|
||||
if((p.OperatorSmallerExtends() || p.OperatorSmaller()) && p.TA2.equals(type))
|
||||
return new Ret(i, p.TA1);
|
||||
}
|
||||
return -1;
|
||||
return new Ret(-1,null);
|
||||
}
|
||||
|
||||
public Iterator<Pair> iterator() {
|
||||
|
@ -80,8 +80,11 @@ public class TypeinferenceResultSet
|
||||
* Ermittelt den in diesem ResultSet für den TypePlaceholder tph zugewiesenen Wert.
|
||||
* @author Andreas Stadelmeier, a10023
|
||||
*/
|
||||
public Type getTypeOfPlaceholder(TypePlaceholder tph){
|
||||
return this.getUnifiedConstraints().getTypeEqualTo(tph);
|
||||
public Type getTypeOfPlaceholder(TypePlaceholder tph){
|
||||
return this.getTypeOfPlaceholder(tph,null);
|
||||
}
|
||||
public Type getTypeOfPlaceholder(TypePlaceholder tph, Menge<TypePlaceholder> ofType){
|
||||
return this.getUnifiedConstraints().getTypeEqualTo(tph, ofType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,4 +1,4 @@
|
||||
|
||||
class Matrix {
|
||||
class Matrix2 {
|
||||
op = (f) -> f.apply(2);
|
||||
}
|
4
test/bytecode/Matrix_lambda3.jav
Normal file
4
test/bytecode/Matrix_lambda3.jav
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
class Matrix3 {
|
||||
op = (f) -> f.apply();
|
||||
}
|
@ -5,7 +5,7 @@ import org.junit.Test;
|
||||
public class Matrix_lambdaTest2 {
|
||||
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
||||
public final static String testFile = "Matrix_lambda2.jav";
|
||||
public final static String outputFile = "Matrix_lambda2.class";
|
||||
public final static String outputFile = "Matrix2.class";
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
14
test/bytecode/Matrix_lambdaTest3.java
Normal file
14
test/bytecode/Matrix_lambdaTest3.java
Normal file
@ -0,0 +1,14 @@
|
||||
package bytecode;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Matrix_lambdaTest3 {
|
||||
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
||||
public final static String testFile = "Matrix_lambda3.jav";
|
||||
public final static String outputFile = "Matrix3.class";
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ class Test2<X>{
|
||||
return f;
|
||||
}
|
||||
public static void main(String[] args){
|
||||
Test2<Integer> t = new Test2<>();
|
||||
System.out.println(t.m().apply(1));
|
||||
Matrix2<Integer,Integer> m2 = new Matrix2<>();
|
||||
System.out.println(m2.op.apply((Integer x) -> x));
|
||||
}
|
||||
}
|
||||
|
3
test/plugindevelopment/TypeInsertTests/LambdaTest29.jav
Normal file
3
test/plugindevelopment/TypeInsertTests/LambdaTest29.jav
Normal file
@ -0,0 +1,3 @@
|
||||
class LambdaTest29{
|
||||
lambda = (f)->f.apply();
|
||||
}
|
18
test/plugindevelopment/TypeInsertTests/LambdaTest29.java
Normal file
18
test/plugindevelopment/TypeInsertTests/LambdaTest29.java
Normal file
@ -0,0 +1,18 @@
|
||||
package plugindevelopment.TypeInsertTests;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class LambdaTest29 {
|
||||
|
||||
private static final String TEST_FILE = "LambdaTest29.jav";
|
||||
|
||||
@Test
|
||||
public void run(){
|
||||
Menge<String> mustContain = new Menge<String>();
|
||||
//mustContain.add("A a");
|
||||
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user