From cef7c777b2bb4bcfaaa984414cd56e858de2ca86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=BCtterling=2C=20Franziska=20=28WWI2012D=29?= Date: Thu, 25 Jun 2015 15:49:22 +0200 Subject: [PATCH] GenCode: StringLit erfolgreich getestet - Strings werden in dynamisch in den Konstantenpool geschrieben und ausgelesen --- .../syntaxtree/statement/StringLiteral.java | 21 +++++++++++++++---- test/bytecode/StringLitTest.jav | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java index 6b270490..e398d088 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java @@ -4,11 +4,15 @@ import de.dhbwstuttgart.typeinference.Menge; + + // ino.end // ino.module.StringLiteral.8653.import import java.util.Hashtable; +import org.apache.bcel.classfile.ConstantPool; import org.apache.bcel.generic.ClassGen; +import org.apache.bcel.generic.ConstantPoolGen; import org.apache.bcel.generic.InstructionFactory; import org.apache.bcel.generic.InstructionList; import org.apache.bcel.generic.LDC; @@ -108,14 +112,23 @@ public class StringLiteral extends Literal return "\""+this.string+"\""; } - public static int counterString = 0; + + public String get_String() + // ino.end + // ino.method.get_Name.26246.body + { + return string; + } + //public static int counterString = 0; @Override public InstructionList genByteCode(ClassGen cg) { - InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool()); + ConstantPoolGen cp = cg.getConstantPool(); + InstructionFactory _factory = new InstructionFactory(cg, cp); InstructionList il = new InstructionList(); - counterString++; + //counterString++; //il.append(_factory.ASTORE_1, _factory.createNew(string)); - il.append(new LDC(counterString)); + cp.addString(get_String()); + il.append(new LDC(cp.getSize()-1)); return il; } diff --git a/test/bytecode/StringLitTest.jav b/test/bytecode/StringLitTest.jav index d86c0e37..a063d123 100644 --- a/test/bytecode/StringLitTest.jav +++ b/test/bytecode/StringLitTest.jav @@ -1,7 +1,7 @@ class StringLitTest{ -void method() { s; s = "abcdefg"; } +void method() { s; s = "abcdefg"; t; t ="jfowehfowh"; } } \ No newline at end of file