forked from JavaTX/JavaCompilerCore
Erster Bytecodegeneration-Test angefügt. codegen()-Methode angepasst
This commit is contained in:
parent
5d57179364
commit
931e90e7f2
@ -13,6 +13,7 @@ import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.Vector;
|
||||
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.myclass.Class;
|
||||
import mycompiler.myclass.ClassBody;
|
||||
import mycompiler.myclass.Constructor_Backup;
|
||||
@ -42,6 +43,7 @@ import org.apache.log4j.xml.DOMConfigurator;
|
||||
import com.sun.corba.se.spi.orbutil.fsm.Guard.Result;
|
||||
import com.sun.org.apache.xerces.internal.impl.xs.identity.Field;
|
||||
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.TypinferenzException;
|
||||
// ino.end
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
@ -534,30 +536,30 @@ public class MyCompiler implements MyCompilerAPI
|
||||
|
||||
|
||||
|
||||
// ino.method.codeGeneration.21310.defdescription type=javadoc
|
||||
/**
|
||||
* Author: J<EFBFBD>rg B<EFBFBD>uerle<br/>
|
||||
* Generiert den Bytecode und das Class-File f<EFBFBD>r den Syntaxbaum.
|
||||
* @throws NullPointerException Wenn noch kein abstrakter Syntaxbaum vorhanden
|
||||
* ist.
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.codeGeneration.21310.definition
|
||||
public void codeGeneration()
|
||||
@Override
|
||||
public Vector<ClassFile> codeGeneration(ResultSet result)
|
||||
throws NullPointerException, JVMCodeException
|
||||
// ino.end
|
||||
// ino.method.codeGeneration.21310.body
|
||||
{
|
||||
if(m_AbstractSyntaxTree==null){
|
||||
throw new NullPointerException("Es wurde noch kein Abstrakter Syntaxbaum erstellt!");
|
||||
}
|
||||
codegenlog.info("Beginn der Codegenerierung ...");
|
||||
|
||||
//m_AbstractSyntaxTree.codegen();
|
||||
Vector<ClassFile> ret = new Vector<ClassFile>();
|
||||
|
||||
for(SourceFile sf : m_AbstractSyntaxTree){
|
||||
ret.addAll(sf.codegen(result));
|
||||
}
|
||||
|
||||
codegenlog.info("Codegenerierung beendet!");
|
||||
return ret;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.main.21313.defdescription type=javadoc
|
||||
/**
|
||||
|
@ -7,6 +7,9 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Vector;
|
||||
|
||||
import typinferenz.ResultSet;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.myexception.CTypeReconstructionException;
|
||||
import mycompiler.myexception.JVMCodeException;
|
||||
import mycompiler.myparser.JavaParser;
|
||||
@ -94,7 +97,7 @@ public interface MyCompilerAPI
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.codeGeneration.21346.declaration
|
||||
public void codeGeneration()
|
||||
public Vector<ClassFile> codeGeneration(ResultSet result)
|
||||
throws NullPointerException, JVMCodeException;
|
||||
// ino.end
|
||||
|
||||
|
@ -3,11 +3,13 @@ package mycompiler;
|
||||
// ino.end
|
||||
|
||||
// ino.module.SourceFile.8722.import
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.myclass.BasicAssumptionClass;
|
||||
import mycompiler.myclass.Class;
|
||||
import mycompiler.myclass.ImportDeclarations;
|
||||
@ -216,11 +218,12 @@ public class SourceFile
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.codegen.21397.definition
|
||||
public void codegen()
|
||||
public Vector<ClassFile> codegen(ResultSet result)
|
||||
throws JVMCodeException
|
||||
// ino.end
|
||||
// ino.method.codegen.21397.body
|
||||
{
|
||||
Vector<ClassFile> ret = new Vector<ClassFile>();
|
||||
codegenlog.info("Anzahl der Interfaces: "
|
||||
+ Integer.toString(InterfaceVektor.size()));
|
||||
for(int i = 0; i < InterfaceVektor.size(); i++) {
|
||||
@ -230,8 +233,9 @@ public class SourceFile
|
||||
codegenlog.info("Anzahl der Klassen: "
|
||||
+ Integer.toString(KlassenVektor.size()));
|
||||
for(int i = 0; i < KlassenVektor.size(); i++) {
|
||||
KlassenVektor.elementAt(i).codegen(this);
|
||||
ret.add(KlassenVektor.elementAt(i).codegen(result));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@ -1539,5 +1543,6 @@ public class SourceFile
|
||||
//this.filename = filename;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -299,8 +299,14 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generiert die ClassFile für diese Klasse.
|
||||
* @param typeinferenceResult - Das ResultSet einer Typinferierung oder null, falls alle Typen eindeutig feststehen.
|
||||
* @return
|
||||
* @throws JVMCodeException
|
||||
*/
|
||||
// ino.method.codegen.23071.definition
|
||||
public void codegen(SourceFile sf)
|
||||
public ClassFile codegen(ResultSet typeinferenceResult)
|
||||
throws JVMCodeException
|
||||
// ino.end
|
||||
// ino.method.codegen.23071.body
|
||||
@ -316,12 +322,13 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface
|
||||
}
|
||||
|
||||
// Handling der Package
|
||||
String pkgName = "";
|
||||
if (sf.getPackageName() != null) {
|
||||
pkgName = sf.getPackageName().get_codegen_UsedId() + "/";
|
||||
}
|
||||
//String pkgName = "";
|
||||
//if (sf.getPackageName() != null) {
|
||||
// pkgName = sf.getPackageName().get_codegen_UsedId() + "/";
|
||||
//}
|
||||
|
||||
classfile.add_class(getName(), pkgName, superClass, getAccessFlags());
|
||||
//geändert von Andreas Stadelmeier: pkgName wird nicht mehr aus dem SourceFile ausgelesen:
|
||||
classfile.add_class(getName(), pkgName.get_Name_1Element(), superClass, getAccessFlags());
|
||||
|
||||
// Handling fuer Superinterfaces
|
||||
classfile.addSuperInterfaces(getSuperInterfaces());
|
||||
@ -340,9 +347,10 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface
|
||||
classfile.add_method("<init>", "()V", null, null, null, (short)0, this.paralist, false);
|
||||
}
|
||||
|
||||
classfile.codegen();
|
||||
//classfile.codegen();
|
||||
|
||||
codegenlog.info("Compilierung erfolgreich abgeschlossen, "+ getName() + ".class erstellt.");
|
||||
return classfile;
|
||||
}
|
||||
|
||||
public void codegen(ClassFile classfile, Vector paralist)
|
||||
|
@ -121,5 +121,13 @@ public class TypeinferenceResultSet
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Startet die Bytecodegenerierung dieser Lösung.
|
||||
* Dabei wird die codegen-Methode der inferierten Klasse mit diesem ResultSet aufgerufen.
|
||||
*/
|
||||
public void codegen(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
28
test/bytecode/EmptyClassTest.java
Normal file
28
test/bytecode/EmptyClassTest.java
Normal file
@ -0,0 +1,28 @@
|
||||
package bytecode;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import mycompiler.MyCompiler;
|
||||
import mycompiler.MyCompilerAPI;
|
||||
import mycompiler.myexception.JVMCodeException;
|
||||
import mycompiler.mytypereconstruction.TypeinferenceResultSet;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class EmptyClassTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
MyCompilerAPI compiler = MyCompiler.getAPI();
|
||||
compiler.parse("class EmptyClass{}");
|
||||
try {
|
||||
compiler.codeGeneration(null);
|
||||
} catch (NullPointerException | JVMCodeException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
assertTrue("Test erfolgreich",true);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user