|
23 | 23 | #include "swift/AST/ClangNode.h" |
24 | 24 | #include "swift/AST/ConcreteDeclRef.h" |
25 | 25 | #include "swift/AST/DefaultArgumentKind.h" |
| 26 | +#include "swift/AST/DiagnosticConsumer.h" |
26 | 27 | #include "swift/AST/GenericParamKey.h" |
27 | 28 | #include "swift/AST/IfConfigClause.h" |
28 | 29 | #include "swift/AST/LayoutConstraint.h" |
@@ -107,6 +108,7 @@ enum class DescriptiveDeclKind : uint8_t { |
107 | 108 | EnumCase, |
108 | 109 | TopLevelCode, |
109 | 110 | IfConfig, |
| 111 | + PoundDiagnostic, |
110 | 112 | PatternBinding, |
111 | 113 | Var, |
112 | 114 | Param, |
@@ -591,6 +593,14 @@ class alignas(1 << DeclAlignInBits) Decl { |
591 | 593 | HadMissingEnd : 1 |
592 | 594 | ); |
593 | 595 |
|
| 596 | + SWIFT_INLINE_BITFIELD(PoundDiagnosticDecl, Decl, 1+1, |
| 597 | + /// `true` if the diagnostic is an error, `false` if it's a warning. |
| 598 | + IsError : 1, |
| 599 | + |
| 600 | + /// Whether this diagnostic has already been emitted. |
| 601 | + HasBeenEmitted : 1 |
| 602 | + ); |
| 603 | + |
594 | 604 | SWIFT_INLINE_BITFIELD(MissingMemberDecl, Decl, 1+2, |
595 | 605 | NumberOfFieldOffsetVectorEntries : 1, |
596 | 606 | NumberOfVTableEntries : 2 |
@@ -2059,6 +2069,52 @@ class IfConfigDecl : public Decl { |
2059 | 2069 | } |
2060 | 2070 | }; |
2061 | 2071 |
|
| 2072 | +class StringLiteralExpr; |
| 2073 | + |
| 2074 | +class PoundDiagnosticDecl : public Decl { |
| 2075 | + SourceLoc StartLoc; |
| 2076 | + SourceLoc EndLoc; |
| 2077 | + StringLiteralExpr *Message; |
| 2078 | + |
| 2079 | +public: |
| 2080 | + PoundDiagnosticDecl(DeclContext *Parent, bool IsError, SourceLoc StartLoc, |
| 2081 | + SourceLoc EndLoc, StringLiteralExpr *Message) |
| 2082 | + : Decl(DeclKind::PoundDiagnostic, Parent), StartLoc(StartLoc), |
| 2083 | + EndLoc(EndLoc), Message(Message) { |
| 2084 | + Bits.PoundDiagnosticDecl.IsError = IsError; |
| 2085 | + Bits.PoundDiagnosticDecl.HasBeenEmitted = false; |
| 2086 | + } |
| 2087 | + |
| 2088 | + DiagnosticKind getKind() { |
| 2089 | + return isError() ? DiagnosticKind::Error : DiagnosticKind::Warning; |
| 2090 | + } |
| 2091 | + |
| 2092 | + StringLiteralExpr *getMessage() { return Message; } |
| 2093 | + |
| 2094 | + bool isError() { |
| 2095 | + return Bits.PoundDiagnosticDecl.IsError; |
| 2096 | + } |
| 2097 | + |
| 2098 | + bool hasBeenEmitted() { |
| 2099 | + return Bits.PoundDiagnosticDecl.HasBeenEmitted; |
| 2100 | + } |
| 2101 | + |
| 2102 | + void markEmitted() { |
| 2103 | + Bits.PoundDiagnosticDecl.HasBeenEmitted = true; |
| 2104 | + } |
| 2105 | + |
| 2106 | + SourceLoc getEndLoc() const { return EndLoc; }; |
| 2107 | + SourceLoc getLoc() const { return StartLoc; } |
| 2108 | + |
| 2109 | + SourceRange getSourceRange() const { |
| 2110 | + return SourceRange(StartLoc, EndLoc); |
| 2111 | + } |
| 2112 | + |
| 2113 | + static bool classof(const Decl *D) { |
| 2114 | + return D->getKind() == DeclKind::PoundDiagnostic; |
| 2115 | + } |
| 2116 | +}; |
| 2117 | + |
2062 | 2118 | /// ValueDecl - All named decls that are values in the language. These can |
2063 | 2119 | /// have a type, etc. |
2064 | 2120 | class ValueDecl : public Decl { |
|
0 commit comments