Skip to content

Commit

Permalink
* Withdraw the internal AST APIs Pattern.suspendVariables &
Browse files Browse the repository at this point in the history
Pattern.resumeVariables

* Fixes #2019
  • Loading branch information
srikanth-sankaran committed Mar 5, 2024
1 parent cee692e commit 787111c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,6 @@ public void traverse(ASTVisitor visitor, BlockScope scope) {
visitor.endVisit(this, scope);
}

@Override
public void suspendVariables(CodeStream codeStream, BlockScope scope) {
codeStream.removeNotDefinitelyAssignedVariables(scope, this.thenInitStateIndex1);
this.primaryPattern.suspendVariables(codeStream, scope);
}

@Override
public void resumeVariables(CodeStream codeStream, BlockScope scope) {
codeStream.addDefinitelyAssignedVariables(scope, this.thenInitStateIndex2);
this.primaryPattern.resumeVariables(codeStream, scope);
}

@Override
protected boolean isPatternTypeCompatible(TypeBinding other, BlockScope scope) {
return this.primaryPattern.isPatternTypeCompatible(other, scope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) {
this.thenTarget = new BranchLabel(codeStream);
}

public void suspendVariables(CodeStream codeStream, BlockScope scope) {
// nothing by default
}

public void resumeVariables(CodeStream codeStream, BlockScope scope) {
// nothing by default
}

public abstract void generateOptimizedBoolean(BlockScope currentScope, CodeStream codeStream, BranchLabel trueLabel, BranchLabel falseLabel);

public TypeReference getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,6 @@ original record instance as receiver - leaving the stack drained.
}
}

@Override
public void suspendVariables(CodeStream codeStream, BlockScope scope) {
codeStream.removeNotDefinitelyAssignedVariables(scope, this.thenInitStateIndex1);
}

@Override
public void resumeVariables(CodeStream codeStream, BlockScope scope) {
codeStream.addDefinitelyAssignedVariables(scope, this.thenInitStateIndex2);
}

@Override
public void traverse(ASTVisitor visitor, BlockScope scope) {
if (visitor.visit(this, scope)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Set;
import java.util.function.Function;
import java.util.function.IntPredicate;
import java.util.stream.Stream;

import org.eclipse.jdt.internal.compiler.ASTVisitor;
import org.eclipse.jdt.internal.compiler.ast.CaseStatement.ResolvedCase;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
Expand Down Expand Up @@ -985,15 +987,16 @@ private void generateCodePatternCaseEpilogue(CodeStream codeStream, int caseInde
) {
Pattern pattern = (Pattern) caseStatement.constantExpressions[caseStatement.patternIndex];
pattern.elseTarget.place();
pattern.suspendVariables(codeStream, this.scope);
caseIndex = this.nullProcessed ? caseIndex - 1 : caseIndex;
if (!pattern.isAlwaysTrue()) {
codeStream.loadInt(caseIndex);
// at the trampoline here, pattern bindings are not definitely assigned.
final LocalVariableBinding[] bindingsWhenTrue = pattern.bindingsWhenTrue();
Stream.of(bindingsWhenTrue).forEach(v->v.recordInitializationEndPC(codeStream.position));
codeStream.loadInt(this.nullProcessed ? caseIndex - 1 : caseIndex);
codeStream.store(this.restartIndexLocal, false);
codeStream.goto_(this.switchPatternRestartTarget);
Stream.of(bindingsWhenTrue).forEach(v->v.recordInitializationStartPC(codeStream.position));
}
pattern.thenTarget.place();
pattern.resumeVariables(codeStream, this.scope);
} else if (this.containsNull && caseStatement != null) {
this.nullProcessed |= caseStatement.patternIndex == -1;
}
Expand Down

0 comments on commit 787111c

Please sign in to comment.