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_DEPENDENT_DIAGNOSTIC_H
19 #define LLVM_CLANG_AST_DEPENDENT_DIAGNOSTIC_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"
33 /// A dependently-generated diagnostic.
34 class DependentDiagnostic {
36 enum AccessNonce { Access = 0 };
38 static DependentDiagnostic *Create(ASTContext &Context,
44 NamedDecl *TargetDecl,
45 CXXRecordDecl *NamingClass,
46 QualType BaseObjectType,
47 const PartialDiagnostic &PDiag) {
48 DependentDiagnostic *DD = Create(Context, Parent, PDiag);
49 DD->AccessData.Loc = Loc.getRawEncoding();
50 DD->AccessData.IsMember = IsMemberAccess;
51 DD->AccessData.Access = AS;
52 DD->AccessData.TargetDecl = TargetDecl;
53 DD->AccessData.NamingClass = NamingClass;
54 DD->AccessData.BaseObjectType = BaseObjectType.getAsOpaquePtr();
58 unsigned getKind() const {
62 bool isAccessToMember() const {
63 assert(getKind() == Access);
64 return AccessData.IsMember;
67 AccessSpecifier getAccess() const {
68 assert(getKind() == Access);
69 return AccessSpecifier(AccessData.Access);
72 SourceLocation getAccessLoc() const {
73 assert(getKind() == Access);
74 return SourceLocation::getFromRawEncoding(AccessData.Loc);
77 NamedDecl *getAccessTarget() const {
78 assert(getKind() == Access);
79 return AccessData.TargetDecl;
82 NamedDecl *getAccessNamingClass() const {
83 assert(getKind() == Access);
84 return AccessData.NamingClass;
87 QualType getAccessBaseObjectType() const {
88 assert(getKind() == Access);
89 return QualType::getFromOpaquePtr(AccessData.BaseObjectType);
92 const PartialDiagnostic &getDiagnostic() const {
97 DependentDiagnostic(const PartialDiagnostic &PDiag,
98 PartialDiagnostic::Storage *Storage)
99 : Diag(PDiag, Storage) {}
101 static DependentDiagnostic *Create(ASTContext &Context,
103 const PartialDiagnostic &PDiag);
105 friend class DependentStoredDeclsMap;
106 friend class DeclContext::ddiag_iterator;
107 DependentDiagnostic *NextDiagnostic;
109 PartialDiagnostic Diag;
114 unsigned IsMember : 1;
115 NamedDecl *TargetDecl;
116 CXXRecordDecl *NamingClass;
117 void *BaseObjectType;
123 /// An iterator over the dependent diagnostics in a dependent context.
124 class DeclContext::ddiag_iterator {
126 ddiag_iterator() : Ptr(0) {}
127 explicit ddiag_iterator(DependentDiagnostic *Ptr) : Ptr(Ptr) {}
129 typedef DependentDiagnostic *value_type;
130 typedef DependentDiagnostic *reference;
131 typedef DependentDiagnostic *pointer;
132 typedef int difference_type;
133 typedef std::forward_iterator_tag iterator_category;
135 reference operator*() const { return Ptr; }
137 ddiag_iterator &operator++() {
138 assert(Ptr && "attempt to increment past end of diag list");
139 Ptr = Ptr->NextDiagnostic;
143 ddiag_iterator operator++(int) {
144 ddiag_iterator tmp = *this;
149 bool operator==(ddiag_iterator Other) const {
150 return Ptr == Other.Ptr;
153 bool operator!=(ddiag_iterator Other) const {
154 return Ptr != Other.Ptr;
157 ddiag_iterator &operator+=(difference_type N) {
158 assert(N >= 0 && "cannot rewind a DeclContext::ddiag_iterator");
164 ddiag_iterator operator+(difference_type N) const {
165 ddiag_iterator tmp = *this;
171 DependentDiagnostic *Ptr;
174 inline DeclContext::ddiag_iterator DeclContext::ddiag_begin() const {
175 assert(isDependentContext()
176 && "cannot iterate dependent diagnostics of non-dependent context");
177 const DependentStoredDeclsMap *Map
178 = static_cast<DependentStoredDeclsMap*>(getPrimaryContext()->getLookupPtr());
180 if (!Map) return ddiag_iterator();
181 return ddiag_iterator(Map->FirstDiagnostic);
184 inline DeclContext::ddiag_iterator DeclContext::ddiag_end() const {
185 return ddiag_iterator();