clang  6.0.0svn
DependentDiagnostic.h
Go to the documentation of this file.
1 //==- DependentDiagnostic.h - Dependently-generated diagnostics --*- C++ -*-==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines interfaces for diagnostics which may or may
11 // fire based on how a template is instantiated.
12 //
13 // At the moment, the only consumer of this interface is access
14 // control.
15 //
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef LLVM_CLANG_AST_DEPENDENTDIAGNOSTIC_H
19 #define LLVM_CLANG_AST_DEPENDENTDIAGNOSTIC_H
20 
21 #include "clang/AST/DeclBase.h"
23 #include "clang/AST/Type.h"
26 #include "clang/Basic/Specifiers.h"
27 #include <cassert>
28 #include <iterator>
29 
30 namespace clang {
31 
32 class ASTContext;
33 class CXXRecordDecl;
34 class NamedDecl;
35 
36 /// A dependently-generated diagnostic.
38 public:
39  enum AccessNonce { Access = 0 };
40 
43  AccessNonce _,
45  bool IsMemberAccess,
46  AccessSpecifier AS,
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();
58  return DD;
59  }
60 
61  unsigned getKind() const {
62  return Access;
63  }
64 
65  bool isAccessToMember() const {
66  assert(getKind() == Access);
67  return AccessData.IsMember;
68  }
69 
71  assert(getKind() == Access);
72  return AccessSpecifier(AccessData.Access);
73  }
74 
76  assert(getKind() == Access);
77  return SourceLocation::getFromRawEncoding(AccessData.Loc);
78  }
79 
81  assert(getKind() == Access);
82  return AccessData.TargetDecl;
83  }
84 
86  assert(getKind() == Access);
87  return AccessData.NamingClass;
88  }
89 
91  assert(getKind() == Access);
92  return QualType::getFromOpaquePtr(AccessData.BaseObjectType);
93  }
94 
96  return Diag;
97  }
98 
99 private:
102 
104  PartialDiagnostic::Storage *Storage)
105  : Diag(PDiag, Storage) {}
106 
107  static DependentDiagnostic *Create(ASTContext &Context,
109  const PartialDiagnostic &PDiag);
110 
111  DependentDiagnostic *NextDiagnostic;
112 
114 
115  struct {
116  unsigned Loc;
117  unsigned Access : 2;
118  unsigned IsMember : 1;
122  } AccessData;
123 };
124 
125 /// An iterator over the dependent diagnostics in a dependent context.
127 public:
128  ddiag_iterator() = default;
129  explicit ddiag_iterator(DependentDiagnostic *Ptr) : Ptr(Ptr) {}
130 
134  using difference_type = int;
135  using iterator_category = std::forward_iterator_tag;
136 
137  reference operator*() const { return Ptr; }
138 
140  assert(Ptr && "attempt to increment past end of diag list");
141  Ptr = Ptr->NextDiagnostic;
142  return *this;
143  }
144 
146  ddiag_iterator tmp = *this;
147  ++*this;
148  return tmp;
149  }
150 
151  bool operator==(ddiag_iterator Other) const {
152  return Ptr == Other.Ptr;
153  }
154 
155  bool operator!=(ddiag_iterator Other) const {
156  return Ptr != Other.Ptr;
157  }
158 
160  assert(N >= 0 && "cannot rewind a DeclContext::ddiag_iterator");
161  while (N--)
162  ++*this;
163  return *this;
164  }
165 
167  ddiag_iterator tmp = *this;
168  tmp += N;
169  return tmp;
170  }
171 
172 private:
173  DependentDiagnostic *Ptr = nullptr;
174 };
175 
177  assert(isDependentContext()
178  && "cannot iterate dependent diagnostics of non-dependent context");
179  const DependentStoredDeclsMap *Map
180  = static_cast<DependentStoredDeclsMap*>(getPrimaryContext()->getLookupPtr());
181 
182  if (!Map)
183  // Return an empty range using the always-end default constructor.
185 
186  return ddiag_range(ddiag_iterator(Map->FirstDiagnostic), ddiag_iterator());
187 }
188 
189 } // namespace clang
190 
191 #endif // LLVM_CLANG_AST_DEPENDENTDIAGNOSTIC_H
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.
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
A (possibly-)qualified type.
Definition: Type.h:653
AccessSpecifier getAccess() const
C Language Family Type Representation.
SourceLocation getAccessLoc() const
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:95
const PartialDiagnostic & getDiagnostic() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:149
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
void * getAsOpaquePtr() const
Definition: Type.h:699
ddiag_iterator operator+(difference_type N) const
NodeId Parent
Definition: ASTDiff.cpp:192
ddiag_iterator & operator+=(difference_type N)
std::forward_iterator_tag iterator_category
ddiag_iterator(DependentDiagnostic *Ptr)
Encodes a location in the source.
bool operator==(ddiag_iterator Other) const
NamedDecl * getAccessNamingClass() const
llvm::iterator_range< DeclContext::ddiag_iterator > ddiag_range
Definition: DeclBase.h:1858
bool operator!=(ddiag_iterator Other) const
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:701
Defines various enumerations that describe declaration and type specifiers.
ddiag_range ddiags() const
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1252
QualType getAccessBaseObjectType() const
A dependently-generated diagnostic.
static DependentDiagnostic * Create(ASTContext &Context, DeclContext *Parent, AccessNonce _, SourceLocation Loc, bool IsMemberAccess, AccessSpecifier AS, NamedDecl *TargetDecl, CXXRecordDecl *NamingClass, QualType BaseObjectType, const PartialDiagnostic &PDiag)
An iterator over the dependent diagnostics in a dependent context.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream...
Defines the clang::SourceLocation class and associated facilities.
Represents a C++ struct/union/class.
Definition: DeclCXX.h:299
NamedDecl * getAccessTarget() const
NamedDecl - This represents a decl with a name.
Definition: Decl.h:245