@@ -224,43 +224,32 @@ bool Parser::parseTopLevel() {
224
224
// allows type declarations and other things to be parsed, name bound, and
225
225
// type checked in batches, similar to immediate mode. This also enforces
226
226
// that SIL bodies can only be at the top level.
227
- if (Tok.is (tok::kw_sil)) {
228
- assert (isInSILMode () && " 'sil' should only be a keyword in SIL mode" );
229
- SIL->parseDeclSIL (*this );
230
- } else if (Tok.is (tok::kw_sil_stage)) {
231
- assert (isInSILMode () && " 'sil_stage' should only be a keyword in SIL mode" );
232
- SIL->parseDeclSILStage (*this );
233
- } else if (Tok.is (tok::kw_sil_vtable)) {
234
- assert (isInSILMode () &&
235
- " 'sil_vtable' should only be a keyword in SIL mode" );
236
- SIL->parseSILVTable (*this );
237
- } else if (Tok.is (tok::kw_sil_global)) {
238
- assert (isInSILMode () &&
239
- " 'sil_global' should only be a keyword in SIL mode" );
240
- SIL->parseSILGlobal (*this );
241
- } else if (Tok.is (tok::kw_sil_witness_table)) {
242
- assert (isInSILMode () &&
243
- " 'sil_witness_table' should only be a keyword in SIL mode" );
244
- SIL->parseSILWitnessTable (*this );
245
- } else if (Tok.is (tok::kw_sil_default_witness_table)) {
246
- assert (isInSILMode () &&
247
- " 'sil_default_witness_table' should only be a keyword in SIL mode" );
248
- SIL->parseSILDefaultWitnessTable (*this );
249
- } else if (Tok.is (tok::kw_sil_coverage_map)) {
250
- assert (isInSILMode () &&
251
- " 'sil_coverage_map' should only be a keyword in SIL mode" );
252
- SIL->parseSILCoverageMap (*this );
253
- } else if (Tok.is (tok::kw_sil_property)) {
254
- assert (isInSILMode () &&
255
- " 'sil_property' should only be a keyword in SIL mode" );
256
- SIL->parseSILProperty (*this );
257
- } else if (Tok.is (tok::kw_sil_scope)) {
258
- assert (isInSILMode () && " 'sil_scope' should only be a keyword in SIL mode" );
259
- SIL->parseSILScope (*this );
260
- } else {
261
- parseBraceItems (Items,
262
- allowTopLevelCode () ? BraceItemListKind::TopLevelCode
263
- : BraceItemListKind::TopLevelLibrary);
227
+ switch (Tok.getKind ()) {
228
+ default :
229
+ parseBraceItems (Items, allowTopLevelCode ()
230
+ ? BraceItemListKind::TopLevelCode
231
+ : BraceItemListKind::TopLevelLibrary);
232
+ break ;
233
+
234
+ // For now, create 'UnknownDecl' for all SIL declarations.
235
+ #define CASE_SIL (KW, NAME ) \
236
+ case tok::kw_##KW: { \
237
+ assert (isInSILMode () && " '" #KW " ' should only be a keyword in SIL mode" ); \
238
+ SyntaxParsingContext itemCtxt (SyntaxContext, SyntaxKind::CodeBlockItem); \
239
+ SyntaxParsingContext declCtxt (SyntaxContext, SyntaxContextKind::Decl); \
240
+ SIL->parse ##NAME (*this ); \
241
+ break ; \
242
+ }
243
+ CASE_SIL (sil, DeclSIL)
244
+ CASE_SIL (sil_stage, DeclSILStage)
245
+ CASE_SIL (sil_vtable, SILVTable)
246
+ CASE_SIL (sil_global, SILGlobal)
247
+ CASE_SIL (sil_witness_table, SILWitnessTable)
248
+ CASE_SIL (sil_default_witness_table, SILDefaultWitnessTable)
249
+ CASE_SIL (sil_coverage_map, SILCoverageMap)
250
+ CASE_SIL (sil_property, SILProperty)
251
+ CASE_SIL (sil_scope, SILScope)
252
+ #undef CASE_SIL
264
253
}
265
254
266
255
// In the case of a catastrophic parse error, consume any trailing
@@ -270,6 +259,10 @@ bool Parser::parseTopLevel() {
270
259
Tok.is (tok::pound_endif)) {
271
260
diagnose (Tok.getLoc (),
272
261
diag::unexpected_conditional_compilation_block_terminator);
262
+ // Create 'UnknownDecl' for orphan directives.
263
+ SyntaxParsingContext itemCtxt (SyntaxContext, SyntaxKind::CodeBlockItem);
264
+ SyntaxParsingContext declCtxt (SyntaxContext, SyntaxContextKind::Decl);
265
+
273
266
consumeToken ();
274
267
}
275
268
0 commit comments