Skip to content

Commit

Permalink
fix nested patterns in boolean assignment
Browse files Browse the repository at this point in the history
Boolean assignments are working, but switch statements aren't.
Fully removes unused pattern variables from stack map frame.

Fixes eclipse-jdt#1804

Signed-off-by: David Thompson <[email protected]>
  • Loading branch information
datho7561 committed Jan 12, 2024
1 parent f700559 commit eb08ae8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ public void wrapupGeneration(CodeStream codeStream) {
this.primaryPattern.wrapupGeneration(codeStream);
}
@Override
public void fullWrapupGeneration(CodeStream codeStream) {
this.primaryPattern.fullWrapupGeneration(codeStream);
}
@Override
protected void generatePatternVariable(BlockScope currentScope, CodeStream codeStream, BranchLabel trueLabel,
BranchLabel falseLabel) {
this.primaryPattern.generatePatternVariable(currentScope, codeStream, trueLabel, falseLabel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,30 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean

int pc = codeStream.position;

if (this.elementVariable != null) {
if (this.elementVariable != null || this.pattern != null) {
addAssignment(currentScope, codeStream, this.secretInstanceOfPatternExpressionValue);
codeStream.load(this.secretInstanceOfPatternExpressionValue);
} else {
this.expression.generateCode(currentScope, codeStream, true);
}

codeStream.instance_of(this.type, this.type.resolvedType);
if (this.elementVariable != null) {
if (this.pattern != null) {
BranchLabel trueLabel = new BranchLabel(codeStream);
BranchLabel falseLabel = new BranchLabel(codeStream);
BranchLabel continueLabel = new BranchLabel(codeStream);
codeStream.ifeq(falseLabel);
codeStream.load(this.secretInstanceOfPatternExpressionValue);
this.pattern.generateOptimizedBoolean(currentScope, codeStream, trueLabel, falseLabel);
this.pattern.fullWrapupGeneration(codeStream);
codeStream.removeVariable(this.secretInstanceOfPatternExpressionValue);
trueLabel.place();
codeStream.iconst_1();
codeStream.goto_(continueLabel);
falseLabel.place();
codeStream.iconst_0();
continueLabel.place();
} else if (this.elementVariable != null) {
BranchLabel actionLabel = new BranchLabel(codeStream);
codeStream.dup();
codeStream.ifeq(actionLabel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public void resumeVariables(CodeStream codeStream, BlockScope scope) {
protected abstract void generatePatternVariable(BlockScope currentScope, CodeStream codeStream, BranchLabel trueLabel, BranchLabel falseLabel);
protected abstract void wrapupGeneration(CodeStream codeStream);

/**
* Clean up all variables (actual and secret) used in this pattern and child patterns.
*/
protected abstract void fullWrapupGeneration(CodeStream codeStream);

public TypeReference getType() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,13 @@ public void wrapupGeneration(CodeStream codeStream) {
super.wrapupGeneration(codeStream);
}
@Override
public void fullWrapupGeneration(CodeStream codeStream) {
for (Pattern p : this.patterns) {
p.fullWrapupGeneration(codeStream);
}
super.fullWrapupGeneration(codeStream);
}
@Override
public void suspendVariables(CodeStream codeStream, BlockScope scope) {
codeStream.removeNotDefinitelyAssignedVariables(scope, this.thenInitStateIndex1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ public void wrapupGeneration(CodeStream codeStream) {
codeStream.removeVariable(this.secretPatternVariable);
}
@Override
public void fullWrapupGeneration(CodeStream codeStream) {
this.wrapupGeneration(codeStream);
if (this.local != null) {
codeStream.removeVariable(this.local.binding);
}
}
@Override
public LocalDeclaration getPatternVariable() {
return this.local;
}
Expand Down
Binary file removed org.eclipse.jdt.core/jdtCompilerAdapter.jar
Binary file not shown.

0 comments on commit eb08ae8

Please sign in to comment.