|
15 | 15 | #define LLVM_CLANG_BASIC_ATTRIBUTECOMMONINFO_H |
16 | 16 |
|
17 | 17 | #include "clang/Basic/AttributeScopeInfo.h" |
| 18 | +#include "clang/Basic/Diagnostic.h" |
18 | 19 | #include "clang/Basic/SourceLocation.h" |
19 | 20 | #include "clang/Basic/TokenKinds.h" |
20 | 21 |
|
@@ -175,6 +176,10 @@ class AttributeCommonInfo { |
175 | 176 | : AttributeCommonInfo(nullptr, AttributeScopeInfo(), AttrRange, K, |
176 | 177 | FormUsed) {} |
177 | 178 |
|
| 179 | + AttributeCommonInfo(SourceRange AttrRange, AttributeScopeInfo AttrScope, |
| 180 | + Kind K, Form FormUsed) |
| 181 | + : AttributeCommonInfo(nullptr, AttrScope, AttrRange, K, FormUsed) {} |
| 182 | + |
178 | 183 | AttributeCommonInfo(AttributeCommonInfo &&) = default; |
179 | 184 | AttributeCommonInfo(const AttributeCommonInfo &) = default; |
180 | 185 |
|
@@ -292,6 +297,45 @@ inline bool doesKeywordAttributeTakeArgs(tok::TokenKind Kind) { |
292 | 297 | } |
293 | 298 | } |
294 | 299 |
|
| 300 | +inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB, |
| 301 | + const AttributeCommonInfo &CI) { |
| 302 | + DB.AddTaggedVal(reinterpret_cast<uint64_t>(&CI), |
| 303 | + DiagnosticsEngine::ak_attr_info); |
| 304 | + return DB; |
| 305 | +} |
| 306 | + |
| 307 | +inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB, |
| 308 | + const AttributeCommonInfo *CI) { |
| 309 | + DB.AddTaggedVal(reinterpret_cast<uint64_t>(CI), |
| 310 | + DiagnosticsEngine::ak_attr_info); |
| 311 | + return DB; |
| 312 | +} |
| 313 | + |
| 314 | +/// AttributeCommonInfo has a non-explicit constructor which takes an |
| 315 | +/// SourceRange as its only argument, this constructor has many uses so making |
| 316 | +/// it explicit is hard. This constructor causes ambiguity with |
| 317 | +/// DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, SourceRange R). |
| 318 | +/// We use SFINAE to disable any conversion and remove any ambiguity. |
| 319 | +template < |
| 320 | + typename ACI, |
| 321 | + std::enable_if_t<std::is_same<ACI, AttributeCommonInfo>::value, int> = 0> |
| 322 | +inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB, |
| 323 | + const ACI &CI) { |
| 324 | + DB.AddTaggedVal(reinterpret_cast<uint64_t>(&CI), |
| 325 | + DiagnosticsEngine::ak_attr_info); |
| 326 | + return DB; |
| 327 | +} |
| 328 | + |
| 329 | +template < |
| 330 | + typename ACI, |
| 331 | + std::enable_if_t<std::is_same<ACI, AttributeCommonInfo>::value, int> = 0> |
| 332 | +inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB, |
| 333 | + const ACI *CI) { |
| 334 | + DB.AddTaggedVal(reinterpret_cast<uint64_t>(CI), |
| 335 | + DiagnosticsEngine::ak_attr_info); |
| 336 | + return DB; |
| 337 | +} |
| 338 | + |
295 | 339 | } // namespace clang |
296 | 340 |
|
297 | 341 | #endif // LLVM_CLANG_BASIC_ATTRIBUTECOMMONINFO_H |
0 commit comments