Skip to content

Commit 5b2520e

Browse files
committed
Remove IfConfigDecl from the AST
The swift-syntax tree retains information about the parsed #if regions. Drop it from the semantic AST.
1 parent d762dd5 commit 5b2520e

38 files changed

+16
-476
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ enum class DescriptiveDeclKind : uint8_t {
151151
Extension,
152152
EnumCase,
153153
TopLevelCode,
154-
IfConfig,
155154
PoundDiagnostic,
156155
PatternBinding,
157156
Var,
@@ -819,11 +818,6 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
819818
HasLazyConformances : 1
820819
);
821820

822-
SWIFT_INLINE_BITFIELD(IfConfigDecl, Decl, 1,
823-
/// Whether this decl is missing its closing '#endif'.
824-
HadMissingEnd : 1
825-
);
826-
827821
SWIFT_INLINE_BITFIELD(PoundDiagnosticDecl, Decl, 1+1,
828822
/// `true` if the diagnostic is an error, `false` if it's a warning.
829823
IsError : 1,
@@ -2658,51 +2652,6 @@ class SerializedTopLevelCodeDeclContext : public DeclContext {
26582652
}
26592653
};
26602654

2661-
/// IfConfigDecl - This class represents #if/#else/#endif blocks.
2662-
/// Active and inactive block members are stored separately, with the intention
2663-
/// being that active members will be handed back to the enclosing context.
2664-
class IfConfigDecl : public Decl {
2665-
/// An array of clauses controlling each of the #if/#elseif/#else conditions.
2666-
/// The array is ASTContext allocated.
2667-
ArrayRef<IfConfigClause> Clauses;
2668-
SourceLoc EndLoc;
2669-
SourceLoc getLocFromSource() const { return Clauses[0].Loc; }
2670-
friend class Decl;
2671-
public:
2672-
2673-
IfConfigDecl(DeclContext *Parent, ArrayRef<IfConfigClause> Clauses,
2674-
SourceLoc EndLoc, bool HadMissingEnd)
2675-
: Decl(DeclKind::IfConfig, Parent), Clauses(Clauses), EndLoc(EndLoc)
2676-
{
2677-
Bits.IfConfigDecl.HadMissingEnd = HadMissingEnd;
2678-
}
2679-
2680-
ArrayRef<IfConfigClause> getClauses() const { return Clauses; }
2681-
2682-
/// Return the active clause, or null if there is no active one.
2683-
const IfConfigClause *getActiveClause() const {
2684-
for (auto &Clause : Clauses)
2685-
if (Clause.isActive) return &Clause;
2686-
return nullptr;
2687-
}
2688-
2689-
const ArrayRef<ASTNode> getActiveClauseElements() const {
2690-
if (auto *Clause = getActiveClause())
2691-
return Clause->Elements;
2692-
return {};
2693-
}
2694-
2695-
SourceLoc getEndLoc() const { return EndLoc; }
2696-
2697-
bool hadMissingEnd() const { return Bits.IfConfigDecl.HadMissingEnd; }
2698-
2699-
SourceRange getSourceRange() const;
2700-
2701-
static bool classof(const Decl *D) {
2702-
return D->getKind() == DeclKind::IfConfig;
2703-
}
2704-
};
2705-
27062655
class StringLiteralExpr;
27072656

