clang  3.7.0
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 
27 namespace clang {
28 
29 class ASTContext;
30 class CXXRecordDecl;
31 class NamedDecl;
32 
33 /// A dependently-generated diagnostic.
35 public:
36  enum AccessNonce { Access = 0 };
37 
39  DeclContext *Parent,
40  AccessNonce _,
42  bool IsMemberAccess,
43  AccessSpecifier AS,
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();
55  return DD;
56  }
57 
58  unsigned getKind() const {
59  return Access;
60  }
61 
62  bool isAccessToMember() const {
63  assert(getKind() == Access);
64  return AccessData.IsMember;
65  }
66 
68  assert(getKind() == Access);
69  return AccessSpecifier(AccessData.Access);
70  }
71 
73  assert(getKind() == Access);
74  return SourceLocation::getFromRawEncoding(AccessData.Loc);
75  }
76 
78  assert(getKind() == Access);
79  return AccessData.TargetDecl;
80  }
81 
83  assert(getKind() == Access);
84  return AccessData.NamingClass;
85  }
86 
88  assert(getKind() == Access);
89  return QualType::getFromOpaquePtr(AccessData.BaseObjectType);
90  }
91 
93  return Diag;
94  }
95 
96 private:
99  : Diag(PDiag, Storage) {}
100 
101  static DependentDiagnostic *Create(ASTContext &Context,
102  DeclContext *Parent,
103  const PartialDiagnostic &PDiag);
104 
107  DependentDiagnostic *NextDiagnostic;
108 
110 
111  struct {
112  unsigned Loc;
113  unsigned Access : 2;
114  unsigned IsMember : 1;
118  } AccessData;
119 };
120 
121 ///
122 
123 /// An iterator over the dependent diagnostics in a dependent context.
125 public:
126  ddiag_iterator() : Ptr(nullptr) {}
127  explicit ddiag_iterator(DependentDiagnostic *Ptr) : Ptr(Ptr) {}
128 
132  typedef int difference_type;
133  typedef std::forward_iterator_tag iterator_category;
134 
135  reference operator*() const { return Ptr; }
136 
138  assert(Ptr && "attempt to increment past end of diag list");
139  Ptr = Ptr->NextDiagnostic;
140  return *this;
141  }
142 
144  ddiag_iterator tmp = *this;
145  ++*this;
146  return tmp;
147  }
148 
149  bool operator==(ddiag_iterator Other) const {
150  return Ptr == Other.Ptr;
151  }
152 
153  bool operator!=(ddiag_iterator Other) const {
154  return Ptr != Other.Ptr;
155  }
156 
158  assert(N >= 0 && "cannot rewind a DeclContext::ddiag_iterator");
159  while (N--)
160  ++*this;
161  return *this;
162  }
163 
165  ddiag_iterator tmp = *this;
166  tmp += N;
167  return tmp;
168  }
169 
170 private:
171  DependentDiagnostic *Ptr;
172 };
173 
175  assert(isDependentContext()
176  && "cannot iterate dependent diagnostics of non-dependent context");
179 
180  if (!Map)
181  // Return an empty range using the always-end default constructor.
183 
184  return ddiag_range(ddiag_iterator(Map->FirstDiagnostic), ddiag_iterator());
185 }
186 
187 }
188 
189 #endif
bool operator==(ddiag_iterator Other) const
ddiag_range ddiags() const
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.
AccessSpecifier getAccess() const
NamedDecl * getAccessNamingClass() const
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:851
StoredDeclsMap * getLookupPtr() const
Retrieve the internal representation of the lookup structure. This may omit some names if we are lazi...
Definition: DeclBase.h:1709
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:83
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
void * getAsOpaquePtr() const
Definition: Type.h:614
SourceLocation getAccessLoc() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:89
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
QualType getAccessBaseObjectType() const
std::forward_iterator_tag iterator_category
NamedDecl * getAccessTarget() const
ddiag_iterator operator+(difference_type N) const
ddiag_iterator & operator+=(difference_type N)
ASTContext * Context
ddiag_iterator(DependentDiagnostic *Ptr)
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:615
const PartialDiagnostic & getDiagnostic() const
llvm::iterator_range< DeclContext::ddiag_iterator > ddiag_range
Definition: DeclBase.h:1688
bool operator!=(ddiag_iterator Other) const
unsigned Map[Count]
Definition: AddressSpaces.h:45
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:285
DeclContext * getPrimaryContext()
Definition: DeclBase.cpp:920