Skip to content

Commit f9c58fc

Browse files
committed
[Parse/AST] Remove PoundDiagnosticDecl
There is no reson to make a AST node for '#error' and '#warning' directives. Parser knows the diagnostics should be emitted or not.
1 parent 9edb7f9 commit f9c58fc

37 files changed

+57
-190
lines changed

SwiftCompilerSources/Sources/AST/Declarations.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ final public class TopLevelCodeDecl: Decl {}
110110

111111
final public class ImportDecl: Decl {}
112112

113-
final public class PoundDiagnosticDecl: Decl {}
114-
115113
final public class PrecedenceGroupDecl: Decl {}
116114

117115
final public class MissingDecl: Decl {}

SwiftCompilerSources/Sources/AST/Registration.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public func registerAST() {
3636
registerDecl(ExtensionDecl.self)
3737
registerDecl(TopLevelCodeDecl.self)
3838
registerDecl(ImportDecl.self)
39-
registerDecl(PoundDiagnosticDecl.self)
4039
registerDecl(PrecedenceGroupDecl.self)
4140
registerDecl(MissingDecl.self)
4241
registerDecl(MissingMemberDecl.self)

include/swift/AST/Decl.h

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ enum class DescriptiveDeclKind : uint8_t {
156156
Extension,
157157
EnumCase,
158158
TopLevelCode,
159-
PoundDiagnostic,
160159
PatternBinding,
161160
Var,
162161
Param,
@@ -839,14 +838,6 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
839838
HasLazyConformances : 1
840839
);
841840

842-
SWIFT_INLINE_BITFIELD(PoundDiagnosticDecl, Decl, 1+1,
843-
/// `true` if the diagnostic is an error, `false` if it's a warning.
844-
IsError : 1,
845-
846-
/// Whether this diagnostic has already been emitted.
847-
HasBeenEmitted : 1
848-
);
849-
850841
SWIFT_INLINE_BITFIELD(MissingMemberDecl, Decl, 1+2,
851842
NumberOfFieldOffsetVectorEntries : 1,
852843
NumberOfVTableEntries : 2
@@ -2799,52 +2790,6 @@ class SerializedTopLevelCodeDeclContext : public DeclContext {
27992790
}
28002791
};
28012792

2802-
class StringLiteralExpr;
2803-
2804-
class PoundDiagnosticDecl : public Decl {
2805-
SourceLoc StartLoc;
2806-
SourceLoc EndLoc;
2807-
StringLiteralExpr *Message;
2808-
SourceLoc getLocFromSource() const { return StartLoc; }
2809-
friend class Decl;
2810-
public:
2811-
PoundDiagnosticDecl(DeclContext *Parent, bool IsError, SourceLoc StartLoc,
2812-
SourceLoc EndLoc, StringLiteralExpr *Message)
2813-
: Decl(DeclKind::PoundDiagnostic, Parent), StartLoc(StartLoc),
2814-
EndLoc(EndLoc), Message(Message) {
2815-
Bits.PoundDiagnosticDecl.IsError = IsError;
2816-
Bits.PoundDiagnosticDecl.HasBeenEmitted = false;
2817-
}
2818-
2819-
DiagnosticKind getKind() const {
2820-
return isError() ? DiagnosticKind::Error : DiagnosticKind::Warning;
2821-
}
2822-
2823-
StringLiteralExpr *getMessage() const { return Message; }
2824-
2825-
bool isError() const {
2826-
return Bits.PoundDiagnosticDecl.IsError;
2827-
}
2828-
2829-
bool hasBeenEmitted() const {
2830-
return Bits.PoundDiagnosticDecl.HasBeenEmitted;
2831-
}
2832-
2833-
void markEmitted() {
2834-
Bits.PoundDiagnosticDecl.HasBeenEmitted = true;
2835-
}
2836-
2837-
SourceLoc getEndLoc() const { return EndLoc; };
2838-
2839-
SourceRange getSourceRange() const {
2840-
return SourceRange(StartLoc, EndLoc);
2841-
}
2842-
2843-
static bool classof(const Decl *D) {
2844-
return D->getKind() == DeclKind::PoundDiagnostic;
2845-
}
2846-
};
2847-
28482793
class OpaqueTypeDecl;
28492794

28502795
/// ValueDecl - All named decls that are values in the language. These can

include/swift/AST/DeclExportabilityVisitor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ class DeclExportabilityVisitor
171171
bool visit##KIND##Decl(const KIND##Decl *D) { return true; }
172172
UNINTERESTING(TopLevelCode);
173173
UNINTERESTING(Import);
174-
UNINTERESTING(PoundDiagnostic);
175174
UNINTERESTING(PrecedenceGroup);
176175
UNINTERESTING(EnumCase);
177176
UNINTERESTING(Operator);

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(PoundDiagnostic, Decl)
189188
DECL(PrecedenceGroup, Decl)
190189
DECL(Missing, Decl)
191190
DECL(MissingMember, Decl)

include/swift/AST/DiagnosticsCommon.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,5 +274,12 @@ ERROR(bridged_error, none, "%0", (StringRef))
274274
ERROR(bridged_fatal_error, Fatal, "%0", (StringRef))
275275
REMARK(bridged_remark, none, "%0", (StringRef))
276276

277+
//------------------------------------------------------------------------------
278+
// MARK: #warning and #error
279+
//------------------------------------------------------------------------------
280+
281+
WARNING(pound_warning, none, "%0", (StringRef))
282+
ERROR(pound_error, none, "%0", (StringRef))
283+
277284
#define UNDEFINE_DIAGNOSTIC_MACROS
278285
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,9 +1708,6 @@ ERROR(invalid_autoclosure_pointer_conversion,none,
17081708
ERROR(missing_initializer_def,PointsToFirstBadToken,
17091709
"initializer requires a body", ())
17101710

1711-
WARNING(pound_warning, none, "%0", (StringRef))
1712-
ERROR(pound_error, none, "%0", (StringRef))
1713-
17141711
// Attributes
17151712

17161713
ERROR(operator_not_func,none,

include/swift/AST/TypeMemberVisitor.h

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

45-
// These decls are disregarded.
46-
RetTy visitPoundDiagnosticDecl(PoundDiagnosticDecl *D) {
47-
return RetTy();
48-
}
49-
5045
RetTy visitMacroExpansionDecl(MacroExpansionDecl *D) {
5146
// Expansion already visited as auxiliary decls.
5247
return RetTy();

include/swift/Parse/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ class Parser {
984984
DeclAttributes &attributes, bool ifConfigsAreDeclAttrs);
985985

986986
/// Parse a #error or #warning diagnostic.
987-
ParserResult<PoundDiagnosticDecl> parseDeclPoundDiagnostic();
987+
ParserStatus parseDeclPoundDiagnostic();
988988

989989
/// Parse a #line/#sourceLocation directive.
990990
/// 'isLine = true' indicates parsing #line instead of #sourcelocation

include/swift/SIL/SILWitnessVisitor.h

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

175-
void visitPoundDiagnosticDecl(PoundDiagnosticDecl *pdd) {
176-
// We don't care about diagnostics at this stage.
177-
}
178-
179175
private:
180176
void addAutoDiffDerivativeMethodsIfRequired(AbstractFunctionDecl *AFD,
181177
SILDeclRef::Kind kind) {

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,8 +1935,6 @@ SwiftDeclCollector::addMembersToRoot(SDKNode *Root, IterableDeclContext *Context
19351935
// All containing variables should have been handled.
19361936
} else if (isa<EnumCaseDecl>(Member)) {
19371937
// All containing variables should have been handled.
1938-
} else if (isa<PoundDiagnosticDecl>(Member)) {
1939-
// All containing members should have been handled.
19401938
} else if (isa<DestructorDecl>(Member)) {
19411939
// deinit has no impact.
19421940
} else if (isa<MissingMemberDecl>(Member)) {

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,13 +2691,6 @@ namespace {
26912691
printFoot();
26922692
}
26932693

2694-
void visitPoundDiagnosticDecl(PoundDiagnosticDecl *PDD, Label label) {
2695-
printCommon(PDD, "pound_diagnostic_decl", label);
2696-
printField(PDD->isError() ? "error" : "warning", Label::always("kind"));
2697-
printRec(PDD->getMessage(), Label::optional("message"));
2698-
printFoot();
2699-
}
2700-
27012694
void visitPrecedenceGroupDecl(PrecedenceGroupDecl *PGD, Label label) {
27022695
printCommon(PGD, "precedence_group_decl", label);
27032696
printName(PGD->getName(), Label::optional("name"));

lib/AST/ASTMangler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5289,7 +5289,6 @@ ASTMangler::BaseEntitySignature::BaseEntitySignature(const Decl *decl)
52895289
case DeclKind::Extension:
52905290
case DeclKind::TopLevelCode:
52915291
case DeclKind::Import:
5292-
case DeclKind::PoundDiagnostic:
52935292
case DeclKind::PrecedenceGroup:
52945293
case DeclKind::Missing:
52955294
case DeclKind::MissingMember:

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3522,17 +3522,6 @@ void PrintAST::visitTopLevelCodeDecl(TopLevelCodeDecl *decl) {
35223522
printASTNodes(decl->getBody()->getElements(), /*NeedIndent=*/false);
35233523
}
35243524

3525-
void PrintAST::visitPoundDiagnosticDecl(PoundDiagnosticDecl *PDD) {
3526-
/// TODO: Should we even print #error/#warning?
3527-
if (PDD->isError()) {
3528-
Printer << tok::pound_error;
3529-
} else {
3530-
Printer << tok::pound_warning;
3531-
}
3532-
3533-
Printer << "(\"" << PDD->getMessage()->getValue() << "\")";
3534-
}
3535-
35363525
void PrintAST::visitOpaqueTypeDecl(OpaqueTypeDecl *decl) {
35373526
// TODO: If we introduce explicit opaque type decls, print them.
35383527
assert(decl->getName().empty());

lib/AST/ASTScopeCreation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ class NodeAdder
364364
VISIT_AND_IGNORE(AssociatedTypeDecl)
365365
VISIT_AND_IGNORE(ModuleDecl)
366366
VISIT_AND_IGNORE(ParamDecl)
367-
VISIT_AND_IGNORE(PoundDiagnosticDecl)
368367
VISIT_AND_IGNORE(MissingDecl)
369368
VISIT_AND_IGNORE(MissingMemberDecl)
370369

lib/AST/ASTWalker.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,6 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
244244
return true;
245245
}
246246

247-
bool visitPoundDiagnosticDecl(PoundDiagnosticDecl *PDD) {
248-
// By default, ignore #error/#warning.
249-
return false;
250-
}
251-
252247
bool visitOperatorDecl(OperatorDecl *OD) {
253248
return false;
254249
}
@@ -2076,10 +2071,6 @@ Stmt *Traversal::visitSwitchStmt(SwitchStmt *S) {
20762071
(void)aStmt;
20772072
} else
20782073
return nullptr;
2079-
} else {
2080-
assert(isa<PoundDiagnosticDecl>(N.get<Decl*>()));
2081-
if (doIt(N.get<Decl*>()))
2082-
return nullptr;
20832074
}
20842075
}
20852076

lib/AST/Decl.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ DescriptiveDeclKind Decl::getDescriptiveKind() const {
170170
TRIVIAL_KIND(Extension);
171171
TRIVIAL_KIND(EnumCase);
172172
TRIVIAL_KIND(TopLevelCode);
173-
TRIVIAL_KIND(PoundDiagnostic);
174173
TRIVIAL_KIND(PatternBinding);
175174
TRIVIAL_KIND(PrecedenceGroup);
176175
TRIVIAL_KIND(InfixOperator);
@@ -337,7 +336,6 @@ StringRef Decl::getDescriptiveKindName(DescriptiveDeclKind K) {
337336
ENTRY(Extension, "extension");
338337
ENTRY(EnumCase, "case");
339338
ENTRY(TopLevelCode, "top-level code");
340-
ENTRY(PoundDiagnostic, "diagnostic");
341339
ENTRY(PatternBinding, "pattern binding");
342340
ENTRY(Var, "var");
343341
ENTRY(Param, "parameter");
@@ -1616,7 +1614,6 @@ ImportKind ImportDecl::getBestImportKind(const ValueDecl *VD) {
16161614
case DeclKind::PrefixOperator:
16171615
case DeclKind::PostfixOperator:
16181616
case DeclKind::EnumCase:
1619-
case DeclKind::PoundDiagnostic:
16201617
case DeclKind::PrecedenceGroup:
16211618
case DeclKind::Missing:
16221619
case DeclKind::MissingMember:
@@ -3457,7 +3454,6 @@ bool ValueDecl::isInstanceMember() const {
34573454
case DeclKind::InfixOperator:
34583455
case DeclKind::PrefixOperator:
34593456
case DeclKind::PostfixOperator:
3460-
case DeclKind::PoundDiagnostic:
34613457
case DeclKind::PrecedenceGroup:
34623458
case DeclKind::Missing:
34633459
case DeclKind::MissingMember:
@@ -4506,7 +4502,6 @@ SourceLoc Decl::getAttributeInsertionLoc(bool forModifier) const {
45064502
switch (getKind()) {
45074503
case DeclKind::Module:
45084504
case DeclKind::TopLevelCode:
4509-
case DeclKind::PoundDiagnostic:
45104505
case DeclKind::Missing:
45114506
case DeclKind::MissingMember:
45124507
case DeclKind::MacroExpansion:

lib/AST/FrontendSourceFileDepGraphFactory.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ StringRef DependencyKey::Builder::getTopLevelName(const Decl *decl) {
217217
case DeclKind::PatternBinding:
218218
case DeclKind::EnumCase:
219219
case DeclKind::TopLevelCode:
220-
case DeclKind::PoundDiagnostic:
221220
case DeclKind::Missing:
222221
case DeclKind::MissingMember:
223222
case DeclKind::Module:

lib/AST/Stmt.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,7 @@ SwitchStmt *SwitchStmt::create(LabeledStmtInfo LabelInfo, SourceLoc SwitchLoc,
948948
ASTContext &C) {
949949
#ifndef NDEBUG
950950
for (auto N : Cases)
951-
assert((N.is<Stmt*>() && isa<CaseStmt>(N.get<Stmt*>())) ||
952-
(N.is<Decl*>() && (isa<PoundDiagnosticDecl>(N.get<Decl*>()))));
951+
assert(N.is<Stmt*>() && isa<CaseStmt>(N.get<Stmt*>()));
953952
#endif
954953

955954
void *p = C.Allocate(totalSizeToAlloc<ASTNode>(Cases.size()),

lib/IDE/CodeCompletionResult.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ ContextFreeCodeCompletionResult::getCodeCompletionDeclKind(const Decl *D) {
310310
case DeclKind::PatternBinding:
311311
case DeclKind::EnumCase:
312312
case DeclKind::TopLevelCode:
313-
case DeclKind::PoundDiagnostic:
314313
case DeclKind::Missing:
315314
case DeclKind::MissingMember:
316315
case DeclKind::OpaqueType:

lib/IDE/Formatting.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,6 @@ class RangeWalker: protected ASTWalker {
525525
SourceRange Braces(PGD->getLBraceLoc(), PGD->getRBraceLoc());
526526
if (!handleBraces(Braces, ContextLoc))
527527
return Action::Stop();
528-
} else if (isa<PoundDiagnosticDecl>(D)) {
529-
// TODO: add paren locations to PoundDiagnosticDecl
530528
}
531529

532530
return Action::Continue();
@@ -1909,17 +1907,6 @@ class FormatWalker : public ASTWalker {
19091907
return IndentContext {ContextLoc, !OutdentChecker::hasOutdent(SM, D)};
19101908
}
19111909

1912-
if (auto *PDD = dyn_cast<PoundDiagnosticDecl>(D)) {
1913-
SourceLoc ContextLoc = PDD->getStartLoc();
1914-
// FIXME: add paren source locations to the AST Node.
1915-
if (auto *SLE = PDD->getMessage()) {
1916-
SourceRange MessageRange = SLE->getSourceRange();
1917-
if (MessageRange.isValid() && overlapsTarget(MessageRange))
1918-
return IndentContext {ContextLoc, true};
1919-
}
1920-
return IndentContext {ContextLoc, !OutdentChecker::hasOutdent(SM, D)};
1921-
}
1922-
19231910
switch (D->getKind()) {
19241911
case DeclKind::InfixOperator:
19251912
case DeclKind::PostfixOperator:

lib/IRGen/GenDecl.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,7 +2586,6 @@ void IRGenModule::emitGlobalDecl(Decl *D) {
25862586
case DeclKind::TypeAlias:
25872587
case DeclKind::GenericTypeParam:
25882588
case DeclKind::AssociatedType:
2589-
case DeclKind::PoundDiagnostic:
25902589
case DeclKind::Macro:
25912590
return;
25922591

@@ -5744,7 +5743,6 @@ void IRGenModule::emitNestedTypeDecls(DeclRange members) {
57445743
case DeclKind::Missing:
57455744
llvm_unreachable("missing decl in IRGen");
57465745

5747-
case DeclKind::PoundDiagnostic:
57485746
case DeclKind::Macro:
57495747
continue;
57505748

lib/Index/IndexSymbol.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ SymbolInfo index::getSymbolInfoForDecl(const Decl *D) {
242242
case DeclKind::PatternBinding:
243243
case DeclKind::EnumCase:
244244
case DeclKind::TopLevelCode:
245-
case DeclKind::PoundDiagnostic:
246245
case DeclKind::Missing:
247246
case DeclKind::MissingMember:
248247
case DeclKind::Module:

0 commit comments

Comments
 (0)