diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-06-16 21:03:44 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-06-16 21:03:44 +0000 |
commit | 325377b57338e700317f5e423e5b0f1c08d99a39 (patch) | |
tree | acd401a9713562cf3e93d13fa6a70ad67eb5cd99 /tools | |
parent | 1b08b196ac845675036ac78f3ac927d0a37f707c (diff) | |
download | src-325377b57338e700317f5e423e5b0f1c08d99a39.tar.gz src-325377b57338e700317f5e423e5b0f1c08d99a39.zip |
Vendor import of clang trunk r305575:vendor/clang/clang-trunk-r305575
Notes
Notes:
svn path=/vendor/clang/dist/; revision=320015
svn path=/vendor/clang/clang-trunk-r305575/; revision=320016; tag=vendor/clang/clang-trunk-r305575
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/clang-format/git-clang-format | 2 | ||||
-rw-r--r-- | tools/libclang/CIndex.cpp | 120 |
2 files changed, 84 insertions, 38 deletions
diff --git a/tools/clang-format/git-clang-format b/tools/clang-format/git-clang-format index 71b9124149fc..60cd4fb25b63 100755 --- a/tools/clang-format/git-clang-format +++ b/tools/clang-format/git-clang-format @@ -324,6 +324,8 @@ def filter_by_extension(dictionary, allowed_extensions): allowed_extensions = frozenset(allowed_extensions) for filename in list(dictionary.keys()): base_ext = filename.rsplit('.', 1) + if len(base_ext) == 1 and '' in allowed_extensions: + continue if len(base_ext) == 1 or base_ext[1].lower() not in allowed_extensions: del dictionary[filename] diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 1ccf6cbd328e..f92096195081 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -7216,15 +7216,11 @@ static CXVersion convertVersion(VersionTuple In) { return Out; } -static int getCursorPlatformAvailabilityForDecl(const Decl *D, - int *always_deprecated, - CXString *deprecated_message, - int *always_unavailable, - CXString *unavailable_message, - CXPlatformAvailability *availability, - int availability_size) { +static void getCursorPlatformAvailabilityForDecl( + const Decl *D, int *always_deprecated, CXString *deprecated_message, + int *always_unavailable, CXString *unavailable_message, + SmallVectorImpl<AvailabilityAttr *> &AvailabilityAttrs) { bool HadAvailAttr = false; - int N = 0; for (auto A : D->attrs()) { if (DeprecatedAttr *Deprecated = dyn_cast<DeprecatedAttr>(A)) { HadAvailAttr = true; @@ -7236,7 +7232,7 @@ static int getCursorPlatformAvailabilityForDecl(const Decl *D, } continue; } - + if (UnavailableAttr *Unavailable = dyn_cast<UnavailableAttr>(A)) { HadAvailAttr = true; if (always_unavailable) @@ -7247,38 +7243,71 @@ static int getCursorPlatformAvailabilityForDecl(const Decl *D, } 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, - availability, - availability_size); - - return N; + 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()); } -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, @@ -7300,14 +7329,29 @@ int clang_getCursorPlatformAvailability(CXCursor cursor, if (!D) return 0; - return getCursorPlatformAvailabilityForDecl(D, always_deprecated, - deprecated_message, - always_unavailable, - unavailable_message, - availability, - availability_size); + 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(); } - + void clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability) { clang_disposeString(availability->Platform); clang_disposeString(availability->Message); |