Skip to content

Commit 7e561b6

Browse files
committed
[NFC] Refactor DiagnosticBuilder and PartialDiagnostic
PartialDiagnostic misses some functions compared to DiagnosticBuilder. This patch refactors DiagnosticBuilder and PartialDiagnostic, extracts the common functionality so that the streaming << operators are shared. Differential Revision: https://reviews.llvm.org/D84362
1 parent ea693a1 commit 7e561b6

25 files changed

+403
-545
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
573573
mutable llvm::BumpPtrAllocator BumpAlloc;
574574

575575
/// Allocator for partial diagnostics.
576-
PartialDiagnostic::StorageAllocator DiagAllocator;
576+
PartialDiagnostic::DiagStorageAllocator DiagAllocator;
577577

578578
/// The current C++ ABI.
579579
std::unique_ptr<CXXABI> ABI;
@@ -652,7 +652,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
652652
/// Return the total memory used for various side tables.
653653
size_t getSideTableAllocatedMemory() const;
654654

655-
PartialDiagnostic::StorageAllocator &getDiagAllocator() {
655+
PartialDiagnostic::DiagStorageAllocator &getDiagAllocator() {
656656
return DiagAllocator;
657657
}
658658

@@ -3096,8 +3096,8 @@ OPT_LIST(V)
30963096
};
30973097

30983098
/// Insertion operator for diagnostics.
3099-
const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
3100-
const ASTContext::SectionInfo &Section);
3099+
const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
3100+
const ASTContext::SectionInfo &Section);
31013101

31023102
/// Utility function for constructing a nullary selector.
31033103
inline Selector GetNullarySelector(StringRef name, ASTContext &Ctx) {

clang/include/clang/AST/Attr.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,19 +350,12 @@ struct ParsedTargetAttr {
350350

351351
#include "clang/AST/Attrs.inc"
352352

353-
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
354-
const Attr *At) {
353+
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
354+
const Attr *At) {
355355
DB.AddTaggedVal(reinterpret_cast<intptr_t>(At),
356356
DiagnosticsEngine::ak_attr);
357357
return DB;
358358
}
359-
360-
inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
361-
const Attr *At) {
362-
PD.AddTaggedVal(reinterpret_cast<intptr_t>(At),
363-
DiagnosticsEngine::ak_attr);
364-
return PD;
365-
}
366359
} // end namespace clang
367360

368361
#endif

clang/include/clang/AST/CanonicalType.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ inline CanQualType Type::getCanonicalTypeUnqualified() const {
215215
return CanQualType::CreateUnsafe(getCanonicalTypeInternal());
216216
}
217217

218-
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
219-
CanQualType T) {
218+
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
219+
CanQualType T) {
220220
DB << static_cast<QualType>(T);
221221
return DB;
222222
}

clang/include/clang/AST/Decl.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4513,14 +4513,8 @@ class EmptyDecl : public Decl {
45134513

45144514
/// Insertion operator for diagnostics. This allows sending NamedDecl's
45154515
/// into a diagnostic with <<.
4516-
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
4517-
const NamedDecl* ND) {
4518-
DB.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
4519-
DiagnosticsEngine::ak_nameddecl);
4520-
return DB;
4521-
}
4522-
inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
4523-
const NamedDecl* ND) {
4516+
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD,
4517+
const NamedDecl *ND) {
45244518
PD.AddTaggedVal(reinterpret_cast<intptr_t>(ND),
45254519
DiagnosticsEngine::ak_nameddecl);
45264520
return PD;

clang/include/clang/AST/DeclCXX.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4075,11 +4075,8 @@ class MSGuidDecl : public ValueDecl,
40754075

40764076
/// Insertion operator for diagnostics. This allows sending an AccessSpecifier
40774077
/// into a diagnostic with <<.
4078-
const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
4079-
AccessSpecifier AS);
4080-
4081-
const PartialDiagnostic &operator<<(const PartialDiagnostic &DB,
4082-
AccessSpecifier AS);
4078+
const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
4079+
AccessSpecifier AS);
40834080

40844081
} // namespace clang
40854082

clang/include/clang/AST/DeclarationName.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -811,19 +811,10 @@ struct DeclarationNameInfo {
811811
SourceLocation getEndLocPrivate() const;
812812
};
813813

814-
/// Insertion operator for diagnostics. This allows sending DeclarationName's
815-
/// into a diagnostic with <<.
816-
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
817-
DeclarationName N) {
818-
DB.AddTaggedVal(N.getAsOpaqueInteger(),
819-
DiagnosticsEngine::ak_declarationname);
820-
return DB;
821-
}
822-
823814
/// Insertion operator for partial diagnostics. This allows binding
824815
/// DeclarationName's into a partial diagnostic with <<.
825-
inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
826-
DeclarationName N) {
816+
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD,
817+
DeclarationName N) {
827818
PD.AddTaggedVal(N.getAsOpaqueInteger(),
828819
DiagnosticsEngine::ak_declarationname);
829820
return PD;

clang/include/clang/AST/DependentDiagnostic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ class DependentDiagnostic {
100100
friend class DependentStoredDeclsMap;
101101

102102
DependentDiagnostic(const PartialDiagnostic &PDiag,
103-
PartialDiagnostic::Storage *Storage)
104-
: Diag(PDiag, Storage) {}
103+
DiagnosticStorage *Storage)
104+
: Diag(PDiag, Storage) {}
105105

106106
static DependentDiagnostic *Create(ASTContext &Context,
107107
DeclContext *Parent,

clang/include/clang/AST/NestedNameSpecifier.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,8 @@ class NestedNameSpecifierLocBuilder {
519519

520520
/// Insertion operator for diagnostics. This allows sending
521521
/// NestedNameSpecifiers into a diagnostic with <<.
522-
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
523-
NestedNameSpecifier *NNS) {
522+
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
523+
NestedNameSpecifier *NNS) {
524524
DB.AddTaggedVal(reinterpret_cast<intptr_t>(NNS),
525525
DiagnosticsEngine::ak_nestednamespec);
526526
return DB;

clang/include/clang/AST/TemplateBase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,8 @@ struct alignas(void *) ASTTemplateKWAndArgsInfo {
687687
TemplateArgumentListInfo &List) const;
688688
};
689689

690-
const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
691-
const TemplateArgument &Arg);
690+
const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
691+
const TemplateArgument &Arg);
692692

693693
inline TemplateSpecializationType::iterator
694694
TemplateSpecializationType::end() const {

clang/include/clang/AST/TemplateName.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,8 @@ class TemplateName {
342342

343343
/// Insertion operator for diagnostics. This allows sending TemplateName's
344344
/// into a diagnostic with <<.
345-
const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
346-
TemplateName N);
347-
const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
348-
TemplateName N);
345+
const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
346+
TemplateName N);
349347

350348
/// A structure for storing the information associated with a
351349
/// substituted template template parameter.

0 commit comments

Comments
 (0)