forked from JavaTX/JavaCompilerCore
Test für Bytecode anfügen. Beispielhaft generateBytecode-Methode in MyCompiler implementiert
This commit is contained in:
parent
8692a01c50
commit
6030682400
@ -36,6 +36,7 @@ import de.dhbwstuttgart.syntaxtree.type.ITypeContainer;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.ByteCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.FunNInterface;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
@ -852,5 +853,22 @@ public class MyCompiler implements MyCompilerAPI
|
||||
this.m_AbstractSyntaxTree.add(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteCodeResult generateBytecode() {
|
||||
/*
|
||||
* TODO Für das Bytecode-Team:
|
||||
* - generateBytecode-Methode implementieren
|
||||
* - Sich einen passenden Container für den Bytecode überlegen
|
||||
* - Dieser wird von generateBytecode zurückgeliefert und sollte die Möglichkeit zum schreiben von Bytecode in eine Datei bieten.
|
||||
* - wird der Rückgabetyp von generateBytecode in MyCompiler geändert, so muss auch der Rückgabetyp im Interface MyCompilerAPI geändert werden
|
||||
*/
|
||||
try {
|
||||
return this.m_AbstractSyntaxTree.firstElement().KlassenVektor.firstElement().genByteCode();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -6,12 +6,13 @@ package de.dhbwstuttgart.core;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.parser.JavaParser;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.typeinference.ByteCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.ParserError;
|
||||
@ -121,5 +122,6 @@ public interface MyCompilerAPI
|
||||
*/
|
||||
public SourceFile parse(String sourceCode) throws ParserError;
|
||||
|
||||
public ByteCodeResult generateBytecode();
|
||||
}
|
||||
// ino.end
|
||||
|
2
test/bytecode/EmptyClass.jav
Normal file
2
test/bytecode/EmptyClass.jav
Normal file
@ -0,0 +1,2 @@
|
||||
class EmptyClass{
|
||||
}
|
42
test/bytecode/EmptyClass.java
Normal file
42
test/bytecode/EmptyClass.java
Normal file
@ -0,0 +1,42 @@
|
||||
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.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 EmptyClass {
|
||||
|
||||
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
||||
public final static String testFile = "EmptyClass.jav";
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
LoggerConfiguration logConfig = new LoggerConfiguration();
|
||||
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
|
||||
try {
|
||||
compiler.parse(new File(rootDirectory + testFile));
|
||||
compiler.typeReconstruction();
|
||||
ByteCodeResult bytecode = compiler.generateBytecode();
|
||||
System.out.println(bytecode);
|
||||
} catch (IOException | yyException e) {
|
||||
e.printStackTrace();
|
||||
TestCase.fail();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user