forked from JavaTX/JavaCompilerCore
main-Methode in .jav Files möglich
This commit is contained in:
parent
ca447fd44e
commit
36a3aeddb3
@ -34,8 +34,8 @@ public class ClassGenerator extends ClassGen{
|
|||||||
|
|
||||||
private Map<String, ClassGenerator> extraClasses = new HashMap<>();
|
private Map<String, ClassGenerator> extraClasses = new HashMap<>();
|
||||||
|
|
||||||
public ClassGenerator(String name, Type superClass, String string, short accPublic, String[] strings, TypeinferenceResultSet resultSet) {
|
public ClassGenerator(String name, Type superClass, String string, short accessflags, String[] strings, TypeinferenceResultSet resultSet) {
|
||||||
super(name,superClass.get_Name(),string,accPublic,strings, new DHBWConstantPoolGen());
|
super(name,superClass.get_Name(),string,accessflags,strings, new DHBWConstantPoolGen());
|
||||||
this.tiResult = resultSet;
|
this.tiResult = resultSet;
|
||||||
this.superClass = superClass;
|
this.superClass = superClass;
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@ import java.util.Enumeration;
|
|||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import javax.lang.model.element.Modifier;
|
||||||
|
|
||||||
import org.apache.commons.bcel6.generic.ClassGen;
|
import org.apache.commons.bcel6.generic.ClassGen;
|
||||||
import org.apache.commons.bcel6.generic.ConstantPoolGen;
|
import org.apache.commons.bcel6.generic.ConstantPoolGen;
|
||||||
import org.apache.commons.bcel6.generic.InstructionFactory;
|
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.DeclId;
|
||||||
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
|
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
|
||||||
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
|
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.modifier.Static;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Expr;
|
import de.dhbwstuttgart.syntaxtree.statement.Expr;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||||
@ -86,7 +89,8 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
|||||||
logger.debug("Test");
|
logger.debug("Test");
|
||||||
|
|
||||||
if(pkgName != null)throw new NotImplementedException();
|
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();
|
_cp = _cg.getConstantPool();
|
||||||
_factory = new DHBWInstructionFactory(_cg, _cp);
|
_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){
|
public Class(String name, RefType superClass, Modifiers mod, int offset){
|
||||||
this(name,mod,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;
|
else this.superClass = superClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ import de.dhbwstuttgart.myexception.SCStatementException;
|
|||||||
import de.dhbwstuttgart.parser.JavaClassName;
|
import de.dhbwstuttgart.parser.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
|
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
|
||||||
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
|
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.modifier.Static;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
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;
|
private int m_LineNumber = MyCompiler.NO_LINENUMBER;
|
||||||
// ino.end
|
// ino.end
|
||||||
private int m_Offset = -1; // hinzugef�gt hoth: 07.04.2006
|
private int m_Offset = -1; // hinzugef�gt hoth: 07.04.2006
|
||||||
|
private Modifiers modifiers;
|
||||||
// ino.attribute.inferencelog.23515.declaration
|
// ino.attribute.inferencelog.23515.declaration
|
||||||
protected static Logger inferencelog = Logger.getLogger("inference");
|
protected static Logger inferencelog = Logger.getLogger("inference");
|
||||||
// ino.end
|
// ino.end
|
||||||
@ -226,7 +228,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
|||||||
// ino.method.set_Modifiers.23545.body
|
// ino.method.set_Modifiers.23545.body
|
||||||
{
|
{
|
||||||
declid.firstElement().set_Modifiers(modif);
|
declid.firstElement().set_Modifiers(modif);
|
||||||
// this.modi = modif;
|
this.modifiers = modif;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ino.end
|
// 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:
|
//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:
|
//Methode generieren und anfügen:
|
||||||
cg.addMethod(method.createMethod(cg, getParameterList(), getType(), get_Block()));
|
cg.addMethod(method.createMethod(cg, getParameterList(), getType(), get_Block()));
|
||||||
|
@ -326,6 +326,7 @@ public class SourceFile
|
|||||||
for(ClassAssumption cAss : ass.getClassAssumptions()){
|
for(ClassAssumption cAss : ass.getClassAssumptions()){
|
||||||
Type t1 = cAss.getAssumedClass().getType();
|
Type t1 = cAss.getAssumedClass().getType();
|
||||||
Type t2 = cAss.getAssumedClass().getSuperClass();
|
Type t2 = cAss.getAssumedClass().getSuperClass();
|
||||||
|
if(t2 != null){
|
||||||
Pair p = new Pair(t1, t2);
|
Pair p = new Pair(t1, t2);
|
||||||
//System.out.println("FCPair: "+p);
|
//System.out.println("FCPair: "+p);
|
||||||
if(! t1.equals(t2)){//Um FC_TTO darf kein T <. T stehen.
|
if(! t1.equals(t2)){//Um FC_TTO darf kein T <. T stehen.
|
||||||
@ -337,6 +338,7 @@ public class SourceFile
|
|||||||
}else{
|
}else{
|
||||||
//System.out.println("Wurde nicht aufgenommen");
|
//System.out.println("Wurde nicht aufgenommen");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int i = 0; i < KlassenVektor.size(); i++ )
|
for( int i = 0; i < KlassenVektor.size(); i++ )
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
class Assign{
|
class Main{
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public class MainTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
|
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user