27082657
class PoundDiagnosticDecl : public Decl {

include/swift/AST/DeclExportabilityVisitor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ class DeclExportabilityVisitor
170170
#define UNINTERESTING(KIND) \
171171
bool visit##KIND##Decl(const KIND##Decl *D) { return true; }
172172
UNINTERESTING(TopLevelCode);
173-
UNINTERESTING(IfConfig);
174173
UNINTERESTING(Import);
175174
UNINTERESTING(PoundDiagnostic);
176175
UNINTERESTING(PrecedenceGroup);

include/swift/AST/DeclNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ ABSTRACT_DECL(Value, Decl)
185185
ITERABLE_GENERIC_DECL(Extension, Decl)
186186
CONTEXT_DECL(TopLevelCode, Decl)
187187
DECL(Import, Decl)
188-
DECL(IfConfig, Decl)
189188
DECL(PoundDiagnostic, Decl)
190189
DECL(PrecedenceGroup, Decl)
191190
DECL(Missing, Decl)

include/swift/AST/TypeMemberVisitor.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ class TypeMemberVisitor : public DeclVisitor<ImplClass, RetTy> {
4242
BAD_MEMBER(PrecedenceGroup)
4343
BAD_MEMBER(Macro)
4444

45-
// The children of these are automatically inserted into the
46-
// surrounding context.
47-
RetTy visitIfConfigDecl(IfConfigDecl *D) {
48-
return RetTy();
49-
}
50-
5145
// These decls are disregarded.
5246
RetTy visitPoundDiagnosticDecl(PoundDiagnosticDecl *D) {
5347
return RetTy();

include/swift/Parse/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ class Parser {
10231023
llvm::function_ref<void(bool)> parseElements);
10241024

10251025
/// Parse an #if ... #endif containing only attributes.
1026-
ParserStatus parseIfConfigDeclAttributes(
1026+
ParserStatus parseIfConfigAttributes(
10271027
DeclAttributes &attributes, bool ifConfigsAreDeclAttrs,
10281028
PatternBindingInitializer *initContext);
10291029

include/swift/SIL/SILWitnessVisitor.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,6 @@ template <class T> class SILWitnessVisitor : public ASTVisitor<T> {
172172
// We only care about the contained VarDecls.
173173
}
174174

175-
void visitIfConfigDecl(IfConfigDecl *icd) {
176-
// We only care about the active members, which were already subsumed by the
177-
// enclosing type.
178-
}
179-
180175
void visitPoundDiagnosticDecl(PoundDiagnosticDecl *pdd) {
181176
// We don't care about diagnostics at this stage.
182177
}

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,8 +1943,6 @@ SwiftDeclCollector::addMembersToRoot(SDKNode *Root, IterableDeclContext *Context
19431943
// All containing variables should have been handled.
19441944
} else if (isa<EnumCaseDecl>(Member)) {
19451945
// All containing variables should have been handled.
1946-
} else if (isa<IfConfigDecl>(Member)) {
1947-
// All containing members should have been handled.
19481946
} else if (isa<PoundDiagnosticDecl>(Member)) {
19491947
// All containing members should have been handled.
19501948
} else if (isa<DestructorDecl>(Member)) {

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,12 +1634,6 @@ namespace {
16341634
printFoot();
16351635
}
16361636

1637-
void visitIfConfigDecl(IfConfigDecl *ICD, StringRef label) {
1638-
printCommon(ICD, "if_config_decl", label);
1639-
printRecRange(ICD->getClauses(), &ICD->getASTContext(), "clauses");
1640-
printFoot();
1641-
}
1642-
16431637
void visitPoundDiagnosticDecl(PoundDiagnosticDecl *PDD, StringRef label) {
16441638
printCommon(PDD, "pound_diagnostic_decl", label);
16451639
printField(PDD->isError() ? "error" : "warning", "kind");

lib/AST/ASTMangler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4871,7 +4871,6 @@ ASTMangler::BaseEntitySignature::BaseEntitySignature(const Decl *decl)
48714871
case DeclKind::Extension:
48724872
case DeclKind::TopLevelCode:
48734873
case DeclKind::Import:
4874-
case DeclKind::IfConfig:
48754874
case DeclKind::PoundDiagnostic:
48764875
case DeclKind::PrecedenceGroup:
48774876
case DeclKind::Missing:

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,10 +2284,6 @@ bool ShouldPrintChecker::shouldPrint(const Decl *D,
22842284
return false;
22852285
}
22862286

2287-
if (isa<IfConfigDecl>(D)) {
2288-
return false;
2289-
}
2290-
22912287
return true;
22922288
}
22932289

@@ -3373,10 +3369,6 @@ void PrintAST::visitTopLevelCodeDecl(TopLevelCodeDecl *decl) {
33733369
printASTNodes(decl->getBody()->getElements(), /*NeedIndent=*/false);
33743370
}
33753371

3376-
void PrintAST::visitIfConfigDecl(IfConfigDecl *ICD) {
3377-
// Never printed
3378-
}
3379-
33803372
void PrintAST::visitPoundDiagnosticDecl(PoundDiagnosticDecl *PDD) {
33813373
/// TODO: Should we even print #error/#warning?
33823374
if (PDD->isError()) {
@@ -5533,8 +5525,6 @@ void PrintAST::visitSwitchStmt(SwitchStmt *stmt) {
55335525
for (auto N : stmt->getRawCases()) {
55345526
if (N.is<Stmt*>())
55355527
visit(cast<CaseStmt>(N.get<Stmt*>()));
5536-
else
5537-
visit(cast<IfConfigDecl>(N.get<Decl*>()));
55385528
Printer.printNewline();
55395529
}
55405530
indent();
@@ -5633,10 +5623,6 @@ bool Decl::shouldPrintInContext(const PrintOptions &PO) const {
56335623
}
56345624
}
56355625

5636-
if (isa<IfConfigDecl>(this)) {
5637-
return false;
5638-
}
5639-
56405626
// Print everything else.
56415627
return true;
56425628
}

0 commit comments

Comments
 (0)