[Parse][SR-702] Disallow attributes before #if

This commit is contained in:
Rintaro Ishizaki
2016-08-11 23:36:17 +09:00
parent 56f7274cdf
commit 0bfa734c6a
2 changed files with 27 additions and 14 deletions

View File

@@ -1896,6 +1896,19 @@ void Parser::delayParseFromBeginningToHere(ParserPosition BeginParserPosition,
/// \endverbatim
ParserStatus Parser::parseDecl(ParseDeclOptions Flags,
llvm::function_ref<void(Decl*)> Handler) {
if (Tok.is(tok::pound_if)) {
auto IfConfigResult = parseDeclIfConfig(Flags);
if (auto ICD = IfConfigResult.getPtrOrNull()) {
// The IfConfigDecl is ahead of its members in source order.
Handler(ICD);
// Copy the active members into the entries list.
for (auto activeMember : ICD->getActiveMembers()) {
Handler(activeMember);
}
}
return IfConfigResult;
}
Decl* LastDecl = nullptr;
auto InternalHandler = [&](Decl *D) {
LastDecl = D;
@@ -2139,20 +2152,6 @@ ParserStatus Parser::parseDecl(ParseDeclOptions Flags,
DeclResult = parseDeclProtocol(Flags, Attributes);
Status = DeclResult;
break;
case tok::pound_if: {
auto IfConfigResult = parseDeclIfConfig(Flags);
Status = IfConfigResult;
if (auto ICD = IfConfigResult.getPtrOrNull()) {
// The IfConfigDecl is ahead of its members in source order.
InternalHandler(ICD);
// Copy the active members into the entries list.
for (auto activeMember : ICD->getActiveMembers()) {
InternalHandler(activeMember);
}
}
break;
}
case tok::pound_sourceLocation:
Status = parseLineDirective(false);
break;

View File

@@ -1,5 +1,19 @@
// RUN: %target-parse-verify-swift
public
#if FOO // expected-error {{expected declaration}}
var val1: Int = 0
#else
var val1: UInt = 1
#endif
struct S2 { // expected-note {{in declaration of 'S2'}}
@available(*, deprecated)
#if FOO // expected-error {{expected declaration}}
func fn1() {}
#endif
}
class C { // expected-note 3 {{in declaration of 'C'}}
#if os(iOS)