Skip to content

Commit c2ce23c

Browse files
Enhanced Switches v2.0
1 parent 6b53bf4 commit c2ce23c

File tree

21 files changed

+952
-1079
lines changed

21 files changed

+952
-1079
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ClassFile.java

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import org.eclipse.jdt.core.compiler.CharOperation;
4949
import org.eclipse.jdt.core.compiler.IProblem;
5050
import org.eclipse.jdt.internal.compiler.ast.*;
51-
import org.eclipse.jdt.internal.compiler.ast.CaseStatement.ResolvedCase;
51+
import org.eclipse.jdt.internal.compiler.ast.CaseStatement.LabelExpression;
5252
import org.eclipse.jdt.internal.compiler.ast.SwitchStatement.SingletonBootstrap;
5353
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
5454
import org.eclipse.jdt.internal.compiler.codegen.*;
@@ -3613,8 +3613,8 @@ private int generateBootstrapMethods(List<Object> bootStrapMethodsList) {
36133613
}
36143614
} else if (o instanceof String) {
36153615
localContentsOffset = addBootStrapStringConcatEntry(localContentsOffset, (String) o, fPtr);
3616-
} else if (o instanceof ResolvedCase) {
3617-
localContentsOffset = addBootStrapTypeCaseConstantEntry(localContentsOffset, (ResolvedCase) o, fPtr);
3616+
} else if (o instanceof LabelExpression) {
3617+
localContentsOffset = addBootStrapTypeCaseConstantEntry(localContentsOffset, (LabelExpression) o, fPtr);
36183618
} else if (o instanceof TypeBinding) {
36193619
localContentsOffset = addClassDescBootstrap(localContentsOffset, (TypeBinding) o, fPtr);
36203620
} else if (o instanceof SingletonBootstrap sb) {
@@ -3807,7 +3807,7 @@ private int addBootStrapRecordEntry(int localContentsOffset, TypeDeclaration typ
38073807
}
38083808
return localContentsOffset;
38093809
}
3810-
private int addBootStrapTypeCaseConstantEntry(int localContentsOffset, ResolvedCase caseConstant, Map<String, Integer> fPtr) {
3810+
private int addBootStrapTypeCaseConstantEntry(int localContentsOffset, LabelExpression caseConstant, Map<String, Integer> fPtr) {
38113811
final int contentsEntries = 10;
38123812
if (contentsEntries + localContentsOffset >= this.contents.length) {
38133813
resizeContents(contentsEntries);
@@ -3852,7 +3852,8 @@ private int addBootStrapTypeCaseConstantEntry(int localContentsOffset, ResolvedC
38523852
this.contents[localContentsOffset++] = (byte) (idx >> 8);
38533853
this.contents[localContentsOffset++] = (byte) idx;
38543854

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

@@ -3930,7 +3931,7 @@ private int addSingletonBootstrap(int localContentsOffset, SingletonBootstrap sb
39303931
}
39313932

39323933
private int addBootStrapTypeSwitchEntry(int localContentsOffset, SwitchStatement switchStatement, Map<String, Integer> fPtr) {
3933-
CaseStatement.ResolvedCase[] constants = switchStatement.otherConstants;
3934+
CaseStatement.LabelExpression[] constants = switchStatement.labelExpressions;
39343935
int numArgs = constants.length;
39353936
final int contentsEntries = 10 + (numArgs * 2);
39363937
int indexFortypeSwitch = fPtr.get(ClassFile.TYPESWITCH_STRING);
@@ -3952,16 +3953,16 @@ private int addBootStrapTypeSwitchEntry(int localContentsOffset, SwitchStatement
39523953
this.contents[numArgsLocation++] = (byte) (numArgs >> 8);
39533954
this.contents[numArgsLocation] = (byte) numArgs;
39543955
localContentsOffset += 2;
3955-
for (CaseStatement.ResolvedCase c : constants) {
3956+
for (CaseStatement.LabelExpression c : constants) {
39563957
if (c.isPattern()) {
39573958
int typeOrDynIndex;
3958-
if (c.e.resolvedType.isPrimitiveType()) {
3959+
if (c.expression.resolvedType.isPrimitiveType()) {
39593960
// Dynamic for Class.getPrimitiveClass(Z) or such
39603961
typeOrDynIndex = this.constantPool.literalIndexForDynamic(c.primitivesBootstrapIdx,
3961-
c.t.signature(),
3962+
c.type.signature(),
39623963
ConstantPool.JavaLangClassSignature);
39633964
} else {
3964-
char[] typeName = c.t.constantPoolName();
3965+
char[] typeName = c.type.constantPoolName();
39653966
typeOrDynIndex = this.constantPool.literalIndexForType(typeName);
39663967
}
39673968
this.contents[localContentsOffset++] = (byte) (typeOrDynIndex >> 8);
@@ -3972,26 +3973,26 @@ private int addBootStrapTypeSwitchEntry(int localContentsOffset, SwitchStatement
39723973
ConstantPool.JAVA_LANG_ENUM_ENUMDESC);
39733974
this.contents[localContentsOffset++] = (byte) (typeIndex >> 8);
39743975
this.contents[localContentsOffset++] = (byte) typeIndex;
3975-
} else if ((c.e instanceof StringLiteral)||(c.c instanceof StringConstant)) {
3976+
} else if ((c.expression instanceof StringLiteral)||(c.constant instanceof StringConstant)) {
39763977
int intValIdx =
3977-
this.constantPool.literalIndex(c.c.stringValue());
3978+
this.constantPool.literalIndex(c.constant.stringValue());
39783979
this.contents[localContentsOffset++] = (byte) (intValIdx >> 8);
39793980
this.contents[localContentsOffset++] = (byte) intValIdx;
39803981
} else {
3981-
if (c.e instanceof NullLiteral) continue;
3982-
int valIdx = switch (c.t.id) {
3982+
if (c.expression instanceof NullLiteral) continue;
3983+
int valIdx = switch (c.type.id) {
39833984
case TypeIds.T_boolean -> // Dynamic for Boolean.getStaticFinal(TRUE|FALSE) :
39843985
this.constantPool.literalIndexForDynamic(c.primitivesBootstrapIdx,
3985-
c.c.booleanValue() ? BooleanConstant.TRUE_STRING : BooleanConstant.FALSE_STRING,
3986+
c.constant.booleanValue() ? BooleanConstant.TRUE_STRING : BooleanConstant.FALSE_STRING,
39863987
ConstantPool.JavaLangBooleanSignature);
39873988
case TypeIds.T_byte, TypeIds.T_char, TypeIds.T_short, TypeIds.T_int ->
39883989
this.constantPool.literalIndex(c.intValue());
39893990
case TypeIds.T_long ->
3990-
this.constantPool.literalIndex(c.c.longValue());
3991+
this.constantPool.literalIndex(c.constant.longValue());
39913992
case TypeIds.T_float ->
3992-
this.constantPool.literalIndex(c.c.floatValue());
3993+
this.constantPool.literalIndex(c.constant.floatValue());
39933994
case TypeIds.T_double ->
3994-
this.constantPool.literalIndex(c.c.doubleValue());
3995+
this.constantPool.literalIndex(c.constant.doubleValue());
39953996
default ->
39963997
throw new IllegalArgumentException("Switch has unexpected type: "+switchStatement); //$NON-NLS-1$
39973998
};
@@ -4019,25 +4020,23 @@ private int addBootStrapEnumSwitchEntry(int localContentsOffset, SwitchStatement
40194020

40204021
// u2 num_bootstrap_arguments
40214022
int numArgsLocation = localContentsOffset;
4022-
CaseStatement.ResolvedCase[] constants = switchStatement.otherConstants;
4023+
CaseStatement.LabelExpression[] constants = switchStatement.labelExpressions;
40234024
int numArgs = constants.length;
40244025
if (switchStatement.containsNull) --numArgs;
40254026
this.contents[numArgsLocation++] = (byte) (numArgs >> 8);
40264027
this.contents[numArgsLocation] = (byte) numArgs;
40274028
localContentsOffset += 2;
40284029

4029-
for (CaseStatement.ResolvedCase c : constants) {
4030+
for (CaseStatement.LabelExpression c : constants) {
40304031
if (c.isPattern()) {
40314032
char[] typeName = switchStatement.expression.resolvedType.constantPoolName();
40324033
int typeIndex = this.constantPool.literalIndexForType(typeName);
40334034
this.contents[localContentsOffset++] = (byte) (typeIndex >> 8);
40344035
this.contents[localContentsOffset++] = (byte) typeIndex;
40354036
} else {
4036-
if (c.e instanceof NullLiteral) continue;
4037-
String s = c.e instanceof QualifiedNameReference qnr ? // handle superfluously qualified enumerator.
4038-
new String(qnr.tokens[qnr.tokens.length-1]) : c.e.toString();
4039-
int intValIdx =
4040-
this.constantPool.literalIndex(s);
4037+
if (c.expression instanceof NullLiteral) continue;
4038+
String enumerator = c.expression instanceof QualifiedNameReference qnr ? new String(qnr.tokens[qnr.tokens.length - 1]) : c.expression.toString();
4039+
int intValIdx = this.constantPool.literalIndex(enumerator);
40414040
this.contents[localContentsOffset++] = (byte) (intValIdx >> 8);
40424041
this.contents[localContentsOffset++] = (byte) intValIdx;
40434042
}
@@ -6370,7 +6369,7 @@ public int recordBootstrapMethod(SwitchStatement switchStatement) {
63706369
this.bootstrapMethods.add(switchStatement);
63716370
return this.bootstrapMethods.size() - 1;
63726371
}
6373-
public int recordBootstrapMethod(ResolvedCase resolvedCase) {
6372+
public int recordBootstrapMethod(LabelExpression resolvedCase) {
63746373
if (this.bootstrapMethods == null) {
63756374
this.bootstrapMethods = new ArrayList<>();
63766375
}

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/BreakStatement.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
public class BreakStatement extends BranchStatement {
2525

26-
public boolean isSynthetic;
2726
public BreakStatement(char[] label, int sourceStart, int e) {
2827
super(label, sourceStart, e);
2928
}
@@ -115,10 +114,4 @@ public boolean doesNotCompleteNormally() {
115114
public boolean canCompleteNormally() {
116115
return false;
117116
}
118-
119-
120-
@Override
121-
protected boolean doNotReportUnreachable() {
122-
return this.isSynthetic;
123-
}
124117
}

0 commit comments

Comments
 (0)