diff --git a/.classpath b/.classpath index 45b378eff..a88ba6e07 100755 --- a/.classpath +++ b/.classpath @@ -1,10 +1,11 @@ - - - - - - - - - - + + + + + + + + + + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 2e8ab188d..37e3515b8 100755 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,13 +1,13 @@ -eclipse.preferences.version=1 -instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.8 +eclipse.preferences.version=1 +instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/bin/log4j.xml b/bin/log4j.xml index 64e7c5dbd..f36fb342a 100755 --- a/bin/log4j.xml +++ b/bin/log4j.xml @@ -1,35 +1,35 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bin/log4jTesting.xml b/bin/log4jTesting.xml index dc30c2453..ef8492188 100755 --- a/bin/log4jTesting.xml +++ b/bin/log4jTesting.xml @@ -1,24 +1,24 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index 09d447975..5acd3c003 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -7,6 +7,14 @@ import java.util.Collection; import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; + +import org.apache.bcel.generic.ClassGen; +import org.apache.bcel.generic.ConstantPoolGen; +import org.apache.bcel.generic.InstructionFactory; +import org.apache.bcel.generic.InstructionHandle; +import org.apache.bcel.generic.InstructionList; +import org.apache.bcel.generic.MethodGen; + import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.logger.Logger; @@ -33,6 +41,11 @@ import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; import de.dhbwstuttgart.typeinference.unify.FC_TTO; import de.dhbwstuttgart.typeinference.unify.Unify; +import org.apache.bcel.generic.*; +import org.apache.bcel.classfile.*; +import org.apache.bcel.*; +import java.io.*; + // ino.class.Class.23010.declaration @@ -49,6 +62,42 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I protected UsedId pkgName; protected Modifiers modifiers; protected String name; + //For ByteCode Construction + private InstructionFactory _factory; + private ConstantPoolGen _cp; + private ClassGen _cg; + + //Method created with BCEL to generate ByteCode + public ByteCodeResult genByteCode() throws IOException { + + ByteCodeResult code = new ByteCodeResult(); + + _cg = new ClassGen(pkgName.get_Name() + "/" + name, superClass.get_Name(), name + ".java", Constants.ACC_PUBLIC , new String[] { }); //new String necessary? + _cp = _cg.getConstantPool(); + _factory = new InstructionFactory(_cg, _cp); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + + InstructionList il = new InstructionList(); + MethodGen method = new MethodGen(Constants.ACC_PUBLIC, org.apache.bcel.generic.Type.VOID, org.apache.bcel.generic.Type.NO_ARGS, new String[] { }, "", pkgName.get_Name() + "." + name, il, _cp); + + InstructionHandle ih_0 = il.append(_factory.createLoad(org.apache.bcel.generic.Type.OBJECT, 0)); //creates Constructor + il.append(_factory.createInvoke("java.lang.Object", "", org.apache.bcel.generic.Type.VOID, org.apache.bcel.generic.Type.NO_ARGS, Constants.INVOKESPECIAL)); + InstructionHandle ih_4 = il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID)); //creates Constructor + method.setMaxStack(); + method.setMaxLocals(); + _cg.addMethod(method.getMethod()); + il.dispose(); + _cg.getJavaClass().dump(out); + code.attach(out.toString()); + + return code; + + /*ByteCodeResult bc = new ByteCodeResult(); + _cg = new ClassGen(pkgName.get_Name() + "/" + name, superClass.get_Name(), name + ".java", Constants.ACC_PUBLIC , new String[] { }); + //_cg zurückgeben + bc.append(BCELByteCodeOutput); + return _cg;*/ + } private Menge superif = new Menge(); diff --git a/src/de/dhbwstuttgart/syntaxtree/ClassBody.java b/src/de/dhbwstuttgart/syntaxtree/ClassBody.java index cbac8f9f8..1c96052ff 100755 --- a/src/de/dhbwstuttgart/syntaxtree/ClassBody.java +++ b/src/de/dhbwstuttgart/syntaxtree/ClassBody.java @@ -345,8 +345,7 @@ public void istParameterOK( Menge Parameter, Menge KlassenVektor ) return ret.attach("}\n"); } - - + } diff --git a/src/de/dhbwstuttgart/typeinference/ByteCodeResult.java b/src/de/dhbwstuttgart/typeinference/ByteCodeResult.java new file mode 100644 index 000000000..e0f2b382f --- /dev/null +++ b/src/de/dhbwstuttgart/typeinference/ByteCodeResult.java @@ -0,0 +1,64 @@ +package de.dhbwstuttgart.typeinference; + +import de.dhbwstuttgart.typeinference.Menge; + +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; + +public class ByteCodeResult{ + + private String byteCode = ""; + //TODO: unresolvedTPHs entfernen. BROKEN! + private Menge unresolvedTPHs = new Menge(); + + public ByteCodeResult(){ + + } + + public ByteCodeResult(String byteCode){ + this.byteCode += byteCode; + } + + public String getByteCode(){ + return byteCode; + } + + public ByteCodeResult attach(ByteCodeResult byteCodeResult){ + this.byteCode += byteCodeResult.getByteCode(); + //Alle TPH anfügen: + for(TypePlaceholder tph : byteCodeResult.getUnresolvedTPH())this.addUnresolvedTPH(tph); + return this; + } + + public ByteCodeResult attach(String javaCode){ + this.byteCode += javaCode; + return this; + } + + public void addUnresolvedTPH(TypePlaceholder typePlaceholder) { + unresolvedTPHs.add(typePlaceholder); + } + + /** + * Liefert alle TPHs, welche in diesem ByteCodeResult nicht zu einem Typ aufgelöst wurden. + * Diese TPHs stehen dadurch im ByteCode als Variablennamen ohne zugeordnetem Typ. + * @return + */ + public Menge getUnresolvedTPH(){ + return unresolvedTPHs; + } + + @Override + public String toString(){ + return getByteCode(); + } + + @Override + public boolean equals(Object obj){ + if(!(obj instanceof ByteCodeResult))return false; + ByteCodeResult equals = (ByteCodeResult)obj; + if(!equals.getByteCode().equals(this.getByteCode()))return false; + if(!equals.getUnresolvedTPH().equals(this.getUnresolvedTPH()))return false; + return true; + } + +}