author | mcimadamore |
Mon, 21 Jan 2013 20:14:39 +0000 | |
changeset 15375 | d2529dc91d77 |
parent 15367 | 31b57f2b8d0b |
child 15377 | 515846bb6637 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2 |
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.parser; |
|
27 |
||
28 |
import java.util.*; |
|
29 |
||
11144
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
30 |
import com.sun.source.tree.MemberReferenceTree.ReferenceMode; |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
31 |
|
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
32 |
import com.sun.tools.javac.code.*; |
10815 | 33 |
import com.sun.tools.javac.parser.Tokens.*; |
10948 | 34 |
import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle; |
10 | 35 |
import com.sun.tools.javac.tree.*; |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
36 |
import com.sun.tools.javac.tree.JCTree.*; |
10 | 37 |
import com.sun.tools.javac.util.*; |
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
7074
diff
changeset
|
38 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
39 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
10 | 40 |
import com.sun.tools.javac.util.List; |
41 |
||
10950 | 42 |
import static com.sun.tools.javac.parser.Tokens.TokenKind.*; |
43 |
import static com.sun.tools.javac.parser.Tokens.TokenKind.ASSERT; |
|
44 |
import static com.sun.tools.javac.parser.Tokens.TokenKind.CASE; |
|
45 |
import static com.sun.tools.javac.parser.Tokens.TokenKind.CATCH; |
|
46 |
import static com.sun.tools.javac.parser.Tokens.TokenKind.EQ; |
|
47 |
import static com.sun.tools.javac.parser.Tokens.TokenKind.GT; |
|
48 |
import static com.sun.tools.javac.parser.Tokens.TokenKind.IMPORT; |
|
49 |
import static com.sun.tools.javac.parser.Tokens.TokenKind.LT; |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14450
diff
changeset
|
50 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
51 |
import static com.sun.tools.javac.util.ListBuffer.lb; |
10 | 52 |
|
53 |
/** The parser maps a token sequence into an abstract syntax |
|
54 |
* tree. It operates by recursive descent, with code derived |
|
55 |
* systematically from an LL(1) grammar. For efficiency reasons, an |
|
56 |
* operator precedence scheme is used for parsing binary operation |
|
57 |
* expressions. |
|
58 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
59 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
60 |
* If you write code that depends on this, you do so at your own risk. |
10 | 61 |
* This code and its internal interfaces are subject to change or |
62 |
* deletion without notice.</b> |
|
63 |
*/ |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
64 |
public class JavacParser implements Parser { |
10 | 65 |
|
66 |
/** The number of precedence levels of infix operators. |
|
67 |
*/ |
|
68 |
private static final int infixPrecedenceLevels = 10; |
|
69 |
||
70 |
/** The scanner used for lexical analysis. |
|
71 |
*/ |
|
10200
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
10199
diff
changeset
|
72 |
protected Lexer S; |
10 | 73 |
|
74 |
/** The factory to be used for abstract syntax tree construction. |
|
75 |
*/ |
|
76 |
protected TreeMaker F; |
|
77 |
||
78 |
/** The log to be used for error diagnostics. |
|
79 |
*/ |
|
80 |
private Log log; |
|
81 |
||
82 |
/** The Source language setting. */ |
|
83 |
private Source source; |
|
84 |
||
85 |
/** The name table. */ |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1258
diff
changeset
|
86 |
private Names names; |
10 | 87 |
|
11055 | 88 |
/** End position mappings container */ |
89 |
private final AbstractEndPosTable endPosTable; |
|
90 |
||
14450
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
91 |
interface ErrorRecoveryAction { |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
92 |
JCTree doRecover(JavacParser parser); |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
93 |
} |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
94 |
|
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
95 |
enum BasicErrorRecoveryAction implements ErrorRecoveryAction { |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
96 |
BLOCK_STMT {public JCTree doRecover(JavacParser parser) { return parser.parseStatementAsBlock(); }}, |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
97 |
CATCH_CLAUSE {public JCTree doRecover(JavacParser parser) { return parser.catchClause(); }} |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
98 |
} |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
99 |
|
10 | 100 |
/** Construct a parser from a given scanner, tree factory and log. |
101 |
*/ |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
102 |
protected JavacParser(ParserFactory fac, |
10 | 103 |
Lexer S, |
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
104 |
boolean keepDocComments, |
11055 | 105 |
boolean keepLineMap, |
106 |
boolean keepEndPositions) { |
|
10 | 107 |
this.S = S; |
10815 | 108 |
nextToken(); // prime the pump |
10 | 109 |
this.F = fac.F; |
110 |
this.log = fac.log; |
|
111 |
this.names = fac.names; |
|
112 |
this.source = fac.source; |
|
113 |
this.allowGenerics = source.allowGenerics(); |
|
114 |
this.allowVarargs = source.allowVarargs(); |
|
115 |
this.allowAsserts = source.allowAsserts(); |
|
116 |
this.allowEnums = source.allowEnums(); |
|
117 |
this.allowForeach = source.allowForeach(); |
|
118 |
this.allowStaticImport = source.allowStaticImport(); |
|
119 |
this.allowAnnotations = source.allowAnnotations(); |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
120 |
this.allowTWR = source.allowTryWithResources(); |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
121 |
this.allowDiamond = source.allowDiamond(); |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
122 |
this.allowMulticatch = source.allowMulticatch(); |
10200
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
10199
diff
changeset
|
123 |
this.allowStringFolding = fac.options.getBoolean("allowStringFolding", true); |
14547 | 124 |
this.allowLambda = source.allowLambda(); |
125 |
this.allowMethodReferences = source.allowMethodReferences(); |
|
126 |
this.allowDefaultMethods = source.allowDefaultMethods(); |
|
15375
d2529dc91d77
8006566: Remove transient lambda-related guards from JavacParser
mcimadamore
parents:
15367
diff
changeset
|
127 |
this.allowIntersectionTypesInCast = source.allowIntersectionTypesInCast(); |
10 | 128 |
this.keepDocComments = keepDocComments; |
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14450
diff
changeset
|
129 |
docComments = newDocCommentTable(keepDocComments, fac); |
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
130 |
this.keepLineMap = keepLineMap; |
10 | 131 |
this.errorTree = F.Erroneous(); |
11055 | 132 |
endPosTable = newEndPosTable(keepEndPositions); |
10 | 133 |
} |
134 |
||
11055 | 135 |
protected AbstractEndPosTable newEndPosTable(boolean keepEndPositions) { |
136 |
return keepEndPositions |
|
137 |
? new SimpleEndPosTable() |
|
138 |
: new EmptyEndPosTable(); |
|
139 |
} |
|
13077 | 140 |
|
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14450
diff
changeset
|
141 |
protected DocCommentTable newDocCommentTable(boolean keepDocComments, ParserFactory fac) { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14450
diff
changeset
|
142 |
return keepDocComments ? new LazyDocCommentTable(fac) : null; |
13077 | 143 |
} |
144 |
||
10 | 145 |
/** Switch: Should generics be recognized? |
146 |
*/ |
|
147 |
boolean allowGenerics; |
|
148 |
||
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
149 |
/** Switch: Should diamond operator be recognized? |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
150 |
*/ |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
151 |
boolean allowDiamond; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
152 |
|
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
153 |
/** Switch: Should multicatch clause be accepted? |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
154 |
*/ |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
155 |
boolean allowMulticatch; |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
156 |
|
10 | 157 |
/** Switch: Should varargs be recognized? |
158 |
*/ |
|
159 |
boolean allowVarargs; |
|
160 |
||
161 |
/** Switch: should we recognize assert statements, or just give a warning? |
|
162 |
*/ |
|
163 |
boolean allowAsserts; |
|
164 |
||
165 |
/** Switch: should we recognize enums, or just give a warning? |
|
166 |
*/ |
|
167 |
boolean allowEnums; |
|
168 |
||
169 |
/** Switch: should we recognize foreach? |
|
170 |
*/ |
|
171 |
boolean allowForeach; |
|
172 |
||
173 |
/** Switch: should we recognize foreach? |
|
174 |
*/ |
|
175 |
boolean allowStaticImport; |
|
176 |
||
177 |
/** Switch: should we recognize annotations? |
|
178 |
*/ |
|
179 |
boolean allowAnnotations; |
|
180 |
||
8224
8f18e1622660
7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents:
8047
diff
changeset
|
181 |
/** Switch: should we recognize try-with-resources? |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
182 |
*/ |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
183 |
boolean allowTWR; |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
184 |
|
10200
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
10199
diff
changeset
|
185 |
/** Switch: should we fold strings? |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
10199
diff
changeset
|
186 |
*/ |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
10199
diff
changeset
|
187 |
boolean allowStringFolding; |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
10199
diff
changeset
|
188 |
|
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
189 |
/** Switch: should we recognize lambda expressions? |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
190 |
*/ |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
191 |
boolean allowLambda; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
192 |
|
11144
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
193 |
/** Switch: should we allow method/constructor references? |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
194 |
*/ |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
195 |
boolean allowMethodReferences; |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
196 |
|
14267
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14263
diff
changeset
|
197 |
/** Switch: should we allow default methods in interfaces? |
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14263
diff
changeset
|
198 |
*/ |
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14263
diff
changeset
|
199 |
boolean allowDefaultMethods; |
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14263
diff
changeset
|
200 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
201 |
/** Switch: should we allow intersection types in cast? |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
202 |
*/ |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
203 |
boolean allowIntersectionTypesInCast; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
204 |
|
10 | 205 |
/** Switch: should we keep docComments? |
206 |
*/ |
|
207 |
boolean keepDocComments; |
|
208 |
||
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
209 |
/** Switch: should we keep line table? |
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
210 |
*/ |
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
211 |
boolean keepLineMap; |
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
212 |
|
10 | 213 |
/** When terms are parsed, the mode determines which is expected: |
214 |
* mode = EXPR : an expression |
|
215 |
* mode = TYPE : a type |
|
216 |
* mode = NOPARAMS : no parameters allowed for type |
|
217 |
* mode = TYPEARG : type argument |
|
218 |
*/ |
|
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
219 |
static final int EXPR = 0x1; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
220 |
static final int TYPE = 0x2; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
221 |
static final int NOPARAMS = 0x4; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
222 |
static final int TYPEARG = 0x8; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
223 |
static final int DIAMOND = 0x10; |
10 | 224 |
|
225 |
/** The current mode. |
|
226 |
*/ |
|
227 |
private int mode = 0; |
|
228 |
||
229 |
/** The mode of the term that was parsed last. |
|
230 |
*/ |
|
231 |
private int lastmode = 0; |
|
232 |
||
10815 | 233 |
/* ---------- token management -------------- */ |
234 |
||
235 |
protected Token token; |
|
236 |
||
14541
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14450
diff
changeset
|
237 |
public Token token() { |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14450
diff
changeset
|
238 |
return token; |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14450
diff
changeset
|
239 |
} |
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14450
diff
changeset
|
240 |
|
36f9d11fc9aa
7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents:
14450
diff
changeset
|
241 |
public void nextToken() { |
10815 | 242 |
S.nextToken(); |
243 |
token = S.token(); |
|
244 |
} |
|
245 |
||
15367 | 246 |
protected boolean peekToken(Filter<TokenKind> tk) { |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
247 |
return peekToken(0, tk); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
248 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
249 |
|
15367 | 250 |
protected boolean peekToken(int lookahead, Filter<TokenKind> tk) { |
251 |
return tk.accepts(S.token(lookahead + 1).kind); |
|
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
252 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
253 |
|
15367 | 254 |
protected boolean peekToken(Filter<TokenKind> tk1, Filter<TokenKind> tk2) { |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
255 |
return peekToken(0, tk1, tk2); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
256 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
257 |
|
15367 | 258 |
protected boolean peekToken(int lookahead, Filter<TokenKind> tk1, Filter<TokenKind> tk2) { |
259 |
return tk1.accepts(S.token(lookahead + 1).kind) && |
|
260 |
tk2.accepts(S.token(lookahead + 2).kind); |
|
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
261 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
262 |
|
15367 | 263 |
protected boolean peekToken(Filter<TokenKind> tk1, Filter<TokenKind> tk2, Filter<TokenKind> tk3) { |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
264 |
return peekToken(0, tk1, tk2, tk3); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
265 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
266 |
|
15367 | 267 |
protected boolean peekToken(int lookahead, Filter<TokenKind> tk1, Filter<TokenKind> tk2, Filter<TokenKind> tk3) { |
268 |
return tk1.accepts(S.token(lookahead + 1).kind) && |
|
269 |
tk2.accepts(S.token(lookahead + 2).kind) && |
|
270 |
tk3.accepts(S.token(lookahead + 3).kind); |
|
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
271 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
272 |
|
15367 | 273 |
@SuppressWarnings("unchecked") |
274 |
protected boolean peekToken(Filter<TokenKind>... kinds) { |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
275 |
return peekToken(0, kinds); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
276 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
277 |
|
15367 | 278 |
@SuppressWarnings("unchecked") |
279 |
protected boolean peekToken(int lookahead, Filter<TokenKind>... kinds) { |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
280 |
for (; lookahead < kinds.length ; lookahead++) { |
15367 | 281 |
if (!kinds[lookahead].accepts(S.token(lookahead + 1).kind)) { |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
282 |
return false; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
283 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
284 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
285 |
return true; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
286 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
287 |
|
10815 | 288 |
/* ---------- error recovery -------------- */ |
10 | 289 |
|
290 |
private JCErroneous errorTree; |
|
291 |
||
292 |
/** Skip forward until a suitable stop token is found. |
|
293 |
*/ |
|
294 |
private void skip(boolean stopAtImport, boolean stopAtMemberDecl, boolean stopAtIdentifier, boolean stopAtStatement) { |
|
295 |
while (true) { |
|
10815 | 296 |
switch (token.kind) { |
10 | 297 |
case SEMI: |
10815 | 298 |
nextToken(); |
10 | 299 |
return; |
300 |
case PUBLIC: |
|
301 |
case FINAL: |
|
302 |
case ABSTRACT: |
|
303 |
case MONKEYS_AT: |
|
304 |
case EOF: |
|
305 |
case CLASS: |
|
306 |
case INTERFACE: |
|
307 |
case ENUM: |
|
308 |
return; |
|
309 |
case IMPORT: |
|
310 |
if (stopAtImport) |
|
311 |
return; |
|
312 |
break; |
|
313 |
case LBRACE: |
|
314 |
case RBRACE: |
|
315 |
case PRIVATE: |
|
316 |
case PROTECTED: |
|
317 |
case STATIC: |
|
318 |
case TRANSIENT: |
|
319 |
case NATIVE: |
|
320 |
case VOLATILE: |
|
321 |
case SYNCHRONIZED: |
|
322 |
case STRICTFP: |
|
323 |
case LT: |
|
324 |
case BYTE: |
|
325 |
case SHORT: |
|
326 |
case CHAR: |
|
327 |
case INT: |
|
328 |
case LONG: |
|
329 |
case FLOAT: |
|
330 |
case DOUBLE: |
|
331 |
case BOOLEAN: |
|
332 |
case VOID: |
|
333 |
if (stopAtMemberDecl) |
|
334 |
return; |
|
335 |
break; |
|
15367 | 336 |
case UNDERSCORE: |
10 | 337 |
case IDENTIFIER: |
338 |
if (stopAtIdentifier) |
|
339 |
return; |
|
340 |
break; |
|
341 |
case CASE: |
|
342 |
case DEFAULT: |
|
343 |
case IF: |
|
344 |
case FOR: |
|
345 |
case WHILE: |
|
346 |
case DO: |
|
347 |
case TRY: |
|
348 |
case SWITCH: |
|
349 |
case RETURN: |
|
350 |
case THROW: |
|
351 |
case BREAK: |
|
352 |
case CONTINUE: |
|
353 |
case ELSE: |
|
354 |
case FINALLY: |
|
355 |
case CATCH: |
|
356 |
if (stopAtStatement) |
|
357 |
return; |
|
358 |
break; |
|
359 |
} |
|
10815 | 360 |
nextToken(); |
10 | 361 |
} |
362 |
} |
|
363 |
||
10815 | 364 |
private JCErroneous syntaxError(int pos, String key, TokenKind... args) { |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
365 |
return syntaxError(pos, List.<JCTree>nil(), key, args); |
10 | 366 |
} |
367 |
||
10815 | 368 |
private JCErroneous syntaxError(int pos, List<JCTree> errs, String key, TokenKind... args) { |
10 | 369 |
setErrorEndPos(pos); |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
370 |
JCErroneous err = F.at(pos).Erroneous(errs); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
371 |
reportSyntaxError(err, key, (Object[])args); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
372 |
if (errs != null) { |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
373 |
JCTree last = errs.last(); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
374 |
if (last != null) |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
375 |
storeEnd(last, pos); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
376 |
} |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
377 |
return toP(err); |
10 | 378 |
} |
379 |
||
380 |
private int errorPos = Position.NOPOS; |
|
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
381 |
|
10 | 382 |
/** |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
383 |
* Report a syntax using the given the position parameter and arguments, |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
384 |
* unless one was already reported at the same position. |
10 | 385 |
*/ |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
386 |
private void reportSyntaxError(int pos, String key, Object... args) { |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
387 |
JCDiagnostic.DiagnosticPosition diag = new JCDiagnostic.SimpleDiagnosticPosition(pos); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
388 |
reportSyntaxError(diag, key, args); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
389 |
} |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
390 |
|
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
391 |
/** |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
392 |
* Report a syntax error using the given DiagnosticPosition object and |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
393 |
* arguments, unless one was already reported at the same position. |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
394 |
*/ |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
395 |
private void reportSyntaxError(JCDiagnostic.DiagnosticPosition diagPos, String key, Object... args) { |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
396 |
int pos = diagPos.getPreferredPosition(); |
10 | 397 |
if (pos > S.errPos() || pos == Position.NOPOS) { |
10815 | 398 |
if (token.kind == EOF) { |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
399 |
error(diagPos, "premature.eof"); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
400 |
} else { |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
401 |
error(diagPos, key, args); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
402 |
} |
10 | 403 |
} |
404 |
S.errPos(pos); |
|
10815 | 405 |
if (token.pos == errorPos) |
406 |
nextToken(); // guarantee progress |
|
407 |
errorPos = token.pos; |
|
10 | 408 |
} |
409 |
||
410 |
||
411 |
/** Generate a syntax error at current position unless one was already |
|
412 |
* reported at the same position. |
|
413 |
*/ |
|
414 |
private JCErroneous syntaxError(String key) { |
|
10815 | 415 |
return syntaxError(token.pos, key); |
10 | 416 |
} |
417 |
||
418 |
/** Generate a syntax error at current position unless one was |
|
419 |
* already reported at the same position. |
|
420 |
*/ |
|
10815 | 421 |
private JCErroneous syntaxError(String key, TokenKind arg) { |
422 |
return syntaxError(token.pos, key, arg); |
|
10 | 423 |
} |
424 |
||
425 |
/** If next input token matches given token, skip it, otherwise report |
|
426 |
* an error. |
|
427 |
*/ |
|
10815 | 428 |
public void accept(TokenKind tk) { |
429 |
if (token.kind == tk) { |
|
430 |
nextToken(); |
|
10 | 431 |
} else { |
10815 | 432 |
setErrorEndPos(token.pos); |
433 |
reportSyntaxError(S.prevToken().endPos, "expected", tk); |
|
10 | 434 |
} |
435 |
} |
|
436 |
||
437 |
/** Report an illegal start of expression/type error at given position. |
|
438 |
*/ |
|
439 |
JCExpression illegal(int pos) { |
|
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
440 |
setErrorEndPos(pos); |
10 | 441 |
if ((mode & EXPR) != 0) |
442 |
return syntaxError(pos, "illegal.start.of.expr"); |
|
443 |
else |
|
444 |
return syntaxError(pos, "illegal.start.of.type"); |
|
445 |
||
446 |
} |
|
447 |
||
448 |
/** Report an illegal start of expression/type error at current position. |
|
449 |
*/ |
|
450 |
JCExpression illegal() { |
|
10815 | 451 |
return illegal(token.pos); |
10 | 452 |
} |
453 |
||
454 |
/** Diagnose a modifier flag from the set, if any. */ |
|
455 |
void checkNoMods(long mods) { |
|
456 |
if (mods != 0) { |
|
457 |
long lowestMod = mods & -mods; |
|
10815 | 458 |
error(token.pos, "mod.not.allowed.here", |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
459 |
Flags.asFlagSet(lowestMod)); |
10 | 460 |
} |
461 |
} |
|
462 |
||
463 |
/* ---------- doc comments --------- */ |
|
464 |
||
13077 | 465 |
/** A table to store all documentation comments |
10 | 466 |
* indexed by the tree nodes they refer to. |
467 |
* defined only if option flag keepDocComment is set. |
|
468 |
*/ |
|
13077 | 469 |
private final DocCommentTable docComments; |
10 | 470 |
|
471 |
/** Make an entry into docComments hashtable, |
|
472 |
* provided flag keepDocComments is set and given doc comment is non-null. |
|
473 |
* @param tree The tree to be used as index in the hashtable |
|
474 |
* @param dc The doc comment to associate with the tree, or null. |
|
475 |
*/ |
|
13077 | 476 |
void attach(JCTree tree, Comment dc) { |
10 | 477 |
if (keepDocComments && dc != null) { |
478 |
// System.out.println("doc comment = ");System.out.println(dc);//DEBUG |
|
13077 | 479 |
docComments.putComment(tree, dc); |
10 | 480 |
} |
481 |
} |
|
482 |
||
483 |
/* -------- source positions ------- */ |
|
484 |
||
485 |
private void setErrorEndPos(int errPos) { |
|
11055 | 486 |
endPosTable.setErrorEndPos(errPos); |
10 | 487 |
} |
488 |
||
11055 | 489 |
private void storeEnd(JCTree tree, int endpos) { |
490 |
endPosTable.storeEnd(tree, endpos); |
|
10 | 491 |
} |
492 |
||
11055 | 493 |
private <T extends JCTree> T to(T t) { |
494 |
return endPosTable.to(t); |
|
495 |
} |
|
10 | 496 |
|
11055 | 497 |
private <T extends JCTree> T toP(T t) { |
498 |
return endPosTable.toP(t); |
|
499 |
} |
|
10 | 500 |
|
501 |
/** Get the start position for a tree node. The start position is |
|
502 |
* defined to be the position of the first character of the first |
|
503 |
* token of the node's source text. |
|
504 |
* @param tree The tree node |
|
505 |
*/ |
|
506 |
public int getStartPos(JCTree tree) { |
|
507 |
return TreeInfo.getStartPos(tree); |
|
508 |
} |
|
509 |
||
510 |
/** |
|
511 |
* Get the end position for a tree node. The end position is |
|
512 |
* defined to be the position of the last character of the last |
|
513 |
* token of the node's source text. Returns Position.NOPOS if end |
|
514 |
* positions are not generated or the position is otherwise not |
|
515 |
* found. |
|
516 |
* @param tree The tree node |
|
517 |
*/ |
|
518 |
public int getEndPos(JCTree tree) { |
|
11055 | 519 |
return endPosTable.getEndPos(tree); |
10 | 520 |
} |
521 |
||
522 |
||
523 |
||
524 |
/* ---------- parsing -------------- */ |
|
525 |
||
526 |
/** |
|
527 |
* Ident = IDENTIFIER |
|
528 |
*/ |
|
529 |
Name ident() { |
|
10815 | 530 |
if (token.kind == IDENTIFIER) { |
531 |
Name name = token.name(); |
|
532 |
nextToken(); |
|
10 | 533 |
return name; |
10815 | 534 |
} else if (token.kind == ASSERT) { |
10 | 535 |
if (allowAsserts) { |
10815 | 536 |
error(token.pos, "assert.as.identifier"); |
537 |
nextToken(); |
|
10 | 538 |
return names.error; |
539 |
} else { |
|
10815 | 540 |
warning(token.pos, "assert.as.identifier"); |
541 |
Name name = token.name(); |
|
542 |
nextToken(); |
|
10 | 543 |
return name; |
544 |
} |
|
10815 | 545 |
} else if (token.kind == ENUM) { |
10 | 546 |
if (allowEnums) { |
10815 | 547 |
error(token.pos, "enum.as.identifier"); |
548 |
nextToken(); |
|
10 | 549 |
return names.error; |
550 |
} else { |
|
10815 | 551 |
warning(token.pos, "enum.as.identifier"); |
552 |
Name name = token.name(); |
|
553 |
nextToken(); |
|
10 | 554 |
return name; |
555 |
} |
|
15367 | 556 |
} else if (token.kind == UNDERSCORE) { |
557 |
warning(token.pos, "underscore.as.identifier"); |
|
558 |
Name name = token.name(); |
|
559 |
nextToken(); |
|
560 |
return name; |
|
10 | 561 |
} else { |
562 |
accept(IDENTIFIER); |
|
563 |
return names.error; |
|
564 |
} |
|
15367 | 565 |
} |
10 | 566 |
|
567 |
/** |
|
568 |
* Qualident = Ident { DOT Ident } |
|
569 |
*/ |
|
570 |
public JCExpression qualident() { |
|
10815 | 571 |
JCExpression t = toP(F.at(token.pos).Ident(ident())); |
572 |
while (token.kind == DOT) { |
|
573 |
int pos = token.pos; |
|
574 |
nextToken(); |
|
10 | 575 |
t = toP(F.at(pos).Select(t, ident())); |
576 |
} |
|
577 |
return t; |
|
578 |
} |
|
579 |
||
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
580 |
JCExpression literal(Name prefix) { |
10815 | 581 |
return literal(prefix, token.pos); |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
582 |
} |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
583 |
|
10 | 584 |
/** |
585 |
* Literal = |
|
586 |
* INTLITERAL |
|
587 |
* | LONGLITERAL |
|
588 |
* | FLOATLITERAL |
|
589 |
* | DOUBLELITERAL |
|
590 |
* | CHARLITERAL |
|
591 |
* | STRINGLITERAL |
|
592 |
* | TRUE |
|
593 |
* | FALSE |
|
594 |
* | NULL |
|
595 |
*/ |
|
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
596 |
JCExpression literal(Name prefix, int pos) { |
10 | 597 |
JCExpression t = errorTree; |
10815 | 598 |
switch (token.kind) { |
10 | 599 |
case INTLITERAL: |
600 |
try { |
|
601 |
t = F.at(pos).Literal( |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
602 |
TypeTag.INT, |
10815 | 603 |
Convert.string2int(strval(prefix), token.radix())); |
10 | 604 |
} catch (NumberFormatException ex) { |
10815 | 605 |
error(token.pos, "int.number.too.large", strval(prefix)); |
10 | 606 |
} |
607 |
break; |
|
608 |
case LONGLITERAL: |
|
609 |
try { |
|
610 |
t = F.at(pos).Literal( |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
611 |
TypeTag.LONG, |
10815 | 612 |
new Long(Convert.string2long(strval(prefix), token.radix()))); |
10 | 613 |
} catch (NumberFormatException ex) { |
10815 | 614 |
error(token.pos, "int.number.too.large", strval(prefix)); |
10 | 615 |
} |
616 |
break; |
|
617 |
case FLOATLITERAL: { |
|
10815 | 618 |
String proper = token.radix() == 16 ? |
619 |
("0x"+ token.stringVal()) : |
|
620 |
token.stringVal(); |
|
10 | 621 |
Float n; |
622 |
try { |
|
623 |
n = Float.valueOf(proper); |
|
624 |
} catch (NumberFormatException ex) { |
|
7636
030f141aa32b
6504896: TreeMaker.Literal(Object) does not support Booleans
jjg
parents:
7211
diff
changeset
|
625 |
// error already reported in scanner |
10 | 626 |
n = Float.NaN; |
627 |
} |
|
628 |
if (n.floatValue() == 0.0f && !isZero(proper)) |
|
10815 | 629 |
error(token.pos, "fp.number.too.small"); |
10 | 630 |
else if (n.floatValue() == Float.POSITIVE_INFINITY) |
10815 | 631 |
error(token.pos, "fp.number.too.large"); |
10 | 632 |
else |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
633 |
t = F.at(pos).Literal(TypeTag.FLOAT, n); |
10 | 634 |
break; |
635 |
} |
|
636 |
case DOUBLELITERAL: { |
|
10815 | 637 |
String proper = token.radix() == 16 ? |
638 |
("0x"+ token.stringVal()) : |
|
639 |
token.stringVal(); |
|
10 | 640 |
Double n; |
641 |
try { |
|
642 |
n = Double.valueOf(proper); |
|
643 |
} catch (NumberFormatException ex) { |
|
644 |
// error already reported in scanner |
|
645 |
n = Double.NaN; |
|
646 |
} |
|
647 |
if (n.doubleValue() == 0.0d && !isZero(proper)) |
|
10815 | 648 |
error(token.pos, "fp.number.too.small"); |
10 | 649 |
else if (n.doubleValue() == Double.POSITIVE_INFINITY) |
10815 | 650 |
error(token.pos, "fp.number.too.large"); |
10 | 651 |
else |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
652 |
t = F.at(pos).Literal(TypeTag.DOUBLE, n); |
10 | 653 |
break; |
654 |
} |
|
655 |
case CHARLITERAL: |
|
656 |
t = F.at(pos).Literal( |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
657 |
TypeTag.CHAR, |
10815 | 658 |
token.stringVal().charAt(0) + 0); |
10 | 659 |
break; |
660 |
case STRINGLITERAL: |
|
661 |
t = F.at(pos).Literal( |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
662 |
TypeTag.CLASS, |
10815 | 663 |
token.stringVal()); |
10 | 664 |
break; |
665 |
case TRUE: case FALSE: |
|
666 |
t = F.at(pos).Literal( |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
667 |
TypeTag.BOOLEAN, |
10815 | 668 |
(token.kind == TRUE ? 1 : 0)); |
10 | 669 |
break; |
670 |
case NULL: |
|
671 |
t = F.at(pos).Literal( |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
672 |
TypeTag.BOT, |
10 | 673 |
null); |
674 |
break; |
|
675 |
default: |
|
8032 | 676 |
Assert.error(); |
10 | 677 |
} |
678 |
if (t == errorTree) |
|
679 |
t = F.at(pos).Erroneous(); |
|
10815 | 680 |
storeEnd(t, token.endPos); |
681 |
nextToken(); |
|
10 | 682 |
return t; |
683 |
} |
|
684 |
//where |
|
685 |
boolean isZero(String s) { |
|
686 |
char[] cs = s.toCharArray(); |
|
3894 | 687 |
int base = ((cs.length > 1 && Character.toLowerCase(cs[1]) == 'x') ? 16 : 10); |
10 | 688 |
int i = ((base==16) ? 2 : 0); |
689 |
while (i < cs.length && (cs[i] == '0' || cs[i] == '.')) i++; |
|
690 |
return !(i < cs.length && (Character.digit(cs[i], base) > 0)); |
|
691 |
} |
|
692 |
||
693 |
String strval(Name prefix) { |
|
10815 | 694 |
String s = token.stringVal(); |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1258
diff
changeset
|
695 |
return prefix.isEmpty() ? s : prefix + s; |
10 | 696 |
} |
697 |
||
698 |
/** terms can be either expressions or types. |
|
699 |
*/ |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
700 |
public JCExpression parseExpression() { |
10 | 701 |
return term(EXPR); |
702 |
} |
|
703 |
||
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
704 |
public JCExpression parseType() { |
10 | 705 |
return term(TYPE); |
706 |
} |
|
707 |
||
708 |
JCExpression term(int newmode) { |
|
709 |
int prevmode = mode; |
|
710 |
mode = newmode; |
|
711 |
JCExpression t = term(); |
|
712 |
lastmode = mode; |
|
713 |
mode = prevmode; |
|
714 |
return t; |
|
715 |
} |
|
716 |
||
717 |
/** |
|
13844 | 718 |
* {@literal |
10 | 719 |
* Expression = Expression1 [ExpressionRest] |
720 |
* ExpressionRest = [AssignmentOperator Expression1] |
|
721 |
* AssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | |
|
722 |
* "&=" | "|=" | "^=" | |
|
723 |
* "%=" | "<<=" | ">>=" | ">>>=" |
|
724 |
* Type = Type1 |
|
725 |
* TypeNoParams = TypeNoParams1 |
|
726 |
* StatementExpression = Expression |
|
727 |
* ConstantExpression = Expression |
|
13844 | 728 |
* } |
10 | 729 |
*/ |
730 |
JCExpression term() { |
|
731 |
JCExpression t = term1(); |
|
732 |
if ((mode & EXPR) != 0 && |
|
10815 | 733 |
token.kind == EQ || PLUSEQ.compareTo(token.kind) <= 0 && token.kind.compareTo(GTGTGTEQ) <= 0) |
10 | 734 |
return termRest(t); |
735 |
else |
|
736 |
return t; |
|
737 |
} |
|
738 |
||
739 |
JCExpression termRest(JCExpression t) { |
|
10815 | 740 |
switch (token.kind) { |
10 | 741 |
case EQ: { |
10815 | 742 |
int pos = token.pos; |
743 |
nextToken(); |
|
10 | 744 |
mode = EXPR; |
745 |
JCExpression t1 = term(); |
|
746 |
return toP(F.at(pos).Assign(t, t1)); |
|
747 |
} |
|
748 |
case PLUSEQ: |
|
749 |
case SUBEQ: |
|
750 |
case STAREQ: |
|
751 |
case SLASHEQ: |
|
752 |
case PERCENTEQ: |
|
753 |
case AMPEQ: |
|
754 |
case BAREQ: |
|
755 |
case CARETEQ: |
|
756 |
case LTLTEQ: |
|
757 |
case GTGTEQ: |
|
758 |
case GTGTGTEQ: |
|
10815 | 759 |
int pos = token.pos; |
760 |
TokenKind tk = token.kind; |
|
761 |
nextToken(); |
|
10 | 762 |
mode = EXPR; |
763 |
JCExpression t1 = term(); |
|
10815 | 764 |
return F.at(pos).Assignop(optag(tk), t, t1); |
10 | 765 |
default: |
766 |
return t; |
|
767 |
} |
|
768 |
} |
|
769 |
||
770 |
/** Expression1 = Expression2 [Expression1Rest] |
|
771 |
* Type1 = Type2 |
|
772 |
* TypeNoParams1 = TypeNoParams2 |
|
773 |
*/ |
|
774 |
JCExpression term1() { |
|
775 |
JCExpression t = term2(); |
|
10815 | 776 |
if ((mode & EXPR) != 0 && token.kind == QUES) { |
10 | 777 |
mode = EXPR; |
778 |
return term1Rest(t); |
|
779 |
} else { |
|
780 |
return t; |
|
781 |
} |
|
782 |
} |
|
783 |
||
784 |
/** Expression1Rest = ["?" Expression ":" Expression1] |
|
785 |
*/ |
|
786 |
JCExpression term1Rest(JCExpression t) { |
|
10815 | 787 |
if (token.kind == QUES) { |
788 |
int pos = token.pos; |
|
789 |
nextToken(); |
|
10 | 790 |
JCExpression t1 = term(); |
791 |
accept(COLON); |
|
792 |
JCExpression t2 = term1(); |
|
793 |
return F.at(pos).Conditional(t, t1, t2); |
|
794 |
} else { |
|
795 |
return t; |
|
796 |
} |
|
797 |
} |
|
798 |
||
799 |
/** Expression2 = Expression3 [Expression2Rest] |
|
800 |
* Type2 = Type3 |
|
801 |
* TypeNoParams2 = TypeNoParams3 |
|
802 |
*/ |
|
803 |
JCExpression term2() { |
|
804 |
JCExpression t = term3(); |
|
10815 | 805 |
if ((mode & EXPR) != 0 && prec(token.kind) >= TreeInfo.orPrec) { |
10 | 806 |
mode = EXPR; |
807 |
return term2Rest(t, TreeInfo.orPrec); |
|
808 |
} else { |
|
809 |
return t; |
|
810 |
} |
|
811 |
} |
|
812 |
||
813 |
/* Expression2Rest = {infixop Expression3} |
|
814 |
* | Expression3 instanceof Type |
|
815 |
* infixop = "||" |
|
816 |
* | "&&" |
|
817 |
* | "|" |
|
818 |
* | "^" |
|
819 |
* | "&" |
|
820 |
* | "==" | "!=" |
|
821 |
* | "<" | ">" | "<=" | ">=" |
|
822 |
* | "<<" | ">>" | ">>>" |
|
823 |
* | "+" | "-" |
|
824 |
* | "*" | "/" | "%" |
|
825 |
*/ |
|
826 |
JCExpression term2Rest(JCExpression t, int minprec) { |
|
827 |
JCExpression[] odStack = newOdStack(); |
|
828 |
Token[] opStack = newOpStack(); |
|
10815 | 829 |
|
10 | 830 |
// optimization, was odStack = new Tree[...]; opStack = new Tree[...]; |
831 |
int top = 0; |
|
832 |
odStack[0] = t; |
|
10815 | 833 |
int startPos = token.pos; |
834 |
Token topOp = Tokens.DUMMY; |
|
835 |
while (prec(token.kind) >= minprec) { |
|
10 | 836 |
opStack[top] = topOp; |
837 |
top++; |
|
10815 | 838 |
topOp = token; |
839 |
nextToken(); |
|
11322
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
840 |
odStack[top] = (topOp.kind == INSTANCEOF) ? parseType() : term3(); |
10815 | 841 |
while (top > 0 && prec(topOp.kind) >= prec(token.kind)) { |
842 |
odStack[top-1] = makeOp(topOp.pos, topOp.kind, odStack[top-1], |
|
10 | 843 |
odStack[top]); |
844 |
top--; |
|
845 |
topOp = opStack[top]; |
|
846 |
} |
|
847 |
} |
|
8032 | 848 |
Assert.check(top == 0); |
10 | 849 |
t = odStack[0]; |
850 |
||
10950 | 851 |
if (t.hasTag(JCTree.Tag.PLUS)) { |
14263 | 852 |
StringBuilder buf = foldStrings(t); |
10 | 853 |
if (buf != null) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
854 |
t = toP(F.at(startPos).Literal(TypeTag.CLASS, buf.toString())); |
10 | 855 |
} |
856 |
} |
|
857 |
||
14803
88347e495d34
8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents:
14725
diff
changeset
|
858 |
odStackSupply.add(odStack); |
88347e495d34
8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents:
14725
diff
changeset
|
859 |
opStackSupply.add(opStack); |
10 | 860 |
return t; |
861 |
} |
|
862 |
//where |
|
863 |
/** Construct a binary or type test node. |
|
864 |
*/ |
|
865 |
private JCExpression makeOp(int pos, |
|
10815 | 866 |
TokenKind topOp, |
10 | 867 |
JCExpression od1, |
868 |
JCExpression od2) |
|
869 |
{ |
|
870 |
if (topOp == INSTANCEOF) { |
|
871 |
return F.at(pos).TypeTest(od1, od2); |
|
872 |
} else { |
|
873 |
return F.at(pos).Binary(optag(topOp), od1, od2); |
|
874 |
} |
|
875 |
} |
|
876 |
/** If tree is a concatenation of string literals, replace it |
|
877 |
* by a single literal representing the concatenated string. |
|
878 |
*/ |
|
14263 | 879 |
protected StringBuilder foldStrings(JCTree tree) { |
10200
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
10199
diff
changeset
|
880 |
if (!allowStringFolding) |
56cc93e7b6ef
7068902: (javac) allow enabling or disabling of String folding
ksrini
parents:
10199
diff
changeset
|
881 |
return null; |
10 | 882 |
List<String> buf = List.nil(); |
883 |
while (true) { |
|
10950 | 884 |
if (tree.hasTag(LITERAL)) { |
10 | 885 |
JCLiteral lit = (JCLiteral) tree; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
886 |
if (lit.typetag == TypeTag.CLASS) { |
14263 | 887 |
StringBuilder sbuf = |
888 |
new StringBuilder((String)lit.value); |
|
10 | 889 |
while (buf.nonEmpty()) { |
890 |
sbuf.append(buf.head); |
|
891 |
buf = buf.tail; |
|
892 |
} |
|
893 |
return sbuf; |
|
894 |
} |
|
10950 | 895 |
} else if (tree.hasTag(JCTree.Tag.PLUS)) { |
10 | 896 |
JCBinary op = (JCBinary)tree; |
10950 | 897 |
if (op.rhs.hasTag(LITERAL)) { |
10 | 898 |
JCLiteral lit = (JCLiteral) op.rhs; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
899 |
if (lit.typetag == TypeTag.CLASS) { |
10 | 900 |
buf = buf.prepend((String) lit.value); |
901 |
tree = op.lhs; |
|
902 |
continue; |
|
903 |
} |
|
904 |
} |
|
905 |
} |
|
906 |
return null; |
|
907 |
} |
|
908 |
} |
|
909 |
||
910 |
/** optimization: To save allocating a new operand/operator stack |
|
911 |
* for every binary operation, we use supplys. |
|
912 |
*/ |
|
14803
88347e495d34
8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents:
14725
diff
changeset
|
913 |
ArrayList<JCExpression[]> odStackSupply = new ArrayList<JCExpression[]>(); |
88347e495d34
8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents:
14725
diff
changeset
|
914 |
ArrayList<Token[]> opStackSupply = new ArrayList<Token[]>(); |
10 | 915 |
|
916 |
private JCExpression[] newOdStack() { |
|
14803
88347e495d34
8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents:
14725
diff
changeset
|
917 |
if (odStackSupply.isEmpty()) |
88347e495d34
8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents:
14725
diff
changeset
|
918 |
return new JCExpression[infixPrecedenceLevels + 1]; |
88347e495d34
8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents:
14725
diff
changeset
|
919 |
return odStackSupply.remove(odStackSupply.size() - 1); |
10 | 920 |
} |
921 |
||
922 |
private Token[] newOpStack() { |
|
14803
88347e495d34
8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents:
14725
diff
changeset
|
923 |
if (opStackSupply.isEmpty()) |
88347e495d34
8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents:
14725
diff
changeset
|
924 |
return new Token[infixPrecedenceLevels + 1]; |
88347e495d34
8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents:
14725
diff
changeset
|
925 |
return opStackSupply.remove(opStackSupply.size() - 1); |
10 | 926 |
} |
927 |
||
13844 | 928 |
/** |
929 |
* Expression3 = PrefixOp Expression3 |
|
10 | 930 |
* | "(" Expr | TypeNoParams ")" Expression3 |
931 |
* | Primary {Selector} {PostfixOp} |
|
13844 | 932 |
* |
933 |
* {@literal |
|
10 | 934 |
* Primary = "(" Expression ")" |
935 |
* | Literal |
|
936 |
* | [TypeArguments] THIS [Arguments] |
|
937 |
* | [TypeArguments] SUPER SuperSuffix |
|
938 |
* | NEW [TypeArguments] Creator |
|
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
939 |
* | "(" Arguments ")" "->" ( Expression | Block ) |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
940 |
* | Ident "->" ( Expression | Block ) |
7072 | 941 |
* | Ident { "." Ident } |
11144
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
942 |
* | Expression3 MemberReferenceSuffix |
7072 | 943 |
* [ "[" ( "]" BracketsOpt "." CLASS | Expression "]" ) |
10 | 944 |
* | Arguments |
945 |
* | "." ( CLASS | THIS | [TypeArguments] SUPER Arguments | NEW [TypeArguments] InnerCreator ) |
|
946 |
* ] |
|
947 |
* | BasicType BracketsOpt "." CLASS |
|
13844 | 948 |
* } |
949 |
* |
|
10 | 950 |
* PrefixOp = "++" | "--" | "!" | "~" | "+" | "-" |
951 |
* PostfixOp = "++" | "--" |
|
952 |
* Type3 = Ident { "." Ident } [TypeArguments] {TypeSelector} BracketsOpt |
|
953 |
* | BasicType |
|
954 |
* TypeNoParams3 = Ident { "." Ident } BracketsOpt |
|
955 |
* Selector = "." [TypeArguments] Ident [Arguments] |
|
956 |
* | "." THIS |
|
957 |
* | "." [TypeArguments] SUPER SuperSuffix |
|
958 |
* | "." NEW [TypeArguments] InnerCreator |
|
959 |
* | "[" Expression "]" |
|
960 |
* TypeSelector = "." Ident [TypeArguments] |
|
961 |
* SuperSuffix = Arguments | "." Ident [Arguments] |
|
962 |
*/ |
|
963 |
protected JCExpression term3() { |
|
10815 | 964 |
int pos = token.pos; |
10 | 965 |
JCExpression t; |
966 |
List<JCExpression> typeArgs = typeArgumentsOpt(EXPR); |
|
10815 | 967 |
switch (token.kind) { |
10 | 968 |
case QUES: |
969 |
if ((mode & TYPE) != 0 && (mode & (TYPEARG|NOPARAMS)) == TYPEARG) { |
|
970 |
mode = TYPE; |
|
971 |
return typeArgument(); |
|
972 |
} else |
|
973 |
return illegal(); |
|
974 |
case PLUSPLUS: case SUBSUB: case BANG: case TILDE: case PLUS: case SUB: |
|
975 |
if (typeArgs == null && (mode & EXPR) != 0) { |
|
10815 | 976 |
TokenKind tk = token.kind; |
977 |
nextToken(); |
|
10 | 978 |
mode = EXPR; |
10815 | 979 |
if (tk == SUB && |
980 |
(token.kind == INTLITERAL || token.kind == LONGLITERAL) && |
|
981 |
token.radix() == 10) { |
|
10 | 982 |
mode = EXPR; |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
983 |
t = literal(names.hyphen, pos); |
10 | 984 |
} else { |
11322
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
985 |
t = term3(); |
10815 | 986 |
return F.at(pos).Unary(unoptag(tk), t); |
10 | 987 |
} |
988 |
} else return illegal(); |
|
989 |
break; |
|
990 |
case LPAREN: |
|
991 |
if (typeArgs == null && (mode & EXPR) != 0) { |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
992 |
ParensResult pres = analyzeParens(); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
993 |
switch (pres) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
994 |
case CAST: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
995 |
accept(LPAREN); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
996 |
mode = TYPE; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
997 |
int pos1 = pos; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
998 |
List<JCExpression> targets = List.of(t = term3()); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
999 |
while (token.kind == AMP) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1000 |
checkIntersectionTypesInCast(); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1001 |
accept(AMP); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1002 |
targets = targets.prepend(term3()); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1003 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1004 |
if (targets.length() > 1) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1005 |
t = toP(F.at(pos1).TypeIntersection(targets.reverse())); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1006 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1007 |
accept(RPAREN); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1008 |
mode = EXPR; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1009 |
JCExpression t1 = term3(); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1010 |
return F.at(pos).TypeCast(t, t1); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1011 |
case IMPLICIT_LAMBDA: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1012 |
case EXPLICIT_LAMBDA: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1013 |
t = lambdaExpressionOrStatement(true, pres == ParensResult.EXPLICIT_LAMBDA, pos); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1014 |
break; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1015 |
default: //PARENS |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1016 |
accept(LPAREN); |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1017 |
mode = EXPR; |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1018 |
t = termRest(term1Rest(term2Rest(term3(), TreeInfo.orPrec))); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1019 |
accept(RPAREN); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1020 |
t = toP(F.at(pos).Parens(t)); |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1021 |
break; |
10 | 1022 |
} |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1023 |
} else { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1024 |
return illegal(); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1025 |
} |
10 | 1026 |
break; |
1027 |
case THIS: |
|
1028 |
if ((mode & EXPR) != 0) { |
|
1029 |
mode = EXPR; |
|
1030 |
t = to(F.at(pos).Ident(names._this)); |
|
10815 | 1031 |
nextToken(); |
10 | 1032 |
if (typeArgs == null) |
1033 |
t = argumentsOpt(null, t); |
|
1034 |
else |
|
1035 |
t = arguments(typeArgs, t); |
|
1036 |
typeArgs = null; |
|
1037 |
} else return illegal(); |
|
1038 |
break; |
|
1039 |
case SUPER: |
|
1040 |
if ((mode & EXPR) != 0) { |
|
1041 |
mode = EXPR; |
|
4870
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
1042 |
t = to(F.at(pos).Ident(names._super)); |
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
1043 |
t = superSuffix(typeArgs, t); |
10 | 1044 |
typeArgs = null; |
1045 |
} else return illegal(); |
|
1046 |
break; |
|
1047 |
case INTLITERAL: case LONGLITERAL: case FLOATLITERAL: case DOUBLELITERAL: |
|
1048 |
case CHARLITERAL: case STRINGLITERAL: |
|
1049 |
case TRUE: case FALSE: case NULL: |
|
1050 |
if (typeArgs == null && (mode & EXPR) != 0) { |
|
1051 |
mode = EXPR; |
|
1052 |
t = literal(names.empty); |
|
1053 |
} else return illegal(); |
|
1054 |
break; |
|
1055 |
case NEW: |
|
1056 |
if (typeArgs != null) return illegal(); |
|
1057 |
if ((mode & EXPR) != 0) { |
|
1058 |
mode = EXPR; |
|
10815 | 1059 |
nextToken(); |
1060 |
if (token.kind == LT) typeArgs = typeArguments(false); |
|
10 | 1061 |
t = creator(pos, typeArgs); |
1062 |
typeArgs = null; |
|
1063 |
} else return illegal(); |
|
1064 |
break; |
|
15367 | 1065 |
case UNDERSCORE: case IDENTIFIER: case ASSERT: case ENUM: |
10 | 1066 |
if (typeArgs != null) return illegal(); |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1067 |
if ((mode & EXPR) != 0 && peekToken(ARROW)) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1068 |
t = lambdaExpressionOrStatement(false, false, pos); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1069 |
} else { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1070 |
t = toP(F.at(token.pos).Ident(ident())); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1071 |
loop: while (true) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1072 |
pos = token.pos; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1073 |
switch (token.kind) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1074 |
case LBRACKET: |
10815 | 1075 |
nextToken(); |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1076 |
if (token.kind == RBRACKET) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1077 |
nextToken(); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1078 |
t = bracketsOpt(t); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1079 |
t = toP(F.at(pos).TypeArray(t)); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1080 |
t = bracketsSuffix(t); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1081 |
} else { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1082 |
if ((mode & EXPR) != 0) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1083 |
mode = EXPR; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1084 |
JCExpression t1 = term(); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1085 |
t = to(F.at(pos).Indexed(t, t1)); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1086 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1087 |
accept(RBRACKET); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1088 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1089 |
break loop; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1090 |
case LPAREN: |
10 | 1091 |
if ((mode & EXPR) != 0) { |
1092 |
mode = EXPR; |
|
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1093 |
t = arguments(typeArgs, t); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1094 |
typeArgs = null; |
10 | 1095 |
} |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1096 |
break loop; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1097 |
case DOT: |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1098 |
nextToken(); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1099 |
int oldmode = mode; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1100 |
mode &= ~NOPARAMS; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1101 |
typeArgs = typeArgumentsOpt(EXPR); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1102 |
mode = oldmode; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1103 |
if ((mode & EXPR) != 0) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1104 |
switch (token.kind) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1105 |
case CLASS: |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1106 |
if (typeArgs != null) return illegal(); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1107 |
mode = EXPR; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1108 |
t = to(F.at(pos).Select(t, names._class)); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1109 |
nextToken(); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1110 |
break loop; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1111 |
case THIS: |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1112 |
if (typeArgs != null) return illegal(); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1113 |
mode = EXPR; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1114 |
t = to(F.at(pos).Select(t, names._this)); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1115 |
nextToken(); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1116 |
break loop; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1117 |
case SUPER: |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1118 |
mode = EXPR; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1119 |
t = to(F.at(pos).Select(t, names._super)); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1120 |
t = superSuffix(typeArgs, t); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1121 |
typeArgs = null; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1122 |
break loop; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1123 |
case NEW: |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1124 |
if (typeArgs != null) return illegal(); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1125 |
mode = EXPR; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1126 |
int pos1 = token.pos; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1127 |
nextToken(); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1128 |
if (token.kind == LT) typeArgs = typeArguments(false); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1129 |
t = innerCreator(pos1, typeArgs, t); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1130 |
typeArgs = null; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1131 |
break loop; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1132 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1133 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1134 |
// typeArgs saved for next loop iteration. |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1135 |
t = toP(F.at(pos).Select(t, ident())); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1136 |
break; |
11322
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1137 |
case LT: |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1138 |
if ((mode & TYPE) == 0 && isUnboundMemberRef()) { |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1139 |
//this is an unbound method reference whose qualifier |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1140 |
//is a generic type i.e. A<S>::m |
11322
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1141 |
int pos1 = token.pos; |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1142 |
accept(LT); |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1143 |
ListBuffer<JCExpression> args = new ListBuffer<JCExpression>(); |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1144 |
args.append(typeArgument()); |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1145 |
while (token.kind == COMMA) { |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1146 |
nextToken(); |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1147 |
args.append(typeArgument()); |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1148 |
} |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1149 |
accept(GT); |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1150 |
t = toP(F.at(pos1).TypeApply(t, args.toList())); |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1151 |
checkGenerics(); |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1152 |
while (token.kind == DOT) { |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1153 |
nextToken(); |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1154 |
mode = TYPE; |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1155 |
t = toP(F.at(token.pos).Select(t, ident())); |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1156 |
t = typeArgumentsOpt(t); |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1157 |
} |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1158 |
t = bracketsOpt(t); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1159 |
if (token.kind != COLCOL) { |
11322
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1160 |
//method reference expected here |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1161 |
t = illegal(); |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1162 |
} |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1163 |
mode = EXPR; |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1164 |
return term3Rest(t, typeArgs); |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1165 |
} |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1166 |
break loop; |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1167 |
default: |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1168 |
break loop; |
10 | 1169 |
} |
1170 |
} |
|
1171 |
} |
|
1172 |
if (typeArgs != null) illegal(); |
|
1173 |
t = typeArgumentsOpt(t); |
|
1174 |
break; |
|
1175 |
case BYTE: case SHORT: case CHAR: case INT: case LONG: case FLOAT: |
|
1176 |
case DOUBLE: case BOOLEAN: |
|
1177 |
if (typeArgs != null) illegal(); |
|
1178 |
t = bracketsSuffix(bracketsOpt(basicType())); |
|
1179 |
break; |
|
1180 |
case VOID: |
|
1181 |
if (typeArgs != null) illegal(); |
|
1182 |
if ((mode & EXPR) != 0) { |
|
10815 | 1183 |
nextToken(); |
1184 |
if (token.kind == DOT) { |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1185 |
JCPrimitiveTypeTree ti = toP(F.at(pos).TypeIdent(TypeTag.VOID)); |
10 | 1186 |
t = bracketsSuffix(ti); |
1187 |
} else { |
|
1188 |
return illegal(pos); |
|
1189 |
} |
|
1190 |
} else { |
|
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
1191 |
// Support the corner case of myMethodHandle.<void>invoke() by passing |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
1192 |
// a void type (like other primitive types) to the next phase. |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
1193 |
// The error will be reported in Attr.attribTypes or Attr.visitApply. |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
1194 |
JCPrimitiveTypeTree ti = to(F.at(pos).TypeIdent(TypeTag.VOID)); |
10815 | 1195 |
nextToken(); |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
1196 |
return ti; |
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
2212
diff
changeset
|
1197 |
//return illegal(); |
10 | 1198 |
} |
1199 |
break; |
|
1200 |
default: |
|
1201 |
return illegal(); |
|
1202 |
} |
|
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1203 |
return term3Rest(t, typeArgs); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1204 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1205 |
|
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1206 |
JCExpression term3Rest(JCExpression t, List<JCExpression> typeArgs) { |
10 | 1207 |
if (typeArgs != null) illegal(); |
1208 |
while (true) { |
|
10815 | 1209 |
int pos1 = token.pos; |
1210 |
if (token.kind == LBRACKET) { |
|
1211 |
nextToken(); |
|
10 | 1212 |
if ((mode & TYPE) != 0) { |
1213 |
int oldmode = mode; |
|
1214 |
mode = TYPE; |
|
10815 | 1215 |
if (token.kind == RBRACKET) { |
1216 |
nextToken(); |
|
7072 | 1217 |
t = bracketsOpt(t); |
10 | 1218 |
t = toP(F.at(pos1).TypeArray(t)); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1219 |
if (token.kind == COLCOL) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1220 |
mode = EXPR; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1221 |
continue; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1222 |
} |
10 | 1223 |
return t; |
1224 |
} |
|
1225 |
mode = oldmode; |
|
1226 |
} |
|
1227 |
if ((mode & EXPR) != 0) { |
|
1228 |
mode = EXPR; |
|
1229 |
JCExpression t1 = term(); |
|
1230 |
t = to(F.at(pos1).Indexed(t, t1)); |
|
1231 |
} |
|
1232 |
accept(RBRACKET); |
|
10815 | 1233 |
} else if (token.kind == DOT) { |
1234 |
nextToken(); |
|
10 | 1235 |
typeArgs = typeArgumentsOpt(EXPR); |
10815 | 1236 |
if (token.kind == SUPER && (mode & EXPR) != 0) { |
10 | 1237 |
mode = EXPR; |
1238 |
t = to(F.at(pos1).Select(t, names._super)); |
|
10815 | 1239 |
nextToken(); |
10 | 1240 |
t = arguments(typeArgs, t); |
1241 |
typeArgs = null; |
|
10815 | 1242 |
} else if (token.kind == NEW && (mode & EXPR) != 0) { |
10 | 1243 |
if (typeArgs != null) return illegal(); |
1244 |
mode = EXPR; |
|
10815 | 1245 |
int pos2 = token.pos; |
1246 |
nextToken(); |
|
1247 |
if (token.kind == LT) typeArgs = typeArguments(false); |
|
10 | 1248 |
t = innerCreator(pos2, typeArgs, t); |
1249 |
typeArgs = null; |
|
1250 |
} else { |
|
1251 |
t = toP(F.at(pos1).Select(t, ident())); |
|
1252 |
t = argumentsOpt(typeArgs, typeArgumentsOpt(t)); |
|
1253 |
typeArgs = null; |
|
1254 |
} |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1255 |
} else if ((mode & EXPR) != 0 && token.kind == COLCOL) { |
11144
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1256 |
mode = EXPR; |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1257 |
if (typeArgs != null) return illegal(); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1258 |
accept(COLCOL); |
11144
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1259 |
t = memberReferenceSuffix(pos1, t); |
10 | 1260 |
} else { |
1261 |
break; |
|
1262 |
} |
|
1263 |
} |
|
10815 | 1264 |
while ((token.kind == PLUSPLUS || token.kind == SUBSUB) && (mode & EXPR) != 0) { |
10 | 1265 |
mode = EXPR; |
10815 | 1266 |
t = to(F.at(token.pos).Unary( |
10950 | 1267 |
token.kind == PLUSPLUS ? POSTINC : POSTDEC, t)); |
10815 | 1268 |
nextToken(); |
10 | 1269 |
} |
1270 |
return toP(t); |
|
1271 |
} |
|
1272 |
||
11322
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1273 |
/** |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1274 |
* If we see an identifier followed by a '<' it could be an unbound |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1275 |
* method reference or a binary expression. To disambiguate, look for a |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1276 |
* matching '>' and see if the subsequent terminal is either '.' or '#'. |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1277 |
*/ |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1278 |
@SuppressWarnings("fallthrough") |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1279 |
boolean isUnboundMemberRef() { |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1280 |
int pos = 0, depth = 0; |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1281 |
for (Token t = S.token(pos) ; ; t = S.token(++pos)) { |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1282 |
switch (t.kind) { |
15367 | 1283 |
case IDENTIFIER: case UNDERSCORE: case QUES: case EXTENDS: case SUPER: |
11322
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1284 |
case DOT: case RBRACKET: case LBRACKET: case COMMA: |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1285 |
case BYTE: case SHORT: case INT: case LONG: case FLOAT: |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1286 |
case DOUBLE: case BOOLEAN: case CHAR: |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1287 |
break; |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1288 |
case LT: |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1289 |
depth++; break; |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1290 |
case GTGTGT: |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1291 |
depth--; |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1292 |
case GTGT: |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1293 |
depth--; |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1294 |
case GT: |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1295 |
depth--; |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1296 |
if (depth == 0) { |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1297 |
TokenKind nextKind = S.token(pos + 1).kind; |
11322
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1298 |
return |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1299 |
nextKind == TokenKind.DOT || |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1300 |
nextKind == TokenKind.LBRACKET || |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1301 |
nextKind == TokenKind.COLCOL; |
11322
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1302 |
} |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1303 |
break; |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1304 |
default: |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1305 |
return false; |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1306 |
} |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1307 |
} |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1308 |
} |
6ee85f80967a
7120463: Fix method reference parser support in order to avoid ambiguities
mcimadamore
parents:
11149
diff
changeset
|
1309 |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1310 |
/** |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1311 |
* If we see an identifier followed by a '<' it could be an unbound |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1312 |
* method reference or a binary expression. To disambiguate, look for a |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1313 |
* matching '>' and see if the subsequent terminal is either '.' or '#'. |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1314 |
*/ |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1315 |
@SuppressWarnings("fallthrough") |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1316 |
ParensResult analyzeParens() { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1317 |
int depth = 0; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1318 |
boolean type = false; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1319 |
for (int lookahead = 0 ; ; lookahead++) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1320 |
TokenKind tk = S.token(lookahead).kind; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1321 |
switch (tk) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1322 |
case EXTENDS: case SUPER: case COMMA: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1323 |
type = true; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1324 |
case QUES: case DOT: case AMP: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1325 |
//skip |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1326 |
break; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1327 |
case BYTE: case SHORT: case INT: case LONG: case FLOAT: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1328 |
case DOUBLE: case BOOLEAN: case CHAR: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1329 |
if (peekToken(lookahead, RPAREN)) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1330 |
//Type, ')' -> cast |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1331 |
return ParensResult.CAST; |
15367 | 1332 |
} else if (peekToken(lookahead, LAX_IDENTIFIER)) { |
1333 |
//Type, Identifier/'_'/'assert'/'enum' -> explicit lambda |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1334 |
return ParensResult.EXPLICIT_LAMBDA; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1335 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1336 |
break; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1337 |
case LPAREN: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1338 |
if (lookahead != 0) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1339 |
// '(' in a non-starting position -> parens |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1340 |
return ParensResult.PARENS; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1341 |
} else if (peekToken(lookahead, RPAREN)) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1342 |
// '(', ')' -> explicit lambda |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1343 |
return ParensResult.EXPLICIT_LAMBDA; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1344 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1345 |
break; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1346 |
case RPAREN: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1347 |
// if we have seen something that looks like a type, |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1348 |
// then it's a cast expression |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1349 |
if (type) return ParensResult.CAST; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1350 |
// otherwise, disambiguate cast vs. parenthesized expression |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1351 |
// based on subsequent token. |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1352 |
switch (S.token(lookahead + 1).kind) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1353 |
/*case PLUSPLUS: case SUBSUB: */ |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1354 |
case BANG: case TILDE: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1355 |
case LPAREN: case THIS: case SUPER: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1356 |
case INTLITERAL: case LONGLITERAL: case FLOATLITERAL: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1357 |
case DOUBLELITERAL: case CHARLITERAL: case STRINGLITERAL: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1358 |
case TRUE: case FALSE: case NULL: |
15367 | 1359 |
case NEW: case IDENTIFIER: case ASSERT: case ENUM: case UNDERSCORE: |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1360 |
case BYTE: case SHORT: case CHAR: case INT: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1361 |
case LONG: case FLOAT: case DOUBLE: case BOOLEAN: case VOID: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1362 |
return ParensResult.CAST; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1363 |
default: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1364 |
return ParensResult.PARENS; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1365 |
} |
15367 | 1366 |
case UNDERSCORE: |
1367 |
case ASSERT: |
|
1368 |
case ENUM: |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1369 |
case IDENTIFIER: |
15367 | 1370 |
if (peekToken(lookahead, LAX_IDENTIFIER)) { |
1371 |
// Identifier, Identifier/'_'/'assert'/'enum' -> explicit lambda |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1372 |
return ParensResult.EXPLICIT_LAMBDA; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1373 |
} else if (peekToken(lookahead, RPAREN, ARROW)) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1374 |
// Identifier, ')' '->' -> implicit lambda |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1375 |
return ParensResult.IMPLICIT_LAMBDA; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1376 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1377 |
break; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1378 |
case FINAL: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1379 |
case ELLIPSIS: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1380 |
case MONKEYS_AT: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1381 |
//those can only appear in explicit lambdas |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1382 |
return ParensResult.EXPLICIT_LAMBDA; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1383 |
case LBRACKET: |
15367 | 1384 |
if (peekToken(lookahead, RBRACKET, LAX_IDENTIFIER)) { |
1385 |
// '[', ']', Identifier/'_'/'assert'/'enum' -> explicit lambda |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1386 |
return ParensResult.EXPLICIT_LAMBDA; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1387 |
} else if (peekToken(lookahead, RBRACKET, RPAREN) || |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1388 |
peekToken(lookahead, RBRACKET, AMP)) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1389 |
// '[', ']', ')' -> cast |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1390 |
// '[', ']', '&' -> cast (intersection type) |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1391 |
return ParensResult.CAST; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1392 |
} else if (peekToken(lookahead, RBRACKET)) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1393 |
//consume the ']' and skip |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1394 |
type = true; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1395 |
lookahead++; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1396 |
break; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1397 |
} else { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1398 |
return ParensResult.PARENS; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1399 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1400 |
case LT: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1401 |
depth++; break; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1402 |
case GTGTGT: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1403 |
depth--; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1404 |
case GTGT: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1405 |
depth--; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1406 |
case GT: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1407 |
depth--; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1408 |
if (depth == 0) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1409 |
if (peekToken(lookahead, RPAREN) || |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1410 |
peekToken(lookahead, AMP)) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1411 |
// '>', ')' -> cast |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1412 |
// '>', '&' -> cast |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1413 |
return ParensResult.CAST; |
15367 | 1414 |
} else if (peekToken(lookahead, LAX_IDENTIFIER, COMMA) || |
1415 |
peekToken(lookahead, LAX_IDENTIFIER, RPAREN, ARROW) || |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1416 |
peekToken(lookahead, ELLIPSIS)) { |
15367 | 1417 |
// '>', Identifier/'_'/'assert'/'enum', ',' -> explicit lambda |
1418 |
// '>', Identifier/'_'/'assert'/'enum', ')', '->' -> explicit lambda |
|
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1419 |
// '>', '...' -> explicit lambda |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1420 |
return ParensResult.EXPLICIT_LAMBDA; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1421 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1422 |
//it looks a type, but could still be (i) a cast to generic type, |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1423 |
//(ii) an unbound method reference or (iii) an explicit lambda |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1424 |
type = true; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1425 |
break; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1426 |
} else if (depth < 0) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1427 |
//unbalanced '<', '>' - not a generic type |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1428 |
return ParensResult.PARENS; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1429 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1430 |
break; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1431 |
default: |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1432 |
//this includes EOF |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1433 |
return ParensResult.PARENS; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1434 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1435 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1436 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1437 |
|
15367 | 1438 |
/** Accepts all identifier-like tokens */ |
1439 |
Filter<TokenKind> LAX_IDENTIFIER = new Filter<TokenKind>() { |
|
1440 |
public boolean accepts(TokenKind t) { |
|
1441 |
return t == IDENTIFIER || t == UNDERSCORE || t == ASSERT || t == ENUM; |
|
1442 |
} |
|
1443 |
}; |
|
1444 |
||
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1445 |
enum ParensResult { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1446 |
CAST, |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1447 |
EXPLICIT_LAMBDA, |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1448 |
IMPLICIT_LAMBDA, |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1449 |
PARENS; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1450 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
1451 |
|
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1452 |
JCExpression lambdaExpressionOrStatement(boolean hasParens, boolean explicitParams, int pos) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1453 |
List<JCVariableDecl> params = explicitParams ? |
15367 | 1454 |
formalParameters(true) : |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1455 |
implicitParameters(hasParens); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1456 |
|
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1457 |
return lambdaExpressionOrStatementRest(params, pos); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1458 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1459 |
|
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1460 |
JCExpression lambdaExpressionOrStatementRest(List<JCVariableDecl> args, int pos) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1461 |
checkLambda(); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1462 |
accept(ARROW); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1463 |
|
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1464 |
return token.kind == LBRACE ? |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1465 |
lambdaStatement(args, pos, pos) : |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1466 |
lambdaExpression(args, pos); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1467 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1468 |
|
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1469 |
JCExpression lambdaStatement(List<JCVariableDecl> args, int pos, int pos2) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1470 |
JCBlock block = block(pos2, 0); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1471 |
return toP(F.at(pos).Lambda(args, block)); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1472 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1473 |
|
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1474 |
JCExpression lambdaExpression(List<JCVariableDecl> args, int pos) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1475 |
JCTree expr = parseExpression(); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1476 |
return toP(F.at(pos).Lambda(args, expr)); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1477 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
1478 |
|
10 | 1479 |
/** SuperSuffix = Arguments | "." [TypeArguments] Ident [Arguments] |
1480 |
*/ |
|
1481 |
JCExpression superSuffix(List<JCExpression> typeArgs, JCExpression t) { |
|
10815 | 1482 |
nextToken(); |
1483 |
if (token.kind == LPAREN || typeArgs != null) { |
|
10 | 1484 |
t = arguments(typeArgs, t); |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1485 |
} else if (token.kind == COLCOL) { |
11144
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1486 |
if (typeArgs != null) return illegal(); |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1487 |
t = memberReferenceSuffix(t); |
10 | 1488 |
} else { |
10815 | 1489 |
int pos = token.pos; |
10 | 1490 |
accept(DOT); |
10815 | 1491 |
typeArgs = (token.kind == LT) ? typeArguments(false) : null; |
10 | 1492 |
t = toP(F.at(pos).Select(t, ident())); |
1493 |
t = argumentsOpt(typeArgs, t); |
|
1494 |
} |
|
1495 |
return t; |
|
1496 |
} |
|
1497 |
||
1498 |
/** BasicType = BYTE | SHORT | CHAR | INT | LONG | FLOAT | DOUBLE | BOOLEAN |
|
1499 |
*/ |
|
1500 |
JCPrimitiveTypeTree basicType() { |
|
10815 | 1501 |
JCPrimitiveTypeTree t = to(F.at(token.pos).TypeIdent(typetag(token.kind))); |
1502 |
nextToken(); |
|
10 | 1503 |
return t; |
1504 |
} |
|
1505 |
||
1506 |
/** ArgumentsOpt = [ Arguments ] |
|
1507 |
*/ |
|
1508 |
JCExpression argumentsOpt(List<JCExpression> typeArgs, JCExpression t) { |
|
10815 | 1509 |
if ((mode & EXPR) != 0 && token.kind == LPAREN || typeArgs != null) { |
10 | 1510 |
mode = EXPR; |
1511 |
return arguments(typeArgs, t); |
|
1512 |
} else { |
|
1513 |
return t; |
|
1514 |
} |
|
1515 |
} |
|
1516 |
||
1517 |
/** Arguments = "(" [Expression { COMMA Expression }] ")" |
|
1518 |
*/ |
|
1519 |
List<JCExpression> arguments() { |
|
1520 |
ListBuffer<JCExpression> args = lb(); |
|
10815 | 1521 |
if (token.kind == LPAREN) { |
1522 |
nextToken(); |
|
1523 |
if (token.kind != RPAREN) { |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
1524 |
args.append(parseExpression()); |
10815 | 1525 |
while (token.kind == COMMA) { |
1526 |
nextToken(); |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
1527 |
args.append(parseExpression()); |
10 | 1528 |
} |
1529 |
} |
|
1530 |
accept(RPAREN); |
|
1531 |
} else { |
|
10815 | 1532 |
syntaxError(token.pos, "expected", LPAREN); |
10 | 1533 |
} |
1534 |
return args.toList(); |
|
1535 |
} |
|
1536 |
||
1537 |
JCMethodInvocation arguments(List<JCExpression> typeArgs, JCExpression t) { |
|
10815 | 1538 |
int pos = token.pos; |
10 | 1539 |
List<JCExpression> args = arguments(); |
1540 |
return toP(F.at(pos).Apply(typeArgs, t, args)); |
|
1541 |
} |
|
1542 |
||
1543 |
/** TypeArgumentsOpt = [ TypeArguments ] |
|
1544 |
*/ |
|
1545 |
JCExpression typeArgumentsOpt(JCExpression t) { |
|
10815 | 1546 |
if (token.kind == LT && |
10 | 1547 |
(mode & TYPE) != 0 && |
1548 |
(mode & NOPARAMS) == 0) { |
|
1549 |
mode = TYPE; |
|
1550 |
checkGenerics(); |
|
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1551 |
return typeArguments(t, false); |
10 | 1552 |
} else { |
1553 |
return t; |
|
1554 |
} |
|
1555 |
} |
|
1556 |
List<JCExpression> typeArgumentsOpt() { |
|
1557 |
return typeArgumentsOpt(TYPE); |
|
1558 |
} |
|
1559 |
||
1560 |
List<JCExpression> typeArgumentsOpt(int useMode) { |
|
10815 | 1561 |
if (token.kind == LT) { |
10 | 1562 |
checkGenerics(); |
1563 |
if ((mode & useMode) == 0 || |
|
1564 |
(mode & NOPARAMS) != 0) { |
|
1565 |
illegal(); |
|
1566 |
} |
|
1567 |
mode = useMode; |
|
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1568 |
return typeArguments(false); |
10 | 1569 |
} |
1570 |
return null; |
|
1571 |
} |
|
1572 |
||
13844 | 1573 |
/** |
1574 |
* {@literal |
|
1575 |
* TypeArguments = "<" TypeArgument {"," TypeArgument} ">" |
|
1576 |
* } |
|
10 | 1577 |
*/ |
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1578 |
List<JCExpression> typeArguments(boolean diamondAllowed) { |
10815 | 1579 |
if (token.kind == LT) { |
1580 |
nextToken(); |
|
1581 |
if (token.kind == GT && diamondAllowed) { |
|
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1582 |
checkDiamond(); |
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1583 |
mode |= DIAMOND; |
10815 | 1584 |
nextToken(); |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1585 |
return List.nil(); |
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1586 |
} else { |
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1587 |
ListBuffer<JCExpression> args = ListBuffer.lb(); |
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
1588 |
args.append(((mode & EXPR) == 0) ? typeArgument() : parseType()); |
10815 | 1589 |
while (token.kind == COMMA) { |
1590 |
nextToken(); |
|
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1591 |
args.append(((mode & EXPR) == 0) ? typeArgument() : parseType()); |
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1592 |
} |
10815 | 1593 |
switch (token.kind) { |
1594 |
||
1595 |
case GTGTGTEQ: case GTGTEQ: case GTEQ: |
|
1596 |
case GTGTGT: case GTGT: |
|
1597 |
token = S.split(); |
|
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1598 |
break; |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
1599 |
case GT: |
10815 | 1600 |
nextToken(); |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
1601 |
break; |
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1602 |
default: |
10815 | 1603 |
args.append(syntaxError(token.pos, "expected", GT)); |
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1604 |
break; |
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1605 |
} |
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1606 |
return args.toList(); |
10 | 1607 |
} |
1608 |
} else { |
|
10815 | 1609 |
return List.<JCExpression>of(syntaxError(token.pos, "expected", LT)); |
10 | 1610 |
} |
1611 |
} |
|
1612 |
||
13844 | 1613 |
/** |
1614 |
* {@literal |
|
1615 |
* TypeArgument = Type |
|
7072 | 1616 |
* | "?" |
1617 |
* | "?" EXTENDS Type {"&" Type} |
|
1618 |
* | "?" SUPER Type |
|
13844 | 1619 |
* } |
10 | 1620 |
*/ |
1621 |
JCExpression typeArgument() { |
|
10815 | 1622 |
if (token.kind != QUES) return parseType(); |
1623 |
int pos = token.pos; |
|
1624 |
nextToken(); |
|
1625 |
if (token.kind == EXTENDS) { |
|
4870
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
1626 |
TypeBoundKind t = to(F.at(pos).TypeBoundKind(BoundKind.EXTENDS)); |
10815 | 1627 |
nextToken(); |
4870
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
1628 |
JCExpression bound = parseType(); |
7072 | 1629 |
return F.at(pos).Wildcard(t, bound); |
10815 | 1630 |
} else if (token.kind == SUPER) { |
4870
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
1631 |
TypeBoundKind t = to(F.at(pos).TypeBoundKind(BoundKind.SUPER)); |
10815 | 1632 |
nextToken(); |
4870
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
1633 |
JCExpression bound = parseType(); |
7072 | 1634 |
return F.at(pos).Wildcard(t, bound); |
15367 | 1635 |
} else if (LAX_IDENTIFIER.accepts(token.kind)) { |
10 | 1636 |
//error recovery |
1637 |
TypeBoundKind t = F.at(Position.NOPOS).TypeBoundKind(BoundKind.UNBOUND); |
|
1638 |
JCExpression wc = toP(F.at(pos).Wildcard(t, null)); |
|
10815 | 1639 |
JCIdent id = toP(F.at(token.pos).Ident(ident())); |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
1640 |
JCErroneous err = F.at(pos).Erroneous(List.<JCTree>of(wc, id)); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
1641 |
reportSyntaxError(err, "expected3", GT, EXTENDS, SUPER); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
1642 |
return err; |
10 | 1643 |
} else { |
4870
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
1644 |
TypeBoundKind t = toP(F.at(pos).TypeBoundKind(BoundKind.UNBOUND)); |
7072 | 1645 |
return toP(F.at(pos).Wildcard(t, null)); |
10 | 1646 |
} |
1647 |
} |
|
1648 |
||
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1649 |
JCTypeApply typeArguments(JCExpression t, boolean diamondAllowed) { |
10815 | 1650 |
int pos = token.pos; |
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1651 |
List<JCExpression> args = typeArguments(diamondAllowed); |
10 | 1652 |
return toP(F.at(pos).TypeApply(t, args)); |
1653 |
} |
|
1654 |
||
7072 | 1655 |
/** BracketsOpt = {"[" "]"} |
10 | 1656 |
*/ |
7072 | 1657 |
private JCExpression bracketsOpt(JCExpression t) { |
10815 | 1658 |
if (token.kind == LBRACKET) { |
1659 |
int pos = token.pos; |
|
1660 |
nextToken(); |
|
7072 | 1661 |
t = bracketsOptCont(t, pos); |
1662 |
F.at(pos); |
|
10 | 1663 |
} |
1664 |
return t; |
|
1665 |
} |
|
1666 |
||
7072 | 1667 |
private JCArrayTypeTree bracketsOptCont(JCExpression t, int pos) { |
10 | 1668 |
accept(RBRACKET); |
7072 | 1669 |
t = bracketsOpt(t); |
10 | 1670 |
return toP(F.at(pos).TypeArray(t)); |
1671 |
} |
|
1672 |
||
1673 |
/** BracketsSuffixExpr = "." CLASS |
|
1674 |
* BracketsSuffixType = |
|
1675 |
*/ |
|
1676 |
JCExpression bracketsSuffix(JCExpression t) { |
|
10815 | 1677 |
if ((mode & EXPR) != 0 && token.kind == DOT) { |
10 | 1678 |
mode = EXPR; |
10815 | 1679 |
int pos = token.pos; |
1680 |
nextToken(); |
|
10 | 1681 |
accept(CLASS); |
11055 | 1682 |
if (token.pos == endPosTable.errorEndPos) { |
10 | 1683 |
// error recovery |
1684 |
Name name = null; |
|
15367 | 1685 |
if (LAX_IDENTIFIER.accepts(token.kind)) { |
10815 | 1686 |
name = token.name(); |
1687 |
nextToken(); |
|
10 | 1688 |
} else { |
1689 |
name = names.error; |
|
1690 |
} |
|
1691 |
t = F.at(pos).Erroneous(List.<JCTree>of(toP(F.at(pos).Select(t, name)))); |
|
1692 |
} else { |
|
1693 |
t = toP(F.at(pos).Select(t, names._class)); |
|
1694 |
} |
|
1695 |
} else if ((mode & TYPE) != 0) { |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1696 |
if (token.kind != COLCOL) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1697 |
mode = TYPE; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1698 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1699 |
} else if (token.kind != COLCOL) { |
10815 | 1700 |
syntaxError(token.pos, "dot.class.expected"); |
10 | 1701 |
} |
1702 |
return t; |
|
1703 |
} |
|
1704 |
||
11144
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1705 |
/** |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1706 |
* MemberReferenceSuffix = "::" [TypeArguments] Ident |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1707 |
* | "::" [TypeArguments] "new" |
11144
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1708 |
*/ |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1709 |
JCExpression memberReferenceSuffix(JCExpression t) { |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1710 |
int pos1 = token.pos; |
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
14058
diff
changeset
|
1711 |
accept(COLCOL); |
11144
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1712 |
return memberReferenceSuffix(pos1, t); |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1713 |
} |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1714 |
|
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1715 |
JCExpression memberReferenceSuffix(int pos1, JCExpression t) { |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1716 |
checkMethodReferences(); |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1717 |
mode = EXPR; |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1718 |
List<JCExpression> typeArgs = null; |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1719 |
if (token.kind == LT) { |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1720 |
typeArgs = typeArguments(false); |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1721 |
} |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1722 |
Name refName = null; |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1723 |
ReferenceMode refMode = null; |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1724 |
if (token.kind == NEW) { |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1725 |
refMode = ReferenceMode.NEW; |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1726 |
refName = names.init; |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1727 |
nextToken(); |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1728 |
} else { |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1729 |
refMode = ReferenceMode.INVOKE; |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1730 |
refName = ident(); |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1731 |
} |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1732 |
return toP(F.at(t.getStartPosition()).Reference(refMode, refName, t, typeArgs)); |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1733 |
} |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
1734 |
|
7072 | 1735 |
/** Creator = Qualident [TypeArguments] ( ArrayCreatorRest | ClassCreatorRest ) |
10 | 1736 |
*/ |
1737 |
JCExpression creator(int newpos, List<JCExpression> typeArgs) { |
|
10815 | 1738 |
switch (token.kind) { |
10 | 1739 |
case BYTE: case SHORT: case CHAR: case INT: case LONG: case FLOAT: |
1740 |
case DOUBLE: case BOOLEAN: |
|
7072 | 1741 |
if (typeArgs == null) |
1742 |
return arrayCreatorRest(newpos, basicType()); |
|
10 | 1743 |
break; |
1744 |
default: |
|
1745 |
} |
|
1746 |
JCExpression t = qualident(); |
|
1747 |
int oldmode = mode; |
|
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1748 |
mode = TYPE; |
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1749 |
boolean diamondFound = false; |
10199
48bd09ecc88a
7057297: Project Coin: diamond erroneously accepts in array initializer expressions
mcimadamore
parents:
9300
diff
changeset
|
1750 |
int lastTypeargsPos = -1; |
10815 | 1751 |
if (token.kind == LT) { |
10 | 1752 |
checkGenerics(); |
10815 | 1753 |
lastTypeargsPos = token.pos; |
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1754 |
t = typeArguments(t, true); |
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1755 |
diamondFound = (mode & DIAMOND) != 0; |
10 | 1756 |
} |
10815 | 1757 |
while (token.kind == DOT) { |
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1758 |
if (diamondFound) { |
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1759 |
//cannot select after a diamond |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
1760 |
illegal(); |
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1761 |
} |
10815 | 1762 |
int pos = token.pos; |
1763 |
nextToken(); |
|
10 | 1764 |
t = toP(F.at(pos).Select(t, ident())); |
10815 | 1765 |
if (token.kind == LT) { |
1766 |
lastTypeargsPos = token.pos; |
|
10 | 1767 |
checkGenerics(); |
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1768 |
t = typeArguments(t, true); |
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1769 |
diamondFound = (mode & DIAMOND) != 0; |
10 | 1770 |
} |
1771 |
} |
|
1772 |
mode = oldmode; |
|
10815 | 1773 |
if (token.kind == LBRACKET) { |
10 | 1774 |
JCExpression e = arrayCreatorRest(newpos, t); |
10199
48bd09ecc88a
7057297: Project Coin: diamond erroneously accepts in array initializer expressions
mcimadamore
parents:
9300
diff
changeset
|
1775 |
if (diamondFound) { |
48bd09ecc88a
7057297: Project Coin: diamond erroneously accepts in array initializer expressions
mcimadamore
parents:
9300
diff
changeset
|
1776 |
reportSyntaxError(lastTypeargsPos, "cannot.create.array.with.diamond"); |
48bd09ecc88a
7057297: Project Coin: diamond erroneously accepts in array initializer expressions
mcimadamore
parents:
9300
diff
changeset
|
1777 |
return toP(F.at(newpos).Erroneous(List.of(e))); |
48bd09ecc88a
7057297: Project Coin: diamond erroneously accepts in array initializer expressions
mcimadamore
parents:
9300
diff
changeset
|
1778 |
} |
48bd09ecc88a
7057297: Project Coin: diamond erroneously accepts in array initializer expressions
mcimadamore
parents:
9300
diff
changeset
|
1779 |
else if (typeArgs != null) { |
10 | 1780 |
int pos = newpos; |
1781 |
if (!typeArgs.isEmpty() && typeArgs.head.pos != Position.NOPOS) { |
|
1782 |
// note: this should always happen but we should |
|
1783 |
// not rely on this as the parser is continuously |
|
1784 |
// modified to improve error recovery. |
|
1785 |
pos = typeArgs.head.pos; |
|
1786 |
} |
|
10815 | 1787 |
setErrorEndPos(S.prevToken().endPos); |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
1788 |
JCErroneous err = F.at(pos).Erroneous(typeArgs.prepend(e)); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
1789 |
reportSyntaxError(err, "cannot.create.array.with.type.arguments"); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
1790 |
return toP(err); |
10 | 1791 |
} |
1792 |
return e; |
|
10815 | 1793 |
} else if (token.kind == LPAREN) { |
7072 | 1794 |
return classCreatorRest(newpos, null, typeArgs, t); |
10 | 1795 |
} else { |
10815 | 1796 |
setErrorEndPos(token.pos); |
1797 |
reportSyntaxError(token.pos, "expected2", LPAREN, LBRACKET); |
|
10 | 1798 |
t = toP(F.at(newpos).NewClass(null, typeArgs, t, List.<JCExpression>nil(), null)); |
1799 |
return toP(F.at(newpos).Erroneous(List.<JCTree>of(t))); |
|
1800 |
} |
|
1801 |
} |
|
1802 |
||
1803 |
/** InnerCreator = Ident [TypeArguments] ClassCreatorRest |
|
1804 |
*/ |
|
1805 |
JCExpression innerCreator(int newpos, List<JCExpression> typeArgs, JCExpression encl) { |
|
10815 | 1806 |
JCExpression t = toP(F.at(token.pos).Ident(ident())); |
1807 |
if (token.kind == LT) { |
|
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1808 |
int oldmode = mode; |
10 | 1809 |
checkGenerics(); |
9073
a29adf86aa0c
7030687: Diamond: compiler accepts erroneous code where diamond is used with non-generic inner class
mcimadamore
parents:
8625
diff
changeset
|
1810 |
t = typeArguments(t, true); |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
1811 |
mode = oldmode; |
10 | 1812 |
} |
1813 |
return classCreatorRest(newpos, encl, typeArgs, t); |
|
1814 |
} |
|
1815 |
||
7072 | 1816 |
/** ArrayCreatorRest = "[" ( "]" BracketsOpt ArrayInitializer |
1817 |
* | Expression "]" {"[" Expression "]"} BracketsOpt ) |
|
10 | 1818 |
*/ |
1819 |
JCExpression arrayCreatorRest(int newpos, JCExpression elemtype) { |
|
1820 |
accept(LBRACKET); |
|
10815 | 1821 |
if (token.kind == RBRACKET) { |
10 | 1822 |
accept(RBRACKET); |
7072 | 1823 |
elemtype = bracketsOpt(elemtype); |
10815 | 1824 |
if (token.kind == LBRACE) { |
7072 | 1825 |
return arrayInitializer(newpos, elemtype); |
10 | 1826 |
} else { |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
1827 |
JCExpression t = toP(F.at(newpos).NewArray(elemtype, List.<JCExpression>nil(), null)); |
10815 | 1828 |
return syntaxError(token.pos, List.<JCTree>of(t), "array.dimension.missing"); |
10 | 1829 |
} |
1830 |
} else { |
|
1831 |
ListBuffer<JCExpression> dims = new ListBuffer<JCExpression>(); |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
1832 |
dims.append(parseExpression()); |
10 | 1833 |
accept(RBRACKET); |
10815 | 1834 |
while (token.kind == LBRACKET) { |
1835 |
int pos = token.pos; |
|
1836 |
nextToken(); |
|
1837 |
if (token.kind == RBRACKET) { |
|
7072 | 1838 |
elemtype = bracketsOptCont(elemtype, pos); |
10 | 1839 |
} else { |
7072 | 1840 |
dims.append(parseExpression()); |
1841 |
accept(RBRACKET); |
|
10 | 1842 |
} |
1843 |
} |
|
7072 | 1844 |
return toP(F.at(newpos).NewArray(elemtype, dims.toList(), null)); |
10 | 1845 |
} |
1846 |
} |
|
1847 |
||
1848 |
/** ClassCreatorRest = Arguments [ClassBody] |
|
1849 |
*/ |
|
3149 | 1850 |
JCNewClass classCreatorRest(int newpos, |
10 | 1851 |
JCExpression encl, |
1852 |
List<JCExpression> typeArgs, |
|
1853 |
JCExpression t) |
|
1854 |
{ |
|
1855 |
List<JCExpression> args = arguments(); |
|
1856 |
JCClassDecl body = null; |
|
10815 | 1857 |
if (token.kind == LBRACE) { |
1858 |
int pos = token.pos; |
|
10 | 1859 |
List<JCTree> defs = classOrInterfaceBody(names.empty, false); |
1860 |
JCModifiers mods = F.at(Position.NOPOS).Modifiers(0); |
|
1861 |
body = toP(F.at(pos).AnonymousClassDef(mods, defs)); |
|
1862 |
} |
|
1863 |
return toP(F.at(newpos).NewClass(encl, typeArgs, t, args, body)); |
|
1864 |
} |
|
1865 |
||
1866 |
/** ArrayInitializer = "{" [VariableInitializer {"," VariableInitializer}] [","] "}" |
|
1867 |
*/ |
|
1868 |
JCExpression arrayInitializer(int newpos, JCExpression t) { |
|
1869 |
accept(LBRACE); |
|
1870 |
ListBuffer<JCExpression> elems = new ListBuffer<JCExpression>(); |
|
10815 | 1871 |
if (token.kind == COMMA) { |
1872 |
nextToken(); |
|
1873 |
} else if (token.kind != RBRACE) { |
|
10 | 1874 |
elems.append(variableInitializer()); |
10815 | 1875 |
while (token.kind == COMMA) { |
1876 |
nextToken(); |
|
1877 |
if (token.kind == RBRACE) break; |
|
10 | 1878 |
elems.append(variableInitializer()); |
1879 |
} |
|
1880 |
} |
|
1881 |
accept(RBRACE); |
|
1882 |
return toP(F.at(newpos).NewArray(t, List.<JCExpression>nil(), elems.toList())); |
|
1883 |
} |
|
1884 |
||
1885 |
/** VariableInitializer = ArrayInitializer | Expression |
|
1886 |
*/ |
|
1887 |
public JCExpression variableInitializer() { |
|
10815 | 1888 |
return token.kind == LBRACE ? arrayInitializer(token.pos, null) : parseExpression(); |
10 | 1889 |
} |
1890 |
||
1891 |
/** ParExpression = "(" Expression ")" |
|
1892 |
*/ |
|
1893 |
JCExpression parExpression() { |
|
11055 | 1894 |
int pos = token.pos; |
10 | 1895 |
accept(LPAREN); |
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
1896 |
JCExpression t = parseExpression(); |
10 | 1897 |
accept(RPAREN); |
11055 | 1898 |
return toP(F.at(pos).Parens(t)); |
10 | 1899 |
} |
1900 |
||
1901 |
/** Block = "{" BlockStatements "}" |
|
1902 |
*/ |
|
1903 |
JCBlock block(int pos, long flags) { |
|
1904 |
accept(LBRACE); |
|
1905 |
List<JCStatement> stats = blockStatements(); |
|
1906 |
JCBlock t = F.at(pos).Block(flags, stats); |
|
10815 | 1907 |
while (token.kind == CASE || token.kind == DEFAULT) { |
1908 |
syntaxError("orphaned", token.kind); |
|
10 | 1909 |
switchBlockStatementGroups(); |
1910 |
} |
|
1911 |
// the Block node has a field "endpos" for first char of last token, which is |
|
1912 |
// usually but not necessarily the last char of the last token. |
|
10815 | 1913 |
t.endpos = token.pos; |
10 | 1914 |
accept(RBRACE); |
1915 |
return toP(t); |
|
1916 |
} |
|
1917 |
||
1918 |
public JCBlock block() { |
|
10815 | 1919 |
return block(token.pos, 0); |
10 | 1920 |
} |
1921 |
||
1922 |
/** BlockStatements = { BlockStatement } |
|
1923 |
* BlockStatement = LocalVariableDeclarationStatement |
|
1924 |
* | ClassOrInterfaceOrEnumDeclaration |
|
1925 |
* | [Ident ":"] Statement |
|
1926 |
* LocalVariableDeclarationStatement |
|
1927 |
* = { FINAL | '@' Annotation } Type VariableDeclarators ";" |
|
1928 |
*/ |
|
1929 |
@SuppressWarnings("fallthrough") |
|
1930 |
List<JCStatement> blockStatements() { |
|
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1931 |
//todo: skip to anchor on error(?) |
10 | 1932 |
ListBuffer<JCStatement> stats = new ListBuffer<JCStatement>(); |
1933 |
while (true) { |
|
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1934 |
List<JCStatement> stat = blockStatement(); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1935 |
if (stat.isEmpty()) { |
10 | 1936 |
return stats.toList(); |
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1937 |
} else { |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1938 |
if (token.pos <= endPosTable.errorEndPos) { |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1939 |
skip(false, true, true, true); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1940 |
} |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1941 |
stats.addAll(stat); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1942 |
} |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1943 |
} |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1944 |
} |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1945 |
|
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1946 |
/* |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1947 |
* This method parses a statement treating it as a block, relaxing the |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1948 |
* JLS restrictions, allows us to parse more faulty code, doing so |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1949 |
* enables us to provide better and accurate diagnostics to the user. |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1950 |
*/ |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1951 |
JCStatement parseStatementAsBlock() { |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1952 |
int pos = token.pos; |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1953 |
List<JCStatement> stats = blockStatement(); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1954 |
if (stats.isEmpty()) { |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1955 |
JCErroneous e = F.at(pos).Erroneous(); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1956 |
error(e, "illegal.start.of.stmt"); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1957 |
return F.at(pos).Exec(e); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1958 |
} else { |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1959 |
JCStatement first = stats.head; |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1960 |
String error = null; |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1961 |
switch (first.getTag()) { |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1962 |
case CLASSDEF: |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1963 |
error = "class.not.allowed"; |
10 | 1964 |
break; |
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1965 |
case VARDEF: |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1966 |
error = "variable.not.allowed"; |
10 | 1967 |
break; |
1968 |
} |
|
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1969 |
if (error != null) { |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1970 |
error(first, error); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1971 |
List<JCBlock> blist = List.of(F.at(first.pos).Block(0, stats)); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1972 |
return toP(F.at(pos).Exec(F.at(first.pos).Erroneous(blist))); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1973 |
} |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1974 |
return first; |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1975 |
} |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1976 |
} |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1977 |
|
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1978 |
@SuppressWarnings("fallthrough") |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1979 |
List<JCStatement> blockStatement() { |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1980 |
//todo: skip to anchor on error(?) |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1981 |
int pos = token.pos; |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1982 |
switch (token.kind) { |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1983 |
case RBRACE: case CASE: case DEFAULT: case EOF: |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1984 |
return List.nil(); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1985 |
case LBRACE: case IF: case FOR: case WHILE: case DO: case TRY: |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1986 |
case SWITCH: case SYNCHRONIZED: case RETURN: case THROW: case BREAK: |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1987 |
case CONTINUE: case SEMI: case ELSE: case FINALLY: case CATCH: |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1988 |
return List.of(parseStatement()); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1989 |
case MONKEYS_AT: |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1990 |
case FINAL: { |
13077 | 1991 |
Comment dc = token.comment(CommentStyle.JAVADOC); |
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1992 |
JCModifiers mods = modifiersOpt(); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1993 |
if (token.kind == INTERFACE || |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1994 |
token.kind == CLASS || |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1995 |
allowEnums && token.kind == ENUM) { |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1996 |
return List.of(classOrInterfaceOrEnumDeclaration(mods, dc)); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1997 |
} else { |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1998 |
JCExpression t = parseType(); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
1999 |
ListBuffer<JCStatement> stats = |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2000 |
variableDeclarators(mods, t, new ListBuffer<JCStatement>()); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2001 |
// A "LocalVariableDeclarationStatement" subsumes the terminating semicolon |
14803
88347e495d34
8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents:
14725
diff
changeset
|
2002 |
storeEnd(stats.last(), token.endPos); |
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2003 |
accept(SEMI); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2004 |
return stats.toList(); |
10 | 2005 |
} |
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2006 |
} |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2007 |
case ABSTRACT: case STRICTFP: { |
13077 | 2008 |
Comment dc = token.comment(CommentStyle.JAVADOC); |
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2009 |
JCModifiers mods = modifiersOpt(); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2010 |
return List.of(classOrInterfaceOrEnumDeclaration(mods, dc)); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2011 |
} |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2012 |
case INTERFACE: |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2013 |
case CLASS: |
13077 | 2014 |
Comment dc = token.comment(CommentStyle.JAVADOC); |
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2015 |
return List.of(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc)); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2016 |
case ENUM: |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2017 |
case ASSERT: |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2018 |
if (allowEnums && token.kind == ENUM) { |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2019 |
error(token.pos, "local.enum"); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2020 |
dc = token.comment(CommentStyle.JAVADOC); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2021 |
return List.of(classOrInterfaceOrEnumDeclaration(modifiersOpt(), dc)); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2022 |
} else if (allowAsserts && token.kind == ASSERT) { |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2023 |
return List.of(parseStatement()); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2024 |
} |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2025 |
/* fall through to default */ |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2026 |
default: |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2027 |
Token prevToken = token; |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2028 |
JCExpression t = term(EXPR | TYPE); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2029 |
if (token.kind == COLON && t.hasTag(IDENT)) { |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2030 |
nextToken(); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2031 |
JCStatement stat = parseStatement(); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2032 |
return List.<JCStatement>of(F.at(pos).Labelled(prevToken.name(), stat)); |
15367 | 2033 |
} else if ((lastmode & TYPE) != 0 && LAX_IDENTIFIER.accepts(token.kind)) { |
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2034 |
pos = token.pos; |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2035 |
JCModifiers mods = F.at(Position.NOPOS).Modifiers(0); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2036 |
F.at(pos); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2037 |
ListBuffer<JCStatement> stats = |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2038 |
variableDeclarators(mods, t, new ListBuffer<JCStatement>()); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2039 |
// A "LocalVariableDeclarationStatement" subsumes the terminating semicolon |
14803
88347e495d34
8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents:
14725
diff
changeset
|
2040 |
storeEnd(stats.last(), token.endPos); |
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2041 |
accept(SEMI); |
10 | 2042 |
return stats.toList(); |
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2043 |
} else { |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2044 |
// This Exec is an "ExpressionStatement"; it subsumes the terminating semicolon |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2045 |
JCExpressionStatement expr = to(F.at(pos).Exec(checkExprStat(t))); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2046 |
accept(SEMI); |
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2047 |
return List.<JCStatement>of(expr); |
10 | 2048 |
} |
2049 |
} |
|
2050 |
} |
|
2051 |
||
2052 |
/** Statement = |
|
2053 |
* Block |
|
2054 |
* | IF ParExpression Statement [ELSE Statement] |
|
2055 |
* | FOR "(" ForInitOpt ";" [Expression] ";" ForUpdateOpt ")" Statement |
|
2056 |
* | FOR "(" FormalParameter : Expression ")" Statement |
|
2057 |
* | WHILE ParExpression Statement |
|
2058 |
* | DO Statement WHILE ParExpression ";" |
|
2059 |
* | TRY Block ( Catches | [Catches] FinallyPart ) |
|
8234
5050975e2df0
7014734: Project Coin: Allow optional trailing semicolon to terminate resources list in try-with-resources
darcy
parents:
8224
diff
changeset
|
2060 |
* | TRY "(" ResourceSpecification ";"opt ")" Block [Catches] [FinallyPart] |
10 | 2061 |
* | SWITCH ParExpression "{" SwitchBlockStatementGroups "}" |
2062 |
* | SYNCHRONIZED ParExpression Block |
|
2063 |
* | RETURN [Expression] ";" |
|
2064 |
* | THROW Expression ";" |
|
2065 |
* | BREAK [Ident] ";" |
|
2066 |
* | CONTINUE [Ident] ";" |
|
2067 |
* | ASSERT Expression [ ":" Expression ] ";" |
|
2068 |
* | ";" |
|
2069 |
* | ExpressionStatement |
|
2070 |
* | Ident ":" Statement |
|
2071 |
*/ |
|
2072 |
@SuppressWarnings("fallthrough") |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2073 |
public JCStatement parseStatement() { |
10815 | 2074 |
int pos = token.pos; |
2075 |
switch (token.kind) { |
|
10 | 2076 |
case LBRACE: |
2077 |
return block(); |
|
2078 |
case IF: { |
|
10815 | 2079 |
nextToken(); |
10 | 2080 |
JCExpression cond = parExpression(); |
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2081 |
JCStatement thenpart = parseStatementAsBlock(); |
10 | 2082 |
JCStatement elsepart = null; |
10815 | 2083 |
if (token.kind == ELSE) { |
2084 |
nextToken(); |
|
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2085 |
elsepart = parseStatementAsBlock(); |
10 | 2086 |
} |
2087 |
return F.at(pos).If(cond, thenpart, elsepart); |
|
2088 |
} |
|
2089 |
case FOR: { |
|
10815 | 2090 |
nextToken(); |
10 | 2091 |
accept(LPAREN); |
10815 | 2092 |
List<JCStatement> inits = token.kind == SEMI ? List.<JCStatement>nil() : forInit(); |
10 | 2093 |
if (inits.length() == 1 && |
10950 | 2094 |
inits.head.hasTag(VARDEF) && |
10 | 2095 |
((JCVariableDecl) inits.head).init == null && |
10815 | 2096 |
token.kind == COLON) { |
10 | 2097 |
checkForeach(); |
2098 |
JCVariableDecl var = (JCVariableDecl)inits.head; |
|
2099 |
accept(COLON); |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2100 |
JCExpression expr = parseExpression(); |
10 | 2101 |
accept(RPAREN); |
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2102 |
JCStatement body = parseStatementAsBlock(); |
10 | 2103 |
return F.at(pos).ForeachLoop(var, expr, body); |
2104 |
} else { |
|
2105 |
accept(SEMI); |
|
10815 | 2106 |
JCExpression cond = token.kind == SEMI ? null : parseExpression(); |
10 | 2107 |
accept(SEMI); |
10815 | 2108 |
List<JCExpressionStatement> steps = token.kind == RPAREN ? List.<JCExpressionStatement>nil() : forUpdate(); |
10 | 2109 |
accept(RPAREN); |
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2110 |
JCStatement body = parseStatementAsBlock(); |
10 | 2111 |
return F.at(pos).ForLoop(inits, cond, steps, body); |
2112 |
} |
|
2113 |
} |
|
2114 |
case WHILE: { |
|
10815 | 2115 |
nextToken(); |
10 | 2116 |
JCExpression cond = parExpression(); |
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2117 |
JCStatement body = parseStatementAsBlock(); |
10 | 2118 |
return F.at(pos).WhileLoop(cond, body); |
2119 |
} |
|
2120 |
case DO: { |
|
10815 | 2121 |
nextToken(); |
12466
08863ee323df
7156633: (javac) incorrect errors when parsing variable declaration in block statements.
ksrini
parents:
12337
diff
changeset
|
2122 |
JCStatement body = parseStatementAsBlock(); |
10 | 2123 |
accept(WHILE); |
2124 |
JCExpression cond = parExpression(); |
|
2125 |
JCDoWhileLoop t = to(F.at(pos).DoLoop(body, cond)); |
|
2126 |
accept(SEMI); |
|
2127 |
return t; |
|
2128 |
} |
|
2129 |
case TRY: { |
|
10815 | 2130 |
nextToken(); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2131 |
List<JCTree> resources = List.<JCTree>nil(); |
10815 | 2132 |
if (token.kind == LPAREN) { |
7211
163fe60f63de
6970016: Clean up ARM/try-with-resources implementation
mcimadamore
parents:
7076
diff
changeset
|
2133 |
checkTryWithResources(); |
10815 | 2134 |
nextToken(); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2135 |
resources = resources(); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2136 |
accept(RPAREN); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2137 |
} |
10 | 2138 |
JCBlock body = block(); |
2139 |
ListBuffer<JCCatch> catchers = new ListBuffer<JCCatch>(); |
|
2140 |
JCBlock finalizer = null; |
|
10815 | 2141 |
if (token.kind == CATCH || token.kind == FINALLY) { |
2142 |
while (token.kind == CATCH) catchers.append(catchClause()); |
|
2143 |
if (token.kind == FINALLY) { |
|
2144 |
nextToken(); |
|
10 | 2145 |
finalizer = block(); |
2146 |
} |
|
2147 |
} else { |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2148 |
if (allowTWR) { |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2149 |
if (resources.isEmpty()) |
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
7074
diff
changeset
|
2150 |
error(pos, "try.without.catch.finally.or.resource.decls"); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2151 |
} else |
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
7074
diff
changeset
|
2152 |
error(pos, "try.without.catch.or.finally"); |
10 | 2153 |
} |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2154 |
return F.at(pos).Try(resources, body, catchers.toList(), finalizer); |
10 | 2155 |
} |
2156 |
case SWITCH: { |
|
10815 | 2157 |
nextToken(); |
10 | 2158 |
JCExpression selector = parExpression(); |
2159 |
accept(LBRACE); |
|
2160 |
List<JCCase> cases = switchBlockStatementGroups(); |
|
2161 |
JCSwitch t = to(F.at(pos).Switch(selector, cases)); |
|
2162 |
accept(RBRACE); |
|
2163 |
return t; |
|
2164 |
} |
|
2165 |
case SYNCHRONIZED: { |
|
10815 | 2166 |
nextToken(); |
10 | 2167 |
JCExpression lock = parExpression(); |
2168 |
JCBlock body = block(); |
|
2169 |
return F.at(pos).Synchronized(lock, body); |
|
2170 |
} |
|
2171 |
case RETURN: { |
|
10815 | 2172 |
nextToken(); |
2173 |
JCExpression result = token.kind == SEMI ? null : parseExpression(); |
|
10 | 2174 |
JCReturn t = to(F.at(pos).Return(result)); |
2175 |
accept(SEMI); |
|
2176 |
return t; |
|
2177 |
} |
|
2178 |
case THROW: { |
|
10815 | 2179 |
nextToken(); |
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2180 |
JCExpression exc = parseExpression(); |
10 | 2181 |
JCThrow t = to(F.at(pos).Throw(exc)); |
2182 |
accept(SEMI); |
|
2183 |
return t; |
|
2184 |
} |
|
2185 |
case BREAK: { |
|
10815 | 2186 |
nextToken(); |
15367 | 2187 |
Name label = LAX_IDENTIFIER.accepts(token.kind) ? ident() : null; |
10 | 2188 |
JCBreak t = to(F.at(pos).Break(label)); |
2189 |
accept(SEMI); |
|
2190 |
return t; |
|
2191 |
} |
|
2192 |
case CONTINUE: { |
|
10815 | 2193 |
nextToken(); |
15367 | 2194 |
Name label = LAX_IDENTIFIER.accepts(token.kind) ? ident() : null; |
10 | 2195 |
JCContinue t = to(F.at(pos).Continue(label)); |
2196 |
accept(SEMI); |
|
2197 |
return t; |
|
2198 |
} |
|
2199 |
case SEMI: |
|
10815 | 2200 |
nextToken(); |
10 | 2201 |
return toP(F.at(pos).Skip()); |
2202 |
case ELSE: |
|
14450
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
2203 |
int elsePos = token.pos; |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
2204 |
nextToken(); |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
2205 |
return doRecover(elsePos, BasicErrorRecoveryAction.BLOCK_STMT, "else.without.if"); |
10 | 2206 |
case FINALLY: |
14450
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
2207 |
int finallyPos = token.pos; |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
2208 |
nextToken(); |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
2209 |
return doRecover(finallyPos, BasicErrorRecoveryAction.BLOCK_STMT, "finally.without.try"); |
10 | 2210 |
case CATCH: |
14450
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
2211 |
return doRecover(token.pos, BasicErrorRecoveryAction.CATCH_CLAUSE, "catch.without.try"); |
10 | 2212 |
case ASSERT: { |
10815 | 2213 |
if (allowAsserts && token.kind == ASSERT) { |
2214 |
nextToken(); |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2215 |
JCExpression assertion = parseExpression(); |
10 | 2216 |
JCExpression message = null; |
10815 | 2217 |
if (token.kind == COLON) { |
2218 |
nextToken(); |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2219 |
message = parseExpression(); |
10 | 2220 |
} |
2221 |
JCAssert t = to(F.at(pos).Assert(assertion, message)); |
|
2222 |
accept(SEMI); |
|
2223 |
return t; |
|
2224 |
} |
|
2225 |
/* else fall through to default case */ |
|
2226 |
} |
|
2227 |
case ENUM: |
|
2228 |
default: |
|
10815 | 2229 |
Token prevToken = token; |
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2230 |
JCExpression expr = parseExpression(); |
10950 | 2231 |
if (token.kind == COLON && expr.hasTag(IDENT)) { |
10815 | 2232 |
nextToken(); |
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2233 |
JCStatement stat = parseStatement(); |
10815 | 2234 |
return F.at(pos).Labelled(prevToken.name(), stat); |
10 | 2235 |
} else { |
2236 |
// This Exec is an "ExpressionStatement"; it subsumes the terminating semicolon |
|
2237 |
JCExpressionStatement stat = to(F.at(pos).Exec(checkExprStat(expr))); |
|
2238 |
accept(SEMI); |
|
2239 |
return stat; |
|
2240 |
} |
|
2241 |
} |
|
2242 |
} |
|
2243 |
||
14450
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
2244 |
private JCStatement doRecover(int startPos, ErrorRecoveryAction action, String key) { |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
2245 |
int errPos = S.errPos(); |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
2246 |
JCTree stm = action.doRecover(this); |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
2247 |
S.errPos(errPos); |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
2248 |
return toP(F.Exec(syntaxError(startPos, List.<JCTree>of(stm), key))); |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
2249 |
} |
7a62c5b13d6e
8000484: Bad error recovery when 'catch' without 'try' is found
vromero
parents:
14359
diff
changeset
|
2250 |
|
10 | 2251 |
/** CatchClause = CATCH "(" FormalParameter ")" Block |
2252 |
*/ |
|
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
2253 |
protected JCCatch catchClause() { |
10815 | 2254 |
int pos = token.pos; |
10 | 2255 |
accept(CATCH); |
2256 |
accept(LPAREN); |
|
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
2257 |
JCModifiers mods = optFinal(Flags.PARAMETER); |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
2258 |
List<JCExpression> catchTypes = catchTypes(); |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
2259 |
JCExpression paramType = catchTypes.size() > 1 ? |
9300
c2de4dd9853b
7033809: Rename "disjunctive" to "union" in javax.lang.model
darcy
parents:
9073
diff
changeset
|
2260 |
toP(F.at(catchTypes.head.getStartPosition()).TypeUnion(catchTypes)) : |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
2261 |
catchTypes.head; |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
2262 |
JCVariableDecl formal = variableDeclaratorId(mods, paramType); |
10 | 2263 |
accept(RPAREN); |
2264 |
JCBlock body = block(); |
|
2265 |
return F.at(pos).Catch(formal, body); |
|
2266 |
} |
|
2267 |
||
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
2268 |
List<JCExpression> catchTypes() { |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
2269 |
ListBuffer<JCExpression> catchTypes = ListBuffer.lb(); |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
2270 |
catchTypes.add(parseType()); |
10815 | 2271 |
while (token.kind == BAR) { |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
2272 |
checkMulticatch(); |
10815 | 2273 |
nextToken(); |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
2274 |
catchTypes.add(qualident()); |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
2275 |
} |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
2276 |
return catchTypes.toList(); |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
2277 |
} |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
2278 |
|
10 | 2279 |
/** SwitchBlockStatementGroups = { SwitchBlockStatementGroup } |
2280 |
* SwitchBlockStatementGroup = SwitchLabel BlockStatements |
|
2281 |
* SwitchLabel = CASE ConstantExpression ":" | DEFAULT ":" |
|
2282 |
*/ |
|
2283 |
List<JCCase> switchBlockStatementGroups() { |
|
2284 |
ListBuffer<JCCase> cases = new ListBuffer<JCCase>(); |
|
2285 |
while (true) { |
|
10815 | 2286 |
int pos = token.pos; |
2287 |
switch (token.kind) { |
|
14056 | 2288 |
case CASE: |
2289 |
case DEFAULT: |
|
2290 |
cases.append(switchBlockStatementGroup()); |
|
10 | 2291 |
break; |
2292 |
case RBRACE: case EOF: |
|
2293 |
return cases.toList(); |
|
2294 |
default: |
|
10815 | 2295 |
nextToken(); // to ensure progress |
10 | 2296 |
syntaxError(pos, "expected3", |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
2297 |
CASE, DEFAULT, RBRACE); |
10 | 2298 |
} |
2299 |
} |
|
2300 |
} |
|
2301 |
||
14056 | 2302 |
protected JCCase switchBlockStatementGroup() { |
2303 |
int pos = token.pos; |
|
2304 |
List<JCStatement> stats; |
|
2305 |
JCCase c; |
|
2306 |
switch (token.kind) { |
|
2307 |
case CASE: |
|
2308 |
nextToken(); |
|
2309 |
JCExpression pat = parseExpression(); |
|
2310 |
accept(COLON); |
|
2311 |
stats = blockStatements(); |
|
2312 |
c = F.at(pos).Case(pat, stats); |
|
2313 |
if (stats.isEmpty()) |
|
2314 |
storeEnd(c, S.prevToken().endPos); |
|
2315 |
return c; |
|
2316 |
case DEFAULT: |
|
2317 |
nextToken(); |
|
2318 |
accept(COLON); |
|
2319 |
stats = blockStatements(); |
|
2320 |
c = F.at(pos).Case(null, stats); |
|
2321 |
if (stats.isEmpty()) |
|
2322 |
storeEnd(c, S.prevToken().endPos); |
|
2323 |
return c; |
|
2324 |
} |
|
2325 |
throw new AssertionError("should not reach here"); |
|
2326 |
} |
|
2327 |
||
10 | 2328 |
/** MoreStatementExpressions = { COMMA StatementExpression } |
2329 |
*/ |
|
2330 |
<T extends ListBuffer<? super JCExpressionStatement>> T moreStatementExpressions(int pos, |
|
2331 |
JCExpression first, |
|
2332 |
T stats) { |
|
2333 |
// This Exec is a "StatementExpression"; it subsumes no terminating token |
|
2334 |
stats.append(toP(F.at(pos).Exec(checkExprStat(first)))); |
|
10815 | 2335 |
while (token.kind == COMMA) { |
2336 |
nextToken(); |
|
2337 |
pos = token.pos; |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2338 |
JCExpression t = parseExpression(); |
10 | 2339 |
// This Exec is a "StatementExpression"; it subsumes no terminating token |
2340 |
stats.append(toP(F.at(pos).Exec(checkExprStat(t)))); |
|
2341 |
} |
|
2342 |
return stats; |
|
2343 |
} |
|
2344 |
||
2345 |
/** ForInit = StatementExpression MoreStatementExpressions |
|
2346 |
* | { FINAL | '@' Annotation } Type VariableDeclarators |
|
2347 |
*/ |
|
2348 |
List<JCStatement> forInit() { |
|
2349 |
ListBuffer<JCStatement> stats = lb(); |
|
10815 | 2350 |
int pos = token.pos; |
2351 |
if (token.kind == FINAL || token.kind == MONKEYS_AT) { |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2352 |
return variableDeclarators(optFinal(0), parseType(), stats).toList(); |
10 | 2353 |
} else { |
2354 |
JCExpression t = term(EXPR | TYPE); |
|
15367 | 2355 |
if ((lastmode & TYPE) != 0 && LAX_IDENTIFIER.accepts(token.kind)) { |
10 | 2356 |
return variableDeclarators(modifiersOpt(), t, stats).toList(); |
12715
139b8354de6a
7159445: (javac) emits inaccurate diagnostics for enhanced for-loops
ksrini
parents:
12466
diff
changeset
|
2357 |
} else if ((lastmode & TYPE) != 0 && token.kind == COLON) { |
139b8354de6a
7159445: (javac) emits inaccurate diagnostics for enhanced for-loops
ksrini
parents:
12466
diff
changeset
|
2358 |
error(pos, "bad.initializer", "for-loop"); |
139b8354de6a
7159445: (javac) emits inaccurate diagnostics for enhanced for-loops
ksrini
parents:
12466
diff
changeset
|
2359 |
return List.of((JCStatement)F.at(pos).VarDef(null, null, t, null)); |
139b8354de6a
7159445: (javac) emits inaccurate diagnostics for enhanced for-loops
ksrini
parents:
12466
diff
changeset
|
2360 |
} else { |
10 | 2361 |
return moreStatementExpressions(pos, t, stats).toList(); |
12715
139b8354de6a
7159445: (javac) emits inaccurate diagnostics for enhanced for-loops
ksrini
parents:
12466
diff
changeset
|
2362 |
} |
10 | 2363 |
} |
2364 |
} |
|
2365 |
||
2366 |
/** ForUpdate = StatementExpression MoreStatementExpressions |
|
2367 |
*/ |
|
2368 |
List<JCExpressionStatement> forUpdate() { |
|
10815 | 2369 |
return moreStatementExpressions(token.pos, |
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2370 |
parseExpression(), |
10 | 2371 |
new ListBuffer<JCExpressionStatement>()).toList(); |
2372 |
} |
|
2373 |
||
2374 |
/** AnnotationsOpt = { '@' Annotation } |
|
2375 |
*/ |
|
7072 | 2376 |
List<JCAnnotation> annotationsOpt() { |
10815 | 2377 |
if (token.kind != MONKEYS_AT) return List.nil(); // optimization |
10 | 2378 |
ListBuffer<JCAnnotation> buf = new ListBuffer<JCAnnotation>(); |
10815 | 2379 |
while (token.kind == MONKEYS_AT) { |
2380 |
int pos = token.pos; |
|
2381 |
nextToken(); |
|
7072 | 2382 |
buf.append(annotation(pos)); |
10 | 2383 |
} |
7072 | 2384 |
return buf.toList(); |
10 | 2385 |
} |
2386 |
||
2387 |
/** ModifiersOpt = { Modifier } |
|
2388 |
* Modifier = PUBLIC | PROTECTED | PRIVATE | STATIC | ABSTRACT | FINAL |
|
2389 |
* | NATIVE | SYNCHRONIZED | TRANSIENT | VOLATILE | "@" |
|
2390 |
* | "@" Annotation |
|
2391 |
*/ |
|
2392 |
JCModifiers modifiersOpt() { |
|
2393 |
return modifiersOpt(null); |
|
2394 |
} |
|
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
2395 |
protected JCModifiers modifiersOpt(JCModifiers partial) { |
4870
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2396 |
long flags; |
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2397 |
ListBuffer<JCAnnotation> annotations = new ListBuffer<JCAnnotation>(); |
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2398 |
int pos; |
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2399 |
if (partial == null) { |
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2400 |
flags = 0; |
10815 | 2401 |
pos = token.pos; |
4870
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2402 |
} else { |
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2403 |
flags = partial.flags; |
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2404 |
annotations.appendList(partial.annotations); |
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2405 |
pos = partial.pos; |
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2406 |
} |
10948 | 2407 |
if (token.deprecatedFlag()) { |
10 | 2408 |
flags |= Flags.DEPRECATED; |
2409 |
} |
|
2410 |
int lastPos = Position.NOPOS; |
|
2411 |
loop: |
|
2412 |
while (true) { |
|
2413 |
long flag; |
|
10815 | 2414 |
switch (token.kind) { |
10 | 2415 |
case PRIVATE : flag = Flags.PRIVATE; break; |
2416 |
case PROTECTED : flag = Flags.PROTECTED; break; |
|
2417 |
case PUBLIC : flag = Flags.PUBLIC; break; |
|
2418 |
case STATIC : flag = Flags.STATIC; break; |
|
2419 |
case TRANSIENT : flag = Flags.TRANSIENT; break; |
|
2420 |
case FINAL : flag = Flags.FINAL; break; |
|
2421 |
case ABSTRACT : flag = Flags.ABSTRACT; break; |
|
2422 |
case NATIVE : flag = Flags.NATIVE; break; |
|
2423 |
case VOLATILE : flag = Flags.VOLATILE; break; |
|
2424 |
case SYNCHRONIZED: flag = Flags.SYNCHRONIZED; break; |
|
2425 |
case STRICTFP : flag = Flags.STRICTFP; break; |
|
2426 |
case MONKEYS_AT : flag = Flags.ANNOTATION; break; |
|
14267
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14263
diff
changeset
|
2427 |
case DEFAULT : checkDefaultMethods(); flag = Flags.DEFAULT; break; |
10815 | 2428 |
case ERROR : flag = 0; nextToken(); break; |
10 | 2429 |
default: break loop; |
2430 |
} |
|
10815 | 2431 |
if ((flags & flag) != 0) error(token.pos, "repeated.modifier"); |
2432 |
lastPos = token.pos; |
|
2433 |
nextToken(); |
|
10 | 2434 |
if (flag == Flags.ANNOTATION) { |
2435 |
checkAnnotations(); |
|
10815 | 2436 |
if (token.kind != INTERFACE) { |
7072 | 2437 |
JCAnnotation ann = annotation(lastPos); |
4870
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2438 |
// if first modifier is an annotation, set pos to annotation's. |
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2439 |
if (flags == 0 && annotations.isEmpty()) |
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2440 |
pos = ann.pos; |
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2441 |
annotations.append(ann); |
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2442 |
lastPos = ann.pos; |
10 | 2443 |
flag = 0; |
2444 |
} |
|
2445 |
} |
|
2446 |
flags |= flag; |
|
2447 |
} |
|
10815 | 2448 |
switch (token.kind) { |
10 | 2449 |
case ENUM: flags |= Flags.ENUM; break; |
2450 |
case INTERFACE: flags |= Flags.INTERFACE; break; |
|
2451 |
default: break; |
|
2452 |
} |
|
2453 |
||
2454 |
/* A modifiers tree with no modifier tokens or annotations |
|
2455 |
* has no text position. */ |
|
6152
111b884a19a7
6972327: JCTree.pos incorrect for annotations without modifiers and package
jjg
parents:
6148
diff
changeset
|
2456 |
if ((flags & (Flags.ModifierFlags | Flags.ANNOTATION)) == 0 && annotations.isEmpty()) |
10 | 2457 |
pos = Position.NOPOS; |
2458 |
||
2459 |
JCModifiers mods = F.at(pos).Modifiers(flags, annotations.toList()); |
|
2460 |
if (pos != Position.NOPOS) |
|
10815 | 2461 |
storeEnd(mods, S.prevToken().endPos); |
10 | 2462 |
return mods; |
2463 |
} |
|
2464 |
||
2465 |
/** Annotation = "@" Qualident [ "(" AnnotationFieldValues ")" ] |
|
2466 |
* @param pos position of "@" token |
|
2467 |
*/ |
|
7072 | 2468 |
JCAnnotation annotation(int pos) { |
10 | 2469 |
// accept(AT); // AT consumed by caller |
2470 |
checkAnnotations(); |
|
2471 |
JCTree ident = qualident(); |
|
2472 |
List<JCExpression> fieldValues = annotationFieldValuesOpt(); |
|
7072 | 2473 |
JCAnnotation ann = F.at(pos).Annotation(ident, fieldValues); |
10815 | 2474 |
storeEnd(ann, S.prevToken().endPos); |
10 | 2475 |
return ann; |
2476 |
} |
|
2477 |
||
2478 |
List<JCExpression> annotationFieldValuesOpt() { |
|
10815 | 2479 |
return (token.kind == LPAREN) ? annotationFieldValues() : List.<JCExpression>nil(); |
10 | 2480 |
} |
2481 |
||
2482 |
/** AnnotationFieldValues = "(" [ AnnotationFieldValue { "," AnnotationFieldValue } ] ")" */ |
|
2483 |
List<JCExpression> annotationFieldValues() { |
|
2484 |
accept(LPAREN); |
|
2485 |
ListBuffer<JCExpression> buf = new ListBuffer<JCExpression>(); |
|
10815 | 2486 |
if (token.kind != RPAREN) { |
10 | 2487 |
buf.append(annotationFieldValue()); |
10815 | 2488 |
while (token.kind == COMMA) { |
2489 |
nextToken(); |
|
10 | 2490 |
buf.append(annotationFieldValue()); |
2491 |
} |
|
2492 |
} |
|
2493 |
accept(RPAREN); |
|
2494 |
return buf.toList(); |
|
2495 |
} |
|
2496 |
||
2497 |
/** AnnotationFieldValue = AnnotationValue |
|
2498 |
* | Identifier "=" AnnotationValue |
|
2499 |
*/ |
|
2500 |
JCExpression annotationFieldValue() { |
|
10815 | 2501 |
if (token.kind == IDENTIFIER) { |
10 | 2502 |
mode = EXPR; |
2503 |
JCExpression t1 = term1(); |
|
10950 | 2504 |
if (t1.hasTag(IDENT) && token.kind == EQ) { |
10815 | 2505 |
int pos = token.pos; |
10 | 2506 |
accept(EQ); |
4870
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2507 |
JCExpression v = annotationValue(); |
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2508 |
return toP(F.at(pos).Assign(t1, v)); |
10 | 2509 |
} else { |
2510 |
return t1; |
|
2511 |
} |
|
2512 |
} |
|
2513 |
return annotationValue(); |
|
2514 |
} |
|
2515 |
||
2516 |
/* AnnotationValue = ConditionalExpression |
|
2517 |
* | Annotation |
|
3997
35250de1d4ea
6337964: should ignore last comma in annotation array
darcy
parents:
3894
diff
changeset
|
2518 |
* | "{" [ AnnotationValue { "," AnnotationValue } ] [","] "}" |
10 | 2519 |
*/ |
2520 |
JCExpression annotationValue() { |
|
2521 |
int pos; |
|
10815 | 2522 |
switch (token.kind) { |
10 | 2523 |
case MONKEYS_AT: |
10815 | 2524 |
pos = token.pos; |
2525 |
nextToken(); |
|
7072 | 2526 |
return annotation(pos); |
10 | 2527 |
case LBRACE: |
10815 | 2528 |
pos = token.pos; |
10 | 2529 |
accept(LBRACE); |
2530 |
ListBuffer<JCExpression> buf = new ListBuffer<JCExpression>(); |
|
10815 | 2531 |
if (token.kind != RBRACE) { |
10 | 2532 |
buf.append(annotationValue()); |
10815 | 2533 |
while (token.kind == COMMA) { |
2534 |
nextToken(); |
|
2535 |
if (token.kind == RBRACE) break; |
|
10 | 2536 |
buf.append(annotationValue()); |
2537 |
} |
|
2538 |
} |
|
2539 |
accept(RBRACE); |
|
2540 |
return toP(F.at(pos).NewArray(null, List.<JCExpression>nil(), buf.toList())); |
|
2541 |
default: |
|
2542 |
mode = EXPR; |
|
2543 |
return term1(); |
|
2544 |
} |
|
2545 |
} |
|
2546 |
||
2547 |
/** VariableDeclarators = VariableDeclarator { "," VariableDeclarator } |
|
2548 |
*/ |
|
2549 |
public <T extends ListBuffer<? super JCVariableDecl>> T variableDeclarators(JCModifiers mods, |
|
2550 |
JCExpression type, |
|
2551 |
T vdefs) |
|
2552 |
{ |
|
10815 | 2553 |
return variableDeclaratorsRest(token.pos, mods, type, ident(), false, null, vdefs); |
10 | 2554 |
} |
2555 |
||
2556 |
/** VariableDeclaratorsRest = VariableDeclaratorRest { "," VariableDeclarator } |
|
2557 |
* ConstantDeclaratorsRest = ConstantDeclaratorRest { "," ConstantDeclarator } |
|
2558 |
* |
|
2559 |
* @param reqInit Is an initializer always required? |
|
2560 |
* @param dc The documentation comment for the variable declarations, or null. |
|
2561 |
*/ |
|
2562 |
<T extends ListBuffer<? super JCVariableDecl>> T variableDeclaratorsRest(int pos, |
|
2563 |
JCModifiers mods, |
|
2564 |
JCExpression type, |
|
2565 |
Name name, |
|
2566 |
boolean reqInit, |
|
13077 | 2567 |
Comment dc, |
10 | 2568 |
T vdefs) |
2569 |
{ |
|
2570 |
vdefs.append(variableDeclaratorRest(pos, mods, type, name, reqInit, dc)); |
|
10815 | 2571 |
while (token.kind == COMMA) { |
10 | 2572 |
// All but last of multiple declarators subsume a comma |
14803
88347e495d34
8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents:
14725
diff
changeset
|
2573 |
storeEnd((JCTree)vdefs.last(), token.endPos); |
10815 | 2574 |
nextToken(); |
10 | 2575 |
vdefs.append(variableDeclarator(mods, type, reqInit, dc)); |
2576 |
} |
|
2577 |
return vdefs; |
|
2578 |
} |
|
2579 |
||
2580 |
/** VariableDeclarator = Ident VariableDeclaratorRest |
|
2581 |
* ConstantDeclarator = Ident ConstantDeclaratorRest |
|
2582 |
*/ |
|
13077 | 2583 |
JCVariableDecl variableDeclarator(JCModifiers mods, JCExpression type, boolean reqInit, Comment dc) { |
10815 | 2584 |
return variableDeclaratorRest(token.pos, mods, type, ident(), reqInit, dc); |
10 | 2585 |
} |
2586 |
||
2587 |
/** VariableDeclaratorRest = BracketsOpt ["=" VariableInitializer] |
|
2588 |
* ConstantDeclaratorRest = BracketsOpt "=" VariableInitializer |
|
2589 |
* |
|
2590 |
* @param reqInit Is an initializer always required? |
|
2591 |
* @param dc The documentation comment for the variable declarations, or null. |
|
2592 |
*/ |
|
2593 |
JCVariableDecl variableDeclaratorRest(int pos, JCModifiers mods, JCExpression type, Name name, |
|
13077 | 2594 |
boolean reqInit, Comment dc) { |
10 | 2595 |
type = bracketsOpt(type); |
2596 |
JCExpression init = null; |
|
10815 | 2597 |
if (token.kind == EQ) { |
2598 |
nextToken(); |
|
10 | 2599 |
init = variableInitializer(); |
2600 |
} |
|
10815 | 2601 |
else if (reqInit) syntaxError(token.pos, "expected", EQ); |
10 | 2602 |
JCVariableDecl result = |
2603 |
toP(F.at(pos).VarDef(mods, name, type, init)); |
|
2604 |
attach(result, dc); |
|
2605 |
return result; |
|
2606 |
} |
|
2607 |
||
2608 |
/** VariableDeclaratorId = Ident BracketsOpt |
|
2609 |
*/ |
|
2610 |
JCVariableDecl variableDeclaratorId(JCModifiers mods, JCExpression type) { |
|
15367 | 2611 |
return variableDeclaratorId(mods, type, false); |
2612 |
} |
|
2613 |
//where |
|
2614 |
JCVariableDecl variableDeclaratorId(JCModifiers mods, JCExpression type, boolean lambdaParameter) { |
|
10815 | 2615 |
int pos = token.pos; |
15367 | 2616 |
Name name; |
2617 |
if (lambdaParameter && token.kind == UNDERSCORE) { |
|
2618 |
syntaxError(pos, "expected", IDENTIFIER); |
|
2619 |
name = token.name(); |
|
2620 |
} else { |
|
2621 |
name = ident(); |
|
2622 |
} |
|
8047
c7f08cdb5c3c
6569633: Varargs: parser error when varargs element type is an array
mcimadamore
parents:
8033
diff
changeset
|
2623 |
if ((mods.flags & Flags.VARARGS) != 0 && |
10815 | 2624 |
token.kind == LBRACKET) { |
2625 |
log.error(token.pos, "varargs.and.old.array.syntax"); |
|
8047
c7f08cdb5c3c
6569633: Varargs: parser error when varargs element type is an array
mcimadamore
parents:
8033
diff
changeset
|
2626 |
} |
c7f08cdb5c3c
6569633: Varargs: parser error when varargs element type is an array
mcimadamore
parents:
8033
diff
changeset
|
2627 |
type = bracketsOpt(type); |
10 | 2628 |
return toP(F.at(pos).VarDef(mods, name, type, null)); |
2629 |
} |
|
2630 |
||
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2631 |
/** Resources = Resource { ";" Resources } |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2632 |
*/ |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2633 |
List<JCTree> resources() { |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2634 |
ListBuffer<JCTree> defs = new ListBuffer<JCTree>(); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2635 |
defs.append(resource()); |
10815 | 2636 |
while (token.kind == SEMI) { |
8234
5050975e2df0
7014734: Project Coin: Allow optional trailing semicolon to terminate resources list in try-with-resources
darcy
parents:
8224
diff
changeset
|
2637 |
// All but last of multiple declarators must subsume a semicolon |
14803
88347e495d34
8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents:
14725
diff
changeset
|
2638 |
storeEnd(defs.last(), token.endPos); |
10815 | 2639 |
int semiColonPos = token.pos; |
2640 |
nextToken(); |
|
2641 |
if (token.kind == RPAREN) { // Optional trailing semicolon |
|
8224
8f18e1622660
7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents:
8047
diff
changeset
|
2642 |
// after last resource |
8f18e1622660
7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents:
8047
diff
changeset
|
2643 |
break; |
8f18e1622660
7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents:
8047
diff
changeset
|
2644 |
} |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2645 |
defs.append(resource()); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2646 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2647 |
return defs.toList(); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2648 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2649 |
|
8224
8f18e1622660
7013420: Project Coin: remove general expression support from try-with-resources statement
darcy
parents:
8047
diff
changeset
|
2650 |
/** Resource = VariableModifiersOpt Type VariableDeclaratorId = Expression |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2651 |
*/ |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
2652 |
protected JCTree resource() { |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
2653 |
JCModifiers optFinal = optFinal(Flags.FINAL); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
2654 |
JCExpression type = parseType(); |
10815 | 2655 |
int pos = token.pos; |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
2656 |
Name ident = ident(); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
2657 |
return variableDeclaratorRest(pos, optFinal, type, ident, true, null); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2658 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
2659 |
|
10 | 2660 |
/** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration} |
2661 |
*/ |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2662 |
public JCTree.JCCompilationUnit parseCompilationUnit() { |
10815 | 2663 |
Token firstToken = token; |
10 | 2664 |
JCExpression pid = null; |
2665 |
JCModifiers mods = null; |
|
10815 | 2666 |
boolean consumedToplevelDoc = false; |
2667 |
boolean seenImport = false; |
|
2668 |
boolean seenPackage = false; |
|
10 | 2669 |
List<JCAnnotation> packageAnnotations = List.nil(); |
10815 | 2670 |
if (token.kind == MONKEYS_AT) |
10 | 2671 |
mods = modifiersOpt(); |
2672 |
||
10815 | 2673 |
if (token.kind == PACKAGE) { |
2674 |
seenPackage = true; |
|
10 | 2675 |
if (mods != null) { |
2676 |
checkNoMods(mods.flags); |
|
2677 |
packageAnnotations = mods.annotations; |
|
2678 |
mods = null; |
|
2679 |
} |
|
10815 | 2680 |
nextToken(); |
10 | 2681 |
pid = qualident(); |
2682 |
accept(SEMI); |
|
2683 |
} |
|
2684 |
ListBuffer<JCTree> defs = new ListBuffer<JCTree>(); |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2685 |
boolean checkForImports = true; |
10815 | 2686 |
boolean firstTypeDecl = true; |
2687 |
while (token.kind != EOF) { |
|
11055 | 2688 |
if (token.pos <= endPosTable.errorEndPos) { |
10 | 2689 |
// error recovery |
2690 |
skip(checkForImports, false, false, false); |
|
10815 | 2691 |
if (token.kind == EOF) |
10 | 2692 |
break; |
2693 |
} |
|
10815 | 2694 |
if (checkForImports && mods == null && token.kind == IMPORT) { |
2695 |
seenImport = true; |
|
10 | 2696 |
defs.append(importDeclaration()); |
2697 |
} else { |
|
13077 | 2698 |
Comment docComment = token.comment(CommentStyle.JAVADOC); |
10815 | 2699 |
if (firstTypeDecl && !seenImport && !seenPackage) { |
10948 | 2700 |
docComment = firstToken.comment(CommentStyle.JAVADOC); |
10815 | 2701 |
consumedToplevelDoc = true; |
6716
71df48777dd1
6877202: Elements.getDocComment() is not getting JavaDocComments
jjg
parents:
6585
diff
changeset
|
2702 |
} |
10815 | 2703 |
JCTree def = typeDeclaration(mods, docComment); |
10 | 2704 |
if (def instanceof JCExpressionStatement) |
2705 |
def = ((JCExpressionStatement)def).expr; |
|
2706 |
defs.append(def); |
|
2707 |
if (def instanceof JCClassDecl) |
|
2708 |
checkForImports = false; |
|
2709 |
mods = null; |
|
10815 | 2710 |
firstTypeDecl = false; |
10 | 2711 |
} |
2712 |
} |
|
10815 | 2713 |
JCTree.JCCompilationUnit toplevel = F.at(firstToken.pos).TopLevel(packageAnnotations, pid, defs.toList()); |
2714 |
if (!consumedToplevelDoc) |
|
10948 | 2715 |
attach(toplevel, firstToken.comment(CommentStyle.JAVADOC)); |
14803
88347e495d34
8004504: ListBuffer could reuse List.nil() as the sentinel element
jlahoda
parents:
14725
diff
changeset
|
2716 |
if (defs.isEmpty()) |
10815 | 2717 |
storeEnd(toplevel, S.prevToken().endPos); |
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2718 |
if (keepDocComments) |
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2719 |
toplevel.docComments = docComments; |
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2720 |
if (keepLineMap) |
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2721 |
toplevel.lineMap = S.getLineMap(); |
11055 | 2722 |
toplevel.endPositions = this.endPosTable; |
10 | 2723 |
return toplevel; |
2724 |
} |
|
2725 |
||
2726 |
/** ImportDeclaration = IMPORT [ STATIC ] Ident { "." Ident } [ "." "*" ] ";" |
|
2727 |
*/ |
|
2728 |
JCTree importDeclaration() { |
|
10815 | 2729 |
int pos = token.pos; |
2730 |
nextToken(); |
|
10 | 2731 |
boolean importStatic = false; |
10815 | 2732 |
if (token.kind == STATIC) { |
10 | 2733 |
checkStaticImports(); |
2734 |
importStatic = true; |
|
10815 | 2735 |
nextToken(); |
10 | 2736 |
} |
10815 | 2737 |
JCExpression pid = toP(F.at(token.pos).Ident(ident())); |
10 | 2738 |
do { |
10815 | 2739 |
int pos1 = token.pos; |
10 | 2740 |
accept(DOT); |
10815 | 2741 |
if (token.kind == STAR) { |
10 | 2742 |
pid = to(F.at(pos1).Select(pid, names.asterisk)); |
10815 | 2743 |
nextToken(); |
10 | 2744 |
break; |
2745 |
} else { |
|
2746 |
pid = toP(F.at(pos1).Select(pid, ident())); |
|
2747 |
} |
|
10815 | 2748 |
} while (token.kind == DOT); |
10 | 2749 |
accept(SEMI); |
2750 |
return toP(F.at(pos).Import(pid, importStatic)); |
|
2751 |
} |
|
2752 |
||
2753 |
/** TypeDeclaration = ClassOrInterfaceOrEnumDeclaration |
|
2754 |
* | ";" |
|
2755 |
*/ |
|
13077 | 2756 |
JCTree typeDeclaration(JCModifiers mods, Comment docComment) { |
10815 | 2757 |
int pos = token.pos; |
2758 |
if (mods == null && token.kind == SEMI) { |
|
2759 |
nextToken(); |
|
10 | 2760 |
return toP(F.at(pos).Skip()); |
2761 |
} else { |
|
10815 | 2762 |
return classOrInterfaceOrEnumDeclaration(modifiersOpt(mods), docComment); |
10 | 2763 |
} |
2764 |
} |
|
2765 |
||
2766 |
/** ClassOrInterfaceOrEnumDeclaration = ModifiersOpt |
|
2767 |
* (ClassDeclaration | InterfaceDeclaration | EnumDeclaration) |
|
2768 |
* @param mods Any modifiers starting the class or interface declaration |
|
2769 |
* @param dc The documentation comment for the class, or null. |
|
2770 |
*/ |
|
13077 | 2771 |
JCStatement classOrInterfaceOrEnumDeclaration(JCModifiers mods, Comment dc) { |
10815 | 2772 |
if (token.kind == CLASS) { |
10 | 2773 |
return classDeclaration(mods, dc); |
10815 | 2774 |
} else if (token.kind == INTERFACE) { |
10 | 2775 |
return interfaceDeclaration(mods, dc); |
2776 |
} else if (allowEnums) { |
|
10815 | 2777 |
if (token.kind == ENUM) { |
10 | 2778 |
return enumDeclaration(mods, dc); |
2779 |
} else { |
|
10815 | 2780 |
int pos = token.pos; |
10 | 2781 |
List<JCTree> errs; |
15367 | 2782 |
if (LAX_IDENTIFIER.accepts(token.kind)) { |
10 | 2783 |
errs = List.<JCTree>of(mods, toP(F.at(pos).Ident(ident()))); |
10815 | 2784 |
setErrorEndPos(token.pos); |
10 | 2785 |
} else { |
2786 |
errs = List.<JCTree>of(mods); |
|
2787 |
} |
|
2788 |
return toP(F.Exec(syntaxError(pos, errs, "expected3", |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
2789 |
CLASS, INTERFACE, ENUM))); |
10 | 2790 |
} |
2791 |
} else { |
|
10815 | 2792 |
if (token.kind == ENUM) { |
2793 |
error(token.pos, "enums.not.supported.in.source", source.name); |
|
10 | 2794 |
allowEnums = true; |
2795 |
return enumDeclaration(mods, dc); |
|
2796 |
} |
|
10815 | 2797 |
int pos = token.pos; |
10 | 2798 |
List<JCTree> errs; |
15367 | 2799 |
if (LAX_IDENTIFIER.accepts(token.kind)) { |
10 | 2800 |
errs = List.<JCTree>of(mods, toP(F.at(pos).Ident(ident()))); |
10815 | 2801 |
setErrorEndPos(token.pos); |
10 | 2802 |
} else { |
2803 |
errs = List.<JCTree>of(mods); |
|
2804 |
} |
|
2805 |
return toP(F.Exec(syntaxError(pos, errs, "expected2", |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
2806 |
CLASS, INTERFACE))); |
10 | 2807 |
} |
2808 |
} |
|
2809 |
||
2810 |
/** ClassDeclaration = CLASS Ident TypeParametersOpt [EXTENDS Type] |
|
2811 |
* [IMPLEMENTS TypeList] ClassBody |
|
2812 |
* @param mods The modifiers starting the class declaration |
|
2813 |
* @param dc The documentation comment for the class, or null. |
|
2814 |
*/ |
|
13077 | 2815 |
protected JCClassDecl classDeclaration(JCModifiers mods, Comment dc) { |
10815 | 2816 |
int pos = token.pos; |
10 | 2817 |
accept(CLASS); |
2818 |
Name name = ident(); |
|
2819 |
||
2820 |
List<JCTypeParameter> typarams = typeParametersOpt(); |
|
2821 |
||
8625
6b51ef804d49
6639645: Modeling type implementing missing interfaces
jjg
parents:
8234
diff
changeset
|
2822 |
JCExpression extending = null; |
10815 | 2823 |
if (token.kind == EXTENDS) { |
2824 |
nextToken(); |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2825 |
extending = parseType(); |
10 | 2826 |
} |
2827 |
List<JCExpression> implementing = List.nil(); |
|
10815 | 2828 |
if (token.kind == IMPLEMENTS) { |
2829 |
nextToken(); |
|
10 | 2830 |
implementing = typeList(); |
2831 |
} |
|
2832 |
List<JCTree> defs = classOrInterfaceBody(name, false); |
|
2833 |
JCClassDecl result = toP(F.at(pos).ClassDef( |
|
2834 |
mods, name, typarams, extending, implementing, defs)); |
|
2835 |
attach(result, dc); |
|
2836 |
return result; |
|
2837 |
} |
|
2838 |
||
2839 |
/** InterfaceDeclaration = INTERFACE Ident TypeParametersOpt |
|
2840 |
* [EXTENDS TypeList] InterfaceBody |
|
2841 |
* @param mods The modifiers starting the interface declaration |
|
2842 |
* @param dc The documentation comment for the interface, or null. |
|
2843 |
*/ |
|
13077 | 2844 |
protected JCClassDecl interfaceDeclaration(JCModifiers mods, Comment dc) { |
10815 | 2845 |
int pos = token.pos; |
10 | 2846 |
accept(INTERFACE); |
2847 |
Name name = ident(); |
|
2848 |
||
2849 |
List<JCTypeParameter> typarams = typeParametersOpt(); |
|
2850 |
||
2851 |
List<JCExpression> extending = List.nil(); |
|
10815 | 2852 |
if (token.kind == EXTENDS) { |
2853 |
nextToken(); |
|
10 | 2854 |
extending = typeList(); |
2855 |
} |
|
2856 |
List<JCTree> defs = classOrInterfaceBody(name, true); |
|
2857 |
JCClassDecl result = toP(F.at(pos).ClassDef( |
|
2858 |
mods, name, typarams, null, extending, defs)); |
|
2859 |
attach(result, dc); |
|
2860 |
return result; |
|
2861 |
} |
|
2862 |
||
2863 |
/** EnumDeclaration = ENUM Ident [IMPLEMENTS TypeList] EnumBody |
|
2864 |
* @param mods The modifiers starting the enum declaration |
|
2865 |
* @param dc The documentation comment for the enum, or null. |
|
2866 |
*/ |
|
13077 | 2867 |
protected JCClassDecl enumDeclaration(JCModifiers mods, Comment dc) { |
10815 | 2868 |
int pos = token.pos; |
10 | 2869 |
accept(ENUM); |
2870 |
Name name = ident(); |
|
2871 |
||
2872 |
List<JCExpression> implementing = List.nil(); |
|
10815 | 2873 |
if (token.kind == IMPLEMENTS) { |
2874 |
nextToken(); |
|
10 | 2875 |
implementing = typeList(); |
2876 |
} |
|
2877 |
||
2878 |
List<JCTree> defs = enumBody(name); |
|
4870
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2879 |
mods.flags |= Flags.ENUM; |
10 | 2880 |
JCClassDecl result = toP(F.at(pos). |
4870
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
2881 |
ClassDef(mods, name, List.<JCTypeParameter>nil(), |
10 | 2882 |
null, implementing, defs)); |
2883 |
attach(result, dc); |
|
2884 |
return result; |
|
2885 |
} |
|
2886 |
||
2887 |
/** EnumBody = "{" { EnumeratorDeclarationList } [","] |
|
2888 |
* [ ";" {ClassBodyDeclaration} ] "}" |
|
2889 |
*/ |
|
2890 |
List<JCTree> enumBody(Name enumName) { |
|
2891 |
accept(LBRACE); |
|
2892 |
ListBuffer<JCTree> defs = new ListBuffer<JCTree>(); |
|
10815 | 2893 |
if (token.kind == COMMA) { |
2894 |
nextToken(); |
|
2895 |
} else if (token.kind != RBRACE && token.kind != SEMI) { |
|
10 | 2896 |
defs.append(enumeratorDeclaration(enumName)); |
10815 | 2897 |
while (token.kind == COMMA) { |
2898 |
nextToken(); |
|
2899 |
if (token.kind == RBRACE || token.kind == SEMI) break; |
|
10 | 2900 |
defs.append(enumeratorDeclaration(enumName)); |
2901 |
} |
|
10815 | 2902 |
if (token.kind != SEMI && token.kind != RBRACE) { |
2903 |
defs.append(syntaxError(token.pos, "expected3", |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
735
diff
changeset
|
2904 |
COMMA, RBRACE, SEMI)); |
10815 | 2905 |
nextToken(); |
10 | 2906 |
} |
2907 |
} |
|
10815 | 2908 |
if (token.kind == SEMI) { |
2909 |
nextToken(); |
|
2910 |
while (token.kind != RBRACE && token.kind != EOF) { |
|
10 | 2911 |
defs.appendList(classOrInterfaceBodyDeclaration(enumName, |
2912 |
false)); |
|
11055 | 2913 |
if (token.pos <= endPosTable.errorEndPos) { |
10 | 2914 |
// error recovery |
2915 |
skip(false, true, true, false); |
|
2916 |
} |
|
2917 |
} |
|
2918 |
} |
|
2919 |
accept(RBRACE); |
|
2920 |
return defs.toList(); |
|
2921 |
} |
|
2922 |
||
2923 |
/** EnumeratorDeclaration = AnnotationsOpt [TypeArguments] IDENTIFIER [ Arguments ] [ "{" ClassBody "}" ] |
|
2924 |
*/ |
|
2925 |
JCTree enumeratorDeclaration(Name enumName) { |
|
13077 | 2926 |
Comment dc = token.comment(CommentStyle.JAVADOC); |
10 | 2927 |
int flags = Flags.PUBLIC|Flags.STATIC|Flags.FINAL|Flags.ENUM; |
10948 | 2928 |
if (token.deprecatedFlag()) { |
10 | 2929 |
flags |= Flags.DEPRECATED; |
2930 |
} |
|
10815 | 2931 |
int pos = token.pos; |
7072 | 2932 |
List<JCAnnotation> annotations = annotationsOpt(); |
10 | 2933 |
JCModifiers mods = F.at(annotations.isEmpty() ? Position.NOPOS : pos).Modifiers(flags, annotations); |
2934 |
List<JCExpression> typeArgs = typeArgumentsOpt(); |
|
10815 | 2935 |
int identPos = token.pos; |
10 | 2936 |
Name name = ident(); |
10815 | 2937 |
int createPos = token.pos; |
2938 |
List<JCExpression> args = (token.kind == LPAREN) |
|
10 | 2939 |
? arguments() : List.<JCExpression>nil(); |
2940 |
JCClassDecl body = null; |
|
10815 | 2941 |
if (token.kind == LBRACE) { |
10 | 2942 |
JCModifiers mods1 = F.at(Position.NOPOS).Modifiers(Flags.ENUM | Flags.STATIC); |
2943 |
List<JCTree> defs = classOrInterfaceBody(names.empty, false); |
|
2944 |
body = toP(F.at(identPos).AnonymousClassDef(mods1, defs)); |
|
2945 |
} |
|
2946 |
if (args.isEmpty() && body == null) |
|
4704
5206047418c2
6472751: SourcePositions.getStartPos returns incorrect value for enum constants
jjg
parents:
3997
diff
changeset
|
2947 |
createPos = identPos; |
5206047418c2
6472751: SourcePositions.getStartPos returns incorrect value for enum constants
jjg
parents:
3997
diff
changeset
|
2948 |
JCIdent ident = F.at(identPos).Ident(enumName); |
10 | 2949 |
JCNewClass create = F.at(createPos).NewClass(null, typeArgs, ident, args, body); |
4704
5206047418c2
6472751: SourcePositions.getStartPos returns incorrect value for enum constants
jjg
parents:
3997
diff
changeset
|
2950 |
if (createPos != identPos) |
10815 | 2951 |
storeEnd(create, S.prevToken().endPos); |
4704
5206047418c2
6472751: SourcePositions.getStartPos returns incorrect value for enum constants
jjg
parents:
3997
diff
changeset
|
2952 |
ident = F.at(identPos).Ident(enumName); |
10 | 2953 |
JCTree result = toP(F.at(pos).VarDef(mods, name, ident, create)); |
2954 |
attach(result, dc); |
|
2955 |
return result; |
|
2956 |
} |
|
2957 |
||
2958 |
/** TypeList = Type {"," Type} |
|
2959 |
*/ |
|
2960 |
List<JCExpression> typeList() { |
|
2961 |
ListBuffer<JCExpression> ts = new ListBuffer<JCExpression>(); |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2962 |
ts.append(parseType()); |
10815 | 2963 |
while (token.kind == COMMA) { |
2964 |
nextToken(); |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
2965 |
ts.append(parseType()); |
10 | 2966 |
} |
2967 |
return ts.toList(); |
|
2968 |
} |
|
2969 |
||
2970 |
/** ClassBody = "{" {ClassBodyDeclaration} "}" |
|
2971 |
* InterfaceBody = "{" {InterfaceBodyDeclaration} "}" |
|
2972 |
*/ |
|
2973 |
List<JCTree> classOrInterfaceBody(Name className, boolean isInterface) { |
|
2974 |
accept(LBRACE); |
|
11055 | 2975 |
if (token.pos <= endPosTable.errorEndPos) { |
10 | 2976 |
// error recovery |
2977 |
skip(false, true, false, false); |
|
10815 | 2978 |
if (token.kind == LBRACE) |
2979 |
nextToken(); |
|
10 | 2980 |
} |
2981 |
ListBuffer<JCTree> defs = new ListBuffer<JCTree>(); |
|
10815 | 2982 |
while (token.kind != RBRACE && token.kind != EOF) { |
10 | 2983 |
defs.appendList(classOrInterfaceBodyDeclaration(className, isInterface)); |
11055 | 2984 |
if (token.pos <= endPosTable.errorEndPos) { |
10 | 2985 |
// error recovery |
2986 |
skip(false, true, true, false); |
|
2987 |
} |
|
2988 |
} |
|
2989 |
accept(RBRACE); |
|
2990 |
return defs.toList(); |
|
2991 |
} |
|
2992 |
||
2993 |
/** ClassBodyDeclaration = |
|
2994 |
* ";" |
|
2995 |
* | [STATIC] Block |
|
2996 |
* | ModifiersOpt |
|
2997 |
* ( Type Ident |
|
2998 |
* ( VariableDeclaratorsRest ";" | MethodDeclaratorRest ) |
|
2999 |
* | VOID Ident MethodDeclaratorRest |
|
3000 |
* | TypeParameters (Type | VOID) Ident MethodDeclaratorRest |
|
3001 |
* | Ident ConstructorDeclaratorRest |
|
3002 |
* | TypeParameters Ident ConstructorDeclaratorRest |
|
3003 |
* | ClassOrInterfaceOrEnumDeclaration |
|
3004 |
* ) |
|
3005 |
* InterfaceBodyDeclaration = |
|
3006 |
* ";" |
|
3007 |
* | ModifiersOpt Type Ident |
|
3008 |
* ( ConstantDeclaratorsRest | InterfaceMethodDeclaratorRest ";" ) |
|
3009 |
*/ |
|
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
3010 |
protected List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface) { |
10815 | 3011 |
if (token.kind == SEMI) { |
3012 |
nextToken(); |
|
6585
189f53daed52
6921495: spurious semicolons in class def cause empty NOPOS blocks
jjg
parents:
6152
diff
changeset
|
3013 |
return List.<JCTree>nil(); |
10 | 3014 |
} else { |
13077 | 3015 |
Comment dc = token.comment(CommentStyle.JAVADOC); |
10815 | 3016 |
int pos = token.pos; |
10 | 3017 |
JCModifiers mods = modifiersOpt(); |
10815 | 3018 |
if (token.kind == CLASS || |
3019 |
token.kind == INTERFACE || |
|
3020 |
allowEnums && token.kind == ENUM) { |
|
10 | 3021 |
return List.<JCTree>of(classOrInterfaceOrEnumDeclaration(mods, dc)); |
10815 | 3022 |
} else if (token.kind == LBRACE && !isInterface && |
10 | 3023 |
(mods.flags & Flags.StandardFlags & ~Flags.STATIC) == 0 && |
3024 |
mods.annotations.isEmpty()) { |
|
3025 |
return List.<JCTree>of(block(pos, mods.flags)); |
|
3026 |
} else { |
|
10815 | 3027 |
pos = token.pos; |
10 | 3028 |
List<JCTypeParameter> typarams = typeParametersOpt(); |
8033
13d9c18b8fa1
6993305: starting position of a method without modifiers and with type parameters is incorrect
jjg
parents:
8032
diff
changeset
|
3029 |
// if there are type parameters but no modifiers, save the start |
13d9c18b8fa1
6993305: starting position of a method without modifiers and with type parameters is incorrect
jjg
parents:
8032
diff
changeset
|
3030 |
// position of the method in the modifiers. |
13d9c18b8fa1
6993305: starting position of a method without modifiers and with type parameters is incorrect
jjg
parents:
8032
diff
changeset
|
3031 |
if (typarams.nonEmpty() && mods.pos == Position.NOPOS) { |
13d9c18b8fa1
6993305: starting position of a method without modifiers and with type parameters is incorrect
jjg
parents:
8032
diff
changeset
|
3032 |
mods.pos = pos; |
13d9c18b8fa1
6993305: starting position of a method without modifiers and with type parameters is incorrect
jjg
parents:
8032
diff
changeset
|
3033 |
storeEnd(mods, pos); |
13d9c18b8fa1
6993305: starting position of a method without modifiers and with type parameters is incorrect
jjg
parents:
8032
diff
changeset
|
3034 |
} |
10815 | 3035 |
Token tk = token; |
3036 |
pos = token.pos; |
|
10 | 3037 |
JCExpression type; |
10815 | 3038 |
boolean isVoid = token.kind == VOID; |
10 | 3039 |
if (isVoid) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3040 |
type = to(F.at(pos).TypeIdent(TypeTag.VOID)); |
10815 | 3041 |
nextToken(); |
10 | 3042 |
} else { |
7072 | 3043 |
type = parseType(); |
10 | 3044 |
} |
10950 | 3045 |
if (token.kind == LPAREN && !isInterface && type.hasTag(IDENT)) { |
10815 | 3046 |
if (isInterface || tk.name() != className) |
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
7074
diff
changeset
|
3047 |
error(pos, "invalid.meth.decl.ret.type.req"); |
10 | 3048 |
return List.of(methodDeclaratorRest( |
3049 |
pos, mods, null, names.init, typarams, |
|
3050 |
isInterface, true, dc)); |
|
3051 |
} else { |
|
10815 | 3052 |
pos = token.pos; |
3053 |
Name name = ident(); |
|
3054 |
if (token.kind == LPAREN) { |
|
10 | 3055 |
return List.of(methodDeclaratorRest( |
3056 |
pos, mods, type, name, typarams, |
|
3057 |
isInterface, isVoid, dc)); |
|
3058 |
} else if (!isVoid && typarams.isEmpty()) { |
|
3059 |
List<JCTree> defs = |
|
3060 |
variableDeclaratorsRest(pos, mods, type, name, isInterface, dc, |
|
3061 |
new ListBuffer<JCTree>()).toList(); |
|
10815 | 3062 |
storeEnd(defs.last(), token.endPos); |
10 | 3063 |
accept(SEMI); |
3064 |
return defs; |
|
3065 |
} else { |
|
10815 | 3066 |
pos = token.pos; |
10 | 3067 |
List<JCTree> err = isVoid |
3068 |
? List.<JCTree>of(toP(F.at(pos).MethodDef(mods, name, type, typarams, |
|
3069 |
List.<JCVariableDecl>nil(), List.<JCExpression>nil(), null, null))) |
|
3070 |
: null; |
|
10815 | 3071 |
return List.<JCTree>of(syntaxError(token.pos, err, "expected", LPAREN)); |
10 | 3072 |
} |
3073 |
} |
|
3074 |
} |
|
3075 |
} |
|
3076 |
} |
|
3077 |
||
3078 |
/** MethodDeclaratorRest = |
|
7072 | 3079 |
* FormalParameters BracketsOpt [Throws TypeList] ( MethodBody | [DEFAULT AnnotationValue] ";") |
10 | 3080 |
* VoidMethodDeclaratorRest = |
7072 | 3081 |
* FormalParameters [Throws TypeList] ( MethodBody | ";") |
10 | 3082 |
* InterfaceMethodDeclaratorRest = |
7072 | 3083 |
* FormalParameters BracketsOpt [THROWS TypeList] ";" |
10 | 3084 |
* VoidInterfaceMethodDeclaratorRest = |
7072 | 3085 |
* FormalParameters [THROWS TypeList] ";" |
10 | 3086 |
* ConstructorDeclaratorRest = |
7072 | 3087 |
* "(" FormalParameterListOpt ")" [THROWS TypeList] MethodBody |
10 | 3088 |
*/ |
11147
20770e90d993
7119032: (javac) increase visibility of JavacParser methods to improve subtyping
ksrini
parents:
11144
diff
changeset
|
3089 |
protected JCTree methodDeclaratorRest(int pos, |
10 | 3090 |
JCModifiers mods, |
3091 |
JCExpression type, |
|
3092 |
Name name, |
|
3093 |
List<JCTypeParameter> typarams, |
|
3094 |
boolean isInterface, boolean isVoid, |
|
13077 | 3095 |
Comment dc) { |
10 | 3096 |
List<JCVariableDecl> params = formalParameters(); |
7072 | 3097 |
if (!isVoid) type = bracketsOpt(type); |
10 | 3098 |
List<JCExpression> thrown = List.nil(); |
10815 | 3099 |
if (token.kind == THROWS) { |
3100 |
nextToken(); |
|
10 | 3101 |
thrown = qualidentList(); |
3102 |
} |
|
3103 |
JCBlock body = null; |
|
3104 |
JCExpression defaultValue; |
|
10815 | 3105 |
if (token.kind == LBRACE) { |
10 | 3106 |
body = block(); |
3107 |
defaultValue = null; |
|
3108 |
} else { |
|
10815 | 3109 |
if (token.kind == DEFAULT) { |
10 | 3110 |
accept(DEFAULT); |
3111 |
defaultValue = annotationValue(); |
|
3112 |
} else { |
|
3113 |
defaultValue = null; |
|
3114 |
} |
|
3115 |
accept(SEMI); |
|
11055 | 3116 |
if (token.pos <= endPosTable.errorEndPos) { |
10 | 3117 |
// error recovery |
3118 |
skip(false, true, false, false); |
|
10815 | 3119 |
if (token.kind == LBRACE) { |
10 | 3120 |
body = block(); |
3121 |
} |
|
3122 |
} |
|
3123 |
} |
|
4870
a132763160d7
6919889: assorted position errors in compiler syntax trees
jjg
parents:
4704
diff
changeset
|
3124 |
|
10 | 3125 |
JCMethodDecl result = |
3126 |
toP(F.at(pos).MethodDef(mods, name, type, typarams, |
|
7072 | 3127 |
params, thrown, |
10 | 3128 |
body, defaultValue)); |
3129 |
attach(result, dc); |
|
3130 |
return result; |
|
3131 |
} |
|
3132 |
||
7072 | 3133 |
/** QualidentList = Qualident {"," Qualident} |
10 | 3134 |
*/ |
3135 |
List<JCExpression> qualidentList() { |
|
3136 |
ListBuffer<JCExpression> ts = new ListBuffer<JCExpression>(); |
|
7072 | 3137 |
ts.append(qualident()); |
10815 | 3138 |
while (token.kind == COMMA) { |
3139 |
nextToken(); |
|
7072 | 3140 |
ts.append(qualident()); |
10 | 3141 |
} |
3142 |
return ts.toList(); |
|
3143 |
} |
|
3144 |
||
13844 | 3145 |
/** |
3146 |
* {@literal |
|
3147 |
* TypeParametersOpt = ["<" TypeParameter {"," TypeParameter} ">"] |
|
3148 |
* } |
|
10 | 3149 |
*/ |
3150 |
List<JCTypeParameter> typeParametersOpt() { |
|
10815 | 3151 |
if (token.kind == LT) { |
10 | 3152 |
checkGenerics(); |
3153 |
ListBuffer<JCTypeParameter> typarams = new ListBuffer<JCTypeParameter>(); |
|
10815 | 3154 |
nextToken(); |
10 | 3155 |
typarams.append(typeParameter()); |
10815 | 3156 |
while (token.kind == COMMA) { |
3157 |
nextToken(); |
|
10 | 3158 |
typarams.append(typeParameter()); |
3159 |
} |
|
3160 |
accept(GT); |
|
3161 |
return typarams.toList(); |
|
3162 |
} else { |
|
3163 |
return List.nil(); |
|
3164 |
} |
|
3165 |
} |
|
3166 |
||
13844 | 3167 |
/** |
3168 |
* {@literal |
|
3169 |
* TypeParameter = TypeVariable [TypeParameterBound] |
|
10 | 3170 |
* TypeParameterBound = EXTENDS Type {"&" Type} |
3171 |
* TypeVariable = Ident |
|
13844 | 3172 |
* } |
10 | 3173 |
*/ |
3174 |
JCTypeParameter typeParameter() { |
|
10815 | 3175 |
int pos = token.pos; |
10 | 3176 |
Name name = ident(); |
3177 |
ListBuffer<JCExpression> bounds = new ListBuffer<JCExpression>(); |
|
10815 | 3178 |
if (token.kind == EXTENDS) { |
3179 |
nextToken(); |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
3180 |
bounds.append(parseType()); |
10815 | 3181 |
while (token.kind == AMP) { |
3182 |
nextToken(); |
|
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
3183 |
bounds.append(parseType()); |
10 | 3184 |
} |
3185 |
} |
|
7072 | 3186 |
return toP(F.at(pos).TypeParameter(name, bounds.toList())); |
10 | 3187 |
} |
3188 |
||
3189 |
/** FormalParameters = "(" [ FormalParameterList ] ")" |
|
3190 |
* FormalParameterList = [ FormalParameterListNovarargs , ] LastFormalParameter |
|
3191 |
* FormalParameterListNovarargs = [ FormalParameterListNovarargs , ] FormalParameter |
|
3192 |
*/ |
|
3193 |
List<JCVariableDecl> formalParameters() { |
|
15367 | 3194 |
return formalParameters(false); |
3195 |
} |
|
3196 |
List<JCVariableDecl> formalParameters(boolean lambdaParameters) { |
|
10 | 3197 |
ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>(); |
3198 |
JCVariableDecl lastParam = null; |
|
3199 |
accept(LPAREN); |
|
10815 | 3200 |
if (token.kind != RPAREN) { |
15367 | 3201 |
params.append(lastParam = formalParameter(lambdaParameters)); |
10815 | 3202 |
while ((lastParam.mods.flags & Flags.VARARGS) == 0 && token.kind == COMMA) { |
3203 |
nextToken(); |
|
15367 | 3204 |
params.append(lastParam = formalParameter(lambdaParameters)); |
10 | 3205 |
} |
3206 |
} |
|
3207 |
accept(RPAREN); |
|
3208 |
return params.toList(); |
|
3209 |
} |
|
3210 |
||
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3211 |
List<JCVariableDecl> implicitParameters(boolean hasParens) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3212 |
if (hasParens) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3213 |
accept(LPAREN); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3214 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3215 |
ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>(); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3216 |
if (token.kind != RPAREN && token.kind != ARROW) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3217 |
params.append(implicitParameter()); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3218 |
while (token.kind == COMMA) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3219 |
nextToken(); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3220 |
params.append(implicitParameter()); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3221 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3222 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3223 |
if (hasParens) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3224 |
accept(RPAREN); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3225 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3226 |
return params.toList(); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3227 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3228 |
|
10 | 3229 |
JCModifiers optFinal(long flags) { |
3230 |
JCModifiers mods = modifiersOpt(); |
|
3231 |
checkNoMods(mods.flags & ~(Flags.FINAL | Flags.DEPRECATED)); |
|
3232 |
mods.flags |= flags; |
|
3233 |
return mods; |
|
3234 |
} |
|
3235 |
||
3236 |
/** FormalParameter = { FINAL | '@' Annotation } Type VariableDeclaratorId |
|
3237 |
* LastFormalParameter = { FINAL | '@' Annotation } Type '...' Ident | FormalParameter |
|
3238 |
*/ |
|
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
3239 |
protected JCVariableDecl formalParameter() { |
15367 | 3240 |
return formalParameter(false); |
3241 |
} |
|
3242 |
protected JCVariableDecl formalParameter(boolean lambdaParameter) { |
|
10 | 3243 |
JCModifiers mods = optFinal(Flags.PARAMETER); |
1258
1cf37d8837d1
6724118: change JavaCompiler to not use Scanner directly
jjg
parents:
939
diff
changeset
|
3244 |
JCExpression type = parseType(); |
10815 | 3245 |
if (token.kind == ELLIPSIS) { |
10 | 3246 |
checkVarargs(); |
3247 |
mods.flags |= Flags.VARARGS; |
|
10815 | 3248 |
type = to(F.at(token.pos).TypeArray(type)); |
3249 |
nextToken(); |
|
10 | 3250 |
} |
15367 | 3251 |
return variableDeclaratorId(mods, type, lambdaParameter); |
10 | 3252 |
} |
3253 |
||
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3254 |
protected JCVariableDecl implicitParameter() { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3255 |
JCModifiers mods = F.at(token.pos).Modifiers(Flags.PARAMETER); |
15367 | 3256 |
return variableDeclaratorId(mods, null, true); |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3257 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3258 |
|
10 | 3259 |
/* ---------- auxiliary methods -------------- */ |
3260 |
||
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
7074
diff
changeset
|
3261 |
void error(int pos, String key, Object ... args) { |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
7074
diff
changeset
|
3262 |
log.error(DiagnosticFlag.SYNTAX, pos, key, args); |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
7074
diff
changeset
|
3263 |
} |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
7074
diff
changeset
|
3264 |
|
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
3265 |
void error(DiagnosticPosition pos, String key, Object ... args) { |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
3266 |
log.error(DiagnosticFlag.SYNTAX, pos, key, args); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
3267 |
} |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
3268 |
|
7076
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
7074
diff
changeset
|
3269 |
void warning(int pos, String key, Object ... args) { |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
7074
diff
changeset
|
3270 |
log.warning(pos, key, args); |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
7074
diff
changeset
|
3271 |
} |
c96fa26247c8
6994946: option to specify only syntax errors as unrecoverable
jjg
parents:
7074
diff
changeset
|
3272 |
|
10 | 3273 |
/** Check that given tree is a legal expression statement. |
3274 |
*/ |
|
3275 |
protected JCExpression checkExprStat(JCExpression t) { |
|
14722
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
3276 |
if (!TreeInfo.isExpressionStatement(t)) { |
10455
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
3277 |
JCExpression ret = F.at(t.pos).Erroneous(List.<JCTree>of(t)); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
3278 |
error(ret, "not.stmt"); |
3d070be0fff8
7073631: (javac) javac parser improvements for error position reporting
ksrini
parents:
10200
diff
changeset
|
3279 |
return ret; |
14722
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
3280 |
} else { |
aaa39655aa2e
8004105: Expression statement lambdas should be void-compatible
mcimadamore
parents:
14547
diff
changeset
|
3281 |
return t; |
10 | 3282 |
} |
3283 |
} |
|
3284 |
||
3285 |
/** Return precedence of operator represented by token, |
|
3286 |
* -1 if token is not a binary operator. @see TreeInfo.opPrec |
|
3287 |
*/ |
|
10815 | 3288 |
static int prec(TokenKind token) { |
10950 | 3289 |
JCTree.Tag oc = optag(token); |
3290 |
return (oc != NO_TAG) ? TreeInfo.opPrec(oc) : -1; |
|
10 | 3291 |
} |
3292 |
||
5013
e942b2e52479
6931927: position issues with synthesized anonymous class
jjg
parents:
4870
diff
changeset
|
3293 |
/** |
e942b2e52479
6931927: position issues with synthesized anonymous class
jjg
parents:
4870
diff
changeset
|
3294 |
* Return the lesser of two positions, making allowance for either one |
e942b2e52479
6931927: position issues with synthesized anonymous class
jjg
parents:
4870
diff
changeset
|
3295 |
* being unset. |
e942b2e52479
6931927: position issues with synthesized anonymous class
jjg
parents:
4870
diff
changeset
|
3296 |
*/ |
e942b2e52479
6931927: position issues with synthesized anonymous class
jjg
parents:
4870
diff
changeset
|
3297 |
static int earlier(int pos1, int pos2) { |
e942b2e52479
6931927: position issues with synthesized anonymous class
jjg
parents:
4870
diff
changeset
|
3298 |
if (pos1 == Position.NOPOS) |
e942b2e52479
6931927: position issues with synthesized anonymous class
jjg
parents:
4870
diff
changeset
|
3299 |
return pos2; |
e942b2e52479
6931927: position issues with synthesized anonymous class
jjg
parents:
4870
diff
changeset
|
3300 |
if (pos2 == Position.NOPOS) |
e942b2e52479
6931927: position issues with synthesized anonymous class
jjg
parents:
4870
diff
changeset
|
3301 |
return pos1; |
e942b2e52479
6931927: position issues with synthesized anonymous class
jjg
parents:
4870
diff
changeset
|
3302 |
return (pos1 < pos2 ? pos1 : pos2); |
e942b2e52479
6931927: position issues with synthesized anonymous class
jjg
parents:
4870
diff
changeset
|
3303 |
} |
e942b2e52479
6931927: position issues with synthesized anonymous class
jjg
parents:
4870
diff
changeset
|
3304 |
|
10 | 3305 |
/** Return operation tag of binary operator represented by token, |
10950 | 3306 |
* No_TAG if token is not a binary operator. |
10 | 3307 |
*/ |
10950 | 3308 |
static JCTree.Tag optag(TokenKind token) { |
10 | 3309 |
switch (token) { |
3310 |
case BARBAR: |
|
10950 | 3311 |
return OR; |
10 | 3312 |
case AMPAMP: |
10950 | 3313 |
return AND; |
10 | 3314 |
case BAR: |
10950 | 3315 |
return BITOR; |
10 | 3316 |
case BAREQ: |
10950 | 3317 |
return BITOR_ASG; |
10 | 3318 |
case CARET: |
10950 | 3319 |
return BITXOR; |
10 | 3320 |
case CARETEQ: |
10950 | 3321 |
return BITXOR_ASG; |
10 | 3322 |
case AMP: |
10950 | 3323 |
return BITAND; |
10 | 3324 |
case AMPEQ: |
10950 | 3325 |
return BITAND_ASG; |
10 | 3326 |
case EQEQ: |
10950 | 3327 |
return JCTree.Tag.EQ; |
10 | 3328 |
case BANGEQ: |
10950 | 3329 |
return NE; |
10 | 3330 |
case LT: |
10950 | 3331 |
return JCTree.Tag.LT; |
10 | 3332 |
case GT: |
10950 | 3333 |
return JCTree.Tag.GT; |
10 | 3334 |
case LTEQ: |
10950 | 3335 |
return LE; |
10 | 3336 |
case GTEQ: |
10950 | 3337 |
return GE; |
10 | 3338 |
case LTLT: |
10950 | 3339 |
return SL; |
10 | 3340 |
case LTLTEQ: |
10950 | 3341 |
return SL_ASG; |
10 | 3342 |
case GTGT: |
10950 | 3343 |
return SR; |
10 | 3344 |
case GTGTEQ: |
10950 | 3345 |
return SR_ASG; |
10 | 3346 |
case GTGTGT: |
10950 | 3347 |
return USR; |
10 | 3348 |
case GTGTGTEQ: |
10950 | 3349 |
return USR_ASG; |
10 | 3350 |
case PLUS: |
10950 | 3351 |
return JCTree.Tag.PLUS; |
10 | 3352 |
case PLUSEQ: |
10950 | 3353 |
return PLUS_ASG; |
10 | 3354 |
case SUB: |
10950 | 3355 |
return MINUS; |
10 | 3356 |
case SUBEQ: |
10950 | 3357 |
return MINUS_ASG; |
10 | 3358 |
case STAR: |
10950 | 3359 |
return MUL; |
10 | 3360 |
case STAREQ: |
10950 | 3361 |
return MUL_ASG; |
10 | 3362 |
case SLASH: |
10950 | 3363 |
return DIV; |
10 | 3364 |
case SLASHEQ: |
10950 | 3365 |
return DIV_ASG; |
10 | 3366 |
case PERCENT: |
10950 | 3367 |
return MOD; |
10 | 3368 |
case PERCENTEQ: |
10950 | 3369 |
return MOD_ASG; |
10 | 3370 |
case INSTANCEOF: |
10950 | 3371 |
return TYPETEST; |
10 | 3372 |
default: |
10950 | 3373 |
return NO_TAG; |
10 | 3374 |
} |
3375 |
} |
|
3376 |
||
3377 |
/** Return operation tag of unary operator represented by token, |
|
10950 | 3378 |
* No_TAG if token is not a binary operator. |
10 | 3379 |
*/ |
10950 | 3380 |
static JCTree.Tag unoptag(TokenKind token) { |
10 | 3381 |
switch (token) { |
3382 |
case PLUS: |
|
10950 | 3383 |
return POS; |
10 | 3384 |
case SUB: |
10950 | 3385 |
return NEG; |
10 | 3386 |
case BANG: |
10950 | 3387 |
return NOT; |
10 | 3388 |
case TILDE: |
10950 | 3389 |
return COMPL; |
10 | 3390 |
case PLUSPLUS: |
10950 | 3391 |
return PREINC; |
10 | 3392 |
case SUBSUB: |
10950 | 3393 |
return PREDEC; |
10 | 3394 |
default: |
10950 | 3395 |
return NO_TAG; |
10 | 3396 |
} |
3397 |
} |
|
3398 |
||
3399 |
/** Return type tag of basic type represented by token, |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3400 |
* NONE if token is not a basic type identifier. |
10 | 3401 |
*/ |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3402 |
static TypeTag typetag(TokenKind token) { |
10 | 3403 |
switch (token) { |
3404 |
case BYTE: |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3405 |
return TypeTag.BYTE; |
10 | 3406 |
case CHAR: |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3407 |
return TypeTag.CHAR; |
10 | 3408 |
case SHORT: |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3409 |
return TypeTag.SHORT; |
10 | 3410 |
case INT: |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3411 |
return TypeTag.INT; |
10 | 3412 |
case LONG: |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3413 |
return TypeTag.LONG; |
10 | 3414 |
case FLOAT: |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3415 |
return TypeTag.FLOAT; |
10 | 3416 |
case DOUBLE: |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3417 |
return TypeTag.DOUBLE; |
10 | 3418 |
case BOOLEAN: |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3419 |
return TypeTag.BOOLEAN; |
10 | 3420 |
default: |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14267
diff
changeset
|
3421 |
return TypeTag.NONE; |
10 | 3422 |
} |
3423 |
} |
|
3424 |
||
3425 |
void checkGenerics() { |
|
3426 |
if (!allowGenerics) { |
|
10815 | 3427 |
error(token.pos, "generics.not.supported.in.source", source.name); |
10 | 3428 |
allowGenerics = true; |
3429 |
} |
|
3430 |
} |
|
3431 |
void checkVarargs() { |
|
3432 |
if (!allowVarargs) { |
|
10815 | 3433 |
error(token.pos, "varargs.not.supported.in.source", source.name); |
10 | 3434 |
allowVarargs = true; |
3435 |
} |
|
3436 |
} |
|
3437 |
void checkForeach() { |
|
3438 |
if (!allowForeach) { |
|
10815 | 3439 |
error(token.pos, "foreach.not.supported.in.source", source.name); |
10 | 3440 |
allowForeach = true; |
3441 |
} |
|
3442 |
} |
|
3443 |
void checkStaticImports() { |
|
3444 |
if (!allowStaticImport) { |
|
10815 | 3445 |
error(token.pos, "static.import.not.supported.in.source", source.name); |
10 | 3446 |
allowStaticImport = true; |
3447 |
} |
|
3448 |
} |
|
3449 |
void checkAnnotations() { |
|
3450 |
if (!allowAnnotations) { |
|
10815 | 3451 |
error(token.pos, "annotations.not.supported.in.source", source.name); |
10 | 3452 |
allowAnnotations = true; |
3453 |
} |
|
3454 |
} |
|
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3455 |
void checkDiamond() { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3456 |
if (!allowDiamond) { |
10815 | 3457 |
error(token.pos, "diamond.not.supported.in.source", source.name); |
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3458 |
allowDiamond = true; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3459 |
} |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
3460 |
} |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
3461 |
void checkMulticatch() { |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
3462 |
if (!allowMulticatch) { |
10815 | 3463 |
error(token.pos, "multicatch.not.supported.in.source", source.name); |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
3464 |
allowMulticatch = true; |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
3465 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
3466 |
} |
7211
163fe60f63de
6970016: Clean up ARM/try-with-resources implementation
mcimadamore
parents:
7076
diff
changeset
|
3467 |
void checkTryWithResources() { |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
3468 |
if (!allowTWR) { |
10815 | 3469 |
error(token.pos, "try.with.resources.not.supported.in.source", source.name); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
3470 |
allowTWR = true; |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
6146
diff
changeset
|
3471 |
} |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
3472 |
} |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3473 |
void checkLambda() { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3474 |
if (!allowLambda) { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3475 |
log.error(token.pos, "lambda.not.supported.in.source", source.name); |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3476 |
allowLambda = true; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3477 |
} |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
11055
diff
changeset
|
3478 |
} |
11144
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
3479 |
void checkMethodReferences() { |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
3480 |
if (!allowMethodReferences) { |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
3481 |
log.error(token.pos, "method.references.not.supported.in.source", source.name); |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
3482 |
allowMethodReferences = true; |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
3483 |
} |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
3484 |
} |
14267
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14263
diff
changeset
|
3485 |
void checkDefaultMethods() { |
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14263
diff
changeset
|
3486 |
if (!allowDefaultMethods) { |
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14263
diff
changeset
|
3487 |
log.error(token.pos, "default.methods.not.supported.in.source", source.name); |
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14263
diff
changeset
|
3488 |
allowDefaultMethods = true; |
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14263
diff
changeset
|
3489 |
} |
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14263
diff
changeset
|
3490 |
} |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
3491 |
void checkIntersectionTypesInCast() { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
3492 |
if (!allowIntersectionTypesInCast) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
3493 |
log.error(token.pos, "intersection.types.in.cast.not.supported.in.source", source.name); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
3494 |
allowIntersectionTypesInCast = true; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
3495 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14722
diff
changeset
|
3496 |
} |
11055 | 3497 |
|
3498 |
/* |
|
3499 |
* a functional source tree and end position mappings |
|
3500 |
*/ |
|
3501 |
protected class SimpleEndPosTable extends AbstractEndPosTable { |
|
3502 |
||
3503 |
private final Map<JCTree, Integer> endPosMap; |
|
3504 |
||
3505 |
SimpleEndPosTable() { |
|
3506 |
endPosMap = new HashMap<JCTree, Integer>(); |
|
3507 |
} |
|
3508 |
||
3509 |
protected void storeEnd(JCTree tree, int endpos) { |
|
3510 |
endPosMap.put(tree, errorEndPos > endpos ? errorEndPos : endpos); |
|
3511 |
} |
|
3512 |
||
3513 |
protected <T extends JCTree> T to(T t) { |
|
3514 |
storeEnd(t, token.endPos); |
|
3515 |
return t; |
|
3516 |
} |
|
3517 |
||
3518 |
protected <T extends JCTree> T toP(T t) { |
|
3519 |
storeEnd(t, S.prevToken().endPos); |
|
3520 |
return t; |
|
3521 |
} |
|
3522 |
||
3523 |
public int getEndPos(JCTree tree) { |
|
3524 |
Integer value = endPosMap.get(tree); |
|
3525 |
return (value == null) ? Position.NOPOS : value; |
|
3526 |
} |
|
3527 |
||
3528 |
public int replaceTree(JCTree oldTree, JCTree newTree) { |
|
3529 |
Integer pos = endPosMap.remove(oldTree); |
|
3530 |
if (pos != null) { |
|
3531 |
endPosMap.put(newTree, pos); |
|
3532 |
return pos; |
|
3533 |
} |
|
3534 |
return Position.NOPOS; |
|
3535 |
} |
|
3536 |
} |
|
3537 |
||
3538 |
/* |
|
3539 |
* a default skeletal implementation without any mapping overhead. |
|
3540 |
*/ |
|
3541 |
protected class EmptyEndPosTable extends AbstractEndPosTable { |
|
3542 |
||
3543 |
protected void storeEnd(JCTree tree, int endpos) { /* empty */ } |
|
3544 |
||
3545 |
protected <T extends JCTree> T to(T t) { |
|
3546 |
return t; |
|
3547 |
} |
|
3548 |
||
3549 |
protected <T extends JCTree> T toP(T t) { |
|
3550 |
return t; |
|
3551 |
} |
|
3552 |
||
3553 |
public int getEndPos(JCTree tree) { |
|
3554 |
return Position.NOPOS; |
|
3555 |
} |
|
3556 |
||
3557 |
public int replaceTree(JCTree oldTree, JCTree newTree) { |
|
3558 |
return Position.NOPOS; |
|
3559 |
} |
|
3560 |
||
3561 |
} |
|
3562 |
||
3563 |
protected abstract class AbstractEndPosTable implements EndPosTable { |
|
3564 |
||
3565 |
/** |
|
3566 |
* Store the last error position. |
|
3567 |
*/ |
|
3568 |
protected int errorEndPos; |
|
3569 |
||
3570 |
/** |
|
3571 |
* Store ending position for a tree, the value of which is the greater |
|
3572 |
* of last error position and the given ending position. |
|
3573 |
* @param tree The tree. |
|
3574 |
* @param endpos The ending position to associate with the tree. |
|
3575 |
*/ |
|
3576 |
protected abstract void storeEnd(JCTree tree, int endpos); |
|
3577 |
||
3578 |
/** |
|
3579 |
* Store current token's ending position for a tree, the value of which |
|
3580 |
* will be the greater of last error position and the ending position of |
|
3581 |
* the current token. |
|
3582 |
* @param t The tree. |
|
3583 |
*/ |
|
3584 |
protected abstract <T extends JCTree> T to(T t); |
|
3585 |
||
3586 |
/** |
|
3587 |
* Store current token's ending position for a tree, the value of which |
|
3588 |
* will be the greater of last error position and the ending position of |
|
3589 |
* the previous token. |
|
3590 |
* @param t The tree. |
|
3591 |
*/ |
|
3592 |
protected abstract <T extends JCTree> T toP(T t); |
|
3593 |
||
3594 |
/** |
|
3595 |
* Set the error position during the parsing phases, the value of which |
|
3596 |
* will be set only if it is greater than the last stored error position. |
|
3597 |
* @param errPos The error position |
|
3598 |
*/ |
|
3599 |
protected void setErrorEndPos(int errPos) { |
|
3600 |
if (errPos > errorEndPos) { |
|
3601 |
errorEndPos = errPos; |
|
3602 |
} |
|
3603 |
} |
|
3604 |
} |
|
10 | 3605 |
} |