Author: hokein Date: Fri Jul 8 08:11:38 2016 New Revision: 274845 URL: http://llvm.org/viewvc/llvm-project?rev=274845&view=rev Log: [include-fixer] Pull out Context implementation code to a cpp file.
Added: clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp Modified: clang-tools-extra/trunk/include-fixer/CMakeLists.txt clang-tools-extra/trunk/include-fixer/IncludeFixerContext.h Modified: clang-tools-extra/trunk/include-fixer/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/CMakeLists.txt?rev=274845&r1=274844&r2=274845&view=diff ============================================================================== --- clang-tools-extra/trunk/include-fixer/CMakeLists.txt (original) +++ clang-tools-extra/trunk/include-fixer/CMakeLists.txt Fri Jul 8 08:11:38 2016 @@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS add_clang_library(clangIncludeFixer IncludeFixer.cpp + IncludeFixerContext.cpp InMemorySymbolIndex.cpp SymbolIndexManager.cpp YamlSymbolIndex.cpp Added: clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp?rev=274845&view=auto ============================================================================== --- clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp (added) +++ clang-tools-extra/trunk/include-fixer/IncludeFixerContext.cpp Fri Jul 8 08:11:38 2016 @@ -0,0 +1,61 @@ +//===-- IncludeFixerContext.cpp - Include fixer context ---------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "IncludeFixerContext.h" +#include <algorithm> + +namespace clang { +namespace include_fixer { + +IncludeFixerContext::IncludeFixerContext( + llvm::StringRef Name, llvm::StringRef ScopeQualifiers, + const std::vector<find_all_symbols::SymbolInfo> Symbols, + tooling::Range Range) + : SymbolIdentifier(Name), SymbolScopedQualifiers(ScopeQualifiers), + MatchedSymbols(Symbols), SymbolRange(Range) { + // Deduplicate headers, so that we don't want to suggest the same header + // twice. + for (const auto &Symbol : MatchedSymbols) + Headers.push_back(Symbol.getFilePath()); + Headers.erase(std::unique(Headers.begin(), Headers.end(), + [](const std::string &A, const std::string &B) { + return A == B; + }), + Headers.end()); +} + +tooling::Replacement +IncludeFixerContext::createSymbolReplacement(llvm::StringRef FilePath, + size_t Idx) { + assert(Idx < MatchedSymbols.size()); + std::string QualifiedName = MatchedSymbols[Idx].getQualifiedName(); + // For nested classes, the qualified name constructed from database misses + // some stripped qualifiers, because when we search a symbol in database, + // we strip qualifiers from the end until we find a result. So append the + // missing stripped qualifiers here. + // + // Get stripped qualifiers. + llvm::SmallVector<llvm::StringRef, 8> SymbolQualifiers; + getSymbolIdentifier().split(SymbolQualifiers, "::"); + std::string StrippedQualifiers; + while (!SymbolQualifiers.empty() && + !llvm::StringRef(QualifiedName).endswith(SymbolQualifiers.back())) { + StrippedQualifiers = "::" + SymbolQualifiers.back().str(); + SymbolQualifiers.pop_back(); + } + // Append the missing stripped qualifiers. + std::string FullyQualifiedName = QualifiedName + StrippedQualifiers; + auto pos = FullyQualifiedName.find(SymbolScopedQualifiers); + return {FilePath, SymbolRange.getOffset(), SymbolRange.getLength(), + FullyQualifiedName.substr( + pos == std::string::npos ? 0 : SymbolScopedQualifiers.size())}; +} + +} // include_fixer +} // clang Modified: clang-tools-extra/trunk/include-fixer/IncludeFixerContext.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/IncludeFixerContext.h?rev=274845&r1=274844&r2=274845&view=diff ============================================================================== --- clang-tools-extra/trunk/include-fixer/IncludeFixerContext.h (original) +++ clang-tools-extra/trunk/include-fixer/IncludeFixerContext.h Fri Jul 8 08:11:38 2016 @@ -12,7 +12,6 @@ #include "find-all-symbols/SymbolInfo.h" #include "clang/Tooling/Core/Replacement.h" -#include <algorithm> #include <string> #include <vector> @@ -22,51 +21,15 @@ namespace include_fixer { /// \brief A context for the symbol being queried. class IncludeFixerContext { public: - IncludeFixerContext() {} + IncludeFixerContext() = default; IncludeFixerContext(llvm::StringRef Name, llvm::StringRef ScopeQualifiers, const std::vector<find_all_symbols::SymbolInfo> Symbols, - tooling::Range Range) - : SymbolIdentifier(Name), SymbolScopedQualifiers(ScopeQualifiers), - MatchedSymbols(Symbols), SymbolRange(Range) { - // Deduplicate headers, so that we don't want to suggest the same header - // twice. - for (const auto &Symbol : MatchedSymbols) - Headers.push_back(Symbol.getFilePath()); - Headers.erase(std::unique(Headers.begin(), Headers.end(), - [](const std::string &A, const std::string &B) { - return A == B; - }), - Headers.end()); - } + tooling::Range Range); /// \brief Create a replacement for adding missing namespace qualifiers to the /// symbol. tooling::Replacement createSymbolReplacement(llvm::StringRef FilePath, - size_t Idx = 0) { - assert(Idx < MatchedSymbols.size()); - std::string QualifiedName = MatchedSymbols[Idx].getQualifiedName(); - // For nested classes, the qualified name constructed from database misses - // some stripped qualifiers, because when we search a symbol in database, - // we strip qualifiers from the end until we find a result. So append the - // missing stripped qualifiers here. - // - // Get stripped qualifiers. - llvm::SmallVector<llvm::StringRef, 8> SymbolQualifiers; - getSymbolIdentifier().split(SymbolQualifiers, "::"); - std::string StrippedQualifiers; - while (!SymbolQualifiers.empty() && - !llvm::StringRef(QualifiedName).endswith(SymbolQualifiers.back())) { - StrippedQualifiers= "::" + SymbolQualifiers.back().str(); - SymbolQualifiers.pop_back(); - } - // Append the missing stripped qualifiers. - std::string FullyQualifiedName = QualifiedName + StrippedQualifiers; - auto pos = FullyQualifiedName.find(SymbolScopedQualifiers); - return {FilePath, SymbolRange.getOffset(), SymbolRange.getLength(), - FullyQualifiedName.substr( - pos == std::string::npos ? 0 : SymbolScopedQualifiers.size())}; - } - + size_t Idx = 0); /// \brief Get symbol name. llvm::StringRef getSymbolIdentifier() const { return SymbolIdentifier; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits