diff --git a/BCEL/bcelifier/IfStatement.java b/BCEL/bcelifier/IfStatement.java new file mode 100644 index 00000000..8f16e0d4 --- /dev/null +++ b/BCEL/bcelifier/IfStatement.java @@ -0,0 +1,12 @@ +package bcelifier; + +class IfStatement{ + Integer methode(Boolean b){ + if(b){ + return 1; + }else{ + return 2; + } + } + +} \ No newline at end of file diff --git a/BCEL/bcelifier/IfStatementCreator.java b/BCEL/bcelifier/IfStatementCreator.java new file mode 100644 index 00000000..88b43e39 --- /dev/null +++ b/BCEL/bcelifier/IfStatementCreator.java @@ -0,0 +1,71 @@ +package bcelifier; + +import org.apache.commons.bcel6.generic.*; + +import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.bytecode.ClassGenerator; +import de.dhbwstuttgart.bytecode.MethodGenerator; +import de.dhbwstuttgart.typeinference.TypeinferenceResults; + +import org.apache.commons.bcel6.*; +import java.io.*; + +public class IfStatementCreator { + private InstructionFactory _factory; + private ConstantPoolGen _cp; + private ClassGenerator _cg; + + public IfStatementCreator() { + + TypeinferenceResults typeinferenceResults = null; + _cg = new ClassGenerator("bcelifier.IfStatement", new RefType("java.lang.Object", null, 0), "IfStatement.java", Const.ACC_SUPER, new String[] { }, typeinferenceResults); + + _cp = _cg.getConstantPool(); + _factory = new InstructionFactory(_cg, _cp); + } + + public void create(OutputStream out) throws IOException { + createMethod_0(); + createMethod_1(); + _cg.getJavaClass().dump(out); + } + + private void createMethod_0() { + InstructionList il = new InstructionList(); + MethodGen method = new MethodGenerator(0, Type.VOID, new Type[] { new ObjectType("java.lang.Boolean") }, new String[] { "arg0" }, "", "bcelifier.IfStatement", il, _cp); + + InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0)); + il.append(_factory.createInvoke("java.lang.Object", "", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); + InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID)); + method.setMaxStack(); + method.setMaxLocals(); + _cg.addMethod(method.getMethod()); + } + + private void createMethod_1() { + InstructionList il = new InstructionList(); + MethodGen method = new MethodGenerator(0, new ObjectType("java.lang.Integer"), new Type[] { new ObjectType("java.lang.Boolean") }, new String[] { "arg0" }, "methode", "bcelifier.IfStatement", il, _cp); + + il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); + il.append(_factory.createInvoke("java.lang.Boolean", "booleanValue", Type.BOOLEAN, Type.NO_ARGS, Const.INVOKEVIRTUAL)); + BranchInstruction ifeq_4 = InstructionFactory.createBranchInstruction(Const.IFEQ, null); + il.append(ifeq_4); + il.append(new PUSH(_cp, 1)); + il.append(_factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new Type[] { Type.INT }, Const.INVOKESTATIC)); + il.append(InstructionFactory.createReturn(Type.OBJECT)); + InstructionHandle ih_12 = il.append(new PUSH(_cp, 2)); + il.append(_factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new Type[] { Type.INT }, Const.INVOKESTATIC)); + il.append(InstructionFactory.createReturn(Type.OBJECT)); + ifeq_4.setTarget(ih_12); + method.setMaxStack(); + method.setMaxLocals(); + _cg.addMethod(method.getMethod()); + } + + public static void main(String[] args) throws Exception { + bcelifier.IfStatementCreator creator = new bcelifier.IfStatementCreator(); + creator.create(new FileOutputStream("bcelifier.IfStatement.class")); + + System.out.println("bcelifier.IfStatement.class"); + } +} diff --git a/BCEL/bcelifier/JavaToBCEL.java b/BCEL/bcelifier/JavaToBCEL.java index 2c87bc2f..0d162b00 100644 --- a/BCEL/bcelifier/JavaToBCEL.java +++ b/BCEL/bcelifier/JavaToBCEL.java @@ -24,16 +24,16 @@ public class JavaToBCEL { public JavaToBCEL(){ try { //new BCELifier(new ClassParser(rootDirectory+"Lambda1.class").parse(), new FileOutputStream(new File(rootDirectory+"Lambda1Creator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"This.class").parse(), new FileOutputStream(new File(rootDirectory+"ThisCreator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"IntLiteral.class").parse(), new FileOutputStream(new File(rootDirectory+"IntLiteralCreator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"MethodCall.class").parse(), new FileOutputStream(new File(rootDirectory+"MethodCallCreator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"FieldDeclaration.class").parse(), new FileOutputStream(new File(rootDirectory+"FieldDeclarationCreator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"Null.class").parse(), new FileOutputStream(new File(rootDirectory+"NullCreator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"LocalVarAccess.class").parse(), new FileOutputStream(new File(rootDirectory+"LocalVarAccessCreator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"Wildcard.class").parse(), new FileOutputStream(new File(rootDirectory+"WildcardCreator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"BooleanValue.class").parse(), new FileOutputStream(new File(rootDirectory+"BooleanValueCreator.java"))).start(); - new BCELifier(new ClassParser(rootDirectory+"NewClass.class").parse(), new FileOutputStream(new File(rootDirectory+"NewClassCreator.java"))).start(); - + //new BCELifier(new ClassParser(rootDirectory+"This.class").parse(), new FileOutputStream(new File(rootDirectory+"ThisCreator.java"))).start(); + //new BCELifier(new ClassParser(rootDirectory+"IntLiteral.class").parse(), new FileOutputStream(new File(rootDirectory+"IntLiteralCreator.java"))).start(); + //new BCELifier(new ClassParser(rootDirectory+"MethodCall.class").parse(), new FileOutputStream(new File(rootDirectory+"MethodCallCreator.java"))).start(); + //new BCELifier(new ClassParser(rootDirectory+"FieldDeclaration.class").parse(), new FileOutputStream(new File(rootDirectory+"FieldDeclarationCreator.java"))).start(); + //new BCELifier(new ClassParser(rootDirectory+"Null.class").parse(), new FileOutputStream(new File(rootDirectory+"NullCreator.java"))).start(); + //new BCELifier(new ClassParser(rootDirectory+"LocalVarAccess.class").parse(), new FileOutputStream(new File(rootDirectory+"LocalVarAccessCreator.java"))).start(); + //new BCELifier(new ClassParser(rootDirectory+"Wildcard.class").parse(), new FileOutputStream(new File(rootDirectory+"WildcardCreator.java"))).start(); + //new BCELifier(new ClassParser(rootDirectory+"BooleanValue.class").parse(), new FileOutputStream(new File(rootDirectory+"BooleanValueCreator.java"))).start(); + //new BCELifier(new ClassParser(rootDirectory+"NewClass.class").parse(), new FileOutputStream(new File(rootDirectory+"NewClassCreator.java"))).start(); + new BCELifier(new ClassParser(rootDirectory+"IfStatement.class").parse(), new FileOutputStream(new File(rootDirectory+"IfStatementCreator.java"))).start(); } catch (ClassFormatException | IOException e) { e.printStackTrace(); } diff --git a/lib/commons-bcel6-6.0-SNAPSHOT.jar b/lib/commons-bcel6-6.0-SNAPSHOT.jar index 11dcfef9..d84ca41f 100644 Binary files a/lib/commons-bcel6-6.0-SNAPSHOT.jar and b/lib/commons-bcel6-6.0-SNAPSHOT.jar differ diff --git a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java index 393d2e6e..decb0f8b 100644 --- a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java +++ b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java @@ -68,7 +68,7 @@ public class ClassGenerator extends ClassGen{ //return getNearestType((TypePlaceholder) t); return new TypePlaceholderType((TypePlaceholder) t); }else{ - return t.getBytecodeType(this, getTypeinferenceResults().getTypeReconstructions().firstElement()); + return t.getBytecodeType(this, getTypeinferenceResults().getTypeReconstructions().get(0)); } } public org.apache.commons.bcel6.generic.Type getNearestUsedType(TypePlaceholder toTPH){ @@ -150,7 +150,7 @@ public class ClassGenerator extends ClassGen{ TypePlaceholder tph = it.next(); //ret += tph.getBytecodeMethodSignature(this); //ret += ":"; - ret += tph.getClassSignature(this, getTypeinferenceResults().getTypeReconstructions().firstElement()); + ret += tph.getClassSignature(this, getTypeinferenceResults().getTypeReconstructions().get(0)); } ret += ">"; } diff --git a/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java b/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java index 853ddae1..8b4b9929 100644 --- a/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java +++ b/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java @@ -139,13 +139,18 @@ public class DHBWInstructionFactory extends InstructionFactory{ return new INVOKEDYNAMIC(index); } - public LocalVariableInstruction createLoad(org.apache.commons.bcel6.generic.Type bytecodeType, String variableName) { - return InstructionFactory.createLoad(bytecodeType, storeIndexes.get(variableName)); + public static LocalVariableInstruction createLoad(org.apache.commons.bcel6.generic.Type bytecodeType, String variableName) { + return InstructionFactory.createLoad(bytecodeType, getStoreIndex(variableName)); } - public Integer getStoreIndex(String variableName) { - if(!storeIndexes.containsKey(variableName)){ - storeIndexes.put(variableName, storeIndexes.size()+1); + public LocalVariableInstruction createStore(org.apache.commons.bcel6.generic.Type bytecodeType, String variableName) { + return InstructionFactory.createStore(bytecodeType, getStoreIndex(variableName)); + } + + public static Integer getStoreIndex(String variableName) { + if(storeIndexes.get(variableName) == null){ + Integer index = storeIndexes.size()+1; + storeIndexes.put(variableName, index); } return storeIndexes.get(variableName); @@ -160,6 +165,6 @@ public class DHBWInstructionFactory extends InstructionFactory{ } public void resetStoreIndexes() { - storeIndexes = new HashMap<>(); + //storeIndexes.clear(); } } diff --git a/src/de/dhbwstuttgart/bytecode/MethodGenerator.java b/src/de/dhbwstuttgart/bytecode/MethodGenerator.java index 887766ce..d374f3f6 100644 --- a/src/de/dhbwstuttgart/bytecode/MethodGenerator.java +++ b/src/de/dhbwstuttgart/bytecode/MethodGenerator.java @@ -74,7 +74,7 @@ public class MethodGenerator extends MethodGen{ method.addAttribute(factory.createSignatureAttribute(paramTypesSig+retTypeSig)); - StackMap stackMap = new StackMapTableGen(this.getInstructionList(), cp).getStackMap(); + StackMap stackMap = new StackMapTableGen(this, cp).getStackMap(); if(stackMap != null)method.addCodeAttribute(stackMap); return method.getMethod(); diff --git a/src/de/dhbwstuttgart/core/MyCompiler.java b/src/de/dhbwstuttgart/core/MyCompiler.java index 1f39fb97..9a194a03 100755 --- a/src/de/dhbwstuttgart/core/MyCompiler.java +++ b/src/de/dhbwstuttgart/core/MyCompiler.java @@ -159,11 +159,11 @@ public class MyCompiler implements MyCompilerAPI{ FunNInterface funN = new FunNInterface(i); ret.add(funN.getPublicFieldAssumptions()); } - for(int i = 0; i<6; i++){ - FunVoidNInterface funN = new FunVoidNInterface(i); - ret.add(funN.getPublicFieldAssumptions()); - } - + //Keine FunVoidInterfaces in den Assumptions. + //for(int i = 0; i<6; i++){ + // FunVoidNInterface funN = new FunVoidNInterface(i); + // ret.add(funN.getPublicFieldAssumptions()); + //} return ret; } @@ -209,43 +209,6 @@ public class MyCompiler implements MyCompilerAPI{ return OutputDir; } - /** - * @author Arne Lüdtke - * Ersetzt alle GTVs durch TPHs mit gleichem Namen. Arbeitet Rekursiv. - * ACHTUNG: BACKDOOR CREATE!!! Nur für Testzwecke verwenden. - * @param T - Typ, bei welchem die GTVs ersetzt werden sollen. - */ - public static Type makeGenericTypeVars2TypePlaceHolders(Type T) - { - if(T instanceof RefType) - { - RefType refT = (RefType)T; - if(refT.get_ParaList() != null) - { - Menge paras = refT.get_ParaList(); - for(int i = 0; ilogLine==null); Logger.LOG_HISTORY.sort((log1, log2)->log1.timestamp.compareTo(log2.timestamp)); ret += Logger.LOG_HISTORY.toString(); return ret; diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index c7c38d09..7e6ce461 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -111,7 +111,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I } InstructionList fieldInitializations = new InstructionList(); for(FieldDeclaration f : fieldDeclarations){ - fieldInitializations.append(f.genByteCode(_cg, typeinferenceResults.getTypeReconstructions().firstElement())); + fieldInitializations.append(f.genByteCode(_cg, typeinferenceResults.getTypeReconstructions().get(0))); } //Die Konstruktoren müssen die Feld initialisierungswerte beinhalten: for(Constructor c : constructors){ @@ -554,7 +554,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I */ // ino.method.get_ParaList.23101.definition - public Menge get_ParaList() + public List get_ParaList() // ino.end // ino.method.get_ParaList.23101.body { diff --git a/src/de/dhbwstuttgart/syntaxtree/ClassBody.java b/src/de/dhbwstuttgart/syntaxtree/ClassBody.java index 1c96052f..0dcb7609 100755 --- a/src/de/dhbwstuttgart/syntaxtree/ClassBody.java +++ b/src/de/dhbwstuttgart/syntaxtree/ClassBody.java @@ -85,64 +85,6 @@ Paratyp gesetzt."); } fielddecl.addElement(i); } -// ino.method.is_declared.23188.defdescription type=line -// -// ******************************************************************************************** -// -// ino.end - -// ino.method.is_declared.23188.definition -public boolean is_declared(Type t, Menge classlist) -throws SCClassBodyException -// ino.end -// ino.method.is_declared.23188.body -{ - boolean flag=false; - for(Enumeration e = classlist.elements();e.hasMoreElements();) - { - flag = false; - Class c = e.nextElement(); - -// System.out.println("is_init: vergleiche "+t.get_Type_()+" mit "+c.getName()); - if(c.getName().equals(t.getName())){ -// System.out.println("Klasse "+t.get_Type()+"im Menge classlist gefunden."); - flag = true; - break; - } - } - - if( t instanceof RefType && ((RefType)t).get_ParaList()!=null) - { - if( ((RefType)t).get_ParaList().size() > 0 ) - { - for(Enumeration e1 = ((RefType)t).get_ParaList().elements(); e1.hasMoreElements(); ) - { - try - { - is_declared((Type)e1.nextElement(),classlist); - } - catch(SCClassBodyException ex) - { - throw ex; - } - } - } - } - - if(flag) - return true; - else - { - SCClassBodyException ex = new SCClassBodyException(); - SCExcept e = new SCExcept(); - e.set_error("unbekannte Klasse "+t.getName()+"."); - e.set_function("complete_parahashtable() --> is_declared()"); - e.set_statement(t.getName().toString()); - ex.addException(e); - throw ex; - } -} -// ino.end // ino.method.string_rec.23191.definition static String string_rec(Hashtable ht) diff --git a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java index f2f9099e..bc529a12 100755 --- a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java +++ b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java @@ -237,7 +237,7 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns public String getDescription(){ String ret = ""; if(this.getType() != null && !(this.getType() instanceof TypePlaceholder)){ - ret += this.getType().getBytecodeSignature(null, null); + ret += this.getType().toString();//getBytecodeSignature(null, null); } return ret+this.getIdentifier(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index 662ac477..dfff897c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -1,9 +1,8 @@ // ino.module.Method.8564.package package de.dhbwstuttgart.syntaxtree; +import java.util.ArrayList; import java.util.Arrays; -// ino.end -// ino.module.Method.8564.import import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; @@ -65,58 +64,23 @@ import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; * */ public class Method extends Field implements IItemWithOffset, TypeInsertable -// ino.end -// ino.class.Method.23482.body { - // ino.attribute.block.23488.declaration private Block block; - // ino.end - // ino.attribute.parameterlist.23491.declaration public ParameterList parameterlist = new ParameterList(); - // ino.end - // ino.attribute.exceptionlist.23494.declaration private ExceptionList exceptionlist; - // ino.end - // ino.attribute.returntype.23497.declaration private Type returntype; - // ino.end - - // ino.attribute.genericMethodParameters.23500.decldescription type=javadoc - /** - * HOTI 4.5.06 Dieser Vektor beinhaltet alle Generischen Typen und v.a. die - * F-Bounded-Generics, die die Methode besitzt size()==0, falls es keine - * gibt - */ - // ino.end - // ino.attribute.genericMethodParameters.23500.declaration - // private Menge genericMethodParameters=new - // Menge(); - // ino.end - // ino.attribute.overloadedID.23503.declaration private int overloadedID; - // ino.end - // ino.attribute.isAbstract.23506.declaration private boolean isAbstract = false; - // ino.end - // ino.attribute.types_in_parameterlist.23509.declaration private Menge types_in_parameterlist = new Menge(); - // ino.end - // ino.attribute.m_LineNumber.23512.declaration private int m_LineNumber = MyCompiler.NO_LINENUMBER; - // ino.end private int m_Offset = -1; // hinzugef�gt hoth: 07.04.2006 private Modifiers modifiers; - // ino.attribute.inferencelog.23515.declaration protected static Logger inferencelog = Logger.getLogger("inference"); - // ino.end - // ino.attribute.parserlog.23518.declaration protected static Logger parserlog = Logger.getLogger("parser"); protected Menge createdMethods = new Menge<>(); - // ino.end - public Method(int offset) { super(offset); } @@ -136,51 +100,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable this.setReturnType(returnType); } - /* - * // ino.method.setGenericMethodParameters.23521.definition public void - * setGenericMethodParameters(Menge genericMethodParameters) - * // ino.end // ino.method.setGenericMethodParameters.23521.body { - * this.genericMethodParameters=genericMethodParameters; } // ino.end // - * ino.method.getGenericMethodParameters.23524.definition public - * Menge getGenericMethodParameters() // ino.end // - * ino.method.getGenericMethodParameters.23524.body { - * return(genericMethodParameters); } // ino.end - */ - /* - * // ino.method.sc_init_parameterlist.23530.definition public void - * sc_init_parameterlist(boolean ext) // ino.end // - * ino.method.sc_init_parameterlist.23530.body { DeclId hilf=null; - * Menge list; FormalParameter para; String typeofpara; int - * i=1; if(this.getParameterList()!=null) //es gibt Parameter, dann: { - * hilf=declid.elementAt(0); if(ext) - * parserlog.debug("Semantik-Check hat in Methode " - * +hilf.get_Name()+" bergabewerte gefunden:"); - * list=this.getParameterList().sc_get_Formalparalist(); //Menge - * Formalparalist aus FormalParameterList wird zwischen gesichert - * for(Enumeration el2=list.elements(); - * el2.hasMoreElements();) { para=el2.nextElement(); - * typeofpara=para.getTypeName(); if(ext) - * parserlog.debug(" "+i+". Parameter hat Typ "+typeofpara); - * types_in_parameterlist.addElement(typeofpara); //Typ der Parameter werden - * im Menge abgelegt i++; } } else //keine Parameter vorhanden: { if(ext) { - * hilf=declid.elementAt(0); - * parserlog.debug("Semantik-Check hat in Methode " - * +hilf.get_Name()+" keine bergabewerte gefunden."); } } if(ext) { - * parserlog.debug("Semantik-Check hat in Methode "+hilf.get_Name()+" "+ - * types_in_parameterlist.size()+" bergabeparameter gefunden."); - * parserlog.debug - * (" namentlich: "+types_in_parameterlist.toString()); } } // - * ino.end - */ - // ino.method.getTypeName.23533.defdescription type=line - // Eine der beiden Funktionen ist ueberflssig. Wer sich daran strt kann die - // get_ReturnType() auf eigene Gefahr lschen. - // ino.end - - // ino.method.getTypeName.23533.definition public JavaClassName getTypeName() - // ino.end - // ino.method.getTypeName.23533.body { if (this.getType() == null) return null; @@ -188,101 +108,58 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable return this.getType().getName(); } - // ino.end - // ino.method.get_Block.23536.definition public Block get_Block() - // ino.end - // ino.method.get_Block.23536.body { return block; } - // ino.end - // ino.method.setReturnType.23539.defdescription type=javadoc /** *
* Author: Jrg Buerle * * @param type */ - // ino.end - // ino.method.setReturnType.23539.definition private void setReturnType(Type type) - // ino.end - // ino.method.setReturnType.23539.body { this.returntype = type; } - // ino.end - - // ino.method.set_Block.23542.definition public void set_Block(Block blo) - // ino.end - // ino.method.set_Block.23542.body { if (blo.getType() == null) blo.setType(this.returntype); this.block = blo; } - // ino.end - - // ino.method.set_Modifiers.23545.definition public void set_Modifiers(Modifiers modif) - // ino.end - // ino.method.set_Modifiers.23545.body { declid.firstElement().set_Modifiers(modif); this.modifiers = modif; } - // ino.end - - // ino.method.set_ExceptionList.23548.definition public void set_ExceptionList(ExceptionList exlist) - // ino.end - // ino.method.set_ExceptionList.23548.body { this.exceptionlist = exlist; } - // ino.end - - // ino.method.setParameterList.23551.definition public void setParameterList(ParameterList paralist) - // ino.end - // ino.method.setParameterList.23551.body { this.parameterlist = paralist; } - // ino.end - - // ino.method.getParameterList.23554.definition public ParameterList getParameterList() - // ino.end - // ino.method.getParameterList.23554.body { - // otth: gibt die Parameterliste zurueck return this.parameterlist; } - // ino.end - - // ino.method.getParameterCount.23557.defdescription type=javadoc /** * Author: Jrg Buerle
* * @return Die Anzahl der Methoden-Paramater */ - // ino.end - // ino.method.getParameterCount.23557.definition public int getParameterCount() - // ino.end - // ino.method.getParameterCount.23557.body { if (this.getParameterList() == null) return 0; @@ -290,177 +167,94 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable return this.getParameterList().getParameterCount(); } - // ino.end - - // ino.method.get_ExceptionList.23560.definition public ExceptionList get_ExceptionList() - // ino.end - // ino.method.get_ExceptionList.23560.body { // otth: gibt die Exceptionliste zurueck return this.exceptionlist; } - // ino.end - - // ino.method.getOverloadedID.23563.definition public int getOverloadedID() - // ino.end - // ino.method.getOverloadedID.23563.body { return (overloadedID); } - // ino.end - // ino.method.setOverloadedID.23566.definition public void setOverloadedID(int overloadedID) - // ino.end - // ino.method.setOverloadedID.23566.body { this.overloadedID = overloadedID; } - // ino.end - - // ino.method.get_Method_Name.23575.definition public String get_Method_Name() - // ino.end - // ino.method.get_Method_Name.23575.body { DeclId hilf = declid.elementAt(0); return hilf.get_Name(); } - // ino.end - - // ino.method.get_Type_Paralist.23578.definition public Menge get_Type_Paralist() - // ino.end - // ino.method.get_Type_Paralist.23578.body { return types_in_parameterlist; } - // ino.end - - // ino.method.getLineNumber.23584.definition public int getLineNumber() - // ino.end - // ino.method.getLineNumber.23584.body { return m_LineNumber; } - - // ino.end - - // ino.method.setLineNumber.23587.definition + public void setLineNumber(int lineNumber) - // ino.end - // ino.method.setLineNumber.23587.body { m_LineNumber = lineNumber; } - - // ino.end - - // ino.method.getOffset.23590.defdescription type=line - // hinzugef�gt hoth: 07.04.2006 - // ino.end - // ino.method.getOffset.23590.definition + public int getOffset() - // ino.end - // ino.method.getOffset.23590.body { return m_Offset; } - // ino.end - - // ino.method.getVariableLength.23593.definition public int getVariableLength() - // ino.end - // ino.method.getVariableLength.23593.body { return get_Method_Name().length(); } - // ino.end - - // ino.method.setOffset.23596.defdescription type=line - // hinzugef�gt hoth: 07.04.2006 - // ino.end - // ino.method.setOffset.23596.definition public void setOffset(int Offset) - // ino.end - // ino.method.setOffset.23596.body { m_Offset = Offset; } - // ino.end - - // ino.method.getTypeLineNumber.23602.defdescription type=javadoc /** *
* Author: Jrg Buerle * * @return */ - // ino.end - // ino.method.getTypeLineNumber.23602.definition public int getTypeLineNumber() - // ino.end - // ino.method.getTypeLineNumber.23602.body { return this.getLineNumber(); } - - // ino.end - - // ino.method.toString.23605.defdescription type=javadoc + /** *
* Author: Martin Pl�micke * * @return */ - // ino.end - // ino.method.toString.23605.definition public String toString() - // ino.end - // ino.method.toString.23605.body { return this.getType() + " " + this.get_Name() + ((block != null) ? block.toString() : ""); } - // ino.end - - // ino.method.setAbstract.23608.defdescription type=javadoc /** * Legt fuer die ByteCodeGen fest, ob Bytecode innerhalb der Methode * generiert wird. */ - // ino.end - // ino.method.setAbstract.23608.definition public void setAbstract(boolean b) - // ino.end - // ino.method.setAbstract.23608.body { isAbstract = b; } - - // ino.end - - // ino.method.isAbstract.23611.defdescription type=javadoc + /** * Gibt zurueck, ob ByteCode innerhabl der Methode generiert wird. */ - // ino.end - // ino.method.isAbstract.23611.definition public boolean isAbstract() - // ino.end - // ino.method.isAbstract.23611.body { return isAbstract; } @@ -610,44 +404,40 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable public void genByteCode(ClassGenerator cg, Class classObj) { List typeInterferenceResults = cg.getTypeinferenceResults().getTypeReconstructions(this, cg); + DHBWInstructionFactory _factory = cg.getInstructionFactory(); for(TypeinferenceResultSet t: typeInterferenceResults){ - DHBWConstantPoolGen _cp = cg.getConstantPool(); - InstructionList il = new InstructionList(); - Class parentClass = this.getParentClass(); - - //Die Argumentliste generieren: - org.apache.commons.bcel6.generic.Type[] argumentTypes = org.apache.commons.bcel6.generic.Type.NO_ARGS; - String[] argumentNames = new String[]{}; - if(this.parameterlist != null && this.parameterlist.size() > 0){ - argumentTypes = new org.apache.commons.bcel6.generic.Type[this.parameterlist.size()]; - argumentNames = new String[this.parameterlist.size()]; - int i = 0; - for(FormalParameter parameter : this.parameterlist){ - argumentTypes[i] = parameter.getType().getBytecodeType(cg, t); - argumentNames[i] = parameter.getIdentifier(); - i++; - } - } - - String nameAndSignature = get_Method_Name()+Arrays.toString(argumentTypes); - - Logger.getLogger("nameAndSignature").error(nameAndSignature, Section.CODEGEN); - + addMethodToClassGenerator(cg, _factory, t); + } + } - short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public - if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC; - - Type returnType = this.getType(); + private void addMethodToClassGenerator(ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) { + DHBWConstantPoolGen _cp = cg.getConstantPool(); + InstructionList il = new InstructionList(); + + ArrayList argumentTypes = new ArrayList(); + ArrayList argumentNames = new ArrayList(); + + if(this.parameterlist != null && this.parameterlist.size() > 0){ + generateArgumentList(argumentTypes, argumentNames, cg, _factory, t); + } + + short constants = Constants.ACC_PUBLIC; + if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC; + + Type returnType = this.getType(); + + MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes.toArray(new org.apache.commons.bcel6.generic.Type[parameterlist.size()]) , argumentNames.toArray(new String[parameterlist.size()]), this.get_Method_Name(), getParentClass().name, il, _cp); + + cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t)); + } + + private void generateArgumentList(ArrayList argumentTypes, ArrayList argumentNames, ClassGenerator cg, DHBWInstructionFactory _factory, TypeinferenceResultSet t) { + for(FormalParameter parameter : this.parameterlist){ + argumentTypes.add(parameter.getType().getBytecodeType(cg, t)); + argumentNames.add(parameter.getIdentifier()); - //Methode generieren: - MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp); - - //Methode generieren und anfügen: - cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t)); - - Logger.getLogger("createMethod").debug(this.toString(), Section.CODEGEN); + _factory.getStoreIndex(parameter.getIdentifier()); } } } -// ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 2464730b..d37d6e8e 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -39,17 +39,12 @@ import de.dhbwstuttgart.syntaxtree.type.Void; import de.dhbwstuttgart.typeinference.ByteCodeResult; import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.FunNInterface; -import de.dhbwstuttgart.typeinference.FunNMethod; -import de.dhbwstuttgart.typeinference.KomplexeMenge; import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.TypeinferenceResults; -import de.dhbwstuttgart.typeinference.UndConstraint; import de.dhbwstuttgart.typeinference.UnifyConstraintsSet; import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption; -import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption; -import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index ba397a58..06069bc6 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -1,17 +1,21 @@ package de.dhbwstuttgart.syntaxtree.factory; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.logging.Logger; import de.dhbwstuttgart.myexception.NotImplementedException; import de.dhbwstuttgart.syntaxtree.NullSyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType; +import de.dhbwstuttgart.syntaxtree.type.FunN; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.type.ObjectType; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.syntaxtree.type.Void; import de.dhbwstuttgart.syntaxtree.type.WildcardType; import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.EinzelElement; @@ -29,6 +33,7 @@ import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.unify.model.ExtendsType; import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; +import de.dhbwstuttgart.typeinference.unify.model.FunNType; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; @@ -67,18 +72,20 @@ public class UnifyTypeFactory { //Es wurde versucht ein Typ umzuwandeln, welcher noch nicht von der Factory abgedeckt ist if(t instanceof GenericTypeVar){ return UnifyTypeFactory.convert((GenericTypeVar)t); - }else if(t instanceof RefType){ - return UnifyTypeFactory.convert((RefType)t); + }else if(t instanceof FunN){ + return UnifyTypeFactory.convert((FunN)t); }else if(t instanceof TypePlaceholder){ return UnifyTypeFactory.convert((TypePlaceholder)t); }else if(t instanceof ExtendsWildcardType){ return UnifyTypeFactory.convert((ExtendsWildcardType)t); }else if(t instanceof SuperWildcardType){ return UnifyTypeFactory.convert((SuperWildcardType)t); + }else if(t instanceof RefType){ + return UnifyTypeFactory.convert((RefType)t); } throw new NotImplementedException("Der Typ "+t+" kann nicht umgewandelt werden"); } - + public static UnifyType convert(RefType t){ UnifyType ret; if(t.getParaList() != null && t.getParaList().size() > 0){ @@ -92,6 +99,18 @@ public class UnifyTypeFactory { } return ret; } + + public static UnifyType convert(FunN t){ + UnifyType ret; + Menge params = new Menge<>(); + if(t.getParaList() != null && t.getParaList().size() > 0){ + for(Type pT : t.getParaList()){ + params.add(UnifyTypeFactory.convert(pT)); + } + } + ret = FunNType.getFunNType(new TypeParams(params)); + return ret; + } public static UnifyType convert(TypePlaceholder tph){ return new PlaceholderType(tph.get_Name()); @@ -106,7 +125,8 @@ public class UnifyTypeFactory { } public static UnifyType convert(GenericTypeVar t){ - return new PlaceholderType(t.get_Name()); + //return new PlaceholderType(t.get_Name()); + return new ReferenceType(t.get_Name()); } public static UnifyConstraintsSet convert(ConstraintsSet constraints) { @@ -151,7 +171,17 @@ public class UnifyTypeFactory { } public static Type convert(ReferenceType t) { - return new RefType(t.getName(),null,0); + //TODO: Hier kann man die GTVs extrahieren + if(t.getName() == "void")return new Void(NULL_NODE, 0); + RefType ret = new RefType(t.getName(),null,0); + ret.set_ParaList(convert(t.getTypeParams())); + return ret; + } + + public static Type convert(FunNType t) { + RefType ret = new RefType(t.getName(),null,0); + ret.set_ParaList(convert(t.getTypeParams())); + return ret; } public static Type convert(SuperType t) { @@ -165,14 +195,29 @@ public class UnifyTypeFactory { } public static Type convert(PlaceholderType t) { - return TypePlaceholder.getInstance(t.getName()); + TypePlaceholder ret = TypePlaceholder.getInstance(t.getName()); + if(ret == null){ //Dieser TPH wurde vom Unifikationsalgorithmus erstellt + ret = TypePlaceholder.fresh(NULL_NODE); + } + return ret; } public static Type convert(UnifyType t) { + if(t instanceof FunNType)return convert((FunNType) t); if(t instanceof ReferenceType)return convert((ReferenceType) t); if(t instanceof SuperType)return convert((SuperType) t); if(t instanceof ExtendsType)return convert((ExtendsType) t); if(t instanceof PlaceholderType)return convert((PlaceholderType) t); throw new NotImplementedException("Der Typ "+t+" kann nicht umgewandelt werden"); } + + private static List convert(TypeParams typeParams) { + List ret = new ArrayList<>(); + for(UnifyType uT : typeParams){ + Type toAdd = convert(uT); + ret.add(toAdd); + } + return ret; + } + } diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/AddOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/AddOp.java index d56b6ac2..c2811dec 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/AddOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/AddOp.java @@ -5,19 +5,36 @@ package de.dhbwstuttgart.syntaxtree.operator; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; -import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.Constants; +import org.apache.commons.bcel6.generic.ArithmeticInstruction; +import org.apache.commons.bcel6.generic.DUP; +import org.apache.commons.bcel6.generic.IADD; +import org.apache.commons.bcel6.generic.InstructionList; +import org.apache.commons.bcel6.generic.InvokeInstruction; +import org.apache.commons.bcel6.generic.ObjectType; + +import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; +import de.dhbwstuttgart.bytecode.DHBWInstructionFactory; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; import de.dhbwstuttgart.syntaxtree.statement.Expr; +import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType; import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType; import de.dhbwstuttgart.syntaxtree.type.Type; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.unify.TypeUnify; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; +import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; +import de.dhbwstuttgart.typeinference.exceptions.DebugException; +import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; @@ -61,5 +78,86 @@ public abstract class AddOp extends Operator return ret; } + @Override + public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator) { + /* + 0: aload_1 + 1: invokevirtual #2 // Method java/lang/Integer.intValue:()I + 4: aload_1 + 5: invokevirtual #2 // Method java/lang/Integer.intValue:()I + 8: iadd + 9: invokestatic #3 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; + 12: areturn + */ + + String returnType = getReturnType(operator.get_Expr1(), operator.get_Expr2(), rs); + + if(returnType.equals("java.lang.String")){ + DHBWInstructionFactory _factory = _cg.getInstructionFactory(); + + ObjectType objectType = new ObjectType("java.lang.StringBuilder"); + + InstructionList il = new InstructionList(); + il.append(_factory.createNew("java.lang.StringBuilder")); + il.append(new DUP()); + il.append(_cg.getInstructionFactory().createInvoke("java.lang.StringBuilder", "", org.apache.commons.bcel6.generic.Type.VOID, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKESPECIAL)); + + il.append(operator.get_Expr1().genByteCode(_cg, rs)); + + + il.append(_cg.getInstructionFactory().createInvoke("java.lang.StringBuilder", "append", objectType, new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.STRING}, Constants.INVOKEVIRTUAL)); + + il.append(operator.get_Expr2().genByteCode(_cg, rs)); + + il.append(_cg.getInstructionFactory().createInvoke("java.lang.StringBuilder", "append", objectType, new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.STRING}, Constants.INVOKEVIRTUAL)); + + il.append(_cg.getInstructionFactory().createInvoke("java.lang.StringBuilder", "toString", new ObjectType("java.lang.String"), new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL)); + + return il; + }else{ + DHBWInstructionFactory _factory = _cg.getInstructionFactory(); + + InstructionList il = getInstructionListForOperand(_cg, rs, operator.get_Expr1(), returnType); + + il.append(getInstructionListForOperand(_cg, rs, operator.get_Expr2(), returnType)); + + il.append(getOperator(returnType)); + + il.append(convertValueToObject(_factory, returnType)); + return il; + } + } + + private String getReturnType(Expr expr1, Expr expr2, TypeinferenceResultSet rs) { + Type type = expr1.getType(); + if(type instanceof TypePlaceholder){ + Type tphType = rs.getTypeOfPlaceholder((TypePlaceholder) expr1.getType()); + if(tphType instanceof ExtendsWildcardType){ + return ((ExtendsWildcardType) tphType).get_ExtendsType().get_Name(); + }else if(tphType instanceof SuperWildcardType){ + return ((SuperWildcardType) tphType).get_SuperType().get_Name(); + }else{ + return tphType.getName().toString(); + } + }else{ + return type.get_Name(); + } + } + + abstract ArithmeticInstruction getOperator(String returnType); + + private InvokeInstruction convertValueToObject(DHBWInstructionFactory _factory, String returnType) { + if(returnType.equals("java.lang.Integer")){ + return _factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.INT}, Constants.INVOKESTATIC); + }else if(returnType.equals("java.lang.Double")){ + return _factory.createInvoke("java.lang.Double", "valueOf", new ObjectType("java.lang.Double"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.DOUBLE}, Constants.INVOKESTATIC); + }else if(returnType.equals("java.lang.Float")){ + return _factory.createInvoke("java.lang.Float", "valueOf", new ObjectType("java.lang.Float"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.FLOAT}, Constants.INVOKESTATIC); + }else if(returnType.equals("java.lang.Long")){ + return _factory.createInvoke("java.lang.Long", "valueOf", new ObjectType("java.lang.Long"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.LONG}, Constants.INVOKESTATIC); + }else{ + throw new NotImplementedException(); + } + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/AndOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/AndOp.java index 09323e48..246019b2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/AndOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/AndOp.java @@ -3,10 +3,15 @@ package de.dhbwstuttgart.syntaxtree.operator; import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.generic.InstructionList; + +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; +import de.dhbwstuttgart.syntaxtree.statement.Binary; import de.dhbwstuttgart.syntaxtree.statement.Expr; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.typeinference.ConstraintsSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; // ino.class.AndOp.24101.declaration @@ -24,6 +29,12 @@ public class AndOp extends LogOp } // ino.end + @Override + public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator) { + // TODO Auto-generated method stub + return null; + } + } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/DivideOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/DivideOp.java index 4442e7a9..e776617c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/DivideOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/DivideOp.java @@ -3,6 +3,17 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.end // ino.module.DivideOp.8596.import import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; + +import org.apache.commons.bcel6.generic.ArithmeticInstruction; +import org.apache.commons.bcel6.generic.DADD; +import org.apache.commons.bcel6.generic.DDIV; +import org.apache.commons.bcel6.generic.FADD; +import org.apache.commons.bcel6.generic.FDIV; +import org.apache.commons.bcel6.generic.IADD; +import org.apache.commons.bcel6.generic.IDIV; +import org.apache.commons.bcel6.generic.LADD; +import org.apache.commons.bcel6.generic.LDIV; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; @@ -25,9 +36,19 @@ public class DivideOp extends MulOp super(offset,variableLength); } // ino.end - - - - + + ArithmeticInstruction getOperator(String returnType) { + if(returnType.equals("java.lang.Integer")){ + return new IDIV(); + }else if(returnType.equals("java.lang.Double")){ + return new DDIV(); + }else if(returnType.equals("java.lang.Float")){ + return new FDIV(); + }else if(returnType.equals("java.lang.Long")){ + return new LDIV(); + }else{ + throw new NotImplementedException(); + } + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/EqualOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/EqualOp.java index c49f3957..b71d9a2f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/EqualOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/EqualOp.java @@ -3,10 +3,22 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.end // ino.module.EqualOp.8597.import import java.util.Iterator; -import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.Constants; +import org.apache.commons.bcel6.generic.BranchInstruction; +import org.apache.commons.bcel6.generic.GOTO; +import org.apache.commons.bcel6.generic.IF_ICMPNE; +import org.apache.commons.bcel6.generic.InstructionConstants; +import org.apache.commons.bcel6.generic.InstructionList; +import org.apache.commons.bcel6.generic.NOP; +import org.apache.commons.bcel6.generic.ObjectType; + +import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; +import de.dhbwstuttgart.bytecode.DHBWInstructionFactory; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; +import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.statement.Binary; import de.dhbwstuttgart.syntaxtree.statement.Expr; @@ -14,6 +26,8 @@ import de.dhbwstuttgart.syntaxtree.statement.Null; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.unify.TypeUnify; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; +import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; @@ -31,6 +45,11 @@ public class EqualOp extends RelOp super(offset, variableLength); } // ino.end + + @Override + BranchInstruction getOperator() { + return new IF_ICMPNE(null); + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/GreaterEquOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/GreaterEquOp.java index a01e1285..588c2271 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/GreaterEquOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/GreaterEquOp.java @@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.module.GreaterEquOp.8598.import import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.generic.BranchInstruction; +import org.apache.commons.bcel6.generic.IF_ICMPLT; + import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.statement.Binary; @@ -25,6 +28,11 @@ public class GreaterEquOp extends RelOp super(offset,variableLength); } // ino.end + + @Override + BranchInstruction getOperator() { + return new IF_ICMPLT(null); + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/GreaterOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/GreaterOp.java index 97a66824..f6b037db 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/GreaterOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/GreaterOp.java @@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.module.GreaterOp.8599.import import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.generic.BranchInstruction; +import org.apache.commons.bcel6.generic.IF_ICMPLE; + import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; import de.dhbwstuttgart.syntaxtree.statement.Expr; @@ -25,5 +28,10 @@ public class GreaterOp extends RelOp } // ino.end + @Override + BranchInstruction getOperator() { + return new IF_ICMPLE(null); + } + } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/LessEquOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/LessEquOp.java index cff4e504..7a60fa49 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/LessEquOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/LessEquOp.java @@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.module.LessEquOp.8600.import import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.generic.BranchInstruction; +import org.apache.commons.bcel6.generic.IF_ICMPGT; + import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; import de.dhbwstuttgart.syntaxtree.statement.Expr; @@ -25,5 +28,10 @@ public class LessEquOp extends RelOp } // ino.end + @Override + BranchInstruction getOperator() { + return new IF_ICMPGT(null); + } + } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/LessOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/LessOp.java index 2fcc7f11..5b6722b3 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/LessOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/LessOp.java @@ -3,6 +3,8 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.end // ino.module.LessOp.8601.import import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.generic.BranchInstruction; +import org.apache.commons.bcel6.generic.IF_ICMPGE; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; @@ -25,5 +27,10 @@ public class LessOp extends RelOp } // ino.end + @Override + BranchInstruction getOperator() { + return new IF_ICMPGE(null); + } + } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/MinusOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/MinusOp.java index 3cd233ad..72313dd6 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/MinusOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/MinusOp.java @@ -4,6 +4,10 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.module.MinusOp.8603.import import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.generic.ArithmeticInstruction; +import org.apache.commons.bcel6.generic.IADD; +import org.apache.commons.bcel6.generic.ISUB; + import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; import de.dhbwstuttgart.syntaxtree.statement.Expr; @@ -25,6 +29,8 @@ public class MinusOp extends AddOp } // ino.end - + ArithmeticInstruction getOperator(String returnType) { + return new ISUB(); + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/ModuloOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/ModuloOp.java index 57465f01..d387958e 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/ModuloOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/ModuloOp.java @@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.module.ModuloOp.8604.import import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.generic.ArithmeticInstruction; +import org.apache.commons.bcel6.generic.IREM; + import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; import de.dhbwstuttgart.syntaxtree.statement.Expr; @@ -25,5 +28,10 @@ public class ModuloOp extends MulOp } // ino.end + @Override + ArithmeticInstruction getOperator(String returnType) { + return new IREM(); + } + } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/MulOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/MulOp.java index 6abb1d5d..d84690d8 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/MulOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/MulOp.java @@ -6,16 +6,30 @@ package de.dhbwstuttgart.syntaxtree.operator; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; -import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.Constants; +import org.apache.commons.bcel6.generic.ArithmeticInstruction; +import org.apache.commons.bcel6.generic.InstructionList; +import org.apache.commons.bcel6.generic.InvokeInstruction; +import org.apache.commons.bcel6.generic.ObjectType; + +import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; +import de.dhbwstuttgart.bytecode.DHBWInstructionFactory; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.syntaxtree.statement.Binary; +import de.dhbwstuttgart.syntaxtree.statement.Expr; +import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType; import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType; import de.dhbwstuttgart.syntaxtree.type.Type; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.unify.TypeUnify; +import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; // ino.class.MulOp.24231.declaration public abstract class MulOp extends Operator @@ -50,6 +64,62 @@ public abstract class MulOp extends Operator return ret; } - + @Override + public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator) { + // TODO Plus Operator ist bis jetzt nur für Integer implementiert + /* + 0: aload_1 + 1: invokevirtual #2 // Method java/lang/Integer.intValue:()I + 4: aload_1 + 5: invokevirtual #2 // Method java/lang/Integer.intValue:()I + 8: imul + 9: invokestatic #3 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; + 12: areturn + */ + DHBWInstructionFactory _factory = _cg.getInstructionFactory(); + + String returnType = getReturnType(operator.get_Expr1(), operator.get_Expr2(), rs); + + InstructionList il = getInstructionListForOperand(_cg, rs, operator.get_Expr1(), returnType); + + il.append(getInstructionListForOperand(_cg, rs, operator.get_Expr2(), returnType)); + + il.append(getOperator(returnType)); + + il.append(convertValueToObject(_factory, returnType)); + return il; + } + + private String getReturnType(Expr expr1, Expr expr2, TypeinferenceResultSet rs) { + Type type = expr1.getType(); + if(type instanceof TypePlaceholder){ + Type tphType = rs.getTypeOfPlaceholder((TypePlaceholder) expr1.getType()); + if(tphType instanceof ExtendsWildcardType){ + return ((ExtendsWildcardType) tphType).get_ExtendsType().get_Name(); + }else if(tphType instanceof SuperWildcardType){ + return ((SuperWildcardType) tphType).get_SuperType().get_Name(); + }else{ + return tphType.getName().toString(); + } + }else{ + return type.get_Name(); + } + } + + abstract ArithmeticInstruction getOperator(String returnType); + + private InvokeInstruction convertValueToObject(DHBWInstructionFactory _factory, String returnType) { + if(returnType.equals("java.lang.Integer")){ + return _factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.INT}, Constants.INVOKESTATIC); + }else if(returnType.equals("java.lang.Double")){ + return _factory.createInvoke("java.lang.Double", "valueOf", new ObjectType("java.lang.Double"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.DOUBLE}, Constants.INVOKESTATIC); + }else if(returnType.equals("java.lang.Float")){ + return _factory.createInvoke("java.lang.Float", "valueOf", new ObjectType("java.lang.Float"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.FLOAT}, Constants.INVOKESTATIC); + }else if(returnType.equals("java.lang.Long")){ + return _factory.createInvoke("java.lang.Long", "valueOf", new ObjectType("java.lang.Long"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.LONG}, Constants.INVOKESTATIC); + }else{ + throw new NotImplementedException(); + } + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/NotEqualOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/NotEqualOp.java index 50c9fdfc..f1b5f85f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/NotEqualOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/NotEqualOp.java @@ -3,7 +3,6 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.end // ino.module.NotEqualOp.8606.import import java.util.Iterator; -import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; @@ -13,6 +12,9 @@ import de.dhbwstuttgart.syntaxtree.statement.Null; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.unify.TypeUnify; +import org.apache.commons.bcel6.generic.BranchInstruction; +import org.apache.commons.bcel6.generic.IF_ACMPEQ; + // ino.class.NotEqualOp.24241.declaration public class NotEqualOp extends RelOp @@ -28,5 +30,10 @@ public class NotEqualOp extends RelOp } // ino.end + @Override + BranchInstruction getOperator() { + return new IF_ACMPEQ(null); + } + } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/Operator.java b/src/de/dhbwstuttgart/syntaxtree/operator/Operator.java index 7e87ff73..7c6613f6 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/Operator.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/Operator.java @@ -5,8 +5,16 @@ package de.dhbwstuttgart.syntaxtree.operator; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; -import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.Constants; +import org.apache.commons.bcel6.generic.DADD; +import org.apache.commons.bcel6.generic.FADD; +import org.apache.commons.bcel6.generic.IADD; +import org.apache.commons.bcel6.generic.InstructionList; +import org.apache.commons.bcel6.generic.LADD; + +import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.core.IItemWithOffset; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; @@ -19,8 +27,10 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.OderConstraint; import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.UndConstraint; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; +import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.unify.TypeUnify; @@ -63,11 +73,33 @@ public abstract class Operator extends SyntaxTreeNode * @return */ public abstract HashMap getReturnTypes(TypeAssumptions ass); + + public abstract InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator); @Override public Menge getChildren() { return new Menge<>(); } + + + protected InstructionList getInstructionListForOperand(ClassGenerator _cg, TypeinferenceResultSet rs, Expr operand, String returnType){ + InstructionList il = new InstructionList(); + il.append(operand.genByteCode(_cg, rs)); + if(returnType.equals("java.lang.Integer")){ + il.append(_cg.getInstructionFactory().createInvoke("java.lang.Integer", "intValue", org.apache.commons.bcel6.generic.Type.INT, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL)); + }else if(returnType.equals("java.lang.Double")){ + il.append(_cg.getInstructionFactory().createInvoke("java.lang.Double", "doubleValue", org.apache.commons.bcel6.generic.Type.DOUBLE, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL)); + }else if(returnType.equals("java.lang.Float")){ + il.append(_cg.getInstructionFactory().createInvoke("java.lang.Float", "floatValue", org.apache.commons.bcel6.generic.Type.FLOAT, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL)); + }else if(returnType.equals("java.lang.Long")){ + il.append(_cg.getInstructionFactory().createInvoke("java.lang.Long", "longValue", org.apache.commons.bcel6.generic.Type.LONG, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL)); + }else if(returnType.equals("java.lang.String")){ + + }else{ + throw new NotImplementedException(returnType); + } + return il; + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/OrOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/OrOp.java index 41bbdac9..3bf1c44f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/OrOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/OrOp.java @@ -2,6 +2,19 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.end +import org.apache.commons.bcel6.Constants; +import org.apache.commons.bcel6.generic.BranchInstruction; +import org.apache.commons.bcel6.generic.GOTO; +import org.apache.commons.bcel6.generic.IFEQ; +import org.apache.commons.bcel6.generic.IFNE; +import org.apache.commons.bcel6.generic.InstructionConstants; +import org.apache.commons.bcel6.generic.InstructionList; +import org.apache.commons.bcel6.generic.ObjectType; + +import de.dhbwstuttgart.bytecode.ClassGenerator; +import de.dhbwstuttgart.bytecode.DHBWInstructionFactory; +import de.dhbwstuttgart.syntaxtree.statement.Binary; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; // ino.class.OrOp.24282.declaration public class OrOp extends LogOp @@ -17,6 +30,47 @@ public class OrOp extends LogOp super(offset,variableLength); } // ino.end + + @Override + public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator) { + /* + 0: aload_1 + 1: invokevirtual #2 // Method java/lang/Boolean.booleanValue:()Z + 4: ifne 14 + 7: aload_2 + 8: invokevirtual #2 // Method java/lang/Boolean.booleanValue:()Z + 11: ifeq 18 + 14: iconst_1 + 15: goto 19 + 18: iconst_0 + 19: invokestatic #3 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean; + 22: areturn + */ + DHBWInstructionFactory _factory = _cg.getInstructionFactory(); + + InstructionList il = operator.get_Expr1().genByteCode(_cg, rs); + il.append(_factory.createInvoke("java.lang.Boolean", "booleanValue", org.apache.commons.bcel6.generic.Type.BOOLEAN, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL)); + + BranchInstruction firstTest = new IFNE(null); + il.append(firstTest); + + il.append(operator.get_Expr2().genByteCode(_cg, rs)); + il.append(_factory.createInvoke("java.lang.Boolean", "booleanValue", org.apache.commons.bcel6.generic.Type.BOOLEAN, new org.apache.commons.bcel6.generic.Type[] {}, Constants.INVOKEVIRTUAL)); + + BranchInstruction secondTest = new IFEQ(null); + il.append(secondTest); + + firstTest.setTarget(il.append(InstructionConstants.ICONST_1)); + + BranchInstruction gotoInstruction = new GOTO(null); + il.append(gotoInstruction); + + secondTest.setTarget(il.append(InstructionConstants.ICONST_0)); + + gotoInstruction.setTarget(il.append(_factory.createInvoke("java.lang.Boolean", "valueOf", new ObjectType("java.lang.Boolean"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.BOOLEAN}, Constants.INVOKESTATIC))); + + return il; + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/PlusOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/PlusOp.java index e7d82823..53fbae1c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/PlusOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/PlusOp.java @@ -3,10 +3,30 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.end // ino.module.PlusOp.8609.import import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; +import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; +import org.apache.commons.bcel6.Constants; +import org.apache.commons.bcel6.generic.ArithmeticInstruction; +import org.apache.commons.bcel6.generic.BranchInstruction; +import org.apache.commons.bcel6.generic.DADD; +import org.apache.commons.bcel6.generic.FADD; +import org.apache.commons.bcel6.generic.GOTO; +import org.apache.commons.bcel6.generic.IADD; +import org.apache.commons.bcel6.generic.IFEQ; +import org.apache.commons.bcel6.generic.IFNE; +import org.apache.commons.bcel6.generic.InstructionConstants; +import org.apache.commons.bcel6.generic.InstructionList; +import org.apache.commons.bcel6.generic.InvokeInstruction; +import org.apache.commons.bcel6.generic.LADD; +import org.apache.commons.bcel6.generic.ObjectType; + +import de.dhbwstuttgart.bytecode.ClassGenerator; +import de.dhbwstuttgart.bytecode.DHBWInstructionFactory; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; import de.dhbwstuttgart.syntaxtree.statement.Expr; +import de.dhbwstuttgart.syntaxtree.type.Type; @@ -24,6 +44,19 @@ public class PlusOp extends AddOp super(offset,variableLength); } // ino.end - + + ArithmeticInstruction getOperator(String returnType) { + if(returnType.equals("java.lang.Integer")){ + return new IADD(); + }else if(returnType.equals("java.lang.Double")){ + return new DADD(); + }else if(returnType.equals("java.lang.Float")){ + return new FADD(); + }else if(returnType.equals("java.lang.Long")){ + return new LADD(); + }else{ + throw new NotImplementedException(); + } + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java index dae2941b..5278bc91 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java @@ -6,14 +6,24 @@ package de.dhbwstuttgart.syntaxtree.operator; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; -import de.dhbwstuttgart.typeinference.Menge; +import org.apache.commons.bcel6.Constants; +import org.apache.commons.bcel6.generic.BranchInstruction; +import org.apache.commons.bcel6.generic.GOTO; +import org.apache.commons.bcel6.generic.InstructionConstants; +import org.apache.commons.bcel6.generic.InstructionList; +import org.apache.commons.bcel6.generic.ObjectType; + +import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.bytecode.ClassGenerator; +import de.dhbwstuttgart.bytecode.DHBWInstructionFactory; import de.dhbwstuttgart.myexception.CTypeReconstructionException; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.typeinference.Pair; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.unify.TypeUnify; @@ -54,6 +64,45 @@ public abstract class RelOp extends Operator return ret; } + + @Override + public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator) { + /* + 0: aload_1 + 1: invokevirtual #3 // Method java/lang/Integer.intValue:()I + 4: aload_2 + 5: invokevirtual #3 // Method java/lang/Integer.intValue:()I + 8: if_icmplt 15 + 11: iconst_1 + 12: goto 16 + 15: iconst_0 + 16: invokestatic #2 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean; + 19: areturn + */ + + DHBWInstructionFactory _factory = _cg.getInstructionFactory(); + + InstructionList il = getInstructionListForOperand(_cg, rs, operator.get_Expr1(), "java.lang.Boolean"); + + il.append(getInstructionListForOperand(_cg, rs, operator.get_Expr2(), "java.lang.Boolean")); + + BranchInstruction operatorBranchInstruction = getOperator(); + + il.append(operatorBranchInstruction); + + il.append(InstructionConstants.ICONST_1); + + BranchInstruction gotoInstruction = new GOTO(null); + + il.append(gotoInstruction); + + operatorBranchInstruction.setTarget(il.append(InstructionConstants.ICONST_0)); + gotoInstruction.setTarget(il.append(_factory.createInvoke("java.lang.Boolean", "valueOf", new ObjectType("java.lang.Boolean"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.BOOLEAN}, Constants.INVOKESTATIC))); + + return il; + } + + abstract BranchInstruction getOperator(); } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/TimesOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/TimesOp.java index 6f47068d..e54693cb 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/TimesOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/TimesOp.java @@ -4,6 +4,13 @@ package de.dhbwstuttgart.syntaxtree.operator; // ino.module.TimesOp.8611.import import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; + +import org.apache.commons.bcel6.generic.ArithmeticInstruction; +import org.apache.commons.bcel6.generic.DMUL; +import org.apache.commons.bcel6.generic.FMUL; +import org.apache.commons.bcel6.generic.IMUL; +import org.apache.commons.bcel6.generic.LMUL; import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.syntaxtree.statement.Binary; @@ -22,6 +29,20 @@ public class TimesOp extends MulOp super(offset,variableLength); } // ino.end + + ArithmeticInstruction getOperator(String returnType) { + if(returnType.equals("java.lang.Integer")){ + return new IMUL(); + }else if(returnType.equals("java.lang.Double")){ + return new DMUL(); + }else if(returnType.equals("java.lang.Float")){ + return new FMUL(); + }else if(returnType.equals("java.lang.Long")){ + return new LMUL(); + }else{ + throw new NotImplementedException(); + } + } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java b/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java index f2086ec3..8b0997f9 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java @@ -207,7 +207,7 @@ public class Assign extends Expr } */ //Es wird momentan immer von RefType ausgegangen: - il.append(new ASTORE(_factory.getStoreIndex(expr1.get_Name()))); + il.append(_factory.createStore(expr2.getType().getBytecodeType(cg, rs), expr1.get_Name())); return il; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java index 44fc3cc8..464513b0 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java @@ -227,27 +227,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { @Override public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) { - InstructionList linkeSeite = this.expr1.genByteCode(_cg, rs); - InstructionList rechteSeite = this.expr2.genByteCode(_cg, rs); - if(this.getReturnType().getName().equals(new JavaClassName("String"))){ - throw new TypeinferenceException("Zeichenketten zusammenfügen ist noch nicht unterstützt",this); - } - - linkeSeite.append(rechteSeite); - - //TODO: bytecode (Bis jetzt wird jeder Condition als EQUALS behandelt) - //TODO: bytecode autoboxing - - BranchInstruction if_icmpneInstruction = new IF_ICMPNE(null); - linkeSeite.append(if_icmpneInstruction); - linkeSeite.append(InstructionConstants.ICONST_1); - - BranchInstruction gotoInstruction = new GOTO(null); - - linkeSeite.append(gotoInstruction); - if_icmpneInstruction.setTarget(linkeSeite.append(InstructionConstants.ICONST_0)); - gotoInstruction.setTarget(linkeSeite.append(new NOP())); - return linkeSeite; + return op.genByteCode(_cg, rs, this); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java index c402a83a..a9ce0295 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java @@ -38,10 +38,6 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.unify.TypeUnify; - - - - public class ForStmt extends Statement { diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java index 4acaa018..04900cb0 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java @@ -164,38 +164,13 @@ public class LambdaExpression extends Expr{ ret.add(method_body.TYPEStmt(ArgumentAssumptions.add(assumptions))); //Es gibt die LambdaExpression nur mit einem Block als Method Body, nicht mit einer einzelnen Expression //Die Constraints für ParameterTypen und Ret Typ erstellen: - Menge modifiedParamTypes = new Menge<>(); - for(Type pT : paramTypes){ - if(pT instanceof WildcardType){ - //Auf Typfehler kontrollieren. Siehe Bug #12 Kommentar 3 - if(pT instanceof ExtendsWildcardType){ - throw new TypeinferenceException("Typfehler von Parametertyp "+pT,this); - }else{ - modifiedParamTypes.add(pT); - } - }else{ - modifiedParamTypes.add(new SuperWildcardType((ObjectType) pT)); - } - } + Type retType = method_body.getType(); - // PN < TPH PN - if(retType instanceof WildcardType){ - //Auf Typfehler kontrollieren. Siehe Bug #12 Kommentar 3 - if(retType instanceof SuperWildcardType){ - throw new TypeinferenceException("Typfehler von Parametertyp "+retType,this); - }else{ - //retType bleibt unverändert - } - }else{ - //Die LambdaExpression kann zu diesem Zeit schon feststellen, ob der Return-Type Void ist (Kein Return-Statement): - if(!typeIsVoid(retType)){ //Nur, wenn es nicht void ist, kann der ExtendsWildcardType gebildet werden. - retType = new ExtendsWildcardType((ObjectType) retType); - } - } + if(typeIsVoid(retType)){//In diesem Fall, muss der Typ des LambdaAusdrucks FunVoid sein - this.lambdaType = new FunVoidN(modifiedParamTypes); + this.lambdaType = new FunVoidN(paramTypes); }else{ - this.lambdaType = new FunN(retType, modifiedParamTypes); + this.lambdaType = new FunN(retType, paramTypes); } ret.add(ConstraintsSet.createSingleConstraint(lambdaType.TYPE(assumptions, this),this.getType().TYPE(assumptions, this))); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java index 5fb393db..bfed3c5e 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java @@ -99,59 +99,6 @@ public class LocalVarDecl extends Statement implements TypeInsertable } // ino.end - // ino.method.is_declared.25587.definition - public void is_declared(Type t, Menge classlist) - throws SCStatementException - // ino.end - // ino.method.is_declared.25587.body - { - boolean flag=false; - for(Enumeration e = classlist.elements();e.hasMoreElements();){ - flag = false; - Class c = e.nextElement(); - - // System.out.println("is_init: vergleiche "+t.get_Type_()+" mit "+c.get_classname()); - if(c.getName().equals(t.getName())){ - // System.out.println("Klasse "+t.get_Type()+" im Menge classlist gefunden."); - flag = true; - break; - } - } - - if ( t instanceof RefType ) - { - if(((RefType)t).get_ParaList()!=null) - { - if( ((RefType)t).get_ParaList().size()>0) - { - for(Enumeration e1 = ((RefType)t).get_ParaList().elements();e1.hasMoreElements();) - { - try - { - is_declared((Type)e1.nextElement(),classlist); - } - catch(SCStatementException ex) - { - throw ex; - } - } - } - } - } - - if(!flag) - { - SCStatementException ex = new SCStatementException(); - SCExcept e = new SCExcept(); - e.set_error("unbekannte Klasse "+t.getName()+"."); - e.set_function("complete_parahashtable() --> is_declared()"); - e.set_statement(t.getName().toString()); - ex.addException(e); - throw ex; - } - } - // ino.end - /* // ino.method.check_anz.25590.definition public void check_anz(Type type, Menge paralist, Menge classlist) @@ -429,7 +376,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable @Override public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) { - // TODO Auto-generated method stub + _cg.getInstructionFactory().getStoreIndex(get_Name()); return new InstructionList(); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java index 7b7b82bb..affe569d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java @@ -326,6 +326,7 @@ public class MethodCall extends Expr public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) { InstructionList il = new InstructionList(); DHBWInstructionFactory _factory = cg.getInstructionFactory(); + //TODO: später wiederherstelln? _factory.resetStoreIndexes(); il.append(receiver.get_Expr().genByteCode(cg, rs)); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java index e29f45f6..4da17ecd 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java @@ -6,7 +6,11 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; +import org.apache.commons.bcel6.generic.BranchInstruction; import org.apache.commons.bcel6.generic.ClassGen; +import org.apache.commons.bcel6.generic.DUP; +import org.apache.commons.bcel6.generic.GOTO; +import org.apache.commons.bcel6.generic.IFEQ; import org.apache.commons.bcel6.generic.InstructionList; import de.dhbwstuttgart.typeinference.Menge; @@ -138,8 +142,20 @@ public class WhileStmt extends Statement @Override public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) { - // TODO Bytecode - throw new NotImplementedException(); + //TOD: while Statement + InstructionList il = expr.genByteCode(_cg, rs); + + BranchInstruction ifeq = new IFEQ(null); + il.append(ifeq); + + il.append(loop_block.genByteCode(_cg, rs)); + + il.append(new GOTO(il.getStart())); + + ifeq.setTarget(il.append(new DUP())); + + + return il; } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/type/FunN.java b/src/de/dhbwstuttgart/syntaxtree/type/FunN.java index efe96c26..0e23a2a2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/FunN.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/FunN.java @@ -1,15 +1,21 @@ package de.dhbwstuttgart.syntaxtree.type; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; + import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.ParameterList; +import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; +import de.dhbwstuttgart.typeinference.exceptions.DebugException; +import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; /** * @see Spezifikation "Complete Typeinference in Java 8" von Martin Plümicke @@ -23,7 +29,7 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; public class FunN extends RefType { private Type R; - private Menge T; + private List T; /** * @author Andreas Stadelmeier, a10023 @@ -33,7 +39,7 @@ public class FunN extends RefType { * @param T * @return */ - public FunN(Type R, Menge T) { + public FunN(Type R, List T) { super("",null,0); if(T==null || R == null)throw new NullPointerException(); setT(T); @@ -44,11 +50,11 @@ public class FunN extends RefType { /** * Spezieller Konstruktor um eine FunN ohne Returntype zu generieren */ - protected FunN(Menge T){ + protected FunN(List list){ super("",null,0); - if(T==null)throw new NullPointerException(); - setT(T); - this.name = new JavaClassName("Fun"+T.size());//getName(); + if(list==null)throw new NullPointerException(); + setT(list); + this.name = new JavaClassName("Fun"+list.size());//getName(); } /** @@ -68,15 +74,6 @@ public class FunN extends RefType { setT(t); this.name = new JavaClassName("Fun"+parameterCount); - /* - Menge t = new Menge(); - for(int i=0;i t = new Menge(); if(R!=null)t.add(R); if(T!=null)t.addAll(T); + for(Type type : t){ + if(type instanceof WildcardType){ + throw new DebugException("Der FunN-Typ darf keine Wildcards in den Parameter enthalten"); + } + } this.set_ParaList(t); } - protected void setT(Menge T){ - this.T = T; + protected void setT(List list){ + this.T = list; calculateNewParalist(); } protected void setR(Type R){ @@ -137,6 +139,18 @@ public class FunN extends RefType { return ret; } + @Override + public Type TYPE(TypeAssumptions ass, SyntaxTreeNode parent){ + //FunN Typen müssen nicht geprüft werden. Sie werden schließlich nur von unserem Typinferenzalgorithmus erstellt: + List paraList = new ArrayList<>(); + for(Type t : this.T){ + Type toAdd = t.TYPE(ass, parent); + //if(toAdd == null)throw new TypeinferenceException("Typ "+toAdd+" ist in den Assumptions nicht vorhanden",this); + paraList.add(toAdd); + } + FunN ret = new FunN(this.R.TYPE(ass, parent),paraList); + return ret; + } /* public CMethodTypeAssumption toCMethodTypeAssumption() { diff --git a/src/de/dhbwstuttgart/syntaxtree/type/GenericClassType.java b/src/de/dhbwstuttgart/syntaxtree/type/GenericClassType.java index 0df35e3c..9985f48f 100644 --- a/src/de/dhbwstuttgart/syntaxtree/type/GenericClassType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/GenericClassType.java @@ -1,5 +1,7 @@ package de.dhbwstuttgart.syntaxtree.type; +import java.util.List; + import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.Class; @@ -12,7 +14,7 @@ import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; public class GenericClassType extends RefType{ - public GenericClassType(String fullyQualifiedName, Menge parameter, SyntaxTreeNode parent, int offset) { + public GenericClassType(String fullyQualifiedName, List parameter, SyntaxTreeNode parent, int offset) { super(fullyQualifiedName, parameter, parent, offset); } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index d0033d32..20e8fe25 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; +import java.util.List; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.logger.Logger; @@ -47,7 +48,7 @@ public class RefType extends ObjectType implements IMatchable private boolean IsArray = false; // ino.attribute.parameter.26625.declaration - private Menge parameter = null; + private List parameter = null; // ino.end // ino.attribute.primitiveFlag.29412.decldescription type=javadoc /** @@ -97,7 +98,7 @@ public class RefType extends ObjectType implements IMatchable } // ino.method.RefType.26640.definition - public RefType(String fullyQualifiedName, Menge parameter,SyntaxTreeNode parent, int offset) + public RefType(String fullyQualifiedName, List parameter,SyntaxTreeNode parent, int offset) // ino.end // ino.method.RefType.26640.body { @@ -134,52 +135,6 @@ public class RefType extends ObjectType implements IMatchable this(jName.toString(), parent, offset); } - // ino.method.Type2Key.26646.definition - public String Type2Key() - // ino.end - // ino.method.Type2Key.26646.body - { - if(parameter==null) - { - return name.toString(); - } - else - { - String para = new String(); - for(Enumeration e=parameter.elements();e.hasMoreElements();) - { - String t = ((Type)e.nextElement()).Type2Key(); - if(para.length() > 0) - para = para +", "+ t; - else para = " " + t; - } - return name + "<"+para + " >" ; - } - } - // ino.end - - // ino.method.Type2String.26649.definition - public String Type2String() - // ino.end - // ino.method.Type2String.26649.body - { - if(parameter==null) - { - return name.toString(); - } - else - { - String para = new String(); - for(Enumeration e=parameter.elements();e.hasMoreElements();) - { - String t = ((Type)e.nextElement()).Type2String(); - if(para.length() > 0) - para = para +", "+ t; - else para = " " + t; - } - return name + "<"+para + " >" ; - } - } /** * Wandelt die Parameter des RefTypes in TPHs um, sofern es sich um Generische Variablen handelt. @@ -290,7 +245,7 @@ public class RefType extends ObjectType implements IMatchable * @param v */ // ino.method.set_ParaList.26661.definition - public void set_ParaList(Menge v) + public void set_ParaList(List v) // ino.end // ino.method.set_ParaList.26661.body { @@ -301,8 +256,6 @@ public class RefType extends ObjectType implements IMatchable else paralist.add(t); }*/ this.parameter = v;//paralist; - //parserlog.debug("T->Type.java->set_ParaList->parameter: " + parameter); - //parserlog.debug("T->Type.java->get_Type: " + getName()); } // ino.end @@ -310,7 +263,7 @@ public class RefType extends ObjectType implements IMatchable * @return gibt bei leere Parameterliste null zurück. Ist entscheidend für unify-Algorithmus */ // ino.method.get_ParaList.26664.definition - public Menge get_ParaList() + public List get_ParaList() // ino.end // ino.method.get_ParaList.26664.body { @@ -319,7 +272,7 @@ public class RefType extends ObjectType implements IMatchable } // ino.end - public Menge getParaList(){ + public List getParaList(){ if(this.parameter==null)return new Menge<>(); return this.parameter; } @@ -341,179 +294,7 @@ public class RefType extends ObjectType implements IMatchable // otth: Liefert den Namen des Typs, ohne Parameter, z.B. Stapel bei Stapel return name.toString(); } - // ino.end - // ino.method.getParaN.26673.definition - public String getParaN( int n ) - throws SCException - // ino.end - // ino.method.getParaN.26673.body - { - // otth: liefert n.ten Parameter - if( parameter == null ) - { - throw new SCException(); - } - - if( n >= parameter.size() ) - return ""; - - return ((Type)parameter.elementAt(n)).getName().toString(); - } - // ino.end - - // ino.method.isTV.26676.definition - public boolean isTV( int n ) - // ino.end - // ino.method.isTV.26676.body - { - // otth: Prueft, ob Parameter n eine TV ist - return parameter.elementAt(n) instanceof TypePlaceholder; - } - // ino.end - - - // ino.method.is_Equiv.26679.defdescription type=line - // GenericTypeVar ergaenzt PL 06-03-16 - // ino.end - // ino.method.is_Equiv.26679.definition - public boolean is_Equiv(RefType ty2, Hashtable ht) - // ino.end - // ino.method.is_Equiv.26679.body - { - //vergleicht einen Typ ty2 mit dem aktuellen Typ, ob es bis auf Variablenumbennung - //gleich ist. - //System.out.println("is_EquivSTART: " + this.get_Type()); - //System.out.println("is_EquivSTART: " + ty2.get_Type()); - if (this.getTypeName().equals(ty2.getTypeName())) { - //System.out.println("is_EquivSTARTx: " + this.get_Type()); - if ((get_ParaList() != null) && (ty2.get_ParaList() != null)) { - if (get_ParaList().size() == ty2.get_ParaList().size()) { - for(int i=0; i < get_ParaList().size(); i++) { - Type pty1 = (Type)get_ParaList().elementAt(i); - Type pty2 = (Type)ty2.get_ParaList().elementAt(i); - if ((pty1 instanceof RefType) && (pty2 instanceof RefType)) { - //System.out.println("Instance RefType" + ((RefType)pty1).get_Type()); - //System.out.println("Instance RefType" + ((RefType)pty2).get_Type()); - if (!((RefType)pty1).is_Equiv((RefType)pty2, ht)) return false; - } - else { - if ((pty1 instanceof TypePlaceholder) && (pty2 instanceof TypePlaceholder)) { - //System.out.println("Instance TypePlaceholder" + (((TypePlaceholder)pty1).get_Type())); - //System.out.println("Instance TypePlaceholder" + (((TypePlaceholder)pty2).get_Type())); - if (ht.get((((TypePlaceholder)pty1).getName())) != null) { - //System.out.println(ht.get((((TypePlaceholder)pty1).getName()))); - if (!((TypePlaceholder)ht.get((((TypePlaceholder)pty1).getName()))).getName().equals(pty2.getName())) return false; - } - else { - //System.out.println("INPUT" + pty1.getName()); - //System.out.println("INPUT" + pty2); - ht.put(pty1.getName(), pty2); - } - } - else { - if ((pty1 instanceof GenericTypeVar) && (pty2 instanceof GenericTypeVar)) { - if (ht.get((((GenericTypeVar)pty1).getName())) != null) { - if (!((GenericTypeVar)ht.get((((GenericTypeVar)pty1).getName()))).getName().equals(pty2.getName())) return false; - } - else { - ht.put(pty1.getName(), pty2); - } - } - else { - return false; - } - } - } - } - return true; - } - else { - return false; - } - } - else { - //Typ ohne Parameter - return true; - } - } - else { - return false; - } - } - // ino.end - - // ino.method.Equiv2Equal.26682.definition - public boolean Equiv2Equal(RefType ty2, Hashtable ht) - // ino.end - // ino.method.Equiv2Equal.26682.body - { - //vergleicht einen Typ ty2 mit dem aktuellen Typ, ob er bis auf Variablenumbennung - //gleich ist und bennent ty2 so um, dass sie gleich sind. - //System.out.println("is_EquivSTART: " + this.getName()); - //System.out.println("is_EquivSTART: " + ty2.getName()); - if (this.getTypeName().equals(ty2.getTypeName())) { - //System.out.println("is_EquivSTARTx: " + this.getName()); - if ((get_ParaList() != null) && (ty2.get_ParaList() != null)) { - if (get_ParaList().size() == ty2.get_ParaList().size()) { - for(int i=0; i < get_ParaList().size(); i++) { - Type pty1 = (Type)get_ParaList().elementAt(i); - Type pty2 = (Type)ty2.get_ParaList().elementAt(i); - if ((pty1 instanceof RefType) && (pty2 instanceof RefType)) { - //System.out.println("Instance RefType" + ((RefType)pty1).getName()); - //System.out.println("Instance RefType" + ((RefType)pty2).getName()); - if (!((RefType)pty1).is_Equiv((RefType)pty2, ht)) return false; - } - else { - if ((pty1 instanceof TypePlaceholder) && (pty2 instanceof TypePlaceholder)) { - //System.out.println("Instance TypePlaceholder" + (((TypePlaceholder)pty1).getName())); - //System.out.println("Instance TypePlaceholder" + (((TypePlaceholder)pty2).getName())); - if (ht.get((((TypePlaceholder)pty1).getName())) != null) { - //System.out.println(ht.get((((TypePlaceholder)pty1).getName()))); - if (!((TypePlaceholder)ht.get((((TypePlaceholder)pty1).getName()))).getName().equals(pty2.getName())) return false; - else { //Typvariablen gleich machen - // #JB# 11.04.2005 - // ########################################################### - ((TypePlaceholder)pty2).backdoorSetName(((TypePlaceholder)ht.get((((TypePlaceholder)pty1).getName()))).getName().toString()); - //pty2.setName(((TypePlaceholder)ht.get((((TypePlaceholder)pty1).getName()))).getName()); - // ########################################################### - } - - } - else { - //System.out.println("INPUT" + pty1.getName()); - //System.out.println("INPUT" + pty2); - ht.put(pty1.getName(), pty2); - // #JB# 11.04.2005 - // ########################################################### - ((TypePlaceholder)pty2).backdoorSetName(pty1.getName().toString()); - //pty2.setName(pty1.getName()); - // ########################################################### - } - } - else { - return false; - } - } - } - return true; - } - else { - return false; - } - } - else { - //Typ ohne Parameter - return true; - } - } - else { - return false; - } - } - // ino.end - - // ino.method.equals.26685.defdescription type=javadoc /** * Author: Jrg Buerle
* @param Object @@ -565,11 +346,11 @@ public class RefType extends ObjectType implements IMatchable { if(this.get_ParaList() != null ) { - Menge para = this.get_ParaList(); + List para = this.get_ParaList(); Menge clonepara = new Menge(); for(int i = 0; i< para.size(); i++) { - clonepara.addElement(((Type)para.elementAt(i)).clone()); + clonepara.addElement(((Type)para.get(i)).clone()); } RefType newRefType=new RefType(this.getTypeName(), clonepara,this.getParent(),getOffset()); newRefType.setPrimitiveFlag(this.getPrimitiveFlag()); @@ -598,10 +379,10 @@ public class RefType extends ObjectType implements IMatchable else { String para = new String(); - Enumeration e=parameter.elements(); - while(e.hasMoreElements()) + Iterator e=parameter.iterator(); + while(e.hasNext()) { - Type ty = (Type)e.nextElement(); + Type ty = (Type)e.next(); String t = ty.toString(); if(para.length() > 0) para = para +", "+ t; diff --git a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java index e9f9918d..dd4a2ff1 100755 --- a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java +++ b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java @@ -71,19 +71,6 @@ public class ConstraintsSet extends UndMenge implements Iterable filterUndConstraints() { - Vector ret = new Vector<>(); - for(OderConstraint con : constraintsSet){ - UndConstraint filtered = con.filterUndConstraints(); - if(filtered != null)ret.add(filtered); - } - return ret; - } public void add(UndConstraint singleConstraint) { OderConstraint toAdd = new OderConstraint(); diff --git a/src/de/dhbwstuttgart/typeinference/FunNInterface.java b/src/de/dhbwstuttgart/typeinference/FunNInterface.java index 920b4899..877e0632 100644 --- a/src/de/dhbwstuttgart/typeinference/FunNInterface.java +++ b/src/de/dhbwstuttgart/typeinference/FunNInterface.java @@ -2,9 +2,14 @@ package de.dhbwstuttgart.typeinference; import de.dhbwstuttgart.typeinference.Menge; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; +import de.dhbwstuttgart.syntaxtree.type.FunN; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; @@ -78,5 +83,19 @@ public class FunNInterface extends Class{ return new FunNMethod(this.get_ParaList()); //return new FunNMethod(this.get_ParaList().size()-1); } + + @Override + public RefType getType() { + List paraList = this.get_ParaList(); + Iterator paraIter = paraList.iterator(); + Type R = paraIter.next(); + List paraListNew = new ArrayList<>(); + while(paraIter.hasNext()){ + paraListNew.add(paraIter.next()); + } + return new FunN(R, paraListNew); + } + + } diff --git a/src/de/dhbwstuttgart/typeinference/FunNMethod.java b/src/de/dhbwstuttgart/typeinference/FunNMethod.java index d7a18ad4..6ac8011e 100755 --- a/src/de/dhbwstuttgart/typeinference/FunNMethod.java +++ b/src/de/dhbwstuttgart/typeinference/FunNMethod.java @@ -3,6 +3,9 @@ package de.dhbwstuttgart.typeinference; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.syntaxtree.FormalParameter; + +import java.util.List; + import de.dhbwstuttgart.syntaxtree.Class; import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.ParameterList; @@ -16,10 +19,10 @@ public class FunNMethod extends Method{ * * @param N - Anzahl der Parameter (Beispiel: Fun2) */ - public FunNMethod(Menge paralist){ + public FunNMethod(List paralist){ super(0); //Hat keinen Offset, da nur theoretisch gedachte Methode int N = paralist.size(); //In der paraliste ist der erste Parameter der Rückgabetyp - this.setType(paralist.firstElement()); + this.setType(paralist.get(0)); this.set_DeclId(new DeclId("apply")); ParameterList pl = new ParameterList(); Menge fpList = new Menge(); diff --git a/src/de/dhbwstuttgart/typeinference/FunVoidNMethod.java b/src/de/dhbwstuttgart/typeinference/FunVoidNMethod.java index bf1d9f41..41bf2242 100644 --- a/src/de/dhbwstuttgart/typeinference/FunVoidNMethod.java +++ b/src/de/dhbwstuttgart/typeinference/FunVoidNMethod.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.typeinference; import de.dhbwstuttgart.typeinference.Menge; +import java.util.List; import de.dhbwstuttgart.syntaxtree.type.Void; import de.dhbwstuttgart.syntaxtree.FormalParameter; @@ -17,7 +18,7 @@ public class FunVoidNMethod extends Method{ * * @param N - Anzahl der Parameter (Beispiel: Fun2) */ - public FunVoidNMethod(Menge paralist, Class parent){ + public FunVoidNMethod(List paralist, Class parent){ super(0); //Hat keinen Offset, da nur theoretisch gedachte Methode int N = paralist.size(); this.setType(new Void(this, -1)); diff --git a/src/de/dhbwstuttgart/typeinference/OderConstraint.java b/src/de/dhbwstuttgart/typeinference/OderConstraint.java index 9c741ec8..c3853f83 100755 --- a/src/de/dhbwstuttgart/typeinference/OderConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/OderConstraint.java @@ -59,7 +59,9 @@ public class OderConstraint extends OderMenge{ * @param toAdd */ public void addConstraint(Pair toAdd){ - oderConstraintPairs.add(new SingleConstraint(toAdd)); + UndConstraint uCons = new UndConstraint(); + uCons.addConstraint(toAdd); + oderConstraintPairs.add(uCons); } @Override diff --git a/src/de/dhbwstuttgart/typeinference/Pair.java b/src/de/dhbwstuttgart/typeinference/Pair.java index c31fc695..b0792868 100755 --- a/src/de/dhbwstuttgart/typeinference/Pair.java +++ b/src/de/dhbwstuttgart/typeinference/Pair.java @@ -9,6 +9,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Hashtable; +import java.util.List; import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; @@ -143,8 +144,8 @@ public class Pair implements Serializable, DeepCloneable RefType RT1=(RefType)TA1; RefType RT2=(RefType)TA2; if(RT1.getTypeName().equals(RT2.getTypeName())){ - Menge v1=RT1.get_ParaList(); - Menge v2=RT2.get_ParaList(); + List v1=RT1.get_ParaList(); + List v2=RT2.get_ParaList(); if(v1==null && v2==null){ return true; }else{ @@ -155,8 +156,8 @@ public class Pair implements Serializable, DeepCloneable return false; }else{ for(int i=0;i ht = new Hashtable(); - //System.out.println((((RefType)TA1).is_Equiv((RefType)p.TA1, ht))); - //System.out.println(((RefType)TA2).is_Equiv((RefType)p.TA2, ht)); - - //Typen boxen, da es sich um TypePlaceholder handeln koennte - Menge hilfsMenge1 = new Menge(); - Menge hilfsMenge2 = new Menge(); - hilfsMenge1.addElement(TA1); - hilfsMenge2.addElement(TA2); - Menge hilfsMenge3 = new Menge(); - Menge hilfsMenge4 = new Menge(); - hilfsMenge3.addElement(p.TA1); - hilfsMenge4.addElement(p.TA2); - //return (((RefType)TA1).is_Equiv((RefType)p.TA1, ht) && ((RefType)TA2).is_Equiv((RefType)p.TA2, ht)); - return (new RefType("dummy", hilfsMenge3,null,-1)).is_Equiv(new RefType("dummy", hilfsMenge1,null,-1), ht) && - (new RefType("dummy", hilfsMenge4,null,-1)).is_Equiv(new RefType("dummy", hilfsMenge2,null,-1), ht); - } - // ino.end - - - // ino.method.isInMenge.26585.definition - public boolean isInMenge( Menge V ) - // ino.end - // ino.method.isInMenge.26585.body - { - // otth: prueft, ob Paar in Vektor liegt - for( int i = 0; i < V.size(); i++ ) - { - if( V.elementAt(i) instanceof Pair ) - { - //if( this.toString().equals( ( (Pair)V.elementAt(i) ).toString() ) ) - if(Pair_isEquiv(V.elementAt(i))) { - return true; - } - } - } - return false; - } - // ino.end - // ino.method.equals.26588.defdescription type=javadoc /** *
Author: J�rg B�uerle diff --git a/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java b/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java index 5ce7a445..d4f01d53 100644 --- a/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java +++ b/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java @@ -1,5 +1,7 @@ package de.dhbwstuttgart.typeinference; +import java.util.List; + import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.logger.Section; @@ -9,21 +11,21 @@ import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType; public class TypeinferenceResults { - private Menge typeReconstructions; + private List typeReconstructions; public TypeinferenceResults() { typeReconstructions = new Menge<>(); } - public TypeinferenceResults(Menge typeReconstructions) { + public TypeinferenceResults(List typeReconstructions) { this.typeReconstructions = typeReconstructions; } - public Menge getTypeReconstructions() { + public List getTypeReconstructions() { return typeReconstructions; } - public Menge getTypeReconstructions(Method method, ClassGenerator cg) { + public List getTypeReconstructions(Method method, ClassGenerator cg) { return typeReconstructions; } } \ No newline at end of file diff --git a/src/de/dhbwstuttgart/typeinference/UndConstraint.java b/src/de/dhbwstuttgart/typeinference/UndConstraint.java index a53f0998..bb6914ee 100755 --- a/src/de/dhbwstuttgart/typeinference/UndConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/UndConstraint.java @@ -33,7 +33,11 @@ public class UndConstraint extends UndMenge { public void addConstraint(Type type, Type rT) { Pair p = new Pair(type, rT); - this.set.add(new EinzelElement(p)); + addConstraint(p); + } + + public void addConstraint(Pair toAdd){ + this.set.add(new EinzelElement(toAdd)); } @Override diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java index 7ece0a81..fe59bbd2 100755 --- a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java @@ -257,18 +257,6 @@ public class TypeAssumptions { * @return null, falls der Typ nicht vorhanden ist. */ public Type getTypeFor(Type t, SyntaxTreeNode inNode){ - /* - if(t instanceof WildcardType){ - WildcardType wt = (WildcardType)t; - Type innerType = wt.GetWildcardType(); - innerType = getTypeFor(innerType, t).getType(); - wt.SetWildcardType(innerType); - return new ConstraintType(wt); - } - - if(t instanceof TypePlaceholder) - return new ConstraintType((TypePlaceholder)t); //Handelt es sich um einen TypePlaceholder kann dieser nicht in den Assumptions vorkommen. - */ //Alle bekannten Klassen nach diesem Typ durchsuchen: JavaClassName typName = t.getName(); for(ClassAssumption ass : this.classAssumptions){ diff --git a/src/de/dhbwstuttgart/typeinference/exceptions/NotImplementedException.java b/src/de/dhbwstuttgart/typeinference/exceptions/NotImplementedException.java index 5daaef67..bf7e7779 100644 --- a/src/de/dhbwstuttgart/typeinference/exceptions/NotImplementedException.java +++ b/src/de/dhbwstuttgart/typeinference/exceptions/NotImplementedException.java @@ -1,5 +1,11 @@ package de.dhbwstuttgart.typeinference.exceptions; public class NotImplementedException extends RuntimeException { + + public NotImplementedException() { + } + public NotImplementedException(String string) { + super(string); + } } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java b/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java index b7e5c60e..cf2c86ae 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java @@ -14,7 +14,7 @@ public class FunNType extends UnifyType { * Creates a FunN-Type with the specified TypeParameters. */ protected FunNType(TypeParams p) { - super("FuN", p); + super("Fun"+(p.size()-1), p); } /** diff --git a/test/bytecode/ASTBytecodeTest.java b/test/bytecode/ASTBytecodeTest.java index 32fd8088..d2b4af70 100644 --- a/test/bytecode/ASTBytecodeTest.java +++ b/test/bytecode/ASTBytecodeTest.java @@ -56,10 +56,7 @@ public abstract class ASTBytecodeTest { String rootDirectory = getRootDirectory(); - System.out.println(rootDirectory); - JavaClass javaClass = result.getByteCode().getJavaClass(); - System.out.println(javaClass.toString()); javaClass.dump(new File(rootDirectory+javaClass.getClassName()+".class")); for(ClassGenerator cg: result.getByteCode().getExtraClasses().values()){ @@ -68,7 +65,6 @@ public abstract class ASTBytecodeTest { } }catch(Exception e){ - System.out.print(e.getMessage()); throw new RuntimeException(e); } } @@ -91,8 +87,4 @@ public abstract class ASTBytecodeTest { public String getTestName() { return "No Testname defined!"; } - - - - } diff --git a/test/bytecode/AssignTest.java b/test/bytecode/AssignTest.java index 232564df..03a32865 100644 --- a/test/bytecode/AssignTest.java +++ b/test/bytecode/AssignTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class AssignTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Assign.jav"; - public final static String outputFile = "Assign.class"; +public class AssignTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Assign"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } } diff --git a/test/bytecode/BinaryTest.java b/test/bytecode/BinaryTest.java index 37b0ab82..3e73a2ea 100644 --- a/test/bytecode/BinaryTest.java +++ b/test/bytecode/BinaryTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class BinaryTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Binary.jav"; - public final static String outputFile = "Binary.class"; +public class BinaryTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Binary"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/BinaryTest2.java b/test/bytecode/BinaryTest2.java index 842af094..5ea33514 100644 --- a/test/bytecode/BinaryTest2.java +++ b/test/bytecode/BinaryTest2.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class BinaryTest2 { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Binary2.jav"; - public final static String outputFile = "Binary2.class"; +public class BinaryTest2 extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Binary2"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } } diff --git a/test/bytecode/BoolLitTest.java b/test/bytecode/BoolLitTest.java index 75bd41ed..be459e8d 100644 --- a/test/bytecode/BoolLitTest.java +++ b/test/bytecode/BoolLitTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class BoolLitTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "BoolLit.jav"; - public final static String outputFile = "BoolLit.class"; +public class BoolLitTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "BoolLit"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/CharLitTest.java b/test/bytecode/CharLitTest.java index 60f2c4d5..87b35013 100644 --- a/test/bytecode/CharLitTest.java +++ b/test/bytecode/CharLitTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class CharLitTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "CharLitTest.jav"; - public final static String outputFile = "CharLitTest.class"; +public class CharLitTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "CharLit"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } } diff --git a/test/bytecode/ConditionTest.java b/test/bytecode/ConditionTest.java index 851d6426..dfbbadf9 100644 --- a/test/bytecode/ConditionTest.java +++ b/test/bytecode/ConditionTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class ConditionTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Condition.jav"; - public final static String outputFile = "Condition.class"; +public class ConditionTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Condition"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } } diff --git a/test/bytecode/EmptyClassTest.java b/test/bytecode/EmptyClassTest.java index de7d900a..6050dd37 100644 --- a/test/bytecode/EmptyClassTest.java +++ b/test/bytecode/EmptyClassTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class EmptyClassTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "EmptyClass.jav"; - public final static String outputFile = "EmptyClass.class"; +public class EmptyClassTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "EmptyClass"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } } diff --git a/test/bytecode/FieldDeclarationTest.java b/test/bytecode/FieldDeclarationTest.java index 7724c0e8..ea6b8062 100644 --- a/test/bytecode/FieldDeclarationTest.java +++ b/test/bytecode/FieldDeclarationTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class FieldDeclarationTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "FieldDeclaration.jav"; - public final static String outputFile = "FieldDeclaration.class"; +public class FieldDeclarationTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "FieldDeclaration"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file diff --git a/test/bytecode/ForTest.jav b/test/bytecode/ForTest.jav index 649b71b0..d2723cf4 100644 --- a/test/bytecode/ForTest.jav +++ b/test/bytecode/ForTest.jav @@ -1,6 +1,6 @@ -class IfElse{ - method(){ - for( i = 0; i < 10 ; i = i++){ +class ForTest{ + void method(){ + for(Integer i = 0; i < 10 ; i = i + 1){ } } diff --git a/test/bytecode/ForTest.java b/test/bytecode/ForTest.java index 497dc375..d34b2a63 100644 --- a/test/bytecode/ForTest.java +++ b/test/bytecode/ForTest.java @@ -3,14 +3,20 @@ package bytecode; import org.junit.Ignore; import org.junit.Test; -public class ForTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "ForTest.jav"; - public final static String outputFile = "ForTest.class"; +public class ForTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "ForTest"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - @Ignore - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } } diff --git a/test/bytecode/IdTest.java b/test/bytecode/IdTest.java index f303e5d0..f5da1ab2 100644 --- a/test/bytecode/IdTest.java +++ b/test/bytecode/IdTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class IdTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Id.jav"; - public final static String outputFile = "Id.class"; +public class IdTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Id"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file diff --git a/test/bytecode/IdentityField.jav b/test/bytecode/IdentityField.jav index 29781431..8063d0b3 100644 --- a/test/bytecode/IdentityField.jav +++ b/test/bytecode/IdentityField.jav @@ -1,3 +1,3 @@ -class Id { +class IdentityField { Fun1 op = (x) -> x; } \ No newline at end of file diff --git a/test/bytecode/IdentityFieldTest.java b/test/bytecode/IdentityFieldTest.java index e50b001e..2a6e7ecd 100644 --- a/test/bytecode/IdentityFieldTest.java +++ b/test/bytecode/IdentityFieldTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class IdentityFieldTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "IdentityField.jav"; - public final static String outputFile = "IdentityField.class"; +public class IdentityFieldTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "IdentityField"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file diff --git a/test/bytecode/IdentityTest.java b/test/bytecode/IdentityTest.java index 7d5493ee..2aa2563e 100644 --- a/test/bytecode/IdentityTest.java +++ b/test/bytecode/IdentityTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class IdentityTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Identity.jav"; - public final static String outputFile = "Identity.class"; +public class IdentityTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Identity"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file diff --git a/test/bytecode/IfElseIfStatement.jav b/test/bytecode/IfElseIfStatement.jav index 1b6fbb89..caf9d524 100644 --- a/test/bytecode/IfElseIfStatement.jav +++ b/test/bytecode/IfElseIfStatement.jav @@ -4,6 +4,8 @@ class IfElseIfStatement{ return 0; }else if(flag){ return 1; + }else{ + return 2; } } diff --git a/test/bytecode/IfElseIfStatementTest.java b/test/bytecode/IfElseIfStatementTest.java index 9ac14c4c..6e60d3a6 100644 --- a/test/bytecode/IfElseIfStatementTest.java +++ b/test/bytecode/IfElseIfStatementTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class IfElseIfStatementTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "IfElseIfStatement.jav"; - public final static String outputFile = "IfElseIfStatement.class"; +public class IfElseIfStatementTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "IfElseIfStatement"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } } diff --git a/test/bytecode/IfElseStatementTest.java b/test/bytecode/IfElseStatementTest.java index 9b491a6b..3209b8d1 100644 --- a/test/bytecode/IfElseStatementTest.java +++ b/test/bytecode/IfElseStatementTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class IfElseStatementTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "IfElseStatement.jav"; - public final static String outputFile = "IfElseStatement.class"; +public class IfElseStatementTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "IfElseStatement"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } } diff --git a/test/bytecode/IfStatementTest.java b/test/bytecode/IfStatementTest.java index 848f46d4..baa8b906 100644 --- a/test/bytecode/IfStatementTest.java +++ b/test/bytecode/IfStatementTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class IfStatementTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "IfStatement.jav"; - public final static String outputFile = "IfStatement.class"; +public class IfStatementTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "IfStatement"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } } diff --git a/test/bytecode/LambdaExpr2.java b/test/bytecode/LambdaExpr2Test.java similarity index 63% rename from test/bytecode/LambdaExpr2.java rename to test/bytecode/LambdaExpr2Test.java index 83308ca5..ac85b8d0 100644 --- a/test/bytecode/LambdaExpr2.java +++ b/test/bytecode/LambdaExpr2Test.java @@ -21,16 +21,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class LambdaExpr2 { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "LambdaExpr2.jav"; - public final static String outputFile = "LambdaExpr2.class"; +public class LambdaExpr2Test extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "LambdaExpr"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - @Ignore - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } } diff --git a/test/bytecode/LambdaExpr.java b/test/bytecode/LambdaExprTest.java similarity index 62% rename from test/bytecode/LambdaExpr.java rename to test/bytecode/LambdaExprTest.java index c28dad56..c6b8e0f5 100644 --- a/test/bytecode/LambdaExpr.java +++ b/test/bytecode/LambdaExprTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class LambdaExpr { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "LambdaExpr.jav"; - public final static String outputFile = "LambdaExpr.class"; +public class LambdaExprTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "LambdaExpr"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/MainTest.java b/test/bytecode/MainTest.java index 768c2fca..97abece4 100644 --- a/test/bytecode/MainTest.java +++ b/test/bytecode/MainTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class MainTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Main.jav"; - public final static String outputFile = "Main.class"; +public class MainTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Main"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } } diff --git a/test/bytecode/Matrix_lambda.jav b/test/bytecode/Matrix_lambda.jav index 293f776e..f531d2ba 100644 --- a/test/bytecode/Matrix_lambda.jav +++ b/test/bytecode/Matrix_lambda.jav @@ -1,5 +1,5 @@ import java.util.Vector; -class Matrix extends Vector> { +class Matrix_lambda extends Vector> { op = (Matrix m) -> (f) -> f.apply(this, m); } \ No newline at end of file diff --git a/test/bytecode/Matrix_lambda2.jav b/test/bytecode/Matrix_lambda2.jav index e67ce40c..667e02e2 100644 --- a/test/bytecode/Matrix_lambda2.jav +++ b/test/bytecode/Matrix_lambda2.jav @@ -1,4 +1,4 @@ -class Matrix2 { +class Matrix_lambda2 { op = (f) -> f.apply(2); } \ No newline at end of file diff --git a/test/bytecode/Matrix_lambda3.jav b/test/bytecode/Matrix_lambda3.jav index 7fc6dede..f0341cdc 100644 --- a/test/bytecode/Matrix_lambda3.jav +++ b/test/bytecode/Matrix_lambda3.jav @@ -1,4 +1,4 @@ -class Matrix3 { +class Matrix_lambda3 { op = (f) -> f.apply(); } \ No newline at end of file diff --git a/test/bytecode/Matrix_lambdaTest.java b/test/bytecode/Matrix_lambdaTest.java index 7cbf4932..5d8b4e39 100644 --- a/test/bytecode/Matrix_lambdaTest.java +++ b/test/bytecode/Matrix_lambdaTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class Matrix_lambdaTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Matrix_lambda.jav"; - public final static String outputFile = "Matrix_lambda.class"; +public class Matrix_lambdaTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Matrix_lambda"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file diff --git a/test/bytecode/Matrix_lambdaTest2.java b/test/bytecode/Matrix_lambdaTest2.java index 3264bfa0..374802a3 100644 --- a/test/bytecode/Matrix_lambdaTest2.java +++ b/test/bytecode/Matrix_lambdaTest2.java @@ -2,13 +2,20 @@ package bytecode; 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 = "Matrix2.class"; +public class Matrix_lambdaTest2 extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Matrix_lambda2"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file diff --git a/test/bytecode/Matrix_lambdaTest3.java b/test/bytecode/Matrix_lambdaTest3.java index a649ec93..6addc9fd 100644 --- a/test/bytecode/Matrix_lambdaTest3.java +++ b/test/bytecode/Matrix_lambdaTest3.java @@ -2,13 +2,20 @@ 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"; +public class Matrix_lambdaTest3 extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Matrix_lambda3"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file diff --git a/test/bytecode/MethodAndVariable.jav b/test/bytecode/MethodAndVariable.jav new file mode 100644 index 00000000..2ae7002e --- /dev/null +++ b/test/bytecode/MethodAndVariable.jav @@ -0,0 +1,18 @@ +class MethodAndVariable{ + public Integer method(Integer parameter){ + Integer lokaleVariable; + lokaleVariable = 2; + + Integer lokaleVariable2; + lokaleVariable2 = method2(lokaleVariable); + + return parameter+lokaleVariable2; + } + + public Integer method2(Integer parameter){ + Integer lokaleVariable; + lokaleVariable = 2; + + return parameter+lokaleVariable; + } +} \ No newline at end of file diff --git a/test/bytecode/MethodCallTest.java b/test/bytecode/MethodCallTest.java index 96d23eee..c5bfa352 100644 --- a/test/bytecode/MethodCallTest.java +++ b/test/bytecode/MethodCallTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class MethodCallTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "MethodCall.jav"; - public final static String outputFile = "MethodCall.class"; +public class MethodCallTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "MethodCall"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } } diff --git a/test/bytecode/MethodEmpty.java b/test/bytecode/MethodEmpty.java index 1f6af8be..ce72531b 100644 --- a/test/bytecode/MethodEmpty.java +++ b/test/bytecode/MethodEmpty.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class MethodEmpty { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "MethodEmpty.jav"; - public final static String outputFile = "MethodEmpty.class"; +public class MethodEmpty extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "MethodEmpty"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/MethodEmptyRetType.java b/test/bytecode/MethodEmptyRetType.java index 272e3998..82f8848b 100644 --- a/test/bytecode/MethodEmptyRetType.java +++ b/test/bytecode/MethodEmptyRetType.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class MethodEmptyRetType { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "MethodEmptyRetType.jav"; - public final static String outputFile = "MethodEmptyRetType.class"; +public class MethodEmptyRetType extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "MethodEmptyRetType"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/MethodsAndVariableTest.java b/test/bytecode/MethodsAndVariableTest.java new file mode 100644 index 00000000..8e0fd808 --- /dev/null +++ b/test/bytecode/MethodsAndVariableTest.java @@ -0,0 +1,26 @@ +package bytecode; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + + +public class MethodsAndVariableTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "MethodAndVariable"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} diff --git a/test/bytecode/MultiClass.jav b/test/bytecode/MultiClass.jav new file mode 100644 index 00000000..11114b32 --- /dev/null +++ b/test/bytecode/MultiClass.jav @@ -0,0 +1,5 @@ +class MultiClass{ +} + +class MultiClass2{ +} \ No newline at end of file diff --git a/test/bytecode/MultiClassTest.java b/test/bytecode/MultiClassTest.java new file mode 100644 index 00000000..54b51f47 --- /dev/null +++ b/test/bytecode/MultiClassTest.java @@ -0,0 +1,49 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.IOException; + +import junit.framework.TestCase; + +import org.junit.Test; + +import plugindevelopment.TypeInsertTester; +import de.dhbwstuttgart.core.MyCompiler; +import de.dhbwstuttgart.core.MyCompilerAPI; +import de.dhbwstuttgart.logger.LoggerConfiguration; +import de.dhbwstuttgart.logger.Section; +import de.dhbwstuttgart.parser.JavaParser.yyException; +import de.dhbwstuttgart.typeinference.ByteCodeResult; +import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; +import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; + +public class MultiClassTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "MultiClass"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void testConstruct2() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName+2); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} diff --git a/test/bytecode/NewStatementTest.java b/test/bytecode/NewStatementTest.java index 1272c626..6f930699 100644 --- a/test/bytecode/NewStatementTest.java +++ b/test/bytecode/NewStatementTest.java @@ -23,35 +23,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class NewStatementTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "NewStatement.jav"; - public final static String outputFile = "NewStatement.class"; +public class NewStatementTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "NewStatement"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory); - } - /* - @Test - public void testUntypedVectorDeclaredMethods() { - try{ - File file = new File(System.getProperty("user.dir")+"/test/bytecode/types/"); - URL url = file.toURL(); - URL[] urls = new URL[]{url}; + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); - ClassLoader classLoader = new URLClassLoader(urls); - - Class untypedVectorTest = classLoader.loadClass("UntypedVector"); - - for(Method method: untypedVectorTest.getDeclaredMethods()){ - System.out.println(method.toGenericString()); - } - }catch(Exception e){ - throw new RuntimeException(e); - } + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } - */ - } diff --git a/test/bytecode/ParameterTest.java b/test/bytecode/ParameterTest.java index cd06eeef..09993db3 100644 --- a/test/bytecode/ParameterTest.java +++ b/test/bytecode/ParameterTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class ParameterTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Parameter.jav"; - public final static String outputFile = "Parameter.class"; +public class ParameterTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Parameter"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/PostDecrement.java b/test/bytecode/PostDecrement.java index b0dbee20..6ab8bbf3 100644 --- a/test/bytecode/PostDecrement.java +++ b/test/bytecode/PostDecrement.java @@ -21,16 +21,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class PostDecrement { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "PostDecrement.jav"; - public final static String outputFile = "PostDecrement.class"; +public class PostDecrement extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "PostDecrement"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - @Ignore - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/PostIncrement.java b/test/bytecode/PostIncrement.java index da1fe1e3..83f189dc 100644 --- a/test/bytecode/PostIncrement.java +++ b/test/bytecode/PostIncrement.java @@ -21,16 +21,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class PostIncrement { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "PostIncrement.jav"; - public final static String outputFile = "PostIncrement.class"; +public class PostIncrement extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "PostIncrement"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - @Ignore - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/ReturnTest.java b/test/bytecode/ReturnTest.java index a7179e11..cad56bfa 100644 --- a/test/bytecode/ReturnTest.java +++ b/test/bytecode/ReturnTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class ReturnTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Return.jav"; - public final static String outputFile = "Return.class"; +public class ReturnTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Return"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/RunnableTest.java b/test/bytecode/RunnableTest.java index 2eb55d85..82b6abc8 100644 --- a/test/bytecode/RunnableTest.java +++ b/test/bytecode/RunnableTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class RunnableTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "Runnable.jav"; - public final static String outputFile = "Runnable.class"; +public class RunnableTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Runnable"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + 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 5c4eface..034a780c 100644 --- a/test/bytecode/SingleClassTester.java +++ b/test/bytecode/SingleClassTester.java @@ -38,20 +38,20 @@ public class SingleClassTester { Menge bytecode = compiler.generateBytecode(sourceFiles, results); //System.out.println(bytecode); - - - ByteCodeResult result = bytecode.firstElement(); - - 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")); + 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); + } - Logger.getLogger("SingleClassTester").error(result.getByteCode().getJavaClass().toString(), Section.CODEGEN); - + } catch (IOException | yyException e) { diff --git a/test/bytecode/StringLitTest.java b/test/bytecode/StringLitTest.java index d4d93f19..690968e4 100644 --- a/test/bytecode/StringLitTest.java +++ b/test/bytecode/StringLitTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class StringLitTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "StringLitTest.jav"; - public final static String outputFile = "StringLitTest.class"; +public class StringLitTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "StringLitTest"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/SystemOutPrintlnTest.java b/test/bytecode/SystemOutPrintlnTest.java index b5e2d577..39db74e3 100644 --- a/test/bytecode/SystemOutPrintlnTest.java +++ b/test/bytecode/SystemOutPrintlnTest.java @@ -20,15 +20,20 @@ import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; -public class SystemOutPrintlnTest { - - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "SystemOutPrintln.jav"; - public final static String outputFile = "SystemOutPrintln.class"; +public class SystemOutPrintlnTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "SystemOutPrintln"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory); - } + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); -} + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} \ No newline at end of file diff --git a/test/bytecode/Test3.java b/test/bytecode/Test3.java index 5c1fc6a3..6bc9a737 100644 --- a/test/bytecode/Test3.java +++ b/test/bytecode/Test3.java @@ -1,6 +1,6 @@ class Test3{ public static void main(String[] args){ -System.out.println(new LambdaExpr2().op.apply()); +System.out.println(new LambdaExpr2Test().op.apply()); } } diff --git a/test/bytecode/Variable.jav b/test/bytecode/Variable.jav new file mode 100644 index 00000000..ef9de331 --- /dev/null +++ b/test/bytecode/Variable.jav @@ -0,0 +1,8 @@ +class Variable{ + public Integer method(Integer parameter){ + Integer lokaleVariable; + lokaleVariable = 2; + + return parameter+lokaleVariable; + } +} \ No newline at end of file diff --git a/test/bytecode/VariableTest.java b/test/bytecode/VariableTest.java new file mode 100644 index 00000000..de387566 --- /dev/null +++ b/test/bytecode/VariableTest.java @@ -0,0 +1,35 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Test; + +import org.junit.Ignore; + +import bytecode.SourceFileBytecodeTest; + + +public class VariableTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Variable"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} diff --git a/test/bytecode/WhileTest.jav b/test/bytecode/WhileTest.jav index 7343a1b8..fa39c905 100644 --- a/test/bytecode/WhileTest.jav +++ b/test/bytecode/WhileTest.jav @@ -1,7 +1,9 @@ -class IfElse{ - method(){ - while(true){ - +class WhileTest{ + void method(){ + Integer i; + i = 1; + while(i < 10){ + i = i + 1; } } } \ No newline at end of file diff --git a/test/bytecode/WhileTest.java b/test/bytecode/WhileTest.java index cd7e4f8f..be51a813 100644 --- a/test/bytecode/WhileTest.java +++ b/test/bytecode/WhileTest.java @@ -2,13 +2,20 @@ package bytecode; import org.junit.Test; -public class WhileTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; - public final static String testFile = "WhileTest.jav"; - public final static String outputFile = "WhileTest.class"; +public class WhileTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "WhileTest"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } -} +} \ No newline at end of file diff --git a/test/bytecode/operators/AddDoubleOperator.jav b/test/bytecode/operators/AddDoubleOperator.jav new file mode 100644 index 00000000..2ed1848c --- /dev/null +++ b/test/bytecode/operators/AddDoubleOperator.jav @@ -0,0 +1,5 @@ +class AddDoubleOperator{ + Double method(Double x, Double y){ + return x + y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/AddDoubleOperatorTest.java b/test/bytecode/operators/AddDoubleOperatorTest.java new file mode 100644 index 00000000..5461b172 --- /dev/null +++ b/test/bytecode/operators/AddDoubleOperatorTest.java @@ -0,0 +1,53 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Ignore; +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class AddDoubleOperatorTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "AddDoubleOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void testTwoDoubles() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Double x = new Double(1); + Double y = new Double(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Double returnValue = (Double) method.invoke(obj, x, y); + assertEquals(new Double(3.0), returnValue); + } +} diff --git a/test/bytecode/operators/AddFloatOperator.jav b/test/bytecode/operators/AddFloatOperator.jav new file mode 100644 index 00000000..b7968498 --- /dev/null +++ b/test/bytecode/operators/AddFloatOperator.jav @@ -0,0 +1,5 @@ +class AddFloatOperator{ + Float method(Float x, Float y){ + return x + y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/AddFloatOperatorTest.java b/test/bytecode/operators/AddFloatOperatorTest.java new file mode 100644 index 00000000..205c4856 --- /dev/null +++ b/test/bytecode/operators/AddFloatOperatorTest.java @@ -0,0 +1,53 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Ignore; +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class AddFloatOperatorTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "AddFloatOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void testTwoFloats() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Float x = new Float(1.0); + Float y = new Float(2.0); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Float returnValue = (Float) method.invoke(obj, x, y); + assertEquals(new Float(3.0), returnValue); + } +} diff --git a/test/bytecode/operators/AddIntegerOperator.jav b/test/bytecode/operators/AddIntegerOperator.jav new file mode 100644 index 00000000..7a1ee0b3 --- /dev/null +++ b/test/bytecode/operators/AddIntegerOperator.jav @@ -0,0 +1,5 @@ +class AddIntegerOperator{ + Integer method(Integer x, Integer y){ + return x + y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/AddIntegerOperatorTest.java b/test/bytecode/operators/AddIntegerOperatorTest.java new file mode 100644 index 00000000..a012307d --- /dev/null +++ b/test/bytecode/operators/AddIntegerOperatorTest.java @@ -0,0 +1,53 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Ignore; +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class AddIntegerOperatorTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "AddIntegerOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void testTwoIntegers() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = new Integer(1); + Integer y = new Integer(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Integer returnValue = (Integer) method.invoke(obj, x, y); + assertEquals(new Integer(3), returnValue); + } +} diff --git a/test/bytecode/operators/AddLongOperator.jav b/test/bytecode/operators/AddLongOperator.jav new file mode 100644 index 00000000..86cba083 --- /dev/null +++ b/test/bytecode/operators/AddLongOperator.jav @@ -0,0 +1,5 @@ +class AddLongOperator{ + Long method(Long x, Long y){ + return x + y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/AddLongOperatorTest.java b/test/bytecode/operators/AddLongOperatorTest.java new file mode 100644 index 00000000..7dc791f3 --- /dev/null +++ b/test/bytecode/operators/AddLongOperatorTest.java @@ -0,0 +1,53 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Ignore; +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class AddLongOperatorTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "AddLongOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void testTwoLongs() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Long x = new Long(1); + Long y = new Long(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Long returnValue = (Long) method.invoke(obj, x, y); + assertEquals(new Long(3), returnValue); + } +} diff --git a/test/bytecode/operators/AddOperator.jav b/test/bytecode/operators/AddOperator.jav new file mode 100644 index 00000000..8eec40b3 --- /dev/null +++ b/test/bytecode/operators/AddOperator.jav @@ -0,0 +1,5 @@ +class AddOperator{ + method(x){ + return x + x; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/AddOperatorTest.java b/test/bytecode/operators/AddOperatorTest.java new file mode 100644 index 00000000..3f623038 --- /dev/null +++ b/test/bytecode/operators/AddOperatorTest.java @@ -0,0 +1,108 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Ignore; +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class AddOperatorTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "AddOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void testTwoIntegers() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = new Integer(1); + + Class[] params = new Class[]{ + x.getClass() + }; + + Method method = cls.getDeclaredMethod("method", params); + Integer returnValue = (Integer) method.invoke(obj, x); + assertEquals(new Integer(2), returnValue); + } + + @Test + public void testTwoDoubles() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Double x = new Double(1.0); + + Class[] params = new Class[]{ + x.getClass() + }; + + Method method = cls.getDeclaredMethod("method", params); + Double returnValue = (Double) method.invoke(obj, x); + assertEquals(new Double(2.0), returnValue); + } + + @Test + public void testTwoFloats() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Float x = new Float(1.0); + + Class[] params = new Class[]{ + x.getClass() + }; + + Method method = cls.getDeclaredMethod("method", params); + Float returnValue = (Float) method.invoke(obj, x); + assertEquals(new Float(2.0), returnValue); + } + + @Test + public void testTwoLongs() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Long x = new Long(1); + + Class[] params = new Class[]{ + x.getClass() + }; + + Method method = cls.getDeclaredMethod("method", params); + Long returnValue = (Long) method.invoke(obj, x); + assertEquals(new Long(3), returnValue); + } +} diff --git a/test/bytecode/operators/DivOperator.jav b/test/bytecode/operators/DivOperator.jav new file mode 100644 index 00000000..d23c04ba --- /dev/null +++ b/test/bytecode/operators/DivOperator.jav @@ -0,0 +1,5 @@ +class DivOperator{ + method(x, y){ + return x / y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/DivOperatorTest.java b/test/bytecode/operators/DivOperatorTest.java new file mode 100644 index 00000000..6b7db4e0 --- /dev/null +++ b/test/bytecode/operators/DivOperatorTest.java @@ -0,0 +1,53 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Ignore; +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class DivOperatorTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "DivOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void testTwoIntegers() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = new Integer(1); + Integer y = new Integer(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Integer returnValue = (Integer) method.invoke(obj, x, y); + assertEquals(new Integer(0), returnValue); + } +} diff --git a/test/bytecode/operators/EqualOperator.jav b/test/bytecode/operators/EqualOperator.jav new file mode 100644 index 00000000..a51b512a --- /dev/null +++ b/test/bytecode/operators/EqualOperator.jav @@ -0,0 +1,5 @@ +class EqualOperator{ + Boolean method(Integer x, Integer y){ + return x == y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/EqualOperatorTest.java b/test/bytecode/operators/EqualOperatorTest.java new file mode 100644 index 00000000..46720335 --- /dev/null +++ b/test/bytecode/operators/EqualOperatorTest.java @@ -0,0 +1,30 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import org.junit.Test; +import bytecode.SourceFileBytecodeTest; + +public class EqualOperatorTest extends RelOperatorTest{ + @Override + protected void init() { + testName = "EqualOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Override + protected Boolean getTest1x2ReturnValue() { + return new Boolean(false); + } + + @Override + protected Boolean getTest2x2ReturnValue() { + return new Boolean(true); + } + + @Override + protected Boolean getTest2x1ReturnValue() { + return new Boolean(false); + } +} diff --git a/test/bytecode/operators/GreaterEqualOperator.jav b/test/bytecode/operators/GreaterEqualOperator.jav new file mode 100644 index 00000000..798891f9 --- /dev/null +++ b/test/bytecode/operators/GreaterEqualOperator.jav @@ -0,0 +1,5 @@ +class GreaterEqualOperator{ + Boolean method(Integer x, Integer y){ + return x >= y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/GreaterEqualOperatorTest.java b/test/bytecode/operators/GreaterEqualOperatorTest.java new file mode 100644 index 00000000..41834e73 --- /dev/null +++ b/test/bytecode/operators/GreaterEqualOperatorTest.java @@ -0,0 +1,30 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import org.junit.Test; +import bytecode.SourceFileBytecodeTest; + +public class GreaterEqualOperatorTest extends RelOperatorTest{ + @Override + protected void init() { + testName = "GreaterEqualOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Override + protected Boolean getTest1x2ReturnValue() { + return new Boolean(false); + } + + @Override + protected Boolean getTest2x2ReturnValue() { + return new Boolean(true); + } + + @Override + protected Boolean getTest2x1ReturnValue() { + return new Boolean(true); + } +} diff --git a/test/bytecode/operators/GreaterOperator.jav b/test/bytecode/operators/GreaterOperator.jav new file mode 100644 index 00000000..f2c28682 --- /dev/null +++ b/test/bytecode/operators/GreaterOperator.jav @@ -0,0 +1,5 @@ +class GreaterOperator{ + Boolean method(Integer x, Integer y){ + return x > y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/GreaterOperatorTest.java b/test/bytecode/operators/GreaterOperatorTest.java new file mode 100644 index 00000000..7a562461 --- /dev/null +++ b/test/bytecode/operators/GreaterOperatorTest.java @@ -0,0 +1,30 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import org.junit.Test; +import bytecode.SourceFileBytecodeTest; + +public class GreaterOperatorTest extends RelOperatorTest{ + @Override + protected void init() { + testName = "GreaterOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Override + protected Boolean getTest1x2ReturnValue() { + return new Boolean(false); + } + + @Override + protected Boolean getTest2x2ReturnValue() { + return new Boolean(false); + } + + @Override + protected Boolean getTest2x1ReturnValue() { + return new Boolean(true); + } +} diff --git a/test/bytecode/operators/ModuloOperator.jav b/test/bytecode/operators/ModuloOperator.jav new file mode 100644 index 00000000..6a17f28e --- /dev/null +++ b/test/bytecode/operators/ModuloOperator.jav @@ -0,0 +1,5 @@ +class ModuloOperator{ + Integer method(Integer x, Integer y){ + return x % y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/ModuloOperatorTest.java b/test/bytecode/operators/ModuloOperatorTest.java new file mode 100644 index 00000000..5c0c600f --- /dev/null +++ b/test/bytecode/operators/ModuloOperatorTest.java @@ -0,0 +1,53 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Ignore; +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class ModuloOperatorTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "ModuloOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void testTwoIntegers() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = new Integer(1); + Integer y = new Integer(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Integer returnValue = (Integer) method.invoke(obj, x, y); + assertEquals(new Integer(1), returnValue); + } +} diff --git a/test/bytecode/operators/MulOperator.jav b/test/bytecode/operators/MulOperator.jav new file mode 100644 index 00000000..8efd6349 --- /dev/null +++ b/test/bytecode/operators/MulOperator.jav @@ -0,0 +1,5 @@ +class MulOperator{ + method(x, y){ + return x * y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/MulOperatorTest.java b/test/bytecode/operators/MulOperatorTest.java new file mode 100644 index 00000000..2c663021 --- /dev/null +++ b/test/bytecode/operators/MulOperatorTest.java @@ -0,0 +1,53 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Ignore; +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class MulOperatorTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "MulOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void testTwoIntegers() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = new Integer(1); + Integer y = new Integer(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Integer returnValue = (Integer) method.invoke(obj, x, y); + assertEquals(new Integer(2), returnValue); + } +} diff --git a/test/bytecode/operators/NotEqualOperator.jav b/test/bytecode/operators/NotEqualOperator.jav new file mode 100644 index 00000000..68c8a168 --- /dev/null +++ b/test/bytecode/operators/NotEqualOperator.jav @@ -0,0 +1,5 @@ +class NotEqualOperator{ + Boolean method(Integer x, Integer y){ + return x != y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/NotEqualOperatorTest.java b/test/bytecode/operators/NotEqualOperatorTest.java new file mode 100644 index 00000000..89b2d871 --- /dev/null +++ b/test/bytecode/operators/NotEqualOperatorTest.java @@ -0,0 +1,30 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import org.junit.Test; +import bytecode.SourceFileBytecodeTest; + +public class NotEqualOperatorTest extends RelOperatorTest{ + @Override + protected void init() { + testName = "NotEqualOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Override + protected Boolean getTest1x2ReturnValue() { + return new Boolean(true); + } + + @Override + protected Boolean getTest2x2ReturnValue() { + return new Boolean(false); + } + + @Override + protected Boolean getTest2x1ReturnValue() { + return new Boolean(true); + } +} diff --git a/test/bytecode/operators/OrOperator.jav b/test/bytecode/operators/OrOperator.jav new file mode 100644 index 00000000..c10a96e2 --- /dev/null +++ b/test/bytecode/operators/OrOperator.jav @@ -0,0 +1,5 @@ +class OrOperator{ + Boolean method(Boolean x, Boolean y){ + return x || y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/OrOperatorTest.java b/test/bytecode/operators/OrOperatorTest.java new file mode 100644 index 00000000..8d8faaa9 --- /dev/null +++ b/test/bytecode/operators/OrOperatorTest.java @@ -0,0 +1,32 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Ignore; +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class OrOperatorTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "OrOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } +} diff --git a/test/bytecode/operators/RelOperatorTest.java b/test/bytecode/operators/RelOperatorTest.java new file mode 100644 index 00000000..59f3ded7 --- /dev/null +++ b/test/bytecode/operators/RelOperatorTest.java @@ -0,0 +1,86 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import org.junit.Test; +import bytecode.SourceFileBytecodeTest; + +public abstract class RelOperatorTest extends SourceFileBytecodeTest{ + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void test1x2() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = new Integer(1); + Integer y = new Integer(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Boolean returnValue = (Boolean) method.invoke(obj, x, y); + assertEquals(getTest1x2ReturnValue(), returnValue); + } + + @Test + public void test2x2() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = new Integer(2); + Integer y = new Integer(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Boolean returnValue = (Boolean) method.invoke(obj, x, y); + assertEquals(getTest2x2ReturnValue(), returnValue); + } + + @Test + public void test2x1() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = new Integer(2); + Integer y = new Integer(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Boolean returnValue = (Boolean) method.invoke(obj, x, y); + assertEquals(getTest2x1ReturnValue(), returnValue); + } + + protected abstract Boolean getTest1x2ReturnValue(); + protected abstract Boolean getTest2x2ReturnValue(); + protected abstract Boolean getTest2x1ReturnValue(); +} diff --git a/test/bytecode/operators/SmallerEqualOperator.jav b/test/bytecode/operators/SmallerEqualOperator.jav new file mode 100644 index 00000000..b0448dba --- /dev/null +++ b/test/bytecode/operators/SmallerEqualOperator.jav @@ -0,0 +1,5 @@ +class SmallerEqualOperator{ + Boolean method(Integer x, Integer y){ + return x <= y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/SmallerEqualOperatorTest.java b/test/bytecode/operators/SmallerEqualOperatorTest.java new file mode 100644 index 00000000..d4da5f6f --- /dev/null +++ b/test/bytecode/operators/SmallerEqualOperatorTest.java @@ -0,0 +1,30 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import org.junit.Test; +import bytecode.SourceFileBytecodeTest; + +public class SmallerEqualOperatorTest extends RelOperatorTest{ + @Override + protected void init() { + testName = "SmallerEqual"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Override + protected Boolean getTest1x2ReturnValue() { + return new Boolean(true); + } + + @Override + protected Boolean getTest2x2ReturnValue() { + return new Boolean(true); + } + + @Override + protected Boolean getTest2x1ReturnValue() { + return new Boolean(false); + } +} diff --git a/test/bytecode/operators/SmallerOperator.jav b/test/bytecode/operators/SmallerOperator.jav new file mode 100644 index 00000000..5ddc8c91 --- /dev/null +++ b/test/bytecode/operators/SmallerOperator.jav @@ -0,0 +1,5 @@ +class SmallerOperator{ + Boolean method(Integer x, Integer y){ + return x < y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/SmallerOperatorTest.java b/test/bytecode/operators/SmallerOperatorTest.java new file mode 100644 index 00000000..2609b70f --- /dev/null +++ b/test/bytecode/operators/SmallerOperatorTest.java @@ -0,0 +1,30 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.lang.reflect.Method; +import org.junit.Test; +import bytecode.SourceFileBytecodeTest; + +public class SmallerOperatorTest extends RelOperatorTest{ + @Override + protected void init() { + testName = "Smaller"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Override + protected Boolean getTest1x2ReturnValue() { + return new Boolean(true); + } + + @Override + protected Boolean getTest2x2ReturnValue() { + return new Boolean(false); + } + + @Override + protected Boolean getTest2x1ReturnValue() { + return new Boolean(false); + } +} diff --git a/test/bytecode/operators/SubOperator.jav b/test/bytecode/operators/SubOperator.jav new file mode 100644 index 00000000..1c591522 --- /dev/null +++ b/test/bytecode/operators/SubOperator.jav @@ -0,0 +1,5 @@ +class SubOperator{ + Integer method(Integer x, Integer y){ + return x - y; + } +} \ No newline at end of file diff --git a/test/bytecode/operators/SubOperatorTest.java b/test/bytecode/operators/SubOperatorTest.java new file mode 100644 index 00000000..a9b3294f --- /dev/null +++ b/test/bytecode/operators/SubOperatorTest.java @@ -0,0 +1,53 @@ +package bytecode.operators; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Ignore; +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class SubOperatorTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "SubOperator"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/operators/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void testTwoIntegers() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Integer x = new Integer(1); + Integer y = new Integer(2); + + Class[] params = new Class[]{ + x.getClass(), + y.getClass(), + }; + + Method method = cls.getDeclaredMethod("method", params); + Integer returnValue = (Integer) method.invoke(obj, x, y); + assertEquals(new Integer(-1), returnValue); + } +} diff --git a/test/bytecode/stackmaptable/IfStatement.jav b/test/bytecode/stackmaptable/IfStatement.jav index ba78a2be..1451af17 100644 --- a/test/bytecode/stackmaptable/IfStatement.jav +++ b/test/bytecode/stackmaptable/IfStatement.jav @@ -1,10 +1,10 @@ class IfStatement{ -Integer methode(Boolean b){ - if(b){ - return 1; + Integer methode(Boolean b){ + if(b){ + return 1; }else{ - return 2; + return 2; } -} + } } \ No newline at end of file diff --git a/test/bytecode/stackmaptable/IfStatementTest.java b/test/bytecode/stackmaptable/IfStatementTest.java index 18a0a046..7c10e42b 100644 --- a/test/bytecode/stackmaptable/IfStatementTest.java +++ b/test/bytecode/stackmaptable/IfStatementTest.java @@ -3,14 +3,22 @@ package bytecode.stackmaptable; import org.junit.Test; import bytecode.SingleClassTester; +import bytecode.SourceFileBytecodeTest; -public class IfStatementTest { - public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/stackmaptable/"; - public final static String testFile = "IfStatement.jav"; - public final static String outputFile = "IfStatement.class"; +public class IfStatementTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "IfStatement"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/stackmaptable/"; + } @Test - public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory); + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); } } diff --git a/test/bytecode/types/OL.jav b/test/bytecode/types/OL.jav index 66e95aeb..c6349bdc 100644 --- a/test/bytecode/types/OL.jav +++ b/test/bytecode/types/OL.jav @@ -1,16 +1,6 @@ class OL { - Integer m(Integer x) { return x + x; } + m(x) { return x + x; } - Boolean m(Boolean x) {return x || x; } -} - -class Main { - - main(x) { - ol; - ol = new OL(); - return ol.m(x); - } - -} + Boolean m(Boolean x) {return x; } +} \ No newline at end of file diff --git a/test/bytecode/types/OLTest.java b/test/bytecode/types/OLTest.java index 4b369283..7f326304 100644 --- a/test/bytecode/types/OLTest.java +++ b/test/bytecode/types/OLTest.java @@ -33,13 +33,39 @@ public class OLTest extends SourceFileBytecodeTest{ URL url = file.toURL(); URL[] urls = new URL[]{url}; - Class stringVector = classLoader.loadClass("Integer"); + Integer integer = new Integer(1); Class[] params = new Class[1]; - params[0] = stringVector; + params[0] = integer.getClass(); Method method = cls.getDeclaredMethod("m", params); - method.invoke(obj, stringVector.newInstance()); + method.invoke(obj, integer); + assertTrue(true); + }catch(Exception e){ + throw new RuntimeException(e); + } + } + + @Test + public void testString() { + try{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + File file = new File(rootDirectory); + URL url = file.toURL(); + URL[] urls = new URL[]{url}; + + String string = "foo"; + + Class[] params = new Class[1]; + params[0] = string.getClass(); + + Method method = cls.getDeclaredMethod("m", params); + method.invoke(obj, string); assertTrue(true); }catch(Exception e){ throw new RuntimeException(e); @@ -59,13 +85,13 @@ public class OLTest extends SourceFileBytecodeTest{ URL url = file.toURL(); URL[] urls = new URL[]{url}; - Class stringVector = classLoader.loadClass("Boolean"); + Boolean bool = new Boolean(true); Class[] params = new Class[1]; - params[0] = stringVector; + params[0] = bool.getClass(); Method method = cls.getDeclaredMethod("m", params); - method.invoke(obj, stringVector.newInstance()); + method.invoke(obj, bool); assertTrue(true); }catch(Exception e){ throw new RuntimeException(e); diff --git a/test/bytecode/types/Overloading.jav b/test/bytecode/types/Overloading.jav index 0c0fdb2b..66a2ad81 100644 --- a/test/bytecode/types/Overloading.jav +++ b/test/bytecode/types/Overloading.jav @@ -10,8 +10,12 @@ class Overloading{ } - main(String[] args) { - new Overloading().method(new Vector ()); + main(String[] args) { + ol; + ol = new Overloading(); + v; + v = new Vector (); + ol.method(v); } } \ No newline at end of file diff --git a/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java b/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java index 4542f9f0..77e1c27b 100755 --- a/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java +++ b/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java @@ -69,11 +69,12 @@ public class MultipleTypesInsertTester extends TypeInsertTester{ } catch (IOException | yyException e) { e.printStackTrace(); TestCase.fail(); + }finally{ + writeLog(sourceFileToInfere+".log"); } for(String containString : mustContain){ TestCase.assertTrue("\""+containString+"\" muss in den inferierten Lösungen vorkommen",gesamterSrc.contains(containString)); } - writeLog(sourceFileToInfere+".log"); } public static void testSingleInsert(String sourceFileToInfere, Menge mustContain){ diff --git a/test/unify/UnifyTest.java b/test/unify/UnifyTest.java index d4f36b39..825fd40d 100644 --- a/test/unify/UnifyTest.java +++ b/test/unify/UnifyTest.java @@ -850,6 +850,38 @@ public class UnifyTest { //Assert.assertEquals(expected, actual); } + @Test + public void unifyTestVector(){ + /* + * Vector < T1 + * T1 < Vector + */ + TypeFactory tf = new TypeFactory(); + FiniteClosureBuilder fcb = new FiniteClosureBuilder(); + + UnifyType tphT1 = tf.getPlaceholderType("T1"); + UnifyType tphT2 = tf.getPlaceholderType("T2"); + + UnifyType gtv = tf.getSimpleType("gtv"); + UnifyType vector = tf.getSimpleType("Vector", gtv); + UnifyType vectorE = tf.getSimpleType("Vector", tphT2); + UnifyType string = tf.getSimpleType("String"); + UnifyType vectorString = tf.getSimpleType("Vector", string); + + fcb.add(vector, vector); + + IFiniteClosure fc = fcb.getFiniteClosure(); + + Set eq = new HashSet(); + eq.add(new UnifyPair(tphT1, vectorString, PairOperator.SMALLERDOT)); + eq.add(new UnifyPair(vectorE, tphT1, PairOperator.SMALLERDOT)); + + Set> actual = new TypeUnify().unifySequential(eq, fc); + + System.out.println("Test OverloadingVector:"); + System.out.println(actual); + } + @Test public void unifyTestOverloading(){ /*