View | Details | Raw Unified | Return to bug 195317 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/ForStatementTest.java (+63 lines)
Lines 233-239 Link Here
233
		assertTrue(false);
233
		assertTrue(false);
234
	}
234
	}
235
}
235
}
236
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=180471 - variation
237
public void test005() { 
238
	this.runConformTest(
239
		new String[] {
240
			"X.java",
241
			"public class X {\n" + 
242
			"	public static void main(String[] args) {\n" + 
243
			"		int mode = 1;\n" + 
244
			"		loop: for (;;) {\n" + 
245
			"			switch (mode) {\n" + 
246
			"				case 2 :\n" + 
247
			"					return;\n" + 
248
			"				case 1:\n" + 
249
			"					mode = 2;\n" + 
250
			"					continue loop;\n" + 
251
			"			}\n" + 
252
			"		}\n" + 
253
			"	}\n" + 
254
			"}",
255
		},
256
		"");
236
257
258
	String expectedOutput =
259
		"  // Method descriptor #15 ([Ljava/lang/String;)V\n" + 
260
		"  // Stack: 1, Locals: 2\n" + 
261
		"  public static void main(java.lang.String[] args);\n" + 
262
		"     0  iconst_1\n" + 
263
		"     1  istore_1 [mode]\n" + 
264
		"     2  iload_1 [mode]\n" + 
265
		"     3  tableswitch default: 27\n" + 
266
		"          case 1: 25\n" + 
267
		"          case 2: 24\n" + 
268
		"    24  return\n" + 
269
		"    25  iconst_2\n" + 
270
		"    26  istore_1 [mode]\n" + 
271
		"    27  goto 2\n" + 
272
		"      Line numbers:\n" + 
273
		"        [pc: 0, line: 3]\n" + 
274
		"        [pc: 2, line: 5]\n" + 
275
		"        [pc: 24, line: 7]\n" + 
276
		"        [pc: 25, line: 9]\n" + 
277
		"        [pc: 27, line: 4]\n" + 
278
		"      Local variable table:\n" + 
279
		"        [pc: 0, pc: 30] local: args index: 0 type: java.lang.String[]\n" + 
280
		"        [pc: 2, pc: 30] local: mode index: 1 type: int\n";
281
	
282
	try {
283
		File f = new File(OUTPUT_DIR + File.separator + "X.class");
284
		byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
285
		ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
286
		String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
287
		int index = result.indexOf(expectedOutput);
288
		if (index == -1 || expectedOutput.length() == 0) {
289
			System.out.println(Util.displayString(result, 3));
290
		}
291
		if (index == -1) {
292
			assertEquals("Wrong contents", expectedOutput, result);
293
		}
294
	} catch (org.eclipse.jdt.core.util.ClassFormatException e) {
295
		assertTrue(false);
296
	} catch (IOException e) {
297
		assertTrue(false);
298
	}
299
}
237
public static Class testClass() {
300
public static Class testClass() {
238
	return ForStatementTest.class;
301
	return ForStatementTest.class;
239
}
302
}
(-)compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java (+10 lines)
Lines 5872-5877 Link Here
5872
		}
5872
		}
5873
	}
5873
	}
5874
}
5874
}
5875
/**
5876
 * Remove all entries in pcToSourceMap table that are beyond this.position
5877
 */
5878
public void removeUnusedPcToSourceMapEntries() {
5879
	if (this.pcToSourceMapSize != 0) {
5880
		while (pcToSourceMap[pcToSourceMapSize - 2] > this.position) {
5881
			this.pcToSourceMapSize -= 2;
5882
		}
5883
	}
5884
}
5875
public void removeVariable(LocalVariableBinding localBinding) {
5885
public void removeVariable(LocalVariableBinding localBinding) {
5876
	if (localBinding == null) return;
5886
	if (localBinding == null) return;
5877
	if (localBinding.initializationCount > 0) {
5887
	if (localBinding.initializationCount > 0) {
(-)compiler/org/eclipse/jdt/internal/compiler/codegen/BranchLabel.java (-8 / +4 lines)
Lines 205-218 Link Here
205
				this.codeStream.position = (this.position -= 3);
205
				this.codeStream.position = (this.position -= 3);
206
				this.codeStream.classFileOffset -= 3;
206
				this.codeStream.classFileOffset -= 3;
207
				this.forwardReferenceCount--;
207
				this.forwardReferenceCount--;
208
				// also update the PCs in the related debug attributes
209
				/* OLD CODE
210
					int index = codeStream.pcToSourceMapSize - 1;
211
						while ((index >= 0) && (codeStream.pcToSourceMap[index][1] == oldPosition)) {
212
							codeStream.pcToSourceMap[index--][1] = position;
213
						}
214
				*/
215
				// Beginning of new code
216
				if (this.codeStream.lastEntryPC == oldPosition) {
208
				if (this.codeStream.lastEntryPC == oldPosition) {
217
					this.codeStream.lastEntryPC = this.position;
209
					this.codeStream.lastEntryPC = this.position;
218
				}
210
				}
Lines 233-238 Link Here
233
						}
225
						}
234
					}
226
					}
235
				}
227
				}
228
				if ((this.codeStream.generateAttributes & ClassFileConstants.ATTR_LINES) != 0) {
229
					// we need to remove all entries that is beyond this.position inside the pcToSourcerMap table
230
					this.codeStream.removeUnusedPcToSourceMapEntries();
231
				}
236
			}
232
			}
237
		}
233
		}
238
		for (int i = 0; i < this.forwardReferenceCount; i++) {
234
		for (int i = 0; i < this.forwardReferenceCount; i++) {

Return to bug 195317