clang  14.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"
25 #include "clang/Basic/Specifiers.h"
26 #include <cassert>
27 #include <iterator>
28 
29 namespace clang {
30 
31 class ASTContext;
32 class CXXRecordDecl;
33 class NamedDecl;
34 
35 /// A dependently-generated diagnostic.
37 public:
38  enum AccessNonce { Access = 0 };
39 
42  AccessNonce _,
44  bool IsMemberAccess,
45  AccessSpecifier AS,
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 
98 private:
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  unsigned Access : 2;
117  unsigned IsMember : 1;
121  } AccessData;
122 };
123 
124 /// An iterator over the dependent diagnostics in a dependent context.
126 public:
127  ddiag_iterator() = default;
128  explicit ddiag_iterator(DependentDiagnostic *Ptr) : Ptr(Ptr) {}
129 
134  using iterator_category = std::forward_iterator_tag;
135 
136  reference operator*() const { return Ptr; }
137 
139  assert(Ptr && "attempt to increment past end of diag list");
140  Ptr = Ptr->NextDiagnostic;
141  return *this;
142  }
143 
145  ddiag_iterator tmp = *this;
146  ++*this;
147  return tmp;
148  }
149 
150  bool operator==(ddiag_iterator Other) const {
151  return Ptr == Other.Ptr;
152  }
153 
154  bool operator!=(ddiag_iterator Other) const {
155  return Ptr != Other.Ptr;
156  }
157 
159  assert(N >= 0 && "cannot rewind a DeclContext::ddiag_iterator");
160  while (N--)
161  ++*this;
162  return *this;
163  }
164 
166  ddiag_iterator tmp = *this;
167  tmp += N;
168  return tmp;
169  }
170 
171 private:
172  DependentDiagnostic *Ptr = nullptr;
173 };
174 
176  assert(isDependentContext()
177  && "cannot iterate dependent diagnostics of non-dependent context");
178  const DependentStoredDeclsMap *Map
180 
181  if (!Map)
182  // Return an empty range using the always-end default constructor.
184 
185  return ddiag_range(ddiag_iterator(Map->FirstDiagnostic), ddiag_iterator());
186 }
187 
188 } // namespace clang
189 
190 #endif // LLVM_CLANG_AST_DEPENDENTDIAGNOSTIC_H
clang::DeclContext::ddiag_iterator::difference_type
int difference_type
Definition: DependentDiagnostic.h:133
Specifiers.h
clang::DependentDiagnostic::isAccessToMember
bool isAccessToMember() const
Definition: DependentDiagnostic.h:64
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1347
Diag
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.
Definition: LiteralSupport.cpp:78
clang::DependentDiagnostic::getAccessNamingClass
NamedDecl * getAccessNamingClass() const
Definition: DependentDiagnostic.h:84
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:249
clang::DeclContext::getPrimaryContext
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
Definition: DeclBase.cpp:1229
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
int
__device__ int
Definition: __clang_hip_libdevice_declares.h:63
clang::DeclContext::ddiag_iterator::ddiag_iterator
ddiag_iterator()=default
clang::DependentDiagnostic::getKind
unsigned getKind() const
Definition: DependentDiagnostic.h:60
clang::DependentDiagnostic::IsMember
unsigned IsMember
Definition: DependentDiagnostic.h:117
clang::DeclContext::ddiag_iterator::operator==
bool operator==(ddiag_iterator Other) const
Definition: DependentDiagnostic.h:150
clang::DependentDiagnostic::getAccessBaseObjectType
QualType getAccessBaseObjectType() const
Definition: DependentDiagnostic.h:89
clang::DeclContext::ddiag_iterator::operator++
ddiag_iterator operator++(int)
Definition: DependentDiagnostic.h:144
clang::DependentDiagnostic::Create
static DependentDiagnostic * Create(ASTContext &Context, DeclContext *Parent, AccessNonce _, SourceLocation Loc, bool IsMemberAccess, AccessSpecifier AS, NamedDecl *TargetDecl, CXXRecordDecl *NamingClass, QualType BaseObjectType, const PartialDiagnostic &PDiag)
Definition: DependentDiagnostic.h:40
clang::DiagnosticStorage
Definition: Diagnostic.h:147
clang::DependentDiagnostic::NamingClass
CXXRecordDecl * NamingClass
Definition: DependentDiagnostic.h:119
clang::DependentDiagnostic::TargetDecl
NamedDecl * TargetDecl
Definition: DependentDiagnostic.h:118
clang::DependentDiagnostic::getAccessTarget
NamedDecl * getAccessTarget() const
Definition: DependentDiagnostic.h:79
clang::DependentStoredDeclsMap
Definition: DeclContextInternals.h:307
DeclBase.h
clang::DependentDiagnostic::Loc
SourceLocation Loc
Definition: DependentDiagnostic.h:115
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:211
clang::DeclContext::ddiags
ddiag_range ddiags() const
Definition: DependentDiagnostic.h:175
Type.h
clang::DeclContext::ddiag_range
llvm::iterator_range< DeclContext::ddiag_iterator > ddiag_range
Definition: DeclBase.h:2403
clang::DependentDiagnostic::getAccess
AccessSpecifier getAccess() const
Definition: DependentDiagnostic.h:69
clang::DependentDiagnostic::AccessNonce
AccessNonce
Definition: DependentDiagnostic.h:38
clang::DependentDiagnostic::Access
unsigned Access
Definition: DependentDiagnostic.h:116
clang::AccessSpecifier
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:99
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:255
SourceLocation.h
clang::DeclContext::ddiag_iterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: DependentDiagnostic.h:134
clang::DeclContext::ddiag_iterator::operator+=
ddiag_iterator & operator+=(difference_type N)
Definition: DependentDiagnostic.h:158
clang::DependentDiagnostic::getDiagnostic
const PartialDiagnostic & getDiagnostic() const
Definition: DependentDiagnostic.h:94
clang::DeclContext::ddiag_iterator::ddiag_iterator
ddiag_iterator(DependentDiagnostic *Ptr)
Definition: DependentDiagnostic.h:128
clang::DependentDiagnostic::getAccessLoc
SourceLocation getAccessLoc() const
Definition: DependentDiagnostic.h:74
clang::QualType::getFromOpaquePtr
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:720
clang::PartialDiagnostic
Definition: PartialDiagnostic.h:34
clang::DeclContext::ddiag_iterator
An iterator over the dependent diagnostics in a dependent context.
Definition: DependentDiagnostic.h:125
clang::DependentDiagnostic
A dependently-generated diagnostic.
Definition: DependentDiagnostic.h:36
PartialDiagnostic.h
clang
Definition: CalledOnceCheck.h:17
clang::DeclContext::isDependentContext
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1142
clang::DependentDiagnostic::BaseObjectType
void * BaseObjectType
Definition: DependentDiagnostic.h:120
clang::DeclContext::getLookupPtr
StoredDeclsMap * getLookupPtr() const
Retrieve the internal representation of the lookup structure.
Definition: DeclBase.h:2423
clang::DeclContext::ddiag_iterator::operator++
ddiag_iterator & operator++()
Definition: DependentDiagnostic.h:138
Parent
NodeId Parent
Definition: ASTDiff.cpp:192
clang::DeclContext::ddiag_iterator::operator!=
bool operator!=(ddiag_iterator Other) const
Definition: DependentDiagnostic.h:154
clang::DeclContext::ddiag_iterator::operator+
ddiag_iterator operator+(difference_type N) const
Definition: DependentDiagnostic.h:165
clang::DeclContext::ddiag_iterator::operator*
reference operator*() const
Definition: DependentDiagnostic.h:136
DeclContextInternals.h