Skip to content

Commit 8944ec0

Browse files
committed
Add 'EscapedFromIfConfig' bit to Decl
This is a temporary stop-gap for getting round-trip parsing off the ground. The real fix, not re-injecting declarations into an if-config's declaration context, is a deep dive and is still ongoing.
1 parent e1a960c commit 8944ec0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

include/swift/AST/Decl.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,12 @@ class alignas(1 << DeclAlignInBits) Decl {
237237

238238
/// \brief Whether this declaration is currently being validated.
239239
unsigned BeingValidated : 1;
240+
241+
/// \brief Whether this declaration was added to the surrounding
242+
/// DeclContext of an active #if config clause.
243+
unsigned EscapedFromIfConfig : 1;
240244
};
241-
enum { NumDeclBits = 11 };
245+
enum { NumDeclBits = 12 };
242246
static_assert(NumDeclBits <= 32, "fits in an unsigned");
243247

244248
class PatternBindingDeclBitfields {
@@ -649,6 +653,7 @@ class alignas(1 << DeclAlignInBits) Decl {
649653
DeclBits.FromClang = false;
650654
DeclBits.EarlyAttrValidation = false;
651655
DeclBits.BeingValidated = false;
656+
DeclBits.EscapedFromIfConfig = false;
652657
}
653658

654659
ClangNode getClangNodeImpl() const {
@@ -804,6 +809,14 @@ class alignas(1 << DeclAlignInBits) Decl {
804809
DeclBits.BeingValidated = ibv;
805810
}
806811

812+
bool escapedFromIfConfig() const {
813+
return DeclBits.EscapedFromIfConfig;
814+
}
815+
816+
void setEscapedFromIfConfig(bool Escaped) {
817+
DeclBits.EscapedFromIfConfig = Escaped;
818+
}
819+
807820
/// \returns the unparsed comment attached to this declaration.
808821
RawComment getRawComment() const;
809822

lib/Parse/ParseStmt.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ ParserStatus Parser::parseBraceItems(SmallVectorImpl<ASTNode> &Entries,
345345
IfConfigStmt *ICS = cast<IfConfigStmt>(Result.get<Stmt*>());
346346
for (auto &Entry : ICS->getActiveClauseElements()) {
347347
Entries.push_back(Entry);
348+
if (Entry.is<Decl*>()) {
349+
Entry.get<Decl*>()->setEscapedFromIfConfig(true);
350+
}
348351
}
349352
} else if (Tok.is(tok::pound_line)) {
350353
ParserStatus Status = parseLineDirective(true);

0 commit comments

Comments
 (0)