forked from JavaTX/JavaCompilerCore
NewArray implementiert, scheitert daran, dass der Parser keine Array
Initialisierung annimmt.
This commit is contained in:
parent
03b0544131
commit
d2f50069d2
@ -5,6 +5,8 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
|||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
|
||||||
import org.apache.bcel.generic.ClassGen;
|
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.typeinference.Menge;
|
||||||
import de.dhbwstuttgart.logger.Logger;
|
import de.dhbwstuttgart.logger.Logger;
|
||||||
@ -144,9 +146,16 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void genByteCode(ClassGen _cg) {
|
public InstructionList genByteCode(ClassGen cg) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
|
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
|
||||||
|
InstructionList il = new InstructionList();
|
||||||
|
|
||||||
|
il.append(expr.elementAt(0).genByteCode(cg));
|
||||||
|
il.append(_factory.createNewArray(org.apache.bcel.generic.Type.getType(getTypeName()), (short)1));
|
||||||
|
|
||||||
|
|
||||||
|
return il;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
10
test/bytecode/NewArray.jav
Normal file
10
test/bytecode/NewArray.jav
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
class NewArray{
|
||||||
|
|
||||||
|
void method() {
|
||||||
|
zahl;
|
||||||
|
zahl = new Integer[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
45
test/bytecode/NewArrayTest.java
Normal file
45
test/bytecode/NewArrayTest.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 NewArrayTest {
|
||||||
|
|
||||||
|
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
||||||
|
public final static String testFile = "NewArray.jav";
|
||||||
|
public final static String outputFile = "NewArray.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