Skip to content

Commit 0d09f6b

Browse files
committed
[Parser] Include all AST nodes from every #if regions in ParserUnit
'ParserUnit' is used for analyzing syntax structures _mainly_ in SourceKit. Since we removed IfConfigDecl from AST, ParserUnit didn't inclue any AST in #if ... #endif regions even for active region because it used to consider all inactive. Instead, consider every region "active" and include all the AST nodes. rdar://117387631
1 parent 3afe8eb commit 0d09f6b

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

include/swift/AST/SourceFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ class SourceFile final : public FileUnit {
9898

9999
/// Validate the new SwiftSyntax parser diagnostics.
100100
ValidateNewParserDiagnostics = 1 << 6,
101+
102+
/// Consider every #if ... #endif region active.
103+
PoundIfAllActive = 1 << 7,
101104
};
102105
using ParsingOptions = OptionSet<ParsingFlags>;
103106

lib/Parse/ParseIfConfig.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,11 @@ Result Parser::parseIfConfigRaw(
834834
// determined solely by which block has the completion token.
835835
!ideInspectionClauseLoc.isValid();
836836

837+
// For constructing syntactic structures, we need AST nodes even for
838+
// non-active regions.
839+
bool allActive = SF.getParsingOptions().contains(
840+
SourceFile::ParsingFlags::PoundIfAllActive);
841+
837842
bool foundActive = false;
838843
bool isVersionCondition = false;
839844
CharSourceRange activeBodyRange;
@@ -893,6 +898,9 @@ Result Parser::parseIfConfigRaw(
893898
if (ideInspectionClauseLoc.isValid() && !foundActive)
894899
isActive = (ClauseLoc == ideInspectionClauseLoc);
895900

901+
if (allActive)
902+
isActive = true;
903+
896904
foundActive |= isActive;
897905

898906
if (!Tok.isAtStartOfLine() && Tok.isNot(tok::eof)) {

lib/Parse/Parser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ struct ParserUnit::Implementation {
11451145
auto parsingOpts = SourceFile::getDefaultParsingOptions(LangOpts);
11461146
parsingOpts |= ParsingFlags::DisableDelayedBodies;
11471147
parsingOpts |= ParsingFlags::DisablePoundIfEvaluation;
1148+
parsingOpts |= ParsingFlags::PoundIfAllActive;
11481149

11491150
auto *M = ModuleDecl::createEmpty(Ctx.getIdentifier(ModuleName), Ctx);
11501151
SF = new (Ctx) SourceFile(*M, SFKind, BufferID, parsingOpts);

0 commit comments

Comments
 (0)