|
Lines 874-879
Link Here
|
| 874 |
declSpecifier= e.declSpec; |
874 |
declSpecifier= e.declSpec; |
| 875 |
declarator= e.declarator; |
875 |
declarator= e.declarator; |
| 876 |
backup(e.currToken); |
876 |
backup(e.currToken); |
|
|
877 |
} catch (FoundAggregateInitializer lie) { |
| 878 |
// type-ids have no initializers |
| 879 |
return null; |
| 877 |
} catch (BacktrackException bt) { |
880 |
} catch (BacktrackException bt) { |
| 878 |
return null; |
881 |
return null; |
| 879 |
} |
882 |
} |
|
Lines 2245-2268
Link Here
|
| 2245 |
|
2248 |
|
| 2246 |
final int firstOffset= LA(1).getOffset(); |
2249 |
final int firstOffset= LA(1).getOffset(); |
| 2247 |
int endOffset= firstOffset; |
2250 |
int endOffset= firstOffset; |
|
|
2251 |
boolean insertSemi= false; |
| 2252 |
boolean parseDtors= true; |
| 2248 |
|
2253 |
|
| 2249 |
ICPPASTDeclSpecifier declSpec; |
2254 |
ICPPASTDeclSpecifier declSpec= null; |
| 2250 |
IASTDeclarator dtor= null; |
2255 |
IASTDeclarator dtor= null; |
| 2251 |
IToken markBeforDtor= null; |
2256 |
IToken markBeforDtor= null; |
| 2252 |
try { |
2257 |
try { |
| 2253 |
declSpec = declSpecifierSeq(declOption); |
2258 |
declSpec = declSpecifierSeq(declOption); |
| 2254 |
switch(LTcatchEOF(1)) { |
2259 |
final int lt1= LTcatchEOF(1); |
|
|
2260 |
switch(lt1) { |
| 2255 |
case 0: // eof |
2261 |
case 0: // eof |
|
|
2262 |
case IToken.tEOC: |
| 2256 |
case IToken.tSEMI: |
2263 |
case IToken.tSEMI: |
| 2257 |
if (!validWithoutDtor(declOption, declSpec)) { |
2264 |
if (lt1 != IToken.tEOC && !validWithoutDtor(declOption, declSpec)) |
| 2258 |
throwBacktrack(LA(1)); |
2265 |
throwBacktrack(LA(1)); |
| 2259 |
} |
2266 |
|
|
|
2267 |
parseDtors= false; |
| 2268 |
insertSemi= lt1==0; |
| 2269 |
if (lt1 == IToken.tSEMI) |
| 2270 |
endOffset= consume().getEndOffset(); |
| 2271 |
else |
| 2272 |
endOffset= calculateEndOffset(declSpec); |
| 2260 |
break; |
2273 |
break; |
|
|
2274 |
|
| 2261 |
case IToken.tCOMMA: |
2275 |
case IToken.tCOMMA: |
| 2262 |
throwBacktrack(LA(1)); |
2276 |
throwBacktrack(LA(1)); |
| 2263 |
break; |
2277 |
break; |
| 2264 |
case IToken.tEOC: |
|
|
| 2265 |
break; |
| 2266 |
default: |
2278 |
default: |
| 2267 |
markBeforDtor= mark(); |
2279 |
markBeforDtor= mark(); |
| 2268 |
try { |
2280 |
try { |
|
Lines 2278-2283
Link Here
|
| 2278 |
} |
2290 |
} |
| 2279 |
break; |
2291 |
break; |
| 2280 |
} |
2292 |
} |
|
|
2293 |
} catch (FoundAggregateInitializer lie) { |
| 2294 |
if (declSpec == null) |
| 2295 |
declSpec= (ICPPASTDeclSpecifier) lie.fDeclSpec; |
| 2296 |
// scalability: don't keep references to tokens, initializer may be large |
| 2297 |
declarationMark= null; |
| 2298 |
markBeforDtor= null; |
| 2299 |
dtor= addInitializer(lie); |
| 2281 |
} catch (FoundDeclaratorException e) { |
2300 |
} catch (FoundDeclaratorException e) { |
| 2282 |
declSpec= (ICPPASTDeclSpecifier) e.declSpec; |
2301 |
declSpec= (ICPPASTDeclSpecifier) e.declSpec; |
| 2283 |
dtor= e.declarator; |
2302 |
dtor= e.declarator; |
|
Lines 2293-2343
Link Here
|
| 2293 |
throw e; |
2312 |
throw e; |
| 2294 |
} |
2313 |
} |
| 2295 |
|
2314 |
|
| 2296 |
IASTDeclarator[] declarators= {dtor}; |
2315 |
IASTDeclarator[] declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY; |
| 2297 |
while (LTcatchEOF(1) == IToken.tCOMMA) { |
2316 |
if (parseDtors) { |
| 2298 |
consume(); |
2317 |
declarators= new IASTDeclarator[]{dtor}; |
| 2299 |
declarators= (IASTDeclarator[]) ArrayUtil.append( IASTDeclarator.class, declarators, initDeclarator(declSpec, declOption)); |
2318 |
while (LTcatchEOF(1) == IToken.tCOMMA) { |
| 2300 |
} |
2319 |
consume(); |
| 2301 |
|
2320 |
try { |
| 2302 |
declarators= (IASTDeclarator[]) ArrayUtil.removeNulls( IASTDeclarator.class, declarators ); |
2321 |
dtor= initDeclarator(declSpec, declOption); |
| 2303 |
|
2322 |
} catch (FoundAggregateInitializer e) { |
| 2304 |
boolean insertSemi= false; |
2323 |
// scalability: don't keep references to tokens, initializer may be large |
| 2305 |
final int lt1= LTcatchEOF(1); |
2324 |
declarationMark= null; |
| 2306 |
switch (lt1) { |
2325 |
markBeforDtor= null; |
| 2307 |
case IToken.tEOC: |
2326 |
dtor= addInitializer(e); |
| 2308 |
endOffset= figureEndOffset(declSpec, declarators); |
2327 |
} |
| 2309 |
break; |
2328 |
declarators = (IASTDeclarator[]) ArrayUtil.append(IASTDeclarator.class, declarators, dtor); |
| 2310 |
case IToken.tSEMI: |
2329 |
} |
| 2311 |
endOffset= consume().getEndOffset(); |
2330 |
declarators = (IASTDeclarator[]) ArrayUtil.removeNulls(IASTDeclarator.class, declarators); |
| 2312 |
break; |
2331 |
|
| 2313 |
case IToken.t_try: |
2332 |
final int lt1= LTcatchEOF(1); |
| 2314 |
case IToken.tCOLON: |
2333 |
switch (lt1) { |
| 2315 |
case IToken.tLBRACE: |
2334 |
case IToken.tEOC: |
| 2316 |
return functionDefinition(firstOffset, declSpec, declarators); |
2335 |
endOffset= figureEndOffset(declSpec, declarators); |
| 2317 |
default: |
2336 |
break; |
| 2318 |
if (declOption != DeclarationOptions.LOCAL) { |
2337 |
case IToken.tSEMI: |
| 2319 |
insertSemi= true; |
2338 |
endOffset= consume().getEndOffset(); |
| 2320 |
if (validWithoutDtor(declOption, declSpec)) { |
2339 |
break; |
| 2321 |
// class definition without semicolon |
2340 |
case IToken.t_try: |
| 2322 |
if (markBeforDtor == null || !isOnSameLine(calculateEndOffset(declSpec), markBeforDtor.getOffset())) { |
2341 |
case IToken.tCOLON: |
| 2323 |
if (markBeforDtor != null) { |
2342 |
case IToken.tLBRACE: |
|
|
2343 |
return functionDefinition(firstOffset, declSpec, declarators); |
| 2344 |
default: |
| 2345 |
if (declOption != DeclarationOptions.LOCAL) { |
| 2346 |
insertSemi= true; |
| 2347 |
if (validWithoutDtor(declOption, declSpec)) { |
| 2348 |
if (markBeforDtor != null && !isOnSameLine(calculateEndOffset(declSpec), markBeforDtor.getOffset())) { |
| 2324 |
backup(markBeforDtor); |
2349 |
backup(markBeforDtor); |
|
|
2350 |
declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY; |
| 2351 |
endOffset= calculateEndOffset(declSpec); |
| 2352 |
break; |
| 2325 |
} |
2353 |
} |
| 2326 |
declarators= IASTDeclarator.EMPTY_DECLARATOR_ARRAY; |
2354 |
} |
| 2327 |
endOffset= calculateEndOffset(declSpec); |
2355 |
endOffset= figureEndOffset(declSpec, declarators); |
|
|
2356 |
if (lt1 == 0 || !isOnSameLine(endOffset, LA(1).getOffset())) { |
| 2357 |
break; |
| 2358 |
} |
| 2359 |
if (declarators.length == 1 && declarators[0] instanceof IASTFunctionDeclarator) { |
| 2328 |
break; |
2360 |
break; |
| 2329 |
} |
2361 |
} |
| 2330 |
} |
|
|
| 2331 |
endOffset= figureEndOffset(declSpec, declarators); |
| 2332 |
if (lt1 == 0 || !isOnSameLine(endOffset, LA(1).getOffset())) { |
| 2333 |
insertSemi= true; |
| 2334 |
break; |
| 2335 |
} |
| 2336 |
if (declarators.length == 1 && declarators[0] instanceof IASTFunctionDeclarator) { |
| 2337 |
break; |
| 2338 |
} |
2362 |
} |
|
|
2363 |
throwBacktrack(LA(1)); |
| 2339 |
} |
2364 |
} |
| 2340 |
throwBacktrack(LA(1)); |
|
|
| 2341 |
} |
2365 |
} |
| 2342 |
|
2366 |
|
| 2343 |
// no function body |
2367 |
// no function body |
|
Lines 2515-2521
Link Here
|
| 2515 |
skipBrackets(IToken.tLBRACKET, IToken.tRBRACKET); |
2539 |
skipBrackets(IToken.tLBRACKET, IToken.tRBRACKET); |
| 2516 |
} |
2540 |
} |
| 2517 |
|
2541 |
|
| 2518 |
IASTDeclSpecifier declSpec; |
2542 |
IASTDeclSpecifier declSpec= null; |
| 2519 |
IASTDeclarator declarator; |
2543 |
IASTDeclarator declarator; |
| 2520 |
try { |
2544 |
try { |
| 2521 |
declSpec= declSpecifierSeq(DeclarationOptions.PARAMETER); |
2545 |
declSpec= declSpecifierSeq(DeclarationOptions.PARAMETER); |
|
Lines 2524-2529
Link Here
|
| 2524 |
declSpec= e.declSpec; |
2548 |
declSpec= e.declSpec; |
| 2525 |
declarator= e.declarator; |
2549 |
declarator= e.declarator; |
| 2526 |
backup(e.currToken); |
2550 |
backup(e.currToken); |
|
|
2551 |
} catch (FoundAggregateInitializer lie) { |
| 2552 |
if (declSpec == null) |
| 2553 |
declSpec= lie.fDeclSpec; |
| 2554 |
declarator= addInitializer(lie); |
| 2527 |
} |
2555 |
} |
| 2528 |
|
2556 |
|
| 2529 |
final ICPPASTParameterDeclaration parm = createParameterDeclaration(); |
2557 |
final ICPPASTParameterDeclaration parm = createParameterDeclaration(); |
|
Lines 2558-2567
Link Here
|
| 2558 |
* ("typename")? name | |
2586 |
* ("typename")? name | |
| 2559 |
* { "class" | "struct" | "union" } classSpecifier | |
2587 |
* { "class" | "struct" | "union" } classSpecifier | |
| 2560 |
* {"enum"} enumSpecifier |
2588 |
* {"enum"} enumSpecifier |
|
|
2589 |
* @throws FoundAggregateInitializer |
| 2561 |
*/ |
2590 |
*/ |
| 2562 |
@Override |
2591 |
@Override |
| 2563 |
protected ICPPASTDeclSpecifier declSpecifierSeq(final DeclarationOptions option) |
2592 |
protected ICPPASTDeclSpecifier declSpecifierSeq(final DeclarationOptions option) |
| 2564 |
throws BacktrackException, EndOfFileException, FoundDeclaratorException { |
2593 |
throws BacktrackException, EndOfFileException, FoundDeclaratorException, FoundAggregateInitializer { |
| 2565 |
int storageClass = IASTDeclSpecifier.sc_unspecified; |
2594 |
int storageClass = IASTDeclSpecifier.sc_unspecified; |
| 2566 |
int simpleType = IASTSimpleDeclSpecifier.t_unspecified; |
2595 |
int simpleType = IASTSimpleDeclSpecifier.t_unspecified; |
| 2567 |
int options= 0; |
2596 |
int options= 0; |
|
Lines 2748-2754
Link Here
|
| 2748 |
if (option.fAllowEmptySpecifier && LT(1) != IToken.tCOMPLETION) { |
2777 |
if (option.fAllowEmptySpecifier && LT(1) != IToken.tCOMPLETION) { |
| 2749 |
lookAheadForDeclarator(option); |
2778 |
lookAheadForDeclarator(option); |
| 2750 |
} |
2779 |
} |
| 2751 |
} catch (FoundDeclaratorException e) { |
2780 |
} catch (FoundAggregateInitializer e) { |
|
|
2781 |
e.fDeclSpec= createSimpleDeclSpec(storageClass, simpleType, options, isLong, typeofExpression, offset, endOffset); |
| 2782 |
throw e; |
| 2783 |
}catch (FoundDeclaratorException e) { |
| 2752 |
if (e.currToken.getType() == IToken.tEOC || option == DeclarationOptions.FUNCTION_STYLE_ASM |
2784 |
if (e.currToken.getType() == IToken.tEOC || option == DeclarationOptions.FUNCTION_STYLE_ASM |
| 2753 |
|| canBeConstructorDestructorOrConversion(option, storageClass, options, e.declarator)) { |
2785 |
|| canBeConstructorDestructorOrConversion(option, storageClass, options, e.declarator)) { |
| 2754 |
e.declSpec= createSimpleDeclSpec(storageClass, simpleType, options, isLong, typeofExpression, offset, endOffset); |
2786 |
e.declSpec= createSimpleDeclSpec(storageClass, simpleType, options, isLong, typeofExpression, offset, endOffset); |
|
Lines 3046-3057
Link Here
|
| 3046 |
} |
3078 |
} |
| 3047 |
|
3079 |
|
| 3048 |
@Override |
3080 |
@Override |
| 3049 |
protected IASTDeclarator initDeclarator(DeclarationOptions option) throws EndOfFileException, BacktrackException { |
3081 |
protected IASTDeclarator initDeclarator(DeclarationOptions option) |
|
|
3082 |
throws EndOfFileException, BacktrackException, FoundAggregateInitializer { |
| 3050 |
// called from the lookahead, only. |
3083 |
// called from the lookahead, only. |
| 3051 |
return initDeclarator(DtorStrategy.PREFER_FUNCTION, option); |
3084 |
return initDeclarator(DtorStrategy.PREFER_FUNCTION, option); |
| 3052 |
} |
3085 |
} |
| 3053 |
|
3086 |
|
| 3054 |
protected IASTDeclarator initDeclarator(IASTDeclSpecifier declspec, DeclarationOptions option) throws EndOfFileException, BacktrackException { |
3087 |
protected IASTDeclarator initDeclarator(IASTDeclSpecifier declspec, DeclarationOptions option) |
|
|
3088 |
throws EndOfFileException, BacktrackException, FoundAggregateInitializer { |
| 3055 |
final IToken mark= mark(); |
3089 |
final IToken mark= mark(); |
| 3056 |
IASTDeclarator dtor1= null; |
3090 |
IASTDeclarator dtor1= null; |
| 3057 |
IToken end1= null; |
3091 |
IToken end1= null; |
|
Lines 3076-3082
Link Here
|
| 3076 |
} |
3110 |
} |
| 3077 |
} catch (BacktrackException e) { |
3111 |
} catch (BacktrackException e) { |
| 3078 |
bt= e; |
3112 |
bt= e; |
| 3079 |
} |
3113 |
} |
| 3080 |
|
3114 |
|
| 3081 |
if (!option.fAllowConstructorInitializer || !canHaveConstructorInitializer(declspec)) { |
3115 |
if (!option.fAllowConstructorInitializer || !canHaveConstructorInitializer(declspec)) { |
| 3082 |
if (bt != null) |
3116 |
if (bt != null) |
|
Lines 3096-3102
Link Here
|
| 3096 |
return dtor1; |
3130 |
return dtor1; |
| 3097 |
} |
3131 |
} |
| 3098 |
throw e; |
3132 |
throw e; |
| 3099 |
} |
3133 |
} |
| 3100 |
|
3134 |
|
| 3101 |
// we have an ambiguity |
3135 |
// we have an ambiguity |
| 3102 |
if (end1 != null && LA(1).getEndOffset() != end1.getEndOffset()) { |
3136 |
if (end1 != null && LA(1).getEndOffset() != end1.getEndOffset()) { |
|
Lines 3144-3154
Link Here
|
| 3144 |
* @return declarator that this parsing produced. |
3178 |
* @return declarator that this parsing produced. |
| 3145 |
* @throws BacktrackException |
3179 |
* @throws BacktrackException |
| 3146 |
* request a backtrack |
3180 |
* request a backtrack |
|
|
3181 |
* @throws FoundAggregateInitializer |
| 3147 |
*/ |
3182 |
*/ |
| 3148 |
protected IASTDeclarator initDeclarator(DtorStrategy strategy, DeclarationOptions option) |
3183 |
protected IASTDeclarator initDeclarator(DtorStrategy strategy, DeclarationOptions option) |
| 3149 |
throws EndOfFileException, BacktrackException { |
3184 |
throws EndOfFileException, BacktrackException, FoundAggregateInitializer { |
| 3150 |
final IASTDeclarator dtor= declarator(strategy, option); |
3185 |
final IASTDeclarator dtor= declarator(strategy, option); |
| 3151 |
if (option.fAllowInitializer) { |
3186 |
if (option.fAllowInitializer) { |
|
|
3187 |
if (LT(1) == IToken.tASSIGN && LT(2) == IToken.tLBRACE) |
| 3188 |
throw new FoundAggregateInitializer(dtor); |
| 3189 |
|
| 3152 |
IASTInitializer initializer= optionalCPPInitializer(dtor); |
3190 |
IASTInitializer initializer= optionalCPPInitializer(dtor); |
| 3153 |
if (initializer != null) { |
3191 |
if (initializer != null) { |
| 3154 |
dtor.setInitializer(initializer); |
3192 |
dtor.setInitializer(initializer); |
|
Lines 3157-3162
Link Here
|
| 3157 |
} |
3195 |
} |
| 3158 |
return dtor; |
3196 |
return dtor; |
| 3159 |
} |
3197 |
} |
|
|
3198 |
|
| 3199 |
@Override |
| 3200 |
protected IASTDeclarator addInitializer(FoundAggregateInitializer e) throws EndOfFileException { |
| 3201 |
final IASTDeclarator d = e.fDeclarator; |
| 3202 |
try { |
| 3203 |
IASTInitializer i = optionalCPPInitializer(e.fDeclarator); |
| 3204 |
if (i != null) { |
| 3205 |
d.setInitializer(i); |
| 3206 |
((ASTNode) d).setLength(calculateEndOffset(i) - ((ASTNode) d).getOffset()); |
| 3207 |
} |
| 3208 |
} catch (BacktrackException e1) { |
| 3209 |
// mstodo add problem node |
| 3210 |
} |
| 3211 |
return d; |
| 3212 |
} |
| 3160 |
|
3213 |
|
| 3161 |
protected IASTInitializer optionalCPPInitializer(IASTDeclarator d) |
3214 |
protected IASTInitializer optionalCPPInitializer(IASTDeclarator d) |
| 3162 |
throws EndOfFileException, BacktrackException { |
3215 |
throws EndOfFileException, BacktrackException { |
|
Lines 3165-3171
Link Here
|
| 3165 |
if (LT(1) == IToken.tASSIGN) { |
3218 |
if (LT(1) == IToken.tASSIGN) { |
| 3166 |
consume(); |
3219 |
consume(); |
| 3167 |
try { |
3220 |
try { |
| 3168 |
return initializerClause(); |
3221 |
return initializerClause(false); |
| 3169 |
} catch (EndOfFileException eof) { |
3222 |
} catch (EndOfFileException eof) { |
| 3170 |
failParse(); |
3223 |
failParse(); |
| 3171 |
throw eof; |
3224 |
throw eof; |
|
Lines 3200-3206
Link Here
|
| 3200 |
} |
3253 |
} |
| 3201 |
|
3254 |
|
| 3202 |
|
3255 |
|
| 3203 |
protected IASTInitializer initializerClause() throws EndOfFileException, BacktrackException { |
3256 |
protected IASTInitializer initializerClause(boolean inAggregateInitializer) throws EndOfFileException, BacktrackException { |
| 3204 |
if (LT(1) == IToken.tLBRACE) { |
3257 |
if (LT(1) == IToken.tLBRACE) { |
| 3205 |
int startingOffset = consume().getOffset(); |
3258 |
int startingOffset = consume().getOffset(); |
| 3206 |
|
3259 |
|
|
Lines 3219-3225
Link Here
|
| 3219 |
if (LT(1) == IToken.tRBRACE) |
3272 |
if (LT(1) == IToken.tRBRACE) |
| 3220 |
break; |
3273 |
break; |
| 3221 |
|
3274 |
|
| 3222 |
IASTInitializer clause = initializerClause(); |
3275 |
IASTInitializer clause = initializerClause(true); |
| 3223 |
if (clause != null) { |
3276 |
if (clause != null) { |
| 3224 |
result.addInitializer(clause); |
3277 |
result.addInitializer(clause); |
| 3225 |
} |
3278 |
} |
|
Lines 3236-3241
Link Here
|
| 3236 |
// try this now instead |
3289 |
// try this now instead |
| 3237 |
// assignmentExpression |
3290 |
// assignmentExpression |
| 3238 |
IASTExpression assignmentExpression = assignmentExpression(); |
3291 |
IASTExpression assignmentExpression = assignmentExpression(); |
|
|
3292 |
if (inAggregateInitializer && skipTrivialExpressionsInAggregateInitializers) { |
| 3293 |
if (!NAME_CHECKER.containsName(assignmentExpression)) |
| 3294 |
return null; |
| 3295 |
} |
| 3296 |
|
| 3239 |
IASTInitializerExpression result = createInitializerExpression(); |
3297 |
IASTInitializerExpression result = createInitializerExpression(); |
| 3240 |
((ASTNode) result).setOffsetAndLength(((ASTNode) assignmentExpression)); |
3298 |
((ASTNode) result).setOffsetAndLength(((ASTNode) assignmentExpression)); |
| 3241 |
result.setExpression(assignmentExpression); |
3299 |
result.setExpression(assignmentExpression); |
|
Lines 3975-3981
Link Here
|
| 3975 |
|
4033 |
|
| 3976 |
private IASTSimpleDeclaration simpleSingleDeclaration(DeclarationOptions options) throws BacktrackException, EndOfFileException { |
4034 |
private IASTSimpleDeclaration simpleSingleDeclaration(DeclarationOptions options) throws BacktrackException, EndOfFileException { |
| 3977 |
final int startOffset= LA(1).getOffset(); |
4035 |
final int startOffset= LA(1).getOffset(); |
| 3978 |
IASTDeclSpecifier declSpec; |
4036 |
IASTDeclSpecifier declSpec= null; |
| 3979 |
IASTDeclarator declarator; |
4037 |
IASTDeclarator declarator; |
| 3980 |
|
4038 |
|
| 3981 |
try { |
4039 |
try { |
|
Lines 3985-3990
Link Here
|
| 3985 |
declSpec= e.declSpec; |
4043 |
declSpec= e.declSpec; |
| 3986 |
declarator= e.declarator; |
4044 |
declarator= e.declarator; |
| 3987 |
backup(e.currToken); |
4045 |
backup(e.currToken); |
|
|
4046 |
} catch (FoundAggregateInitializer lie) { |
| 4047 |
if (declSpec == null) |
| 4048 |
declSpec= lie.fDeclSpec; |
| 4049 |
declarator= addInitializer(lie); |
| 3988 |
} |
4050 |
} |
| 3989 |
|
4051 |
|
| 3990 |
final int endOffset = figureEndOffset(declSpec, declarator); |
4052 |
final int endOffset = figureEndOffset(declSpec, declarator); |