Skip to content

Commit 6ae52cf

Browse files
committed
GROOVY-9373
1 parent 7ad488e commit 6ae52cf

File tree

8 files changed

+59
-6
lines changed

8 files changed

+59
-6
lines changed

base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/AsmClassGenerator.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor)
469469
}
470470

471471
private void visitStdMethod(MethodNode node, boolean isConstructor, Parameter[] parameters, Statement code) {
472-
controller.getCompileStack().init(node.getVariableScope(), parameters);
472+
Label l0 = controller.getCompileStack().init(node.getVariableScope(), parameters);
473473
controller.getCallSiteWriter().makeSiteEntry();
474474

475475
MethodVisitor mv = controller.getMethodVisitor();
@@ -491,6 +491,15 @@ private void visitStdMethod(MethodNode node, boolean isConstructor, Parameter[]
491491
}
492492
}
493493
if (!hasCallToSuper) {
494+
// GRECLIPSE add -- GROOVY-9373
495+
if (code != null) {
496+
int line = code.getLineNumber();
497+
if (line > 0) {
498+
mv.visitLineNumber(line, l0);
499+
controller.setLineNumber(line);
500+
}
501+
}
502+
// GRECLIPSE end
494503
// add call to "super()"
495504
mv.visitVarInsn(ALOAD, 0);
496505
ClassNode superClass = controller.getClassNode().getSuperClass();
@@ -505,6 +514,12 @@ private void visitStdMethod(MethodNode node, boolean isConstructor, Parameter[]
505514
*/
506515
if (code != null) {
507516
code.visit(this);
517+
// GROOVY-7647, GROOVY-9373
518+
int line = code.getLastLineNumber();
519+
if (line > controller.getLineNumber()) {
520+
Label label = new Label(); mv.visitLabel(label);
521+
mv.visitLineNumber(line, label); controller.setLineNumber(line);
522+
}
508523
}
509524
// GRECLIPSE end
510525
if (node.isVoidMethod()) {

base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/ReturnAdder.java

+4
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,13 @@ private Statement addReturnsIfNeeded(Statement statement, VariableScope scope) {
120120
}
121121

122122
if (statement instanceof EmptyStatement) {
123+
/* GRECLIPSE edit -- GROOVY-9373
123124
final ReturnStatement returnStatement = new ReturnStatement(ConstantExpression.NULL);
124125
listener.returnStatementAdded(returnStatement);
125126
return returnStatement;
127+
*/
128+
return statement;
129+
// GRECLIPSE end
126130
}
127131

128132
if (statement instanceof ExpressionStatement) {

base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/asm/CompileStack.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,15 @@ public void addExceptionBlock(Label start, Label end, Label goal, String sig) {
419419
* can be accessed by calling getVariable().
420420
*
421421
*/
422-
public void init(VariableScope el, Parameter[] parameters) {
422+
public Label init(VariableScope el, Parameter[] parameters) {
423423
if (!clear) throw new GroovyBugError("CompileStack#init called without calling clear before");
424424
clear=false;
425425
pushVariableScope(el);
426426
defineMethodVariables(parameters,el.isInStaticContext());
427-
this.className = BytecodeHelper.getTypeDescription(controller.getClassNode());
427+
className = BytecodeHelper.getTypeDescription(controller.getClassNode());
428+
// GRECLIPSE add -- GROOVY-9373
429+
return thisStartLabel;
430+
// GRECLIPSE end
428431
}
429432

430433
/**

base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/asm/StatementWriter.java

+4
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ public void writeWhileLoop(WhileStatement loop) {
287287
}
288288

289289
public void writeDoWhileLoop(DoWhileStatement loop) {
290+
/* GRECLIPSE edit -- GROOVY-9373
290291
controller.getAcg().onLineNumber(loop, "visitDoWhileLoop");
292+
*/
291293
writeStatementLabel(loop);
292294

293295
MethodVisitor mv = controller.getMethodVisitor();
@@ -344,7 +346,9 @@ public void writeIfElse(IfStatement ifElse) {
344346
}
345347

346348
public void writeTryCatchFinally(TryCatchStatement statement) {
349+
/* GRECLIPSE edit -- GROOVY-9373
347350
controller.getAcg().onLineNumber(statement, "visitTryCatchFinally");
351+
*/
348352
writeStatementLabel(statement);
349353

350354
MethodVisitor mv = controller.getMethodVisitor();

base/org.codehaus.groovy30/src/org/codehaus/groovy/classgen/AsmClassGenerator.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ protected void visitConstructorOrMethod(final MethodNode node, final boolean isC
434434
}
435435

436436
private void visitStdMethod(final MethodNode node, final boolean isConstructor, final Parameter[] parameters, final Statement code) {
437-
controller.getCompileStack().init(node.getVariableScope(), parameters);
437+
Label l0 = controller.getCompileStack().init(node.getVariableScope(), parameters);
438438
controller.getCallSiteWriter().makeSiteEntry();
439439

440440
MethodVisitor mv = controller.getMethodVisitor();
@@ -450,6 +450,15 @@ private void visitStdMethod(final MethodNode node, final boolean isConstructor,
450450
}
451451
}
452452
if (!hasCallToSuper) {
453+
// GRECLIPSE add -- GROOVY-9373
454+
if (code != null) {
455+
int line = code.getLineNumber();
456+
if (line > 0) {
457+
mv.visitLineNumber(line, l0);
458+
controller.setLineNumber(line);
459+
}
460+
}
461+
// GRECLIPSE end
453462
// add call to "super()"
454463
mv.visitVarInsn(ALOAD, 0);
455464
mv.visitMethodInsn(INVOKESPECIAL, controller.getInternalBaseClassName(), "<init>", "()V", false);
@@ -467,6 +476,14 @@ private void visitStdMethod(final MethodNode node, final boolean isConstructor,
467476
code.visit(this);
468477
}
469478
if (!checkIfLastStatementIsReturnOrThrow(code)) {
479+
if (code != null) {
480+
// GROOVY-7647, GROOVY-9373
481+
int line = code.getLastLineNumber();
482+
if (line > controller.getLineNumber()) {
483+
Label label = new Label(); mv.visitLabel(label);
484+
mv.visitLineNumber(line, label); controller.setLineNumber(line);
485+
}
486+
}
470487
// GRECLIPSE end
471488
if (node.isVoidMethod()) {
472489
mv.visitInsn(RETURN);

base/org.codehaus.groovy30/src/org/codehaus/groovy/classgen/ReturnAdder.java

+3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ public void visitMethod(final MethodNode node) {
100100

101101
private Statement addReturnsIfNeeded(final Statement statement, final VariableScope scope) {
102102
if (statement instanceof ReturnStatement || statement instanceof ThrowStatement
103+
// GRECLIPSE add -- GROOVY-9373
104+
|| statement instanceof EmptyStatement
105+
// GRECLIPSE end
103106
|| statement instanceof BytecodeSequence) {
104107
return statement;
105108
}

base/org.codehaus.groovy30/src/org/codehaus/groovy/classgen/asm/CompileStack.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,15 @@ public void addExceptionBlock(final Label start, final Label end, final Label go
416416
* can be accessed by calling getVariable().
417417
*
418418
*/
419-
public void init(final VariableScope scope, final Parameter[] parameters) {
419+
public Label init(final VariableScope scope, final Parameter[] parameters) {
420420
if (!clear) throw new GroovyBugError("CompileStack#init called without calling clear before");
421421
clear = false;
422422
pushVariableScope(scope);
423423
defineMethodVariables(parameters, scope.isInStaticContext());
424-
this.className = BytecodeHelper.getTypeDescription(controller.getClassNode());
424+
className = BytecodeHelper.getTypeDescription(controller.getClassNode());
425+
// GRECLIPSE add -- GROOVY-9373
426+
return thisStartLabel;
427+
// GRECLIPSE end
425428
}
426429

427430
/**

base/org.codehaus.groovy30/src/org/codehaus/groovy/classgen/asm/StatementWriter.java

+4
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ public void writeWhileLoop(final WhileStatement statement) {
295295
}
296296

297297
public void writeDoWhileLoop(final DoWhileStatement statement) {
298+
/* GRECLIPSE edit -- GROOVY-9373
298299
controller.getAcg().onLineNumber(statement, "visitDoWhileLoop");
300+
*/
299301
writeStatementLabel(statement);
300302

301303
MethodVisitor mv = controller.getMethodVisitor();
@@ -337,7 +339,9 @@ public void writeIfElse(final IfStatement statement) {
337339
}
338340

339341
public void writeTryCatchFinally(final TryCatchStatement statement) {
342+
/* GRECLIPSE edit -- GROOVY-9373
340343
controller.getAcg().onLineNumber(statement, "visitTryCatchFinally");
344+
*/
341345
writeStatementLabel(statement);
342346

343347
MethodVisitor mv = controller.getMethodVisitor();

0 commit comments

Comments
 (0)