forked from JavaTX/JavaCompilerCore
GenCode: PostIncrement umgesetzt, aufgrund von Problemen bei der
TypInferenz aber nicht testbar. Vermutlich muss der Counter/Index der Variablen noch weiter angepasst werden.
This commit is contained in:
parent
8bc2867eb7
commit
c7bed0fa0e
@ -172,15 +172,15 @@ public class Assign extends Expr
|
||||
|
||||
|
||||
|
||||
public static int counter = 0; //Zaehlvariable für ISTORE
|
||||
public static int counterAssign = 0; //Zaehlvariable für ISTORE
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGen cg) {
|
||||
// TODO Auto-generated method stub
|
||||
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
|
||||
InstructionList il = expr2.genByteCode(cg);//expr2 rechte expr
|
||||
counter++;
|
||||
il.append(new ISTORE(counter)); //macht ISTORE für meherere Variable nutzbar (nicht nur ISTORE_1, ISTORE_2, etc.)
|
||||
counterAssign++;
|
||||
il.append(new ISTORE(counterAssign)); //macht ISTORE für meherere Variable nutzbar (nicht nur ISTORE_1, ISTORE_2, etc.)
|
||||
//Anpassung für Variablen außerhalb von int = ISTORE nötig?
|
||||
return il;
|
||||
}
|
||||
|
@ -4,7 +4,10 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
// ino.module.IntLiteral.8635.import
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.apache.bcel.generic.BIPUSH;
|
||||
import org.apache.bcel.generic.ClassGen;
|
||||
import org.apache.bcel.generic.InstructionFactory;
|
||||
import org.apache.bcel.generic.InstructionList;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
@ -129,9 +132,11 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
}
|
||||
|
||||
@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(new BIPUSH(new Double(get_Double()).byteValue()));
|
||||
return il;
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -5,7 +5,11 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.bcel.generic.BIPUSH;
|
||||
import org.apache.bcel.generic.ClassGen;
|
||||
import org.apache.bcel.generic.IINC;
|
||||
import org.apache.bcel.generic.InstructionFactory;
|
||||
import org.apache.bcel.generic.InstructionList;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
@ -95,10 +99,17 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static int counterPostInc = 0;
|
||||
@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();
|
||||
counterPostInc++;
|
||||
il.append(new IINC(counterPostInc,1));
|
||||
//Tests aufgrund fehlener TypInferenz-Funktionalität nicht möglich
|
||||
//Vermutlich muss der Counter noch angepasst werden, da nicht incrementierende Variablen nicht mitgezählt werden, und zu falschen aufrufen führen
|
||||
//Gibt es einen Compiler-internen Variablenindex, der den Counter effektiver ersetzen könnte
|
||||
return il;
|
||||
}
|
||||
|
||||
}
|
||||
|
6
test/bytecode/PostIncrement.jav
Normal file
6
test/bytecode/PostIncrement.jav
Normal file
@ -0,0 +1,6 @@
|
||||
class PostIncrement{
|
||||
|
||||
void method() {a; a = 20; a++;}
|
||||
|
||||
|
||||
}
|
45
test/bytecode/PostIncrement.java
Normal file
45
test/bytecode/PostIncrement.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 PostIncrement {
|
||||
|
||||
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
||||
public final static String testFile = "PostIncrement.jav";
|
||||
public final static String outputFile = "PostIncrement.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