mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 03:58:21 +00:00
8375646: Some parser flags seem unused
Reviewed-by: jlahoda, vromero
This commit is contained in:
parent
3033e6f421
commit
17086d3119
@ -271,16 +271,11 @@ public class JavacParser implements Parser {
|
||||
/** When terms are parsed, the mode determines which is expected:
|
||||
* mode = EXPR : an expression
|
||||
* mode = TYPE : a type
|
||||
* mode = NOPARAMS : no parameters allowed for type
|
||||
* mode = TYPEARG : type argument
|
||||
* mode |= NOLAMBDA : lambdas are not allowed
|
||||
* mode = NOLAMBDA : lambdas are not allowed
|
||||
*/
|
||||
protected static final int EXPR = 1 << 0;
|
||||
protected static final int TYPE = 1 << 1;
|
||||
protected static final int NOPARAMS = 1 << 2;
|
||||
protected static final int TYPEARG = 1 << 3;
|
||||
protected static final int DIAMOND = 1 << 4;
|
||||
protected static final int NOLAMBDA = 1 << 5;
|
||||
protected static final int NOLAMBDA = 1 << 2;
|
||||
|
||||
protected void setMode(int mode) {
|
||||
this.mode = mode;
|
||||
@ -1439,12 +1434,6 @@ public class JavacParser implements Parser {
|
||||
int startMode = mode;
|
||||
List<JCExpression> typeArgs = typeArgumentsOpt(EXPR);
|
||||
switch (token.kind) {
|
||||
case QUES:
|
||||
if (isMode(TYPE) && isMode(TYPEARG) && !isMode(NOPARAMS)) {
|
||||
selectTypeMode();
|
||||
return typeArgument();
|
||||
} else
|
||||
return illegal();
|
||||
case PLUSPLUS: case SUBSUB: case BANG: case TILDE: case PLUS: case SUB:
|
||||
if (typeArgs == null && isMode(EXPR)) {
|
||||
TokenKind tk = token.kind;
|
||||
@ -1522,7 +1511,7 @@ public class JavacParser implements Parser {
|
||||
if (isMode(EXPR)) {
|
||||
selectExprMode();
|
||||
nextToken();
|
||||
if (token.kind == LT) typeArgs = typeArguments(false);
|
||||
if (token.kind == LT) typeArgs = typeArguments();
|
||||
t = creator(pos, typeArgs);
|
||||
typeArgs = null;
|
||||
} else return illegal();
|
||||
@ -1625,7 +1614,6 @@ public class JavacParser implements Parser {
|
||||
return illegal();
|
||||
}
|
||||
int prevmode = mode;
|
||||
setMode(mode & ~NOPARAMS);
|
||||
typeArgs = typeArgumentsOpt(EXPR);
|
||||
setMode(prevmode);
|
||||
if (isMode(EXPR)) {
|
||||
@ -1653,7 +1641,7 @@ public class JavacParser implements Parser {
|
||||
selectExprMode();
|
||||
int pos1 = token.pos;
|
||||
nextToken();
|
||||
if (token.kind == LT) typeArgs = typeArguments(false);
|
||||
if (token.kind == LT) typeArgs = typeArguments();
|
||||
t = innerCreator(pos1, typeArgs, t);
|
||||
typeArgs = null;
|
||||
break loop;
|
||||
@ -1704,7 +1692,7 @@ public class JavacParser implements Parser {
|
||||
nextToken();
|
||||
selectTypeMode();
|
||||
t = toP(F.at(token.pos).Select(t, ident()));
|
||||
t = typeArgumentsOpt(t);
|
||||
t = typeApplyOpt(t);
|
||||
}
|
||||
t = bracketsOpt(t);
|
||||
if (token.kind != COLCOL) {
|
||||
@ -1721,7 +1709,7 @@ public class JavacParser implements Parser {
|
||||
}
|
||||
}
|
||||
if (typeArgs != null) illegal();
|
||||
t = typeArgumentsOpt(t);
|
||||
t = typeApplyOpt(t);
|
||||
break;
|
||||
case BYTE: case SHORT: case CHAR: case INT: case LONG: case FLOAT:
|
||||
case DOUBLE: case BOOLEAN:
|
||||
@ -1880,7 +1868,7 @@ public class JavacParser implements Parser {
|
||||
selectExprMode();
|
||||
int pos2 = token.pos;
|
||||
nextToken();
|
||||
if (token.kind == LT) typeArgs = typeArguments(false);
|
||||
if (token.kind == LT) typeArgs = typeArguments();
|
||||
t = innerCreator(pos2, typeArgs, t);
|
||||
typeArgs = null;
|
||||
} else {
|
||||
@ -1900,7 +1888,7 @@ public class JavacParser implements Parser {
|
||||
if (tyannos != null && tyannos.nonEmpty()) {
|
||||
t = toP(F.at(tyannos.head.pos).AnnotatedType(tyannos, t));
|
||||
}
|
||||
t = argumentsOpt(typeArgs, typeArgumentsOpt(t));
|
||||
t = argumentsOpt(typeArgs, typeApplyOpt(t));
|
||||
typeArgs = null;
|
||||
}
|
||||
} else if (isMode(EXPR) && token.kind == COLCOL) {
|
||||
@ -2302,7 +2290,7 @@ public class JavacParser implements Parser {
|
||||
} else {
|
||||
int pos = token.pos;
|
||||
accept(DOT);
|
||||
typeArgs = (token.kind == LT) ? typeArguments(false) : null;
|
||||
typeArgs = (token.kind == LT) ? typeArguments() : null;
|
||||
t = toP(F.at(pos).Select(t, ident()));
|
||||
t = argumentsOpt(typeArgs, t);
|
||||
}
|
||||
@ -2373,12 +2361,11 @@ public class JavacParser implements Parser {
|
||||
|
||||
/** TypeArgumentsOpt = [ TypeArguments ]
|
||||
*/
|
||||
JCExpression typeArgumentsOpt(JCExpression t) {
|
||||
JCExpression typeApplyOpt(JCExpression t) {
|
||||
if (token.kind == LT &&
|
||||
isMode(TYPE) &&
|
||||
!isMode(NOPARAMS)) {
|
||||
isMode(TYPE)) {
|
||||
selectTypeMode();
|
||||
return typeArguments(t, false);
|
||||
return typeApply(t);
|
||||
} else {
|
||||
return t;
|
||||
}
|
||||
@ -2389,12 +2376,11 @@ public class JavacParser implements Parser {
|
||||
|
||||
List<JCExpression> typeArgumentsOpt(int useMode) {
|
||||
if (token.kind == LT) {
|
||||
if (!isMode(useMode) ||
|
||||
isMode(NOPARAMS)) {
|
||||
if (!isMode(useMode)) {
|
||||
illegal();
|
||||
}
|
||||
setMode(useMode);
|
||||
return typeArguments(false);
|
||||
return typeArguments();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -2404,35 +2390,29 @@ public class JavacParser implements Parser {
|
||||
* TypeArguments = "<" TypeArgument {"," TypeArgument} ">"
|
||||
* }
|
||||
*/
|
||||
List<JCExpression> typeArguments(boolean diamondAllowed) {
|
||||
List<JCExpression> typeArguments() {
|
||||
if (token.kind == LT) {
|
||||
nextToken();
|
||||
if (token.kind == GT && diamondAllowed) {
|
||||
setMode(mode | DIAMOND);
|
||||
ListBuffer<JCExpression> args = new ListBuffer<>();
|
||||
args.append(!isMode(EXPR) ? typeArgument() : parseType());
|
||||
while (token.kind == COMMA) {
|
||||
nextToken();
|
||||
return List.nil();
|
||||
} else {
|
||||
ListBuffer<JCExpression> args = new ListBuffer<>();
|
||||
args.append(!isMode(EXPR) ? typeArgument() : parseType());
|
||||
while (token.kind == COMMA) {
|
||||
nextToken();
|
||||
args.append(!isMode(EXPR) ? typeArgument() : parseType());
|
||||
}
|
||||
switch (token.kind) {
|
||||
|
||||
case GTGTGTEQ: case GTGTEQ: case GTEQ:
|
||||
case GTGTGT: case GTGT:
|
||||
token = S.split();
|
||||
break;
|
||||
case GT:
|
||||
nextToken();
|
||||
break;
|
||||
default:
|
||||
args.append(syntaxError(token.pos, Errors.Expected2(GT, COMMA)));
|
||||
break;
|
||||
}
|
||||
return args.toList();
|
||||
}
|
||||
switch (token.kind) {
|
||||
|
||||
case GTGTGTEQ: case GTGTEQ: case GTEQ:
|
||||
case GTGTGT: case GTGT:
|
||||
token = S.split();
|
||||
break;
|
||||
case GT:
|
||||
nextToken();
|
||||
break;
|
||||
default:
|
||||
args.append(syntaxError(token.pos, Errors.Expected2(GT, COMMA)));
|
||||
break;
|
||||
}
|
||||
return args.toList();
|
||||
} else {
|
||||
return List.of(syntaxError(token.pos, Errors.Expected(LT)));
|
||||
}
|
||||
@ -2480,12 +2460,23 @@ public class JavacParser implements Parser {
|
||||
return result;
|
||||
}
|
||||
|
||||
JCTypeApply typeArguments(JCExpression t, boolean diamondAllowed) {
|
||||
JCTypeApply typeApply(JCExpression t) {
|
||||
int pos = token.pos;
|
||||
List<JCExpression> args = typeArguments(diamondAllowed);
|
||||
List<JCExpression> args = typeArguments();
|
||||
return toP(F.at(pos).TypeApply(t, args));
|
||||
}
|
||||
|
||||
JCTypeApply typeApplyOrDiamond(JCExpression t) {
|
||||
if (peekToken(GT)) {
|
||||
int pos = token.pos;
|
||||
accept(LT);
|
||||
accept(GT);
|
||||
return toP(F.at(pos).TypeApply(t, List.nil()));
|
||||
} else {
|
||||
return typeApply(t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* BracketsOpt = { [Annotations] "[" "]" }*
|
||||
*
|
||||
@ -2585,7 +2576,7 @@ public class JavacParser implements Parser {
|
||||
selectExprMode();
|
||||
List<JCExpression> typeArgs = null;
|
||||
if (token.kind == LT) {
|
||||
typeArgs = typeArguments(false);
|
||||
typeArgs = typeArguments();
|
||||
}
|
||||
Name refName;
|
||||
ReferenceMode refMode;
|
||||
@ -2622,15 +2613,13 @@ public class JavacParser implements Parser {
|
||||
|
||||
int prevmode = mode;
|
||||
selectTypeMode();
|
||||
boolean diamondFound = false;
|
||||
int lastTypeargsPos = -1;
|
||||
if (token.kind == LT) {
|
||||
lastTypeargsPos = token.pos;
|
||||
t = typeArguments(t, true);
|
||||
diamondFound = isMode(DIAMOND);
|
||||
t = typeApplyOrDiamond(t);
|
||||
}
|
||||
while (token.kind == DOT) {
|
||||
if (diamondFound) {
|
||||
if (TreeInfo.isDiamond(t)) {
|
||||
//cannot select after a diamond
|
||||
illegal();
|
||||
}
|
||||
@ -2645,8 +2634,7 @@ public class JavacParser implements Parser {
|
||||
|
||||
if (token.kind == LT) {
|
||||
lastTypeargsPos = token.pos;
|
||||
t = typeArguments(t, true);
|
||||
diamondFound = isMode(DIAMOND);
|
||||
t = typeApplyOrDiamond(t);
|
||||
}
|
||||
}
|
||||
setMode(prevmode);
|
||||
@ -2657,7 +2645,7 @@ public class JavacParser implements Parser {
|
||||
}
|
||||
|
||||
JCExpression e = arrayCreatorRest(newpos, t);
|
||||
if (diamondFound) {
|
||||
if (TreeInfo.isDiamond(t)) {
|
||||
reportSyntaxError(lastTypeargsPos, Errors.CannotCreateArrayWithDiamond);
|
||||
return toP(F.at(newpos).Erroneous(List.of(e)));
|
||||
}
|
||||
@ -2702,7 +2690,7 @@ public class JavacParser implements Parser {
|
||||
|
||||
if (token.kind == LT) {
|
||||
int prevmode = mode;
|
||||
t = typeArguments(t, true);
|
||||
t = typeApplyOrDiamond(t);
|
||||
setMode(prevmode);
|
||||
}
|
||||
return classCreatorRest(newpos, encl, typeArgs, t);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user