2017-11-08 08:39:18 +08:00
|
|
|
//===- DeclBase.cpp - Declaration AST Node Implementation -----------------===//
|
2008-06-08 00:52:53 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2008-06-08 00:52:53 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the Decl and DeclContext classes.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/DeclBase.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2019-09-05 09:23:47 +08:00
|
|
|
#include "clang/AST/ASTLambda.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/AST/ASTMutationListener.h"
|
|
|
|
#include "clang/AST/Attr.h"
|
2017-11-08 08:39:18 +08:00
|
|
|
#include "clang/AST/AttrIterator.h"
|
2009-02-03 07:39:07 +08:00
|
|
|
#include "clang/AST/Decl.h"
|
2008-06-10 05:05:31 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/AST/DeclContextInternals.h"
|
2010-03-11 15:50:04 +08:00
|
|
|
#include "clang/AST/DeclFriend.h"
|
2009-02-05 03:02:06 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2013-03-22 14:34:35 +08:00
|
|
|
#include "clang/AST/DeclOpenMP.h"
|
2009-02-05 03:02:06 +08:00
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2010-03-24 13:22:00 +08:00
|
|
|
#include "clang/AST/DependentDiagnostic.h"
|
2012-12-01 23:09:41 +08:00
|
|
|
#include "clang/AST/ExternalASTSource.h"
|
2009-04-27 04:35:05 +08:00
|
|
|
#include "clang/AST/Stmt.h"
|
2012-12-01 23:09:41 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2017-11-08 08:39:18 +08:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
|
|
|
#include "clang/Basic/LLVM.h"
|
|
|
|
#include "clang/Basic/LangOptions.h"
|
|
|
|
#include "clang/Basic/ObjCRuntime.h"
|
|
|
|
#include "clang/Basic/PartialDiagnostic.h"
|
|
|
|
#include "clang/Basic/SourceLocation.h"
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2017-11-08 08:39:18 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/ADT/PointerIntPair.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
2018-06-11 18:28:04 +08:00
|
|
|
#include "llvm/Support/VersionTuple.h"
|
2009-03-05 16:00:35 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-12-24 05:05:05 +08:00
|
|
|
#include <algorithm>
|
2017-11-08 08:39:18 +08:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <string>
|
|
|
|
#include <tuple>
|
|
|
|
#include <utility>
|
|
|
|
|
2008-06-08 00:52:53 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Statistics
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-05-30 15:21:58 +08:00
|
|
|
#define DECL(DERIVED, BASE) static int n##DERIVED##s = 0;
|
|
|
|
#define ABSTRACT_DECL(DECL)
|
|
|
|
#include "clang/AST/DeclNodes.inc"
|
2008-06-08 00:52:53 +08:00
|
|
|
|
Ensure that type definitions present in just-loaded modules are
visible.
The basic problem here is that a given translation unit can use
forward declarations to form pointers to a given type, say,
class X;
X *x;
and then import a module that includes a definition of X:
import XDef;
We will then fail when attempting to access a member of X, e.g.,
x->method()
because the AST reader did not know to look for a default of a class
named X within the new module.
This implementation is a bit of a C-centric hack, because the only
definitions that can have this property are enums, structs, unions,
Objective-C classes, and Objective-C protocols, and all of those are
either visible at the top-level or can't be defined later. Hence, we
can use the out-of-date-ness of the name and the identifier-update
mechanism to force the update.
In C++, we will not be so lucky, and will need a more advanced
solution, because the definitions could be in namespaces defined in
two different modules, e.g.,
// module 1
namespace N { struct X; }
// module 2
namespace N { struct X { /* ... */ }; }
One possible implementation here is for C++ to extend the information
associated with each identifier table to include the declaration IDs
of any definitions associated with that name, regardless of
context. We would have to eagerly load those definitions.
llvm-svn: 174794
2013-02-09 09:35:03 +08:00
|
|
|
void Decl::updateOutOfDate(IdentifierInfo &II) const {
|
|
|
|
getASTContext().getExternalSource()->updateOutOfDateIdentifier(II);
|
|
|
|
}
|
|
|
|
|
2015-07-18 02:21:37 +08:00
|
|
|
#define DECL(DERIVED, BASE) \
|
2016-10-20 22:27:22 +08:00
|
|
|
static_assert(alignof(Decl) >= alignof(DERIVED##Decl), \
|
2015-07-18 02:21:37 +08:00
|
|
|
"Alignment sufficient after objects prepended to " #DERIVED);
|
|
|
|
#define ABSTRACT_DECL(DECL)
|
|
|
|
#include "clang/AST/DeclNodes.inc"
|
|
|
|
|
2013-11-22 17:01:48 +08:00
|
|
|
void *Decl::operator new(std::size_t Size, const ASTContext &Context,
|
|
|
|
unsigned ID, std::size_t Extra) {
|
2012-01-06 07:49:36 +08:00
|
|
|
// Allocate an extra 8 bytes worth of storage, which ensures that the
|
2015-07-18 02:21:37 +08:00
|
|
|
// resulting pointer will still be 8-byte aligned.
|
2016-10-20 22:27:22 +08:00
|
|
|
static_assert(sizeof(unsigned) * 2 >= alignof(Decl),
|
2015-07-18 02:21:37 +08:00
|
|
|
"Decl won't be misaligned");
|
2013-11-22 17:01:48 +08:00
|
|
|
void *Start = Context.Allocate(Size + Extra + 8);
|
2012-01-06 07:49:36 +08:00
|
|
|
void *Result = (char*)Start + 8;
|
2013-11-22 17:01:48 +08:00
|
|
|
|
2012-01-10 01:30:44 +08:00
|
|
|
unsigned *PrefixPtr = (unsigned *)Result - 2;
|
2013-11-22 17:01:48 +08:00
|
|
|
|
2012-01-10 01:30:44 +08:00
|
|
|
// Zero out the first 4 bytes; this is used to store the owning module ID.
|
|
|
|
PrefixPtr[0] = 0;
|
2013-11-22 17:01:48 +08:00
|
|
|
|
2012-01-10 01:30:44 +08:00
|
|
|
// Store the global declaration ID in the second 4 bytes.
|
|
|
|
PrefixPtr[1] = ID;
|
2013-11-22 17:01:48 +08:00
|
|
|
|
2012-01-06 06:27:05 +08:00
|
|
|
return Result;
|
2012-01-06 05:55:30 +08:00
|
|
|
}
|
|
|
|
|
2013-11-22 17:01:48 +08:00
|
|
|
void *Decl::operator new(std::size_t Size, const ASTContext &Ctx,
|
|
|
|
DeclContext *Parent, std::size_t Extra) {
|
|
|
|
assert(!Parent || &Parent->getParentASTContext() == &Ctx);
|
2015-05-16 04:05:43 +08:00
|
|
|
// With local visibility enabled, we track the owning module even for local
|
2017-09-05 08:50:19 +08:00
|
|
|
// declarations. We create the TU decl early and may not yet know what the
|
|
|
|
// LangOpts are, so conservatively allocate the storage.
|
|
|
|
if (Ctx.getLangOpts().trackLocalOwningModule() || !Parent) {
|
2015-07-18 02:21:37 +08:00
|
|
|
// Ensure required alignment of the resulting object by adding extra
|
|
|
|
// padding at the start if required.
|
|
|
|
size_t ExtraAlign =
|
[Alignment] Move OffsetToAlignment to Alignment.h
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790
Reviewers: courbet, JDevlieghere, alexshap, rupprecht, jhenderson
Subscribers: sdardis, nemanjai, hiraditya, kbarton, jakehehrlich, jrtc27, MaskRay, atanasyan, jsji, seiya, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D67499
llvm-svn: 371742
2019-09-12 23:20:36 +08:00
|
|
|
llvm::offsetToAlignment(sizeof(Module *), llvm::Align(alignof(Decl)));
|
2018-04-10 06:14:10 +08:00
|
|
|
auto *Buffer = reinterpret_cast<char *>(
|
2015-07-18 02:21:37 +08:00
|
|
|
::operator new(ExtraAlign + sizeof(Module *) + Size + Extra, Ctx));
|
|
|
|
Buffer += ExtraAlign;
|
2017-05-17 08:24:14 +08:00
|
|
|
auto *ParentModule =
|
|
|
|
Parent ? cast<Decl>(Parent)->getOwningModule() : nullptr;
|
|
|
|
return new (Buffer) Module*(ParentModule) + 1;
|
2015-05-16 04:05:43 +08:00
|
|
|
}
|
2013-11-22 17:01:48 +08:00
|
|
|
return ::operator new(Size + Extra, Ctx);
|
|
|
|
}
|
|
|
|
|
2013-01-12 09:29:50 +08:00
|
|
|
Module *Decl::getOwningModuleSlow() const {
|
|
|
|
assert(isFromASTFile() && "Not from AST file?");
|
|
|
|
return getASTContext().getExternalSource()->getModule(getOwningModuleID());
|
|
|
|
}
|
|
|
|
|
2015-06-09 08:35:49 +08:00
|
|
|
bool Decl::hasLocalOwningModuleStorage() const {
|
2017-05-17 08:24:14 +08:00
|
|
|
return getASTContext().getLangOpts().trackLocalOwningModule();
|
2015-06-09 08:35:49 +08:00
|
|
|
}
|
|
|
|
|
2008-06-08 00:52:53 +08:00
|
|
|
const char *Decl::getDeclKindName() const {
|
|
|
|
switch (DeclKind) {
|
2011-09-23 13:06:16 +08:00
|
|
|
default: llvm_unreachable("Declaration not in DeclNodes.inc!");
|
2010-05-30 15:21:58 +08:00
|
|
|
#define DECL(DERIVED, BASE) case DERIVED: return #DERIVED;
|
|
|
|
#define ABSTRACT_DECL(DECL)
|
|
|
|
#include "clang/AST/DeclNodes.inc"
|
2008-06-08 00:52:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-05 08:26:45 +08:00
|
|
|
void Decl::setInvalidDecl(bool Invalid) {
|
|
|
|
InvalidDecl = Invalid;
|
2013-12-21 09:10:54 +08:00
|
|
|
assert(!isa<TagDecl>(this) || !cast<TagDecl>(this)->isCompleteDefinition());
|
2016-11-12 04:51:04 +08:00
|
|
|
if (!Invalid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isa<ParmVarDecl>(this)) {
|
2010-03-05 08:26:45 +08:00
|
|
|
// Defensive maneuver for ill-formed code: we're likely not to make it to
|
|
|
|
// a point where we set the access specifier, so default it to "public"
|
2018-07-31 03:24:48 +08:00
|
|
|
// to avoid triggering asserts elsewhere in the front end.
|
2010-03-05 08:26:45 +08:00
|
|
|
setAccess(AS_public);
|
|
|
|
}
|
2016-11-12 04:51:04 +08:00
|
|
|
|
|
|
|
// Marking a DecompositionDecl as invalid implies all the child BindingDecl's
|
|
|
|
// are invalid too.
|
2018-04-10 06:14:10 +08:00
|
|
|
if (auto *DD = dyn_cast<DecompositionDecl>(this)) {
|
|
|
|
for (auto *Binding : DD->bindings()) {
|
2016-11-12 04:51:04 +08:00
|
|
|
Binding->setInvalidDecl();
|
|
|
|
}
|
|
|
|
}
|
2010-03-05 08:26:45 +08:00
|
|
|
}
|
|
|
|
|
2009-01-21 03:53:53 +08:00
|
|
|
const char *DeclContext::getDeclKindName() const {
|
2018-08-02 04:48:16 +08:00
|
|
|
switch (getDeclKind()) {
|
2010-05-30 15:21:58 +08:00
|
|
|
#define DECL(DERIVED, BASE) case Decl::DERIVED: return #DERIVED;
|
|
|
|
#define ABSTRACT_DECL(DECL)
|
|
|
|
#include "clang/AST/DeclNodes.inc"
|
2009-01-21 03:53:53 +08:00
|
|
|
}
|
2018-08-02 06:10:03 +08:00
|
|
|
llvm_unreachable("Declaration context not in DeclNodes.inc!");
|
2009-01-21 03:53:53 +08:00
|
|
|
}
|
|
|
|
|
2012-03-06 05:42:49 +08:00
|
|
|
bool Decl::StatisticsEnabled = false;
|
|
|
|
void Decl::EnableStatistics() {
|
|
|
|
StatisticsEnabled = true;
|
2008-06-08 00:52:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Decl::PrintStats() {
|
2011-07-04 14:13:27 +08:00
|
|
|
llvm::errs() << "\n*** Decl Stats:\n";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-03 07:39:07 +08:00
|
|
|
int totalDecls = 0;
|
2010-05-30 15:21:58 +08:00
|
|
|
#define DECL(DERIVED, BASE) totalDecls += n##DERIVED##s;
|
|
|
|
#define ABSTRACT_DECL(DECL)
|
|
|
|
#include "clang/AST/DeclNodes.inc"
|
2011-07-04 14:13:27 +08:00
|
|
|
llvm::errs() << " " << totalDecls << " decls total.\n";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-03 07:39:07 +08:00
|
|
|
int totalBytes = 0;
|
2010-05-30 15:21:58 +08:00
|
|
|
#define DECL(DERIVED, BASE) \
|
|
|
|
if (n##DERIVED##s > 0) { \
|
|
|
|
totalBytes += (int)(n##DERIVED##s * sizeof(DERIVED##Decl)); \
|
2011-07-04 14:13:27 +08:00
|
|
|
llvm::errs() << " " << n##DERIVED##s << " " #DERIVED " decls, " \
|
|
|
|
<< sizeof(DERIVED##Decl) << " each (" \
|
|
|
|
<< n##DERIVED##s * sizeof(DERIVED##Decl) \
|
|
|
|
<< " bytes)\n"; \
|
2009-02-03 07:39:07 +08:00
|
|
|
}
|
2010-05-30 15:21:58 +08:00
|
|
|
#define ABSTRACT_DECL(DECL)
|
|
|
|
#include "clang/AST/DeclNodes.inc"
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-07-04 14:13:27 +08:00
|
|
|
llvm::errs() << "Total bytes = " << totalBytes << "\n";
|
2008-06-08 00:52:53 +08:00
|
|
|
}
|
|
|
|
|
2010-05-30 15:21:58 +08:00
|
|
|
void Decl::add(Kind k) {
|
2008-06-08 00:52:53 +08:00
|
|
|
switch (k) {
|
2010-05-30 15:21:58 +08:00
|
|
|
#define DECL(DERIVED, BASE) case DERIVED: ++n##DERIVED##s; break;
|
|
|
|
#define ABSTRACT_DECL(DECL)
|
|
|
|
#include "clang/AST/DeclNodes.inc"
|
2008-06-08 00:52:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-13 08:08:58 +08:00
|
|
|
bool Decl::isTemplateParameterPack() const {
|
2018-04-10 06:14:10 +08:00
|
|
|
if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(this))
|
2009-06-13 08:08:58 +08:00
|
|
|
return TTP->isParameterPack();
|
2018-04-10 06:14:10 +08:00
|
|
|
if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(this))
|
2010-12-24 07:51:58 +08:00
|
|
|
return NTTP->isParameterPack();
|
2018-04-10 06:14:10 +08:00
|
|
|
if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(this))
|
2011-01-05 23:48:55 +08:00
|
|
|
return TTP->isParameterPack();
|
2009-06-13 08:08:58 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-06 05:11:38 +08:00
|
|
|
bool Decl::isParameterPack() const {
|
2019-05-22 04:10:50 +08:00
|
|
|
if (const auto *Var = dyn_cast<VarDecl>(this))
|
|
|
|
return Var->isParameterPack();
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-01-06 05:11:38 +08:00
|
|
|
return isTemplateParameterPack();
|
|
|
|
}
|
|
|
|
|
2014-01-22 15:29:52 +08:00
|
|
|
FunctionDecl *Decl::getAsFunction() {
|
2018-04-10 06:14:10 +08:00
|
|
|
if (auto *FD = dyn_cast<FunctionDecl>(this))
|
2014-01-22 15:29:52 +08:00
|
|
|
return FD;
|
2018-04-10 06:14:10 +08:00
|
|
|
if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(this))
|
2014-01-22 15:29:52 +08:00
|
|
|
return FTD->getTemplatedDecl();
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2009-06-26 06:08:12 +08:00
|
|
|
}
|
|
|
|
|
2011-09-09 01:42:31 +08:00
|
|
|
bool Decl::isTemplateDecl() const {
|
|
|
|
return isa<TemplateDecl>(this);
|
|
|
|
}
|
|
|
|
|
2016-04-19 14:19:52 +08:00
|
|
|
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();
|
2018-02-01 08:28:36 +08:00
|
|
|
else if (auto *AD = dyn_cast<TypeAliasDecl>(this))
|
|
|
|
return AD->getDescribedAliasTemplate();
|
2016-04-19 14:19:52 +08:00
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-02-01 08:28:36 +08:00
|
|
|
bool Decl::isTemplated() const {
|
|
|
|
// A declaration is dependent if it is a template or a template pattern, or
|
|
|
|
// is within (lexcially for a friend, semantically otherwise) a dependent
|
|
|
|
// context.
|
|
|
|
// FIXME: Should local extern declarations be treated like friends?
|
|
|
|
if (auto *AsDC = dyn_cast<DeclContext>(this))
|
|
|
|
return AsDC->isDependentContext();
|
|
|
|
auto *DC = getFriendObjectKind() ? getLexicalDeclContext() : getDeclContext();
|
|
|
|
return DC->isDependentContext() || isTemplateDecl() || getDescribedTemplate();
|
|
|
|
}
|
|
|
|
|
2011-09-28 10:45:33 +08:00
|
|
|
const DeclContext *Decl::getParentFunctionOrMethod() const {
|
|
|
|
for (const DeclContext *DC = getDeclContext();
|
2018-07-31 03:24:48 +08:00
|
|
|
DC && !DC->isTranslationUnit() && !DC->isNamespace();
|
2010-01-17 04:21:20 +08:00
|
|
|
DC = DC->getParent())
|
|
|
|
if (DC->isFunctionOrMethod())
|
2011-09-28 10:45:33 +08:00
|
|
|
return DC;
|
2010-01-17 04:21:20 +08:00
|
|
|
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2010-01-17 04:21:20 +08:00
|
|
|
}
|
|
|
|
|
2009-03-05 16:00:35 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PrettyStackTraceDecl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
void PrettyStackTraceDecl::print(raw_ostream &OS) const {
|
2009-03-05 16:00:35 +08:00
|
|
|
SourceLocation TheLoc = Loc;
|
|
|
|
if (TheLoc.isInvalid() && TheDecl)
|
|
|
|
TheLoc = TheDecl->getLocation();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-05 16:00:35 +08:00
|
|
|
if (TheLoc.isValid()) {
|
|
|
|
TheLoc.print(OS, SM);
|
|
|
|
OS << ": ";
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << Message;
|
|
|
|
|
2018-04-10 06:14:10 +08:00
|
|
|
if (const auto *DN = dyn_cast_or_null<NamedDecl>(TheDecl)) {
|
2013-02-23 21:53:57 +08:00
|
|
|
OS << " '";
|
|
|
|
DN->printQualifiedName(OS);
|
|
|
|
OS << '\'';
|
|
|
|
}
|
2009-03-05 16:00:35 +08:00
|
|
|
OS << '\n';
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-06-08 00:52:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Decl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-02-20 02:51:44 +08:00
|
|
|
// Out-of-line virtual method providing a home for Decl.
|
2017-11-08 08:39:18 +08:00
|
|
|
Decl::~Decl() = default;
|
2011-02-17 15:02:32 +08:00
|
|
|
|
2009-01-20 09:17:11 +08:00
|
|
|
void Decl::setDeclContext(DeclContext *DC) {
|
2009-03-29 14:06:59 +08:00
|
|
|
DeclCtx = DC;
|
2009-01-20 09:17:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Decl::setLexicalDeclContext(DeclContext *DC) {
|
|
|
|
if (DC == getLexicalDeclContext())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (isInSemaDC()) {
|
2012-02-09 10:44:08 +08:00
|
|
|
setDeclContextsImpl(getDeclContext(), DC, getASTContext());
|
2009-01-20 09:17:11 +08:00
|
|
|
} else {
|
|
|
|
getMultipleDC()->LexicalDC = DC;
|
|
|
|
}
|
2017-05-24 06:02:49 +08:00
|
|
|
|
|
|
|
// FIXME: We shouldn't be changing the lexical context of declarations
|
|
|
|
// imported from AST files.
|
|
|
|
if (!isFromASTFile()) {
|
2017-06-23 09:04:34 +08:00
|
|
|
setModuleOwnershipKind(getModuleOwnershipKindForChildOf(DC));
|
|
|
|
if (hasOwningModule())
|
2017-05-24 06:02:49 +08:00
|
|
|
setLocalOwningModule(cast<Decl>(DC)->getOwningModule());
|
|
|
|
}
|
|
|
|
|
2017-07-05 15:47:11 +08:00
|
|
|
assert(
|
|
|
|
(getModuleOwnershipKind() != ModuleOwnershipKind::VisibleWhenImported ||
|
|
|
|
getOwningModule()) &&
|
|
|
|
"hidden declaration has no owning module");
|
2009-01-20 09:17:11 +08:00
|
|
|
}
|
|
|
|
|
2012-02-09 10:44:08 +08:00
|
|
|
void Decl::setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC,
|
|
|
|
ASTContext &Ctx) {
|
|
|
|
if (SemaDC == LexicalDC) {
|
|
|
|
DeclCtx = SemaDC;
|
|
|
|
} else {
|
2018-04-10 06:14:10 +08:00
|
|
|
auto *MDC = new (Ctx) Decl::MultipleDC();
|
2012-02-09 10:44:08 +08:00
|
|
|
MDC->SemanticDC = SemaDC;
|
|
|
|
MDC->LexicalDC = LexicalDC;
|
|
|
|
DeclCtx = MDC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-23 18:22:28 +08:00
|
|
|
bool Decl::isLexicallyWithinFunctionOrMethod() const {
|
|
|
|
const DeclContext *LDC = getLexicalDeclContext();
|
2015-08-23 19:09:40 +08:00
|
|
|
while (true) {
|
2015-08-23 18:22:28 +08:00
|
|
|
if (LDC->isFunctionOrMethod())
|
|
|
|
return true;
|
|
|
|
if (!isa<TagDecl>(LDC))
|
|
|
|
return false;
|
2015-08-23 19:09:40 +08:00
|
|
|
LDC = LDC->getLexicalParent();
|
|
|
|
}
|
2015-08-23 18:22:28 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-01 08:25:31 +08:00
|
|
|
bool Decl::isInAnonymousNamespace() const {
|
2017-10-11 06:33:17 +08:00
|
|
|
for (const DeclContext *DC = getDeclContext(); DC; DC = DC->getParent()) {
|
2018-04-10 06:14:10 +08:00
|
|
|
if (const auto *ND = dyn_cast<NamespaceDecl>(DC))
|
2009-10-01 08:25:31 +08:00
|
|
|
if (ND->isAnonymousNamespace())
|
|
|
|
return true;
|
2017-10-11 06:33:17 +08:00
|
|
|
}
|
2009-10-01 08:25:31 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-28 10:16:01 +08:00
|
|
|
bool Decl::isInStdNamespace() const {
|
2019-05-03 20:50:00 +08:00
|
|
|
const DeclContext *DC = getDeclContext();
|
|
|
|
return DC && DC->isStdNamespace();
|
2014-05-28 10:16:01 +08:00
|
|
|
}
|
|
|
|
|
2009-06-30 01:38:40 +08:00
|
|
|
TranslationUnitDecl *Decl::getTranslationUnitDecl() {
|
2018-04-10 06:14:10 +08:00
|
|
|
if (auto *TUD = dyn_cast<TranslationUnitDecl>(this))
|
2009-06-30 10:34:53 +08:00
|
|
|
return TUD;
|
|
|
|
|
2009-06-30 01:38:40 +08:00
|
|
|
DeclContext *DC = getDeclContext();
|
|
|
|
assert(DC && "This decl is not contained in a translation unit!");
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-30 01:38:40 +08:00
|
|
|
while (!DC->isTranslationUnit()) {
|
|
|
|
DC = DC->getParent();
|
|
|
|
assert(DC && "This decl is not contained in a translation unit!");
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-30 01:38:40 +08:00
|
|
|
return cast<TranslationUnitDecl>(DC);
|
|
|
|
}
|
|
|
|
|
|
|
|
ASTContext &Decl::getASTContext() const {
|
2009-09-09 23:08:12 +08:00
|
|
|
return getTranslationUnitDecl()->getASTContext();
|
2009-06-30 01:38:40 +08:00
|
|
|
}
|
|
|
|
|
2010-10-25 01:26:36 +08:00
|
|
|
ASTMutationListener *Decl::getASTMutationListener() const {
|
|
|
|
return getASTContext().getASTMutationListener();
|
|
|
|
}
|
|
|
|
|
2012-12-01 23:09:41 +08:00
|
|
|
unsigned Decl::getMaxAlignment() const {
|
|
|
|
if (!hasAttrs())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
unsigned Align = 0;
|
|
|
|
const AttrVec &V = getAttrs();
|
|
|
|
ASTContext &Ctx = getASTContext();
|
|
|
|
specific_attr_iterator<AlignedAttr> I(V.begin()), E(V.end());
|
|
|
|
for (; I != E; ++I)
|
|
|
|
Align = std::max(Align, I->getAlignment(Ctx));
|
|
|
|
return Align;
|
|
|
|
}
|
|
|
|
|
2016-04-28 22:13:28 +08:00
|
|
|
bool Decl::isUsed(bool CheckUsedAttr) const {
|
|
|
|
const Decl *CanonD = getCanonicalDecl();
|
|
|
|
if (CanonD->Used)
|
2010-02-17 10:17:21 +08:00
|
|
|
return true;
|
2016-04-28 22:13:28 +08:00
|
|
|
|
2010-02-17 10:17:21 +08:00
|
|
|
// Check for used attribute.
|
2016-04-28 22:13:28 +08:00
|
|
|
// Ask the most recent decl, since attributes accumulate in the redecl chain.
|
|
|
|
if (CheckUsedAttr && getMostRecentDecl()->hasAttr<UsedAttr>())
|
2010-02-17 10:17:21 +08:00
|
|
|
return true;
|
2012-11-24 00:26:30 +08:00
|
|
|
|
2016-04-28 22:13:28 +08:00
|
|
|
// The information may have not been deserialized yet. Force deserialization
|
|
|
|
// to complete the needed information.
|
|
|
|
return getMostRecentDecl()->getCanonicalDecl()->Used;
|
2010-02-17 10:17:21 +08:00
|
|
|
}
|
|
|
|
|
2013-09-05 08:02:25 +08:00
|
|
|
void Decl::markUsed(ASTContext &C) {
|
2016-04-28 22:13:28 +08:00
|
|
|
if (isUsed(false))
|
2013-09-05 08:02:25 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (C.getASTMutationListener())
|
|
|
|
C.getASTMutationListener()->DeclarationMarkedUsed(this);
|
|
|
|
|
2016-04-28 22:13:28 +08:00
|
|
|
setIsUsed();
|
2013-09-05 08:02:25 +08:00
|
|
|
}
|
|
|
|
|
2018-07-31 03:24:48 +08:00
|
|
|
bool Decl::isReferenced() const {
|
2011-04-20 03:51:10 +08:00
|
|
|
if (Referenced)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Check redeclarations.
|
2018-04-10 06:14:10 +08:00
|
|
|
for (const auto *I : redecls())
|
2011-04-20 03:51:10 +08:00
|
|
|
if (I->Referenced)
|
|
|
|
return true;
|
|
|
|
|
2018-07-31 03:24:48 +08:00
|
|
|
return false;
|
2011-04-20 03:51:10 +08:00
|
|
|
}
|
|
|
|
|
2017-05-20 12:11:33 +08:00
|
|
|
ExternalSourceSymbolAttr *Decl::getExternalSourceSymbolAttr() const {
|
|
|
|
const Decl *Definition = nullptr;
|
2018-04-10 06:14:10 +08:00
|
|
|
if (auto *ID = dyn_cast<ObjCInterfaceDecl>(this)) {
|
2017-05-20 12:11:33 +08:00
|
|
|
Definition = ID->getDefinition();
|
2018-04-10 06:14:10 +08:00
|
|
|
} else if (auto *PD = dyn_cast<ObjCProtocolDecl>(this)) {
|
2017-05-20 12:11:33 +08:00
|
|
|
Definition = PD->getDefinition();
|
2018-04-10 06:14:10 +08:00
|
|
|
} else if (auto *TD = dyn_cast<TagDecl>(this)) {
|
2017-05-20 12:11:33 +08:00
|
|
|
Definition = TD->getDefinition();
|
|
|
|
}
|
|
|
|
if (!Definition)
|
|
|
|
Definition = this;
|
|
|
|
|
|
|
|
if (auto *attr = Definition->getAttr<ExternalSourceSymbolAttr>())
|
|
|
|
return attr;
|
|
|
|
if (auto *dcd = dyn_cast<Decl>(getDeclContext())) {
|
|
|
|
return dcd->getAttr<ExternalSourceSymbolAttr>();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-04-11 15:48:59 +08:00
|
|
|
bool Decl::hasDefiningAttr() const {
|
|
|
|
return hasAttr<AliasAttr>() || hasAttr<IFuncAttr>();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Attr *Decl::getDefiningAttr() const {
|
2018-04-10 06:14:10 +08:00
|
|
|
if (auto *AA = getAttr<AliasAttr>())
|
2016-04-11 15:48:59 +08:00
|
|
|
return AA;
|
2018-04-10 06:14:10 +08:00
|
|
|
if (auto *IFA = getAttr<IFuncAttr>())
|
2016-04-11 15:48:59 +08:00
|
|
|
return IFA;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-05-27 04:08:24 +08:00
|
|
|
static StringRef getRealizedPlatform(const AvailabilityAttr *A,
|
|
|
|
const ASTContext &Context) {
|
2017-04-27 18:43:48 +08:00
|
|
|
// Check if this is an App Extension "platform", and if so chop off
|
|
|
|
// the suffix for matching with the actual platform.
|
|
|
|
StringRef RealizedPlatform = A->getPlatform()->getName();
|
|
|
|
if (!Context.getLangOpts().AppExt)
|
|
|
|
return RealizedPlatform;
|
|
|
|
size_t suffix = RealizedPlatform.rfind("_app_extension");
|
|
|
|
if (suffix != StringRef::npos)
|
|
|
|
return RealizedPlatform.slice(0, suffix);
|
|
|
|
return RealizedPlatform;
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Determine the availability of the given declaration based on
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
/// the target platform.
|
|
|
|
///
|
|
|
|
/// When it returns an availability result other than \c AR_Available,
|
|
|
|
/// if the \p Message parameter is non-NULL, it will be set to a
|
|
|
|
/// string describing why the entity is unavailable.
|
|
|
|
///
|
|
|
|
/// FIXME: Make these strings localizable, since they end up in
|
|
|
|
/// diagnostics.
|
|
|
|
static AvailabilityResult CheckAvailability(ASTContext &Context,
|
|
|
|
const AvailabilityAttr *A,
|
2016-07-30 01:37:38 +08:00
|
|
|
std::string *Message,
|
|
|
|
VersionTuple EnclosingVersion) {
|
|
|
|
if (EnclosingVersion.empty())
|
|
|
|
EnclosingVersion = Context.getTargetInfo().getPlatformMinVersion();
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
|
2016-07-30 01:37:38 +08:00
|
|
|
if (EnclosingVersion.empty())
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
return AR_Available;
|
|
|
|
|
2015-03-03 03:01:14 +08:00
|
|
|
StringRef ActualPlatform = A->getPlatform()->getName();
|
|
|
|
StringRef TargetPlatform = Context.getTargetInfo().getPlatformName();
|
|
|
|
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
// Match the platform name.
|
2017-04-27 18:43:48 +08:00
|
|
|
if (getRealizedPlatform(A, Context) != TargetPlatform)
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
return AR_Available;
|
2015-03-03 03:01:14 +08:00
|
|
|
|
|
|
|
StringRef PrettyPlatformName
|
|
|
|
= AvailabilityAttr::getPrettyPlatformName(ActualPlatform);
|
|
|
|
|
|
|
|
if (PrettyPlatformName.empty())
|
|
|
|
PrettyPlatformName = ActualPlatform;
|
|
|
|
|
2011-12-10 08:28:41 +08:00
|
|
|
std::string HintMessage;
|
|
|
|
if (!A->getMessage().empty()) {
|
|
|
|
HintMessage = " - ";
|
|
|
|
HintMessage += A->getMessage();
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-03-26 11:35:55 +08:00
|
|
|
// Make sure that this declaration has not been marked 'unavailable'.
|
|
|
|
if (A->getUnavailable()) {
|
|
|
|
if (Message) {
|
|
|
|
Message->clear();
|
|
|
|
llvm::raw_string_ostream Out(*Message);
|
2018-07-31 03:24:48 +08:00
|
|
|
Out << "not available on " << PrettyPlatformName
|
2011-12-10 08:28:41 +08:00
|
|
|
<< HintMessage;
|
2011-03-26 11:35:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return AR_Unavailable;
|
|
|
|
}
|
|
|
|
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
// Make sure that this declaration has already been introduced.
|
2018-07-31 03:24:48 +08:00
|
|
|
if (!A->getIntroduced().empty() &&
|
2016-07-30 01:37:38 +08:00
|
|
|
EnclosingVersion < A->getIntroduced()) {
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
if (Message) {
|
|
|
|
Message->clear();
|
|
|
|
llvm::raw_string_ostream Out(*Message);
|
2014-10-07 00:46:02 +08:00
|
|
|
VersionTuple VTI(A->getIntroduced());
|
2018-07-31 03:24:48 +08:00
|
|
|
Out << "introduced in " << PrettyPlatformName << ' '
|
2014-10-07 00:46:02 +08:00
|
|
|
<< VTI << HintMessage;
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
}
|
|
|
|
|
2016-03-08 14:12:54 +08:00
|
|
|
return A->getStrict() ? AR_Unavailable : AR_NotYetIntroduced;
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that this declaration hasn't been obsoleted.
|
2016-07-30 01:37:38 +08:00
|
|
|
if (!A->getObsoleted().empty() && EnclosingVersion >= A->getObsoleted()) {
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
if (Message) {
|
|
|
|
Message->clear();
|
|
|
|
llvm::raw_string_ostream Out(*Message);
|
2014-10-07 00:46:02 +08:00
|
|
|
VersionTuple VTO(A->getObsoleted());
|
2018-07-31 03:24:48 +08:00
|
|
|
Out << "obsoleted in " << PrettyPlatformName << ' '
|
2014-10-07 00:46:02 +08:00
|
|
|
<< VTO << HintMessage;
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
return AR_Unavailable;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that this declaration hasn't been deprecated.
|
2016-07-30 01:37:38 +08:00
|
|
|
if (!A->getDeprecated().empty() && EnclosingVersion >= A->getDeprecated()) {
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
if (Message) {
|
|
|
|
Message->clear();
|
|
|
|
llvm::raw_string_ostream Out(*Message);
|
2014-10-07 00:46:02 +08:00
|
|
|
VersionTuple VTD(A->getDeprecated());
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
Out << "first deprecated in " << PrettyPlatformName << ' '
|
2014-10-07 00:46:02 +08:00
|
|
|
<< VTD << HintMessage;
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
return AR_Deprecated;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AR_Available;
|
|
|
|
}
|
|
|
|
|
2016-07-30 01:37:38 +08:00
|
|
|
AvailabilityResult Decl::getAvailability(std::string *Message,
|
2018-05-03 09:12:06 +08:00
|
|
|
VersionTuple EnclosingVersion,
|
|
|
|
StringRef *RealizedPlatform) const {
|
2016-02-27 03:27:00 +08:00
|
|
|
if (auto *FTD = dyn_cast<FunctionTemplateDecl>(this))
|
2018-05-03 09:12:06 +08:00
|
|
|
return FTD->getTemplatedDecl()->getAvailability(Message, EnclosingVersion,
|
|
|
|
RealizedPlatform);
|
2016-02-27 03:27:00 +08:00
|
|
|
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
AvailabilityResult Result = AR_Available;
|
|
|
|
std::string ResultMessage;
|
|
|
|
|
2014-03-09 06:19:01 +08:00
|
|
|
for (const auto *A : attrs()) {
|
|
|
|
if (const auto *Deprecated = dyn_cast<DeprecatedAttr>(A)) {
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
if (Result >= AR_Deprecated)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (Message)
|
|
|
|
ResultMessage = Deprecated->getMessage();
|
|
|
|
|
|
|
|
Result = AR_Deprecated;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-03-09 06:19:01 +08:00
|
|
|
if (const auto *Unavailable = dyn_cast<UnavailableAttr>(A)) {
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
if (Message)
|
|
|
|
*Message = Unavailable->getMessage();
|
|
|
|
return AR_Unavailable;
|
|
|
|
}
|
|
|
|
|
2014-03-09 06:19:01 +08:00
|
|
|
if (const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
AvailabilityResult AR = CheckAvailability(getASTContext(), Availability,
|
2016-07-30 01:37:38 +08:00
|
|
|
Message, EnclosingVersion);
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
|
2018-05-03 09:12:06 +08:00
|
|
|
if (AR == AR_Unavailable) {
|
|
|
|
if (RealizedPlatform)
|
|
|
|
*RealizedPlatform = Availability->getPlatform()->getName();
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
return AR_Unavailable;
|
2018-05-03 09:12:06 +08:00
|
|
|
}
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
|
|
|
|
if (AR > Result) {
|
|
|
|
Result = AR;
|
|
|
|
if (Message)
|
|
|
|
ResultMessage.swap(*Message);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Message)
|
|
|
|
Message->swap(ResultMessage);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2017-04-27 18:43:48 +08:00
|
|
|
VersionTuple Decl::getVersionIntroduced() const {
|
|
|
|
const ASTContext &Context = getASTContext();
|
|
|
|
StringRef TargetPlatform = Context.getTargetInfo().getPlatformName();
|
|
|
|
for (const auto *A : attrs()) {
|
|
|
|
if (const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
|
|
|
|
if (getRealizedPlatform(Availability, Context) != TargetPlatform)
|
|
|
|
continue;
|
|
|
|
if (!Availability->getIntroduced().empty())
|
|
|
|
return Availability->getIntroduced();
|
|
|
|
}
|
|
|
|
}
|
2018-04-10 06:14:10 +08:00
|
|
|
return {};
|
2017-04-27 18:43:48 +08:00
|
|
|
}
|
|
|
|
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
bool Decl::canBeWeakImported(bool &IsDefinition) const {
|
|
|
|
IsDefinition = false;
|
2012-06-20 14:18:46 +08:00
|
|
|
|
|
|
|
// Variables, if they aren't definitions.
|
2018-04-10 06:14:10 +08:00
|
|
|
if (const auto *Var = dyn_cast<VarDecl>(this)) {
|
2013-04-04 03:27:57 +08:00
|
|
|
if (Var->isThisDeclarationADefinition()) {
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
IsDefinition = true;
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-20 14:18:46 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Functions, if they aren't definitions.
|
2018-04-10 06:14:10 +08:00
|
|
|
} else if (const auto *FD = dyn_cast<FunctionDecl>(this)) {
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
if (FD->hasBody()) {
|
|
|
|
IsDefinition = true;
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-20 14:18:46 +08:00
|
|
|
return true;
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
|
2012-06-20 14:18:46 +08:00
|
|
|
// Objective-C classes, if this is the non-fragile runtime.
|
|
|
|
} else if (isa<ObjCInterfaceDecl>(this) &&
|
2012-06-21 05:58:02 +08:00
|
|
|
getASTContext().getLangOpts().ObjCRuntime.hasWeakClassImport()) {
|
2012-06-20 14:18:46 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Nothing else.
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Decl::isWeakImported() const {
|
|
|
|
bool IsDefinition;
|
|
|
|
if (!canBeWeakImported(IsDefinition))
|
|
|
|
return false;
|
|
|
|
|
2014-03-09 06:19:01 +08:00
|
|
|
for (const auto *A : attrs()) {
|
|
|
|
if (isa<WeakImportAttr>(A))
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
return true;
|
|
|
|
|
2014-03-09 06:19:01 +08:00
|
|
|
if (const auto *Availability = dyn_cast<AvailabilityAttr>(A)) {
|
2016-07-30 01:37:38 +08:00
|
|
|
if (CheckAvailability(getASTContext(), Availability, nullptr,
|
|
|
|
VersionTuple()) == AR_NotYetIntroduced)
|
Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,
void foo()
__attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));
says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:
- If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
will result in a deprecation warning, as if we had placed
attribute((deprecated)) on it (but with a better diagnostic)
- If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
will result in an "unavailable" warning (in C)/error (in C++), as
if we had placed attribute((unavailable)) on it
- If we choose a deployment target prior to 10.2, foo() is
weak-imported (if it is a kind of entity that can be weak
imported), as if we had placed the weak_import attribute on it.
Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.
The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.
Addresses <rdar://problem/6690412>.
As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.
llvm-svn: 128127
2011-03-23 08:50:03 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2010-02-17 10:17:21 +08:00
|
|
|
|
2009-03-28 04:18:19 +08:00
|
|
|
unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
|
|
|
|
switch (DeclKind) {
|
2009-11-17 13:59:44 +08:00
|
|
|
case Function:
|
2017-02-18 04:05:37 +08:00
|
|
|
case CXXDeductionGuide:
|
2009-11-17 13:59:44 +08:00
|
|
|
case CXXMethod:
|
|
|
|
case CXXConstructor:
|
P0136R1, DR1573, DR1645, DR1715, DR1736, DR1903, DR1941, DR1959, DR1991:
Replace inheriting constructors implementation with new approach, voted into
C++ last year as a DR against C++11.
Instead of synthesizing a set of derived class constructors for each inherited
base class constructor, we make the constructors of the base class visible to
constructor lookup in the derived class, using the normal rules for
using-declarations.
For constructors, UsingShadowDecl now has a ConstructorUsingShadowDecl derived
class that tracks the requisite additional information. We create shadow
constructors (not found by name lookup) in the derived class to model the
actual initialization, and have a new expression node,
CXXInheritedCtorInitExpr, to model the initialization of a base class from such
a constructor. (This initialization is special because it performs real perfect
forwarding of arguments.)
In cases where argument forwarding is not possible (for inalloca calls,
variadic calls, and calls with callee parameter cleanup), the shadow inheriting
constructor is not emitted and instead we directly emit the initialization code
into the caller of the inherited constructor.
Note that this new model is not perfectly compatible with the old model in some
corner cases. In particular:
* if B inherits a private constructor from A, and C uses that constructor to
construct a B, then we previously required that A befriends B and B
befriends C, but the new rules require A to befriend C directly, and
* if a derived class has its own constructors (and so its implicit default
constructor is suppressed), it may still inherit a default constructor from
a base class
llvm-svn: 274049
2016-06-29 03:03:57 +08:00
|
|
|
case ConstructorUsingShadow:
|
2009-11-17 13:59:44 +08:00
|
|
|
case CXXDestructor:
|
|
|
|
case CXXConversion:
|
2009-03-28 04:18:19 +08:00
|
|
|
case EnumConstant:
|
|
|
|
case Var:
|
|
|
|
case ImplicitParam:
|
|
|
|
case ParmVar:
|
|
|
|
case ObjCMethod:
|
|
|
|
case ObjCProperty:
|
2013-04-16 15:28:30 +08:00
|
|
|
case MSProperty:
|
2010-04-23 21:07:39 +08:00
|
|
|
return IDNS_Ordinary;
|
2011-02-17 15:39:24 +08:00
|
|
|
case Label:
|
|
|
|
return IDNS_Label;
|
2010-11-21 14:08:52 +08:00
|
|
|
case IndirectField:
|
|
|
|
return IDNS_Ordinary | IDNS_Member;
|
|
|
|
|
2017-09-08 04:22:00 +08:00
|
|
|
case Binding:
|
2016-01-07 06:49:11 +08:00
|
|
|
case NonTypeTemplateParm:
|
2017-09-08 04:22:00 +08:00
|
|
|
case VarTemplate:
|
2019-07-11 05:25:49 +08:00
|
|
|
case Concept:
|
2017-09-08 04:22:00 +08:00
|
|
|
// These (C++-only) declarations are found by redeclaration lookup for
|
|
|
|
// tag types, so we include them in the tag namespace.
|
2016-01-07 06:49:11 +08:00
|
|
|
return IDNS_Ordinary | IDNS_Tag;
|
|
|
|
|
2010-04-24 02:46:30 +08:00
|
|
|
case ObjCCompatibleAlias:
|
|
|
|
case ObjCInterface:
|
|
|
|
return IDNS_Ordinary | IDNS_Type;
|
|
|
|
|
|
|
|
case Typedef:
|
2011-04-15 22:24:37 +08:00
|
|
|
case TypeAlias:
|
2010-04-24 02:46:30 +08:00
|
|
|
case TemplateTypeParm:
|
Parsing, semantic analysis, and AST for Objective-C type parameters.
Produce type parameter declarations for Objective-C type parameters,
and attach lists of type parameters to Objective-C classes,
categories, forward declarations, and extensions as
appropriate. Perform semantic analysis of type bounds for type
parameters, both in isolation and across classes/categories/extensions
to ensure consistency.
Also handle (de-)serialization of Objective-C type parameter lists,
along with sundry other things one must do to add a new declaration to
Clang.
Note that Objective-C type parameters are typedef name declarations,
like typedefs and C++11 type aliases, in support of type erasure.
Part of rdar://problem/6294649.
llvm-svn: 241541
2015-07-07 11:57:15 +08:00
|
|
|
case ObjCTypeParam:
|
2010-04-24 02:46:30 +08:00
|
|
|
return IDNS_Ordinary | IDNS_Type;
|
|
|
|
|
2016-12-21 05:35:28 +08:00
|
|
|
case UnresolvedUsingTypename:
|
|
|
|
return IDNS_Ordinary | IDNS_Type | IDNS_Using;
|
|
|
|
|
2009-11-17 13:59:44 +08:00
|
|
|
case UsingShadow:
|
|
|
|
return 0; // we'll actually overwrite this later
|
|
|
|
|
2009-11-18 10:36:19 +08:00
|
|
|
case UnresolvedUsingValue:
|
|
|
|
return IDNS_Ordinary | IDNS_Using;
|
2009-11-17 13:59:44 +08:00
|
|
|
|
|
|
|
case Using:
|
2016-12-21 05:35:28 +08:00
|
|
|
case UsingPack:
|
2009-11-17 13:59:44 +08:00
|
|
|
return IDNS_Using;
|
|
|
|
|
2009-03-28 04:18:19 +08:00
|
|
|
case ObjCProtocol:
|
2009-04-24 08:11:27 +08:00
|
|
|
return IDNS_ObjCProtocol;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-28 04:18:19 +08:00
|
|
|
case Field:
|
|
|
|
case ObjCAtDefsField:
|
|
|
|
case ObjCIvar:
|
|
|
|
return IDNS_Member;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-28 04:18:19 +08:00
|
|
|
case Record:
|
|
|
|
case CXXRecord:
|
|
|
|
case Enum:
|
2010-04-24 02:46:30 +08:00
|
|
|
return IDNS_Tag | IDNS_Type;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-28 04:18:19 +08:00
|
|
|
case Namespace:
|
2010-04-24 02:46:30 +08:00
|
|
|
case NamespaceAlias:
|
|
|
|
return IDNS_Namespace;
|
|
|
|
|
2009-03-28 04:18:19 +08:00
|
|
|
case FunctionTemplate:
|
2010-04-24 02:46:30 +08:00
|
|
|
return IDNS_Ordinary;
|
|
|
|
|
2009-03-28 04:18:19 +08:00
|
|
|
case ClassTemplate:
|
|
|
|
case TemplateTemplateParm:
|
2017-09-08 04:22:00 +08:00
|
|
|
case TypeAliasTemplate:
|
2010-04-24 02:46:30 +08:00
|
|
|
return IDNS_Ordinary | IDNS_Tag | IDNS_Type;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2016-03-03 13:21:39 +08:00
|
|
|
case OMPDeclareReduction:
|
|
|
|
return IDNS_OMPReduction;
|
|
|
|
|
2019-02-02 04:25:04 +08:00
|
|
|
case OMPDeclareMapper:
|
|
|
|
return IDNS_OMPMapper;
|
|
|
|
|
2009-03-28 04:18:19 +08:00
|
|
|
// Never have names.
|
2009-08-28 15:59:38 +08:00
|
|
|
case Friend:
|
2009-09-17 06:47:08 +08:00
|
|
|
case FriendTemplate:
|
2010-06-05 13:09:32 +08:00
|
|
|
case AccessSpec:
|
2009-03-28 04:18:19 +08:00
|
|
|
case LinkageSpec:
|
2016-09-09 07:14:54 +08:00
|
|
|
case Export:
|
2009-03-28 04:18:19 +08:00
|
|
|
case FileScopeAsm:
|
|
|
|
case StaticAssert:
|
|
|
|
case ObjCPropertyImpl:
|
2016-03-03 01:28:48 +08:00
|
|
|
case PragmaComment:
|
2016-03-03 03:28:54 +08:00
|
|
|
case PragmaDetectMismatch:
|
2009-03-28 04:18:19 +08:00
|
|
|
case Block:
|
2013-04-17 03:37:38 +08:00
|
|
|
case Captured:
|
2009-03-28 04:18:19 +08:00
|
|
|
case TranslationUnit:
|
2015-03-07 08:04:49 +08:00
|
|
|
case ExternCContext:
|
2016-07-23 07:36:59 +08:00
|
|
|
case Decomposition:
|
2009-03-28 04:18:19 +08:00
|
|
|
|
|
|
|
case UsingDirective:
|
2015-11-04 11:40:30 +08:00
|
|
|
case BuiltinTemplate:
|
2009-03-28 04:18:19 +08:00
|
|
|
case ClassTemplateSpecialization:
|
2009-05-31 17:31:02 +08:00
|
|
|
case ClassTemplatePartialSpecialization:
|
2011-08-14 11:52:19 +08:00
|
|
|
case ClassScopeFunctionSpecialization:
|
2013-08-06 09:03:05 +08:00
|
|
|
case VarTemplateSpecialization:
|
|
|
|
case VarTemplatePartialSpecialization:
|
2010-04-23 07:19:50 +08:00
|
|
|
case ObjCImplementation:
|
|
|
|
case ObjCCategory:
|
|
|
|
case ObjCCategoryImpl:
|
2011-12-03 07:23:56 +08:00
|
|
|
case Import:
|
2013-03-22 14:34:35 +08:00
|
|
|
case OMPThreadPrivate:
|
2019-03-08 01:54:44 +08:00
|
|
|
case OMPAllocate:
|
2018-09-26 12:28:39 +08:00
|
|
|
case OMPRequires:
|
2016-02-11 13:35:55 +08:00
|
|
|
case OMPCapturedExpr:
|
2013-02-23 01:15:32 +08:00
|
|
|
case Empty:
|
2010-04-23 07:19:50 +08:00
|
|
|
// Never looked up by name.
|
2009-03-28 04:18:19 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2009-11-17 13:59:44 +08:00
|
|
|
|
2012-01-21 05:50:17 +08:00
|
|
|
llvm_unreachable("Invalid DeclKind!");
|
2008-06-08 00:52:53 +08:00
|
|
|
}
|
|
|
|
|
2012-02-09 10:44:08 +08:00
|
|
|
void Decl::setAttrsImpl(const AttrVec &attrs, ASTContext &Ctx) {
|
2010-06-12 07:09:25 +08:00
|
|
|
assert(!HasAttrs && "Decl already contains attrs.");
|
|
|
|
|
2012-02-09 10:44:08 +08:00
|
|
|
AttrVec &AttrBlank = Ctx.getDeclAttrs(this);
|
2010-08-19 07:23:40 +08:00
|
|
|
assert(AttrBlank.empty() && "HasAttrs was wrong?");
|
2010-06-12 07:09:25 +08:00
|
|
|
|
|
|
|
AttrBlank = attrs;
|
|
|
|
HasAttrs = true;
|
|
|
|
}
|
|
|
|
|
2010-08-19 07:23:40 +08:00
|
|
|
void Decl::dropAttrs() {
|
2008-06-08 00:52:53 +08:00
|
|
|
if (!HasAttrs) return;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-06-08 00:52:53 +08:00
|
|
|
HasAttrs = false;
|
2009-06-30 10:34:44 +08:00
|
|
|
getASTContext().eraseDeclAttrs(this);
|
2008-06-08 00:52:53 +08:00
|
|
|
}
|
|
|
|
|
2018-09-24 14:31:37 +08:00
|
|
|
void Decl::addAttr(Attr *A) {
|
|
|
|
if (!hasAttrs()) {
|
|
|
|
setAttrs(AttrVec(1, A));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AttrVec &Attrs = getAttrs();
|
|
|
|
if (!A->isInherited()) {
|
|
|
|
Attrs.push_back(A);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attribute inheritance is processed after attribute parsing. To keep the
|
|
|
|
// order as in the source code, add inherited attributes before non-inherited
|
|
|
|
// ones.
|
|
|
|
auto I = Attrs.begin(), E = Attrs.end();
|
|
|
|
for (; I != E; ++I) {
|
|
|
|
if (!(*I)->isInherited())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Attrs.insert(I, A);
|
|
|
|
}
|
|
|
|
|
2010-08-19 07:23:40 +08:00
|
|
|
const AttrVec &Decl::getAttrs() const {
|
|
|
|
assert(HasAttrs && "No attrs to get!");
|
2009-06-30 10:34:44 +08:00
|
|
|
return getASTContext().getDeclAttrs(this);
|
2008-06-08 00:52:53 +08:00
|
|
|
}
|
|
|
|
|
2008-10-13 00:14:48 +08:00
|
|
|
Decl *Decl::castFromDeclContext (const DeclContext *D) {
|
2009-02-16 22:29:28 +08:00
|
|
|
Decl::Kind DK = D->getDeclKind();
|
|
|
|
switch(DK) {
|
2010-05-30 15:21:58 +08:00
|
|
|
#define DECL(NAME, BASE)
|
|
|
|
#define DECL_CONTEXT(NAME) \
|
|
|
|
case Decl::NAME: \
|
2018-04-10 06:14:10 +08:00
|
|
|
return static_cast<NAME##Decl *>(const_cast<DeclContext *>(D));
|
2010-05-30 15:21:58 +08:00
|
|
|
#define DECL_CONTEXT_BASE(NAME)
|
|
|
|
#include "clang/AST/DeclNodes.inc"
|
2009-02-16 22:29:28 +08:00
|
|
|
default:
|
2010-05-30 15:21:58 +08:00
|
|
|
#define DECL(NAME, BASE)
|
|
|
|
#define DECL_CONTEXT_BASE(NAME) \
|
|
|
|
if (DK >= first##NAME && DK <= last##NAME) \
|
2018-04-10 06:14:10 +08:00
|
|
|
return static_cast<NAME##Decl *>(const_cast<DeclContext *>(D));
|
2010-05-30 15:21:58 +08:00
|
|
|
#include "clang/AST/DeclNodes.inc"
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("a decl that inherits DeclContext isn't handled");
|
2009-02-16 22:29:28 +08:00
|
|
|
}
|
2008-10-13 00:14:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DeclContext *Decl::castToDeclContext(const Decl *D) {
|
2009-02-16 22:29:28 +08:00
|
|
|
Decl::Kind DK = D->getKind();
|
|
|
|
switch(DK) {
|
2010-05-30 15:21:58 +08:00
|
|
|
#define DECL(NAME, BASE)
|
|
|
|
#define DECL_CONTEXT(NAME) \
|
|
|
|
case Decl::NAME: \
|
2018-04-10 06:14:10 +08:00
|
|
|
return static_cast<NAME##Decl *>(const_cast<Decl *>(D));
|
2010-05-30 15:21:58 +08:00
|
|
|
#define DECL_CONTEXT_BASE(NAME)
|
|
|
|
#include "clang/AST/DeclNodes.inc"
|
2009-02-16 22:29:28 +08:00
|
|
|
default:
|
2010-05-30 15:21:58 +08:00
|
|
|
#define DECL(NAME, BASE)
|
|
|
|
#define DECL_CONTEXT_BASE(NAME) \
|
|
|
|
if (DK >= first##NAME && DK <= last##NAME) \
|
2018-04-10 06:14:10 +08:00
|
|
|
return static_cast<NAME##Decl *>(const_cast<Decl *>(D));
|
2010-05-30 15:21:58 +08:00
|
|
|
#include "clang/AST/DeclNodes.inc"
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("a decl that inherits DeclContext isn't handled");
|
2009-02-16 22:29:28 +08:00
|
|
|
}
|
2008-10-13 00:14:48 +08:00
|
|
|
}
|
|
|
|
|
2009-06-30 10:35:26 +08:00
|
|
|
SourceLocation Decl::getBodyRBrace() const {
|
2010-07-07 19:31:19 +08:00
|
|
|
// Special handling of FunctionDecl to avoid de-serializing the body from PCH.
|
|
|
|
// FunctionDecl stores EndRangeLoc for this purpose.
|
2018-04-10 06:14:10 +08:00
|
|
|
if (const auto *FD = dyn_cast<FunctionDecl>(this)) {
|
2010-07-07 19:31:19 +08:00
|
|
|
const FunctionDecl *Definition;
|
|
|
|
if (FD->hasBody(Definition))
|
|
|
|
return Definition->getSourceRange().getEnd();
|
2018-04-10 06:14:10 +08:00
|
|
|
return {};
|
2010-07-07 19:31:19 +08:00
|
|
|
}
|
|
|
|
|
2010-07-07 19:31:27 +08:00
|
|
|
if (Stmt *Body = getBody())
|
|
|
|
return Body->getSourceRange().getEnd();
|
|
|
|
|
2018-04-10 06:14:10 +08:00
|
|
|
return {};
|
2009-04-27 04:35:05 +08:00
|
|
|
}
|
|
|
|
|
2013-12-07 21:51:35 +08:00
|
|
|
bool Decl::AccessDeclContextSanity() const {
|
2010-12-02 08:22:25 +08:00
|
|
|
#ifndef NDEBUG
|
2010-01-21 05:53:11 +08:00
|
|
|
// Suppress this check if any of the following hold:
|
|
|
|
// 1. this is the translation unit (and thus has no parent)
|
|
|
|
// 2. this is a template parameter (and thus doesn't belong to its context)
|
2010-09-09 05:58:42 +08:00
|
|
|
// 3. this is a non-type template parameter
|
|
|
|
// 4. the context is not a record
|
|
|
|
// 5. it's invalid
|
|
|
|
// 6. it's a C++0x static_assert.
|
2018-01-20 04:46:19 +08:00
|
|
|
// 7. it's a block literal declaration
|
2009-08-30 04:47:47 +08:00
|
|
|
if (isa<TranslationUnitDecl>(this) ||
|
2010-07-02 19:55:44 +08:00
|
|
|
isa<TemplateTypeParmDecl>(this) ||
|
2010-09-09 05:58:42 +08:00
|
|
|
isa<NonTypeTemplateParmDecl>(this) ||
|
2019-06-07 07:24:15 +08:00
|
|
|
!getDeclContext() ||
|
2010-02-23 01:53:38 +08:00
|
|
|
!isa<CXXRecordDecl>(getDeclContext()) ||
|
2010-09-09 05:32:35 +08:00
|
|
|
isInvalidDecl() ||
|
|
|
|
isa<StaticAssertDecl>(this) ||
|
2018-01-20 04:46:19 +08:00
|
|
|
isa<BlockDecl>(this) ||
|
2010-09-09 05:32:35 +08:00
|
|
|
// FIXME: a ParmVarDecl can have ClassTemplateSpecialization
|
|
|
|
// as DeclContext (?).
|
2010-09-09 05:58:42 +08:00
|
|
|
isa<ParmVarDecl>(this) ||
|
|
|
|
// FIXME: a ClassTemplateSpecialization or CXXRecordDecl can have
|
|
|
|
// AS_none as access specifier.
|
2011-08-17 09:06:54 +08:00
|
|
|
isa<CXXRecordDecl>(this) ||
|
|
|
|
isa<ClassScopeFunctionSpecializationDecl>(this))
|
2013-12-07 21:51:35 +08:00
|
|
|
return true;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
assert(Access != AS_none &&
|
2009-03-26 07:38:06 +08:00
|
|
|
"Access specifier is AS_none inside a record decl");
|
2010-12-02 08:22:25 +08:00
|
|
|
#endif
|
2013-12-07 21:51:35 +08:00
|
|
|
return true;
|
2009-03-26 07:38:06 +08:00
|
|
|
}
|
|
|
|
|
2013-05-03 15:33:41 +08:00
|
|
|
static Decl::Kind getKind(const Decl *D) { return D->getKind(); }
|
|
|
|
static Decl::Kind getKind(const DeclContext *DC) { return DC->getDeclKind(); }
|
|
|
|
|
2018-09-15 10:03:58 +08:00
|
|
|
int64_t Decl::getID() const {
|
2018-12-04 06:19:05 +08:00
|
|
|
return getASTContext().getAllocator().identifyKnownAlignedObject<Decl>(this);
|
2018-09-15 10:03:58 +08:00
|
|
|
}
|
|
|
|
|
2014-01-16 21:55:42 +08:00
|
|
|
const FunctionType *Decl::getFunctionType(bool BlocksToo) const {
|
|
|
|
QualType Ty;
|
2018-04-10 06:14:10 +08:00
|
|
|
if (const auto *D = dyn_cast<ValueDecl>(this))
|
2014-01-16 21:55:42 +08:00
|
|
|
Ty = D->getType();
|
2018-04-10 06:14:10 +08:00
|
|
|
else if (const auto *D = dyn_cast<TypedefNameDecl>(this))
|
2014-01-16 21:55:42 +08:00
|
|
|
Ty = D->getUnderlyingType();
|
|
|
|
else
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2014-01-16 21:55:42 +08:00
|
|
|
|
|
|
|
if (Ty->isFunctionPointerType())
|
2019-10-04 00:58:01 +08:00
|
|
|
Ty = Ty->castAs<PointerType>()->getPointeeType();
|
2019-06-04 02:36:33 +08:00
|
|
|
else if (Ty->isFunctionReferenceType())
|
2019-10-04 00:58:01 +08:00
|
|
|
Ty = Ty->castAs<ReferenceType>()->getPointeeType();
|
2014-01-16 21:55:42 +08:00
|
|
|
else if (BlocksToo && Ty->isBlockPointerType())
|
2019-10-04 00:58:01 +08:00
|
|
|
Ty = Ty->castAs<BlockPointerType>()->getPointeeType();
|
2014-01-16 21:55:42 +08:00
|
|
|
|
|
|
|
return Ty->getAs<FunctionType>();
|
|
|
|
}
|
|
|
|
|
2013-05-03 15:33:41 +08:00
|
|
|
/// Starting at a given context (a Decl or DeclContext), look for a
|
|
|
|
/// code context that is not a closure (a lambda, block, etc.).
|
|
|
|
template <class T> static Decl *getNonClosureContext(T *D) {
|
|
|
|
if (getKind(D) == Decl::CXXMethod) {
|
2018-04-10 06:14:10 +08:00
|
|
|
auto *MD = cast<CXXMethodDecl>(D);
|
2013-05-04 01:11:14 +08:00
|
|
|
if (MD->getOverloadedOperator() == OO_Call &&
|
|
|
|
MD->getParent()->isLambda())
|
2013-05-03 15:33:41 +08:00
|
|
|
return getNonClosureContext(MD->getParent()->getParent());
|
|
|
|
return MD;
|
2018-04-10 06:14:10 +08:00
|
|
|
} else if (auto *FD = dyn_cast<FunctionDecl>(D))
|
2013-05-03 15:33:41 +08:00
|
|
|
return FD;
|
2018-04-10 06:14:10 +08:00
|
|
|
else if (auto *MD = dyn_cast<ObjCMethodDecl>(D))
|
2013-05-03 15:33:41 +08:00
|
|
|
return MD;
|
2018-04-10 06:14:10 +08:00
|
|
|
else if (auto *BD = dyn_cast<BlockDecl>(D))
|
2013-05-03 15:33:41 +08:00
|
|
|
return getNonClosureContext(BD->getParent());
|
2018-04-10 06:14:10 +08:00
|
|
|
else if (auto *CD = dyn_cast<CapturedDecl>(D))
|
2013-05-03 15:33:41 +08:00
|
|
|
return getNonClosureContext(CD->getParent());
|
2018-04-10 06:14:10 +08:00
|
|
|
else
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2011-11-06 17:01:30 +08:00
|
|
|
}
|
|
|
|
|
2013-05-03 15:33:41 +08:00
|
|
|
Decl *Decl::getNonClosureContext() {
|
|
|
|
return ::getNonClosureContext(this);
|
|
|
|
}
|
2011-02-23 06:25:23 +08:00
|
|
|
|
2013-05-03 15:33:41 +08:00
|
|
|
Decl *DeclContext::getNonClosureAncestor() {
|
|
|
|
return ::getNonClosureContext(this);
|
2011-02-23 06:25:23 +08:00
|
|
|
}
|
2009-03-26 07:38:06 +08:00
|
|
|
|
2008-06-08 00:52:53 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// DeclContext Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-08-02 04:48:16 +08:00
|
|
|
DeclContext::DeclContext(Decl::Kind K) {
|
|
|
|
DeclContextBits.DeclKind = K;
|
|
|
|
setHasExternalLexicalStorage(false);
|
|
|
|
setHasExternalVisibleStorage(false);
|
|
|
|
setNeedToReconcileExternalVisibleStorage(false);
|
|
|
|
setHasLazyLocalLexicalLookups(false);
|
|
|
|
setHasLazyExternalLexicalLookups(false);
|
|
|
|
setUseQualifiedLookup(false);
|
|
|
|
}
|
|
|
|
|
2009-02-16 22:29:28 +08:00
|
|
|
bool DeclContext::classof(const Decl *D) {
|
|
|
|
switch (D->getKind()) {
|
2010-05-30 15:21:58 +08:00
|
|
|
#define DECL(NAME, BASE)
|
|
|
|
#define DECL_CONTEXT(NAME) case Decl::NAME:
|
|
|
|
#define DECL_CONTEXT_BASE(NAME)
|
|
|
|
#include "clang/AST/DeclNodes.inc"
|
2009-02-16 22:29:28 +08:00
|
|
|
return true;
|
|
|
|
default:
|
2010-05-30 15:21:58 +08:00
|
|
|
#define DECL(NAME, BASE)
|
|
|
|
#define DECL_CONTEXT_BASE(NAME) \
|
|
|
|
if (D->getKind() >= Decl::first##NAME && \
|
|
|
|
D->getKind() <= Decl::last##NAME) \
|
2009-02-16 22:29:28 +08:00
|
|
|
return true;
|
2010-05-30 15:21:58 +08:00
|
|
|
#include "clang/AST/DeclNodes.inc"
|
2009-02-16 22:29:28 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-08 08:39:18 +08:00
|
|
|
DeclContext::~DeclContext() = default;
|
2008-12-12 00:49:14 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Find the parent context of this context that will be
|
2009-09-11 00:57:35 +08:00
|
|
|
/// used for unqualified name lookup.
|
|
|
|
///
|
|
|
|
/// Generally, the parent lookup context is the semantic context. However, for
|
|
|
|
/// a friend function the parent lookup context is the lexical context, which
|
|
|
|
/// is the class in which the friend is declared.
|
|
|
|
DeclContext *DeclContext::getLookupParent() {
|
2018-08-03 21:13:05 +08:00
|
|
|
// FIXME: Find a better way to identify friends.
|
2009-09-11 00:57:35 +08:00
|
|
|
if (isa<FunctionDecl>(this))
|
2010-08-31 08:36:30 +08:00
|
|
|
if (getParent()->getRedeclContext()->isFileContext() &&
|
|
|
|
getLexicalParent()->getRedeclContext()->isRecord())
|
2009-09-11 00:57:35 +08:00
|
|
|
return getLexicalParent();
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2019-09-05 09:23:47 +08:00
|
|
|
// A lookup within the call operator of a lambda never looks in the lambda
|
|
|
|
// class; instead, skip to the context in which that closure type is
|
|
|
|
// declared.
|
|
|
|
if (isLambdaCallOperator(this))
|
|
|
|
return getParent()->getParent();
|
|
|
|
|
2009-09-11 00:57:35 +08:00
|
|
|
return getParent();
|
|
|
|
}
|
|
|
|
|
2019-04-18 08:00:16 +08:00
|
|
|
const BlockDecl *DeclContext::getInnermostBlockDecl() const {
|
|
|
|
const DeclContext *Ctx = this;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (Ctx->isClosure())
|
|
|
|
return cast<BlockDecl>(Ctx);
|
|
|
|
Ctx = Ctx->getParent();
|
|
|
|
} while (Ctx);
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2010-09-01 04:53:31 +08:00
|
|
|
bool DeclContext::isInlineNamespace() const {
|
|
|
|
return isNamespace() &&
|
|
|
|
cast<NamespaceDecl>(this)->isInline();
|
|
|
|
}
|
|
|
|
|
2014-05-28 10:16:01 +08:00
|
|
|
bool DeclContext::isStdNamespace() const {
|
|
|
|
if (!isNamespace())
|
|
|
|
return false;
|
|
|
|
|
2018-04-10 06:14:10 +08:00
|
|
|
const auto *ND = cast<NamespaceDecl>(this);
|
2014-05-28 10:16:01 +08:00
|
|
|
if (ND->isInline()) {
|
|
|
|
return ND->getParent()->isStdNamespace();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!getParent()->getRedeclContext()->isTranslationUnit())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const IdentifierInfo *II = ND->getIdentifier();
|
|
|
|
return II && II->isStr("std");
|
|
|
|
}
|
|
|
|
|
2009-05-29 00:34:51 +08:00
|
|
|
bool DeclContext::isDependentContext() const {
|
|
|
|
if (isFileContext())
|
|
|
|
return false;
|
2009-05-31 17:31:02 +08:00
|
|
|
|
|
|
|
if (isa<ClassTemplatePartialSpecializationDecl>(this))
|
|
|
|
return true;
|
2009-05-29 00:34:51 +08:00
|
|
|
|
2018-04-10 06:14:10 +08:00
|
|
|
if (const auto *Record = dyn_cast<CXXRecordDecl>(this)) {
|
2009-05-29 00:34:51 +08:00
|
|
|
if (Record->getDescribedClassTemplate())
|
|
|
|
return true;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2012-02-22 03:11:17 +08:00
|
|
|
if (Record->isDependentLambda())
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2018-04-10 06:14:10 +08:00
|
|
|
if (const auto *Function = dyn_cast<FunctionDecl>(this)) {
|
2009-05-29 00:34:51 +08:00
|
|
|
if (Function->getDescribedFunctionTemplate())
|
|
|
|
return true;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-03-24 13:22:00 +08:00
|
|
|
// Friend function declarations are dependent if their *lexical*
|
|
|
|
// context is dependent.
|
|
|
|
if (cast<Decl>(this)->getFriendObjectKind())
|
|
|
|
return getLexicalParent()->isDependentContext();
|
|
|
|
}
|
|
|
|
|
2015-02-07 11:11:11 +08:00
|
|
|
// FIXME: A variable template is a dependent context, but is not a
|
|
|
|
// DeclContext. A context within it (such as a lambda-expression)
|
|
|
|
// should be considered dependent.
|
|
|
|
|
2009-05-29 00:34:51 +08:00
|
|
|
return getParent() && getParent()->isDependentContext();
|
|
|
|
}
|
|
|
|
|
2009-01-06 03:45:36 +08:00
|
|
|
bool DeclContext::isTransparentContext() const {
|
2018-08-02 04:48:16 +08:00
|
|
|
if (getDeclKind() == Decl::Enum)
|
2010-10-09 07:50:27 +08:00
|
|
|
return !cast<EnumDecl>(this)->isScoped();
|
2018-08-02 04:48:16 +08:00
|
|
|
else if (getDeclKind() == Decl::LinkageSpec || getDeclKind() == Decl::Export)
|
2009-01-06 03:45:36 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-14 10:13:03 +08:00
|
|
|
static bool isLinkageSpecContext(const DeclContext *DC,
|
|
|
|
LinkageSpecDecl::LanguageIDs ID) {
|
|
|
|
while (DC->getDeclKind() != Decl::TranslationUnit) {
|
|
|
|
if (DC->getDeclKind() == Decl::LinkageSpec)
|
|
|
|
return cast<LinkageSpecDecl>(DC)->getLanguage() == ID;
|
2014-04-15 04:23:58 +08:00
|
|
|
DC = DC->getLexicalParent();
|
2013-11-14 10:13:03 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DeclContext::isExternCContext() const {
|
2017-11-08 08:39:18 +08:00
|
|
|
return isLinkageSpecContext(this, LinkageSpecDecl::lang_c);
|
2013-11-14 10:13:03 +08:00
|
|
|
}
|
|
|
|
|
2016-11-02 23:46:34 +08:00
|
|
|
const LinkageSpecDecl *DeclContext::getExternCContext() const {
|
|
|
|
const DeclContext *DC = this;
|
|
|
|
while (DC->getDeclKind() != Decl::TranslationUnit) {
|
|
|
|
if (DC->getDeclKind() == Decl::LinkageSpec &&
|
2017-11-08 08:39:18 +08:00
|
|
|
cast<LinkageSpecDecl>(DC)->getLanguage() == LinkageSpecDecl::lang_c)
|
2016-11-02 23:46:34 +08:00
|
|
|
return cast<LinkageSpecDecl>(DC);
|
|
|
|
DC = DC->getLexicalParent();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-11-14 10:13:03 +08:00
|
|
|
bool DeclContext::isExternCXXContext() const {
|
2017-11-08 08:39:18 +08:00
|
|
|
return isLinkageSpecContext(this, LinkageSpecDecl::lang_cxx);
|
2013-11-14 10:13:03 +08:00
|
|
|
}
|
|
|
|
|
2010-08-31 08:36:30 +08:00
|
|
|
bool DeclContext::Encloses(const DeclContext *DC) const {
|
2009-08-27 14:03:53 +08:00
|
|
|
if (getPrimaryContext() != this)
|
|
|
|
return getPrimaryContext()->Encloses(DC);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-08-27 14:03:53 +08:00
|
|
|
for (; DC; DC = DC->getParent())
|
|
|
|
if (DC->getPrimaryContext() == this)
|
|
|
|
return true;
|
2009-09-09 23:08:12 +08:00
|
|
|
return false;
|
2009-08-27 14:03:53 +08:00
|
|
|
}
|
|
|
|
|
2009-01-09 01:28:14 +08:00
|
|
|
DeclContext *DeclContext::getPrimaryContext() {
|
2018-08-02 04:48:16 +08:00
|
|
|
switch (getDeclKind()) {
|
2008-12-12 00:49:14 +08:00
|
|
|
case Decl::TranslationUnit:
|
2015-03-07 08:04:49 +08:00
|
|
|
case Decl::ExternCContext:
|
2009-01-06 03:45:36 +08:00
|
|
|
case Decl::LinkageSpec:
|
2016-09-09 07:14:54 +08:00
|
|
|
case Decl::Export:
|
2009-09-09 23:08:12 +08:00
|
|
|
case Decl::Block:
|
2013-04-17 03:37:38 +08:00
|
|
|
case Decl::Captured:
|
2016-03-03 13:21:39 +08:00
|
|
|
case Decl::OMPDeclareReduction:
|
2019-02-02 04:25:04 +08:00
|
|
|
case Decl::OMPDeclareMapper:
|
2008-12-12 00:49:14 +08:00
|
|
|
// There is only one DeclContext for these entities.
|
|
|
|
return this;
|
|
|
|
|
|
|
|
case Decl::Namespace:
|
|
|
|
// The original namespace is our primary context.
|
2018-04-10 06:14:10 +08:00
|
|
|
return static_cast<NamespaceDecl *>(this)->getOriginalNamespace();
|
2008-12-12 00:49:14 +08:00
|
|
|
|
|
|
|
case Decl::ObjCMethod:
|
|
|
|
return this;
|
|
|
|
|
|
|
|
case Decl::ObjCInterface:
|
2019-03-19 14:14:14 +08:00
|
|
|
if (auto *OID = dyn_cast<ObjCInterfaceDecl>(this))
|
|
|
|
if (auto *Def = OID->getDefinition())
|
|
|
|
return Def;
|
2011-12-16 02:03:09 +08:00
|
|
|
return this;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2009-01-09 01:28:14 +08:00
|
|
|
case Decl::ObjCProtocol:
|
2019-03-19 14:14:14 +08:00
|
|
|
if (auto *OPD = dyn_cast<ObjCProtocolDecl>(this))
|
|
|
|
if (auto *Def = OPD->getDefinition())
|
|
|
|
return Def;
|
2012-01-02 03:51:50 +08:00
|
|
|
return this;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2009-01-09 01:28:14 +08:00
|
|
|
case Decl::ObjCCategory:
|
2008-12-12 00:49:14 +08:00
|
|
|
return this;
|
|
|
|
|
2009-01-09 01:28:14 +08:00
|
|
|
case Decl::ObjCImplementation:
|
|
|
|
case Decl::ObjCCategoryImpl:
|
|
|
|
return this;
|
|
|
|
|
2008-12-12 00:49:14 +08:00
|
|
|
default:
|
2018-08-02 04:48:16 +08:00
|
|
|
if (getDeclKind() >= Decl::firstTag && getDeclKind() <= Decl::lastTag) {
|
2009-02-18 07:15:12 +08:00
|
|
|
// If this is a tag type that has a definition or is currently
|
|
|
|
// being defined, that definition is our primary context.
|
2018-04-10 06:14:10 +08:00
|
|
|
auto *Tag = cast<TagDecl>(this);
|
2010-03-10 11:28:59 +08:00
|
|
|
|
|
|
|
if (TagDecl *Def = Tag->getDefinition())
|
|
|
|
return Def;
|
|
|
|
|
2018-04-10 06:14:10 +08:00
|
|
|
if (const auto *TagTy = dyn_cast<TagType>(Tag->getTypeForDecl())) {
|
2014-04-24 02:20:42 +08:00
|
|
|
// Note, TagType::getDecl returns the (partial) definition one exists.
|
|
|
|
TagDecl *PossiblePartialDef = TagTy->getDecl();
|
|
|
|
if (PossiblePartialDef->isBeingDefined())
|
|
|
|
return PossiblePartialDef;
|
|
|
|
} else {
|
|
|
|
assert(isa<InjectedClassNameType>(Tag->getTypeForDecl()));
|
2010-03-10 11:28:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return Tag;
|
2009-02-18 07:15:12 +08:00
|
|
|
}
|
|
|
|
|
2018-08-02 04:48:16 +08:00
|
|
|
assert(getDeclKind() >= Decl::firstFunction &&
|
|
|
|
getDeclKind() <= Decl::lastFunction &&
|
2008-12-12 00:49:14 +08:00
|
|
|
"Unknown DeclContext kind");
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-31 03:24:48 +08:00
|
|
|
void
|
2013-01-13 03:30:44 +08:00
|
|
|
DeclContext::collectAllContexts(SmallVectorImpl<DeclContext *> &Contexts){
|
2012-01-07 17:11:48 +08:00
|
|
|
Contexts.clear();
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2018-08-02 04:48:16 +08:00
|
|
|
if (getDeclKind() != Decl::Namespace) {
|
2012-01-07 17:11:48 +08:00
|
|
|
Contexts.push_back(this);
|
|
|
|
return;
|
2008-12-12 00:49:14 +08:00
|
|
|
}
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2018-04-10 06:14:10 +08:00
|
|
|
auto *Self = static_cast<NamespaceDecl *>(this);
|
2012-01-15 00:38:05 +08:00
|
|
|
for (NamespaceDecl *N = Self->getMostRecentDecl(); N;
|
|
|
|
N = N->getPreviousDecl())
|
2012-01-07 17:11:48 +08:00
|
|
|
Contexts.push_back(N);
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2012-01-07 17:11:48 +08:00
|
|
|
std::reverse(Contexts.begin(), Contexts.end());
|
2008-12-12 00:49:14 +08:00
|
|
|
}
|
|
|
|
|
2010-10-15 04:14:34 +08:00
|
|
|
std::pair<Decl *, Decl *>
|
2018-04-10 06:14:10 +08:00
|
|
|
DeclContext::BuildDeclChain(ArrayRef<Decl *> Decls,
|
2011-10-08 05:55:43 +08:00
|
|
|
bool FieldsAlreadyLoaded) {
|
2012-01-07 00:59:53 +08:00
|
|
|
// Build up a chain of declarations via the Decl::NextInContextAndBits field.
|
2014-05-12 13:36:57 +08:00
|
|
|
Decl *FirstNewDecl = nullptr;
|
|
|
|
Decl *PrevDecl = nullptr;
|
2018-04-10 06:14:10 +08:00
|
|
|
for (auto *D : Decls) {
|
|
|
|
if (FieldsAlreadyLoaded && isa<FieldDecl>(D))
|
2011-10-08 05:55:43 +08:00
|
|
|
continue;
|
|
|
|
|
2010-10-15 04:14:34 +08:00
|
|
|
if (PrevDecl)
|
2012-01-07 00:59:53 +08:00
|
|
|
PrevDecl->NextInContextAndBits.setPointer(D);
|
2010-10-15 04:14:34 +08:00
|
|
|
else
|
|
|
|
FirstNewDecl = D;
|
|
|
|
|
|
|
|
PrevDecl = D;
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::make_pair(FirstNewDecl, PrevDecl);
|
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// We have just acquired external visible storage, and we already have
|
2013-02-07 11:37:08 +08:00
|
|
|
/// built a lookup map. For every name in the map, pull in the new names from
|
|
|
|
/// the external storage.
|
2014-03-25 08:34:21 +08:00
|
|
|
void DeclContext::reconcileExternalVisibleStorage() const {
|
2018-08-02 04:48:16 +08:00
|
|
|
assert(hasNeedToReconcileExternalVisibleStorage() && LookupPtr);
|
|
|
|
setNeedToReconcileExternalVisibleStorage(false);
|
2013-02-07 11:37:08 +08:00
|
|
|
|
2015-03-23 11:25:59 +08:00
|
|
|
for (auto &Lookup : *LookupPtr)
|
2014-03-25 08:34:21 +08:00
|
|
|
Lookup.second.setHasExternalDecls();
|
2013-02-07 11:37:08 +08:00
|
|
|
}
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Load the declarations within this lexical storage from an
|
2009-04-10 06:27:44 +08:00
|
|
|
/// external source.
|
2015-03-24 10:44:20 +08:00
|
|
|
/// \return \c true if any declarations were added.
|
|
|
|
bool
|
2009-06-30 10:36:12 +08:00
|
|
|
DeclContext::LoadLexicalDeclsFromExternalStorage() const {
|
|
|
|
ExternalASTSource *Source = getParentASTContext().getExternalSource();
|
2009-04-10 06:27:44 +08:00
|
|
|
assert(hasExternalLexicalStorage() && Source && "No external storage?");
|
|
|
|
|
2010-07-30 18:03:23 +08:00
|
|
|
// Notify that we have a DeclContext that is initializing.
|
|
|
|
ExternalASTSource::Deserializing ADeclContext(Source);
|
2015-03-23 11:25:59 +08:00
|
|
|
|
2011-07-16 05:46:17 +08:00
|
|
|
// Load the external declarations, if any.
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<Decl*, 64> Decls;
|
2018-08-02 04:48:16 +08:00
|
|
|
setHasExternalLexicalStorage(false);
|
2015-08-06 06:41:45 +08:00
|
|
|
Source->FindExternalLexicalDecls(this, Decls);
|
2009-04-10 06:27:44 +08:00
|
|
|
|
|
|
|
if (Decls.empty())
|
2015-03-24 10:44:20 +08:00
|
|
|
return false;
|
2015-03-23 11:25:59 +08:00
|
|
|
|
2011-10-08 05:55:43 +08:00
|
|
|
// We may have already loaded just the fields of this record, in which case
|
|
|
|
// we need to ignore them.
|
|
|
|
bool FieldsAlreadyLoaded = false;
|
2018-04-10 06:14:10 +08:00
|
|
|
if (const auto *RD = dyn_cast<RecordDecl>(this))
|
2018-08-02 04:48:16 +08:00
|
|
|
FieldsAlreadyLoaded = RD->hasLoadedFieldsFromExternalStorage();
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2009-04-10 06:27:44 +08:00
|
|
|
// Splice the newly-read declarations into the beginning of the list
|
|
|
|
// of declarations.
|
2010-10-15 04:14:34 +08:00
|
|
|
Decl *ExternalFirst, *ExternalLast;
|
2014-03-02 21:01:17 +08:00
|
|
|
std::tie(ExternalFirst, ExternalLast) =
|
|
|
|
BuildDeclChain(Decls, FieldsAlreadyLoaded);
|
2012-01-07 00:59:53 +08:00
|
|
|
ExternalLast->NextInContextAndBits.setPointer(FirstDecl);
|
2010-10-15 04:14:34 +08:00
|
|
|
FirstDecl = ExternalFirst;
|
2009-04-10 06:27:44 +08:00
|
|
|
if (!LastDecl)
|
2010-10-15 04:14:34 +08:00
|
|
|
LastDecl = ExternalLast;
|
2015-03-24 10:44:20 +08:00
|
|
|
return true;
|
2009-04-10 06:27:44 +08:00
|
|
|
}
|
|
|
|
|
2010-06-01 17:23:16 +08:00
|
|
|
DeclContext::lookup_result
|
|
|
|
ExternalASTSource::SetNoExternalVisibleDeclsForName(const DeclContext *DC,
|
|
|
|
DeclarationName Name) {
|
|
|
|
ASTContext &Context = DC->getParentASTContext();
|
|
|
|
StoredDeclsMap *Map;
|
2015-03-23 11:25:59 +08:00
|
|
|
if (!(Map = DC->LookupPtr))
|
2010-06-01 17:23:16 +08:00
|
|
|
Map = DC->CreateStoredDeclsMap(Context);
|
2018-08-02 04:48:16 +08:00
|
|
|
if (DC->hasNeedToReconcileExternalVisibleStorage())
|
2014-03-25 08:34:21 +08:00
|
|
|
DC->reconcileExternalVisibleStorage();
|
2010-06-01 17:23:16 +08:00
|
|
|
|
2013-09-09 15:34:56 +08:00
|
|
|
(*Map)[Name].removeExternalDecls();
|
2010-06-01 17:23:16 +08:00
|
|
|
|
|
|
|
return DeclContext::lookup_result();
|
|
|
|
}
|
2009-04-10 06:27:44 +08:00
|
|
|
|
2010-06-01 17:23:16 +08:00
|
|
|
DeclContext::lookup_result
|
|
|
|
ExternalASTSource::SetExternalVisibleDeclsForName(const DeclContext *DC,
|
|
|
|
DeclarationName Name,
|
2011-09-09 14:44:14 +08:00
|
|
|
ArrayRef<NamedDecl*> Decls) {
|
2012-09-11 05:20:09 +08:00
|
|
|
ASTContext &Context = DC->getParentASTContext();
|
2010-06-01 17:23:16 +08:00
|
|
|
StoredDeclsMap *Map;
|
2015-03-23 11:25:59 +08:00
|
|
|
if (!(Map = DC->LookupPtr))
|
2010-06-01 17:23:16 +08:00
|
|
|
Map = DC->CreateStoredDeclsMap(Context);
|
2018-08-02 04:48:16 +08:00
|
|
|
if (DC->hasNeedToReconcileExternalVisibleStorage())
|
2014-03-25 08:34:21 +08:00
|
|
|
DC->reconcileExternalVisibleStorage();
|
2009-04-10 06:27:44 +08:00
|
|
|
|
2010-06-01 17:23:16 +08:00
|
|
|
StoredDeclsList &List = (*Map)[Name];
|
2013-06-24 09:46:41 +08:00
|
|
|
|
|
|
|
// Clear out any old external visible declarations, to avoid quadratic
|
|
|
|
// performance in the redeclaration checks below.
|
|
|
|
List.removeExternalDecls();
|
|
|
|
|
|
|
|
if (!List.isNull()) {
|
|
|
|
// We have both existing declarations and new declarations for this name.
|
|
|
|
// Some of the declarations may simply replace existing ones. Handle those
|
|
|
|
// first.
|
|
|
|
llvm::SmallVector<unsigned, 8> Skip;
|
|
|
|
for (unsigned I = 0, N = Decls.size(); I != N; ++I)
|
2015-02-10 11:28:10 +08:00
|
|
|
if (List.HandleRedeclaration(Decls[I], /*IsKnownNewer*/false))
|
2013-06-24 09:46:41 +08:00
|
|
|
Skip.push_back(I);
|
|
|
|
Skip.push_back(Decls.size());
|
|
|
|
|
|
|
|
// Add in any new declarations.
|
|
|
|
unsigned SkipPos = 0;
|
|
|
|
for (unsigned I = 0, N = Decls.size(); I != N; ++I) {
|
|
|
|
if (I == Skip[SkipPos])
|
|
|
|
++SkipPos;
|
|
|
|
else
|
|
|
|
List.AddSubsequentDecl(Decls[I]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Convert the array to a StoredDeclsList.
|
2018-04-10 06:14:10 +08:00
|
|
|
for (auto *D : Decls) {
|
2013-06-24 09:46:41 +08:00
|
|
|
if (List.isNull())
|
2018-04-10 06:14:10 +08:00
|
|
|
List.setOnlyValue(D);
|
2013-06-24 09:46:41 +08:00
|
|
|
else
|
2018-04-10 06:14:10 +08:00
|
|
|
List.AddSubsequentDecl(D);
|
2013-06-24 09:46:41 +08:00
|
|
|
}
|
2010-06-01 17:23:16 +08:00
|
|
|
}
|
|
|
|
|
2010-08-21 00:04:35 +08:00
|
|
|
return List.getLookupResult();
|
2010-06-01 17:23:16 +08:00
|
|
|
}
|
|
|
|
|
2014-03-08 06:17:20 +08:00
|
|
|
DeclContext::decl_iterator DeclContext::decls_begin() const {
|
|
|
|
if (hasExternalLexicalStorage())
|
|
|
|
LoadLexicalDeclsFromExternalStorage();
|
|
|
|
return decl_iterator(FirstDecl);
|
|
|
|
}
|
|
|
|
|
2009-06-30 10:36:12 +08:00
|
|
|
bool DeclContext::decls_empty() const {
|
2009-04-11 01:25:41 +08:00
|
|
|
if (hasExternalLexicalStorage())
|
2009-06-30 10:36:12 +08:00
|
|
|
LoadLexicalDeclsFromExternalStorage();
|
2009-04-11 01:25:41 +08:00
|
|
|
|
|
|
|
return !FirstDecl;
|
|
|
|
}
|
|
|
|
|
2013-05-04 10:04:27 +08:00
|
|
|
bool DeclContext::containsDecl(Decl *D) const {
|
|
|
|
return (D->getLexicalDeclContext() == this &&
|
|
|
|
(D->NextInContextAndBits.getPointer() || D == LastDecl));
|
|
|
|
}
|
|
|
|
|
Re-apply: [ASTImporter] Import the whole redecl chain of functions
Summary:
With this patch when any `FunctionDecl` of a redeclaration chain is imported
then we bring in the whole declaration chain. This involves functions and
function template specializations. Also friend functions are affected. The
chain is imported as it is in the "from" tu, the order of the redeclarations
are kept. I also changed the lookup logic in order to find friends, but first
making them visible in their declaration context. We may have long
redeclaration chains if all TU contains the same prototype, but our
measurements shows no degradation in time of CTU analysis (Tmux, Xerces,
Bitcoin, Protobuf). Also, as further work we could squash redundant
prototypes, but first ensure that functionality is working properly; then
should we optimize.
This may seem like a huge patch, sorry about that. But, most of the changes are
new tests, changes in the production code is not that much. I also tried to
create a smaller patch which does not affect specializations, but that patch
failed to pass some of the `clang-import-test`s because there we import
function specializations. Also very importantly, we can't just change the
import of `FunctionDecl`s without changing the import of function template
specializations because they are handled as `FunctionDecl`s.
Reviewers: a.sidorin, r.stahl, xazax.hun, balazske, a_sidorin
Reviewed By: a_sidorin
Subscribers: labath, aprantl, a_sidorin, rnkovacs, dkrupp, cfe-commits
Differential Revision: https://reviews.llvm.org/D47532
Re-apply commit rC335480
llvm-svn: 335731
2018-06-27 21:32:50 +08:00
|
|
|
bool DeclContext::containsDeclAndLoad(Decl *D) const {
|
|
|
|
if (hasExternalLexicalStorage())
|
|
|
|
LoadLexicalDeclsFromExternalStorage();
|
|
|
|
return containsDecl(D);
|
|
|
|
}
|
|
|
|
|
2018-05-18 17:08:47 +08:00
|
|
|
/// shouldBeHidden - Determine whether a declaration which was declared
|
|
|
|
/// within its semantic context should be invisible to qualified name lookup.
|
|
|
|
static bool shouldBeHidden(NamedDecl *D) {
|
|
|
|
// Skip unnamed declarations.
|
|
|
|
if (!D->getDeclName())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Skip entities that can't be found by name lookup into a particular
|
|
|
|
// context.
|
|
|
|
if ((D->getIdentifierNamespace() == 0 && !isa<UsingDirectiveDecl>(D)) ||
|
|
|
|
D->isTemplateParameter())
|
|
|
|
return true;
|
|
|
|
|
2019-01-07 14:00:46 +08:00
|
|
|
// Skip friends and local extern declarations unless they're the first
|
|
|
|
// declaration of the entity.
|
|
|
|
if ((D->isLocalExternDecl() || D->getFriendObjectKind()) &&
|
|
|
|
D != D->getCanonicalDecl())
|
|
|
|
return true;
|
|
|
|
|
2018-05-18 17:08:47 +08:00
|
|
|
// Skip template specializations.
|
|
|
|
// FIXME: This feels like a hack. Should DeclarationName support
|
|
|
|
// template-ids, or is there a better way to keep specializations
|
|
|
|
// from being visible?
|
|
|
|
if (isa<ClassTemplateSpecializationDecl>(D))
|
|
|
|
return true;
|
|
|
|
if (auto *FD = dyn_cast<FunctionDecl>(D))
|
|
|
|
if (FD->isFunctionTemplateSpecialization())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-12-10 17:41:52 +08:00
|
|
|
void DeclContext::removeDecl(Decl *D) {
|
|
|
|
assert(D->getLexicalDeclContext() == this &&
|
|
|
|
"decl being removed from non-lexical context");
|
2012-01-07 00:59:53 +08:00
|
|
|
assert((D->NextInContextAndBits.getPointer() || D == LastDecl) &&
|
2009-12-10 17:41:52 +08:00
|
|
|
"decl is not in decls list");
|
|
|
|
|
|
|
|
// Remove D from the decl chain. This is O(n) but hopefully rare.
|
|
|
|
if (D == FirstDecl) {
|
|
|
|
if (D == LastDecl)
|
2014-05-12 13:36:57 +08:00
|
|
|
FirstDecl = LastDecl = nullptr;
|
2009-12-10 17:41:52 +08:00
|
|
|
else
|
2012-01-07 00:59:53 +08:00
|
|
|
FirstDecl = D->NextInContextAndBits.getPointer();
|
2009-12-10 17:41:52 +08:00
|
|
|
} else {
|
2012-01-07 00:59:53 +08:00
|
|
|
for (Decl *I = FirstDecl; true; I = I->NextInContextAndBits.getPointer()) {
|
2009-12-10 17:41:52 +08:00
|
|
|
assert(I && "decl not found in linked list");
|
2012-01-07 00:59:53 +08:00
|
|
|
if (I->NextInContextAndBits.getPointer() == D) {
|
|
|
|
I->NextInContextAndBits.setPointer(D->NextInContextAndBits.getPointer());
|
2009-12-10 17:41:52 +08:00
|
|
|
if (D == LastDecl) LastDecl = I;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-18 17:08:47 +08:00
|
|
|
|
2009-12-10 17:41:52 +08:00
|
|
|
// Mark that D is no longer in the decl chain.
|
2014-05-12 13:36:57 +08:00
|
|
|
D->NextInContextAndBits.setPointer(nullptr);
|
2009-12-10 17:41:52 +08:00
|
|
|
|
|
|
|
// Remove D from the lookup table if necessary.
|
|
|
|
if (isa<NamedDecl>(D)) {
|
2018-04-10 06:14:10 +08:00
|
|
|
auto *ND = cast<NamedDecl>(D);
|
2009-12-10 17:41:52 +08:00
|
|
|
|
2018-05-18 17:08:47 +08:00
|
|
|
// Do not try to remove the declaration if that is invisible to qualified
|
|
|
|
// lookup. E.g. template specializations are skipped.
|
|
|
|
if (shouldBeHidden(ND))
|
|
|
|
return;
|
|
|
|
|
2011-08-26 22:06:12 +08:00
|
|
|
// Remove only decls that have a name
|
2018-05-18 17:08:47 +08:00
|
|
|
if (!ND->getDeclName())
|
|
|
|
return;
|
2011-08-26 22:06:12 +08:00
|
|
|
|
2017-06-20 22:59:57 +08:00
|
|
|
auto *DC = D->getDeclContext();
|
2015-11-13 11:52:13 +08:00
|
|
|
do {
|
|
|
|
StoredDeclsMap *Map = DC->getPrimaryContext()->LookupPtr;
|
|
|
|
if (Map) {
|
|
|
|
StoredDeclsMap::iterator Pos = Map->find(ND->getDeclName());
|
|
|
|
assert(Pos != Map->end() && "no lookup entry for decl");
|
2018-12-17 20:42:12 +08:00
|
|
|
// Remove the decl only if it is contained.
|
|
|
|
StoredDeclsList::DeclsTy *Vec = Pos->second.getAsVector();
|
|
|
|
if ((Vec && is_contained(*Vec, ND)) || Pos->second.getAsDecl() == ND)
|
2015-11-13 11:52:13 +08:00
|
|
|
Pos->second.remove(ND);
|
|
|
|
}
|
|
|
|
} while (DC->isTransparentContext() && (DC = DC->getParent()));
|
2009-12-10 17:41:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-11 14:59:38 +08:00
|
|
|
void DeclContext::addHiddenDecl(Decl *D) {
|
2009-02-20 08:56:18 +08:00
|
|
|
assert(D->getLexicalDeclContext() == this &&
|
|
|
|
"Decl inserted into wrong lexical context");
|
2009-09-09 23:08:12 +08:00
|
|
|
assert(!D->getNextDeclInContext() && D != LastDecl &&
|
2009-01-10 03:42:16 +08:00
|
|
|
"Decl already inserted into a DeclContext");
|
|
|
|
|
|
|
|
if (FirstDecl) {
|
2012-01-07 00:59:53 +08:00
|
|
|
LastDecl->NextInContextAndBits.setPointer(D);
|
2009-01-10 03:42:16 +08:00
|
|
|
LastDecl = D;
|
|
|
|
} else {
|
|
|
|
FirstDecl = LastDecl = D;
|
|
|
|
}
|
2010-09-28 06:06:20 +08:00
|
|
|
|
|
|
|
// Notify a C++ record declaration that we've added a member, so it can
|
2015-10-19 04:32:12 +08:00
|
|
|
// update its class-specific state.
|
2018-04-10 06:14:10 +08:00
|
|
|
if (auto *Record = dyn_cast<CXXRecordDecl>(this))
|
2010-09-28 06:06:20 +08:00
|
|
|
Record->addedMember(D);
|
2011-12-03 08:30:27 +08:00
|
|
|
|
|
|
|
// If this is a newly-created (not de-serialized) import declaration, wire
|
|
|
|
// it in to the list of local import declarations.
|
|
|
|
if (!D->isFromASTFile()) {
|
2018-04-10 06:14:10 +08:00
|
|
|
if (auto *Import = dyn_cast<ImportDecl>(D))
|
2011-12-03 08:30:27 +08:00
|
|
|
D->getASTContext().addedLocalImportDecl(Import);
|
|
|
|
}
|
2009-08-11 14:59:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeclContext::addDecl(Decl *D) {
|
|
|
|
addHiddenDecl(D);
|
2009-01-20 09:17:11 +08:00
|
|
|
|
2018-04-10 06:14:10 +08:00
|
|
|
if (auto *ND = dyn_cast<NamedDecl>(D))
|
2012-03-16 14:12:59 +08:00
|
|
|
ND->getDeclContext()->getPrimaryContext()->
|
|
|
|
makeDeclVisibleInContextWithFlags(ND, false, true);
|
2008-12-12 00:49:14 +08:00
|
|
|
}
|
|
|
|
|
2011-10-21 10:57:43 +08:00
|
|
|
void DeclContext::addDeclInternal(Decl *D) {
|
|
|
|
addHiddenDecl(D);
|
|
|
|
|
2018-04-10 06:14:10 +08:00
|
|
|
if (auto *ND = dyn_cast<NamedDecl>(D))
|
2012-03-16 14:12:59 +08:00
|
|
|
ND->getDeclContext()->getPrimaryContext()->
|
|
|
|
makeDeclVisibleInContextWithFlags(ND, true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// buildLookup - Build the lookup data structure with all of the
|
|
|
|
/// declarations in this DeclContext (and any other contexts linked
|
|
|
|
/// to it or transparent contexts nested within it) and return it.
|
2014-03-25 08:34:21 +08:00
|
|
|
///
|
|
|
|
/// Note that the produced map may miss out declarations from an
|
|
|
|
/// external source. If it does, those entries will be marked with
|
|
|
|
/// the 'hasExternalDecls' flag.
|
2012-03-16 14:12:59 +08:00
|
|
|
StoredDeclsMap *DeclContext::buildLookup() {
|
|
|
|
assert(this == getPrimaryContext() && "buildLookup called on non-primary DC");
|
|
|
|
|
2018-08-02 04:48:16 +08:00
|
|
|
if (!hasLazyLocalLexicalLookups() &&
|
|
|
|
!hasLazyExternalLexicalLookups())
|
2015-03-23 11:25:59 +08:00
|
|
|
return LookupPtr;
|
|
|
|
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<DeclContext *, 2> Contexts;
|
2012-03-16 14:12:59 +08:00
|
|
|
collectAllContexts(Contexts);
|
2015-03-24 10:44:20 +08:00
|
|
|
|
2018-08-02 04:48:16 +08:00
|
|
|
if (hasLazyExternalLexicalLookups()) {
|
|
|
|
setHasLazyExternalLexicalLookups(false);
|
2015-03-24 10:44:20 +08:00
|
|
|
for (auto *DC : Contexts) {
|
2018-08-02 04:48:16 +08:00
|
|
|
if (DC->hasExternalLexicalStorage()) {
|
|
|
|
bool LoadedDecls = DC->LoadLexicalDeclsFromExternalStorage();
|
|
|
|
setHasLazyLocalLexicalLookups(
|
|
|
|
hasLazyLocalLexicalLookups() | LoadedDecls );
|
|
|
|
}
|
2015-03-24 10:44:20 +08:00
|
|
|
}
|
|
|
|
|
2018-08-02 04:48:16 +08:00
|
|
|
if (!hasLazyLocalLexicalLookups())
|
2015-03-24 10:44:20 +08:00
|
|
|
return LookupPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto *DC : Contexts)
|
|
|
|
buildLookupImpl(DC, hasExternalVisibleStorage());
|
2012-03-16 14:12:59 +08:00
|
|
|
|
|
|
|
// We no longer have any lazy decls.
|
2018-08-02 04:48:16 +08:00
|
|
|
setHasLazyLocalLexicalLookups(false);
|
2015-03-23 11:25:59 +08:00
|
|
|
return LookupPtr;
|
2012-03-16 14:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// buildLookupImpl - Build part of the lookup data structure for the
|
|
|
|
/// declarations contained within DCtx, which will either be this
|
|
|
|
/// DeclContext, a DeclContext linked to it, or a transparent context
|
|
|
|
/// nested within it.
|
2015-02-07 08:45:52 +08:00
|
|
|
void DeclContext::buildLookupImpl(DeclContext *DCtx, bool Internal) {
|
2018-04-10 06:14:10 +08:00
|
|
|
for (auto *D : DCtx->noload_decls()) {
|
2012-03-16 14:12:59 +08:00
|
|
|
// Insert this declaration into the lookup structure, but only if
|
|
|
|
// it's semantically within its decl context. Any other decls which
|
|
|
|
// should be found in this context are added eagerly.
|
2013-06-24 15:20:36 +08:00
|
|
|
//
|
|
|
|
// If it's from an AST file, don't add it now. It'll get handled by
|
|
|
|
// FindExternalVisibleDeclsByName if needed. Exception: if we're not
|
|
|
|
// in C++, we do not track external visible decls for the TU, so in
|
|
|
|
// that case we need to collect them all here.
|
2018-04-10 06:14:10 +08:00
|
|
|
if (auto *ND = dyn_cast<NamedDecl>(D))
|
2013-06-24 15:20:36 +08:00
|
|
|
if (ND->getDeclContext() == DCtx && !shouldBeHidden(ND) &&
|
|
|
|
(!ND->isFromASTFile() ||
|
|
|
|
(isTranslationUnit() &&
|
|
|
|
!getParentASTContext().getLangOpts().CPlusPlus)))
|
2015-02-07 08:45:52 +08:00
|
|
|
makeDeclVisibleInContextImpl(ND, Internal);
|
2012-03-16 14:12:59 +08:00
|
|
|
|
|
|
|
// If this declaration is itself a transparent declaration context
|
|
|
|
// or inline namespace, add the members of this declaration of that
|
|
|
|
// context (recursively).
|
2018-04-10 06:14:10 +08:00
|
|
|
if (auto *InnerCtx = dyn_cast<DeclContext>(D))
|
2012-03-16 14:12:59 +08:00
|
|
|
if (InnerCtx->isTransparentContext() || InnerCtx->isInlineNamespace())
|
2015-03-23 11:25:59 +08:00
|
|
|
buildLookupImpl(InnerCtx, Internal);
|
2012-03-16 14:12:59 +08:00
|
|
|
}
|
2011-10-21 10:57:43 +08:00
|
|
|
}
|
|
|
|
|
2015-02-21 10:31:57 +08:00
|
|
|
NamedDecl *const DeclContextLookupResult::SingleElementDummyList = nullptr;
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
DeclContext::lookup_result
|
2015-02-21 10:31:57 +08:00
|
|
|
DeclContext::lookup(DeclarationName Name) const {
|
2018-08-02 04:48:16 +08:00
|
|
|
assert(getDeclKind() != Decl::LinkageSpec &&
|
|
|
|
getDeclKind() != Decl::Export &&
|
2016-09-09 07:14:54 +08:00
|
|
|
"should not perform lookups into transparent contexts");
|
2012-03-13 12:12:34 +08:00
|
|
|
|
2016-09-10 03:03:07 +08:00
|
|
|
const DeclContext *PrimaryContext = getPrimaryContext();
|
|
|
|
if (PrimaryContext != this)
|
|
|
|
return PrimaryContext->lookup(Name);
|
|
|
|
|
2015-02-26 06:20:13 +08:00
|
|
|
// If we have an external source, ensure that any later redeclarations of this
|
|
|
|
// context have been loaded, since they may add names to the result of this
|
|
|
|
// lookup (or add external visible storage).
|
|
|
|
ExternalASTSource *Source = getParentASTContext().getExternalSource();
|
|
|
|
if (Source)
|
|
|
|
(void)cast<Decl>(this)->getMostRecentDecl();
|
2014-08-13 09:23:33 +08:00
|
|
|
|
2012-03-13 11:12:56 +08:00
|
|
|
if (hasExternalVisibleStorage()) {
|
2015-02-26 06:20:13 +08:00
|
|
|
assert(Source && "external visible storage but no external source?");
|
|
|
|
|
2018-08-02 04:48:16 +08:00
|
|
|
if (hasNeedToReconcileExternalVisibleStorage())
|
2014-03-25 08:34:21 +08:00
|
|
|
reconcileExternalVisibleStorage();
|
|
|
|
|
2015-03-23 11:25:59 +08:00
|
|
|
StoredDeclsMap *Map = LookupPtr;
|
2014-03-25 08:34:21 +08:00
|
|
|
|
2018-08-02 04:48:16 +08:00
|
|
|
if (hasLazyLocalLexicalLookups() ||
|
|
|
|
hasLazyExternalLexicalLookups())
|
2015-02-21 10:31:57 +08:00
|
|
|
// FIXME: Make buildLookup const?
|
|
|
|
Map = const_cast<DeclContext*>(this)->buildLookup();
|
2013-02-07 11:37:08 +08:00
|
|
|
|
2013-02-08 08:37:45 +08:00
|
|
|
if (!Map)
|
|
|
|
Map = CreateStoredDeclsMap(getParentASTContext());
|
|
|
|
|
2013-09-09 15:34:56 +08:00
|
|
|
// If we have a lookup result with no external decls, we are done.
|
2013-02-08 08:37:45 +08:00
|
|
|
std::pair<StoredDeclsMap::iterator, bool> R =
|
|
|
|
Map->insert(std::make_pair(Name, StoredDeclsList()));
|
2013-09-09 15:34:56 +08:00
|
|
|
if (!R.second && !R.first->second.hasExternalDecls())
|
2013-02-08 08:37:45 +08:00
|
|
|
return R.first->second.getLookupResult();
|
2012-03-16 14:12:59 +08:00
|
|
|
|
2014-03-04 08:21:14 +08:00
|
|
|
if (Source->FindExternalVisibleDeclsByName(this, Name) || !R.second) {
|
2015-03-23 11:25:59 +08:00
|
|
|
if (StoredDeclsMap *Map = LookupPtr) {
|
2013-02-07 11:30:24 +08:00
|
|
|
StoredDeclsMap::iterator I = Map->find(Name);
|
|
|
|
if (I != Map->end())
|
|
|
|
return I->second.getLookupResult();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-10 06:14:10 +08:00
|
|
|
return {};
|
2010-06-01 17:23:16 +08:00
|
|
|
}
|
2009-04-10 06:27:44 +08:00
|
|
|
|
2015-03-23 11:25:59 +08:00
|
|
|
StoredDeclsMap *Map = LookupPtr;
|
2018-08-02 04:48:16 +08:00
|
|
|
if (hasLazyLocalLexicalLookups() ||
|
|
|
|
hasLazyExternalLexicalLookups())
|
2015-02-21 10:31:57 +08:00
|
|
|
Map = const_cast<DeclContext*>(this)->buildLookup();
|
2012-03-16 14:12:59 +08:00
|
|
|
|
|
|
|
if (!Map)
|
2018-04-10 06:14:10 +08:00
|
|
|
return {};
|
2012-03-16 14:12:59 +08:00
|
|
|
|
|
|
|
StoredDeclsMap::iterator I = Map->find(Name);
|
|
|
|
if (I == Map->end())
|
2018-04-10 06:14:10 +08:00
|
|
|
return {};
|
2012-03-16 14:12:59 +08:00
|
|
|
|
|
|
|
return I->second.getLookupResult();
|
2008-12-12 00:49:14 +08:00
|
|
|
}
|
|
|
|
|
2013-07-13 10:00:19 +08:00
|
|
|
DeclContext::lookup_result
|
|
|
|
DeclContext::noload_lookup(DeclarationName Name) {
|
2018-08-02 04:48:16 +08:00
|
|
|
assert(getDeclKind() != Decl::LinkageSpec &&
|
|
|
|
getDeclKind() != Decl::Export &&
|
2016-09-09 07:14:54 +08:00
|
|
|
"should not perform lookups into transparent contexts");
|
2013-07-13 10:00:19 +08:00
|
|
|
|
|
|
|
DeclContext *PrimaryContext = getPrimaryContext();
|
|
|
|
if (PrimaryContext != this)
|
|
|
|
return PrimaryContext->noload_lookup(Name);
|
|
|
|
|
2018-01-16 20:33:46 +08:00
|
|
|
loadLazyLocalLexicalLookups();
|
2015-03-23 11:25:59 +08:00
|
|
|
StoredDeclsMap *Map = LookupPtr;
|
2013-07-13 10:00:19 +08:00
|
|
|
if (!Map)
|
2018-04-10 06:14:10 +08:00
|
|
|
return {};
|
2013-07-13 10:00:19 +08:00
|
|
|
|
|
|
|
StoredDeclsMap::iterator I = Map->find(Name);
|
2014-05-12 13:36:57 +08:00
|
|
|
return I != Map->end() ? I->second.getLookupResult()
|
2015-02-21 10:31:57 +08:00
|
|
|
: lookup_result();
|
2013-07-13 10:00:19 +08:00
|
|
|
}
|
|
|
|
|
2018-01-16 20:33:46 +08:00
|
|
|
// If we have any lazy lexical declarations not in our lookup map, add them
|
|
|
|
// now. Don't import any external declarations, not even if we know we have
|
|
|
|
// some missing from the external visible lookups.
|
|
|
|
void DeclContext::loadLazyLocalLexicalLookups() {
|
2018-08-02 04:48:16 +08:00
|
|
|
if (hasLazyLocalLexicalLookups()) {
|
2018-01-16 20:33:46 +08:00
|
|
|
SmallVector<DeclContext *, 2> Contexts;
|
|
|
|
collectAllContexts(Contexts);
|
2018-04-10 06:14:10 +08:00
|
|
|
for (auto *Context : Contexts)
|
|
|
|
buildLookupImpl(Context, hasExternalVisibleStorage());
|
2018-08-02 04:48:16 +08:00
|
|
|
setHasLazyLocalLexicalLookups(false);
|
2018-01-16 20:33:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-13 03:30:44 +08:00
|
|
|
void DeclContext::localUncachedLookup(DeclarationName Name,
|
|
|
|
SmallVectorImpl<NamedDecl *> &Results) {
|
2011-10-15 08:10:27 +08:00
|
|
|
Results.clear();
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2011-10-15 08:10:27 +08:00
|
|
|
// If there's no external storage, just perform a normal lookup and copy
|
|
|
|
// the results.
|
2012-07-18 05:16:27 +08:00
|
|
|
if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
|
2011-10-15 08:10:27 +08:00
|
|
|
lookup_result LookupResults = lookup(Name);
|
2012-12-19 08:45:41 +08:00
|
|
|
Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
|
2011-10-15 08:10:27 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have a lookup table, check there first. Maybe we'll get lucky.
|
2015-03-23 11:25:59 +08:00
|
|
|
// FIXME: Should we be checking these flags on the primary context?
|
2018-08-02 04:48:16 +08:00
|
|
|
if (Name && !hasLazyLocalLexicalLookups() &&
|
|
|
|
!hasLazyExternalLexicalLookups()) {
|
2015-03-23 11:25:59 +08:00
|
|
|
if (StoredDeclsMap *Map = LookupPtr) {
|
2012-07-18 05:16:27 +08:00
|
|
|
StoredDeclsMap::iterator Pos = Map->find(Name);
|
|
|
|
if (Pos != Map->end()) {
|
|
|
|
Results.insert(Results.end(),
|
2012-12-19 08:45:41 +08:00
|
|
|
Pos->second.getLookupResult().begin(),
|
|
|
|
Pos->second.getLookupResult().end());
|
2012-07-18 05:16:27 +08:00
|
|
|
return;
|
|
|
|
}
|
2011-10-15 08:10:27 +08:00
|
|
|
}
|
|
|
|
}
|
2012-07-18 05:16:27 +08:00
|
|
|
|
2018-07-31 03:24:48 +08:00
|
|
|
// Slow case: grovel through the declarations in our chain looking for
|
2011-10-15 08:10:27 +08:00
|
|
|
// matches.
|
2015-03-23 11:25:59 +08:00
|
|
|
// FIXME: If we have lazy external declarations, this will not find them!
|
|
|
|
// FIXME: Should we CollectAllContexts and walk them all here?
|
2011-10-15 08:10:27 +08:00
|
|
|
for (Decl *D = FirstDecl; D; D = D->getNextDeclInContext()) {
|
2018-04-10 06:14:10 +08:00
|
|
|
if (auto *ND = dyn_cast<NamedDecl>(D))
|
2011-10-15 08:10:27 +08:00
|
|
|
if (ND->getDeclName() == Name)
|
|
|
|
Results.push_back(ND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-31 08:36:30 +08:00
|
|
|
DeclContext *DeclContext::getRedeclContext() {
|
2009-03-28 03:19:59 +08:00
|
|
|
DeclContext *Ctx = this;
|
2018-10-24 03:44:51 +08:00
|
|
|
|
|
|
|
// In C, a record type is the redeclaration context for its fields only. If
|
|
|
|
// we arrive at a record context after skipping anything else, we should skip
|
|
|
|
// the record as well. Currently, this means skipping enumerations because
|
|
|
|
// they're the only transparent context that can exist within a struct or
|
|
|
|
// union.
|
|
|
|
bool SkipRecords = getDeclKind() == Decl::Kind::Enum &&
|
|
|
|
!getParentASTContext().getLangOpts().CPlusPlus;
|
|
|
|
|
|
|
|
// Skip through contexts to get to the redeclaration context. Transparent
|
|
|
|
// contexts are always skipped.
|
|
|
|
while ((SkipRecords && Ctx->isRecord()) || Ctx->isTransparentContext())
|
2009-01-07 07:51:29 +08:00
|
|
|
Ctx = Ctx->getParent();
|
|
|
|
return Ctx;
|
|
|
|
}
|
|
|
|
|
2009-02-26 06:02:03 +08:00
|
|
|
DeclContext *DeclContext::getEnclosingNamespaceContext() {
|
|
|
|
DeclContext *Ctx = this;
|
|
|
|
// Skip through non-namespace, non-translation-unit contexts.
|
2010-08-31 08:36:23 +08:00
|
|
|
while (!Ctx->isFileContext())
|
2009-02-26 06:02:03 +08:00
|
|
|
Ctx = Ctx->getParent();
|
|
|
|
return Ctx->getPrimaryContext();
|
|
|
|
}
|
|
|
|
|
2014-11-18 07:36:45 +08:00
|
|
|
RecordDecl *DeclContext::getOuterLexicalRecordContext() {
|
|
|
|
// Loop until we find a non-record context.
|
|
|
|
RecordDecl *OutermostRD = nullptr;
|
|
|
|
DeclContext *DC = this;
|
|
|
|
while (DC->isRecord()) {
|
|
|
|
OutermostRD = cast<RecordDecl>(DC);
|
|
|
|
DC = DC->getLexicalParent();
|
|
|
|
}
|
|
|
|
return OutermostRD;
|
|
|
|
}
|
|
|
|
|
2010-08-31 08:36:30 +08:00
|
|
|
bool DeclContext::InEnclosingNamespaceSetOf(const DeclContext *O) const {
|
|
|
|
// For non-file contexts, this is equivalent to Equals.
|
|
|
|
if (!isFileContext())
|
|
|
|
return O->Equals(this);
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (O->Equals(this))
|
|
|
|
return true;
|
|
|
|
|
2018-04-10 06:14:10 +08:00
|
|
|
const auto *NS = dyn_cast<NamespaceDecl>(O);
|
2010-08-31 08:36:30 +08:00
|
|
|
if (!NS || !NS->isInline())
|
|
|
|
break;
|
|
|
|
O = NS->getParent();
|
|
|
|
} while (O);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-16 14:12:59 +08:00
|
|
|
void DeclContext::makeDeclVisibleInContext(NamedDecl *D) {
|
|
|
|
DeclContext *PrimaryDC = this->getPrimaryContext();
|
|
|
|
DeclContext *DeclDC = D->getDeclContext()->getPrimaryContext();
|
|
|
|
// If the decl is being added outside of its semantic decl context, we
|
|
|
|
// need to ensure that we eagerly build the lookup information for it.
|
|
|
|
PrimaryDC->makeDeclVisibleInContextWithFlags(D, false, PrimaryDC == DeclDC);
|
2011-10-21 10:57:43 +08:00
|
|
|
}
|
|
|
|
|
2012-03-16 14:12:59 +08:00
|
|
|
void DeclContext::makeDeclVisibleInContextWithFlags(NamedDecl *D, bool Internal,
|
|
|
|
bool Recoverable) {
|
|
|
|
assert(this == getPrimaryContext() && "expected a primary DC");
|
2008-12-12 00:49:14 +08:00
|
|
|
|
2016-04-07 04:56:03 +08:00
|
|
|
if (!isLookupContext()) {
|
|
|
|
if (isTransparentContext())
|
|
|
|
getParent()->getPrimaryContext()
|
|
|
|
->makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
|
2009-02-18 07:15:12 +08:00
|
|
|
return;
|
2016-04-07 04:56:03 +08:00
|
|
|
}
|
2009-02-18 07:15:12 +08:00
|
|
|
|
2012-03-16 14:12:59 +08:00
|
|
|
// Skip declarations which should be invisible to name lookup.
|
|
|
|
if (shouldBeHidden(D))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If we already have a lookup data structure, perform the insertion into
|
|
|
|
// it. If we might have externally-stored decls with this name, look them
|
|
|
|
// up and perform the insertion. If this decl was declared outside its
|
|
|
|
// semantic context, buildLookup won't add it, so add it now.
|
|
|
|
//
|
|
|
|
// FIXME: As a performance hack, don't add such decls into the translation
|
|
|
|
// unit unless we're in C++, since qualified lookup into the TU is never
|
|
|
|
// performed.
|
2015-03-23 11:25:59 +08:00
|
|
|
if (LookupPtr || hasExternalVisibleStorage() ||
|
2012-03-16 14:12:59 +08:00
|
|
|
((!Recoverable || D->getDeclContext() != D->getLexicalDeclContext()) &&
|
|
|
|
(getParentASTContext().getLangOpts().CPlusPlus ||
|
|
|
|
!isTranslationUnit()))) {
|
|
|
|
// If we have lazily omitted any decls, they might have the same name as
|
|
|
|
// the decl which we are adding, so build a full lookup table before adding
|
|
|
|
// this decl.
|
|
|
|
buildLookup();
|
|
|
|
makeDeclVisibleInContextImpl(D, Internal);
|
|
|
|
} else {
|
2018-08-02 04:48:16 +08:00
|
|
|
setHasLazyLocalLexicalLookups(true);
|
2012-03-16 14:12:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we are a transparent context or inline namespace, insert into our
|
|
|
|
// parent context, too. This operation is recursive.
|
|
|
|
if (isTransparentContext() || isInlineNamespace())
|
|
|
|
getParent()->getPrimaryContext()->
|
|
|
|
makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
|
|
|
|
|
2018-04-10 06:14:10 +08:00
|
|
|
auto *DCAsDecl = cast<Decl>(this);
|
2012-03-16 14:12:59 +08:00
|
|
|
// Notify that a decl was made visible unless we are a Tag being defined.
|
|
|
|
if (!(isa<TagDecl>(DCAsDecl) && cast<TagDecl>(DCAsDecl)->isBeingDefined()))
|
|
|
|
if (ASTMutationListener *L = DCAsDecl->getASTMutationListener())
|
|
|
|
L->AddedVisibleDecl(this, D);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeclContext::makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal) {
|
|
|
|
// Find or create the stored declaration map.
|
2015-03-23 11:25:59 +08:00
|
|
|
StoredDeclsMap *Map = LookupPtr;
|
2012-03-16 14:12:59 +08:00
|
|
|
if (!Map) {
|
|
|
|
ASTContext *C = &getParentASTContext();
|
|
|
|
Map = CreateStoredDeclsMap(*C);
|
2010-07-05 05:44:25 +08:00
|
|
|
}
|
|
|
|
|
2010-08-21 00:04:35 +08:00
|
|
|
// If there is an external AST source, load any declarations it knows about
|
|
|
|
// with this declaration's name.
|
|
|
|
// If the lookup table contains an entry about this name it means that we
|
|
|
|
// have already checked the external source.
|
2011-10-21 10:57:43 +08:00
|
|
|
if (!Internal)
|
|
|
|
if (ExternalASTSource *Source = getParentASTContext().getExternalSource())
|
|
|
|
if (hasExternalVisibleStorage() &&
|
2012-03-16 14:12:59 +08:00
|
|
|
Map->find(D->getDeclName()) == Map->end())
|
2011-10-21 10:57:43 +08:00
|
|
|
Source->FindExternalVisibleDeclsByName(this, D->getDeclName());
|
2010-08-21 00:04:35 +08:00
|
|
|
|
2008-12-12 00:49:14 +08:00
|
|
|
// Insert this declaration into the map.
|
2012-03-16 14:12:59 +08:00
|
|
|
StoredDeclsList &DeclNameEntries = (*Map)[D->getDeclName()];
|
2013-09-09 15:34:56 +08:00
|
|
|
|
|
|
|
if (Internal) {
|
|
|
|
// If this is being added as part of loading an external declaration,
|
|
|
|
// this may not be the only external declaration with this name.
|
|
|
|
// In this case, we never try to replace an existing declaration; we'll
|
|
|
|
// handle that when we finalize the list of declarations for this name.
|
|
|
|
DeclNameEntries.setHasExternalDecls();
|
|
|
|
DeclNameEntries.AddSubsequentDecl(D);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-07 08:45:52 +08:00
|
|
|
if (DeclNameEntries.isNull()) {
|
2009-02-20 09:44:05 +08:00
|
|
|
DeclNameEntries.setOnlyValue(D);
|
2012-03-16 14:12:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-10 11:28:10 +08:00
|
|
|
if (DeclNameEntries.HandleRedeclaration(D, /*IsKnownNewer*/!Internal)) {
|
2012-03-13 11:12:56 +08:00
|
|
|
// This declaration has replaced an existing one for which
|
|
|
|
// declarationReplaces returns true.
|
2012-03-16 14:12:59 +08:00
|
|
|
return;
|
2008-12-12 00:49:14 +08:00
|
|
|
}
|
2009-02-20 08:55:03 +08:00
|
|
|
|
2012-03-16 14:12:59 +08:00
|
|
|
// Put this declaration into the appropriate slot.
|
|
|
|
DeclNameEntries.AddSubsequentDecl(D);
|
2008-12-12 00:49:14 +08:00
|
|
|
}
|
2009-02-04 03:21:40 +08:00
|
|
|
|
2015-02-21 10:31:57 +08:00
|
|
|
UsingDirectiveDecl *DeclContext::udir_iterator::operator*() const {
|
|
|
|
return cast<UsingDirectiveDecl>(*I);
|
|
|
|
}
|
|
|
|
|
2009-02-04 03:21:40 +08:00
|
|
|
/// Returns iterator range [First, Last) of UsingDirectiveDecls stored within
|
|
|
|
/// this context.
|
2014-03-18 01:14:12 +08:00
|
|
|
DeclContext::udir_range DeclContext::using_directives() const {
|
2012-03-13 11:12:56 +08:00
|
|
|
// FIXME: Use something more efficient than normal lookup for using
|
|
|
|
// directives. In C++, using directives are looked up more than anything else.
|
2015-02-21 10:45:19 +08:00
|
|
|
lookup_result Result = lookup(UsingDirectiveDecl::getName());
|
2015-02-21 10:31:57 +08:00
|
|
|
return udir_range(Result.begin(), Result.end());
|
2009-02-04 03:21:40 +08:00
|
|
|
}
|
2009-04-10 06:27:44 +08:00
|
|
|
|
2010-02-11 15:12:28 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Creation and Destruction of StoredDeclsMaps. //
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-03-24 13:22:00 +08:00
|
|
|
StoredDeclsMap *DeclContext::CreateStoredDeclsMap(ASTContext &C) const {
|
2015-03-23 11:25:59 +08:00
|
|
|
assert(!LookupPtr && "context already has a decls map");
|
2010-03-24 13:22:00 +08:00
|
|
|
assert(getPrimaryContext() == this &&
|
|
|
|
"creating decls map on non-primary context");
|
|
|
|
|
|
|
|
StoredDeclsMap *M;
|
|
|
|
bool Dependent = isDependentContext();
|
|
|
|
if (Dependent)
|
|
|
|
M = new DependentStoredDeclsMap();
|
|
|
|
else
|
|
|
|
M = new StoredDeclsMap();
|
|
|
|
M->Previous = C.LastSDM;
|
|
|
|
C.LastSDM = llvm::PointerIntPair<StoredDeclsMap*,1>(M, Dependent);
|
2015-03-23 11:25:59 +08:00
|
|
|
LookupPtr = M;
|
2010-02-11 15:12:28 +08:00
|
|
|
return M;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTContext::ReleaseDeclContextMaps() {
|
2010-03-24 13:22:00 +08:00
|
|
|
// It's okay to delete DependentStoredDeclsMaps via a StoredDeclsMap
|
|
|
|
// pointer because the subclass doesn't add anything that needs to
|
|
|
|
// be deleted.
|
|
|
|
StoredDeclsMap::DestroyAll(LastSDM.getPointer(), LastSDM.getInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
void StoredDeclsMap::DestroyAll(StoredDeclsMap *Map, bool Dependent) {
|
|
|
|
while (Map) {
|
|
|
|
// Advance the iteration before we invalidate memory.
|
|
|
|
llvm::PointerIntPair<StoredDeclsMap*,1> Next = Map->Previous;
|
|
|
|
|
|
|
|
if (Dependent)
|
|
|
|
delete static_cast<DependentStoredDeclsMap*>(Map);
|
|
|
|
else
|
|
|
|
delete Map;
|
|
|
|
|
|
|
|
Map = Next.getPointer();
|
|
|
|
Dependent = Next.getInt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DependentDiagnostic *DependentDiagnostic::Create(ASTContext &C,
|
|
|
|
DeclContext *Parent,
|
|
|
|
const PartialDiagnostic &PDiag) {
|
|
|
|
assert(Parent->isDependentContext()
|
|
|
|
&& "cannot iterate dependent diagnostics of non-dependent context");
|
|
|
|
Parent = Parent->getPrimaryContext();
|
2015-03-23 11:25:59 +08:00
|
|
|
if (!Parent->LookupPtr)
|
2010-03-24 13:22:00 +08:00
|
|
|
Parent->CreateStoredDeclsMap(C);
|
|
|
|
|
2018-04-10 06:14:10 +08:00
|
|
|
auto *Map = static_cast<DependentStoredDeclsMap *>(Parent->LookupPtr);
|
2010-03-24 13:22:00 +08:00
|
|
|
|
2010-03-30 07:56:53 +08:00
|
|
|
// Allocate the copy of the PartialDiagnostic via the ASTContext's
|
2010-03-30 07:34:08 +08:00
|
|
|
// BumpPtrAllocator, rather than the ASTContext itself.
|
2014-05-12 13:36:57 +08:00
|
|
|
PartialDiagnostic::Storage *DiagStorage = nullptr;
|
2010-03-30 07:56:53 +08:00
|
|
|
if (PDiag.hasStorage())
|
|
|
|
DiagStorage = new (C) PartialDiagnostic::Storage;
|
2018-07-31 03:24:48 +08:00
|
|
|
|
2018-04-10 06:14:10 +08:00
|
|
|
auto *DD = new (C) DependentDiagnostic(PDiag, DiagStorage);
|
2010-03-24 13:22:00 +08:00
|
|
|
|
|
|
|
// TODO: Maybe we shouldn't reverse the order during insertion.
|
|
|
|
DD->NextDiagnostic = Map->FirstDiagnostic;
|
|
|
|
Map->FirstDiagnostic = DD;
|
|
|
|
|
|
|
|
return DD;
|
2010-02-11 15:12:28 +08:00
|
|
|
}
|