Skip to content

Commit 17086d3

Browse files
committed
8375646: Some parser flags seem unused
Reviewed-by: jlahoda, vromero
1 parent 3033e6f commit 17086d3

File tree

1 file changed

+50
-62
lines changed

1 file changed

+50
-62
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java

Lines changed: 50 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,11 @@ protected DocCommentTable newDocCommentTable(boolean keepDocComments, ParserFact
271271
/** When terms are parsed, the mode determines which is expected:
272272
* mode = EXPR : an expression
273273
* mode = TYPE : a type
274-
* mode = NOPARAMS : no parameters allowed for type
275-
* mode = TYPEARG : type argument
276-
* mode |= NOLAMBDA : lambdas are not allowed
274+
* mode = NOLAMBDA : lambdas are not allowed
277275
*/
278276
protected static final int EXPR = 1 << 0;
279277
protected static final int TYPE = 1 << 1;
280-
protected static final int NOPARAMS = 1 << 2;
281-
protected static final int TYPEARG = 1 << 3;
282-
protected static final int DIAMOND = 1 << 4;
283-
protected static final int NOLAMBDA = 1 << 5;
278+
protected static final int NOLAMBDA = 1 << 2;
284279

285280
protected void setMode(int mode) {
286281
this.mode = mode;
@@ -1439,12 +1434,6 @@ protected JCExpression term3() {
14391434
int startMode = mode;
14401435
List<JCExpression> typeArgs = typeArgumentsOpt(EXPR);
14411436
switch (token.kind) {
1442-
case QUES:
1443-
if (isMode(TYPE) && isMode(TYPEARG) && !isMode(NOPARAMS)) {
1444-
selectTypeMode();
1445-
return typeArgument();
1446-
} else
1447-
return illegal();
14481437
case PLUSPLUS: case SUBSUB: case BANG: case TILDE: case PLUS: case SUB:
14491438
if (typeArgs == null && isMode(EXPR)) {
14501439
TokenKind tk = token.kind;
@@ -1522,7 +1511,7 @@ protected JCExpression term3() {
15221511
if (isMode(EXPR)) {
15231512
selectExprMode();
15241513
nextToken();
1525-
if (token.kind == LT) typeArgs = typeArguments(false);
1514+
if (token.kind == LT) typeArgs = typeArguments();
15261515
t = creator(pos, typeArgs);
15271516
typeArgs = null;
15281517
} else return illegal();
@@ -1625,7 +1614,6 @@ protected JCExpression term3() {
16251614
return illegal();
16261615
}
16271616
int prevmode = mode;
1628-
setMode(mode & ~NOPARAMS);
16291617
typeArgs = typeArgumentsOpt(EXPR);
16301618
setMode(prevmode);
16311619
if (isMode(EXPR)) {
@@ -1653,7 +1641,7 @@ protected JCExpression term3() {
16531641
selectExprMode();
16541642
int pos1 = token.pos;
16551643
nextToken();
1656-
if (token.kind == LT) typeArgs = typeArguments(false);
1644+
if (token.kind == LT) typeArgs = typeArguments();
16571645
t = innerCreator(pos1, typeArgs, t);
16581646
typeArgs = null;
16591647
break loop;
@@ -1704,7 +1692,7 @@ protected JCExpression term3() {
17041692
nextToken();
17051693
selectTypeMode();
17061694
t = toP(F.at(token.pos).Select(t, ident()));
1707-
t = typeArgumentsOpt(t);
1695+
t = typeApplyOpt(t);
17081696
}
17091697
t = bracketsOpt(t);
17101698
if (token.kind != COLCOL) {
@@ -1721,7 +1709,7 @@ protected JCExpression term3() {
17211709
}
17221710
}
17231711
if (typeArgs != null) illegal();
1724-
t = typeArgumentsOpt(t);
1712+
t = typeApplyOpt(t);
17251713
break;
17261714
case BYTE: case SHORT: case CHAR: case INT: case LONG: case FLOAT:
17271715
case DOUBLE: case BOOLEAN:
@@ -1880,7 +1868,7 @@ JCExpression term3Rest(JCExpression t, List<JCExpression> typeArgs) {
18801868
selectExprMode();
18811869
int pos2 = token.pos;
18821870
nextToken();
1883-
if (token.kind == LT) typeArgs = typeArguments(false);
1871+
if (token.kind == LT) typeArgs = typeArguments();
18841872
t = innerCreator(pos2, typeArgs, t);
18851873
typeArgs = null;
18861874
} else {
@@ -1900,7 +1888,7 @@ JCExpression term3Rest(JCExpression t, List<JCExpression> typeArgs) {
19001888
if (tyannos != null && tyannos.nonEmpty()) {
19011889
t = toP(F.at(tyannos.head.pos).AnnotatedType(tyannos, t));
19021890
}
1903-
t = argumentsOpt(typeArgs, typeArgumentsOpt(t));
1891+
t = argumentsOpt(typeArgs, typeApplyOpt(t));
19041892
typeArgs = null;
19051893
}
19061894
} else if (isMode(EXPR) && token.kind == COLCOL) {
@@ -2302,7 +2290,7 @@ JCExpression superSuffix(List<JCExpression> typeArgs, JCExpression t) {
23022290
} else {
23032291
int pos = token.pos;
23042292
accept(DOT);
2305-
typeArgs = (token.kind == LT) ? typeArguments(false) : null;
2293+
typeArgs = (token.kind == LT) ? typeArguments() : null;
23062294
t = toP(F.at(pos).Select(t, ident()));
23072295
t = argumentsOpt(typeArgs, t);
23082296
}
@@ -2373,12 +2361,11 @@ boolean isInvalidUnqualifiedMethodIdentifier(int pos, Name name) {
23732361

23742362
/** TypeArgumentsOpt = [ TypeArguments ]
23752363
*/
2376-
JCExpression typeArgumentsOpt(JCExpression t) {
2364+
JCExpression typeApplyOpt(JCExpression t) {
23772365
if (token.kind == LT &&
2378-
isMode(TYPE) &&
2379-
!isMode(NOPARAMS)) {
2366+
isMode(TYPE)) {
23802367
selectTypeMode();
2381-
return typeArguments(t, false);
2368+
return typeApply(t);
23822369
} else {
23832370
return t;
23842371
}
@@ -2389,12 +2376,11 @@ List<JCExpression> typeArgumentsOpt() {
23892376

23902377
List<JCExpression> typeArgumentsOpt(int useMode) {
23912378
if (token.kind == LT) {
2392-
if (!isMode(useMode) ||
2393-
isMode(NOPARAMS)) {
2379+
if (!isMode(useMode)) {
23942380
illegal();
23952381
}
23962382
setMode(useMode);
2397-
return typeArguments(false);
2383+
return typeArguments();
23982384
}
23992385
return null;
24002386
}
@@ -2404,35 +2390,29 @@ List<JCExpression> typeArgumentsOpt(int useMode) {
24042390
* TypeArguments = "<" TypeArgument {"," TypeArgument} ">"
24052391
* }
24062392
*/
2407-
List<JCExpression> typeArguments(boolean diamondAllowed) {
2393+
List<JCExpression> typeArguments() {
24082394
if (token.kind == LT) {
24092395
nextToken();
2410-
if (token.kind == GT && diamondAllowed) {
2411-
setMode(mode | DIAMOND);
2396+
ListBuffer<JCExpression> args = new ListBuffer<>();
2397+
args.append(!isMode(EXPR) ? typeArgument() : parseType());
2398+
while (token.kind == COMMA) {
24122399
nextToken();
2413-
return List.nil();
2414-
} else {
2415-
ListBuffer<JCExpression> args = new ListBuffer<>();
24162400
args.append(!isMode(EXPR) ? typeArgument() : parseType());
2417-
while (token.kind == COMMA) {
2418-
nextToken();
2419-
args.append(!isMode(EXPR) ? typeArgument() : parseType());
2420-
}
2421-
switch (token.kind) {
2401+
}
2402+
switch (token.kind) {
24222403

2423-
case GTGTGTEQ: case GTGTEQ: case GTEQ:
2424-
case GTGTGT: case GTGT:
2425-
token = S.split();
2426-
break;
2427-
case GT:
2428-
nextToken();
2429-
break;
2430-
default:
2431-
args.append(syntaxError(token.pos, Errors.Expected2(GT, COMMA)));
2432-
break;
2433-
}
2434-
return args.toList();
2404+
case GTGTGTEQ: case GTGTEQ: case GTEQ:
2405+
case GTGTGT: case GTGT:
2406+
token = S.split();
2407+
break;
2408+
case GT:
2409+
nextToken();
2410+
break;
2411+
default:
2412+
args.append(syntaxError(token.pos, Errors.Expected2(GT, COMMA)));
2413+
break;
24352414
}
2415+
return args.toList();
24362416
} else {
24372417
return List.of(syntaxError(token.pos, Errors.Expected(LT)));
24382418
}
@@ -2480,12 +2460,23 @@ JCExpression typeArgument() {
24802460
return result;
24812461
}
24822462

2483-
JCTypeApply typeArguments(JCExpression t, boolean diamondAllowed) {
2463+
JCTypeApply typeApply(JCExpression t) {
24842464
int pos = token.pos;
2485-
List<JCExpression> args = typeArguments(diamondAllowed);
2465+
List<JCExpression> args = typeArguments();
24862466
return toP(F.at(pos).TypeApply(t, args));
24872467
}
24882468

2469+
JCTypeApply typeApplyOrDiamond(JCExpression t) {
2470+
if (peekToken(GT)) {
2471+
int pos = token.pos;
2472+
accept(LT);
2473+
accept(GT);
2474+
return toP(F.at(pos).TypeApply(t, List.nil()));
2475+
} else {
2476+
return typeApply(t);
2477+
}
2478+
}
2479+
24892480
/**
24902481
* BracketsOpt = { [Annotations] "[" "]" }*
24912482
*
@@ -2585,7 +2576,7 @@ JCExpression memberReferenceSuffix(int pos1, JCExpression t) {
25852576
selectExprMode();
25862577
List<JCExpression> typeArgs = null;
25872578
if (token.kind == LT) {
2588-
typeArgs = typeArguments(false);
2579+
typeArgs = typeArguments();
25892580
}
25902581
Name refName;
25912582
ReferenceMode refMode;
@@ -2622,15 +2613,13 @@ JCExpression creator(int newpos, List<JCExpression> typeArgs) {
26222613

26232614
int prevmode = mode;
26242615
selectTypeMode();
2625-
boolean diamondFound = false;
26262616
int lastTypeargsPos = -1;
26272617
if (token.kind == LT) {
26282618
lastTypeargsPos = token.pos;
2629-
t = typeArguments(t, true);
2630-
diamondFound = isMode(DIAMOND);
2619+
t = typeApplyOrDiamond(t);
26312620
}
26322621
while (token.kind == DOT) {
2633-
if (diamondFound) {
2622+
if (TreeInfo.isDiamond(t)) {
26342623
//cannot select after a diamond
26352624
illegal();
26362625
}
@@ -2645,8 +2634,7 @@ JCExpression creator(int newpos, List<JCExpression> typeArgs) {
26452634

26462635
if (token.kind == LT) {
26472636
lastTypeargsPos = token.pos;
2648-
t = typeArguments(t, true);
2649-
diamondFound = isMode(DIAMOND);
2637+
t = typeApplyOrDiamond(t);
26502638
}
26512639
}
26522640
setMode(prevmode);
@@ -2657,7 +2645,7 @@ JCExpression creator(int newpos, List<JCExpression> typeArgs) {
26572645
}
26582646

26592647
JCExpression e = arrayCreatorRest(newpos, t);
2660-
if (diamondFound) {
2648+
if (TreeInfo.isDiamond(t)) {
26612649
reportSyntaxError(lastTypeargsPos, Errors.CannotCreateArrayWithDiamond);
26622650
return toP(F.at(newpos).Erroneous(List.of(e)));
26632651
}
@@ -2702,7 +2690,7 @@ JCExpression innerCreator(int newpos, List<JCExpression> typeArgs, JCExpression
27022690

27032691
if (token.kind == LT) {
27042692
int prevmode = mode;
2705-
t = typeArguments(t, true);
2693+
t = typeApplyOrDiamond(t);
27062694
setMode(prevmode);
27072695
}
27082696
return classCreatorRest(newpos, encl, typeArgs, t);

0 commit comments

Comments
 (0)