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