1 //==- DependentDiagnostic.h - Dependently-generated diagnostics --*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines interfaces for diagnostics which may or may
11 // fire based on how a template is instantiated.
13 // At the moment, the only consumer of this interface is access
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_CLANG_AST_DEPENDENTDIAGNOSTIC_H
19 #define LLVM_CLANG_AST_DEPENDENTDIAGNOSTIC_H
21 #include "clang/AST/DeclBase.h"
22 #include "clang/AST/DeclContextInternals.h"
23 #include "clang/AST/Type.h"
24 #include "clang/Basic/PartialDiagnostic.h"
25 #include "clang/Basic/SourceLocation.h"
26 #include "clang/Basic/Specifiers.h"
36 /// A dependently-generated diagnostic.
37 class DependentDiagnostic {
39 enum AccessNonce { Access = 0 };
41 static DependentDiagnostic *Create(ASTContext &Context,
47 NamedDecl *TargetDecl,
48 CXXRecordDecl *NamingClass,
49 QualType BaseObjectType,
50 const PartialDiagnostic &PDiag) {
51 DependentDiagnostic *DD = Create(Context, Parent, PDiag);
52 DD->AccessData.Loc = Loc.getRawEncoding();
53 DD->AccessData.IsMember = IsMemberAccess;
54 DD->AccessData.Access = AS;
55 DD->AccessData.TargetDecl = TargetDecl;
56 DD->AccessData.NamingClass = NamingClass;
57 DD->AccessData.BaseObjectType = BaseObjectType.getAsOpaquePtr();
61 unsigned getKind() const {
65 bool isAccessToMember() const {
66 assert(getKind() == Access);
67 return AccessData.IsMember;
70 AccessSpecifier getAccess() const {
71 assert(getKind() == Access);
72 return AccessSpecifier(AccessData.Access);
75 SourceLocation getAccessLoc() const {
76 assert(getKind() == Access);
77 return SourceLocation::getFromRawEncoding(AccessData.Loc);
80 NamedDecl *getAccessTarget() const {
81 assert(getKind() == Access);
82 return AccessData.TargetDecl;
85 NamedDecl *getAccessNamingClass() const {
86 assert(getKind() == Access);
87 return AccessData.NamingClass;
90 QualType getAccessBaseObjectType() const {
91 assert(getKind() == Access);
92 return QualType::getFromOpaquePtr(AccessData.BaseObjectType);
95 const PartialDiagnostic &getDiagnostic() const {
100 friend class DeclContext::ddiag_iterator;
101 friend class DependentStoredDeclsMap;
103 DependentDiagnostic(const PartialDiagnostic &PDiag,
104 PartialDiagnostic::Storage *Storage)
105 : Diag(PDiag, Storage) {}
107 static DependentDiagnostic *Create(ASTContext &Context,
109 const PartialDiagnostic &PDiag);
111 DependentDiagnostic *NextDiagnostic;
113 PartialDiagnostic Diag;
118 unsigned IsMember : 1;
119 NamedDecl *TargetDecl;
120 CXXRecordDecl *NamingClass;
121 void *BaseObjectType;
125 /// An iterator over the dependent diagnostics in a dependent context.
126 class DeclContext::ddiag_iterator {
128 ddiag_iterator() = default;
129 explicit ddiag_iterator(DependentDiagnostic *Ptr) : Ptr(Ptr) {}
131 using value_type = DependentDiagnostic *;
132 using reference = DependentDiagnostic *;
133 using pointer = DependentDiagnostic *;
134 using difference_type = int;
135 using iterator_category = std::forward_iterator_tag;
137 reference operator*() const { return Ptr; }
139 ddiag_iterator &operator++() {
140 assert(Ptr && "attempt to increment past end of diag list");
141 Ptr = Ptr->NextDiagnostic;
145 ddiag_iterator operator++(int) {
146 ddiag_iterator tmp = *this;
151 bool operator==(ddiag_iterator Other) const {
152 return Ptr == Other.Ptr;
155 bool operator!=(ddiag_iterator Other) const {
156 return Ptr != Other.Ptr;
159 ddiag_iterator &operator+=(difference_type N) {
160 assert(N >= 0 && "cannot rewind a DeclContext::ddiag_iterator");
166 ddiag_iterator operator+(difference_type N) const {
167 ddiag_iterator tmp = *this;
173 DependentDiagnostic *Ptr = nullptr;
176 inline DeclContext::ddiag_range DeclContext::ddiags() const {
177 assert(isDependentContext()
178 && "cannot iterate dependent diagnostics of non-dependent context");
179 const DependentStoredDeclsMap *Map
180 = static_cast<DependentStoredDeclsMap*>(getPrimaryContext()->getLookupPtr());
183 // Return an empty range using the always-end default constructor.
184 return ddiag_range(ddiag_iterator(), ddiag_iterator());
186 return ddiag_range(ddiag_iterator(Map->FirstDiagnostic), ddiag_iterator());
191 #endif // LLVM_CLANG_AST_DEPENDENTDIAGNOSTIC_H