forked from JavaTX/JavaCompilerCore
Weitere Testfaelle
This commit is contained in:
parent
24671ceca4
commit
c7a77c0646
@ -1,35 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
|
||||
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
|
||||
|
||||
<appender name="CONSOLE" class="de.dhbwstuttgart.logger.ConsoleAppender">
|
||||
<param name="Target" value="System.out"/>
|
||||
|
||||
<layout class="de.dhbwstuttgart.logger.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-15C{1} %-5p [%-9c] %m%n"/>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<logger name="codegen">
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
<logger name="parser">
|
||||
<level value="OFF"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
<logger name="inference">
|
||||
<level value="WARN"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
|
||||
<logger name="bytecode">
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
</log4j:configuration>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
|
||||
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
|
||||
|
||||
<appender name="CONSOLE" class="de.dhbwstuttgart.logger.ConsoleAppender">
|
||||
<param name="Target" value="System.out"/>
|
||||
|
||||
<layout class="de.dhbwstuttgart.logger.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-15C{1} %-5p [%-9c] %m%n"/>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<logger name="codegen">
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
<logger name="parser">
|
||||
<level value="OFF"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
<logger name="inference">
|
||||
<level value="WARN"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
|
||||
<logger name="bytecode">
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
</log4j:configuration>
|
||||
|
@ -1,24 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
|
||||
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
|
||||
|
||||
<appender name="CONSOLE" class="de.dhbwstuttgart.logger.ConsoleAppender">
|
||||
<param name="Target" value="System.out"/>
|
||||
|
||||
<layout class="de.dhbwstuttgart.logger.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-15C{1} %-5p [%-9c] %m%n"/>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<logger name="trtest">
|
||||
<level value="DEBUG"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
<logger name="funcTest">
|
||||
<level value="DEBUG"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
</log4j:configuration>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
|
||||
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
|
||||
|
||||
<appender name="CONSOLE" class="de.dhbwstuttgart.logger.ConsoleAppender">
|
||||
<param name="Target" value="System.out"/>
|
||||
|
||||
<layout class="de.dhbwstuttgart.logger.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-15C{1} %-5p [%-9c] %m%n"/>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<logger name="trtest">
|
||||
<level value="DEBUG"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
<logger name="funcTest">
|
||||
<level value="DEBUG"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
</log4j:configuration>
|
||||
|
@ -65,8 +65,8 @@ public class Constructor extends Method {
|
||||
this.method = new MethodGen(Constants.ACC_PUBLIC, this.getType().getBytecodeType(), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp);
|
||||
|
||||
//Iteration <EFBFBD>ber Block starten
|
||||
Block instructions = this.get_Block();
|
||||
InstructionList blockInstructions = instructions.genByteCode(cg);
|
||||
Block block = this.get_Block();
|
||||
InstructionList blockInstructions = block.genByteCode(cg);
|
||||
|
||||
il.append(blockInstructions);//Die vom Block generierten Instructions an die InstructionList der Methode anfügen
|
||||
|
||||
|
@ -741,19 +741,27 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
|
||||
@Override
|
||||
public void genByteCode(ClassGen cg) {
|
||||
/*ConstantPoolGen _cp = cg.getConstantPool();
|
||||
* InstructionFactory _factory = new InstructionFactory(cg, _cp);
|
||||
* InstructionList il = new InstructionList();
|
||||
* Class parentClass = this.getParentClass();
|
||||
*/
|
||||
ConstantPoolGen _cp = cg.getConstantPool();
|
||||
InstructionFactory _factory = new InstructionFactory(cg, _cp);
|
||||
InstructionList il = new InstructionList();
|
||||
Class parentClass = this.getParentClass();
|
||||
|
||||
MethodGen method = new MethodGen(Constants.ACC_PUBLIC, this.getType().getBytecodeType(), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, this.get_Method_Name(), parentClass.name, il, _cp);
|
||||
|
||||
//oben steht MethodGen method als Variable (Z. 71)
|
||||
Block block = this.get_Block();
|
||||
InstructionList blockInstructions = block.genByteCode(cg);
|
||||
|
||||
// <EFBFBD>ber Statements iterieren um Block abzurufen
|
||||
for (Statement statements : block.get_Statement()) {
|
||||
statements.genByteCode(cg);
|
||||
il.append(blockInstructions);//Die vom Block generierten Instructions an die InstructionList der Methode anfügen
|
||||
|
||||
if (block.get_Statement().size() == 0) { il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID)); }
|
||||
else {
|
||||
if (!(block.get_Statement().lastElement() instanceof Return)) { il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID)); }
|
||||
}
|
||||
|
||||
method.setMaxStack(); //Die Stack Größe automatisch berechnen lassen (erst nach dem alle Instructions angehängt wurden)
|
||||
|
||||
cg.addMethod(method.getMethod());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
// ino.module.Return.8651.import
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.apache.bcel.generic.ConstantPoolGen;
|
||||
import org.apache.bcel.generic.InstructionFactory;
|
||||
import org.apache.bcel.generic.InstructionList;
|
||||
import org.apache.bcel.generic.ClassGen;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
@ -130,9 +133,13 @@ public class Return extends Statement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void genByteCode(ClassGen _cg) {
|
||||
// TODO Auto-generated method stub
|
||||
public InstructionList genByteCode(ClassGen cg) {
|
||||
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
|
||||
InstructionList il = new InstructionList();
|
||||
il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID));
|
||||
//TO BE DONE
|
||||
|
||||
return il;
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -810,6 +810,10 @@ public class RefType extends ObjectType implements IMatchable
|
||||
param.parserPostProcessing(this);
|
||||
}
|
||||
}
|
||||
|
||||
public org.apache.bcel.generic.Type getBytecodeType() {
|
||||
return new org.apache.bcel.generic.ObjectType(this.getTypeName());
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -1,7 +1,7 @@
|
||||
class EmptyClass{
|
||||
|
||||
public EmptyClass(){}
|
||||
|
||||
public void leckMichAmArsch(){}
|
||||
|
||||
|
||||
|
||||
}
|
7
test/bytecode/MethodEmpty.jav
Normal file
7
test/bytecode/MethodEmpty.jav
Normal file
@ -0,0 +1,7 @@
|
||||
class MethodEmpty{
|
||||
|
||||
|
||||
void method() { }
|
||||
|
||||
|
||||
}
|
45
test/bytecode/MethodEmpty.java
Normal file
45
test/bytecode/MethodEmpty.java
Normal file
@ -0,0 +1,45 @@
|
||||
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.logger.Section;
|
||||
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 MethodEmpty {
|
||||
|
||||
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
||||
public final static String testFile = "MethodEmpty.jav";
|
||||
public final static String outputFile = "MethodEmpty.class";
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
|
||||
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
|
||||
try {
|
||||
compiler.parse(new File(rootDirectory + testFile));
|
||||
compiler.typeReconstruction();
|
||||
ByteCodeResult bytecode = compiler.generateBytecode();
|
||||
System.out.println(bytecode);
|
||||
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
|
||||
} catch (IOException | yyException e) {
|
||||
e.printStackTrace();
|
||||
TestCase.fail();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
7
test/bytecode/MethodEmptyRetType.jav
Normal file
7
test/bytecode/MethodEmptyRetType.jav
Normal file
@ -0,0 +1,7 @@
|
||||
class MethodEmptyRetType{
|
||||
|
||||
|
||||
Object method() { return null; }
|
||||
|
||||
|
||||
}
|
45
test/bytecode/MethodEmptyRetType.java
Normal file
45
test/bytecode/MethodEmptyRetType.java
Normal file
@ -0,0 +1,45 @@
|
||||
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.logger.Section;
|
||||
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 MethodEmptyRetType {
|
||||
|
||||
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
||||
public final static String testFile = "MethodEmptyRetType.jav";
|
||||
public final static String outputFile = "MethodEmptyRetType.class";
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
|
||||
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
|
||||
try {
|
||||
compiler.parse(new File(rootDirectory + testFile));
|
||||
compiler.typeReconstruction();
|
||||
ByteCodeResult bytecode = compiler.generateBytecode();
|
||||
System.out.println(bytecode);
|
||||
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
|
||||
} catch (IOException | yyException e) {
|
||||
e.printStackTrace();
|
||||
TestCase.fail();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user