Skip to content

Commit

Permalink
Enhanced Switches v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-sankaran committed Nov 23, 2024
1 parent 6b53bf4 commit 7bed7f4
Show file tree
Hide file tree
Showing 21 changed files with 869 additions and 1,015 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.internal.compiler.ast.*;
import org.eclipse.jdt.internal.compiler.ast.CaseStatement.ResolvedCase;
import org.eclipse.jdt.internal.compiler.ast.CaseStatement.LabelExpression;
import org.eclipse.jdt.internal.compiler.ast.SwitchStatement.SingletonBootstrap;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.codegen.*;
Expand Down Expand Up @@ -3613,8 +3613,8 @@ private int generateBootstrapMethods(List<Object> bootStrapMethodsList) {
}
} else if (o instanceof String) {
localContentsOffset = addBootStrapStringConcatEntry(localContentsOffset, (String) o, fPtr);
} else if (o instanceof ResolvedCase) {
localContentsOffset = addBootStrapTypeCaseConstantEntry(localContentsOffset, (ResolvedCase) o, fPtr);
} else if (o instanceof LabelExpression) {
localContentsOffset = addBootStrapTypeCaseConstantEntry(localContentsOffset, (LabelExpression) o, fPtr);
} else if (o instanceof TypeBinding) {
localContentsOffset = addClassDescBootstrap(localContentsOffset, (TypeBinding) o, fPtr);
} else if (o instanceof SingletonBootstrap sb) {
Expand Down Expand Up @@ -3807,7 +3807,7 @@ private int addBootStrapRecordEntry(int localContentsOffset, TypeDeclaration typ
}
return localContentsOffset;
}
private int addBootStrapTypeCaseConstantEntry(int localContentsOffset, ResolvedCase caseConstant, Map<String, Integer> fPtr) {
private int addBootStrapTypeCaseConstantEntry(int localContentsOffset, LabelExpression caseConstant, Map<String, Integer> fPtr) {
final int contentsEntries = 10;
if (contentsEntries + localContentsOffset >= this.contents.length) {
resizeContents(contentsEntries);
Expand Down Expand Up @@ -3852,7 +3852,8 @@ private int addBootStrapTypeCaseConstantEntry(int localContentsOffset, ResolvedC
this.contents[localContentsOffset++] = (byte) (idx >> 8);
this.contents[localContentsOffset++] = (byte) idx;

idx = this.constantPool.literalIndex(caseConstant.c.stringValue());
String enumerator = caseConstant.e instanceof QualifiedNameReference qnr ? new String(qnr.tokens[qnr.tokens.length - 1]) : caseConstant.e.toString();
idx = this.constantPool.literalIndex(enumerator);
this.contents[localContentsOffset++] = (byte) (idx >> 8);
this.contents[localContentsOffset++] = (byte) idx;

Expand Down Expand Up @@ -3930,7 +3931,7 @@ private int addSingletonBootstrap(int localContentsOffset, SingletonBootstrap sb
}

private int addBootStrapTypeSwitchEntry(int localContentsOffset, SwitchStatement switchStatement, Map<String, Integer> fPtr) {
CaseStatement.ResolvedCase[] constants = switchStatement.otherConstants;
CaseStatement.LabelExpression[] constants = switchStatement.labelExpressions;
int numArgs = constants.length;
final int contentsEntries = 10 + (numArgs * 2);
int indexFortypeSwitch = fPtr.get(ClassFile.TYPESWITCH_STRING);
Expand All @@ -3952,7 +3953,7 @@ private int addBootStrapTypeSwitchEntry(int localContentsOffset, SwitchStatement
this.contents[numArgsLocation++] = (byte) (numArgs >> 8);
this.contents[numArgsLocation] = (byte) numArgs;
localContentsOffset += 2;
for (CaseStatement.ResolvedCase c : constants) {
for (CaseStatement.LabelExpression c : constants) {
if (c.isPattern()) {
int typeOrDynIndex;
if (c.e.resolvedType.isPrimitiveType()) {
Expand Down Expand Up @@ -4019,25 +4020,23 @@ private int addBootStrapEnumSwitchEntry(int localContentsOffset, SwitchStatement

// u2 num_bootstrap_arguments
int numArgsLocation = localContentsOffset;
CaseStatement.ResolvedCase[] constants = switchStatement.otherConstants;
CaseStatement.LabelExpression[] constants = switchStatement.labelExpressions;
int numArgs = constants.length;
if (switchStatement.containsNull) --numArgs;
this.contents[numArgsLocation++] = (byte) (numArgs >> 8);
this.contents[numArgsLocation] = (byte) numArgs;
localContentsOffset += 2;

for (CaseStatement.ResolvedCase c : constants) {
for (CaseStatement.LabelExpression c : constants) {
if (c.isPattern()) {
char[] typeName = switchStatement.expression.resolvedType.constantPoolName();
int typeIndex = this.constantPool.literalIndexForType(typeName);
this.contents[localContentsOffset++] = (byte) (typeIndex >> 8);
this.contents[localContentsOffset++] = (byte) typeIndex;
} else {
if (c.e instanceof NullLiteral) continue;
String s = c.e instanceof QualifiedNameReference qnr ? // handle superfluously qualified enumerator.
new String(qnr.tokens[qnr.tokens.length-1]) : c.e.toString();
int intValIdx =
this.constantPool.literalIndex(s);
String enumerator = c.e instanceof QualifiedNameReference qnr ? new String(qnr.tokens[qnr.tokens.length - 1]) : c.e.toString();
int intValIdx = this.constantPool.literalIndex(enumerator);
this.contents[localContentsOffset++] = (byte) (intValIdx >> 8);
this.contents[localContentsOffset++] = (byte) intValIdx;
}
Expand Down Expand Up @@ -6370,7 +6369,7 @@ public int recordBootstrapMethod(SwitchStatement switchStatement) {
this.bootstrapMethods.add(switchStatement);
return this.bootstrapMethods.size() - 1;
}
public int recordBootstrapMethod(ResolvedCase resolvedCase) {
public int recordBootstrapMethod(LabelExpression resolvedCase) {
if (this.bootstrapMethods == null) {
this.bootstrapMethods = new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

public class BreakStatement extends BranchStatement {

public boolean isSynthetic;
public BreakStatement(char[] label, int sourceStart, int e) {
super(label, sourceStart, e);
}
Expand Down Expand Up @@ -115,10 +114,4 @@ public boolean doesNotCompleteNormally() {
public boolean canCompleteNormally() {
return false;
}


@Override
protected boolean doNotReportUnreachable() {
return this.isSynthetic;
}
}
Loading

0 comments on commit 7bed7f4

Please sign in to comment.