diff options
author | Philipe Mulet | 2006-06-20 13:26:16 +0000 |
---|---|---|
committer | Philipe Mulet | 2006-06-20 13:26:16 +0000 |
commit | 36ea8918dc55f4005af093c49c73e83fed79ee60 (patch) | |
tree | 9340260ec2757f6553068bbd12bb26327bac9abc | |
parent | a60e5bb086b568a51e1bde690fc1428b7f995ead (diff) | |
download | eclipse.jdt.core-36ea8918dc55f4005af093c49c73e83fed79ee60.tar.gz eclipse.jdt.core-36ea8918dc55f4005af093c49c73e83fed79ee60.tar.xz eclipse.jdt.core-36ea8918dc55f4005af093c49c73e83fed79ee60.zip |
147024
5 files changed, 328 insertions, 17 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BooleanTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BooleanTest.java index 509941c926..692aa94a3b 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BooleanTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BooleanTest.java @@ -1570,6 +1570,321 @@ public void test036() { assertTrue(false); } } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=147024 +public void test037() { + this.runConformTest( + new String[] { + "X.java", + " public class X {\n" + + " public static final boolean T = true;\n" + + " public static final boolean F = false;\n" + + " \n" + + " public boolean getFlagBT() {\n" + + " boolean b = this.T;\n" + + " if (this.T)\n" + + " return true;\n" + + " else\n" + + " return false;\n" + + " }\n" + + "\n" + + " public int getFlagIT() {\n" + + " boolean b = this.T;\n" + + " if (this.T)\n" + + " return 0;\n" + + " else\n" + + " return 1;\n" + + " }\n" + + "\n" + + " public boolean getFlagBF() {\n" + + " boolean b = this.F;\n" + + " if (this.F)\n" + + " return true;\n" + + " else\n" + + " return false;\n" + + " }\n" + + "\n" + + " public int getFlagIF() {\n" + + " boolean b = this.F;\n" + + " if (this.F)\n" + + " return 0;\n" + + " else\n" + + " return 1;\n" + + " }\n" + + " public boolean getFlagBT2() {\n" + + " boolean b = T;\n" + + " if (T)\n" + + " return true;\n" + + " else\n" + + " return false;\n" + + " }\n" + + "\n" + + " public int getFlagIT2() {\n" + + " boolean b = T;\n" + + " if (T)\n" + + " return 0;\n" + + " else\n" + + " return 1;\n" + + " }\n" + + "\n" + + " public boolean getFlagBF2() {\n" + + " boolean b = F;\n" + + " if (F)\n" + + " return true;\n" + + " else\n" + + " return false;\n" + + " }\n" + + "\n" + + " public int getFlagIF2() {\n" + + " boolean b = F;\n" + + " if (F)\n" + + " return 0;\n" + + " else\n" + + " return 1;\n" + + " }\n" + + " public boolean getFlagBT3() {\n" + + " X self = this;\n" + + " boolean b = self.T;\n" + + " if (self.T)\n" + + " return true;\n" + + " else\n" + + " return false;\n" + + " }\n" + + "\n" + + " public int getFlagIT3() {\n" + + " X self = this;\n" + + " boolean b = self.T;\n" + + " if (self.T)\n" + + " return 0;\n" + + " else\n" + + " return 1;\n" + + " }\n" + + "\n" + + " public boolean getFlagBF3() {\n" + + " X self = this;\n" + + " boolean b = self.F;\n" + + " if (self.F)\n" + + " return true;\n" + + " else\n" + + " return false;\n" + + " }\n" + + " public int getFlagIF3() {\n" + + " X self = this;\n" + + " boolean b = self.F;\n" + + " if (self.F)\n" + + " return 0;\n" + + " else\n" + + " return 1;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"It worked.\");\n" + + " }\n" + + "}", // ================= + }, + "It worked."); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #21 ()Z\n" + + " // Stack: 1, Locals: 2\n" + + " public boolean getFlagBT();\n" + + " 0 iconst_1\n" + + " 1 istore_1 [b]\n" + + " 2 iconst_1\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 2, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + + " \n" + + " // Method descriptor #24 ()I\n" + + " // Stack: 1, Locals: 2\n" + + " public int getFlagIT();\n" + + " 0 iconst_1\n" + + " 1 istore_1 [b]\n" + + " 2 iconst_0\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " [pc: 2, line: 16]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + + " \n" + + " // Method descriptor #21 ()Z\n" + + " // Stack: 1, Locals: 2\n" + + " public boolean getFlagBF();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 iconst_0\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 22]\n" + + " [pc: 2, line: 26]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + + " \n" + + " // Method descriptor #24 ()I\n" + + " // Stack: 1, Locals: 2\n" + + " public int getFlagIF();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 iconst_1\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 30]\n" + + " [pc: 2, line: 34]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + + " \n" + + " // Method descriptor #21 ()Z\n" + + " // Stack: 1, Locals: 2\n" + + " public boolean getFlagBT2();\n" + + " 0 iconst_1\n" + + " 1 istore_1 [b]\n" + + " 2 iconst_1\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 37]\n" + + " [pc: 2, line: 39]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + + " \n" + + " // Method descriptor #24 ()I\n" + + " // Stack: 1, Locals: 2\n" + + " public int getFlagIT2();\n" + + " 0 iconst_1\n" + + " 1 istore_1 [b]\n" + + " 2 iconst_0\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 45]\n" + + " [pc: 2, line: 47]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + + " \n" + + " // Method descriptor #21 ()Z\n" + + " // Stack: 1, Locals: 2\n" + + " public boolean getFlagBF2();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 iconst_0\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 53]\n" + + " [pc: 2, line: 57]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + + " \n" + + " // Method descriptor #24 ()I\n" + + " // Stack: 1, Locals: 2\n" + + " public int getFlagIF2();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 iconst_1\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 61]\n" + + " [pc: 2, line: 65]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + + " \n" + + " // Method descriptor #21 ()Z\n" + + " // Stack: 1, Locals: 3\n" + + " public boolean getFlagBT3();\n" + + " 0 aload_0 [this]\n" + + " 1 astore_1 [self]\n" + + " 2 iconst_1\n" + + " 3 istore_2 [b]\n" + + " 4 iconst_1\n" + + " 5 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 68]\n" + + " [pc: 2, line: 69]\n" + + " [pc: 4, line: 71]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 6] local: this index: 0 type: X\n" + + " [pc: 2, pc: 6] local: self index: 1 type: X\n" + + " [pc: 4, pc: 6] local: b index: 2 type: boolean\n" + + " \n" + + " // Method descriptor #24 ()I\n" + + " // Stack: 1, Locals: 3\n" + + " public int getFlagIT3();\n" + + " 0 aload_0 [this]\n" + + " 1 astore_1 [self]\n" + + " 2 iconst_1\n" + + " 3 istore_2 [b]\n" + + " 4 iconst_0\n" + + " 5 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 77]\n" + + " [pc: 2, line: 78]\n" + + " [pc: 4, line: 80]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 6] local: this index: 0 type: X\n" + + " [pc: 2, pc: 6] local: self index: 1 type: X\n" + + " [pc: 4, pc: 6] local: b index: 2 type: boolean\n" + + " \n" + + " // Method descriptor #21 ()Z\n" + + " // Stack: 1, Locals: 3\n" + + " public boolean getFlagBF3();\n" + + " 0 aload_0 [this]\n" + + " 1 astore_1 [self]\n" + + " 2 iconst_0\n" + + " 3 istore_2 [b]\n" + + " 4 iconst_0\n" + + " 5 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 86]\n" + + " [pc: 2, line: 87]\n" + + " [pc: 4, line: 91]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 6] local: this index: 0 type: X\n" + + " [pc: 2, pc: 6] local: self index: 1 type: X\n" + + " [pc: 4, pc: 6] local: b index: 2 type: boolean\n" + + " \n" + + " // Method descriptor #24 ()I\n" + + " // Stack: 1, Locals: 3\n" + + " public int getFlagIF3();\n" + + " 0 aload_0 [this]\n" + + " 1 astore_1 [self]\n" + + " 2 iconst_0\n" + + " 3 istore_2 [b]\n" + + " 4 iconst_1\n" + + " 5 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 94]\n" + + " [pc: 2, line: 95]\n" + + " [pc: 4, line: 99]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 6] local: this index: 0 type: X\n" + + " [pc: 2, pc: 6] local: self index: 1 type: X\n" + + " [pc: 4, pc: 6] local: b index: 2 type: boolean\n"; + + try { + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } catch (org.eclipse.jdt.core.util.ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } +} public static Class testClass() { return BooleanTest.class; diff --git a/org.eclipse.jdt.core/buildnotes_jdt-core.html b/org.eclipse.jdt.core/buildnotes_jdt-core.html index 72c3f9d51d..248006fed0 100644 --- a/org.eclipse.jdt.core/buildnotes_jdt-core.html +++ b/org.eclipse.jdt.core/buildnotes_jdt-core.html @@ -57,7 +57,9 @@ Eclipse SDK 3.2.1 - ?th September 2006 </ul> <h3>Problem Reports Fixed</h3> -<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=143684">143684</a> +<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=147024">147024</a> +[compiler] Compiler bug when accessing static final attribute in a non-static way +<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=143684">143684</a> Creating of static imports is unavailable.. <br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=147736">147736</a> ClassCastException in TypeHierarchy diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java index 426f136b81..1dd21be130 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java @@ -121,18 +121,12 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, codeStream.recordPositionsFrom(pc, this.sourceStart); return; } - Constant cst = condition.constant; - Constant condCst = condition.optimizedBooleanConstant(); - boolean needTruePart = - !(((cst != Constant.NotAConstant) && (cst.booleanValue() == false)) - || ((condCst != Constant.NotAConstant) && (condCst.booleanValue() == false))); - boolean needFalsePart = - !(((cst != Constant.NotAConstant) && (cst.booleanValue() == true)) - || ((condCst != Constant.NotAConstant) && (condCst.booleanValue() == true))); + Constant cst = condition.optimizedBooleanConstant(); + boolean needTruePart = !(cst != Constant.NotAConstant && cst.booleanValue() == false); + boolean needFalsePart = !(cst != Constant.NotAConstant && cst.booleanValue() == true); endifLabel = new BranchLabel(codeStream); // Generate code for the condition - boolean needConditionValue = (cst == Constant.NotAConstant) && (condCst == Constant.NotAConstant); falseLabel = new BranchLabel(codeStream); falseLabel.tagBits |= BranchLabel.USED; condition.generateOptimizedBoolean( @@ -140,7 +134,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, codeStream, null, falseLabel, - needConditionValue); + cst == Constant.NotAConstant); if (trueInitStateIndex != -1) { codeStream.removeNotDefinitelyAssignedVariables( diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java index b324874cef..f8c3c2912e 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java @@ -621,9 +621,11 @@ public boolean checkUnsafeCast(Scope scope, TypeBinding castType, TypeBinding ex // a label valued to nil means: by default we fall through the case... // both nil means we leave the value on the stack - if ((constant != Constant.NotAConstant) && (constant.typeID() == T_boolean)) { + Constant cst = this.optimizedBooleanConstant(); + generateCode(currentScope, codeStream, valueRequired && cst == Constant.NotAConstant); + if ((cst != Constant.NotAConstant) && (cst.typeID() == T_boolean)) { int pc = codeStream.position; - if (constant.booleanValue() == true) { + if (cst.booleanValue() == true) { // constant == true if (valueRequired) { if (falseLabel == null) { @@ -646,7 +648,6 @@ public boolean checkUnsafeCast(Scope scope, TypeBinding castType, TypeBinding ex codeStream.recordPositionsFrom(pc, this.sourceStart); return; } - generateCode(currentScope, codeStream, valueRequired); // branching int position = codeStream.position; if (valueRequired) { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java index 117fe2f14e..1f6f11f7a0 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java @@ -142,7 +142,6 @@ public class IfStatement extends Statement { !((cst != Constant.NotAConstant && cst.booleanValue() == true) || this.elseStatement == null || this.elseStatement.isEmptyBlock()); - if (hasThenPart) { BranchLabel falseLabel = null; // generate boolean condition @@ -151,7 +150,7 @@ public class IfStatement extends Statement { codeStream, null, hasElsePart ? (falseLabel = new BranchLabel(codeStream)) : endifLabel, - true); + true/*cst == Constant.NotAConstant*/); // May loose some local variable initializations : affecting the local variable attributes if (thenInitStateIndex != -1) { codeStream.removeNotDefinitelyAssignedVariables(currentScope, thenInitStateIndex); @@ -186,7 +185,7 @@ public class IfStatement extends Statement { codeStream, endifLabel, null, - true); + true/*cst == Constant.NotAConstant*/); // generate else statement // May loose some local variable initializations : affecting the local variable attributes if (elseInitStateIndex != -1) { |