Skip to content

Commit 1e8c33b

Browse files
committed
---
yaml --- r: 349399 b: refs/heads/master-next c: c11cb4f h: refs/heads/master i: 349397: fbc9ed1 349395: 50c0796 349391: 13a628a
1 parent 3fceeec commit 1e8c33b

File tree

3 files changed

+36
-38
lines changed

3 files changed

+36
-38
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 3574c513bbc5578dd9346b4ea9ab5995c5927bb5
3-
refs/heads/master-next: b6e97a229ed68eb429855010f70daf1365f6b739
3+
refs/heads/master-next: c11cb4f63324a20573df826e8a98d1239e01d514
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/lib/Parse/ParseDecl.cpp

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -224,43 +224,32 @@ bool Parser::parseTopLevel() {
224224
// allows type declarations and other things to be parsed, name bound, and
225225
// type checked in batches, similar to immediate mode. This also enforces
226226
// 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
264253
}
265254

266255
// In the case of a catastrophic parse error, consume any trailing
@@ -270,6 +259,10 @@ bool Parser::parseTopLevel() {
270259
Tok.is(tok::pound_endif)) {
271260
diagnose(Tok.getLoc(),
272261
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+
273266
consumeToken();
274267
}
275268

branches/master-next/test/Syntax/round_trip_misc.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class C {
1414
// Orphan '}' at top level
1515
}
1616

17+
// Orphan #elseif, #else, #endif at top level.
18+
#elseif foobar
19+
#else
20+
#endif
21+
1722
// Compound name.
1823
foo(x:y:)()
1924

0 commit comments

Comments
 (0)