@@ -855,9 +855,9 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
855
855
// identifier
856
856
if (!Tok.is (tok::identifier) &&
857
857
!(Tok.isAnyOperator () && Tok.getText () == " *" )) {
858
- if (Tok.is (tok::code_complete) && CodeCompletion) {
859
- CodeCompletion->completeDeclAttrParam (DAK_Available, 0 );
860
- consumeToken (tok::code_complete);
858
+ if (Tok.is (tok::code_complete) && CodeCompletion) {
859
+ CodeCompletion->completeDeclAttrParam (DAK_Available, 0 );
860
+ consumeToken (tok::code_complete);
861
861
}
862
862
diagnose (Tok.getLoc (), diag::attr_availability_platform, AttrName)
863
863
.highlight (SourceRange (Tok.getLoc ()));
@@ -2020,10 +2020,15 @@ void Parser::delayParseFromBeginningToHere(ParserPosition BeginParserPosition,
2020
2020
// / decl-import
2021
2021
// / decl-operator
2022
2022
// / \endverbatim
2023
- ParserStatus Parser::parseDecl (ParseDeclOptions Flags,
2024
- llvm::function_ref<void (Decl*)> Handler) {
2025
- if (Tok.isAny (tok::pound_sourceLocation, tok::pound_line))
2026
- return parseLineDirective (Tok.is (tok::pound_line));
2023
+ ParserResult<Decl>
2024
+ Parser::parseDecl (ParseDeclOptions Flags,
2025
+ llvm::function_ref<void (Decl*)> Handler) {
2026
+ if (Tok.isAny (tok::pound_sourceLocation, tok::pound_line)) {
2027
+ auto LineDirectiveStatus = parseLineDirective (Tok.is (tok::pound_line));
2028
+ if (LineDirectiveStatus.isError ())
2029
+ return LineDirectiveStatus;
2030
+ // If success, go on. line directive never produce decls.
2031
+ }
2027
2032
2028
2033
if (Tok.is (tok::pound_if)) {
2029
2034
auto IfConfigResult = parseDeclIfConfig (Flags);
@@ -2065,7 +2070,6 @@ ParserStatus Parser::parseDecl(ParseDeclOptions Flags,
2065
2070
SourceLoc StaticLoc;
2066
2071
StaticSpellingKind StaticSpelling = StaticSpellingKind::None;
2067
2072
ParserResult<Decl> DeclResult;
2068
- ParserStatus Status;
2069
2073
2070
2074
while (1 ) {
2071
2075
// Save the original token, in case code-completion needs it.
@@ -2107,7 +2111,6 @@ ParserStatus Parser::parseDecl(ParseDeclOptions Flags,
2107
2111
2108
2112
// Otherwise this is the start of a class declaration.
2109
2113
DeclResult = parseDeclClass (ClassLoc, Flags, Attributes);
2110
- Status = DeclResult;
2111
2114
break ;
2112
2115
}
2113
2116
@@ -2230,18 +2233,15 @@ ParserStatus Parser::parseDecl(ParseDeclOptions Flags,
2230
2233
// Unambiguous top level decls.
2231
2234
case tok::kw_import:
2232
2235
DeclResult = parseDeclImport (Flags, Attributes);
2233
- Status = DeclResult;
2234
2236
break ;
2235
2237
case tok::kw_extension:
2236
2238
DeclResult = parseDeclExtension (Flags, Attributes);
2237
- Status = DeclResult;
2238
2239
break ;
2239
2240
case tok::kw_let:
2240
2241
case tok::kw_var: {
2241
2242
llvm::SmallVector<Decl *, 4 > Entries;
2242
2243
DeclResult = parseDeclVar (Flags, Attributes, Entries, StaticLoc,
2243
2244
StaticSpelling, tryLoc);
2244
- Status = DeclResult;
2245
2245
StaticLoc = SourceLoc (); // we handled static if present.
2246
2246
MayNeedOverrideCompletion = true ;
2247
2247
std::for_each (Entries.begin (), Entries.end (), InternalHandler);
@@ -2251,54 +2251,43 @@ ParserStatus Parser::parseDecl(ParseDeclOptions Flags,
2251
2251
}
2252
2252
case tok::kw_typealias:
2253
2253
DeclResult = parseDeclTypeAlias (Flags, Attributes);
2254
- Status = DeclResult;
2255
2254
MayNeedOverrideCompletion = true ;
2256
2255
break ;
2257
2256
case tok::kw_associatedtype:
2258
2257
DeclResult = parseDeclAssociatedType (Flags, Attributes);
2259
- Status = DeclResult;
2260
2258
break ;
2261
2259
case tok::kw_enum:
2262
2260
DeclResult = parseDeclEnum (Flags, Attributes);
2263
- Status = DeclResult;
2264
2261
break ;
2265
2262
case tok::kw_case: {
2266
2263
llvm::SmallVector<Decl *, 4 > Entries;
2267
2264
DeclResult = parseDeclEnumCase (Flags, Attributes, Entries);
2268
- Status = DeclResult;
2269
2265
std::for_each (Entries.begin (), Entries.end (), InternalHandler);
2270
2266
if (auto *D = DeclResult.getPtrOrNull ())
2271
2267
markWasHandled (D);
2272
2268
break ;
2273
2269
}
2274
2270
case tok::kw_struct:
2275
2271
DeclResult = parseDeclStruct (Flags, Attributes);
2276
- Status = DeclResult;
2277
2272
break ;
2278
2273
case tok::kw_init:
2279
2274
DeclResult = parseDeclInit (Flags, Attributes);
2280
- Status = DeclResult;
2281
2275
break ;
2282
2276
case tok::kw_deinit:
2283
2277
DeclResult = parseDeclDeinit (Flags, Attributes);
2284
- Status = DeclResult;
2285
2278
break ;
2286
2279
case tok::kw_operator:
2287
2280
DeclResult = parseDeclOperator (Flags, Attributes);
2288
- Status = DeclResult;
2289
2281
break ;
2290
2282
case tok::kw_precedencegroup:
2291
2283
DeclResult = parseDeclPrecedenceGroup (Flags, Attributes);
2292
- Status = DeclResult;
2293
2284
break ;
2294
2285
case tok::kw_protocol:
2295
2286
DeclResult = parseDeclProtocol (Flags, Attributes);
2296
- Status = DeclResult;
2297
2287
break ;
2298
2288
2299
2289
case tok::kw_func:
2300
2290
DeclResult = parseDeclFunc (StaticLoc, StaticSpelling, Flags, Attributes);
2301
- Status = DeclResult;
2302
2291
StaticLoc = SourceLoc (); // we handled static if present.
2303
2292
MayNeedOverrideCompletion = true ;
2304
2293
break ;
@@ -2311,7 +2300,6 @@ ParserStatus Parser::parseDecl(ParseDeclOptions Flags,
2311
2300
}
2312
2301
llvm::SmallVector<Decl *, 4 > Entries;
2313
2302
DeclResult = parseDeclSubscript (Flags, Attributes, Entries);
2314
- Status = DeclResult;
2315
2303
std::for_each (Entries.begin (), Entries.end (), InternalHandler);
2316
2304
MayNeedOverrideCompletion = true ;
2317
2305
if (auto *D = DeclResult.getPtrOrNull ())
@@ -2321,14 +2309,14 @@ ParserStatus Parser::parseDecl(ParseDeclOptions Flags,
2321
2309
2322
2310
case tok::code_complete:
2323
2311
MayNeedOverrideCompletion = true ;
2324
- Status. setIsParseError ();
2312
+ DeclResult = makeParserError ();
2325
2313
// Handled below.
2326
2314
break ;
2327
2315
}
2328
2316
2329
- if (Status. isError () && MayNeedOverrideCompletion &&
2317
+ if (DeclResult. isParseError () && MayNeedOverrideCompletion &&
2330
2318
Tok.is (tok::code_complete)) {
2331
- Status = makeParserCodeCompletionStatus ();
2319
+ DeclResult = makeParserCodeCompletionStatus ();
2332
2320
if (CodeCompletion) {
2333
2321
// If we need to complete an override, collect the keywords already
2334
2322
// specified so that we do not duplicate them in code completion
@@ -2372,17 +2360,16 @@ ParserStatus Parser::parseDecl(ParseDeclOptions Flags,
2372
2360
false );
2373
2361
} else {
2374
2362
delayParseFromBeginningToHere (BeginParserPosition, Flags);
2375
- return makeParserSuccess ();
2363
+ return makeParserError ();
2376
2364
}
2377
2365
}
2378
2366
2379
- if (Status .hasCodeCompletion () && isCodeCompletionFirstPass () &&
2367
+ if (DeclResult .hasCodeCompletion () && isCodeCompletionFirstPass () &&
2380
2368
!CurDeclContext->isModuleScopeContext ()) {
2381
2369
// Only consume non-toplevel decls.
2382
2370
consumeDecl (BeginParserPosition, Flags, /* IsTopLevel=*/ false );
2383
2371
2384
- // Pretend that there was no error.
2385
- return makeParserSuccess ();
2372
+ return makeParserError ();
2386
2373
}
2387
2374
2388
2375
if (DeclResult.isNonNull ()) {
@@ -2391,16 +2378,16 @@ ParserStatus Parser::parseDecl(ParseDeclOptions Flags,
2391
2378
InternalHandler (DeclResult.get ());
2392
2379
}
2393
2380
2394
- if (Status. isSuccess ()) {
2381
+ if (!DeclResult. isParseError ()) {
2395
2382
// If we parsed 'class' or 'static', but didn't handle it above, complain
2396
2383
// about it.
2397
2384
if (StaticLoc.isValid ())
2398
- diagnose (LastDecl ->getLoc (), diag::decl_not_static,
2385
+ diagnose (DeclResult. get () ->getLoc (), diag::decl_not_static,
2399
2386
StaticSpelling)
2400
2387
.fixItRemove (SourceRange (StaticLoc));
2401
2388
}
2402
2389
2403
- return Status ;
2390
+ return DeclResult ;
2404
2391
}
2405
2392
2406
2393
void Parser::parseDeclDelayed () {
0 commit comments