clang  14.0.0git
DeclBase.cpp
Go to the documentation of this file.
1 //===- DeclBase.cpp - Declaration AST Node Implementation -----------------===//
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 implements the Decl and DeclContext classes.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "clang/AST/DeclBase.h"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/ASTLambda.h"
17 #include "clang/AST/Attr.h"
18 #include "clang/AST/AttrIterator.h"
19 #include "clang/AST/Decl.h"
20 #include "clang/AST/DeclCXX.h"
22 #include "clang/AST/DeclFriend.h"
23 #include "clang/AST/DeclObjC.h"
24 #include "clang/AST/DeclOpenMP.h"
25 #include "clang/AST/DeclTemplate.h"
28 #include "clang/AST/Stmt.h"
29 #include "clang/AST/Type.h"
31 #include "clang/Basic/LLVM.h"
36 #include "clang/Basic/TargetInfo.h"
37 #include "llvm/ADT/ArrayRef.h"
38 #include "llvm/ADT/PointerIntPair.h"
39 #include "llvm/ADT/SmallVector.h"
40 #include "llvm/ADT/StringRef.h"
41 #include "llvm/Support/Casting.h"
42 #include "llvm/Support/ErrorHandling.h"
43 #include "llvm/Support/MathExtras.h"
44 #include "llvm/Support/VersionTuple.h"
45 #include "llvm/Support/raw_ostream.h"
46 #include <algorithm>
47 #include <cassert>
48 #include <cstddef>
49 #include <string>
50 #include <tuple>
51 #include <utility>
52 
53 using namespace clang;
54 
55 //===----------------------------------------------------------------------===//
56 // Statistics
57 //===----------------------------------------------------------------------===//
58 
59 #define DECL(DERIVED, BASE) static int n##DERIVED##s = 0;
60 #define ABSTRACT_DECL(DECL)
61 #include "clang/AST/DeclNodes.inc"
62 
65 }
66 
67 #define DECL(DERIVED, BASE) \
68  static_assert(alignof(Decl) >= alignof(DERIVED##Decl), \
69  "Alignment sufficient after objects prepended to " #DERIVED);
70 #define ABSTRACT_DECL(DECL)
71 #include "clang/AST/DeclNodes.inc"
72 
73 void *Decl::operator new(std::size_t Size, const ASTContext &Context,
74  unsigned ID, std::size_t Extra) {
75  // Allocate an extra 8 bytes worth of storage, which ensures that the
76  // resulting pointer will still be 8-byte aligned.
77  static_assert(sizeof(unsigned) * 2 >= alignof(Decl),
78  "Decl won't be misaligned");
79  void *Start = Context.Allocate(Size + Extra + 8);
80  void *Result = (char*)Start + 8;
81 
82  unsigned *PrefixPtr = (unsigned *)Result - 2;
83 
84  // Zero out the first 4 bytes; this is used to store the owning module ID.
85  PrefixPtr[0] = 0;
86 
87  // Store the global declaration ID in the second 4 bytes.
88  PrefixPtr[1] = ID;
89 
90  return Result;
91 }
92 
93 void *Decl::operator new(std::size_t Size, const ASTContext &Ctx,
94  DeclContext *Parent, std::size_t Extra) {
95  assert(!Parent || &Parent->getParentASTContext() == &Ctx);
96  // With local visibility enabled, we track the owning module even for local
97  // declarations. We create the TU decl early and may not yet know what the
98  // LangOpts are, so conservatively allocate the storage.
99  if (Ctx.getLangOpts().trackLocalOwningModule() || !Parent) {
100  // Ensure required alignment of the resulting object by adding extra
101  // padding at the start if required.
102  size_t ExtraAlign =
103  llvm::offsetToAlignment(sizeof(Module *), llvm::Align(alignof(Decl)));
104  auto *Buffer = reinterpret_cast<char *>(
105  ::operator new(ExtraAlign + sizeof(Module *) + Size + Extra, Ctx));
106  Buffer += ExtraAlign;
107  auto *ParentModule =
108  Parent ? cast<Decl>(Parent)->getOwningModule() : nullptr;
109  return new (Buffer) Module*(ParentModule) + 1;
110  }
111  return ::operator new(Size + Extra, Ctx);
112 }
113 
114 Module *Decl::getOwningModuleSlow() const {
115  assert(isFromASTFile() && "Not from AST file?");
117 }
118 
121 }
122 
123 const char *Decl::getDeclKindName() const {
124  switch (DeclKind) {
125  default: llvm_unreachable("Declaration not in DeclNodes.inc!");
126 #define DECL(DERIVED, BASE) case DERIVED: return #DERIVED;
127 #define ABSTRACT_DECL(DECL)
128 #include "clang/AST/DeclNodes.inc"
129  }
130 }
131 
132 void Decl::setInvalidDecl(bool Invalid) {
133  InvalidDecl = Invalid;
134  assert(!isa<TagDecl>(this) || !cast<TagDecl>(this)->isCompleteDefinition());
135  if (!Invalid) {
136  return;
137  }
138 
139  if (!isa<ParmVarDecl>(this)) {
140  // Defensive maneuver for ill-formed code: we're likely not to make it to
141  // a point where we set the access specifier, so default it to "public"
142  // to avoid triggering asserts elsewhere in the front end.
144  }
145 
146  // Marking a DecompositionDecl as invalid implies all the child BindingDecl's
147  // are invalid too.
148  if (auto *DD = dyn_cast<DecompositionDecl>(this)) {
149  for (auto *Binding : DD->bindings()) {
150  Binding->setInvalidDecl();
151  }
152  }
153 }
154 
155 const char *DeclContext::getDeclKindName() const {
156  switch (getDeclKind()) {
157 #define DECL(DERIVED, BASE) case Decl::DERIVED: return #DERIVED;
158 #define ABSTRACT_DECL(DECL)
159 #include "clang/AST/DeclNodes.inc"
160  }
161  llvm_unreachable("Declaration context not in DeclNodes.inc!");
162 }
163 
164 bool Decl::StatisticsEnabled = false;
166  StatisticsEnabled = true;
167 }
168 
170  llvm::errs() << "\n*** Decl Stats:\n";
171 
172  int totalDecls = 0;
173 #define DECL(DERIVED, BASE) totalDecls += n##DERIVED##s;
174 #define ABSTRACT_DECL(DECL)
175 #include "clang/AST/DeclNodes.inc"
176  llvm::errs() << " " << totalDecls << " decls total.\n";
177 
178  int totalBytes = 0;
179 #define DECL(DERIVED, BASE) \
180  if (n##DERIVED##s > 0) { \
181  totalBytes += (int)(n##DERIVED##s * sizeof(DERIVED##Decl)); \
182  llvm::errs() << " " << n##DERIVED##s << " " #DERIVED " decls, " \
183  << sizeof(DERIVED##Decl) << " each (" \
184  << n##DERIVED##s * sizeof(DERIVED##Decl) \
185  << " bytes)\n"; \
186  }
187 #define ABSTRACT_DECL(DECL)
188 #include "clang/AST/DeclNodes.inc"
189 
190  llvm::errs() << "Total bytes = " << totalBytes << "\n";
191 }
192 
193 void Decl::add(Kind k) {
194  switch (k) {
195 #define DECL(DERIVED, BASE) case DERIVED: ++n##DERIVED##s; break;
196 #define ABSTRACT_DECL(DECL)
197 #include "clang/AST/DeclNodes.inc"
198  }
199 }
200 
202  if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(this))
203  return TTP->isParameterPack();
204  if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(this))
205  return NTTP->isParameterPack();
206  if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(this))
207  return TTP->isParameterPack();
208  return false;
209 }
210 
211 bool Decl::isParameterPack() const {
212  if (const auto *Var = dyn_cast<VarDecl>(this))
213  return Var->isParameterPack();
214 
215  return isTemplateParameterPack();
216 }
217 
219  if (auto *FD = dyn_cast<FunctionDecl>(this))
220  return FD;
221  if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(this))
222  return FTD->getTemplatedDecl();
223  return nullptr;
224 }
225 
226 bool Decl::isTemplateDecl() const {
227  return isa<TemplateDecl>(this);
228 }
229 
231  if (auto *FD = dyn_cast<FunctionDecl>(this))
232  return FD->getDescribedFunctionTemplate();
233  if (auto *RD = dyn_cast<CXXRecordDecl>(this))
234  return RD->getDescribedClassTemplate();
235  if (auto *VD = dyn_cast<VarDecl>(this))
236  return VD->getDescribedVarTemplate();
237  if (auto *AD = dyn_cast<TypeAliasDecl>(this))
238  return AD->getDescribedAliasTemplate();
239 
240  return nullptr;
241 }
242 
244  if (auto *TD = getDescribedTemplate())
245  return TD->getTemplateParameters();
246  if (auto *CTPSD = dyn_cast<ClassTemplatePartialSpecializationDecl>(this))
247  return CTPSD->getTemplateParameters();
248  if (auto *VTPSD = dyn_cast<VarTemplatePartialSpecializationDecl>(this))
249  return VTPSD->getTemplateParameters();
250  return nullptr;
251 }
252 
253 bool Decl::isTemplated() const {
254  // A declaration is templated if it is a template or a template pattern, or
255  // is within (lexcially for a friend, semantically otherwise) a dependent
256  // context.
257  // FIXME: Should local extern declarations be treated like friends?
258  if (auto *AsDC = dyn_cast<DeclContext>(this))
259  return AsDC->isDependentContext();
261  return DC->isDependentContext() || isTemplateDecl() ||
263 }
264 
265 unsigned Decl::getTemplateDepth() const {
266  if (auto *DC = dyn_cast<DeclContext>(this))
267  if (DC->isFileContext())
268  return 0;
269 
270  if (auto *TPL = getDescribedTemplateParams())
271  return TPL->getDepth() + 1;
272 
273  // If this is a dependent lambda, there might be an enclosing variable
274  // template. In this case, the next step is not the parent DeclContext (or
275  // even a DeclContext at all).
276  auto *RD = dyn_cast<CXXRecordDecl>(this);
277  if (RD && RD->isDependentLambda())
278  if (Decl *Context = RD->getLambdaContextDecl())
279  return Context->getTemplateDepth();
280 
281  const DeclContext *DC =
283  return cast<Decl>(DC)->getTemplateDepth();
284 }
285 
287  for (const DeclContext *DC = getDeclContext();
288  DC && !DC->isTranslationUnit() && !DC->isNamespace();
289  DC = DC->getParent())
290  if (DC->isFunctionOrMethod())
291  return DC;
292 
293  return nullptr;
294 }
295 
296 //===----------------------------------------------------------------------===//
297 // PrettyStackTraceDecl Implementation
298 //===----------------------------------------------------------------------===//
299 
300 void PrettyStackTraceDecl::print(raw_ostream &OS) const {
301  SourceLocation TheLoc = Loc;
302  if (TheLoc.isInvalid() && TheDecl)
303  TheLoc = TheDecl->getLocation();
304 
305  if (TheLoc.isValid()) {
306  TheLoc.print(OS, SM);
307  OS << ": ";
308  }
309 
310  OS << Message;
311 
312  if (const auto *DN = dyn_cast_or_null<NamedDecl>(TheDecl)) {
313  OS << " '";
314  DN->printQualifiedName(OS);
315  OS << '\'';
316  }
317  OS << '\n';
318 }
319 
320 //===----------------------------------------------------------------------===//
321 // Decl Implementation
322 //===----------------------------------------------------------------------===//
323 
324 // Out-of-line virtual method providing a home for Decl.
325 Decl::~Decl() = default;
326 
328  DeclCtx = DC;
329 }
330 
332  if (DC == getLexicalDeclContext())
333  return;
334 
335  if (isInSemaDC()) {
336  setDeclContextsImpl(getDeclContext(), DC, getASTContext());
337  } else {
338  getMultipleDC()->LexicalDC = DC;
339  }
340 
341  // FIXME: We shouldn't be changing the lexical context of declarations
342  // imported from AST files.
343  if (!isFromASTFile()) {
344  setModuleOwnershipKind(getModuleOwnershipKindForChildOf(DC));
345  if (hasOwningModule())
346  setLocalOwningModule(cast<Decl>(DC)->getOwningModule());
347  }
348 
349  assert(
351  getOwningModule()) &&
352  "hidden declaration has no owning module");
353 }
354 
355 void Decl::setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC,
356  ASTContext &Ctx) {
357  if (SemaDC == LexicalDC) {
358  DeclCtx = SemaDC;
359  } else {
360  auto *MDC = new (Ctx) Decl::MultipleDC();
361  MDC->SemanticDC = SemaDC;
362  MDC->LexicalDC = LexicalDC;
363  DeclCtx = MDC;
364  }
365 }
366 
368  const DeclContext *LDC = getLexicalDeclContext();
369  if (!LDC->isDependentContext())
370  return false;
371  while (true) {
372  if (LDC->isFunctionOrMethod())
373  return true;
374  if (!isa<TagDecl>(LDC))
375  return false;
376  if (const auto *CRD = dyn_cast<CXXRecordDecl>(LDC))
377  if (CRD->isLambda())
378  return true;
379  LDC = LDC->getLexicalParent();
380  }
381  return false;
382 }
383 
385  for (const DeclContext *DC = getDeclContext(); DC; DC = DC->getParent()) {
386  if (const auto *ND = dyn_cast<NamespaceDecl>(DC))
387  if (ND->isAnonymousNamespace())
388  return true;
389  }
390 
391  return false;
392 }
393 
395  const DeclContext *DC = getDeclContext();
396  return DC && DC->isStdNamespace();
397 }
398 
400  if (auto *TUD = dyn_cast<TranslationUnitDecl>(this))
401  return TUD;
402 
403  DeclContext *DC = getDeclContext();
404  assert(DC && "This decl is not contained in a translation unit!");
405 
406  while (!DC->isTranslationUnit()) {
407  DC = DC->getParent();
408  assert(DC && "This decl is not contained in a translation unit!");
409  }
410 
411  return cast<TranslationUnitDecl>(DC);
412 }
413 
416 }
417 
418 /// Helper to get the language options from the ASTContext.
419 /// Defined out of line to avoid depending on ASTContext.h.
421  return getASTContext().getLangOpts();
422 }
423 
426 }
427 
428 unsigned Decl::getMaxAlignment() const {
429  if (!hasAttrs())
430  return 0;
431 
432  unsigned Align = 0;
433  const AttrVec &V = getAttrs();
434  ASTContext &Ctx = getASTContext();
435  specific_attr_iterator<AlignedAttr> I(V.begin()), E(V.end());
436  for (; I != E; ++I) {
437  if (!I->isAlignmentErrorDependent())
438  Align = std::max(Align, I->getAlignment(Ctx));
439  }
440  return Align;
441 }
442 
443 bool Decl::isUsed(bool CheckUsedAttr) const {
444  const Decl *CanonD = getCanonicalDecl();
445  if (CanonD->Used)
446  return true;
447 
448  // Check for used attribute.
449  // Ask the most recent decl, since attributes accumulate in the redecl chain.
450  if (CheckUsedAttr && getMostRecentDecl()->hasAttr<UsedAttr>())
451  return true;
452 
453  // The information may have not been deserialized yet. Force deserialization
454  // to complete the needed information.
455  return getMostRecentDecl()->getCanonicalDecl()->Used;
456 }
457 
459  if (isUsed(false))
460  return;
461 
462  if (C.getASTMutationListener())
463  C.getASTMutationListener()->DeclarationMarkedUsed(this);
464 
465  setIsUsed();
466 }
467 
468 bool Decl::isReferenced() const {
469  if (Referenced)
470  return true;
471 
472  // Check redeclarations.
473  for (const auto *I : redecls())
474  if (I->Referenced)
475  return true;
476 
477  return false;
478 }
479 
480 ExternalSourceSymbolAttr *Decl::getExternalSourceSymbolAttr() const {
481  const Decl *Definition = nullptr;
482  if (auto *ID = dyn_cast<ObjCInterfaceDecl>(this)) {
483  Definition = ID->getDefinition();
484  } else if (auto *PD = dyn_cast<ObjCProtocolDecl>(this)) {
485  Definition = PD->getDefinition();
486  } else if (auto *TD = dyn_cast<TagDecl>(this)) {
487  Definition = TD->getDefinition();
488  }
489  if (!Definition)
490  Definition = this;
491 
492  if (auto *attr = Definition->getAttr<ExternalSourceSymbolAttr>())
493  return attr;
494  if (auto *dcd = dyn_cast<Decl>(getDeclContext())) {
495  return dcd->getAttr<ExternalSourceSymbolAttr>();
496  }
497 
498  return nullptr;
499 }
500 
501 bool Decl::hasDefiningAttr() const {
502  return hasAttr<AliasAttr>() || hasAttr<IFuncAttr>() ||
503  hasAttr<LoaderUninitializedAttr>();
504 }
505 
506 const Attr *Decl::getDefiningAttr() const {
507  if (auto *AA = getAttr<AliasAttr>())
508  return AA;
509  if (auto *IFA = getAttr<IFuncAttr>())
510  return IFA;
511  if (auto *NZA = getAttr<LoaderUninitializedAttr>())
512  return NZA;
513  return nullptr;
514 }
515 
516 static StringRef getRealizedPlatform(const AvailabilityAttr *A,
517  const ASTContext &Context) {
518  // Check if this is an App Extension "platform", and if so chop off
519  // the suffix for matching with the actual platform.
520  StringRef RealizedPlatform = A->getPlatform()->getName();
521  if (!Context.getLangOpts().AppExt)
522  return RealizedPlatform;
523  size_t suffix = RealizedPlatform.rfind("_app_extension");
524  if (suffix != StringRef::npos)
525  return RealizedPlatform.slice(0, suffix);
526  return RealizedPlatform;
527 }
528 
529 /// Determine the availability of the given declaration based on
530 /// the target platform.
531 ///
532 /// When it returns an availability result other than \c AR_Available,
533 /// if the \p Message parameter is non-NULL, it will be set to a
534 /// string describing why the entity is unavailable.
535 ///
536 /// FIXME: Make these strings localizable, since they end up in
537 /// diagnostics.
539  const AvailabilityAttr *A,
540  std::string *Message,
541  VersionTuple EnclosingVersion) {
542  if (EnclosingVersion.empty())
543  EnclosingVersion = Context.getTargetInfo().getPlatformMinVersion();
544 
545  if (EnclosingVersion.empty())
546  return AR_Available;
547 
548  StringRef ActualPlatform = A->getPlatform()->getName();
549  StringRef TargetPlatform = Context.getTargetInfo().getPlatformName();
550 
551  // Match the platform name.
552  if (getRealizedPlatform(A, Context) != TargetPlatform)
553  return AR_Available;
554 
555  StringRef PrettyPlatformName
556  = AvailabilityAttr::getPrettyPlatformName(ActualPlatform);
557 
558  if (PrettyPlatformName.empty())
559  PrettyPlatformName = ActualPlatform;
560 
561  std::string HintMessage;
562  if (!A->getMessage().empty()) {
563  HintMessage = " - ";
564  HintMessage += A->getMessage();
565  }
566 
567  // Make sure that this declaration has not been marked 'unavailable'.
568  if (A->getUnavailable()) {
569  if (Message) {
570  Message->clear();
571  llvm::raw_string_ostream Out(*Message);
572  Out << "not available on " << PrettyPlatformName
573  << HintMessage;
574  }
575 
576  return AR_Unavailable;
577  }
578 
579  // Make sure that this declaration has already been introduced.
580  if (!A->getIntroduced().empty() &&
581  EnclosingVersion < A->getIntroduced()) {
582  if (Message) {
583  Message->clear();
584  llvm::raw_string_ostream Out(*Message);
585  VersionTuple VTI(A->getIntroduced());
586  Out << "introduced in " << PrettyPlatformName << ' '
587  << VTI << HintMessage;
588  }
589 
590  return A->getStrict() ? AR_Unavailable : AR_NotYetIntroduced;
591  }
592 
593  // Make sure that this declaration hasn't been obsoleted.
594  if (!A->getObsoleted().empty() && EnclosingVersion >= A->getObsoleted()) {
595  if (Message) {
596  Message->clear();
597  llvm::raw_string_ostream Out(*Message);
598  VersionTuple VTO(A->getObsoleted());
599  Out << "obsoleted in " << PrettyPlatformName << ' '
600  << VTO << HintMessage;
601  }
602 
603  return AR_Unavailable;
604  }
605 
606  // Make sure that this declaration hasn't been deprecated.
607  if (!A->getDeprecated().empty() && EnclosingVersion >= A->getDeprecated()) {
608  if (Message) {
609  Message->clear();
610  llvm::raw_string_ostream Out(*Message);
611  VersionTuple VTD(A->getDeprecated());
612  Out << "first deprecated in " << PrettyPlatformName << ' '
613  << VTD << HintMessage;
614  }
615 
616  return AR_Deprecated;
617  }
618 
619  return AR_Available;
620 }
621 
623  VersionTuple EnclosingVersion,
624  StringRef *RealizedPlatform) const {
625  if (auto *FTD = dyn_cast<FunctionTemplateDecl>(this))
626  return FTD->getTemplatedDecl()->getAvailability(Message, EnclosingVersion,
627  RealizedPlatform);
628 
630  std::string ResultMessage;
631 
632  for (const auto *A : attrs()) {
633  if (const auto *Deprecated = dyn_cast<DeprecatedAttr>(A)) {
634  if (Result >= AR_Deprecated)
635  continue;
636 
637  if (Message)
638  ResultMessage = std::string(Deprecated->getMessage());
639 
640  Result = AR_Deprecated;
641  continue;
642  }
643 
644  if (const auto *Unavailable = dyn_cast<UnavailableAttr>(A)) {
645  if (Message)
646  *Message = std::string(Unavailable->getMessage());
647  return AR_Unavailable;
648  }
649 
650  if (const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
652  Message, EnclosingVersion);
653 
654  if (AR == AR_Unavailable) {
655  if (RealizedPlatform)
656  *RealizedPlatform = Availability->getPlatform()->getName();
657  return AR_Unavailable;
658  }
659 
660  if (AR > Result) {
661  Result = AR;
662  if (Message)
663  ResultMessage.swap(*Message);
664  }
665  continue;
666  }
667  }
668 
669  if (Message)
670  Message->swap(ResultMessage);
671  return Result;
672 }
673 
674 VersionTuple Decl::getVersionIntroduced() const {
675  const ASTContext &Context = getASTContext();
676  StringRef TargetPlatform = Context.getTargetInfo().getPlatformName();
677  for (const auto *A : attrs()) {
678  if (const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
679  if (getRealizedPlatform(Availability, Context) != TargetPlatform)
680  continue;
681  if (!Availability->getIntroduced().empty())
682  return Availability->getIntroduced();
683  }
684  }
685  return {};
686 }
687 
688 bool Decl::canBeWeakImported(bool &IsDefinition) const {
689  IsDefinition = false;
690 
691  // Variables, if they aren't definitions.
692  if (const auto *Var = dyn_cast<VarDecl>(this)) {
693  if (Var->isThisDeclarationADefinition()) {
694  IsDefinition = true;
695  return false;
696  }
697  return true;
698  }
699  // Functions, if they aren't definitions.
700  if (const auto *FD = dyn_cast<FunctionDecl>(this)) {
701  if (FD->hasBody()) {
702  IsDefinition = true;
703  return false;
704  }
705  return true;
706 
707  }
708  // Objective-C classes, if this is the non-fragile runtime.
709  if (isa<ObjCInterfaceDecl>(this) &&
711  return true;
712  }
713  // Nothing else.
714  return false;
715 }
716 
717 bool Decl::isWeakImported() const {
718  bool IsDefinition;
719  if (!canBeWeakImported(IsDefinition))
720  return false;
721 
722  for (const auto *A : getMostRecentDecl()->attrs()) {
723  if (isa<WeakImportAttr>(A))
724  return true;
725 
726  if (const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
727  if (CheckAvailability(getASTContext(), Availability, nullptr,
728  VersionTuple()) == AR_NotYetIntroduced)
729  return true;
730  }
731  }
732 
733  return false;
734 }
735 
737  switch (DeclKind) {
738  case Function:
739  case CXXDeductionGuide:
740  case CXXMethod:
741  case CXXConstructor:
742  case ConstructorUsingShadow:
743  case CXXDestructor:
744  case CXXConversion:
745  case EnumConstant:
746  case Var:
747  case ImplicitParam:
748  case ParmVar:
749  case ObjCMethod:
750  case ObjCProperty:
751  case MSProperty:
752  return IDNS_Ordinary;
753  case Label:
754  return IDNS_Label;
755  case IndirectField:
756  return IDNS_Ordinary | IDNS_Member;
757 
758  case Binding:
759  case NonTypeTemplateParm:
760  case VarTemplate:
761  case Concept:
762  // These (C++-only) declarations are found by redeclaration lookup for
763  // tag types, so we include them in the tag namespace.
764  return IDNS_Ordinary | IDNS_Tag;
765 
766  case ObjCCompatibleAlias:
767  case ObjCInterface:
768  return IDNS_Ordinary | IDNS_Type;
769 
770  case Typedef:
771  case TypeAlias:
772  case TemplateTypeParm:
773  case ObjCTypeParam:
774  return IDNS_Ordinary | IDNS_Type;
775 
776  case UnresolvedUsingTypename:
778 
779  case UsingShadow:
780  return 0; // we'll actually overwrite this later
781 
782  case UnresolvedUsingValue:
783  return IDNS_Ordinary | IDNS_Using;
784 
785  case Using:
786  case UsingPack:
787  case UsingEnum:
788  return IDNS_Using;
789 
790  case ObjCProtocol:
791  return IDNS_ObjCProtocol;
792 
793  case Field:
794  case ObjCAtDefsField:
795  case ObjCIvar:
796  return IDNS_Member;
797 
798  case Record:
799  case CXXRecord:
800  case Enum:
801  return IDNS_Tag | IDNS_Type;
802 
803  case Namespace:
804  case NamespaceAlias:
805  return IDNS_Namespace;
806 
807  case FunctionTemplate:
808  return IDNS_Ordinary;
809 
810  case ClassTemplate:
811  case TemplateTemplateParm:
812  case TypeAliasTemplate:
813  return IDNS_Ordinary | IDNS_Tag | IDNS_Type;
814 
815  case UnresolvedUsingIfExists:
816  return IDNS_Type | IDNS_Ordinary;
817 
818  case OMPDeclareReduction:
819  return IDNS_OMPReduction;
820 
821  case OMPDeclareMapper:
822  return IDNS_OMPMapper;
823 
824  // Never have names.
825  case Friend:
826  case FriendTemplate:
827  case AccessSpec:
828  case LinkageSpec:
829  case Export:
830  case FileScopeAsm:
831  case StaticAssert:
832  case ObjCPropertyImpl:
833  case PragmaComment:
834  case PragmaDetectMismatch:
835  case Block:
836  case Captured:
837  case TranslationUnit:
838  case ExternCContext:
839  case Decomposition:
840  case MSGuid:
841  case TemplateParamObject:
842 
843  case UsingDirective:
844  case BuiltinTemplate:
845  case ClassTemplateSpecialization:
846  case ClassTemplatePartialSpecialization:
847  case ClassScopeFunctionSpecialization:
848  case VarTemplateSpecialization:
849  case VarTemplatePartialSpecialization:
850  case ObjCImplementation:
851  case ObjCCategory:
852  case ObjCCategoryImpl:
853  case Import:
854  case OMPThreadPrivate:
855  case OMPAllocate:
856  case OMPRequires:
857  case OMPCapturedExpr:
858  case Empty:
859  case LifetimeExtendedTemporary:
860  case RequiresExprBody:
861  // Never looked up by name.
862  return 0;
863  }
864 
865  llvm_unreachable("Invalid DeclKind!");
866 }
867 
868 void Decl::setAttrsImpl(const AttrVec &attrs, ASTContext &Ctx) {
869  assert(!HasAttrs && "Decl already contains attrs.");
870 
871  AttrVec &AttrBlank = Ctx.getDeclAttrs(this);
872  assert(AttrBlank.empty() && "HasAttrs was wrong?");
873 
874  AttrBlank = attrs;
875  HasAttrs = true;
876 }
877 
879  if (!HasAttrs) return;
880 
881  HasAttrs = false;
883 }
884 
885 void Decl::addAttr(Attr *A) {
886  if (!hasAttrs()) {
887  setAttrs(AttrVec(1, A));
888  return;
889  }
890 
891  AttrVec &Attrs = getAttrs();
892  if (!A->isInherited()) {
893  Attrs.push_back(A);
894  return;
895  }
896 
897  // Attribute inheritance is processed after attribute parsing. To keep the
898  // order as in the source code, add inherited attributes before non-inherited
899  // ones.
900  auto I = Attrs.begin(), E = Attrs.end();
901  for (; I != E; ++I) {
902  if (!(*I)->isInherited())
903  break;
904  }
905  Attrs.insert(I, A);
906 }
907 
908 const AttrVec &Decl::getAttrs() const {
909  assert(HasAttrs && "No attrs to get!");
910  return getASTContext().getDeclAttrs(this);
911 }
912 
914  Decl::Kind DK = D->getDeclKind();
915  switch(DK) {
916 #define DECL(NAME, BASE)
917 #define DECL_CONTEXT(NAME) \
918  case Decl::NAME: \
919  return static_cast<NAME##Decl *>(const_cast<DeclContext *>(D));
920 #define DECL_CONTEXT_BASE(NAME)
921 #include "clang/AST/DeclNodes.inc"
922  default:
923 #define DECL(NAME, BASE)
924 #define DECL_CONTEXT_BASE(NAME) \
925  if (DK >= first##NAME && DK <= last##NAME) \
926  return static_cast<NAME##Decl *>(const_cast<DeclContext *>(D));
927 #include "clang/AST/DeclNodes.inc"
928  llvm_unreachable("a decl that inherits DeclContext isn't handled");
929  }
930 }
931 
933  Decl::Kind DK = D->getKind();
934  switch(DK) {
935 #define DECL(NAME, BASE)
936 #define DECL_CONTEXT(NAME) \
937  case Decl::NAME: \
938  return static_cast<NAME##Decl *>(const_cast<Decl *>(D));
939 #define DECL_CONTEXT_BASE(NAME)
940 #include "clang/AST/DeclNodes.inc"
941  default:
942 #define DECL(NAME, BASE)
943 #define DECL_CONTEXT_BASE(NAME) \
944  if (DK >= first##NAME && DK <= last##NAME) \
945  return static_cast<NAME##Decl *>(const_cast<Decl *>(D));
946 #include "clang/AST/DeclNodes.inc"
947  llvm_unreachable("a decl that inherits DeclContext isn't handled");
948  }
949 }
950 
952  // Special handling of FunctionDecl to avoid de-serializing the body from PCH.
953  // FunctionDecl stores EndRangeLoc for this purpose.
954  if (const auto *FD = dyn_cast<FunctionDecl>(this)) {
955  const FunctionDecl *Definition;
956  if (FD->hasBody(Definition))
957  return Definition->getSourceRange().getEnd();
958  return {};
959  }
960 
961  if (Stmt *Body = getBody())
962  return Body->getSourceRange().getEnd();
963 
964  return {};
965 }
966 
967 bool Decl::AccessDeclContextSanity() const {
968 #ifndef NDEBUG
969  // Suppress this check if any of the following hold:
970  // 1. this is the translation unit (and thus has no parent)
971  // 2. this is a template parameter (and thus doesn't belong to its context)
972  // 3. this is a non-type template parameter
973  // 4. the context is not a record
974  // 5. it's invalid
975  // 6. it's a C++0x static_assert.
976  // 7. it's a block literal declaration
977  // 8. it's a temporary with lifetime extended due to being default value.
978  if (isa<TranslationUnitDecl>(this) || isa<TemplateTypeParmDecl>(this) ||
979  isa<NonTypeTemplateParmDecl>(this) || !getDeclContext() ||
980  !isa<CXXRecordDecl>(getDeclContext()) || isInvalidDecl() ||
981  isa<StaticAssertDecl>(this) || isa<BlockDecl>(this) ||
982  // FIXME: a ParmVarDecl can have ClassTemplateSpecialization
983  // as DeclContext (?).
984  isa<ParmVarDecl>(this) ||
985  // FIXME: a ClassTemplateSpecialization or CXXRecordDecl can have
986  // AS_none as access specifier.
987  isa<CXXRecordDecl>(this) ||
988  isa<ClassScopeFunctionSpecializationDecl>(this) ||
989  isa<LifetimeExtendedTemporaryDecl>(this))
990  return true;
991 
992  assert(Access != AS_none &&
993  "Access specifier is AS_none inside a record decl");
994 #endif
995  return true;
996 }
997 
998 static Decl::Kind getKind(const Decl *D) { return D->getKind(); }
999 static Decl::Kind getKind(const DeclContext *DC) { return DC->getDeclKind(); }
1000 
1001 int64_t Decl::getID() const {
1002  return getASTContext().getAllocator().identifyKnownAlignedObject<Decl>(this);
1003 }
1004 
1005 const FunctionType *Decl::getFunctionType(bool BlocksToo) const {
1006  QualType Ty;
1007  if (const auto *D = dyn_cast<ValueDecl>(this))
1008  Ty = D->getType();
1009  else if (const auto *D = dyn_cast<TypedefNameDecl>(this))
1010  Ty = D->getUnderlyingType();
1011  else
1012  return nullptr;
1013 
1014  if (Ty->isFunctionPointerType())
1015  Ty = Ty->castAs<PointerType>()->getPointeeType();
1016  else if (Ty->isFunctionReferenceType())
1017  Ty = Ty->castAs<ReferenceType>()->getPointeeType();
1018  else if (BlocksToo && Ty->isBlockPointerType())
1019  Ty = Ty->castAs<BlockPointerType>()->getPointeeType();
1020 
1021  return Ty->getAs<FunctionType>();
1022 }
1023 
1024 /// Starting at a given context (a Decl or DeclContext), look for a
1025 /// code context that is not a closure (a lambda, block, etc.).
1026 template <class T> static Decl *getNonClosureContext(T *D) {
1027  if (getKind(D) == Decl::CXXMethod) {
1028  auto *MD = cast<CXXMethodDecl>(D);
1029  if (MD->getOverloadedOperator() == OO_Call &&
1030  MD->getParent()->isLambda())
1031  return getNonClosureContext(MD->getParent()->getParent());
1032  return MD;
1033  }
1034  if (auto *FD = dyn_cast<FunctionDecl>(D))
1035  return FD;
1036  if (auto *MD = dyn_cast<ObjCMethodDecl>(D))
1037  return MD;
1038  if (auto *BD = dyn_cast<BlockDecl>(D))
1039  return getNonClosureContext(BD->getParent());
1040  if (auto *CD = dyn_cast<CapturedDecl>(D))
1041  return getNonClosureContext(CD->getParent());
1042  return nullptr;
1043 }
1044 
1047 }
1048 
1051 }
1052 
1053 //===----------------------------------------------------------------------===//
1054 // DeclContext Implementation
1055 //===----------------------------------------------------------------------===//
1056 
1058  DeclContextBits.DeclKind = K;
1061  setNeedToReconcileExternalVisibleStorage(false);
1062  setHasLazyLocalLexicalLookups(false);
1063  setHasLazyExternalLexicalLookups(false);
1064  setUseQualifiedLookup(false);
1065 }
1066 
1067 bool DeclContext::classof(const Decl *D) {
1068  switch (D->getKind()) {
1069 #define DECL(NAME, BASE)
1070 #define DECL_CONTEXT(NAME) case Decl::NAME:
1071 #define DECL_CONTEXT_BASE(NAME)
1072 #include "clang/AST/DeclNodes.inc"
1073  return true;
1074  default:
1075 #define DECL(NAME, BASE)
1076 #define DECL_CONTEXT_BASE(NAME) \
1077  if (D->getKind() >= Decl::first##NAME && \
1078  D->getKind() <= Decl::last##NAME) \
1079  return true;
1080 #include "clang/AST/DeclNodes.inc"
1081  return false;
1082  }
1083 }
1084 
1085 DeclContext::~DeclContext() = default;
1086 
1087 /// Find the parent context of this context that will be
1088 /// used for unqualified name lookup.
1089 ///
1090 /// Generally, the parent lookup context is the semantic context. However, for
1091 /// a friend function the parent lookup context is the lexical context, which
1092 /// is the class in which the friend is declared.
1094  // FIXME: Find a better way to identify friends.
1095  if (isa<FunctionDecl>(this))
1098  return getLexicalParent();
1099 
1100  // A lookup within the call operator of a lambda never looks in the lambda
1101  // class; instead, skip to the context in which that closure type is
1102  // declared.
1103  if (isLambdaCallOperator(this))
1104  return getParent()->getParent();
1105 
1106  return getParent();
1107 }
1108 
1110  const DeclContext *Ctx = this;
1111 
1112  do {
1113  if (Ctx->isClosure())
1114  return cast<BlockDecl>(Ctx);
1115  Ctx = Ctx->getParent();
1116  } while (Ctx);
1117 
1118  return nullptr;
1119 }
1120 
1122  return isNamespace() &&
1123  cast<NamespaceDecl>(this)->isInline();
1124 }
1125 
1127  if (!isNamespace())
1128  return false;
1129 
1130  const auto *ND = cast<NamespaceDecl>(this);
1131  if (ND->isInline()) {
1132  return ND->getParent()->isStdNamespace();
1133  }
1134 
1136  return false;
1137 
1138  const IdentifierInfo *II = ND->getIdentifier();
1139  return II && II->isStr("std");
1140 }
1141 
1143  if (isFileContext())
1144  return false;
1145 
1146  if (isa<ClassTemplatePartialSpecializationDecl>(this))
1147  return true;
1148 
1149  if (const auto *Record = dyn_cast<CXXRecordDecl>(this)) {
1150  if (Record->getDescribedClassTemplate())
1151  return true;
1152 
1153  if (Record->isDependentLambda())
1154  return true;
1155  }
1156 
1157  if (const auto *Function = dyn_cast<FunctionDecl>(this)) {
1158  if (Function->getDescribedFunctionTemplate())
1159  return true;
1160 
1161  // Friend function declarations are dependent if their *lexical*
1162  // context is dependent.
1163  if (cast<Decl>(this)->getFriendObjectKind())
1165  }
1166 
1167  // FIXME: A variable template is a dependent context, but is not a
1168  // DeclContext. A context within it (such as a lambda-expression)
1169  // should be considered dependent.
1170 
1171  return getParent() && getParent()->isDependentContext();
1172 }
1173 
1175  if (getDeclKind() == Decl::Enum)
1176  return !cast<EnumDecl>(this)->isScoped();
1177 
1178  return getDeclKind() == Decl::LinkageSpec || getDeclKind() == Decl::Export;
1179 }
1180 
1181 static bool isLinkageSpecContext(const DeclContext *DC,
1183  while (DC->getDeclKind() != Decl::TranslationUnit) {
1184  if (DC->getDeclKind() == Decl::LinkageSpec)
1185  return cast<LinkageSpecDecl>(DC)->getLanguage() == ID;
1186  DC = DC->getLexicalParent();
1187  }
1188  return false;
1189 }
1190 
1193 }
1194 
1196  const DeclContext *DC = this;
1197  while (DC->getDeclKind() != Decl::TranslationUnit) {
1198  if (DC->getDeclKind() == Decl::LinkageSpec &&
1199  cast<LinkageSpecDecl>(DC)->getLanguage() == LinkageSpecDecl::lang_c)
1200  return cast<LinkageSpecDecl>(DC);
1201  DC = DC->getLexicalParent();
1202  }
1203  return nullptr;
1204 }
1205 
1208 }
1209 
1210 bool DeclContext::Encloses(const DeclContext *DC) const {
1211  if (getPrimaryContext() != this)
1212  return getPrimaryContext()->Encloses(DC);
1213 
1214  for (; DC; DC = DC->getParent())
1215  if (DC->getPrimaryContext() == this)
1216  return true;
1217  return false;
1218 }
1219 
1221  DeclContext *DC = this;
1222  while (DC->isTransparentContext()) {
1223  DC = DC->getParent();
1224  assert(DC && "All transparent contexts should have a parent!");
1225  }
1226  return DC;
1227 }
1228 
1230  switch (getDeclKind()) {
1231  case Decl::ExternCContext:
1232  case Decl::LinkageSpec:
1233  case Decl::Export:
1234  case Decl::Block:
1235  case Decl::Captured:
1236  case Decl::OMPDeclareReduction:
1237  case Decl::OMPDeclareMapper:
1238  case Decl::RequiresExprBody:
1239  // There is only one DeclContext for these entities.
1240  return this;
1241 
1242  case Decl::TranslationUnit:
1243  return static_cast<TranslationUnitDecl *>(this)->getFirstDecl();
1244  case Decl::Namespace:
1245  // The original namespace is our primary context.
1246  return static_cast<NamespaceDecl *>(this)->getOriginalNamespace();
1247 
1248  case Decl::ObjCMethod:
1249  return this;
1250 
1251  case Decl::ObjCInterface:
1252  if (auto *OID = dyn_cast<ObjCInterfaceDecl>(this))
1253  if (auto *Def = OID->getDefinition())
1254  return Def;
1255  return this;
1256 
1257  case Decl::ObjCProtocol:
1258  if (auto *OPD = dyn_cast<ObjCProtocolDecl>(this))
1259  if (auto *Def = OPD->getDefinition())
1260  return Def;
1261  return this;
1262 
1263  case Decl::ObjCCategory:
1264  return this;
1265 
1266  case Decl::ObjCImplementation:
1267  case Decl::ObjCCategoryImpl:
1268  return this;
1269 
1270  default:
1271  if (getDeclKind() >= Decl::firstTag && getDeclKind() <= Decl::lastTag) {
1272  // If this is a tag type that has a definition or is currently
1273  // being defined, that definition is our primary context.
1274  auto *Tag = cast<TagDecl>(this);
1275 
1276  if (TagDecl *Def = Tag->getDefinition())
1277  return Def;
1278 
1279  if (const auto *TagTy = dyn_cast<TagType>(Tag->getTypeForDecl())) {
1280  // Note, TagType::getDecl returns the (partial) definition one exists.
1281  TagDecl *PossiblePartialDef = TagTy->getDecl();
1282  if (PossiblePartialDef->isBeingDefined())
1283  return PossiblePartialDef;
1284  } else {
1285  assert(isa<InjectedClassNameType>(Tag->getTypeForDecl()));
1286  }
1287 
1288  return Tag;
1289  }
1290 
1291  assert(getDeclKind() >= Decl::firstFunction &&
1292  getDeclKind() <= Decl::lastFunction &&
1293  "Unknown DeclContext kind");
1294  return this;
1295  }
1296 }
1297 
1298 template <typename T>
1300  for (T *D = Self->getMostRecentDecl(); D; D = D->getPreviousDecl())
1301  Contexts.push_back(D);
1302 
1303  std::reverse(Contexts.begin(), Contexts.end());
1304 }
1305 
1307  Contexts.clear();
1308 
1310 
1311  if (Kind == Decl::TranslationUnit)
1312  collectAllContextsImpl(static_cast<TranslationUnitDecl *>(this), Contexts);
1313  else if (Kind == Decl::Namespace)
1314  collectAllContextsImpl(static_cast<NamespaceDecl *>(this), Contexts);
1315  else
1316  Contexts.push_back(this);
1317 }
1318 
1319 std::pair<Decl *, Decl *>
1321  bool FieldsAlreadyLoaded) {
1322  // Build up a chain of declarations via the Decl::NextInContextAndBits field.
1323  Decl *FirstNewDecl = nullptr;
1324  Decl *PrevDecl = nullptr;
1325  for (auto *D : Decls) {
1326  if (FieldsAlreadyLoaded && isa<FieldDecl>(D))
1327  continue;
1328 
1329  if (PrevDecl)
1330  PrevDecl->NextInContextAndBits.setPointer(D);
1331  else
1332  FirstNewDecl = D;
1333 
1334  PrevDecl = D;
1335  }
1336 
1337  return std::make_pair(FirstNewDecl, PrevDecl);
1338 }
1339 
1340 /// We have just acquired external visible storage, and we already have
1341 /// built a lookup map. For every name in the map, pull in the new names from
1342 /// the external storage.
1343 void DeclContext::reconcileExternalVisibleStorage() const {
1344  assert(hasNeedToReconcileExternalVisibleStorage() && LookupPtr);
1345  setNeedToReconcileExternalVisibleStorage(false);
1346 
1347  for (auto &Lookup : *LookupPtr)
1348  Lookup.second.setHasExternalDecls();
1349 }
1350 
1351 /// Load the declarations within this lexical storage from an
1352 /// external source.
1353 /// \return \c true if any declarations were added.
1354 bool
1355 DeclContext::LoadLexicalDeclsFromExternalStorage() const {
1357  assert(hasExternalLexicalStorage() && Source && "No external storage?");
1358 
1359  // Notify that we have a DeclContext that is initializing.
1360  ExternalASTSource::Deserializing ADeclContext(Source);
1361 
1362  // Load the external declarations, if any.
1363  SmallVector<Decl*, 64> Decls;
1365  Source->FindExternalLexicalDecls(this, Decls);
1366 
1367  if (Decls.empty())
1368  return false;
1369 
1370  // We may have already loaded just the fields of this record, in which case
1371  // we need to ignore them.
1372  bool FieldsAlreadyLoaded = false;
1373  if (const auto *RD = dyn_cast<RecordDecl>(this))
1374  FieldsAlreadyLoaded = RD->hasLoadedFieldsFromExternalStorage();
1375 
1376  // Splice the newly-read declarations into the beginning of the list
1377  // of declarations.
1378  Decl *ExternalFirst, *ExternalLast;
1379  std::tie(ExternalFirst, ExternalLast) =
1380  BuildDeclChain(Decls, FieldsAlreadyLoaded);
1381  ExternalLast->NextInContextAndBits.setPointer(FirstDecl);
1382  FirstDecl = ExternalFirst;
1383  if (!LastDecl)
1384  LastDecl = ExternalLast;
1385  return true;
1386 }
1387 
1390  DeclarationName Name) {
1391  ASTContext &Context = DC->getParentASTContext();
1392  StoredDeclsMap *Map;
1393  if (!(Map = DC->LookupPtr))
1394  Map = DC->CreateStoredDeclsMap(Context);
1395  if (DC->hasNeedToReconcileExternalVisibleStorage())
1396  DC->reconcileExternalVisibleStorage();
1397 
1398  (*Map)[Name].removeExternalDecls();
1399 
1400  return DeclContext::lookup_result();
1401 }
1402 
1405  DeclarationName Name,
1406  ArrayRef<NamedDecl*> Decls) {
1407  ASTContext &Context = DC->getParentASTContext();
1408  StoredDeclsMap *Map;
1409  if (!(Map = DC->LookupPtr))
1410  Map = DC->CreateStoredDeclsMap(Context);
1411  if (DC->hasNeedToReconcileExternalVisibleStorage())
1412  DC->reconcileExternalVisibleStorage();
1413 
1414  StoredDeclsList &List = (*Map)[Name];
1415  List.replaceExternalDecls(Decls);
1416  return List.getLookupResult();
1417 }
1418 
1421  LoadLexicalDeclsFromExternalStorage();
1422  return decl_iterator(FirstDecl);
1423 }
1424 
1427  LoadLexicalDeclsFromExternalStorage();
1428 
1429  return !FirstDecl;
1430 }
1431 
1433  return (D->getLexicalDeclContext() == this &&
1434  (D->NextInContextAndBits.getPointer() || D == LastDecl));
1435 }
1436 
1439  LoadLexicalDeclsFromExternalStorage();
1440  return containsDecl(D);
1441 }
1442 
1443 /// shouldBeHidden - Determine whether a declaration which was declared
1444 /// within its semantic context should be invisible to qualified name lookup.
1445 static bool shouldBeHidden(NamedDecl *D) {
1446  // Skip unnamed declarations.
1447  if (!D->getDeclName())
1448  return true;
1449 
1450  // Skip entities that can't be found by name lookup into a particular
1451  // context.
1452  if ((D->getIdentifierNamespace() == 0 && !isa<UsingDirectiveDecl>(D)) ||
1453  D->isTemplateParameter())
1454  return true;
1455 
1456  // Skip friends and local extern declarations unless they're the first
1457  // declaration of the entity.
1458  if ((D->isLocalExternDecl() || D->getFriendObjectKind()) &&
1459  D != D->getCanonicalDecl())
1460  return true;
1461 
1462  // Skip template specializations.
1463  // FIXME: This feels like a hack. Should DeclarationName support
1464  // template-ids, or is there a better way to keep specializations
1465  // from being visible?
1466  if (isa<ClassTemplateSpecializationDecl>(D))
1467  return true;
1468  if (auto *FD = dyn_cast<FunctionDecl>(D))
1469  if (FD->isFunctionTemplateSpecialization())
1470  return true;
1471 
1472  // Hide destructors that are invalid. There should always be one destructor,
1473  // but if it is an invalid decl, another one is created. We need to hide the
1474  // invalid one from places that expect exactly one destructor, like the
1475  // serialization code.
1476  if (isa<CXXDestructorDecl>(D) && D->isInvalidDecl())
1477  return true;
1478 
1479  return false;
1480 }
1481 
1483  assert(D->getLexicalDeclContext() == this &&
1484  "decl being removed from non-lexical context");
1485  assert((D->NextInContextAndBits.getPointer() || D == LastDecl) &&
1486  "decl is not in decls list");
1487 
1488  // Remove D from the decl chain. This is O(n) but hopefully rare.
1489  if (D == FirstDecl) {
1490  if (D == LastDecl)
1491  FirstDecl = LastDecl = nullptr;
1492  else
1493  FirstDecl = D->NextInContextAndBits.getPointer();
1494  } else {
1495  for (Decl *I = FirstDecl; true; I = I->NextInContextAndBits.getPointer()) {
1496  assert(I && "decl not found in linked list");
1497  if (I->NextInContextAndBits.getPointer() == D) {
1498  I->NextInContextAndBits.setPointer(D->NextInContextAndBits.getPointer());
1499  if (D == LastDecl) LastDecl = I;
1500  break;
1501  }
1502  }
1503  }
1504 
1505  // Mark that D is no longer in the decl chain.
1506  D->NextInContextAndBits.setPointer(nullptr);
1507 
1508  // Remove D from the lookup table if necessary.
1509  if (isa<NamedDecl>(D)) {
1510  auto *ND = cast<NamedDecl>(D);
1511 
1512  // Do not try to remove the declaration if that is invisible to qualified
1513  // lookup. E.g. template specializations are skipped.
1514  if (shouldBeHidden(ND))
1515  return;
1516 
1517  // Remove only decls that have a name
1518  if (!ND->getDeclName())
1519  return;
1520 
1521  auto *DC = D->getDeclContext();
1522  do {
1523  StoredDeclsMap *Map = DC->getPrimaryContext()->LookupPtr;
1524  if (Map) {
1525  StoredDeclsMap::iterator Pos = Map->find(ND->getDeclName());
1526  assert(Pos != Map->end() && "no lookup entry for decl");
1527  Pos->second.remove(ND);
1528  }
1529  } while (DC->isTransparentContext() && (DC = DC->getParent()));
1530  }
1531 }
1532 
1534  assert(D->getLexicalDeclContext() == this &&
1535  "Decl inserted into wrong lexical context");
1536  assert(!D->getNextDeclInContext() && D != LastDecl &&
1537  "Decl already inserted into a DeclContext");
1538 
1539  if (FirstDecl) {
1540  LastDecl->NextInContextAndBits.setPointer(D);
1541  LastDecl = D;
1542  } else {
1543  FirstDecl = LastDecl = D;
1544  }
1545 
1546  // Notify a C++ record declaration that we've added a member, so it can
1547  // update its class-specific state.
1548  if (auto *Record = dyn_cast<CXXRecordDecl>(this))
1549  Record->addedMember(D);
1550 
1551  // If this is a newly-created (not de-serialized) import declaration, wire
1552  // it in to the list of local import declarations.
1553  if (!D->isFromASTFile()) {
1554  if (auto *Import = dyn_cast<ImportDecl>(D))
1555  D->getASTContext().addedLocalImportDecl(Import);
1556  }
1557 }
1558 
1560  addHiddenDecl(D);
1561 
1562  if (auto *ND = dyn_cast<NamedDecl>(D))
1563  ND->getDeclContext()->getPrimaryContext()->
1564  makeDeclVisibleInContextWithFlags(ND, false, true);
1565 }
1566 
1568  addHiddenDecl(D);
1569 
1570  if (auto *ND = dyn_cast<NamedDecl>(D))
1571  ND->getDeclContext()->getPrimaryContext()->
1572  makeDeclVisibleInContextWithFlags(ND, true, true);
1573 }
1574 
1575 /// buildLookup - Build the lookup data structure with all of the
1576 /// declarations in this DeclContext (and any other contexts linked
1577 /// to it or transparent contexts nested within it) and return it.
1578 ///
1579 /// Note that the produced map may miss out declarations from an
1580 /// external source. If it does, those entries will be marked with
1581 /// the 'hasExternalDecls' flag.
1583  assert(this == getPrimaryContext() && "buildLookup called on non-primary DC");
1584 
1585  if (!hasLazyLocalLexicalLookups() &&
1586  !hasLazyExternalLexicalLookups())
1587  return LookupPtr;
1588 
1590  collectAllContexts(Contexts);
1591 
1592  if (hasLazyExternalLexicalLookups()) {
1593  setHasLazyExternalLexicalLookups(false);
1594  for (auto *DC : Contexts) {
1595  if (DC->hasExternalLexicalStorage()) {
1596  bool LoadedDecls = DC->LoadLexicalDeclsFromExternalStorage();
1597  setHasLazyLocalLexicalLookups(
1598  hasLazyLocalLexicalLookups() | LoadedDecls );
1599  }
1600  }
1601 
1602  if (!hasLazyLocalLexicalLookups())
1603  return LookupPtr;
1604  }
1605 
1606  for (auto *DC : Contexts)
1607  buildLookupImpl(DC, hasExternalVisibleStorage());
1608 
1609  // We no longer have any lazy decls.
1610  setHasLazyLocalLexicalLookups(false);
1611  return LookupPtr;
1612 }
1613 
1614 /// buildLookupImpl - Build part of the lookup data structure for the
1615 /// declarations contained within DCtx, which will either be this
1616 /// DeclContext, a DeclContext linked to it, or a transparent context
1617 /// nested within it.
1618 void DeclContext::buildLookupImpl(DeclContext *DCtx, bool Internal) {
1619  for (auto *D : DCtx->noload_decls()) {
1620  // Insert this declaration into the lookup structure, but only if
1621  // it's semantically within its decl context. Any other decls which
1622  // should be found in this context are added eagerly.
1623  //
1624  // If it's from an AST file, don't add it now. It'll get handled by
1625  // FindExternalVisibleDeclsByName if needed. Exception: if we're not
1626  // in C++, we do not track external visible decls for the TU, so in
1627  // that case we need to collect them all here.
1628  if (auto *ND = dyn_cast<NamedDecl>(D))
1629  if (ND->getDeclContext() == DCtx && !shouldBeHidden(ND) &&
1630  (!ND->isFromASTFile() ||
1631  (isTranslationUnit() &&
1632  !getParentASTContext().getLangOpts().CPlusPlus)))
1633  makeDeclVisibleInContextImpl(ND, Internal);
1634 
1635  // If this declaration is itself a transparent declaration context
1636  // or inline namespace, add the members of this declaration of that
1637  // context (recursively).
1638  if (auto *InnerCtx = dyn_cast<DeclContext>(D))
1639  if (InnerCtx->isTransparentContext() || InnerCtx->isInlineNamespace())
1640  buildLookupImpl(InnerCtx, Internal);
1641  }
1642 }
1643 
1646  assert(getDeclKind() != Decl::LinkageSpec &&
1647  getDeclKind() != Decl::Export &&
1648  "should not perform lookups into transparent contexts");
1649 
1650  const DeclContext *PrimaryContext = getPrimaryContext();
1651  if (PrimaryContext != this)
1652  return PrimaryContext->lookup(Name);
1653 
1654  // If we have an external source, ensure that any later redeclarations of this
1655  // context have been loaded, since they may add names to the result of this
1656  // lookup (or add external visible storage).
1658  if (Source)
1659  (void)cast<Decl>(this)->getMostRecentDecl();
1660 
1661  if (hasExternalVisibleStorage()) {
1662  assert(Source && "external visible storage but no external source?");
1663 
1664  if (hasNeedToReconcileExternalVisibleStorage())
1665  reconcileExternalVisibleStorage();
1666 
1667  StoredDeclsMap *Map = LookupPtr;
1668 
1669  if (hasLazyLocalLexicalLookups() ||
1670  hasLazyExternalLexicalLookups())
1671  // FIXME: Make buildLookup const?
1672  Map = const_cast<DeclContext*>(this)->buildLookup();
1673 
1674  if (!Map)
1675  Map = CreateStoredDeclsMap(getParentASTContext());
1676 
1677  // If we have a lookup result with no external decls, we are done.
1678  std::pair<StoredDeclsMap::iterator, bool> R =
1679  Map->insert(std::make_pair(Name, StoredDeclsList()));
1680  if (!R.second && !R.first->second.hasExternalDecls())
1681  return R.first->second.getLookupResult();
1682 
1683  if (Source->FindExternalVisibleDeclsByName(this, Name) || !R.second) {
1684  if (StoredDeclsMap *Map = LookupPtr) {
1685  StoredDeclsMap::iterator I = Map->find(Name);
1686  if (I != Map->end())
1687  return I->second.getLookupResult();
1688  }
1689  }
1690 
1691  return {};
1692  }
1693 
1694  StoredDeclsMap *Map = LookupPtr;
1695  if (hasLazyLocalLexicalLookups() ||
1696  hasLazyExternalLexicalLookups())
1697  Map = const_cast<DeclContext*>(this)->buildLookup();
1698 
1699  if (!Map)
1700  return {};
1701 
1702  StoredDeclsMap::iterator I = Map->find(Name);
1703  if (I == Map->end())
1704  return {};
1705 
1706  return I->second.getLookupResult();
1707 }
1708 
1711  assert(getDeclKind() != Decl::LinkageSpec &&
1712  getDeclKind() != Decl::Export &&
1713  "should not perform lookups into transparent contexts");
1714 
1715  DeclContext *PrimaryContext = getPrimaryContext();
1716  if (PrimaryContext != this)
1717  return PrimaryContext->noload_lookup(Name);
1718 
1719  loadLazyLocalLexicalLookups();
1720  StoredDeclsMap *Map = LookupPtr;
1721  if (!Map)
1722  return {};
1723 
1724  StoredDeclsMap::iterator I = Map->find(Name);
1725  return I != Map->end() ? I->second.getLookupResult()
1726  : lookup_result();
1727 }
1728 
1729 // If we have any lazy lexical declarations not in our lookup map, add them
1730 // now. Don't import any external declarations, not even if we know we have
1731 // some missing from the external visible lookups.
1732 void DeclContext::loadLazyLocalLexicalLookups() {
1733  if (hasLazyLocalLexicalLookups()) {
1735  collectAllContexts(Contexts);
1736  for (auto *Context : Contexts)
1737  buildLookupImpl(Context, hasExternalVisibleStorage());
1738  setHasLazyLocalLexicalLookups(false);
1739  }
1740 }
1741 
1743  SmallVectorImpl<NamedDecl *> &Results) {
1744  Results.clear();
1745 
1746  // If there's no external storage, just perform a normal lookup and copy
1747  // the results.
1749  lookup_result LookupResults = lookup(Name);
1750  Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
1751  return;
1752  }
1753 
1754  // If we have a lookup table, check there first. Maybe we'll get lucky.
1755  // FIXME: Should we be checking these flags on the primary context?
1756  if (Name && !hasLazyLocalLexicalLookups() &&
1757  !hasLazyExternalLexicalLookups()) {
1758  if (StoredDeclsMap *Map = LookupPtr) {
1759  StoredDeclsMap::iterator Pos = Map->find(Name);
1760  if (Pos != Map->end()) {
1761  Results.insert(Results.end(),
1762  Pos->second.getLookupResult().begin(),
1763  Pos->second.getLookupResult().end());
1764  return;
1765  }
1766  }
1767  }
1768 
1769  // Slow case: grovel through the declarations in our chain looking for
1770  // matches.
1771  // FIXME: If we have lazy external declarations, this will not find them!
1772  // FIXME: Should we CollectAllContexts and walk them all here?
1773  for (Decl *D = FirstDecl; D; D = D->getNextDeclInContext()) {
1774  if (auto *ND = dyn_cast<NamedDecl>(D))
1775  if (ND->getDeclName() == Name)
1776  Results.push_back(ND);
1777  }
1778 }
1779 
1781  DeclContext *Ctx = this;
1782 
1783  // In C, a record type is the redeclaration context for its fields only. If
1784  // we arrive at a record context after skipping anything else, we should skip
1785  // the record as well. Currently, this means skipping enumerations because
1786  // they're the only transparent context that can exist within a struct or
1787  // union.
1788  bool SkipRecords = getDeclKind() == Decl::Kind::Enum &&
1789  !getParentASTContext().getLangOpts().CPlusPlus;
1790 
1791  // Skip through contexts to get to the redeclaration context. Transparent
1792  // contexts are always skipped.
1793  while ((SkipRecords && Ctx->isRecord()) || Ctx->isTransparentContext())
1794  Ctx = Ctx->getParent();
1795  return Ctx;
1796 }
1797 
1799  DeclContext *Ctx = this;
1800  // Skip through non-namespace, non-translation-unit contexts.
1801  while (!Ctx->isFileContext())
1802  Ctx = Ctx->getParent();
1803  return Ctx->getPrimaryContext();
1804 }
1805 
1807  // Loop until we find a non-record context.
1808  RecordDecl *OutermostRD = nullptr;
1809  DeclContext *DC = this;
1810  while (DC->isRecord()) {
1811  OutermostRD = cast<RecordDecl>(DC);
1812  DC = DC->getLexicalParent();
1813  }
1814  return OutermostRD;
1815 }
1816 
1818  // For non-file contexts, this is equivalent to Equals.
1819  if (!isFileContext())
1820  return O->Equals(this);
1821 
1822  do {
1823  if (O->Equals(this))
1824  return true;
1825 
1826  const auto *NS = dyn_cast<NamespaceDecl>(O);
1827  if (!NS || !NS->isInline())
1828  break;
1829  O = NS->getParent();
1830  } while (O);
1831 
1832  return false;
1833 }
1834 
1836  DeclContext *PrimaryDC = this->getPrimaryContext();
1837  DeclContext *DeclDC = D->getDeclContext()->getPrimaryContext();
1838  // If the decl is being added outside of its semantic decl context, we
1839  // need to ensure that we eagerly build the lookup information for it.
1840  PrimaryDC->makeDeclVisibleInContextWithFlags(D, false, PrimaryDC == DeclDC);
1841 }
1842 
1843 void DeclContext::makeDeclVisibleInContextWithFlags(NamedDecl *D, bool Internal,
1844  bool Recoverable) {
1845  assert(this == getPrimaryContext() && "expected a primary DC");
1846 
1847  if (!isLookupContext()) {
1848  if (isTransparentContext())
1850  ->makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
1851  return;
1852  }
1853 
1854  // Skip declarations which should be invisible to name lookup.
1855  if (shouldBeHidden(D))
1856  return;
1857 
1858  // If we already have a lookup data structure, perform the insertion into
1859  // it. If we might have externally-stored decls with this name, look them
1860  // up and perform the insertion. If this decl was declared outside its
1861  // semantic context, buildLookup won't add it, so add it now.
1862  //
1863  // FIXME: As a performance hack, don't add such decls into the translation
1864  // unit unless we're in C++, since qualified lookup into the TU is never
1865  // performed.
1866  if (LookupPtr || hasExternalVisibleStorage() ||
1867  ((!Recoverable || D->getDeclContext() != D->getLexicalDeclContext()) &&
1868  (getParentASTContext().getLangOpts().CPlusPlus ||
1869  !isTranslationUnit()))) {
1870  // If we have lazily omitted any decls, they might have the same name as
1871  // the decl which we are adding, so build a full lookup table before adding
1872  // this decl.
1873  buildLookup();
1874  makeDeclVisibleInContextImpl(D, Internal);
1875  } else {
1876  setHasLazyLocalLexicalLookups(true);
1877  }
1878 
1879  // If we are a transparent context or inline namespace, insert into our
1880  // parent context, too. This operation is recursive.
1883  makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
1884 
1885  auto *DCAsDecl = cast<Decl>(this);
1886  // Notify that a decl was made visible unless we are a Tag being defined.
1887  if (!(isa<TagDecl>(DCAsDecl) && cast<TagDecl>(DCAsDecl)->isBeingDefined()))
1888  if (ASTMutationListener *L = DCAsDecl->getASTMutationListener())
1889  L->AddedVisibleDecl(this, D);
1890 }
1891 
1892 void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal) {
1893  // Find or create the stored declaration map.
1894  StoredDeclsMap *Map = LookupPtr;
1895  if (!Map) {
1897  Map = CreateStoredDeclsMap(*C);
1898  }
1899 
1900  // If there is an external AST source, load any declarations it knows about
1901  // with this declaration's name.
1902  // If the lookup table contains an entry about this name it means that we
1903  // have already checked the external source.
1904  if (!Internal)
1905  if (ExternalASTSource *Source = getParentASTContext().getExternalSource())
1906  if (hasExternalVisibleStorage() &&
1907  Map->find(D->getDeclName()) == Map->end())
1908  Source->FindExternalVisibleDeclsByName(this, D->getDeclName());
1909 
1910  // Insert this declaration into the map.
1911  StoredDeclsList &DeclNameEntries = (*Map)[D->getDeclName()];
1912 
1913  if (Internal) {
1914  // If this is being added as part of loading an external declaration,
1915  // this may not be the only external declaration with this name.
1916  // In this case, we never try to replace an existing declaration; we'll
1917  // handle that when we finalize the list of declarations for this name.
1918  DeclNameEntries.setHasExternalDecls();
1919  DeclNameEntries.prependDeclNoReplace(D);
1920  return;
1921  }
1922 
1923  DeclNameEntries.addOrReplaceDecl(D);
1924 }
1925 
1927  return cast<UsingDirectiveDecl>(*I);
1928 }
1929 
1930 /// Returns iterator range [First, Last) of UsingDirectiveDecls stored within
1931 /// this context.
1933  // FIXME: Use something more efficient than normal lookup for using
1934  // directives. In C++, using directives are looked up more than anything else.
1935  lookup_result Result = lookup(UsingDirectiveDecl::getName());
1936  return udir_range(Result.begin(), Result.end());
1937 }
1938 
1939 //===----------------------------------------------------------------------===//
1940 // Creation and Destruction of StoredDeclsMaps. //
1941 //===----------------------------------------------------------------------===//
1942 
1943 StoredDeclsMap *DeclContext::CreateStoredDeclsMap(ASTContext &C) const {
1944  assert(!LookupPtr && "context already has a decls map");
1945  assert(getPrimaryContext() == this &&
1946  "creating decls map on non-primary context");
1947 
1948  StoredDeclsMap *M;
1949  bool Dependent = isDependentContext();
1950  if (Dependent)
1951  M = new DependentStoredDeclsMap();
1952  else
1953  M = new StoredDeclsMap();
1954  M->Previous = C.LastSDM;
1955  C.LastSDM = llvm::PointerIntPair<StoredDeclsMap*,1>(M, Dependent);
1956  LookupPtr = M;
1957  return M;
1958 }
1959 
1960 void ASTContext::ReleaseDeclContextMaps() {
1961  // It's okay to delete DependentStoredDeclsMaps via a StoredDeclsMap
1962  // pointer because the subclass doesn't add anything that needs to
1963  // be deleted.
1964  StoredDeclsMap::DestroyAll(LastSDM.getPointer(), LastSDM.getInt());
1965 }
1966 
1967 void StoredDeclsMap::DestroyAll(StoredDeclsMap *Map, bool Dependent) {
1968  while (Map) {
1969  // Advance the iteration before we invalidate memory.
1970  llvm::PointerIntPair<StoredDeclsMap*,1> Next = Map->Previous;
1971 
1972  if (Dependent)
1973  delete static_cast<DependentStoredDeclsMap*>(Map);
1974  else
1975  delete Map;
1976 
1977  Map = Next.getPointer();
1978  Dependent = Next.getInt();
1979  }
1980 }
1981 
1984  const PartialDiagnostic &PDiag) {
1985  assert(Parent->isDependentContext()
1986  && "cannot iterate dependent diagnostics of non-dependent context");
1987  Parent = Parent->getPrimaryContext();
1988  if (!Parent->LookupPtr)
1989  Parent->CreateStoredDeclsMap(C);
1990 
1991  auto *Map = static_cast<DependentStoredDeclsMap *>(Parent->LookupPtr);
1992 
1993  // Allocate the copy of the PartialDiagnostic via the ASTContext's
1994  // BumpPtrAllocator, rather than the ASTContext itself.
1995  DiagnosticStorage *DiagStorage = nullptr;
1996  if (PDiag.hasStorage())
1997  DiagStorage = new (C) DiagnosticStorage;
1998 
1999  auto *DD = new (C) DependentDiagnostic(PDiag, DiagStorage);
2000 
2001  // TODO: Maybe we shouldn't reverse the order during insertion.
2002  DD->NextDiagnostic = Map->FirstDiagnostic;
2003  Map->FirstDiagnostic = DD;
2004 
2005  return DD;
2006 }
clang::Decl::setLexicalDeclContext
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:331
clang::DeclContext::hasExternalVisibleStorage
bool hasExternalVisibleStorage() const
Whether this DeclContext has external storage containing additional declarations that are visible in ...
Definition: DeclBase.h:2442
clang::DeclContext::localUncachedLookup
void localUncachedLookup(DeclarationName Name, SmallVectorImpl< NamedDecl * > &Results)
A simplistic name lookup mechanism that performs name lookup into this declaration context without co...
Definition: DeclBase.cpp:1742
max
__DEVICE__ int max(int __a, int __b)
Definition: __clang_cuda_math.h:196
clang::Decl::getASTContext
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:414
clang::ASTContext::getASTMutationListener
ASTMutationListener * getASTMutationListener() const
Retrieve a pointer to the AST mutation listener associated with this AST context, if any.
Definition: ASTContext.h:1167
clang::isLambdaCallOperator
bool isLambdaCallOperator(const CXXMethodDecl *MD)
Definition: ASTLambda.h:27
clang::DeclContext::removeDecl
void removeDecl(Decl *D)
Removes a declaration from this context.
Definition: DeclBase.cpp:1482
clang::Decl::IDNS_Type
@ IDNS_Type
Types, declared with 'struct foo', typedefs, etc.
Definition: DeclBase.h:133
clang::DeclContext::getParentASTContext
ASTContext & getParentASTContext() const
Definition: DeclBase.h:1889
clang::Type::isBlockPointerType
bool isBlockPointerType() const
Definition: Type.h:6681
clang::DeclContext::getExternCContext
const LinkageSpecDecl * getExternCContext() const
Retrieve the nearest enclosing C linkage specification context.
Definition: DeclBase.cpp:1195
clang::PartialDiagnostic::hasStorage
bool hasStorage() const
Definition: PartialDiagnostic.h:188
clang::Decl::setDeclContext
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition: DeclBase.cpp:327
ObjCRuntime.h
clang::DeclContext::hasExternalLexicalStorage
bool hasExternalLexicalStorage() const
Whether this DeclContext has external storage containing additional declarations that are lexically i...
Definition: DeclBase.h:2430
clang::LinkageSpecDecl
Represents a linkage specification.
Definition: DeclCXX.h:2797
clang::DeclContext::addHiddenDecl
void addHiddenDecl(Decl *D)
Add the declaration D to this context without modifying any lookup tables.
Definition: DeclBase.cpp:1533
clang::Decl::isTemplateDecl
bool isTemplateDecl() const
returns true if this declaration is a template
Definition: DeclBase.cpp:226
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1347
clang::Decl::getParentFunctionOrMethod
const DeclContext * getParentFunctionOrMethod() const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext,...
Definition: DeclBase.cpp:286
clang::Decl::isTemplateParameter
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
Definition: DeclBase.h:2540
clang::Decl::getAsFunction
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition: DeclBase.cpp:218
clang::DeclContext::getNonClosureAncestor
Decl * getNonClosureAncestor()
Find the nearest non-closure ancestor of this context, i.e.
Definition: DeclBase.cpp:1049
clang::ExternalASTSource::FindExternalVisibleDeclsByName
virtual bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name)
Find all declarations with the given name in the given context, and add them to the context by callin...
Definition: ExternalASTSource.cpp:98
clang::UsingDirectiveDecl
Represents C++ using-directive.
Definition: DeclCXX.h:2882
clang::Decl::getASTMutationListener
ASTMutationListener * getASTMutationListener() const
Definition: DeclBase.cpp:424
llvm::SmallVector
Definition: LLVM.h:38
clang::AR_Deprecated
@ AR_Deprecated
Definition: DeclBase.h:78
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
TargetInfo.h
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
clang::Decl::add
static void add(Kind k)
Definition: DeclBase.cpp:193
Attr.h
clang::DeclContext::addDeclInternal
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
Definition: DeclBase.cpp:1567
AttributeLangSupport::C
@ C
Definition: SemaDeclAttr.cpp:54
clang::Decl::IDNS_Using
@ IDNS_Using
This declaration is a using declaration.
Definition: DeclBase.h:166
clang::Decl::PrintStats
static void PrintStats()
Definition: DeclBase.cpp:169
clang::StoredDeclsMap::DestroyAll
static void DestroyAll(StoredDeclsMap *Map, bool Dependent)
Definition: DeclBase.cpp:1967
clang::Decl::getNextDeclInContext
Decl * getNextDeclInContext()
Definition: DeclBase.h:436
DeclCXX.h
clang::Decl::isUsed
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition: DeclBase.cpp:443
clang::StoredDeclsList::setHasExternalDecls
void setHasExternalDecls()
Definition: DeclContextInternals.h:145
AttrIterator.h
clang::ASTContext::eraseDeclAttrs
void eraseDeclAttrs(const Decl *D)
Erase the attributes corresponding to the given declaration.
Definition: ASTContext.cpp:1516
clang::Decl::getIdentifierNamespace
unsigned getIdentifierNamespace() const
Definition: DeclBase.h:814
DeclOpenMP.h
clang::Decl::isTemplateParameterPack
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack.
Definition: DeclBase.cpp:201
clang::DeclContext::setHasExternalLexicalStorage
void setHasExternalLexicalStorage(bool ES=true) const
State whether this DeclContext has external storage for declarations lexically in this context.
Definition: DeclBase.h:2436
clang::Decl::getLangOpts
const LangOptions & getLangOpts() const LLVM_READONLY
Helper to get the language options from the ASTContext.
Definition: DeclBase.cpp:420
clang::Decl::setIsUsed
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition: DeclBase.h:578
ASTLambda.h
clang::DeclContext::isInlineNamespace
bool isInlineNamespace() const
Definition: DeclBase.cpp:1121
clang::DeclContext::using_directives
udir_range using_directives() const
Returns iterator range [First, Last) of UsingDirectiveDecls stored within this context.
Definition: DeclBase.cpp:1932
clang::DeclContext::getLexicalParent
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
Definition: DeclBase.h:1876
clang::DeclContext::classof
static bool classof(const Decl *D)
Definition: DeclBase.cpp:1067
clang::FunctionType
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3546
clang::ObjCRuntime::hasWeakClassImport
bool hasWeakClassImport() const
Does this runtime support weakly importing classes?
Definition: ObjCRuntime.h:362
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::DeclarationName
The name of a declaration.
Definition: DeclarationName.h:145
clang::Decl::isReferenced
bool isReferenced() const
Whether any declaration of this entity was referenced.
Definition: DeclBase.cpp:468
clang::DeclContext::isClosure
bool isClosure() const
Definition: DeclBase.h:1893
clang::DeclContextLookupResult::begin
iterator begin()
Definition: DeclBase.h:1306
clang::Decl::isLocalExternDecl
bool isLocalExternDecl()
Determine whether this is a block-scope declaration with linkage.
Definition: DeclBase.h:1092
clang::Decl::markUsed
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
Definition: DeclBase.cpp:458
clang::DiagnosticStorage
Definition: Diagnostic.h:147
clang::DeclContext::decls_empty
bool decls_empty() const
Definition: DeclBase.cpp:1425
clang::Decl::getModuleOwnershipKind
ModuleOwnershipKind getModuleOwnershipKind() const
Get the kind of module ownership for this declaration.
Definition: DeclBase.h:801
clang::DeclContext::getNonTransparentContext
DeclContext * getNonTransparentContext()
Definition: DeclBase.cpp:1220
clang::Decl::getAvailability
AvailabilityResult getAvailability(std::string *Message=nullptr, VersionTuple EnclosingVersion=VersionTuple(), StringRef *RealizedPlatform=nullptr) const
Determine the availability of the given declaration.
Definition: DeclBase.cpp:622
Decl.h
clang::ExternalASTSource::getModule
virtual Module * getModule(unsigned ID)
Retrieve the module that corresponds to the given module ID.
Definition: ExternalASTSource.h:160
DeclObjC.h
clang::Decl::isWeakImported
bool isWeakImported() const
Determine whether this is a weak-imported symbol.
Definition: DeclBase.cpp:717
clang::DeclContext::noload_decls
decl_range noload_decls() const
noload_decls_begin/end - Iterate over the declarations stored in this context that are currently load...
Definition: DeclBase.h:2123
clang::AS_none
@ AS_none
Definition: Specifiers.h:103
clang::LinkageSpecDecl::lang_c
@ lang_c
Definition: DeclCXX.h:2806
clang::DeclContext::InEnclosingNamespaceSetOf
bool InEnclosingNamespaceSetOf(const DeclContext *NS) const
Test if this context is part of the enclosing namespace set of the context NS, as defined in C++0x [n...
Definition: DeclBase.cpp:1817
clang::ExternalASTSource::FindExternalLexicalDecls
virtual void FindExternalLexicalDecls(const DeclContext *DC, llvm::function_ref< bool(Decl::Kind)> IsKindWeWant, SmallVectorImpl< Decl * > &Result)
Finds all declarations lexically contained within the given DeclContext, after applying an optional f...
Definition: ExternalASTSource.cpp:105
size_t
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c-base.h:102
clang::Decl::getFunctionType
const FunctionType * getFunctionType(bool BlocksToo=true) const
Looks through the Decl's underlying type to extract a FunctionType when possible.
Definition: DeclBase.cpp:1005
clang::ASTContext::Allocate
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:701
clang::DeclContext::BuildDeclChain
static std::pair< Decl *, Decl * > BuildDeclChain(ArrayRef< Decl * > Decls, bool FieldsAlreadyLoaded)
Build up a chain of declarations.
Definition: DeclBase.cpp:1320
clang::IdentifierInfo::isStr
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
Definition: IdentifierTable.h:156
clang::Decl::getLexicalDeclContext
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:843
clang::DeclContext::setUseQualifiedLookup
bool setUseQualifiedLookup(bool use=true) const
Definition: DeclBase.h:2461
V
#define V(N, I)
Definition: ASTContext.h:3113
clang::ASTContext::getExternalSource
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1152
clang::TranslationUnitDecl
The top declaration context.
Definition: Decl.h:82
clang::SourceLocation::print
void print(raw_ostream &OS, const SourceManager &SM) const
Definition: SourceLocation.cpp:62
clang::ast_matchers::attr
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
Definition: ASTMatchersInternal.cpp:1016
clang::Decl::Kind
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:92
clang::Decl::getIdentifierNamespaceForKind
static unsigned getIdentifierNamespaceForKind(Kind DK)
Definition: DeclBase.cpp:736
clang::DeclContext::FirstDecl
Decl * FirstDecl
FirstDecl - The first declaration stored within this declaration context.
Definition: DeclBase.h:1834
clang::AR_Available
@ AR_Available
Definition: DeclBase.h:76
clang::Module
Describes a module or submodule.
Definition: Module.h:96
DeclTemplate.h
DeclFriend.h
clang::BlockDecl
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4153
clang::Decl::getKind
Kind getKind() const
Definition: DeclBase.h:433
clang::DependentStoredDeclsMap
Definition: DeclContextInternals.h:307
clang::Decl::getNonClosureContext
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks,...
Definition: DeclBase.cpp:1045
clang::Decl::ModuleOwnershipKind::VisibleWhenImported
@ VisibleWhenImported
This declaration has an owning module, and is visible when that module is imported.
clang::DeclContext::getEnclosingNamespaceContext
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
Definition: DeclBase.cpp:1798
clang::Decl::setAccess
void setAccess(AccessSpecifier AS)
Definition: DeclBase.h:473
clang::Decl::NextInContextAndBits
llvm::PointerIntPair< Decl *, 2, ModuleOwnershipKind > NextInContextAndBits
The next declaration within the same lexical DeclContext.
Definition: DeclBase.h:245
DeclBase.h
clang::DeclContext::getDeclKind
Decl::Kind getDeclKind() const
Definition: DeclBase.h:1853
clang::Decl::isInStdNamespace
bool isInStdNamespace() const
Definition: DeclBase.cpp:394
clang::Decl::setModuleOwnershipKind
void setModuleOwnershipKind(ModuleOwnershipKind MOK)
Set whether this declaration is hidden from name lookup.
Definition: DeclBase.h:806
clang::StoredDeclsMap
Definition: DeclContextInternals.h:297
clang::AS_public
@ AS_public
Definition: Specifiers.h:100
clang::Type::isFunctionPointerType
bool isFunctionPointerType() const
Definition: Type.h:6707
clang::Decl::setAttrs
void setAttrs(const AttrVec &Attrs)
Definition: DeclBase.h:491
clang::Decl::getBodyRBrace
SourceLocation getBodyRBrace() const
getBodyRBrace - Gets the right brace of the body, if a body exists.
Definition: DeclBase.cpp:951
clang::DeclContext::setHasExternalVisibleStorage
void setHasExternalVisibleStorage(bool ES=true) const
State whether this DeclContext has external storage for declarations visible in this context.
Definition: DeclBase.h:2448
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:211
shouldBeHidden
static bool shouldBeHidden(NamedDecl *D)
shouldBeHidden - Determine whether a declaration which was declared within its semantic context shoul...
Definition: DeclBase.cpp:1445
clang::TagDecl::getDefinition
TagDecl * getDefinition() const
Returns the TagDecl that actually defines this struct/union/class/enum.
Definition: Decl.cpp:4320
clang::CPlusPlus
@ CPlusPlus
Definition: LangStandard.h:48
clang::StoredDeclsList
An array of decls optimized for the common case of only containing one entry.
Definition: DeclContextInternals.h:33
clang::DeclContext::isLookupContext
bool isLookupContext() const
Test whether the context supports looking up names.
Definition: DeclBase.h:1925
LangOptions.h
clang::Decl::getDefiningAttr
const Attr * getDefiningAttr() const
Return this declaration's defining attribute if it has one.
Definition: DeclBase.cpp:506
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7162
clang::Decl::updateOutOfDate
void updateOutOfDate(IdentifierInfo &II) const
Update a potentially out-of-date declaration.
Definition: DeclBase.cpp:63
clang::DeclContext::makeDeclVisibleInContext
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
Definition: DeclBase.cpp:1835
clang::DeclContext::isTransparentContext
bool isTransparentContext() const
isTransparentContext - Determines whether this context is a "transparent" context,...
Definition: DeclBase.cpp:1174
clang::Decl::isInvalidDecl
bool isInvalidDecl() const
Definition: DeclBase.h:558
getRealizedPlatform
static StringRef getRealizedPlatform(const AvailabilityAttr *A, const ASTContext &Context)
Definition: DeclBase.cpp:516
clang::ASTContext::getDeclAttrs
AttrVec & getDeclAttrs(const Decl *D)
Retrieve the attributes for the given declaration.
Definition: ASTContext.cpp:1505
clang::ASTMutationListener
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
Definition: ASTMutationListener.h:46
clang::DeclContext::containsDecl
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1432
clang::TargetInfo::getPlatformMinVersion
VersionTuple getPlatformMinVersion() const
Retrieve the minimum desired version of the platform, to which the program should be compiled.
Definition: TargetInfo.h:1438
clang::Decl::getCanonicalDecl
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:901
clang::Decl::EnableStatistics
static void EnableStatistics()
Definition: DeclBase.cpp:165
clang::DeclContext::decl_iterator
decl_iterator - Iterates through the declarations stored within this context.
Definition: DeclBase.h:2072
IdentifierTable.h
clang::DeclContext::isTranslationUnit
bool isTranslationUnit() const
Definition: DeclBase.h:1935
Type.h
clang::DeclContext::isStdNamespace
bool isStdNamespace() const
Definition: DeclBase.cpp:1126
clang::AttrVec
SmallVector< Attr *, 4 > AttrVec
AttrVec - A vector of Attr, which is how they are stored on the AST.
Definition: AttrIterator.h:29
ASTContext.h
isLinkageSpecContext
static bool isLinkageSpecContext(const DeclContext *DC, LinkageSpecDecl::LanguageIDs ID)
Definition: DeclBase.cpp:1181
clang::DeclContext::DependentDiagnostic
friend class DependentDiagnostic
For CreateStoredDeclsMap.
Definition: DeclBase.h:1354
clang::DeclContext::containsDeclAndLoad
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1437
clang::TagDecl
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3328
clang::TemplateParameterList
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:69
clang::LinkageSpecDecl::LanguageIDs
LanguageIDs
Represents the language in a linkage specification.
Definition: DeclCXX.h:2806
clang::DeclContext::isNamespace
bool isNamespace() const
Definition: DeclBase.h:1944
clang::Decl::redecls
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:972
CheckAvailability
static AvailabilityResult CheckAvailability(ASTContext &Context, const AvailabilityAttr *A, std::string *Message, VersionTuple EnclosingVersion)
Determine the availability of the given declaration based on the target platform.
Definition: DeclBase.cpp:538
clang::DeclContext::getLookupParent
DeclContext * getLookupParent()
Find the parent context of this context that will be used for unqualified name lookup.
Definition: DeclBase.cpp:1093
Label
std::string Label
Definition: UsingDeclarationsSorter.cpp:69
clang::DeclContext::isRecord
bool isRecord() const
Definition: DeclBase.h:1939
clang::BlockPointerType
Pointer to a block type.
Definition: Type.h:2720
getKind
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:998
clang::Decl::castToDeclContext
static DeclContext * castToDeclContext(const Decl *)
Definition: DeclBase.cpp:932
clang::Decl::getOwningModule
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
Definition: DeclBase.h:773
clang::Decl::IDNS_Member
@ IDNS_Member
Members, declared with object declarations within tag definitions.
Definition: DeclBase.h:139
clang::Decl::canBeWeakImported
bool canBeWeakImported(bool &IsDefinition) const
Determines whether this symbol can be weak-imported, e.g., whether it would be well-formed to add the...
Definition: DeclBase.cpp:688
clang::ExternalASTSource::updateOutOfDateIdentifier
virtual void updateOutOfDateIdentifier(IdentifierInfo &II)
Update an out-of-date identifier.
Definition: ExternalASTSource.h:141
clang::Decl::IDNS_OMPMapper
@ IDNS_OMPMapper
This declaration is an OpenMP user defined mapper.
Definition: DeclBase.h:184
clang::Decl::IDNS_Ordinary
@ IDNS_Ordinary
Ordinary names.
Definition: DeclBase.h:147
ExternalASTSource.h
clang::Decl::hasDefiningAttr
bool hasDefiningAttr() const
Return true if this declaration has an attribute which acts as definition of the entity,...
Definition: DeclBase.cpp:501
clang::Decl::castFromDeclContext
static Decl * castFromDeclContext(const DeclContext *)
Definition: DeclBase.cpp:913
clang::Decl::getTranslationUnitDecl
TranslationUnitDecl * getTranslationUnitDecl()
Definition: DeclBase.cpp:399
clang::Type::castAs
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7227
clang::Decl::IDNS_Namespace
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
Definition: DeclBase.h:143
clang::DeclContext::DeclContext
DeclContext(Decl::Kind K)
Definition: DeclBase.cpp:1057
SourceLocation.h
clang::DeclContext::getRedeclContext
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1780
clang::Attr::isInherited
bool isInherited() const
Definition: Attr.h:95
clang::DeclContext::DeclContextBits
DeclContextBitfields DeclContextBits
Definition: DeclBase.h:1796
clang::Decl::getFriendObjectKind
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition: DeclBase.h:1143
clang::Decl::hasAttrs
bool hasAttrs() const
Definition: DeclBase.h:489
clang::Decl::isFromASTFile
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:716
clang::DeclContext::getDeclKindName
const char * getDeclKindName() const
Definition: DeclBase.cpp:155
clang::Decl::IDNS_Label
@ IDNS_Label
Labels, declared with 'x:' and referenced with 'goto x'.
Definition: DeclBase.h:120
clang::TagDecl::isBeingDefined
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3453
clang::DeclContext::udir_iterator::operator*
UsingDirectiveDecl * operator*() const
Definition: DeclBase.cpp:1926
clang::DeclContext::addDecl
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1559
clang::Decl::Access
unsigned Access
Access - Used by C++ decls for the access specifier.
Definition: DeclBase.h:326
clang::Decl::getDescribedTemplate
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
Definition: DeclBase.cpp:230
clang::DeclContext::getParent
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1860
clang::Decl::IDNS_OMPReduction
@ IDNS_OMPReduction
This declaration is an OpenMP user defined reduction construction.
Definition: DeclBase.h:181
clang::DeclContext::~DeclContext
~DeclContext()
clang::TemplateDecl
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:399
llvm::ArrayRef
Definition: LLVM.h:34
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
clang::Decl::isTemplated
bool isTemplated() const
Determine whether this declaration is a templated entity (whether it is.
Definition: DeclBase.cpp:253
clang::Decl::getTemplateDepth
unsigned getTemplateDepth() const
Determine the number of levels of template parameter surrounding this declaration.
Definition: DeclBase.cpp:265
clang::LinkageSpecDecl::lang_cxx
@ lang_cxx
Definition: DeclCXX.h:2806
ASTMutationListener.h
clang::Decl::IDNS_ObjCProtocol
@ IDNS_ObjCProtocol
Objective C @protocol.
Definition: DeclBase.h:150
clang::DeclContext::getOuterLexicalRecordContext
RecordDecl * getOuterLexicalRecordContext()
Retrieve the outermost lexically enclosing record context.
Definition: DeclBase.cpp:1806
LLVM.h
clang::DeclContext::isExternCXXContext
bool isExternCXXContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
Definition: DeclBase.cpp:1206
clang::DeclContextLookupResult::end
iterator end()
Definition: DeclBase.h:1307
clang::DeclContext::lookup_result
DeclContextLookupResult lookup_result
Definition: DeclBase.h:2319
clang::Decl::getExternalSourceSymbolAttr
ExternalSourceSymbolAttr * getExternalSourceSymbolAttr() const
Looks on this and related declarations for an applicable external source symbol attribute.
Definition: DeclBase.cpp:480
clang::Decl::attrs
attr_range attrs() const
Definition: DeclBase.h:506
clang::DeclContext::Encloses
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context encloses the declaration context DC.
Definition: DeclBase.cpp:1210
clang::DeclContext::isFileContext
bool isFileContext() const
Definition: DeclBase.h:1930
clang::DeclContext::noload_lookup
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don't attempt to retr...
Definition: DeclBase.cpp:1710
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:67
clang::ObjCRuntime
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:28
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:740
clang::PartialDiagnostic
Definition: PartialDiagnostic.h:34
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::DeclContext::getInnermostBlockDecl
const BlockDecl * getInnermostBlockDecl() const
Return this DeclContext if it is a BlockDecl.
Definition: DeclBase.cpp:1109
clang::DeclContext::collectAllContexts
void collectAllContexts(SmallVectorImpl< DeclContext * > &Contexts)
Collects all of the declaration contexts that are semantically connected to this declaration context.
Definition: DeclBase.cpp:1306
clang::Decl::getBody
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition: DeclBase.h:1010
clang::Decl::hasOwningModule
bool hasOwningModule() const
Is this declaration owned by some module?
Definition: DeclBase.h:768
clang::ExternalASTSource::SetNoExternalVisibleDeclsForName
static DeclContextLookupResult SetNoExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name)
Definition: DeclBase.cpp:1389
clang::TranslationUnitDecl::getASTContext
ASTContext & getASTContext() const
Definition: Decl.h:120
clang::PointerType
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2640
clang::PrettyStackTraceDecl::print
void print(raw_ostream &OS) const override
Definition: DeclBase.cpp:300
DependentDiagnostic.h
clang::DependentDiagnostic
A dependently-generated diagnostic.
Definition: DependentDiagnostic.h:36
clang::Decl::~Decl
virtual ~Decl()
clang::AR_NotYetIntroduced
@ AR_NotYetIntroduced
Definition: DeclBase.h:77
clang::Decl::isParameterPack
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:211
clang::Builtin::ID
ID
Definition: Builtins.h:48
clang::SourceLocation::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:113
clang::ASTContext::addedLocalImportDecl
void addedLocalImportDecl(ImportDecl *Import)
Notify the AST context that a new import declaration has been parsed or implicitly created within thi...
Definition: ASTContext.cpp:1685
PartialDiagnostic.h
clang::AR_Unavailable
@ AR_Unavailable
Definition: DeclBase.h:79
clang::StoredDeclsList::prependDeclNoReplace
void prependDeclNoReplace(NamedDecl *D)
Add a declaration to the list without checking if it replaces anything.
Definition: DeclContextInternals.h:266
clang
Definition: CalledOnceCheck.h:17
clang::DeclContext::lookup
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1645
clang::DeclContext::buildLookup
StoredDeclsMap * buildLookup()
Ensure the lookup structure is fully-built and return it.
Definition: DeclBase.cpp:1582
clang::DeclaratorContext::Block
@ Block
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:68
clang::AvailabilityResult
AvailabilityResult
Captures the result of checking the availability of a declaration.
Definition: DeclBase.h:75
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:112
clang::Attr
Attr - This represents one attribute.
Definition: Attr.h:46
clang::NamedDecl::getDeclName
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:313
clang::DeclContext::udir_range
llvm::iterator_range< udir_iterator > udir_range
Definition: DeclBase.h:2396
clang::TargetInfo::getPlatformName
StringRef getPlatformName() const
Retrieve the name of the platform as it is used in the availability attribute.
Definition: TargetInfo.h:1434
clang::DeclContext::isDependentContext
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1142
clang::LangOptions::trackLocalOwningModule
bool trackLocalOwningModule() const
Do we need to track the owning module for a local declaration?
Definition: LangOptions.h:397
clang::Decl::getAttrs
AttrVec & getAttrs()
Definition: DeclBase.h:495
clang::Decl::hasLocalOwningModuleStorage
bool hasLocalOwningModuleStorage() const
Definition: DeclBase.cpp:119
clang::DeclContextLookupResult
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1292
clang::Decl::getOwningModuleID
unsigned getOwningModuleID() const
Retrieve the global ID of the module that owns this particular declaration.
Definition: DeclBase.h:728
clang::ExternalASTSource::Deserializing
RAII class for safely pairing a StartedDeserializing call with FinishedDeserializing.
Definition: ExternalASTSource.h:76
Parent
NodeId Parent
Definition: ASTDiff.cpp:192
clang::ReferenceType
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:2751
clang::DeclContext::isExternCContext
bool isExternCContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
Definition: DeclBase.cpp:1191
clang::Decl::getDescribedTemplateParams
const TemplateParameterList * getDescribedTemplateParams() const
If this is a declaration that describes some template or partial specialization, this returns the cor...
Definition: DeclBase.cpp:243
clang::Decl::setInvalidDecl
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition: DeclBase.cpp:132
Stmt.h
llvm::SmallVectorImpl
Definition: LLVM.h:39
clang::Type::isFunctionReferenceType
bool isFunctionReferenceType() const
Definition: Type.h:6714
clang::DeclContext::LastDecl
Decl * LastDecl
LastDecl - The last declaration stored within this declaration context.
Definition: DeclBase.h:1840
clang::Decl::getVersionIntroduced
VersionTuple getVersionIntroduced() const
Retrieve the version of the target platform in which this declaration was introduced.
Definition: DeclBase.cpp:674
clang::Decl::dropAttrs
void dropAttrs()
Definition: DeclBase.cpp:878
clang::ExternalASTSource
Abstract interface for external sources of AST nodes.
Definition: ExternalASTSource.h:60
clang::DeclContext::isFunctionOrMethod
bool isFunctionOrMethod() const
Definition: DeclBase.h:1912
clang::Decl::isInLocalScopeForInstantiation
bool isInLocalScopeForInstantiation() const
Determine whether a substitution into this declaration would occur as part of a substitution into a d...
Definition: DeclBase.cpp:367
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:430
clang::Decl::getMaxAlignment
unsigned getMaxAlignment() const
getMaxAlignment - return the maximum alignment specified by attributes on this decl,...
Definition: DeclBase.cpp:428
clang::Decl::getID
int64_t getID() const
Definition: DeclBase.cpp:1001
clang::Decl::addAttr
void addAttr(Attr *A)
Definition: DeclBase.cpp:885
clang::Decl::IDNS_Tag
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition: DeclBase.h:128
clang::NamespaceDecl
Represent a C++ namespace.
Definition: Decl.h:542
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1856
DeclContextInternals.h
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3859
clang::DeclContext::Equals
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
Definition: DeclBase.h:1984
clang::StoredDeclsList::addOrReplaceDecl
void addOrReplaceDecl(NamedDecl *D)
If this is a redeclaration of an existing decl, replace the old one with D.
Definition: DeclContextInternals.h:216
clang::Decl::setLocalOwningModule
void setLocalOwningModule(Module *M)
Definition: DeclBase.h:760
clang::ExternalASTSource::SetExternalVisibleDeclsForName
static DeclContextLookupResult SetExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name, ArrayRef< NamedDecl * > Decls)
Definition: DeclBase.cpp:1404
clang::ASTContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: ASTContext.h:757
clang::ASTContext::getAllocator
llvm::BumpPtrAllocator & getAllocator() const
Definition: ASTContext.h:697
clang::specific_attr_iterator
specific_attr_iterator - Iterates over a subrange of an AttrVec, only providing attributes that are o...
Definition: AttrIterator.h:34
clang::Decl::getMostRecentDecl
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
Definition: DeclBase.h:999
getNonClosureContext
static Decl * getNonClosureContext(T *D)
Starting at a given context (a Decl or DeclContext), look for a code context that is not a closure (a...
Definition: DeclBase.cpp:1026
clang::Decl::getDeclKindName
const char * getDeclKindName() const
Definition: DeclBase.cpp:123
clang::Decl::isInAnonymousNamespace
bool isInAnonymousNamespace() const
Definition: DeclBase.cpp:384
collectAllContextsImpl
void collectAllContextsImpl(T *Self, SmallVectorImpl< DeclContext * > &Contexts)
Definition: DeclBase.cpp:1299
clang::Decl::getDeclContext
DeclContext * getDeclContext()
Definition: DeclBase.h:439
clang::DeclContext::decls_begin
decl_iterator decls_begin() const
Definition: DeclBase.cpp:1419