Skip to content

Commit 002d7d7

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 002d7d7

37 files changed

+57
-192
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) {

0 commit comments

Comments
 (0)