summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2017-06-09 22:06:36 +0000
committerAlex Lorenz <arphaman@gmail.com>2017-06-09 22:06:36 +0000
commitdd4ce29ba053c530cab3a68b8ba9dfae60e4a271 (patch)
tree989b0d679d61f38bbfc5cf6c0f2e1d06f9c13771 /tools
parent2399fffdef8de031c82c9deed299ff3ed7d8922e (diff)
Revert r305117
It caused `Index/availability.c` test failure on Linux git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305122 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/libclang/CIndex.cpp120
1 files changed, 38 insertions, 82 deletions
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index f920961950..1ccf6cbd32 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -7216,11 +7216,15 @@ static CXVersion convertVersion(VersionTuple In) {
return Out;
}
-static void getCursorPlatformAvailabilityForDecl(
- const Decl *D, int *always_deprecated, CXString *deprecated_message,
- int *always_unavailable, CXString *unavailable_message,
- SmallVectorImpl<AvailabilityAttr *> &AvailabilityAttrs) {
+static int getCursorPlatformAvailabilityForDecl(const Decl *D,
+ int *always_deprecated,
+ CXString *deprecated_message,
+ int *always_unavailable,
+ CXString *unavailable_message,
+ CXPlatformAvailability *availability,
+ int availability_size) {
bool HadAvailAttr = false;
+ int N = 0;
for (auto A : D->attrs()) {
if (DeprecatedAttr *Deprecated = dyn_cast<DeprecatedAttr>(A)) {
HadAvailAttr = true;
@@ -7232,7 +7236,7 @@ static void getCursorPlatformAvailabilityForDecl(
}
continue;
}
-
+
if (UnavailableAttr *Unavailable = dyn_cast<UnavailableAttr>(A)) {
HadAvailAttr = true;
if (always_unavailable)
@@ -7243,71 +7247,38 @@ static void getCursorPlatformAvailabilityForDecl(
}
continue;
}
-
+
if (AvailabilityAttr *Avail = dyn_cast<AvailabilityAttr>(A)) {
- AvailabilityAttrs.push_back(Avail);
HadAvailAttr = true;
+ if (N < availability_size) {
+ availability[N].Platform
+ = cxstring::createDup(Avail->getPlatform()->getName());
+ availability[N].Introduced = convertVersion(Avail->getIntroduced());
+ availability[N].Deprecated = convertVersion(Avail->getDeprecated());
+ availability[N].Obsoleted = convertVersion(Avail->getObsoleted());
+ availability[N].Unavailable = Avail->getUnavailable();
+ availability[N].Message = cxstring::createDup(Avail->getMessage());
+ }
+ ++N;
}
}
if (!HadAvailAttr)
if (const EnumConstantDecl *EnumConst = dyn_cast<EnumConstantDecl>(D))
return getCursorPlatformAvailabilityForDecl(
- cast<Decl>(EnumConst->getDeclContext()), always_deprecated,
- deprecated_message, always_unavailable, unavailable_message,
- AvailabilityAttrs);
-
- if (AvailabilityAttrs.empty())
- return;
-
- std::sort(AvailabilityAttrs.begin(), AvailabilityAttrs.end(),
- [](AvailabilityAttr *LHS, AvailabilityAttr *RHS) {
- return LHS->getPlatform() > RHS->getPlatform();
- });
- ASTContext &Ctx = D->getASTContext();
- auto It = std::unique(
- AvailabilityAttrs.begin(), AvailabilityAttrs.end(),
- [&Ctx](AvailabilityAttr *LHS, AvailabilityAttr *RHS) {
- if (LHS->getPlatform() != RHS->getPlatform())
- return false;
-
- if (LHS->getIntroduced() == RHS->getIntroduced() &&
- LHS->getDeprecated() == RHS->getDeprecated() &&
- LHS->getObsoleted() == RHS->getObsoleted() &&
- LHS->getMessage() == RHS->getMessage() &&
- LHS->getReplacement() == RHS->getReplacement())
- return true;
-
- if ((!LHS->getIntroduced().empty() && !RHS->getIntroduced().empty()) ||
- (!LHS->getDeprecated().empty() && !RHS->getDeprecated().empty()) ||
- (!LHS->getObsoleted().empty() && !RHS->getObsoleted().empty()))
- return false;
-
- if (LHS->getIntroduced().empty() && !RHS->getIntroduced().empty())
- LHS->setIntroduced(Ctx, RHS->getIntroduced());
-
- if (LHS->getDeprecated().empty() && !RHS->getDeprecated().empty()) {
- LHS->setDeprecated(Ctx, RHS->getDeprecated());
- if (LHS->getMessage().empty())
- LHS->setMessage(Ctx, RHS->getMessage());
- if (LHS->getReplacement().empty())
- LHS->setReplacement(Ctx, RHS->getReplacement());
- }
-
- if (LHS->getObsoleted().empty() && !RHS->getObsoleted().empty()) {
- LHS->setObsoleted(Ctx, RHS->getObsoleted());
- if (LHS->getMessage().empty())
- LHS->setMessage(Ctx, RHS->getMessage());
- if (LHS->getReplacement().empty())
- LHS->setReplacement(Ctx, RHS->getReplacement());
- }
-
- return true;
- });
- AvailabilityAttrs.erase(It, AvailabilityAttrs.end());
+ cast<Decl>(EnumConst->getDeclContext()),
+ always_deprecated,
+ deprecated_message,
+ always_unavailable,
+ unavailable_message,
+ availability,
+ availability_size);
+
+ return N;
}
-int clang_getCursorPlatformAvailability(CXCursor cursor, int *always_deprecated,
+int clang_getCursorPlatformAvailability(CXCursor cursor,
+ int *always_deprecated,
CXString *deprecated_message,
int *always_unavailable,
CXString *unavailable_message,
@@ -7329,29 +7300,14 @@ int clang_getCursorPlatformAvailability(CXCursor cursor, int *always_deprecated,
if (!D)
return 0;
- SmallVector<AvailabilityAttr *, 8> AvailabilityAttrs;
- getCursorPlatformAvailabilityForDecl(D, always_deprecated, deprecated_message,
- always_unavailable, unavailable_message,
- AvailabilityAttrs);
- for (const auto &Avail :
- llvm::enumerate(llvm::makeArrayRef(AvailabilityAttrs)
- .take_front(availability_size))) {
- availability[Avail.index()].Platform =
- cxstring::createDup(Avail.value()->getPlatform()->getName());
- availability[Avail.index()].Introduced =
- convertVersion(Avail.value()->getIntroduced());
- availability[Avail.index()].Deprecated =
- convertVersion(Avail.value()->getDeprecated());
- availability[Avail.index()].Obsoleted =
- convertVersion(Avail.value()->getObsoleted());
- availability[Avail.index()].Unavailable = Avail.value()->getUnavailable();
- availability[Avail.index()].Message =
- cxstring::createDup(Avail.value()->getMessage());
- }
-
- return AvailabilityAttrs.size();
+ return getCursorPlatformAvailabilityForDecl(D, always_deprecated,
+ deprecated_message,
+ always_unavailable,
+ unavailable_message,
+ availability,
+ availability_size);
}
-
+
void clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability) {
clang_disposeString(availability->Platform);
clang_disposeString(availability->Message);