From a5c34896bab7b8f3fe45c6b5fd5cb2c763c45867 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Fri, 16 Sep 2016 14:26:18 +0200 Subject: [PATCH 1/6] Fehler in Lambda-Generierung fixen --- .../syntaxtree/statement/LambdaExpression.java | 13 ++++++++++++- test/bytecode/LambdaExpr.jav | 6 +++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java index 85f5327f..39a5e8eb 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.ArrayList; +import java.util.List; import org.apache.bcel.Const; import org.apache.bcel.Constants; @@ -214,6 +215,16 @@ public class LambdaExpression extends Expr{ return ret; } + /* + private List crawlVariables(SyntaxTreeNode inStatements){ + List ret = new ArrayList<>(); + for(SyntaxTreeNode child : inStatements.getChildren()){ + ret.addAll(crawlVariables(child)); + } + return ret; + } + */ + @Override public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) { DHBWConstantPoolGen cp = cg.getConstantPool(); @@ -296,7 +307,7 @@ public class LambdaExpression extends Expr{ String interfaceMethodName = "apply"; //Das ist ein Hack, funktioniert momentan, da nur FunN Interfaces für LambdaAusdrücke funktionieren //String invokeDynamicType = org.apache.bcel.generic.Type.getMethodSignature(lambdaType.getBytecodeType(cg, rs), additionalParameters); - String invokeDynamicType = org.apache.bcel.generic.Type.getMethodSignature(new org.apache.bcel.generic.ObjectType("Fun0"), additionalParameters); + String invokeDynamicType = org.apache.bcel.generic.Type.getMethodSignature(new org.apache.bcel.generic.ObjectType(lambdaType.get_Name()), additionalParameters); il.append(cg.getInstructionFactory().createInvokeDynamic(interfaceMethodName,invokeDynamicType, bMethod)); return il; diff --git a/test/bytecode/LambdaExpr.jav b/test/bytecode/LambdaExpr.jav index 882f8f9e..3339ec0e 100644 --- a/test/bytecode/LambdaExpr.jav +++ b/test/bytecode/LambdaExpr.jav @@ -1,9 +1,9 @@ class LambdaExpr { - void method() { + method() { lambda; - lambda = () -> 1; - + lambda = (Integer a) -> a; + return lambda; } } \ No newline at end of file From a33ce04734e3d856de78b024a0529ef46e5d5c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 30 Sep 2016 12:48:41 +0200 Subject: [PATCH 2/6] modified --- test/bytecode/Identity.jav | 3 +++ test/plugindevelopment/TypeInsertTests/Id.jav | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/test/bytecode/Identity.jav b/test/bytecode/Identity.jav index 28bdd3d1..4524c60b 100644 --- a/test/bytecode/Identity.jav +++ b/test/bytecode/Identity.jav @@ -1,4 +1,7 @@ class Identity{ op = (x)->x; +m(){ + op.apply(1); + } } \ No newline at end of file diff --git a/test/plugindevelopment/TypeInsertTests/Id.jav b/test/plugindevelopment/TypeInsertTests/Id.jav index 54a930cf..91d9acef 100644 --- a/test/plugindevelopment/TypeInsertTests/Id.jav +++ b/test/plugindevelopment/TypeInsertTests/Id.jav @@ -1,4 +1,8 @@ -class Id{ - op = (x)->x; -} +class Id { + op = (x) -> x; + +m(){ + op.apply(1); + } +} From e60e6b622c6d3cc9772817839bea11e78208ea8c Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Fri, 7 Oct 2016 14:12:18 +0200 Subject: [PATCH 3/6] Bugfix --- .../bytecode/ClassGenerator.java | 22 ++++++++++--------- src/de/dhbwstuttgart/syntaxtree/Class.java | 6 ++--- .../dhbwstuttgart/syntaxtree/Constructor.java | 3 ++- .../syntaxtree/FieldDeclaration.java | 6 ----- src/de/dhbwstuttgart/syntaxtree/Method.java | 5 +++-- .../dhbwstuttgart/syntaxtree/SourceFile.java | 14 +++++++++++- .../syntaxtree/factory/ASTFactory.java | 5 +++++ .../statement/LambdaExpression.java | 2 +- .../statement/LocalOrFieldVarOrClassname.java | 5 +++-- .../syntaxtree/statement/MethodCall.java | 10 ++++++--- .../syntaxtree/statement/Receiver.java | 1 + .../syntaxtree/type/RefType.java | 19 +++++++++------- .../dhbwstuttgart/syntaxtree/type/Type.java | 11 ++++++++++ test/bytecode/IdTest.java | 2 +- test/bytecode/SingleClassTester.java | 4 ++-- test/bytecode/SourceFileBytecodeTest.java | 11 ++++++++++ 16 files changed, 86 insertions(+), 40 deletions(-) diff --git a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java index 14c12a85..4da51404 100644 --- a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java +++ b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java @@ -33,7 +33,7 @@ public class ClassGenerator extends ClassGen{ private DHBWConstantPoolGen cp; private DHBWInstructionFactory factory; - private TypeinferenceResults tiResult; + //private TypeinferenceResults tiResult; private int lambdaMethodeNr = 0; private Type superClass; @@ -43,9 +43,9 @@ public class ClassGenerator extends ClassGen{ private List methodsNamesAndTypes = new LinkedList<>(); private MethodGenerator methodGenerator; - public ClassGenerator(String name, Type superClass, String string, short accessflags, String[] strings, TypeinferenceResults typeinferenceResults) { + public ClassGenerator(String name, Type superClass, String string, short accessflags, String[] strings) { super(name,superClass.get_Name(),string,accessflags,strings, new DHBWConstantPoolGen()); - this.tiResult = typeinferenceResults; + //this.tiResult = typeinferenceResultSet; this.superClass = superClass; cp = (DHBWConstantPoolGen) super.getConstantPool(); @@ -62,7 +62,7 @@ public class ClassGenerator extends ClassGen{ * Versucht einen Type zu finden von dem dieser TPH ein Subtyp sein muss. * @param toTPH * @return Es gilt dann "toTPH extends Type" - */ + public org.apache.bcel.generic.Type getNearestUsedType(Type t, Menge usedTypes){ if(t == null){ return this.getInstructionFactory().createObjectType(); @@ -70,13 +70,13 @@ public class ClassGenerator extends ClassGen{ //return getNearestType((TypePlaceholder) t); return new TypePlaceholderType((TypePlaceholder) t); }else{ - return t.getBytecodeType(this, getTypeinferenceResults().getTypeReconstructions().get(0)); + return t.getBytecodeType(this, getTypeinferenceResultSet().getTypeReconstructions().get(0)); } } public org.apache.bcel.generic.Type getNearestUsedType(TypePlaceholder toTPH){ return this.getNearestUsedType(toTPH, null); } - + */ public String createLambdaMethodName() { return "lambda$methode$"+(lambdaMethodeNr++); } @@ -185,7 +185,7 @@ public class ClassGenerator extends ClassGen{ TypePlaceholder tph = it.next(); //ret += tph.getBytecodeMethodSignature(this); //ret += ":"; - ret += tph.getClassSignature(this, getTypeinferenceResults().getTypeReconstructions().get(0)); + ret += tph.getClassSignature(this, null); //Es wird null übergeben. Die ClassSignaturen dürfen von keinem ResultSet abhängen. } ret += ">"; } @@ -199,11 +199,12 @@ public class ClassGenerator extends ClassGen{ public Map getExtraClasses() { return extraClasses; } - - public TypeinferenceResults getTypeinferenceResults() { + /* + public TypeinferenceResults getTypeinferenceResultSet() { return tiResult; } - + */ + @Override public void addMethod(Method m) { //TODO: Die Prüfung, ob Methode bereits vorhanden vor die Bytecodegenerierung verlegen (Beispielsweise in Method) @@ -225,4 +226,5 @@ public class ClassGenerator extends ClassGen{ return methodGenerator; } + } diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index f5cbb6c9..753ac838 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -91,7 +91,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I if(pkgName != null)throw new NotImplementedException(); short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public - _cg = new ClassGenerator(name, this.getSuperClass(), name + ".java", constants , new String[] { }, typeinferenceResults); //letzter Parameter sind implementierte Interfaces + _cg = new ClassGenerator(name, this.getSuperClass(), name + ".java", constants , new String[] { }); //letzter Parameter sind implementierte Interfaces _cp = _cg.getConstantPool(); _factory = new DHBWInstructionFactory(_cg, _cp); @@ -107,10 +107,11 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I } //Zuerst die Methoden und Felder abarbeiten: for(Method m : methods){ - m.genByteCode(_cg, this); + m.genByteCode(_cg, this, typeinferenceResults); } InstructionList fieldInitializations = new InstructionList(); for(FieldDeclaration f : fieldDeclarations){ + //Die Felder können noch nicht überladen werden. Hier ist nur die erste der Lösungen möglich: fieldInitializations.append(f.genByteCode(_cg, typeinferenceResults.getTypeReconstructions().get(0))); } //Die Konstruktoren müssen die Feld initialisierungswerte beinhalten: @@ -1011,7 +1012,6 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I public boolean isInterface(){ return false; } - /* private Collection getGenericClasses() { Collection results = new Menge<>(); diff --git a/src/de/dhbwstuttgart/syntaxtree/Constructor.java b/src/de/dhbwstuttgart/syntaxtree/Constructor.java index cf82752c..c72158e8 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Constructor.java +++ b/src/de/dhbwstuttgart/syntaxtree/Constructor.java @@ -28,6 +28,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResults; import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption; import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption; import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption; @@ -96,7 +97,7 @@ public class Constructor extends Method { } @Override - public void genByteCode(ClassGenerator cg, Class classObj) { + public void genByteCode(ClassGenerator cg, Class classObj, TypeinferenceResults resultSets) { this.genByteCode(cg, new InstructionList()); } // super statement muss drin sein diff --git a/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java b/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java index fe48efcd..245efed0 100644 --- a/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java +++ b/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java @@ -190,11 +190,5 @@ public class FieldDeclaration extends Field{ il.append(putFieldInstruction ); return il; } - - /*@Override - public void genByteCode(ClassGen cg) { - // TODO Auto-generated method stub - - }*/ } diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index d4f269a8..7df79dbe 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -44,6 +44,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.TypeInsertable; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResults; import de.dhbwstuttgart.typeinference.UndConstraint; import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption; import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption; @@ -396,8 +397,8 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable return super.equals(obj); } - public void genByteCode(ClassGenerator cg, Class classObj) { - List typeInterferenceResults = cg.getTypeinferenceResults().getTypeReconstructions(this, cg); + public void genByteCode(ClassGenerator cg, Class classObj, TypeinferenceResults resultSets) { + List typeInterferenceResults = resultSets.getTypeReconstructions(this, cg); DHBWInstructionFactory _factory = cg.getInstructionFactory(); for(TypeinferenceResultSet t: typeInterferenceResults){ diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 175639d7..91468ae4 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -1065,7 +1065,7 @@ public class SourceFile } /** - * Bisher wird nur der Bytecode der Klassen generiert. Nicht der Interfaces. + * Bytecode generieren für das resultSet * @return */ public Menge generateBytecode(TypeinferenceResults results) { @@ -1073,6 +1073,18 @@ public class SourceFile for(Class cl : this.KlassenVektor){ ret.add(cl.genByteCode(results)); } + /* + //Add all FunN Interfaces + for(Pair ucons : results.getUnifiedConstraints()){ + for(Type t : ucons.getTypes()){ + List xClasses = t.isClassFromJavaX(); + for(Class xClass : xClasses){ + ByteCodeResult bC = xClass.genByteCode(results); + if(! ret.contains(bC))ret.add(bC); + } + } + } + */ return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index c02ed64f..384e03fa 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -66,6 +66,11 @@ public class ASTFactory { return generatedClass; } + public static Class createInterface(String className, RefType type){ + //Class generatedClass = new Class(className, ) + return null; + } + public static Class createObjectClass() { Class generatedClass = new Class("java.lang.Object", 0); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java index 39a5e8eb..220517e2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java @@ -307,7 +307,7 @@ public class LambdaExpression extends Expr{ String interfaceMethodName = "apply"; //Das ist ein Hack, funktioniert momentan, da nur FunN Interfaces für LambdaAusdrücke funktionieren //String invokeDynamicType = org.apache.bcel.generic.Type.getMethodSignature(lambdaType.getBytecodeType(cg, rs), additionalParameters); - String invokeDynamicType = org.apache.bcel.generic.Type.getMethodSignature(new org.apache.bcel.generic.ObjectType(lambdaType.get_Name()), additionalParameters); + String invokeDynamicType = org.apache.bcel.generic.Type.getMethodSignature(lambdaType.getBytecodeType(cg, rs), additionalParameters); il.append(cg.getInstructionFactory().createInvokeDynamic(interfaceMethodName,invokeDynamicType, bMethod)); return il; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java index bb0992e8..c4f75ad4 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java @@ -160,11 +160,12 @@ public class LocalOrFieldVarOrClassname extends Expr public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) { InstructionList il = new InstructionList(); if(this.isFieldAccess){ + il.append(new This(this).genByteCode(cg, rs)); il.append(cg.getInstructionFactory().createFieldAccess(this.getParentClass().getName().toString(), this.get_Name(), this.getType().getBytecodeType(cg, rs), Constants.GETFIELD)); + }else{ + il.append(createLoad(cg, rs)); } - il.append(createLoad(cg, rs)); - return il; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java index 97cdc19c..c47a4442 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java @@ -4,6 +4,7 @@ package de.dhbwstuttgart.syntaxtree.statement; // ino.module.MethodCall.8639.import import java.util.Hashtable; +import org.apache.bcel.Const; import org.apache.bcel.Constants; import org.apache.bcel.generic.ClassGen; import org.apache.bcel.generic.InstructionFactory; @@ -333,9 +334,9 @@ public class MethodCall extends Expr de.dhbwstuttgart.syntaxtree.Class receiverClass = this.receiver.getReceiverClass(cg, rs); short kind = 0; if(receiverClass.isInterface()){ - kind = Constants.INVOKEINTERFACE; + kind = Const.INVOKEINTERFACE; }else{//Ansonsten muss es eine Klasse sein: - kind = Constants.INVOKEVIRTUAL; + kind = Const.INVOKEVIRTUAL; } org.apache.bcel.generic.Type[] argumentTypen = org.apache.bcel.generic.Type.NO_ARGS; @@ -353,7 +354,10 @@ public class MethodCall extends Expr } org.apache.bcel.generic.Type returnType = this.getType().getBytecodeType(cg, rs); - il.append(_factory.createInvoke(receiver.getReceiverClass(cg, rs).getName().toString(), this.get_Name(), returnType , argumentTypen, kind)); + il.append(_factory.createInvoke( + receiver.get_Expr().getType().getBytecodeType(cg, rs).toString(), + //receiver.getReceiverClass(cg, rs).getBytecodeType(cg, rs).toString(), + this.get_Name(), returnType , argumentTypen, kind)); return il; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java b/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java index 5c1d2bbd..2b0dbb0d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java @@ -122,5 +122,6 @@ public class Receiver public JavaCodeResult printJavaCode(ResultSet resultSet) { return new JavaCodeResult().attach(this.get_Expr().printJavaCode(resultSet)); } + } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index 27443bb4..16ca7b46 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -579,12 +579,9 @@ public class RefType extends ObjectType implements IMatchable @Override public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) { String combinedType = getCombinedType(cg, rs); - if(!combinedType.equals(getName().toString())){ - getSuperWildcardTypes(); - Class generatedClass = ASTFactory.createClass(getCombinedType(cg, rs), getGenericClassType(), null, null, new SourceFile()); - - cg.addExtraClass(generatedClass.genByteCode(new TypeinferenceResults()).getByteCode()); - } + /* + + */ String ret = new org.apache.bcel.generic.ObjectType(combinedType).getSignature(); return ret; } @@ -611,8 +608,14 @@ public class RefType extends ObjectType implements IMatchable } return sb.toString(); } - - return sb.append(this.getName().toString()).toString(); + String ret = sb.append(this.getName().toString()).toString(); + if(!ret.equals(getName().toString())){ + //getSuperWildcardTypes(); + Class generatedClass = ASTFactory.createClass(getCombinedType(cg, rs), getGenericClassType(), null, null, new SourceFile()); + + cg.addExtraClass(generatedClass.genByteCode(new TypeinferenceResults()).getByteCode()); + } + return ret; } public GenericClassType getGenericClassType(){ diff --git a/src/de/dhbwstuttgart/syntaxtree/type/Type.java b/src/de/dhbwstuttgart/syntaxtree/type/Type.java index 603258ea..812a0350 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/Type.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/Type.java @@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree.type; // ino.end // ino.module.Type.8677.import import java.util.ArrayList; +import java.util.List; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.bytecode.ClassGenerator; @@ -328,5 +329,15 @@ public abstract class Type extends SyntaxTreeNode implements IItemWithOffset public String getClassSignature(ClassGenerator cg, TypeinferenceResultSet rs){ return this.getBytecodeSignature(cg, rs); } + + /** + * Wird beim Bytecode gebraucht. + * Einige Klassen werden vom Compiler als gegeben angenommen, + * obwohl sie sich nicht in der Java Standard Library befinden. + * Diese müssen beim generieren von Bytecode als zusätzliche Klassen generiert werden. + * + * @return - Eine Liste der Klassen, welche bei Verwendung dieses Typs zusätzlich gebraucht werden. + */ + //public abstract List isClassFromJavaX(); } // ino.end diff --git a/test/bytecode/IdTest.java b/test/bytecode/IdTest.java index f5da1ab2..e7185ca5 100644 --- a/test/bytecode/IdTest.java +++ b/test/bytecode/IdTest.java @@ -18,4 +18,4 @@ public class IdTest extends SourceFileBytecodeTest{ Object obj = cls.newInstance(); assertTrue(true); } -} \ No newline at end of file +} diff --git a/test/bytecode/SingleClassTester.java b/test/bytecode/SingleClassTester.java index 2f731e5c..312416ab 100644 --- a/test/bytecode/SingleClassTester.java +++ b/test/bytecode/SingleClassTester.java @@ -41,12 +41,12 @@ public class SingleClassTester { for(ByteCodeResult result: bytecode){ JavaClass javaClass = result.getByteCode().getJavaClass(); javaClass.dump(new File(outputDirectory+javaClass.getClassName()+".class")); - + /* for(ClassGenerator cg: result.getByteCode().getExtraClasses().values()){ JavaClass jc = cg.getJavaClass(); jc.dump(new File(outputDirectory+jc.getClassName()+".class")); } - + */ Logger.getLogger("SingleClassTester").error(result.getByteCode().getJavaClass().toString(), Section.CODEGEN); } diff --git a/test/bytecode/SourceFileBytecodeTest.java b/test/bytecode/SourceFileBytecodeTest.java index 3cf8ce2a..d975c0c1 100644 --- a/test/bytecode/SourceFileBytecodeTest.java +++ b/test/bytecode/SourceFileBytecodeTest.java @@ -4,6 +4,8 @@ import static org.junit.Assert.*; import java.io.File; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; @@ -60,4 +62,13 @@ public abstract class SourceFileBytecodeTest extends TestCase{ return new URLClassLoader(urls); } + + protected void testMethod(String methodName) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException{ + Class testClass = getClassToTest(); + for(Method m : testClass.getMethods()){ + if(m.getName().equals(methodName)){ + m.invoke(testClass, new Object[0]); + } + } + } } From 107201c00ce2e4bec9cf50d8bcf4396ff4f4668b Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Fri, 28 Oct 2016 18:31:42 +0200 Subject: [PATCH 4/6] Fehler in FunN Generierung beheben --- .../bytecode/ClassGenerator.java | 37 ++- src/de/dhbwstuttgart/core/MyCompiler.java | 2 +- src/de/dhbwstuttgart/syntaxtree/Class.java | 33 ++- .../dhbwstuttgart/syntaxtree/Constructor.java | 4 +- .../syntaxtree/GenericDeclarationList.java | 4 + src/de/dhbwstuttgart/syntaxtree/Method.java | 10 +- .../dhbwstuttgart/syntaxtree/SourceFile.java | 225 +----------------- .../syntaxtree/factory/ASTFactory.java | 18 +- .../dhbwstuttgart/syntaxtree/type/FunN.java | 13 +- .../syntaxtree/type/FunVoidN.java | 3 +- .../syntaxtree/type/RefType.java | 13 +- .../syntaxtree/type/TypePlaceholder.java | 107 +-------- test/bytecode/SingleClassTester.java | 9 +- 13 files changed, 120 insertions(+), 358 deletions(-) diff --git a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java index 4da51404..a94dda29 100644 --- a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java +++ b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java @@ -20,6 +20,8 @@ import org.apache.bcel.classfile.Signature; import org.apache.bcel.generic.ClassGen; import org.apache.bcel.generic.ConstantPoolGen; +import de.dhbwstuttgart.parser.JavaClassName; +import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; @@ -33,9 +35,10 @@ public class ClassGenerator extends ClassGen{ private DHBWConstantPoolGen cp; private DHBWInstructionFactory factory; - //private TypeinferenceResults tiResult; + private TypeinferenceResults tiResult; private int lambdaMethodeNr = 0; private Type superClass; + private List generics; private Menge usedTPHs = new Menge<>(); @@ -43,11 +46,14 @@ public class ClassGenerator extends ClassGen{ private List methodsNamesAndTypes = new LinkedList<>(); private MethodGenerator methodGenerator; - public ClassGenerator(String name, Type superClass, String string, short accessflags, String[] strings) { - super(name,superClass.get_Name(),string,accessflags,strings, new DHBWConstantPoolGen()); + public ClassGenerator(JavaClassName name, Type superClass, List generics, + String sourceFileName, short accessflags, String[] implementedInterfaces, TypeinferenceResults rs) { + super(name.toString(),superClass.get_Name(),sourceFileName,accessflags,implementedInterfaces, new DHBWConstantPoolGen()); //this.tiResult = typeinferenceResultSet; this.superClass = superClass; + this.generics = generics; + tiResult = rs; cp = (DHBWConstantPoolGen) super.getConstantPool(); factory = new DHBWInstructionFactory(this, cp); this.setMajor(52); //Java 8 Version 52.0 @@ -152,8 +158,18 @@ public class ClassGenerator extends ClassGen{ //Signatur setzen: String typeParameters = this.generateParameterSignature(); - String superClassSignature = this.superClass.getBytecodeSignature(this, null); - String classSignature = typeParameters + superClassSignature; + String superClassSignature = this.superClass.get_Name(); + if(this.superClass instanceof RefType && + ((RefType)superClass).get_ParaList() != null && + ((RefType)superClass).get_ParaList().size() > 0){ + superClassSignature += "<"; + RefType superRefType = (RefType) this.superClass; + for(Type param : superRefType.get_ParaList()){ + superClassSignature += param.getBytecodeSignature(this, null); + } + superClassSignature += ">"; + } + String classSignature = typeParameters + superClassSignature; //TOOD: Hier noch die Signaturen der SuperInterfaces anfügen if(classSignature.length()>0){ this.addAttribute(new Signature(cp.addUtf8("Signature"),2,cp.addUtf8(classSignature),cp.getConstantPool())); } @@ -178,6 +194,16 @@ public class ClassGenerator extends ClassGen{ private String generateParameterSignature(){ String ret = ""; + //ret += "L" + this.getClassName().replace(".", "/") + ";"; + if(this.generics != null && this.generics.size() > 0){ + ret += "<"; + for(GenericTypeVar gtv : this.generics){ + ret += gtv.getBytecodeSignature(this, tiResult.getTypeReconstructions().get(0)); + } + ret += ">"; + } + + /* if(this.getUsedTPH().size()>0){ ret += "<"; Iterator it = ((Menge)this.getUsedTPH().clone()).iterator(); @@ -189,6 +215,7 @@ public class ClassGenerator extends ClassGen{ } ret += ">"; } + */ return ret; } diff --git a/src/de/dhbwstuttgart/core/MyCompiler.java b/src/de/dhbwstuttgart/core/MyCompiler.java index c363041d..9591cffc 100755 --- a/src/de/dhbwstuttgart/core/MyCompiler.java +++ b/src/de/dhbwstuttgart/core/MyCompiler.java @@ -148,7 +148,7 @@ public class MyCompiler implements MyCompilerAPI{ * Fun0-FunN (momentan für N = 6) * @return */ - private TypeAssumptions makeFunNAssumptions(){ + public static TypeAssumptions makeFunNAssumptions(){ TypeAssumptions ret = new TypeAssumptions(); //Basic Assumptions für die FunN Interfaces: diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index 753ac838..bf16babd 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -72,7 +72,8 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I protected static Logger parserlog = Logger.getLogger("parser"); protected UsedId pkgName; protected Modifiers modifiers; - protected String name; + protected JavaClassName name; + protected List implementedInterfaces = new ArrayList<>(); /** * @@ -90,8 +91,10 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I logger.debug("Test"); if(pkgName != null)throw new NotImplementedException(); - short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public - _cg = new ClassGenerator(name, this.getSuperClass(), name + ".java", constants , new String[] { }); //letzter Parameter sind implementierte Interfaces + short constants = Const.ACC_PUBLIC; //Per Definition ist jede Methode public + if(isInterface())constants+=Const.ACC_INTERFACE; + + _cg = new ClassGenerator(name, this.getSuperClass(), this.getGenericParameter(), name + ".java", constants , new String[] { }, typeinferenceResults); //letzter Parameter sind implementierte Interfaces _cp = _cg.getConstantPool(); _factory = new DHBWInstructionFactory(_cg, _cp); @@ -105,6 +108,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I if(field instanceof FieldDeclaration)fieldDeclarations.add((FieldDeclaration)field); //field.genByteCode(_cg); } + //Zuerst die Methoden und Felder abarbeiten: for(Method m : methods){ m.genByteCode(_cg, this, typeinferenceResults); @@ -138,7 +142,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I } public void setName(String strName) { - name = strName; + name = new JavaClassName(strName); } public void setModifiers(Modifiers mod) { @@ -195,7 +199,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I public Class(String name, int offset) { - this.name = name; + this.name = new JavaClassName(name); if(name.equals("java.lang.Object")){ superclassid=null; } @@ -203,8 +207,18 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I if(!name.equals("Object") && !name.equals("java.lang.Object"))//Alle Klassen außer Object erben von Object: this.superClass = new Class("java.lang.Object", -1).getType(); } - // ino.end + public Class(JavaClassName name, List methoden, List felder, Modifiers modifier, + boolean isInterface, RefType superClass, List implementedInterfaces, + GenericDeclarationList generics, int offset){ + this(name.toString(), superClass, modifier, new Menge<>()); + this.implementedInterfaces = implementedInterfaces; + this.offset = offset; + this.isInterface = isInterface; + this.isInterface(); + this.genericClassParameters = generics; + } + /** * Erstellt eine Klasse, welche nur für die Assumptions verwendet wird. * Sie enthält keine unnötigen Informationen, wie Offset oder ClassBody. @@ -695,7 +709,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I { //return superclassid.toString() + body.toString(); //geaendert PL 07-07-28 - return name; + return name.toString(); } // ino.end @@ -897,7 +911,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I break; } } - if(!constructorVorhanden){//Falls kein Konstruktor vorhanden ist, muss noch der Standardkonstruktor angefügt werden: + if(!constructorVorhanden && ! isInterface()){//Falls kein Konstruktor vorhanden ist, muss noch der Standardkonstruktor angefügt werden: Block konstruktorBlock = new Block(); konstruktorBlock.statements.add(new SuperCall(konstruktorBlock)); Constructor standardKonstruktor = new Constructor(Method.createEmptyMethod(konstruktorBlock,this.getName().toString(), this), this); @@ -1009,8 +1023,9 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I return true; } + protected boolean isInterface; public boolean isInterface(){ - return false; + return isInterface; } /* private Collection getGenericClasses() { diff --git a/src/de/dhbwstuttgart/syntaxtree/Constructor.java b/src/de/dhbwstuttgart/syntaxtree/Constructor.java index c72158e8..4e97e681 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Constructor.java +++ b/src/de/dhbwstuttgart/syntaxtree/Constructor.java @@ -66,7 +66,9 @@ public class Constructor extends Method { InstructionList il = new InstructionList(); //sollte nicht new sein sondern aus Block kommen Class parentClass = this.getParentClass(); - MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg, null), this.parameterlist.getBytecodeTypeList(cg,null) , this.parameterlist.getParameterNameArray(), "", parentClass.name, il, _cp); + MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, + this.getType().getBytecodeType(cg, null), this.parameterlist.getBytecodeTypeList(cg,null), + this.parameterlist.getParameterNameArray(), "", parentClass.name.toString(), il, _cp); //FieldInitializations an Block anfügen Block block = this.get_Block(); diff --git a/src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java b/src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java index 45fb0f09..d3c6d6ce 100644 --- a/src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java +++ b/src/de/dhbwstuttgart/syntaxtree/GenericDeclarationList.java @@ -21,6 +21,10 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable gtvs = new Menge<>(); + public GenericDeclarationList(){ + this(new Menge(), -1); + } + public GenericDeclarationList(Menge values, int endOffset) { this.addAll(values); this.offsetOfLastElement = endOffset; diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index 7df79dbe..2a7b38e9 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -81,7 +81,8 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable super(offset); } - public Method(String name, Type returnType, ParameterList parameterList, Block block, GenericDeclarationList gtvDeclarations, int offset) { + public Method(String name, Type returnType, ParameterList parameterList, Block block, + GenericDeclarationList gtvDeclarations, int offset) { this(offset); /* * if(parameterList != null)parameterList.parserPostProcessing(this); @@ -405,7 +406,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable addMethodToClassGenerator(cg, _factory, t); } } - + private void addMethodToClassGenerator(ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) { DHBWConstantPoolGen _cp = cg.getConstantPool(); InstructionList il = new InstructionList(); @@ -422,7 +423,10 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable Type returnType = this.getType(); - MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes.toArray(new org.apache.bcel.generic.Type[parameterlist.size()]) , argumentNames.toArray(new String[parameterlist.size()]), this.get_Method_Name(), getParentClass().name, il, _cp); + MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), + argumentTypes.toArray(new org.apache.bcel.generic.Type[parameterlist.size()]) , + argumentNames.toArray(new String[parameterlist.size()]), this.get_Method_Name(), + getParentClass().name.toString(), il, _cp); cg.setMethodeGenerator(method); diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 91468ae4..7b7ec1dc 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -707,227 +707,6 @@ public class SourceFile } //} } - // ino.end - - - // ino.method.makeBasicAssumptions.21418.defdescription type=javadoc - /** - * Erzeugt die Anfangsinformationen �ber bereits bekannte Klassen. - *
Achtung Workaround: Die RefTypes m�ssen sp�ter noch durch BaseTypes - * ersetzt werden.
- * Author: J�rg B�uerle - * - * @return A priori Typinformationen - * @throws ClassNotFoundException - */ - // ino.end - // ino.method.makeBasicAssumptions.21418.definition - private TypeAssumptions makeBasicAssumptions() - // ino.end - // ino.method.makeBasicAssumptions.21418.body - { - /* - if(LOAD_BASIC_ASSUMPTIONS_FROM_JRE){ - - Menge strImports=new Menge(); - ImportDeclarations usedIdImports=getImports(); - for(int i=0;i()); - foo.addFieldOrLocalVarAssumption(instVar); - - meth = new CMethodTypeAssumption(new RefType("java.lang.Integer", 0), "", new RefType("java.lang.Integer",-1), 0,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge(),null); - foo.addMethodIntersectionType(new CIntersectionType(meth)); - - meth = new CMethodTypeAssumption(new RefType("java.lang.Integer", 0), "", new RefType("java.lang.Integer",-1),1, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge(),null); - meth.addParaAssumption(new CParaTypeAssumption("java.lang.Integer", "", 1, 0,"value", new RefType("java.lang.Integer",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge())); - foo.addMethodIntersectionType(new CIntersectionType(meth)); - - meth = new CMethodTypeAssumption(new RefType("java.lang.Integer", 0), "intValue", new RefType("java.lang.Integer",-1), 0,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge(),null); - foo.addMethodIntersectionType(new CIntersectionType(meth)); - - - - c = new BasicAssumptionClass("java.lang.Integer", mod); - - // ui = new UsedId(); - // ui.set_Name("Super-Class-Blub"); - // c.set_UsedId(ui); - // pl = new Menge(); - // pl.addElement(new GenericTypeVar("bla")); - // c.set_ParaList(pl); - this.addElement(c); - - //------------------------ - // Boolean bauen: - //------------------------ - foo.addClassName("java.lang.Boolean"); //PL 05-08-01 eingefuegt - meth = new CMethodTypeAssumption(new RefType("java.lang.Boolean", 0), "", new RefType("java.lang.Boolean",-1),0, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge(),null); - foo.addMethodIntersectionType(new CIntersectionType(meth)); - - meth = new CMethodTypeAssumption(new RefType("java.lang.Boolean", 0), "", new RefType("java.lang.Boolean",-1), 1,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge(),null); - meth.addParaAssumption(new CParaTypeAssumption("java.lang.Boolean", "", 1, 0, "value", new RefType("java.lang.Boolean",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge())); - foo.addMethodIntersectionType(new CIntersectionType(meth)); - - meth = new CMethodTypeAssumption(new RefType("java.lang.Boolean", 0), "booleanValue", new RefType("java.lang.Boolean",-1), 0,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge(),null); - foo.addMethodIntersectionType(new CIntersectionType(meth)); - - c = new BasicAssumptionClass("java.lang.Boolean", mod); - - // ui = new UsedId(); - // ui.set_Name("Super-Class-Blub"); - // c.set_UsedId(ui); - // pl = new Menge(); - // pl.addElement(new GenericTypeVar("bla")); - // c.set_ParaList(pl); - this.addElement(c); - - //------------------------ - // Character bauen: - //------------------------ - foo.addClassName("java.lang.Character"); //PL 05-08-01 eingefuegt - meth = new CMethodTypeAssumption(new RefType("java.lang.Character", 0), "", new RefType("java.lang.Character",-1),0, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge(),null); - foo.addMethodIntersectionType(new CIntersectionType(meth)); - - meth = new CMethodTypeAssumption(new RefType("java.lang.Character", 0), "", new RefType("java.lang.Character",-1),1, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge(),null); - meth.addParaAssumption(new CParaTypeAssumption("java.lang.Character", "", 1, 0,"value", new RefType("java.lang.Character",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge())); - foo.addMethodIntersectionType(new CIntersectionType(meth)); - - meth = new CMethodTypeAssumption(new RefType("java.lang.Character", 0), "charValue", new BooleanType(),0, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge(),null); - foo.addMethodIntersectionType(new CIntersectionType(meth)); - - c = new BasicAssumptionClass("java.lang.Character", mod); - - // ui = new UsedId(); - // ui.set_Name("Super-Class-Blub"); - // c.set_UsedId(ui); - // pl = new Menge(); - // pl.addElement(new GenericTypeVar("bla")); - // c.set_ParaList(pl); - this.addElement(c); - - //------------------------ - // Menge bauen: - //------------------------ - foo.addClassName("java.lang.Menge"); //PL 05-08-01 eingefuegt - TypePlaceholder E = TypePlaceholder.fresh(); // Sp�ter ersetzen durch GenericTypeVar - Menge typeGenPara = new Menge(); - typeGenPara.addElement(new GenericTypeVar(E.getName(),-1)); - foo.addGenericTypeVars("java.lang.Menge", typeGenPara); - meth = new CMethodTypeAssumption(new RefType("java.lang.Menge", 0), "elementAt", new GenericTypeVar(E.getName(),-1), 1,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge(),null); - meth.addParaAssumption(new CParaTypeAssumption("java.lang.Menge", "elementAt", 1, 0, "index", new RefType("java.lang.Integer",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge())); - foo.addMethodIntersectionType(new CIntersectionType(meth)); - - meth = new CMethodTypeAssumption(new RefType("java.lang.Menge", 0), "addElement", new Void(-1),1, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge(),null); - meth.addParaAssumption(new CParaTypeAssumption("java.lang.Menge", "addElement", 1, 0,"element", new GenericTypeVar(E.getName(),-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge())); - foo.addMethodIntersectionType(new CIntersectionType(meth)); - - meth = new CMethodTypeAssumption(new RefType("java.lang.Menge", 0), "size", new RefType("java.lang.Integer",-1), 0,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge(),null); - foo.addMethodIntersectionType(new CIntersectionType(meth)); - - c = new BasicAssumptionClass("java.lang.Menge", mod); - - // ui = new UsedId(); - // ui.set_Name("Super-Class-Blub"); - // c.set_UsedId(ui); - // pl = new Menge(); - // pl.addElement(E); - // c.set_ParaList(pl); - this.addElement(c); - - //------------------------ - // Stack bauen: - //------------------------ - foo.addClassName("java.lang.Stack"); //PL 05-08-01 eingefuegt - c = new BasicAssumptionClass("java.lang.Stack", mod); - ui = new UsedId(-1); - ui.set_Name("java.lang.Menge"); - c.set_UsedId(ui); - // pl = new Menge(); - // pl.addElement(E); - // c.set_ParaList(pl); - this.addElement(c); - - return foo; - */ - TypeAssumptions ret = new TypeAssumptions(); - - //Basic Assumptions für die FunN Interfaces: - //TODO: Hier mehr als Fun1-Fun5 implementieren - for(int i = 0; i<6; i++){ - FunNInterface funN = new FunNInterface(i); - ret.add(funN.getPublicFieldAssumptions()); - } - - return ret; //TODO: Diese TypeAssumptions mit basic-Assumptions füllen - } - // ino.end - - // ino.method.setImports.21421.definition - private void setImports(ImportDeclarations newImports) - // ino.end - // ino.method.setImports.21421.body - { - this.imports=newImports; - - } - // ino.end - - - // ino.method.removeBasicAssumptions.21424.defdescription type=javadoc - /** - * L�scht die Anfangsinformation wieder aus dem Klassenvektor - *
Author: J�rg B�uerle - */ - // ino.end - // ino.method.removeBasicAssumptions.21424.definition - private void removeBasicAssumptions() - // ino.end - // ino.method.removeBasicAssumptions.21424.body - { - for(int i=0; i supertypeGenPara @@ -65,10 +72,13 @@ public class ASTFactory { return generatedClass; } - - public static Class createInterface(String className, RefType type){ - //Class generatedClass = new Class(className, ) - return null; +*/ + public static Class createInterface(String className, RefType superClass, Modifiers modifiers, + Menge supertypeGenPara, SourceFile parent){ + Class generatedClass = new Class(new JavaClassName(className), new ArrayList(), new ArrayList(), modifiers, + true, superClass, new ArrayList(), new GenericDeclarationList(), -1); + generatedClass.parserPostProcessing(parent); + return generatedClass; } public static Class createObjectClass() { diff --git a/src/de/dhbwstuttgart/syntaxtree/type/FunN.java b/src/de/dhbwstuttgart/syntaxtree/type/FunN.java index 7657c791..6b3613b9 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/FunN.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/FunN.java @@ -13,6 +13,7 @@ import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.ParameterList; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; +import de.dhbwstuttgart.syntaxtree.factory.NameGenerator; import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.DebugException; @@ -50,18 +51,19 @@ public class FunN extends RefType { /** * Spezieller Konstruktor um eine FunN ohne Returntype zu generieren - */ + protected FunN(List list){ super("",null,0); if(list==null)throw new NullPointerException(); setT(list); this.name = new JavaClassName("Fun"+list.size());//getName(); } + */ /** * Erstellt eine FunN: * FunN - * R und T1 - TparameterCount werden mit TypePlaceholdern besetzt. + * R und T1 - TparameterCount werden mit GenericTypeVars besetzt. * @param parameterCount */ public FunN(int parameterCount) { @@ -69,14 +71,15 @@ public class FunN extends RefType { if(parameterCount<0)throw new RuntimeException("Anzahl der Parameter muss >0 sein"); Menge t = new Menge(); for(int i=0;i T) { - super(T); + super(null,T); + this.setR(new Void(this, -1)); this.name = new JavaClassName("FunVoid"+T.size()); } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index 16ca7b46..bbd2b533 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -589,7 +589,7 @@ public class RefType extends ObjectType implements IMatchable public String getCombinedType(ClassGenerator cg, TypeinferenceResultSet rs){ //Bsp.: Ljava/util/Vector; StringBuilder sb = new StringBuilder(); - + String ret; if(parameter != null && parameter.size() > 0){ sb.append(getName().toString().replace(".", "%")); sb.append("%%"); @@ -606,21 +606,24 @@ public class RefType extends ObjectType implements IMatchable sb.append("%"); } - return sb.toString(); - } - String ret = sb.append(this.getName().toString()).toString(); + ret = sb.toString(); + }else{ + ret = sb.append(this.getName().toString()).toString(); + } if(!ret.equals(getName().toString())){ //getSuperWildcardTypes(); - Class generatedClass = ASTFactory.createClass(getCombinedType(cg, rs), getGenericClassType(), null, null, new SourceFile()); + Class generatedClass = ASTFactory.createInterface(ret, this, null, null, new SourceFile()); cg.addExtraClass(generatedClass.genByteCode(new TypeinferenceResults()).getByteCode()); } return ret; } + /* public GenericClassType getGenericClassType(){ return new GenericClassType(getName().toString(), getParaList(), parent, getOffset()); } + */ } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java b/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java index 96274d36..76e87f2f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java @@ -14,6 +14,7 @@ import de.dhbwstuttgart.bytecode.TypePlaceholderType; import de.dhbwstuttgart.core.MyCompiler; import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; +import de.dhbwstuttgart.syntaxtree.factory.NameGenerator; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.TypeInsertable; @@ -39,8 +40,6 @@ public class TypePlaceholder extends ObjectType // ino.class.TypePlaceholder.26780.body { private static final Logger log = Logger.getLogger(TypePlaceholder.class.getName()); - // ino.attribute.strNextName.26785.declaration - private static String strNextName = "A"; // ino.end // ino.attribute.m_TypePlaceholdersRegistry.26788.declaration private static Hashtable m_TypePlaceholdersRegistry = new Hashtable(); @@ -104,7 +103,7 @@ public class TypePlaceholder extends ObjectType TypePlaceholder typeVar = new TypePlaceholder(name, parent); TypePlaceholder oldTPH = m_TypePlaceholdersRegistry.put(typeVar.getName().toString(), typeVar); if(oldTPH != null){ - oldTPH.name = new JavaClassName(makeNewName()); + oldTPH.name = new JavaClassName(NameGenerator.makeNewName()); m_TypePlaceholdersRegistry.put(oldTPH.getName().toString(), oldTPH); } return typeVar; @@ -120,7 +119,7 @@ public class TypePlaceholder extends ObjectType * @return */ public static TypePlaceholder fresh(SyntaxTreeNode parent){ - TypePlaceholder ret= new TypePlaceholder(makeNewName(), parent); + TypePlaceholder ret= new TypePlaceholder(NameGenerator.makeNewName(), parent); m_TypePlaceholdersRegistry.put(ret.getName().toString(), ret); return ret; } @@ -132,98 +131,7 @@ public class TypePlaceholder extends ObjectType return ret; } - // ino.method.makeNewName.26803.defdescription type=javadoc - /** - * Berechnet einen neuen, eindeutigen Namen f�r eine neue - * TypePlaceholder.
Author: J�rg B�uerle - * @return Der Name - */ - // ino.end - // ino.method.makeNewName.26803.definition - private static String makeNewName() - // ino.end - // ino.method.makeNewName.26803.body - { - // otth: Funktion berechnet einen neuen Namen anhand eines alten gespeicherten - String strReturn = strNextName; - - // n�chster Name berechnen und in strNextName speichern - inc( strNextName.length() - 1 ); - - return strReturn; - } - // ino.end - // ino.method.inc.26806.defdescription type=javadoc - /** - * Hilfsfunktion zur Berechnung eines neuen Namens - *
Author: J�rg B�uerle - * @param i - */ - // ino.end - // ino.method.inc.26806.definition - private static void inc(int i) - // ino.end - // ino.method.inc.26806.body - { - // otth: Hilfsfunktion zur Berechnung eines neuen Namens - // otth: Erh�hung des Buchstabens an der Stelle i im String strNextName - // otth: Nach �berlauf: rekursiver Aufruf - - // falls i = -1 --> neuer Buchstabe vorne anf�gen - if ( i == -1 ) - { - strNextName = "A" + strNextName; - return; - } - - char cBuchstabe = (char)(strNextName.charAt( i )); - cBuchstabe++; - if ( cBuchstabe - 65 > 25 ) - { - // aktuelle Stelle: auf A zuruecksetzen - manipulate( i, 'A' ); - - // vorherige Stelle erh�hen - inc( i - 1 ); - } - else - { - // aktueller Buchstabe �ndern - manipulate( i, cBuchstabe ); - } - - } - // ino.end - - // ino.method.manipulate.26809.defdescription type=javadoc - /** - * Hilfsfunktion zur Berechnung eines neuen Namens. - *
Author: J�rg B�uerle - * @param nStelle - * @param nWert - */ - // ino.end - // ino.method.manipulate.26809.definition - private static void manipulate( int nStelle, char nWert ) - // ino.end - // ino.method.manipulate.26809.body - { - // otth: Hilfsfunktion zur Berechnung eines neuen Namens - // otth: Ersetzt im String 'strNextName' an der Position 'nStelle' den Buchstaben durch 'nWert' - - String strTemp = ""; - for( int i = 0; i < strNextName.length(); i++) - { - if ( i == nStelle ) - strTemp = strTemp + nWert; - else - strTemp = strTemp + strNextName.charAt( i ); - } - strNextName = strTemp; - } - // ino.end - // ino.method.equals.26812.defdescription type=javadoc /** * Author: J�rg B�uerle
@@ -327,7 +235,7 @@ public class TypePlaceholder extends ObjectType //backdoorvars werden registiert, weil am Ende beim execute //auf den CSubstitution nicht registrierte Variablen zu //Exceptions fuehrt - TypePlaceholder typeVar = new TypePlaceholder(makeNewName(), null); + TypePlaceholder typeVar = new TypePlaceholder(NameGenerator.makeNewName(), null); m_TypePlaceholdersRegistry.put(typeVar.getName().toString(), typeVar); return typeVar; @@ -447,6 +355,10 @@ public class TypePlaceholder extends ObjectType @Override public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) { + if(rs == null){ + System.out.println(""); + return null; + } Type resolvedType = rs.getTypeOfPlaceholder(this); if(resolvedType instanceof TypePlaceholder){ cg.addUsedTPH((TypePlaceholder)resolvedType); @@ -463,7 +375,8 @@ public class TypePlaceholder extends ObjectType ret+=":"; Menge possibleTPHs = cg.getUsedTPH(); possibleTPHs.remove(this); - org.apache.bcel.generic.Type nearestType = cg.getNearestUsedType(this, possibleTPHs); + //TODO: hier komplett überarbeiten. Wann wird ein TPH eine generische Variable, das sollte geklärt werden. + org.apache.bcel.generic.Type nearestType = null;//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(); diff --git a/test/bytecode/SingleClassTester.java b/test/bytecode/SingleClassTester.java index 312416ab..07564f55 100644 --- a/test/bytecode/SingleClassTester.java +++ b/test/bytecode/SingleClassTester.java @@ -38,21 +38,18 @@ public class SingleClassTester { Menge bytecode = compiler.generateBytecode(sourceFiles, results); //System.out.println(bytecode); - for(ByteCodeResult result: bytecode){ + for(ByteCodeResult result: bytecode){ JavaClass javaClass = result.getByteCode().getJavaClass(); javaClass.dump(new File(outputDirectory+javaClass.getClassName()+".class")); - /* + ///* for(ClassGenerator cg: result.getByteCode().getExtraClasses().values()){ JavaClass jc = cg.getJavaClass(); jc.dump(new File(outputDirectory+jc.getClassName()+".class")); } - */ + //*/ Logger.getLogger("SingleClassTester").error(result.getByteCode().getJavaClass().toString(), Section.CODEGEN); - } - - } catch (IOException | yyException e) { Logger.getLogger("SingleClassTester").error(e.toString(), Section.CODEGEN); From c4aff43f71b7bd6c98e671713b18b43dbe0760b5 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Fri, 28 Oct 2016 18:32:05 +0200 Subject: [PATCH 5/6] =?UTF-8?q?NameGenerator=20einf=C3=BChren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../syntaxtree/factory/NameGenerator.java | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java b/src/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java new file mode 100644 index 00000000..f20ea0cd --- /dev/null +++ b/src/de/dhbwstuttgart/syntaxtree/factory/NameGenerator.java @@ -0,0 +1,81 @@ +package de.dhbwstuttgart.syntaxtree.factory; + +public class NameGenerator { + + private static String strNextName = "A"; + + /** + * Berechnet einen neuen, eindeutigen Namen f�r eine neue + * TypePlaceholder.
Author: J�rg B�uerle + * @return Der Name + */ + public static String makeNewName() + { + // otth: Funktion berechnet einen neuen Namen anhand eines alten gespeicherten + String strReturn = strNextName; + + // n�chster Name berechnen und in strNextName speichern + inc( strNextName.length() - 1 ); + + return strReturn; + } + + /** + * Hilfsfunktion zur Berechnung eines neuen Namens + *
Author: J�rg B�uerle + * @param i + */ + private static void inc(int i) + { + // otth: Hilfsfunktion zur Berechnung eines neuen Namens + // otth: Erh�hung des Buchstabens an der Stelle i im String strNextName + // otth: Nach �berlauf: rekursiver Aufruf + + // falls i = -1 --> neuer Buchstabe vorne anf�gen + if ( i == -1 ) + { + strNextName = "A" + strNextName; + return; + } + + char cBuchstabe = (char)(strNextName.charAt( i )); + cBuchstabe++; + if ( cBuchstabe - 65 > 25 ) + { + // aktuelle Stelle: auf A zuruecksetzen + manipulate( i, 'A' ); + + // vorherige Stelle erh�hen + inc( i - 1 ); + } + else + { + // aktueller Buchstabe �ndern + manipulate( i, cBuchstabe ); + } + + } + + /** + * Hilfsfunktion zur Berechnung eines neuen Namens. + *
Author: J�rg B�uerle + * @param nStelle + * @param nWert + */ + private static void manipulate( int nStelle, char nWert ) + { + // otth: Hilfsfunktion zur Berechnung eines neuen Namens + // otth: Ersetzt im String 'strNextName' an der Position 'nStelle' den Buchstaben durch 'nWert' + + String strTemp = ""; + for( int i = 0; i < strNextName.length(); i++) + { + if ( i == nStelle ) + strTemp = strTemp + nWert; + else + strTemp = strTemp + strNextName.charAt( i ); + } + strNextName = strTemp; + } + +} From accbe5bbfcfc9953aac56d77cdd136ae4d2f8783 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 9 Nov 2016 16:59:08 +0100 Subject: [PATCH 6/6] Beginnen der BytecodeTypeFactory --- .../bytecode/BytecodeTypeFactory.java | 93 +++++++++++++++++++ .../bytecode/ClassGenerator.java | 5 +- .../syntaxtree/factory/ASTFactory.java | 5 +- .../syntaxtree/type/GenericTypeVar.java | 19 ++-- .../syntaxtree/type/RefType.java | 20 ++-- test/bytecode/lambda/Simple.jav | 8 ++ test/bytecode/lambda/SimpleTest.java | 19 ++++ test/bytecode/lambda/Test.java | 5 + test/bytecode/lambda/TestInterface.java | 1 + 9 files changed, 160 insertions(+), 15 deletions(-) create mode 100644 src/de/dhbwstuttgart/bytecode/BytecodeTypeFactory.java create mode 100644 test/bytecode/lambda/Simple.jav create mode 100644 test/bytecode/lambda/SimpleTest.java create mode 100644 test/bytecode/lambda/Test.java create mode 100644 test/bytecode/lambda/TestInterface.java diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeTypeFactory.java b/src/de/dhbwstuttgart/bytecode/BytecodeTypeFactory.java new file mode 100644 index 00000000..d55f9daf --- /dev/null +++ b/src/de/dhbwstuttgart/bytecode/BytecodeTypeFactory.java @@ -0,0 +1,93 @@ +package de.dhbwstuttgart.bytecode; + +import de.dhbwstuttgart.syntaxtree.type.BoundedGenericTypeVar; +import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; +import de.dhbwstuttgart.syntaxtree.type.ObjectType; +import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.syntaxtree.type.Type; +import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; + +public class BytecodeTypeFactory { + + /** + * @see https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-FieldType + */ + public static String generateFieldDescriptor(Type t){ + String ret = ""; + if(t instanceof RefType){ + ret += "L" + t.getName().toString().replace('.', '/') + ";"; + }else{ + throw new NotImplementedException(); + } + return ret; + } + + /** + * @see https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-ClassSignature + */ + public static String generateClassSignature(de.dhbwstuttgart.syntaxtree.Class c){ + String ret = ""; + if(c.getGenericParameter() != null && c.getGenericParameter().size() > 0){ + ret += "<"; + for(GenericTypeVar gtv : c.getGenericParameter()){ + ret += generateTypeParameter(gtv); + } + ret += ">"; + } + //Add the SuperClassSignature: + c.getSuperClass(); + ret += generateClassTypeSignature(); + return ret; + } + + public static String generateSuperClassSignature(Type superClass){ + String ret = ""; + //TODO: + throw new NotImplementedException(); + } + + private static String generateTypeParameter(GenericTypeVar gtv){ + String ret = gtv.get_Name() + ":"; + for(ObjectType t : gtv.getBounds()){ + ret += generateReferenceTypeSignature(t); + ret += ":"; + } + ret = ret.substring(0, ret.length()-1); + return ret; + } + + /** + * @see https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-ClassTypeSignature + */ + private static String generateClassTypeSignature(){ + return null; + } + + /** + * @see https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-ReferenceTypeSignature + */ + private static String generateReferenceTypeSignature(Type t){ + if(t instanceof RefType)return generateReferenceTypeSignature((RefType)t); + if(t instanceof GenericTypeVar)return generateReferenceTypeSignature((GenericTypeVar)t); + throw new NotImplementedException(); + } + + private static String generateReferenceTypeSignature(RefType t){ + String ret = "L" + t.get_Name(); + if(t.getParaList() != null && t.getParaList().size() > 0){ + ret += "<"; + for(Type p : t.getParaList()){ + ret += generateReferenceTypeSignature(p); + } + ret+=">"; + } + return ret + ";"; + } + + private static String generateReferenceTypeSignature(GenericTypeVar t){ + String ret = "T" + t.get_Name(); + return ret + ";"; + } + + +} diff --git a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java index a94dda29..2b8fe81e 100644 --- a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java +++ b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java @@ -158,7 +158,8 @@ public class ClassGenerator extends ClassGen{ //Signatur setzen: String typeParameters = this.generateParameterSignature(); - String superClassSignature = this.superClass.get_Name(); + String superClassSignature = BytecodeTypeFactory.generateSuperClassSignature(this.superClass);//"L" + this.superClass.getBytecodeType(cg, rs) + superClassSignature = superClassSignature.substring(0, superClassSignature.length()-1); //Das ";" am Ende entfernen if(this.superClass instanceof RefType && ((RefType)superClass).get_ParaList() != null && ((RefType)superClass).get_ParaList().size() > 0){ @@ -167,7 +168,7 @@ public class ClassGenerator extends ClassGen{ for(Type param : superRefType.get_ParaList()){ superClassSignature += param.getBytecodeSignature(this, null); } - superClassSignature += ">"; + superClassSignature += ">;"; } String classSignature = typeParameters + superClassSignature; //TOOD: Hier noch die Signaturen der SuperInterfaces anfügen if(classSignature.length()>0){ diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index 0f7a4fc3..ba682476 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -83,7 +83,10 @@ public class ASTFactory { public static Class createObjectClass() { Class generatedClass = new Class("java.lang.Object", 0); - return generatedClass; } + + public static RefType createObjectType(){ + return createObjectClass().getType(); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java b/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java index 39c1e690..b68cb9dc 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java @@ -2,9 +2,12 @@ package de.dhbwstuttgart.syntaxtree.type; // ino.end +import java.util.ArrayList; // ino.module.GenericTypeVar.8671.import import java.util.HashMap; import java.util.Iterator; +import java.util.List; + import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.ConstraintsSet; @@ -22,17 +25,14 @@ import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.GTVDeclarationContext; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; -// ino.class.GenericTypeVar.26505.description type=javadoc +import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; + /** * TODO: Diese Klasse überarbeiten. Pair genericTypeVar ist nicht implementiert. * @author J�rg B�uerle * @version $Date: 2013/09/22 20:12:53 $ */ -// ino.end -// ino.class.GenericTypeVar.26505.declaration public class GenericTypeVar extends ObjectType -// ino.end -// ino.class.GenericTypeVar.26505.body { //Type genericTypeVar; //Menge extendVars = new Menge(); @@ -236,7 +236,14 @@ public class GenericTypeVar extends ObjectType // TODO Bytecode return org.apache.bcel.generic.Type.getType(getSignatureType(null));// new org.apache.bcel.generic.ObjectType("Object"); } - + + public List getBounds() + { + //Gibt eine Liste mit "java.lang.Object" zurück, da jede Generic von Object erbt + ArrayList ret = new ArrayList<>(); + ret.add(ASTFactory.createObjectType()); + return ret; + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index bbd2b533..f45bc1f2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -130,12 +130,13 @@ public class RefType extends ObjectType implements IMatchable //this.parameter = null; } - public RefType(JavaClassName jName, SyntaxTreeNode parent, int offset) { - this(jName.toString(), parent, offset); + + public RefType(JavaClassName name, List parameter, int offset) { + super(name.toString(), null, offset); + this.parameter = parameter; } - - /** + /** * Wandelt die Parameter des RefTypes in TPHs um, sofern es sich um Generische Variablen handelt. * @return */ @@ -590,20 +591,26 @@ public class RefType extends ObjectType implements IMatchable //Bsp.: Ljava/util/Vector; StringBuilder sb = new StringBuilder(); String ret; + List newParams = new ArrayList<>(); if(parameter != null && parameter.size() > 0){ sb.append(getName().toString().replace(".", "%")); sb.append("%%"); for(Type type: parameter){ + Type newParameter; if(type instanceof RefType){ sb.append(((RefType) type).getCombinedType(cg, rs).replace(".", "%")); + newParameter = type; }else if(type instanceof TypePlaceholder){ + newParameter = rs.getTypeOfPlaceholder((TypePlaceholder)type); sb.append(((TypePlaceholder) type).getBytecodeType(cg, rs).toString().replace(".", "%")); }else if(type instanceof WildcardType){ + //TODO: unresolved! return this.getName().toString(); }else{ + newParameter = type; sb.append(type.getBytecodeType(cg, rs).toString().replace(".", "%")); } - + newParams.add(newParameter); sb.append("%"); } ret = sb.toString(); @@ -612,7 +619,8 @@ public class RefType extends ObjectType implements IMatchable } if(!ret.equals(getName().toString())){ //getSuperWildcardTypes(); - Class generatedClass = ASTFactory.createInterface(ret, this, null, null, new SourceFile()); + RefType superClass = new RefType(this.getName(),newParams,this.getOffset()); + Class generatedClass = ASTFactory.createInterface(ret, superClass, null, null, new SourceFile()); cg.addExtraClass(generatedClass.genByteCode(new TypeinferenceResults()).getByteCode()); } diff --git a/test/bytecode/lambda/Simple.jav b/test/bytecode/lambda/Simple.jav new file mode 100644 index 00000000..d29da619 --- /dev/null +++ b/test/bytecode/lambda/Simple.jav @@ -0,0 +1,8 @@ +class Simple{ + +op = (i)->i; + +public void main(){ + op.apply(1); +} +} \ No newline at end of file diff --git a/test/bytecode/lambda/SimpleTest.java b/test/bytecode/lambda/SimpleTest.java new file mode 100644 index 00000000..9ca78037 --- /dev/null +++ b/test/bytecode/lambda/SimpleTest.java @@ -0,0 +1,19 @@ +package bytecode.lambda; + +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class SimpleTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Simple"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/lambda/"; + } + + @Test + public void testConstruct() throws Exception{ + this.testMethod("main"); + assertTrue(true); + } +} diff --git a/test/bytecode/lambda/Test.java b/test/bytecode/lambda/Test.java new file mode 100644 index 00000000..70efddea --- /dev/null +++ b/test/bytecode/lambda/Test.java @@ -0,0 +1,5 @@ +class Test{ + public static void main(String[] args){ + new Simple().main(); +} +} diff --git a/test/bytecode/lambda/TestInterface.java b/test/bytecode/lambda/TestInterface.java new file mode 100644 index 00000000..5b92f6c9 --- /dev/null +++ b/test/bytecode/lambda/TestInterface.java @@ -0,0 +1 @@ +interface TestInterface extends Fun1{}