forked from JavaTX/JavaCompilerCore
Versuch bcel für StringLiteral
This commit is contained in:
parent
d96b36c5d1
commit
09a447cc48
@ -142,6 +142,7 @@ public class Return extends Statement
|
||||
il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID));
|
||||
|
||||
|
||||
|
||||
return il;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
// ino.end
|
||||
// ino.module.StringLiteral.8653.import
|
||||
import java.util.Hashtable;
|
||||
|
||||
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;
|
||||
@ -103,9 +106,14 @@ public class StringLiteral extends Literal
|
||||
}
|
||||
|
||||
@Override
|
||||
public void genByteCode(ClassGen _cg) {
|
||||
// TODO Auto-generated method stub
|
||||
public InstructionList genByteCode(ClassGen cg) {
|
||||
InstructionList il = new InstructionList();
|
||||
|
||||
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
|
||||
|
||||
il.append(_factory.ASTORE_1.createNew(this.getString()));
|
||||
|
||||
return il;
|
||||
}
|
||||
|
||||
}
|
||||
|
7
test/bytecode/StringLitTest.jav
Normal file
7
test/bytecode/StringLitTest.jav
Normal file
@ -0,0 +1,7 @@
|
||||
class StringLitTest{
|
||||
|
||||
|
||||
Object method() { s = ""; }
|
||||
|
||||
|
||||
}
|
45
test/bytecode/StringLitTest.java
Normal file
45
test/bytecode/StringLitTest.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 StringLitTest {
|
||||
|
||||
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
||||
public final static String testFile = "StringLitTest.jav";
|
||||
public final static String outputFile = "StringLitTest.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