@@ -245,7 +245,6 @@ ParserStatus Parser::parseBraceItems(SmallVectorImpl<ASTNode> &Entries,
245
245
}
246
246
247
247
ParserStatus BraceItemsStatus;
248
- SmallVector<Decl*, 8 > TmpDecls;
249
248
250
249
bool PreviousHadSemi = true ;
251
250
while ((Kind == BraceItemListKind::TopLevelLibrary ||
@@ -292,57 +291,29 @@ ParserStatus Parser::parseBraceItems(SmallVectorImpl<ASTNode> &Entries,
292
291
293
292
// Parse the decl, stmt, or expression.
294
293
PreviousHadSemi = false ;
295
- if (isStartOfDecl ()
296
- && Tok.isNot (
297
- tok::pound_if, tok::pound_sourceLocation, tok::pound_line)) {
298
- ParserResult<Decl> DeclResult =
299
- parseDecl (IsTopLevel ? PD_AllowTopLevel : PD_Default,
300
- [&](Decl *D) {TmpDecls.push_back (D);});
301
- if (DeclResult.isParseError ()) {
302
- NeedParseErrorRecovery = true ;
303
- if (DeclResult.hasCodeCompletion () && IsTopLevel &&
304
- isCodeCompletionFirstPass ()) {
305
- consumeDecl (BeginParserPosition, None, IsTopLevel);
306
- return DeclResult;
307
- }
308
- }
309
- Result = DeclResult.getPtrOrNull ();
310
-
311
- for (Decl *D : TmpDecls)
312
- Entries.push_back (D);
313
- TmpDecls.clear ();
314
- } else if (Tok.is (tok::pound_if)) {
294
+ if (Tok.is (tok::pound_if)) {
315
295
auto IfConfigResult = parseIfConfig (
316
296
[&](SmallVectorImpl<ASTNode> &Elements, bool IsActive) {
317
297
parseBraceItems (Elements, Kind, IsActive
318
298
? BraceItemListKind::ActiveConditionalBlock
319
299
: BraceItemListKind::InactiveConditionalBlock);
320
300
});
321
-
322
- if (IfConfigResult.isParseError ()) {
323
- NeedParseErrorRecovery = true ;
324
- continue ;
325
- }
326
-
327
- Result = IfConfigResult.get ();
328
-
329
- if (!Result) {
330
- NeedParseErrorRecovery = true ;
331
- continue ;
332
- }
301
+ if (auto ICD = IfConfigResult.getPtrOrNull ()) {
302
+ Result = ICD;
303
+ // Add the #if block itself
304
+ Entries.push_back (ICD);
333
305
334
- // Add the #if block itself
335
- Entries.push_back (Result);
336
-
337
- IfConfigDecl *ICD = cast<IfConfigDecl>(Result.get <Decl*>());
338
- for (auto &Entry : ICD->getActiveClauseElements ()) {
339
- if (Entry.is <Decl*>() && isa<IfConfigDecl>(Entry.get <Decl*>()))
340
- // Don't hoist nested '#if'.
341
- continue ;
342
- Entries.push_back (Entry);
343
- if (Entry.is <Decl*>()) {
344
- Entry.get <Decl*>()->setEscapedFromIfConfig (true );
306
+ for (auto &Entry : ICD->getActiveClauseElements ()) {
307
+ if (Entry.is <Decl *>() && isa<IfConfigDecl>(Entry.get <Decl *>()))
308
+ // Don't hoist nested '#if'.
309
+ continue ;
310
+ Entries.push_back (Entry);
311
+ if (Entry.is <Decl *>())
312
+ Entry.get <Decl *>()->setEscapedFromIfConfig (true );
345
313
}
314
+ } else {
315
+ NeedParseErrorRecovery = true ;
316
+ continue ;
346
317
}
347
318
} else if (Tok.is (tok::pound_line)) {
348
319
ParserStatus Status = parseLineDirective (true );
@@ -352,6 +323,21 @@ ParserStatus Parser::parseBraceItems(SmallVectorImpl<ASTNode> &Entries,
352
323
ParserStatus Status = parseLineDirective (false );
353
324
BraceItemsStatus |= Status;
354
325
NeedParseErrorRecovery = Status.isError ();
326
+ } else if (isStartOfDecl ()) {
327
+ SmallVector<Decl*, 8 > TmpDecls;
328
+ ParserResult<Decl> DeclResult =
329
+ parseDecl (IsTopLevel ? PD_AllowTopLevel : PD_Default,
330
+ [&](Decl *D) {TmpDecls.push_back (D);});
331
+ if (DeclResult.isParseError ()) {
332
+ NeedParseErrorRecovery = true ;
333
+ if (DeclResult.hasCodeCompletion () && IsTopLevel &&
334
+ isCodeCompletionFirstPass ()) {
335
+ consumeDecl (BeginParserPosition, None, IsTopLevel);
336
+ return DeclResult;
337
+ }
338
+ }
339
+ Result = DeclResult.getPtrOrNull ();
340
+ Entries.append (TmpDecls.begin (), TmpDecls.end ());
355
341
} else if (IsTopLevel) {
356
342
// If this is a statement or expression at the top level of the module,
357
343
// Parse it as a child of a TopLevelCodeDecl.
0 commit comments