Skip to content

Commit accd108

Browse files
authored
Merge pull request swiftlang#79857 from rintaro/retire-pound-diagnostics-decl
[Parse/AST] Remove PoundDiagnosticDecl
2 parents b57f8a9 + 5eac58e commit accd108

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+119
-305
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/Stmt.h

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ class CaseStmt final
14081408

14091409
/// Switch statement.
14101410
class SwitchStmt final : public LabeledStmt,
1411-
private llvm::TrailingObjects<SwitchStmt, ASTNode> {
1411+
private llvm::TrailingObjects<SwitchStmt, CaseStmt *> {
14121412
friend TrailingObjects;
14131413

14141414
SourceLoc SwitchLoc, LBraceLoc, RBraceLoc;
@@ -1431,16 +1431,13 @@ class SwitchStmt final : public LabeledStmt,
14311431
public:
14321432
/// Allocate a new SwitchStmt in the given ASTContext.
14331433
static SwitchStmt *create(LabeledStmtInfo LabelInfo, SourceLoc SwitchLoc,
1434-
Expr *SubjectExpr,
1435-
SourceLoc LBraceLoc,
1436-
ArrayRef<ASTNode> Cases,
1437-
SourceLoc RBraceLoc,
1438-
SourceLoc EndLoc,
1439-
ASTContext &C);
1434+
Expr *SubjectExpr, SourceLoc LBraceLoc,
1435+
ArrayRef<CaseStmt *> Cases, SourceLoc RBraceLoc,
1436+
SourceLoc EndLoc, ASTContext &C);
14401437

14411438
static SwitchStmt *createImplicit(LabeledStmtInfo LabelInfo,
1442-
Expr *SubjectExpr, ArrayRef<ASTNode> Cases,
1443-
ASTContext &C) {
1439+
Expr *SubjectExpr,
1440+
ArrayRef<CaseStmt *> Cases, ASTContext &C) {
14441441
return SwitchStmt::create(LabelInfo, /*SwitchLoc=*/SourceLoc(), SubjectExpr,
14451442
/*LBraceLoc=*/SourceLoc(), Cases,
14461443
/*RBraceLoc=*/SourceLoc(), /*EndLoc=*/SourceLoc(),
@@ -1463,27 +1460,10 @@ class SwitchStmt final : public LabeledStmt,
14631460
Expr *getSubjectExpr() const { return SubjectExpr; }
14641461
void setSubjectExpr(Expr *e) { SubjectExpr = e; }
14651462

1466-
ArrayRef<ASTNode> getRawCases() const {
1467-
return {getTrailingObjects<ASTNode>(), static_cast<size_t>(Bits.SwitchStmt.CaseCount)};
1468-
}
1469-
1470-
private:
1471-
struct AsCaseStmtWithSkippingNonCaseStmts {
1472-
AsCaseStmtWithSkippingNonCaseStmts() {}
1473-
std::optional<CaseStmt *> operator()(const ASTNode &N) const {
1474-
if (auto *CS = llvm::dyn_cast_or_null<CaseStmt>(N.dyn_cast<Stmt*>()))
1475-
return CS;
1476-
return std::nullopt;
1477-
}
1478-
};
1479-
1480-
public:
1481-
using AsCaseStmtRange = OptionalTransformRange<ArrayRef<ASTNode>,
1482-
AsCaseStmtWithSkippingNonCaseStmts>;
1483-
14841463
/// Get the list of case clauses.
1485-
AsCaseStmtRange getCases() const {
1486-
return AsCaseStmtRange(getRawCases(), AsCaseStmtWithSkippingNonCaseStmts());
1464+
ArrayRef<CaseStmt *> getCases() const {
1465+
return {getTrailingObjects<CaseStmt *>(),
1466+
static_cast<size_t>(Bits.SwitchStmt.CaseCount)};
14871467
}
14881468

14891469
/// Retrieve the complete set of branches for this switch statement.

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: 3 additions & 2 deletions
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
@@ -1969,7 +1969,8 @@ class Parser {
19691969
ParserResult<CaseStmt> parseStmtCatch();
19701970
ParserResult<Stmt> parseStmtForEach(LabeledStmtInfo LabelInfo);
19711971
ParserResult<Stmt> parseStmtSwitch(LabeledStmtInfo LabelInfo);
1972-
ParserStatus parseStmtCases(SmallVectorImpl<ASTNode> &cases, bool IsActive);
1972+
ParserStatus parseStmtCases(SmallVectorImpl<CaseStmt *> &cases,
1973+
bool IsActive);
19731974
ParserResult<CaseStmt> parseStmtCase(bool IsActive);
19741975
ParserResult<Stmt> parseStmtPoundAssert();
19751976

0 commit comments

Comments
 (0)