diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2016-08-16 21:17:51 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2016-08-16 21:17:51 +0000 | 
| commit | e7145dcb9f6563389ebbfa0572ef7589bdd94b1b (patch) | |
| tree | b1b30c4998f6e9769784be87d402e4f8db13e34d /contrib/llvm/tools/clang/lib/AST/DeclBase.cpp | |
| parent | 3ca95b020283db6244cab92ede73c969253b6a31 (diff) | |
| parent | 7fd6ba58d980ec2bf312a80444948501dd27d020 (diff) | |
Notes
Diffstat (limited to 'contrib/llvm/tools/clang/lib/AST/DeclBase.cpp')
| -rw-r--r-- | contrib/llvm/tools/clang/lib/AST/DeclBase.cpp | 68 | 
1 files changed, 55 insertions, 13 deletions
diff --git a/contrib/llvm/tools/clang/lib/AST/DeclBase.cpp b/contrib/llvm/tools/clang/lib/AST/DeclBase.cpp index 72587e388e47..bfb7d02b2955 100644 --- a/contrib/llvm/tools/clang/lib/AST/DeclBase.cpp +++ b/contrib/llvm/tools/clang/lib/AST/DeclBase.cpp @@ -46,7 +46,7 @@ void Decl::updateOutOfDate(IdentifierInfo &II) const {  }  #define DECL(DERIVED, BASE)                                                    \ -  static_assert(Decl::DeclObjAlignment >=                                      \ +  static_assert(llvm::AlignOf<Decl>::Alignment >=                              \                      llvm::AlignOf<DERIVED##Decl>::Alignment,                   \                  "Alignment sufficient after objects prepended to " #DERIVED);  #define ABSTRACT_DECL(DECL) @@ -56,7 +56,7 @@ void *Decl::operator new(std::size_t Size, const ASTContext &Context,                           unsigned ID, std::size_t Extra) {    // Allocate an extra 8 bytes worth of storage, which ensures that the    // resulting pointer will still be 8-byte aligned. -  static_assert(sizeof(unsigned) * 2 >= DeclObjAlignment, +  static_assert(sizeof(unsigned) * 2 >= llvm::AlignOf<Decl>::Alignment,                  "Decl won't be misaligned");    void *Start = Context.Allocate(Size + Extra + 8);    void *Result = (char*)Start + 8; @@ -81,7 +81,8 @@ void *Decl::operator new(std::size_t Size, const ASTContext &Ctx,      // Ensure required alignment of the resulting object by adding extra      // padding at the start if required.      size_t ExtraAlign = -        llvm::OffsetToAlignment(sizeof(Module *), DeclObjAlignment); +        llvm::OffsetToAlignment(sizeof(Module *), +                                llvm::AlignOf<Decl>::Alignment);      char *Buffer = reinterpret_cast<char *>(          ::operator new(ExtraAlign + sizeof(Module *) + Size + Extra, Ctx));      Buffer += ExtraAlign; @@ -196,6 +197,17 @@ bool Decl::isTemplateDecl() const {    return isa<TemplateDecl>(this);  } +TemplateDecl *Decl::getDescribedTemplate() const { +  if (auto *FD = dyn_cast<FunctionDecl>(this)) +    return FD->getDescribedFunctionTemplate(); +  else if (auto *RD = dyn_cast<CXXRecordDecl>(this)) +    return RD->getDescribedClassTemplate(); +  else if (auto *VD = dyn_cast<VarDecl>(this)) +    return VD->getDescribedVarTemplate(); + +  return nullptr; +} +  const DeclContext *Decl::getParentFunctionOrMethod() const {    for (const DeclContext *DC = getDeclContext();         DC && !DC->isTranslationUnit() && !DC->isNamespace();  @@ -329,25 +341,29 @@ unsigned Decl::getMaxAlignment() const {    return Align;  } -bool Decl::isUsed(bool CheckUsedAttr) const {  -  if (Used) +bool Decl::isUsed(bool CheckUsedAttr) const { +  const Decl *CanonD = getCanonicalDecl(); +  if (CanonD->Used)      return true; -   +    // Check for used attribute. -  if (CheckUsedAttr && hasAttr<UsedAttr>()) +  // Ask the most recent decl, since attributes accumulate in the redecl chain. +  if (CheckUsedAttr && getMostRecentDecl()->hasAttr<UsedAttr>())      return true; -  return false;  +  // The information may have not been deserialized yet. Force deserialization +  // to complete the needed information. +  return getMostRecentDecl()->getCanonicalDecl()->Used;  }  void Decl::markUsed(ASTContext &C) { -  if (Used) +  if (isUsed(false))      return;    if (C.getASTMutationListener())      C.getASTMutationListener()->DeclarationMarkedUsed(this); -  Used = true; +  setIsUsed();  }  bool Decl::isReferenced() const {  @@ -362,6 +378,18 @@ bool Decl::isReferenced() const {    return false;   } +bool Decl::hasDefiningAttr() const { +  return hasAttr<AliasAttr>() || hasAttr<IFuncAttr>(); +} + +const Attr *Decl::getDefiningAttr() const { +  if (AliasAttr *AA = getAttr<AliasAttr>()) +    return AA; +  if (IFuncAttr *IFA = getAttr<IFuncAttr>()) +    return IFA; +  return nullptr; +} +  /// \brief Determine the availability of the given declaration based on  /// the target platform.  /// @@ -432,7 +460,7 @@ static AvailabilityResult CheckAvailability(ASTContext &Context,            << VTI << HintMessage;      } -    return AR_NotYetIntroduced; +    return A->getStrict() ? AR_Unavailable : AR_NotYetIntroduced;    }    // Make sure that this declaration hasn't been obsoleted. @@ -467,6 +495,9 @@ static AvailabilityResult CheckAvailability(ASTContext &Context,  }  AvailabilityResult Decl::getAvailability(std::string *Message) const { +  if (auto *FTD = dyn_cast<FunctionTemplateDecl>(this)) +    return FTD->getTemplatedDecl()->getAvailability(Message); +    AvailabilityResult Result = AR_Available;    std::string ResultMessage; @@ -563,6 +594,7 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {      case Function:      case CXXMethod:      case CXXConstructor: +    case ConstructorUsingShadow:      case CXXDestructor:      case CXXConversion:      case EnumConstant: @@ -630,6 +662,9 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {      case TemplateTemplateParm:        return IDNS_Ordinary | IDNS_Tag | IDNS_Type; +    case OMPDeclareReduction: +      return IDNS_OMPReduction; +      // Never have names.      case Friend:      case FriendTemplate: @@ -638,6 +673,8 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {      case FileScopeAsm:      case StaticAssert:      case ObjCPropertyImpl: +    case PragmaComment: +    case PragmaDetectMismatch:      case Block:      case Captured:      case TranslationUnit: @@ -655,6 +692,7 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {      case ObjCCategoryImpl:      case Import:      case OMPThreadPrivate: +    case OMPCapturedExpr:      case Empty:        // Never looked up by name.        return 0; @@ -957,6 +995,7 @@ DeclContext *DeclContext::getPrimaryContext() {    case Decl::LinkageSpec:    case Decl::Block:    case Decl::Captured: +  case Decl::OMPDeclareReduction:      // There is only one DeclContext for these entities.      return this; @@ -1549,9 +1588,12 @@ void DeclContext::makeDeclVisibleInContextWithFlags(NamedDecl *D, bool Internal,                                                      bool Recoverable) {    assert(this == getPrimaryContext() && "expected a primary DC"); -  // Skip declarations within functions. -  if (isFunctionOrMethod()) +  if (!isLookupContext()) { +    if (isTransparentContext()) +      getParent()->getPrimaryContext() +        ->makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);      return; +  }    // Skip declarations which should be invisible to name lookup.    if (shouldBeHidden(D))  | 
