clang 19.0.0git
DependentDiagnostic.h
Go to the documentation of this file.
1//==- DependentDiagnostic.h - Dependently-generated diagnostics --*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines interfaces for diagnostics which may or may
10// fire based on how a template is instantiated.
11//
12// At the moment, the only consumer of this interface is access
13// control.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_CLANG_AST_DEPENDENTDIAGNOSTIC_H
18#define LLVM_CLANG_AST_DEPENDENTDIAGNOSTIC_H
19
20#include "clang/AST/DeclBase.h"
22#include "clang/AST/Type.h"
26#include <cassert>
27#include <iterator>
28
29namespace clang {
30
31class ASTContext;
32class CXXRecordDecl;
33class NamedDecl;
34
35/// A dependently-generated diagnostic.
37public:
38 enum AccessNonce { Access = 0 };
39
44 bool IsMemberAccess,
49 const PartialDiagnostic &PDiag) {
50 DependentDiagnostic *DD = Create(Context, Parent, PDiag);
51 DD->AccessData.Loc = Loc;
52 DD->AccessData.IsMember = IsMemberAccess;
53 DD->AccessData.Access = AS;
54 DD->AccessData.TargetDecl = TargetDecl;
55 DD->AccessData.NamingClass = NamingClass;
56 DD->AccessData.BaseObjectType = BaseObjectType.getAsOpaquePtr();
57 return DD;
58 }
59
60 unsigned getKind() const {
61 return Access;
62 }
63
64 bool isAccessToMember() const {
65 assert(getKind() == Access);
66 return AccessData.IsMember;
67 }
68
70 assert(getKind() == Access);
71 return AccessSpecifier(AccessData.Access);
72 }
73
75 assert(getKind() == Access);
76 return AccessData.Loc;
77 }
78
80 assert(getKind() == Access);
81 return AccessData.TargetDecl;
82 }
83
85 assert(getKind() == Access);
86 return AccessData.NamingClass;
87 }
88
90 assert(getKind() == Access);
91 return QualType::getFromOpaquePtr(AccessData.BaseObjectType);
92 }
93
95 return Diag;
96 }
97
98private:
101
103 DiagnosticStorage *Storage)
104 : Diag(PDiag, Storage) {}
105
106 static DependentDiagnostic *Create(ASTContext &Context,
108 const PartialDiagnostic &PDiag);
109
110 DependentDiagnostic *NextDiagnostic;
111
113
114 struct {
116 LLVM_PREFERRED_TYPE(AccessSpecifier)
118 LLVM_PREFERRED_TYPE(bool)
119 unsigned IsMember : 1;
123 } AccessData;
124};
125
126/// An iterator over the dependent diagnostics in a dependent context.
128public:
129 ddiag_iterator() = default;
130 explicit ddiag_iterator(DependentDiagnostic *Ptr) : Ptr(Ptr) {}
131
136 using iterator_category = std::forward_iterator_tag;
137
138 reference operator*() const { return Ptr; }
139
141 assert(Ptr && "attempt to increment past end of diag list");
142 Ptr = Ptr->NextDiagnostic;
143 return *this;
144 }
145
147 ddiag_iterator tmp = *this;
148 ++*this;
149 return tmp;
150 }
151
153 return Ptr == Other.Ptr;
154 }
155
157 return Ptr != Other.Ptr;
158 }
159
161 assert(N >= 0 && "cannot rewind a DeclContext::ddiag_iterator");
162 while (N--)
163 ++*this;
164 return *this;
165 }
166
168 ddiag_iterator tmp = *this;
169 tmp += N;
170 return tmp;
171 }
172
173private:
174 DependentDiagnostic *Ptr = nullptr;
175};
176
178 assert(isDependentContext()
179 && "cannot iterate dependent diagnostics of non-dependent context");
180 const DependentStoredDeclsMap *Map
181 = static_cast<DependentStoredDeclsMap*>(getPrimaryContext()->getLookupPtr());
182
183 if (!Map)
184 // Return an empty range using the always-end default constructor.
186
187 return ddiag_range(ddiag_iterator(Map->FirstDiagnostic), ddiag_iterator());
188}
189
190} // namespace clang
191
192#endif // LLVM_CLANG_AST_DEPENDENTDIAGNOSTIC_H
NodeId Parent
Definition: ASTDiff.cpp:191
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
C Language Family Type Representation.
__device__ int
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
An iterator over the dependent diagnostics in a dependent context.
bool operator==(ddiag_iterator Other) const
bool operator!=(ddiag_iterator Other) const
ddiag_iterator operator+(difference_type N) const
ddiag_iterator & operator+=(difference_type N)
ddiag_iterator(DependentDiagnostic *Ptr)
std::forward_iterator_tag iterator_category
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1436
ddiag_range ddiags() const
llvm::iterator_range< DeclContext::ddiag_iterator > ddiag_range
Definition: DeclBase.h:2610
A dependently-generated diagnostic.
NamedDecl * getAccessNamingClass() const
QualType getAccessBaseObjectType() const
friend class DeclContext::ddiag_iterator
NamedDecl * getAccessTarget() const
SourceLocation getAccessLoc() const
const PartialDiagnostic & getDiagnostic() const
static DependentDiagnostic * Create(ASTContext &Context, DeclContext *Parent, AccessNonce _, SourceLocation Loc, bool IsMemberAccess, AccessSpecifier AS, NamedDecl *TargetDecl, CXXRecordDecl *NamingClass, QualType BaseObjectType, const PartialDiagnostic &PDiag)
AccessSpecifier getAccess() const
This represents a decl that may have a name.
Definition: Decl.h:249
A (possibly-)qualified type.
Definition: Type.h:940
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:989
Encodes a location in the source.
The JSON file list parser is used to communicate input to InstallAPI.
@ Create
'copyin' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
@ Other
Other implicit parameter.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:120