diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/GuardedPattern.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/GuardedPattern.java index 6db84d30b35..921d5dc6851 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/GuardedPattern.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/GuardedPattern.java @@ -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); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java index 0cb159691b4..7f15fe694bc 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java @@ -117,7 +117,7 @@ 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 { @@ -125,7 +125,22 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean } 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); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Pattern.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Pattern.java index a64a3abcaa4..7ae8879d630 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Pattern.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Pattern.java @@ -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; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/RecordPattern.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/RecordPattern.java index e3eaefdb90e..6deedbae76f 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/RecordPattern.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/RecordPattern.java @@ -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); } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypePattern.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypePattern.java index bbf3f090b7a..61848aa97b5 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypePattern.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypePattern.java @@ -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; } diff --git a/org.eclipse.jdt.core/jdtCompilerAdapter.jar b/org.eclipse.jdt.core/jdtCompilerAdapter.jar deleted file mode 100644 index 8b78e733e31..00000000000 Binary files a/org.eclipse.jdt.core/jdtCompilerAdapter.jar and /dev/null differ