From 36a3aeddb3829a1e17b5c0814a975f4e140c919d Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Fri, 23 Oct 2015 16:22:44 +0200 Subject: [PATCH] =?UTF-8?q?main-Methode=20in=20.jav=20Files=20m=C3=B6glich?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/de/dhbwstuttgart/bytecode/ClassGenerator.java | 4 ++-- src/de/dhbwstuttgart/syntaxtree/Class.java | 8 ++++++-- src/de/dhbwstuttgart/syntaxtree/Method.java | 8 ++++++-- src/de/dhbwstuttgart/syntaxtree/SourceFile.java | 2 ++ test/bytecode/Main.jav | 2 +- test/bytecode/MainTest.java | 2 +- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java index be42c2ba..f7f5e711 100644 --- a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java +++ b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java @@ -34,8 +34,8 @@ public class ClassGenerator extends ClassGen{ private Map extraClasses = new HashMap<>(); - public ClassGenerator(String name, Type superClass, String string, short accPublic, String[] strings, TypeinferenceResultSet resultSet) { - super(name,superClass.get_Name(),string,accPublic,strings, new DHBWConstantPoolGen()); + public ClassGenerator(String name, Type superClass, String string, short accessflags, String[] strings, TypeinferenceResultSet resultSet) { + super(name,superClass.get_Name(),string,accessflags,strings, new DHBWConstantPoolGen()); this.tiResult = resultSet; this.superClass = superClass; diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index 2ea33d0e..53adfd40 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -8,6 +8,8 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; +import javax.lang.model.element.Modifier; + import org.apache.commons.bcel6.generic.ClassGen; import org.apache.commons.bcel6.generic.ConstantPoolGen; import org.apache.commons.bcel6.generic.InstructionFactory; @@ -27,6 +29,7 @@ import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.misc.DeclId; import de.dhbwstuttgart.syntaxtree.misc.UsedId; import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; +import de.dhbwstuttgart.syntaxtree.modifier.Static; import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.statement.Expr; import de.dhbwstuttgart.syntaxtree.statement.Statement; @@ -86,7 +89,8 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I logger.debug("Test"); if(pkgName != null)throw new NotImplementedException(); - _cg = new ClassGenerator(name, this.getSuperClass(), name + ".java", Constants.ACC_PUBLIC , new String[] { }, resultSet); //letzter Parameter sind implementierte Interfaces + short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public + _cg = new ClassGenerator(name, this.getSuperClass(), name + ".java", constants , new String[] { }, resultSet); //letzter Parameter sind implementierte Interfaces _cp = _cg.getConstantPool(); _factory = new DHBWInstructionFactory(_cg, _cp); @@ -250,7 +254,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I public Class(String name, RefType superClass, Modifiers mod, int offset){ this(name,mod,offset); - if(superClass == null)this.superClass = new Class("Object",-1).getType(); + if(superClass == null)this.superClass = new Class("java.lang.Object",-1).getType(); else this.superClass = superClass; } diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index 3d4a60ce..e7aeb1ff 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -30,6 +30,7 @@ import de.dhbwstuttgart.myexception.SCStatementException; import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.misc.DeclId; import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; +import de.dhbwstuttgart.syntaxtree.modifier.Static; import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.statement.Return; import de.dhbwstuttgart.syntaxtree.statement.Statement; @@ -99,6 +100,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable 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 @@ -226,7 +228,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable // ino.method.set_Modifiers.23545.body { declid.firstElement().set_Modifiers(modif); - // this.modi = modif; + this.modifiers = modif; } // ino.end @@ -764,8 +766,10 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable } } + short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public + if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC; //Methode generieren: - MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp); + MethodGenerator method = new MethodGenerator(constants, this.getType().getBytecodeType(cg), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp); //Methode generieren und anfügen: cg.addMethod(method.createMethod(cg, getParameterList(), getType(), get_Block())); diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 56222f1a..b7185c82 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -326,6 +326,7 @@ public class SourceFile for(ClassAssumption cAss : ass.getClassAssumptions()){ Type t1 = cAss.getAssumedClass().getType(); Type t2 = cAss.getAssumedClass().getSuperClass(); + if(t2 != null){ Pair p = new Pair(t1, t2); //System.out.println("FCPair: "+p); if(! t1.equals(t2)){//Um FC_TTO darf kein T <. T stehen. @@ -337,6 +338,7 @@ public class SourceFile }else{ //System.out.println("Wurde nicht aufgenommen"); } + } } for( int i = 0; i < KlassenVektor.size(); i++ ) diff --git a/test/bytecode/Main.jav b/test/bytecode/Main.jav index 479d42e8..3e87c03e 100644 --- a/test/bytecode/Main.jav +++ b/test/bytecode/Main.jav @@ -1,4 +1,4 @@ -class Assign{ +class Main{ public static void main(String[] args){ } diff --git a/test/bytecode/MainTest.java b/test/bytecode/MainTest.java index 5a81f8d6..768c2fca 100644 --- a/test/bytecode/MainTest.java +++ b/test/bytecode/MainTest.java @@ -28,7 +28,7 @@ public class MainTest { @Test public void test() { - SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile); + SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory); } }