From 01a96537a83d13a9f473b2b16b040bd26f411d83 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 1 Feb 2017 12:29:27 +0100 Subject: Utils: Move forward declaration of SmallString in an extra header Change-Id: I6da1cc60d425f654a31570373eb3b4f660d5f975 Reviewed-by: Tim Jenssen --- src/libs/clangbackendipc/clangbackendipc_global.h | 9 ++---- src/libs/utils/smallstringfwd.h | 37 ++++++++++++++++++++++ src/libs/utils/utils-lib.pri | 3 +- .../source/clangpchmanagerbackend_global.h | 9 ++---- .../source/collectincludesaction.h | 8 ++--- .../source/collectincludespreprocessorcallbacks.h | 4 +-- .../source/collectincludestoolaction.h | 4 +-- .../source/includecollector.cpp | 2 +- .../source/includecollector.h | 4 +-- .../clangpchmanagerbackend/source/pchcreator.cpp | 10 +++--- .../clangpchmanagerbackend/source/pchcreator.h | 6 ++-- .../source/sourcerangeextractor.h | 8 ++--- tests/unit/unittest/includecollector-test.cpp | 2 +- tests/unit/unittest/pchcreator-test.cpp | 2 +- 14 files changed, 66 insertions(+), 42 deletions(-) create mode 100644 src/libs/utils/smallstringfwd.h diff --git a/src/libs/clangbackendipc/clangbackendipc_global.h b/src/libs/clangbackendipc/clangbackendipc_global.h index 5c12e159b8..33775c7cac 100644 --- a/src/libs/clangbackendipc/clangbackendipc_global.h +++ b/src/libs/clangbackendipc/clangbackendipc_global.h @@ -29,6 +29,8 @@ #include +#include + #ifdef UNIT_TESTS #include #endif @@ -51,13 +53,6 @@ #define unitttest_public private #endif -namespace Utils { -template -class BasicSmallString; -using SmallString = BasicSmallString<31>; -using PathString = BasicSmallString<190>; -} - namespace ClangBackEnd { enum class DiagnosticSeverity : quint32 // one to one mapping of the clang enum numbers diff --git a/src/libs/utils/smallstringfwd.h b/src/libs/utils/smallstringfwd.h new file mode 100644 index 0000000000..90af2c7b42 --- /dev/null +++ b/src/libs/utils/smallstringfwd.h @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +namespace Utils { + +using uint = unsigned int; + +template +class BasicSmallString; +using SmallString = BasicSmallString<31>; +using PathString = BasicSmallString<190>; + +} // namespace Utils diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index aa5ff4716b..6d67f87b4c 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -235,7 +235,8 @@ HEADERS += \ $$PWD/sizedarray.h \ $$PWD/smallstringio.h \ $$PWD/guard.h \ - $$PWD/asconst.h + $$PWD/asconst.h \ + $$PWD/smallstringfwd.h FORMS += $$PWD/filewizardpage.ui \ $$PWD/projectintropage.ui \ diff --git a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend_global.h b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend_global.h index 9794f2bb60..b5b5fdc0c7 100644 --- a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend_global.h +++ b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend_global.h @@ -25,6 +25,8 @@ #pragma once +#include + #ifdef UNIT_TESTS #define unitttest_public public #define non_unittest_final @@ -40,13 +42,6 @@ class SmallVector; using uint = unsigned int; -namespace Utils { -template -class BasicSmallString; -using SmallString = BasicSmallString<31>; -using PathString = BasicSmallString<190>; -} - namespace ClangBackEnd { using USRName = llvm::SmallVector; diff --git a/src/tools/clangpchmanagerbackend/source/collectincludesaction.h b/src/tools/clangpchmanagerbackend/source/collectincludesaction.h index 3f98b307e1..292a263808 100644 --- a/src/tools/clangpchmanagerbackend/source/collectincludesaction.h +++ b/src/tools/clangpchmanagerbackend/source/collectincludesaction.h @@ -39,8 +39,8 @@ class CollectIncludesAction final : public clang::PreprocessOnlyAction { public: CollectIncludesAction(std::vector &includeIds, - StringCache &filePathCache, - const std::vector &excludedIncludeUID, + StringCache &filePathCache, + std::vector &excludedIncludeUID, std::vector &alreadyIncludedFileUIDs) : m_includeIds(includeIds), m_filePathCache(filePathCache), @@ -77,8 +77,8 @@ public: private: std::vector &m_includeIds; - StringCache &m_filePathCache; - const std::vector &m_excludedIncludeUID; + StringCache &m_filePathCache; + std::vector &m_excludedIncludeUID; std::vector &m_alreadyIncludedFileUIDs; }; diff --git a/src/tools/clangpchmanagerbackend/source/collectincludespreprocessorcallbacks.h b/src/tools/clangpchmanagerbackend/source/collectincludespreprocessorcallbacks.h index 137b462ada..2fddb22a74 100644 --- a/src/tools/clangpchmanagerbackend/source/collectincludespreprocessorcallbacks.h +++ b/src/tools/clangpchmanagerbackend/source/collectincludespreprocessorcallbacks.h @@ -44,7 +44,7 @@ class CollectIncludesPreprocessorCallbacks final : public clang::PPCallbacks public: CollectIncludesPreprocessorCallbacks(clang::HeaderSearch &headerSearch, std::vector &includeIds, - StringCache &filePathCache, + StringCache &filePathCache, const std::vector &excludedIncludeUID, std::vector &alreadyIncludedFileUIDs) : m_headerSearch(headerSearch), @@ -119,7 +119,7 @@ public: private: clang::HeaderSearch &m_headerSearch; std::vector &m_includeIds; - StringCache &m_filePathCache; + StringCache &m_filePathCache; const std::vector &m_excludedIncludeUID; std::vector &m_alreadyIncludedFileUIDs; }; diff --git a/src/tools/clangpchmanagerbackend/source/collectincludestoolaction.h b/src/tools/clangpchmanagerbackend/source/collectincludestoolaction.h index 7b81228b09..eea42ca9f3 100644 --- a/src/tools/clangpchmanagerbackend/source/collectincludestoolaction.h +++ b/src/tools/clangpchmanagerbackend/source/collectincludestoolaction.h @@ -37,7 +37,7 @@ class CollectIncludesToolAction final : public clang::tooling::FrontendActionFac { public: CollectIncludesToolAction(std::vector &includeIds, - StringCache &filePathCache, + StringCache &filePathCache, const Utils::PathStringVector &excludedIncludes) : m_includeIds(includeIds), m_filePathCache(filePathCache), @@ -87,7 +87,7 @@ private: std::vector m_alreadyIncludedFileUIDs; std::vector m_excludedIncludeUIDs; std::vector &m_includeIds; - StringCache &m_filePathCache; + StringCache &m_filePathCache; const Utils::PathStringVector &m_excludedIncludes; }; diff --git a/src/tools/clangpchmanagerbackend/source/includecollector.cpp b/src/tools/clangpchmanagerbackend/source/includecollector.cpp index cf9dd75933..b380fa2b8b 100644 --- a/src/tools/clangpchmanagerbackend/source/includecollector.cpp +++ b/src/tools/clangpchmanagerbackend/source/includecollector.cpp @@ -33,7 +33,7 @@ namespace ClangBackEnd { -IncludeCollector::IncludeCollector(StringCache &filePathCache) +IncludeCollector::IncludeCollector(StringCache &filePathCache) : m_filePathCache(filePathCache) { } diff --git a/src/tools/clangpchmanagerbackend/source/includecollector.h b/src/tools/clangpchmanagerbackend/source/includecollector.h index 09575abd42..ba485ea33d 100644 --- a/src/tools/clangpchmanagerbackend/source/includecollector.h +++ b/src/tools/clangpchmanagerbackend/source/includecollector.h @@ -34,7 +34,7 @@ namespace ClangBackEnd { class IncludeCollector : public ClangTool { public: - IncludeCollector(StringCache &filePathCache); + IncludeCollector(StringCache &filePathCache); void collectIncludes(); @@ -46,7 +46,7 @@ private: Utils::PathStringVector m_excludedIncludes; std::vector m_includeIds; Utils::SmallStringVector m_directories; - StringCache &m_filePathCache; + StringCache &m_filePathCache; }; } // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp index 7ab04738eb..2ca4acb5e6 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp @@ -36,7 +36,7 @@ namespace ClangBackEnd { -PchCreator::PchCreator(Environment &environment, StringCache &filePathCache) +PchCreator::PchCreator(Environment &environment, StringCache &filePathCache) : m_environment(environment), m_filePathCache(filePathCache) { @@ -44,7 +44,7 @@ PchCreator::PchCreator(Environment &environment, StringCache PchCreator::PchCreator(V2::ProjectPartContainers &&projectsParts, Environment &environment, - StringCache &filePathCache, + StringCache &filePathCache, PchGeneratorInterface *pchGenerator, V2::FileContainers &&generatedFiles) : m_projectParts(std::move(projectsParts)), @@ -255,9 +255,9 @@ std::vector PchCreator::generateGlobalPchIncludeIds() const namespace { -std::size_t contentSize(const std::vector &includes) +std::size_t contentSize(const std::vector &includes) { - auto countIncludeSize = [] (std::size_t size, const Utils::SmallString &include) { + auto countIncludeSize = [] (std::size_t size, const Utils::PathString &include) { return size + include.size(); }; @@ -274,7 +274,7 @@ Utils::SmallString PchCreator::generatePchIncludeFileContent( fileContent.reserve(includes.size() * lineTemplateSize + contentSize(includes)); - for (const Utils::SmallString &include : includes) { + for (const Utils::PathString &include : includes) { fileContent += "#include \""; fileContent += include; fileContent += "\"\n"; diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.h b/src/tools/clangpchmanagerbackend/source/pchcreator.h index 70fddd2964..1ea1e08037 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.h +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.h @@ -48,10 +48,10 @@ class PchCreator final : public PchCreatorInterface { public: PchCreator(Environment &environment, - StringCache &filePathCache); + StringCache &filePathCache); PchCreator(V2::ProjectPartContainers &&projectsParts, Environment &environment, - StringCache &filePathCache, + StringCache &filePathCache, PchGeneratorInterface *pchGenerator, V2::FileContainers &&generatedFiles); @@ -123,7 +123,7 @@ private: std::vector m_projectPartPchs; std::vector m_projectsIncludeIds; Environment &m_environment; - StringCache &m_filePathCache; + StringCache &m_filePathCache; PchGeneratorInterface *m_pchGenerator = nullptr; }; diff --git a/src/tools/clangrefactoringbackend/source/sourcerangeextractor.h b/src/tools/clangrefactoringbackend/source/sourcerangeextractor.h index 05ba1f7132..5bd6cf75ab 100644 --- a/src/tools/clangrefactoringbackend/source/sourcerangeextractor.h +++ b/src/tools/clangrefactoringbackend/source/sourcerangeextractor.h @@ -25,16 +25,12 @@ #pragma once +#include + #include using uint = unsigned int; -namespace Utils { -template -class BasicSmallString; -using SmallString = BasicSmallString<31>; -} - namespace llvm { class StringRef; } diff --git a/tests/unit/unittest/includecollector-test.cpp b/tests/unit/unittest/includecollector-test.cpp index 663de3fedd..e574733892 100644 --- a/tests/unit/unittest/includecollector-test.cpp +++ b/tests/unit/unittest/includecollector-test.cpp @@ -43,7 +43,7 @@ protected: uint id(const Utils::SmallString &path); protected: - ClangBackEnd::StringCache filePathCache; + ClangBackEnd::StringCache filePathCache; ClangBackEnd::IncludeCollector collector{filePathCache}; }; diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp index b4d3977c2f..274cd207f2 100644 --- a/tests/unit/unittest/pchcreator-test.cpp +++ b/tests/unit/unittest/pchcreator-test.cpp @@ -61,7 +61,7 @@ protected: uint id(const Utils::SmallString &path); protected: - ClangBackEnd::StringCache filePathCache; + ClangBackEnd::StringCache filePathCache; PathString main1Path = TESTDATA_DIR "/includecollector_main3.cpp"; PathString main2Path = TESTDATA_DIR "/includecollector_main2.cpp"; PathString header1Path = TESTDATA_DIR "/includecollector_header1.h"; -- cgit v1.2.1