From baa83725f640419bc2c17cd28b91e1604255a3dc Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 14 Jun 2021 11:47:51 +0200 Subject: [PATCH] Remove ClangRefactoring and ClangPchManager This removes the plugins and tools, and removes all the tests that would fail to build because of that. Fixes: QTCREATORBUG-25659 Change-Id: I8adb5d503fc8eea313bcaada421f309dbbfa8c26 Reviewed-by: Christian Kandeler Reviewed-by: Christian Stenger Reviewed-by: Qt CI Bot Reviewed-by: Marco Bubke --- qbs/modules/libclang/libclang.qbs | 1 - src/libs/clangsupport/CMakeLists.txt | 77 -- src/libs/clangsupport/cancelmessage.cpp | 39 - src/libs/clangsupport/cancelmessage.h | 54 - src/libs/clangsupport/clangpathwatcher.h | 449 ------- .../clangsupport/clangpathwatcherinterface.h | 52 - .../clangsupport/clangpathwatchernotifier.h | 50 - .../clangrefactoringclientmessages.h | 31 - .../clangsupport/clangrefactoringmessages.h | 29 - .../clangrefactoringservermessages.h | 35 - src/libs/clangsupport/clangsupport-lib.pri | 119 +- src/libs/clangsupport/clangsupport_global.h | 16 - .../clangsupport/clangsupportexceptions.h | 47 - src/libs/clangsupport/commandlinebuilder.h | 313 ----- src/libs/clangsupport/compilermacro.h | 99 -- .../clangsupport/directoryandfilepathid.h | 90 -- .../clangsupport/directorypathcompressor.h | 86 -- src/libs/clangsupport/directorypathid.h | 81 -- .../dynamicastmatcherdiagnosticcontainer.cpp | 40 - .../dynamicastmatcherdiagnosticcontainer.h | 93 -- ...icastmatcherdiagnosticcontextcontainer.cpp | 54 - ...amicastmatcherdiagnosticcontextcontainer.h | 97 -- ...icastmatcherdiagnosticmessagecontainer.cpp | 70 - ...amicastmatcherdiagnosticmessagecontainer.h | 95 -- .../clangsupport/dynamicmatcherdiagnostics.h | 58 - src/libs/clangsupport/environment.h | 47 - src/libs/clangsupport/executeinloop.h | 39 - src/libs/clangsupport/filecontainerv2.cpp | 44 - src/libs/clangsupport/filecontainerv2.h | 102 -- src/libs/clangsupport/filepath.cpp | 37 - src/libs/clangsupport/filepath.h | 197 --- src/libs/clangsupport/filepathcache.h | 206 --- src/libs/clangsupport/filepathcaching.cpp | 100 -- src/libs/clangsupport/filepathcaching.h | 90 -- src/libs/clangsupport/filepathcachingfwd.h | 32 - .../clangsupport/filepathcachinginterface.h | 89 -- src/libs/clangsupport/filepathexceptions.h | 68 - src/libs/clangsupport/filepathid.cpp | 39 - src/libs/clangsupport/filepathid.h | 103 -- src/libs/clangsupport/filepathstorage.h | 246 ---- .../clangsupport/filepathstoragesources.h | 146 -- .../filepathstoragesqlitestatementfactory.h | 74 - src/libs/clangsupport/filepathview.h | 112 -- src/libs/clangsupport/filestatus.h | 63 - src/libs/clangsupport/filestatuscache.cpp | 136 -- src/libs/clangsupport/filestatuscache.h | 96 -- src/libs/clangsupport/filesystem.cpp | 70 - src/libs/clangsupport/filesystem.h | 50 - src/libs/clangsupport/filesysteminterface.h | 44 - src/libs/clangsupport/generatedfiles.cpp | 128 -- src/libs/clangsupport/generatedfiles.h | 47 - .../clangsupport/generatedfilesinterface.h | 47 - src/libs/clangsupport/idpaths.h | 94 -- src/libs/clangsupport/includesearchpath.h | 102 -- src/libs/clangsupport/modifiedtimechecker.h | 120 -- .../modifiedtimecheckerinterface.h | 48 - src/libs/clangsupport/nativefilepath.h | 189 --- .../pchmanagerclientinterface.cpp | 53 - .../clangsupport/pchmanagerclientinterface.h | 45 - .../clangsupport/pchmanagerclientproxy.cpp | 81 -- src/libs/clangsupport/pchmanagerclientproxy.h | 57 - .../pchmanagerserverinterface.cpp | 61 - .../clangsupport/pchmanagerserverinterface.h | 44 - .../clangsupport/pchmanagerserverproxy.cpp | 76 -- src/libs/clangsupport/pchmanagerserverproxy.h | 60 - src/libs/clangsupport/pchpaths.h | 52 - .../precompiledheadersupdatedmessage.cpp | 39 - .../precompiledheadersupdatedmessage.h | 81 -- src/libs/clangsupport/progresscounter.h | 108 -- src/libs/clangsupport/progressmessage.h | 83 -- .../projectmanagementserverinterface.h | 46 - src/libs/clangsupport/projectpartartefact.cpp | 128 -- src/libs/clangsupport/projectpartartefact.h | 122 -- .../clangsupport/projectpartcontainer.cpp | 38 - src/libs/clangsupport/projectpartcontainer.h | 184 --- src/libs/clangsupport/projectpartid.h | 97 -- src/libs/clangsupport/projectpartpch.cpp | 37 - src/libs/clangsupport/projectpartpch.h | 94 -- src/libs/clangsupport/projectpartsstorage.h | 416 ------ .../projectpartsstorageinterface.h | 77 -- .../clangsupport/projectpartstoragestructs.h | 55 - .../refactoringclientinterface.cpp | 55 - .../clangsupport/refactoringclientinterface.h | 55 - .../clangsupport/refactoringclientproxy.cpp | 84 -- .../clangsupport/refactoringclientproxy.h | 63 - .../refactoringdatabaseinitializer.h | 240 ---- .../refactoringserverinterface.cpp | 67 - .../clangsupport/refactoringserverinterface.h | 65 - .../clangsupport/refactoringserverproxy.cpp | 88 -- .../clangsupport/refactoringserverproxy.h | 64 - .../removegeneratedfilesmessage.cpp | 37 - .../removegeneratedfilesmessage.h | 79 -- .../clangsupport/removeprojectpartsmessage.h | 73 - ...rcerangesanddiagnosticsforquerymessage.cpp | 39 - ...ourcerangesanddiagnosticsforquerymessage.h | 89 -- .../requestsourcerangesforquerymessage.cpp | 39 - .../requestsourcerangesforquerymessage.h | 101 -- src/libs/clangsupport/sourceentry.h | 169 --- .../sourcelocationcontainerv2.cpp | 45 - .../clangsupport/sourcelocationcontainerv2.h | 106 -- .../clangsupport/sourcelocationscontainer.cpp | 2 +- .../clangsupport/sourcelocationscontainer.h | 14 +- .../clangsupport/sourcerangecontainerv2.cpp | 44 - .../clangsupport/sourcerangecontainerv2.h | 104 -- ...rcerangesanddiagnosticsforquerymessage.cpp | 39 - ...ourcerangesanddiagnosticsforquerymessage.h | 87 -- .../clangsupport/sourcerangescontainer.cpp | 46 - src/libs/clangsupport/sourcerangescontainer.h | 106 -- .../sourcerangesforquerymessage.cpp | 38 - .../sourcerangesforquerymessage.h | 74 - .../sourcerangewithtextcontainer.cpp | 41 - .../sourcerangewithtextcontainer.h | 112 -- src/libs/clangsupport/stringcache.h | 426 ------ src/libs/clangsupport/stringcachealgorithms.h | 72 - src/libs/clangsupport/stringcacheentry.h | 50 - src/libs/clangsupport/stringcachefwd.h | 37 - .../updategeneratedfilesmessage.cpp | 38 - .../updategeneratedfilesmessage.h | 77 -- .../updateprojectpartsmessage.cpp | 38 - .../clangsupport/updateprojectpartsmessage.h | 85 -- src/plugins/CMakeLists.txt | 2 - .../clangcodemodel/clangrefactoringengine.cpp | 6 +- src/plugins/clangpchmanager/CMakeLists.txt | 23 - .../clangpchmanager/ClangPchManager.json.in | 20 - .../clangindexingprojectsettings.cpp | 96 -- .../clangindexingprojectsettings.h | 50 - .../clangindexingprojectsettingswidget.cpp | 74 - .../clangindexingprojectsettingswidget.h | 64 - .../clangindexingprojectsettingswidget.ui | 72 - .../clangindexingsettingsmanager.cpp | 55 - .../clangindexingsettingsmanager.h | 59 - .../clangpchmanager-source.pri | 30 - .../clangpchmanager/clangpchmanager.pro | 26 - .../clangpchmanager/clangpchmanager.qbs | 49 - .../clangpchmanager_dependencies.pri | 8 - .../clangpchmanager/clangpchmanager_global.h | 42 - .../clangpchmanager/clangpchmanagerplugin.cpp | 168 --- .../clangpchmanager/clangpchmanagerplugin.h | 62 - .../clangpchmanager/pchmanagerclient.cpp | 102 -- .../clangpchmanager/pchmanagerclient.h | 71 - .../pchmanagerconnectionclient.cpp | 96 -- .../pchmanagerconnectionclient.h | 51 - .../pchmanagernotifierinterface.cpp | 43 - .../pchmanagernotifierinterface.h | 54 - .../pchmanagerprojectupdater.cpp | 50 - .../pchmanagerprojectupdater.h | 51 - .../preprocessormacrocollector.cpp | 68 - .../preprocessormacrocollector.h | 51 - .../preprocessormacrowidget.cpp | 282 ---- .../clangpchmanager/preprocessormacrowidget.h | 79 -- src/plugins/clangpchmanager/progressmanager.h | 85 -- .../progressmanagerinterface.h | 39 - .../clangpchmanager/projectupdater.cpp | 481 ------- src/plugins/clangpchmanager/projectupdater.h | 143 -- .../qtcreatorprojectupdater.cpp | 92 -- .../clangpchmanager/qtcreatorprojectupdater.h | 145 -- src/plugins/clangrefactoring/CMakeLists.txt | 41 - .../clangrefactoring/ClangRefactoring.json.in | 20 - .../baseclangquerytexteditorwidget.cpp | 42 - .../baseclangquerytexteditorwidget.h | 40 - .../clangqueryexamplehighlighter.cpp | 62 - .../clangqueryexamplehighlighter.h | 56 - .../clangqueryexamplehighlightmarker.h | 220 --- .../clangqueryexampletexteditorwidget.cpp | 47 - .../clangqueryexampletexteditorwidget.h | 47 - .../clangqueryhighlighter.cpp | 93 -- .../clangrefactoring/clangqueryhighlighter.h | 60 - .../clangqueryhighlightmarker.h | 345 ----- .../clangqueryhoverhandler.cpp | 65 - .../clangrefactoring/clangqueryhoverhandler.h | 48 - .../clangqueryprojectsfindfilter.cpp | 247 ---- .../clangqueryprojectsfindfilter.h | 100 -- .../clangqueryprojectsfindfilter.ui | 92 -- .../clangqueryprojectsfindfilterwidget.cpp | 68 - .../clangqueryprojectsfindfilterwidget.h | 52 - .../clangquerytexteditorwidget.cpp | 53 - .../clangquerytexteditorwidget.h | 52 - .../clangrefactoring-source.pri | 34 - .../clangrefactoring/clangrefactoring.pro | 43 - .../clangrefactoring/clangrefactoring.qbs | 81 -- .../clangrefactoring_dependencies.pri | 9 - .../clangrefactoringplugin.cpp | 202 --- .../clangrefactoring/clangrefactoringplugin.h | 67 - .../clangsymbolsfindfilter.cpp | 67 - .../clangrefactoring/clangsymbolsfindfilter.h | 58 - .../clangrefactoring/editormanagerinterface.h | 53 - .../clangrefactoring/locatorfilter.cpp | 64 - src/plugins/clangrefactoring/locatorfilter.h | 67 - .../projectpartproviderinterface.h | 56 - .../clangrefactoring/projectpartutilities.cpp | 47 - .../clangrefactoring/projectpartutilities.h | 35 - .../qtcreatorclangqueryfindfilter.cpp | 141 -- .../qtcreatorclangqueryfindfilter.h | 64 - .../qtcreatoreditormanager.cpp | 44 - .../clangrefactoring/qtcreatoreditormanager.h | 49 - .../qtcreatorrefactoringprojectupdater.cpp | 114 -- .../qtcreatorrefactoringprojectupdater.h | 47 - .../clangrefactoring/qtcreatorsearch.cpp | 64 - .../clangrefactoring/qtcreatorsearch.h | 41 - .../qtcreatorsearchhandle.cpp | 71 - .../clangrefactoring/qtcreatorsearchhandle.h | 57 - .../qtcreatorsymbolsfindfilter.cpp | 37 - .../qtcreatorsymbolsfindfilter.h | 41 - .../querysqlitestatementfactory.h | 82 -- .../clangrefactoring/refactoringclient.cpp | 135 -- .../clangrefactoring/refactoringclient.h | 97 -- .../refactoringconnectionclient.cpp | 89 -- .../refactoringconnectionclient.h | 53 - .../clangrefactoring/refactoringengine.cpp | 148 -- .../clangrefactoring/refactoringengine.h | 86 -- .../refactoringprojectupdater.cpp | 47 - .../refactoringprojectupdater.h | 58 - src/plugins/clangrefactoring/searchhandle.cpp | 44 - src/plugins/clangrefactoring/searchhandle.h | 60 - .../clangrefactoring/searchinterface.h | 50 - .../clangrefactoring/sourcelocations.h | 65 - src/plugins/clangrefactoring/symbol.h | 65 - src/plugins/clangrefactoring/symbolquery.h | 161 --- .../clangrefactoring/symbolqueryinterface.h | 65 - .../symbolsfindfilterconfigwidget.cpp | 39 - .../symbolsfindfilterconfigwidget.h | 41 - src/plugins/cppeditor/cppeditor.qbs | 1 + src/plugins/cppeditor/cppeditorwidget.cpp | 2 +- src/plugins/cpptools/CMakeLists.txt | 2 +- src/plugins/cpptools/cpprefactoringengine.cpp | 1 + src/plugins/cpptools/cpptools.qbs | 1 + .../cpptools/cpptools_dependencies.pri | 1 + .../cpptools/refactoringengineinterface.h | 11 +- src/plugins/plugins.pro | 6 - src/plugins/plugins.qbs | 2 - src/shared/clang/clang_installation.pri | 16 - src/tools/CMakeLists.txt | 2 - .../clangpchmanagerbackend/CMakeLists.txt | 11 - .../clangpchmanagerbackend.pro | 31 - .../clangpchmanagerbackend.qbs | 53 - .../clangpchmanagerbackendmain.cpp | 297 ---- .../source/CMakeLists.txt | 54 - .../source/builddependenciesprovider.cpp | 140 -- .../source/builddependenciesprovider.h | 79 -- .../builddependenciesproviderinterface.h | 47 - .../source/builddependenciesstorage.h | 411 ------ .../builddependenciesstorageinterface.h | 73 - .../source/builddependency.h | 66 - .../source/builddependencycollector.cpp | 179 --- .../source/builddependencycollector.h | 103 -- .../builddependencygeneratorinterface.h | 43 - .../source/clangpchmanagerbackend-source.pri | 59 - .../source/clangpchmanagerbackend_global.h | 49 - .../source/collectbuilddependencyaction.h | 90 -- ...lectbuilddependencypreprocessorcallbacks.h | 369 ----- .../source/collectbuilddependencytoolaction.h | 100 -- .../source/collectusedmacroactionfactory.h | 82 -- .../source/collectusedmacrosaction.h | 92 -- ...sedmacrosandsourcespreprocessorcallbacks.h | 254 ---- .../source/generatepchactionfactory.h | 84 -- .../source/pchcreator.cpp | 221 --- .../source/pchcreator.h | 111 -- .../source/pchcreatorinterface.h | 52 - .../source/pchmanagerserver.cpp | 306 ----- .../source/pchmanagerserver.h | 84 -- .../source/pchnotcreatederror.h | 36 - .../clangpchmanagerbackend/source/pchtask.h | 152 --- .../source/pchtaskgenerator.cpp | 123 -- .../source/pchtaskgenerator.h | 68 - .../source/pchtaskgeneratorinterface.h | 47 - .../source/pchtaskqueue.cpp | 234 ---- .../source/pchtaskqueue.h | 100 -- .../source/pchtaskqueueinterface.h | 43 - .../source/pchtasksmerger.cpp | 161 --- .../source/pchtasksmerger.h | 61 - .../source/pchtasksmergerinterface.h | 40 - .../source/precompiledheaderstorage.h | 287 ---- .../precompiledheaderstorageinterface.h | 69 - .../source/processorinterface.h | 47 - .../source/processormanager.h | 92 -- .../source/processormanagerinterface.h | 47 - .../source/projectpartsmanager.cpp | 415 ------ .../source/projectpartsmanager.h | 92 -- .../source/projectpartsmanagerinterface.h | 58 - .../source/queueinterface.h | 44 - .../source/taskscheduler.h | 164 --- .../source/taskschedulerinterface.h | 60 - .../source/toolchainargumentscache.h | 189 --- .../source/usedmacrofilter.h | 229 ---- .../source/usedmacrosandsourcescollector.cpp | 67 - .../source/usedmacrosandsourcescollector.h | 84 -- .../clangrefactoringbackend/CMakeLists.txt | 9 - .../clangrefactoringbackend.pro | 26 - .../clangrefactoringbackend.qbs | 40 - .../clangrefactoringbackendmain.cpp | 174 --- .../source/CMakeLists.txt | 46 - .../source/clangquery.cpp | 227 ---- .../source/clangquery.h | 75 -- .../source/clangquerygatherer.cpp | 165 --- .../source/clangquerygatherer.h | 81 -- .../source/clangrefactoringbackend-source.pri | 58 - .../source/clangrefactoringbackend_global.h | 43 - .../source/clangtool.cpp | 117 -- .../source/clangtool.h | 90 -- .../collectmacrospreprocessorcallbacks.h | 230 ---- .../collectmacrossourcefilecallbacks.cpp | 52 - .../source/collectmacrossourcefilecallbacks.h | 99 -- .../source/collectsymbolsaction.cpp | 39 - .../source/collectsymbolsaction.h | 104 -- .../source/indexdataconsumer.cpp | 222 --- .../source/indexdataconsumer.h | 87 -- .../source/locationsourcefilecallbacks.cpp | 78 -- .../source/locationsourcefilecallbacks.h | 67 - .../source/macropreprocessorcallbacks.cpp | 45 - .../source/macropreprocessorcallbacks.h | 187 --- .../source/projectpartentry.h | 60 - .../source/refactoringcompilationdatabase.cpp | 85 -- .../source/refactoringcompilationdatabase.h | 49 - .../source/refactoringserver.cpp | 167 --- .../source/refactoringserver.h | 96 -- .../source/sourcedependency.h | 65 - .../source/sourcelocationentry.h | 70 - .../source/sourcelocationsutils.h | 101 -- .../source/sourcerangeextractor.cpp | 185 --- .../source/sourcerangeextractor.h | 95 -- .../source/sourcerangefilter.cpp | 74 - .../source/sourcerangefilter.h | 47 - .../source/sourcesmanager.h | 120 -- .../source/symbolentry.h | 71 - .../source/symbolindexer.cpp | 306 ----- .../source/symbolindexer.h | 95 -- .../source/symbolindexertask.h | 83 -- .../source/symbolindexertaskqueue.h | 122 -- .../source/symbolindexertaskqueueinterface.h | 49 - .../source/symbolindexing.cpp | 35 - .../source/symbolindexing.h | 157 --- .../source/symbolindexinginterface.h | 46 - .../source/symbolscollector.cpp | 161 --- .../source/symbolscollector.h | 79 -- .../source/symbolscollectorinterface.h | 53 - .../source/symbolstorage.h | 198 --- .../source/symbolstorageinterface.h | 56 - .../source/symbolsvisitorbase.h | 163 --- .../source/usedmacro.h | 76 -- src/tools/tools.pro | 6 - src/tools/tools.qbs | 2 - tests/unit/unittest/CMakeLists.txt | 153 +-- .../builddependenciesprovider-test.cpp | 274 ---- .../builddependenciesstorage-test.cpp | 468 ------- .../builddependencycollector-test.cpp | 1042 -------------- .../clangindexingsettingsmanager-test.cpp | 83 -- tests/unit/unittest/clangpathwatcher-test.cpp | 402 ------ tests/unit/unittest/clangquery-test.cpp | 238 ---- .../clangqueryexamplehighlightmarker-test.cpp | 223 --- .../unit/unittest/clangquerygatherer-test.cpp | 357 ----- .../clangqueryhighlightmarker-test.cpp | 390 ------ .../clangqueryprojectfindfilter-test.cpp | 224 --- .../unit/unittest/commandlinebuilder-test.cpp | 660 --------- tests/unit/unittest/creator_dependency.pri | 4 - .../external/external1.h | 3 - .../external/external2.h | 1 - .../external/external3.h | 1 - .../external/indirect_external.h | 3 - .../external/indirect_external2.h | 2 - .../builddependencycollector/project/false.h | 2 - .../project/faulty.cpp | 1 - .../builddependencycollector/project/faulty.h | 8 - .../project/header1.h | 2 - .../project/header2.h | 3 - .../builddependencycollector/project/if.cpp | 7 - .../project/indirect_missinginclude.h | 3 - .../project/indirect_missinginclude2.h | 3 - .../project/indirect_missinginclude3.h | 3 - .../project/indirect_missinginclude4.h | 5 - .../builddependencycollector/project/macros.h | 11 - .../builddependencycollector/project/main.cpp | 4 - .../project/main2.cpp | 5 - .../project/main3.cpp | 6 - .../project/main4.cpp | 10 - .../project/main5.cpp | 4 - .../project/main6.cpp | 3 - .../project/missingfile.cpp | 6 - .../project/missingfile.h | 8 - .../project/missinginclude2.h | 3 - .../project/missinginclude3.h | 3 - .../builddependencycollector/project/true.h | 2 - .../system/indirect_system.h | 3 - .../system/indirect_system2.h | 2 - .../builddependencycollector/system/system1.h | 3 - .../builddependencycollector/system/system2.h | 1 - .../builddependencycollector/system/system3.h | 1 - .../unittest/data/filestatuscache_header.cpp | 0 .../unittest/data/filestatuscache_header.h | 1 - .../unit/unittest/data/preincludes/system1.h | 1 - .../unit/unittest/data/query_simpleclass.cpp | 8 - .../unittest/data/query_simplefunction.cpp | 8 - .../unittest/data/query_simplefunction2.cpp | 4 - .../unittest/data/query_simplefunction2.h | 2 - .../unittest/data/query_simplefunction3.cpp | 4 - tests/unit/unittest/data/renamevariable.cpp | 20 - .../data/sourcerangeextractor_location.cpp | 2 - .../unit/unittest/data/symbolfinder_macro.cpp | 15 - .../unittest/data/symbolindexer_header1.h | 0 .../unittest/data/symbolindexer_header2.h | 0 .../unittest/data/symbolindexer_main1.cpp | 1 - .../unittest/data/symbolindexer_main2.cpp | 0 .../data/symbolindexer_pathChanged.cpp | 1 - .../unittest/data/symbolindexing_main1.cpp | 41 - .../unittest/data/symbolscollector/class.cpp | 14 - .../unittest/data/symbolscollector/defines.h | 42 - .../unittest/data/symbolscollector/error.cpp | 1 - .../unittest/data/symbolscollector/header1.h | 3 - .../unittest/data/symbolscollector/header2.h | 1 - .../unittest/data/symbolscollector/header3.h | 3 - .../include/unmodified_header.h | 22 - .../include/unmodified_header2.h | 3 - .../unittest/data/symbolscollector/main.cpp | 4 - .../unittest/data/symbolscollector/main2.cpp | 5 - .../unittest/data/symbolscollector/simple.cpp | 15 - .../data/symbolscollector/symbolkind.cpp | 13 - .../data/symbolscollector/unmodified.cpp | 8 - .../data/symbolscollector/unmodified2.cpp | 9 - .../data/symbolscollector/unmodified3.cpp | 9 - .../data/symbolscollector/unsaved.cpp | 1 - .../unittest/directorypathcompressor-test.cpp | 99 -- tests/unit/unittest/filepath-test.cpp | 89 -- tests/unit/unittest/filepathcache-test.cpp | 490 ------- tests/unit/unittest/filepathstorage-test.cpp | 674 ---------- ...pathstoragesqlitestatementfactory-test.cpp | 86 -- tests/unit/unittest/filepathview-test.cpp | 125 -- tests/unit/unittest/filestatuscache-test.cpp | 298 ---- tests/unit/unittest/generatedfiles-test.cpp | 100 -- tests/unit/unittest/gtest-clang-printing.cpp | 1 - .../unit/unittest/gtest-creator-printing.cpp | 7 +- tests/unit/unittest/gtest-creator-printing.h | 2 - tests/unit/unittest/locatorfilter-test.cpp | 123 -- .../unittest/mockbuilddependenciesprovider.h | 49 - .../unittest/mockbuilddependenciesstorage.h | 71 - .../unittest/mockbuilddependencygenerator.h | 38 - tests/unit/unittest/mockclangpathwatcher.h | 41 - .../unittest/mockclangpathwatchernotifier.h | 40 - tests/unit/unittest/mockeditormanager.h | 43 - tests/unit/unittest/mockfilepathcaching.h | 47 - tests/unit/unittest/mockfilepathstorage.h | 57 - tests/unit/unittest/mockfilesystem.h | 38 - tests/unit/unittest/mockgeneratedfiles.h | 48 - tests/unit/unittest/mockmodifiedtimechecker.h | 47 - tests/unit/unittest/mockmutex.h | 4 +- tests/unit/unittest/mockpchcreator.h | 50 - tests/unit/unittest/mockpchmanagerclient.h | 52 - tests/unit/unittest/mockpchmanagernotifier.h | 41 - tests/unit/unittest/mockpchmanagerserver.h | 67 - tests/unit/unittest/mockpchtaskgenerator.h | 54 - tests/unit/unittest/mockpchtaskqueue.h | 49 - tests/unit/unittest/mockpchtasksmerger.h | 46 - .../unittest/mockprecompiledheaderstorage.h | 61 - tests/unit/unittest/mockprocessor.h | 79 -- tests/unit/unittest/mockprocessormanager.h | 36 - tests/unit/unittest/mockprogressmanager.h | 37 - tests/unit/unittest/mockprojectpartprovider.h | 39 - tests/unit/unittest/mockprojectpartqueue.h | 46 - tests/unit/unittest/mockprojectpartsmanager.h | 59 - tests/unit/unittest/mockprojectpartsstorage.h | 65 - tests/unit/unittest/mockrefactoringclient.h | 59 - tests/unit/unittest/mockrefactoringserver.h | 91 -- tests/unit/unittest/mocksearch.h | 38 - tests/unit/unittest/mocksearchhandle.h | 45 - tests/unit/unittest/mocksearchresult.h | 28 - .../unittest/mocksymbolindexertaskqueue.h | 39 - tests/unit/unittest/mocksymbolindexing.h | 43 - tests/unit/unittest/mocksymbolquery.h | 50 - tests/unit/unittest/mocksymbolscollector.h | 104 -- tests/unit/unittest/mocksymbolstorage.h | 40 - tests/unit/unittest/mocktaskscheduler.h | 46 - .../unittest/modifiedtimechecker-test.cpp | 134 -- tests/unit/unittest/nativefilepath-test.cpp | 100 -- .../unit/unittest/nativefilepathview-test.cpp | 143 -- tests/unit/unittest/pchcreator-test.cpp | 440 ------ tests/unit/unittest/pchmanagerclient-test.cpp | 122 -- .../pchmanagerclientserverinprocess-test.cpp | 200 --- tests/unit/unittest/pchmanagerserver-test.cpp | 442 ------ tests/unit/unittest/pchtaskgenerator-test.cpp | 202 --- tests/unit/unittest/pchtaskqueue-test.cpp | 503 ------- tests/unit/unittest/pchtasksmerger-test.cpp | 400 ------ .../precompiledheaderstorage-test.cpp | 525 -------- .../preprocessormacrocollector-test.cpp | 71 - tests/unit/unittest/processormanager-test.cpp | 112 -- tests/unit/unittest/progresscounter-test.cpp | 153 --- .../unittest/projectpartartefact-test.cpp | 209 --- .../unittest/projectpartsmanager-test.cpp | 945 ------------- .../unittest/projectpartsstorage-test.cpp | 671 --------- tests/unit/unittest/projectupdater-test.cpp | 542 -------- .../unit/unittest/refactoringclient-test.cpp | 217 --- .../refactoringclientserverinprocess-test.cpp | 254 ---- .../refactoringcompilationdatabase-test.cpp | 115 -- .../refactoringdatabaseinitializer-test.cpp | 368 ----- .../unit/unittest/refactoringengine-test.cpp | 201 --- .../refactoringprojectupdater-test.cpp | 137 -- .../unit/unittest/refactoringserver-test.cpp | 361 ----- .../unittest/sourcerangeextractor-test.cpp | 178 --- .../unit/unittest/sourcerangefilter-test.cpp | 122 -- tests/unit/unittest/sourcesmanager-test.cpp | 235 ---- tests/unit/unittest/sqlitereadstatementmock.h | 125 -- tests/unit/unittest/stringcache-test.cpp | 631 --------- tests/unit/unittest/symbolindexer-test.cpp | 1196 ----------------- .../unittest/symbolindexertaskqueue-test.cpp | 244 ---- tests/unit/unittest/symbolindexing-test.cpp | 151 --- tests/unit/unittest/symbolquery-test.cpp | 240 ---- tests/unit/unittest/symbolscollector-test.cpp | 688 ---------- .../unit/unittest/symbolsfindfilter-test.cpp | 43 - tests/unit/unittest/symbolstorage-test.cpp | 195 --- tests/unit/unittest/taskscheduler-test.cpp | 197 --- tests/unit/unittest/testclangtool.cpp | 52 - tests/unit/unittest/testclangtool.h | 44 - tests/unit/unittest/testenvironment.h | 50 - .../unittest/toolchainargumentscache-test.cpp | 193 --- tests/unit/unittest/unittest.pro | 105 -- tests/unit/unittest/unittest.qbs | 308 ----- .../unit/unittest/usedmacrocollector-test.cpp | 286 ---- tests/unit/unittest/usedmacrofilter-test.cpp | 144 -- 515 files changed, 31 insertions(+), 51951 deletions(-) delete mode 100644 src/libs/clangsupport/cancelmessage.cpp delete mode 100644 src/libs/clangsupport/cancelmessage.h delete mode 100644 src/libs/clangsupport/clangpathwatcher.h delete mode 100644 src/libs/clangsupport/clangpathwatcherinterface.h delete mode 100644 src/libs/clangsupport/clangpathwatchernotifier.h delete mode 100644 src/libs/clangsupport/clangrefactoringclientmessages.h delete mode 100644 src/libs/clangsupport/clangrefactoringmessages.h delete mode 100644 src/libs/clangsupport/clangrefactoringservermessages.h delete mode 100644 src/libs/clangsupport/clangsupportexceptions.h delete mode 100644 src/libs/clangsupport/commandlinebuilder.h delete mode 100644 src/libs/clangsupport/compilermacro.h delete mode 100644 src/libs/clangsupport/directoryandfilepathid.h delete mode 100644 src/libs/clangsupport/directorypathcompressor.h delete mode 100644 src/libs/clangsupport/directorypathid.h delete mode 100644 src/libs/clangsupport/dynamicastmatcherdiagnosticcontainer.cpp delete mode 100644 src/libs/clangsupport/dynamicastmatcherdiagnosticcontainer.h delete mode 100644 src/libs/clangsupport/dynamicastmatcherdiagnosticcontextcontainer.cpp delete mode 100644 src/libs/clangsupport/dynamicastmatcherdiagnosticcontextcontainer.h delete mode 100644 src/libs/clangsupport/dynamicastmatcherdiagnosticmessagecontainer.cpp delete mode 100644 src/libs/clangsupport/dynamicastmatcherdiagnosticmessagecontainer.h delete mode 100644 src/libs/clangsupport/dynamicmatcherdiagnostics.h delete mode 100644 src/libs/clangsupport/environment.h delete mode 100644 src/libs/clangsupport/executeinloop.h delete mode 100644 src/libs/clangsupport/filecontainerv2.cpp delete mode 100644 src/libs/clangsupport/filecontainerv2.h delete mode 100644 src/libs/clangsupport/filepath.cpp delete mode 100644 src/libs/clangsupport/filepath.h delete mode 100644 src/libs/clangsupport/filepathcache.h delete mode 100644 src/libs/clangsupport/filepathcaching.cpp delete mode 100644 src/libs/clangsupport/filepathcaching.h delete mode 100644 src/libs/clangsupport/filepathcachingfwd.h delete mode 100644 src/libs/clangsupport/filepathcachinginterface.h delete mode 100644 src/libs/clangsupport/filepathexceptions.h delete mode 100644 src/libs/clangsupport/filepathid.cpp delete mode 100644 src/libs/clangsupport/filepathid.h delete mode 100644 src/libs/clangsupport/filepathstorage.h delete mode 100644 src/libs/clangsupport/filepathstoragesources.h delete mode 100644 src/libs/clangsupport/filepathstoragesqlitestatementfactory.h delete mode 100644 src/libs/clangsupport/filepathview.h delete mode 100644 src/libs/clangsupport/filestatus.h delete mode 100644 src/libs/clangsupport/filestatuscache.cpp delete mode 100644 src/libs/clangsupport/filestatuscache.h delete mode 100644 src/libs/clangsupport/filesystem.cpp delete mode 100644 src/libs/clangsupport/filesystem.h delete mode 100644 src/libs/clangsupport/filesysteminterface.h delete mode 100644 src/libs/clangsupport/generatedfiles.cpp delete mode 100644 src/libs/clangsupport/generatedfiles.h delete mode 100644 src/libs/clangsupport/generatedfilesinterface.h delete mode 100644 src/libs/clangsupport/idpaths.h delete mode 100644 src/libs/clangsupport/includesearchpath.h delete mode 100644 src/libs/clangsupport/modifiedtimechecker.h delete mode 100644 src/libs/clangsupport/modifiedtimecheckerinterface.h delete mode 100644 src/libs/clangsupport/nativefilepath.h delete mode 100644 src/libs/clangsupport/pchmanagerclientinterface.cpp delete mode 100644 src/libs/clangsupport/pchmanagerclientinterface.h delete mode 100644 src/libs/clangsupport/pchmanagerclientproxy.cpp delete mode 100644 src/libs/clangsupport/pchmanagerclientproxy.h delete mode 100644 src/libs/clangsupport/pchmanagerserverinterface.cpp delete mode 100644 src/libs/clangsupport/pchmanagerserverinterface.h delete mode 100644 src/libs/clangsupport/pchmanagerserverproxy.cpp delete mode 100644 src/libs/clangsupport/pchmanagerserverproxy.h delete mode 100644 src/libs/clangsupport/pchpaths.h delete mode 100644 src/libs/clangsupport/precompiledheadersupdatedmessage.cpp delete mode 100644 src/libs/clangsupport/precompiledheadersupdatedmessage.h delete mode 100644 src/libs/clangsupport/progresscounter.h delete mode 100644 src/libs/clangsupport/progressmessage.h delete mode 100644 src/libs/clangsupport/projectmanagementserverinterface.h delete mode 100644 src/libs/clangsupport/projectpartartefact.cpp delete mode 100644 src/libs/clangsupport/projectpartartefact.h delete mode 100644 src/libs/clangsupport/projectpartcontainer.cpp delete mode 100644 src/libs/clangsupport/projectpartcontainer.h delete mode 100644 src/libs/clangsupport/projectpartid.h delete mode 100644 src/libs/clangsupport/projectpartpch.cpp delete mode 100644 src/libs/clangsupport/projectpartpch.h delete mode 100644 src/libs/clangsupport/projectpartsstorage.h delete mode 100644 src/libs/clangsupport/projectpartsstorageinterface.h delete mode 100644 src/libs/clangsupport/projectpartstoragestructs.h delete mode 100644 src/libs/clangsupport/refactoringclientinterface.cpp delete mode 100644 src/libs/clangsupport/refactoringclientinterface.h delete mode 100644 src/libs/clangsupport/refactoringclientproxy.cpp delete mode 100644 src/libs/clangsupport/refactoringclientproxy.h delete mode 100644 src/libs/clangsupport/refactoringdatabaseinitializer.h delete mode 100644 src/libs/clangsupport/refactoringserverinterface.cpp delete mode 100644 src/libs/clangsupport/refactoringserverinterface.h delete mode 100644 src/libs/clangsupport/refactoringserverproxy.cpp delete mode 100644 src/libs/clangsupport/refactoringserverproxy.h delete mode 100644 src/libs/clangsupport/removegeneratedfilesmessage.cpp delete mode 100644 src/libs/clangsupport/removegeneratedfilesmessage.h delete mode 100644 src/libs/clangsupport/removeprojectpartsmessage.h delete mode 100644 src/libs/clangsupport/requestsourcerangesanddiagnosticsforquerymessage.cpp delete mode 100644 src/libs/clangsupport/requestsourcerangesanddiagnosticsforquerymessage.h delete mode 100644 src/libs/clangsupport/requestsourcerangesforquerymessage.cpp delete mode 100644 src/libs/clangsupport/requestsourcerangesforquerymessage.h delete mode 100644 src/libs/clangsupport/sourceentry.h delete mode 100644 src/libs/clangsupport/sourcelocationcontainerv2.cpp delete mode 100644 src/libs/clangsupport/sourcelocationcontainerv2.h delete mode 100644 src/libs/clangsupport/sourcerangecontainerv2.cpp delete mode 100644 src/libs/clangsupport/sourcerangecontainerv2.h delete mode 100644 src/libs/clangsupport/sourcerangesanddiagnosticsforquerymessage.cpp delete mode 100644 src/libs/clangsupport/sourcerangesanddiagnosticsforquerymessage.h delete mode 100644 src/libs/clangsupport/sourcerangescontainer.cpp delete mode 100644 src/libs/clangsupport/sourcerangescontainer.h delete mode 100644 src/libs/clangsupport/sourcerangesforquerymessage.cpp delete mode 100644 src/libs/clangsupport/sourcerangesforquerymessage.h delete mode 100644 src/libs/clangsupport/sourcerangewithtextcontainer.cpp delete mode 100644 src/libs/clangsupport/sourcerangewithtextcontainer.h delete mode 100644 src/libs/clangsupport/stringcache.h delete mode 100644 src/libs/clangsupport/stringcachealgorithms.h delete mode 100644 src/libs/clangsupport/stringcacheentry.h delete mode 100644 src/libs/clangsupport/stringcachefwd.h delete mode 100644 src/libs/clangsupport/updategeneratedfilesmessage.cpp delete mode 100644 src/libs/clangsupport/updategeneratedfilesmessage.h delete mode 100644 src/libs/clangsupport/updateprojectpartsmessage.cpp delete mode 100644 src/libs/clangsupport/updateprojectpartsmessage.h delete mode 100644 src/plugins/clangpchmanager/CMakeLists.txt delete mode 100644 src/plugins/clangpchmanager/ClangPchManager.json.in delete mode 100644 src/plugins/clangpchmanager/clangindexingprojectsettings.cpp delete mode 100644 src/plugins/clangpchmanager/clangindexingprojectsettings.h delete mode 100644 src/plugins/clangpchmanager/clangindexingprojectsettingswidget.cpp delete mode 100644 src/plugins/clangpchmanager/clangindexingprojectsettingswidget.h delete mode 100644 src/plugins/clangpchmanager/clangindexingprojectsettingswidget.ui delete mode 100644 src/plugins/clangpchmanager/clangindexingsettingsmanager.cpp delete mode 100644 src/plugins/clangpchmanager/clangindexingsettingsmanager.h delete mode 100644 src/plugins/clangpchmanager/clangpchmanager-source.pri delete mode 100644 src/plugins/clangpchmanager/clangpchmanager.pro delete mode 100644 src/plugins/clangpchmanager/clangpchmanager.qbs delete mode 100644 src/plugins/clangpchmanager/clangpchmanager_dependencies.pri delete mode 100644 src/plugins/clangpchmanager/clangpchmanager_global.h delete mode 100644 src/plugins/clangpchmanager/clangpchmanagerplugin.cpp delete mode 100644 src/plugins/clangpchmanager/clangpchmanagerplugin.h delete mode 100644 src/plugins/clangpchmanager/pchmanagerclient.cpp delete mode 100644 src/plugins/clangpchmanager/pchmanagerclient.h delete mode 100644 src/plugins/clangpchmanager/pchmanagerconnectionclient.cpp delete mode 100644 src/plugins/clangpchmanager/pchmanagerconnectionclient.h delete mode 100644 src/plugins/clangpchmanager/pchmanagernotifierinterface.cpp delete mode 100644 src/plugins/clangpchmanager/pchmanagernotifierinterface.h delete mode 100644 src/plugins/clangpchmanager/pchmanagerprojectupdater.cpp delete mode 100644 src/plugins/clangpchmanager/pchmanagerprojectupdater.h delete mode 100644 src/plugins/clangpchmanager/preprocessormacrocollector.cpp delete mode 100644 src/plugins/clangpchmanager/preprocessormacrocollector.h delete mode 100644 src/plugins/clangpchmanager/preprocessormacrowidget.cpp delete mode 100644 src/plugins/clangpchmanager/preprocessormacrowidget.h delete mode 100644 src/plugins/clangpchmanager/progressmanager.h delete mode 100644 src/plugins/clangpchmanager/progressmanagerinterface.h delete mode 100644 src/plugins/clangpchmanager/projectupdater.cpp delete mode 100644 src/plugins/clangpchmanager/projectupdater.h delete mode 100644 src/plugins/clangpchmanager/qtcreatorprojectupdater.cpp delete mode 100644 src/plugins/clangpchmanager/qtcreatorprojectupdater.h delete mode 100644 src/plugins/clangrefactoring/CMakeLists.txt delete mode 100644 src/plugins/clangrefactoring/ClangRefactoring.json.in delete mode 100644 src/plugins/clangrefactoring/baseclangquerytexteditorwidget.cpp delete mode 100644 src/plugins/clangrefactoring/baseclangquerytexteditorwidget.h delete mode 100644 src/plugins/clangrefactoring/clangqueryexamplehighlighter.cpp delete mode 100644 src/plugins/clangrefactoring/clangqueryexamplehighlighter.h delete mode 100644 src/plugins/clangrefactoring/clangqueryexamplehighlightmarker.h delete mode 100644 src/plugins/clangrefactoring/clangqueryexampletexteditorwidget.cpp delete mode 100644 src/plugins/clangrefactoring/clangqueryexampletexteditorwidget.h delete mode 100644 src/plugins/clangrefactoring/clangqueryhighlighter.cpp delete mode 100644 src/plugins/clangrefactoring/clangqueryhighlighter.h delete mode 100644 src/plugins/clangrefactoring/clangqueryhighlightmarker.h delete mode 100644 src/plugins/clangrefactoring/clangqueryhoverhandler.cpp delete mode 100644 src/plugins/clangrefactoring/clangqueryhoverhandler.h delete mode 100644 src/plugins/clangrefactoring/clangqueryprojectsfindfilter.cpp delete mode 100644 src/plugins/clangrefactoring/clangqueryprojectsfindfilter.h delete mode 100644 src/plugins/clangrefactoring/clangqueryprojectsfindfilter.ui delete mode 100644 src/plugins/clangrefactoring/clangqueryprojectsfindfilterwidget.cpp delete mode 100644 src/plugins/clangrefactoring/clangqueryprojectsfindfilterwidget.h delete mode 100644 src/plugins/clangrefactoring/clangquerytexteditorwidget.cpp delete mode 100644 src/plugins/clangrefactoring/clangquerytexteditorwidget.h delete mode 100644 src/plugins/clangrefactoring/clangrefactoring-source.pri delete mode 100644 src/plugins/clangrefactoring/clangrefactoring.pro delete mode 100644 src/plugins/clangrefactoring/clangrefactoring.qbs delete mode 100644 src/plugins/clangrefactoring/clangrefactoring_dependencies.pri delete mode 100644 src/plugins/clangrefactoring/clangrefactoringplugin.cpp delete mode 100644 src/plugins/clangrefactoring/clangrefactoringplugin.h delete mode 100644 src/plugins/clangrefactoring/clangsymbolsfindfilter.cpp delete mode 100644 src/plugins/clangrefactoring/clangsymbolsfindfilter.h delete mode 100644 src/plugins/clangrefactoring/editormanagerinterface.h delete mode 100644 src/plugins/clangrefactoring/locatorfilter.cpp delete mode 100644 src/plugins/clangrefactoring/locatorfilter.h delete mode 100644 src/plugins/clangrefactoring/projectpartproviderinterface.h delete mode 100644 src/plugins/clangrefactoring/projectpartutilities.cpp delete mode 100644 src/plugins/clangrefactoring/projectpartutilities.h delete mode 100644 src/plugins/clangrefactoring/qtcreatorclangqueryfindfilter.cpp delete mode 100644 src/plugins/clangrefactoring/qtcreatorclangqueryfindfilter.h delete mode 100644 src/plugins/clangrefactoring/qtcreatoreditormanager.cpp delete mode 100644 src/plugins/clangrefactoring/qtcreatoreditormanager.h delete mode 100644 src/plugins/clangrefactoring/qtcreatorrefactoringprojectupdater.cpp delete mode 100644 src/plugins/clangrefactoring/qtcreatorrefactoringprojectupdater.h delete mode 100644 src/plugins/clangrefactoring/qtcreatorsearch.cpp delete mode 100644 src/plugins/clangrefactoring/qtcreatorsearch.h delete mode 100644 src/plugins/clangrefactoring/qtcreatorsearchhandle.cpp delete mode 100644 src/plugins/clangrefactoring/qtcreatorsearchhandle.h delete mode 100644 src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.cpp delete mode 100644 src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.h delete mode 100644 src/plugins/clangrefactoring/querysqlitestatementfactory.h delete mode 100644 src/plugins/clangrefactoring/refactoringclient.cpp delete mode 100644 src/plugins/clangrefactoring/refactoringclient.h delete mode 100644 src/plugins/clangrefactoring/refactoringconnectionclient.cpp delete mode 100644 src/plugins/clangrefactoring/refactoringconnectionclient.h delete mode 100644 src/plugins/clangrefactoring/refactoringengine.cpp delete mode 100644 src/plugins/clangrefactoring/refactoringengine.h delete mode 100644 src/plugins/clangrefactoring/refactoringprojectupdater.cpp delete mode 100644 src/plugins/clangrefactoring/refactoringprojectupdater.h delete mode 100644 src/plugins/clangrefactoring/searchhandle.cpp delete mode 100644 src/plugins/clangrefactoring/searchhandle.h delete mode 100644 src/plugins/clangrefactoring/searchinterface.h delete mode 100644 src/plugins/clangrefactoring/sourcelocations.h delete mode 100644 src/plugins/clangrefactoring/symbol.h delete mode 100644 src/plugins/clangrefactoring/symbolquery.h delete mode 100644 src/plugins/clangrefactoring/symbolqueryinterface.h delete mode 100644 src/plugins/clangrefactoring/symbolsfindfilterconfigwidget.cpp delete mode 100644 src/plugins/clangrefactoring/symbolsfindfilterconfigwidget.h delete mode 100644 src/tools/clangpchmanagerbackend/CMakeLists.txt delete mode 100644 src/tools/clangpchmanagerbackend/clangpchmanagerbackend.pro delete mode 100644 src/tools/clangpchmanagerbackend/clangpchmanagerbackend.qbs delete mode 100644 src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp delete mode 100644 src/tools/clangpchmanagerbackend/source/CMakeLists.txt delete mode 100644 src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp delete mode 100644 src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h delete mode 100644 src/tools/clangpchmanagerbackend/source/builddependenciesproviderinterface.h delete mode 100644 src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h delete mode 100644 src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h delete mode 100644 src/tools/clangpchmanagerbackend/source/builddependency.h delete mode 100644 src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp delete mode 100644 src/tools/clangpchmanagerbackend/source/builddependencycollector.h delete mode 100644 src/tools/clangpchmanagerbackend/source/builddependencygeneratorinterface.h delete mode 100644 src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri delete mode 100644 src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend_global.h delete mode 100644 src/tools/clangpchmanagerbackend/source/collectbuilddependencyaction.h delete mode 100644 src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h delete mode 100644 src/tools/clangpchmanagerbackend/source/collectbuilddependencytoolaction.h delete mode 100644 src/tools/clangpchmanagerbackend/source/collectusedmacroactionfactory.h delete mode 100644 src/tools/clangpchmanagerbackend/source/collectusedmacrosaction.h delete mode 100644 src/tools/clangpchmanagerbackend/source/collectusedmacrosandsourcespreprocessorcallbacks.h delete mode 100644 src/tools/clangpchmanagerbackend/source/generatepchactionfactory.h delete mode 100644 src/tools/clangpchmanagerbackend/source/pchcreator.cpp delete mode 100644 src/tools/clangpchmanagerbackend/source/pchcreator.h delete mode 100644 src/tools/clangpchmanagerbackend/source/pchcreatorinterface.h delete mode 100644 src/tools/clangpchmanagerbackend/source/pchmanagerserver.cpp delete mode 100644 src/tools/clangpchmanagerbackend/source/pchmanagerserver.h delete mode 100644 src/tools/clangpchmanagerbackend/source/pchnotcreatederror.h delete mode 100644 src/tools/clangpchmanagerbackend/source/pchtask.h delete mode 100644 src/tools/clangpchmanagerbackend/source/pchtaskgenerator.cpp delete mode 100644 src/tools/clangpchmanagerbackend/source/pchtaskgenerator.h delete mode 100644 src/tools/clangpchmanagerbackend/source/pchtaskgeneratorinterface.h delete mode 100644 src/tools/clangpchmanagerbackend/source/pchtaskqueue.cpp delete mode 100644 src/tools/clangpchmanagerbackend/source/pchtaskqueue.h delete mode 100644 src/tools/clangpchmanagerbackend/source/pchtaskqueueinterface.h delete mode 100644 src/tools/clangpchmanagerbackend/source/pchtasksmerger.cpp delete mode 100644 src/tools/clangpchmanagerbackend/source/pchtasksmerger.h delete mode 100644 src/tools/clangpchmanagerbackend/source/pchtasksmergerinterface.h delete mode 100644 src/tools/clangpchmanagerbackend/source/precompiledheaderstorage.h delete mode 100644 src/tools/clangpchmanagerbackend/source/precompiledheaderstorageinterface.h delete mode 100644 src/tools/clangpchmanagerbackend/source/processorinterface.h delete mode 100644 src/tools/clangpchmanagerbackend/source/processormanager.h delete mode 100644 src/tools/clangpchmanagerbackend/source/processormanagerinterface.h delete mode 100644 src/tools/clangpchmanagerbackend/source/projectpartsmanager.cpp delete mode 100644 src/tools/clangpchmanagerbackend/source/projectpartsmanager.h delete mode 100644 src/tools/clangpchmanagerbackend/source/projectpartsmanagerinterface.h delete mode 100644 src/tools/clangpchmanagerbackend/source/queueinterface.h delete mode 100644 src/tools/clangpchmanagerbackend/source/taskscheduler.h delete mode 100644 src/tools/clangpchmanagerbackend/source/taskschedulerinterface.h delete mode 100644 src/tools/clangpchmanagerbackend/source/toolchainargumentscache.h delete mode 100644 src/tools/clangpchmanagerbackend/source/usedmacrofilter.h delete mode 100644 src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.cpp delete mode 100644 src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.h delete mode 100644 src/tools/clangrefactoringbackend/CMakeLists.txt delete mode 100644 src/tools/clangrefactoringbackend/clangrefactoringbackend.pro delete mode 100644 src/tools/clangrefactoringbackend/clangrefactoringbackend.qbs delete mode 100644 src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/CMakeLists.txt delete mode 100644 src/tools/clangrefactoringbackend/source/clangquery.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/clangquery.h delete mode 100644 src/tools/clangrefactoringbackend/source/clangquerygatherer.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/clangquerygatherer.h delete mode 100644 src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri delete mode 100644 src/tools/clangrefactoringbackend/source/clangrefactoringbackend_global.h delete mode 100644 src/tools/clangrefactoringbackend/source/clangtool.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/clangtool.h delete mode 100644 src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h delete mode 100644 src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.h delete mode 100644 src/tools/clangrefactoringbackend/source/collectsymbolsaction.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/collectsymbolsaction.h delete mode 100644 src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/indexdataconsumer.h delete mode 100644 src/tools/clangrefactoringbackend/source/locationsourcefilecallbacks.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/locationsourcefilecallbacks.h delete mode 100644 src/tools/clangrefactoringbackend/source/macropreprocessorcallbacks.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/macropreprocessorcallbacks.h delete mode 100644 src/tools/clangrefactoringbackend/source/projectpartentry.h delete mode 100644 src/tools/clangrefactoringbackend/source/refactoringcompilationdatabase.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/refactoringcompilationdatabase.h delete mode 100644 src/tools/clangrefactoringbackend/source/refactoringserver.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/refactoringserver.h delete mode 100644 src/tools/clangrefactoringbackend/source/sourcedependency.h delete mode 100644 src/tools/clangrefactoringbackend/source/sourcelocationentry.h delete mode 100644 src/tools/clangrefactoringbackend/source/sourcelocationsutils.h delete mode 100644 src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/sourcerangeextractor.h delete mode 100644 src/tools/clangrefactoringbackend/source/sourcerangefilter.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/sourcerangefilter.h delete mode 100644 src/tools/clangrefactoringbackend/source/sourcesmanager.h delete mode 100644 src/tools/clangrefactoringbackend/source/symbolentry.h delete mode 100644 src/tools/clangrefactoringbackend/source/symbolindexer.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/symbolindexer.h delete mode 100644 src/tools/clangrefactoringbackend/source/symbolindexertask.h delete mode 100644 src/tools/clangrefactoringbackend/source/symbolindexertaskqueue.h delete mode 100644 src/tools/clangrefactoringbackend/source/symbolindexertaskqueueinterface.h delete mode 100644 src/tools/clangrefactoringbackend/source/symbolindexing.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/symbolindexing.h delete mode 100644 src/tools/clangrefactoringbackend/source/symbolindexinginterface.h delete mode 100644 src/tools/clangrefactoringbackend/source/symbolscollector.cpp delete mode 100644 src/tools/clangrefactoringbackend/source/symbolscollector.h delete mode 100644 src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h delete mode 100644 src/tools/clangrefactoringbackend/source/symbolstorage.h delete mode 100644 src/tools/clangrefactoringbackend/source/symbolstorageinterface.h delete mode 100644 src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h delete mode 100644 src/tools/clangrefactoringbackend/source/usedmacro.h delete mode 100644 tests/unit/unittest/builddependenciesprovider-test.cpp delete mode 100644 tests/unit/unittest/builddependenciesstorage-test.cpp delete mode 100644 tests/unit/unittest/builddependencycollector-test.cpp delete mode 100644 tests/unit/unittest/clangindexingsettingsmanager-test.cpp delete mode 100644 tests/unit/unittest/clangpathwatcher-test.cpp delete mode 100644 tests/unit/unittest/clangquery-test.cpp delete mode 100644 tests/unit/unittest/clangqueryexamplehighlightmarker-test.cpp delete mode 100644 tests/unit/unittest/clangquerygatherer-test.cpp delete mode 100644 tests/unit/unittest/clangqueryhighlightmarker-test.cpp delete mode 100644 tests/unit/unittest/clangqueryprojectfindfilter-test.cpp delete mode 100644 tests/unit/unittest/commandlinebuilder-test.cpp delete mode 100644 tests/unit/unittest/data/builddependencycollector/external/external1.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/external/external2.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/external/external3.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/external/indirect_external.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/external/indirect_external2.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/false.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/faulty.cpp delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/faulty.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/header1.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/header2.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/if.cpp delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/indirect_missinginclude.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/indirect_missinginclude2.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/indirect_missinginclude3.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/indirect_missinginclude4.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/macros.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/main.cpp delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/main2.cpp delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/main3.cpp delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/main4.cpp delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/main5.cpp delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/main6.cpp delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/missingfile.cpp delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/missingfile.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/missinginclude2.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/missinginclude3.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/project/true.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/system/indirect_system.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/system/indirect_system2.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/system/system1.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/system/system2.h delete mode 100644 tests/unit/unittest/data/builddependencycollector/system/system3.h delete mode 100644 tests/unit/unittest/data/filestatuscache_header.cpp delete mode 100644 tests/unit/unittest/data/filestatuscache_header.h delete mode 100644 tests/unit/unittest/data/preincludes/system1.h delete mode 100644 tests/unit/unittest/data/query_simpleclass.cpp delete mode 100644 tests/unit/unittest/data/query_simplefunction.cpp delete mode 100644 tests/unit/unittest/data/query_simplefunction2.cpp delete mode 100644 tests/unit/unittest/data/query_simplefunction2.h delete mode 100644 tests/unit/unittest/data/query_simplefunction3.cpp delete mode 100644 tests/unit/unittest/data/renamevariable.cpp delete mode 100644 tests/unit/unittest/data/sourcerangeextractor_location.cpp delete mode 100644 tests/unit/unittest/data/symbolfinder_macro.cpp delete mode 100644 tests/unit/unittest/data/symbolindexer_header1.h delete mode 100644 tests/unit/unittest/data/symbolindexer_header2.h delete mode 100644 tests/unit/unittest/data/symbolindexer_main1.cpp delete mode 100644 tests/unit/unittest/data/symbolindexer_main2.cpp delete mode 100644 tests/unit/unittest/data/symbolindexer_pathChanged.cpp delete mode 100644 tests/unit/unittest/data/symbolindexing_main1.cpp delete mode 100644 tests/unit/unittest/data/symbolscollector/class.cpp delete mode 100644 tests/unit/unittest/data/symbolscollector/defines.h delete mode 100644 tests/unit/unittest/data/symbolscollector/error.cpp delete mode 100644 tests/unit/unittest/data/symbolscollector/header1.h delete mode 100644 tests/unit/unittest/data/symbolscollector/header2.h delete mode 100644 tests/unit/unittest/data/symbolscollector/header3.h delete mode 100644 tests/unit/unittest/data/symbolscollector/include/unmodified_header.h delete mode 100644 tests/unit/unittest/data/symbolscollector/include/unmodified_header2.h delete mode 100644 tests/unit/unittest/data/symbolscollector/main.cpp delete mode 100644 tests/unit/unittest/data/symbolscollector/main2.cpp delete mode 100644 tests/unit/unittest/data/symbolscollector/simple.cpp delete mode 100644 tests/unit/unittest/data/symbolscollector/symbolkind.cpp delete mode 100644 tests/unit/unittest/data/symbolscollector/unmodified.cpp delete mode 100644 tests/unit/unittest/data/symbolscollector/unmodified2.cpp delete mode 100644 tests/unit/unittest/data/symbolscollector/unmodified3.cpp delete mode 100644 tests/unit/unittest/data/symbolscollector/unsaved.cpp delete mode 100644 tests/unit/unittest/directorypathcompressor-test.cpp delete mode 100644 tests/unit/unittest/filepath-test.cpp delete mode 100644 tests/unit/unittest/filepathcache-test.cpp delete mode 100644 tests/unit/unittest/filepathstorage-test.cpp delete mode 100644 tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp delete mode 100644 tests/unit/unittest/filepathview-test.cpp delete mode 100644 tests/unit/unittest/filestatuscache-test.cpp delete mode 100644 tests/unit/unittest/generatedfiles-test.cpp delete mode 100644 tests/unit/unittest/locatorfilter-test.cpp delete mode 100644 tests/unit/unittest/mockbuilddependenciesprovider.h delete mode 100644 tests/unit/unittest/mockbuilddependenciesstorage.h delete mode 100644 tests/unit/unittest/mockbuilddependencygenerator.h delete mode 100644 tests/unit/unittest/mockclangpathwatcher.h delete mode 100644 tests/unit/unittest/mockclangpathwatchernotifier.h delete mode 100644 tests/unit/unittest/mockeditormanager.h delete mode 100644 tests/unit/unittest/mockfilepathcaching.h delete mode 100644 tests/unit/unittest/mockfilepathstorage.h delete mode 100644 tests/unit/unittest/mockfilesystem.h delete mode 100644 tests/unit/unittest/mockgeneratedfiles.h delete mode 100644 tests/unit/unittest/mockmodifiedtimechecker.h delete mode 100644 tests/unit/unittest/mockpchcreator.h delete mode 100644 tests/unit/unittest/mockpchmanagerclient.h delete mode 100644 tests/unit/unittest/mockpchmanagernotifier.h delete mode 100644 tests/unit/unittest/mockpchmanagerserver.h delete mode 100644 tests/unit/unittest/mockpchtaskgenerator.h delete mode 100644 tests/unit/unittest/mockpchtaskqueue.h delete mode 100644 tests/unit/unittest/mockpchtasksmerger.h delete mode 100644 tests/unit/unittest/mockprecompiledheaderstorage.h delete mode 100644 tests/unit/unittest/mockprocessor.h delete mode 100644 tests/unit/unittest/mockprocessormanager.h delete mode 100644 tests/unit/unittest/mockprogressmanager.h delete mode 100644 tests/unit/unittest/mockprojectpartprovider.h delete mode 100644 tests/unit/unittest/mockprojectpartqueue.h delete mode 100644 tests/unit/unittest/mockprojectpartsmanager.h delete mode 100644 tests/unit/unittest/mockprojectpartsstorage.h delete mode 100644 tests/unit/unittest/mockrefactoringclient.h delete mode 100644 tests/unit/unittest/mockrefactoringserver.h delete mode 100644 tests/unit/unittest/mocksearch.h delete mode 100644 tests/unit/unittest/mocksearchhandle.h delete mode 100644 tests/unit/unittest/mocksearchresult.h delete mode 100644 tests/unit/unittest/mocksymbolindexertaskqueue.h delete mode 100644 tests/unit/unittest/mocksymbolindexing.h delete mode 100644 tests/unit/unittest/mocksymbolquery.h delete mode 100644 tests/unit/unittest/mocksymbolscollector.h delete mode 100644 tests/unit/unittest/mocksymbolstorage.h delete mode 100644 tests/unit/unittest/mocktaskscheduler.h delete mode 100644 tests/unit/unittest/modifiedtimechecker-test.cpp delete mode 100644 tests/unit/unittest/nativefilepath-test.cpp delete mode 100644 tests/unit/unittest/nativefilepathview-test.cpp delete mode 100644 tests/unit/unittest/pchcreator-test.cpp delete mode 100644 tests/unit/unittest/pchmanagerclient-test.cpp delete mode 100644 tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp delete mode 100644 tests/unit/unittest/pchmanagerserver-test.cpp delete mode 100644 tests/unit/unittest/pchtaskgenerator-test.cpp delete mode 100644 tests/unit/unittest/pchtaskqueue-test.cpp delete mode 100644 tests/unit/unittest/pchtasksmerger-test.cpp delete mode 100644 tests/unit/unittest/precompiledheaderstorage-test.cpp delete mode 100644 tests/unit/unittest/preprocessormacrocollector-test.cpp delete mode 100644 tests/unit/unittest/processormanager-test.cpp delete mode 100644 tests/unit/unittest/progresscounter-test.cpp delete mode 100644 tests/unit/unittest/projectpartartefact-test.cpp delete mode 100644 tests/unit/unittest/projectpartsmanager-test.cpp delete mode 100644 tests/unit/unittest/projectpartsstorage-test.cpp delete mode 100644 tests/unit/unittest/projectupdater-test.cpp delete mode 100644 tests/unit/unittest/refactoringclient-test.cpp delete mode 100644 tests/unit/unittest/refactoringclientserverinprocess-test.cpp delete mode 100644 tests/unit/unittest/refactoringcompilationdatabase-test.cpp delete mode 100644 tests/unit/unittest/refactoringdatabaseinitializer-test.cpp delete mode 100644 tests/unit/unittest/refactoringengine-test.cpp delete mode 100644 tests/unit/unittest/refactoringprojectupdater-test.cpp delete mode 100644 tests/unit/unittest/refactoringserver-test.cpp delete mode 100644 tests/unit/unittest/sourcerangeextractor-test.cpp delete mode 100644 tests/unit/unittest/sourcerangefilter-test.cpp delete mode 100644 tests/unit/unittest/sourcesmanager-test.cpp delete mode 100644 tests/unit/unittest/stringcache-test.cpp delete mode 100644 tests/unit/unittest/symbolindexer-test.cpp delete mode 100644 tests/unit/unittest/symbolindexertaskqueue-test.cpp delete mode 100644 tests/unit/unittest/symbolindexing-test.cpp delete mode 100644 tests/unit/unittest/symbolquery-test.cpp delete mode 100644 tests/unit/unittest/symbolscollector-test.cpp delete mode 100644 tests/unit/unittest/symbolsfindfilter-test.cpp delete mode 100644 tests/unit/unittest/symbolstorage-test.cpp delete mode 100644 tests/unit/unittest/taskscheduler-test.cpp delete mode 100644 tests/unit/unittest/testclangtool.cpp delete mode 100644 tests/unit/unittest/testclangtool.h delete mode 100644 tests/unit/unittest/testenvironment.h delete mode 100644 tests/unit/unittest/toolchainargumentscache-test.cpp delete mode 100644 tests/unit/unittest/usedmacrocollector-test.cpp delete mode 100644 tests/unit/unittest/usedmacrofilter-test.cpp diff --git a/qbs/modules/libclang/libclang.qbs b/qbs/modules/libclang/libclang.qbs index 98c28719e19..93cd2d1c256 100644 --- a/qbs/modules/libclang/libclang.qbs +++ b/qbs/modules/libclang/libclang.qbs @@ -64,7 +64,6 @@ Module { return incl != llvmIncludeDir; }) property stringList llvmToolingCxxFlags: clangProbe.llvmToolingCxxFlags - property bool toolingEnabled: Environment.getEnv("QTC_ENABLE_CLANG_REFACTORING") validate: { if (!clangProbe.found) { diff --git a/src/libs/clangsupport/CMakeLists.txt b/src/libs/clangsupport/CMakeLists.txt index 93487a9f946..032284a10a4 100644 --- a/src/libs/clangsupport/CMakeLists.txt +++ b/src/libs/clangsupport/CMakeLists.txt @@ -14,7 +14,6 @@ add_qtc_library(ClangSupport alivemessage.cpp alivemessage.h annotationsmessage.cpp annotationsmessage.h baseserverproxy.cpp baseserverproxy.h - cancelmessage.cpp cancelmessage.h clangcodemodelclientinterface.cpp clangcodemodelclientinterface.h clangcodemodelclientmessages.h clangcodemodelclientproxy.cpp clangcodemodelclientproxy.h @@ -22,124 +21,48 @@ add_qtc_library(ClangSupport clangcodemodelserverinterface.cpp clangcodemodelserverinterface.h clangcodemodelservermessages.h clangcodemodelserverproxy.cpp clangcodemodelserverproxy.h - clangpathwatcher.h - clangpathwatcherinterface.h - clangpathwatchernotifier.h - clangrefactoringclientmessages.h - clangrefactoringmessages.h - clangrefactoringservermessages.h clangsupport_global.h clangsupportdebugutils.cpp clangsupportdebugutils.h - clangsupportexceptions.h codecompletion.cpp codecompletion.h codecompletionchunk.cpp codecompletionchunk.h - commandlinebuilder.h - compilermacro.h completionsmessage.cpp completionsmessage.h connectionclient.cpp connectionclient.h connectionserver.cpp connectionserver.h diagnosticcontainer.cpp diagnosticcontainer.h - directoryandfilepathid.h - directorypathid.h documentschangedmessage.cpp documentschangedmessage.h documentsclosedmessage.cpp documentsclosedmessage.h documentsopenedmessage.cpp documentsopenedmessage.h documentvisibilitychangedmessage.cpp documentvisibilitychangedmessage.h - dynamicastmatcherdiagnosticcontainer.cpp dynamicastmatcherdiagnosticcontainer.h - dynamicastmatcherdiagnosticcontextcontainer.cpp dynamicastmatcherdiagnosticcontextcontainer.h - dynamicastmatcherdiagnosticmessagecontainer.cpp dynamicastmatcherdiagnosticmessagecontainer.h - dynamicmatcherdiagnostics.h echomessage.cpp echomessage.h endmessage.cpp endmessage.h - environment.h - executeinloop.h filecontainer.cpp filecontainer.h - filecontainerv2.cpp filecontainerv2.h - filepath.cpp filepath.h - filepathcache.h - filepathcaching.cpp filepathcaching.h - filepathcachingfwd.h - filepathcachinginterface.h - filepathexceptions.h - filepathid.cpp filepathid.h - filepathstorage.h - filepathstoragesources.h - filepathstoragesqlitestatementfactory.h - filepathview.h - filestatus.h - filestatuscache.cpp filestatuscache.h - filesystem.cpp filesystem.h - filesysteminterface.h fixitcontainer.cpp fixitcontainer.h followsymbolmessage.cpp followsymbolmessage.h - generatedfiles.cpp generatedfiles.h - generatedfilesinterface.h - idpaths.h - includesearchpath.h ipcclientinterface.h ipcclientprovider.h ipcinterface.h ipcserverinterface.h lineprefixer.cpp lineprefixer.h messageenvelop.cpp messageenvelop.h - modifiedtimechecker.h - modifiedtimecheckerinterface.h - nativefilepath.h - pchmanagerclientinterface.cpp pchmanagerclientinterface.h - pchmanagerclientproxy.cpp pchmanagerclientproxy.h - pchmanagerserverinterface.cpp pchmanagerserverinterface.h - pchmanagerserverproxy.cpp pchmanagerserverproxy.h - pchpaths.h - precompiledheadersupdatedmessage.cpp precompiledheadersupdatedmessage.h processcreator.cpp processcreator.h processexception.cpp processexception.h processhandle.h processstartedevent.cpp processstartedevent.h - progresscounter.h - progressmessage.h - projectmanagementserverinterface.h - projectpartartefact.cpp projectpartartefact.h - projectpartcontainer.cpp projectpartcontainer.h - projectpartid.h - projectpartpch.cpp projectpartpch.h - projectpartsstorage.h - projectpartsstorageinterface.h readmessageblock.cpp readmessageblock.h - refactoringclientinterface.cpp refactoringclientinterface.h - refactoringclientproxy.cpp refactoringclientproxy.h - refactoringdatabaseinitializer.h - refactoringserverinterface.cpp refactoringserverinterface.h - refactoringserverproxy.cpp refactoringserverproxy.h referencesmessage.cpp referencesmessage.h - removegeneratedfilesmessage.cpp removegeneratedfilesmessage.h - removeprojectpartsmessage.h requestannotationsmessage.cpp requestannotationsmessage.h requestcompletionsmessage.cpp requestcompletionsmessage.h requestfollowsymbolmessage.cpp requestfollowsymbolmessage.h requestreferencesmessage.cpp requestreferencesmessage.h - requestsourcerangesanddiagnosticsforquerymessage.cpp requestsourcerangesanddiagnosticsforquerymessage.h - requestsourcerangesforquerymessage.cpp requestsourcerangesforquerymessage.h requesttooltipmessage.cpp requesttooltipmessage.h - sourceentry.h sourcelocationcontainer.cpp sourcelocationcontainer.h - sourcelocationcontainerv2.cpp sourcelocationcontainerv2.h sourcelocationscontainer.cpp sourcelocationscontainer.h sourcerangecontainer.cpp sourcerangecontainer.h - sourcerangecontainerv2.cpp sourcerangecontainerv2.h - sourcerangesanddiagnosticsforquerymessage.cpp sourcerangesanddiagnosticsforquerymessage.h - sourcerangescontainer.cpp sourcerangescontainer.h - sourcerangesforquerymessage.cpp sourcerangesforquerymessage.h - sourcerangewithtextcontainer.cpp sourcerangewithtextcontainer.h - stringcache.h - stringcachealgorithms.h - stringcachefwd.h tokeninfocontainer.cpp tokeninfocontainer.h tooltipinfo.cpp tooltipinfo.h tooltipmessage.cpp tooltipmessage.h unsavedfilesremovedmessage.cpp unsavedfilesremovedmessage.h unsavedfilesupdatedmessage.cpp unsavedfilesupdatedmessage.h - updategeneratedfilesmessage.cpp updategeneratedfilesmessage.h - updateprojectpartsmessage.cpp updateprojectpartsmessage.h writemessageblock.cpp writemessageblock.h ) diff --git a/src/libs/clangsupport/cancelmessage.cpp b/src/libs/clangsupport/cancelmessage.cpp deleted file mode 100644 index dbca27725b0..00000000000 --- a/src/libs/clangsupport/cancelmessage.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "cancelmessage.h" - -#include - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const CancelMessage &) -{ - debug.nospace() << "CancelMessage()"; - - return debug; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/cancelmessage.h b/src/libs/clangsupport/cancelmessage.h deleted file mode 100644 index c75076b16ae..00000000000 --- a/src/libs/clangsupport/cancelmessage.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangsupport_global.h" - -namespace ClangBackEnd { - -class CancelMessage -{ -public: - friend QDataStream &operator<<(QDataStream &out, const CancelMessage &/*message*/) - { - return out; - } - - friend QDataStream &operator>>(QDataStream &in, CancelMessage &/*message*/) - { - return in; - } - - friend bool operator==(const CancelMessage &/*first*/, const CancelMessage &/*second*/) - { - return true; - } -}; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const CancelMessage &message); - -DECLARE_MESSAGE(CancelMessage) -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/clangpathwatcher.h b/src/libs/clangsupport/clangpathwatcher.h deleted file mode 100644 index 27f76462710..00000000000 --- a/src/libs/clangsupport/clangpathwatcher.h +++ /dev/null @@ -1,449 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangpathwatcherinterface.h" -#include "clangpathwatchernotifier.h" -#include "directorypathcompressor.h" -#include "filepathcachinginterface.h" -#include "filesystem.h" -#include "stringcache.h" - -#include - -#include - -namespace ClangBackEnd { - -template -void set_greedy_intersection_call( - InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Callable callable) -{ - while (first1 != last1 && first2 != last2) { - if (*first1 < *first2) { - ++first1; - } else { - if (*first2 < *first1) - ++first2; - else - callable(*first1++); - } - } -} - -class WatcherEntry -{ -public: - ProjectChunkId id; - DirectoryPathId directoryPathId; - FilePathId filePathId; - long long lastModified = -1; - - friend bool operator==(WatcherEntry first, WatcherEntry second) - { - return first.id == second.id && first.directoryPathId == second.directoryPathId - && first.filePathId == second.filePathId; - } - - friend bool operator<(WatcherEntry first, WatcherEntry second) - { - return std::tie(first.directoryPathId, first.filePathId, first.id) - < std::tie(second.directoryPathId, second.filePathId, second.id); - } - - friend bool operator<(DirectoryPathId directoryPathId, WatcherEntry entry) - { - return directoryPathId < entry.directoryPathId; - } - - friend bool operator<(WatcherEntry entry, DirectoryPathId directoryPathId) - { - return entry.directoryPathId < directoryPathId; - } - - operator FilePathId() const { return filePathId; } - - operator DirectoryPathId() const { return directoryPathId; } -}; - -using WatcherEntries = std::vector; - -template -class CLANGSUPPORT_GCCEXPORT ClangPathWatcher : public ClangPathWatcherInterface -{ -public: - ClangPathWatcher(FilePathCachingInterface &pathCache, - FileSystemInterface &fileSystem, - ClangPathWatcherNotifier *notifier = nullptr) - : m_fileStatusCache(fileSystem) - , m_fileSystem(fileSystem) - , m_pathCache(pathCache) - , m_notifier(notifier) - { - QObject::connect(&m_fileSystemWatcher, - &FileSystemWatcher::directoryChanged, - [&](const QString &path) { compressChangedDirectoryPath(path); }); - - m_directoryPathCompressor.setCallback([&](ClangBackEnd::DirectoryPathIds &&directoryPathIds) { - addChangedPathForFilePath(std::move(directoryPathIds)); - }); - } - - ~ClangPathWatcher() - { - m_directoryPathCompressor.setCallback([&](DirectoryPathIds &&) {}); - } - - void updateIdPaths(const std::vector &idPaths) override - { - auto entriesAndIds = convertIdPathsToWatcherEntriesAndIds(idPaths); - - addEntries(entriesAndIds.first); - removeUnusedEntries(entriesAndIds.first, entriesAndIds.second); - } - - void removeIds(const ProjectPartIds &ids) override - { - auto removedEntries = removeIdsFromWatchedEntries(ids); - - auto filteredPaths = filterNotWatchedPaths(removedEntries); - - if (!filteredPaths.empty()) - m_fileSystemWatcher.removePaths(convertWatcherEntriesToDirectoryPathList(filteredPaths)); - } - - void setNotifier(ClangPathWatcherNotifier *notifier) override - { - m_notifier = notifier; - } - - std::size_t sizeOfIdPaths(const std::vector &idPaths) - { - auto sumSize = [] (std::size_t size, const IdPaths &idPath) { - return size + idPath.filePathIds.size(); - }; - - return std::accumulate(idPaths.begin(), idPaths.end(), std::size_t(0), sumSize); - } - - std::pair convertIdPathsToWatcherEntriesAndIds( - const std::vector &idPaths) - { - WatcherEntries entries; - entries.reserve(sizeOfIdPaths(idPaths)); - ProjectChunkIds ids; - ids.reserve(ids.size()); - - auto outputIterator = std::back_inserter(entries); - - for (const IdPaths &idPath : idPaths) - { - ProjectChunkId id = idPath.id; - - ids.push_back(id); - - outputIterator = std::transform(idPath.filePathIds.begin(), - idPath.filePathIds.end(), - outputIterator, - [&](FilePathId filePathId) { - return WatcherEntry{ - id, - m_pathCache.directoryPathId(filePathId), - filePathId, - m_fileStatusCache.lastModifiedTime(filePathId)}; - }); - } - - std::sort(entries.begin(), entries.end()); - std::sort(ids.begin(), ids.end()); - - return {entries, ids}; - } - - void addEntries(const WatcherEntries &entries) - { - auto newEntries = notWatchedEntries(entries); - - auto filteredPaths = filterNotWatchedPaths(newEntries); - - mergeToWatchedEntries(newEntries); - - if (!filteredPaths.empty()) - m_fileSystemWatcher.addPaths(convertWatcherEntriesToDirectoryPathList(filteredPaths)); - } - - void removeUnusedEntries(const WatcherEntries &entries, const ProjectChunkIds &ids) - { - auto oldEntries = notAnymoreWatchedEntriesWithIds(entries, ids); - - removeFromWatchedEntries(oldEntries); - - auto filteredPaths = filterNotWatchedPaths(oldEntries); - - if (!filteredPaths.empty()) - m_fileSystemWatcher.removePaths(convertWatcherEntriesToDirectoryPathList(filteredPaths)); - } - - FileSystemWatcher &fileSystemWatcher() { return m_fileSystemWatcher; } - - QStringList convertWatcherEntriesToDirectoryPathList(const DirectoryPathIds &directoryPathIds) const - { - return Utils::transform(directoryPathIds, [&](DirectoryPathId id) { - return QString(m_pathCache.directoryPath(id)); - }); - } - - QStringList convertWatcherEntriesToDirectoryPathList(const WatcherEntries &watcherEntries) const - { - DirectoryPathIds directoryPathIds = Utils::transform( - watcherEntries, [&](WatcherEntry entry) { return entry.directoryPathId; }); - - std::sort(directoryPathIds.begin(), directoryPathIds.end()); - directoryPathIds.erase(std::unique(directoryPathIds.begin(), directoryPathIds.end()), - directoryPathIds.end()); - - return convertWatcherEntriesToDirectoryPathList(directoryPathIds); - } - - WatcherEntries notWatchedEntries(const WatcherEntries &entries) const - { - WatcherEntries notWatchedEntries; - notWatchedEntries.reserve(entries.size()); - - std::set_difference(entries.begin(), - entries.end(), - m_watchedEntries.cbegin(), - m_watchedEntries.cend(), - std::back_inserter(notWatchedEntries)); - - return notWatchedEntries; - } - - DirectoryPathIds notWatchedPaths(const DirectoryPathIds &ids) const - { - DirectoryPathIds notWatchedDirectoryIds; - notWatchedDirectoryIds.reserve(ids.size()); - - std::set_difference(ids.begin(), - ids.end(), - m_watchedEntries.cbegin(), - m_watchedEntries.cend(), - std::back_inserter(notWatchedDirectoryIds)); - - return notWatchedDirectoryIds; - } - - template - WatcherEntries notAnymoreWatchedEntries( - const WatcherEntries &newEntries, - Compare compare) const - { - WatcherEntries notAnymoreWatchedEntries; - notAnymoreWatchedEntries.reserve(m_watchedEntries.size()); - - std::set_difference(m_watchedEntries.cbegin(), - m_watchedEntries.cend(), - newEntries.begin(), - newEntries.end(), - std::back_inserter(notAnymoreWatchedEntries), - compare); - - return notAnymoreWatchedEntries; - } - - WatcherEntries notAnymoreWatchedEntriesWithIds(const WatcherEntries &newEntries, - const ProjectChunkIds &ids) const - { - auto oldEntries = notAnymoreWatchedEntries(newEntries, std::less()); - - auto newEnd = std::remove_if(oldEntries.begin(), - oldEntries.end(), - [&] (WatcherEntry entry) { - return !std::binary_search(ids.begin(), ids.end(), entry.id); - }); - - oldEntries.erase(newEnd, oldEntries.end()); - - return oldEntries; - } - - void mergeToWatchedEntries(const WatcherEntries &newEntries) - { - WatcherEntries newWatchedEntries; - newWatchedEntries.reserve(m_watchedEntries.size() + newEntries.size()); - - std::merge(m_watchedEntries.cbegin(), - m_watchedEntries.cend(), - newEntries.begin(), - newEntries.end(), - std::back_inserter(newWatchedEntries)); - - m_watchedEntries = std::move(newWatchedEntries); - } - - static DirectoryPathIds uniquePaths(const WatcherEntries &pathEntries) - { - DirectoryPathIds uniqueDirectoryIds; - uniqueDirectoryIds.reserve(pathEntries.size()); - - auto compare = [](WatcherEntry first, WatcherEntry second) { - return first.directoryPathId == second.directoryPathId; - }; - - std::unique_copy(pathEntries.begin(), - pathEntries.end(), - std::back_inserter(uniqueDirectoryIds), - compare); - - return uniqueDirectoryIds; - } - - DirectoryPathIds filterNotWatchedPaths(const WatcherEntries &entries) const - { - return notWatchedPaths(uniquePaths(entries)); - } - - const WatcherEntries &watchedEntries() const - { - return m_watchedEntries; - } - - WatcherEntries removeIdsFromWatchedEntries(const ProjectPartIds &ids) - { - auto keep = [&](WatcherEntry entry) { - return !std::binary_search(ids.begin(), ids.end(), entry.id); - }; - - auto found = std::stable_partition(m_watchedEntries.begin(), m_watchedEntries.end(), keep); - - WatcherEntries removedEntries(found, m_watchedEntries.end()); - - m_watchedEntries.erase(found, m_watchedEntries.end()); - - return removedEntries; - } - - void removeFromWatchedEntries(const WatcherEntries &oldEntries) - { - WatcherEntries newWatchedEntries; - newWatchedEntries.reserve(m_watchedEntries.size() - oldEntries.size()); - - std::set_difference(m_watchedEntries.cbegin(), - m_watchedEntries.cend(), - oldEntries.begin(), - oldEntries.end(), - std::back_inserter(newWatchedEntries)); - - m_watchedEntries = std::move(newWatchedEntries); - } - - void compressChangedDirectoryPath(const QString &path) - { - m_directoryPathCompressor.addDirectoryPathId( - m_pathCache.directoryPathId(Utils::PathString{path})); - } - - WatcherEntries watchedEntriesForPaths(ClangBackEnd::DirectoryPathIds &&directoryPathIds) - { - WatcherEntries foundEntries; - foundEntries.reserve(m_watchedEntries.size()); - - set_greedy_intersection_call(m_watchedEntries.begin(), - m_watchedEntries.end(), - directoryPathIds.begin(), - directoryPathIds.end(), - [&](WatcherEntry &entry) { - m_fileStatusCache.update(entry.filePathId); - auto currentLastModified = m_fileStatusCache.lastModifiedTime( - entry.filePathId); - if (entry.lastModified < currentLastModified) { - foundEntries.push_back(entry); - entry.lastModified = currentLastModified; - } - }); - - return foundEntries; - } - - FilePathIds watchedPaths(const WatcherEntries &entries) const - { - auto filePathIds = Utils::transform(entries, &WatcherEntry::filePathId); - - std::sort(filePathIds.begin(), filePathIds.end()); - - filePathIds.erase(std::unique(filePathIds.begin(), filePathIds.end()), filePathIds.end()); - - return filePathIds; - } - - std::vector idPathsForWatcherEntries(WatcherEntries &&foundEntries) - { - std::sort(foundEntries.begin(), foundEntries.end(), [](WatcherEntry first, WatcherEntry second) { - return std::tie(first.id, first.filePathId) < std::tie(second.id, second.filePathId); - }); - - std::vector idPaths; - idPaths.reserve(foundEntries.size()); - - for (WatcherEntry entry : foundEntries) { - if (idPaths.empty() || idPaths.back().id != entry.id) - idPaths.emplace_back(entry.id, FilePathIds{}); - idPaths.back().filePathIds.push_back(entry.filePathId); - } - - return idPaths; - } - - void addChangedPathForFilePath(DirectoryPathIds &&directoryPathIds) - { - if (m_notifier) { - WatcherEntries foundEntries = watchedEntriesForPaths(std::move(directoryPathIds)); - - FilePathIds watchedFilePathIds = watchedPaths(foundEntries); - - std::vector changedIdPaths = idPathsForWatcherEntries(std::move(foundEntries)); - - m_notifier->pathsChanged(watchedFilePathIds); - m_notifier->pathsWithIdsChanged(changedIdPaths); - } - } - - FilePathCachingInterface &pathCache() - { - return m_pathCache; - } - -private: - WatcherEntries m_watchedEntries; - FileSystemWatcher m_fileSystemWatcher; - FileStatusCache m_fileStatusCache; - FileSystemInterface &m_fileSystem; - FilePathCachingInterface &m_pathCache; - ClangPathWatcherNotifier *m_notifier; - DirectoryPathCompressor m_directoryPathCompressor; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/clangpathwatcherinterface.h b/src/libs/clangsupport/clangpathwatcherinterface.h deleted file mode 100644 index 1b478fd19a4..00000000000 --- a/src/libs/clangsupport/clangpathwatcherinterface.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "idpaths.h" - -#include - -namespace ClangBackEnd { - -class ClangPathWatcherNotifier; - -class ClangPathWatcherInterface -{ -public: - ClangPathWatcherInterface() = default; - ClangPathWatcherInterface(const ClangPathWatcherInterface &) = delete; - ClangPathWatcherInterface &operator=(const ClangPathWatcherInterface &) = delete; - - virtual void updateIdPaths(const std::vector &idPaths) = 0; - virtual void removeIds(const ProjectPartIds &ids) = 0; - - virtual void setNotifier(ClangPathWatcherNotifier *notifier) = 0; - -protected: - ~ClangPathWatcherInterface() = default; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/clangpathwatchernotifier.h b/src/libs/clangsupport/clangpathwatchernotifier.h deleted file mode 100644 index 248925ffb92..00000000000 --- a/src/libs/clangsupport/clangpathwatchernotifier.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangsupport_global.h" -#include "filepathid.h" -#include "idpaths.h" - -#include - -namespace ClangBackEnd { - -class ClangPathWatcherNotifier -{ -public: - ClangPathWatcherNotifier() = default; - ClangPathWatcherNotifier(const ClangPathWatcherNotifier &) = delete; - ClangPathWatcherNotifier &operator=(const ClangPathWatcherNotifier &) = delete; - - virtual void pathsWithIdsChanged(const std::vector &idPaths) = 0; - virtual void pathsChanged(const FilePathIds &filePathIds) = 0; - -protected: - ~ClangPathWatcherNotifier() = default; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/clangrefactoringclientmessages.h b/src/libs/clangsupport/clangrefactoringclientmessages.h deleted file mode 100644 index 87b61b4c6ba..00000000000 --- a/src/libs/clangsupport/clangrefactoringclientmessages.h +++ /dev/null @@ -1,31 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "alivemessage.h" -#include "progressmessage.h" -#include "sourcerangesanddiagnosticsforquerymessage.h" -#include "sourcerangesforquerymessage.h" diff --git a/src/libs/clangsupport/clangrefactoringmessages.h b/src/libs/clangsupport/clangrefactoringmessages.h deleted file mode 100644 index 7f6f0de69ea..00000000000 --- a/src/libs/clangsupport/clangrefactoringmessages.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "clangrefactoringclientmessages.h" -#include "clangrefactoringservermessages.h" diff --git a/src/libs/clangsupport/clangrefactoringservermessages.h b/src/libs/clangsupport/clangrefactoringservermessages.h deleted file mode 100644 index 8a79518c7e6..00000000000 --- a/src/libs/clangsupport/clangrefactoringservermessages.h +++ /dev/null @@ -1,35 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "cancelmessage.h" -#include "endmessage.h" -#include "requestsourcerangesanddiagnosticsforquerymessage.h" -#include "requestsourcerangesforquerymessage.h" -#include "removegeneratedfilesmessage.h" -#include "removeprojectpartsmessage.h" -#include "updategeneratedfilesmessage.h" -#include "updateprojectpartsmessage.h" diff --git a/src/libs/clangsupport/clangsupport-lib.pri b/src/libs/clangsupport/clangsupport-lib.pri index 7eaee4a42aa..c53974ce0cf 100644 --- a/src/libs/clangsupport/clangsupport-lib.pri +++ b/src/libs/clangsupport/clangsupport-lib.pri @@ -9,7 +9,6 @@ QT += network INCLUDEPATH += $$PWD SOURCES += \ - $$PWD/cancelmessage.cpp \ $$PWD/clangsupportdebugutils.cpp \ $$PWD/clangcodemodelclientinterface.cpp \ $$PWD/clangcodemodelclientproxy.cpp \ @@ -18,7 +17,6 @@ SOURCES += \ $$PWD/clangcodemodelserverproxy.cpp \ $$PWD/alivemessage.cpp \ $$PWD/completionsmessage.cpp \ - $$PWD/filesystem.cpp \ $$PWD/requestcompletionsmessage.cpp \ $$PWD/echomessage.cpp \ $$PWD/endmessage.cpp \ @@ -30,70 +28,34 @@ SOURCES += \ $$PWD/connectionserver.cpp \ $$PWD/diagnosticcontainer.cpp \ $$PWD/annotationsmessage.cpp \ - $$PWD/dynamicastmatcherdiagnosticcontainer.cpp \ - $$PWD/dynamicastmatcherdiagnosticcontextcontainer.cpp \ - $$PWD/dynamicastmatcherdiagnosticmessagecontainer.cpp \ $$PWD/filecontainer.cpp \ - $$PWD/filecontainerv2.cpp \ - $$PWD/filepath.cpp \ $$PWD/fixitcontainer.cpp \ $$PWD/followsymbolmessage.cpp \ $$PWD/lineprefixer.cpp \ $$PWD/messageenvelop.cpp \ - $$PWD/pchmanagerclientinterface.cpp \ - $$PWD/pchmanagerclientproxy.cpp \ - $$PWD/pchmanagerserverinterface.cpp \ - $$PWD/pchmanagerserverproxy.cpp \ - $$PWD/precompiledheadersupdatedmessage.cpp \ - $$PWD/projectpartpch.cpp \ $$PWD/readmessageblock.cpp \ - $$PWD/refactoringclientinterface.cpp \ - $$PWD/refactoringclientproxy.cpp \ - $$PWD/refactoringserverinterface.cpp \ - $$PWD/refactoringserverproxy.cpp \ $$PWD/referencesmessage.cpp \ $$PWD/unsavedfilesupdatedmessage.cpp \ $$PWD/requestannotationsmessage.cpp \ $$PWD/requestfollowsymbolmessage.cpp \ $$PWD/requestreferencesmessage.cpp \ - $$PWD/requestsourcerangesanddiagnosticsforquerymessage.cpp \ - $$PWD/requestsourcerangesforquerymessage.cpp \ $$PWD/requesttooltipmessage.cpp \ $$PWD/sourcelocationcontainer.cpp \ - $$PWD/sourcelocationcontainerv2.cpp \ $$PWD/sourcelocationscontainer.cpp \ $$PWD/sourcerangecontainer.cpp \ $$PWD/processcreator.cpp \ $$PWD/processexception.cpp \ $$PWD/processstartedevent.cpp \ - $$PWD/sourcerangecontainerv2.cpp \ - $$PWD/sourcerangesanddiagnosticsforquerymessage.cpp \ - $$PWD/sourcerangescontainer.cpp \ - $$PWD/sourcerangesforquerymessage.cpp \ - $$PWD/sourcerangewithtextcontainer.cpp \ $$PWD/tokeninfocontainer.cpp \ $$PWD/tooltipmessage.cpp \ $$PWD/tooltipinfo.cpp \ $$PWD/unsavedfilesremovedmessage.cpp \ - $$PWD/updateprojectpartsmessage.cpp \ $$PWD/documentschangedmessage.cpp \ $$PWD/documentvisibilitychangedmessage.cpp \ $$PWD/writemessageblock.cpp \ - $$PWD/filepathcaching.cpp \ - $$PWD/filepathid.cpp \ - $$PWD/baseserverproxy.cpp \ - $$PWD/updategeneratedfilesmessage.cpp \ - $$PWD/removegeneratedfilesmessage.cpp \ - $$PWD/generatedfiles.cpp \ - $$PWD/projectpartartefact.cpp \ - $$PWD/projectpartcontainer.cpp \ - $$PWD/filestatuscache.cpp + $$PWD/baseserverproxy.cpp HEADERS += \ - $$PWD/cancelmessage.h \ - $$PWD/clangpathwatcher.h \ - $$PWD/clangpathwatcherinterface.h \ - $$PWD/clangpathwatchernotifier.h \ $$PWD/clangsupportdebugutils.h \ $$PWD/clangsupport_global.h \ $$PWD/clangcodemodelclientinterface.h \ @@ -103,22 +65,8 @@ HEADERS += \ $$PWD/clangcodemodelserverinterface.h \ $$PWD/clangcodemodelservermessages.h \ $$PWD/clangcodemodelserverproxy.h \ - $$PWD/clangrefactoringclientmessages.h \ - $$PWD/clangrefactoringmessages.h \ - $$PWD/clangrefactoringservermessages.h \ $$PWD/alivemessage.h \ - $$PWD/clangsupportexceptions.h \ $$PWD/completionsmessage.h \ - $$PWD/directoryandfilepathid.h \ - $$PWD/directorypathid.h \ - $$PWD/executeinloop.h \ - $$PWD/filesystem.h \ - $$PWD/filesysteminterface.h \ - $$PWD/pchpaths.h \ - $$PWD/projectpartid.h \ - $$PWD/projectpartsstorage.h \ - $$PWD/projectpartsstorageinterface.h \ - $$PWD/projectpartstoragestructs.h \ $$PWD/requestcompletionsmessage.h \ $$PWD/echomessage.h \ $$PWD/endmessage.h \ @@ -130,99 +78,36 @@ HEADERS += \ $$PWD/connectionserver.h \ $$PWD/diagnosticcontainer.h \ $$PWD/annotationsmessage.h \ - $$PWD/dynamicastmatcherdiagnosticcontainer.h \ - $$PWD/dynamicastmatcherdiagnosticcontextcontainer.h \ - $$PWD/dynamicastmatcherdiagnosticmessagecontainer.h \ - $$PWD/dynamicmatcherdiagnostics.h \ $$PWD/filecontainer.h \ - $$PWD/filecontainerv2.h \ $$PWD/fixitcontainer.h \ $$PWD/followsymbolmessage.h \ - $$PWD/idpaths.h \ $$PWD/ipcclientinterface.h \ $$PWD/ipcinterface.h \ $$PWD/ipcserverinterface.h \ $$PWD/lineprefixer.h \ $$PWD/messageenvelop.h \ - $$PWD/pchmanagerclientinterface.h \ - $$PWD/pchmanagerclientproxy.h \ - $$PWD/pchmanagerserverinterface.h \ - $$PWD/pchmanagerserverproxy.h \ - $$PWD/precompiledheadersupdatedmessage.h \ - $$PWD/projectpartpch.h \ $$PWD/readmessageblock.h \ - $$PWD/refactoringclientinterface.h \ - $$PWD/refactoringclientproxy.h \ - $$PWD/refactoringserverinterface.h \ - $$PWD/refactoringserverproxy.h \ $$PWD/referencesmessage.h \ - $$PWD/stringcacheentry.h \ $$PWD/unsavedfilesupdatedmessage.h \ - $$PWD/removeprojectpartsmessage.h \ $$PWD/requestannotationsmessage.h \ $$PWD/requestfollowsymbolmessage.h \ $$PWD/requestreferencesmessage.h \ - $$PWD/requestsourcerangesanddiagnosticsforquerymessage.h \ - $$PWD/requestsourcerangesforquerymessage.h \ $$PWD/requesttooltipmessage.h \ $$PWD/sourcelocationcontainer.h \ - $$PWD/sourcelocationcontainerv2.h \ $$PWD/sourcelocationscontainer.h \ $$PWD/sourcerangecontainer.h \ - $$PWD/filepath.h \ $$PWD/processcreator.h \ $$PWD/processexception.h \ $$PWD/processhandle.h \ $$PWD/processstartedevent.h \ - $$PWD/sourcerangecontainerv2.h \ - $$PWD/sourcerangesanddiagnosticsforquerymessage.h \ - $$PWD/sourcerangescontainer.h \ - $$PWD/sourcerangesforquerymessage.h \ - $$PWD/sourcerangewithtextcontainer.h \ - $$PWD/stringcache.h \ $$PWD/tokeninfocontainer.h \ $$PWD/tooltipmessage.h \ $$PWD/tooltipinfo.h \ $$PWD/unsavedfilesremovedmessage.h \ - $$PWD/updateprojectpartsmessage.h \ $$PWD/documentschangedmessage.h \ $$PWD/documentvisibilitychangedmessage.h \ $$PWD/writemessageblock.h \ $$PWD/ipcclientprovider.h \ - $$PWD/requestsourcerangesforquerymessage.h \ - $$PWD/stringcachefwd.h \ - $$PWD/stringcachealgorithms.h \ - $$PWD/projectmanagementserverinterface.h \ - $$PWD/refactoringdatabaseinitializer.h \ - $$PWD/filepathcache.h \ - $$PWD/filepathid.h \ - $$PWD/filepathstorage.h \ - $$PWD/filepathstoragesqlitestatementfactory.h \ - $$PWD/filepathstoragesources.h \ - $$PWD/filepathexceptions.h \ - $$PWD/filepathcachinginterface.h \ - $$PWD/filepathcaching.h \ - $$PWD/filepathcachingfwd.h \ - $$PWD/baseserverproxy.h \ - $$PWD/filepath.h \ - $$PWD/nativefilepath.h \ - $$PWD/filepathview.h \ - $$PWD/compilermacro.h \ - $$PWD/updategeneratedfilesmessage.h \ - $$PWD/removegeneratedfilesmessage.h \ - $$PWD/generatedfiles.h \ - $$PWD/generatedfilesinterface.h \ - $$PWD/progressmessage.h \ - $$PWD/progresscounter.h \ - $$PWD/includesearchpath.h \ - $$PWD/commandlinebuilder.h \ - $$PWD/projectpartartefact.h \ - $$PWD/projectpartcontainer.h \ - $$PWD/sourceentry.h \ - $$PWD/modifiedtimecheckerinterface.h \ - $$PWD/environment.h \ - $$PWD/filestatus.h \ - $$PWD/filestatuscache.h \ - $$PWD/modifiedtimechecker.h + $$PWD/baseserverproxy.h contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols diff --git a/src/libs/clangsupport/clangsupport_global.h b/src/libs/clangsupport/clangsupport_global.h index b482c103273..f8428e8ecf1 100644 --- a/src/libs/clangsupport/clangsupport_global.h +++ b/src/libs/clangsupport/clangsupport_global.h @@ -169,22 +169,6 @@ enum class MessageType : quint8 { RequestCompletionsMessage, CompletionsMessage, - - SourceLocationsForRenamingMessage, - RequestSourceLocationsForRenamingMessage, - - RequestSourceRangesAndDiagnosticsForQueryMessage, - RequestSourceRangesForQueryMessage, - SourceRangesAndDiagnosticsForQueryMessage, - SourceRangesForQueryMessage, - - CancelMessage, - UpdateProjectPartsMessage, - RemoveProjectPartsMessage, - PrecompiledHeadersUpdatedMessage, - UpdateGeneratedFilesMessage, - RemoveGeneratedFilesMessage, - ProgressMessage }; template diff --git a/src/libs/clangsupport/clangsupportexceptions.h b/src/libs/clangsupport/clangsupportexceptions.h deleted file mode 100644 index 05e48bea508..00000000000 --- a/src/libs/clangsupport/clangsupportexceptions.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -namespace ClangBackEnd { - -class ProjectPartArtefactParseError : public Sqlite::Exception -{ -public: - ProjectPartArtefactParseError(const char *whatErrorHasHappen, Utils::SmallString &&errorMessage) - : Exception(whatErrorHasHappen, std::move(errorMessage)) - {} -}; - -class ProjectPartDoesNotExists : public Sqlite::Exception -{ -public: - ProjectPartDoesNotExists(const char *whatErrorHasHappen, Utils::SmallString &&errorMessage) - : Exception(whatErrorHasHappen, std::move(errorMessage)) - {} -}; -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/commandlinebuilder.h b/src/libs/clangsupport/commandlinebuilder.h deleted file mode 100644 index 3aa3f1204fb..00000000000 --- a/src/libs/clangsupport/commandlinebuilder.h +++ /dev/null @@ -1,313 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "filepath.h" -#include "nativefilepath.h" - -#include -#include - -#include -#include - -#include -#include - -namespace ClangBackEnd { - -enum class InputFileType : unsigned char { Header, Source }; - -template -class CommandLineBuilder -{ -public: - CommandLineBuilder(const ProjectInfo &projectInfo, - const Utils::SmallStringVector &toolChainArguments = {}, - InputFileType sourceType = InputFileType::Header, - FilePathView sourcePath = {}, - FilePathView outputPath = {}, - FilePathView includePchPath = {}, - NativeFilePathView preIncludeSearchPath = {}) - { - commandLine.reserve(1024); - - addCompiler(projectInfo.language); - disableWarnings(); - addToolChainArguments(toolChainArguments); - addExtraFlags(); - addLanguage(projectInfo, sourceType); - addLanguageVersion(projectInfo); - addNoStdIncAndNoStdLibInc(projectInfo.language); - addCompilerMacros(projectInfo.compilerMacros); - addPreIncludeSearchPath(preIncludeSearchPath); - addProjectIncludeSearchPaths( - sortedIncludeSearchPaths(projectInfo.projectIncludeSearchPaths)); - addSystemAndBuiltInIncludeSearchPaths( - sortedIncludeSearchPaths(projectInfo.systemIncludeSearchPaths)); - addIncludePchPath(includePchPath); - addOutputPath(outputPath); - addSourcePath(sourcePath); - } - - void addCompiler(Utils::Language language) - { - if (language == Utils::Language::Cxx) - commandLine.emplace_back("clang++"); - else - commandLine.emplace_back("clang"); - } - - void disableWarnings() { commandLine.emplace_back("-w"); } - - void addToolChainArguments(const Utils::SmallStringVector &toolChainArguments) - { - for (Utils::SmallStringView argument : toolChainArguments) - commandLine.emplace_back(argument); - } - - void addExtraFlags() { commandLine.emplace_back("-DNOMINMAX"); } - - static const char *language(const ProjectInfo &projectInfo, InputFileType sourceType) - { - switch (projectInfo.language) { - case Utils::Language::C: - if (projectInfo.languageExtension && Utils::LanguageExtension::ObjectiveC) - return sourceType == InputFileType::Header ? "objective-c-header" : "objective-c"; - - return sourceType == InputFileType::Header ? "c-header" : "c"; - case Utils::Language::Cxx: - if (projectInfo.languageExtension && Utils::LanguageExtension::ObjectiveC) - return sourceType == InputFileType::Header ? "objective-c++-header" - : "objective-c++"; - return sourceType == InputFileType::Header ? "c++-header" : "c++"; - case Utils::Language::None: - return "none"; - } - - return "none"; - } - - void addLanguage(const ProjectInfo &projectInfo, InputFileType sourceType) - { - commandLine.emplace_back("-x"); - commandLine.emplace_back(language(projectInfo, sourceType)); - } - - const char *standardLanguageVersion(Utils::LanguageVersion languageVersion) - { - switch (languageVersion) { - case Utils::LanguageVersion::C89: - return "-std=c89"; - case Utils::LanguageVersion::C99: - return "-std=c99"; - case Utils::LanguageVersion::C11: - return "-std=c11"; - case Utils::LanguageVersion::C18: - return "-std=c17"; - case Utils::LanguageVersion::CXX98: - return "-std=c++98"; - case Utils::LanguageVersion::CXX03: - return "-std=c++03"; - case Utils::LanguageVersion::CXX11: - return "-std=c++11"; - case Utils::LanguageVersion::CXX14: - return "-std=c++14"; - case Utils::LanguageVersion::CXX17: - return "-std=c++17"; - case Utils::LanguageVersion::CXX2a: - return "-std=c++2a"; - case Utils::LanguageVersion::None: - return ""; - } - - return "-std=c++2a"; - } - - const char *gnuLanguageVersion(Utils::LanguageVersion languageVersion) - { - switch (languageVersion) { - case Utils::LanguageVersion::C89: - return "-std=gnu89"; - case Utils::LanguageVersion::C99: - return "-std=gnu99"; - case Utils::LanguageVersion::C11: - return "-std=gnu11"; - case Utils::LanguageVersion::C18: - return "-std=gnu17"; - case Utils::LanguageVersion::CXX98: - return "-std=gnu++98"; - case Utils::LanguageVersion::CXX03: - return "-std=gnu++03"; - case Utils::LanguageVersion::CXX11: - return "-std=gnu++11"; - case Utils::LanguageVersion::CXX14: - return "-std=gnu++14"; - case Utils::LanguageVersion::CXX17: - return "-std=gnu++17"; - case Utils::LanguageVersion::CXX2a: - return "-std=gnu++2a"; - case Utils::LanguageVersion::None: - return ""; - } - - return "-std=gnu++2a"; - } - - const char *includeOption(IncludeSearchPathType type) - { - switch (type) { - case IncludeSearchPathType::User: - case IncludeSearchPathType::System: - case IncludeSearchPathType::BuiltIn: - return "-isystem"; - case IncludeSearchPathType::Framework: - return "-F"; - case IncludeSearchPathType::Invalid: - return ""; - } - - return "-I"; - } - - void addLanguageVersion(const ProjectInfo &projectInfo) - { - if (projectInfo.languageExtension && Utils::LanguageExtension::Gnu) - commandLine.emplace_back(gnuLanguageVersion(projectInfo.languageVersion)); - else - commandLine.emplace_back(standardLanguageVersion(projectInfo.languageVersion)); - } - - void addCompilerMacros(const CompilerMacros &compilerMacros) - { - CompilerMacros macros = compilerMacros; - - macros.erase(std::remove_if(macros.begin(), - macros.end(), - [](const auto ¯o) { - return macro.type == CompilerMacroType::NotDefined; - }), - macros.end()); - - std::sort(macros.begin(), - macros.end(), - [](const CompilerMacro &first, const CompilerMacro &second) { - return first.index < second.index; - }); - - for (const CompilerMacro ¯o : macros) - commandLine.emplace_back(Utils::SmallString::join({"-D", macro.key, "=", macro.value})); - } - - void addPreIncludeSearchPath(NativeFilePathView preIncludeSearchPath) - { - if (!preIncludeSearchPath.empty()) { - commandLine.emplace_back("-isystem"); - commandLine.emplace_back(preIncludeSearchPath); - } - } - - IncludeSearchPaths sortedIncludeSearchPaths(const IncludeSearchPaths &unsortedPaths) - { - IncludeSearchPaths paths = unsortedPaths; - std::sort(paths.begin(), paths.end(), [](const auto &first, const auto &second) { - return first.index < second.index; - }); - - return paths; - } - - void addProjectIncludeSearchPaths(const IncludeSearchPaths &projectIncludeSearchPaths) - { - for (const IncludeSearchPath &path : projectIncludeSearchPaths) { - commandLine.emplace_back("-I"); - commandLine.emplace_back(NativeFilePath(FilePathView(path.path))); - } - } - - void addSystemAndBuiltInIncludeSearchPaths(const IncludeSearchPaths &systemIncludeSearchPaths) - { - addSystemIncludeSearchPaths(systemIncludeSearchPaths); - addBuiltInSystemSearchPaths(systemIncludeSearchPaths); - } - - void addSystemIncludeSearchPaths(const IncludeSearchPaths &systemIncludeSearchPaths) - { - for (const IncludeSearchPath &path : systemIncludeSearchPaths) { - if (path.type != IncludeSearchPathType::BuiltIn) { - commandLine.emplace_back(includeOption(path.type)); - commandLine.emplace_back(NativeFilePath(FilePathView(path.path))); - } - } - } - - void addBuiltInSystemSearchPaths(const IncludeSearchPaths &systemIncludeSearchPaths) - { - for (const IncludeSearchPath &path : systemIncludeSearchPaths) { - if (path.type == IncludeSearchPathType::BuiltIn) { - commandLine.emplace_back(includeOption(path.type)); - commandLine.emplace_back(NativeFilePath(FilePathView(path.path))); - } - } - } - - void addOutputPath(FilePathView outputPath) - { - if (!outputPath.isEmpty()) { - commandLine.emplace_back("-o"); - commandLine.emplace_back(NativeFilePath(outputPath)); - } - } - - void addSourcePath(FilePathView sourcePath) - { - if (!sourcePath.isEmpty()) - commandLine.emplace_back(NativeFilePath(sourcePath)); - } - - void addIncludePchPath(FilePathView includePchPath) - { - - if (!includePchPath.isEmpty()) { - commandLine.emplace_back("-Xclang"); - commandLine.emplace_back("-include-pch"); - commandLine.emplace_back("-Xclang"); - commandLine.emplace_back(NativeFilePath(includePchPath)); - } - } - - void addNoStdIncAndNoStdLibInc(Utils::Language language) - { - commandLine.emplace_back("-nostdinc"); - if (language == Utils::Language::Cxx) - commandLine.emplace_back("-nostdinc++"); - } - -public: - OutputContainer commandLine; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/compilermacro.h b/src/libs/clangsupport/compilermacro.h deleted file mode 100644 index 798bab2ebd7..00000000000 --- a/src/libs/clangsupport/compilermacro.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -#include - -namespace ClangBackEnd { - -enum class CompilerMacroType : unsigned char { Define, NotDefined }; - -class CompilerMacro -{ -public: - constexpr CompilerMacro() = default; - - CompilerMacro(Utils::SmallString &&key, Utils::SmallString &&value, int index) - : key(std::move(key)) - , value(std::move(value)) - , index(index) - , type(CompilerMacroType::Define) - {} - - CompilerMacro(Utils::SmallString &&key) - : key(std::move(key)) - {} - - CompilerMacro(const Utils::SmallString &key) - : key(key) - {} - - friend QDataStream &operator<<(QDataStream &out, const CompilerMacro &compilerMacro) - { - out << compilerMacro.key; - out << compilerMacro.value; - out << compilerMacro.index; - out << static_cast(compilerMacro.type); - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, CompilerMacro &compilerMacro) - { - unsigned char type; - - in >> compilerMacro.key; - in >> compilerMacro.value; - in >> compilerMacro.index; - in >> type; - - compilerMacro.type = static_cast(type); - - return in; - } - - friend bool operator==(const CompilerMacro &first, const CompilerMacro &second) - { - return first.key == second.key && first.value == second.value && first.type == second.type; - } - - friend bool operator<(const CompilerMacro &first, const CompilerMacro &second) - { - return std::tie(first.key, first.type, first.value) - < std::tie(second.key, second.type, second.value); - } - -public: - Utils::SmallString key; - Utils::SmallString value; - int index = -1; - CompilerMacroType type = CompilerMacroType::NotDefined; -}; - -using CompilerMacros = std::vector; -} diff --git a/src/libs/clangsupport/directoryandfilepathid.h b/src/libs/clangsupport/directoryandfilepathid.h deleted file mode 100644 index 8969372919d..00000000000 --- a/src/libs/clangsupport/directoryandfilepathid.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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 - -#include "directorypathid.h" -#include "filepathid.h" - -#include - -#include - -namespace ClangBackEnd { -class DirectoryAndFilePathId -{ -public: - constexpr DirectoryAndFilePathId() = default; - - DirectoryAndFilePathId(const char *) = delete; - - DirectoryAndFilePathId(int directoryPathId, int filePathId) - : directoryPathId(directoryPathId) - , filePathId(filePathId) - {} - - bool isValid() const { return directoryPathId.isValid() && filePathId.isValid(); } - - friend bool operator==(DirectoryAndFilePathId first, DirectoryAndFilePathId second) - { - return first.isValid() && first.directoryPathId == second.directoryPathId - && first.filePathId == second.filePathId; - } - - friend bool operator!=(DirectoryAndFilePathId first, DirectoryAndFilePathId second) - { - return !(first == second); - } - - friend bool operator<(DirectoryAndFilePathId first, DirectoryAndFilePathId second) - { - return std::tie(first.directoryPathId, first.filePathId) - < std::tie(second.directoryPathId, second.filePathId); - } - - friend QDataStream &operator<<(QDataStream &out, - const DirectoryAndFilePathId &directoryAndFilePathId) - { - out << directoryAndFilePathId.directoryPathId; - out << directoryAndFilePathId.filePathId; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, DirectoryAndFilePathId &directoryAndFilePathId) - { - in >> directoryAndFilePathId.directoryPathId; - in >> directoryAndFilePathId.filePathId; - return in; - } - -public: - DirectoryPathId directoryPathId; - FilePathId filePathId; -}; - -using DirectoryAndFilePathIds = std::vector; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/directorypathcompressor.h b/src/libs/clangsupport/directorypathcompressor.h deleted file mode 100644 index cd02948e834..00000000000 --- a/src/libs/clangsupport/directorypathcompressor.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangsupport_global.h" - -#include "filepathcachinginterface.h" - -#include -#include - -#include - -#include - -namespace ClangBackEnd { - -template -class DirectoryPathCompressor -{ -public: - DirectoryPathCompressor() { m_timer.setSingleShot(true); } - - virtual ~DirectoryPathCompressor() = default; - - void addDirectoryPathId(DirectoryPathId directoryPathIdId) - { - auto found = std::lower_bound(m_directoryPathIds.begin(), - m_directoryPathIds.end(), - directoryPathIdId); - - if (found == m_directoryPathIds.end() || *found != directoryPathIdId) - m_directoryPathIds.insert(found, directoryPathIdId); - - restartTimer(); - } - - DirectoryPathIds takeDirectoryPathIds() { return std::move(m_directoryPathIds); } - - virtual void setCallback(std::function &&callback) - { - QObject::connect(&m_timer, &Timer::timeout, [this, callback = std::move(callback)] { - callback(takeDirectoryPathIds()); - }); - } - -unittest_public: - virtual void restartTimer() - { - m_timer.start(20); - } - - Timer &timer() - { - return m_timer; - } - -private: - DirectoryPathIds m_directoryPathIds; - Timer m_timer; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/directorypathid.h b/src/libs/clangsupport/directorypathid.h deleted file mode 100644 index 2fd0b5847e7..00000000000 --- a/src/libs/clangsupport/directorypathid.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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 - -#include - -#include - -namespace ClangBackEnd { -class DirectoryPathId -{ -public: - constexpr DirectoryPathId() = default; - - DirectoryPathId(const char *) = delete; - - DirectoryPathId(int directoryPathId) - : directoryPathId(directoryPathId) - {} - - bool isValid() const { return directoryPathId >= 0; } - - friend bool operator==(DirectoryPathId first, DirectoryPathId second) - { - return first.isValid() && first.directoryPathId == second.directoryPathId; - } - - friend bool operator!=(DirectoryPathId first, DirectoryPathId second) - { - return !(first == second); - } - - friend bool operator<(DirectoryPathId first, DirectoryPathId second) - { - return first.directoryPathId < second.directoryPathId; - } - - friend QDataStream &operator<<(QDataStream &out, const DirectoryPathId &directoryPathId) - { - out << directoryPathId.directoryPathId; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, DirectoryPathId &directoryPathId) - { - in >> directoryPathId.directoryPathId; - - return in; - } - -public: - int directoryPathId = -1; -}; - -using DirectoryPathIds = std::vector; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/dynamicastmatcherdiagnosticcontainer.cpp b/src/libs/clangsupport/dynamicastmatcherdiagnosticcontainer.cpp deleted file mode 100644 index 7f081f1a622..00000000000 --- a/src/libs/clangsupport/dynamicastmatcherdiagnosticcontainer.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "dynamicastmatcherdiagnosticcontainer.h" - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const DynamicASTMatcherDiagnosticContainer &container) -{ - debug.nospace() << "DynamicASTMatcherDiagnosticContextContainer(" - << container.messages << ", " - << container.contexts - << ")"; - - return debug; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/dynamicastmatcherdiagnosticcontainer.h b/src/libs/clangsupport/dynamicastmatcherdiagnosticcontainer.h deleted file mode 100644 index 6a02fb842f0..00000000000 --- a/src/libs/clangsupport/dynamicastmatcherdiagnosticcontainer.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "dynamicastmatcherdiagnosticmessagecontainer.h" -#include "dynamicastmatcherdiagnosticcontextcontainer.h" - -namespace ClangBackEnd { - -class DynamicASTMatcherDiagnosticContainer -{ -public: - DynamicASTMatcherDiagnosticContainer() = default; - DynamicASTMatcherDiagnosticContainer(DynamicASTMatcherDiagnosticMessageContainers &&messages, - DynamicASTMatcherDiagnosticContextContainers &&contexts) - : messages(std::move(messages)), - contexts(std::move(contexts)) - { - } - - void insertMessage(V2::SourceRangeContainer &&sourceRange, - ClangQueryDiagnosticErrorType errorType, - Utils::SmallStringVector &&arguments) { - messages.emplace_back(std::move(sourceRange), errorType, std::move(arguments)); - } - - void insertContext(V2::SourceRangeContainer &&sourceRange, - ClangQueryDiagnosticContextType contextType, - Utils::SmallStringVector &&arguments) { - contexts.emplace_back(std::move(sourceRange), contextType, std::move(arguments)); - } - - friend QDataStream &operator<<(QDataStream &out, const DynamicASTMatcherDiagnosticContainer &container) - { - out << container.messages; - out << container.contexts; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, DynamicASTMatcherDiagnosticContainer &container) - { - in >> container.messages; - in >> container.contexts; - - return in; - } - - friend bool operator==(const DynamicASTMatcherDiagnosticContainer &first, - const DynamicASTMatcherDiagnosticContainer &second) - { - return first.messages == second.messages - && first.contexts == second.contexts; - } - - DynamicASTMatcherDiagnosticContainer clone() const - { - return *this; - } - -public: - DynamicASTMatcherDiagnosticMessageContainers messages; - DynamicASTMatcherDiagnosticContextContainers contexts; -}; - -using DynamicASTMatcherDiagnosticContainers = std::vector; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const DynamicASTMatcherDiagnosticContainer &container); - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/dynamicastmatcherdiagnosticcontextcontainer.cpp b/src/libs/clangsupport/dynamicastmatcherdiagnosticcontextcontainer.cpp deleted file mode 100644 index eed953cdf84..00000000000 --- a/src/libs/clangsupport/dynamicastmatcherdiagnosticcontextcontainer.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "dynamicastmatcherdiagnosticcontextcontainer.h" - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const DynamicASTMatcherDiagnosticContextContainer &container) -{ - debug.nospace() << "DynamicASTMatcherDiagnosticContextContainer(" - << container.sourceRange << ", " - << container.contextTypeText() << ", " - << container.arguments - << ")"; - - return debug; -} - -#define RETURN_CASE(name) \ - case ClangQueryDiagnosticContextType::name: return #name; - -Utils::SmallString DynamicASTMatcherDiagnosticContextContainer::contextTypeText() const -{ - switch (contextType) { - RETURN_CASE(MatcherArg) - RETURN_CASE(MatcherConstruct) - } - - Q_UNREACHABLE(); -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/dynamicastmatcherdiagnosticcontextcontainer.h b/src/libs/clangsupport/dynamicastmatcherdiagnosticcontextcontainer.h deleted file mode 100644 index aa46a346c5d..00000000000 --- a/src/libs/clangsupport/dynamicastmatcherdiagnosticcontextcontainer.h +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "dynamicmatcherdiagnostics.h" -#include "sourcerangecontainerv2.h" - -#include - -namespace ClangBackEnd { - -class DynamicASTMatcherDiagnosticContextContainer -{ -public: - DynamicASTMatcherDiagnosticContextContainer() = default; - DynamicASTMatcherDiagnosticContextContainer(V2::SourceRangeContainer &&sourceRange, - ClangQueryDiagnosticContextType contextType, - Utils::SmallStringVector &&arguments) - : sourceRange(sourceRange), - contextType(contextType), - arguments(std::move(arguments)) - { - } - - CLANGSUPPORT_EXPORT Utils::SmallString contextTypeText() const; - - friend QDataStream &operator<<(QDataStream &out, const DynamicASTMatcherDiagnosticContextContainer &container) - { - out << container.sourceRange; - out << quint32(container.contextType); - out << container.arguments; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, DynamicASTMatcherDiagnosticContextContainer &container) - { - quint32 contextType; - - in >> container.sourceRange; - in >> contextType; - in >> container.arguments; - - container.contextType = static_cast(contextType); - - return in; - } - - friend bool operator==(const DynamicASTMatcherDiagnosticContextContainer &first, - const DynamicASTMatcherDiagnosticContextContainer &second) - { - return first.contextType == second.contextType - && first.sourceRange == second.sourceRange - && first.arguments == second.arguments; - } - - DynamicASTMatcherDiagnosticContextContainer clone() const - { - return DynamicASTMatcherDiagnosticContextContainer(sourceRange.clone(), - contextType, - arguments.clone()); - } - -public: - V2::SourceRangeContainer sourceRange; - ClangQueryDiagnosticContextType contextType = ClangQueryDiagnosticContextType::MatcherArg; - Utils::SmallStringVector arguments; -}; - -using DynamicASTMatcherDiagnosticContextContainers = std::vector; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const DynamicASTMatcherDiagnosticContextContainer &container); - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/dynamicastmatcherdiagnosticmessagecontainer.cpp b/src/libs/clangsupport/dynamicastmatcherdiagnosticmessagecontainer.cpp deleted file mode 100644 index 70e73ca7be9..00000000000 --- a/src/libs/clangsupport/dynamicastmatcherdiagnosticmessagecontainer.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "dynamicastmatcherdiagnosticmessagecontainer.h" - -#define RETURN_CASE(name) \ - case ClangQueryDiagnosticErrorType::name: return #name; - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const DynamicASTMatcherDiagnosticMessageContainer &container) -{ - debug.nospace() << "DynamicASTMatcherDiagnosticMessageContainer(" - << container.errorTypeText() << ", " - << container.sourceRange << ", " - << container.arguments - << ")"; - - return debug; -} - -Utils::SmallString DynamicASTMatcherDiagnosticMessageContainer::errorTypeText() const -{ - switch (errorType) { - RETURN_CASE(None) - RETURN_CASE(RegistryMatcherNotFound) - RETURN_CASE(RegistryWrongArgCount) - RETURN_CASE(RegistryWrongArgType) - RETURN_CASE(RegistryNotBindable) - RETURN_CASE(RegistryAmbiguousOverload) - RETURN_CASE(RegistryValueNotFound) - RETURN_CASE(ParserStringError) - RETURN_CASE(ParserNoOpenParen) - RETURN_CASE(ParserNoCloseParen) - RETURN_CASE(ParserNoComma) - RETURN_CASE(ParserNoCode) - RETURN_CASE(ParserNotAMatcher) - RETURN_CASE(ParserInvalidToken) - RETURN_CASE(ParserMalformedBindExpr) - RETURN_CASE(ParserTrailingCode) - RETURN_CASE(ParserNumberError) - RETURN_CASE(ParserOverloadedType) - } - - Q_UNREACHABLE(); -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/dynamicastmatcherdiagnosticmessagecontainer.h b/src/libs/clangsupport/dynamicastmatcherdiagnosticmessagecontainer.h deleted file mode 100644 index 533028ae127..00000000000 --- a/src/libs/clangsupport/dynamicastmatcherdiagnosticmessagecontainer.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "dynamicmatcherdiagnostics.h" -#include "sourcerangecontainerv2.h" - -#include - -namespace ClangBackEnd { - -class DynamicASTMatcherDiagnosticMessageContainer -{ -public: - DynamicASTMatcherDiagnosticMessageContainer() = default; - DynamicASTMatcherDiagnosticMessageContainer(V2::SourceRangeContainer &&sourceRange, - ClangQueryDiagnosticErrorType errorType, - Utils::SmallStringVector &&arguments) - : sourceRange(sourceRange), - errorType(errorType), - arguments(std::move(arguments)) - { - } - - CLANGSUPPORT_EXPORT Utils::SmallString errorTypeText() const; - - friend QDataStream &operator<<(QDataStream &out, const DynamicASTMatcherDiagnosticMessageContainer &container) - { - out << container.sourceRange; - out << quint32(container.errorType); - out << container.arguments; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, DynamicASTMatcherDiagnosticMessageContainer &container) - { - quint32 errorType; - - in >> container.sourceRange; - in >> errorType; - in >> container.arguments; - - container.errorType = static_cast(errorType); - - return in; - } - - friend bool operator==(const DynamicASTMatcherDiagnosticMessageContainer &first, - const DynamicASTMatcherDiagnosticMessageContainer &second) - { - return first.errorType == second.errorType - && first.sourceRange == second.sourceRange - && first.arguments == second.arguments; - } - - DynamicASTMatcherDiagnosticMessageContainer clone() const - { - return *this; - } - -public: - V2::SourceRangeContainer sourceRange; - ClangQueryDiagnosticErrorType errorType = ClangQueryDiagnosticErrorType::None; - Utils::SmallStringVector arguments; -}; - -using DynamicASTMatcherDiagnosticMessageContainers = std::vector; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const DynamicASTMatcherDiagnosticMessageContainer &container); - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/dynamicmatcherdiagnostics.h b/src/libs/clangsupport/dynamicmatcherdiagnostics.h deleted file mode 100644 index 7f58ad934a2..00000000000 --- a/src/libs/clangsupport/dynamicmatcherdiagnostics.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** 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 ClangBackEnd { - -enum class ClangQueryDiagnosticContextType { - MatcherArg, - MatcherConstruct -}; - -enum class ClangQueryDiagnosticErrorType { - None, - - RegistryMatcherNotFound, - RegistryWrongArgCount, - RegistryWrongArgType, - RegistryNotBindable, - RegistryAmbiguousOverload, - RegistryValueNotFound, - - ParserStringError, - ParserNoOpenParen, - ParserNoCloseParen, - ParserNoComma, - ParserNoCode, - ParserNotAMatcher, - ParserInvalidToken, - ParserMalformedBindExpr, - ParserTrailingCode, - ParserNumberError, - ParserOverloadedType -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/environment.h b/src/libs/clangsupport/environment.h deleted file mode 100644 index ffa4d907cc2..00000000000 --- a/src/libs/clangsupport/environment.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include - -namespace ClangBackEnd { - -class Environment -{ -public: - Environment() = default; - Environment(const Environment &) = delete; - Environment &operator=(const Environment &) = delete; - - virtual Utils::PathString pchBuildDirectory() const = 0; - virtual uint hardwareConcurrency() const = 0; - virtual NativeFilePathView preIncludeSearchPath() const = 0; - -protected: - ~Environment() = default; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/executeinloop.h b/src/libs/clangsupport/executeinloop.h deleted file mode 100644 index 3642c3ccd3a..00000000000 --- a/src/libs/clangsupport/executeinloop.h +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include -#include -#include - -template -void executeInLoop(Callable &&callable, QObject *object = QCoreApplication::instance()) -{ - if (QThread *thread = qobject_cast(object)) - object = QAbstractEventDispatcher::instance(thread); - - QMetaObject::invokeMethod(object, std::forward(callable)); -} diff --git a/src/libs/clangsupport/filecontainerv2.cpp b/src/libs/clangsupport/filecontainerv2.cpp deleted file mode 100644 index af5d89a787b..00000000000 --- a/src/libs/clangsupport/filecontainerv2.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "filecontainerv2.h" - -namespace ClangBackEnd { -namespace V2 { - -QDebug operator<<(QDebug debug, const FileContainer &container) -{ - debug.nospace() << "FileContainer(" << container.filePath << ", " - << container.commandLineArguments << ", " - << container.unsavedFileContent.hasContent() << ", " - << container.documentRevision; - - debug.nospace() << ")"; - - return debug; -} - -} // namespace V2 -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filecontainerv2.h b/src/libs/clangsupport/filecontainerv2.h deleted file mode 100644 index e6e8c6622f4..00000000000 --- a/src/libs/clangsupport/filecontainerv2.h +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangsupport_global.h" -#include "filepath.h" -#include "filepathid.h" - -#include - -namespace ClangBackEnd { -namespace V2 { - -class FileContainer -{ -public: - FileContainer() = default; - - FileContainer(FilePath &&filePath, - FilePathId filePathId, - Utils::SmallString &&unsavedFileContent, - Utils::SmallStringVector &&commandLineArguments = {}, - quint32 documentRevision = 0) - : filePath(std::move(filePath)) - , filePathId(filePathId) - , unsavedFileContent(std::move(unsavedFileContent)) - , commandLineArguments(std::move(commandLineArguments)) - , documentRevision(documentRevision) - { - } - - friend QDataStream &operator<<(QDataStream &out, const FileContainer &container) - { - out << container.filePath; - out << container.commandLineArguments; - out << container.unsavedFileContent; - out << container.documentRevision; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, FileContainer &container) - { - in >> container.filePath; - in >> container.commandLineArguments; - in >> container.unsavedFileContent; - in >> container.documentRevision; - - return in; - } - - friend bool operator==(const FileContainer &first, const FileContainer &second) - { - return first.filePath == second.filePath - && first.commandLineArguments == second.commandLineArguments; - } - - friend bool operator<(const FileContainer &first, const FileContainer &second) - { - return std::tie(first.filePath, first.documentRevision, first.unsavedFileContent, first.commandLineArguments) - < std::tie(second.filePath, second.documentRevision, second.unsavedFileContent, second.commandLineArguments); - } - - FileContainer clone() const { return *this; } - -public: - FilePath filePath; - FilePathId filePathId; - Utils::SmallString unsavedFileContent; - Utils::SmallStringVector commandLineArguments; - quint32 documentRevision = 0; -}; - -using FileContainers = std::vector; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const FileContainer &container); - -} // namespace V2 -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filepath.cpp b/src/libs/clangsupport/filepath.cpp deleted file mode 100644 index 0dbb1b4e266..00000000000 --- a/src/libs/clangsupport/filepath.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "filepath.h" - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const FilePath &filePath) -{ - debug.nospace() << filePath.directory() << "/" << filePath.name(); - - return debug; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filepath.h b/src/libs/clangsupport/filepath.h deleted file mode 100644 index c29c1bd22ef..00000000000 --- a/src/libs/clangsupport/filepath.h +++ /dev/null @@ -1,197 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangsupport_global.h" - -#include "filepathview.h" - -#include -#include - -#include - -namespace ClangBackEnd { - -class NativeFilePath; - -class FilePath : public Utils::PathString -{ - using size_type = Utils::PathString::size_type; - -public: - FilePath() = default; - explicit FilePath(Utils::PathString &&filePath) - : Utils::PathString(std::move(filePath)) - { - FilePathView view{*this}; - - m_slashIndex = view.slashIndex(); - } - - explicit FilePath(Utils::SmallStringView &&filePath) - : Utils::PathString(filePath) - { - FilePathView view{*this}; - - m_slashIndex = view.slashIndex(); - } - - FilePath(FilePathView filePathView) - : Utils::PathString(filePathView.toStringView()), - m_slashIndex(filePathView.slashIndex()) - { - } - - template - FilePath(const char(&string)[Size]) noexcept - : FilePath(FilePathView(string, Size - 1)) - { - static_assert(Size >= 1, "Invalid string literal! Length is zero!"); - } - - explicit FilePath(const Utils::PathString &filePath) - : FilePath(filePath.clone()) - { - } - - explicit FilePath(Utils::PathString &&filePath, std::ptrdiff_t slashIndex) - : Utils::PathString(std::move(filePath)), - m_slashIndex(slashIndex) - { - } - - explicit FilePath(const QString &filePath) - : FilePath(Utils::PathString(filePath)) - { - } - - FilePath(Utils::SmallStringView directory, Utils::SmallStringView name) - : Utils::PathString(Utils::PathString::join({directory, "/", name})) - , m_slashIndex(std::ptrdiff_t(directory.size())) - {} - - bool isValid() const { return size() > 0 && m_slashIndex >= 0; } - - Utils::SmallStringView directory() const noexcept - { - return mid(0, std::size_t(std::max(std::ptrdiff_t(0), m_slashIndex))); - } - - Utils::SmallStringView name() const noexcept - { - return mid(std::size_t(m_slashIndex + 1), - std::size_t(std::ptrdiff_t(size()) - m_slashIndex - std::ptrdiff_t(1))); - } - - const Utils::PathString &path() const noexcept - { - return *this; - } - - operator FilePathView() const noexcept - { - return FilePathView(toStringView()); - } - - operator Utils::SmallStringView() const noexcept - { - return toStringView(); - } - - friend QDataStream &operator<<(QDataStream &out, const FilePath &filePath) - { - out << static_cast(filePath); - out << uint(filePath.m_slashIndex); - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, FilePath &filePath) - { - uint slashIndex; - - in >> static_cast(filePath); - in >> slashIndex; - - filePath.m_slashIndex = slashIndex; - - return in; - } - - friend bool operator==(const FilePath &first, const FilePath &second) - { - return first.slashIndex() == second.slashIndex() - && first.name() == second.name() - && first.directory() == second.directory(); - } - - friend bool operator==(const FilePath &first, const FilePathView &second) - { - return first.toStringView() == second.toStringView(); - } - - friend bool operator==(const FilePathView &first, const FilePath &second) - { - return second == first; - } - - friend bool operator<(const FilePath &first, const FilePath &second) - { - return std::make_tuple(first.slashIndex(), first.name(), first.directory()) - < std::make_tuple(second.slashIndex(), second.name(), second.directory()); - } - - FilePath clone() const - { - return *this; - } - - std::ptrdiff_t slashIndex() const - { - return m_slashIndex; - } - - template - static FilePath fromNativeFilePath(const String &filePath) - { - Utils::PathString nativePath{filePath.data(), filePath.size()}; - - if (Utils::HostOsInfo::isWindowsHost()) - nativePath.replace('\\', '/'); - - return FilePath(std::move(nativePath)); - } - -private: - std::ptrdiff_t m_slashIndex = -1; -}; - -using FilePaths = std::vector; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const FilePath &filePath); - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filepathcache.h b/src/libs/clangsupport/filepathcache.h deleted file mode 100644 index 541769b0b51..00000000000 --- a/src/libs/clangsupport/filepathcache.h +++ /dev/null @@ -1,206 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "directorypathid.h" -#include "filepath.h" -#include "filepathexceptions.h" -#include "filepathid.h" -#include "filepathstoragesources.h" -#include "filepathview.h" -#include "stringcache.h" - -#include - -#include - -namespace ClangBackEnd { - -template -class CLANGSUPPORT_GCCEXPORT FilePathCache -{ - FilePathCache(const FilePathCache &) = default; - FilePathCache &operator=(const FilePathCache &) = default; - - template - friend class FilePathCache; - -public: - using DirectoryPathCache = StringCache; - using FileNameCache = StringCache; - - FilePathCache(FilePathStorage &filePathStorage) - : m_filePathStorage(filePathStorage) - { - populateIfEmpty(); - } - - FilePathCache(FilePathCache &&) = default; - FilePathCache &operator=(FilePathCache &&) = default; - - void populateIfEmpty() - { - if (m_fileNameCache.isEmpty()) { - m_directoryPathCache.populate(m_filePathStorage.fetchAllDirectories()); - m_fileNameCache.populate(m_filePathStorage.fetchAllSources()); - } - } - - template - Cache clone() - { - using DirectoryPathCache = typename Cache::DirectoryPathCache; - using FileNameCache = typename Cache::FileNameCache; - Cache cache{m_filePathStorage}; - cache.m_directoryPathCache = m_directoryPathCache.template clone(); - cache.m_fileNameCache = m_fileNameCache.template clone(); - - return cache; - } - - FilePathId filePathId(FilePathView filePath) const - { - Utils::SmallStringView directoryPath = filePath.directory(); - - int directoryId = m_directoryPathCache.stringId( - directoryPath, [&](const Utils::SmallStringView directoryPath) { - return m_filePathStorage.fetchDirectoryId(directoryPath); - }); - - Utils::SmallStringView fileName = filePath.name(); - - int fileNameId = m_fileNameCache.stringId({fileName, directoryId}, - [&] (const FileNameView) { - return m_filePathStorage.fetchSourceId(directoryId, fileName); - }); - - return fileNameId; - } - - DirectoryPathId directoryPathId(Utils::SmallStringView directoryPath) const - { - Utils::SmallStringView path = directoryPath.back() == '/' - ? directoryPath.mid(0, directoryPath.size() - 1) - : directoryPath; - - return m_directoryPathCache.stringId(path, [&](const Utils::SmallStringView directoryPath) { - return m_filePathStorage.fetchDirectoryId(directoryPath); - }); - } - - FilePath filePath(FilePathId filePathId) const - { - if (Q_UNLIKELY(!filePathId.isValid())) - throw NoFilePathForInvalidFilePathId(); - - auto fetchSoureNameAndDirectoryId = [&] (int id) { - auto entry = m_filePathStorage.fetchSourceNameAndDirectoryId(id); - return FileNameEntry{entry.sourceName, entry.directoryId}; - }; - - auto entry = m_fileNameCache.string(filePathId.filePathId, fetchSoureNameAndDirectoryId); - - auto fetchDirectoryPath = [&] (int id) { return m_filePathStorage.fetchDirectoryPath(id); }; - - Utils::PathString directoryPath = m_directoryPathCache.string(entry.directoryId, - fetchDirectoryPath); - - return FilePath{directoryPath, entry.fileName}; - } - - Utils::PathString directoryPath(DirectoryPathId directoryPathId) const - { - if (Q_UNLIKELY(!directoryPathId.isValid())) - throw NoDirectoryPathForInvalidDirectoryPathId(); - - auto fetchDirectoryPath = [&](int id) { return m_filePathStorage.fetchDirectoryPath(id); }; - - return m_directoryPathCache.string(directoryPathId.directoryPathId, fetchDirectoryPath); - } - - DirectoryPathId directoryPathId(FilePathId filePathId) const - { - if (Q_UNLIKELY(!filePathId.isValid())) - throw NoFilePathForInvalidFilePathId(); - - auto fetchSoureNameAndDirectoryId = [&](int id) { - auto entry = m_filePathStorage.fetchSourceNameAndDirectoryId(id); - return FileNameEntry{entry.sourceName, entry.directoryId}; - }; - - return m_fileNameCache.string(filePathId.filePathId, fetchSoureNameAndDirectoryId).directoryId; - } - - template - void addFilePaths(Container &&filePaths) - { - auto directoryPaths = Utils::transform>( - filePaths, [](FilePathView filePath) { return filePath.directory(); }); - - std::unique_ptr transaction; - - m_directoryPathCache.addStrings(std::move(directoryPaths), [&](Utils::SmallStringView directoryPath) { - if (!transaction) - transaction = std::make_unique( - m_filePathStorage.database()); - return m_filePathStorage.fetchDirectoryIdUnguarded(directoryPath); - }); - - auto sourcePaths = Utils::transform>(filePaths, [&](FilePathView filePath) { - return FileNameView{filePath.name(), m_directoryPathCache.stringId(filePath.directory())}; - }); - - m_fileNameCache.addStrings(std::move(sourcePaths), [&](FileNameView fileNameView) { - if (!transaction) - transaction = std::make_unique( - m_filePathStorage.database()); - return m_filePathStorage.fetchSourceIdUnguarded(fileNameView.directoryId, - fileNameView.fileName); - }); - - if (transaction) - transaction->commit(); - } - -private: - mutable DirectoryPathCache m_directoryPathCache; - mutable FileNameCache m_fileNameCache; - FilePathStorage &m_filePathStorage; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filepathcaching.cpp b/src/libs/clangsupport/filepathcaching.cpp deleted file mode 100644 index f6d9ba9691d..00000000000 --- a/src/libs/clangsupport/filepathcaching.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "filepathcaching.h" - -namespace ClangBackEnd { - -FilePathId FilePathCaching::filePathId(FilePathView filePath) const -{ - return m_cache.filePathId(filePath); -} - -FilePath FilePathCaching::filePath(FilePathId filePathId) const -{ - return m_cache.filePath(filePathId); -} - -DirectoryPathId FilePathCaching::directoryPathId(Utils::SmallStringView directoryPath) const -{ - return m_cache.directoryPathId(directoryPath); -} - -Utils::PathString FilePathCaching::directoryPath(DirectoryPathId directoryPathId) const -{ - return m_cache.directoryPath(directoryPathId); -} - -DirectoryPathId FilePathCaching::directoryPathId(FilePathId filePathId) const -{ - return m_cache.directoryPathId(filePathId); -} - -void FilePathCaching::addFilePaths(const FilePaths &filePaths) -{ - m_cache.addFilePaths(filePaths); -} - -void FilePathCaching::populateIfEmpty() -{ - m_cache.populateIfEmpty(); -} - -FilePathId CopyableFilePathCaching::filePathId(FilePathView filePath) const -{ - return m_cache.filePathId(filePath); -} - -FilePath CopyableFilePathCaching::filePath(FilePathId filePathId) const -{ - return m_cache.filePath(filePathId); -} - -DirectoryPathId CopyableFilePathCaching::directoryPathId(Utils::SmallStringView directoryPath) const -{ - return m_cache.directoryPathId(directoryPath); -} - -Utils::PathString CopyableFilePathCaching::directoryPath(DirectoryPathId directoryPathId) const -{ - return m_cache.directoryPath(directoryPathId); -} - -DirectoryPathId CopyableFilePathCaching::directoryPathId(FilePathId filePathId) const -{ - return m_cache.directoryPathId(filePathId); -} - -void CopyableFilePathCaching::addFilePaths(const FilePaths &filePaths) -{ - m_cache.addFilePaths(filePaths); -} - -void CopyableFilePathCaching::populateIfEmpty() -{ - m_cache.populateIfEmpty(); -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filepathcaching.h b/src/libs/clangsupport/filepathcaching.h deleted file mode 100644 index 7c1f3434019..00000000000 --- a/src/libs/clangsupport/filepathcaching.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "clangsupport_global.h" - -#include "filepathcachinginterface.h" -#include "filepathcache.h" -#include "filepathstoragesqlitestatementfactory.h" -#include "filepathstorage.h" - -#include -#include -#include - -namespace ClangBackEnd { - -class CLANGSUPPORT_EXPORT FilePathCaching final : public FilePathCachingInterface -{ - friend class CopyableFilePathCaching; - using Factory = FilePathStorageSqliteStatementFactory; - using Storage = FilePathStorage; - using Cache = FilePathCache; - -public: - FilePathCaching(Sqlite::Database &database) - : m_factory(database) - {} - - FilePathId filePathId(FilePathView filePath) const override; - FilePath filePath(FilePathId filePathId) const override; - DirectoryPathId directoryPathId(Utils::SmallStringView directoryPath) const override; - Utils::PathString directoryPath(DirectoryPathId directoryPathId) const override; - DirectoryPathId directoryPathId(FilePathId filePathId) const override; - void addFilePaths(const ClangBackEnd::FilePaths &filePaths) override; - void populateIfEmpty() override; - -private: - Factory m_factory; - Storage m_storage{m_factory}; - Cache m_cache{m_storage}; -}; - -class CLANGSUPPORT_EXPORT CopyableFilePathCaching final : public FilePathCachingInterface -{ - using Factory = FilePathStorageSqliteStatementFactory; - using Storage = FilePathStorage; - using Cache = FilePathCache; - -public: - CopyableFilePathCaching(FilePathCaching &cache) - : m_cache(cache.m_cache.clone()) - {} - - FilePathId filePathId(FilePathView filePath) const override; - FilePath filePath(FilePathId filePathId) const override; - DirectoryPathId directoryPathId(Utils::SmallStringView directoryPath) const override; - Utils::PathString directoryPath(DirectoryPathId directoryPathId) const override; - DirectoryPathId directoryPathId(FilePathId filePathId) const override; - void addFilePaths(const ClangBackEnd::FilePaths &filePaths) override; - void populateIfEmpty() override; - -private: - Cache m_cache; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filepathcachingfwd.h b/src/libs/clangsupport/filepathcachingfwd.h deleted file mode 100644 index 7519dde634f..00000000000 --- a/src/libs/clangsupport/filepathcachingfwd.h +++ /dev/null @@ -1,32 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 ClangBackEnd { - -class FilePathCachingInterface; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filepathcachinginterface.h b/src/libs/clangsupport/filepathcachinginterface.h deleted file mode 100644 index 69be405d37d..00000000000 --- a/src/libs/clangsupport/filepathcachinginterface.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "directorypathid.h" -#include "filepath.h" -#include "filepathid.h" -#include "filepathview.h" - -namespace ClangBackEnd { - -class FilePathCachingInterface -{ -public: - FilePathCachingInterface() = default; - FilePathCachingInterface(const FilePathCachingInterface &) = delete; - FilePathCachingInterface &operator=(const FilePathCachingInterface &) = delete; - - virtual FilePathId filePathId(FilePathView filePath) const = 0; - virtual FilePath filePath(FilePathId filePathId) const = 0; - virtual DirectoryPathId directoryPathId(Utils::SmallStringView directoryPath) const = 0; - virtual DirectoryPathId directoryPathId(FilePathId filePathId) const = 0; - virtual Utils::PathString directoryPath(DirectoryPathId directoryPathId) const = 0; - virtual void addFilePaths(const ClangBackEnd::FilePaths &filePaths) = 0; - virtual void populateIfEmpty() = 0; - - template - FilePathIds filePathIds(Container &&filePaths) const - { - FilePathIds filePathIds; - filePathIds.reserve(filePaths.size()); - - std::transform(filePaths.begin(), - filePaths.end(), - std::back_inserter(filePathIds), - [&] (const auto &filePath) { return this->filePathId(filePath); }); - - std::sort(filePathIds.begin(), filePathIds.end()); - - return filePathIds; - } - - template - FilePathIds filePathIds(std::initializer_list filePaths) const - { - return filePathIds(std::vector(filePaths)); - } - - FilePaths filePaths(const FilePathIds &filePathIds) const - { - FilePaths filePaths; - filePaths.reserve(filePathIds.size()); - - std::transform(filePathIds.begin(), - filePathIds.end(), - std::back_inserter(filePaths), - [&] (auto filePathId) { return this->filePath(filePathId); }); - - return filePaths; - } - -protected: - ~FilePathCachingInterface() = default; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filepathexceptions.h b/src/libs/clangsupport/filepathexceptions.h deleted file mode 100644 index 3174d894794..00000000000 --- a/src/libs/clangsupport/filepathexceptions.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -namespace ClangBackEnd { - -class NoFilePathForInvalidFilePathId : std::exception -{ -public: - const char *what() const noexcept override - { - return "You cannot get a file path for an invalid file path id!"; - } -}; - -class NoDirectoryPathForInvalidDirectoryPathId : std::exception -{ -public: - const char *what() const noexcept override - { - return "You cannot get a directory path for an invalid directory path id!"; - } -}; - -class SourceNameIdDoesNotExists : std::exception -{ -public: - const char *what() const noexcept override - { - return "The source name id does not exist in the database!"; - } -}; - -class DirectoryPathIdDoesNotExists : std::exception -{ -public: - const char *what() const noexcept override - { - return "The directory path id does not exist in the database!"; - } -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filepathid.cpp b/src/libs/clangsupport/filepathid.cpp deleted file mode 100644 index 2491bc02d07..00000000000 --- a/src/libs/clangsupport/filepathid.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "filepathid.h" - -#include - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const FilePathId &filePathId) -{ - debug.nospace() << "(" << filePathId.filePathId << ")"; - - return debug; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filepathid.h b/src/libs/clangsupport/filepathid.h deleted file mode 100644 index 4feb06a5311..00000000000 --- a/src/libs/clangsupport/filepathid.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "clangsupport_global.h" - -#include - -#include -#include -#include - -namespace ClangBackEnd { - -class FilePathId -{ -public: - constexpr FilePathId() = default; - - FilePathId(const char *) = delete; - - FilePathId(int filePathId) - : filePathId(filePathId) - {} - - bool isValid() const - { - return filePathId >= 0; - } - - friend bool operator==(FilePathId first, FilePathId second) - { - return first.isValid() && first.filePathId == second.filePathId; - } - - friend bool operator!=(FilePathId first, FilePathId second) - { - return !(first==second); - } - - friend bool operator<(FilePathId first, FilePathId second) - { - return first.filePathId < second.filePathId; - } - - friend QDataStream &operator<<(QDataStream &out, const FilePathId &filePathId) - { - out << filePathId.filePathId; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, FilePathId &filePathId) - { - in >> filePathId.filePathId; - - return in; - } - -public: - int filePathId = -1; -}; - -using FilePathIds = std::vector; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const FilePathId &filePathId); -} // namespace ClangBackEnd - -namespace std { -template<> struct hash -{ - using argument_type = ClangBackEnd::FilePathId; - using result_type = std::size_t; - result_type operator()(const argument_type& filePathId) const - { - return std::hash{}(filePathId.filePathId); - } -}; - -} // namespace std diff --git a/src/libs/clangsupport/filepathstorage.h b/src/libs/clangsupport/filepathstorage.h deleted file mode 100644 index 7670c3091db..00000000000 --- a/src/libs/clangsupport/filepathstorage.h +++ /dev/null @@ -1,246 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "filepathexceptions.h" -#include "filepathid.h" -#include "filepathstoragesources.h" - -#include -#include - -#include - -namespace ClangBackEnd { - -template -class FilePathStorage -{ - template - using ReadStatement = typename StatementFactory::template ReadStatement; - using WriteStatement = typename StatementFactory::WriteStatement; - using Database = typename StatementFactory::Database; - -public: - FilePathStorage(StatementFactory &statementFactory) - : m_statementFactory(statementFactory) - {} - - int fetchDirectoryIdUnguarded(Utils::SmallStringView directoryPath) - { - Utils::optional optionalDirectoryId = readDirectoryId(directoryPath); - - if (optionalDirectoryId) - return optionalDirectoryId.value(); - - return writeDirectoryId(directoryPath); - } - - int fetchDirectoryId(Utils::SmallStringView directoryPath) - { - try { - Sqlite::DeferredTransaction transaction{m_statementFactory.database}; - - Utils::optional optionalDirectoryId = readDirectoryId(directoryPath); - - int directoryId = -1; - - if (optionalDirectoryId) - directoryId = optionalDirectoryId.value(); - else - directoryId = writeDirectoryId(directoryPath); - - transaction.commit(); - - return directoryId; - } catch (const Sqlite::StatementIsBusy &) { - return fetchDirectoryId(directoryPath); - } catch (const Sqlite::ConstraintPreventsModification &) { - return fetchDirectoryId(directoryPath); - } - } - - Utils::optional readDirectoryId(Utils::SmallStringView directoryPath) - { - auto &statement = m_statementFactory.selectDirectoryIdFromDirectoriesByDirectoryPath; - - return statement.template optionalValue(directoryPath); - } - - int writeDirectoryId(Utils::SmallStringView directoryPath) - { - WriteStatement &statement = m_statementFactory.insertIntoDirectories; - - statement.write(directoryPath); - - return int(m_statementFactory.database.lastInsertedRowId()); - } - - Utils::PathString fetchDirectoryPath(int directoryPathId) - { - try { - Sqlite::DeferredTransaction transaction{m_statementFactory.database}; - - auto &statement = m_statementFactory.selectDirectoryPathFromDirectoriesByDirectoryId; - - auto optionalDirectoryPath = statement.template optionalValue(directoryPathId); - - if (!optionalDirectoryPath) - throw DirectoryPathIdDoesNotExists(); - - transaction.commit(); - - return optionalDirectoryPath.value(); - } catch (const Sqlite::StatementIsBusy &) { - return fetchDirectoryPath(directoryPathId); - } - } - - std::vector fetchAllDirectories() - { - try { - Sqlite::DeferredTransaction transaction{m_statementFactory.database}; - - auto &statement = m_statementFactory.selectAllDirectories; - - auto directories = statement.template values(256); - - transaction.commit(); - - return directories; - } catch (const Sqlite::StatementIsBusy &) { - return fetchAllDirectories(); - } - } - - int fetchSourceIdUnguarded(int directoryId, Utils::SmallStringView sourceName) - { - Utils::optional optionalSourceId = readSourceId(directoryId, sourceName); - - if (optionalSourceId) - return optionalSourceId.value(); - - return writeSourceId(directoryId, sourceName); - } - - int fetchSourceId(int directoryId, Utils::SmallStringView sourceName) - { - try { - Sqlite::DeferredTransaction transaction{m_statementFactory.database}; - - int sourceId = fetchSourceIdUnguarded(directoryId, sourceName); - - transaction.commit(); - - return sourceId; - } catch (const Sqlite::StatementIsBusy &) { - return fetchSourceId(directoryId, sourceName); - } catch (const Sqlite::ConstraintPreventsModification &) { - return fetchSourceId(directoryId, sourceName); - } - } - - int writeSourceId(int directoryId, Utils::SmallStringView sourceName) - { - auto &statement = m_statementFactory.insertIntoSources; - - statement.write(directoryId, sourceName); - - return int(m_statementFactory.database.lastInsertedRowId()); - } - - Utils::optional readSourceId(int directoryId, Utils::SmallStringView sourceName) - { - auto &statement = m_statementFactory.selectSourceIdFromSourcesByDirectoryIdAndSourceName; - - return statement.template optionalValue(directoryId, sourceName); - } - - Sources::SourceNameAndDirectoryId fetchSourceNameAndDirectoryId(int sourceId) - { - try { - Sqlite::DeferredTransaction transaction{m_statementFactory.database}; - - auto &statement = m_statementFactory.selectSourceNameAndDirectoryIdFromSourcesBySourceId; - - auto optionalSourceName = statement.template optionalValue( - sourceId); - - if (!optionalSourceName) - throw SourceNameIdDoesNotExists(); - - transaction.commit(); - - return *optionalSourceName; - } catch (const Sqlite::StatementIsBusy &) { - return fetchSourceNameAndDirectoryId(sourceId); - } - } - - int fetchDirectoryId(int sourceId) - { - try { - Sqlite::DeferredTransaction transaction{m_statementFactory.database}; - - auto &statement = m_statementFactory.selectDirectoryIdFromSourcesBySourceId; - - auto optionalDirectoryId = statement.template optionalValue(sourceId); - - if (!optionalDirectoryId) - throw SourceNameIdDoesNotExists(); - - transaction.commit(); - - return *optionalDirectoryId; - } catch (const Sqlite::StatementIsBusy &) { - return fetchDirectoryId(sourceId); - } - } - - std::vector fetchAllSources() - { - try { - Sqlite::DeferredTransaction transaction{m_statementFactory.database}; - - auto &statement = m_statementFactory.selectAllSources; - - auto sources = statement.template values(8192); - - transaction.commit(); - - return sources; - } catch (const Sqlite::StatementIsBusy &) { - return fetchAllSources(); - } - } - - Database &database() { return m_statementFactory.database; } - -private: - StatementFactory &m_statementFactory; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filepathstoragesources.h b/src/libs/clangsupport/filepathstoragesources.h deleted file mode 100644 index 2194e75b955..00000000000 --- a/src/libs/clangsupport/filepathstoragesources.h +++ /dev/null @@ -1,146 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "stringcacheentry.h" - -#include - -#include -#include -#include -#include - -namespace ClangBackEnd { - -class FileNameView -{ -public: - friend bool operator==(const FileNameView &first, const FileNameView &second) - { - return first.directoryId == second.directoryId && first.fileName == second.fileName; - } - - static int compare(FileNameView first, FileNameView second) noexcept - { - int directoryDifference = first.directoryId - second.directoryId; - - if (directoryDifference) - return directoryDifference; - - return Utils::compare(first.fileName, second.fileName); - } - -public: - Utils::SmallStringView fileName; - int directoryId; -}; - -class FileNameEntry -{ -public: - FileNameEntry(Utils::SmallStringView fileName, int directoryId) - : fileName(fileName) - , directoryId(directoryId) - {} - - FileNameEntry(FileNameView view) - : fileName(view.fileName) - , directoryId(view.directoryId) - {} - - friend bool operator==(const FileNameEntry &first, const FileNameEntry &second) - { - return first.directoryId == second.directoryId && first.fileName == second.fileName; - } - - friend bool operator!=(const FileNameEntry &first, const FileNameEntry &second) - { - return !(first == second); - } - - friend bool operator==(const FileNameEntry &first, const FileNameView &second) - { - return first.directoryId == second.directoryId && first.fileName == second.fileName; - } - - friend bool operator!=(const FileNameEntry &first, const FileNameView &second) - { - return !(first == second); - } - - operator FileNameView() const { return {fileName, directoryId}; } - - operator Utils::SmallString() && { return std::move(fileName); } - -public: - Utils::SmallString fileName; - int directoryId; -}; - -namespace Sources { -class Directory : public StringCacheEntry -{ - using Base = StringCacheEntry; - -public: - using Base::Base; - - friend bool operator==(const Directory &first, const Directory &second) - { - return first.id == second.id && first.string == second.string; - } -}; - -class Source : public StringCacheEntry -{ - using Base = StringCacheEntry; - -public: - using Base::Base; - Source(Utils::SmallStringView sourceName, int directoryId, int sourceId) - : Base{{sourceName, directoryId}, sourceId} - {} - - friend bool operator==(const Source &first, const Source &second) - { - return first.id == second.id && first.string == second.string; - } -}; - -class SourceNameAndDirectoryId -{ -public: - SourceNameAndDirectoryId(Utils::SmallStringView sourceName, int directoryId) - : sourceName(sourceName), directoryId(directoryId) - {} - - Utils::SmallString sourceName; - int directoryId = -1; -}; -} // namespace ClangBackEnd - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filepathstoragesqlitestatementfactory.h b/src/libs/clangsupport/filepathstoragesqlitestatementfactory.h deleted file mode 100644 index 1698fcf0649..00000000000 --- a/src/libs/clangsupport/filepathstoragesqlitestatementfactory.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include -#include - -namespace ClangBackEnd { - -template -class FilePathStorageSqliteStatementFactory -{ -public: - using Database = DatabaseType; - template - using ReadStatement = typename Database::template ReadStatement; - using WriteStatement = typename Database::WriteStatement; - - FilePathStorageSqliteStatementFactory(Database &database) - : database(database) - { - } - -public: - Database &database; - ReadStatement<1> selectDirectoryIdFromDirectoriesByDirectoryPath{ - "SELECT directoryId FROM directories WHERE directoryPath = ?", database}; - ReadStatement<1> selectDirectoryPathFromDirectoriesByDirectoryId{ - "SELECT directoryPath FROM directories WHERE directoryId = ?", database}; - ReadStatement<2> selectAllDirectories{"SELECT directoryPath, directoryId FROM directories", - database}; - WriteStatement insertIntoDirectories{ - "INSERT INTO directories(directoryPath) VALUES (?)", - database - }; - ReadStatement<1> selectSourceIdFromSourcesByDirectoryIdAndSourceName{ - "SELECT sourceId FROM sources WHERE directoryId = ? AND sourceName = ?", database}; - ReadStatement<2> selectSourceNameAndDirectoryIdFromSourcesBySourceId{ - "SELECT sourceName, directoryId FROM sources WHERE sourceId = ?", database}; - ReadStatement<1> selectDirectoryIdFromSourcesBySourceId{ - "SELECT directoryId FROM sources WHERE sourceId = ?", database}; - WriteStatement insertIntoSources{ - "INSERT INTO sources(directoryId, sourceName) VALUES (?,?)", - database - }; - ReadStatement<3> selectAllSources{"SELECT sourceName, directoryId, sourceId FROM sources", - database}; -}; - -} // namespace ClangBackEnd - diff --git a/src/libs/clangsupport/filepathview.h b/src/libs/clangsupport/filepathview.h deleted file mode 100644 index 848ee3207f1..00000000000 --- a/src/libs/clangsupport/filepathview.h +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include -#include - -#include -#include - -namespace ClangBackEnd { - -template -class AbstractFilePathView : public Utils::SmallStringView -{ -public: - constexpr AbstractFilePathView() = default; - explicit AbstractFilePathView(const char *const string, const size_type size) noexcept - : AbstractFilePathView{Utils::SmallStringView{string, size}} - { - } - - explicit AbstractFilePathView(Utils::SmallStringView filePath) - : Utils::SmallStringView(filePath) - , m_slashIndex(lastSlashIndex(filePath)) - { - } - - template ::value>> - explicit AbstractFilePathView(String &&filePath) - : AbstractFilePathView(filePath.data(), filePath.size()) - { - } - - template - AbstractFilePathView(const char(&string)[Size]) noexcept - : AbstractFilePathView(string, Size - 1) - { - static_assert(Size >= 1, "Invalid string literal! Length is zero!"); - } - - Utils::SmallStringView toStringView() const - { - return *this; - } - - std::ptrdiff_t slashIndex() const - { - return m_slashIndex; - } - - Utils::SmallStringView directory() const noexcept - { - return mid(0, std::size_t(std::max(std::ptrdiff_t(0), m_slashIndex))); - } - - Utils::SmallStringView name() const noexcept - { - return mid(std::size_t(m_slashIndex + 1), - std::size_t(std::ptrdiff_t(size()) - m_slashIndex - std::ptrdiff_t(1))); - } - - static - std::ptrdiff_t lastSlashIndex(Utils::SmallStringView filePath) - { - constexpr char separator = Utils::HostOsInfo::isWindowsHost() ? WindowsSlash : '/'; - auto foundReverse = std::find(filePath.rbegin(), filePath.rend(), separator); - auto found = foundReverse.base(); - - auto distance = std::distance(filePath.begin(), found); - - return distance - 1; - } - - friend bool operator==(const AbstractFilePathView &first, const AbstractFilePathView &second) - { - return first.toStringView() == second.toStringView(); - } - -private: - std::ptrdiff_t m_slashIndex = -1; -}; - -using FilePathView = AbstractFilePathView<'/'>; -using NativeFilePathView = AbstractFilePathView<'\\'>; -using FilePathViews = std::vector; -using NativeFilePathViews = std::vector; -} diff --git a/src/libs/clangsupport/filestatus.h b/src/libs/clangsupport/filestatus.h deleted file mode 100644 index da2be4a304e..00000000000 --- a/src/libs/clangsupport/filestatus.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -#include -#include -#include - -namespace ClangBackEnd { - -class FileStatus -{ -public: - FileStatus(FilePathId filePathId, off_t size, std::time_t lastModified) - : filePathId(filePathId), size(size), lastModified(lastModified) {} - - friend - bool operator==(const FileStatus &first, const FileStatus &second) - { - return first.filePathId == second.filePathId - && first.size == second.size - && first.lastModified == second.lastModified; - } - - friend - bool operator<(const FileStatus &first, const FileStatus &second) - { - return first.filePathId < second.filePathId; - } - -public: - FilePathId filePathId; - off_t size; - std::time_t lastModified; -}; - -using FileStatuses = std::vector; -} diff --git a/src/libs/clangsupport/filestatuscache.cpp b/src/libs/clangsupport/filestatuscache.cpp deleted file mode 100644 index 3a13de79f52..00000000000 --- a/src/libs/clangsupport/filestatuscache.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "filestatuscache.h" -#include "filesystem.h" - -#include -#include - -#include -#include - -namespace ClangBackEnd { - -long long FileStatusCache::lastModifiedTime(FilePathId filePathId) const -{ - return findEntry(filePathId).lastModified; -} - -void FileStatusCache::update(FilePathId filePathId) -{ - auto found = std::lower_bound(m_cacheEntries.begin(), - m_cacheEntries.end(), - Internal::FileStatusCacheEntry{filePathId}, - [] (const auto &first, const auto &second) { - return first.filePathId < second.filePathId; - }); - - if (found != m_cacheEntries.end() && found->filePathId == filePathId) - found->lastModified = m_fileSystem.lastModified(filePathId); -} - -void FileStatusCache::update(FilePathIds filePathIds) -{ - std::set_intersection(m_cacheEntries.begin(), - m_cacheEntries.end(), - filePathIds.begin(), - filePathIds.end(), - Utils::make_iterator([&](auto &entry) { - entry.lastModified = m_fileSystem.lastModified(entry.filePathId); - })); -} - -FilePathIds FileStatusCache::modified(FilePathIds filePathIds) const -{ - FilePathIds modifiedFilePathIds; - modifiedFilePathIds.reserve(filePathIds.size()); - - std::set_intersection(m_cacheEntries.begin(), - m_cacheEntries.end(), - filePathIds.begin(), - filePathIds.end(), - Utils::make_iterator([&](auto &entry) { - auto newLastModified = m_fileSystem.lastModified(entry.filePathId); - if (newLastModified > entry.lastModified) { - modifiedFilePathIds.push_back(entry.filePathId); - entry.lastModified = newLastModified; - } - })); - - Internal::FileStatusCacheEntries newEntries; - newEntries.reserve(filePathIds.size()); - - std::set_difference(filePathIds.begin(), - filePathIds.end(), - m_cacheEntries.begin(), - m_cacheEntries.end(), - Utils::make_iterator([&](FilePathId newFilePathId) { - newEntries.emplace_back(newFilePathId, - m_fileSystem.lastModified(newFilePathId)); - modifiedFilePathIds.push_back(newFilePathId); - })); - - if (newEntries.size()) { - Internal::FileStatusCacheEntries mergedEntries; - mergedEntries.reserve(m_cacheEntries.size() + newEntries.size()); - - std::set_union(newEntries.begin(), - newEntries.end(), - m_cacheEntries.begin(), - m_cacheEntries.end(), - std::back_inserter(mergedEntries)); - - m_cacheEntries = std::move(mergedEntries); - } - - std::sort(modifiedFilePathIds.begin(), modifiedFilePathIds.end()); - - return modifiedFilePathIds; -} - -FileStatusCache::size_type FileStatusCache::size() const -{ - return m_cacheEntries.size(); -} - -Internal::FileStatusCacheEntry FileStatusCache::findEntry(FilePathId filePathId) const -{ - auto found = std::lower_bound(m_cacheEntries.begin(), - m_cacheEntries.end(), - Internal::FileStatusCacheEntry{filePathId}, - [] (const auto &first, const auto &second) { - return first.filePathId < second.filePathId; - }); - - if (found != m_cacheEntries.end() && found->filePathId == filePathId) - return *found; - - auto inserted = m_cacheEntries.emplace(found, filePathId, m_fileSystem.lastModified(filePathId)); - - return *inserted; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filestatuscache.h b/src/libs/clangsupport/filestatuscache.h deleted file mode 100644 index 3f0af56b3ae..00000000000 --- a/src/libs/clangsupport/filestatuscache.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -QT_FORWARD_DECLARE_CLASS(QFileInfo) - -namespace ClangBackEnd { - -class FileSystemInterface; - -namespace Internal { -class FileStatusCacheEntry -{ -public: - FileStatusCacheEntry(ClangBackEnd::FilePathId filePathId, - long long lastModified = 0) - : filePathId(filePathId), - lastModified(lastModified) - {} - - friend bool operator<(FileStatusCacheEntry first, FileStatusCacheEntry second) - { - return first.filePathId < second.filePathId; - } - - friend bool operator<(FileStatusCacheEntry first, FilePathId second) - { - return first.filePathId < second; - } - - friend bool operator<(FilePathId first, FileStatusCacheEntry second) - { - return first < second.filePathId; - } - -public: - FilePathId filePathId; - long long lastModified; -}; - -using FileStatusCacheEntries = std::vector; - -} - -class CLANGSUPPORT_EXPORT FileStatusCache -{ -public: - using size_type = Internal::FileStatusCacheEntries::size_type; - - FileStatusCache(FileSystemInterface &fileSystem) - : m_fileSystem(fileSystem) - {} - FileStatusCache &operator=(const FileStatusCache &) = delete; - FileStatusCache(const FileStatusCache &) = delete; - - long long lastModifiedTime(FilePathId filePathId) const; - void update(FilePathId filePathId); - void update(FilePathIds filePathIds); - FilePathIds modified(FilePathIds filePathIds) const; - - size_type size() const; - -private: - Internal::FileStatusCacheEntry findEntry(FilePathId filePathId) const; - -private: - mutable Internal::FileStatusCacheEntries m_cacheEntries; - FileSystemInterface &m_fileSystem; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filesystem.cpp b/src/libs/clangsupport/filesystem.cpp deleted file mode 100644 index e6c0ed34b70..00000000000 --- a/src/libs/clangsupport/filesystem.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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. -** -****************************************************************************/ - -#include "filesystem.h" -#include "filepathcachinginterface.h" - -#include - -#include -#include -#include - -namespace ClangBackEnd { - -FilePathIds FileSystem::directoryEntries(const QString &directoryPath) const -{ - QDir directory{directoryPath}; - - QFileInfoList fileInfos = directory.entryInfoList(); - - FilePathIds filePathIds = Utils::transform(fileInfos, [&](const QFileInfo &fileInfo) { - return m_filePathCache.filePathId(FilePath{fileInfo.path()}); - }); - - std::sort(filePathIds.begin(), filePathIds.end()); - - return filePathIds; -} - -long long FileSystem::lastModified(FilePathId filePathId) const -{ - QFileInfo fileInfo(QString(m_filePathCache.filePath(filePathId))); - - fileInfo.refresh(); - - if (fileInfo.exists()) - return fileInfo.lastModified().toMSecsSinceEpoch() / 1000; - - return 0; -} - -void FileSystem::remove(const FilePathIds &filePathIds) -{ - for (FilePathId filePathId : filePathIds) - QFile::remove(QString{m_filePathCache.filePath(filePathId)}); -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filesystem.h b/src/libs/clangsupport/filesystem.h deleted file mode 100644 index 827fdcfd0e8..00000000000 --- a/src/libs/clangsupport/filesystem.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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 - -#include "filestatuscache.h" -#include "filesysteminterface.h" - -namespace ClangBackEnd { -class FilePathCachingInterface; - -class CLANGSUPPORT_EXPORT FileSystem final : public FileSystemInterface -{ -public: - FileSystem(FilePathCachingInterface &filePathCache) - : m_filePathCache(filePathCache) - {} - - FilePathIds directoryEntries(const QString &directoryPath) const override; - long long lastModified(FilePathId filePathId) const override; - - void remove(const FilePathIds &filePathIds) override; - -private: - FilePathCachingInterface &m_filePathCache; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/filesysteminterface.h b/src/libs/clangsupport/filesysteminterface.h deleted file mode 100644 index 68be461657b..00000000000 --- a/src/libs/clangsupport/filesysteminterface.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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 - -#include "filepathid.h" - -#include - -namespace ClangBackEnd { - -class FileSystemInterface -{ -public: - virtual FilePathIds directoryEntries(const QString &directoryPath) const = 0; - virtual long long lastModified(FilePathId filePathId) const = 0; - virtual void remove(const FilePathIds &filePathIds) = 0; - -protected: - ~FileSystemInterface() = default; -}; -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/generatedfiles.cpp b/src/libs/clangsupport/generatedfiles.cpp deleted file mode 100644 index 22b1e8044a9..00000000000 --- a/src/libs/clangsupport/generatedfiles.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "generatedfiles.h" - -#include - -namespace ClangBackEnd { - -void GeneratedFiles::update(V2::FileContainers &&fileContainers) -{ - V2::FileContainers unionFileContainers; - unionFileContainers.reserve(m_fileContainers.size() + fileContainers.size()); - - auto compare = [](const V2::FileContainer &first, const V2::FileContainer &second) { - return first.filePath < second.filePath; - }; - - Utils::set_union(std::make_move_iterator(fileContainers.begin()), - std::make_move_iterator(fileContainers.end()), - std::make_move_iterator(m_fileContainers.begin()), - std::make_move_iterator(m_fileContainers.end()), - std::back_inserter(unionFileContainers), - compare); - - m_fileContainers = std::move(unionFileContainers); -} - -void GeneratedFiles::update(const V2::FileContainers &fileContainers) -{ - V2::FileContainers unionFileContainers; - unionFileContainers.reserve(m_fileContainers.size() + fileContainers.size()); - - auto compare = [](const V2::FileContainer &first, const V2::FileContainer &second) { - return first.filePath < second.filePath; - }; - - Utils::set_union(fileContainers.begin(), - fileContainers.end(), - std::make_move_iterator(m_fileContainers.begin()), - std::make_move_iterator(m_fileContainers.end()), - std::back_inserter(unionFileContainers), - compare); - - m_fileContainers = std::move(unionFileContainers); -} - -class Compare { -public: - bool operator()(const FilePath &first, const FilePath &second) { return first < second; } - bool operator()(const V2::FileContainer &first, const V2::FileContainer &second) - { - return first.filePath < second.filePath; - } - bool operator()(const V2::FileContainer &first, const FilePath &second) - { - return first.filePath < second; - } - bool operator()(const FilePath &first, const V2::FileContainer &second) - { - return first < second.filePath; - } -}; - -void GeneratedFiles::remove(const FilePaths &filePaths) -{ - V2::FileContainers differenceFileContainers; - differenceFileContainers.reserve(m_fileContainers.size()); - - std::set_difference(std::make_move_iterator(m_fileContainers.begin()), - std::make_move_iterator(m_fileContainers.end()), - filePaths.begin(), - filePaths.end(), - std::back_inserter(differenceFileContainers), - Compare{}); - - m_fileContainers = std::move(differenceFileContainers); -} - -bool GeneratedFiles::isValid() const -{ - return std::all_of(m_fileContainers.begin(), - m_fileContainers.end(), - [](const V2::FileContainer &container) { - return container.unsavedFileContent.hasContent(); - }); -} - -const V2::FileContainers &GeneratedFiles::fileContainers() const -{ - return m_fileContainers; -} - -FilePathIds GeneratedFiles::filePathIds() const -{ - auto ids = Utils::transform(m_fileContainers, - [](const V2::FileContainer &fileContainer) { - return fileContainer.filePathId; - }); - - std::sort(ids.begin(), ids.end()); - - return ids; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/generatedfiles.h b/src/libs/clangsupport/generatedfiles.h deleted file mode 100644 index 3e87048be9c..00000000000 --- a/src/libs/clangsupport/generatedfiles.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "generatedfilesinterface.h" - -namespace ClangBackEnd { - -class CLANGSUPPORT_EXPORT GeneratedFiles final : public GeneratedFilesInterface -{ -public: - void update(V2::FileContainers &&fileContainers); - void update(const V2::FileContainers &fileContainers); - void remove(const FilePaths &filePaths); - bool isValid() const; - - const V2::FileContainers &fileContainers() const; - FilePathIds filePathIds() const; - -private: - V2::FileContainers m_fileContainers; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/generatedfilesinterface.h b/src/libs/clangsupport/generatedfilesinterface.h deleted file mode 100644 index 72a1dfccfb4..00000000000 --- a/src/libs/clangsupport/generatedfilesinterface.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -namespace ClangBackEnd { - -class GeneratedFilesInterface -{ -public: - virtual void update(V2::FileContainers &&fileContainers) = 0; - virtual void update(const V2::FileContainers &fileContainers) = 0; - virtual void remove(const FilePaths &filePaths) = 0; - virtual bool isValid() const = 0; - - virtual const V2::FileContainers &fileContainers() const = 0; - virtual FilePathIds filePathIds() const = 0; - -protected: - ~GeneratedFilesInterface() = default; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/idpaths.h b/src/libs/clangsupport/idpaths.h deleted file mode 100644 index 8410bbbbd5f..00000000000 --- a/src/libs/clangsupport/idpaths.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "filepathid.h" -#include "projectpartid.h" -#include "sourceentry.h" - -namespace ClangBackEnd { - -class ProjectChunkId -{ -public: - ProjectPartId id; - SourceType sourceType; - - friend bool operator==(ProjectChunkId first, ProjectChunkId second) - { - return first.id == second.id && first.sourceType == second.sourceType; - } - - friend bool operator==(ProjectChunkId first, ProjectPartId second) - { - return first.id == second; - } - - friend bool operator==(ProjectPartId first, ProjectChunkId second) - { - return first == second.id; - } - - friend bool operator!=(ProjectChunkId first, ProjectChunkId second) - { - return !(first == second); - } - - friend bool operator<(ProjectChunkId first, ProjectChunkId second) - { - return std::tie(first.id, first.sourceType) < std::tie(second.id, second.sourceType); - } - - friend bool operator<(ProjectChunkId first, ProjectPartId second) { return first.id < second; } - - friend bool operator<(ProjectPartId first, ProjectChunkId second) { return first < second.id; } -}; - -class IdPaths -{ -public: - IdPaths(ProjectPartId projectPartId, SourceType sourceType, FilePathIds &&filePathIds) - : id{projectPartId, sourceType} - , filePathIds(std::move(filePathIds)) - {} - IdPaths(ProjectChunkId projectChunkId, FilePathIds &&filePathIds) - : id(projectChunkId) - , filePathIds(std::move(filePathIds)) - {} - - friend bool operator==(IdPaths first, IdPaths second) - { - return first.id == second.id && first.filePathIds == second.filePathIds; - } - -public: - ProjectChunkId id; - FilePathIds filePathIds; -}; - -using ProjectChunkIds = std::vector; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/includesearchpath.h b/src/libs/clangsupport/includesearchpath.h deleted file mode 100644 index 239af9c1a47..00000000000 --- a/src/libs/clangsupport/includesearchpath.h +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -#include - -#include - -namespace ClangBackEnd { - -enum class IncludeSearchPathType : unsigned char { - Invalid, - User, - BuiltIn, - System, - Framework, -}; - -class IncludeSearchPath -{ -public: - IncludeSearchPath() = default; - IncludeSearchPath(Utils::PathString &&path, int index, IncludeSearchPathType type) - : path(std::move(path)) - , index(index) - , type(type) - {} - - IncludeSearchPath(Utils::PathString &&path, int index, int type) - : path(std::move(path)) - , index(index) - , type(static_cast(type)) - {} - - friend QDataStream &operator<<(QDataStream &out, const IncludeSearchPath &includeSearchPath) - { - out << includeSearchPath.path; - out << includeSearchPath.index; - out << static_cast(includeSearchPath.type); - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, IncludeSearchPath &includeSearchPath) - { - unsigned char type; - - in >> includeSearchPath.path; - in >> includeSearchPath.index; - in >> type; - - includeSearchPath.type = static_cast(type); - - return in; - } - - friend bool operator==(const IncludeSearchPath &first, const IncludeSearchPath &second) - { - return std::tie(first.type, first.index, first.path) - == std::tie(second.type, second.index, second.path); - } - - friend bool operator<(const IncludeSearchPath &first, const IncludeSearchPath &second) - { - return std::tie(first.path, first.index, first.type) - < std::tie(second.path, second.index, second.type); - } - -public: - Utils::PathString path; - int index = -1; - IncludeSearchPathType type = IncludeSearchPathType::Invalid; -}; - -using IncludeSearchPaths = std::vector; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/modifiedtimechecker.h b/src/libs/clangsupport/modifiedtimechecker.h deleted file mode 100644 index 9d6b56d9e3d..00000000000 --- a/src/libs/clangsupport/modifiedtimechecker.h +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "filesysteminterface.h" -#include "modifiedtimecheckerinterface.h" - -#include - -#include -#include - -namespace ClangBackEnd { - -template -class ModifiedTimeChecker final : public ModifiedTimeCheckerInterface -{ - using SourceEntry = typename SourceEntries::value_type; - -public: - ModifiedTimeChecker(FileSystemInterface &fileSystem) - : m_fileSystem(fileSystem) - {} - - bool isUpToDate(const SourceEntries &sourceEntries) const override - { - if (sourceEntries.empty()) - return false; - - updateCurrentSourceTimeStamps(sourceEntries); - - return compareEntries(sourceEntries); - } - - void pathsChanged(const FilePathIds &filePathIds) override - { - std::set_intersection(m_currentSourceTimeStamps.begin(), - m_currentSourceTimeStamps.end(), - filePathIds.begin(), - filePathIds.end(), - Utils::make_iterator([&](SourceTimeStamp &sourceTimeStamp) { - sourceTimeStamp.timeStamp = m_fileSystem.lastModified( - sourceTimeStamp.sourceId); - })); - } - -private: - bool compareEntries(const SourceEntries &sourceEntries) const - { - return !Utils::set_intersection_compare( - m_currentSourceTimeStamps.begin(), - m_currentSourceTimeStamps.end(), - sourceEntries.begin(), - sourceEntries.end(), - [](auto first, auto second) { return first.timeStamp > second.timeStamp; }, - [](auto first, auto second) { return first.sourceId < second.sourceId; }); - } - - void updateCurrentSourceTimeStamps(const SourceEntries &sourceEntries) const - { - SourceTimeStamps sourceTimeStamps = newSourceTimeStamps(sourceEntries); - - auto split = sourceTimeStamps.insert(sourceTimeStamps.end(), - m_currentSourceTimeStamps.begin(), - m_currentSourceTimeStamps.end()); - std::inplace_merge(sourceTimeStamps.begin(), split, sourceTimeStamps.end()); - - m_currentSourceTimeStamps = std::move(sourceTimeStamps); - } - - SourceTimeStamps newSourceTimeStamps(const SourceEntries &sourceEntries) const - { - SourceTimeStamps newTimeStamps; - newTimeStamps.reserve(sourceEntries.size()); - - std::set_difference(sourceEntries.begin(), - sourceEntries.end(), - m_currentSourceTimeStamps.begin(), - m_currentSourceTimeStamps.end(), - Utils::make_iterator([&](const SourceEntry &sourceEntry) { - newTimeStamps.emplace_back(sourceEntry.sourceId, - m_fileSystem.lastModified( - sourceEntry.sourceId)); - }), - [](auto first, auto second) { - return first.sourceId < second.sourceId; - }); - - return newTimeStamps; - } - -private: - mutable SourceTimeStamps m_currentSourceTimeStamps; - FileSystemInterface &m_fileSystem; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/modifiedtimecheckerinterface.h b/src/libs/clangsupport/modifiedtimecheckerinterface.h deleted file mode 100644 index b48c38869e5..00000000000 --- a/src/libs/clangsupport/modifiedtimecheckerinterface.h +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "sourceentry.h" - -namespace ClangBackEnd { - -template -class ModifiedTimeCheckerInterface -{ -public: - ModifiedTimeCheckerInterface() = default; - ModifiedTimeCheckerInterface(const ModifiedTimeCheckerInterface &) = delete; - ModifiedTimeCheckerInterface &operator=(const ModifiedTimeCheckerInterface &) = delete; - - virtual bool isUpToDate(const SourceEntries &sourceEntries) const = 0; - virtual void pathsChanged(const FilePathIds &filePathIds) = 0; - -protected: - ~ModifiedTimeCheckerInterface() = default; -}; - -} // namespace ClangBackEnd - diff --git a/src/libs/clangsupport/nativefilepath.h b/src/libs/clangsupport/nativefilepath.h deleted file mode 100644 index 66e3e16d65a..00000000000 --- a/src/libs/clangsupport/nativefilepath.h +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "filepathview.h" - -#include -#include - -namespace ClangBackEnd { - -class FilePath; - -class NativeFilePath -{ - using size_type = Utils::PathString::size_type; - -public: - NativeFilePath() = default; - explicit NativeFilePath(Utils::PathString &&filePath) - : m_path(std::move(filePath)) - { - NativeFilePathView view{m_path}; - - m_slashIndex = view.slashIndex(); - } - - NativeFilePath(NativeFilePathView filePathView) - : m_path(filePathView.toStringView()), - m_slashIndex(filePathView.slashIndex()) - {} - - explicit NativeFilePath(FilePathView filePathView) { *this = fromFilePath(filePathView); } - - explicit NativeFilePath(const FilePath &filePath) - : NativeFilePath{FilePathView{filePath}} - {} - - template - NativeFilePath(const char(&string)[Size]) noexcept - : NativeFilePath(NativeFilePathView(string, Size - 1)) - { - static_assert(Size >= 1, "Invalid string literal! Length is zero!"); - } - - explicit NativeFilePath(const Utils::PathString &filePath) - : NativeFilePath(filePath.clone()) - { - } - - explicit NativeFilePath(Utils::PathString &&filePath, std::ptrdiff_t slashIndex) - : m_path(std::move(filePath)), - m_slashIndex(slashIndex) - { - } - - explicit NativeFilePath(const QString &filePath) - : NativeFilePath(Utils::PathString(filePath)) - { - } - - NativeFilePath(Utils::SmallStringView directory, Utils::SmallStringView name) - : m_path(Utils::PathString::join( - {directory, Utils::HostOsInfo::isWindowsHost() ? "\\" : "/", name})) - , m_slashIndex(directory.size()) - {} - - Utils::SmallStringView directory() const noexcept - { - return m_path.mid(0, std::size_t(std::max(std::ptrdiff_t(0), m_slashIndex))); } - - Utils::SmallStringView name() const noexcept - { - return m_path.mid(std::size_t(m_slashIndex + 1), - std::size_t(std::ptrdiff_t(m_path.size()) - m_slashIndex - std::ptrdiff_t(1))); - } - - bool empty() const - { - return m_path.empty(); - } - - const Utils::PathString &path() const noexcept - { - return m_path; - } - - operator const Utils::PathString&() const noexcept - { - return m_path; - } - - operator NativeFilePathView() const noexcept - { - return NativeFilePathView(Utils::SmallStringView(m_path)); - } - - friend QDataStream &operator<<(QDataStream &out, const NativeFilePath &filePath) - { - out << filePath.m_path; - out << uint(filePath.m_slashIndex); - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, NativeFilePath &filePath) - { - uint slashIndex; - - in >> filePath.m_path; - in >> slashIndex; - - filePath.m_slashIndex = slashIndex; - - return in; - } - - friend bool operator==(const NativeFilePath &first, const NativeFilePath &second) - { - return first.m_path == second.m_path; - } - - friend bool operator==(const NativeFilePath &first, const NativeFilePathView &second) - { - return first.path() == second.toStringView(); - } - - friend bool operator==(const NativeFilePathView &first, const NativeFilePath &second) - { - return second == first; - } - - friend bool operator<(const NativeFilePath &first, const NativeFilePath &second) - { - return first.m_path < second.m_path; - } - - NativeFilePath clone() const - { - return *this; - } - - std::ptrdiff_t slashIndex() const - { - return m_slashIndex; - } - - template - static NativeFilePath fromFilePath(String filePath) - { - Utils::PathString nativePath{filePath.data(), size_type(filePath.size())}; - - if (Utils::HostOsInfo::isWindowsHost()) - nativePath.replace('/', '\\'); - - return NativeFilePath(std::move(nativePath)); - } - -private: - Utils::PathString m_path; - std::ptrdiff_t m_slashIndex = -1; -}; - -using NativeFilePaths = std::vector; -} // namespace ClangBackEnd - diff --git a/src/libs/clangsupport/pchmanagerclientinterface.cpp b/src/libs/clangsupport/pchmanagerclientinterface.cpp deleted file mode 100644 index 1f8d1dba181..00000000000 --- a/src/libs/clangsupport/pchmanagerclientinterface.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "pchmanagerclientinterface.h" -#include "messageenvelop.h" - -#include -#include - -#include - -namespace ClangBackEnd { - -void PchManagerClientInterface::dispatch(const MessageEnvelop &messageEnvelop) -{ - switch (messageEnvelop.messageType()) { - case MessageType::AliveMessage: - alive(); - break; - case MessageType::PrecompiledHeadersUpdatedMessage: - precompiledHeadersUpdated(messageEnvelop.message()); - break; - case MessageType::ProgressMessage: - progress(messageEnvelop.message()); - break; - default: - qWarning() << "Unknown IpcClientMessage"; - } -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/pchmanagerclientinterface.h b/src/libs/clangsupport/pchmanagerclientinterface.h deleted file mode 100644 index c0aa183d8b3..00000000000 --- a/src/libs/clangsupport/pchmanagerclientinterface.h +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "ipcclientinterface.h" - -namespace ClangBackEnd { - -class PrecompiledHeadersUpdatedMessage; -class ProgressMessage; - -class CLANGSUPPORT_EXPORT PchManagerClientInterface : public IpcClientInterface -{ -public: - void dispatch(const MessageEnvelop &messageEnvelop) override; - - virtual void alive() = 0; - virtual void precompiledHeadersUpdated(PrecompiledHeadersUpdatedMessage &&message) = 0; - virtual void progress(ProgressMessage &&message) = 0; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/pchmanagerclientproxy.cpp b/src/libs/clangsupport/pchmanagerclientproxy.cpp deleted file mode 100644 index a18ac166d2f..00000000000 --- a/src/libs/clangsupport/pchmanagerclientproxy.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "pchmanagerclientproxy.h" - -#include "alivemessage.h" -#include "messageenvelop.h" -#include "pchmanagerserverinterface.h" -#include "precompiledheadersupdatedmessage.h" -#include "progressmessage.h" - -#include -#include - -namespace ClangBackEnd { - -PchManagerClientProxy::PchManagerClientProxy(PchManagerServerInterface *server, - QLocalSocket *localSocket) - : writeMessageBlock(localSocket) - , readMessageBlock(localSocket) - , server(server) -{ - QObject::connect(localSocket, &QIODevice::readyRead, [this]() { - PchManagerClientProxy::readMessages(); - }); -} - -PchManagerClientProxy::PchManagerClientProxy(PchManagerServerInterface *server, QIODevice *ioDevice) - : writeMessageBlock(ioDevice) - , readMessageBlock(ioDevice) - , server(server) -{ - QObject::connect(ioDevice, &QIODevice::readyRead, [this]() { - PchManagerClientProxy::readMessages(); - }); -} - -void PchManagerClientProxy::readMessages() -{ - for (const MessageEnvelop &message : readMessageBlock.readAll()) - server->dispatch(message); -} - -void PchManagerClientProxy::alive() -{ - writeMessageBlock.write(AliveMessage()); -} - -void PchManagerClientProxy::precompiledHeadersUpdated(PrecompiledHeadersUpdatedMessage &&message) -{ - writeMessageBlock.write(message); -} - -void PchManagerClientProxy::progress(ProgressMessage &&message) -{ - writeMessageBlock.write(message); -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/pchmanagerclientproxy.h b/src/libs/clangsupport/pchmanagerclientproxy.h deleted file mode 100644 index 6dec4ecfcae..00000000000 --- a/src/libs/clangsupport/pchmanagerclientproxy.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangsupport_global.h" -#include "pchmanagerclientinterface.h" -#include "readmessageblock.h" -#include "writemessageblock.h" - -namespace ClangBackEnd { - -class PchManagerServerInterface; - -class CLANGSUPPORT_EXPORT PchManagerClientProxy final : public PchManagerClientInterface -{ -public: - explicit PchManagerClientProxy(PchManagerServerInterface *server, QLocalSocket *localSocket); - explicit PchManagerClientProxy(PchManagerServerInterface *server, QIODevice *ioDevice); - PchManagerClientProxy(const PchManagerClientProxy&) = delete; - const PchManagerClientProxy &operator=(const PchManagerClientProxy&) = delete; - - void readMessages(); - - void alive() override; - void precompiledHeadersUpdated(PrecompiledHeadersUpdatedMessage &&message) override; - void progress(ProgressMessage &&message) override; - -private: - ClangBackEnd::WriteMessageBlock writeMessageBlock; - ClangBackEnd::ReadMessageBlock readMessageBlock; - PchManagerServerInterface *server = nullptr; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/pchmanagerserverinterface.cpp b/src/libs/clangsupport/pchmanagerserverinterface.cpp deleted file mode 100644 index 256aa228ace..00000000000 --- a/src/libs/clangsupport/pchmanagerserverinterface.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "pchmanagerserverinterface.h" - -#include "messageenvelop.h" -#include "removegeneratedfilesmessage.h" -#include "removeprojectpartsmessage.h" -#include "updategeneratedfilesmessage.h" -#include "updateprojectpartsmessage.h" - -#include - -namespace ClangBackEnd { - -void PchManagerServerInterface::dispatch(const MessageEnvelop &messageEnvelop) -{ - switch (messageEnvelop.messageType()) { - case MessageType::EndMessage: - end(); - break; - case MessageType::UpdateProjectPartsMessage: - updateProjectParts(messageEnvelop.message()); - break; - case MessageType::RemoveProjectPartsMessage: - removeProjectParts(messageEnvelop.message()); - break; - case MessageType::UpdateGeneratedFilesMessage: - updateGeneratedFiles(messageEnvelop.message()); - break; - case MessageType::RemoveGeneratedFilesMessage: - removeGeneratedFiles(messageEnvelop.message()); - break; - default: - qWarning() << "Unknown IpcClientMessage"; - } -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/pchmanagerserverinterface.h b/src/libs/clangsupport/pchmanagerserverinterface.h deleted file mode 100644 index fe473770e8d..00000000000 --- a/src/libs/clangsupport/pchmanagerserverinterface.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "projectmanagementserverinterface.h" - -#include - -namespace ClangBackEnd { - -class PchManagerClientInterface; - -class CLANGSUPPORT_EXPORT PchManagerServerInterface : public ProjectManagementServerInterface -{ -public: - void dispatch(const MessageEnvelop &messageEnvelop) override; - - virtual void end() = 0; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/pchmanagerserverproxy.cpp b/src/libs/clangsupport/pchmanagerserverproxy.cpp deleted file mode 100644 index 5f1fb03948a..00000000000 --- a/src/libs/clangsupport/pchmanagerserverproxy.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "pchmanagerserverproxy.h" - -#include "endmessage.h" -#include "messageenvelop.h" -#include "pchmanagerclientinterface.h" -#include "removegeneratedfilesmessage.h" -#include "removeprojectpartsmessage.h" -#include "updategeneratedfilesmessage.h" -#include "updateprojectpartsmessage.h" - -#include -#include - -namespace ClangBackEnd { - -PchManagerServerProxy::PchManagerServerProxy(PchManagerClientInterface *client, - QLocalSocket *localSocket) - : BaseServerProxy(client, localSocket) -{} - -PchManagerServerProxy::PchManagerServerProxy(PchManagerClientInterface *client, QIODevice *ioDevice) - : BaseServerProxy(client, ioDevice) -{ -} - -void PchManagerServerProxy::end() -{ - m_writeMessageBlock.write(EndMessage()); -} - -void PchManagerServerProxy::updateProjectParts(UpdateProjectPartsMessage &&message) -{ - m_writeMessageBlock.write(message); -} - -void PchManagerServerProxy::removeProjectParts(RemoveProjectPartsMessage &&message) -{ - m_writeMessageBlock.write(message); -} - -void PchManagerServerProxy::updateGeneratedFiles(UpdateGeneratedFilesMessage &&message) -{ - m_writeMessageBlock.write(message); -} - -void PchManagerServerProxy::removeGeneratedFiles(RemoveGeneratedFilesMessage &&message) -{ - m_writeMessageBlock.write(message); -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/pchmanagerserverproxy.h b/src/libs/clangsupport/pchmanagerserverproxy.h deleted file mode 100644 index d13d88ee8e8..00000000000 --- a/src/libs/clangsupport/pchmanagerserverproxy.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "baseserverproxy.h" -#include "clangsupport_global.h" -#include "pchmanagerserverinterface.h" -#include "readmessageblock.h" -#include "writemessageblock.h" - -#include - -#include - -QT_BEGIN_NAMESPACE -class QIODevice; -QT_END_NAMESPACE - -namespace ClangBackEnd { - -class PchManagerClientInterface; - -class CLANGSUPPORT_EXPORT PchManagerServerProxy final : public BaseServerProxy, - public PchManagerServerInterface -{ -public: - explicit PchManagerServerProxy(PchManagerClientInterface *client, QLocalSocket *localSocket); - explicit PchManagerServerProxy(PchManagerClientInterface *client, QIODevice *ioDevice); - - void end() override; - void updateProjectParts(UpdateProjectPartsMessage &&message) override; - void removeProjectParts(RemoveProjectPartsMessage &&message) override; - void updateGeneratedFiles(UpdateGeneratedFilesMessage &&message) override; - void removeGeneratedFiles(RemoveGeneratedFilesMessage &&message) override; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/pchpaths.h b/src/libs/clangsupport/pchpaths.h deleted file mode 100644 index 048ec9da8d1..00000000000 --- a/src/libs/clangsupport/pchpaths.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "filepath.h" - -namespace ClangBackEnd { - -class PchPaths -{ -public: - PchPaths() = default; - PchPaths(Utils::SmallStringView projectPchPath, Utils::SmallStringView systemPchPath) - : projectPchPath(FilePathView{projectPchPath}) - , systemPchPath(FilePathView{systemPchPath}) - {} - - friend bool operator==(const PchPaths &first, const PchPaths &second) - { - return first.projectPchPath == second.projectPchPath - && first.systemPchPath == second.systemPchPath; - } - -public: - FilePath projectPchPath; - FilePath systemPchPath; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/precompiledheadersupdatedmessage.cpp b/src/libs/clangsupport/precompiledheadersupdatedmessage.cpp deleted file mode 100644 index afb4bdc03b3..00000000000 --- a/src/libs/clangsupport/precompiledheadersupdatedmessage.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "precompiledheadersupdatedmessage.h" - -#include - -namespace ClangBackEnd { - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const PrecompiledHeadersUpdatedMessage &) -{ - debug.nospace() << "PrecompiledHeaderUpdatedMessage()"; - - return debug; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/precompiledheadersupdatedmessage.h b/src/libs/clangsupport/precompiledheadersupdatedmessage.h deleted file mode 100644 index 9e3e3b981c6..00000000000 --- a/src/libs/clangsupport/precompiledheadersupdatedmessage.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangsupport_global.h" -#include "filepathid.h" -#include "projectpartid.h" - -#include - -namespace ClangBackEnd { - -class PrecompiledHeadersUpdatedMessage -{ -public: - PrecompiledHeadersUpdatedMessage() = default; - PrecompiledHeadersUpdatedMessage(ProjectPartId projectPartId) - - { - projectPartIds.push_back(projectPartId); - } - PrecompiledHeadersUpdatedMessage(ProjectPartIds &&projectPartIds) - : projectPartIds(std::move(projectPartIds)) - {} - - ProjectPartIds takeProjectPartIds() const { return std::move(projectPartIds); } - - friend QDataStream &operator<<(QDataStream &out, const PrecompiledHeadersUpdatedMessage &message) - { - out << message.projectPartIds; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, PrecompiledHeadersUpdatedMessage &message) - { - in >> message.projectPartIds; - - return in; - } - - friend bool operator==(const PrecompiledHeadersUpdatedMessage &first, - const PrecompiledHeadersUpdatedMessage &second) - { - return first.projectPartIds == second.projectPartIds; - } - - PrecompiledHeadersUpdatedMessage clone() const { return *this; } - -public: - ProjectPartIds projectPartIds; -}; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const PrecompiledHeadersUpdatedMessage &message); - -DECLARE_MESSAGE(PrecompiledHeadersUpdatedMessage) - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/progresscounter.h b/src/libs/clangsupport/progresscounter.h deleted file mode 100644 index 21a8e13b777..00000000000 --- a/src/libs/clangsupport/progresscounter.h +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include -#include - -namespace ClangBackEnd { - -class ProgressCounter -{ -public: - using SetProgressCallback = std::function; - using Lock = std::lock_guard; - - ProgressCounter(SetProgressCallback &&progressCallback) - : m_progressCallback(std::move(progressCallback)) - {} - - void addTotal(int total) - { - Lock lock(m_mutex); - - if (total) { - m_total += total; - - m_progressCallback(m_progress, m_total); - } - } - - void removeTotal(int total) - { - Lock lock(m_mutex); - - if (total) { - m_total -= total; - - sendProgress(); - } - } - - void addProgress(int progress) - { - Lock lock(m_mutex); - - if (progress) { - m_progress += progress; - - sendProgress(); - } - } - - int total() const - { - Lock lock(m_mutex); - - return m_total; - } - - int progress() const - { - Lock lock(m_mutex); - - return m_progress; - } - -private: - void sendProgress() - { - m_progressCallback(m_progress, m_total); - - if (m_progress >= m_total) { - m_progress = 0; - m_total = 0; - } - } - -private: - mutable std::mutex m_mutex; - std::function m_progressCallback; - int m_progress = 0; - int m_total = 0; -}; - -} diff --git a/src/libs/clangsupport/progressmessage.h b/src/libs/clangsupport/progressmessage.h deleted file mode 100644 index 75902a90c3c..00000000000 --- a/src/libs/clangsupport/progressmessage.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "clangsupport_global.h" - -#include - -namespace ClangBackEnd { - -class ProgressMessage -{ -public: - ProgressMessage() = default; - ProgressMessage(ProgressType progressType, int progress, int total) - : progress(progress) - , total(total) - , progressType(progressType) - {} - - friend QDataStream &operator<<(QDataStream &out, const ProgressMessage &message) - { - out << message.progress; - out << message.total; - out << static_cast(message.progressType); - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, ProgressMessage &message) - { - int progressTupe; - in >> message.progress; - in >> message.total; - in >> progressTupe; - message.progressType = static_cast(progressTupe); - - return in; - } - - friend bool operator==(const ProgressMessage &first, const ProgressMessage &second) - { - return first.progress == second.progress - && first.total == second.total; - } - - ProgressMessage clone() const - { - return *this; - } - -public: - int progress = 0; - int total = 0; - ProgressType progressType = ProgressType::Invalid; -}; - -DECLARE_MESSAGE(ProgressMessage) -} // namespace ClangBackEnd - diff --git a/src/libs/clangsupport/projectmanagementserverinterface.h b/src/libs/clangsupport/projectmanagementserverinterface.h deleted file mode 100644 index 7a92e5ad70d..00000000000 --- a/src/libs/clangsupport/projectmanagementserverinterface.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "ipcserverinterface.h" - -namespace ClangBackEnd { - -class RemoveGeneratedFilesMessage; -class RemoveProjectPartsMessage; -class UpdateGeneratedFilesMessage; -class UpdateProjectPartsMessage; - -class ProjectManagementServerInterface : public IpcServerInterface -{ -public: - virtual void updateProjectParts(UpdateProjectPartsMessage &&message) = 0; - virtual void removeProjectParts(RemoveProjectPartsMessage &&message) = 0; - virtual void updateGeneratedFiles(UpdateGeneratedFilesMessage &&message) = 0; - virtual void removeGeneratedFiles(RemoveGeneratedFilesMessage &&message) = 0; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/projectpartartefact.cpp b/src/libs/clangsupport/projectpartartefact.cpp deleted file mode 100644 index 2c6b095ab23..00000000000 --- a/src/libs/clangsupport/projectpartartefact.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "projectpartartefact.h" - -#include - -#include -#include -#include - -namespace ClangBackEnd { - -Utils::SmallStringVector ProjectPartArtefact::toStringVector(Utils::SmallStringView jsonText) -{ - if (jsonText.isEmpty()) - return {}; - - QJsonDocument document = createJsonDocument(jsonText, "Compiler arguments parsing error"); - - return Utils::transform(document.array(), [] (const QJsonValue &value) { - return Utils::SmallString{value.toString()}; - }); -} - -CompilerMacros ProjectPartArtefact::createCompilerMacrosFromDocument(const QJsonDocument &document) -{ - QJsonArray array = document.array(); - CompilerMacros macros; - macros.reserve(array.size()); - - for (const QJsonValueRef entry : array) { - const QJsonArray entryArray = entry.toArray(); - macros.emplace_back( - entryArray[0].toString(), entryArray[1].toString(), entryArray[2].toInt()); - } - - std::sort(macros.begin(), macros.end()); - - return macros; -} - -IncludeSearchPaths ProjectPartArtefact::createIncludeSearchPathsFromDocument(const QJsonDocument &document) -{ - QJsonArray array = document.array(); - IncludeSearchPaths paths; - paths.reserve(array.size()); - - for (const QJsonValueRef entry : array) { - const QJsonArray entryArray = entry.toArray(); - paths.emplace_back(entryArray[0].toString(), entryArray[1].toInt(), entryArray[2].toInt()); - } - - return paths; -} - -CompilerMacros ProjectPartArtefact::toCompilerMacros(Utils::SmallStringView jsonText) -{ - if (jsonText.isEmpty()) - return {}; - - QJsonDocument document = createJsonDocument(jsonText, "Compiler macros parsing error"); - - return createCompilerMacrosFromDocument(document); -} - -QJsonDocument ProjectPartArtefact::createJsonDocument(Utils::SmallStringView jsonText, - const char *whatError) -{ - QJsonParseError error; - QJsonDocument document = QJsonDocument::fromJson( - QByteArray::fromRawData(jsonText.data(), int(jsonText.size())), - &error); - checkError(whatError, error); - - return document; -} - -IncludeSearchPaths ProjectPartArtefact::toIncludeSearchPaths(Utils::SmallStringView jsonText) -{ - - if (jsonText.isEmpty()) - return {}; - - QJsonDocument document = createJsonDocument(jsonText, "Include search paths parsing error"); - - return createIncludeSearchPathsFromDocument(document); -} - -void ProjectPartArtefact::checkError(const char *whatError, const QJsonParseError &error) -{ - if (error.error != QJsonParseError::NoError) { - throw ProjectPartArtefactParseError(whatError, - error.errorString()); - } -} - -bool operator==(const ProjectPartArtefact &first, const ProjectPartArtefact &second) -{ - return first.toolChainArguments == second.toolChainArguments - && first.compilerMacros == second.compilerMacros - && first.systemIncludeSearchPaths == second.systemIncludeSearchPaths - && first.projectIncludeSearchPaths == second.projectIncludeSearchPaths; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/projectpartartefact.h b/src/libs/clangsupport/projectpartartefact.h deleted file mode 100644 index 0d9bcf5c392..00000000000 --- a/src/libs/clangsupport/projectpartartefact.h +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "clangsupport_global.h" -#include "clangsupportexceptions.h" -#include "projectpartid.h" - -#include -#include - -#include -#include - -QT_FORWARD_DECLARE_CLASS(QJsonDocument) -QT_FORWARD_DECLARE_STRUCT(QJsonParseError) - -namespace ClangBackEnd { - -class CLANGSUPPORT_EXPORT ProjectPartArtefact -{ -public: - ProjectPartArtefact() = default; - ProjectPartArtefact(ProjectPartId projectPartId, - Utils::SmallStringVector &&toolChainArguments, - CompilerMacros &&compilerMacros, - IncludeSearchPaths &&systemIncludeSearchPaths, - IncludeSearchPaths &&projectIncludeSearchPaths, - Utils::Language language, - Utils::LanguageVersion languageVersion, - Utils::LanguageExtension languageExtension) - : projectPartId(projectPartId) - , toolChainArguments(std::move(toolChainArguments)) - , compilerMacros(std::move(compilerMacros)) - , systemIncludeSearchPaths(std::move(systemIncludeSearchPaths)) - , projectIncludeSearchPaths(std::move(projectIncludeSearchPaths)) - , language(language) - , languageVersion(languageVersion) - , languageExtension(languageExtension) - {} - - ProjectPartArtefact(Utils::SmallStringView compilerArgumentsText, - Utils::SmallStringView compilerMacrosText, - Utils::SmallStringView systemIncludeSearchPathsText, - Utils::SmallStringView projectIncludeSearchPathsText, - int projectPartId, - int language, - int languageVersion, - int languageExtension) - : projectPartId(projectPartId) - , toolChainArguments(toStringVector(compilerArgumentsText)) - , compilerMacros(toCompilerMacros(compilerMacrosText)) - , systemIncludeSearchPaths(toIncludeSearchPaths(systemIncludeSearchPathsText)) - , projectIncludeSearchPaths(toIncludeSearchPaths(projectIncludeSearchPathsText)) - , language(static_cast(language)) - , languageVersion(static_cast(languageVersion)) - , languageExtension(static_cast(languageExtension)) - {} - - ProjectPartArtefact(Utils::SmallStringView compilerArgumentsText, - Utils::SmallStringView compilerMacrosText, - Utils::SmallStringView systemIncludeSearchPathsText, - Utils::SmallStringView projectIncludeSearchPathsText, - int projectPartId, - Utils::Language language, - Utils::LanguageVersion languageVersion, - Utils::LanguageExtension languageExtension) - : projectPartId(projectPartId) - , toolChainArguments(toStringVector(compilerArgumentsText)) - , compilerMacros(toCompilerMacros(compilerMacrosText)) - , systemIncludeSearchPaths(toIncludeSearchPaths(systemIncludeSearchPathsText)) - , projectIncludeSearchPaths(toIncludeSearchPaths(projectIncludeSearchPathsText)) - , language(language) - , languageVersion(languageVersion) - , languageExtension(languageExtension) - {} - - static Utils::SmallStringVector toStringVector(Utils::SmallStringView jsonText); - static CompilerMacros createCompilerMacrosFromDocument(const QJsonDocument &document); - static IncludeSearchPaths createIncludeSearchPathsFromDocument(const QJsonDocument &document); - static CompilerMacros toCompilerMacros(Utils::SmallStringView jsonText); - static QJsonDocument createJsonDocument(Utils::SmallStringView jsonText, const char *whatError); - static IncludeSearchPaths toIncludeSearchPaths(Utils::SmallStringView jsonText); - static void checkError(const char *whatError, const QJsonParseError &error); - friend bool operator==(const ProjectPartArtefact &first, const ProjectPartArtefact &second); - -public: - ProjectPartId projectPartId; - Utils::SmallStringVector toolChainArguments; - CompilerMacros compilerMacros; - IncludeSearchPaths systemIncludeSearchPaths; - IncludeSearchPaths projectIncludeSearchPaths; - Utils::Language language = Utils::Language::None; - Utils::LanguageVersion languageVersion = Utils::LanguageVersion::None; - Utils::LanguageExtension languageExtension = Utils::LanguageExtension::None; -}; - -using ProjectPartArtefacts = std::vector; -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/projectpartcontainer.cpp b/src/libs/clangsupport/projectpartcontainer.cpp deleted file mode 100644 index 680b414dc7d..00000000000 --- a/src/libs/clangsupport/projectpartcontainer.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "projectpartcontainer.h" - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const ProjectPartContainer &container) -{ - debug.nospace() << "ProjectPartContainer(" << container.projectPartId.projectPathId << "," - << container.toolChainArguments << ", " << container.headerPathIds << ", " - << container.sourcePathIds << ")"; - - return debug; -} -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/projectpartcontainer.h b/src/libs/clangsupport/projectpartcontainer.h deleted file mode 100644 index caededee5c8..00000000000 --- a/src/libs/clangsupport/projectpartcontainer.h +++ /dev/null @@ -1,184 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangsupport_global.h" - -#include "compilermacro.h" -#include "filepathid.h" -#include "includesearchpath.h" -#include "projectpartartefact.h" -#include "projectpartid.h" -#include "sourceentry.h" - -#include -#include - -namespace ClangBackEnd { - -class ProjectPartContainer : public ProjectPartArtefact -{ - using uchar = unsigned char; -public: - ProjectPartContainer() = default; - ProjectPartContainer(ProjectPartId projectPartId, - Utils::SmallStringVector &&toolChainArguments, - CompilerMacros &&compilerMacros, - IncludeSearchPaths &&systemIncludeSearchPaths, - IncludeSearchPaths &&projectIncludeSearchPaths, - FilePathIds &&headerPathIds, - FilePathIds &&sourcePathIds, - Utils::Language language, - Utils::LanguageVersion languageVersion, - Utils::LanguageExtension languageExtension) - : ProjectPartArtefact(projectPartId, - std::move(toolChainArguments), - std::move(compilerMacros), - std::move(systemIncludeSearchPaths), - std::move(projectIncludeSearchPaths), - language, - languageVersion, - languageExtension) - , headerPathIds(std::move(headerPathIds)) - , sourcePathIds(std::move(sourcePathIds)) - - {} - - ProjectPartContainer(Utils::SmallStringView compilerArgumentsText, - Utils::SmallStringView compilerMacrosText, - Utils::SmallStringView systemIncludeSearchPathsText, - Utils::SmallStringView projectIncludeSearchPathsText, - int projectPartId, - int language, - int languageVersion, - int languageExtension) - : ProjectPartArtefact(compilerArgumentsText, - compilerMacrosText, - systemIncludeSearchPathsText, - projectIncludeSearchPathsText, - projectPartId, - language, - languageVersion, - languageExtension) - {} - - friend QDataStream &operator<<(QDataStream &out, const ProjectPartContainer &container) - { - out << container.projectPartId; - out << container.toolChainArguments; - out << container.compilerMacros; - out << container.systemIncludeSearchPaths; - out << container.projectIncludeSearchPaths; - out << container.headerPathIds; - out << container.sourcePathIds; - out << uchar(container.language); - out << uchar(container.languageVersion); - out << uchar(container.languageExtension); - return out; - } - - friend QDataStream &operator>>(QDataStream &in, ProjectPartContainer &container) - { - uchar language; - uchar languageVersion; - uchar languageExtension; - - in >> container.projectPartId; - in >> container.toolChainArguments; - in >> container.compilerMacros; - in >> container.systemIncludeSearchPaths; - in >> container.projectIncludeSearchPaths; - in >> container.headerPathIds; - in >> container.sourcePathIds; - in >> language; - in >> languageVersion; - in >> languageExtension; - - container.language = static_cast(language); - container.languageVersion = static_cast(languageVersion); - container.languageExtension = static_cast(languageExtension); - - return in; - } - - friend bool operator==(const ProjectPartContainer &first, const ProjectPartContainer &second) - { - return first.projectPartId == second.projectPartId - && first.toolChainArguments == second.toolChainArguments - && first.compilerMacros == second.compilerMacros - && first.systemIncludeSearchPaths == second.systemIncludeSearchPaths - && first.projectIncludeSearchPaths == second.projectIncludeSearchPaths - && first.headerPathIds == second.headerPathIds - && first.sourcePathIds == second.sourcePathIds && first.language == second.language - && first.languageVersion == second.languageVersion - && first.languageExtension == second.languageExtension; - } - - friend bool operator<(const ProjectPartContainer &first, const ProjectPartContainer &second) - { - return std::tie(first.projectPartId, - first.toolChainArguments, - first.compilerMacros, - first.systemIncludeSearchPaths, - first.projectIncludeSearchPaths, - first.headerPathIds, - first.sourcePathIds, - first.language, - first.languageVersion, - first.languageExtension, - first.preCompiledHeaderWasGenerated) - < std::tie(second.projectPartId, - second.toolChainArguments, - second.compilerMacros, - second.systemIncludeSearchPaths, - second.projectIncludeSearchPaths, - second.headerPathIds, - second.sourcePathIds, - second.language, - second.languageVersion, - second.languageExtension, - second.preCompiledHeaderWasGenerated); - } - - ProjectPartContainer clone() const - { - return *this; - } - -public: - FilePathIds headerPathIds; - FilePathIds sourcePathIds; - bool updateIsDeferred = false; - bool preCompiledHeaderWasGenerated = true; -}; - -using ProjectPartContainerReference = std::reference_wrapper; -using ProjectPartContainers = std::vector; -using ProjectPartContainerReferences = std::vector; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const ProjectPartContainer &container); - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/projectpartid.h b/src/libs/clangsupport/projectpartid.h deleted file mode 100644 index 7887e99a91a..00000000000 --- a/src/libs/clangsupport/projectpartid.h +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -#include - -namespace ClangBackEnd { - -class ProjectPartId -{ - template - friend class StringCache; - -public: - constexpr ProjectPartId() = default; - - ProjectPartId(const char *) = delete; - - ProjectPartId(int projectPathId) - : projectPathId(projectPathId) - {} - - bool isValid() const { return projectPathId >= 0; } - - friend bool operator==(ProjectPartId first, ProjectPartId second) - { - return first.isValid() && first.projectPathId == second.projectPathId; - } - - friend bool operator==(ProjectPartId first, int second) - { - return first == ProjectPartId{second}; - } - - friend bool operator!=(ProjectPartId first, ProjectPartId second) { return !(first == second); } - - friend bool operator<(ProjectPartId first, ProjectPartId second) - { - return first.projectPathId < second.projectPathId; - } - - friend QDataStream &operator<<(QDataStream &out, ProjectPartId projectPathId) - { - out << projectPathId.projectPathId; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, ProjectPartId &projectPathId) - { - in >> projectPathId.projectPathId; - - return in; - } - -private: - operator int() const { return projectPathId; } - ProjectPartId operator++() { return ++projectPathId; } - -public: - int projectPathId = -1; -}; - -using ProjectPartIds = std::vector; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/projectpartpch.cpp b/src/libs/clangsupport/projectpartpch.cpp deleted file mode 100644 index 9c870ac572b..00000000000 --- a/src/libs/clangsupport/projectpartpch.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "projectpartpch.h" - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const ProjectPartPch &projectPartPch) -{ - debug.nospace() << "FileContainer(" << projectPartPch.projectPartId.projectPathId << ")"; - - return debug; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/projectpartpch.h b/src/libs/clangsupport/projectpartpch.h deleted file mode 100644 index 213247ae429..00000000000 --- a/src/libs/clangsupport/projectpartpch.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangsupport_global.h" - -#include -#include - -namespace ClangBackEnd { - -class ProjectPartPch -{ -public: - ProjectPartPch() = default; - ProjectPartPch(ProjectPartId projectPartId, FilePath &&pchPath, long long lastModified) - : projectPartId(projectPartId) - , pchPath(std::move(pchPath)) - , lastModified(lastModified) - {} - - ProjectPartPch(int projectPartId, Utils::SmallStringView pchPath, long long lastModified) - : projectPartId(projectPartId) - , pchPath(FilePathView(pchPath)) - , lastModified(lastModified) - {} - - bool isValid() const - { - return projectPartId.isValid() && pchPath.isValid() && lastModified >= 0; - } - - friend QDataStream &operator<<(QDataStream &out, const ProjectPartPch &container) - { - out << container.projectPartId; - out << container.pchPath; - out << container.lastModified; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, ProjectPartPch &container) - { - in >> container.projectPartId; - in >> container.pchPath; - in >> container.lastModified; - - return in; - } - - friend bool operator==(const ProjectPartPch &first, - const ProjectPartPch &second) - { - return first.projectPartId == second.projectPartId && first.pchPath == second.pchPath; - } - - ProjectPartPch clone() const - { - return *this; - } - -public: - ProjectPartId projectPartId; - FilePath pchPath; - long long lastModified = -1; -}; - -using ProjectPartPchs = std::vector; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const ProjectPartPch &projectPartPch); -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/projectpartsstorage.h b/src/libs/clangsupport/projectpartsstorage.h deleted file mode 100644 index 671b6f0ef7d..00000000000 --- a/src/libs/clangsupport/projectpartsstorage.h +++ /dev/null @@ -1,416 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "clangsupportexceptions.h" -#include "projectpartsstorageinterface.h" - -#include -#include - -namespace ClangBackEnd { - -template -class ProjectPartsStorage final : public ProjectPartsStorageInterface -{ - template - using ReadStatement = typename Database::template ReadStatement; - using WriteStatement = typename Database::WriteStatement; - -public: - ProjectPartsStorage(Database &database) - : transaction(database) - , database(database) - { - transaction.commit(); - } - - ProjectPartContainers fetchProjectParts() const override - { - try { - Sqlite::DeferredTransaction transaction{database}; - - auto values = fetchProjectPartsStatement.template values(4096); - - transaction.commit(); - - return values; - } catch (const Sqlite::StatementIsBusy &) { - return fetchProjectParts(); - } - } - - FilePathIds fetchHeaders(ProjectPartId projectPartId) const - { - return fetchProjectPartsHeadersByIdStatement - .template values(1024, projectPartId.projectPathId); - } - - FilePathIds fetchSources(ProjectPartId projectPartId) const - { - return fetchProjectPartsSourcesByIdStatement - .template values(1024, projectPartId.projectPathId); - } - - bool preCompiledHeaderWasGenerated(ProjectPartId projectPartId) const - { - auto value = fetchProjectPrecompiledHeaderBuildTimeStatement.template optionalValue( - projectPartId.projectPathId); - - return value && *value > 0; - } - - ProjectPartContainers fetchProjectParts(const ProjectPartIds &projectPartIds) const override - { - try { - ProjectPartContainers projectParts; - projectParts.reserve(projectPartIds.size()); - - Sqlite::DeferredTransaction transaction{database}; - - for (ProjectPartId projectPartId : projectPartIds) { - auto value = fetchProjectPartByIdStatement.template optionalValue( - projectPartId.projectPathId); - if (value) { - value->headerPathIds = fetchHeaders(projectPartId); - value->sourcePathIds = fetchSources(projectPartId); - value->preCompiledHeaderWasGenerated = preCompiledHeaderWasGenerated(projectPartId); - projectParts.push_back(*std::move(value)); - } - } - - transaction.commit(); - - return projectParts; - } catch (const Sqlite::StatementIsBusy &) { - return fetchProjectParts(projectPartIds); - } - } - - ProjectPartId fetchProjectPartIdUnguarded(Utils::SmallStringView projectPartName) const override - { - auto optionalProjectPartId = fetchProjectPartIdStatement.template optionalValue( - projectPartName); - - if (optionalProjectPartId) { - return *optionalProjectPartId; - } else { - insertProjectPartNameStatement.write(projectPartName); - - return static_cast(database.lastInsertedRowId()); - } - - return {}; - } - - ProjectPartId fetchProjectPartId(Utils::SmallStringView projectPartName) const override - { - try { - Sqlite::DeferredTransaction transaction{database}; - - ProjectPartId projectPartId = fetchProjectPartIdUnguarded(projectPartName); - - transaction.commit(); - - return projectPartId; - - } catch (const Sqlite::StatementIsBusy &) { - return fetchProjectPartId(projectPartName); - } - } - - Utils::PathString fetchProjectPartName(ProjectPartId projectPartId) const override - { - try { - Sqlite::DeferredTransaction transaction{database}; - - auto optionalProjectPartName = fetchProjectPartNameStatement - .template optionalValue( - projectPartId.projectPathId); - - transaction.commit(); - - if (optionalProjectPartName) - return *std::move(optionalProjectPartName); - } catch (const Sqlite::StatementIsBusy &) { - return fetchProjectPartName(projectPartId); - } - - throwProjectPartDoesNotExists(projectPartId); - } - - void insertHeaders(ProjectPartId projectPartId, const FilePathIds &headerPathIds) - { - deleteProjectPartsHeadersByIdStatement.write(projectPartId.projectPathId); - for (FilePathId headerPathId : headerPathIds) { - insertProjectPartsHeadersStatement.write(projectPartId.projectPathId, - headerPathId.filePathId); - } - } - - void insertSources(ProjectPartId projectPartId, const FilePathIds &sourcePathIds) - { - deleteProjectPartsSourcesByIdStatement.write(projectPartId.projectPathId); - for (FilePathId sourcePathId : sourcePathIds) { - insertProjectPartsSourcesStatement.write(projectPartId.projectPathId, - sourcePathId.filePathId); - } - } - - void updateProjectPart(ProjectPartId projectPartId, - const Utils::SmallStringVector &toolChainArguments, - const CompilerMacros &compilerMacros, - const IncludeSearchPaths &systemIncludeSearchPaths, - const IncludeSearchPaths &projectIncludeSearchPaths, - Utils::Language language, - Utils::LanguageVersion languageVersion, - Utils::LanguageExtension languageExtension) override - { - Utils::SmallString toolChainArgumentsAsJson = toJson(toolChainArguments); - Utils::SmallString compilerMacrosAsJson = toJson(compilerMacros); - Utils::SmallString systemIncludeSearchPathsAsJason = toJson(systemIncludeSearchPaths); - Utils::SmallString projectIncludeSearchPathsAsJason = toJson(projectIncludeSearchPaths); - - updateProjectPartStatement.write(projectPartId.projectPathId, - toolChainArgumentsAsJson, - compilerMacrosAsJson, - systemIncludeSearchPathsAsJason, - projectIncludeSearchPathsAsJason, - static_cast(language), - static_cast(languageVersion), - static_cast(languageExtension)); - } - - void updateProjectPart(const ProjectPartContainer &projectPart) - { - Utils::SmallString toolChainArgumentsAsJson = toJson(projectPart.toolChainArguments); - Utils::SmallString compilerMacrosAsJson = toJson(projectPart.compilerMacros); - Utils::SmallString systemIncludeSearchPathsAsJason = toJson( - projectPart.systemIncludeSearchPaths); - Utils::SmallString projectIncludeSearchPathsAsJason = toJson( - projectPart.projectIncludeSearchPaths); - - updateProjectPartStatement.write(projectPart.projectPartId.projectPathId, - toolChainArgumentsAsJson, - compilerMacrosAsJson, - systemIncludeSearchPathsAsJason, - projectIncludeSearchPathsAsJason, - static_cast(projectPart.language), - static_cast(projectPart.languageVersion), - static_cast(projectPart.languageExtension)); - - insertHeaders(projectPart.projectPartId, projectPart.headerPathIds); - insertSources(projectPart.projectPartId, projectPart.sourcePathIds); - } - - void updateProjectParts(const ProjectPartContainers &projectParts) override - { - try { - Sqlite::ImmediateTransaction transaction{database}; - - for (const ProjectPartContainer &projectPart : projectParts) - updateProjectPart(projectPart); - - transaction.commit(); - } catch (const Sqlite::StatementIsBusy &) { - updateProjectParts(projectParts); - } - } - - Utils::optional fetchProjectPartArtefact(FilePathId sourceId) const override - { - try { - Sqlite::DeferredTransaction transaction{database}; - - auto &statement = getProjectPartArtefactsBySourceId; - - auto value = statement.template optionalValue(sourceId.filePathId); - - transaction.commit(); - - return value; - } catch (const Sqlite::StatementIsBusy &) { - return fetchProjectPartArtefact(sourceId); - } - } - - Utils::optional fetchProjectPartArtefact(ProjectPartId projectPartId) const override - { - try { - Sqlite::DeferredTransaction transaction{database}; - - auto &statement = getProjectPartArtefactsByProjectPartId; - - auto value = statement.template optionalValue( - projectPartId.projectPathId); - - transaction.commit(); - - return value; - } catch (const Sqlite::StatementIsBusy &) { - return fetchProjectPartArtefact(projectPartId); - } - } - - void resetIndexingTimeStamps(const ProjectPartContainers &projectsParts) override - { - try { - Sqlite::ImmediateTransaction transaction{database}; - - for (const ProjectPartContainer &projectPart : projectsParts) { - for (FilePathId sourcePathId : projectPart.sourcePathIds) - resetDependentIndexingTimeStampsStatement.write(sourcePathId.filePathId); - } - - transaction.commit(); - } catch (const Sqlite::StatementIsBusy &) { - resetIndexingTimeStamps(projectsParts); - } - } - - Sqlite::TransactionInterface &transactionBackend() override { return database; } - - static Utils::SmallString toJson(const Utils::SmallStringVector &strings) - { - QJsonDocument document; - QJsonArray array; - - std::transform(strings.begin(), - strings.end(), - std::back_inserter(array), - [](const auto &string) { return QJsonValue(string.data()); }); - - document.setArray(array); - - return document.toJson(QJsonDocument::Compact); - } - - static Utils::SmallString toJson(const CompilerMacros &compilerMacros) - { - QJsonDocument document; - QJsonArray array; - - for (const CompilerMacro ¯o : compilerMacros) - array.push_back(QJsonArray{{QString(macro.key), QString(macro.value), macro.index}}); - - document.setArray(array); - - return document.toJson(QJsonDocument::Compact); - } - - static Utils::SmallString toJson(const IncludeSearchPaths &includeSearchPaths) - { - QJsonDocument document; - QJsonArray array; - - for (const IncludeSearchPath &path : includeSearchPaths) - array.push_back(QJsonArray{{path.path.data(), path.index, int(path.type)}}); - - document.setArray(array); - - return document.toJson(QJsonDocument::Compact); - } - - [[noreturn]] void throwProjectPartDoesNotExists(ProjectPartId projectPartId) const - { - throw ProjectPartDoesNotExists("Try to fetch non existing project part id: ", - Utils::SmallString::number(projectPartId.projectPathId)); - } - - Internal::ProjectPartNameIds fetchAllProjectPartNamesAndIds() const override - { - try { - Sqlite::DeferredTransaction transaction{database}; - - auto &statement = fetchAllProjectPartNamesAndIdsStatement; - - auto values = statement.template values(256); - - transaction.commit(); - - return values; - } catch (const Sqlite::StatementIsBusy &) { - return fetchAllProjectPartNamesAndIds(); - } - } - -public: - Sqlite::ImmediateNonThrowingDestructorTransaction transaction; - Database &database; - mutable ReadStatement<1> fetchProjectPartIdStatement{ - "SELECT projectPartId FROM projectParts WHERE projectPartName = ?", database}; - mutable WriteStatement insertProjectPartNameStatement{ - "INSERT INTO projectParts(projectPartName) VALUES (?)", database}; - mutable ReadStatement<1> fetchProjectPartNameStatement{ - "SELECT projectPartName FROM projectParts WHERE projectPartId = ?", database}; - mutable ReadStatement<8> fetchProjectPartsStatement{ - "SELECT toolChainArguments, compilerMacros, systemIncludeSearchPaths, " - "projectIncludeSearchPaths, projectPartId, language, languageVersion, languageExtension " - "FROM projectParts", - database}; - mutable ReadStatement<8> fetchProjectPartByIdStatement{ - "SELECT toolChainArguments, compilerMacros, systemIncludeSearchPaths, " - "projectIncludeSearchPaths, projectPartId, language, languageVersion, languageExtension " - "FROM projectParts WHERE projectPartId = ?", - database}; - WriteStatement updateProjectPartStatement{ - "UPDATE projectParts SET toolChainArguments=?002, compilerMacros=?003, " - "systemIncludeSearchPaths=?004, projectIncludeSearchPaths=?005, language=?006, " - "languageVersion=?007, languageExtension=?008 WHERE projectPartId = ?001", - database}; - mutable ReadStatement<8> getProjectPartArtefactsBySourceId{ - "SELECT toolChainArguments, compilerMacros, systemIncludeSearchPaths, " - "projectIncludeSearchPaths, projectPartId, language, languageVersion, languageExtension " - "FROM projectParts WHERE projectPartId = (SELECT " - "projectPartId FROM projectPartsFiles WHERE sourceId = ?)", - database}; - mutable ReadStatement<8> getProjectPartArtefactsByProjectPartId{ - "SELECT toolChainArguments, compilerMacros, systemIncludeSearchPaths, " - "projectIncludeSearchPaths, projectPartId, language, languageVersion, languageExtension " - "FROM projectParts WHERE projectPartId = ?", - database}; - WriteStatement deleteProjectPartsHeadersByIdStatement{ - "DELETE FROM projectPartsHeaders WHERE projectPartId = ?", database}; - WriteStatement deleteProjectPartsSourcesByIdStatement{ - "DELETE FROM projectPartsSources WHERE projectPartId = ?", database}; - WriteStatement insertProjectPartsHeadersStatement{ - "INSERT INTO projectPartsHeaders(projectPartId, sourceId) VALUES (?,?)", database}; - WriteStatement insertProjectPartsSourcesStatement{ - "INSERT INTO projectPartsSources(projectPartId, sourceId) VALUES (?,?)", database}; - mutable ReadStatement<1> fetchProjectPartsHeadersByIdStatement{ - "SELECT sourceId FROM projectPartsHeaders WHERE projectPartId = ? ORDER BY sourceId", - database}; - mutable ReadStatement<1> fetchProjectPartsSourcesByIdStatement{ - "SELECT sourceId FROM projectPartsSources WHERE projectPartId = ? ORDER BY sourceId", - database}; - mutable ReadStatement<1> fetchProjectPrecompiledHeaderBuildTimeStatement{ - "SELECT projectPchBuildTime FROM precompiledHeaders WHERE projectPartId = ?", database}; - WriteStatement resetDependentIndexingTimeStampsStatement{ - "UPDATE fileStatuses SET indexingTimeStamp = NULL WHERE sourceId = ?", database}; - mutable ReadStatement<2> fetchAllProjectPartNamesAndIdsStatement{ - "SELECT projectPartName, projectPartId FROM projectParts", database}; -}; -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/projectpartsstorageinterface.h b/src/libs/clangsupport/projectpartsstorageinterface.h deleted file mode 100644 index ec1ce65dd06..00000000000 --- a/src/libs/clangsupport/projectpartsstorageinterface.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "projectpartcontainer.h" -#include "projectpartstoragestructs.h" - -#include -#include -#include - -#include -#include -#include - -namespace ClangBackEnd { - -class ProjectPartsStorageInterface -{ -public: - ProjectPartsStorageInterface() = default; - ProjectPartsStorageInterface(const ProjectPartsStorageInterface &) = delete; - ProjectPartsStorageInterface &operator=(const ProjectPartsStorageInterface &) = delete; - - virtual ProjectPartContainers fetchProjectParts() const = 0; - virtual ProjectPartContainers fetchProjectParts(const ProjectPartIds &projectPartIds) const = 0; - virtual ProjectPartId fetchProjectPartIdUnguarded(Utils::SmallStringView projectPartName) const = 0; - virtual ProjectPartId fetchProjectPartId(Utils::SmallStringView projectPartName) const = 0; - virtual Utils::PathString fetchProjectPartName(ProjectPartId projectPartId) const = 0; - virtual Internal::ProjectPartNameIds fetchAllProjectPartNamesAndIds() const = 0; - virtual void updateProjectPart(ProjectPartId projectPartId, - const Utils::SmallStringVector &commandLineArguments, - const CompilerMacros &compilerMacros, - const ClangBackEnd::IncludeSearchPaths &systemIncludeSearchPaths, - const ClangBackEnd::IncludeSearchPaths &projectIncludeSearchPaths, - Utils::Language language, - Utils::LanguageVersion languageVersion, - Utils::LanguageExtension languageExtension) - = 0; - - virtual void updateProjectParts(const ProjectPartContainers &projectParts) = 0; - - virtual Utils::optional fetchProjectPartArtefact(FilePathId sourceId) const = 0; - virtual Utils::optional fetchProjectPartArtefact( - ProjectPartId projectPartId) const = 0; - virtual void resetIndexingTimeStamps(const ProjectPartContainers &projectsParts) = 0; - - virtual Sqlite::TransactionInterface &transactionBackend() = 0; - -protected: - ~ProjectPartsStorageInterface() = default; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/projectpartstoragestructs.h b/src/libs/clangsupport/projectpartstoragestructs.h deleted file mode 100644 index b575d312402..00000000000 --- a/src/libs/clangsupport/projectpartstoragestructs.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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 - -#include "projectpartid.h" -#include "stringcacheentry.h" - -#include - -#include - -namespace ClangBackEnd { - -namespace Internal { - -class ProjectPartNameId - : public StringCacheEntry -{ - using Base = StringCacheEntry; - -public: - using Base::Base; - - ProjectPartNameId(Utils::SmallStringView projectPartName, int projectPartId) - : Base(projectPartName, projectPartId) - {} -}; - -using ProjectPartNameIds = std::vector; -} // namespace Internal - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/refactoringclientinterface.cpp b/src/libs/clangsupport/refactoringclientinterface.cpp deleted file mode 100644 index e862e4e4d96..00000000000 --- a/src/libs/clangsupport/refactoringclientinterface.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "refactoringclientinterface.h" - -#include "messageenvelop.h" -#include "clangrefactoringclientmessages.h" - -#include - -namespace ClangBackEnd { - -void RefactoringClientInterface::dispatch(const MessageEnvelop &messageEnvelop) -{ - switch (messageEnvelop.messageType()) { - case MessageType::AliveMessage: - alive(); - break; - case MessageType::SourceRangesAndDiagnosticsForQueryMessage: - sourceRangesAndDiagnosticsForQueryMessage(messageEnvelop.message()); - break; - case MessageType::SourceRangesForQueryMessage: - sourceRangesForQueryMessage(messageEnvelop.message()); - break; - case MessageType::ProgressMessage: - progress(messageEnvelop.message()); - break; - default: - qWarning() << "Unknown IpcClientMessage"; - } -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/refactoringclientinterface.h b/src/libs/clangsupport/refactoringclientinterface.h deleted file mode 100644 index 71c48097535..00000000000 --- a/src/libs/clangsupport/refactoringclientinterface.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "ipcclientinterface.h" - -#include - -namespace ClangBackEnd { - -class ProgressMessage; -class SourceLocationsForRenamingMessage; -class SourceRangesAndDiagnosticsForQueryMessage; -class SourceRangesForQueryMessage; -class SourceLocationsContainer; - -class CLANGSUPPORT_EXPORT RefactoringClientInterface : public IpcClientInterface -{ -public: - using RenameCallback = std::function; - - void dispatch(const MessageEnvelop &messageEnvelop) override; - - virtual void alive() = 0; - virtual void sourceRangesAndDiagnosticsForQueryMessage(SourceRangesAndDiagnosticsForQueryMessage &&message) = 0; - virtual void sourceRangesForQueryMessage(SourceRangesForQueryMessage &&message) = 0; - virtual void progress(ProgressMessage &&message) = 0; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/refactoringclientproxy.cpp b/src/libs/clangsupport/refactoringclientproxy.cpp deleted file mode 100644 index b2d30d7bfb9..00000000000 --- a/src/libs/clangsupport/refactoringclientproxy.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "refactoringclientproxy.h" - -#include "alivemessage.h" -#include "messageenvelop.h" -#include "refactoringserverinterface.h" -#include "clangrefactoringclientmessages.h" - -#include -#include - -namespace ClangBackEnd { - -RefactoringClientProxy::RefactoringClientProxy(RefactoringServerInterface *server, - QLocalSocket *localSocket) - : writeMessageBlock(localSocket) - , readMessageBlock(localSocket) - , server(server) -{ - QObject::connect(localSocket, &QIODevice::readyRead, [this]() { - RefactoringClientProxy::readMessages(); - }); -} - -RefactoringClientProxy::RefactoringClientProxy(RefactoringServerInterface *server, - QIODevice *ioDevice) - : writeMessageBlock(ioDevice) - , readMessageBlock(ioDevice) - , server(server) -{ - QObject::connect(ioDevice, &QIODevice::readyRead, [this] () {RefactoringClientProxy::readMessages();}); -} - -void RefactoringClientProxy::readMessages() -{ - for (const MessageEnvelop &message : readMessageBlock.readAll()) - server->dispatch(message); -} - -void RefactoringClientProxy::alive() -{ - writeMessageBlock.write(AliveMessage()); -} - -void RefactoringClientProxy::sourceRangesAndDiagnosticsForQueryMessage(SourceRangesAndDiagnosticsForQueryMessage &&message) -{ - writeMessageBlock.write(message); -} - -void RefactoringClientProxy::sourceRangesForQueryMessage(SourceRangesForQueryMessage &&message) -{ - writeMessageBlock.write(message); -} - -void RefactoringClientProxy::progress(ProgressMessage &&message) -{ - writeMessageBlock.write(message); -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/refactoringclientproxy.h b/src/libs/clangsupport/refactoringclientproxy.h deleted file mode 100644 index 2af2188d60d..00000000000 --- a/src/libs/clangsupport/refactoringclientproxy.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangsupport_global.h" -#include "refactoringclientinterface.h" -#include "readmessageblock.h" -#include "writemessageblock.h" - -#include - -namespace ClangBackEnd { - -class RefactoringServerInterface; - -class CLANGSUPPORT_EXPORT RefactoringClientProxy : public RefactoringClientInterface -{ -public: - explicit RefactoringClientProxy(RefactoringServerInterface *server, QLocalSocket *localSocket); - explicit RefactoringClientProxy(RefactoringServerInterface *server, QIODevice *ioDevice); - RefactoringClientProxy(const RefactoringClientProxy&) = delete; - const RefactoringClientProxy &operator=(const RefactoringClientProxy&) = delete; - - RefactoringClientProxy(RefactoringClientProxy &&other) = delete; - RefactoringClientProxy &operator=(RefactoringClientProxy &&other) = delete; - - void readMessages(); - - void alive() override; - void sourceRangesAndDiagnosticsForQueryMessage(SourceRangesAndDiagnosticsForQueryMessage &&message) override; - void sourceRangesForQueryMessage(SourceRangesForQueryMessage &&message) override; - void progress(ProgressMessage &&message) override; - -private: - ClangBackEnd::WriteMessageBlock writeMessageBlock; - ClangBackEnd::ReadMessageBlock readMessageBlock; - RefactoringServerInterface *server = nullptr; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/refactoringdatabaseinitializer.h b/src/libs/clangsupport/refactoringdatabaseinitializer.h deleted file mode 100644 index b26bd4ef046..00000000000 --- a/src/libs/clangsupport/refactoringdatabaseinitializer.h +++ /dev/null @@ -1,240 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -#include -#include - -namespace ClangBackEnd { - -template -class RefactoringDatabaseInitializer -{ -public: - RefactoringDatabaseInitializer(DatabaseType &database) - : database(database) - { - if (!database.isInitialized()) { - Sqlite::ExclusiveTransaction transaction{database}; - - createSymbolsTable(); - createLocationsTable(); - createSourcesTable(); - createDirectoriesTable(); - createProjectPartsTable(); - createProjectPartsFilesTable(); - createUsedMacrosTable(); - createFileStatusesTable(); - createSourceDependenciesTable(); - createPrecompiledHeadersTable(); - createProjectPartsHeadersTable(); - createProjectPartsSourcesTable(); - - transaction.commit(); - - database.setIsInitialized(true); - } - } - - void createSymbolsTable() - { - Sqlite::Table table; - table.setUseIfNotExists(true); - table.setName("symbols"); - table.addColumn("symbolId", Sqlite::ColumnType::Integer, {Sqlite::PrimaryKey{}}); - const Sqlite::Column &usrColumn = table.addColumn("usr", Sqlite::ColumnType::Text); - const Sqlite::Column &symbolNameColumn = table.addColumn("symbolName", Sqlite::ColumnType::Text); - const Sqlite::Column &symbolKindColumn = table.addColumn("symbolKind", Sqlite::ColumnType::Integer); - table.addColumn("signature", Sqlite::ColumnType::Text); - table.addIndex({usrColumn}); - table.addIndex({symbolKindColumn, symbolNameColumn}); - - table.initialize(database); - } - - void createLocationsTable() - { - Sqlite::Table table; - table.setUseIfNotExists(true); - table.setName("locations"); - const Sqlite::Column &symbolIdColumn = table.addColumn("symbolId", - Sqlite::ColumnType::Integer); - const Sqlite::Column &lineColumn = table.addColumn("line", Sqlite::ColumnType::Integer); - const Sqlite::Column &columnColumn = table.addColumn("column", Sqlite::ColumnType::Integer); - const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); - const Sqlite::Column &locationKindColumn = table.addColumn("locationKind", Sqlite::ColumnType::Integer); - table.addUniqueIndex({sourceIdColumn, lineColumn, columnColumn}); - table.addIndex({sourceIdColumn, locationKindColumn}); - table.addIndex({symbolIdColumn}); - - table.initialize(database); - } - - void createSourcesTable() - { - Sqlite::Table table; - table.setUseIfNotExists(true); - table.setName("sources"); - table.addColumn("sourceId", Sqlite::ColumnType::Integer, {Sqlite::PrimaryKey{}}); - const Sqlite::Column &directoryIdColumn = table.addColumn("directoryId", Sqlite::ColumnType::Integer); - const Sqlite::Column &sourceNameColumn = table.addColumn("sourceName", Sqlite::ColumnType::Text); - table.addUniqueIndex({directoryIdColumn, sourceNameColumn}); - - table.initialize(database); - } - - void createDirectoriesTable() - { - Sqlite::Table table; - table.setUseIfNotExists(true); - table.setName("directories"); - table.addColumn("directoryId", Sqlite::ColumnType::Integer, {Sqlite::PrimaryKey{}}); - const Sqlite::Column &directoryPathColumn = table.addColumn("directoryPath", Sqlite::ColumnType::Text); - table.addUniqueIndex({directoryPathColumn}); - - table.initialize(database); - } - - void createProjectPartsTable() - { - Sqlite::Table table; - table.setUseIfNotExists(true); - table.setName("projectParts"); - table.addColumn("projectPartId", Sqlite::ColumnType::Integer, {Sqlite::PrimaryKey{}}); - const Sqlite::Column &projectPartNameColumn = table.addColumn("projectPartName", Sqlite::ColumnType::Text); - table.addColumn("toolChainArguments", Sqlite::ColumnType::Text); - table.addColumn("compilerMacros", Sqlite::ColumnType::Text); - table.addColumn("systemIncludeSearchPaths", Sqlite::ColumnType::Text); - table.addColumn("projectIncludeSearchPaths", Sqlite::ColumnType::Text); - table.addColumn("language", Sqlite::ColumnType::Integer); - table.addColumn("languageVersion", Sqlite::ColumnType::Integer); - table.addColumn("languageExtension", Sqlite::ColumnType::Integer); - table.addUniqueIndex({projectPartNameColumn}); - - table.initialize(database); - } - - void createProjectPartsFilesTable() - { - Sqlite::Table table; - table.setUseIfNotExists(true); - table.setName("projectPartsFiles"); - const Sqlite::Column &projectPartIdColumn = table.addColumn("projectPartId", Sqlite::ColumnType::Integer); - const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); - const Sqlite::Column &sourceType = table.addColumn("sourceType", Sqlite::ColumnType::Integer); - table.addColumn("pchCreationTimeStamp", Sqlite::ColumnType::Integer); - table.addColumn("hasMissingIncludes", Sqlite::ColumnType::Integer); - table.addUniqueIndex({sourceIdColumn, projectPartIdColumn}); - table.addIndex({projectPartIdColumn, sourceType}); - - table.initialize(database); - } - - void createUsedMacrosTable() - { - Sqlite::Table table; - table.setUseIfNotExists(true); - table.setName("usedMacros"); - table.addColumn("usedMacroId", Sqlite::ColumnType::Integer, {Sqlite::PrimaryKey{}}); - const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); - const Sqlite::Column ¯oNameColumn = table.addColumn("macroName", Sqlite::ColumnType::Text); - table.addIndex({sourceIdColumn, macroNameColumn}); - table.addIndex({macroNameColumn}); - - table.initialize(database); - } - - void createFileStatusesTable() - { - Sqlite::Table table; - table.setUseIfNotExists(true); - table.setName("fileStatuses"); - table.addColumn("sourceId", Sqlite::ColumnType::Integer, {Sqlite::PrimaryKey{}}); - table.addColumn("size", Sqlite::ColumnType::Integer); - table.addColumn("lastModified", Sqlite::ColumnType::Integer); - table.addColumn("indexingTimeStamp", Sqlite::ColumnType::Integer); - table.initialize(database); - } - - void createSourceDependenciesTable() - { - Sqlite::Table table; - table.setUseIfNotExists(true); - table.setName("sourceDependencies"); - const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); - const Sqlite::Column &dependencySourceIdColumn = table.addColumn("dependencySourceId", Sqlite::ColumnType::Integer); - table.addIndex({sourceIdColumn, dependencySourceIdColumn}); - table.addIndex({dependencySourceIdColumn, sourceIdColumn}); - - table.initialize(database); - } - - void createPrecompiledHeadersTable() - { - Sqlite::Table table; - table.setUseIfNotExists(true); - table.setName("precompiledHeaders"); - table.addColumn("projectPartId", Sqlite::ColumnType::Integer, {Sqlite::PrimaryKey{}}); - table.addColumn("projectPchPath", Sqlite::ColumnType::Text); - table.addColumn("projectPchBuildTime", Sqlite::ColumnType::Integer); - table.addColumn("systemPchPath", Sqlite::ColumnType::Text); - table.addColumn("systemPchBuildTime", Sqlite::ColumnType::Integer); - table.initialize(database); - } - - void createProjectPartsHeadersTable() - { - Sqlite::Table table; - table.setUseIfNotExists(true); - table.setName("projectPartsHeaders"); - const Sqlite::Column &projectPartIdColumn = table.addColumn("projectPartId", - Sqlite::ColumnType::Integer); - table.addColumn("sourceId", Sqlite::ColumnType::Integer); - table.addIndex({projectPartIdColumn}); - - table.initialize(database); - } - - void createProjectPartsSourcesTable() - { - Sqlite::Table table; - table.setUseIfNotExists(true); - table.setName("projectPartsSources"); - const Sqlite::Column &projectPartIdColumn = table.addColumn("projectPartId", - Sqlite::ColumnType::Integer); - table.addColumn("sourceId", Sqlite::ColumnType::Integer); - table.addIndex({projectPartIdColumn}); - - table.initialize(database); - } - -public: - DatabaseType &database; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/refactoringserverinterface.cpp b/src/libs/clangsupport/refactoringserverinterface.cpp deleted file mode 100644 index 6fcaa0f0547..00000000000 --- a/src/libs/clangsupport/refactoringserverinterface.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "refactoringserverinterface.h" - -#include "messageenvelop.h" -#include "clangrefactoringservermessages.h" - -#include - -namespace ClangBackEnd { - -void RefactoringServerInterface::dispatch(const MessageEnvelop &messageEnvelop) -{ - switch (messageEnvelop.messageType()) { - case MessageType::EndMessage: - end(); - break; - case MessageType::RequestSourceRangesAndDiagnosticsForQueryMessage: - requestSourceRangesAndDiagnosticsForQueryMessage(messageEnvelop.message()); - break; - case MessageType::RequestSourceRangesForQueryMessage: - requestSourceRangesForQueryMessage(messageEnvelop.message()); - break; - case MessageType::UpdateProjectPartsMessage: - updateProjectParts(messageEnvelop.message()); - break; - case MessageType::UpdateGeneratedFilesMessage: - updateGeneratedFiles(messageEnvelop.message()); - break; - case MessageType::RemoveProjectPartsMessage: - removeProjectParts(messageEnvelop.message()); - break; - case MessageType::RemoveGeneratedFilesMessage: - removeGeneratedFiles(messageEnvelop.message()); - break; - case MessageType::CancelMessage: - cancel(); - break; - default: - qWarning() << "Unknown IpcClientMessage"; - } -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/refactoringserverinterface.h b/src/libs/clangsupport/refactoringserverinterface.h deleted file mode 100644 index 0f20da9ddfc..00000000000 --- a/src/libs/clangsupport/refactoringserverinterface.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "projectmanagementserverinterface.h" - -#include - -namespace ClangBackEnd { - -class RefactoringClientInterface; -class RequestSourceRangesAndDiagnosticsForQueryMessage; -class RequestSourceRangesForQueryMessage; -class CancelMessage; -class UpdateProjectPartsMessage; -class RemoveProjectPartsMessage; - -class CLANGSUPPORT_EXPORT RefactoringServerInterface : public ProjectManagementServerInterface - -{ -public: - void dispatch(const MessageEnvelop &messageEnvelop) override; - - virtual void end() = 0; - virtual void requestSourceRangesAndDiagnosticsForQueryMessage(RequestSourceRangesAndDiagnosticsForQueryMessage &&message) = 0; - virtual void requestSourceRangesForQueryMessage(RequestSourceRangesForQueryMessage &&message) = 0; - virtual void cancel() = 0; - - bool isAvailable() const - { - return isAvailable_; - } - void setAvailable(bool isAvailable) - { - isAvailable_ = isAvailable; - } - -private: - bool isAvailable_ = false; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/refactoringserverproxy.cpp b/src/libs/clangsupport/refactoringserverproxy.cpp deleted file mode 100644 index a206a2531b8..00000000000 --- a/src/libs/clangsupport/refactoringserverproxy.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "refactoringserverproxy.h" - -#include "messageenvelop.h" -#include "refactoringclientinterface.h" -#include "clangrefactoringservermessages.h" - -#include -#include - -namespace ClangBackEnd { - -RefactoringServerProxy::RefactoringServerProxy(RefactoringClientInterface *client, - QLocalSocket *localSocket) - : BaseServerProxy(client, localSocket) -{} - -RefactoringServerProxy::RefactoringServerProxy(RefactoringClientInterface *client, - QIODevice *ioDevice) - : BaseServerProxy(client, ioDevice) -{ -} - -void RefactoringServerProxy::end() -{ - m_writeMessageBlock.write(EndMessage()); -} - -void RefactoringServerProxy::requestSourceRangesAndDiagnosticsForQueryMessage(RequestSourceRangesAndDiagnosticsForQueryMessage &&message) -{ - m_writeMessageBlock.write(message); -} - -void RefactoringServerProxy::requestSourceRangesForQueryMessage(RequestSourceRangesForQueryMessage &&message) -{ - m_writeMessageBlock.write(message); -} - -void RefactoringServerProxy::updateProjectParts(UpdateProjectPartsMessage &&message) -{ - m_writeMessageBlock.write(message); -} - -void RefactoringServerProxy::removeProjectParts(RemoveProjectPartsMessage &&message) -{ - m_writeMessageBlock.write(message); -} - -void RefactoringServerProxy::updateGeneratedFiles(UpdateGeneratedFilesMessage &&message) -{ - m_writeMessageBlock.write(message); -} - -void RefactoringServerProxy::removeGeneratedFiles(RemoveGeneratedFilesMessage &&message) -{ - m_writeMessageBlock.write(message); -} - -void RefactoringServerProxy::cancel() -{ - m_writeMessageBlock.write(CancelMessage()); -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/refactoringserverproxy.h b/src/libs/clangsupport/refactoringserverproxy.h deleted file mode 100644 index 4b91036c46b..00000000000 --- a/src/libs/clangsupport/refactoringserverproxy.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "baseserverproxy.h" -#include "clangsupport_global.h" -#include "refactoringserverinterface.h" -#include "readmessageblock.h" -#include "writemessageblock.h" - -#include - -#include - -QT_BEGIN_NAMESPACE -class QIODevice; -QT_END_NAMESPACE - -namespace ClangBackEnd { - -class RefactoringClientInterface; - -class CLANGSUPPORT_EXPORT RefactoringServerProxy final : public BaseServerProxy, - public RefactoringServerInterface -{ -public: - explicit RefactoringServerProxy(RefactoringClientInterface *client, - QLocalSocket *localSocket = {}); - explicit RefactoringServerProxy(RefactoringClientInterface *client, QIODevice *ioDevice); - - void end() override; - void requestSourceRangesAndDiagnosticsForQueryMessage(RequestSourceRangesAndDiagnosticsForQueryMessage &&message) override; - void requestSourceRangesForQueryMessage(RequestSourceRangesForQueryMessage &&message) override; - void updateProjectParts(UpdateProjectPartsMessage &&message) override; - void removeProjectParts(RemoveProjectPartsMessage &&message) override; - void updateGeneratedFiles(UpdateGeneratedFilesMessage &&message) override; - void removeGeneratedFiles(RemoveGeneratedFilesMessage &&message) override; - void cancel() override; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/removegeneratedfilesmessage.cpp b/src/libs/clangsupport/removegeneratedfilesmessage.cpp deleted file mode 100644 index 2ed92a81692..00000000000 --- a/src/libs/clangsupport/removegeneratedfilesmessage.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "removegeneratedfilesmessage.h" - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const RemoveGeneratedFilesMessage &message) -{ - debug.nospace() << "RemoveGeneratedFilesMessage(" - << message.generatedFiles << ")"; - - return debug; -} -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/removegeneratedfilesmessage.h b/src/libs/clangsupport/removegeneratedfilesmessage.h deleted file mode 100644 index 6aebaccb27f..00000000000 --- a/src/libs/clangsupport/removegeneratedfilesmessage.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -#include "filepath.h" - -namespace ClangBackEnd { - -class RemoveGeneratedFilesMessage -{ -public: - RemoveGeneratedFilesMessage() = default; - RemoveGeneratedFilesMessage(FilePaths &&generatedFiles) - : generatedFiles(std::move(generatedFiles)) - {} - - FilePaths takeGeneratedFiles() - { - return std::move(generatedFiles); - } - - friend QDataStream &operator<<(QDataStream &out, const RemoveGeneratedFilesMessage &message) - { - out << message.generatedFiles; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, RemoveGeneratedFilesMessage &message) - { - in >> message.generatedFiles; - - return in; - } - - friend bool operator==(const RemoveGeneratedFilesMessage &first, - const RemoveGeneratedFilesMessage &second) - { - return first.generatedFiles == second.generatedFiles; - } - - RemoveGeneratedFilesMessage clone() const - { - return *this; - } - -public: - FilePaths generatedFiles; -}; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const RemoveGeneratedFilesMessage &message); - -DECLARE_MESSAGE(RemoveGeneratedFilesMessage) -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/removeprojectpartsmessage.h b/src/libs/clangsupport/removeprojectpartsmessage.h deleted file mode 100644 index ef80b521785..00000000000 --- a/src/libs/clangsupport/removeprojectpartsmessage.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "projectpartcontainer.h" - -namespace ClangBackEnd { - -class RemoveProjectPartsMessage -{ -public: - RemoveProjectPartsMessage() = default; - RemoveProjectPartsMessage(ProjectPartIds &&projectsPartIds) - : projectsPartIds(std::move(projectsPartIds)) - {} - - ProjectPartIds takeProjectsPartIds() { return std::move(projectsPartIds); } - - friend QDataStream &operator<<(QDataStream &out, const RemoveProjectPartsMessage &message) - { - out << message.projectsPartIds; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, RemoveProjectPartsMessage &message) - { - in >> message.projectsPartIds; - - return in; - } - - friend bool operator==(const RemoveProjectPartsMessage &first, - const RemoveProjectPartsMessage &second) - { - return first.projectsPartIds == second.projectsPartIds; - } - - RemoveProjectPartsMessage clone() const - { - return *this; - } - -public: - ProjectPartIds projectsPartIds; -}; - -DECLARE_MESSAGE(RemoveProjectPartsMessage) - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/requestsourcerangesanddiagnosticsforquerymessage.cpp b/src/libs/clangsupport/requestsourcerangesanddiagnosticsforquerymessage.cpp deleted file mode 100644 index ddad385c376..00000000000 --- a/src/libs/clangsupport/requestsourcerangesanddiagnosticsforquerymessage.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "requestsourcerangesanddiagnosticsforquerymessage.h" - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const RequestSourceRangesAndDiagnosticsForQueryMessage &message) -{ - debug.nospace() << "RequestSourceRangesAndDiagnosticsForQuery(" - << message.query << ", " - << message.source << ")"; - - return debug; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/requestsourcerangesanddiagnosticsforquerymessage.h b/src/libs/clangsupport/requestsourcerangesanddiagnosticsforquerymessage.h deleted file mode 100644 index 7204305e663..00000000000 --- a/src/libs/clangsupport/requestsourcerangesanddiagnosticsforquerymessage.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "filecontainerv2.h" - -namespace ClangBackEnd { - -class RequestSourceRangesAndDiagnosticsForQueryMessage -{ -public: - RequestSourceRangesAndDiagnosticsForQueryMessage() = default; - RequestSourceRangesAndDiagnosticsForQueryMessage(Utils::SmallString &&query, - V2::FileContainer &&source) - : query(std::move(query)), - source(std::move(source)) - - {} - - V2::FileContainer takeSource() - { - return std::move(source); - } - - Utils::SmallString takeQuery() - { - return std::move(query); - } - - friend QDataStream &operator<<(QDataStream &out, const RequestSourceRangesAndDiagnosticsForQueryMessage &message) - { - out << message.query; - out << message.source; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, RequestSourceRangesAndDiagnosticsForQueryMessage &message) - { - in >> message.query; - in >> message.source; - - return in; - } - - friend bool operator==(const RequestSourceRangesAndDiagnosticsForQueryMessage &first, - const RequestSourceRangesAndDiagnosticsForQueryMessage &second) - { - return first.query == second.query - && first.source == second.source; - } - - RequestSourceRangesAndDiagnosticsForQueryMessage clone() const - { - return *this; - } - -public: - Utils::SmallString query; - V2::FileContainer source; -}; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const RequestSourceRangesAndDiagnosticsForQueryMessage &message); - -DECLARE_MESSAGE(RequestSourceRangesAndDiagnosticsForQueryMessage) -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/requestsourcerangesforquerymessage.cpp b/src/libs/clangsupport/requestsourcerangesforquerymessage.cpp deleted file mode 100644 index 0da4ece0c7f..00000000000 --- a/src/libs/clangsupport/requestsourcerangesforquerymessage.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "requestsourcerangesforquerymessage.h" - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const RequestSourceRangesForQueryMessage &message) -{ - debug.nospace() << "RequestSourceRangesForQueryMessage(" - << message.query << ")"; - - return debug; -} - -} // namespace ClangBackEnd - diff --git a/src/libs/clangsupport/requestsourcerangesforquerymessage.h b/src/libs/clangsupport/requestsourcerangesforquerymessage.h deleted file mode 100644 index f68354cc7a0..00000000000 --- a/src/libs/clangsupport/requestsourcerangesforquerymessage.h +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "filecontainerv2.h" - -namespace ClangBackEnd { - -class RequestSourceRangesForQueryMessage -{ -public: - RequestSourceRangesForQueryMessage() = default; - RequestSourceRangesForQueryMessage(Utils::SmallString &&query, - std::vector &&sources, - std::vector &&unsavedContent) - : query(std::move(query)), - sources(std::move(sources)), - unsavedContent(std::move(unsavedContent)) - - {} - - std::vector takeSources() - { - return std::move(sources); - } - - std::vector takeUnsavedContent() - { - return std::move(unsavedContent); - } - - Utils::SmallString takeQuery() - { - return std::move(query); - } - - friend QDataStream &operator<<(QDataStream &out, const RequestSourceRangesForQueryMessage &message) - { - out << message.query; - out << message.sources; - out << message.unsavedContent; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, RequestSourceRangesForQueryMessage &message) - { - in >> message.query; - in >> message.sources; - in >> message.unsavedContent; - - return in; - } - - friend bool operator==(const RequestSourceRangesForQueryMessage &first, - const RequestSourceRangesForQueryMessage &second) - { - return first.query == second.query - && first.sources == second.sources - && first.unsavedContent == second.unsavedContent; - } - - RequestSourceRangesForQueryMessage clone() const - { - return *this; - } - -public: - Utils::SmallString query; - std::vector sources; - std::vector unsavedContent; -}; - - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const RequestSourceRangesForQueryMessage &message); - -DECLARE_MESSAGE(RequestSourceRangesForQueryMessage) -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/sourceentry.h b/src/libs/clangsupport/sourceentry.h deleted file mode 100644 index 4912b367c39..00000000000 --- a/src/libs/clangsupport/sourceentry.h +++ /dev/null @@ -1,169 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -#include - -namespace ClangBackEnd { - -enum class SourceType : unsigned char { - TopProjectInclude, - TopSystemInclude, - UserInclude, - ProjectInclude, - SystemInclude, - Source -}; - -enum class HasMissingIncludes : unsigned char { No, Yes }; - -class TimeStamp -{ - using int64 = long long; -public: - TimeStamp() = default; - TimeStamp(int64 value) - : value(value) - {} - - operator int64() const - { - return value; - } - - int64 value = -1; -}; - -class PrecompiledHeaderTimeStamps -{ -public: - PrecompiledHeaderTimeStamps() = default; - PrecompiledHeaderTimeStamps(long long projectTimeStamp, long long systemTimeStamp) - : project(projectTimeStamp) - , system(systemTimeStamp) - {} - - TimeStamp project; - TimeStamp system; -}; - -class SourceTimeStamp -{ - using int64 = long long; -public: - SourceTimeStamp(int sourceId, int64 lastModified) - : timeStamp(lastModified) - , sourceId(sourceId) - {} - - SourceTimeStamp(FilePathId sourceId, TimeStamp lastModified) - : timeStamp(lastModified) - , sourceId(sourceId) - {} - - friend bool operator<(SourceTimeStamp first, SourceTimeStamp second) - { - return first.sourceId < second.sourceId; - } - - friend bool operator<(SourceTimeStamp first, FilePathId second) - { - return first.sourceId < second; - } - - friend bool operator<(FilePathId first, SourceTimeStamp second) - { - return first < second.sourceId; - } - - friend bool operator==(SourceTimeStamp first, SourceTimeStamp second) - { - return first.sourceId == second.sourceId && first.timeStamp == second.timeStamp; - } - - friend bool operator!=(SourceTimeStamp first, SourceTimeStamp second) - { - return !(first == second); - } - -public: - TimeStamp timeStamp; - FilePathId sourceId; -}; - -using SourceTimeStamps = std::vector; - -class SourceEntry -{ - using int64 = long long; - -public: - SourceEntry(int sourceId, int64 timeStamp, int sourceType, int hasMissingIncludes) - : timeStamp(timeStamp) - , sourceId(sourceId) - , sourceType(static_cast(sourceType)) - , hasMissingIncludes(static_cast(hasMissingIncludes)) - {} - - SourceEntry(FilePathId sourceId, - SourceType sourceType, - TimeStamp timeStamp, - HasMissingIncludes hasMissingIncludes = HasMissingIncludes::No) - : timeStamp(timeStamp) - , sourceId(sourceId) - , sourceType(sourceType) - , hasMissingIncludes(hasMissingIncludes) - {} - - friend bool operator<(SourceEntry first, SourceEntry second) { - return first.sourceId < second.sourceId; - } - - friend bool operator<(SourceEntry first, FilePathId second) { return first.sourceId < second; } - - friend bool operator<(FilePathId first, SourceEntry second) { return first < second.sourceId; } - - friend bool operator==(SourceEntry first, SourceEntry second) - { - return first.sourceId == second.sourceId && first.sourceType == second.sourceType - && first.timeStamp == second.timeStamp; - } - - friend bool operator!=(SourceEntry first, SourceEntry second) { return !(first == second); } - -public: - TimeStamp timeStamp; - FilePathId sourceId; - SourceType sourceType = SourceType::UserInclude; - HasMissingIncludes hasMissingIncludes = HasMissingIncludes::No; -}; - -using SourceEntries = std::vector; -using SourceEntryReference = std::reference_wrapper; -using SourceEntryReferences = std::vector; -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/sourcelocationcontainerv2.cpp b/src/libs/clangsupport/sourcelocationcontainerv2.cpp deleted file mode 100644 index eeb87e7537f..00000000000 --- a/src/libs/clangsupport/sourcelocationcontainerv2.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "sourcelocationcontainerv2.h" - -#include - -namespace ClangBackEnd { -namespace V2 { - -QDebug operator<<(QDebug debug, const SourceLocationContainer &container) -{ - debug.nospace() << "SourceLocationContainer(" - << container.line << ", " - << container.column << ", " - << container.offset << ", " - << container.filePathId.filePathId - << ")"; - return debug; -} - -} // namespace V2 -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/sourcelocationcontainerv2.h b/src/libs/clangsupport/sourcelocationcontainerv2.h deleted file mode 100644 index 36c95377cc3..00000000000 --- a/src/libs/clangsupport/sourcelocationcontainerv2.h +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangsupport_global.h" -#include "filepathid.h" - -#include - -namespace ClangBackEnd { -namespace V2 { - -class SourceLocationContainer -{ -public: - SourceLocationContainer() = default; - SourceLocationContainer(FilePathId filePathId, - uint line, - uint column, - uint offset) - : filePathId(filePathId), - line(line), - column(column), - offset(offset) - { - } - - friend QDataStream &operator<<(QDataStream &out, const SourceLocationContainer &container) - { - out << container.filePathId; - out << container.line; - out << container.column; - out << container.offset; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, SourceLocationContainer &container) - { - in >> container.filePathId; - in >> container.line; - in >> container.column; - in >> container.offset; - - return in; - } - - friend bool operator==(const SourceLocationContainer &first, const SourceLocationContainer &second) - { - return !(first != second); - } - - friend bool operator!=(const SourceLocationContainer &first, const SourceLocationContainer &second) - { - return first.line != second.line - || first.column != second.column - || first.filePathId != second.filePathId; - } - - friend bool operator<(const SourceLocationContainer &first, - const SourceLocationContainer &second) - { - return std::tie(first.filePathId, first.line, first.column) - < std::tie(second.filePathId, second.line, second.column); - } - - SourceLocationContainer clone() const - { - return *this; - } - -public: - FilePathId filePathId; - uint line = 1; - uint column = 1; - uint offset = 0; -}; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const SourceLocationContainer &container); - -} // namespace V2 -} // namespace ClangBackEnd - diff --git a/src/libs/clangsupport/sourcelocationscontainer.cpp b/src/libs/clangsupport/sourcelocationscontainer.cpp index 72f49e896c9..19573ddbd1e 100644 --- a/src/libs/clangsupport/sourcelocationscontainer.cpp +++ b/src/libs/clangsupport/sourcelocationscontainer.cpp @@ -34,7 +34,7 @@ QDebug operator<<(QDebug debug, const SourceLocationsContainer &container) debug.nospace() << "SourceLocationsContainer(["; for (const auto &sourceLocation: container.sourceLocationContainers()) { debug.nospace() << "(" - << sourceLocation.filePathId << "," + << sourceLocation.filePath << "," << sourceLocation.line << "," << sourceLocation.column << "), "; } diff --git a/src/libs/clangsupport/sourcelocationscontainer.h b/src/libs/clangsupport/sourcelocationscontainer.h index 4fc247e0f90..0be15acf900 100644 --- a/src/libs/clangsupport/sourcelocationscontainer.h +++ b/src/libs/clangsupport/sourcelocationscontainer.h @@ -25,21 +25,21 @@ #pragma once -#include "sourcelocationcontainerv2.h" +#include "sourcelocationcontainer.h" #include namespace ClangBackEnd { -class SourceLocationsContainer +class CLANGSUPPORT_EXPORT SourceLocationsContainer { public: SourceLocationsContainer() = default; - SourceLocationsContainer(std::vector &&sourceLocationContainers) + SourceLocationsContainer(std::vector &&sourceLocationContainers) : m_sourceLocationContainers(std::move(sourceLocationContainers)) {} - const std::vector &sourceLocationContainers() const + const std::vector &sourceLocationContainers() const { return m_sourceLocationContainers; } @@ -49,9 +49,9 @@ public: return !m_sourceLocationContainers.empty(); } - void insertSourceLocation(FilePathId filePathId, uint line, uint column, uint offset) + void insertSourceLocation(const Utf8String &filePath, int line, int column) { - m_sourceLocationContainers.emplace_back(filePathId, line, column, offset); + m_sourceLocationContainers.emplace_back(filePath, line, column); } void reserve(std::size_t size) @@ -83,7 +83,7 @@ public: return *this; } - std::vector m_sourceLocationContainers; + std::vector m_sourceLocationContainers; }; CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const SourceLocationsContainer &container); diff --git a/src/libs/clangsupport/sourcerangecontainerv2.cpp b/src/libs/clangsupport/sourcerangecontainerv2.cpp deleted file mode 100644 index 54bdbb5ea34..00000000000 --- a/src/libs/clangsupport/sourcerangecontainerv2.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "sourcerangecontainerv2.h" - -#include - -namespace ClangBackEnd { -namespace V2 { - -QDebug operator<<(QDebug debug, const SourceRangeContainer &container) -{ - debug.nospace() << "SourceRangeContainer(" - << container.start << ", " - << container.end - << ")"; - - return debug; -} - -} // namespace V2 -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/sourcerangecontainerv2.h b/src/libs/clangsupport/sourcerangecontainerv2.h deleted file mode 100644 index 7f0127a4de1..00000000000 --- a/src/libs/clangsupport/sourcerangecontainerv2.h +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "sourcelocationcontainerv2.h" - -#include - -namespace ClangBackEnd { -namespace V2 { - -class SourceRangeContainer -{ -public: - SourceRangeContainer() = default; - SourceRangeContainer(SourceLocationContainer start, - SourceLocationContainer end) - : start(start), - end(end) - { - } - - SourceRangeContainer(FilePathId filePathId, - uint startLine, - uint startColumn, - uint startOffset, - uint endLine, - uint endColumn, - uint endOffset) - : start(filePathId, startLine, startColumn, startOffset), - end(filePathId, endLine, endColumn, endOffset) - { - } - - FilePathId filePathId() const - { - return start.filePathId; - } - - friend QDataStream &operator<<(QDataStream &out, const SourceRangeContainer &container) - { - out << container.start; - out << container.end; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, SourceRangeContainer &container) - { - in >> container.start; - in >> container.end; - - return in; - } - - friend bool operator==(const SourceRangeContainer &first, const SourceRangeContainer &second) - { - return first.start == second.start && first.end == second.end; - } - - friend bool operator<(const SourceRangeContainer &first, - const SourceRangeContainer &second) - { - return std::tie(first.start, first.end) < std::tie(second.start, second.end); - } - - SourceRangeContainer clone() const - { - return *this; - } - -public: - SourceLocationContainer start; - SourceLocationContainer end; -}; - -using SourceRangeContainers = std::vector; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const SourceRangeContainer &container); -} // namespace V2 -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/sourcerangesanddiagnosticsforquerymessage.cpp b/src/libs/clangsupport/sourcerangesanddiagnosticsforquerymessage.cpp deleted file mode 100644 index cc61fde9dd9..00000000000 --- a/src/libs/clangsupport/sourcerangesanddiagnosticsforquerymessage.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "sourcerangesanddiagnosticsforquerymessage.h" - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const SourceRangesAndDiagnosticsForQueryMessage &message) -{ - debug.nospace() << "SourceRangesAndDiagnosticsForQueryMessage(" - << message.sourceRanges << ", " - << message.diagnostics << ")"; - - return debug; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/sourcerangesanddiagnosticsforquerymessage.h b/src/libs/clangsupport/sourcerangesanddiagnosticsforquerymessage.h deleted file mode 100644 index e43ec308114..00000000000 --- a/src/libs/clangsupport/sourcerangesanddiagnosticsforquerymessage.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "sourcerangescontainer.h" -#include "dynamicastmatcherdiagnosticcontainer.h" - -#include - -namespace ClangBackEnd { - -class SourceRangesAndDiagnosticsForQueryMessage -{ -public: - SourceRangesAndDiagnosticsForQueryMessage() = default; - SourceRangesAndDiagnosticsForQueryMessage(SourceRangesContainer &&sourceRangesContainer, - std::vector &&diagnosticContainers) - : sourceRanges(std::move(sourceRangesContainer)), - diagnostics(std::move(diagnosticContainers)) - {} - - SourceRangesContainer takeSourceRanges() - { - return std::move(sourceRanges); - } - - friend QDataStream &operator<<(QDataStream &out, const SourceRangesAndDiagnosticsForQueryMessage &message) - { - out << message.sourceRanges; - out << message.diagnostics; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, SourceRangesAndDiagnosticsForQueryMessage &message) - { - in >> message.sourceRanges; - in >> message.diagnostics; - - return in; - } - - friend bool operator==(const SourceRangesAndDiagnosticsForQueryMessage &first, const SourceRangesAndDiagnosticsForQueryMessage &second) - { - return first.sourceRanges == second.sourceRanges - && first.diagnostics == second.diagnostics; - } - - SourceRangesAndDiagnosticsForQueryMessage clone() const - { - return SourceRangesAndDiagnosticsForQueryMessage(sourceRanges.clone(), - Utils::clone(diagnostics)); - } - -public: - SourceRangesContainer sourceRanges; - DynamicASTMatcherDiagnosticContainers diagnostics; -}; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const SourceRangesAndDiagnosticsForQueryMessage &message); - -DECLARE_MESSAGE(SourceRangesAndDiagnosticsForQueryMessage) - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/sourcerangescontainer.cpp b/src/libs/clangsupport/sourcerangescontainer.cpp deleted file mode 100644 index bba6a626211..00000000000 --- a/src/libs/clangsupport/sourcerangescontainer.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "sourcerangescontainer.h" - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const SourceRangesContainer &container) -{ - debug.nospace() << "SourceRangesContainer(["; - for (const auto &sourceRangeWithText: container.sourceRangeWithTextContainers) { - debug.nospace() << "(" - << sourceRangeWithText.start.line << "," - << sourceRangeWithText.start.column << "), (" - << sourceRangeWithText.end.line << "," - << sourceRangeWithText.end.column << "), "; - } - - debug.nospace() << "])"; - - return debug; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/sourcerangescontainer.h b/src/libs/clangsupport/sourcerangescontainer.h deleted file mode 100644 index f0bac034857..00000000000 --- a/src/libs/clangsupport/sourcerangescontainer.h +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "sourcerangewithtextcontainer.h" - -#include - -namespace ClangBackEnd { - -class SourceRangesContainer -{ -public: - SourceRangesContainer() = default; - SourceRangesContainer(SourceRangeWithTextContainers &&sourceRangeWithTextContainers) - : sourceRangeWithTextContainers(std::move(sourceRangeWithTextContainers)) - {} - - SourceRangeWithTextContainers takeSourceRangeWithTextContainers() - { - return std::move(sourceRangeWithTextContainers); - } - - bool hasContent() const - { - return !sourceRangeWithTextContainers.empty(); - } - - void insertSourceRange(FilePathId filePathId, - uint startLine, - uint startColumn, - uint startOffset, - uint endLine, - uint endColumn, - uint endOffset, - Utils::SmallString &&text) - { - sourceRangeWithTextContainers.emplace_back(filePathId, - startLine, - startColumn, - startOffset, - endLine, - endColumn, - endOffset, - std::move(text)); - } - - void reserve(std::size_t size) - { - sourceRangeWithTextContainers.reserve(size); - } - - friend QDataStream &operator<<(QDataStream &out, const SourceRangesContainer &container) - { - out << container.sourceRangeWithTextContainers; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, SourceRangesContainer &container) - { - in >> container.sourceRangeWithTextContainers; - - return in; - } - - friend bool operator==(const SourceRangesContainer &first, const SourceRangesContainer &second) - { - return first.sourceRangeWithTextContainers == second.sourceRangeWithTextContainers; - } - - SourceRangesContainer clone() const - { - return *this; - } - -public: - SourceRangeWithTextContainers sourceRangeWithTextContainers; -}; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const SourceRangesContainer &container); - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/sourcerangesforquerymessage.cpp b/src/libs/clangsupport/sourcerangesforquerymessage.cpp deleted file mode 100644 index 6de24ac5219..00000000000 --- a/src/libs/clangsupport/sourcerangesforquerymessage.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "sourcerangesforquerymessage.h" - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const SourceRangesForQueryMessage &message) -{ - debug.nospace() << "SourceRangesForQueryMessage(" - << message.sourceRanges << ")"; - - return debug; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/sourcerangesforquerymessage.h b/src/libs/clangsupport/sourcerangesforquerymessage.h deleted file mode 100644 index a3989a13fc3..00000000000 --- a/src/libs/clangsupport/sourcerangesforquerymessage.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "sourcerangescontainer.h" -#include "dynamicastmatcherdiagnosticcontainer.h" - -#include - -namespace ClangBackEnd { - -class SourceRangesForQueryMessage -{ -public: - SourceRangesForQueryMessage() = default; - SourceRangesForQueryMessage(SourceRangesContainer &&sourceRanges) - : sourceRanges(std::move(sourceRanges)) - {} - - friend QDataStream &operator<<(QDataStream &out, const SourceRangesForQueryMessage &message) - { - out << message.sourceRanges; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, SourceRangesForQueryMessage &message) - { - in >> message.sourceRanges; - - return in; - } - - friend bool operator==(const SourceRangesForQueryMessage &first, const SourceRangesForQueryMessage &second) - { - return first.sourceRanges == second.sourceRanges; - } - - SourceRangesForQueryMessage clone() const - { - return *this; - } - -public: - SourceRangesContainer sourceRanges; -}; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const SourceRangesForQueryMessage &message); - -DECLARE_MESSAGE(SourceRangesForQueryMessage) -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/sourcerangewithtextcontainer.cpp b/src/libs/clangsupport/sourcerangewithtextcontainer.cpp deleted file mode 100644 index 0a7a167f745..00000000000 --- a/src/libs/clangsupport/sourcerangewithtextcontainer.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "sourcerangewithtextcontainer.h" - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const SourceRangeWithTextContainer &container) -{ - debug.nospace() << "SourceRangeWithTextContainer(" - << container.start << ", " - << container.end << ", " - << container.text - << ")"; - - return debug; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/sourcerangewithtextcontainer.h b/src/libs/clangsupport/sourcerangewithtextcontainer.h deleted file mode 100644 index fd99797b646..00000000000 --- a/src/libs/clangsupport/sourcerangewithtextcontainer.h +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include - -#include - -namespace ClangBackEnd { - -class SourceRangeWithTextContainer : public V2::SourceRangeContainer -{ -public: - SourceRangeWithTextContainer() = default; - SourceRangeWithTextContainer(FilePathId filePathId, - uint startLine, - uint startColumn, - uint startOffset, - uint endLine, - uint endColumn, - uint endOffset, - Utils::SmallString &&text) - : V2::SourceRangeContainer(filePathId, - startLine, - startColumn, - startOffset, - endLine, - endColumn, - endOffset), - text(std::move(text)) - {} - - SourceRangeWithTextContainer(V2::SourceRangeContainer &&base, - Utils::SmallString &&text) - : V2::SourceRangeContainer(std::move(base)), - text(std::move(text)) - { - } - - using V2::SourceRangeContainer::start; - using V2::SourceRangeContainer::end; - using V2::SourceRangeContainer::filePathId; - - friend QDataStream &operator<<(QDataStream &out, const SourceRangeWithTextContainer &container) - { - out << container.base(); - out << container.text; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, SourceRangeWithTextContainer &container) - { - in >> container.base(); - in >> container.text; - - return in; - } - - friend bool operator==(const SourceRangeWithTextContainer &first, - const SourceRangeWithTextContainer &second) - { - return first.base() == second.base() && first.text == second.text; - } - - V2::SourceRangeContainer &base() - { - return *this; - } - - const V2::SourceRangeContainer &base() const - { - return *this; - } - - SourceRangeWithTextContainer clone() const - { - return *this; - } - -public: - Utils::SmallString text; -}; - -using SourceRangeWithTextContainers = std::vector; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const SourceRangeWithTextContainer &container); -} // namespace ClangBackEnd - diff --git a/src/libs/clangsupport/stringcache.h b/src/libs/clangsupport/stringcache.h deleted file mode 100644 index 87b92b4084a..00000000000 --- a/src/libs/clangsupport/stringcache.h +++ /dev/null @@ -1,426 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "stringcachealgorithms.h" -#include "stringcacheentry.h" -#include "stringcachefwd.h" - -#include -#include -#include -#include - -#include - -#include -#include -#include - -namespace ClangBackEnd { - -class StringCacheException : public std::exception -{ - const char *what() const noexcept override - { - return "StringCache entries are in invalid state."; - } -}; - -class NonLockingMutex -{ -public: - constexpr NonLockingMutex() noexcept {} - NonLockingMutex(const NonLockingMutex&) = delete; - NonLockingMutex& operator=(const NonLockingMutex&) = delete; - void lock() {} - void unlock() {} - void lock_shared() {} - void unlock_shared() {} -}; - -class SharedMutex -{ -public: - SharedMutex() = default; - - SharedMutex(const SharedMutex&) = delete; - SharedMutex& operator=(const SharedMutex&) = delete; - - void lock() - { - m_mutex.lockForWrite(); - } - - void unlock() - { - m_mutex.unlock(); - } - - void lock_shared() - { - m_mutex.lockForRead(); - } - - void unlock_shared() - { - m_mutex.unlock(); - } -private: - QReadWriteLock m_mutex; -}; - -template> -class StringCache -{ - template - friend class StringCache; - - using StringResultType = std:: - conditional_t::value, StringViewType, StringType>; - -public: - using MutexType = Mutex; - using CacheEntries = std::vector; - using const_iterator = typename CacheEntries::const_iterator; - using Found = ClangBackEnd::Found; - - StringCache(std::size_t reserveSize = 1024) - { - m_strings.reserve(reserveSize); - m_indices.reserve(reserveSize); - } - - StringCache(const StringCache &other) - : m_strings(other.m_strings) - , m_indices(other.m_indices) - {} - - template - Cache clone() - { - Cache cache; - cache.m_strings = m_strings; - cache.m_indices = m_indices; - - return cache; - } - - StringCache(StringCache &&other) - : m_strings(std::move(other.m_strings)) - , m_indices(std::move(other.m_indices)) - {} - - StringCache &operator=(StringCache &&other) - { - m_strings = std::move(other.m_strings); - m_indices = std::move(other.m_indices); - - return *this; - } - - void populate(CacheEntries &&entries) - { - uncheckedPopulate(std::move(entries)); - - checkEntries(); - } - - void uncheckedPopulate(CacheEntries &&entries) - { - std::sort(entries.begin(), entries.end(), [](StringViewType first, StringViewType second) { - return compare(first, second) < 0; - }); - - m_strings = std::move(entries); - - int max_id = 0; - - auto found = std::max_element(m_strings.begin(), - m_strings.end(), - [](const auto &first, const auto &second) { - return first.id < second.id; - }); - - if (found != m_strings.end()) - max_id = found->id + 1; - - m_indices.resize(max_id, -1); - - updateIndices(); - } - - template - void addStrings(std::vector &&strings, Function storageFunction) - { - auto less = [](StringViewType first, StringViewType second) { - return compare(first, second) < 0; - }; - - std::sort(strings.begin(), strings.end(), less); - - strings.erase(std::unique(strings.begin(), strings.end()), strings.end()); - - CacheEntries newCacheEntries; - newCacheEntries.reserve(strings.size()); - - std::set_difference(strings.begin(), - strings.end(), - m_strings.begin(), - m_strings.end(), - Utils::make_iterator([&](StringViewType newString) { - IndexType index = storageFunction(newString); - newCacheEntries.emplace_back(newString, index); - }), - less); - - if (newCacheEntries.size()) { - auto found = std::max_element(newCacheEntries.begin(), - newCacheEntries.end(), - [](const auto &first, const auto &second) { - return first.id < second.id; - }); - - int max_id = found->id + 1; - - if (max_id > int(m_indices.size())) - m_indices.resize(max_id, -1); - - CacheEntries mergedCacheEntries; - mergedCacheEntries.reserve(newCacheEntries.size() + m_strings.size()); - - std::merge(std::make_move_iterator(m_strings.begin()), - std::make_move_iterator(m_strings.end()), - std::make_move_iterator(newCacheEntries.begin()), - std::make_move_iterator(newCacheEntries.end()), - std::back_inserter(mergedCacheEntries), - less); - - m_strings = std::move(mergedCacheEntries); - - updateIndices(); - } - } - - IndexType stringId(StringViewType stringView) - { - std::shared_lock sharedLock(m_mutex); - Found found = find(stringView); - - if (found.wasFound) - return found.iterator->id; - - sharedLock.unlock(); - std::lock_guard exclusiveLock(m_mutex); - - if (!std::is_base_of::value) - found = find(stringView); - if (!found.wasFound) { - IndexType index = insertString(found.iterator, stringView, IndexType(m_indices.size())); - found.iterator = m_strings.begin() + index; - } - - return found.iterator->id; - } - - template - std::vector stringIds(const Container &strings) - { - std::vector ids; - ids.reserve(strings.size()); - - std::transform(strings.begin(), - strings.end(), - std::back_inserter(ids), - [&] (const auto &string) { return this->stringId(string); }); - - return ids; - } - - template - std::vector stringIds(const Container &strings, Function storageFunction) - { - std::vector ids; - ids.reserve(strings.size()); - - std::transform(strings.begin(), - strings.end(), - std::back_inserter(ids), - [&](const auto &string) { return this->stringId(string, storageFunction); }); - - return ids; - } - - std::vector stringIds(std::initializer_list strings) - { - return stringIds>(strings); - } - - template - std::vector stringIds(std::initializer_list strings, - Function storageFunction) - { - return stringIds>(strings, storageFunction); - } - - StringResultType string(IndexType id) const - { - std::shared_lock sharedLock(m_mutex); - - return m_strings.at(m_indices.at(id)).string; - } - - template - StringResultType string(IndexType id, Function storageFunction) - { - std::shared_lock sharedLock(m_mutex); - - if (IndexType(m_indices.size()) > id && m_indices.at(id) >= 0) - return m_strings.at(m_indices.at(id)).string; - - - sharedLock.unlock(); - std::lock_guard exclusiveLock(m_mutex); - IndexType index; - - StringType string{storageFunction(id)}; - index = insertString(find(string).iterator, string, id); - - return m_strings[index].string; - } - - std::vector strings(const std::vector &ids) const - { - std::shared_lock sharedLock(m_mutex); - - std::vector strings; - strings.reserve(ids.size()); - - for (IndexType id : ids) - strings.emplace_back(m_strings.at(m_indices.at(id)).string); - - return strings; - } - - bool isEmpty() const - { - return m_strings.empty() && m_indices.empty(); - } - - template - IndexType stringId(StringViewType stringView, Function storageFunction) - { - std::shared_lock sharedLock(m_mutex); - - Found found = find(stringView); - - if (found.wasFound) - return found.iterator->id; - - sharedLock.unlock(); - std::lock_guard exclusiveLock(m_mutex); - - if (!std::is_base_of::value) - found = find(stringView); - if (!found.wasFound) { - IndexType index = insertString(found.iterator, stringView, storageFunction(stringView)); - found.iterator = m_strings.begin() + index; - } - - return found.iterator->id; - } - - Mutex &mutex() const - { - return m_mutex; - } - -private: - void updateIndices() - { - auto begin = m_strings.cbegin(); - for (auto current = begin; current != m_strings.cend(); ++current) - m_indices[current->id] = std::distance(begin, current); - } - - Found find(StringViewType stringView) - { - return findInSorted(m_strings.cbegin(), m_strings.cend(), stringView, compare); - } - - void incrementLargerOrEqualIndicesByOne(IndexType newIndex) - { - std::transform(m_indices.begin(), - m_indices.end(), - m_indices.begin(), - [&] (IndexType index) { - return index >= newIndex ? ++index : index; - }); - } - - void ensureSize(IndexType id) - { - if (m_indices.size() <= std::size_t(id)) - m_indices.resize(id + 1, -1); - } - - IndexType insertString(const_iterator beforeIterator, - StringViewType stringView, - IndexType id) - { - auto inserted = m_strings.emplace(beforeIterator, stringView, id); - - auto newIndex = IndexType(std::distance(m_strings.begin(), inserted)); - - incrementLargerOrEqualIndicesByOne(newIndex); - - ensureSize(id); - m_indices.at(id) = newIndex; - - return newIndex; - } - - void checkEntries() - { - for (const auto &entry : m_strings) { - if (entry.string != string(entry.id) || entry.id != stringId(entry.string)) - throw StringCacheException(); - } - } - -private: - CacheEntries m_strings; - std::vector m_indices; - mutable Mutex m_mutex; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/stringcachealgorithms.h b/src/libs/clangsupport/stringcachealgorithms.h deleted file mode 100644 index 573a692b727..00000000000 --- a/src/libs/clangsupport/stringcachealgorithms.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -#include - -#include - -namespace ClangBackEnd { - -template -class Found -{ -public: - Iterator iterator; - bool wasFound; -}; - -template -Found findInSorted(ForwardIterator first, ForwardIterator last, const Type& value, Compare compare) -{ - ForwardIterator current; - using DifferenceType = typename std::iterator_traits::difference_type; - DifferenceType count{std::distance(first, last)}; - DifferenceType step; - - while (count > 0) { - current = first; - step = count / 2; - std::advance(current, step); - auto comparison = compare(*current, value); - if (comparison < 0) { - first = ++current; - count -= step + 1; - } else if (comparison > 0) { - count = step; - } else { - return {current, true}; - } - } - - return {first, false}; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/stringcacheentry.h b/src/libs/clangsupport/stringcacheentry.h deleted file mode 100644 index bbffcdc8733..00000000000 --- a/src/libs/clangsupport/stringcacheentry.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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 ClangBackEnd { - -template -class StringCacheEntry -{ -public: - StringCacheEntry(StringViewType string, IndexType id) - : string(string) - , id(id) - {} - - operator StringViewType() const { return string; } - friend bool operator==(const StringCacheEntry &first, const StringCacheEntry &second) - { - return first.id == second.id && first.string == second.string; - } - -public: - StringType string; - IndexType id; -}; - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/stringcachefwd.h b/src/libs/clangsupport/stringcachefwd.h deleted file mode 100644 index 2059b503b62..00000000000 --- a/src/libs/clangsupport/stringcachefwd.h +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -namespace ClangBackEnd { - -class NonLockingMutex; - -template -class StringCache; -} // namespace ClangBackEnd - diff --git a/src/libs/clangsupport/updategeneratedfilesmessage.cpp b/src/libs/clangsupport/updategeneratedfilesmessage.cpp deleted file mode 100644 index 9ef71a0df59..00000000000 --- a/src/libs/clangsupport/updategeneratedfilesmessage.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "updategeneratedfilesmessage.h" - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const UpdateGeneratedFilesMessage &message) -{ - debug.nospace() << "UpdateGeneratedFilesMessage(" - << message.generatedFiles << ")"; - - return debug; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/updategeneratedfilesmessage.h b/src/libs/clangsupport/updategeneratedfilesmessage.h deleted file mode 100644 index fabfda01259..00000000000 --- a/src/libs/clangsupport/updategeneratedfilesmessage.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "filecontainerv2.h" - -namespace ClangBackEnd { - -class UpdateGeneratedFilesMessage -{ -public: - UpdateGeneratedFilesMessage() = default; - UpdateGeneratedFilesMessage(V2::FileContainers &&generatedFiles) - : generatedFiles(std::move(generatedFiles)) - {} - - V2::FileContainers takeGeneratedFiles() - { - return std::move(generatedFiles); - } - - friend QDataStream &operator<<(QDataStream &out, const UpdateGeneratedFilesMessage &message) - { - out << message.generatedFiles; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, UpdateGeneratedFilesMessage &message) - { - in >> message.generatedFiles; - - return in; - } - - friend bool operator==(const UpdateGeneratedFilesMessage &first, - const UpdateGeneratedFilesMessage &second) - { - return first.generatedFiles == second.generatedFiles; - } - - UpdateGeneratedFilesMessage clone() const - { - return *this; - } - -public: - V2::FileContainers generatedFiles; -}; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const UpdateGeneratedFilesMessage &message); - -DECLARE_MESSAGE(UpdateGeneratedFilesMessage) -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/updateprojectpartsmessage.cpp b/src/libs/clangsupport/updateprojectpartsmessage.cpp deleted file mode 100644 index 76e56405bc7..00000000000 --- a/src/libs/clangsupport/updateprojectpartsmessage.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "updateprojectpartsmessage.h" - -namespace ClangBackEnd { - -QDebug operator<<(QDebug debug, const UpdateProjectPartsMessage &message) -{ - debug.nospace() << "UpdateProjectPartsMessage(" - << message.projectsParts << ")"; - - return debug; -} - -} // namespace ClangBackEnd diff --git a/src/libs/clangsupport/updateprojectpartsmessage.h b/src/libs/clangsupport/updateprojectpartsmessage.h deleted file mode 100644 index b1c6ca1f611..00000000000 --- a/src/libs/clangsupport/updateprojectpartsmessage.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "filecontainerv2.h" -#include "projectpartcontainer.h" - -namespace ClangBackEnd { - -class UpdateProjectPartsMessage -{ -public: - UpdateProjectPartsMessage() = default; - UpdateProjectPartsMessage(ProjectPartContainers &&projectsParts, - Utils::SmallStringVector &&toolChainArguments) - : projectsParts(std::move(projectsParts)) - , toolChainArguments(toolChainArguments) - {} - - ProjectPartContainers takeProjectsParts() - { - return std::move(projectsParts); - } - - friend QDataStream &operator<<(QDataStream &out, const UpdateProjectPartsMessage &message) - { - out << message.projectsParts; - out << message.toolChainArguments; - - return out; - } - - friend QDataStream &operator>>(QDataStream &in, UpdateProjectPartsMessage &message) - { - in >> message.projectsParts; - in >> message.toolChainArguments; - - return in; - } - - friend bool operator==(const UpdateProjectPartsMessage &first, - const UpdateProjectPartsMessage &second) - { - return first.projectsParts == second.projectsParts - && first.toolChainArguments == second.toolChainArguments; - } - - UpdateProjectPartsMessage clone() const - { - return *this; - } - -public: - ProjectPartContainers projectsParts; - Utils::SmallStringVector toolChainArguments; -}; - -CLANGSUPPORT_EXPORT QDebug operator<<(QDebug debug, const UpdateProjectPartsMessage &message); - -DECLARE_MESSAGE(UpdateProjectPartsMessage) - -} // namespace ClangBackEnd diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index ba8fa0a3e11..4b6e3c43f5b 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -29,7 +29,6 @@ add_subdirectory(nim) add_subdirectory(conan) # Level 4: (only depends on Level 3 and below) -add_subdirectory(clangpchmanager) add_subdirectory(classview) add_subdirectory(cppeditor) add_subdirectory(glsleditor) @@ -42,7 +41,6 @@ add_subdirectory(vcsbase) add_subdirectory(bazaar) add_subdirectory(beautifier) add_subdirectory(clangformat) -add_subdirectory(clangrefactoring) add_subdirectory(clearcase) add_subdirectory(cvs) add_subdirectory(designer) diff --git a/src/plugins/clangcodemodel/clangrefactoringengine.cpp b/src/plugins/clangcodemodel/clangrefactoringengine.cpp index 926f696a827..779a26fbb32 100644 --- a/src/plugins/clangcodemodel/clangrefactoringengine.cpp +++ b/src/plugins/clangcodemodel/clangrefactoringengine.cpp @@ -28,6 +28,7 @@ #include "clangdclient.h" #include "clangmodelmanagersupport.h" +#include "sourcelocationscontainer.h" #include #include @@ -74,10 +75,9 @@ void RefactoringEngine::startLocalRenaming(const CppTools::CursorInEditor &data, const QString symbolName = cursor.selectedText(); ClangBackEnd::SourceLocationsContainer container; for (auto& use : info.useRanges) { - container.insertSourceLocation(ClangBackEnd::FilePathId(), + container.insertSourceLocation({}, use.line, - use.column, - use.length); + use.column); } renameSymbolsCallback(symbolName, container, data.cursor().document()->revision()); }); diff --git a/src/plugins/clangpchmanager/CMakeLists.txt b/src/plugins/clangpchmanager/CMakeLists.txt deleted file mode 100644 index bc637b5640a..00000000000 --- a/src/plugins/clangpchmanager/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -add_qtc_plugin(ClangPchManager - BUILD_DEFAULT OFF - CONDITION TARGET libclang AND QTC_CLANG_BUILDMODE_MATCH - DEPENDS ClangSupport CPlusPlus - DEFINES CLANGPCHMANAGER_LIB - PLUGIN_DEPENDS Core CppTools - SOURCES - clangindexingprojectsettings.cpp clangindexingprojectsettings.h - clangindexingprojectsettingswidget.cpp clangindexingprojectsettingswidget.h clangindexingprojectsettingswidget.ui - clangindexingsettingsmanager.cpp clangindexingsettingsmanager.h - clangpchmanager_global.h - clangpchmanagerplugin.cpp clangpchmanagerplugin.h - pchmanagerclient.cpp pchmanagerclient.h - pchmanagerconnectionclient.cpp pchmanagerconnectionclient.h - pchmanagernotifierinterface.cpp pchmanagernotifierinterface.h - pchmanagerprojectupdater.cpp pchmanagerprojectupdater.h - preprocessormacrocollector.cpp preprocessormacrocollector.h - preprocessormacrowidget.cpp preprocessormacrowidget.h - progressmanager.h - progressmanagerinterface.h - projectupdater.cpp projectupdater.h - qtcreatorprojectupdater.cpp qtcreatorprojectupdater.h -) diff --git a/src/plugins/clangpchmanager/ClangPchManager.json.in b/src/plugins/clangpchmanager/ClangPchManager.json.in deleted file mode 100644 index 72b6ef56b4f..00000000000 --- a/src/plugins/clangpchmanager/ClangPchManager.json.in +++ /dev/null @@ -1,20 +0,0 @@ -{ - \"Name\" : \"ClangPchManager\", - \"Version\" : \"$$QTCREATOR_VERSION\", - \"CompatVersion\" : \"$$QTCREATOR_COMPAT_VERSION\", - \"Experimental\" : true, - \"Vendor\" : \"The Qt Company Ltd\", - \"Copyright\" : \"(C) $$QTCREATOR_COPYRIGHT_YEAR The Qt Company Ltd\", - \"License\" : [ \"Commercial Usage\", - \"\", - \"Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt 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.\", - \"\", - \"GNU General Public License Usage\", - \"\", - \"Alternatively, this plugin 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 plugin. 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.\" - ], - \"Category\" : \"C++\", - \"Description\" : \"Clang precompiled header plugin.\", - \"Url\" : \"http://www.qt.io\", - $$dependencyList -} diff --git a/src/plugins/clangpchmanager/clangindexingprojectsettings.cpp b/src/plugins/clangpchmanager/clangindexingprojectsettings.cpp deleted file mode 100644 index 722c7767bef..00000000000 --- a/src/plugins/clangpchmanager/clangindexingprojectsettings.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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. -** -****************************************************************************/ - -#include "clangindexingprojectsettings.h" - -#include - -namespace ClangPchManager { - -namespace { -Utils::NameValueItems fromQVariantMap(const QVariantMap &variantMap, - Utils::NameValueItem::Operation operation) -{ - Utils::NameValueItems nameValueItems; - nameValueItems.reserve(variantMap.size()); - - auto end = variantMap.end(); - - for (auto iterator = variantMap.cbegin(); iterator != end; ++iterator) // QMap iterators are broken - nameValueItems.push_back({iterator.key(), iterator.value().toString(), operation}); - - return nameValueItems; -} - -} // namespace - -ClangIndexingProjectSettings::ClangIndexingProjectSettings(ProjectExplorer::Project *project) - : m_project(project) -{} - -void ClangIndexingProjectSettings::saveMacros(const Utils::NameValueItems &items) -{ - QVariantMap unsets; - QVariantMap sets; - - for (const Utils::NameValueItem &item : items) { - using Operation = Utils::NameValueItem::Operation; - switch (item.operation) { - case Operation::SetEnabled: - sets[item.name] = item.value; - break; - case Operation::Unset: - unsets[item.name] = item.value; - break; - default: - break; - } - } - - if (sets.size()) - m_project->setNamedSettings("set_indexing_macro", sets); - else - m_project->setNamedSettings("set_indexing_macro", {}); - - if (unsets.size()) - m_project->setNamedSettings("unset_indexing_macro", unsets); - else - m_project->setNamedSettings("unset_indexing_macro", {}); -} - -Utils::NameValueItems ClangIndexingProjectSettings::readMacros() const -{ - QVariant unsets = m_project->namedSettings("unset_indexing_macro"); - - Utils::NameValueItems items = fromQVariantMap(unsets.toMap(), Utils::NameValueItem::Unset); - - QVariant sets = m_project->namedSettings("set_indexing_macro"); - - items += fromQVariantMap(sets.toMap(), Utils::NameValueItem::SetEnabled); - - return items; -} - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/clangindexingprojectsettings.h b/src/plugins/clangpchmanager/clangindexingprojectsettings.h deleted file mode 100644 index 7571034a289..00000000000 --- a/src/plugins/clangpchmanager/clangindexingprojectsettings.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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 - -#include "clangpchmanager_global.h" - -#include - -namespace ProjectExplorer { -class Project; -} - -namespace ClangPchManager { - -class CLANGPCHMANAGER_EXPORT ClangIndexingProjectSettings -{ -public: - ClangIndexingProjectSettings(ProjectExplorer::Project *project); - - Utils::NameValueItems readMacros() const; - void saveMacros(const Utils::NameValueItems &items); - -private: - ProjectExplorer::Project *m_project; -}; - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/clangindexingprojectsettingswidget.cpp b/src/plugins/clangpchmanager/clangindexingprojectsettingswidget.cpp deleted file mode 100644 index fc791fe6522..00000000000 --- a/src/plugins/clangpchmanager/clangindexingprojectsettingswidget.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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. -** -****************************************************************************/ - -#include "clangindexingprojectsettingswidget.h" -#include "ui_clangindexingprojectsettingswidget.h" - -#include -#include - -#include "pchmanagerprojectupdater.h" -#include "preprocessormacrocollector.h" -#include "preprocessormacrowidget.h" -#include "qtcreatorprojectupdater.h" - -namespace ClangPchManager { -ClangIndexingProjectSettingsWidget::ClangIndexingProjectSettingsWidget( - ClangIndexingProjectSettings *settings, - ProjectExplorer::Project *project, - QtCreatorProjectUpdater &projectUpdater) - : ui(new Ui::ClangIndexingProjectSettingsWidget) - , m_project(project) - , m_projectUpdater(projectUpdater) -{ - ui->setupUi(this); - ui->preprocessorMacrosWidget->setSettings(settings); - connect(ui->reindexButton, &QPushButton::clicked, this, &ClangIndexingProjectSettingsWidget::reindex); -} - -ClangIndexingProjectSettingsWidget::~ClangIndexingProjectSettingsWidget() -{ - delete ui; -} - -void ClangIndexingProjectSettingsWidget::onProjectPartsUpdated(ProjectExplorer::Project *project) -{ - const CppTools::ProjectInfo projectInfo = CppTools::CppModelManager::instance()->projectInfo( - project); - - PreprocessorMacroCollector collector; - - for (auto projectPart : projectInfo.projectParts()) - collector.add(projectPart->projectMacros); - - ui->preprocessorMacrosWidget->setBasePreprocessorMacros(collector.macros()); -} - -void ClangIndexingProjectSettingsWidget::reindex() -{ - m_projectUpdater.projectPartsUpdated(m_project); -} - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/clangindexingprojectsettingswidget.h b/src/plugins/clangpchmanager/clangindexingprojectsettingswidget.h deleted file mode 100644 index 846e8bde23f..00000000000 --- a/src/plugins/clangpchmanager/clangindexingprojectsettingswidget.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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 - -#include - -namespace ProjectExplorer { class Project; } - -QT_BEGIN_NAMESPACE -namespace Ui { class ClangIndexingProjectSettingsWidget; } -QT_END_NAMESPACE - -namespace ClangPchManager { - -template -class QtCreatorProjectUpdater; -class PchManagerProjectUpdater; - -class ClangIndexingProjectSettings; - -class ClangIndexingProjectSettingsWidget : public QWidget -{ - Q_OBJECT - -public: - explicit ClangIndexingProjectSettingsWidget( - ClangIndexingProjectSettings *settings, - ProjectExplorer::Project *project, - QtCreatorProjectUpdater &projectUpdater); - ~ClangIndexingProjectSettingsWidget(); - - void onProjectPartsUpdated(ProjectExplorer::Project *project); - void reindex(); - -private: - Ui::ClangIndexingProjectSettingsWidget *ui; - ProjectExplorer::Project *m_project; - QtCreatorProjectUpdater &m_projectUpdater; -}; - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/clangindexingprojectsettingswidget.ui b/src/plugins/clangpchmanager/clangindexingprojectsettingswidget.ui deleted file mode 100644 index 404d207d5ae..00000000000 --- a/src/plugins/clangpchmanager/clangindexingprojectsettingswidget.ui +++ /dev/null @@ -1,72 +0,0 @@ - - - ClangIndexingProjectSettingsWidget - - - - 0 - 0 - 400 - 300 - - - - - - - QLayout::SetDefaultConstraint - - - - - - 0 - 0 - - - - Reindex - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 40 - 20 - - - - - - - - - - - 0 - 0 - - - - - - - - - ClangPchManager::PreprocessorMacroWidget - QWidget -
preprocessormacrowidget.h
- 1 -
-
- - -
diff --git a/src/plugins/clangpchmanager/clangindexingsettingsmanager.cpp b/src/plugins/clangpchmanager/clangindexingsettingsmanager.cpp deleted file mode 100644 index 786581d73d5..00000000000 --- a/src/plugins/clangpchmanager/clangindexingsettingsmanager.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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. -** -****************************************************************************/ - -#include "clangindexingsettingsmanager.h" - -#include "clangindexingprojectsettings.h" - -namespace ClangPchManager { - -ClangIndexingSettingsManager::ClangIndexingSettingsManager() = default; - -ClangIndexingSettingsManager::~ClangIndexingSettingsManager() = default; - -ClangIndexingProjectSettings *ClangIndexingSettingsManager::settings(ProjectExplorer::Project *project) -{ - auto &setting = m_settings[project]; - - if (!setting) - setting = std::make_unique(project); - - return setting.get(); -} - -void ClangIndexingSettingsManager::remove(ProjectExplorer::Project *project) -{ - m_settings.erase(project); -} - -bool ClangIndexingSettingsManager::hasSettings(ProjectExplorer::Project *project) const -{ - return m_settings.find(project) != m_settings.end(); -} -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/clangindexingsettingsmanager.h b/src/plugins/clangpchmanager/clangindexingsettingsmanager.h deleted file mode 100644 index 72f501f35be..00000000000 --- a/src/plugins/clangpchmanager/clangindexingsettingsmanager.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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 - -#include "clangpchmanager_global.h" - -#include -#include - -namespace ProjectExplorer { -class Project; -} - -namespace ClangPchManager { - -class ClangIndexingProjectSettings; - -class CLANGPCHMANAGER_EXPORT ClangIndexingSettingsManager -{ -public: - ClangIndexingSettingsManager(); - ~ClangIndexingSettingsManager(); - - ClangIndexingSettingsManager(const ClangIndexingSettingsManager &) = delete; - ClangIndexingSettingsManager &operator=(const ClangIndexingSettingsManager &) = delete; - - ClangIndexingProjectSettings *settings(ProjectExplorer::Project *project); - void remove(ProjectExplorer::Project *project); - - bool hasSettings(ProjectExplorer::Project *project) const; - -private: - std::map> m_settings; -}; - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/clangpchmanager-source.pri b/src/plugins/clangpchmanager/clangpchmanager-source.pri deleted file mode 100644 index a74d61313c8..00000000000 --- a/src/plugins/clangpchmanager/clangpchmanager-source.pri +++ /dev/null @@ -1,30 +0,0 @@ -shared|dll { - DEFINES += CLANGPCHMANAGER_LIB -} else { - DEFINES += CLANGPCHMANAGER_STATIC_LIB -} - -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/clangindexingprojectsettings.h \ - $$PWD/clangindexingsettingsmanager.h \ - $$PWD/pchmanagerclient.h \ - $$PWD/pchmanagernotifierinterface.h \ - $$PWD/pchmanagerconnectionclient.h \ - $$PWD/clangpchmanager_global.h \ - $$PWD/preprocessormacrocollector.h \ - $$PWD/projectupdater.h \ - $$PWD/pchmanagerprojectupdater.h \ - $$PWD/progressmanager.h \ - $$PWD/progressmanagerinterface.h - -SOURCES += \ - $$PWD/clangindexingprojectsettings.cpp \ - $$PWD/clangindexingsettingsmanager.cpp \ - $$PWD/pchmanagerclient.cpp \ - $$PWD/pchmanagernotifierinterface.cpp \ - $$PWD/pchmanagerconnectionclient.cpp \ - $$PWD/preprocessormacrocollector.cpp \ - $$PWD/projectupdater.cpp \ - $$PWD/pchmanagerprojectupdater.cpp diff --git a/src/plugins/clangpchmanager/clangpchmanager.pro b/src/plugins/clangpchmanager/clangpchmanager.pro deleted file mode 100644 index b0bc548c202..00000000000 --- a/src/plugins/clangpchmanager/clangpchmanager.pro +++ /dev/null @@ -1,26 +0,0 @@ -include(../../qtcreatorplugin.pri) -include(clangpchmanager-source.pri) -include(../../shared/clang/clang_installation.pri) -include(../../shared/clang/clang_defines.pri) - -requires(!isEmpty(LIBTOOLING_LIBS)) - -win32 { - LLVM_BUILDMODE = $$system($$llvm_config --build-mode, lines) - CONFIG(debug, debug|release):requires(equals(LLVM_BUILDMODE, "Debug")) -} - -HEADERS += \ - $$PWD/clangpchmanagerplugin.h \ - clangindexingprojectsettingswidget.h \ - preprocessormacrowidget.h \ - qtcreatorprojectupdater.h - -SOURCES += \ - $$PWD/clangpchmanagerplugin.cpp \ - clangindexingprojectsettingswidget.cpp \ - preprocessormacrowidget.cpp \ - qtcreatorprojectupdater.cpp - -FORMS += \ - clangindexingprojectsettingswidget.ui diff --git a/src/plugins/clangpchmanager/clangpchmanager.qbs b/src/plugins/clangpchmanager/clangpchmanager.qbs deleted file mode 100644 index a49e642e6f4..00000000000 --- a/src/plugins/clangpchmanager/clangpchmanager.qbs +++ /dev/null @@ -1,49 +0,0 @@ -import qbs -import qbs.FileInfo - -QtcPlugin { - name: "ClangPchManager" - - Depends { name: "libclang"; required: false } - Depends { name: "clang_defines" } - condition: libclang.present && libclang.toolingEnabled - - Depends { name: "ClangSupport" } - Depends { name: "Utils" } - - Depends { name: "Core" } - Depends { name: "CppTools" } - Depends { name: "ProjectExplorer" } - - cpp.defines: base.concat("CLANGPCHMANAGER_LIB") - cpp.includePaths: ["."] - - files: [ - "clangindexingprojectsettings.cpp", - "clangindexingprojectsettings.h", - "clangindexingprojectsettingswidget.cpp", - "clangindexingprojectsettingswidget.h", - "clangindexingprojectsettingswidget.ui", - "clangindexingsettingsmanager.cpp", - "clangindexingsettingsmanager.h", - "clangpchmanagerplugin.cpp", - "clangpchmanagerplugin.h", - "clangpchmanager_global.h", - "pchmanagerclient.cpp", - "pchmanagerclient.h", - "pchmanagernotifierinterface.cpp", - "pchmanagernotifierinterface.h", - "pchmanagerconnectionclient.cpp", - "pchmanagerconnectionclient.h", - "pchmanagerprojectupdater.cpp", - "pchmanagerprojectupdater.h", - "preprocessormacrocollector.cpp", - "preprocessormacrocollector.h", - "preprocessormacrowidget.cpp", - "preprocessormacrowidget.h", - "projectupdater.cpp", - "projectupdater.h", - "qtcreatorprojectupdater.cpp", - "qtcreatorprojectupdater.h", - ] -} diff --git a/src/plugins/clangpchmanager/clangpchmanager_dependencies.pri b/src/plugins/clangpchmanager/clangpchmanager_dependencies.pri deleted file mode 100644 index 197da5a97cf..00000000000 --- a/src/plugins/clangpchmanager/clangpchmanager_dependencies.pri +++ /dev/null @@ -1,8 +0,0 @@ -QTC_PLUGIN_NAME = ClangPchManager -QTC_LIB_DEPENDS += \ - utils \ - clangsupport -QTC_PLUGIN_DEPENDS += \ - coreplugin \ - cpptools - diff --git a/src/plugins/clangpchmanager/clangpchmanager_global.h b/src/plugins/clangpchmanager/clangpchmanager_global.h deleted file mode 100644 index 3a75e8e5b66..00000000000 --- a/src/plugins/clangpchmanager/clangpchmanager_global.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include - -#if defined(CLANGPCHMANAGER_LIB) -# define CLANGPCHMANAGER_EXPORT Q_DECL_EXPORT -#elif defined(CLANGPCHMANAGER_STATIC_LIB) // Abuse single files for manual tests -# define CLANGPCHMANAGER_EXPORT -#else -# define CLANGPCHMANAGER_EXPORT Q_DECL_IMPORT -#endif - -#ifdef UNIT_TESTS -#define unittest_public public -#else -#define unittest_public private -#endif diff --git a/src/plugins/clangpchmanager/clangpchmanagerplugin.cpp b/src/plugins/clangpchmanager/clangpchmanagerplugin.cpp deleted file mode 100644 index 5853ad06c06..00000000000 --- a/src/plugins/clangpchmanager/clangpchmanagerplugin.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "clangpchmanagerplugin.h" - -#include "clangindexingprojectsettingswidget.h" -#include "clangindexingsettingsmanager.h" -#include "pchmanagerclient.h" -#include "pchmanagerconnectionclient.h" -#include "progressmanager.h" -#include "qtcreatorprojectupdater.h" - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - -#include - -#include -#include - -using namespace std::chrono_literals; - -namespace ClangPchManager { - -namespace { - -QString backendProcessPath() -{ - return Core::ICore::libexecPath() - + QStringLiteral("/clangpchmanagerbackend") - + QStringLiteral(QTC_HOST_EXE_SUFFIX); -} - -void addIndexingProjectPaneWidget(ClangIndexingSettingsManager &settingsManager, - QtCreatorProjectUpdater &projectUpdater) -{ - auto factory = new ProjectExplorer::ProjectPanelFactory; - factory->setPriority(120); - factory->setDisplayName(ClangIndexingProjectSettingsWidget::tr("Clang Indexing")); - factory->setCreateWidgetFunction([&](ProjectExplorer::Project *project) { - auto widget = new ClangIndexingProjectSettingsWidget(settingsManager.settings(project), - project, - projectUpdater); - - widget->onProjectPartsUpdated(project); - - QObject::connect(CppTools::CppModelManager::instance(), - &CppTools::CppModelManager::projectPartsUpdated, - widget, - &ClangIndexingProjectSettingsWidget::onProjectPartsUpdated); - - return widget; - }); - ProjectExplorer::ProjectPanelFactory::registerFactory(factory); -} - -} // anonymous namespace - -class ClangPchManagerPluginData -{ -public: - Sqlite::Database database{Utils::PathString{Core::ICore::cacheResourcePath() - + "/symbol-experimental-v1.db"}, - 1000ms}; - ClangBackEnd::RefactoringDatabaseInitializer databaseInitializer{database}; - ClangBackEnd::FilePathCaching filePathCache{database}; - ClangPchManager::ProgressManager pchCreationProgressManager{[](QFutureInterface &promise) { - auto title = QCoreApplication::translate("ClangPchProgressManager", - "Creating PCHs", - "PCH stands for precompiled header"); - Core::ProgressManager::addTask(promise.future(), title, "pch creation", {}); - }}; - ClangPchManager::ProgressManager dependencyCreationProgressManager{ - [](QFutureInterface &promise) { - auto title = QCoreApplication::translate("ClangPchProgressManager", - "Creating Dependencies"); - Core::ProgressManager::addTask(promise.future(), title, "dependency creation", {}); - }}; - ClangBackEnd::ProjectPartsStorage projectPartsStorage{database}; - PchManagerClient pchManagerClient{pchCreationProgressManager, dependencyCreationProgressManager}; - PchManagerConnectionClient connectionClient{&pchManagerClient}; - ClangIndexingSettingsManager settingsManager; - QtCreatorProjectUpdater projectUpdater{connectionClient.serverProxy(), - pchManagerClient, - filePathCache, - projectPartsStorage, - settingsManager}; -}; - -std::unique_ptr ClangPchManagerPlugin::d; - -ClangPchManagerPlugin::ClangPchManagerPlugin() = default; -ClangPchManagerPlugin::~ClangPchManagerPlugin() = default; - -bool ClangPchManagerPlugin::initialize(const QStringList & /*arguments*/, QString * /*errorMessage*/) -{ - QDir{}.mkpath(Core::ICore::cacheResourcePath()); - - d = std::make_unique(); - - startBackend(); - - addIndexingProjectPaneWidget(d->settingsManager, d->projectUpdater); - - return true; -} - -ExtensionSystem::IPlugin::ShutdownFlag ClangPchManagerPlugin::aboutToShutdown() -{ - d->connectionClient.finishProcess(); - - d.reset(); - - return SynchronousShutdown; -} - -void ClangPchManagerPlugin::startBackend() -{ - d->pchManagerClient.setConnectionClient(&d->connectionClient); - - d->connectionClient.setProcessPath(backendProcessPath()); - - d->connectionClient.startProcessAndConnectToServerAsynchronously(); -} - - -PchManagerClient &ClangPchManagerPlugin::pchManagerClient() -{ - return d->pchManagerClient; -} - -ClangIndexingSettingsManager &ClangPchManagerPlugin::settingsManager() -{ - return d->settingsManager; -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangpchmanager/clangpchmanagerplugin.h b/src/plugins/clangpchmanager/clangpchmanagerplugin.h deleted file mode 100644 index a33137b4357..00000000000 --- a/src/plugins/clangpchmanager/clangpchmanagerplugin.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangpchmanager_global.h" - -#include - -#include - -namespace ClangPchManager { - -class ClangIndexingSettingsManager; -class ClangPchManagerPluginData; -class PchManagerClient; - -class CLANGPCHMANAGER_EXPORT ClangPchManagerPlugin : public ExtensionSystem::IPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "ClangPchManager.json") - -public: - ClangPchManagerPlugin(); - ~ClangPchManagerPlugin(); - - bool initialize(const QStringList &arguments, QString *errorMessage); - ShutdownFlag aboutToShutdown(); - - static PchManagerClient &pchManagerClient(); - static ClangIndexingSettingsManager &settingsManager(); - -private: - void startBackend(); - -private: - static std::unique_ptr d; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangpchmanager/pchmanagerclient.cpp b/src/plugins/clangpchmanager/pchmanagerclient.cpp deleted file mode 100644 index 04d1d4a0bf8..00000000000 --- a/src/plugins/clangpchmanager/pchmanagerclient.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "pchmanagerclient.h" - -#include -#include -#include -#include -#include - -#include - -namespace ClangPchManager { - -void PchManagerClient::alive() -{ - if (m_connectionClient) - m_connectionClient->resetProcessAliveTimer(); -} - -void PchManagerClient::precompiledHeadersUpdated(ClangBackEnd::PrecompiledHeadersUpdatedMessage &&message) -{ - for (ClangBackEnd::ProjectPartId &projectPartId : message.takeProjectPartIds()) - precompiledHeaderUpdated(projectPartId); -} - -void PchManagerClient::progress(ClangBackEnd::ProgressMessage &&message) -{ - switch (message.progressType) { - case ClangBackEnd::ProgressType::PrecompiledHeader: - m_pchCreationProgressManager.setProgress(message.progress, message.total); - break; - case ClangBackEnd::ProgressType::DependencyCreation: - m_dependencyCreationProgressManager.setProgress(message.progress, message.total); - break; - default: - break; - } -} - -void PchManagerClient::precompiledHeaderRemoved(ClangBackEnd::ProjectPartId projectPartId) -{ - for (auto notifier : m_notifiers) - notifier->precompiledHeaderRemoved(projectPartId); -} - -void PchManagerClient::setConnectionClient(PchManagerConnectionClient *connectionClient) -{ - m_connectionClient = connectionClient; -} - -void PchManagerClient::attach(PchManagerNotifierInterface *notifier) -{ - m_notifiers.push_back(notifier); -} - -void PchManagerClient::detach(PchManagerNotifierInterface *notifierToBeDeleted) -{ - auto newEnd = std::partition(m_notifiers.begin(), - m_notifiers.end(), - [&] (PchManagerNotifierInterface *notifier) { - return notifier != notifierToBeDeleted; - }); - - m_notifiers.erase(newEnd, m_notifiers.end()); -} - -const std::vector &PchManagerClient::notifiers() const -{ - return m_notifiers; -} - -void PchManagerClient::precompiledHeaderUpdated(ClangBackEnd::ProjectPartId projectPartId) -{ - for (auto notifier : m_notifiers) - notifier->precompiledHeaderUpdated(projectPartId); -} - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/pchmanagerclient.h b/src/plugins/clangpchmanager/pchmanagerclient.h deleted file mode 100644 index 7d986a0ab69..00000000000 --- a/src/plugins/clangpchmanager/pchmanagerclient.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangpchmanager_global.h" - -#include -#include - -#include - -namespace ClangPchManager { -class PchManagerConnectionClient; -class ProgressManagerInterface; -class PchManagerNotifierInterface; - -class CLANGPCHMANAGER_EXPORT PchManagerClient final : public ClangBackEnd::PchManagerClientInterface -{ - friend class PchManagerNotifierInterface; -public: - PchManagerClient(ProgressManagerInterface &pchCreationProgressManager, - ProgressManagerInterface &dependencyCreationProgressManager) - : m_pchCreationProgressManager(pchCreationProgressManager) - , m_dependencyCreationProgressManager(dependencyCreationProgressManager) - {} - - void alive() override; - void precompiledHeadersUpdated(ClangBackEnd::PrecompiledHeadersUpdatedMessage &&message) override; - void progress(ClangBackEnd::ProgressMessage &&message) override; - - void precompiledHeaderRemoved(ClangBackEnd::ProjectPartId projectPartId); - - void setConnectionClient(PchManagerConnectionClient *connectionClient); - - unittest_public : const std::vector ¬ifiers() const; - void precompiledHeaderUpdated(ClangBackEnd::ProjectPartId projectPartId); - - void attach(PchManagerNotifierInterface *notifier); - void detach(PchManagerNotifierInterface *notifier); - -private: - std::vector m_notifiers; - PchManagerConnectionClient *m_connectionClient=nullptr; - ProgressManagerInterface &m_pchCreationProgressManager; - ProgressManagerInterface &m_dependencyCreationProgressManager; -}; - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/pchmanagerconnectionclient.cpp b/src/plugins/clangpchmanager/pchmanagerconnectionclient.cpp deleted file mode 100644 index 324f0e2884b..00000000000 --- a/src/plugins/clangpchmanager/pchmanagerconnectionclient.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "pchmanagerconnectionclient.h" - -#include - -#include - -#include - -namespace ClangPchManager { - -namespace { - -QString currentProcessId() -{ - return QString::number(QCoreApplication::applicationPid()); -} - -} - -ClangPchManager::PchManagerConnectionClient::PchManagerConnectionClient( - ClangBackEnd::PchManagerClientInterface *client) - : ConnectionClient(Utils::TemporaryDirectory::masterDirectoryPath() - + QStringLiteral("/ClangPchManagerBackEnd-") - + currentProcessId()), - m_serverProxy(client, ioDevice()) -{ - m_processCreator.setTemporaryDirectoryPattern("clangpchmanagerbackend-XXXXXX"); - - QDir pchsDirectory(Core::ICore::cacheResourcePath().toString()); - pchsDirectory.mkdir("pchs"); - pchsDirectory.cd("pchs"); - m_processCreator.setArguments({connectionName(), - Core::ICore::cacheResourcePath("symbol-experimental-v1.db").toString(), - pchsDirectory.absolutePath(), - Core::ICore::resourcePath().toString()}); - - stdErrPrefixer().setPrefix("PchManagerConnectionClient.stderr: "); - stdOutPrefixer().setPrefix("PchManagerConnectionClient.stdout: "); -} - -PchManagerConnectionClient::~PchManagerConnectionClient() -{ - finishProcess(); -} - -ClangBackEnd::PchManagerServerProxy &ClangPchManager::PchManagerConnectionClient::serverProxy() -{ - return m_serverProxy; -} - -void ClangPchManager::PchManagerConnectionClient::sendEndCommand() -{ - m_serverProxy.end(); -} - -void PchManagerConnectionClient::resetState() -{ - m_serverProxy.resetState(); -} - -QString PchManagerConnectionClient::outputName() const -{ - return QStringLiteral("PchManagerConnectionClient"); -} - -void PchManagerConnectionClient::newConnectedServer(QLocalSocket *localSocket) -{ - m_serverProxy.setLocalSocket(localSocket); -} - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/pchmanagerconnectionclient.h b/src/plugins/clangpchmanager/pchmanagerconnectionclient.h deleted file mode 100644 index 7189c83c0b8..00000000000 --- a/src/plugins/clangpchmanager/pchmanagerconnectionclient.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include -#include - -namespace ClangPchManager { - -class PchManagerConnectionClient : public ClangBackEnd::ConnectionClient -{ -public: - PchManagerConnectionClient(ClangBackEnd::PchManagerClientInterface *client); - ~PchManagerConnectionClient(); - - ClangBackEnd::PchManagerServerProxy &serverProxy(); - -protected: - void sendEndCommand() override; - void resetState() override; - QString outputName() const override; - void newConnectedServer(QLocalSocket *localSocket) override; - -private: - ClangBackEnd::PchManagerServerProxy m_serverProxy; -}; - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/pchmanagernotifierinterface.cpp b/src/plugins/clangpchmanager/pchmanagernotifierinterface.cpp deleted file mode 100644 index f0524152eab..00000000000 --- a/src/plugins/clangpchmanager/pchmanagernotifierinterface.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "pchmanagernotifierinterface.h" - -#include - -namespace ClangPchManager { - -PchManagerNotifierInterface::PchManagerNotifierInterface(PchManagerClient &pchManagerClient) - : m_pchManagerClient(pchManagerClient) -{ - m_pchManagerClient.attach(this); -} - -PchManagerNotifierInterface::~PchManagerNotifierInterface() -{ - m_pchManagerClient.detach(this); -} - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/pchmanagernotifierinterface.h b/src/plugins/clangpchmanager/pchmanagernotifierinterface.h deleted file mode 100644 index 780ec5a2cd1..00000000000 --- a/src/plugins/clangpchmanager/pchmanagernotifierinterface.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangpchmanager_global.h" - -#include - -QT_FORWARD_DECLARE_CLASS(QString) - -namespace ClangPchManager { - -class PchManagerClient; - -class CLANGPCHMANAGER_EXPORT PchManagerNotifierInterface -{ -public: - PchManagerNotifierInterface(PchManagerClient &pchManagerClient); - PchManagerNotifierInterface(const PchManagerNotifierInterface &) = delete; - PchManagerNotifierInterface &operator=(const PchManagerNotifierInterface &) = delete; - - virtual void precompiledHeaderUpdated(ClangBackEnd::ProjectPartId projectPartId) = 0; - virtual void precompiledHeaderRemoved(ClangBackEnd::ProjectPartId projectPartId) = 0; - - PchManagerClient &m_pchManagerClient; - -protected: - ~PchManagerNotifierInterface(); -}; - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/pchmanagerprojectupdater.cpp b/src/plugins/clangpchmanager/pchmanagerprojectupdater.cpp deleted file mode 100644 index 38af78719e4..00000000000 --- a/src/plugins/clangpchmanager/pchmanagerprojectupdater.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "pchmanagerprojectupdater.h" - -#include "pchmanagerclient.h" - -namespace ClangPchManager { - -void PchManagerProjectUpdater::removeProjectParts(const ClangBackEnd::ProjectPartIds &projectPartIds) -{ - ProjectUpdater::removeProjectParts(projectPartIds); - - for (ClangBackEnd::ProjectPartId projectPartId : projectPartIds) - m_client.precompiledHeaderRemoved(projectPartId); -} - -void PchManagerProjectUpdater::removeProjectParts(const QStringList &projectPartNames) -{ - ClangBackEnd::ProjectPartIds projectPartIds = toProjectPartIds(projectPartNames); - - ProjectUpdater::removeProjectParts(projectPartIds); - - for (ClangBackEnd::ProjectPartId projectPartId : projectPartIds) - m_client.precompiledHeaderRemoved(projectPartId); -} - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/pchmanagerprojectupdater.h b/src/plugins/clangpchmanager/pchmanagerprojectupdater.h deleted file mode 100644 index 8d41e564768..00000000000 --- a/src/plugins/clangpchmanager/pchmanagerprojectupdater.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "projectupdater.h" - -namespace ClangPchManager { - -class PchManagerProjectUpdater : public ProjectUpdater -{ -public: - PchManagerProjectUpdater(ClangBackEnd::ProjectManagementServerInterface &server, - PchManagerClient &client, - ClangBackEnd::FilePathCachingInterface &filePathCache, - ClangBackEnd::ProjectPartsStorageInterface &projectPartsStorage, - ClangIndexingSettingsManager &settingsManager) - : ProjectUpdater(server, filePathCache, projectPartsStorage, settingsManager) - , m_client(client) - {} - - void removeProjectParts(const ClangBackEnd::ProjectPartIds &projectPartIds); - void removeProjectParts(const QStringList &projectPartNames); - -private: - PchManagerClient &m_client; -}; - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/preprocessormacrocollector.cpp b/src/plugins/clangpchmanager/preprocessormacrocollector.cpp deleted file mode 100644 index 03b38daeff7..00000000000 --- a/src/plugins/clangpchmanager/preprocessormacrocollector.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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. -** -****************************************************************************/ - -#include "preprocessormacrocollector.h" - -namespace ClangPchManager { - -namespace { -PreprocessorMacros toSortedMacros(const ProjectExplorer::Macros ¯os) -{ - PreprocessorMacros sortedMacros; - sortedMacros.reserve(macros.size()); - - for (const ProjectExplorer::Macro ¯o : macros) - if (macro.type == ProjectExplorer::MacroType::Define) - sortedMacros.push_back({QString::fromUtf8(macro.key), QString::fromUtf8(macro.value)}); - - std::sort(sortedMacros.begin(), sortedMacros.end()); - - return sortedMacros; -} -} // namespace - -void PreprocessorMacroCollector::add(const ProjectExplorer::Macros ¯os) -{ - PreprocessorMacros sortedMacros = toSortedMacros(macros); - std::sort(sortedMacros.begin(), sortedMacros.end()); - - PreprocessorMacros mergedMacros; - mergedMacros.reserve(sortedMacros.size() + m_macros.size()); - - std::set_union(m_macros.begin(), - m_macros.end(), - sortedMacros.begin(), - sortedMacros.end(), - std::back_inserter(mergedMacros)); - - m_macros = mergedMacros; -} - -const PreprocessorMacros &PreprocessorMacroCollector::macros() const -{ - return m_macros; -} - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/preprocessormacrocollector.h b/src/plugins/clangpchmanager/preprocessormacrocollector.h deleted file mode 100644 index 2de2553df31..00000000000 --- a/src/plugins/clangpchmanager/preprocessormacrocollector.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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 - -#include -#include - -#include - -#include - -namespace ClangPchManager { - -using PreprocessorMacro = std::pair; -using PreprocessorMacros = QVector; - -class PreprocessorMacroCollector -{ -public: - void add(const ProjectExplorer::Macros ¯os); - - const PreprocessorMacros ¯os() const; - -private: - PreprocessorMacros m_macros; -}; - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/preprocessormacrowidget.cpp b/src/plugins/clangpchmanager/preprocessormacrowidget.cpp deleted file mode 100644 index 8ebe45bef8e..00000000000 --- a/src/plugins/clangpchmanager/preprocessormacrowidget.cpp +++ /dev/null @@ -1,282 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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. -** -****************************************************************************/ - -#include "preprocessormacrowidget.h" -#include "clangindexingprojectsettings.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -namespace ClangPchManager { - -class ProcessorMacroDelegate : public QStyledItemDelegate -{ -public: - ProcessorMacroDelegate(Utils::NameValueModel *model, QTreeView *view) - : QStyledItemDelegate(view) - , m_model(model) - , m_view(view) - {} - - QWidget *createEditor(QWidget *parent, - const QStyleOptionViewItem &option, - const QModelIndex &index) const override - { - QWidget *w = QStyledItemDelegate::createEditor(parent, option, index); - if (index.column() != 0) - return w; - - if (auto edit = qobject_cast(w)) - edit->setValidator(new Utils::NameValueValidator( - edit, m_model, m_view, index, PreprocessorMacroWidget::tr("Macro already exists."))); - return w; - } - -private: - Utils::NameValueModel *m_model; - QTreeView *m_view; -}; - -PreprocessorMacroWidget::PreprocessorMacroWidget(QWidget *parent) : QWidget(parent) -{ - m_model = std::make_unique(); - connect(m_model.get(), - &Utils::NameValueModel::userChangesChanged, - this, - &PreprocessorMacroWidget::userChangesChanged); - connect(m_model.get(), - &QAbstractItemModel::modelReset, - this, - &PreprocessorMacroWidget::invalidateCurrentIndex); - - connect(m_model.get(), &Utils::NameValueModel::focusIndex, this, &PreprocessorMacroWidget::focusIndex); - - auto vbox = new QVBoxLayout(this); - vbox->setContentsMargins(0, 0, 0, 0); - - m_detailsContainer = new Utils::DetailsWidget(this); - - auto details = new QWidget(m_detailsContainer); - m_detailsContainer->setWidget(details); - details->setVisible(false); - - auto vbox2 = new QVBoxLayout(details); - vbox2->setContentsMargins(0, 0, 0, 0); - - auto horizontalLayout = new QHBoxLayout; - horizontalLayout->setContentsMargins(0, 0, 0, 0); - auto tree = new Utils::TreeView(this); - connect(tree, &QAbstractItemView::activated, tree, [tree](const QModelIndex &idx) { - tree->edit(idx); - }); - m_preprocessorMacrosView = tree; - m_preprocessorMacrosView->setModel(m_model.get()); - m_preprocessorMacrosView->setItemDelegate( - new ProcessorMacroDelegate(m_model.get(), m_preprocessorMacrosView)); - m_preprocessorMacrosView->setMinimumHeight(400); - m_preprocessorMacrosView->setRootIsDecorated(false); - m_preprocessorMacrosView->setUniformRowHeights(true); - new Utils::HeaderViewStretcher(m_preprocessorMacrosView->header(), 1); - m_preprocessorMacrosView->setSelectionMode(QAbstractItemView::SingleSelection); - m_preprocessorMacrosView->setSelectionBehavior(QAbstractItemView::SelectItems); - m_preprocessorMacrosView->setFrameShape(QFrame::NoFrame); - QFrame *findWrapper = Core::ItemViewFind::createSearchableWrapper(m_preprocessorMacrosView, - Core::ItemViewFind::LightColored); - findWrapper->setFrameStyle(QFrame::StyledPanel); - horizontalLayout->addWidget(findWrapper); - - auto buttonLayout = new QVBoxLayout(); - - m_editButton = new QPushButton(this); - m_editButton->setText(tr("Ed&it")); - buttonLayout->addWidget(m_editButton); - - m_addButton = new QPushButton(this); - m_addButton->setText(tr("&Add")); - buttonLayout->addWidget(m_addButton); - - m_resetButton = new QPushButton(this); - m_resetButton->setEnabled(false); - m_resetButton->setText(tr("&Reset")); - buttonLayout->addWidget(m_resetButton); - - m_unsetButton = new QPushButton(this); - m_unsetButton->setEnabled(false); - m_unsetButton->setText(tr("&Unset")); - buttonLayout->addWidget(m_unsetButton); - - buttonLayout->addStretch(); - - horizontalLayout->addLayout(buttonLayout); - vbox2->addLayout(horizontalLayout); - - vbox->addWidget(m_detailsContainer); - - connect(m_model.get(), - &QAbstractItemModel::dataChanged, - this, - &PreprocessorMacroWidget::updateButtons); - - connect(m_editButton, &QAbstractButton::clicked, this, &PreprocessorMacroWidget::editButtonClicked); - connect(m_addButton, &QAbstractButton::clicked, this, &PreprocessorMacroWidget::addButtonClicked); - connect(m_resetButton, &QAbstractButton::clicked, this, &PreprocessorMacroWidget::removeButtonClicked); - connect(m_unsetButton, &QAbstractButton::clicked, this, &PreprocessorMacroWidget::unsetButtonClicked); - connect(m_preprocessorMacrosView->selectionModel(), - &QItemSelectionModel::currentChanged, - this, - &PreprocessorMacroWidget::currentIndexChanged); - connect(m_detailsContainer, - &Utils::DetailsWidget::linkActivated, - this, - &PreprocessorMacroWidget::linkActivated); - connect(m_model.get(), - &Utils::NameValueModel::userChangesChanged, - this, - &PreprocessorMacroWidget::updateSummaryText); - connect(m_model.get(), - &Utils::NameValueModel::userChangesChanged, - this, - &PreprocessorMacroWidget::saveSettings); -} - -void PreprocessorMacroWidget::setBasePreprocessorMacros(const PreprocessorMacros ¯os) -{ - m_model->setUserChanges(m_settings->readMacros()); - m_model->setBaseNameValueDictionary(Utils::NameValueDictionary{macros}); -} - -void PreprocessorMacroWidget::setSettings(ClangIndexingProjectSettings *settings) -{ - m_settings = settings; -} - -PreprocessorMacroWidget::~PreprocessorMacroWidget() = default; - -void PreprocessorMacroWidget::updateButtons() -{ - currentIndexChanged(m_preprocessorMacrosView->currentIndex()); -} - -void PreprocessorMacroWidget::focusIndex(const QModelIndex &index) -{ - m_preprocessorMacrosView->setCurrentIndex(index); - m_preprocessorMacrosView->setFocus(); - - m_preprocessorMacrosView->scrollTo(index, QAbstractItemView::PositionAtTop); -} - -void PreprocessorMacroWidget::invalidateCurrentIndex() -{ - currentIndexChanged(QModelIndex()); -} - -void PreprocessorMacroWidget::editButtonClicked() -{ - m_preprocessorMacrosView->edit(m_preprocessorMacrosView->currentIndex()); -} - -void PreprocessorMacroWidget::addButtonClicked() -{ - QModelIndex index = m_model->addVariable(); - m_preprocessorMacrosView->setCurrentIndex(index); - m_preprocessorMacrosView->edit(index); -} - -void PreprocessorMacroWidget::removeButtonClicked() -{ - const QString &name = m_model->indexToVariable(m_preprocessorMacrosView->currentIndex()); - m_model->resetVariable(name); -} - -void PreprocessorMacroWidget::unsetButtonClicked() -{ - const QString &name = m_model->indexToVariable(m_preprocessorMacrosView->currentIndex()); - if (!m_model->canReset(name)) - m_model->resetVariable(name); - else - m_model->unsetVariable(name); -} - -void PreprocessorMacroWidget::currentIndexChanged(const QModelIndex ¤t) -{ - if (current.isValid()) { - m_editButton->setEnabled(true); - const QString &name = m_model->indexToVariable(current); - bool modified = m_model->canReset(name) && m_model->changes(name); - bool unset = m_model->isUnset(name); - m_resetButton->setEnabled(modified || unset); - m_unsetButton->setEnabled(!unset); - } else { - m_editButton->setEnabled(false); - m_resetButton->setEnabled(false); - m_unsetButton->setEnabled(false); - } -} - -void PreprocessorMacroWidget::linkActivated(const QString &link) -{ - m_detailsContainer->setState(Utils::DetailsWidget::Expanded); - QModelIndex idx = m_model->variableToIndex(link); - focusIndex(idx); -} - -void PreprocessorMacroWidget::updateSummaryText() -{ - Utils::NameValueItems items = m_model->userChanges(); - Utils::NameValueItem::sort(&items); - - QString text; - for (const Utils::EnvironmentItem &item : items) { - if (item.name != Utils::NameValueModel::tr("")) { - text.append(QLatin1String("
")); - if (item.operation == Utils::NameValueItem::Unset) - text.append(tr("Unset %1").arg(item.name.toHtmlEscaped())); - else - text.append(tr("Set %1 to %2") - .arg(item.name.toHtmlEscaped(), item.value.toHtmlEscaped())); - } - } - - m_detailsContainer->setSummaryText(text); -} - -void PreprocessorMacroWidget::saveSettings() -{ - m_settings->saveMacros(m_model->userChanges()); -} - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/preprocessormacrowidget.h b/src/plugins/clangpchmanager/preprocessormacrowidget.h deleted file mode 100644 index 0c4c01545cf..00000000000 --- a/src/plugins/clangpchmanager/preprocessormacrowidget.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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 - -#include -#include - -#include - -namespace Utils { -class DetailsWidget; -class NameValueModel; -} // namespace Utils - -namespace ClangPchManager { -class ClangIndexingProjectSettings; -using PreprocessorMacro = std::pair; -using PreprocessorMacros = QVector; - -class PreprocessorMacroWidget : public QWidget -{ - Q_OBJECT -public: - explicit PreprocessorMacroWidget(QWidget *parent = nullptr); - ~PreprocessorMacroWidget() override; - void setBasePreprocessorMacros(const PreprocessorMacros ¯os); - void setSettings(ClangIndexingProjectSettings *settings); - -signals: - void userChangesChanged(); - -private: - void updateButtons(); - void focusIndex(const QModelIndex &index); - void invalidateCurrentIndex(); - void editButtonClicked(); - void addButtonClicked(); - void removeButtonClicked(); - void unsetButtonClicked(); - void currentIndexChanged(const QModelIndex ¤t); - void linkActivated(const QString &link); - void updateSummaryText(); - void saveSettings(); - -private: - std::unique_ptr m_model; - Utils::DetailsWidget *m_detailsContainer; - QTreeView *m_preprocessorMacrosView; - QPushButton *m_editButton; - QPushButton *m_addButton; - QPushButton *m_resetButton; - QPushButton *m_unsetButton; - ClangIndexingProjectSettings *m_settings = {}; -}; - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/progressmanager.h b/src/plugins/clangpchmanager/progressmanager.h deleted file mode 100644 index 9dc9fc03664..00000000000 --- a/src/plugins/clangpchmanager/progressmanager.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "progressmanagerinterface.h" - -#include -#include -#include - -#include -#include - -namespace ClangPchManager { - -class ProgressManager : public ProgressManagerInterface -{ -public: - using Promise = QFutureInterface; - using Callback = std::function; - - ProgressManager(Callback &&callback) - : m_callback(std::move(callback)) - {} - - - void setProgress(int currentProgress, int maximumProgress) - { - if (!m_promise) - initialize(); - - if (m_promise->progressMaximum() != maximumProgress) - m_promise->setProgressRange(0, maximumProgress); - m_promise->setProgressValue(currentProgress); - - if (currentProgress >= maximumProgress) - finish(); - } - - Promise *promise() - { - return m_promise.get(); - } -private: - void initialize() - { - m_promise = std::make_unique(); - m_callback(*m_promise); - } - - void finish() - { - m_promise->reportFinished(); - m_promise.reset(); - } - -private: - Callback m_callback; - std::unique_ptr m_promise; -}; - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/progressmanagerinterface.h b/src/plugins/clangpchmanager/progressmanagerinterface.h deleted file mode 100644 index 5653e5cd7f5..00000000000 --- a/src/plugins/clangpchmanager/progressmanagerinterface.h +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 ClangPchManager { - -class ProgressManagerInterface -{ -public: - virtual void setProgress(int currentProgress, int maximumProgress) = 0; - -protected: - ~ProgressManagerInterface() = default; -}; - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/projectupdater.cpp b/src/plugins/clangpchmanager/projectupdater.cpp deleted file mode 100644 index 8c021fc3e55..00000000000 --- a/src/plugins/clangpchmanager/projectupdater.cpp +++ /dev/null @@ -1,481 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "projectupdater.h" - -#include "pchmanagerclient.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include -#include -#include - -namespace ClangPchManager { - -class HeaderAndSources -{ -public: - void reserve(std::size_t size) - { - headers.reserve(size); - sources.reserve(size); - } - - ClangBackEnd::FilePathIds headers; - ClangBackEnd::FilePathIds sources; -}; - -void ProjectUpdater::updateProjectParts(const std::vector &projectParts, - Utils::SmallStringVector &&toolChainArguments) -{ - addProjectFilesToFilePathCache(projectParts); - fetchProjectPartIds(projectParts); - - m_server.updateProjectParts( - ClangBackEnd::UpdateProjectPartsMessage{toProjectPartContainers(projectParts), - std::move(toolChainArguments)}); -} - -void ProjectUpdater::removeProjectParts(ClangBackEnd::ProjectPartIds projectPartIds) -{ - auto sortedIds{projectPartIds}; - std::sort(sortedIds.begin(), sortedIds.end()); - - m_server.removeProjectParts(ClangBackEnd::RemoveProjectPartsMessage{std::move(sortedIds)}); -} - -void ProjectUpdater::updateGeneratedFiles(ClangBackEnd::V2::FileContainers &&generatedFiles) -{ - std::sort(generatedFiles.begin(), generatedFiles.end()); - - m_generatedFiles.update(generatedFiles); - - m_excludedPaths = createExcludedPaths(m_generatedFiles.fileContainers()); - - m_server.updateGeneratedFiles( - ClangBackEnd::UpdateGeneratedFilesMessage{std::move(generatedFiles)}); -} - -void ProjectUpdater::removeGeneratedFiles(ClangBackEnd::FilePaths &&filePaths) -{ - m_generatedFiles.remove(filePaths); - - m_excludedPaths = createExcludedPaths(m_generatedFiles.fileContainers()); - - m_server.removeGeneratedFiles( - ClangBackEnd::RemoveGeneratedFilesMessage{std::move(filePaths)}); -} - -void ProjectUpdater::setExcludedPaths(ClangBackEnd::FilePaths &&excludedPaths) -{ - m_excludedPaths = std::move(excludedPaths); -} - -const ClangBackEnd::FilePaths &ProjectUpdater::excludedPaths() const -{ - return m_excludedPaths; -} - -const ClangBackEnd::GeneratedFiles &ProjectUpdater::generatedFiles() const -{ - return m_generatedFiles; -} - -void ProjectUpdater::addToHeaderAndSources(HeaderAndSources &headerAndSources, - const CppTools::ProjectFile &projectFile) const -{ - using ClangBackEnd::FilePathView; - - Utils::PathString path = projectFile.path; - bool exclude = std::binary_search(m_excludedPaths.begin(), m_excludedPaths.end(), path); - - if (!exclude) { - ClangBackEnd::FilePathId filePathId = m_filePathCache.filePathId(FilePathView(path)); - if (projectFile.isSource()) - headerAndSources.sources.push_back(filePathId); - else if (projectFile.isHeader()) - headerAndSources.headers.push_back(filePathId); - } -} - -HeaderAndSources ProjectUpdater::headerAndSourcesFromProjectPart( - CppTools::ProjectPart *projectPart) const -{ - HeaderAndSources headerAndSources; - headerAndSources.reserve(std::size_t(projectPart->files.size()) * 3 / 2); - - for (const CppTools::ProjectFile &projectFile : projectPart->files) { - if (projectFile.active) - addToHeaderAndSources(headerAndSources, projectFile); - } - - std::sort(headerAndSources.sources.begin(), headerAndSources.sources.end()); - std::sort(headerAndSources.headers.begin(), headerAndSources.headers.end()); - - return headerAndSources; -} - -QStringList ProjectUpdater::toolChainArguments(CppTools::ProjectPart *projectPart) -{ - using CppTools::CompilerOptionsBuilder; - CompilerOptionsBuilder builder(*projectPart, CppTools::UseSystemHeader::Yes); - - builder.addWordWidth(); - // builder.addTargetTriple(); TODO resarch why target triples are different - builder.addExtraCodeModelFlags(); - builder.undefineClangVersionMacrosForMsvc(); - - builder.undefineCppLanguageFeatureMacrosForMsvc2015(); - builder.addProjectConfigFileInclude(); - builder.addMsvcCompatibilityVersion(); - - return builder.options(); -} - -namespace { -void cleanupMacros(ClangBackEnd::CompilerMacros ¯os) -{ - auto newEnd = std::partition(macros.begin(), - macros.end(), - [](const ClangBackEnd::CompilerMacro ¯o) { - return macro.key != "QT_TESTCASE_BUILDDIR"; - }); - - macros.erase(newEnd, macros.end()); -} - -void updateWithSettings(ClangBackEnd::CompilerMacros ¯os, - Utils::NameValueItems &&settingsItems, - int &index) -{ - std::sort(settingsItems.begin(), settingsItems.end(), [](const auto &first, const auto &second) { - return std::tie(first.operation, first.name, first.value) - < std::tie(first.operation, second.name, second.value); - }); - - auto point = std::partition_point(settingsItems.begin(), settingsItems.end(), [](const auto &entry) { - return entry.operation == Utils::NameValueItem::SetEnabled; - }); - - std::transform( - settingsItems.begin(), - point, - std::back_inserter(macros), - [&](const Utils::NameValueItem &settingsMacro) { - return ClangBackEnd::CompilerMacro{settingsMacro.name, settingsMacro.value, ++index}; - }); - - std::sort(macros.begin(), macros.end(), [](const auto &first, const auto &second) { - return std::tie(first.key, first.value) < std::tie(second.key, second.value); - }); - - ClangBackEnd::CompilerMacros result; - result.reserve(macros.size()); - - ClangBackEnd::CompilerMacros convertedSettingsMacros; - convertedSettingsMacros.resize(std::distance(point, settingsItems.end())); - std::transform( - point, - settingsItems.end(), - std::back_inserter(convertedSettingsMacros), - [&](const Utils::NameValueItem &settingsMacro) { - return ClangBackEnd::CompilerMacro{settingsMacro.name, settingsMacro.value, ++index}; - }); - - std::set_difference(macros.begin(), - macros.end(), - convertedSettingsMacros.begin(), - convertedSettingsMacros.end(), - std::back_inserter(result), - [](const ClangBackEnd::CompilerMacro &first, - const ClangBackEnd::CompilerMacro &second) { - return std::tie(first.key, first.value) - < std::tie(second.key, second.value); - }); - - macros = std::move(result); -} - -} // namespace - -ClangBackEnd::CompilerMacros ProjectUpdater::createCompilerMacros( - const ProjectExplorer::Macros &projectMacros, Utils::NameValueItems &&settingsMacros) -{ - int index = 0; - auto macros = Utils::transform( - projectMacros, [&](const ProjectExplorer::Macro ¯o) { - return ClangBackEnd::CompilerMacro{macro.key, macro.value, ++index}; - }); - - cleanupMacros(macros); - updateWithSettings(macros, std::move(settingsMacros), index); - - std::sort(macros.begin(), macros.end()); - - return macros; -} - -namespace { -ClangBackEnd::IncludeSearchPathType convertType(ProjectExplorer::HeaderPathType sourceType) -{ - using ProjectExplorer::HeaderPathType; - using ClangBackEnd::IncludeSearchPathType; - - switch (sourceType) { - case HeaderPathType::User: - return IncludeSearchPathType::User; - case HeaderPathType::System: - return IncludeSearchPathType::System; - case HeaderPathType::BuiltIn: - return IncludeSearchPathType::BuiltIn; - case HeaderPathType::Framework: - return IncludeSearchPathType::Framework; - } - - return IncludeSearchPathType::Invalid; -} - -ClangBackEnd::IncludeSearchPaths convertToIncludeSearchPaths(ProjectExplorer::HeaderPaths headerPaths) -{ - ClangBackEnd::IncludeSearchPaths paths; - paths.reserve(Utils::usize(headerPaths)); - - int index = 0; - for (const ProjectExplorer::HeaderPath &headerPath : headerPaths) - paths.emplace_back(headerPath.path, ++index, convertType(headerPath.type)); - - std::sort(paths.begin(), paths.end()); - - return paths; -} - -ClangBackEnd::IncludeSearchPaths convertToIncludeSearchPaths( - ProjectExplorer::HeaderPaths headerPaths, ProjectExplorer::HeaderPaths headerPaths2) -{ - ClangBackEnd::IncludeSearchPaths paths; - paths.reserve(Utils::usize(headerPaths) + Utils::usize(headerPaths2)); - - int index = 0; - for (const ProjectExplorer::HeaderPath &headerPath : headerPaths) - paths.emplace_back(headerPath.path, ++index, convertType(headerPath.type)); - - for (const ProjectExplorer::HeaderPath &headerPath : headerPaths2) - paths.emplace_back(headerPath.path, ++index, convertType(headerPath.type)); - - std::sort(paths.begin(), paths.end()); - - return paths; -} - -QString projectDirectory(ProjectExplorer::Project *project) -{ - if (project) - return project->rootProjectDirectory().toString(); - - return {}; -} - -QString buildDirectory(ProjectExplorer::Project *project) -{ - if (project && project->activeTarget() && project->activeTarget()->activeBuildConfiguration()) - return project->activeTarget()->activeBuildConfiguration()->buildDirectory().toString(); - - return {}; -} -} // namespace - -ProjectUpdater::SystemAndProjectIncludeSearchPaths ProjectUpdater::createIncludeSearchPaths( - const CppTools::ProjectPart &projectPart) -{ - CppTools::HeaderPathFilter filter(projectPart, - CppTools::UseTweakedHeaderPaths::Yes, - CLANG_VERSION, - CLANG_INCLUDE_DIR, - projectDirectory(projectPart.project), - buildDirectory(projectPart.project)); - filter.process(); - - return {convertToIncludeSearchPaths(filter.systemHeaderPaths, filter.builtInHeaderPaths), - convertToIncludeSearchPaths(filter.userHeaderPaths)}; -} - -ClangBackEnd::ProjectPartContainer ProjectUpdater::toProjectPartContainer( - CppTools::ProjectPart *projectPart) const -{ - - QStringList arguments = toolChainArguments(projectPart); - - HeaderAndSources headerAndSources = headerAndSourcesFromProjectPart(projectPart); - - auto includeSearchPaths = createIncludeSearchPaths(*projectPart); - - ClangBackEnd::ProjectPartId projectPartId = m_projectPartIdCache.stringId( - Utils::PathString{projectPart->id()}, [&](Utils::SmallStringView projectPartName) { - return m_projectPartsStorage.fetchProjectPartId(projectPartName); - }); - - ClangIndexingProjectSettings *settings = m_settingsManager.settings(projectPart->project); - - return ClangBackEnd::ProjectPartContainer(projectPartId, - Utils::SmallStringVector(arguments), - createCompilerMacros(projectPart->projectMacros, - settings->readMacros()), - std::move(includeSearchPaths.system), - std::move(includeSearchPaths.project), - std::move(headerAndSources.headers), - std::move(headerAndSources.sources), - projectPart->language, - projectPart->languageVersion, - static_cast( - int(projectPart->languageExtensions))); -} - -ClangBackEnd::ProjectPartContainers ProjectUpdater::toProjectPartContainers( - std::vector projectParts) const -{ - using namespace std::placeholders; - - projectParts.erase(std::remove_if(projectParts.begin(), - projectParts.end(), - [](const CppTools::ProjectPart *projectPart) { - return !projectPart->selectedForBuilding; - }), - projectParts.end()); - - std::vector projectPartContainers; - projectPartContainers.reserve(projectParts.size()); - - std::transform(projectParts.begin(), - projectParts.end(), - std::back_inserter(projectPartContainers), - std::bind(&ProjectUpdater::toProjectPartContainer, this, _1)); - - std::sort(projectPartContainers.begin(), projectPartContainers.end()); - - return projectPartContainers; -} - -ClangBackEnd::FilePaths ProjectUpdater::createExcludedPaths( - const ClangBackEnd::V2::FileContainers &generatedFiles) -{ - ClangBackEnd::FilePaths excludedPaths; - excludedPaths.reserve(generatedFiles.size()); - - auto convertToPath = [] (const ClangBackEnd::V2::FileContainer &fileContainer) { - return fileContainer.filePath; - }; - - std::transform(generatedFiles.begin(), - generatedFiles.end(), - std::back_inserter(excludedPaths), - convertToPath); - - std::sort(excludedPaths.begin(), excludedPaths.end()); - - return excludedPaths; -} - -QString ProjectUpdater::fetchProjectPartName(ClangBackEnd::ProjectPartId projectPartId) const -{ - return QString(m_projectPartIdCache.string(projectPartId.projectPathId, - [&](ClangBackEnd::ProjectPartId projectPartId) { - return m_projectPartsStorage.fetchProjectPartName( - projectPartId); - })); -} - -ClangBackEnd::ProjectPartIds ProjectUpdater::toProjectPartIds( - const QStringList &projectPartNamesAsQString) const -{ - ClangBackEnd::ProjectPartIds projectPartIds; - projectPartIds.reserve(projectPartIds.size()); - - auto projectPartNames = Utils::transform>( - projectPartNamesAsQString, [&](const QString &projectPartName) { return projectPartName; }); - - return m_projectPartIdCache.stringIds(projectPartNames, [&](Utils::SmallStringView projectPartName) { - return m_projectPartsStorage.fetchProjectPartId(projectPartName); - }); -} - -void ProjectUpdater::addProjectFilesToFilePathCache(const std::vector &projectParts) -{ - ClangBackEnd::FilePaths filePaths; - filePaths.reserve(10000); - - for (CppTools::ProjectPart *projectPart : projectParts) { - for (const CppTools::ProjectFile &file : projectPart->files) - if (file.active) - filePaths.emplace_back(file.path); - } - - m_filePathCache.addFilePaths(filePaths); -} - -void ProjectUpdater::fetchProjectPartIds(const std::vector &projectParts) -{ - std::unique_ptr transaction; - - auto projectPartNames = Utils::transform>( - projectParts, [](CppTools::ProjectPart *projectPart) { return projectPart->id(); }); - - auto projectPartNameViews = Utils::transform>( - projectPartNames, - [](const Utils::PathString &projectPartName) { return projectPartName.toStringView(); }); - - m_projectPartIdCache - .addStrings(std::move(projectPartNameViews), [&](Utils::SmallStringView projectPartName) { - if (!transaction) - transaction = std::make_unique( - m_projectPartsStorage.transactionBackend()); - return m_projectPartsStorage.fetchProjectPartIdUnguarded(projectPartName); - }); - - if (transaction) - transaction->commit(); - -} // namespace ClangPchManager - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/projectupdater.h b/src/plugins/clangpchmanager/projectupdater.h deleted file mode 100644 index 0b3865d7b41..00000000000 --- a/src/plugins/clangpchmanager/projectupdater.h +++ /dev/null @@ -1,143 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangpchmanager_global.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -namespace ProjectExplorer { -class Macro; -using Macros = QVector; -} - -namespace CppTools { -class ProjectPart; -class ProjectFile; -} - -namespace ClangBackEnd { -class ProjectManagementServerInterface; -} - -#include - -namespace ClangPchManager { - -class HeaderAndSources; -class PchManagerClient; -class ClangIndexingSettingsManager; -class ClangIndexingProjectSettings; - -class CLANGPCHMANAGER_EXPORT ProjectUpdater -{ - using StringCache = ClangBackEnd::StringCache; - -public: - struct SystemAndProjectIncludeSearchPaths - { - ClangBackEnd::IncludeSearchPaths system; - ClangBackEnd::IncludeSearchPaths project; - }; - - ProjectUpdater(ClangBackEnd::ProjectManagementServerInterface &server, - ClangBackEnd::FilePathCachingInterface &filePathCache, - ClangBackEnd::ProjectPartsStorageInterface &projectPartsStorage, - ClangIndexingSettingsManager &settingsManager) - : m_filePathCache(filePathCache) - , m_server(server) - , m_projectPartsStorage(projectPartsStorage) - , m_settingsManager(settingsManager) - { - m_projectPartIdCache.populate(m_projectPartsStorage.fetchAllProjectPartNamesAndIds()); - } - - void updateProjectParts(const std::vector &projectParts, - Utils::SmallStringVector &&toolChainArguments); - void removeProjectParts(ClangBackEnd::ProjectPartIds projectPartIds); - - void updateGeneratedFiles(ClangBackEnd::V2::FileContainers &&generatedFiles); - void removeGeneratedFiles(ClangBackEnd::FilePaths &&filePaths); - - void setExcludedPaths(ClangBackEnd::FilePaths &&excludedPaths); - const ClangBackEnd::FilePaths &excludedPaths() const; - - const ClangBackEnd::GeneratedFiles &generatedFiles() const; - - HeaderAndSources headerAndSourcesFromProjectPart(CppTools::ProjectPart *projectPart) const; - ClangBackEnd::ProjectPartContainer toProjectPartContainer( - CppTools::ProjectPart *projectPart) const; - ClangBackEnd::ProjectPartContainers toProjectPartContainers( - std::vector projectParts) const; - - void addToHeaderAndSources(HeaderAndSources &headerAndSources, - const CppTools::ProjectFile &projectFile) const; - static QStringList toolChainArguments(CppTools::ProjectPart *projectPart); - static ClangBackEnd::CompilerMacros createCompilerMacros(const ProjectExplorer::Macros &projectMacros, - Utils::NameValueItems &&settingsMacros); - static SystemAndProjectIncludeSearchPaths createIncludeSearchPaths( - const CppTools::ProjectPart &projectPart); - static ClangBackEnd::FilePaths createExcludedPaths( - const ClangBackEnd::V2::FileContainers &generatedFiles); - - QString fetchProjectPartName(ClangBackEnd::ProjectPartId projectPartId) const; - - ClangBackEnd::ProjectPartIds toProjectPartIds(const QStringList &projectPartNames) const; - - void addProjectFilesToFilePathCache(const std::vector &projectParts); - void fetchProjectPartIds(const std::vector &projectParts); - -protected: - ClangBackEnd::FilePathCachingInterface &m_filePathCache; - -private: - ClangBackEnd::GeneratedFiles m_generatedFiles; - ClangBackEnd::FilePaths m_excludedPaths; - ClangBackEnd::ProjectManagementServerInterface &m_server; - ClangBackEnd::ProjectPartsStorageInterface &m_projectPartsStorage; - ClangIndexingSettingsManager &m_settingsManager; - mutable StringCache m_projectPartIdCache; -}; - -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/qtcreatorprojectupdater.cpp b/src/plugins/clangpchmanager/qtcreatorprojectupdater.cpp deleted file mode 100644 index 9a3b1498cc2..00000000000 --- a/src/plugins/clangpchmanager/qtcreatorprojectupdater.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "qtcreatorprojectupdater.h" - -#include - -#include - -#include - -namespace ClangPchManager { - -namespace Internal { - -CppTools::CppModelManager *cppModelManager() -{ - return CppTools::CppModelManager::instance(); -} - -std::vector createGeneratedFiles( - ClangBackEnd::FilePathCachingInterface &filePathCache) -{ - auto abstractEditors = CppTools::CppModelManager::instance()->abstractEditorSupports(); - std::vector generatedFiles; - generatedFiles.reserve(std::size_t(abstractEditors.size())); - - auto toFileContainer = [&](const CppTools::AbstractEditorSupport *abstractEditor) { - ClangBackEnd::FilePath filePath(abstractEditor->fileName()); - ClangBackEnd::FilePathId filePathId = filePathCache.filePathId(filePath); - return ClangBackEnd::V2::FileContainer(std::move(filePath), - filePathId, - Utils::SmallString::fromQByteArray( - abstractEditor->contents()), - {}); - }; - - std::transform(abstractEditors.begin(), - abstractEditors.end(), - std::back_inserter(generatedFiles), - toFileContainer); - - std::sort(generatedFiles.begin(), generatedFiles.end()); - - return generatedFiles; -} - -std::vector createProjectParts(ProjectExplorer::Project *project) -{ - const CppTools::ProjectInfo projectInfo = cppModelManager()->projectInfo(project); - - const QVector projectPartSharedPointers = projectInfo.projectParts(); - - std::vector projectParts; - projectParts.reserve(std::size_t(projectPartSharedPointers.size())); - - auto convertToRawPointer = [] (const CppTools::ProjectPart::Ptr &sharedPointer) { - return sharedPointer.data(); - }; - - std::transform(projectPartSharedPointers.begin(), - projectPartSharedPointers.end(), - std::back_inserter(projectParts), - convertToRawPointer); - - return projectParts; - -} -} // namespace Internal -} // namespace ClangPchManager diff --git a/src/plugins/clangpchmanager/qtcreatorprojectupdater.h b/src/plugins/clangpchmanager/qtcreatorprojectupdater.h deleted file mode 100644 index bd3617329cb..00000000000 --- a/src/plugins/clangpchmanager/qtcreatorprojectupdater.h +++ /dev/null @@ -1,145 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "pchmanagerprojectupdater.h" - -#include -#include - -#include - -#include - -#include - -namespace ProjectExplorer { -class Project; -} - -namespace CppTools { -class CppModelManager; -} - -namespace ClangPchManager { - -namespace Internal { -CLANGPCHMANAGER_EXPORT CppTools::CppModelManager *cppModelManager(); -CLANGPCHMANAGER_EXPORT std::vector createGeneratedFiles( - ClangBackEnd::FilePathCachingInterface &filePathCache); -CLANGPCHMANAGER_EXPORT std::vector createProjectParts(ProjectExplorer::Project *project); -} - -template -class QtCreatorProjectUpdater : public ProjectUpdaterType, - public ProjectExplorer::ExtraCompilerFactoryObserver -{ -public: - template - QtCreatorProjectUpdater(ClangBackEnd::ProjectManagementServerInterface &server, - ClientType &client, - ClangBackEnd::FilePathCachingInterface &filePathCache, - ClangBackEnd::ProjectPartsStorageInterface &projectPartsStorage, - ClangIndexingSettingsManager &settingsManager) - : ProjectUpdaterType(server, client, filePathCache, projectPartsStorage, settingsManager) - { - connectToCppModelManager(); - } - - QtCreatorProjectUpdater(ClangBackEnd::ProjectManagementServerInterface &server, - ClangBackEnd::FilePathCachingInterface &filePathCache) - : ProjectUpdaterType(server, filePathCache) - { - connectToCppModelManager(); - } - - void projectPartsUpdated(ProjectExplorer::Project *project) - { - ProjectUpdaterType::updateProjectParts(Internal::createProjectParts(project), {}); // TODO add support for toolchainarguments - } - - void projectPartsRemoved(const QStringList &projectPartIds) - { - ProjectUpdaterType::removeProjectParts(projectPartIds); - } - - void abstractEditorUpdated(const QString &qFilePath, const QByteArray &contents) - { - ClangBackEnd::FilePath filePath{qFilePath}; - ClangBackEnd::FilePathId filePathId = ProjectUpdaterType::m_filePathCache.filePathId( - filePath); - - ProjectUpdaterType::updateGeneratedFiles({{std::move(filePath), filePathId, contents}}); - } - - void abstractEditorRemoved(const QString &filePath) - { - ProjectUpdaterType::removeGeneratedFiles({ClangBackEnd::FilePath{filePath}}); - } - -protected: - void newExtraCompiler(const ProjectExplorer::Project *, - const Utils::FilePath &, - const Utils::FilePaths &targets) override - { - auto filePaths = Utils::transform(targets, - [](const Utils::FilePath &filePath) { - return ClangBackEnd::FilePath{ - filePath.toString()}; - }); - - ProjectUpdater::m_filePathCache.addFilePaths(filePaths); - - for (const Utils::FilePath &target : targets) - abstractEditorUpdated(target.toString(), {}); - } - -private: - void connectToCppModelManager() - { - ProjectUpdaterType::updateGeneratedFiles( - Internal::createGeneratedFiles(ProjectUpdaterType::m_filePathCache)); - - QObject::connect(Internal::cppModelManager(), - &CppTools::CppModelManager::projectPartsUpdated, - [&] (ProjectExplorer::Project *project) { projectPartsUpdated(project); }); - QObject::connect(Internal::cppModelManager(), - &CppTools::CppModelManager::projectPartsRemoved, - [&] (const QStringList &projectPartIds) { projectPartsRemoved(projectPartIds); }); - QObject::connect(Internal::cppModelManager(), - &CppTools::CppModelManager::abstractEditorSupportContentsUpdated, - [&](const QString &filePath, - const QString &, - const QByteArray &contents) { - abstractEditorUpdated(filePath, contents); - }); - QObject::connect(Internal::cppModelManager(), - &CppTools::CppModelManager::abstractEditorSupportRemoved, - [&] (const QString &filePath) { abstractEditorRemoved(filePath); }); - } -}; - -} // namespace ClangPchManager diff --git a/src/plugins/clangrefactoring/CMakeLists.txt b/src/plugins/clangrefactoring/CMakeLists.txt deleted file mode 100644 index 37b3221e451..00000000000 --- a/src/plugins/clangrefactoring/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -add_qtc_plugin(ClangRefactoring - BUILD_DEFAULT OFF - CONDITION TARGET libclang AND QTC_CLANG_BUILDMODE_MATCH - DEPENDS ClangSupport CPlusPlus - PLUGIN_DEPENDS Core CppTools TextEditor ClangPchManager - SOURCES ${TEST_SOURCES} - baseclangquerytexteditorwidget.cpp baseclangquerytexteditorwidget.h - clangqueryexamplehighlighter.cpp clangqueryexamplehighlighter.h - clangqueryexamplehighlightmarker.h - clangqueryexampletexteditorwidget.cpp clangqueryexampletexteditorwidget.h - clangqueryhighlighter.cpp clangqueryhighlighter.h - clangqueryhighlightmarker.h - clangqueryhoverhandler.cpp clangqueryhoverhandler.h - clangqueryprojectsfindfilter.cpp clangqueryprojectsfindfilter.h clangqueryprojectsfindfilter.ui - clangqueryprojectsfindfilterwidget.cpp clangqueryprojectsfindfilterwidget.h - clangquerytexteditorwidget.cpp clangquerytexteditorwidget.h - clangrefactoringplugin.cpp clangrefactoringplugin.h - editormanagerinterface.h - locatorfilter.cpp locatorfilter.h - projectpartproviderinterface.h - projectpartutilities.cpp projectpartutilities.h - qtcreatorclangqueryfindfilter.cpp qtcreatorclangqueryfindfilter.h - qtcreatoreditormanager.cpp qtcreatoreditormanager.h - qtcreatorrefactoringprojectupdater.cpp qtcreatorrefactoringprojectupdater.h - qtcreatorsearch.cpp qtcreatorsearch.h - qtcreatorsearchhandle.cpp qtcreatorsearchhandle.h - qtcreatorsymbolsfindfilter.cpp qtcreatorsymbolsfindfilter.h - querysqlitestatementfactory.h - refactoringclient.cpp refactoringclient.h - refactoringconnectionclient.cpp refactoringconnectionclient.h - refactoringengine.cpp refactoringengine.h - refactoringprojectupdater.cpp refactoringprojectupdater.h - searchhandle.cpp searchhandle.h - searchinterface.h - sourcelocations.h - symbol.h - symbolquery.h - symbolqueryinterface.h - clangsymbolsfindfilter.cpp clangsymbolsfindfilter.h - symbolsfindfilterconfigwidget.cpp symbolsfindfilterconfigwidget.h -) diff --git a/src/plugins/clangrefactoring/ClangRefactoring.json.in b/src/plugins/clangrefactoring/ClangRefactoring.json.in deleted file mode 100644 index 3992dbeebd5..00000000000 --- a/src/plugins/clangrefactoring/ClangRefactoring.json.in +++ /dev/null @@ -1,20 +0,0 @@ -{ - \"Name\" : \"ClangRefactoring\", - \"Version\" : \"$$QTCREATOR_VERSION\", - \"CompatVersion\" : \"$$QTCREATOR_COMPAT_VERSION\", - \"Experimental\" : true, - \"Vendor\" : \"The Qt Company Ltd\", - \"Copyright\" : \"(C) $$QTCREATOR_COPYRIGHT_YEAR The Qt Company Ltd\", - \"License\" : [ \"Commercial Usage\", - \"\", - \"Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt 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.\", - \"\", - \"GNU General Public License Usage\", - \"\", - \"Alternatively, this plugin 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 plugin. 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.\" - ], - \"Category\" : \"C++\", - \"Description\" : \"Clang Refactoring plugin.\", - \"Url\" : \"http://www.qt.io\", - $$dependencyList -} diff --git a/src/plugins/clangrefactoring/baseclangquerytexteditorwidget.cpp b/src/plugins/clangrefactoring/baseclangquerytexteditorwidget.cpp deleted file mode 100644 index 29f53c71d1e..00000000000 --- a/src/plugins/clangrefactoring/baseclangquerytexteditorwidget.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "baseclangquerytexteditorwidget.h" - -#include - -namespace ClangRefactoring { - -BaseClangQueryTextEditorWidget::BaseClangQueryTextEditorWidget(QWidget *parent) - : TextEditor::TextEditorWidget(parent) -{ - setupFallBackEditor(Utils::Id()); - setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); - setHighlightCurrentLine(false); - setLineNumbersVisible(false); - setParenthesesMatchingEnabled(true); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/baseclangquerytexteditorwidget.h b/src/plugins/clangrefactoring/baseclangquerytexteditorwidget.h deleted file mode 100644 index b7f54a53259..00000000000 --- a/src/plugins/clangrefactoring/baseclangquerytexteditorwidget.h +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -namespace ClangRefactoring { - -class BaseClangQueryTextEditorWidget : public TextEditor::TextEditorWidget -{ - Q_OBJECT - -public: - BaseClangQueryTextEditorWidget(QWidget *parent); -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangqueryexamplehighlighter.cpp b/src/plugins/clangrefactoring/clangqueryexamplehighlighter.cpp deleted file mode 100644 index 5fc59574c7d..00000000000 --- a/src/plugins/clangrefactoring/clangqueryexamplehighlighter.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "clangqueryexamplehighlighter.h" - -#include - -#include - - -namespace ClangRefactoring { - -ClangQueryExampleHighlighter::ClangQueryExampleHighlighter() - : m_marker(*this) -{ - std::array textFormats; - textFormats[0].setBackground(QColor(0xc9, 0xff, 0xc3)); - textFormats[1].setBackground(QColor(0xc3, 0xd9, 0xff)); - textFormats[2].setBackground(QColor(0xe5, 0xc3, 0xff)); - textFormats[3].setBackground(QColor(0xff, 0xc3, 0xcb)); - textFormats[4].setBackground(QColor(0xff, 0xe8, 0xc3)); - - m_marker.setTextFormats(std::move(textFormats)); - - setNoAutomaticHighlighting(true); -} - -void ClangQueryExampleHighlighter::setSourceRanges(ClangBackEnd::SourceRangesContainer &&container) -{ - m_marker.setSourceRanges(container.takeSourceRangeWithTextContainers()); - rehighlight(); -} - -void ClangQueryExampleHighlighter::highlightBlock(const QString &text) -{ - int currentLineNumber = currentBlock().blockNumber() + 1; - m_marker.highlightBlock(uint(currentLineNumber), text); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangqueryexamplehighlighter.h b/src/plugins/clangrefactoring/clangqueryexamplehighlighter.h deleted file mode 100644 index 6c943644dc6..00000000000 --- a/src/plugins/clangrefactoring/clangqueryexamplehighlighter.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "clangqueryexamplehighlightmarker.h" - -#include - -#include - -namespace ClangBackEnd { -class SourceRangesContainer; -} - -namespace ClangRefactoring { - -class ClangQueryExampleHighlighter : public TextEditor::SyntaxHighlighter -{ - friend ClangQueryExampleHighlightMarker; - -public: - ClangQueryExampleHighlighter(); - - void setSourceRanges(ClangBackEnd::SourceRangesContainer &&container); - -protected: - void highlightBlock(const QString &text) override; - -private: - ClangQueryExampleHighlightMarker m_marker; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangqueryexamplehighlightmarker.h b/src/plugins/clangrefactoring/clangqueryexamplehighlightmarker.h deleted file mode 100644 index d3a6bab652e..00000000000 --- a/src/plugins/clangrefactoring/clangqueryexamplehighlightmarker.h +++ /dev/null @@ -1,220 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -#include -#include - -namespace ClangRefactoring { - -template -class ClangQueryExampleHighlightMarker -{ - using SourceRange = ClangBackEnd::V2::SourceRangeContainer; - using SourceRanges = ClangBackEnd::V2::SourceRangeContainers; - using SourceRangeWithTexts = ClangBackEnd::SourceRangeWithTextContainers; -public: - ClangQueryExampleHighlightMarker(SourceRangeWithTexts &&sourceRanges, - SyntaxHighlighter &highlighter, - const std::array &textFormats) - : m_sourceRanges(std::move(sourceRanges)), - m_currentSourceRangeIterator(m_sourceRanges.begin()), - m_highlighter(highlighter), - m_textFormats(textFormats) - { - } - - ClangQueryExampleHighlightMarker(SyntaxHighlighter &highlighter) - : m_currentSourceRangeIterator(m_sourceRanges.begin()), - m_highlighter(highlighter) - { - } - - void setTextFormats(std::array &&textFormats) - { - m_textFormats = std::move(textFormats); - } - - void setSourceRanges(SourceRangeWithTexts &&sourceRanges) - { - m_currentlyUsedSourceRanges.clear(); - m_sourceRanges = std::move(sourceRanges); - m_currentSourceRangeIterator = m_sourceRanges.begin(); - } - - void highlightSourceRanges(uint currentLineNumber, const QString ¤tText) - { - while (hasSourceRangesForCurrentLine(currentLineNumber)) { - SourceRange &sourceRange = *m_currentSourceRangeIterator; - - popSourceRangeIfMultiLineEndsHere(currentLineNumber, sourceRange.start.column); - - formatSourceRange(sourceRange, - currentLineNumber, - currentText.size(), - int(m_currentlyUsedSourceRanges.size())); - - pushSourceRangeIfMultiLine(sourceRange); - ++m_currentSourceRangeIterator; - } - } - - void highlightCurrentlyUsedSourceRanges(uint currentLineNumber, const QString ¤tText) - { - formatCurrentlyUsedSourceRanges(currentLineNumber, currentText.size()); - popSourceRangeIfMultiLineEndsHereAndAllSourceRangesAreConsumed(currentLineNumber); - } - - void highlightBlock(uint currentLineNumber, const QString ¤tText) - { - popSourceRangeIfMultiLineEndedBefore(currentLineNumber); - highlightCurrentlyUsedSourceRanges(currentLineNumber, currentText); - highlightSourceRanges(currentLineNumber, currentText); - } - - bool hasSourceRangesForCurrentLine(uint currentLineNumber) const - { - return m_currentSourceRangeIterator != m_sourceRanges.end() - && m_currentSourceRangeIterator->start.line == currentLineNumber; - } - - bool hasOnlySCurrentlyUsedSourceRanges() const - { - return m_currentSourceRangeIterator == m_sourceRanges.end() - && !m_currentlyUsedSourceRanges.empty(); - } - - void formatSingleSourceRange(const SourceRange &sourceRange, - int textFormatIndex) - { - int size = int(sourceRange.end.column - sourceRange.start.column); - m_highlighter.setFormat(int(sourceRange.start.column) - 1, - size, - m_textFormats[textFormatIndex]); - } - - void formatStartMultipleSourceRange(const SourceRange &sourceRange, - int textSize, - int textFormatIndex) - { - int size = textSize - int(sourceRange.start.column) + 1; - m_highlighter.setFormat(int(sourceRange.start.column) - 1, - size, - m_textFormats[textFormatIndex]); - } - - void formatEndMultipleSourceRange(const SourceRange &sourceRange, - int textFormatIndex) - { - int size = int(sourceRange.end.column) - 1; - m_highlighter.setFormat(0, size, m_textFormats[textFormatIndex]); - } - - void formatMiddleMultipleSourceRange(int textSize, - int textFormatIndex) - { - m_highlighter.setFormat(0, textSize, m_textFormats[textFormatIndex]); - } - - void formatSourceRange(const SourceRange &sourceRange, - uint currentLineNumber, - int textSize, - int textFormatIndex) - { - if (sourceRange.start.line == sourceRange.end.line) - formatSingleSourceRange(sourceRange, textFormatIndex); - else if (sourceRange.start.line == currentLineNumber) - formatStartMultipleSourceRange(sourceRange, textSize, textFormatIndex); - else if (sourceRange.end.line == currentLineNumber) - formatEndMultipleSourceRange(sourceRange, textFormatIndex); - else - formatMiddleMultipleSourceRange(textSize, textFormatIndex); - } - - void formatCurrentlyUsedSourceRanges(uint currentLineNumber, int textSize) - { - int textFormatIndex = 0; - - for (const SourceRange &sourceRange : m_currentlyUsedSourceRanges) { - formatSourceRange(sourceRange, currentLineNumber, textSize, textFormatIndex); - ++textFormatIndex; - } - } - - bool currentlyUsedHasEndLineAndColumnNumber(uint currentLineNumber, uint currentColumnNumber) - { - return !m_currentlyUsedSourceRanges.empty() - && m_currentlyUsedSourceRanges.back().end.line <= currentLineNumber - && m_currentlyUsedSourceRanges.back().end.column <= currentColumnNumber; - } - - void popSourceRangeIfMultiLineEndsHere(uint currentLineNumber, uint currentColumnNumber) - { - while (currentlyUsedHasEndLineAndColumnNumber(currentLineNumber, currentColumnNumber)) - m_currentlyUsedSourceRanges.pop_back(); - } - - bool currentlyUsedHasEndLineNumberAndSourceRangesAreConsumed(uint currentLineNumber) - { - return !m_currentlyUsedSourceRanges.empty() - && m_currentSourceRangeIterator == m_sourceRanges.end() - && m_currentlyUsedSourceRanges.back().end.line == currentLineNumber; - } - - void popSourceRangeIfMultiLineEndsHereAndAllSourceRangesAreConsumed(uint currentLineNumber) - { - while (currentlyUsedHasEndLineNumberAndSourceRangesAreConsumed(currentLineNumber)) - m_currentlyUsedSourceRanges.pop_back(); - } - - bool currentlyUsedHasEndedBeforeLineNumber(uint currentLineNumber) - { - return !m_currentlyUsedSourceRanges.empty() - && m_currentlyUsedSourceRanges.back().end.line < currentLineNumber; - } - - void popSourceRangeIfMultiLineEndedBefore(uint currentLineNumber) - { - while (currentlyUsedHasEndedBeforeLineNumber(currentLineNumber)) - m_currentlyUsedSourceRanges.pop_back(); - } - - void pushSourceRangeIfMultiLine(SourceRange &sourceRange) - { - m_currentlyUsedSourceRanges.push_back(sourceRange); - } - -private: - SourceRangeWithTexts m_sourceRanges; - SourceRangeWithTexts::iterator m_currentSourceRangeIterator; - SourceRanges m_currentlyUsedSourceRanges; - SyntaxHighlighter &m_highlighter; - std::array m_textFormats; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangqueryexampletexteditorwidget.cpp b/src/plugins/clangrefactoring/clangqueryexampletexteditorwidget.cpp deleted file mode 100644 index 79ff5576b92..00000000000 --- a/src/plugins/clangrefactoring/clangqueryexampletexteditorwidget.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "clangqueryexampletexteditorwidget.h" - -#include "clangqueryexamplehighlighter.h" - -#include - -namespace ClangRefactoring { - -ClangQueryExampleTextEditorWidget::ClangQueryExampleTextEditorWidget(QWidget *parent) - : BaseClangQueryTextEditorWidget(parent) -{ - m_syntaxHighlighter = new ClangQueryExampleHighlighter; - textDocument()->setSyntaxHighlighter(m_syntaxHighlighter); - textDocument()->setPlainText("class Foo {\n void function() { int local; }\n int field;\n};"); -} - -ClangQueryExampleHighlighter *ClangQueryExampleTextEditorWidget::syntaxHighlighter() const -{ - return m_syntaxHighlighter; -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangqueryexampletexteditorwidget.h b/src/plugins/clangrefactoring/clangqueryexampletexteditorwidget.h deleted file mode 100644 index 0a86f502206..00000000000 --- a/src/plugins/clangrefactoring/clangqueryexampletexteditorwidget.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "baseclangquerytexteditorwidget.h" - -namespace ClangRefactoring { - -class ClangQueryExampleHighlighter; - -class ClangQueryExampleTextEditorWidget : public BaseClangQueryTextEditorWidget -{ - Q_OBJECT - -public: - ClangQueryExampleTextEditorWidget(QWidget *parent); - - ClangQueryExampleHighlighter *syntaxHighlighter() const; - -private: - ClangQueryExampleHighlighter *m_syntaxHighlighter; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangqueryhighlighter.cpp b/src/plugins/clangrefactoring/clangqueryhighlighter.cpp deleted file mode 100644 index 050904b0a3b..00000000000 --- a/src/plugins/clangrefactoring/clangqueryhighlighter.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "clangqueryhighlighter.h" - -#include -#include -#include - -#include - -namespace ClangRefactoring { - -ClangQueryHighlighter::ClangQueryHighlighter() - : m_marker(*this) -{ -#ifndef UNIT_TESTS - TextEditor::FontSettings fontSettings = TextEditor::TextEditorSettings::fontSettings(); - - m_marker.setTextFormats(fontSettings.toTextCharFormat(TextEditor::C_ERROR), - fontSettings.toTextCharFormat(TextEditor::C_ERROR_CONTEXT)); -#endif - - setNoAutomaticHighlighting(true); -} - -void ClangQueryHighlighter::setDiagnostics( - const ClangBackEnd::DynamicASTMatcherDiagnosticContainers &diagnostics) -{ - using Messages = ClangBackEnd::DynamicASTMatcherDiagnosticMessageContainers; - using Contexts = ClangBackEnd::DynamicASTMatcherDiagnosticContextContainers; - - Messages messages; - Contexts contexts; - - for (const ClangBackEnd::DynamicASTMatcherDiagnosticContainer &diagnostic : diagnostics) { - const Messages &newMessages = diagnostic.messages; - const Contexts &newContexts = diagnostic.contexts; - std::copy(newMessages.begin(), newMessages.end(), std::back_inserter(messages)); - std::copy(newContexts.begin(), newContexts.end(), std::back_inserter(contexts)); - } - - m_marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); - - rehighlight(); -} - -bool ClangQueryHighlighter::hasDiagnostics() const -{ - return m_marker.hasMessagesOrContexts(); -} - -ClangBackEnd::DynamicASTMatcherDiagnosticMessageContainers -ClangQueryHighlighter::messagesForLineAndColumn(uint line, uint column) const -{ - return m_marker.messagesForLineAndColumn(line, column); -} - -ClangBackEnd::DynamicASTMatcherDiagnosticContextContainers -ClangQueryHighlighter::contextsForLineAndColumn(uint line, uint column) const -{ - return m_marker.contextsForLineAndColumn(line, column); -} - -void ClangQueryHighlighter::highlightBlock(const QString &text) -{ - int currentLineNumber = currentBlock().blockNumber() + 1; - m_marker.highlightBlock(uint(currentLineNumber), text); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangqueryhighlighter.h b/src/plugins/clangrefactoring/clangqueryhighlighter.h deleted file mode 100644 index 7e96a1a5f90..00000000000 --- a/src/plugins/clangrefactoring/clangqueryhighlighter.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "clangqueryhighlightmarker.h" - -#include - -#include - -namespace ClangRefactoring { - -class ClangQueryHighlighter : public TextEditor::SyntaxHighlighter -{ - friend class ClangQueryHighlightMarker; - -public: - ClangQueryHighlighter(); - - void setDiagnostics(const ClangBackEnd::DynamicASTMatcherDiagnosticContainers &diagnostics); - - bool hasDiagnostics() const; - - ClangBackEnd::DynamicASTMatcherDiagnosticMessageContainers - messagesForLineAndColumn(uint line, uint column) const; - - ClangBackEnd::DynamicASTMatcherDiagnosticContextContainers - contextsForLineAndColumn(uint line, uint column) const; - -protected: - void highlightBlock(const QString &text) override; - -private: - ClangQueryHighlightMarker m_marker; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangqueryhighlightmarker.h b/src/plugins/clangrefactoring/clangqueryhighlightmarker.h deleted file mode 100644 index fbe7d31208f..00000000000 --- a/src/plugins/clangrefactoring/clangqueryhighlightmarker.h +++ /dev/null @@ -1,345 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include -#include -#include - -#include -#include - -namespace ClangRefactoring { - -template -class ClangQueryHighlightMarker -{ - using SourceRange = ClangBackEnd::V2::SourceRangeContainer; - using Message = ClangBackEnd::DynamicASTMatcherDiagnosticMessageContainer; - using Context = ClangBackEnd::DynamicASTMatcherDiagnosticContextContainer; - using Messages = ClangBackEnd::DynamicASTMatcherDiagnosticMessageContainers; - using Contexts = ClangBackEnd::DynamicASTMatcherDiagnosticContextContainers; - -public: - ClangQueryHighlightMarker(SyntaxHighlighter &highlighter) - : m_highlighter(highlighter) - { - } - - void setTextFormats(const QTextCharFormat &messageTextFormat, - const QTextCharFormat &contextTextFormat) - { - m_contextTextFormat = contextTextFormat; - m_messageTextFormat = messageTextFormat; - } - - void setMessagesAndContexts(Messages &&messages, Contexts &&contexts) - { - m_currentlyUsedContexts.clear(); - m_currentlyUsedMessages.clear(); - m_contexts = std::move(contexts); - m_messages = std::move(messages); - m_currentContextsIterator = m_contexts.begin(); - m_currentMessagesIterator = m_messages.begin(); - } - - bool hasMessage(uint currentLineNumber) const - { - return m_currentMessagesIterator != m_messages.end() - && m_currentMessagesIterator->sourceRange.start.line == currentLineNumber; - } - - bool hasContext(uint currentLineNumber) const - { - return m_currentContextsIterator != m_contexts.end() - && m_currentContextsIterator->sourceRange.start.line == currentLineNumber; - } - - bool isMessageNext() const - { - return m_currentMessagesIterator->sourceRange.start.column - < m_currentContextsIterator->sourceRange.start.column; - } - - void formatSameLineSourceRange(const SourceRange &sourceRange, const QTextCharFormat &textFormat) - { - uint startColumn = sourceRange.start.column; - uint endColumn = sourceRange.end.column; - m_highlighter.setFormat(startColumn - 1, endColumn - startColumn, textFormat); - } - - void formatStartLineSourceRange(const SourceRange &sourceRange, - int textSize, - const QTextCharFormat &textFormat) - { - uint startColumn = sourceRange.start.column; - m_highlighter.setFormat(startColumn - 1, textSize - startColumn, textFormat); - } - - void formatEndLineSourceRange(const SourceRange &sourceRange, const QTextCharFormat &textFormat) - { - uint endColumn = sourceRange.end.column; - m_highlighter.setFormat(0, endColumn - 1, textFormat); - } - - void formatMiddleLineSourceRange(int textSize, const QTextCharFormat &textFormat) - { - m_highlighter.setFormat(0, textSize, textFormat); - } - - static - bool isSameLine(const SourceRange &sourceRange) - { - uint startLine = sourceRange.start.line; - uint endLine = sourceRange.end.line; - - return startLine == endLine; - } - - static - bool isStartLine(const SourceRange &sourceRange, uint currentLineNumber) - { - uint startLine = sourceRange.start.line; - - return startLine == currentLineNumber; - } - - static - bool isEndLine(const SourceRange &sourceRange, uint currentLineNumber) - { - uint endLine = sourceRange.end.line; - - return endLine == currentLineNumber; - } - - void formatLine(const SourceRange &sourceRange, - uint currentLineNumber, - int textSize, - const QTextCharFormat &textFormat) - { - if (isSameLine(sourceRange)) - formatSameLineSourceRange(sourceRange, textFormat); - else if (isStartLine(sourceRange, currentLineNumber)) - formatStartLineSourceRange(sourceRange, textSize, textFormat); - else if (isEndLine(sourceRange, currentLineNumber)) - formatEndLineSourceRange(sourceRange, textFormat); - else - formatMiddleLineSourceRange(textSize, textFormat); - } - - template - void format(Container &container, - typename Container::iterator &iterator, - uint currentLineNumber, - int textSize, - const QTextCharFormat &textFormat) - { - const SourceRange &sourceRange = iterator->sourceRange; - - formatLine(sourceRange, currentLineNumber, textSize, textFormat); - - if (isStartLine(sourceRange, currentLineNumber)) - container.push_back(*iterator); - - if (isSameLine(sourceRange) || isStartLine(sourceRange, currentLineNumber)) - ++iterator; - } - - template - static - void removeEndedContainers(uint currentLineNumber, Container &container) - { - auto newEnd = std::remove_if(container.begin(), - container.end(), - [&] (const auto &entry) { - return ClangQueryHighlightMarker::isEndLine(entry.sourceRange, currentLineNumber); - }); - - container.erase(newEnd, container.end()); - } - - template - void formatCurrentlyUsed(Container container, - uint currentLineNumber, - int textSize, - const QTextCharFormat &textFormat) - { - for (const auto &entry : container) { - formatLine(entry.sourceRange, currentLineNumber, textSize, textFormat);; - } - } - - void formatMessage(uint currentLineNumber, int textSize) - { - format(m_currentlyUsedMessages, - m_currentMessagesIterator, - currentLineNumber, - textSize, - m_messageTextFormat); - } - - void formatContext(uint currentLineNumber, int textSize) - { - format(m_currentlyUsedContexts, - m_currentContextsIterator, - currentLineNumber, - textSize, - m_contextTextFormat); - } - - void formatCurrentlyUsedMessagesAndContexts(uint currentLineNumber, int textSize) - { - formatCurrentlyUsed(m_currentlyUsedContexts, currentLineNumber, textSize, m_contextTextFormat); - formatCurrentlyUsed(m_currentlyUsedMessages, currentLineNumber, textSize, m_messageTextFormat); - - removeEndedContainers(currentLineNumber, m_currentlyUsedContexts); - removeEndedContainers(currentLineNumber, m_currentlyUsedMessages); - } - - void formatCurrentMessageOrContext(uint currentLineNumber, int textSize) - { - bool hasContext = this->hasContext(currentLineNumber); - bool hasMessage = this->hasMessage(currentLineNumber); - - while (hasContext || hasMessage) { - if (!hasContext) - formatMessage(currentLineNumber, textSize); - else if (!hasMessage) - formatContext(currentLineNumber, textSize); - else if (isMessageNext()) - formatMessage(currentLineNumber, textSize); - else - formatContext(currentLineNumber, textSize); - - hasContext = this->hasContext(currentLineNumber); - hasMessage = this->hasMessage(currentLineNumber); - } - } - - void highlightBlock(uint currentLineNumber, const QString ¤tText) - { - formatCurrentlyUsedMessagesAndContexts(currentLineNumber, currentText.size()); - formatCurrentMessageOrContext(currentLineNumber, currentText.size()); - } - - bool hasMessagesOrContexts() const - { - return !m_messages.empty() || !m_contexts.empty(); - } - - static - bool isAfterStartColumn(const SourceRange &sourceRange, uint line, uint column) - { - return sourceRange.start.line == line && sourceRange.start.column <= column; - } - - static - bool isBeforeEndColumn(const SourceRange &sourceRange, uint line, uint column) - { - return sourceRange.end.line == line && sourceRange.end.column >= column; - } - - static - bool isInBetweenLine(const SourceRange &sourceRange, uint line) - { - return sourceRange.start.line < line && sourceRange.end.line > line; - } - - static - bool isSingleLine(const SourceRange &sourceRange) - { - return sourceRange.start.line == sourceRange.end.line; - } - - static - bool isInsideMultiLine(const SourceRange &sourceRange, uint line, uint column) - { - return !isSingleLine(sourceRange) - && (isAfterStartColumn(sourceRange, line, column) - || isInBetweenLine(sourceRange, line) - || isBeforeEndColumn(sourceRange, line, column)); - } - - static - bool isInsideSingleLine(const SourceRange &sourceRange, uint line, uint column) - { - return isSingleLine(sourceRange) - && isAfterStartColumn(sourceRange, line, column) - && isBeforeEndColumn(sourceRange, line, column); - } - - static - bool isInsideRange(const SourceRange &sourceRange, uint line, uint column) - { - return isInsideSingleLine(sourceRange, line, column) - || isInsideMultiLine(sourceRange, line, column); - } - - Messages messagesForLineAndColumn(uint line, uint column) const - { - Messages messages; - - auto underPosition = [=] (const Message &message) { - return ClangQueryHighlightMarker::isInsideRange(message.sourceRange, line, column); - }; - - std::copy_if(m_messages.begin(), - m_messages.end(), - std::back_inserter(messages), - underPosition); - - return messages; - } - - Contexts contextsForLineAndColumn(uint line, uint column) const - { - Contexts contexts; - - auto underPosition = [=] (const Context &context) { - return ClangQueryHighlightMarker::isInsideRange(context.sourceRange, line, column); - }; - - std::copy_if(m_contexts.begin(), - m_contexts.end(), - std::back_inserter(contexts), - underPosition); - - return contexts; - } - -private: - Contexts m_contexts; - Messages m_messages; - Contexts m_currentlyUsedContexts; - Messages m_currentlyUsedMessages; - Contexts::iterator m_currentContextsIterator{m_contexts.begin()}; - Messages::iterator m_currentMessagesIterator{m_messages.begin()}; - QTextCharFormat m_messageTextFormat; - QTextCharFormat m_contextTextFormat; - SyntaxHighlighter &m_highlighter; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangqueryhoverhandler.cpp b/src/plugins/clangrefactoring/clangqueryhoverhandler.cpp deleted file mode 100644 index cb9d64fe42e..00000000000 --- a/src/plugins/clangrefactoring/clangqueryhoverhandler.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "clangqueryhoverhandler.h" - -#include "clangqueryhighlighter.h" - -#include - -#include -#include - -namespace ClangRefactoring { - -ClangQueryHoverHandler::ClangQueryHoverHandler(ClangQueryHighlighter *highligher) - : m_highligher(highligher) -{ -} - -void ClangQueryHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget, - int position, - ReportPriority report) -{ - Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); }); - - using Messages = ClangBackEnd::DynamicASTMatcherDiagnosticMessageContainers; - using Contexts = ClangBackEnd::DynamicASTMatcherDiagnosticContextContainers; - - QTextCursor textCursor = editorWidget->textCursor(); - textCursor.setPosition(position); - int line = textCursor.blockNumber() + 1; - int column = textCursor.columnNumber() + 1; - - Messages messages = m_highligher->messagesForLineAndColumn(line, column); - Contexts contexts = m_highligher->contextsForLineAndColumn(line, column); - - if (!messages.empty()) - setToolTip(QString("%1: %2").arg(QString(messages[0].errorTypeText())).arg(QString(messages[0].arguments.join(", ")))); - else if (!contexts.empty()) - setToolTip(QString("%1: %2").arg(QString(contexts[0].contextTypeText())).arg(QString(contexts[0].arguments.join(", ")))); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangqueryhoverhandler.h b/src/plugins/clangrefactoring/clangqueryhoverhandler.h deleted file mode 100644 index a9dfc5fe229..00000000000 --- a/src/plugins/clangrefactoring/clangqueryhoverhandler.h +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -namespace ClangRefactoring { - -class ClangQueryHighlighter; - -class ClangQueryHoverHandler : public TextEditor::BaseHoverHandler -{ -public: - ClangQueryHoverHandler(ClangQueryHighlighter *highligher); - -protected: - void identifyMatch(TextEditor::TextEditorWidget *editorWidget, - int position, - ReportPriority report) override; - -private: - ClangQueryHighlighter *m_highligher; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangqueryprojectsfindfilter.cpp b/src/plugins/clangrefactoring/clangqueryprojectsfindfilter.cpp deleted file mode 100644 index f253b1d7bd6..00000000000 --- a/src/plugins/clangrefactoring/clangqueryprojectsfindfilter.cpp +++ /dev/null @@ -1,247 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "clangqueryprojectsfindfilter.h" - -#include "projectpartutilities.h" -#include "refactoringclient.h" -#include "searchinterface.h" - -#include -#include - -#include - -#include - -namespace ClangRefactoring { - -ClangQueryProjectsFindFilter::ClangQueryProjectsFindFilter( - ClangBackEnd::RefactoringServerInterface &server, - SearchInterface &searchInterface, - RefactoringClient &refactoringClient) - : m_server(server), - m_searchInterface(searchInterface), - m_refactoringClient(refactoringClient) -{ - temporaryFile.open(); -} - -QString ClangQueryProjectsFindFilter::id() const -{ - return QStringLiteral("Clang Query Project"); -} - -QString ClangQueryProjectsFindFilter::displayName() const -{ - return tr("Clang Query Project"); -} - -bool ClangQueryProjectsFindFilter::isEnabled() const -{ - return true; -} - -namespace { -Utils::SmallString toNative(const QString &path) -{ - Utils::SmallString nativePath = path; - -#ifdef Q_OS_WIN - nativePath.replace('/', '\\'); -#endif - - return nativePath; -} -} - -void ClangQueryProjectsFindFilter::requestSourceRangesAndDiagnostics(const QString &queryText, - const QString &exampleContent) -{ - const QString filePath = temporaryFile.fileName(); - - ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage message( - queryText, - {ClangBackEnd::FilePath(filePath), 1, exampleContent, {"cc", "-std=c++1z", toNative(filePath)}}); - - m_server.requestSourceRangesAndDiagnosticsForQueryMessage(std::move(message)); -} - -SearchHandle *ClangQueryProjectsFindFilter::find(const QString &queryText) -{ - m_searchHandle = m_searchInterface.startNewSearch(tr("Clang Query"), queryText); - - m_searchHandle->setRefactoringServer(&m_server); - - m_refactoringClient.setSearchHandle(m_searchHandle.get()); - - auto message = createMessage(queryText); - - m_refactoringClient.setExpectedResultCount(uint(message.sources.size())); - - m_server.requestSourceRangesForQueryMessage(std::move(message)); - - return m_searchHandle.get(); -} - -void ClangQueryProjectsFindFilter::findAll(const QString &, Core::FindFlags) -{ - find(queryText()); -} - -bool ClangQueryProjectsFindFilter::showSearchTermInput() const -{ - return false; -} - -Core::FindFlags ClangQueryProjectsFindFilter::supportedFindFlags() const -{ - return {}; -} - -void ClangQueryProjectsFindFilter::setProjectParts(const std::vector &projectParts) -{ - this->m_projectParts = projectParts; -} - -bool ClangQueryProjectsFindFilter::isAvailable() const -{ - return m_server.isAvailable(); -} - -void ClangQueryProjectsFindFilter::setAvailable(bool isAvailable) -{ - m_server.setAvailable(isAvailable); -} - -SearchHandle *ClangQueryProjectsFindFilter::searchHandleForTestOnly() const -{ - return m_searchHandle.get(); -} - -void ClangQueryProjectsFindFilter::setUnsavedContent( - std::vector &&unsavedContent) -{ - this->m_unsavedContent = std::move(unsavedContent); -} - -Utils::SmallStringVector ClangQueryProjectsFindFilter::compilerArguments(CppTools::ProjectPart *projectPart, - CppTools::ProjectFile::Kind fileKind) -{ - using CppTools::CompilerOptionsBuilder; - - CompilerOptionsBuilder builder(*projectPart, CppTools::UseSystemHeader::Yes); - - return Utils::SmallStringVector(builder.build(fileKind, CppTools::UsePrecompiledHeaders::No)); -} - -QWidget *ClangQueryProjectsFindFilter::widget() const -{ - return nullptr; -} - -namespace { - -Utils::SmallStringVector createCommandLine(CppTools::ProjectPart *projectPart, - const QString &documentFilePath, - CppTools::ProjectFile::Kind fileKind) -{ - using CppTools::CompilerOptionsBuilder; - - Utils::SmallStringVector commandLine = ClangQueryProjectsFindFilter::compilerArguments(projectPart, fileKind); - - commandLine.push_back(documentFilePath); - - return commandLine; -} - -bool unsavedContentContains(const ClangBackEnd::FilePath &sourceFilePath, - const std::vector &unsavedContent) -{ - auto compare = [&] (const ClangBackEnd::V2::FileContainer &unsavedEntry) { - return unsavedEntry.filePath == sourceFilePath; - }; - - auto found = std::find_if(unsavedContent.begin(), unsavedContent.end(), compare); - - return found != unsavedContent.end(); -} - -bool isCHeader(CppTools::ProjectFile::Kind kind) -{ - return kind == CppTools::ProjectFile::CHeader; -} - -void appendSource(std::vector &sources, - const CppTools::ProjectPart::Ptr &projectPart, - const CppTools::ProjectFile &projectFile, - const std::vector &unsavedContent) -{ - ClangBackEnd::FilePath sourceFilePath(projectFile.path); - - if (!unsavedContentContains(sourceFilePath, unsavedContent) && !isCHeader(projectFile.kind)) { - sources.emplace_back(ClangBackEnd::FilePath(projectFile.path), - -1, - "", - createCommandLine(projectPart.data(), projectFile.path, projectFile.kind)); - } -} - -std::vector -createSources(const std::vector &projectParts, - const std::vector &unsavedContent) -{ - std::vector sources; - - for (const CppTools::ProjectPart::Ptr &projectPart : projectParts) { - for (const CppTools::ProjectFile &projectFile : projectPart->files) - appendSource(sources, projectPart, projectFile, unsavedContent); - } - - return sources; -} - -} - -ClangBackEnd::RequestSourceRangesForQueryMessage ClangQueryProjectsFindFilter::createMessage(const QString &queryText) const -{ - return ClangBackEnd::RequestSourceRangesForQueryMessage( - Utils::SmallString(queryText), - createSources(m_projectParts, m_unsavedContent), - Utils::clone(m_unsavedContent)); -} - -QString ClangQueryProjectsFindFilter::queryText() const -{ - return QString(); -} - -RefactoringClient &ClangQueryProjectsFindFilter::refactoringClient() -{ - return m_refactoringClient; -} - - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangqueryprojectsfindfilter.h b/src/plugins/clangrefactoring/clangqueryprojectsfindfilter.h deleted file mode 100644 index bc5c95579c7..00000000000 --- a/src/plugins/clangrefactoring/clangqueryprojectsfindfilter.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "searchhandle.h" - -#include - -#include - -#include - -#include -#include - -#include - -namespace ClangBackEnd { -class RefactoringServerInterface; -class RequestSourceRangesAndDiagnosticsForQueryMessage; -} - -namespace ClangRefactoring { - -class RefactoringClient; -class SearchInterface; - -class ClangQueryProjectsFindFilter : public Core::IFindFilter -{ - Q_OBJECT - -public: - ClangQueryProjectsFindFilter(ClangBackEnd::RefactoringServerInterface &server, - SearchInterface &searchInterface, - RefactoringClient &refactoringClient); - - QString id() const override; - QString displayName() const override; - bool isEnabled() const override; - void requestSourceRangesAndDiagnostics(const QString &queryText, const QString &exampleContent); - SearchHandle *find(const QString &queryText); - void findAll(const QString &queryText, Core::FindFlags findFlags = {}) override; - bool showSearchTermInput() const override; - Core::FindFlags supportedFindFlags() const override; - - void setProjectParts(const std::vector &m_projectParts); - - bool isAvailable() const; - void setAvailable(bool isAvailable); - - SearchHandle* searchHandleForTestOnly() const; - - void setUnsavedContent(std::vector &&m_unsavedContent); - - static Utils::SmallStringVector compilerArguments(CppTools::ProjectPart *projectPart, - CppTools::ProjectFile::Kind fileKind); - -protected: - virtual QWidget *widget() const; - virtual QString queryText() const; - RefactoringClient &refactoringClient(); - -private: - ClangBackEnd::RequestSourceRangesForQueryMessage createMessage( - const QString &queryText) const; - -private: - std::vector m_unsavedContent; - std::unique_ptr m_searchHandle; - std::vector m_projectParts; - Utils::TemporaryFile temporaryFile{"clangQuery-XXXXXX.cpp"}; - ClangBackEnd::RefactoringServerInterface &m_server; - SearchInterface &m_searchInterface; - RefactoringClient &m_refactoringClient; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangqueryprojectsfindfilter.ui b/src/plugins/clangrefactoring/clangqueryprojectsfindfilter.ui deleted file mode 100644 index d7a01483ea7..00000000000 --- a/src/plugins/clangrefactoring/clangqueryprojectsfindfilter.ui +++ /dev/null @@ -1,92 +0,0 @@ - - - Form - - - - 0 - 0 - 512 - 390 - - - - - 1 - 1 - - - - - 512 - 0 - - - - - - - - QLayout::SetMinimumSize - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 1 - 3 - - - - class Foo { void function() { int x; } }; - - - - - - - - 1 - 1 - - - - - 700 - 0 - - - - functionDecl() - - - - - - - - ClangRefactoring::ClangQueryExampleTextEditorWidget - QPlainTextEdit -
clangqueryexampletexteditorwidget.h
-
- - ClangRefactoring::ClangQueryTextEditorWidget - QPlainTextEdit -
clangquerytexteditorwidget.h
-
-
- - -
diff --git a/src/plugins/clangrefactoring/clangqueryprojectsfindfilterwidget.cpp b/src/plugins/clangrefactoring/clangqueryprojectsfindfilterwidget.cpp deleted file mode 100644 index 2351ecbcdab..00000000000 --- a/src/plugins/clangrefactoring/clangqueryprojectsfindfilterwidget.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "clangqueryprojectsfindfilterwidget.h" - -#include "clangqueryhighlighter.h" - -#include - -#include - -namespace ClangRefactoring { - -ClangQueryProjectsFindFilterWidget::ClangQueryProjectsFindFilterWidget() -{ - m_form.setupUi(this); -} - -QPlainTextEdit *ClangQueryProjectsFindFilterWidget::queryTextEdit() const -{ - return m_form.queryTextEdit; -} - -QPlainTextEdit *ClangQueryProjectsFindFilterWidget::queryExampleTextEdit() const -{ - return m_form.exampleSourceTextEdit; -} - -ClangQueryExampleHighlighter *ClangQueryProjectsFindFilterWidget::clangQueryExampleHighlighter() const -{ - return m_form.exampleSourceTextEdit->syntaxHighlighter(); -} - -ClangQueryHighlighter *ClangQueryProjectsFindFilterWidget::clangQueryHighlighter() const -{ - return m_form.queryTextEdit->syntaxHighlighter(); -} - -bool ClangQueryProjectsFindFilterWidget::isValid() const -{ - return !m_form.queryTextEdit->textDocument()->document()->isEmpty() - && !clangQueryHighlighter()->hasDiagnostics(); - -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangqueryprojectsfindfilterwidget.h b/src/plugins/clangrefactoring/clangqueryprojectsfindfilterwidget.h deleted file mode 100644 index 2d9fdd785a2..00000000000 --- a/src/plugins/clangrefactoring/clangqueryprojectsfindfilterwidget.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "ui_clangqueryprojectsfindfilter.h" - -namespace ClangRefactoring { - -class ClangQueryExampleHighlighter; -class ClangQueryHighlighter; - -class ClangQueryProjectsFindFilterWidget : public QWidget -{ - Q_OBJECT -public: - ClangQueryProjectsFindFilterWidget(); - - QPlainTextEdit *queryTextEdit() const; - QPlainTextEdit *queryExampleTextEdit() const; - ClangQueryExampleHighlighter *clangQueryExampleHighlighter() const; - ClangQueryHighlighter *clangQueryHighlighter() const; - - bool isValid() const; - -private: - Ui::Form m_form; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangquerytexteditorwidget.cpp b/src/plugins/clangrefactoring/clangquerytexteditorwidget.cpp deleted file mode 100644 index e24d6eab5e4..00000000000 --- a/src/plugins/clangrefactoring/clangquerytexteditorwidget.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "clangquerytexteditorwidget.h" - -#include "clangqueryhighlighter.h" -#include "clangqueryhoverhandler.h" - -#include - -namespace ClangRefactoring { - -ClangQueryTextEditorWidget::ClangQueryTextEditorWidget(QWidget *parent) - : BaseClangQueryTextEditorWidget(parent), - m_syntaxHighlighter(new ClangQueryHighlighter), - m_hoverHandler(std::make_unique(m_syntaxHighlighter)) -{ - textDocument()->setSyntaxHighlighter(m_syntaxHighlighter); - textDocument()->setPlainText("functionDecl()"); - - addHoverHandler(m_hoverHandler.get()); -} - -ClangQueryTextEditorWidget::~ClangQueryTextEditorWidget() = default; - -ClangQueryHighlighter *ClangQueryTextEditorWidget::syntaxHighlighter() const -{ - return m_syntaxHighlighter; -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangquerytexteditorwidget.h b/src/plugins/clangrefactoring/clangquerytexteditorwidget.h deleted file mode 100644 index a221eb03fe0..00000000000 --- a/src/plugins/clangrefactoring/clangquerytexteditorwidget.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "baseclangquerytexteditorwidget.h" - -#include - -namespace ClangRefactoring { - -class ClangQueryHighlighter; -class ClangQueryHoverHandler; - -class ClangQueryTextEditorWidget : public BaseClangQueryTextEditorWidget -{ - Q_OBJECT - -public: - ClangQueryTextEditorWidget(QWidget *parent); - ~ClangQueryTextEditorWidget(); - - ClangQueryHighlighter *syntaxHighlighter() const; - -private: - ClangQueryHighlighter *m_syntaxHighlighter; - std::unique_ptr m_hoverHandler; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangrefactoring-source.pri b/src/plugins/clangrefactoring/clangrefactoring-source.pri deleted file mode 100644 index 273e6fe834a..00000000000 --- a/src/plugins/clangrefactoring/clangrefactoring-source.pri +++ /dev/null @@ -1,34 +0,0 @@ -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/clangqueryexamplehighlighter.h \ - $$PWD/clangqueryexamplehighlightmarker.h \ - $$PWD/clangqueryhighlighter.h \ - $$PWD/clangqueryhighlightmarker.h \ - $$PWD/clangqueryprojectsfindfilter.h \ - $$PWD/clangsymbolsfindfilter.h \ - $$PWD/projectpartutilities.h \ - $$PWD/refactoringclient.h \ - $$PWD/refactoringconnectionclient.h \ - $$PWD/refactoringengine.h \ - $$PWD/refactoringprojectupdater.h \ - $$PWD/searchinterface.h \ - $$PWD/searchhandle.h \ - $$PWD/symbolqueryinterface.h \ - $$PWD/symbol.h \ - $$PWD/projectpartproviderinterface.h \ - $$PWD/editormanagerinterface.h \ - $$PWD/locatorfilter.h - -SOURCES += \ - $$PWD/clangqueryexamplehighlighter.cpp \ - $$PWD/clangqueryhighlighter.cpp \ - $$PWD/clangqueryprojectsfindfilter.cpp \ - $$PWD/clangsymbolsfindfilter.cpp \ - $$PWD/projectpartutilities.cpp \ - $$PWD/refactoringclient.cpp \ - $$PWD/refactoringconnectionclient.cpp \ - $$PWD/refactoringengine.cpp \ - $$PWD/refactoringprojectupdater.cpp \ - $$PWD/searchhandle.cpp \ - $$PWD/locatorfilter.cpp diff --git a/src/plugins/clangrefactoring/clangrefactoring.pro b/src/plugins/clangrefactoring/clangrefactoring.pro deleted file mode 100644 index d23e9a9a442..00000000000 --- a/src/plugins/clangrefactoring/clangrefactoring.pro +++ /dev/null @@ -1,43 +0,0 @@ -include(../../qtcreatorplugin.pri) -include(clangrefactoring-source.pri) -include(../../shared/clang/clang_installation.pri) - -include(../../shared/clang/clang_defines.pri) - -requires(!isEmpty(LIBTOOLING_LIBS)) - -HEADERS += \ - clangrefactoringplugin.h \ - baseclangquerytexteditorwidget.h \ - clangqueryexampletexteditorwidget.h \ - clangqueryhoverhandler.h \ - clangqueryprojectsfindfilterwidget.h \ - clangquerytexteditorwidget.h \ - qtcreatorclangqueryfindfilter.h \ - qtcreatorsearch.h \ - qtcreatorsearchhandle.h \ - qtcreatorsymbolsfindfilter.h \ - querysqlitestatementfactory.h \ - sourcelocations.h \ - symbolsfindfilterconfigwidget.h \ - symbolquery.h \ - qtcreatoreditormanager.h \ - qtcreatorrefactoringprojectupdater.h - -SOURCES += \ - clangrefactoringplugin.cpp \ - baseclangquerytexteditorwidget.cpp \ - clangqueryexampletexteditorwidget.cpp \ - clangqueryhoverhandler.cpp \ - clangqueryprojectsfindfilterwidget.cpp \ - clangquerytexteditorwidget.cpp \ - qtcreatorclangqueryfindfilter.cpp \ - qtcreatorsearch.cpp \ - qtcreatorsearchhandle.cpp \ - qtcreatorsymbolsfindfilter.cpp \ - symbolsfindfilterconfigwidget.cpp \ - qtcreatoreditormanager.cpp \ - qtcreatorrefactoringprojectupdater.cpp - -FORMS += \ - clangqueryprojectsfindfilter.ui diff --git a/src/plugins/clangrefactoring/clangrefactoring.qbs b/src/plugins/clangrefactoring/clangrefactoring.qbs deleted file mode 100644 index b440d6e08e1..00000000000 --- a/src/plugins/clangrefactoring/clangrefactoring.qbs +++ /dev/null @@ -1,81 +0,0 @@ -import qbs -import qbs.FileInfo - -QtcPlugin { - name: "ClangRefactoring" - - Depends { name: "libclang"; required: false } - Depends { name: "clang_defines" } - condition: libclang.present && libclang.toolingEnabled - - Depends { name: "ClangSupport" } - Depends { name: "Utils" } - - Depends { name: "ClangPchManager" } - Depends { name: "Core" } - Depends { name: "CppTools" } - Depends { name: "ProjectExplorer" } - Depends { name: "TextEditor" } - - cpp.includePaths: ["."] - - files: [ - "baseclangquerytexteditorwidget.cpp", - "baseclangquerytexteditorwidget.h", - "clangqueryexamplehighlighter.cpp", - "clangqueryexamplehighlighter.h", - "clangqueryexamplehighlightmarker.h", - "clangqueryexampletexteditorwidget.cpp", - "clangqueryexampletexteditorwidget.h", - "clangqueryhighlighter.cpp", - "clangqueryhighlighter.h", - "clangqueryhighlightmarker.h", - "clangqueryhoverhandler.cpp", - "clangqueryhoverhandler.h", - "clangqueryprojectsfindfilter.cpp", - "clangqueryprojectsfindfilter.h", - "clangqueryprojectsfindfilter.ui", - "clangqueryprojectsfindfilterwidget.cpp", - "clangqueryprojectsfindfilterwidget.h", - "clangquerytexteditorwidget.cpp", - "clangquerytexteditorwidget.h", - "clangrefactoringplugin.cpp", - "clangrefactoringplugin.h", - "locatorfilter.cpp", - "locatorfilter.h", - "projectpartutilities.cpp", - "projectpartutilities.h", - "qtcreatorclangqueryfindfilter.cpp", - "qtcreatorclangqueryfindfilter.h", - "qtcreatoreditormanager.cpp", - "qtcreatoreditormanager.h", - "qtcreatorrefactoringprojectupdater.cpp", - "qtcreatorrefactoringprojectupdater.h", - "qtcreatorsearch.cpp", - "qtcreatorsearch.h", - "qtcreatorsearchhandle.cpp", - "qtcreatorsearchhandle.h", - "qtcreatorsymbolsfindfilter.cpp", - "qtcreatorsymbolsfindfilter.h", - "querysqlitestatementfactory.h", - "refactoringclient.cpp", - "refactoringclient.h", - "refactoringconnectionclient.cpp", - "refactoringconnectionclient.h", - "refactoringengine.cpp", - "refactoringengine.h", - "refactoringprojectupdater.cpp", - "refactoringprojectupdater.h", - "searchhandle.cpp", - "searchhandle.h", - "searchinterface.h", - "sourcelocations.h", - "symbol.h", - "symbolquery.h", - "symbolqueryinterface.h", - "clangsymbolsfindfilter.cpp", - "clangsymbolsfindfilter.h", - "symbolsfindfilterconfigwidget.cpp", - "symbolsfindfilterconfigwidget.h", - ] -} diff --git a/src/plugins/clangrefactoring/clangrefactoring_dependencies.pri b/src/plugins/clangrefactoring/clangrefactoring_dependencies.pri deleted file mode 100644 index 8a082361770..00000000000 --- a/src/plugins/clangrefactoring/clangrefactoring_dependencies.pri +++ /dev/null @@ -1,9 +0,0 @@ -QTC_PLUGIN_NAME = ClangRefactoring -QTC_LIB_DEPENDS += \ - utils \ - clangsupport -QTC_PLUGIN_DEPENDS += \ - coreplugin \ - cpptools \ - texteditor \ - clangpchmanager diff --git a/src/plugins/clangrefactoring/clangrefactoringplugin.cpp b/src/plugins/clangrefactoring/clangrefactoringplugin.cpp deleted file mode 100644 index 60ae051a940..00000000000 --- a/src/plugins/clangrefactoring/clangrefactoringplugin.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "clangrefactoringplugin.h" -#include "locatorfilter.h" -#include "qtcreatorsymbolsfindfilter.h" -#include "qtcreatoreditormanager.h" -#include "qtcreatorrefactoringprojectupdater.h" -#include "querysqlitestatementfactory.h" -#include "sqlitedatabase.h" -#include "sqlitereadstatement.h" -#include "symbolquery.h" - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include -#include - -#include - -using namespace std::chrono_literals; - -namespace ClangRefactoring { - -namespace { - -using ClangPchManager::ClangPchManagerPlugin; - -QString backendProcessPath() -{ - return Core::ICore::libexecPath() - + QStringLiteral("/clangrefactoringbackend") - + QStringLiteral(QTC_HOST_EXE_SUFFIX); -} - -} // anonymous namespace - -std::unique_ptr ClangRefactoringPlugin::d; - -class ClangRefactoringPluginData -{ -public: - using QuerySqliteReadStatementFactory = QuerySqliteStatementFactory; - Sqlite::Database database{Utils::PathString{Core::ICore::cacheResourcePath() - + "/symbol-experimental-v1.db"}, - 1000ms}; - ClangBackEnd::RefactoringDatabaseInitializer databaseInitializer{database}; - ClangBackEnd::FilePathCaching filePathCache{database}; - ClangPchManager::ProgressManager progressManager{ - [] (QFutureInterface &promise) { - auto title = QCoreApplication::translate("ClangRefactoringProgressManager", "C++ Indexing"); - Core::ProgressManager::addTask(promise.future(), title, "clang indexing", {});}}; - RefactoringClient refactoringClient{progressManager}; - QtCreatorEditorManager editorManager{filePathCache}; - ClangBackEnd::RefactoringConnectionClient connectionClient{&refactoringClient}; - QuerySqliteReadStatementFactory statementFactory{database}; - SymbolQuery symbolQuery{statementFactory}; - ClangBackEnd::ProjectPartsStorage projectPartsStorage{database}; - RefactoringEngine engine{connectionClient.serverProxy(), refactoringClient, filePathCache, symbolQuery}; - QtCreatorRefactoringProjectUpdater projectUpdate{connectionClient.serverProxy(), - ClangPchManagerPlugin::pchManagerClient(), - filePathCache, - projectPartsStorage, - ClangPchManagerPlugin::settingsManager()}; -}; - -ClangRefactoringPlugin::ClangRefactoringPlugin() = default; - -ClangRefactoringPlugin::~ClangRefactoringPlugin() = default; - -static bool useClangFilters() -{ - static bool use = qEnvironmentVariableIntValue("QTC_CLANG_LOCATORS"); - return use; -} - -bool ClangRefactoringPlugin::initialize(const QStringList & /*arguments*/, QString * /*errorMessage*/) -{ - d = std::make_unique(); - - d->refactoringClient.setRefactoringEngine(&d->engine); - d->refactoringClient.setRefactoringConnectionClient(&d->connectionClient); - - connectBackend(); - startBackend(); - - CppTools::CppModelManager::addRefactoringEngine(CppTools::RefactoringEngineType::ClangRefactoring, - &refactoringEngine()); - - initializeFilters(); - - return true; -} - -ExtensionSystem::IPlugin::ShutdownFlag ClangRefactoringPlugin::aboutToShutdown() -{ - CppTools::CppModelManager::removeRefactoringEngine( - CppTools::RefactoringEngineType::ClangRefactoring); - d->refactoringClient.setRefactoringConnectionClient(nullptr); - d->refactoringClient.setRefactoringEngine(nullptr); - - d.reset(); - - return SynchronousShutdown; -} - -RefactoringEngine &ClangRefactoringPlugin::refactoringEngine() -{ - return d->engine; -} - -void ClangRefactoringPlugin::startBackend() -{ - d->connectionClient.setProcessPath(backendProcessPath()); - - d->connectionClient.startProcessAndConnectToServerAsynchronously(); -} - -void ClangRefactoringPlugin::connectBackend() -{ - connect(&d->connectionClient, - &ClangBackEnd::RefactoringConnectionClient::connectedToLocalSocket, - this, - &ClangRefactoringPlugin::backendIsConnected); -} - -void ClangRefactoringPlugin::backendIsConnected() -{ - d->engine.setRefactoringEngineAvailable(true); -} - -void ClangRefactoringPlugin::initializeFilters() -{ - if (!useClangFilters()) - return; - - CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance(); - modelManager->setClassesFilter(std::make_unique( - d->symbolQuery, - d->editorManager, - ClangBackEnd::SymbolKinds{ClangBackEnd::SymbolKind::Record}, - CppTools::Constants::CLASSES_FILTER_ID, - CppTools::Constants::CLASSES_FILTER_DISPLAY_NAME, - "c")); - modelManager->setFunctionsFilter(std::make_unique( - d->symbolQuery, - d->editorManager, - ClangBackEnd::SymbolKinds{ClangBackEnd::SymbolKind::Function}, - CppTools::Constants::FUNCTIONS_FILTER_ID, - CppTools::Constants::FUNCTIONS_FILTER_DISPLAY_NAME, - "m")); - modelManager->setLocatorFilter(std::make_unique( - d->symbolQuery, - d->editorManager, - ClangBackEnd::SymbolKinds{ClangBackEnd::SymbolKind::Record, - ClangBackEnd::SymbolKind::Enumeration, - ClangBackEnd::SymbolKind::Function}, - CppTools::Constants::LOCATOR_FILTER_ID, - CppTools::Constants::LOCATOR_FILTER_DISPLAY_NAME, - ":")); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangrefactoringplugin.h b/src/plugins/clangrefactoring/clangrefactoringplugin.h deleted file mode 100644 index 3f665e23bbc..00000000000 --- a/src/plugins/clangrefactoring/clangrefactoringplugin.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "refactoringengine.h" -#include "refactoringclient.h" -#include "qtcreatorclangqueryfindfilter.h" -#include "qtcreatorsearch.h" -#include "refactoringconnectionclient.h" - -#include - -#include - -#include - -namespace ClangRefactoring { - -class ClangRefactoringPluginData; - -class ClangRefactoringPlugin : public ExtensionSystem::IPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "ClangRefactoring.json") - -public: - ClangRefactoringPlugin(); - ~ClangRefactoringPlugin(); - bool initialize(const QStringList &arguments, QString *errorMessage); - ShutdownFlag aboutToShutdown(); - - static RefactoringEngine &refactoringEngine(); - -private: - void startBackend(); - void connectBackend(); - void backendIsConnected(); - void initializeFilters(); - -private: - static std::unique_ptr d; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangsymbolsfindfilter.cpp b/src/plugins/clangrefactoring/clangsymbolsfindfilter.cpp deleted file mode 100644 index c2555586346..00000000000 --- a/src/plugins/clangrefactoring/clangsymbolsfindfilter.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "clangsymbolsfindfilter.h" - -#include - -#include - -using namespace Core; - -namespace ClangRefactoring { - -SymbolsFindFilter::SymbolsFindFilter() -{ -} - -QString SymbolsFindFilter::id() const -{ - return QLatin1String(CppTools::Constants::SYMBOLS_FIND_FILTER_ID); -} - -QString SymbolsFindFilter::displayName() const -{ - return QString(CppTools::Constants::SYMBOLS_FIND_FILTER_DISPLAY_NAME); -} - -bool SymbolsFindFilter::isEnabled() const -{ - return true; -} - -void SymbolsFindFilter::findAll(const QString &, FindFlags) -{ -} - -void SymbolsFindFilter::writeSettings(QSettings *) -{ -} - -void SymbolsFindFilter::readSettings(QSettings *) -{ -} - -} // ClangRefactoring diff --git a/src/plugins/clangrefactoring/clangsymbolsfindfilter.h b/src/plugins/clangrefactoring/clangsymbolsfindfilter.h deleted file mode 100644 index ea8872f403e..00000000000 --- a/src/plugins/clangrefactoring/clangsymbolsfindfilter.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -#include -#include -#include -#include - -namespace Core { class SearchResult; } - -namespace ClangRefactoring { - -class CppModelManager; - -class SymbolsFindFilter : public Core::IFindFilter -{ - Q_OBJECT - -public: - explicit SymbolsFindFilter(); - - QString id() const; - QString displayName() const; - bool isEnabled() const; - - void findAll(const QString &txt, Core::FindFlags findFlags); - - void writeSettings(QSettings *settings); - void readSettings(QSettings *settings); -}; - -} // ClangRefactoring diff --git a/src/plugins/clangrefactoring/editormanagerinterface.h b/src/plugins/clangrefactoring/editormanagerinterface.h deleted file mode 100644 index fbb196460e7..00000000000 --- a/src/plugins/clangrefactoring/editormanagerinterface.h +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -#include -#include - -namespace Core { -class IEditor; -} - -namespace ClangRefactoring { - -class EditorManagerInterface -{ -public: - EditorManagerInterface() = default; - EditorManagerInterface(const EditorManagerInterface&) = delete; - EditorManagerInterface &operator=(const EditorManagerInterface&) = delete; - EditorManagerInterface(EditorManagerInterface&&) = delete; - EditorManagerInterface &operator=(EditorManagerInterface&&) = delete; - - virtual Core::IEditor *openEditorAt(ClangBackEnd::FilePathId filePathId, Utils::LineColumn lineColumn) = 0; - -protected: - ~EditorManagerInterface() = default; -}; -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/locatorfilter.cpp b/src/plugins/clangrefactoring/locatorfilter.cpp deleted file mode 100644 index c8fcfcaec31..00000000000 --- a/src/plugins/clangrefactoring/locatorfilter.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "locatorfilter.h" - -#include - -#include - -namespace ClangRefactoring { - -QList LocatorFilter::matchesFor( - QFutureInterface &, const QString &searchTerm) -{ - using EntryList = QList; - Utils::SmallString sqlSearchTerm{searchTerm}; - sqlSearchTerm.replace('*', '%'); - sqlSearchTerm.append("%"); - const Symbols records = m_symbolQuery.symbols(m_symbolKinds, sqlSearchTerm); - return Utils::transform(records, [this](const Symbol &record) { - Core::LocatorFilterEntry entry{this, - record.name.toQString(), - QVariant::fromValue(record)}; - return entry; - }); -} - -void LocatorFilter::accept(Core::LocatorFilterEntry locatorFilterEntry, QString *, int *, int *) const -{ - const Symbol symbol = locatorFilterEntry.internalData.value(); - - const auto sourceLocation = m_symbolQuery.locationForSymbolId(symbol.symbolId, - ClangBackEnd::SourceLocationKind::Definition); - if (sourceLocation) - m_editorManager.openEditorAt(sourceLocation->filePathId, sourceLocation->lineColumn); -} - -void LocatorFilter::refresh(QFutureInterface &) -{ -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/locatorfilter.h b/src/plugins/clangrefactoring/locatorfilter.h deleted file mode 100644 index 9990dbf890d..00000000000 --- a/src/plugins/clangrefactoring/locatorfilter.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "symbolqueryinterface.h" -#include "editormanagerinterface.h" - -#include - -namespace ClangRefactoring { - -class LocatorFilter : public Core::ILocatorFilter -{ - Q_OBJECT -public: - LocatorFilter(SymbolQueryInterface &symbolQuery, - EditorManagerInterface &editorManager, - ClangBackEnd::SymbolKinds &&symbolKinds, - Utils::Id id, - const QString &displayName, - const QString &shortCut, - bool includedByDefault=false) - : m_symbolQuery(symbolQuery), - m_editorManager(editorManager), - m_symbolKinds(std::move(symbolKinds)) - { - setId(id); - setDisplayName(displayName); - setDefaultShortcutString(shortCut); - setDefaultIncludedByDefault(includedByDefault); - } - - QList matchesFor(QFutureInterface &future, - const QString &entry) override; - void accept(Core::LocatorFilterEntry selection, - QString *newText, int *selectionStart, int *selectionLength) const override; - void refresh(QFutureInterface &future) override; -private: - SymbolQueryInterface &m_symbolQuery; - EditorManagerInterface &m_editorManager; - ClangBackEnd::SymbolKinds m_symbolKinds; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/projectpartproviderinterface.h b/src/plugins/clangrefactoring/projectpartproviderinterface.h deleted file mode 100644 index e503303f9c8..00000000000 --- a/src/plugins/clangrefactoring/projectpartproviderinterface.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "filecontainerv2.h" - -#include - -namespace CppTools { -class ProjectPart; -} - -namespace ClangRefactoring { - -class ProjectPartProviderInterface -{ -public: - ProjectPartProviderInterface() = default; - - ProjectPartProviderInterface(const ProjectPartProviderInterface&) = delete; - ProjectPartProviderInterface& operator=(const ProjectPartProviderInterface&) = delete; - - ProjectPartProviderInterface(ProjectPartProviderInterface&&) = default; - ProjectPartProviderInterface& operator=(ProjectPartProviderInterface&&) = default; - - virtual CppTools::ProjectPart *projectPart(const QString &projectPartId) const = 0; - virtual ClangBackEnd::V2::FileContainers generatedFiles() const = 0; - -protected: - ~ProjectPartProviderInterface() = default; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/projectpartutilities.cpp b/src/plugins/clangrefactoring/projectpartutilities.cpp deleted file mode 100644 index a887862da6d..00000000000 --- a/src/plugins/clangrefactoring/projectpartutilities.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "projectpartutilities.h" - -namespace ClangRefactoring { - -CppTools::ProjectFile::Kind fileKindInProjectPart(CppTools::ProjectPart *projectPart, - const QString &filePath) -{ - const auto &projectFiles = projectPart->files; - - auto comparePaths = [&] (const CppTools::ProjectFile &projectFile) { - return projectFile.path == filePath; - }; - - auto found = std::find_if(projectFiles.begin(), projectFiles.end(), comparePaths); - - if (found != projectFiles.end()) - return found->kind; - - return CppTools::ProjectFile::Unclassified; -} - -} diff --git a/src/plugins/clangrefactoring/projectpartutilities.h b/src/plugins/clangrefactoring/projectpartutilities.h deleted file mode 100644 index b8fb0f078d5..00000000000 --- a/src/plugins/clangrefactoring/projectpartutilities.h +++ /dev/null @@ -1,35 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include - -namespace ClangRefactoring { - -CppTools::ProjectFile::Kind fileKindInProjectPart(CppTools::ProjectPart *projectPart, - const QString &filePath); - -} diff --git a/src/plugins/clangrefactoring/qtcreatorclangqueryfindfilter.cpp b/src/plugins/clangrefactoring/qtcreatorclangqueryfindfilter.cpp deleted file mode 100644 index e3dc7ee4e87..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorclangqueryfindfilter.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "qtcreatorclangqueryfindfilter.h" - -#include "clangqueryprojectsfindfilterwidget.h" -#include "refactoringclient.h" - -#include -#include -#include - -#include - -#include - -namespace ClangRefactoring { - -QtCreatorClangQueryFindFilter::QtCreatorClangQueryFindFilter(ClangBackEnd::RefactoringServerInterface &server, - SearchInterface &searchInterface, - RefactoringClient &refactoringClient) - : ClangQueryProjectsFindFilter(server, searchInterface, refactoringClient) -{ -} - -void QtCreatorClangQueryFindFilter::findAll(const QString &queryText, Core::FindFlags findFlags) -{ - prepareFind(); - - ClangQueryProjectsFindFilter::findAll(queryText, findFlags); -} - -void QtCreatorClangQueryFindFilter::handleQueryOrExampleTextChanged() -{ - const QString queryText = this->queryText(); - const QString queryExampleText = this->queryExampleText(); - if (!queryText.isEmpty() && !queryExampleText.isEmpty()) - requestSourceRangesAndDiagnostics(queryText, queryExampleText); -} - -QWidget *QtCreatorClangQueryFindFilter::createConfigWidget() -{ - m_widget = new ClangQueryProjectsFindFilterWidget; - - refactoringClient().setClangQueryExampleHighlighter(m_widget->clangQueryExampleHighlighter()); - refactoringClient().setClangQueryHighlighter(m_widget->clangQueryHighlighter()); - - QObject::connect(m_widget->queryExampleTextEdit(), - &QPlainTextEdit::textChanged, - this, - &QtCreatorClangQueryFindFilter::handleQueryOrExampleTextChanged); - - QObject::connect(m_widget->queryTextEdit(), - &QPlainTextEdit::textChanged, - this, - &QtCreatorClangQueryFindFilter::handleQueryOrExampleTextChanged); - - return m_widget; -} - -bool ClangRefactoring::QtCreatorClangQueryFindFilter::isValid() const -{ - return true; -} - -QWidget *QtCreatorClangQueryFindFilter::widget() const -{ - return m_widget; -} - -QString QtCreatorClangQueryFindFilter::queryText() const -{ - return m_widget->queryTextEdit()->toPlainText(); -} - -QString QtCreatorClangQueryFindFilter::queryExampleText() const -{ - return m_widget->queryExampleTextEdit()->toPlainText(); -} - -namespace { - -std::vector createUnsavedContents() -{ - auto abstractEditors = CppTools::CppModelManager::instance()->abstractEditorSupports(); - std::vector unsavedContents; - unsavedContents.reserve(std::size_t(abstractEditors.size())); - - auto toFileContainer = [](const CppTools::AbstractEditorSupport *abstractEditor) { - return ClangBackEnd::V2::FileContainer(ClangBackEnd::FilePath(abstractEditor->fileName()), - -1, - Utils::SmallString::fromQByteArray( - abstractEditor->contents()), - {}); - }; - - std::transform(abstractEditors.begin(), - abstractEditors.end(), - std::back_inserter(unsavedContents), - toFileContainer); - - return unsavedContents; -} - -} - -void QtCreatorClangQueryFindFilter::prepareFind() -{ - ProjectExplorer::Project *currentProject = ProjectExplorer::SessionManager::startupProject(); - - const CppTools::ProjectInfo projectInfo = CppTools::CppModelManager::instance()->projectInfo(currentProject); - - const QVector parts = projectInfo.projectParts(); - setProjectParts({parts.begin(), parts.end()}); - - setUnsavedContent(createUnsavedContents()); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorclangqueryfindfilter.h b/src/plugins/clangrefactoring/qtcreatorclangqueryfindfilter.h deleted file mode 100644 index 448de0139ca..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorclangqueryfindfilter.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangqueryprojectsfindfilter.h" - -#include - -namespace ClangRefactoring { - -class ClangQueryProjectsFindFilterWidget; - -class QtCreatorClangQueryFindFilter final : public ClangQueryProjectsFindFilter -{ -public: - QtCreatorClangQueryFindFilter(ClangBackEnd::RefactoringServerInterface &m_server, - SearchInterface &m_searchInterface, - RefactoringClient &m_refactoringClient); - - void findAll(const QString &queryText, Core::FindFlags findFlags = {}) override; - - void handleQueryOrExampleTextChanged(); - - QWidget *createConfigWidget() override; - - bool isValid() const override; - - -protected: - QWidget *widget() const override; - QString queryText() const override; - QString queryExampleText() const; - -private: - void prepareFind(); - -private: - QPointer m_widget; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatoreditormanager.cpp b/src/plugins/clangrefactoring/qtcreatoreditormanager.cpp deleted file mode 100644 index 4aef8baa5da..00000000000 --- a/src/plugins/clangrefactoring/qtcreatoreditormanager.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "qtcreatoreditormanager.h" - -#include - -#include - -#include - -namespace ClangRefactoring { - -Core::IEditor *ClangRefactoring::QtCreatorEditorManager::openEditorAt(ClangBackEnd::FilePathId filePathId, - Utils::LineColumn lineColumn) -{ - const QString filePath = m_filePathCache.filePath(filePathId).toQString(); - - return Core::EditorManager::openEditorAt(filePath, lineColumn.line, lineColumn.column - 1); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatoreditormanager.h b/src/plugins/clangrefactoring/qtcreatoreditormanager.h deleted file mode 100644 index 5c09cae082e..00000000000 --- a/src/plugins/clangrefactoring/qtcreatoreditormanager.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "editormanagerinterface.h" - -namespace ClangBackEnd { -class FilePathCachingInterface; -}; - -namespace ClangRefactoring { - -class QtCreatorEditorManager final : public EditorManagerInterface -{ -public: - QtCreatorEditorManager(ClangBackEnd::FilePathCachingInterface &filePathCache) - : m_filePathCache(filePathCache) - {} - - Core::IEditor *openEditorAt(ClangBackEnd::FilePathId filePathId, Utils::LineColumn lineColumn) override; - -private: - ClangBackEnd::FilePathCachingInterface &m_filePathCache; -}; - -} diff --git a/src/plugins/clangrefactoring/qtcreatorrefactoringprojectupdater.cpp b/src/plugins/clangrefactoring/qtcreatorrefactoringprojectupdater.cpp deleted file mode 100644 index 415186d5558..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorrefactoringprojectupdater.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "qtcreatorrefactoringprojectupdater.h" - -#include -#include - -namespace ClangRefactoring { - -namespace { - -CppTools::CppModelManager *cppModelManager() -{ - return CppTools::CppModelManager::instance(); -} - -std::vector createGeneratedFiles( - ClangBackEnd::FilePathCachingInterface &filePathCache) -{ - auto abstractEditors = CppTools::CppModelManager::instance()->abstractEditorSupports(); - std::vector generatedFiles; - generatedFiles.reserve(std::size_t(abstractEditors.size())); - - auto toFileContainer = [&](const CppTools::AbstractEditorSupport *abstractEditor) { - ClangBackEnd::FilePath filePath{abstractEditor->fileName()}; - ClangBackEnd::FilePathId filePathId = filePathCache.filePathId(filePath); - return ClangBackEnd::V2::FileContainer(std::move(filePath), - filePathId, - Utils::SmallString::fromQByteArray( - abstractEditor->contents()), - {}); - }; - - std::transform(abstractEditors.begin(), - abstractEditors.end(), - std::back_inserter(generatedFiles), - toFileContainer); - - std::sort(generatedFiles.begin(), generatedFiles.end()); - - return generatedFiles; -} -} - -QtCreatorRefactoringProjectUpdater::QtCreatorRefactoringProjectUpdater( - ClangBackEnd::ProjectManagementServerInterface &server, - ClangPchManager::PchManagerClient &pchManagerClient, - ClangBackEnd::FilePathCachingInterface &filePathCache, - ClangBackEnd::ProjectPartsStorageInterface &projectPartsStorage, - ClangPchManager::ClangIndexingSettingsManager &settingsManager) - : RefactoringProjectUpdater(server, - pchManagerClient, - *cppModelManager(), - filePathCache, - projectPartsStorage, - settingsManager) -{ - connectToCppModelManager(); -} - -void QtCreatorRefactoringProjectUpdater::abstractEditorUpdated(const QString &qFilePath, - const QByteArray &contents) -{ - ClangBackEnd::FilePath filePath{qFilePath}; - ClangBackEnd::FilePathId filePathId = m_filePathCache.filePathId(filePath); - RefactoringProjectUpdater::updateGeneratedFiles({{std::move(filePath), filePathId, contents}}); -} - -void QtCreatorRefactoringProjectUpdater::abstractEditorRemoved(const QString &filePath) -{ - RefactoringProjectUpdater::removeGeneratedFiles({ClangBackEnd::FilePath{filePath}}); -} - -void QtCreatorRefactoringProjectUpdater::connectToCppModelManager() -{ - RefactoringProjectUpdater::updateGeneratedFiles(createGeneratedFiles(m_filePathCache)); - - QObject::connect(cppModelManager(), - &CppTools::CppModelManager::abstractEditorSupportContentsUpdated, - [&] (const QString &filePath, const QString &, const QByteArray &contents) { - abstractEditorUpdated(filePath, contents); - }); - - QObject::connect(cppModelManager(), - &CppTools::CppModelManager::abstractEditorSupportRemoved, - [&] (const QString &filePath) { - abstractEditorRemoved(filePath); - }); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorrefactoringprojectupdater.h b/src/plugins/clangrefactoring/qtcreatorrefactoringprojectupdater.h deleted file mode 100644 index 7fd16afa16e..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorrefactoringprojectupdater.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "refactoringprojectupdater.h" - -namespace ClangRefactoring { - -class QtCreatorRefactoringProjectUpdater final : public RefactoringProjectUpdater -{ -public: - QtCreatorRefactoringProjectUpdater(ClangBackEnd::ProjectManagementServerInterface &server, - ClangPchManager::PchManagerClient &pchManagerClient, - ClangBackEnd::FilePathCachingInterface &filePathCache, - ClangBackEnd::ProjectPartsStorageInterface &projectPartsStorage, - ClangPchManager::ClangIndexingSettingsManager &settingsManager); - -private: - void abstractEditorUpdated(const QString &filePath, const QByteArray &contents); - void abstractEditorRemoved(const QString &filePath); - void connectToCppModelManager(); -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorsearch.cpp b/src/plugins/clangrefactoring/qtcreatorsearch.cpp deleted file mode 100644 index 341bfe76ac5..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorsearch.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "qtcreatorsearch.h" - -#include "qtcreatorsearchhandle.h" - -#include - -namespace ClangRefactoring { - -QtCreatorSearch::QtCreatorSearch() -{ -} - -std::unique_ptr QtCreatorSearch::startNewSearch(const QString &searchLabel, - const QString &searchTerm) -{ - auto searchResultWindow = Core::SearchResultWindow::instance(); - Core::SearchResult *searchResult = searchResultWindow->startNewSearch( - searchLabel, - {}, - searchTerm, - Core::SearchResultWindow::SearchOnly, - Core::SearchResultWindow::PreserveCaseEnabled); - - QObject::connect(searchResult, - &Core::SearchResult::activated, - [](const Core::SearchResultItem& item) { - Core::EditorManager::openEditorAtSearchResult(item); - }); - - auto searchHandle = std::unique_ptr(new QtCreatorSearchHandle(searchResult)); - - QObject::connect(searchResult, - &Core::SearchResult::cancelled, - [handle=searchHandle.get()] () { handle->cancel(); }); - - return searchHandle; -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorsearch.h b/src/plugins/clangrefactoring/qtcreatorsearch.h deleted file mode 100644 index cb0dcf83419..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorsearch.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "searchinterface.h" - -namespace ClangRefactoring { - -class QtCreatorSearch final : public SearchInterface -{ -public: - QtCreatorSearch(); - - std::unique_ptr startNewSearch(const QString &searchLabel, - const QString &searchTerm); -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorsearchhandle.cpp b/src/plugins/clangrefactoring/qtcreatorsearchhandle.cpp deleted file mode 100644 index c3924dbf4ac..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorsearchhandle.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "qtcreatorsearchhandle.h" - -#include - -#include - -namespace ClangRefactoring { - -QtCreatorSearchHandle::QtCreatorSearchHandle(Core::SearchResult *searchResult) - : searchResult(searchResult) -{ - auto title = QCoreApplication::translate("QtCreatorSearchHandle", "Clang Query"); - Core::ProgressManager::addTask(promise.future(), title, "clang query", {}); -} - -void QtCreatorSearchHandle::addResult(const QString &fileName, - const QString &lineText, - Core::Search::TextRange textRange) -{ - searchResult->addResult(fileName, lineText, textRange); -} - -void QtCreatorSearchHandle::setExpectedResultCount(uint count) -{ - promise.setExpectedResultCount(count); -} - -void QtCreatorSearchHandle::setResultCounter(uint counter) -{ - promise.setProgressValue(counter); -} - -void QtCreatorSearchHandle::cancel() -{ - SearchHandle::cancel(); - promise.reportCanceled(); - promise.reportFinished(); -} - -void QtCreatorSearchHandle::finishSearch() -{ - searchResult->finishSearch(false); - promise.reportFinished(); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorsearchhandle.h b/src/plugins/clangrefactoring/qtcreatorsearchhandle.h deleted file mode 100644 index 8e391e26886..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorsearchhandle.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "searchhandle.h" - -#include - -#include - -namespace ClangRefactoring { - -class QtCreatorSearchHandle final : public SearchHandle -{ -public: - QtCreatorSearchHandle(Core::SearchResult *searchResult); - - void addResult(const QString &fileName, - const QString &lineText, - Core::Search::TextRange textRange) override; - - void setExpectedResultCount(uint count) override; - void setResultCounter(uint counter) override; - - void cancel() override; - - void finishSearch() override; - -private: - Core::SearchResult *searchResult; - QFutureInterface promise; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.cpp b/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.cpp deleted file mode 100644 index eb049d8516a..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "qtcreatorsymbolsfindfilter.h" - -#include "symbolsfindfilterconfigwidget.h" - -namespace ClangRefactoring { - -QWidget *QtCreatorSymbolsFindFilter::createConfigWidget() -{ - return new SymbolsFindFilterConfigWidget(this); -} - -} // ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.h b/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.h deleted file mode 100644 index 60a6d1d7a99..00000000000 --- a/src/plugins/clangrefactoring/qtcreatorsymbolsfindfilter.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "clangsymbolsfindfilter.h" - -namespace ClangRefactoring { - -class QtCreatorSymbolsFindFilter : public SymbolsFindFilter -{ - Q_OBJECT -public: - QtCreatorSymbolsFindFilter() = default; - - QWidget *createConfigWidget() override; -}; - -} // ClangRefactoring diff --git a/src/plugins/clangrefactoring/querysqlitestatementfactory.h b/src/plugins/clangrefactoring/querysqlitestatementfactory.h deleted file mode 100644 index b503a72b0ac..00000000000 --- a/src/plugins/clangrefactoring/querysqlitestatementfactory.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 ClangRefactoring { - -template -class QuerySqliteStatementFactory -{ -public: - using DatabaseType = Database; - template - using ReadStatement = typename Database::template ReadStatement; - - QuerySqliteStatementFactory(Database &database) - : database(database) - {} - Database &database; - ReadStatement<3> selectLocationsForSymbolLocation{ - "SELECT sourceId, line, column FROM locations WHERE symbolId = " - " (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND column=?) " - "ORDER BY sourceId, line, column", - database}; - ReadStatement<3> selectSourceUsagesForSymbolLocation{ - "SELECT directoryPath || '/' || sourceName, line, column " - "FROM locations NATURAL JOIN sources NATURAL JOIN directories " - "WHERE symbolId = (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND " - "column=?)", - database}; - ReadStatement<3> selectSourceUsagesOrderedForSymbolLocation{ - "SELECT directoryPath || '/' || sourceName, line, column " - "FROM locations NATURAL JOIN sources NATURAL JOIN directories " - "WHERE symbolId = (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND " - "column=?) ORDER BY locationKind LIMIT 2", - database}; - ReadStatement<3> selectSourceUsagesByLocationKindForSymbolLocation{ - "SELECT directoryPath || '/' || sourceName, line, column " - "FROM locations NATURAL JOIN sources NATURAL JOIN directories " - "WHERE symbolId = (SELECT symbolId FROM locations WHERE sourceId=? AND line=? AND " - "column=?) AND locationKind = ?", - database}; - ReadStatement<3> selectSymbolsForKindAndStartsWith{ - "SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind = ? AND symbolName " - "LIKE ?", - database}; - ReadStatement<3> selectSymbolsForKindAndStartsWith2{ - "SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind IN (?,?) AND " - "symbolName LIKE ?", - database}; - ReadStatement<3> selectSymbolsForKindAndStartsWith3{ - "SELECT symbolId, symbolName, signature FROM symbols WHERE symbolKind IN (?,?,?) AND " - "symbolName LIKE ?", - database}; - ReadStatement<3> selectLocationOfSymbol{ - "SELECT sourceId, line, column FROM locations AS l WHERE symbolId = ? AND locationKind = ?", - database}; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/refactoringclient.cpp b/src/plugins/clangrefactoring/refactoringclient.cpp deleted file mode 100644 index 4244f441670..00000000000 --- a/src/plugins/clangrefactoring/refactoringclient.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "refactoringclient.h" - -#include "clangqueryhighlighter.h" -#include "clangqueryexamplehighlighter.h" - -#include -#include -#include - -namespace ClangRefactoring { - -void RefactoringClient::alive() -{ - if (m_connectionClient) - m_connectionClient->resetProcessAliveTimer(); -} - -void RefactoringClient::sourceRangesAndDiagnosticsForQueryMessage( - ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage &&message) -{ - m_clangQueryExampleHighlighter->setSourceRanges(message.takeSourceRanges()); - m_clangQueryHighlighter->setDiagnostics(message.diagnostics); -} - -void RefactoringClient::sourceRangesForQueryMessage(ClangBackEnd::SourceRangesForQueryMessage &&message) -{ - ++m_resultCounter; - addSearchResults(message.sourceRanges); - setResultCounterAndSendSearchIsFinishedIfFinished(); -} - -void RefactoringClient::progress(ClangBackEnd::ProgressMessage &&message) -{ - m_progressManager.setProgress(message.progress, message.total); -} - -void RefactoringClient::setRefactoringEngine(RefactoringEngine *refactoringEngine) -{ - m_refactoringEngine = refactoringEngine; -} - -void RefactoringClient::setSearchHandle(SearchHandle *searchHandle) -{ - m_searchHandle = searchHandle; -} - -SearchHandle *RefactoringClient::searchHandle() const -{ - return m_searchHandle; -} - -void RefactoringClient::setClangQueryExampleHighlighter(ClangQueryExampleHighlighter *highlighter) -{ - m_clangQueryExampleHighlighter = highlighter; -} - -void RefactoringClient::setClangQueryHighlighter(ClangQueryHighlighter *highlighter) -{ - m_clangQueryHighlighter = highlighter; -} - -void RefactoringClient::setExpectedResultCount(uint count) -{ - m_expectedResultCount = count; - m_resultCounter = 0; - m_searchHandle->setExpectedResultCount(count); -} - -uint RefactoringClient::expectedResultCount() const -{ - return m_expectedResultCount; -} - -uint RefactoringClient::resultCounter() const -{ - return m_resultCounter; -} - -void RefactoringClient::setRefactoringConnectionClient( - ClangBackEnd::RefactoringConnectionClient *connectionClient) -{ - m_connectionClient = connectionClient; -} - -void RefactoringClient::addSearchResults(const ClangBackEnd::SourceRangesContainer &sourceRanges) -{ - for (const auto &sourceRangeWithText : sourceRanges.sourceRangeWithTextContainers) - addSearchResult(sourceRangeWithText); -} - -void RefactoringClient::addSearchResult(const ClangBackEnd::SourceRangeWithTextContainer &sourceRangeWithText) -{ - auto &filePathCache = m_refactoringEngine->filePathCache(); - - m_searchHandle->addResult(QString(filePathCache.filePath(sourceRangeWithText.filePathId()).path()), - QString(sourceRangeWithText.text), - {{int(sourceRangeWithText.start.line), - int(sourceRangeWithText.start.column - 1)}, - {int(sourceRangeWithText.end.line), - int(sourceRangeWithText.end.column - 1)}}); -} - -void RefactoringClient::setResultCounterAndSendSearchIsFinishedIfFinished() -{ - m_searchHandle->setResultCounter(m_resultCounter); - if (m_resultCounter == m_expectedResultCount) - m_searchHandle->finishSearch(); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/refactoringclient.h b/src/plugins/clangrefactoring/refactoringclient.h deleted file mode 100644 index a68fe39211f..00000000000 --- a/src/plugins/clangrefactoring/refactoringclient.h +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "refactoringengine.h" - -#include "searchhandle.h" - -#include -#include - -#include - -namespace ClangBackEnd { -class FilePath; -class RefactoringConnectionClient; -class SourceRangesContainer; -class SourceRangeWithTextContainer; -} - -namespace ClangRefactoring { - -class ClangQueryExampleHighlighter; -class ClangQueryHighlighter; - -class RefactoringClient final : public ClangBackEnd::RefactoringClientInterface -{ -public: - RefactoringClient(ClangPchManager::ProgressManagerInterface &progressManager) - : m_progressManager(progressManager) - {} - - void alive() override; - void sourceRangesAndDiagnosticsForQueryMessage( - ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage &&message) override; - void sourceRangesForQueryMessage( - ClangBackEnd::SourceRangesForQueryMessage &&message) override; - - void progress(ClangBackEnd::ProgressMessage &&message) override; - - void setRefactoringEngine(ClangRefactoring::RefactoringEngine *refactoringEngine); - void setSearchHandle(ClangRefactoring::SearchHandle *searchHandleInterface); - ClangRefactoring::SearchHandle *searchHandle() const; - void setClangQueryExampleHighlighter(ClangQueryExampleHighlighter *highlighter); - void setClangQueryHighlighter(ClangQueryHighlighter *highlighter); - - void setExpectedResultCount(uint count); - uint expectedResultCount() const; - uint resultCounter() const; - - void setRefactoringConnectionClient(ClangBackEnd::RefactoringConnectionClient *connectionClient); - - -unittest_public: - void addSearchResult(const ClangBackEnd::SourceRangeWithTextContainer &sourceRange); - -private: - void addSearchResults(const ClangBackEnd::SourceRangesContainer &sourceRanges); - - void setResultCounterAndSendSearchIsFinishedIfFinished(); - void sendSearchIsFinished(); - -private: - ClangBackEnd::RefactoringConnectionClient *m_connectionClient = nullptr; - SearchHandle *m_searchHandle = nullptr; - RefactoringEngine *m_refactoringEngine = nullptr; - ClangQueryExampleHighlighter *m_clangQueryExampleHighlighter = nullptr; - ClangQueryHighlighter *m_clangQueryHighlighter = nullptr; - ClangPchManager::ProgressManagerInterface &m_progressManager; - uint m_expectedResultCount = 0; - uint m_resultCounter = 0; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/refactoringconnectionclient.cpp b/src/plugins/clangrefactoring/refactoringconnectionclient.cpp deleted file mode 100644 index d26d20df3f6..00000000000 --- a/src/plugins/clangrefactoring/refactoringconnectionclient.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "refactoringconnectionclient.h" - -#include - -#include - -#include - -namespace ClangBackEnd { - -namespace { - -QString currentProcessId() -{ - return QString::number(QCoreApplication::applicationPid()); -} - -} - -RefactoringConnectionClient::RefactoringConnectionClient(RefactoringClientInterface *client) - : ConnectionClient(Utils::TemporaryDirectory::masterDirectoryPath() - + QStringLiteral("/ClangRefactoringBackEnd-") + currentProcessId()) - , m_serverProxy(client) -{ - m_processCreator.setTemporaryDirectoryPattern("clangrefactoringbackend-XXXXXX"); - m_processCreator.setArguments({connectionName(), - Core::ICore::cacheResourcePath("symbol-experimental-v1.db").toString(), - Core::ICore::resourcePath().toString()}); - - stdErrPrefixer().setPrefix("RefactoringConnectionClient.stderr: "); - stdOutPrefixer().setPrefix("RefactoringConnectionClient.stdout: "); -} - -RefactoringConnectionClient::~RefactoringConnectionClient() -{ - finishProcess(); -} - -RefactoringServerProxy &RefactoringConnectionClient::serverProxy() -{ - return m_serverProxy; -} - -void RefactoringConnectionClient::sendEndCommand() -{ - m_serverProxy.end(); -} - -void RefactoringConnectionClient::resetState() -{ - m_serverProxy.resetState(); -} - -QString RefactoringConnectionClient::outputName() const -{ - return QStringLiteral("RefactoringConnectionClient"); -} - -void RefactoringConnectionClient::newConnectedServer(QLocalSocket *localSocket) -{ - m_serverProxy.setLocalSocket(localSocket); -} - -} // namespace ClangBackEnd diff --git a/src/plugins/clangrefactoring/refactoringconnectionclient.h b/src/plugins/clangrefactoring/refactoringconnectionclient.h deleted file mode 100644 index 3db871e6a21..00000000000 --- a/src/plugins/clangrefactoring/refactoringconnectionclient.h +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include -#include - -namespace ClangBackEnd { - -class RefactoringClientInterface; - -class RefactoringConnectionClient : public ConnectionClient -{ -public: - RefactoringConnectionClient(RefactoringClientInterface *client); - ~RefactoringConnectionClient(); - - RefactoringServerProxy &serverProxy(); - -protected: - void sendEndCommand() override; - void resetState() override; - QString outputName() const override; - void newConnectedServer(QLocalSocket *localSocket) override; - -private: - RefactoringServerProxy m_serverProxy; -}; - -} // namespace ClangBackEnd diff --git a/src/plugins/clangrefactoring/refactoringengine.cpp b/src/plugins/clangrefactoring/refactoringengine.cpp deleted file mode 100644 index f376d5806b4..00000000000 --- a/src/plugins/clangrefactoring/refactoringengine.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "refactoringengine.h" -#include "projectpartutilities.h" - -#include -#include - -#include -#include - -#include - -#include -#include - -#include -#include -#include -#include - -#include - -namespace ClangRefactoring { - - -RefactoringEngine::RefactoringEngine(ClangBackEnd::RefactoringServerInterface &server, - ClangBackEnd::RefactoringClientInterface &client, - ClangBackEnd::FilePathCachingInterface &filePathCache, - SymbolQueryInterface &symbolQuery) - : m_server(server), - m_client(client), - m_filePathCache(filePathCache), - m_symbolQuery(symbolQuery) -{ - Q_UNUSED(m_client) -} - -RefactoringEngine::~RefactoringEngine() = default; - -void RefactoringEngine::startLocalRenaming(const CppTools::CursorInEditor &, - CppTools::ProjectPart *, - RenameCallback &&) -{ -} - -CppTools::Usages RefactoringEngine::locationsAt(const CppTools::CursorInEditor &data) const -{ - if (data.cursor().isNull()) - return {}; - - QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor()); - Utils::OptionalLineColumn lineColumn = Utils::Text::convertPosition(cursor.document(), - cursor.position()); - - if (lineColumn) { - const QByteArray filePath = data.filePath().toString().toUtf8(); - const ClangBackEnd::FilePathId filePathId = m_filePathCache.filePathId(ClangBackEnd::FilePathView(filePath)); - - return m_symbolQuery.sourceUsagesAt(filePathId, lineColumn->line, lineColumn->column); - } - - return {}; -} - -CppTools::Usages RefactoringEngine::declarationAt(const CppTools::CursorInEditor &data) const -{ - if (data.cursor().isNull()) - return {}; - - QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor()); - Utils::OptionalLineColumn lineColumn = Utils::Text::convertPosition(cursor.document(), - cursor.position()); - - if (lineColumn) { - const QByteArray filePath = data.filePath().toString().toUtf8(); - const ClangBackEnd::FilePathId filePathId = m_filePathCache.filePathId( - ClangBackEnd::FilePathView(filePath)); - - return m_symbolQuery.declarationsAt(filePathId, lineColumn->line, lineColumn->column); - } - - return {}; -} - -void RefactoringEngine::globalRename(const CppTools::CursorInEditor &data, - CppTools::UsagesCallback &&renameUsagesCallback, - const QString &) -{ - renameUsagesCallback(locationsAt(data)); -} - -void RefactoringEngine::findUsages(const CppTools::CursorInEditor &data, - CppTools::UsagesCallback &&showUsagesCallback) const -{ - showUsagesCallback(locationsAt(data)); -} - -void RefactoringEngine::globalFollowSymbol(const CppTools::CursorInEditor &data, - Utils::ProcessLinkCallback &&processLinkCallback, - const CPlusPlus::Snapshot &, - const CPlusPlus::Document::Ptr &, - CppTools::SymbolFinder *, - bool) const -{ - const CppTools::Usages usages = declarationAt(data); - CppTools::Usage usage = Utils::findOrDefault(usages, [&data](const CppTools::Usage &usage) { - return usage.path != data.filePath().toString(); - - }); - - processLinkCallback(Link(Utils::FilePath::fromString(usage.path), usage.line, usage.column - 1)); -} - -bool RefactoringEngine::isRefactoringEngineAvailable() const -{ - return m_server.isAvailable(); -} - -void RefactoringEngine::setRefactoringEngineAvailable(bool isAvailable) -{ - m_server.setAvailable(isAvailable); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/refactoringengine.h b/src/plugins/clangrefactoring/refactoringengine.h deleted file mode 100644 index 4dfef3ba0c2..00000000000 --- a/src/plugins/clangrefactoring/refactoringengine.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "symbolqueryinterface.h" - -#include - -#include - -namespace ClangBackEnd { -class RefactoringClientInterface; -class RefactoringServerInterface; -} - -namespace CppTools { class SymbolFinder; } - -namespace ClangRefactoring { - -class RefactoringEngine : public CppTools::RefactoringEngineInterface -{ -public: - RefactoringEngine(ClangBackEnd::RefactoringServerInterface &server, - ClangBackEnd::RefactoringClientInterface &client, - ClangBackEnd::FilePathCachingInterface &filePathCache, - SymbolQueryInterface &symbolQuery); - ~RefactoringEngine() override; - - void startLocalRenaming(const CppTools::CursorInEditor &data, - CppTools::ProjectPart *projectPart, - RenameCallback &&renameSymbolsCallback) override; - void globalRename(const CppTools::CursorInEditor &data, - CppTools::UsagesCallback &&renameUsagesCallback, - const QString &) override; - void findUsages(const CppTools::CursorInEditor &data, - CppTools::UsagesCallback &&showUsagesCallback) const override; - void globalFollowSymbol(const CppTools::CursorInEditor &data, - Utils::ProcessLinkCallback &&processLinkCallback, - const CPlusPlus::Snapshot &, - const CPlusPlus::Document::Ptr &, - CppTools::SymbolFinder *, - bool) const override; - - bool isRefactoringEngineAvailable() const override; - void setRefactoringEngineAvailable(bool isAvailable); - - const ClangBackEnd::FilePathCachingInterface &filePathCache() const - { - return m_filePathCache; - } - -private: - CppTools::Usages locationsAt(const CppTools::CursorInEditor &data) const; - CppTools::Usages declarationAt(const CppTools::CursorInEditor &data) const; - - ClangBackEnd::RefactoringServerInterface &m_server; - ClangBackEnd::RefactoringClientInterface &m_client; - ClangBackEnd::FilePathCachingInterface &m_filePathCache; - - SymbolQueryInterface &m_symbolQuery; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/refactoringprojectupdater.cpp b/src/plugins/clangrefactoring/refactoringprojectupdater.cpp deleted file mode 100644 index 20a9fce730d..00000000000 --- a/src/plugins/clangrefactoring/refactoringprojectupdater.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "refactoringprojectupdater.h" - -#include -#include - -namespace ClangRefactoring { - -void RefactoringProjectUpdater::precompiledHeaderUpdated(ClangBackEnd::ProjectPartId projectPartId) -{ - const QString projectPartName = fetchProjectPartName(projectPartId); - - auto projectPart = m_cppModelManager.projectPartForId(projectPartName); - if (projectPart) - updateProjectParts({projectPart.data()}, {}); -} - -void RefactoringProjectUpdater::precompiledHeaderRemoved(ClangBackEnd::ProjectPartId projectPartId) -{ - removeProjectParts({projectPartId}); -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/refactoringprojectupdater.h b/src/plugins/clangrefactoring/refactoringprojectupdater.h deleted file mode 100644 index 01e96cb0a45..00000000000 --- a/src/plugins/clangrefactoring/refactoringprojectupdater.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include -#include - -#include - -namespace ClangRefactoring { - -class RefactoringProjectUpdater : public ClangPchManager::ProjectUpdater, - public ClangPchManager::PchManagerNotifierInterface -{ -public: - RefactoringProjectUpdater(ClangBackEnd::ProjectManagementServerInterface &server, - ClangPchManager::PchManagerClient &pchManagerClient, - CppTools::CppModelManagerInterface &cppModelManager, - ClangBackEnd::FilePathCachingInterface &filePathCache, - ClangBackEnd::ProjectPartsStorageInterface &projectPartsStorage, - ClangPchManager::ClangIndexingSettingsManager &settingsManager) - : ClangPchManager::ProjectUpdater(server, filePathCache, projectPartsStorage, settingsManager) - , ClangPchManager::PchManagerNotifierInterface(pchManagerClient) - , m_cppModelManager(cppModelManager) - { - } - - void precompiledHeaderUpdated(ClangBackEnd::ProjectPartId projectPartId) override; - void precompiledHeaderRemoved(ClangBackEnd::ProjectPartId projectPartId) override; - -private: - CppTools::CppModelManagerInterface &m_cppModelManager; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/searchhandle.cpp b/src/plugins/clangrefactoring/searchhandle.cpp deleted file mode 100644 index c73aa4e96c4..00000000000 --- a/src/plugins/clangrefactoring/searchhandle.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "searchhandle.h" - -namespace ClangRefactoring { - -SearchHandle::~SearchHandle() -{ -} - -void SearchHandle::cancel() -{ - server->cancel(); -} - -void SearchHandle::setRefactoringServer(ClangBackEnd::RefactoringServerInterface *server) -{ - this->server = server; -} - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/searchhandle.h b/src/plugins/clangrefactoring/searchhandle.h deleted file mode 100644 index 804af2c3702..00000000000 --- a/src/plugins/clangrefactoring/searchhandle.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include - -#include - -namespace ClangRefactoring { - -class SearchHandle -{ -public: - SearchHandle() = default; - SearchHandle(const SearchHandle &) = delete; - SearchHandle &operator=(const SearchHandle &) = delete; - - virtual ~SearchHandle(); - - virtual void addResult(const QString &fileName, - const QString &lineText, - Core::Search::TextRange textRange) = 0; - - virtual void setExpectedResultCount(uint count) = 0; - virtual void setResultCounter(uint counter) = 0; - - virtual void finishSearch() = 0; - - virtual void cancel(); - - void setRefactoringServer(ClangBackEnd::RefactoringServerInterface *server); - -private: - ClangBackEnd::RefactoringServerInterface *server = nullptr; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/searchinterface.h b/src/plugins/clangrefactoring/searchinterface.h deleted file mode 100644 index 62a2f07be86..00000000000 --- a/src/plugins/clangrefactoring/searchinterface.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "searchhandle.h" - -#include - -#include - -namespace ClangRefactoring { - -class SearchInterface -{ -public: - SearchInterface() = default; - SearchInterface(const SearchInterface &) = delete; - SearchInterface &operator=(const SearchInterface &) = delete; - - virtual std::unique_ptr startNewSearch(const QString &searchLabel, - const QString &searchTerm) = 0; - -protected: - ~SearchInterface() = default; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/sourcelocations.h b/src/plugins/clangrefactoring/sourcelocations.h deleted file mode 100644 index 80fc0d89c00..00000000000 --- a/src/plugins/clangrefactoring/sourcelocations.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -#include - -#include - -#include - -namespace ClangRefactoring { - -class SourceLocation -{ -public: - SourceLocation() = default; - SourceLocation(ClangBackEnd::FilePathId filePathId, Utils::LineColumn lineColumn) - : filePathId{filePathId}, lineColumn{lineColumn} - {} - SourceLocation(ClangBackEnd::FilePathId filePathId, int line, int column) - : filePathId{filePathId}, lineColumn{line, column} - {} - SourceLocation(int sourceId, int line, int column) - : filePathId{sourceId}, lineColumn{line, column} - {} - - friend bool operator==(SourceLocation first, SourceLocation second) - { - return first.filePathId == second.filePathId - && first.lineColumn == second.lineColumn; - } - -public: - ClangBackEnd::FilePathId filePathId; - Utils::LineColumn lineColumn; -}; - -using SourceLocations = std::vector; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/symbol.h b/src/plugins/clangrefactoring/symbol.h deleted file mode 100644 index 51feaedfd08..00000000000 --- a/src/plugins/clangrefactoring/symbol.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -#include - -namespace ClangRefactoring { - -using SymbolString = Utils::BasicSmallString<63>; -using SignatureString = Utils::BasicSmallString<126>; -using SymbolId = long long; - -class Symbol -{ -public: - Symbol() = default; - Symbol(SymbolId symbolId, Utils::SmallStringView name) - : name(name), symbolId(symbolId) - {} - Symbol(SymbolId symbolId, Utils::SmallStringView name, Utils::SmallStringView signature) - : signature(signature), name(name), symbolId(symbolId) - {} - SignatureString signature; - SymbolString name; - SymbolId symbolId; - - friend - bool operator==(const Symbol &first, const Symbol &second) - { - return first.symbolId == second.symbolId - && first.name == second.name - && first.signature == second.signature; - } -}; - -using Symbols = std::vector; - -} // namespace ClangRefactoring - -Q_DECLARE_METATYPE(ClangRefactoring::Symbol) diff --git a/src/plugins/clangrefactoring/symbolquery.h b/src/plugins/clangrefactoring/symbolquery.h deleted file mode 100644 index 009a41e0b0d..00000000000 --- a/src/plugins/clangrefactoring/symbolquery.h +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "symbolqueryinterface.h" - -#include "sourcelocations.h" - -#include - -#include - -#include - -namespace ClangRefactoring { - -template -class SymbolQuery final : public SymbolQueryInterface -{ -public: - SymbolQuery(StatementFactory &statementFactory) - : m_statementFactory(statementFactory) - {} - - SourceLocations locationsAt(ClangBackEnd::FilePathId filePathId, - int line, - int utf8Column) const override - { - auto &locationsStatement = m_statementFactory.selectLocationsForSymbolLocation; - - const std::size_t reserveSize = 128; - - return locationsStatement.template values(reserveSize, - filePathId.filePathId, - line, - utf8Column); - } - - CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId, - int line, - int utf8Column) const override - { - auto &locationsStatement = m_statementFactory.selectSourceUsagesForSymbolLocation; - - const std::size_t reserveSize = 128; - - return locationsStatement.template values(reserveSize, - filePathId.filePathId, - line, - utf8Column); - } - - CppTools::Usages sourceUsagesAtByLocationKind(ClangBackEnd::FilePathId filePathId, - int line, - int utf8Column, - ClangBackEnd::SourceLocationKind kind) const override - { - auto &locationsStatement = m_statementFactory.selectSourceUsagesByLocationKindForSymbolLocation; - - const std::size_t reserveSize = 128; - - return locationsStatement.template values(reserveSize, - filePathId.filePathId, - line, - utf8Column, - int(kind)); - } - - CppTools::Usages declarationsAt(ClangBackEnd::FilePathId filePathId, - int line, - int utf8Column) const override - { - auto &locationsStatement = m_statementFactory.selectSourceUsagesOrderedForSymbolLocation; - - const std::size_t reserveSize = 128; - - return locationsStatement.template values(reserveSize, - filePathId.filePathId, - line, - utf8Column); - } - - Symbols symbolsWithOneSymbolKinds(ClangBackEnd::SymbolKind symbolKind, - Utils::SmallStringView searchTerm) const - { - auto &statement = m_statementFactory.selectSymbolsForKindAndStartsWith; - - return statement.template values(100, int(symbolKind), searchTerm); - } - - Symbols symbolsWithTwoSymbolKinds(ClangBackEnd::SymbolKind symbolKind1, - ClangBackEnd::SymbolKind symbolKind2, - Utils::SmallStringView searchTerm) const - { - auto &statement = m_statementFactory.selectSymbolsForKindAndStartsWith2; - - return statement.template values(100, int(symbolKind1), int(symbolKind2), searchTerm); - } - - Symbols symbolsWithThreeSymbolKinds(ClangBackEnd::SymbolKind symbolKind1, - ClangBackEnd::SymbolKind symbolKind2, - ClangBackEnd::SymbolKind symbolKind3, - Utils::SmallStringView searchTerm) const - { - auto &statement = m_statementFactory.selectSymbolsForKindAndStartsWith3; - - return statement.template values(100, - int(symbolKind1), - int(symbolKind2), - int(symbolKind3), - searchTerm); - } - - Symbols symbols(const ClangBackEnd::SymbolKinds &symbolKinds, - Utils::SmallStringView searchTerm) const override - { - switch (symbolKinds.size()) - { - case 1: return symbolsWithOneSymbolKinds(symbolKinds[0], searchTerm); - case 2: return symbolsWithTwoSymbolKinds(symbolKinds[0], symbolKinds[1], searchTerm); - case 3: return symbolsWithThreeSymbolKinds(symbolKinds[0], symbolKinds[1], symbolKinds[2], searchTerm); - } - - return Symbols(); - } - - Utils::optional locationForSymbolId(SymbolId symbolId, - ClangBackEnd::SourceLocationKind kind) const override - { - auto &statement = m_statementFactory.selectLocationOfSymbol; - - return statement.template optionalValue(symbolId, int(kind)); - } -private: - StatementFactory &m_statementFactory; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/symbolqueryinterface.h b/src/plugins/clangrefactoring/symbolqueryinterface.h deleted file mode 100644 index 6ea6c97304c..00000000000 --- a/src/plugins/clangrefactoring/symbolqueryinterface.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "sourcelocations.h" - -#include "symbol.h" - -#include - -namespace ClangRefactoring { - -class SymbolQueryInterface -{ -public: - SymbolQueryInterface() = default; - SymbolQueryInterface(const SymbolQueryInterface &) = delete; - SymbolQueryInterface &operator=(const SymbolQueryInterface &) = delete; - - virtual SourceLocations locationsAt(ClangBackEnd::FilePathId filePathId, - int line, - int utf8Column) const = 0; - virtual CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId, - int line, - int utf8Column) const = 0; - virtual CppTools::Usages sourceUsagesAtByLocationKind(ClangBackEnd::FilePathId filePathId, - int line, - int utf8Column, - ClangBackEnd::SourceLocationKind) const = 0; - virtual Symbols symbols(const ClangBackEnd::SymbolKinds &symbolKinds, - Utils::SmallStringView searchTerm) const = 0; - virtual Utils::optional locationForSymbolId(SymbolId symbolId, - ClangBackEnd::SourceLocationKind kind) const = 0; - virtual CppTools::Usages declarationsAt(ClangBackEnd::FilePathId filePathId, - int line, - int utf8Column) const = 0; - -protected: - ~SymbolQueryInterface() = default; -}; - -} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/symbolsfindfilterconfigwidget.cpp b/src/plugins/clangrefactoring/symbolsfindfilterconfigwidget.cpp deleted file mode 100644 index abe3013c7d9..00000000000 --- a/src/plugins/clangrefactoring/symbolsfindfilterconfigwidget.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - - -#include "symbolsfindfilterconfigwidget.h" - -#include "clangsymbolsfindfilter.h" - -namespace ClangRefactoring { - -SymbolsFindFilterConfigWidget::SymbolsFindFilterConfigWidget(SymbolsFindFilter *) -{ - -} - -} // ClangRefactoring - diff --git a/src/plugins/clangrefactoring/symbolsfindfilterconfigwidget.h b/src/plugins/clangrefactoring/symbolsfindfilterconfigwidget.h deleted file mode 100644 index b51ab4ed1db..00000000000 --- a/src/plugins/clangrefactoring/symbolsfindfilterconfigwidget.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -namespace ClangRefactoring { - -class SymbolsFindFilter; - -class SymbolsFindFilterConfigWidget : public QWidget -{ - Q_OBJECT -public: - SymbolsFindFilterConfigWidget(SymbolsFindFilter *filter); -}; - -} // ClangRefactoring diff --git a/src/plugins/cppeditor/cppeditor.qbs b/src/plugins/cppeditor/cppeditor.qbs index a6c27c30c5a..e20f8245da3 100644 --- a/src/plugins/cppeditor/cppeditor.qbs +++ b/src/plugins/cppeditor/cppeditor.qbs @@ -5,6 +5,7 @@ QtcPlugin { name: "CppEditor" Depends { name: "Qt.widgets" } + Depends { name: "ClangSupport" } Depends { name: "CPlusPlus" } Depends { name: "Utils" } diff --git a/src/plugins/cppeditor/cppeditorwidget.cpp b/src/plugins/cppeditor/cppeditorwidget.cpp index 71842271f59..7e48d545456 100644 --- a/src/plugins/cppeditor/cppeditorwidget.cpp +++ b/src/plugins/cppeditor/cppeditorwidget.cpp @@ -608,7 +608,7 @@ ProjectPart *CppEditorWidget::projectPart() const namespace { -using ClangBackEnd::V2::SourceLocationContainer; +using ClangBackEnd::SourceLocationContainer; using Utils::Text::selectAt; QTextCharFormat occurrencesTextCharFormat() diff --git a/src/plugins/cpptools/CMakeLists.txt b/src/plugins/cpptools/CMakeLists.txt index e1aab60cc95..fe481af9418 100644 --- a/src/plugins/cpptools/CMakeLists.txt +++ b/src/plugins/cpptools/CMakeLists.txt @@ -1,6 +1,6 @@ add_qtc_plugin(CppTools DEPENDS Qt5::Network Qt5::Xml - PUBLIC_DEPENDS CPlusPlus Qt5::Widgets + PUBLIC_DEPENDS CPlusPlus ClangSupport Qt5::Widgets PLUGIN_DEPENDS Core ProjectExplorer TextEditor PLUGIN_TEST_DEPENDS CppEditor QmakeProjectManager SOURCES diff --git a/src/plugins/cpptools/cpprefactoringengine.cpp b/src/plugins/cpptools/cpprefactoringengine.cpp index f816b507a5a..94d2871c368 100644 --- a/src/plugins/cpptools/cpprefactoringengine.cpp +++ b/src/plugins/cpptools/cpprefactoringengine.cpp @@ -30,6 +30,7 @@ #include "cpptoolsreuse.h" #include "cppfollowsymbolundercursor.h" +#include #include #include diff --git a/src/plugins/cpptools/cpptools.qbs b/src/plugins/cpptools/cpptools.qbs index f7dce998c6b..13382138bfb 100644 --- a/src/plugins/cpptools/cpptools.qbs +++ b/src/plugins/cpptools/cpptools.qbs @@ -8,6 +8,7 @@ Project { Depends { name: "Qt.widgets" } Depends { name: "Qt.testlib"; condition: project.withAutotests } Depends { name: "CPlusPlus" } + Depends { name: "ClangSupport" } Depends { name: "Utils" } Depends { name: "Core" } diff --git a/src/plugins/cpptools/cpptools_dependencies.pri b/src/plugins/cpptools/cpptools_dependencies.pri index 9ff54010ad7..96a62635a6f 100644 --- a/src/plugins/cpptools/cpptools_dependencies.pri +++ b/src/plugins/cpptools/cpptools_dependencies.pri @@ -1,6 +1,7 @@ QTC_PLUGIN_NAME = CppTools QTC_LIB_DEPENDS += \ cplusplus \ + clangsupport \ extensionsystem \ utils QTC_PLUGIN_DEPENDS += \ diff --git a/src/plugins/cpptools/refactoringengineinterface.h b/src/plugins/cpptools/refactoringengineinterface.h index 93f365a24b8..d5a95fe0f6a 100644 --- a/src/plugins/cpptools/refactoringengineinterface.h +++ b/src/plugins/cpptools/refactoringengineinterface.h @@ -32,15 +32,16 @@ #include #include -#include -#include - #include namespace TextEditor { class TextEditorWidget; } // namespace TextEditor +namespace ClangBackEnd { +class SourceLocationsContainer; +} + namespace CppTools { class ProjectPart; @@ -56,7 +57,9 @@ enum class CallType class CPPTOOLS_EXPORT RefactoringEngineInterface { public: - using RenameCallback = ClangBackEnd::RefactoringClientInterface::RenameCallback; + using RenameCallback = std::function; using Link = Utils::Link; virtual ~RefactoringEngineInterface() = default; diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 216407558ee..1a1a2eb26bf 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -118,12 +118,6 @@ exists(../shared/qbs/qbs.pro)|!isEmpty(QBS_INSTALL_DIR): \ SUBDIRS += \ clangcodemodel -QTC_ENABLE_CLANG_REFACTORING=$$(QTC_ENABLE_CLANG_REFACTORING) -!isEmpty(QTC_ENABLE_CLANG_REFACTORING) { - SUBDIRS += clangrefactoring - SUBDIRS += clangpchmanager -} - isEmpty(IDE_PACKAGE_MODE) { SUBDIRS += \ helloworld diff --git a/src/plugins/plugins.qbs b/src/plugins/plugins.qbs index 4a2298dc551..eb2af838029 100644 --- a/src/plugins/plugins.qbs +++ b/src/plugins/plugins.qbs @@ -15,8 +15,6 @@ Project { "boot2qt/boot2qt.qbs", "clangcodemodel/clangcodemodel.qbs", "clangformat/clangformat.qbs", - "clangpchmanager/clangpchmanager.qbs", - "clangrefactoring/clangrefactoring.qbs", "clangtools/clangtools.qbs", "classview/classview.qbs", "clearcase/clearcase.qbs", diff --git a/src/shared/clang/clang_installation.pri b/src/shared/clang/clang_installation.pri index bdfefd3616c..2811f0b2c14 100644 --- a/src/shared/clang/clang_installation.pri +++ b/src/shared/clang/clang_installation.pri @@ -241,22 +241,6 @@ isEmpty(LLVM_VERSION) { !contains(QMAKE_DEFAULT_LIBDIRS, $$re_escape($$LLVM_LIBDIR)): LIBCLANG_LIBS = -L$${LLVM_LIBDIR} LIBCLANG_LIBS += $${CLANG_LIB} - isEmpty(QTC_CLANG_BUILDMODE_MISMATCH)|!equals(QTC_CLANG_BUILDMODE_MISMATCH, 1) { - QTC_ENABLE_CLANG_REFACTORING=$$(QTC_ENABLE_CLANG_REFACTORING) - !isEmpty(QTC_ENABLE_CLANG_REFACTORING) { - exists($$LLVM_LIBDIR/*clangBasic*) { - CLANGTOOLING_LIBS=-lclangTooling -lclangIndex -lclangFrontend -lclangParse -lclangSerialization \ - -lclangSema -lclangEdit -lclangAnalysis -lclangDriver -lclangDynamicASTMatchers \ - -lclangASTMatchers -lclangToolingCore -lclangAST -lclangLex -lclangBasic - win32:CLANGTOOLING_LIBS += -lversion - } else { - CLANGTOOLING_LIBS = -lclang-cpp - } - !contains(QMAKE_DEFAULT_LIBDIRS, $$LLVM_LIBDIR): LIBTOOLING_LIBS = -L$${LLVM_LIBDIR} - LIBTOOLING_LIBS += $$CLANGTOOLING_LIBS $$LLVM_STATIC_LIBS - } - } - !isEmpty(CLANGFORMAT_LIBS) { CLANGFORMAT_LIBS = -L$${LLVM_LIBDIR} $$CLANGFORMAT_LIBS $$LLVM_STATIC_LIBS } diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 1bf6f1246d1..1719a99aff9 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -4,8 +4,6 @@ if (NOT Clang_FOUND) message(WARNING "Could not find Clang installation - disabling clangbackend.") else () add_subdirectory(clangbackend) - add_subdirectory(clangrefactoringbackend) - add_subdirectory(clangpchmanagerbackend) endif () option(BUILD_CPLUSPLUS_TOOLS "Build CPlusPlus tools" OFF) diff --git a/src/tools/clangpchmanagerbackend/CMakeLists.txt b/src/tools/clangpchmanagerbackend/CMakeLists.txt deleted file mode 100644 index dc42a23c341..00000000000 --- a/src/tools/clangpchmanagerbackend/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -add_subdirectory(source) - -add_qtc_executable(clangpchmanagerbackend - CONDITION TARGET ClangPchManager - DEPENDS - clangrefactoringbackend_lib clangpchmanagerbackend_lib - Sqlite ClangSupport - ${CLANG_TOOLING_LIBS} - SOURCES - clangpchmanagerbackendmain.cpp -) diff --git a/src/tools/clangpchmanagerbackend/clangpchmanagerbackend.pro b/src/tools/clangpchmanagerbackend/clangpchmanagerbackend.pro deleted file mode 100644 index 0997b0ec961..00000000000 --- a/src/tools/clangpchmanagerbackend/clangpchmanagerbackend.pro +++ /dev/null @@ -1,31 +0,0 @@ -QTC_LIB_DEPENDS += \ - clangsupport - -include(../../qtcreatortool.pri) -include(../../shared/clang/clang_installation.pri) -include(source/clangpchmanagerbackend-source.pri) - -requires(!isEmpty(LIBTOOLING_LIBS)) - -win32 { - LLVM_BUILDMODE = $$system($$llvm_config --build-mode, lines) - CONFIG(debug, debug|release):requires(equals(LLVM_BUILDMODE, "Debug")) -} - -QT += core network -QT -= gui - -LIBS += $$LIBTOOLING_LIBS -INCLUDEPATH += $$LLVM_INCLUDEPATH - -QMAKE_CXXFLAGS_WARN_ON *= $$LLVM_CXXFLAGS_WARNINGS -QMAKE_CXXFLAGS *= $$LLVM_CXXFLAGS - -INCLUDEPATH += ../clangrefactoringbackend/source - -SOURCES += \ - clangpchmanagerbackendmain.cpp \ - ../clangrefactoringbackend/source/clangtool.cpp \ - ../clangrefactoringbackend/source/refactoringcompilationdatabase.cpp - -DEFINES += CLANG_COMPILER_PATH=\"R\\\"xxx($${LLVM_BINDIR}/clang)xxx\\\"\" diff --git a/src/tools/clangpchmanagerbackend/clangpchmanagerbackend.qbs b/src/tools/clangpchmanagerbackend/clangpchmanagerbackend.qbs deleted file mode 100644 index ae35d141ab8..00000000000 --- a/src/tools/clangpchmanagerbackend/clangpchmanagerbackend.qbs +++ /dev/null @@ -1,53 +0,0 @@ -import qbs -import qbs.FileInfo - -QtcTool { - name: "clangpchmanagerbackend" - Depends { name: "libclang"; required: false } - condition: libclang.present - && libclang.toolingEnabled - && (!qbs.targetOS.contains("windows") || libclang.llvmBuildModeMatches) - - Depends { name: "ClangSupport" } - - Depends { name: "Qt.network" } - - cpp.cxxFlags: base.concat(libclang.llvmToolingCxxFlags) - cpp.defines: { - var list = base.concat(libclang.llvmToolingDefines); - list.push('CLANG_COMPILER_PATH="' - + FileInfo.joinPaths(FileInfo.path(libclang.llvmConfig), "clang") + '"'); - return list; - } - cpp.includePaths: base.concat(libclang.llvmIncludeDir).concat(libclang.llvmToolingIncludes) - .concat(["source", "../clangrefactoringbackend/source"]) - cpp.libraryPaths: base.concat(libclang.llvmLibDir) - cpp.dynamicLibraries: base.concat(libclang.llvmToolingLibs) - - Properties { - condition: qbs.targetOS.contains("unix") && !qbs.targetOS.contains("macos") - cpp.rpaths: base.concat(libclang.llvmLibDir) - } - - files: [ - "clangpchmanagerbackendmain.cpp", - ] - - Group { - prefix: "source/" - files: [ - "*.h", - "*.cpp" - ] - } - - Group { - name: "sources from clangrefactoring" - prefix: "../clangrefactoringbackend/source/" - files: [ - "clangtool.cpp", - "refactoringcompilationdatabase.cpp", - ] - } -} - diff --git a/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp b/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp deleted file mode 100644 index c7fe8e41384..00000000000 --- a/src/tools/clangpchmanagerbackend/clangpchmanagerbackendmain.cpp +++ /dev/null @@ -1,297 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std::chrono_literals; - -using ClangBackEnd::ClangPathWatcher; -using ClangBackEnd::ConnectionServer; -using ClangBackEnd::FilePathCache; -using ClangBackEnd::FilePathView; -using ClangBackEnd::GeneratedFiles; -using ClangBackEnd::PchCreator; -using ClangBackEnd::PchManagerClientProxy; -using ClangBackEnd::PchManagerServer; -using ClangBackEnd::PrecompiledHeaderStorage; -using ClangBackEnd::ProjectPartsManager; -using ClangBackEnd::ProjectPartsStorage; -using ClangBackEnd::TimeStamp; - -class PchManagerApplication final : public QCoreApplication -{ -public: - using QCoreApplication::QCoreApplication; - - bool notify(QObject *object, QEvent *event) override - { - try { - return QCoreApplication::notify(object, event); - } catch (Sqlite::Exception &exception) { - exception.printWarning(); - } - - return false; - } -}; - -class ApplicationEnvironment final : public ClangBackEnd::Environment -{ -public: - ApplicationEnvironment(const QString &pchsPath, const QString &preIncludeSearchPath) - : m_pchBuildDirectoryPath(pchsPath.toStdString()) - , m_preIncludeSearchPath(ClangBackEnd::FilePath{preIncludeSearchPath}) - { - } - - Utils::PathString pchBuildDirectory() const override { return m_pchBuildDirectoryPath; } - uint hardwareConcurrency() const override { return std::thread::hardware_concurrency(); } - ClangBackEnd::NativeFilePathView preIncludeSearchPath() const override - { - return m_preIncludeSearchPath; - } - -private: - Utils::PathString m_pchBuildDirectoryPath; - ClangBackEnd::NativeFilePath m_preIncludeSearchPath; -}; - -QStringList processArguments(QCoreApplication &application) -{ - QCommandLineParser parser; - parser.setApplicationDescription(QStringLiteral("Qt Creator Clang PchManager Backend")); - parser.addHelpOption(); - parser.addVersionOption(); - parser.addPositionalArgument(QStringLiteral("connection"), QStringLiteral("Connection")); - parser.addPositionalArgument(QStringLiteral("databasepath"), QStringLiteral("Database path")); - parser.addPositionalArgument(QStringLiteral("pchspath"), QStringLiteral("PCHs path")); - parser.addPositionalArgument(QStringLiteral("resourcepath"), QStringLiteral("Resource path")); - - parser.process(application); - - if (parser.positionalArguments().isEmpty()) - parser.showHelp(1); - - return parser.positionalArguments(); -} - -class PchCreatorManager final : public ClangBackEnd::ProcessorManager -{ -public: - using Processor = ClangBackEnd::PchCreator; - PchCreatorManager(const ClangBackEnd::GeneratedFiles &generatedFiles, - ClangBackEnd::Environment &environment, - ClangBackEnd::FilePathCaching &filePathCache, - PchManagerServer &pchManagerServer, - ClangBackEnd::ClangPathWatcherInterface &pathWatcher, - ClangBackEnd::BuildDependenciesStorageInterface &buildDependenciesStorage) - : ProcessorManager(generatedFiles) - , m_environment(environment) - , m_filePathCache(filePathCache) - , m_pchManagerServer(pchManagerServer) - , m_pathWatcher(pathWatcher) - , m_buildDependenciesStorage(buildDependenciesStorage) - {} - -protected: - std::unique_ptr createProcessor() const override - { - return std::make_unique(m_environment, - m_filePathCache, - *m_pchManagerServer.client(), - m_pathWatcher, - m_buildDependenciesStorage); - } - -private: - ClangBackEnd::Environment &m_environment; - ClangBackEnd::FilePathCaching &m_filePathCache; - ClangBackEnd::PchManagerServer &m_pchManagerServer; - ClangBackEnd::ClangPathWatcherInterface &m_pathWatcher; - ClangBackEnd::BuildDependenciesStorageInterface &m_buildDependenciesStorage; -}; - -struct Data // because we have a cycle dependency -{ - using TaskScheduler = ClangBackEnd::TaskScheduler; - - Data(const QString &databasePath, const QString &pchsPath, const QString &preIncludeSearchPath) - : database{Utils::PathString{databasePath}, 100000ms} - , environment{pchsPath, preIncludeSearchPath} - {} - Sqlite::Database database; - ClangBackEnd::RefactoringDatabaseInitializer databaseInitializer{database}; - ClangBackEnd::FilePathCaching filePathCache{database}; - ClangBackEnd::FileSystem fileSystem{filePathCache}; - ClangPathWatcher includeWatcher{filePathCache, fileSystem}; - ApplicationEnvironment environment; - ProjectPartsStorage<> projectPartsStorage{database}; - PrecompiledHeaderStorage<> preCompiledHeaderStorage{database}; - GeneratedFiles generatedFiles; - ProjectPartsManager projectParts{projectPartsStorage, - preCompiledHeaderStorage, - buildDependencyProvider, - filePathCache, - includeWatcher, - generatedFiles}; - PchCreatorManager pchCreatorManager{generatedFiles, - environment, - filePathCache, - clangPchManagerServer, - includeWatcher, - buildDependencyStorage}; - ClangBackEnd::ProgressCounter pchCreationProgressCounter{[&](int progress, int total) { - executeInLoop([&] { - clangPchManagerServer.setPchCreationProgress(progress, total); - }); - }}; - ClangBackEnd::ProgressCounter dependencyCreationProgressCounter{[&](int progress, int total) { - executeInLoop([&] { - clangPchManagerServer.setDependencyCreationProgress(progress, total); - }); - }}; - ClangBackEnd::PchTaskQueue pchTaskQueue{systemTaskScheduler, - projectTaskScheduler, - pchCreationProgressCounter, - preCompiledHeaderStorage, - database, - environment, - fileSystem, - filePathCache}; - ClangBackEnd::PchTasksMerger pchTaskMerger{pchTaskQueue}; - ClangBackEnd::BuildDependenciesStorage<> buildDependencyStorage{database}; - ClangBackEnd::BuildDependencyCollector buildDependencyCollector{filePathCache, - generatedFiles, - environment}; - ClangBackEnd::ModifiedTimeChecker modifiedTimeChecker{fileSystem}; - ClangBackEnd::BuildDependenciesProvider buildDependencyProvider{buildDependencyStorage, - modifiedTimeChecker, - buildDependencyCollector, - database}; - ClangBackEnd::PchTaskGenerator pchTaskGenerator{buildDependencyProvider, - pchTaskMerger, - dependencyCreationProgressCounter, - pchTaskQueue}; - PchManagerServer clangPchManagerServer{includeWatcher, - pchTaskGenerator, - projectParts, - generatedFiles, - buildDependencyStorage, - filePathCache}; - TaskScheduler systemTaskScheduler{pchCreatorManager, - pchTaskQueue, - pchCreationProgressCounter, - std::thread::hardware_concurrency(), - ClangBackEnd::CallDoInMainThreadAfterFinished::No}; - TaskScheduler projectTaskScheduler{pchCreatorManager, - pchTaskQueue, - pchCreationProgressCounter, - std::thread::hardware_concurrency(), - ClangBackEnd::CallDoInMainThreadAfterFinished::Yes}; -}; - -#ifdef Q_OS_WIN -extern "C" void __stdcall OutputDebugStringW(const wchar_t* msg); -static void messageOutput(QtMsgType type, const QMessageLogContext &, const QString &msg) -{ - OutputDebugStringW(msg.toStdWString().c_str()); - std::wcout << msg.toStdWString() << std::endl; - if (type == QtFatalMsg) - abort(); -} -#endif - -int main(int argc, char *argv[]) -{ -#ifdef Q_OS_WIN - qInstallMessageHandler(messageOutput); -#endif - try { - QCoreApplication::setOrganizationName(QStringLiteral("QtProject")); - QCoreApplication::setOrganizationDomain(QStringLiteral("qt-project.org")); - QCoreApplication::setApplicationName(QStringLiteral("ClangPchManagerBackend")); - QCoreApplication::setApplicationVersion(QStringLiteral("0.1.0")); - - PchManagerApplication application(argc, argv); - - const QStringList arguments = processArguments(application); - const QString connectionName = arguments[0]; - const QString databasePath = arguments[1]; - const QString pchsPath = arguments[2]; - const QString preIncludeSearchPath = arguments[3] + "/indexer_preincludes"; - - Data data{databasePath, pchsPath, preIncludeSearchPath}; - - data.includeWatcher.setNotifier(&data.clangPchManagerServer); - - ConnectionServer connectionServer; - connectionServer.setServer(&data.clangPchManagerServer); - data.buildDependencyProvider.setEnsureAliveMessageIsSentCallback( - [&] { connectionServer.ensureAliveMessageIsSent(); }); - connectionServer.start(connectionName); - - return application.exec(); - } catch (const Sqlite::Exception &exception) { - exception.printWarning(); - } -} - - diff --git a/src/tools/clangpchmanagerbackend/source/CMakeLists.txt b/src/tools/clangpchmanagerbackend/source/CMakeLists.txt deleted file mode 100644 index 63f0a11acf5..00000000000 --- a/src/tools/clangpchmanagerbackend/source/CMakeLists.txt +++ /dev/null @@ -1,54 +0,0 @@ -add_qtc_library(clangpchmanagerbackend_lib STATIC - CONDITION TARGET clangrefactoringbackend_lib - DEPENDS clangrefactoringbackend_lib - PUBLIC_DEPENDS libclang Qt5::Widgets # FIXME: change the way to get the gui pch to linkto - DEFINES - $ - INCLUDES - $ - $ - PUBLIC_INCLUDES - ../../clangrefactoringbackend/source - SOURCES - builddependenciesprovider.cpp builddependenciesprovider.h - builddependenciesproviderinterface.h - builddependenciesstorage.h - builddependenciesstorageinterface.h - builddependency.h - builddependencycollector.cpp builddependencycollector.h - builddependencygeneratorinterface.h - clangpchmanagerbackend_global.h - collectbuilddependencyaction.h - collectbuilddependencypreprocessorcallbacks.h - collectbuilddependencytoolaction.h - collectusedmacroactionfactory.h - collectusedmacrosaction.h - collectusedmacrosandsourcespreprocessorcallbacks.h - generatepchactionfactory.h - pchcreator.cpp pchcreator.h - pchcreatorinterface.h - pchmanagerserver.cpp pchmanagerserver.h - pchnotcreatederror.h - pchtask.h - pchtaskgenerator.cpp pchtaskgenerator.h - pchtaskgeneratorinterface.h - pchtaskqueue.cpp - pchtaskqueue.h - pchtaskqueueinterface.h - pchtasksmerger.cpp - pchtasksmerger.h - pchtasksmergerinterface.h - precompiledheaderstorage.h - precompiledheaderstorageinterface.h - processorinterface.h - processormanager.h - processormanagerinterface.h - projectpartsmanager.cpp projectpartsmanager.h - projectpartsmanagerinterface.h - queueinterface.h - taskscheduler.h - taskschedulerinterface.h - toolchainargumentscache.h - usedmacrofilter.h - usedmacrosandsourcescollector.cpp usedmacrosandsourcescollector.h -) diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp deleted file mode 100644 index 9e0f62bc7d4..00000000000 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "builddependenciesprovider.h" - -#include "builddependenciesstorageinterface.h" -#include "modifiedtimecheckerinterface.h" -#include "builddependencygeneratorinterface.h" - -#include - -#include - -namespace ClangBackEnd { - -template -OutputContainer setUnion(InputContainer1 &&input1, - InputContainer2 &&input2) -{ - OutputContainer results; - results.reserve(input1.size() + input2.size()); - - std::set_union(std::begin(input1), - std::end(input1), - std::begin(input2), - std::end(input2), - std::back_inserter(results)); - - return results; -} - -BuildDependency BuildDependenciesProvider::create(const ProjectPartContainer &projectPart) -{ - return create(projectPart, - createSourceEntriesFromStorage(projectPart.sourcePathIds, projectPart.projectPartId)); -} - -BuildDependency BuildDependenciesProvider::create(const ProjectPartContainer &projectPart, - SourceEntries &&sourceEntries) -{ - m_ensureAliveMessageIsSentCallback(); - - if (!m_modifiedTimeChecker.isUpToDate(sourceEntries)) { - BuildDependency buildDependency = m_generator.create(projectPart); - - storeBuildDependency(buildDependency, projectPart.projectPartId); - - return buildDependency; - } - - return createBuildDependencyFromStorage(std::move(sourceEntries)); -} - -BuildDependency BuildDependenciesProvider::createBuildDependencyFromStorage( - SourceEntries &&includes) const -{ - BuildDependency buildDependency; - - buildDependency.usedMacros = createUsedMacrosFromStorage(includes); - buildDependency.sources = std::move(includes); - - return buildDependency; -} - -UsedMacros BuildDependenciesProvider::createUsedMacrosFromStorage(const SourceEntries &includes) const -{ - UsedMacros usedMacros; - usedMacros.reserve(1024); - - Sqlite::DeferredTransaction transaction(m_transactionBackend); - - for (const SourceEntry &entry : includes) { - UsedMacros macros = m_storage.fetchUsedMacros(entry.sourceId); - std::sort(macros.begin(), macros.end()); - usedMacros.insert(usedMacros.end(), - std::make_move_iterator(macros.begin()), - std::make_move_iterator(macros.end())); - } - - transaction.commit(); - - return usedMacros; -} - -SourceEntries BuildDependenciesProvider::createSourceEntriesFromStorage( - const FilePathIds &sourcePathIds, ProjectPartId projectPartId) const -{ - SourceEntries includes; - - Sqlite::DeferredTransaction transaction(m_transactionBackend); - - for (FilePathId sourcePathId : sourcePathIds) { - SourceEntries entries = m_storage.fetchDependSources(sourcePathId, projectPartId); - SourceEntries mergedEntries = setUnion(includes, entries); - - includes = std::move(mergedEntries); - } - - transaction.commit(); - - return includes; -} - -void BuildDependenciesProvider::storeBuildDependency(const BuildDependency &buildDependency, - ProjectPartId projectPartId) -{ - Sqlite::ImmediateTransaction transaction(m_transactionBackend); - m_storage.insertOrUpdateSources(buildDependency.sources, projectPartId); - m_storage.insertOrUpdateFileStatuses(buildDependency.fileStatuses); - m_storage.insertOrUpdateSourceDependencies(buildDependency.sourceDependencies); - m_storage.insertOrUpdateUsedMacros(buildDependency.usedMacros); - - transaction.commit(); -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h b/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h deleted file mode 100644 index 765ba98a68f..00000000000 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesprovider.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "builddependenciesproviderinterface.h" - -#include - -namespace Sqlite { -class TransactionInterface; -} - -namespace ClangBackEnd { - -class BuildDependenciesStorageInterface; -class BuildDependencyGeneratorInterface; - -class BuildDependenciesProvider : public BuildDependenciesProviderInterface -{ -public: - BuildDependenciesProvider(BuildDependenciesStorageInterface &buildDependenciesStorage, - ModifiedTimeCheckerInterface<> &modifiedTimeChecker, - BuildDependencyGeneratorInterface &buildDependenciesGenerator, - Sqlite::TransactionInterface &transactionBackend) - : m_storage(buildDependenciesStorage) - , m_modifiedTimeChecker(modifiedTimeChecker) - , m_generator(buildDependenciesGenerator) - , m_transactionBackend(transactionBackend) - {} - - BuildDependency create(const ProjectPartContainer &projectPart) override; - BuildDependency create(const ProjectPartContainer &projectPart, - SourceEntries &&sourceEntries) override; - - void setEnsureAliveMessageIsSentCallback(std::function &&callback) - { - m_ensureAliveMessageIsSentCallback = std::move(callback); - } - - SourceEntries createSourceEntriesFromStorage(const FilePathIds &sourcePathIds, - ProjectPartId projectPartId) const override; - -private: - BuildDependency createBuildDependencyFromStorage(SourceEntries &&includes) const; - UsedMacros createUsedMacrosFromStorage(const SourceEntries &includes) const; - void storeBuildDependency(const BuildDependency &buildDependency, ProjectPartId projectPartId); - -private: - BuildDependenciesStorageInterface &m_storage; - ModifiedTimeCheckerInterface<> &m_modifiedTimeChecker; - BuildDependencyGeneratorInterface &m_generator; - Sqlite::TransactionInterface &m_transactionBackend; - std::function m_ensureAliveMessageIsSentCallback; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesproviderinterface.h b/src/tools/clangpchmanagerbackend/source/builddependenciesproviderinterface.h deleted file mode 100644 index 7b5e9342b68..00000000000 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesproviderinterface.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "builddependency.h" - -#include "projectpartcontainer.h" - -namespace ClangBackEnd { - -class BuildDependenciesProviderInterface -{ -public: - virtual BuildDependency create(const ProjectPartContainer &projectPart) = 0; - virtual BuildDependency create(const ProjectPartContainer &projectPart, SourceEntries &&sourceEntries) = 0; - virtual SourceEntries createSourceEntriesFromStorage(const FilePathIds &sourcePathIds, - ProjectPartId projectPartId) const = 0; - -protected: - ~BuildDependenciesProviderInterface() = default; -}; - -} // namespace ClangBackEnd - diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h b/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h deleted file mode 100644 index 0d51b4def9f..00000000000 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesstorage.h +++ /dev/null @@ -1,411 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "builddependenciesstorageinterface.h" - -#include -#include -#include -#include - -#include - -#include -#include -#include - -namespace ClangBackEnd { - -template -class BuildDependenciesStorage final : public BuildDependenciesStorageInterface -{ - template - using ReadStatement = typename Database::template ReadStatement; - using WriteStatement = typename Database::WriteStatement; -public: - BuildDependenciesStorage(Database &database) - : transaction(database), - database(database) - { - transaction.commit(); - } - - void insertOrUpdateSources(const SourceEntries &sourceEntries, ProjectPartId projectPartId) override - { - deleteAllProjectPartsFilesWithProjectPartNameStatement.write(projectPartId.projectPathId); - - for (const SourceEntry &entry : sourceEntries) { - insertOrUpdateProjectPartsFilesStatement.write(entry.sourceId.filePathId, - projectPartId.projectPathId, - static_cast(entry.sourceType), - static_cast( - entry.hasMissingIncludes)); - } - } - - FilePathIds fetchPchSources(ProjectPartId projectPartId) const override - { - try { - Sqlite::DeferredTransaction transaction{database}; - - FilePathIds values = fetchPchSourcesStatement - .template values(1024, projectPartId.projectPathId); - - transaction.commit(); - - return values; - } catch (const Sqlite::StatementIsBusy &) { - return fetchPchSources(projectPartId); - } - } - - FilePathIds fetchSources(ProjectPartId projectPartId) const override - { - return fetchSourcesStatement.template values(1024, projectPartId.projectPathId); - } - - void insertOrUpdateFileStatuses(const FileStatuses &fileStatuses) override - { - WriteStatement &statement = insertOrUpdateFileStatusesStatement; - - for (const FileStatus &fileStatus : fileStatuses) - statement.write(fileStatus.filePathId.filePathId, - fileStatus.size, - fileStatus.lastModified); - } - - long long fetchLowestLastModifiedTime(FilePathId sourceId) const override - { - auto &statement = getLowestLastModifiedTimeOfDependencies; - - return statement.template optionalValue(sourceId.filePathId).value_or(0); - } - - void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) override - { - WriteStatement &insertStatement = insertIntoNewUsedMacrosStatement; - for (const UsedMacro &usedMacro : usedMacros) - insertStatement.write(usedMacro.filePathId.filePathId, - usedMacro.macroName); - - syncNewUsedMacrosStatement.execute(); - deleteOutdatedUsedMacrosStatement.execute(); - deleteNewUsedMacrosTableStatement.execute(); - } - - void insertOrUpdateSourceDependencies(const SourceDependencies &sourceDependencies) override - { - WriteStatement &insertStatement = insertIntoNewSourceDependenciesStatement; - for (SourceDependency sourceDependency : sourceDependencies) - insertStatement.write(sourceDependency.filePathId.filePathId, - sourceDependency.dependencyFilePathId.filePathId); - - syncNewSourceDependenciesStatement.execute(); - deleteOutdatedSourceDependenciesStatement.execute(); - deleteNewSourceDependenciesStatement.execute(); - } - - ProjectPartId fetchProjectPartId(Utils::SmallStringView projectPartName) override - { - auto projectPartId = fetchProjectPartIdStatement.template optionalValue( - projectPartName); - - if (projectPartId) - return *projectPartId; - - insertProjectPartNameStatement.write(projectPartName); - - return static_cast(database.lastInsertedRowId()); - } - - SourceEntries fetchDependSources(FilePathId sourceId, ProjectPartId projectPartId) const override - { - return fetchSourceDependenciesStatement - .template values(300, sourceId.filePathId, projectPartId.projectPathId); - } - - UsedMacros fetchUsedMacros(FilePathId sourceId) const override - { - return fetchUsedMacrosStatement.template values(128, sourceId.filePathId); - } - - void updatePchCreationTimeStamp(long long pchCreationTimeStamp, ProjectPartId projectPartId) override - { - Sqlite::ImmediateTransaction transaction{database}; - - updatePchCreationTimeStampStatement.write(pchCreationTimeStamp, projectPartId.projectPathId); - - transaction.commit(); - } - - void insertOrUpdateIndexingTimeStamps(const FilePathIds &filePathIds, - TimeStamp indexingTimeStamp) override - { - try { - Sqlite::ImmediateTransaction transaction{database}; - - for (FilePathId filePathId : filePathIds) { - inserOrUpdateIndexingTimesStampStatement.write(filePathId.filePathId, - indexingTimeStamp.value); - } - - transaction.commit(); - } catch (const Sqlite::StatementIsBusy &) { - insertOrUpdateIndexingTimeStamps(filePathIds, indexingTimeStamp); - } - } - - void insertOrUpdateIndexingTimeStampsWithoutTransaction(const FilePathIds &filePathIds, - TimeStamp indexingTimeStamp) override - { - for (FilePathId filePathId : filePathIds) { - inserOrUpdateIndexingTimesStampStatement.write(filePathId.filePathId, - indexingTimeStamp.value); - } - } - - SourceTimeStamps fetchIndexingTimeStamps() const override - { - try { - Sqlite::DeferredTransaction transaction{database}; - - auto timeStamps = fetchIndexingTimeStampsStatement.template values(1024); - - transaction.commit(); - - return timeStamps; - } catch (const Sqlite::StatementIsBusy &) { - return fetchIndexingTimeStamps(); - } - } - - SourceTimeStamps fetchIncludedIndexingTimeStamps(FilePathId sourcePathId) const override - { - try { - Sqlite::DeferredTransaction transaction{database}; - - auto timeStamps = fetchIncludedIndexingTimeStampsStatement - .template values(1024, sourcePathId.filePathId); - - transaction.commit(); - - return timeStamps; - } catch (const Sqlite::StatementIsBusy &) { - return fetchIncludedIndexingTimeStamps(sourcePathId); - } - } - - FilePathIds fetchDependentSourceIds(const FilePathIds &sourcePathIds) const override - { - try { - FilePathIds dependentSourceIds; - - Sqlite::DeferredTransaction transaction{database}; - - for (FilePathId sourcePathId : sourcePathIds) { - FilePathIds newDependentSourceIds; - newDependentSourceIds.reserve(dependentSourceIds.size() + 1024); - - auto newIds = fetchDependentSourceIdsStatement - .template values(1024, sourcePathId.filePathId); - - std::set_union(dependentSourceIds.begin(), - dependentSourceIds.end(), - newIds.begin(), - newIds.end(), - std::back_inserter(newDependentSourceIds)); - - dependentSourceIds = std::move(newDependentSourceIds); - } - - transaction.commit(); - - return dependentSourceIds; - } catch (const Sqlite::StatementIsBusy &) { - return fetchDependentSourceIds(sourcePathIds); - } - } - - static Utils::SmallString toJson(const Utils::SmallStringVector &strings) - { - QJsonDocument document; - QJsonArray array; - - std::transform(strings.begin(), strings.end(), std::back_inserter(array), [] (const auto &string) { - return QJsonValue(string.data()); - }); - - document.setArray(array); - - return document.toJson(QJsonDocument::Compact); - } - - static Utils::SmallString toJson(const CompilerMacros &compilerMacros) - { - QJsonDocument document; - QJsonObject object; - - for (const CompilerMacro ¯o : compilerMacros) - object.insert(QString(macro.key), QString(macro.value)); - - document.setObject(object); - - return document.toJson(QJsonDocument::Compact); - } - - Sqlite::Table createNewUsedMacrosTable() const - { - Sqlite::Table table; - table.setName("newUsedMacros"); - table.setUseTemporaryTable(true); - const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); - const Sqlite::Column ¯oNameColumn = table.addColumn("macroName", Sqlite::ColumnType::Text); - table.addIndex({sourceIdColumn, macroNameColumn}); - - table.initialize(database); - - return table; - } - - Sqlite::Table createNewSourceDependenciesTable() const - { - Sqlite::Table table; - table.setName("newSourceDependencies"); - table.setUseTemporaryTable(true); - const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); - const Sqlite::Column &dependencySourceIdColumn = table.addColumn("dependencySourceId", Sqlite::ColumnType::Text); - table.addIndex({sourceIdColumn, dependencySourceIdColumn}); - - table.initialize(database); - - return table; - } - -public: - Sqlite::ImmediateNonThrowingDestructorTransaction transaction; - Database &database; - Sqlite::Table newUsedMacroTable{createNewUsedMacrosTable()}; - Sqlite::Table newNewSourceDependenciesTable{createNewSourceDependenciesTable()}; - WriteStatement insertIntoNewUsedMacrosStatement{ - "INSERT INTO newUsedMacros(sourceId, macroName) VALUES (?,?)", - database - }; - WriteStatement syncNewUsedMacrosStatement{ - "INSERT INTO usedMacros(sourceId, macroName) SELECT sourceId, macroName FROM newUsedMacros WHERE NOT EXISTS (SELECT sourceId FROM usedMacros WHERE usedMacros.sourceId == newUsedMacros.sourceId AND usedMacros.macroName == newUsedMacros.macroName)", - database - }; - WriteStatement deleteOutdatedUsedMacrosStatement{ - "DELETE FROM usedMacros WHERE sourceId IN (SELECT sourceId FROM newUsedMacros) AND NOT EXISTS (SELECT sourceId FROM newUsedMacros WHERE newUsedMacros.sourceId == usedMacros.sourceId AND newUsedMacros.macroName == usedMacros.macroName)", - database - }; - WriteStatement deleteNewUsedMacrosTableStatement{ - "DELETE FROM newUsedMacros", - database - }; - mutable ReadStatement<1> getLowestLastModifiedTimeOfDependencies{ - "WITH RECURSIVE sourceIds(sourceId) AS (VALUES(?) UNION SELECT dependencySourceId FROM " - "sourceDependencies, sourceIds WHERE sourceDependencies.sourceId = sourceIds.sourceId) " - "SELECT min(lastModified) FROM fileStatuses, sourceIds WHERE fileStatuses.sourceId = " - "sourceIds.sourceId", - database}; - WriteStatement insertIntoNewSourceDependenciesStatement{ - "INSERT INTO newSourceDependencies(sourceId, dependencySourceId) VALUES (?,?)", - database - }; - WriteStatement insertOrUpdateFileStatusesStatement{ - "INSERT INTO fileStatuses(sourceId, size, lastModified) VALUES " - "(?001,?002,?003) ON " - "CONFLICT(sourceId) DO UPDATE SET size = ?002, lastModified = ?003", - database}; - WriteStatement syncNewSourceDependenciesStatement{ - "INSERT INTO sourceDependencies(sourceId, dependencySourceId) SELECT sourceId, dependencySourceId FROM newSourceDependencies WHERE NOT EXISTS (SELECT sourceId FROM sourceDependencies WHERE sourceDependencies.sourceId == newSourceDependencies.sourceId AND sourceDependencies.dependencySourceId == newSourceDependencies.dependencySourceId)", - database - }; - WriteStatement deleteOutdatedSourceDependenciesStatement{ - "DELETE FROM sourceDependencies WHERE sourceId IN (SELECT sourceId FROM newSourceDependencies) AND NOT EXISTS (SELECT sourceId FROM newSourceDependencies WHERE newSourceDependencies.sourceId == sourceDependencies.sourceId AND newSourceDependencies.dependencySourceId == sourceDependencies.dependencySourceId)", - database - }; - WriteStatement deleteNewSourceDependenciesStatement{ - "DELETE FROM newSourceDependencies", - database - }; - WriteStatement insertOrUpdateProjectPartsFilesStatement{ - "INSERT INTO projectPartsFiles(sourceId, projectPartId, " - "sourceType, hasMissingIncludes) VALUES (?001, ?002, ?003, ?004) ON " - "CONFLICT(sourceId, projectPartId) DO UPDATE SET sourceType = ?003, " - "hasMissingIncludes = ?004", - database}; - mutable ReadStatement<1> fetchPchSourcesStatement{ - "SELECT sourceId FROM projectPartsFiles WHERE projectPartId = ? AND sourceType IN (0, 1, " - "3, 4) ORDER BY sourceId", - database}; - mutable ReadStatement<1> fetchSourcesStatement{ - "SELECT sourceId FROM projectPartsFiles WHERE projectPartId = ? ORDER BY sourceId", database}; - mutable ReadStatement<4> fetchSourceDependenciesStatement{ - "WITH RECURSIVE collectedDependencies(sourceId) AS (VALUES(?) UNION " - "SELECT dependencySourceId FROM sourceDependencies, " - "collectedDependencies WHERE sourceDependencies.sourceId == " - "collectedDependencies.sourceId) SELECT sourceId, " - "pchCreationTimeStamp, sourceType, hasMissingIncludes FROM " - "collectedDependencies NATURAL JOIN projectPartsFiles WHERE " - "projectPartId = ? ORDER BY sourceId", - database}; - mutable ReadStatement<1> fetchProjectPartIdStatement{ - "SELECT projectPartId FROM projectParts WHERE projectPartName = ?", database}; - WriteStatement insertProjectPartNameStatement{ - "INSERT INTO projectParts(projectPartName) VALUES (?)", database}; - mutable ReadStatement<2> fetchUsedMacrosStatement{ - "SELECT macroName, sourceId FROM usedMacros WHERE sourceId = ? ORDER BY sourceId, " - "macroName", - database}; - WriteStatement updatePchCreationTimeStampStatement{ - "UPDATE projectPartsFiles SET pchCreationTimeStamp = ?001 WHERE projectPartId = ?002", - database}; - WriteStatement deleteAllProjectPartsFilesWithProjectPartNameStatement{ - "DELETE FROM projectPartsFiles WHERE projectPartId = ?", database}; - WriteStatement inserOrUpdateIndexingTimesStampStatement{ - "INSERT INTO fileStatuses(sourceId, indexingTimeStamp) VALUES (?001, ?002) ON " - "CONFLICT(sourceId) DO UPDATE SET indexingTimeStamp = ?002", - database}; - mutable ReadStatement<2> fetchIncludedIndexingTimeStampsStatement{ - "WITH RECURSIVE collectedDependencies(sourceId) AS (VALUES(?) UNION SELECT " - "dependencySourceId FROM sourceDependencies, collectedDependencies WHERE " - "sourceDependencies.sourceId == collectedDependencies.sourceId) SELECT DISTINCT sourceId, " - "indexingTimeStamp FROM collectedDependencies NATURAL LEFT JOIN fileStatuses ORDER BY " - "sourceId", - database}; - mutable ReadStatement<2> fetchIndexingTimeStampsStatement{ - "SELECT sourceId, indexingTimeStamp FROM fileStatuses ORDER BY sourceId", database}; - mutable ReadStatement<1> fetchDependentSourceIdsStatement{ - "WITH RECURSIVE collectedDependencies(sourceId) AS (VALUES(?) UNION SELECT " - "sourceDependencies.sourceId FROM sourceDependencies, collectedDependencies WHERE " - "sourceDependencies.dependencySourceId == collectedDependencies.sourceId) SELECT sourceId " - "FROM collectedDependencies WHERE sourceId NOT IN (SELECT dependencySourceId FROM " - "sourceDependencies) ORDER BY sourceId", - database}; -}; -} diff --git a/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h b/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h deleted file mode 100644 index c4d102246e1..00000000000 --- a/src/tools/clangpchmanagerbackend/source/builddependenciesstorageinterface.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "sourceentry.h" - -#include -#include -#include -#include -#include -#include - -#include - -namespace ClangBackEnd { - -class BuildDependenciesStorageInterface -{ -public: - BuildDependenciesStorageInterface() = default; - BuildDependenciesStorageInterface(const BuildDependenciesStorageInterface &) = delete; - BuildDependenciesStorageInterface &operator=(const BuildDependenciesStorageInterface &) = delete; - - virtual void insertOrUpdateSources(const SourceEntries &sourceIds, ProjectPartId projectPartId) = 0; - virtual void insertOrUpdateUsedMacros(const UsedMacros &usedMacros) = 0; - virtual void - insertOrUpdateFileStatuses(const FileStatuses &fileStatuses) = 0; - virtual void insertOrUpdateSourceDependencies(const SourceDependencies &sourceDependencies) = 0; - virtual long long fetchLowestLastModifiedTime(FilePathId sourceId) const = 0; - virtual SourceEntries fetchDependSources(FilePathId sourceId, - ProjectPartId projectPartId) const = 0; - virtual UsedMacros fetchUsedMacros(FilePathId sourceId) const = 0; - virtual ProjectPartId fetchProjectPartId(Utils::SmallStringView projectPartName) = 0; - virtual void updatePchCreationTimeStamp(long long pchCreationTimeStamp, ProjectPartId projectPartId) = 0; - virtual FilePathIds fetchPchSources(ProjectPartId projectPartId) const = 0; - virtual FilePathIds fetchSources(ProjectPartId projectPartId) const = 0; - virtual void insertOrUpdateIndexingTimeStamps(const FilePathIds &filePathIds, TimeStamp indexingTimeStamp) = 0; - virtual void insertOrUpdateIndexingTimeStampsWithoutTransaction(const FilePathIds &filePathIds, - TimeStamp indexingTimeStamp) - = 0; - virtual SourceTimeStamps fetchIndexingTimeStamps() const = 0; - virtual SourceTimeStamps fetchIncludedIndexingTimeStamps(FilePathId sourcePathId) const = 0; - virtual FilePathIds fetchDependentSourceIds(const FilePathIds &sourcePathIds) const = 0; - -protected: - ~BuildDependenciesStorageInterface() = default; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/builddependency.h b/src/tools/clangpchmanagerbackend/source/builddependency.h deleted file mode 100644 index 6725254e308..00000000000 --- a/src/tools/clangpchmanagerbackend/source/builddependency.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "filestatus.h" -#include "sourcedependency.h" -#include "sourceentry.h" -#include "usedmacro.h" - -namespace ClangBackEnd { - -class BuildDependency -{ -public: - void clear() - { - sources.clear(); - usedMacros.clear(); - sourceFiles.clear(); - fileStatuses.clear(); - sourceDependencies.clear(); - } - - friend bool operator==(const BuildDependency &first, const BuildDependency &second) - { - return first.sources == second.sources && - first.usedMacros == second.usedMacros && - first.sourceFiles == second.sourceFiles && - first.sourceDependencies == second.sourceDependencies && - first.fileStatuses == second.fileStatuses; - } - -public: - SourceEntries sources; - UsedMacros usedMacros; - FilePathIds sourceFiles; - SourceDependencies sourceDependencies; - FileStatuses fileStatuses; -}; - -using BuildDependencies = std::vector; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp b/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp deleted file mode 100644 index 20f08e257e5..00000000000 --- a/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "builddependencycollector.h" - -#include "collectbuilddependencytoolaction.h" -#include "commandlinebuilder.h" - -#include - -#include - -#include - -namespace ClangBackEnd { - -namespace { -FilePathIds operator+(const FilePathIds &first, const FilePathIds &second) -{ - FilePathIds result = first; - - std::copy(second.begin(), second.end(), std::back_inserter(result)); - - return result; -} - -FilePaths operator+(FilePaths &&first, FilePaths &&second) { - FilePaths result = std::move(first); - - std::copy(second.begin(), second.end(), std::back_inserter(result)); - - return result; -} - -FilePaths generatedFilePaths(const V2::FileContainers &containers) { - FilePaths paths; - paths.reserve(containers.size()); - std::transform(containers.begin(), - containers.end(), - std::back_inserter(paths), - [](const auto &container) { return container.filePath; }); - return paths; -} - -} // namespace - -BuildDependency BuildDependencyCollector::create(const ProjectPartContainer &projectPart) -{ - if (projectPart.sourcePathIds.size()) { - CommandLineBuilder builder{ - projectPart, - projectPart.toolChainArguments, - InputFileType::Source, - {}, - {}, - {}, - m_environment.preIncludeSearchPath()}; - - addFiles(projectPart.sourcePathIds, std::move(builder.commandLine)); - - setExcludedFilePaths( - m_filePathCache.filePaths(projectPart.headerPathIds + projectPart.sourcePathIds) - + generatedFilePaths(m_generatedFiles.fileContainers())); - - addUnsavedFiles(m_generatedFiles.fileContainers()); - - collect(); - } - - auto buildDependency = std::move(m_buildDependency); - - clear(); - - return buildDependency; -} - -namespace { - -std::size_t contentSize(const FilePaths &includes) -{ - auto countIncludeSize = [](std::size_t size, const auto &include) { - return size + include.size(); - }; - - return std::accumulate(includes.begin(), includes.end(), std::size_t(0), countIncludeSize); -} -} // namespace - -Utils::SmallString BuildDependencyCollector::generateFakeFileContent( - const FilePathIds &includeIds) const -{ - Utils::SmallString fileContent; - const std::size_t lineTemplateSize = 12; - auto includes = m_filePathCache.filePaths(includeIds); - - fileContent.reserve(includes.size() * lineTemplateSize + contentSize(includes)); - - for (Utils::SmallStringView include : includes) - fileContent += {"#include \"", include, "\"\n"}; - - return fileContent; -} - -void BuildDependencyCollector::collect() -{ - clang::tooling::ClangTool tool = m_clangTool.createTool(); - - auto action = std::make_unique(m_buildDependency, - m_filePathCache, - m_excludedFilePaths); - - tool.run(action.get()); -} - -void BuildDependencyCollector::setExcludedFilePaths(ClangBackEnd::FilePaths &&excludedFilePaths) -{ - m_excludedFilePaths = std::move(excludedFilePaths); -} - -void BuildDependencyCollector::addFiles(const FilePathIds &filePathIds, - Utils::SmallStringVector &&arguments) -{ - m_clangTool.addFile(FilePath{m_environment.pchBuildDirectory(), "dummy.cpp"}, - generateFakeFileContent(filePathIds), - std::move(arguments)); - m_buildDependency.sourceFiles.insert(m_buildDependency.sourceFiles.end(), - filePathIds.begin(), - filePathIds.end()); -} - -void BuildDependencyCollector::addFile(FilePathId filePathId, Utils::SmallStringVector &&arguments) -{ - addFiles({filePathId}, std::move(arguments)); -} - -void BuildDependencyCollector::addFile(FilePath filePath, - const FilePathIds &sourceFileIds, - Utils::SmallStringVector &&arguments) -{ - m_clangTool.addFiles({filePath}, std::move(arguments)); - m_buildDependency.sourceFiles.insert(m_buildDependency.sourceFiles.end(), - sourceFileIds.begin(), - sourceFileIds.end()); -} - -void BuildDependencyCollector::addUnsavedFiles(const V2::FileContainers &unsavedFiles) -{ - m_clangTool.addUnsavedFiles(unsavedFiles); -} - -void BuildDependencyCollector::clear() -{ - m_clangTool = ClangTool(); - m_buildDependency.clear(); -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/builddependencycollector.h b/src/tools/clangpchmanagerbackend/source/builddependencycollector.h deleted file mode 100644 index 084024c8212..00000000000 --- a/src/tools/clangpchmanagerbackend/source/builddependencycollector.h +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "builddependencygeneratorinterface.h" - -#include -#include -#include - -#include - -namespace ClangBackEnd { -class Environment; - -class BuildDependencyCollector : public BuildDependencyGeneratorInterface -{ -public: - BuildDependencyCollector(const FilePathCachingInterface &filePathCache, - const GeneratedFilesInterface &generatedFiles, - const Environment &environment) - : m_filePathCache(filePathCache) - , m_generatedFiles(generatedFiles) - , m_environment(environment) - {} - - BuildDependency create(const ProjectPartContainer &projectPart) override; - - void collect(); - - void setExcludedFilePaths(ClangBackEnd::FilePaths &&excludedIncludes); - void addFiles(const FilePathIds &filePathIds, Utils::SmallStringVector &&arguments); - void addFile(FilePathId filePathId, Utils::SmallStringVector &&arguments); - void addFile(FilePath filePath, - const FilePathIds &sourceFileIds, - Utils::SmallStringVector &&arguments); - void addUnsavedFiles(const V2::FileContainers &unsavedFiles); - - void clear(); - - Utils::SmallString generateFakeFileContent(const FilePathIds &includeIds) const; - - const FileStatuses &fileStatuses() const - { - return m_buildDependency.fileStatuses; - } - - const FilePathIds &sourceFiles() const - { - return m_buildDependency.sourceFiles; - } - - const UsedMacros &usedMacros() const - { - return m_buildDependency.usedMacros; - } - - const SourceDependencies &sourceDependencies() const - { - return m_buildDependency.sourceDependencies; - } - - const SourceEntries &sourceEntries() { - std::sort(m_buildDependency.sources.begin(), - m_buildDependency.sources.end()); - - return std::move(m_buildDependency.sources); - } - -private: - ClangTool m_clangTool; - BuildDependency m_buildDependency; - ClangBackEnd::FilePaths m_excludedFilePaths; - Utils::SmallStringVector m_directories; - const FilePathCachingInterface &m_filePathCache; - const GeneratedFilesInterface &m_generatedFiles; - const Environment &m_environment; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/builddependencygeneratorinterface.h b/src/tools/clangpchmanagerbackend/source/builddependencygeneratorinterface.h deleted file mode 100644 index 0c368e7e252..00000000000 --- a/src/tools/clangpchmanagerbackend/source/builddependencygeneratorinterface.h +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "builddependency.h" - -#include "projectpartcontainer.h" - -namespace ClangBackEnd { - -class BuildDependencyGeneratorInterface -{ -public: - virtual BuildDependency create(const ProjectPartContainer &projectPart) = 0; - -protected: - ~BuildDependencyGeneratorInterface() = default; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri deleted file mode 100644 index 6b79e2e71fb..00000000000 --- a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri +++ /dev/null @@ -1,59 +0,0 @@ -INCLUDEPATH += $$PWD - -SOURCES += \ - $$PWD/builddependenciesprovider.cpp \ - $$PWD/pchmanagerserver.cpp \ - $$PWD/pchtaskgenerator.cpp \ - $$PWD/pchtasksmerger.cpp \ - $$PWD/pchtaskqueue.cpp \ - $$PWD/projectpartsmanager.cpp - -HEADERS += \ - $$PWD/pchmanagerserver.h \ - $$PWD/clangpchmanagerbackend_global.h \ - $$PWD/pchnotcreatederror.h \ - $$PWD/pchcreatorinterface.h \ - $$PWD/projectpartsmanager.h \ - $$PWD/projectpartsmanagerinterface.h \ - $$PWD/queueinterface.h \ - $$PWD/processormanagerinterface.h \ - $$PWD/processorinterface.h \ - $$PWD/taskscheduler.h \ - $$PWD/taskschedulerinterface.h \ - $$PWD/precompiledheaderstorage.h \ - $$PWD/precompiledheaderstorageinterface.h \ - $$PWD/pchtaskgenerator.h \ - $$PWD/pchtask.h \ - $$PWD/builddependenciesproviderinterface.h \ - $$PWD/builddependenciesprovider.h \ - $$PWD/builddependenciesstorageinterface.h \ - $$PWD/builddependency.h \ - $$PWD/builddependenciesstorage.h \ - $$PWD/builddependencygeneratorinterface.h \ - $$PWD/usedmacrofilter.h \ - $$PWD/pchtasksmergerinterface.h \ - $$PWD/pchtasksmerger.h \ - $$PWD/pchtaskqueueinterface.h \ - $$PWD/pchtaskqueue.h \ - $$PWD/generatepchactionfactory.h \ - $$PWD/pchtaskgeneratorinterface.h \ - $$PWD/toolchainargumentscache.h - -!isEmpty(LIBTOOLING_LIBS) { -SOURCES += \ - $$PWD/usedmacrosandsourcescollector.cpp \ - $$PWD/pchcreator.cpp \ - $$PWD/builddependencycollector.cpp - -HEADERS += \ - $$PWD/collectusedmacroactionfactory.h \ - $$PWD/collectusedmacrosaction.h \ - $$PWD/collectusedmacrosandsourcespreprocessorcallbacks.h \ - $$PWD/pchcreator.h \ - $$PWD/processormanager.h \ - $$PWD/usedmacrosandsourcescollector.h \ - $$PWD/builddependencycollector.h \ - $$PWD/collectbuilddependencytoolaction.h \ - $$PWD/collectbuilddependencyaction.h \ - $$PWD/collectbuilddependencypreprocessorcallbacks.h -} diff --git a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend_global.h b/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend_global.h deleted file mode 100644 index b38de487bba..00000000000 --- a/src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend_global.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include - -#ifdef UNIT_TESTS -#define unittest_public public -#define non_unittest_final -#else -#define unittest_public private -#define non_unittest_final final -#endif - -namespace llvm { -template -class SmallVector; -} - -using uint = unsigned int; - -namespace ClangBackEnd { - -using USRName = llvm::SmallVector; - -} diff --git a/src/tools/clangpchmanagerbackend/source/collectbuilddependencyaction.h b/src/tools/clangpchmanagerbackend/source/collectbuilddependencyaction.h deleted file mode 100644 index 3e98dc2483b..00000000000 --- a/src/tools/clangpchmanagerbackend/source/collectbuilddependencyaction.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include - -#include -#include - -#include -#include -#include - -namespace ClangBackEnd { - -class CollectBuildDependencyAction final : public clang::PreprocessOnlyAction -{ -public: - CollectBuildDependencyAction(BuildDependency &buildDependency, - const FilePathCachingInterface &filePathCache, - std::vector &excludedIncludeUID, - std::vector &alreadyIncludedFileUIDs) - : m_buildDependency(buildDependency) - , m_filePathCache(filePathCache) - , m_excludedIncludeUID(excludedIncludeUID) - , m_alreadyIncludedFileUIDs(alreadyIncludedFileUIDs) - { - } - - bool BeginSourceFileAction(clang::CompilerInstance &compilerInstance) override - { - if (clang::PreprocessOnlyAction::BeginSourceFileAction(compilerInstance)) { - auto &preprocessor = compilerInstance.getPreprocessor(); - - preprocessor.SetSuppressIncludeNotFoundError(true); - preprocessor.SetMacroExpansionOnlyInDirectives(); - - auto macroPreprocessorCallbacks = new CollectBuildDependencyPreprocessorCallbacks( - m_buildDependency, - m_filePathCache, - m_excludedIncludeUID, - m_alreadyIncludedFileUIDs, - compilerInstance.getSourceManager(), - compilerInstance.getPreprocessorPtr()); - - preprocessor.addPPCallbacks( - std::unique_ptr(macroPreprocessorCallbacks)); - - return true; - } - - return false; - } - - void EndSourceFileAction() override - { - clang::PreprocessOnlyAction::EndSourceFileAction(); - } - -private: - BuildDependency &m_buildDependency; - const FilePathCachingInterface &m_filePathCache; - std::vector &m_excludedIncludeUID; - std::vector &m_alreadyIncludedFileUIDs; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h b/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h deleted file mode 100644 index 8583ff7a158..00000000000 --- a/src/tools/clangpchmanagerbackend/source/collectbuilddependencypreprocessorcallbacks.h +++ /dev/null @@ -1,369 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "builddependency.h" -#include "collectmacrospreprocessorcallbacks.h" -#include "sourcelocationsutils.h" - -#include -#include - -#include - -#include - -#include -#include -#include - -#include - -namespace ClangBackEnd { - -class CollectBuildDependencyPreprocessorCallbacks final - : public clang::PPCallbacks, - public CollectUsedMacrosAndSourcesPreprocessorCallbacksBase -{ -public: - CollectBuildDependencyPreprocessorCallbacks(BuildDependency &buildDependency, - const FilePathCachingInterface &filePathCache, - const std::vector &excludedIncludeUID, - std::vector &alreadyIncludedFileUIDs, - clang::SourceManager &sourceManager, - std::shared_ptr preprocessor) - : CollectUsedMacrosAndSourcesPreprocessorCallbacksBase(buildDependency.usedMacros, - filePathCache, - sourceManager, - preprocessor, - buildDependency.sourceDependencies, - buildDependency.sourceFiles, - buildDependency.fileStatuses), - m_buildDependency(buildDependency), - m_excludedIncludeUID(excludedIncludeUID), - m_alreadyIncludedFileUIDs(alreadyIncludedFileUIDs) - {} - - void FileChanged(clang::SourceLocation sourceLocation, - clang::PPCallbacks::FileChangeReason reason, - clang::SrcMgr::CharacteristicKind, - clang::FileID previousFileId) override - { - if (reason == clang::PPCallbacks::EnterFile) { - clang::FileID currentFileId = m_sourceManager->getFileID(sourceLocation); - if (m_mainFileId.isInvalid()) { - m_mainFileId = currentFileId; - } else { - const clang::FileEntry *fileEntry = m_sourceManager->getFileEntryForID( - currentFileId); - if (fileEntry) { - if (previousFileId == m_mainFileId) { - uint sourceFileUID = fileEntry->getUID(); - auto notAlreadyIncluded = isNotAlreadyIncluded(sourceFileUID); - if (notAlreadyIncluded.first) - m_alreadyIncludedFileUIDs.insert(notAlreadyIncluded.second, - sourceFileUID); - } else { - addFileStatus(fileEntry); - addSourceFile(fileEntry); - } - } - } - } - } - - void InclusionDirective(clang::SourceLocation hashLocation, - const clang::Token & /*includeToken*/, - llvm::StringRef /*fileName*/, - bool /*isAngled*/, - clang::CharSourceRange /*fileNameRange*/, - const clang::FileEntry *file, - llvm::StringRef /*searchPath*/, - llvm::StringRef /*relativePath*/, - const clang::Module * /*imported*/, - clang::SrcMgr::CharacteristicKind fileType) override - { - clang::FileID currentFileId = m_sourceManager->getFileID(hashLocation); - if (file) { - if (currentFileId != m_mainFileId) { - addSourceDependency(file, hashLocation); - auto fileUID = file->getUID(); - auto sourceFileUID = - m_sourceManager - ->getFileEntryForID( - m_sourceManager->getFileID(hashLocation)) - ->getUID(); - auto notAlreadyIncluded = isNotAlreadyIncluded(fileUID); - if (notAlreadyIncluded.first) { - m_alreadyIncludedFileUIDs.insert(notAlreadyIncluded.second, - fileUID); - FilePath filePath = filePathFromFile(file); - if (!filePath.empty()) { - FilePathId includeId = - m_filePathCache.filePathId(filePath); - - time_t lastModified = file->getModificationTime(); - - SourceType sourceType = SourceType::UserInclude; - if (isSystem(fileType)) { - if (isInSystemHeader(hashLocation)) - sourceType = SourceType::SystemInclude; - else - sourceType = SourceType::TopSystemInclude; - } else if (isNotInExcludedIncludeUID(fileUID)) { - if (isInExcludedIncludeUID(sourceFileUID)) - sourceType = SourceType::TopProjectInclude; - else - sourceType = SourceType::ProjectInclude; - } - - addSource({includeId, sourceType, lastModified}); - } - } - } else { - addSource({m_filePathCache.filePathId(filePathFromFile(file)), - SourceType::Source, - file->getModificationTime()}); - } - } else { - auto sourceFileId = filePathId(hashLocation); - m_containsMissingIncludes.emplace_back(sourceFileId); - } - } - - void Ifndef(clang::SourceLocation, - const clang::Token ¯oNameToken, - const clang::MacroDefinition ¯oDefinition) override - { - addUsedMacro(macroNameToken, macroDefinition); - } - - void Ifdef(clang::SourceLocation, - const clang::Token ¯oNameToken, - const clang::MacroDefinition ¯oDefinition) override - { - addUsedMacro( macroNameToken, macroDefinition); - } - - void Defined(const clang::Token ¯oNameToken, - const clang::MacroDefinition ¯oDefinition, - clang::SourceRange) override - { - addUsedMacro(macroNameToken, macroDefinition); - } - - void MacroExpands(const clang::Token ¯oNameToken, - const clang::MacroDefinition ¯oDefinition, - clang::SourceRange, - const clang::MacroArgs *) override - { - addUsedMacro(macroNameToken, macroDefinition); - } - - void EndOfMainFile() override - { - filterOutHeaderGuards(); - mergeUsedMacros(); - filterOutIncludesWithMissingIncludes(); - } - - static - void sortAndMakeUnique(FilePathIds &filePathIds) - { - std::sort(filePathIds.begin(), filePathIds.end()); - auto newEnd = std::unique(filePathIds.begin(), - filePathIds.end()); - filePathIds.erase(newEnd, filePathIds.end()); - } - - void appendContainsMissingIncludes(const FilePathIds &dependentSourceFilesWithMissingIncludes) - { - auto split = m_containsMissingIncludes.insert( - m_containsMissingIncludes.end(), - dependentSourceFilesWithMissingIncludes.begin(), - dependentSourceFilesWithMissingIncludes.end()); - std::inplace_merge(m_containsMissingIncludes.begin(), - split, - m_containsMissingIncludes.end()); - } - - void removeAlreadyFoundSourcesWithMissingIncludes(FilePathIds &dependentSourceFilesWithMissingIncludes) const - { - FilePathIds filteredDependentSourceFilesWithMissingIncludes; - filteredDependentSourceFilesWithMissingIncludes.reserve(dependentSourceFilesWithMissingIncludes.size()); - std::set_difference( - dependentSourceFilesWithMissingIncludes.begin(), - dependentSourceFilesWithMissingIncludes.end(), - m_containsMissingIncludes.begin(), - m_containsMissingIncludes.end(), - std::back_inserter( - filteredDependentSourceFilesWithMissingIncludes)); - dependentSourceFilesWithMissingIncludes = filteredDependentSourceFilesWithMissingIncludes; - } - - void collectSourceWithMissingIncludes(FilePathIds containsMissingIncludes, - const SourceDependencies &sourceDependencies) - { - if (containsMissingIncludes.empty()) - return; - - class Compare - { - public: - bool operator()(SourceDependency sourceDependency, FilePathId filePathId) - { - return sourceDependency.dependencyFilePathId < filePathId; - } - bool operator()(FilePathId filePathId, SourceDependency sourceDependency) - { - return filePathId < sourceDependency.dependencyFilePathId; - } - }; - - FilePathIds dependentSourceFilesWithMissingIncludes; - auto begin = sourceDependencies.begin(); - for (FilePathId sourceWithMissingInclude : containsMissingIncludes) { - auto range = std::equal_range(begin, - sourceDependencies.end(), - sourceWithMissingInclude, - Compare{}); - std::for_each(range.first, range.second, [&](auto entry) { - dependentSourceFilesWithMissingIncludes.emplace_back(entry.filePathId); - }); - - begin = range.second; - } - - sortAndMakeUnique(dependentSourceFilesWithMissingIncludes); - removeAlreadyFoundSourcesWithMissingIncludes(dependentSourceFilesWithMissingIncludes); - appendContainsMissingIncludes(dependentSourceFilesWithMissingIncludes); - collectSourceWithMissingIncludes(dependentSourceFilesWithMissingIncludes, - sourceDependencies); - } - - void removeSourceWithMissingIncludesFromSources() { - class Compare - { - public: - bool operator()(SourceEntry entry, FilePathId filePathId) - { - return entry.sourceId < filePathId; - } - bool operator()(FilePathId filePathId, SourceEntry entry) - { - return filePathId < entry.sourceId; - } - }; - - SourceEntryReferences sourcesWithMissingIncludes; - sourcesWithMissingIncludes.reserve(m_containsMissingIncludes.size()); - std::set_intersection(m_buildDependency.sources.begin(), - m_buildDependency.sources.end(), - m_containsMissingIncludes.begin(), - m_containsMissingIncludes.end(), - std::back_inserter(sourcesWithMissingIncludes), - Compare{}); - for (SourceEntryReference entry : sourcesWithMissingIncludes) - entry.get().hasMissingIncludes = HasMissingIncludes::Yes; - } - - SourceDependencies sourceDependenciesSortedByDependentFilePathId() const - { - auto sourceDependencies = m_buildDependency.sourceDependencies; - std::sort(sourceDependencies.begin(), sourceDependencies.end(), [](auto first, auto second) { - return std::tie(first.dependencyFilePathId, first.filePathId) - < std::tie(second.dependencyFilePathId, second.filePathId); - }); - - return sourceDependencies; - } - - void filterOutIncludesWithMissingIncludes() - { - sortAndMakeUnique(m_containsMissingIncludes); - - collectSourceWithMissingIncludes(m_containsMissingIncludes, - sourceDependenciesSortedByDependentFilePathId()); - - removeSourceWithMissingIncludesFromSources(); - } - - void ensureDirectory(const QString &directory, const QString &fileName) - { - QStringList directoryEntries = fileName.split('/'); - directoryEntries.pop_back(); - - if (!directoryEntries.isEmpty()) - QDir(directory).mkpath(directoryEntries.join('/')); - } - - bool isNotInExcludedIncludeUID(uint uid) const - { - return !isInExcludedIncludeUID(uid); - } - - bool isInExcludedIncludeUID(uint uid) const - { - return std::binary_search(m_excludedIncludeUID.begin(), - m_excludedIncludeUID.end(), - uid); - } - - std::pair::iterator> isNotAlreadyIncluded(uint uid) const - { - auto range = std::equal_range(m_alreadyIncludedFileUIDs.begin(), - m_alreadyIncludedFileUIDs.end(), - uid); - - return {range.first == range.second, range.first}; - } - - static FilePath filePathFromFile(const clang::FileEntry *file) - { - return FilePath::fromNativeFilePath(absolutePath(file->getName())); - } - - void addSource(SourceEntry sourceEntry) { - auto &sources = m_buildDependency.sources; - auto found = std::lower_bound( - sources.begin(), - sources.end(), - sourceEntry, - [](auto first, auto second) { return first < second; }); - - if (found == sources.end() || *found != sourceEntry) - sources.emplace(found, sourceEntry); - } - -private: - FilePathIds m_containsMissingIncludes; - BuildDependency &m_buildDependency; - const std::vector &m_excludedIncludeUID; - std::vector &m_alreadyIncludedFileUIDs; - clang::FileID m_mainFileId; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/collectbuilddependencytoolaction.h b/src/tools/clangpchmanagerbackend/source/collectbuilddependencytoolaction.h deleted file mode 100644 index 47b86e22191..00000000000 --- a/src/tools/clangpchmanagerbackend/source/collectbuilddependencytoolaction.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "collectbuilddependencyaction.h" - -#include -#include - -#include - -namespace ClangBackEnd { - -class CollectBuildDependencyToolAction final : public clang::tooling::FrontendActionFactory -{ -public: - CollectBuildDependencyToolAction(BuildDependency &buildDependency, - const FilePathCachingInterface &filePathCache, - const ClangBackEnd::FilePaths &excludedIncludes) - : m_buildDependency(buildDependency) - , m_filePathCache(filePathCache) - , m_excludedFilePaths(excludedIncludes) - {} - - - bool runInvocation(std::shared_ptr invocation, - clang::FileManager *fileManager, - std::shared_ptr pchContainerOperations, - clang::DiagnosticConsumer *diagnosticConsumer) override - { - if (m_excludedIncludeUIDs.empty()) - m_excludedIncludeUIDs = generateExcludedIncludeFileUIDs(*fileManager); - - return clang::tooling::FrontendActionFactory::runInvocation(invocation, - fileManager, - pchContainerOperations, - diagnosticConsumer); - } - - std::unique_ptr create() override - { - return std::make_unique( - m_buildDependency, - m_filePathCache, - m_excludedIncludeUIDs, - m_alreadyIncludedFileUIDs); - } - - std::vector generateExcludedIncludeFileUIDs(clang::FileManager &fileManager) const - { - std::vector fileUIDs; - fileUIDs.reserve(m_excludedFilePaths.size()); - - for (const FilePath &filePath : m_excludedFilePaths) { - NativeFilePath nativeFilePath{filePath}; - auto file = fileManager.getFile({nativeFilePath.path().data(), - nativeFilePath.path().size()}, - true); - - if (file) - fileUIDs.push_back(file.get()->getUID()); - } - - std::sort(fileUIDs.begin(), fileUIDs.end()); - - return fileUIDs; - } - -private: - std::vector m_alreadyIncludedFileUIDs; - std::vector m_excludedIncludeUIDs; - BuildDependency &m_buildDependency; - const FilePathCachingInterface &m_filePathCache; - const ClangBackEnd::FilePaths &m_excludedFilePaths; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/collectusedmacroactionfactory.h b/src/tools/clangpchmanagerbackend/source/collectusedmacroactionfactory.h deleted file mode 100644 index e9c7c4b32b9..00000000000 --- a/src/tools/clangpchmanagerbackend/source/collectusedmacroactionfactory.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "collectusedmacrosaction.h" - -#include -#include - -#include - -namespace ClangBackEnd { - -class CollectUsedMacrosToolActionFactory final : public clang::tooling::FrontendActionFactory -{ -public: - CollectUsedMacrosToolActionFactory(UsedMacros &usedMacros, - FilePathCachingInterface &filePathCache, - SourceDependencies &sourceDependencies, - FilePathIds &sourceFiles, - FileStatuses &fileStatuses) - : m_usedMacros(usedMacros), - m_filePathCache(filePathCache), - m_sourceDependencies(sourceDependencies), - m_sourceFiles(sourceFiles), - m_fileStatuses(fileStatuses) - {} - - - bool runInvocation(std::shared_ptr invocation, - clang::FileManager *fileManager, - std::shared_ptr pchContainerOperations, - clang::DiagnosticConsumer *diagnosticConsumer) override - { - return clang::tooling::FrontendActionFactory::runInvocation(invocation, - fileManager, - pchContainerOperations, - diagnosticConsumer); - } - - std::unique_ptr create() override - { - return std::make_unique( - m_usedMacros, - m_filePathCache, - m_sourceDependencies, - m_sourceFiles, - m_fileStatuses); - } - -private: - UsedMacros &m_usedMacros; - FilePathCachingInterface &m_filePathCache; - SourceDependencies &m_sourceDependencies; - FilePathIds &m_sourceFiles; - FileStatuses &m_fileStatuses; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/collectusedmacrosaction.h b/src/tools/clangpchmanagerbackend/source/collectusedmacrosaction.h deleted file mode 100644 index 8f50e5a2308..00000000000 --- a/src/tools/clangpchmanagerbackend/source/collectusedmacrosaction.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -#include -#include - -#include -#include -#include - -namespace ClangBackEnd { - -class CollectUsedMacrosAction final : public clang::PreprocessOnlyAction -{ -public: - CollectUsedMacrosAction(UsedMacros &usedMacros, - FilePathCachingInterface &filePathCache, - SourceDependencies &sourceDependencies, - FilePathIds &sourceFiles, - FileStatuses &fileStatuses) - : m_usedMacros(usedMacros), - m_filePathCache(filePathCache), - m_sourceDependencies(sourceDependencies), - m_sourceFiles(sourceFiles), - m_fileStatuses(fileStatuses) - { - } - - bool BeginSourceFileAction(clang::CompilerInstance &compilerInstance) override - { - if (clang::PreprocessOnlyAction::BeginSourceFileAction(compilerInstance)) { - auto &preprocessor = compilerInstance.getPreprocessor(); - - preprocessor.SetSuppressIncludeNotFoundError(true); - - auto macroPreprocessorCallbacks = new CollectUsedMacrosAndSourcesPreprocessorCallbacks( - m_usedMacros, - m_filePathCache, - compilerInstance.getSourceManager(), - compilerInstance.getPreprocessorPtr(), - m_sourceDependencies, - m_sourceFiles, - m_fileStatuses); - - preprocessor.addPPCallbacks(std::unique_ptr(macroPreprocessorCallbacks)); - - return true; - } - - return false; - } - - void EndSourceFileAction() override - { - clang::PreprocessOnlyAction::EndSourceFileAction(); - } - -private: - UsedMacros &m_usedMacros; - FilePathCachingInterface &m_filePathCache; - SourceDependencies &m_sourceDependencies; - FilePathIds &m_sourceFiles; - FileStatuses &m_fileStatuses; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/collectusedmacrosandsourcespreprocessorcallbacks.h b/src/tools/clangpchmanagerbackend/source/collectusedmacrosandsourcespreprocessorcallbacks.h deleted file mode 100644 index 70adc2dffb5..00000000000 --- a/src/tools/clangpchmanagerbackend/source/collectusedmacrosandsourcespreprocessorcallbacks.h +++ /dev/null @@ -1,254 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "sourcelocationsutils.h" -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -namespace ClangBackEnd { - -class CollectUsedMacrosAndSourcesPreprocessorCallbacksBase : public SymbolsVisitorBase -{ -public: - CollectUsedMacrosAndSourcesPreprocessorCallbacksBase(UsedMacros &usedMacros, - const FilePathCachingInterface &filePathCache, - const clang::SourceManager &sourceManager, - std::shared_ptr preprocessor, - SourceDependencies &sourceDependencies, - FilePathIds &sourceFiles, - FileStatuses &fileStatuses) - : SymbolsVisitorBase(filePathCache, &sourceManager, m_filePathIndices) - , m_usedMacros(usedMacros) - , m_preprocessor(preprocessor) - , m_sourceDependencies(sourceDependencies) - , m_sourceFiles(sourceFiles) - , m_fileStatuses(fileStatuses) - {} - - void addSourceFile(const clang::FileEntry *fileEntry) - { - auto id = filePathId(fileEntry); - - auto found = std::lower_bound(m_sourceFiles.begin(), m_sourceFiles.end(), id); - - if (found == m_sourceFiles.end() || *found != id) - m_sourceFiles.insert(found, id); - } - - void addFileStatus(const clang::FileEntry *fileEntry) - { - auto id = filePathId(fileEntry); - - auto found = std::lower_bound(m_fileStatuses.begin(), - m_fileStatuses.end(), - id, - [] (const auto &first, const auto &second) { - return first.filePathId < second; - }); - - if (found == m_fileStatuses.end() || found->filePathId != id) { - m_fileStatuses.emplace(found, - id, - fileEntry->getSize(), - fileEntry->getModificationTime()); - } - } - - void addSourceDependency(const clang::FileEntry *file, clang::SourceLocation includeLocation) - { - auto includeFilePathId = filePathId(includeLocation); - auto includedFilePathId = filePathId(file); - - SourceDependency sourceDependency{includeFilePathId, includedFilePathId}; - - auto found = std::lower_bound(m_sourceDependencies.begin(), - m_sourceDependencies.end(), - sourceDependency, - [](auto first, auto second) { return first < second; }); - - if (found == m_sourceDependencies.end() || *found != sourceDependency) - m_sourceDependencies.emplace(found, sourceDependency); - } - - void mergeUsedMacros() - { - m_usedMacros.reserve(m_usedMacros.size() + m_maybeUsedMacros.size()); - auto insertionPoint = m_usedMacros.insert(m_usedMacros.end(), - m_maybeUsedMacros.begin(), - m_maybeUsedMacros.end()); - std::inplace_merge(m_usedMacros.begin(), insertionPoint, m_usedMacros.end()); - } - - static void addUsedMacro(UsedMacro &&usedMacro, UsedMacros &usedMacros) - { - if (!usedMacro.filePathId.isValid()) - return; - - auto found = std::lower_bound(usedMacros.begin(), - usedMacros.end(), usedMacro); - - if (found == usedMacros.end() || *found != usedMacro) - usedMacros.insert(found, std::move(usedMacro)); - } - - void addUsedMacro(const clang::Token ¯oNameToken, - const clang::MacroDefinition ¯oDefinition) - { - clang::MacroInfo *macroInfo = macroDefinition.getMacroInfo(); - UsedMacro usedMacro{macroNameToken.getIdentifierInfo()->getName(), - filePathId(macroNameToken.getLocation())}; - if (macroInfo) - addUsedMacro(std::move(usedMacro), m_usedMacros); - else - addUsedMacro(std::move(usedMacro), m_maybeUsedMacros); - } - - bool isInSystemHeader(clang::SourceLocation sourceLocation) const - { - return m_sourceManager->isInSystemHeader(sourceLocation); - } - - void filterOutHeaderGuards() - { - auto partitionPoint = std::stable_partition(m_maybeUsedMacros.begin(), - m_maybeUsedMacros.end(), - [&] (const UsedMacro &usedMacro) { - llvm::StringRef id{usedMacro.macroName.data(), usedMacro.macroName.size()}; - clang::IdentifierInfo &identifierInfo = m_preprocessor->getIdentifierTable().get(id); - clang::MacroInfo *macroInfo = m_preprocessor->getMacroInfo(&identifierInfo); - return !macroInfo || !macroInfo->isUsedForHeaderGuard(); - }); - - m_maybeUsedMacros.erase(partitionPoint, m_maybeUsedMacros.end()); - } - -private: - UsedMacros m_maybeUsedMacros; - FilePathIds m_filePathIndices; - UsedMacros &m_usedMacros; - std::shared_ptr m_preprocessor; - SourceDependencies &m_sourceDependencies; - FilePathIds &m_sourceFiles; - FileStatuses &m_fileStatuses; -}; - -class CollectUsedMacrosAndSourcesPreprocessorCallbacks final : public clang::PPCallbacks, - public CollectUsedMacrosAndSourcesPreprocessorCallbacksBase -{ -public: - using CollectUsedMacrosAndSourcesPreprocessorCallbacksBase::CollectUsedMacrosAndSourcesPreprocessorCallbacksBase; - - void FileChanged(clang::SourceLocation sourceLocation, - clang::PPCallbacks::FileChangeReason reason, - clang::SrcMgr::CharacteristicKind, - clang::FileID) override - { - if (reason == clang::PPCallbacks::EnterFile) - { - const clang::FileEntry *fileEntry = m_sourceManager->getFileEntryForID( - m_sourceManager->getFileID(sourceLocation)); - if (fileEntry) { - addFileStatus(fileEntry); - addSourceFile(fileEntry); - } - } - } - - void InclusionDirective(clang::SourceLocation hashLocation, - const clang::Token & /*includeToken*/, - llvm::StringRef /*fileName*/, - bool /*isAngled*/, - clang::CharSourceRange /*fileNameRange*/, - const clang::FileEntry *file, - llvm::StringRef /*searchPath*/, - llvm::StringRef /*relativePath*/, - const clang::Module * /*imported*/, - clang::SrcMgr::CharacteristicKind /*fileType*/ - ) override - { - if (!m_skipInclude && file) - addSourceDependency(file, hashLocation); - - m_skipInclude = false; - } - - void Ifndef(clang::SourceLocation, - const clang::Token ¯oNameToken, - const clang::MacroDefinition ¯oDefinition) override - { - addUsedMacro(macroNameToken, macroDefinition); - } - - void Ifdef(clang::SourceLocation, - const clang::Token ¯oNameToken, - const clang::MacroDefinition ¯oDefinition) override - { - addUsedMacro( macroNameToken, macroDefinition); - } - - void Defined(const clang::Token ¯oNameToken, - const clang::MacroDefinition ¯oDefinition, - clang::SourceRange) override - { - addUsedMacro(macroNameToken, macroDefinition); - } - - void MacroExpands(const clang::Token ¯oNameToken, - const clang::MacroDefinition ¯oDefinition, - clang::SourceRange, - const clang::MacroArgs *) override - { - addUsedMacro(macroNameToken, macroDefinition); - } - - void EndOfMainFile() override - { - filterOutHeaderGuards(); - mergeUsedMacros(); - } - -private: - bool m_skipInclude = false; -}; -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/generatepchactionfactory.h b/src/tools/clangpchmanagerbackend/source/generatepchactionfactory.h deleted file mode 100644 index cf48003c700..00000000000 --- a/src/tools/clangpchmanagerbackend/source/generatepchactionfactory.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -#include -#include -#include -#include - -namespace ClangBackEnd { - -class GeneratePCHAction final : public clang::GeneratePCHAction -{ -public: - GeneratePCHAction(llvm::StringRef filePath, llvm::StringRef fileContent) - : m_filePath(filePath) - , m_fileContent(fileContent) - {} - - bool BeginInvocation(clang::CompilerInstance &compilerInstance) override - { -#if LLVM_VERSION_MAJOR >= 12 - compilerInstance.getPreprocessorOpts().DisablePCHOrModuleValidation = clang::DisableValidationForModuleKind::PCH; -#else - compilerInstance.getPreprocessorOpts().DisablePCHValidation = true; -#endif - compilerInstance.getPreprocessorOpts().AllowPCHWithCompilerErrors = true; - compilerInstance.getDiagnosticOpts().ErrorLimit = 0; - compilerInstance.getFrontendOpts().SkipFunctionBodies = true; - compilerInstance.getFrontendOpts().IncludeTimestamps = true; - std::unique_ptr Input = llvm::MemoryBuffer::getMemBuffer(m_fileContent); - compilerInstance.getPreprocessorOpts().addRemappedFile(m_filePath, Input.release()); - - return clang::GeneratePCHAction::BeginSourceFileAction(compilerInstance); - } - -private: - llvm::StringRef m_filePath; - llvm::StringRef m_fileContent; -}; - -class GeneratePCHActionFactory final : public clang::tooling::FrontendActionFactory -{ -public: - GeneratePCHActionFactory(llvm::StringRef filePath, llvm::StringRef fileContent) - : m_filePath(filePath) - , m_fileContent(fileContent) - {} - - std::unique_ptr create() override - { - return std::make_unique(m_filePath, m_fileContent); - } - -private: - llvm::StringRef m_filePath; - llvm::StringRef m_fileContent; -}; -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp deleted file mode 100644 index 8cd9e061587..00000000000 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "pchcreator.h" - -#include "builddependencycollector.h" -#include "commandlinebuilder.h" -#include "environment.h" -#include "generatepchactionfactory.h" -#include "pchnotcreatederror.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -namespace ClangBackEnd { - -namespace { - -std::size_t contentSize(const FilePaths &includes) -{ - auto countIncludeSize = [] (std::size_t size, const auto &include) { - return size + include.size(); - }; - - return std::accumulate(includes.begin(), includes.end(), std::size_t(0), countIncludeSize); -} -} - -Utils::SmallString PchCreator::generatePchIncludeFileContent(const FilePathIds &includeIds) const -{ - Utils::SmallString fileContent; - const std::size_t lineTemplateSize = 12; - auto includes = m_filePathCache.filePaths(includeIds); - - fileContent.reserve(includes.size() * lineTemplateSize + contentSize(includes)); - - for (Utils::SmallStringView include : includes) - fileContent += {"#include \"", include, "\"\n"}; - - return fileContent; -} - -bool PchCreator::generatePch(NativeFilePathView path, Utils::SmallStringView content) -{ - clang::tooling::ClangTool tool = m_clangTool.createOutputTool(); - - auto action = std::make_unique(llvm::StringRef{path.data(), - path.size()}, - llvm::StringRef{content.data(), - content.size()}); - - return tool.run(action.get()) != 1; -} - -FilePath PchCreator::generatePchFilePath() const -{ - std::uniform_int_distribution distribution( - 1, std::numeric_limits::max()); - - auto joinedPath = Utils::PathString::join({Utils::SmallString(m_environment.pchBuildDirectory()), - "/", - std::to_string(distribution(randomNumberGenator)), - ".pch"}); - - return FilePathView{joinedPath}; -} - -Utils::SmallStringVector PchCreator::generateClangCompilerArguments(const PchTask &pchTask, - FilePathView pchOutputPath) -{ - CommandLineBuilder builder{pchTask, - pchTask.toolChainArguments, - InputFileType::Header, - {}, - pchOutputPath, - pchTask.systemPchPath, - pchTask.preIncludeSearchPath}; - - return builder.commandLine; -} - -FilePathIds PchCreator::existingSources(const FilePathIds &sources) const -{ - FilePathIds existingSources; - existingSources.reserve(sources.size()); - std::set_difference(sources.begin(), - sources.end(), - m_generatedFilePathIds.begin(), - m_generatedFilePathIds.end(), - std::back_inserter(existingSources)); - - return existingSources; -} - -void PchCreator::generatePch(PchTask &&pchTask) -{ - m_projectPartPch.projectPartId = pchTask.projectPartId(); - m_projectPartPch.lastModified = QDateTime::currentSecsSinceEpoch(); - m_watchedSystemIncludes = std::move(pchTask.watchedSystemIncludes); - m_watchedProjectIncludes = std::move(pchTask.watchedProjectIncludes); - m_watchedUserIncludes = std::move(pchTask.watchedUserIncludes); - m_watchedSources = std::move(pchTask.watchedUserSources); - - if (pchTask.includes.empty()) - return; - - auto content = generatePchIncludeFileContent(pchTask.includes); - auto pchOutputPath = generatePchFilePath(); - - FilePath headerFilePath{m_environment.pchBuildDirectory(), "dummy.h"}; - Utils::SmallStringVector commandLine = generateClangCompilerArguments(pchTask, pchOutputPath); - - m_clangTool.addFile(std::move(headerFilePath), content.clone(), std::move(commandLine)); - bool success = generatePch(NativeFilePath{headerFilePath}, content); - - - if (success) - m_projectPartPch.pchPath = std::move(pchOutputPath); -} - -const ProjectPartPch &PchCreator::projectPartPch() -{ - return m_projectPartPch; -} - -void PchCreator::setUnsavedFiles(const V2::FileContainers &fileContainers) -{ - m_generatedFilePathIds.clear(); - m_generatedFilePathIds.reserve(fileContainers.size()); - std::transform(fileContainers.begin(), - fileContainers.end(), - std::back_inserter(m_generatedFilePathIds), - [&](const V2::FileContainer &fileContainer) { - return m_filePathCache.filePathId(fileContainer.filePath); - }); - std::sort(m_generatedFilePathIds.begin(), m_generatedFilePathIds.end()); - - m_clangTool.addUnsavedFiles(fileContainers); -} - -void PchCreator::setIsUsed(bool isUsed) -{ - m_isUsed = isUsed; -} - -bool PchCreator::isUsed() const -{ - return m_isUsed; -} - -void PchCreator::clear() -{ - m_clangTool = ClangTool{}; - m_projectPartPch = {}; - m_watchedSystemIncludes.clear(); - m_watchedProjectIncludes.clear(); - m_watchedUserIncludes.clear(); - m_watchedSources.clear(); -} - -void PchCreator::doInMainThreadAfterFinished() -{ - if (m_projectPartPch.projectPartId.isValid()) { - m_buildDependenciesStorage.updatePchCreationTimeStamp(m_projectPartPch.lastModified, - m_projectPartPch.projectPartId); - m_clangPathwatcher.updateIdPaths( - {{m_projectPartPch.projectPartId, SourceType::Source, existingSources(m_watchedSources)}, - {m_projectPartPch.projectPartId, - SourceType::UserInclude, - existingSources(m_watchedUserIncludes)}, - {m_projectPartPch.projectPartId, - SourceType::ProjectInclude, - existingSources(m_watchedProjectIncludes)}, - {m_projectPartPch.projectPartId, - SourceType::SystemInclude, - existingSources(m_watchedSystemIncludes)}}); - m_pchManagerClient.precompiledHeadersUpdated(m_projectPartPch.projectPartId); - } -} - -const FilePathCachingInterface &PchCreator::filePathCache() -{ - return m_filePathCache; -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.h b/src/tools/clangpchmanagerbackend/source/pchcreator.h deleted file mode 100644 index af8bf8bfdd6..00000000000 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.h +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "pchcreatorinterface.h" - -#include "idpaths.h" -#include "sourceentry.h" -#include "clangtool.h" - -#include -#include -#include - -#include -#include - -QT_FORWARD_DECLARE_CLASS(QFile) -QT_FORWARD_DECLARE_CLASS(QCryptographicHash) -QT_FORWARD_DECLARE_CLASS(QProcess) - -namespace ClangBackEnd { - -class Environment; -class GeneratedFiles; -class PchManagerClientInterface; -class ClangPathWatcherInterface; -class BuildDependenciesStorageInterface; - -class PchCreator final : public PchCreatorInterface -{ -public: - PchCreator(Environment &environment, - FilePathCaching &filePathCache, - PchManagerClientInterface &pchManagerClient, - ClangPathWatcherInterface &clangPathwatcher, - BuildDependenciesStorageInterface &buildDependenciesStorage) - : m_filePathCache(filePathCache) - , m_environment(environment) - , m_pchManagerClient(pchManagerClient) - , m_clangPathwatcher(clangPathwatcher) - , m_buildDependenciesStorage(buildDependenciesStorage) - {} - - void generatePch(PchTask &&pchTask) override; - const ProjectPartPch &projectPartPch() override; - void setUnsavedFiles(const V2::FileContainers &fileContainers) override; - void setIsUsed(bool isUsed) override; - bool isUsed() const override; - void clear() override; - void doInMainThreadAfterFinished() override; - - const FilePathCachingInterface &filePathCache(); - - Utils::SmallString generatePchIncludeFileContent(const FilePathIds &includeIds) const; - bool generatePch(NativeFilePathView path, Utils::SmallStringView content); - - FilePath generatePchFilePath() const; - static Utils::SmallStringVector generateClangCompilerArguments(const PchTask &pchTask, - FilePathView pchPath); - - const ClangTool &clangTool() const { return m_clangTool; } - - FilePathIds existingSources(const FilePathIds &sources) const; - - const FilePathIds &watchedSystemIncludes() const { return m_watchedSystemIncludes; } - const FilePathIds &watchedProjectIncludes() const { return m_watchedProjectIncludes; } - const FilePathIds &watchedUserIncludes() const { return m_watchedUserIncludes; } - const FilePathIds &watchedSources() const { return m_watchedSources; } - -private: - mutable std::mt19937_64 randomNumberGenator{std::random_device{}()}; - ClangTool m_clangTool; - ProjectPartPch m_projectPartPch; - CopyableFilePathCaching m_filePathCache; - FilePathIds m_watchedSystemIncludes; - FilePathIds m_watchedProjectIncludes; - FilePathIds m_watchedUserIncludes; - FilePathIds m_watchedSources; - FilePathIds m_generatedFilePathIds; - Environment &m_environment; - PchManagerClientInterface &m_pchManagerClient; - ClangPathWatcherInterface &m_clangPathwatcher; - BuildDependenciesStorageInterface &m_buildDependenciesStorage; - bool m_isUsed = false; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchcreatorinterface.h b/src/tools/clangpchmanagerbackend/source/pchcreatorinterface.h deleted file mode 100644 index dd16e78f596..00000000000 --- a/src/tools/clangpchmanagerbackend/source/pchcreatorinterface.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "idpaths.h" -#include "pchtask.h" -#include "projectpartpch.h" -#include "processorinterface.h" - -#include -#include - -namespace ClangBackEnd { - -class PchCreatorInterface : public ProcessorInterface -{ -public: - PchCreatorInterface() = default; - PchCreatorInterface(const PchCreatorInterface &) = delete; - PchCreatorInterface &operator=(const PchCreatorInterface &) = delete; - - virtual void generatePch(PchTask &&pchTask) = 0; - virtual const ProjectPartPch &projectPartPch() = 0; - -protected: - ~PchCreatorInterface() = default; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchmanagerserver.cpp b/src/tools/clangpchmanagerbackend/source/pchmanagerserver.cpp deleted file mode 100644 index fa69cd56ca7..00000000000 --- a/src/tools/clangpchmanagerbackend/source/pchmanagerserver.cpp +++ /dev/null @@ -1,306 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "pchmanagerserver.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include - -namespace ClangBackEnd { - -PchManagerServer::PchManagerServer(ClangPathWatcherInterface &fileSystemWatcher, - PchTaskGeneratorInterface &pchTaskGenerator, - ProjectPartsManagerInterface &projectParts, - GeneratedFilesInterface &generatedFiles, - BuildDependenciesStorageInterface &buildDependenciesStorage, - FilePathCachingInterface &filePathCache) - : m_fileSystemWatcher(fileSystemWatcher) - , m_pchTaskGenerator(pchTaskGenerator) - , m_projectPartsManager(projectParts) - , m_generatedFiles(generatedFiles) - , m_buildDependenciesStorage(buildDependenciesStorage) - , m_filePathCache(filePathCache) -{ - m_fileSystemWatcher.setNotifier(this); -} - -void PchManagerServer::end() -{ - QCoreApplication::exit(); -} - -namespace { -ProjectPartIds toProjectPartIds(const ProjectPartContainers &projectParts) -{ - return Utils::transform(projectParts, [](const auto &projectPart) { - return projectPart.projectPartId; - }); -} - -FilePaths gatherPathsInIncludePaths(const ProjectPartContainers &projectParts) -{ - FilePaths filePaths; - - for (const ProjectPartContainer &projectPart : projectParts) { - for (const IncludeSearchPath &searchPath : projectPart.projectIncludeSearchPaths) { - QDirIterator directoryIterator(QString{searchPath.path}, - {"*.h", "*.hpp"}, - QDir::Files, - QDirIterator::FollowSymlinks - | QDirIterator::Subdirectories); - while (directoryIterator.hasNext()) { - filePaths.emplace_back(directoryIterator.next()); - } - } - for (const IncludeSearchPath &searchPath : projectPart.systemIncludeSearchPaths) { - QDirIterator directoryIterator(QString{searchPath.path}, - {"*.h", "*.hpp"}, - QDir::Files, - QDirIterator::FollowSymlinks); - while (directoryIterator.hasNext()) { - filePaths.emplace_back(directoryIterator.next()); - } - } - } - - return filePaths; -} - -} // namespace - -void PchManagerServer::updateProjectParts(UpdateProjectPartsMessage &&message) -{ - m_filePathCache.populateIfEmpty(); - - m_filePathCache.addFilePaths(gatherPathsInIncludePaths(message.projectsParts)); - - m_toolChainsArgumentsCache.update(message.projectsParts, message.toolChainArguments); - - auto upToDateProjectParts = m_projectPartsManager.update(message.takeProjectsParts()); - - if (m_generatedFiles.isValid()) { - m_pchTaskGenerator.addProjectParts(std::move(upToDateProjectParts.updateSystem), - message.toolChainArguments.clone()); - m_pchTaskGenerator.addNonSystemProjectParts(std::move(upToDateProjectParts.updateProject), - std::move(message.toolChainArguments)); - } else { - m_projectPartsManager.updateDeferred(std::move(upToDateProjectParts.updateSystem), - std::move(upToDateProjectParts.updateProject)); - } - - client()->precompiledHeadersUpdated(toProjectPartIds(upToDateProjectParts.upToDate)); -} - -void PchManagerServer::removeProjectParts(RemoveProjectPartsMessage &&message) -{ - m_fileSystemWatcher.removeIds(message.projectsPartIds); - - m_projectPartsManager.remove(message.projectsPartIds); - - m_pchTaskGenerator.removeProjectParts(message.projectsPartIds); - - m_toolChainsArgumentsCache.remove(message.projectsPartIds); -} - -namespace { -ProjectPartIds projectPartIds(const ProjectPartContainers &projectParts) -{ - ProjectPartIds ids; - ids.reserve(projectParts.size()); - - std::transform(projectParts.cbegin(), - projectParts.cend(), - std::back_inserter(ids), - [](const ProjectPartContainer &projectPart) { return projectPart.projectPartId; }); - - return ids; -} -} - -void PchManagerServer::updateGeneratedFiles(UpdateGeneratedFilesMessage &&message) -{ - m_generatedFiles.update(message.takeGeneratedFiles()); - - if (m_generatedFiles.isValid()) { - ProjectPartContainers deferredSystems = m_projectPartsManager.deferredSystemUpdates(); - ArgumentsEntries systemEntries = m_toolChainsArgumentsCache.arguments( - projectPartIds(deferredSystems)); - - for (ArgumentsEntry &entry : systemEntries) { - m_pchTaskGenerator.addProjectParts(std::move(deferredSystems), std::move(entry.arguments)); - } - - ProjectPartContainers deferredProjects = m_projectPartsManager.deferredProjectUpdates(); - ArgumentsEntries projectEntries = m_toolChainsArgumentsCache.arguments( - projectPartIds(deferredProjects)); - - for (ArgumentsEntry &entry : projectEntries) { - m_pchTaskGenerator.addNonSystemProjectParts(std::move(deferredProjects), - std::move(entry.arguments)); - } - } -} - -void PchManagerServer::removeGeneratedFiles(RemoveGeneratedFilesMessage &&message) -{ - m_generatedFiles.remove(message.takeGeneratedFiles()); -} - -namespace { -struct FilterResults -{ - ProjectPartIds systemIds; - ProjectPartIds projectIds; - ProjectPartIds userIds; -}; - -ProjectPartIds removeIds(const ProjectPartIds &subtrahend, const ProjectPartIds &minuend) -{ - ProjectPartIds difference; - difference.reserve(subtrahend.size()); - - std::set_difference(subtrahend.begin(), - subtrahend.end(), - minuend.begin(), - minuend.end(), - std::back_inserter(difference)); - - return difference; -} - -FilterResults pchProjectPartIds(const std::vector &idPaths) -{ - ProjectPartIds changedUserProjectPartIds; - changedUserProjectPartIds.reserve(idPaths.size()); - - ProjectPartIds changedSystemPchProjectPartIds; - changedSystemPchProjectPartIds.reserve(idPaths.size()); - - ProjectPartIds changedProjectPchProjectPartIds; - changedProjectPchProjectPartIds.reserve(idPaths.size()); - - for (const IdPaths &idPath : idPaths) { - switch (idPath.id.sourceType) { - case SourceType::TopSystemInclude: - case SourceType::SystemInclude: - changedSystemPchProjectPartIds.push_back(idPath.id.id); - break; - case SourceType::TopProjectInclude: - case SourceType::ProjectInclude: - changedProjectPchProjectPartIds.push_back(idPath.id.id); - break; - case SourceType::UserInclude: - case SourceType::Source: - changedUserProjectPartIds.push_back(idPath.id.id); - break; - } - } - - changedSystemPchProjectPartIds.erase(std::unique(changedSystemPchProjectPartIds.begin(), - changedSystemPchProjectPartIds.end()), - changedSystemPchProjectPartIds.end()); - changedProjectPchProjectPartIds.erase(std::unique(changedProjectPchProjectPartIds.begin(), - changedProjectPchProjectPartIds.end()), - changedProjectPchProjectPartIds.end()); - changedUserProjectPartIds.erase(std::unique(changedUserProjectPartIds.begin(), - changedUserProjectPartIds.end()), - changedUserProjectPartIds.end()); - - changedProjectPchProjectPartIds = removeIds(changedProjectPchProjectPartIds, - changedSystemPchProjectPartIds); - - changedUserProjectPartIds = removeIds(changedUserProjectPartIds, changedSystemPchProjectPartIds); - changedUserProjectPartIds = removeIds(changedUserProjectPartIds, changedProjectPchProjectPartIds); - - return {std::move(changedSystemPchProjectPartIds), - std::move(changedProjectPchProjectPartIds), - std::move(changedUserProjectPartIds)}; -} -} // namespace - -void PchManagerServer::pathsWithIdsChanged(const std::vector &idPaths) -{ - auto changedProjectPartIds = pchProjectPartIds(idPaths); - - addCompleteProjectParts(changedProjectPartIds.systemIds); - - addNonSystemProjectParts(changedProjectPartIds.projectIds); - - client()->precompiledHeadersUpdated(std::move(changedProjectPartIds.userIds)); -} - -void PchManagerServer::pathsChanged(const FilePathIds &filePathIds) -{ - m_buildDependenciesStorage.insertOrUpdateIndexingTimeStamps(filePathIds, -1); -} - -void PchManagerServer::setPchCreationProgress(int progress, int total) -{ - client()->progress({ProgressType::PrecompiledHeader, progress, total}); -} - -void PchManagerServer::setDependencyCreationProgress(int progress, int total) -{ - client()->progress({ProgressType::DependencyCreation, progress, total}); -} - -void PchManagerServer::addCompleteProjectParts(const ProjectPartIds &projectPartIds) -{ - ArgumentsEntries entries = m_toolChainsArgumentsCache.arguments(projectPartIds); - - for (ArgumentsEntry &entry : entries) { - m_pchTaskGenerator.addProjectParts(m_projectPartsManager.projects(entry.ids), - std::move(entry.arguments)); - } -} - -void PchManagerServer::addNonSystemProjectParts(const ProjectPartIds &projectPartIds) -{ - ArgumentsEntries entries = m_toolChainsArgumentsCache.arguments(projectPartIds); - - for (ArgumentsEntry &entry : entries) { - m_pchTaskGenerator.addNonSystemProjectParts(m_projectPartsManager.projects(entry.ids), - std::move(entry.arguments)); - } -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchmanagerserver.h b/src/tools/clangpchmanagerbackend/source/pchmanagerserver.h deleted file mode 100644 index 7b1187d5f4b..00000000000 --- a/src/tools/clangpchmanagerbackend/source/pchmanagerserver.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangpathwatcherinterface.h" -#include "clangpathwatchernotifier.h" -#include "pchcreatorinterface.h" -#include "pchmanagerserverinterface.h" -#include "projectpartsmanagerinterface.h" -#include "toolchainargumentscache.h" - -#include -#include - -namespace ClangBackEnd { - -class SourceRangesAndDiagnosticsForQueryMessage; -class PchTaskGeneratorInterface; -class BuildDependenciesStorageInterface; -class FilePathCachingInterface; - -class PchManagerServer : public PchManagerServerInterface, - public ClangPathWatcherNotifier, - public IpcClientProvider - -{ -public: - PchManagerServer(ClangPathWatcherInterface &fileSystemWatcher, - PchTaskGeneratorInterface &pchTaskGenerator, - ProjectPartsManagerInterface &projectParts, - GeneratedFilesInterface &generatedFiles, - BuildDependenciesStorageInterface &buildDependenciesStorage, - FilePathCachingInterface &filePathCache); - - void end() override; - void updateProjectParts(UpdateProjectPartsMessage &&message) override; - void removeProjectParts(RemoveProjectPartsMessage &&message) override; - void updateGeneratedFiles(UpdateGeneratedFilesMessage &&message) override; - void removeGeneratedFiles(RemoveGeneratedFilesMessage &&message) override; - - void pathsWithIdsChanged(const std::vector &idPaths) override; - void pathsChanged(const FilePathIds &filePathIds) override; - - void setPchCreationProgress(int progress, int total); - void setDependencyCreationProgress(int progress, int total); - -private: - void addCompleteProjectParts(const ProjectPartIds &projectPartIds); - void addNonSystemProjectParts(const ProjectPartIds &projectPartIds); - -private: - ClangPathWatcherInterface &m_fileSystemWatcher; - PchTaskGeneratorInterface &m_pchTaskGenerator; - ProjectPartsManagerInterface &m_projectPartsManager; - GeneratedFilesInterface &m_generatedFiles; - BuildDependenciesStorageInterface &m_buildDependenciesStorage; - ToolChainsArgumentsCache m_toolChainsArgumentsCache; - FilePathCachingInterface &m_filePathCache; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchnotcreatederror.h b/src/tools/clangpchmanagerbackend/source/pchnotcreatederror.h deleted file mode 100644 index 6be51c0baa5..00000000000 --- a/src/tools/clangpchmanagerbackend/source/pchnotcreatederror.h +++ /dev/null @@ -1,36 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - - -#include - -namespace ClangBackEnd { - -class PchNotCreatedError : public std::runtime_error -{ - using std::runtime_error::runtime_error; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchtask.h b/src/tools/clangpchmanagerbackend/source/pchtask.h deleted file mode 100644 index edca5a94a62..00000000000 --- a/src/tools/clangpchmanagerbackend/source/pchtask.h +++ /dev/null @@ -1,152 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "builddependency.h" - -#include -#include -#include -#include - -#include -#include - -namespace ClangBackEnd { - -class PchTask -{ -public: - PchTask(ProjectPartId projectPartId, - FilePathIds &&includes, - FilePathIds &&watchedSystemIncludes, - FilePathIds &&watchedProjectIncludes, - FilePathIds &&watchedUserIncludes, - FilePathIds &&watchedUserSources, - CompilerMacros &&compilerMacros, - Utils::SmallStringVector toolChainArguments, - IncludeSearchPaths systemIncludeSearchPaths, - IncludeSearchPaths projectIncludeSearchPaths, - Utils::Language language = Utils::Language::Cxx, - Utils::LanguageVersion languageVersion = Utils::LanguageVersion::CXX98, - Utils::LanguageExtension languageExtension = Utils::LanguageExtension::None) - : projectPartIds({projectPartId}) - , includes(includes) - , watchedSystemIncludes(watchedSystemIncludes) - , watchedProjectIncludes(watchedProjectIncludes) - , watchedUserIncludes(watchedUserIncludes) - , watchedUserSources(watchedUserSources) - , compilerMacros(compilerMacros) - , systemIncludeSearchPaths(std::move(systemIncludeSearchPaths)) - , projectIncludeSearchPaths(std::move(projectIncludeSearchPaths)) - , toolChainArguments(std::move(toolChainArguments)) - , language(language) - , languageVersion(languageVersion) - , languageExtension(languageExtension) - {} - - PchTask(ProjectPartIds &&projectPartIds, - FilePathIds &&includes, - FilePathIds &&watchedSystemIncludes, - FilePathIds &&watchedProjectIncludes, - FilePathIds &&watchedUserIncludes, - FilePathIds &&watchedUserSources, - CompilerMacros &&compilerMacros, - Utils::SmallStringVector toolChainArguments, - IncludeSearchPaths systemIncludeSearchPaths, - IncludeSearchPaths projectIncludeSearchPaths, - Utils::Language language = Utils::Language::Cxx, - Utils::LanguageVersion languageVersion = Utils::LanguageVersion::CXX98, - Utils::LanguageExtension languageExtension = Utils::LanguageExtension::None) - : projectPartIds(std::move(projectPartIds)) - , includes(includes) - , watchedSystemIncludes(watchedSystemIncludes) - , watchedProjectIncludes(watchedProjectIncludes) - , watchedUserIncludes(watchedUserIncludes) - , watchedUserSources(watchedUserSources) - , compilerMacros(compilerMacros) - , systemIncludeSearchPaths(std::move(systemIncludeSearchPaths)) - , projectIncludeSearchPaths(std::move(projectIncludeSearchPaths)) - , toolChainArguments(std::move(toolChainArguments)) - , language(language) - , languageVersion(languageVersion) - , languageExtension(languageExtension) - {} - - friend bool operator==(const PchTask &first, const PchTask &second) - { - return first.systemPchPath == second.systemPchPath - && first.projectPartIds == second.projectPartIds && first.includes == second.includes - && first.watchedSystemIncludes == second.watchedSystemIncludes - && first.watchedProjectIncludes == second.watchedProjectIncludes - && first.watchedUserIncludes == second.watchedUserIncludes - && first.watchedUserSources == second.watchedUserSources - && first.compilerMacros == second.compilerMacros - && first.systemIncludeSearchPaths == second.systemIncludeSearchPaths - && first.projectIncludeSearchPaths == second.projectIncludeSearchPaths - && first.toolChainArguments == second.toolChainArguments - && first.preIncludeSearchPath == second.preIncludeSearchPath - && first.language == second.language && first.languageVersion == second.languageVersion - && first.languageExtension == second.languageExtension; - } - - ProjectPartId projectPartId() const { return projectPartIds.front(); } - -public: - FilePath systemPchPath; - ProjectPartIds projectPartIds; - FilePathIds includes; - FilePathIds watchedSystemIncludes; - FilePathIds watchedProjectIncludes; - FilePathIds watchedUserIncludes; - FilePathIds watchedUserSources; - CompilerMacros compilerMacros; - IncludeSearchPaths systemIncludeSearchPaths; - IncludeSearchPaths projectIncludeSearchPaths; - Utils::SmallStringVector toolChainArguments; - NativeFilePathView preIncludeSearchPath; - Utils::Language language = Utils::Language::Cxx; - Utils::LanguageVersion languageVersion = Utils::LanguageVersion::CXX98; - Utils::LanguageExtension languageExtension = Utils::LanguageExtension::None; - bool isMerged = false; -}; - -class PchTaskSet -{ -public: - PchTaskSet(PchTask &&system, PchTask &&project) - : system(std::move(system)) - , project(std::move(project)) - {} - -public: - PchTask system; - PchTask project; -}; - -using PchTasks = std::vector; -using PchTaskSets = std::vector; -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.cpp b/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.cpp deleted file mode 100644 index 08c7d31430d..00000000000 --- a/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "pchtaskgenerator.h" - -#include "builddependenciesproviderinterface.h" -#include "pchtaskqueueinterface.h" -#include "pchtasksmergerinterface.h" -#include "usedmacrofilter.h" - -#include - -#include - -namespace ClangBackEnd { - -void PchTaskGenerator::addProjectParts(ProjectPartContainers &&projectParts, - Utils::SmallStringVector &&toolChainArguments) -{ - PchTaskSets pchTaskSets; - pchTaskSets.reserve(projectParts.size()); - - m_progressCounter.addTotal(static_cast(projectParts.size())); - - for (auto &projectPart : projectParts) { - BuildDependency buildDependency = m_buildDependenciesProvider.create(projectPart); - UsedMacroFilter filter{buildDependency.sources, - buildDependency.usedMacros, - projectPart.compilerMacros}; - - pchTaskSets.emplace_back(PchTask{projectPart.projectPartId, - std::move(filter.topSystemIncludes), - {}, - {}, - {}, - {}, - std::move(filter.systemCompilerMacros), - projectPart.toolChainArguments, - projectPart.systemIncludeSearchPaths, - {}, - projectPart.language, - projectPart.languageVersion, - projectPart.languageExtension}, - PchTask{projectPart.projectPartId, - std::move(filter.topProjectIncludes), - std::move(filter.systemIncludes), - std::move(filter.projectIncludes), - std::move(filter.userIncludes), - std::move(filter.sources), - std::move(filter.projectCompilerMacros), - projectPart.toolChainArguments, - projectPart.systemIncludeSearchPaths, - projectPart.projectIncludeSearchPaths, - projectPart.language, - projectPart.languageVersion, - projectPart.languageExtension}); - m_progressCounter.addProgress(1); - } - - m_pchTasksMergerInterface.mergeTasks(std::move(pchTaskSets), std::move(toolChainArguments)); -} - -void PchTaskGenerator::removeProjectParts(const ProjectPartIds &projectsPartIds) -{ - m_pchTasksMergerInterface.removePchTasks(projectsPartIds); -} - -void PchTaskGenerator::addNonSystemProjectParts(ProjectPartContainers &&projectParts, - Utils::SmallStringVector &&) -{ - PchTasks pchTasks; - pchTasks.reserve(projectParts.size()); - - m_progressCounter.addTotal(static_cast(projectParts.size())); - - for (auto &projectPart : projectParts) { - BuildDependency buildDependency = m_buildDependenciesProvider.create(projectPart); - UsedMacroFilter filter{buildDependency.sources, - buildDependency.usedMacros, - projectPart.compilerMacros}; - - pchTasks.emplace_back(projectPart.projectPartId, - std::move(filter.topProjectIncludes), - std::move(filter.systemIncludes), - std::move(filter.projectIncludes), - std::move(filter.userIncludes), - std::move(filter.sources), - std::move(filter.projectCompilerMacros), - projectPart.toolChainArguments, - projectPart.systemIncludeSearchPaths, - projectPart.projectIncludeSearchPaths, - projectPart.language, - projectPart.languageVersion, - projectPart.languageExtension); - m_progressCounter.addProgress(1); - } - - m_pchTaskQueue.addProjectPchTasks(std::move(pchTasks)); -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.h b/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.h deleted file mode 100644 index be3d91c8920..00000000000 --- a/src/tools/clangpchmanagerbackend/source/pchtaskgenerator.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "pchtask.h" -#include "pchtaskgeneratorinterface.h" - -#include - -namespace ClangBackEnd { - -class PchTasksMergerInterface; - -class BuildDependenciesProviderInterface; -class PchTaskQueueInterface; -class ProgressCounter; - -class PchTaskGenerator : public PchTaskGeneratorInterface -{ -public: - PchTaskGenerator(BuildDependenciesProviderInterface &buildDependenciesProvider, - PchTasksMergerInterface &pchTasksMergerInterface, - ProgressCounter &progressCounter, - PchTaskQueueInterface &pchTaskQueue) - : m_buildDependenciesProvider(buildDependenciesProvider) - , m_pchTasksMergerInterface(pchTasksMergerInterface) - , m_progressCounter(progressCounter) - , m_pchTaskQueue(pchTaskQueue) - - {} - - void addProjectParts(ProjectPartContainers &&projectParts, - Utils::SmallStringVector &&toolChainArguments) override; - void removeProjectParts(const ProjectPartIds &projectsPartIds) override; - void addNonSystemProjectParts(ProjectPartContainers &&projectParts, - Utils::SmallStringVector &&toolChainArguments) override; - -private: - BuildDependenciesProviderInterface &m_buildDependenciesProvider; - PchTasksMergerInterface &m_pchTasksMergerInterface; - ProgressCounter &m_progressCounter; - PchTaskQueueInterface &m_pchTaskQueue; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchtaskgeneratorinterface.h b/src/tools/clangpchmanagerbackend/source/pchtaskgeneratorinterface.h deleted file mode 100644 index 302789ae9a9..00000000000 --- a/src/tools/clangpchmanagerbackend/source/pchtaskgeneratorinterface.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -namespace ClangBackEnd { - -class PchTaskGeneratorInterface -{ -public: - virtual void addProjectParts(ProjectPartContainers &&projectParts, - Utils::SmallStringVector &&toolChainArguments) - = 0; - virtual void addNonSystemProjectParts(ProjectPartContainers &&projectParts, - Utils::SmallStringVector &&toolChainArguments) - = 0; - virtual void removeProjectParts(const ProjectPartIds &projectsPartIds) = 0; - -protected: - ~PchTaskGeneratorInterface() = default; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchtaskqueue.cpp b/src/tools/clangpchmanagerbackend/source/pchtaskqueue.cpp deleted file mode 100644 index 8f1b53855a1..00000000000 --- a/src/tools/clangpchmanagerbackend/source/pchtaskqueue.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "pchtaskqueue.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -namespace ClangBackEnd { - -void PchTaskQueue::addPchTasks(PchTasks &&newPchTasks, PchTasks &destination) -{ - auto compare = [](const PchTask &first, const PchTask &second) { - return first.projectPartIds < second.projectPartIds; - }; - - const std::size_t oldSize = destination.size(); - - PchTasks mergedPchTasks; - mergedPchTasks.reserve(destination.size() + newPchTasks.size()); - Utils::set_union(std::make_move_iterator(newPchTasks.begin()), - std::make_move_iterator(newPchTasks.end()), - std::make_move_iterator(destination.begin()), - std::make_move_iterator(destination.end()), - std::back_inserter(mergedPchTasks), - compare); - - destination = std::move(mergedPchTasks); - - m_progressCounter.addTotal(int(destination.size() - oldSize)); -} - -void PchTaskQueue::removePchTasksByProjectPartId(const ProjectPartIds &projectsPartIds, - PchTasks &destination) -{ - class CompareDifference - { - public: - bool operator()(const PchTask &first, ProjectPartId second) - { - return first.projectPartId() < second; - } - - bool operator()(ProjectPartId first, const PchTask &second) - { - return first < second.projectPartId(); - } - }; - - const std::size_t oldSize = destination.size(); - - PchTasks notToBeRemovedProjectParts; - notToBeRemovedProjectParts.reserve(destination.size()); - std::set_difference(std::make_move_iterator(destination.begin()), - std::make_move_iterator(destination.end()), - projectsPartIds.begin(), - projectsPartIds.end(), - std::back_inserter(notToBeRemovedProjectParts), - CompareDifference{}); - - destination = std::move(notToBeRemovedProjectParts); - - m_progressCounter.removeTotal(int(oldSize - destination.size())); -} - -void PchTaskQueue::addSystemPchTasks(PchTasks &&pchTasks) -{ - addPchTasks(std::move(pchTasks), m_systemPchTasks); -} - -void PchTaskQueue::addProjectPchTasks(PchTasks &&pchTasks) -{ - addPchTasks(std::move(pchTasks), m_projectPchTasks); -} - -void PchTaskQueue::removePchTasks(const ProjectPartIds &projectsPartIds) -{ - removePchTasksByProjectPartId(projectsPartIds, m_projectPchTasks); -} - -int PchTaskQueue::processProjectPchTasks() -{ - auto slotUsage = m_projectPchTaskScheduler.slotUsage(); - uint freeTaskCount = slotUsage.free; - - int newTaskCount = std::min(int(freeTaskCount), int(m_projectPchTasks.size())); - - auto newEnd = std::prev(m_projectPchTasks.end(), newTaskCount); - m_projectPchTaskScheduler.addTasks(createProjectTasks( - {std::make_move_iterator(newEnd), std::make_move_iterator(m_projectPchTasks.end())})); - m_projectPchTasks.erase(newEnd, m_projectPchTasks.end()); - - return newTaskCount + slotUsage.used; -} - -int PchTaskQueue::processSystemPchTasks() -{ - auto slotUsage = m_systemPchTaskScheduler.slotUsage(); - uint freeTaskCount = slotUsage.free; - - int newTaskCount = std::min(int(freeTaskCount), int(m_systemPchTasks.size())); - - auto newEnd = std::prev(m_systemPchTasks.end(), newTaskCount); - m_systemPchTaskScheduler.addTasks(createSystemTasks( - {std::make_move_iterator(newEnd), std::make_move_iterator(m_systemPchTasks.end())})); - m_systemPchTasks.erase(newEnd, m_systemPchTasks.end()); - - return newTaskCount + slotUsage.used; -} - -void PchTaskQueue::deleteUnusedPchs() -{ - FilePathIds existingPchFilePathIds = m_fileSystem.directoryEntries( - QString{m_environment.pchBuildDirectory()}); - FilePathIds notAnymoreUsedPchFilePathIds; - notAnymoreUsedPchFilePathIds.reserve(existingPchFilePathIds.size()); - - FilePathIds usedPchFilePathIds = m_filePathCache.filePathIds( - m_precompiledHeaderStorage.fetchAllPchPaths()); - std::sort(usedPchFilePathIds.begin(), usedPchFilePathIds.end()); - - std::set_difference(existingPchFilePathIds.begin(), - existingPchFilePathIds.end(), - usedPchFilePathIds.begin(), - usedPchFilePathIds.end(), - std::back_inserter(notAnymoreUsedPchFilePathIds)); - - m_fileSystem.remove(notAnymoreUsedPchFilePathIds); -} - -void PchTaskQueue::processEntries() -{ - int projectTaskCount = 0; - int systemTaskCount = processSystemPchTasks(); - if (systemTaskCount == 0) - projectTaskCount = processProjectPchTasks(); - - int totalTaskCount = projectTaskCount + systemTaskCount; - - if (totalTaskCount == 0) - deleteUnusedPchs(); -} - -std::vector PchTaskQueue::createProjectTasks(PchTasks &&pchTasks) const -{ - std::vector tasks; - tasks.reserve(pchTasks.size()); - - auto convert = [this](auto &&pchTask) { - return [pchTask = std::move(pchTask), this](PchCreatorInterface &pchCreator) mutable { - const auto projectPartId = pchTask.projectPartId(); - pchTask.systemPchPath = m_precompiledHeaderStorage.fetchSystemPrecompiledHeaderPath( - projectPartId); - pchTask.preIncludeSearchPath = m_environment.preIncludeSearchPath(); - pchCreator.generatePch(std::move(pchTask)); - const auto &projectPartPch = pchCreator.projectPartPch(); - if (projectPartPch.pchPath.empty()) { - m_precompiledHeaderStorage.deleteProjectPrecompiledHeader(projectPartId, - projectPartPch.lastModified); - } else { - m_precompiledHeaderStorage.insertProjectPrecompiledHeader( - projectPartId, projectPartPch.pchPath, projectPartPch.lastModified); - } - }; - }; - - std::transform(std::make_move_iterator(pchTasks.begin()), - std::make_move_iterator(pchTasks.end()), - std::back_inserter(tasks), - convert); - - return tasks; -} - -std::vector PchTaskQueue::createSystemTasks(PchTasks &&pchTasks) const -{ - std::vector tasks; - tasks.reserve(pchTasks.size()); - - auto convert = [this](auto &&pchTask) { - return [pchTask = std::move(pchTask), this](PchCreatorInterface &pchCreator) mutable { - const auto projectPartIds = pchTask.projectPartIds; - pchTask.preIncludeSearchPath = m_environment.preIncludeSearchPath(); - pchCreator.generatePch(std::move(pchTask)); - const auto &projectPartPch = pchCreator.projectPartPch(); - if (projectPartPch.pchPath.empty()) { - m_precompiledHeaderStorage.deleteSystemPrecompiledHeaders(projectPartIds); - } else { - m_precompiledHeaderStorage.insertSystemPrecompiledHeaders( - projectPartIds, projectPartPch.pchPath, projectPartPch.lastModified); - } - }; - }; - - std::transform(std::make_move_iterator(pchTasks.begin()), - std::make_move_iterator(pchTasks.end()), - std::back_inserter(tasks), - convert); - - return tasks; -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchtaskqueue.h b/src/tools/clangpchmanagerbackend/source/pchtaskqueue.h deleted file mode 100644 index a7a455b3578..00000000000 --- a/src/tools/clangpchmanagerbackend/source/pchtaskqueue.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "pchtaskqueueinterface.h" -#include "taskschedulerinterface.h" - -namespace Sqlite { -class TransactionInterface; -} - -namespace ClangBackEnd { -class PchCreatorInterface; -class PrecompiledHeaderStorageInterface; -class ProgressCounter; -class Environment; -class FileSystemInterface; -class FilePathCachingInterface; - -class PchTaskQueue final : public PchTaskQueueInterface -{ -public: - using Task = std::function; - - PchTaskQueue(TaskSchedulerInterface &systemPchTaskScheduler, - TaskSchedulerInterface &projectPchTaskScheduler, - ProgressCounter &progressCounter, - PrecompiledHeaderStorageInterface &precompiledHeaderStorage, - Sqlite::TransactionInterface &transactionsInterface, - const Environment &environment, - FileSystemInterface &fileSystem, - FilePathCachingInterface &filePathCache) - : m_systemPchTaskScheduler(systemPchTaskScheduler) - , m_projectPchTaskScheduler(projectPchTaskScheduler) - , m_precompiledHeaderStorage(precompiledHeaderStorage) - , m_transactionsInterface(transactionsInterface) - , m_progressCounter(progressCounter) - , m_environment(environment) - , m_fileSystem(fileSystem) - , m_filePathCache(filePathCache) - { - Q_UNUSED(m_transactionsInterface) - } - - void addSystemPchTasks(PchTasks &&pchTasks) override; - void addProjectPchTasks(PchTasks &&pchTasks) override; - void removePchTasks(const ProjectPartIds &projectsPartIds) override; - - void processEntries() override; - - const PchTasks &systemPchTasks() const { return m_systemPchTasks; } - const PchTasks &projectPchTasks() const { return m_projectPchTasks; } - - std::vector createProjectTasks(PchTasks &&pchTasks) const; - std::vector createSystemTasks(PchTasks &&pchTasks) const; - -private: - void addPchTasks(PchTasks &&pchTasks, PchTasks &destination); - void removePchTasksByProjectPartId(const ProjectPartIds &projectsPartIds, PchTasks &destination); - int processProjectPchTasks(); - int processSystemPchTasks(); - void deleteUnusedPchs(); - -private: - PchTasks m_systemPchTasks; - PchTasks m_projectPchTasks; - TaskSchedulerInterface &m_systemPchTaskScheduler; - TaskSchedulerInterface &m_projectPchTaskScheduler; - PrecompiledHeaderStorageInterface &m_precompiledHeaderStorage; - Sqlite::TransactionInterface &m_transactionsInterface; - ProgressCounter &m_progressCounter; - const Environment &m_environment; - FileSystemInterface &m_fileSystem; - FilePathCachingInterface &m_filePathCache; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchtaskqueueinterface.h b/src/tools/clangpchmanagerbackend/source/pchtaskqueueinterface.h deleted file mode 100644 index 31c709d1a9f..00000000000 --- a/src/tools/clangpchmanagerbackend/source/pchtaskqueueinterface.h +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "queueinterface.h" -#include "pchtask.h" - -namespace ClangBackEnd { - -class PchTaskQueueInterface : public QueueInterface -{ -public: - virtual void addSystemPchTasks(PchTasks &&pchTasks) = 0; - virtual void addProjectPchTasks(PchTasks &&pchTasks) = 0; - virtual void removePchTasks(const ProjectPartIds &projectsPartIds) = 0; - -protected: - ~PchTaskQueueInterface() = default; -}; -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchtasksmerger.cpp b/src/tools/clangpchmanagerbackend/source/pchtasksmerger.cpp deleted file mode 100644 index 6436c0a0b4e..00000000000 --- a/src/tools/clangpchmanagerbackend/source/pchtasksmerger.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "pchtasksmerger.h" - -#include "pchtaskqueueinterface.h" - -#include - -namespace ClangBackEnd { - -void PchTasksMerger::mergeTasks(PchTaskSets &&taskSets, - Utils::SmallStringVector && /*toolChainArguments*/) -{ - mergeSystemTasks(taskSets); - addProjectTasksToQueue(taskSets); - m_pchTaskQueue.processEntries(); -} - -void PchTasksMerger::removePchTasks(const ProjectPartIds &projectPartIds) -{ - m_pchTaskQueue.removePchTasks(projectPartIds); -} - -template>> -Result merge(Container &&first, Container &&second) -{ - Result result; - result.reserve(first.size() + second.size()); - - Utils::set_union(std::make_move_iterator(first.begin()), - std::make_move_iterator(first.end()), - std::make_move_iterator(second.begin()), - std::make_move_iterator(second.end()), - std::back_inserter(result)); - - return result; -} - -CompilerMacros PchTasksMerger::mergeMacros(const CompilerMacros &firstCompilerMacros, - const CompilerMacros &secondCompilerMacros) -{ - return merge(firstCompilerMacros, secondCompilerMacros); -} - -bool PchTasksMerger::hasDuplicates(const CompilerMacros &compilerMacros) -{ - auto found = std::adjacent_find(compilerMacros.begin(), - compilerMacros.end(), - [](const CompilerMacro &first, const CompilerMacro &second) { - return first.key == second.key; - }); - - return found != compilerMacros.end(); -} - -IncludeSearchPaths mergeIncludeSearchPaths(IncludeSearchPaths &&first, IncludeSearchPaths &&second) -{ - if (first.size() > second.size()) - return merge(first, second); - - return merge(first, second); -} - -bool PchTasksMerger::mergePchTasks(PchTask &firstTask, PchTask &secondTask) -{ - if (firstTask.language != secondTask.language || firstTask.isMerged || secondTask.isMerged) - return false; - - CompilerMacros macros = mergeMacros(firstTask.compilerMacros, secondTask.compilerMacros); - - secondTask.isMerged = !hasDuplicates(macros); - - - if (secondTask.isMerged && firstTask.language == secondTask.language) { - firstTask.projectPartIds = merge(std::move(firstTask.projectPartIds), - std::move(secondTask.projectPartIds)); - firstTask.includes = merge(std::move(firstTask.includes), std::move(secondTask.includes)); - firstTask.watchedSystemIncludes = merge(std::move(firstTask.watchedSystemIncludes), - std::move(secondTask.watchedSystemIncludes)); - firstTask.compilerMacros = std::move(macros); - firstTask.systemIncludeSearchPaths = mergeIncludeSearchPaths( - std::move(firstTask.systemIncludeSearchPaths), - std::move(secondTask.systemIncludeSearchPaths)); - - firstTask.languageVersion = std::max(firstTask.languageVersion, secondTask.languageVersion); - firstTask.languageExtension = firstTask.languageExtension | secondTask.languageExtension; - } - - return secondTask.isMerged; -} - -void PchTasksMerger::mergePchTasks(PchTasks &tasks) -{ - auto begin = tasks.begin(); - - while (begin != tasks.end()) { - begin = std::find_if(begin, tasks.end(), [](const auto &task) { return !task.isMerged; }); - if (begin != tasks.end()) { - PchTask &baseTask = *begin; - ++begin; - - std::for_each(begin, tasks.end(), [&](PchTask ¤tTask) { - mergePchTasks(baseTask, currentTask); - }); - } - } -} - -void PchTasksMerger::addProjectTasksToQueue(PchTaskSets &taskSets) -{ - PchTasks projectTasks; - projectTasks.reserve(taskSets.size()); - - for (PchTaskSet &taskSet : taskSets) - projectTasks.push_back(std::move(taskSet.project)); - - m_pchTaskQueue.addProjectPchTasks(std::move(projectTasks)); -} - -void PchTasksMerger::mergeSystemTasks(PchTaskSets &taskSets) -{ - PchTasks systemTasks; - systemTasks.reserve(taskSets.size()); - - for (PchTaskSet &taskSet : taskSets) - systemTasks.push_back(std::move(taskSet.system)); - - mergePchTasks(systemTasks); - - systemTasks.erase(std::remove_if(systemTasks.begin(), - systemTasks.end(), - [](const PchTask &task) { return task.isMerged; }), - systemTasks.end()); - - m_pchTaskQueue.addSystemPchTasks(std::move(systemTasks)); -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchtasksmerger.h b/src/tools/clangpchmanagerbackend/source/pchtasksmerger.h deleted file mode 100644 index 5481a50dfff..00000000000 --- a/src/tools/clangpchmanagerbackend/source/pchtasksmerger.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "pchtasksmergerinterface.h" -#include "pchtask.h" - -namespace ClangBackEnd { - -class PchTaskQueueInterface; - -class PchTasksMerger final : public PchTasksMergerInterface -{ -public: - PchTasksMerger(PchTaskQueueInterface &pchTaskQueue) - : m_pchTaskQueue(pchTaskQueue) - {} - - void mergeTasks(PchTaskSets &&taskSets, Utils::SmallStringVector &&toolChainArguments) override; - void removePchTasks(const ProjectPartIds &projectPartIds) override; - - static CompilerMacros mergeMacros(const CompilerMacros &firstCompilerMacros, - const CompilerMacros &secondCompilerMacros); - static bool hasDuplicates(const CompilerMacros &compilerMacros); - - static bool mergePchTasks(PchTask &first, PchTask &second); - - static void mergePchTasks(PchTasks &tasks); - -private: - void addProjectTasksToQueue(PchTaskSets &taskSets); - void mergeSystemTasks(PchTaskSets &taskSets); - -private: - PchTaskQueueInterface &m_pchTaskQueue; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/pchtasksmergerinterface.h b/src/tools/clangpchmanagerbackend/source/pchtasksmergerinterface.h deleted file mode 100644 index 69f1e0470a9..00000000000 --- a/src/tools/clangpchmanagerbackend/source/pchtasksmergerinterface.h +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "pchtask.h" - -namespace ClangBackEnd { -class PchTasksMergerInterface -{ -public: - virtual void mergeTasks(PchTaskSets &&taskSets, Utils::SmallStringVector &&toolChainArguments) = 0; - virtual void removePchTasks(const ProjectPartIds &projectPartIds) = 0; - -protected: - ~PchTasksMergerInterface() = default; -}; -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/precompiledheaderstorage.h b/src/tools/clangpchmanagerbackend/source/precompiledheaderstorage.h deleted file mode 100644 index d0f596aeb2d..00000000000 --- a/src/tools/clangpchmanagerbackend/source/precompiledheaderstorage.h +++ /dev/null @@ -1,287 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "pchpaths.h" -#include "precompiledheaderstorageinterface.h" - -#include -#include - -#include - -namespace ClangBackEnd { - -template -class PrecompiledHeaderStorage final : public PrecompiledHeaderStorageInterface -{ - template - using ReadStatement = typename Database::template ReadStatement; - using WriteStatement = typename Database::WriteStatement; -public: - PrecompiledHeaderStorage(Database &database) - : transaction(database) - , database(database) - { - transaction.commit(); - } - - void insertProjectPrecompiledHeader(ProjectPartId projectPartId, - Utils::SmallStringView pchPath, - TimeStamp pchBuildTime) override - { - try { - Sqlite::ImmediateTransaction transaction{database}; - - insertProjectPrecompiledHeaderStatement.write(projectPartId.projectPathId, - pchPath, - pchBuildTime.value); - - transaction.commit(); - } catch (const Sqlite::StatementIsBusy &) { - insertProjectPrecompiledHeader(projectPartId, pchPath, pchBuildTime); - } - } - - void deleteProjectPrecompiledHeader(ProjectPartId projectPartId, TimeStamp pchBuildTime) override - { - try { - Sqlite::ImmediateTransaction transaction{database}; - - deleteProjectPrecompiledHeaderPathAndSetBuildTimeStatement.write(projectPartId.projectPathId, - pchBuildTime.value); - - transaction.commit(); - } catch (const Sqlite::StatementIsBusy &) { - deleteProjectPrecompiledHeader(projectPartId, pchBuildTime); - } - } - - void deleteProjectPrecompiledHeaders(const ProjectPartIds &projectPartIds) override - { - try { - Sqlite::ImmediateTransaction transaction{database}; - - for (ProjectPartId projectPartId : projectPartIds) - deleteProjectPrecompiledHeaderStatement.write(projectPartId.projectPathId); - - transaction.commit(); - } catch (const Sqlite::StatementIsBusy &) { - deleteProjectPrecompiledHeaders(projectPartIds); - } - } - - void insertSystemPrecompiledHeaders(const ProjectPartIds &projectPartIds, - Utils::SmallStringView pchPath, - TimeStamp pchBuildTime) override - { - try { - Sqlite::ImmediateTransaction transaction{database}; - - for (ProjectPartId projectPartId : projectPartIds) { - insertSystemPrecompiledHeaderStatement.write(projectPartId.projectPathId, - pchPath, - pchBuildTime.value); - } - transaction.commit(); - } catch (const Sqlite::StatementIsBusy &) { - insertSystemPrecompiledHeaders(projectPartIds, pchPath, pchBuildTime); - } - } - - void deleteSystemPrecompiledHeaders(const ProjectPartIds &projectPartIds) override - { - try { - Sqlite::ImmediateTransaction transaction{database}; - - for (ProjectPartId projectPartId : projectPartIds) - deleteSystemPrecompiledHeaderStatement.write(projectPartId.projectPathId); - - transaction.commit(); - } catch (const Sqlite::StatementIsBusy &) { - deleteSystemPrecompiledHeaders(projectPartIds); - } - } - - void deleteSystemAndProjectPrecompiledHeaders(const ProjectPartIds &projectPartIds) override - { - try { - Sqlite::ImmediateTransaction transaction{database}; - - for (ProjectPartId projectPartId : projectPartIds) - deleteSystemAndProjectPrecompiledHeaderStatement.write(projectPartId.projectPathId); - - transaction.commit(); - } catch (const Sqlite::StatementIsBusy &) { - deleteSystemAndProjectPrecompiledHeaders(projectPartIds); - } - } - - FilePath fetchSystemPrecompiledHeaderPath(ProjectPartId projectPartId) override - { - try { - Sqlite::DeferredTransaction transaction{database}; - - auto value = fetchSystemPrecompiledHeaderPathStatement.template optionalValue( - projectPartId.projectPathId); - - transaction.commit(); - - if (value) - return *value; - - } catch (const Sqlite::StatementIsBusy &) { - return fetchSystemPrecompiledHeaderPath(projectPartId); - } - - return FilePath(""); - } - - FilePath fetchPrecompiledHeader(ProjectPartId projectPartId) const override - { - try { - Sqlite::DeferredTransaction transaction{database}; - - auto value = fetchPrecompiledHeaderStatement.template optionalValue( - projectPartId.projectPathId); - - transaction.commit(); - - if (value) - return *value; - - } catch (const Sqlite::StatementIsBusy &) { - return fetchPrecompiledHeader(projectPartId); - } - - return FilePath(""); - } - - PchPaths fetchPrecompiledHeaders(ProjectPartId projectPartId) const override - { - try { - Sqlite::DeferredTransaction transaction{database}; - - auto value = fetchPrecompiledHeadersStatement.template optionalValue( - projectPartId.projectPathId); - - transaction.commit(); - - if (value) - return *value; - - } catch (const Sqlite::StatementIsBusy &) { - return fetchPrecompiledHeaders(projectPartId); - } - - return {}; - } - - PrecompiledHeaderTimeStamps fetchTimeStamps(ProjectPartId projectPartId) const override - { - try { - Sqlite::DeferredTransaction transaction{database}; - - auto value = fetchTimeStampsStatement.template optionalValue( - projectPartId.projectPathId); - - transaction.commit(); - - if (value) - return *value; - - } catch (const Sqlite::StatementIsBusy &) { - return fetchTimeStamps(projectPartId); - } - - return {}; - } - - FilePaths fetchAllPchPaths() const - { - try { - Sqlite::DeferredTransaction transaction{database}; - - auto filePaths = fetchAllPchPathsStatement.template values(1024); - - transaction.commit(); - - return filePaths; - - } catch (const Sqlite::StatementIsBusy &) { - return fetchAllPchPaths(); - } - } - -public: - Sqlite::ImmediateNonThrowingDestructorTransaction transaction; - Database &database; - WriteStatement insertProjectPrecompiledHeaderStatement{ - "INSERT INTO precompiledHeaders(projectPartId, projectPchPath, projectPchBuildTime) " - "VALUES(?001,?002,?003) " - "ON CONFLICT (projectPartId) DO UPDATE SET projectPchPath=?002,projectPchBuildTime=?003", - database}; - WriteStatement insertSystemPrecompiledHeaderStatement{ - "INSERT INTO precompiledHeaders(projectPartId, systemPchPath, systemPchBuildTime) " - "VALUES(?001,?002,?003) " - "ON CONFLICT (projectPartId) DO UPDATE SET systemPchPath=?002,systemPchBuildTime=?003", - database}; - WriteStatement deleteProjectPrecompiledHeaderStatement{ - "UPDATE OR IGNORE precompiledHeaders SET projectPchPath=NULL,projectPchBuildTime=NULL " - "WHERE projectPartId = ?", - database}; - WriteStatement deleteProjectPrecompiledHeaderPathAndSetBuildTimeStatement{ - "UPDATE OR IGNORE precompiledHeaders SET projectPchPath=NULL,projectPchBuildTime=?002 " - "WHERE projectPartId = ?001", - database}; - WriteStatement deleteSystemPrecompiledHeaderStatement{ - "UPDATE OR IGNORE precompiledHeaders SET systemPchPath=NULL,systemPchBuildTime=NULL " - "WHERE projectPartId = ?", - database}; - WriteStatement deleteSystemAndProjectPrecompiledHeaderStatement{ - "UPDATE OR IGNORE precompiledHeaders SET " - "systemPchPath=NULL,systemPchBuildTime=NULL,projectPchPath=NULL,projectPchBuildTime=NULL " - "WHERE projectPartId = ?", - database}; - ReadStatement<1> fetchSystemPrecompiledHeaderPathStatement{ - "SELECT systemPchPath FROM precompiledHeaders WHERE projectPartId = ?", database}; - mutable ReadStatement<1> fetchPrecompiledHeaderStatement{ - "SELECT ifnull(nullif(projectPchPath, ''), systemPchPath) " - "FROM precompiledHeaders WHERE projectPartId = ?", - database}; - mutable ReadStatement<2> fetchPrecompiledHeadersStatement{ - "SELECT projectPchPath, systemPchPath FROM precompiledHeaders WHERE projectPartId = ?", - database}; - mutable ReadStatement<2> fetchTimeStampsStatement{ - "SELECT projectPchBuildTime, systemPchBuildTime FROM precompiledHeaders WHERE " - "projectPartId = ?", - database}; - mutable ReadStatement<1> fetchAllPchPathsStatement{ - "SELECT DISTINCT systemPchPath FROM precompiledHeaders UNION ALL SELECT " - "DISTINCT projectPchPath FROM precompiledHeaders", - database}; -}; -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/precompiledheaderstorageinterface.h b/src/tools/clangpchmanagerbackend/source/precompiledheaderstorageinterface.h deleted file mode 100644 index fd954a0c8a6..00000000000 --- a/src/tools/clangpchmanagerbackend/source/precompiledheaderstorageinterface.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "projectpartpch.h" - -#include -#include -#include - -#include -#include - -namespace ClangBackEnd { - -class PrecompiledHeaderStorageInterface -{ -public: - PrecompiledHeaderStorageInterface() = default; - - PrecompiledHeaderStorageInterface(const PrecompiledHeaderStorageInterface &) = delete; - PrecompiledHeaderStorageInterface &operator=(const PrecompiledHeaderStorageInterface &) = delete; - - virtual void insertProjectPrecompiledHeader(ProjectPartId projectPartId, - Utils::SmallStringView pchPath, - TimeStamp pchBuildTime) - = 0; - virtual void deleteProjectPrecompiledHeader(ProjectPartId projectPartId, TimeStamp pchBuildTime) = 0; - virtual void deleteProjectPrecompiledHeaders(const ProjectPartIds &projectPartIds) = 0; - virtual void insertSystemPrecompiledHeaders(const ProjectPartIds &projectPartIds, - Utils::SmallStringView pchPath, - TimeStamp pchBuildTime) - = 0; - virtual void deleteSystemPrecompiledHeaders(const ProjectPartIds &projectPartIds) = 0; - virtual void deleteSystemAndProjectPrecompiledHeaders(const ProjectPartIds &projectPartIds) = 0; - virtual FilePath fetchSystemPrecompiledHeaderPath(ProjectPartId projectPartId) = 0; - virtual FilePath fetchPrecompiledHeader(ProjectPartId projectPartId) const = 0; - virtual PchPaths fetchPrecompiledHeaders(ProjectPartId projectPartId) const = 0; - virtual PrecompiledHeaderTimeStamps fetchTimeStamps(ProjectPartId projectPartId) const = 0; - virtual FilePaths fetchAllPchPaths() const = 0; - -protected: - ~PrecompiledHeaderStorageInterface() = default; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/processorinterface.h b/src/tools/clangpchmanagerbackend/source/processorinterface.h deleted file mode 100644 index 444c6c6ddb5..00000000000 --- a/src/tools/clangpchmanagerbackend/source/processorinterface.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -namespace ClangBackEnd { - -class ProcessorInterface -{ -public: - ProcessorInterface() = default; - virtual ~ProcessorInterface() = default; - ProcessorInterface(const ProcessorInterface &) = delete; - ProcessorInterface &operator=(const ProcessorInterface &) = delete; - - virtual void setUnsavedFiles(const V2::FileContainers &unsavedFiles) = 0; - virtual bool isUsed() const = 0; - virtual void setIsUsed(bool isUsed) = 0; - virtual void clear() = 0; - virtual void doInMainThreadAfterFinished() = 0; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/processormanager.h b/src/tools/clangpchmanagerbackend/source/processormanager.h deleted file mode 100644 index be20c5d87fb..00000000000 --- a/src/tools/clangpchmanagerbackend/source/processormanager.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - - -#include "processormanagerinterface.h" -#include "generatedfiles.h" - -#include - -namespace Sqlite { -class Database; -} - -namespace ClangBackEnd { - -class GeneratedFiles; - -template -class ProcessorManager : public ProcessorManagerInterface -{ -public: - using Processor = ProcessorType; - ProcessorManager(const GeneratedFiles &generatedFiles) - : m_generatedFiles(generatedFiles) - {} - - Processor &unusedProcessor() override - { - auto split = std::partition(m_processors.begin(), - m_processors.end(), - [] (const auto &collector) { - return collector->isUsed(); - }); - - auto freeCollectors = std::distance(split, m_processors.end()); - - if (freeCollectors > 0) - return initializedCollector(*split->get()); - - m_processors.push_back(createProcessor()); - - return initializedCollector(*m_processors.back().get()); - } - - const std::vector> &processors() const - { - return m_processors; - } - -protected: - ~ProcessorManager() = default; - virtual std::unique_ptr createProcessor() const = 0; - -private: - Processor &initializedCollector(Processor &creator) - { - creator.setIsUsed(true); - creator.setUnsavedFiles(m_generatedFiles.fileContainers()); - return creator; - } - - -private: - std::vector> m_processors; - const GeneratedFiles &m_generatedFiles; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/processormanagerinterface.h b/src/tools/clangpchmanagerbackend/source/processormanagerinterface.h deleted file mode 100644 index 13d02fbc94b..00000000000 --- a/src/tools/clangpchmanagerbackend/source/processormanagerinterface.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -#include - -namespace ClangBackEnd { - -class ProcessorManagerInterface -{ -public: - ProcessorManagerInterface() = default; - ProcessorManagerInterface(const ProcessorManagerInterface &) = delete; - ProcessorManagerInterface &operator=(const ProcessorManagerInterface &) = delete; - - virtual ProcessorInterface &unusedProcessor() = 0; - -protected: - ~ProcessorManagerInterface() = default; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/projectpartsmanager.cpp b/src/tools/clangpchmanagerbackend/source/projectpartsmanager.cpp deleted file mode 100644 index 48074f440cc..00000000000 --- a/src/tools/clangpchmanagerbackend/source/projectpartsmanager.cpp +++ /dev/null @@ -1,415 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "projectpartsmanager.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -namespace ClangBackEnd { - -inline namespace Pch { -ProjectPartIds toProjectPartIds(const ProjectPartContainers &projectsParts) -{ - ProjectPartIds ids; - ids.reserve(projectsParts.size()); - std::transform(projectsParts.begin(), - projectsParts.end(), - std::back_inserter(ids), - [](const auto &projectPart) { return projectPart.projectPartId; }); - - return ids; -} - -namespace { - -enum class Change { System, Project, No }; - -Change changedSourceType(SourceEntry sourceEntry, Change oldChange) -{ - switch (sourceEntry.sourceType) { - case SourceType::SystemInclude: - case SourceType::TopSystemInclude: - return Change::System; - case SourceType::ProjectInclude: - case SourceType::TopProjectInclude: - if (oldChange != Change::System) - return Change::Project; - break; - case SourceType::Source: - case SourceType::UserInclude: - break; - } - - return oldChange; -} - -FilePathIds existingSources(const FilePathIds &sources, const FilePathIds &generatedFilePathIds) -{ - FilePathIds existingSources; - existingSources.reserve(sources.size()); - std::set_difference(sources.begin(), - sources.end(), - generatedFilePathIds.begin(), - generatedFilePathIds.end(), - std::back_inserter(existingSources)); - - return existingSources; -} - -} // namespace - -ProjectPartsManager::UpToDataProjectParts ProjectPartsManager::update(ProjectPartContainers &&projectsParts) -{ - auto updateSystemProjectParts = filterProjectParts(projectsParts, m_projectParts); - - if (!updateSystemProjectParts.empty()) { - auto persistentProjectParts = m_projectPartsStorage.fetchProjectParts( - toProjectPartIds(updateSystemProjectParts)); - - if (persistentProjectParts.size() > 0) { - mergeProjectParts(persistentProjectParts); - - updateSystemProjectParts = filterProjectParts(updateSystemProjectParts, - persistentProjectParts); - } - - if (updateSystemProjectParts.size()) { - m_projectPartsStorage.updateProjectParts(updateSystemProjectParts); - - mergeProjectParts(updateSystemProjectParts); - } - } - - auto upToDateProjectParts = filterProjectParts(projectsParts, updateSystemProjectParts); - - auto updates = checkDependeciesAndTime(std::move(upToDateProjectParts), - std::move(updateSystemProjectParts)); - - if (updates.updateSystem.size()) { - m_projectPartsStorage.resetIndexingTimeStamps(updates.updateSystem); - m_precompiledHeaderStorage.deleteSystemAndProjectPrecompiledHeaders( - toProjectPartIds(updates.updateSystem)); - } - if (updates.updateProject.size()) { - m_projectPartsStorage.resetIndexingTimeStamps(updates.updateProject); - m_precompiledHeaderStorage.deleteProjectPrecompiledHeaders( - toProjectPartIds(updates.updateProject)); - } - - return updates; -} - -ProjectPartsManagerInterface::UpToDataProjectParts ProjectPartsManager::checkDependeciesAndTime( - ProjectPartContainers &&upToDateProjectParts, ProjectPartContainers &&orignalUpdateSystemProjectParts) -{ - ProjectPartContainerReferences changeProjectParts; - changeProjectParts.reserve(upToDateProjectParts.size()); - - ProjectPartContainers updateProjectProjectParts; - updateProjectProjectParts.reserve(upToDateProjectParts.size()); - - ProjectPartContainers addedUpToDateSystemProjectParts; - addedUpToDateSystemProjectParts.reserve(upToDateProjectParts.size()); - - FilePathIds generatedFiles = m_generatedFiles.filePathIds(); - - std::vector watchedIdPaths; - watchedIdPaths.reserve(upToDateProjectParts.size() * 4); - - for (ProjectPartContainer &projectPart : upToDateProjectParts) { - auto oldSources = m_buildDependenciesProvider.createSourceEntriesFromStorage( - projectPart.sourcePathIds, projectPart.projectPartId); - - BuildDependency buildDependency = m_buildDependenciesProvider.create(projectPart, - Utils::clone(oldSources)); - - const auto &newSources = buildDependency.sources; - - Change change = Change::No; - - std::set_symmetric_difference(newSources.begin(), - newSources.end(), - oldSources.begin(), - oldSources.end(), - Utils::make_iterator([&](SourceEntry entry) { - change = changedSourceType(entry, change); - }), - [](SourceEntry first, SourceEntry second) { - return std::tie(first.sourceId, first.sourceType) - < std::tie(second.sourceId, second.sourceType); - }); - - switch (change) { - case Change::Project: - updateProjectProjectParts.emplace_back(std::move(projectPart)); - projectPart.projectPartId = -1; - break; - case Change::System: - addedUpToDateSystemProjectParts.emplace_back(std::move(projectPart)); - projectPart.projectPartId = -1; - break; - case Change::No: - break; - } - - if (change == Change::No) { - Change change = Utils::mismatch_collect( - newSources.begin(), - newSources.end(), - oldSources.begin(), - oldSources.end(), - Change::No, - [](SourceEntry first, SourceEntry second) { - return first.timeStamp > second.timeStamp; - }, - [](SourceEntry first, SourceEntry, Change change) { - return changedSourceType(first, change); - }); - - switch (change) { - case Change::Project: - updateProjectProjectParts.emplace_back(std::move(projectPart)); - projectPart.projectPartId = -1; - break; - case Change::System: - addedUpToDateSystemProjectParts.emplace_back(std::move(projectPart)); - projectPart.projectPartId = -1; - break; - case Change::No: - UsedMacroFilter usedMacroFilter{newSources, {}, {}}; - - watchedIdPaths.emplace_back(projectPart.projectPartId, - SourceType::Source, - existingSources(usedMacroFilter.sources, generatedFiles)); - watchedIdPaths.emplace_back(projectPart.projectPartId, - SourceType::UserInclude, - existingSources(usedMacroFilter.userIncludes, - generatedFiles)); - watchedIdPaths.emplace_back(projectPart.projectPartId, - SourceType::ProjectInclude, - existingSources(usedMacroFilter.projectIncludes, - generatedFiles)); - watchedIdPaths.emplace_back(projectPart.projectPartId, - SourceType::SystemInclude, - existingSources(usedMacroFilter.systemIncludes, - generatedFiles)); - break; - } - } - } - - if (watchedIdPaths.size()) - m_clangPathwatcher.updateIdPaths(watchedIdPaths); - - ProjectPartContainers updateSystemProjectParts; - updateSystemProjectParts.reserve(orignalUpdateSystemProjectParts.size() + addedUpToDateSystemProjectParts.size()); - - std::merge(std::make_move_iterator(orignalUpdateSystemProjectParts.begin()), - std::make_move_iterator(orignalUpdateSystemProjectParts.end()), - std::make_move_iterator(addedUpToDateSystemProjectParts.begin()), - std::make_move_iterator(addedUpToDateSystemProjectParts.end()), - std::back_inserter(updateSystemProjectParts)); - - upToDateProjectParts.erase(std::remove_if(upToDateProjectParts.begin(), - upToDateProjectParts.end(), - [](const ProjectPartContainer &projectPart) { - return !projectPart.projectPartId.isValid(); - }), - upToDateProjectParts.end()); - - return {std::move(upToDateProjectParts), - std::move(updateSystemProjectParts), - updateProjectProjectParts}; -} - -namespace { -ProjectPartContainers removed(ProjectPartContainers &&projectParts, - const ProjectPartIds &projectPartIds) -{ - ProjectPartContainers projectPartsWithoutIds; - - struct Compare - { - bool operator()(ProjectPartId first, const ProjectPartContainer &second) - { - return first < second.projectPartId; - } - - bool operator()(ProjectPartId first, const ProjectPartId &second) { return first < second; } - - bool operator()(const ProjectPartContainer &first, const ProjectPartContainer &second) - { - return first.projectPartId < second.projectPartId; - } - - bool operator()(const ProjectPartContainer &first, ProjectPartId second) - { - return first.projectPartId < second; - } - }; - - std::set_difference(std::make_move_iterator(projectParts.begin()), - std::make_move_iterator(projectParts.end()), - projectPartIds.begin(), - projectPartIds.end(), - std::back_inserter(projectPartsWithoutIds), - Compare{}); - - return projectPartsWithoutIds; -} -} // namespace - -void ProjectPartsManager::remove(const ProjectPartIds &projectPartIds) -{ - m_projectParts = removed(std::move(m_projectParts), projectPartIds); - m_systemDeferredProjectParts = removed(std::move(m_systemDeferredProjectParts), projectPartIds); - m_projectDeferredProjectParts = removed(std::move(m_projectDeferredProjectParts), projectPartIds); -} - -ProjectPartContainers ProjectPartsManager::projects(const ProjectPartIds &projectPartIds) const -{ - ProjectPartContainers projectPartsWithIds; - - struct Compare - { - bool operator()(ProjectPartId first, const ProjectPartContainer &second) - { - return first < second.projectPartId; - } - - bool operator()(ProjectPartId first, const ProjectPartId &second) { return first < second; } - - bool operator()(const ProjectPartContainer &first, const ProjectPartContainer &second) - { - return first.projectPartId < second.projectPartId; - } - - bool operator()(const ProjectPartContainer &first, ProjectPartId second) - { - return first.projectPartId < second; - } - }; - - std::set_intersection(m_projectParts.begin(), - m_projectParts.end(), - projectPartIds.begin(), - projectPartIds.end(), - std::back_inserter(projectPartsWithIds), - Compare{}); - - return projectPartsWithIds; -} - -namespace { -ProjectPartContainers merge(ProjectPartContainers &&newProjectParts, - ProjectPartContainers &&oldProjectParts) -{ - ProjectPartContainers mergedProjectParts; - mergedProjectParts.reserve(newProjectParts.size() + oldProjectParts.size()); - - std::set_union(std::make_move_iterator(newProjectParts.begin()), - std::make_move_iterator(newProjectParts.end()), - std::make_move_iterator(oldProjectParts.begin()), - std::make_move_iterator(oldProjectParts.end()), - std::back_inserter(mergedProjectParts), - [](const ProjectPartContainer &first, const ProjectPartContainer &second) { - return first.projectPartId < second.projectPartId; - }); - - return mergedProjectParts; -} -} // namespace - -void ProjectPartsManager::updateDeferred(ProjectPartContainers &&system, - ProjectPartContainers &&project) -{ - m_systemDeferredProjectParts = merge(std::move(system), std::move(m_systemDeferredProjectParts)); - m_projectDeferredProjectParts = merge(std::move(project), - std::move(m_projectDeferredProjectParts)); -} - -ProjectPartContainers ProjectPartsManager::deferredSystemUpdates() -{ - return std::move(m_systemDeferredProjectParts); -} - -ProjectPartContainers ProjectPartsManager::deferredProjectUpdates() -{ - return std::move(m_projectDeferredProjectParts); -} - -ProjectPartContainers ProjectPartsManager::filterProjectParts( - const ProjectPartContainers &projectsParts, const ProjectPartContainers &oldProjectParts) -{ - ProjectPartContainers updatedProjectPartContainers; - updatedProjectPartContainers.reserve(projectsParts.size()); - - std::set_difference(std::make_move_iterator(projectsParts.begin()), - std::make_move_iterator(projectsParts.end()), - oldProjectParts.begin(), - oldProjectParts.end(), - std::back_inserter(updatedProjectPartContainers)); - - return updatedProjectPartContainers; -} - -void ProjectPartsManager::mergeProjectParts(const ProjectPartContainers &projectsParts) -{ - ProjectPartContainers newProjectParts; - newProjectParts.reserve(m_projectParts.size() + projectsParts.size()); - - auto compare = [] (const ProjectPartContainer &first, const ProjectPartContainer &second) { - return first.projectPartId < second.projectPartId; - }; - - std::set_union(projectsParts.begin(), - projectsParts.end(), - m_projectParts.begin(), - m_projectParts.end(), - std::back_inserter(newProjectParts), - compare); - - m_projectParts = newProjectParts; -} - -const ProjectPartContainers &ProjectPartsManager::projectParts() const -{ - return m_projectParts; -} - -} // namespace Pch - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/projectpartsmanager.h b/src/tools/clangpchmanagerbackend/source/projectpartsmanager.h deleted file mode 100644 index 8e7de474298..00000000000 --- a/src/tools/clangpchmanagerbackend/source/projectpartsmanager.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangpchmanagerbackend_global.h" - -#include -#include -#include - -#include - -namespace ClangBackEnd { - -class BuildDependenciesProviderInterface; -class FilePathCachingInterface; -class GeneratedFilesInterface; -class ClangPathWatcherInterface; - -inline namespace Pch { - -class ProjectPartsManager final : public ProjectPartsManagerInterface -{ -public: - ProjectPartsManager(ProjectPartsStorageInterface &projectPartsStorage, - PrecompiledHeaderStorageInterface &precompiledHeaderStorage, - BuildDependenciesProviderInterface &buildDependenciesProvider, - FilePathCachingInterface &filePathCache, - ClangPathWatcherInterface &clangPathwatcher, - GeneratedFilesInterface &generatedFiles) - : m_projectPartsStorage(projectPartsStorage) - , m_precompiledHeaderStorage(precompiledHeaderStorage) - , m_buildDependenciesProvider(buildDependenciesProvider) - , m_filePathCache(filePathCache) - , m_clangPathwatcher(clangPathwatcher) - , m_generatedFiles(generatedFiles) - { - Q_UNUSED(m_filePathCache) - } - - UpToDataProjectParts update(ProjectPartContainers &&projectsParts) override; - void remove(const ProjectPartIds &projectPartIds) override; - ProjectPartContainers projects(const ProjectPartIds &projectPartIds) const override; - void updateDeferred(ProjectPartContainers &&system, ProjectPartContainers &&project) override; - ProjectPartContainers deferredSystemUpdates() override; - ProjectPartContainers deferredProjectUpdates() override; - - static ProjectPartContainers filterProjectParts(const ProjectPartContainers &newProjectsParts, - const ProjectPartContainers &oldProjectParts); - void mergeProjectParts(const ProjectPartContainers &projectsParts); - const ProjectPartContainers &projectParts() const; - UpToDataProjectParts checkDependeciesAndTime(ProjectPartContainers &&upToDateProjectParts, - ProjectPartContainers &&updateSystemProjectParts); - -private: - ProjectPartContainers m_projectParts; - ProjectPartContainers m_systemDeferredProjectParts; - ProjectPartContainers m_projectDeferredProjectParts; - ProjectPartsStorageInterface &m_projectPartsStorage; - PrecompiledHeaderStorageInterface &m_precompiledHeaderStorage; - BuildDependenciesProviderInterface &m_buildDependenciesProvider; - FilePathCachingInterface &m_filePathCache; - ClangPathWatcherInterface &m_clangPathwatcher; - GeneratedFilesInterface &m_generatedFiles; -}; - -} // namespace Pch - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/projectpartsmanagerinterface.h b/src/tools/clangpchmanagerbackend/source/projectpartsmanagerinterface.h deleted file mode 100644 index 696839c4b8d..00000000000 --- a/src/tools/clangpchmanagerbackend/source/projectpartsmanagerinterface.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include - -namespace ClangBackEnd { - -class ProjectPartsManagerInterface -{ -public: - class UpToDataProjectParts - { - public: - ProjectPartContainers upToDate; - ProjectPartContainers updateSystem; - ProjectPartContainers updateProject; - }; - - ProjectPartsManagerInterface() = default; - ProjectPartsManagerInterface(const ProjectPartsManagerInterface &) = delete; - ProjectPartsManagerInterface &operator=(const ProjectPartsManagerInterface &) = delete; - - virtual UpToDataProjectParts update(ProjectPartContainers &&projectsParts) = 0; - virtual void remove(const ProjectPartIds &projectPartIds) = 0; - virtual ProjectPartContainers projects(const ProjectPartIds &projectPartIds) const = 0; - virtual void updateDeferred(ProjectPartContainers &&system, ProjectPartContainers &&project) = 0; - virtual ProjectPartContainers deferredSystemUpdates() = 0; - virtual ProjectPartContainers deferredProjectUpdates() = 0; - -protected: - ~ProjectPartsManagerInterface() = default; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/queueinterface.h b/src/tools/clangpchmanagerbackend/source/queueinterface.h deleted file mode 100644 index d8ec0c69ed9..00000000000 --- a/src/tools/clangpchmanagerbackend/source/queueinterface.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -namespace ClangBackEnd { - -class QueueInterface -{ -public: - QueueInterface() = default; - QueueInterface(const QueueInterface &) = delete; - QueueInterface &operator=(const QueueInterface &) = delete; - - virtual void processEntries() = 0; - -protected: - ~QueueInterface() = default; -}; -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/taskscheduler.h b/src/tools/clangpchmanagerbackend/source/taskscheduler.h deleted file mode 100644 index 31d82ed2c4d..00000000000 --- a/src/tools/clangpchmanagerbackend/source/taskscheduler.h +++ /dev/null @@ -1,164 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "taskschedulerinterface.h" -#include "symbolindexertask.h" -#include "queueinterface.h" -#include "progresscounter.h" - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace Sqlite { -class TransactionInterface; -}; - -namespace ClangBackEnd { - -class FilePathCachingInterface; -class ProcessorManagerInterface; -class QueueInterface; -class SymbolStorageInterface; - -enum class CallDoInMainThreadAfterFinished : char { Yes, No }; - -template -class TaskScheduler : public TaskSchedulerInterface -{ -public: - using ProcessorInterface = typename ProcessorManager::Processor; - using Future = std::future; - - TaskScheduler(ProcessorManager &processorManager, - QueueInterface &queue, - ProgressCounter &progressCounter, - uint hardwareConcurrency, - CallDoInMainThreadAfterFinished callDoInMainThreadAfterFinished, - std::launch launchPolicy = std::launch::async) - : m_processorManager(processorManager) - , m_queue(queue) - , m_progressCounter(progressCounter) - , m_hardwareConcurrency(hardwareConcurrency) - , m_launchPolicy(launchPolicy) - , m_callDoInMainThreadAfterFinished(callDoInMainThreadAfterFinished) - {} - - ~TaskScheduler() - { - syncTasks(); - } - - void addTasks(std::vector &&tasks) - { - for (auto &task : tasks) { - auto callWrapper = [&, task = std::move(task)](auto processor) -> ProcessorInterface & { - task(processor.get()); - executeInLoop([&] { m_queue.processEntries(); }); - - return processor; - }; - m_futures.emplace_back(std::async(m_launchPolicy, - std::move(callWrapper), - std::ref(m_processorManager.unusedProcessor()))); - } - } - - const std::vector &futures() const - { - return m_futures; - } - - SlotUsage slotUsage() - { - removeFinishedFutures(); - - if (m_isDisabled) - return {}; - - return {uint(std::max(int(m_hardwareConcurrency) - int(m_futures.size()), 0)), - uint(m_futures.size())}; - } - - void syncTasks() - { - for (auto &future : m_futures) - future.wait(); - } - - void disable() - { - m_isDisabled = true; - } - -private: - void removeFinishedFutures() - { - auto notReady = [] (Future &future) { - return future.wait_for(std::chrono::duration::zero()) != std::future_status::ready; - }; - - auto split = std::partition(m_futures.begin(), m_futures.end(), notReady); - - std::for_each(split, m_futures.end(), [&] (Future &future) { - ProcessorInterface &processor = future.get(); - if (m_callDoInMainThreadAfterFinished == CallDoInMainThreadAfterFinished::Yes) - processor.doInMainThreadAfterFinished(); - processor.setIsUsed(false); - processor.clear(); - }); - - m_progressCounter.addProgress(std::distance(split, m_futures.end())); - - m_futures.erase(split, m_futures.end()); - } - -private: - std::vector m_futures; - ProcessorManager &m_processorManager; - QueueInterface &m_queue; - ProgressCounter &m_progressCounter; - uint m_hardwareConcurrency; - std::launch m_launchPolicy; - bool m_isDisabled = false; - CallDoInMainThreadAfterFinished m_callDoInMainThreadAfterFinished; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/taskschedulerinterface.h b/src/tools/clangpchmanagerbackend/source/taskschedulerinterface.h deleted file mode 100644 index a0835d3c633..00000000000 --- a/src/tools/clangpchmanagerbackend/source/taskschedulerinterface.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -namespace ClangBackEnd { - -using uint = unsigned int; - -struct SlotUsage -{ - SlotUsage() = default; - SlotUsage(uint free, uint used) - : free(free) - , used(used) - {} - uint free = 0; - uint used = 0; -}; - -template -class TaskSchedulerInterface -{ -public: - TaskSchedulerInterface() = default; - TaskSchedulerInterface(const TaskSchedulerInterface &) = delete; - TaskSchedulerInterface &operator=(const TaskSchedulerInterface &) = delete; - - virtual void addTasks(std::vector &&tasks) = 0; - virtual SlotUsage slotUsage() = 0; - -protected: - ~TaskSchedulerInterface() = default; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/toolchainargumentscache.h b/src/tools/clangpchmanagerbackend/source/toolchainargumentscache.h deleted file mode 100644 index d4d8a6479fb..00000000000 --- a/src/tools/clangpchmanagerbackend/source/toolchainargumentscache.h +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -#include - -#include - -namespace ClangBackEnd { - -struct ArgumentsEntry -{ - ArgumentsEntry(ProjectPartIds &&ids, const Utils::SmallStringVector &arguments) - : ids(std::move(ids)) - , arguments(arguments) - {} - - ArgumentsEntry(ProjectPartIds &ids, const Utils::SmallStringVector &arguments) - : ids(ids) - , arguments(arguments) - {} - - void mergeIds(ProjectPartIds &&newIds) - { - ProjectPartIds mergedIds; - mergedIds.reserve(ids.size() + newIds.size()); - - Utils::set_union(std::make_move_iterator(ids.begin()), - std::make_move_iterator(ids.end()), - std::make_move_iterator(newIds.begin()), - std::make_move_iterator(newIds.end()), - std::back_inserter(mergedIds)); - - ids = std::move(mergedIds); - } - - void removeIds(const ProjectPartIds &idsToBeRemoved) - { - ProjectPartIds idsWithout; - idsWithout.reserve(ids.size()); - std::set_difference(std::make_move_iterator(ids.begin()), - std::make_move_iterator(ids.end()), - idsToBeRemoved.begin(), - idsToBeRemoved.end(), - std::back_inserter(idsWithout)); - - ids = std::move(idsWithout); - } - - ProjectPartIds ids; - Utils::SmallStringVector arguments; -}; - -using ArgumentsEntries = std::vector; - -class ToolChainsArgumentsCache -{ -public: - void update(const ProjectPartContainers &projectParts, - const Utils::SmallStringVector &arguments) - { - struct Compare - { - bool operator()(const ArgumentsEntry &entry, const Utils::SmallStringVector &arguments) - { - return entry.arguments < arguments; - } - - bool operator()(const Utils::SmallStringVector &arguments, const ArgumentsEntry &entry) - { - return arguments < entry.arguments; - } - }; - - auto found = std::lower_bound(m_argumentEntries.begin(), - m_argumentEntries.end(), - arguments, - Compare{}); - - if (found != m_argumentEntries.end() && found->arguments == arguments) { - auto ids = createIds(projectParts); - auto removeIds = [&] (ArgumentsEntry &entry) { - entry.removeIds(ids); - }; - std::for_each(m_argumentEntries.begin(), found, removeIds); - std::for_each(std::next(found), m_argumentEntries.end(), removeIds); - found->mergeIds(std::move(ids)); - } else { - auto ids = createIds(projectParts); - for (ArgumentsEntry &entry : m_argumentEntries) - entry.removeIds(ids); - found = m_argumentEntries.emplace(found, std::move(ids), arguments); - } - - removeEmptyEntries(); - } - - void remove(const ProjectPartIds &idsToBeRemoved) - { - ArgumentsEntries entries; - for (ArgumentsEntry &entry : m_argumentEntries) { - ProjectPartIds usedIds; - std::set_difference(entry.ids.begin(), - entry.ids.end(), - idsToBeRemoved.begin(), - idsToBeRemoved.end(), - std::back_inserter(usedIds)); - - entry.ids = std::move(usedIds); - } - - removeEmptyEntries(); - } - - ArgumentsEntries arguments(const ProjectPartIds &ids) const - { - ArgumentsEntries entries; - for (const ArgumentsEntry &entry : m_argumentEntries) { - ProjectPartIds usedIds; - std::set_intersection(entry.ids.begin(), - entry.ids.end(), - ids.begin(), - ids.end(), - std::back_inserter(usedIds)); - - if (!usedIds.empty()) - entries.emplace_back(usedIds, entry.arguments); - } - - return entries; - } - - std::size_t size() const - { - return m_argumentEntries.size(); - } - -private: - static ProjectPartIds createIds(const ProjectPartContainers &projectParts) - { - ProjectPartIds ids; - ids.reserve(projectParts.size()); - for (const auto &projectPart : projectParts) - ids.emplace_back(projectPart.projectPartId); - - std::sort(ids.begin(), ids.end()); - - return ids; - } - - void removeEmptyEntries() - { - auto newEnd = std::remove_if(m_argumentEntries.begin(), - m_argumentEntries.end(), - [](const auto &entry) { return entry.ids.empty(); }); - - m_argumentEntries.erase(newEnd, m_argumentEntries.end()); - } - -private: - ArgumentsEntries m_argumentEntries; -}; - -} diff --git a/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h b/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h deleted file mode 100644 index 63bb503e75f..00000000000 --- a/src/tools/clangpchmanagerbackend/source/usedmacrofilter.h +++ /dev/null @@ -1,229 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "usedmacro.h" -#include "sourceentry.h" - -#include - -namespace ClangBackEnd { - -template -inline OutputIterator set_greedy_intersection(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - Compare comp) -{ - while (first1 != last1 && first2 != last2) - if (comp(*first1, *first2)) - ++first1; - else if (comp(*first2, *first1)) - ++first2; - else { - *result = *first1; - ++first1; - ++result; - } - return result; -} - -template -inline OutputIterator fill_with_second_values(InputIterator1 first1, - InputIterator1 last1, - InputIterator2 first2, - InputIterator2 last2, - OutputIterator result, - Compare comp) -{ - while (first1 != last1 && first2 != last2) - if (comp(*first1, *first2)) { - *result = *first1; - ++first1; - ++result; - } else if (comp(*first2, *first1)) - ++first2; - else { - *result = *first2; - ++first1; - ++result; - } - return result; -} - -class UsedMacroFilter -{ -public: - struct Includes - { - FilePathIds project; - FilePathIds system; - }; - - UsedMacroFilter(const SourceEntries &includes, - const UsedMacros &usedMacros, - const CompilerMacros &compilerMacros) { - filterSources(includes); - systemUsedMacros = filterUsedMarcos(usedMacros, systemIncludes); - projectUsedMacros = filterUsedMarcos(usedMacros, projectIncludes); - filter(compilerMacros); - } - - void filterSources(const SourceEntries &sources) { - systemIncludes.reserve(sources.size()); - projectIncludes.reserve(sources.size()); - topSystemIncludes.reserve(sources.size() / 10); - topProjectIncludes.reserve(sources.size() / 10); - userIncludes.reserve(sources.size()); - this->sources.reserve(sources.size()); - - for (SourceEntry source : sources) - filterSource(source); - } - - void filter(const CompilerMacros &compilerMacros) - { - CompilerMacros indexedCompilerMacro = compilerMacros; - - std::sort(indexedCompilerMacro.begin(), - indexedCompilerMacro.end(), - [](const CompilerMacro &first, const CompilerMacro &second) { - return std::tie(first.key, first.value) < std::tie(second.key, second.value); - }); - - systemCompilerMacros = filterCompilerMacros(indexedCompilerMacro, systemUsedMacros); - projectCompilerMacros = filterCompilerMacros(indexedCompilerMacro, projectUsedMacros); - } - -private: - void filterSource(SourceEntry source) { - if (source.hasMissingIncludes == HasMissingIncludes::Yes) - return; - - switch (source.sourceType) { - case SourceType::TopSystemInclude: - topSystemIncludes.emplace_back(source.sourceId); - systemIncludes.emplace_back(source.sourceId); - break; - case SourceType::SystemInclude: - systemIncludes.emplace_back(source.sourceId); - break; - case SourceType::TopProjectInclude: - topProjectIncludes.emplace_back(source.sourceId); - projectIncludes.emplace_back(source.sourceId); - break; - case SourceType::ProjectInclude: - projectIncludes.emplace_back(source.sourceId); - break; - case SourceType::UserInclude: - userIncludes.emplace_back(source.sourceId); - break; - case SourceType::Source: - sources.emplace_back(source.sourceId); - break; - } - - } - - static Utils::SmallStringVector filterUsedMarcos(const UsedMacros &usedMacros, - const FilePathIds &filePathId) - { - struct Compare - { - bool operator()(const UsedMacro &usedMacro, FilePathId filePathId) - { - return usedMacro.filePathId < filePathId; - } - - bool operator()(FilePathId filePathId, const UsedMacro &usedMacro) - { - return filePathId < usedMacro.filePathId; - } - }; - - Utils::SmallStringVector filtertedMacros; - filtertedMacros.reserve(usedMacros.size()); - - set_greedy_intersection(usedMacros.begin(), - usedMacros.end(), - filePathId.begin(), - filePathId.end(), - std::back_inserter(filtertedMacros), - Compare{}); - - std::sort(filtertedMacros.begin(), filtertedMacros.end()); - - auto newEnd = std::unique(filtertedMacros.begin(), filtertedMacros.end()); - filtertedMacros.erase(newEnd, filtertedMacros.end()); - - return filtertedMacros; - } - - static CompilerMacros filterCompilerMacros(const CompilerMacros &indexedCompilerMacro, - const Utils::SmallStringVector &usedMacros) - { - CompilerMacros filtertedCompilerMacros; - filtertedCompilerMacros.reserve(usedMacros.size()); - - struct Compare - { - bool operator()(const CompilerMacro &compilerMacro, Utils::SmallStringView usedMacro) - { - return compilerMacro.key < usedMacro; - } - - bool operator()(Utils::SmallStringView usedMacro, const CompilerMacro &compilerMacro) - { - return usedMacro < compilerMacro.key; - } - }; - - fill_with_second_values(usedMacros.begin(), - usedMacros.end(), - indexedCompilerMacro.begin(), - indexedCompilerMacro.end(), - std::back_inserter(filtertedCompilerMacros), - Compare{}); - - return filtertedCompilerMacros; - } - -public: - FilePathIds sources; - FilePathIds userIncludes; - FilePathIds projectIncludes; - FilePathIds systemIncludes; - FilePathIds topProjectIncludes; - FilePathIds topSystemIncludes; - Utils::SmallStringVector projectUsedMacros; - Utils::SmallStringVector systemUsedMacros; - CompilerMacros projectCompilerMacros; - CompilerMacros systemCompilerMacros; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.cpp b/src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.cpp deleted file mode 100644 index 770d46f5e14..00000000000 --- a/src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "usedmacrosandsourcescollector.h" - -#include "collectusedmacroactionfactory.h" - -namespace ClangBackEnd { - -void UsedMacroAndSourcesCollector::addFiles(const FilePathIds &filePathIds, - const Utils::SmallStringVector &arguments) -{ - m_clangTool.addFiles(m_filePathCache.filePaths(filePathIds), arguments); - m_sourceFiles.insert(m_sourceFiles.end(), filePathIds.begin(), filePathIds.end()); -} - -void UsedMacroAndSourcesCollector::addFile(FilePathId filePathId, const Utils::SmallStringVector &arguments) -{ - addFiles({filePathId}, arguments); -} - -void UsedMacroAndSourcesCollector::collect() -{ - clang::tooling::ClangTool tool = m_clangTool.createTool(); - - auto action = std::make_unique( - m_usedMacros, - m_filePathCache, - m_sourceDependencies, - m_sourceFiles, - m_fileStatuses); - - tool.run(action.get()); -} - -void UsedMacroAndSourcesCollector::clear() -{ - m_clangTool = ClangTool(); - m_usedMacros.clear(); - m_sourceFiles.clear(); - m_fileStatuses.clear(); - m_sourceDependencies.clear(); -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.h b/src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.h deleted file mode 100644 index 9b72201fbb6..00000000000 --- a/src/tools/clangpchmanagerbackend/source/usedmacrosandsourcescollector.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include -#include -#include -#include -#include - -#include - -namespace ClangBackEnd { - -class UsedMacroAndSourcesCollector -{ -public: - UsedMacroAndSourcesCollector(FilePathCachingInterface &filePathCache) - : m_filePathCache(filePathCache) - { - } - - void addFiles(const FilePathIds &filePathIds, - const Utils::SmallStringVector &arguments); - void addFile(FilePathId filePathId, - const Utils::SmallStringVector &arguments); - - void collect(); - - void clear(); - - const FileStatuses &fileStatuses() const - { - return m_fileStatuses; - } - - const FilePathIds &sourceFiles() const - { - return m_sourceFiles; - } - - const UsedMacros &usedMacros() const - { - return m_usedMacros; - } - - const SourceDependencies &sourceDependencies() const - { - return m_sourceDependencies; - } - -private: - ClangTool m_clangTool; - UsedMacros m_usedMacros; - FilePathCachingInterface &m_filePathCache; - FilePathIds m_sourceFiles; - SourceDependencies m_sourceDependencies; - FileStatuses m_fileStatuses; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/CMakeLists.txt b/src/tools/clangrefactoringbackend/CMakeLists.txt deleted file mode 100644 index c368923d8f6..00000000000 --- a/src/tools/clangrefactoringbackend/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -add_subdirectory(source) - -add_qtc_executable(clangrefactoringbackend - CONDITION TARGET ClangRefactoring - DEPENDS - clangrefactoringbackend_lib Sqlite ClangSupport - SOURCES - clangrefactoringbackendmain.cpp -) diff --git a/src/tools/clangrefactoringbackend/clangrefactoringbackend.pro b/src/tools/clangrefactoringbackend/clangrefactoringbackend.pro deleted file mode 100644 index 630afdf6189..00000000000 --- a/src/tools/clangrefactoringbackend/clangrefactoringbackend.pro +++ /dev/null @@ -1,26 +0,0 @@ -QTC_LIB_DEPENDS += \ - clangsupport - -include(../../qtcreatortool.pri) -include(../../shared/clang/clang_installation.pri) -include(source/clangrefactoringbackend-source.pri) - -requires(!isEmpty(LIBTOOLING_LIBS)) - -win32 { - LLVM_BUILDMODE = $$system($$llvm_config --build-mode, lines) - CONFIG(debug, debug|release):requires(equals(LLVM_BUILDMODE, "Debug")) -} - -QT += core network -QT -= gui - -LIBS += $$LIBTOOLING_LIBS -INCLUDEPATH += $$LLVM_INCLUDEPATH -INCLUDEPATH += ../clangpchmanagerbackend/source - -QMAKE_CXXFLAGS_WARN_ON *= $$LLVM_CXXFLAGS_WARNINGS -QMAKE_CXXFLAGS *= $$LLVM_CXXFLAGS - -SOURCES += \ - clangrefactoringbackendmain.cpp diff --git a/src/tools/clangrefactoringbackend/clangrefactoringbackend.qbs b/src/tools/clangrefactoringbackend/clangrefactoringbackend.qbs deleted file mode 100644 index f7a9745e176..00000000000 --- a/src/tools/clangrefactoringbackend/clangrefactoringbackend.qbs +++ /dev/null @@ -1,40 +0,0 @@ -import qbs -import qbs.FileInfo - -QtcTool { - name: "clangrefactoringbackend" - Depends { name: "libclang"; required: false } - condition: libclang.present - && libclang.toolingEnabled - && (!qbs.targetOS.contains("windows") || libclang.llvmBuildModeMatches) - - Depends { name: "ClangSupport" } - - Depends { name: "Qt.network" } - - cpp.cxxFlags: base.concat(libclang.llvmToolingCxxFlags) - cpp.defines: base.concat(libclang.llvmToolingDefines) - cpp.includePaths: base.concat(libclang.llvmIncludeDir) - .concat(libclang.llvmToolingIncludes) - .concat(["source"]) - .concat(["../clangpchmanagerbackend/source"]) - cpp.libraryPaths: base.concat(libclang.llvmLibDir) - cpp.dynamicLibraries: base.concat(libclang.llvmToolingLibs) - - Properties { - condition: qbs.targetOS.contains("unix") && !qbs.targetOS.contains("macos") - cpp.rpaths: base.concat(libclang.llvmLibDir) - } - - files: [ - "clangrefactoringbackendmain.cpp", - ] - - Group { - prefix: "source/" - files: [ - "*.cpp", - "*.h", - ] - } -} diff --git a/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp b/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp deleted file mode 100644 index df70d4efe77..00000000000 --- a/src/tools/clangrefactoringbackend/clangrefactoringbackendmain.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -using namespace std::chrono_literals; - -using ClangBackEnd::FilePathCaching; -using ClangBackEnd::GeneratedFiles; -using ClangBackEnd::RefactoringClientProxy; -using ClangBackEnd::RefactoringServer; -using ClangBackEnd::RefactoringDatabaseInitializer; -using ClangBackEnd::ConnectionServer; -using ClangBackEnd::SymbolIndexing; - -QStringList processArguments(QCoreApplication &application) -{ - QCommandLineParser parser; - parser.setApplicationDescription(QStringLiteral("Qt Creator Clang Refactoring Backend")); - parser.addHelpOption(); - parser.addVersionOption(); - parser.addPositionalArgument(QStringLiteral("connection"), QStringLiteral("Connection")); - parser.addPositionalArgument(QStringLiteral("databasepath"), QStringLiteral("Database path")); - parser.addPositionalArgument(QStringLiteral("resourcepath"), QStringLiteral("Resource path")); - - parser.process(application); - - if (parser.positionalArguments().isEmpty()) - parser.showHelp(1); - - return parser.positionalArguments(); -} - -class RefactoringApplication : public QCoreApplication -{ -public: - using QCoreApplication::QCoreApplication; - - bool notify(QObject *object, QEvent *event) override - { - try { - return QCoreApplication::notify(object, event); - } catch (Sqlite::Exception &exception) { - exception.printWarning(); - } - - return false; - } -}; - -class ApplicationEnvironment final : public ClangBackEnd::Environment -{ -public: - ApplicationEnvironment(const QString &preIncludeSearchPath) - : m_preIncludeSearchPath(ClangBackEnd::FilePath{preIncludeSearchPath}) - {} - - Utils::PathString pchBuildDirectory() const override { return {}; } - uint hardwareConcurrency() const override { return std::thread::hardware_concurrency(); } - ClangBackEnd::NativeFilePathView preIncludeSearchPath() const override - { - return m_preIncludeSearchPath; - } - -private: - ClangBackEnd::NativeFilePath m_preIncludeSearchPath; -}; - -struct Data // because we have a cycle dependency -{ - Data(const QString &databasePath, const QString &preIncludeSearchPath) - : environment{preIncludeSearchPath} - , database{Utils::PathString{databasePath}, 100000ms} - {} - - ApplicationEnvironment environment; - Sqlite::Database database; - RefactoringDatabaseInitializer databaseInitializer{database}; - FilePathCaching filePathCache{database}; - GeneratedFiles generatedFiles; - RefactoringServer clangCodeModelServer{symbolIndexing, filePathCache, generatedFiles}; - SymbolIndexing symbolIndexing{database, - filePathCache, - generatedFiles, - [&](int progress, int total) { - executeInLoop([&] { - clangCodeModelServer.setProgress(progress, total); - }); - }, - environment}; -}; - -#ifdef Q_OS_WIN -extern "C" void __stdcall OutputDebugStringW(const wchar_t* msg); -static void messageOutput(QtMsgType type, const QMessageLogContext &, const QString &msg) -{ - OutputDebugStringW(msg.toStdWString().c_str()); - std::wcout << msg.toStdWString() << std::endl; - if (type == QtFatalMsg) - abort(); -} -#endif - -int main(int argc, char *argv[]) -{ -#ifdef Q_OS_WIN - qInstallMessageHandler(messageOutput); -#endif - try { - QCoreApplication::setOrganizationName(QStringLiteral("QtProject")); - QCoreApplication::setOrganizationDomain(QStringLiteral("qt-project.org")); - QCoreApplication::setApplicationName(QStringLiteral("ClangRefactoringBackend")); - QCoreApplication::setApplicationVersion(QStringLiteral("0.1.0")); - - RefactoringApplication application(argc, argv); - - const QStringList arguments = processArguments(application); - const QString connectionName = arguments[0]; - const QString databasePath = arguments[1]; - const QString preIncludeSearchPath = arguments[2] + "/indexer_preincludes"; - - Data data{databasePath, preIncludeSearchPath}; - - ConnectionServer connectionServer; - connectionServer.setServer(&data.clangCodeModelServer); - connectionServer.start(connectionName); - - return application.exec(); - } catch (const Sqlite::Exception &exception) { - exception.printWarning(); - } -} - - diff --git a/src/tools/clangrefactoringbackend/source/CMakeLists.txt b/src/tools/clangrefactoringbackend/source/CMakeLists.txt deleted file mode 100644 index b7f266bd845..00000000000 --- a/src/tools/clangrefactoringbackend/source/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -add_qtc_library(clangrefactoringbackend_lib STATIC - CONDITION WITH_TESTS OR TARGET ClangRefactoring OR TARGET ClangPchManager - PUBLIC_DEPENDS - Threads::Threads - ${CLANG_TOOLING_LIBS} - Qt5::Widgets # FIXME: change the way to get the gui pch to linkto - INCLUDES - $ - PUBLIC_INCLUDES - ${CLANG_INCLUDE_DIRS} - ../../clangpchmanagerbackend/source - "${CMAKE_CURRENT_LIST_DIR}" - SOURCES - clangquery.cpp clangquery.h - clangquerygatherer.cpp clangquerygatherer.h - clangrefactoringbackend_global.h - clangtool.cpp clangtool.h - collectmacrospreprocessorcallbacks.h - collectmacrossourcefilecallbacks.cpp collectmacrossourcefilecallbacks.h - collectsymbolsaction.cpp collectsymbolsaction.h - indexdataconsumer.cpp indexdataconsumer.h - locationsourcefilecallbacks.cpp locationsourcefilecallbacks.h - macropreprocessorcallbacks.cpp macropreprocessorcallbacks.h - projectpartentry.h - refactoringcompilationdatabase.cpp refactoringcompilationdatabase.h - refactoringserver.cpp refactoringserver.h - sourcedependency.h - sourcelocationentry.h - sourcelocationsutils.h - sourcerangeextractor.cpp sourcerangeextractor.h - sourcerangefilter.cpp sourcerangefilter.h - sourcesmanager.h - symbolentry.h - symbolindexer.cpp symbolindexer.h - symbolindexertask.h - symbolindexertaskqueue.h - symbolindexertaskqueueinterface.h - symbolindexing.cpp symbolindexing.h - symbolindexinginterface.h - symbolscollector.cpp symbolscollector.h - symbolscollectorinterface.h - symbolstorage.h - symbolstorageinterface.h - symbolsvisitorbase.h - usedmacro.h -) diff --git a/src/tools/clangrefactoringbackend/source/clangquery.cpp b/src/tools/clangrefactoringbackend/source/clangquery.cpp deleted file mode 100644 index 78f2350d8de..00000000000 --- a/src/tools/clangrefactoringbackend/source/clangquery.cpp +++ /dev/null @@ -1,227 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "clangquery.h" - -#include "sourcelocationsutils.h" -#include "sourcerangeextractor.h" - -#include - -#include - -#include - -#include -#include -#include -#include - -using clang::ast_matchers::dynamic::Diagnostics; -using clang::ast_matchers::dynamic::Parser; -using clang::ast_matchers::BoundNodes; -using clang::ast_matchers::MatchFinder; - -namespace ClangBackEnd { - -struct CollectBoundNodes : MatchFinder::MatchCallback { - std::vector &Bindings; - CollectBoundNodes(std::vector &Bindings) : Bindings(Bindings) {} - void run(const MatchFinder::MatchResult &Result) override { - Bindings.push_back(Result.Nodes); - } -}; - -ClangQuery::ClangQuery(FilePathCachingInterface &filePathCache, - Utils::SmallString &&query) - : m_query(std::move(query)), - m_filePathCache(filePathCache) -{ -} - -void ClangQuery::setQuery(Utils::SmallString &&query) -{ - this->m_query = std::move(query); -} - -void ClangQuery::findLocations() -{ - auto tool = createTool(); - - std::vector> asts; - - tool.buildASTs(asts); - - std::for_each (std::make_move_iterator(asts.begin()), - std::make_move_iterator(asts.end()), - [&] (std::unique_ptr &&ast) { - Diagnostics diagnostics; - llvm::StringRef query{m_query.data(), m_query.size()}; - auto optionalMatcher = Parser::parseMatcherExpression(query, - nullptr, - &diagnostics); - parseDiagnostics(diagnostics); - matchLocation(optionalMatcher, std::move(ast)); - }); -} - - -SourceRangesContainer ClangQuery::takeSourceRanges() -{ - return std::move(m_sourceRangesContainer); -} - -DynamicASTMatcherDiagnosticContainers ClangQuery::takeDiagnosticContainers() -{ - return std::move(m_diagnosticContainers_); -} - -namespace { - -V2::SourceRangeContainer convertToContainer(const clang::ast_matchers::dynamic::SourceRange sourceRange) -{ - return V2::SourceRangeContainer(0, - sourceRange.Start.Line, - sourceRange.Start.Column, - 0, - sourceRange.End.Line, - sourceRange.End.Column, - 0); -} - -#define ERROR_RETURN_CASE(name) \ - case Diagnostics::ET_##name: return ClangQueryDiagnosticErrorType::name; - -ClangQueryDiagnosticErrorType convertToErrorType(Diagnostics::ErrorType clangErrorType) -{ - switch (clangErrorType) { - ERROR_RETURN_CASE(None) - ERROR_RETURN_CASE(RegistryMatcherNotFound) - ERROR_RETURN_CASE(RegistryWrongArgCount) - ERROR_RETURN_CASE(RegistryWrongArgType) - ERROR_RETURN_CASE(RegistryNotBindable) - ERROR_RETURN_CASE(RegistryAmbiguousOverload) - ERROR_RETURN_CASE(RegistryValueNotFound) - ERROR_RETURN_CASE(ParserStringError) - ERROR_RETURN_CASE(ParserNoOpenParen) - ERROR_RETURN_CASE(ParserNoCloseParen) - ERROR_RETURN_CASE(ParserNoComma) - ERROR_RETURN_CASE(ParserNoCode) - ERROR_RETURN_CASE(ParserNotAMatcher) - ERROR_RETURN_CASE(ParserInvalidToken) - ERROR_RETURN_CASE(ParserMalformedBindExpr) - ERROR_RETURN_CASE(ParserTrailingCode) - ERROR_RETURN_CASE(ParserNumberError) - ERROR_RETURN_CASE(ParserOverloadedType) - } - - Q_UNREACHABLE(); -} - -#define CONTEXT_RETURN_CASE(name) \ - case Diagnostics::CT_##name: return ClangQueryDiagnosticContextType::name; - -ClangQueryDiagnosticContextType convertToContextType(Diagnostics::ContextType clangContextType) -{ - switch (clangContextType) { - CONTEXT_RETURN_CASE(MatcherArg) - CONTEXT_RETURN_CASE(MatcherConstruct) - } - - Q_UNREACHABLE(); -} - -} - -void ClangQuery::parseDiagnostics(const clang::ast_matchers::dynamic::Diagnostics &diagnostics) -{ - auto errors = diagnostics.errors(); - - for (const auto &errorContent : errors) { - m_diagnosticContainers_.emplace_back(); - DynamicASTMatcherDiagnosticContainer &diagnosticContainer = m_diagnosticContainers_.back(); - - for (const auto &message : errorContent.Messages) { - diagnosticContainer.insertMessage(convertToContainer(message.Range), - convertToErrorType(message.Type), - Utils::SmallStringVector(message.Args)); - } - - for (const auto &message : errorContent.ContextStack) { - diagnosticContainer.insertContext(convertToContainer(message.Range), - convertToContextType(message.Type), - Utils::SmallStringVector(message.Args)); - } - } -} - -namespace { -std::vector generateSourceRangesFromMatches(const std::vector &matches) -{ - std::vector sourceRanges; - sourceRanges.reserve(matches.size()); - - for (const auto boundNodes : matches) { - for (const auto &mapEntry : boundNodes.getMap()) { - const auto sourceRange = mapEntry.second.getSourceRange(); - if (sourceRange.isValid()) - sourceRanges.push_back(sourceRange); - } - - } - - return sourceRanges; -} -} - -void ClangQuery::matchLocation( - const llvm::Optional< clang::ast_matchers::internal::DynTypedMatcher> &optionalStartMatcher, - std::unique_ptr ast) -{ - if (optionalStartMatcher) { - auto matcher = *optionalStartMatcher; - auto optionalMatcher = matcher.tryBind("root"); - matcher = *optionalMatcher; - - MatchFinder finder; - std::vector matches; - CollectBoundNodes collectBoundNodes(matches); - - finder.addDynamicMatcher(matcher, &collectBoundNodes); - - finder.matchAST(ast->getASTContext()); - - auto sourceRanges = generateSourceRangesFromMatches(matches); - - SourceRangeExtractor extractor(ast->getSourceManager(), - ast->getLangOpts(), - m_filePathCache, - m_sourceRangesContainer); - extractor.addSourceRanges(sourceRanges); - - } -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/clangquery.h b/src/tools/clangrefactoringbackend/source/clangquery.h deleted file mode 100644 index daccd8335e4..00000000000 --- a/src/tools/clangrefactoringbackend/source/clangquery.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangtool.h" - -#include -#include - -#include - -namespace clang { -namespace ast_matchers { -namespace dynamic { -class Diagnostics; -} - -namespace internal { -class DynTypedMatcher; -} -} - -class SourceManager; -} - -namespace ClangBackEnd { - -class ClangQuery : public ClangTool -{ -public: - ClangQuery(FilePathCachingInterface &m_filePathCache, Utils::SmallString &&m_query={}); - - void setQuery(Utils::SmallString &&m_query); - - void findLocations(); - - SourceRangesContainer takeSourceRanges(); - DynamicASTMatcherDiagnosticContainers takeDiagnosticContainers(); - -private: - void parseDiagnostics(const clang::ast_matchers::dynamic::Diagnostics &diagnostics); - void matchLocation(const llvm::Optional< clang::ast_matchers::internal::DynTypedMatcher> &optionalStartMatcher, - std::unique_ptr ast); - -private: - SourceRangesContainer m_sourceRangesContainer; - Utils::SmallString m_query; - std::vector m_diagnosticContainers_; - ClangBackEnd::FilePathCachingInterface &m_filePathCache; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/clangquerygatherer.cpp b/src/tools/clangrefactoringbackend/source/clangquerygatherer.cpp deleted file mode 100644 index 42fb7d88bc2..00000000000 --- a/src/tools/clangrefactoringbackend/source/clangquerygatherer.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "clangquerygatherer.h" - -#include "clangquery.h" - -namespace ClangBackEnd { - -ClangQueryGatherer::ClangQueryGatherer(FilePathCachingInterface *filePathCache, - std::vector &&sources, - std::vector &&unsaved, - Utils::SmallString &&query) - : m_filePathCache(filePathCache), - m_sourceRangeFilter(sources.size()), - m_sources(std::move(sources)), - m_unsaved(std::move(unsaved)), - m_query(std::move(query)) -{ -} - -SourceRangesForQueryMessage -ClangQueryGatherer::createSourceRangesForSource( - FilePathCachingInterface *filePathCache, - V2::FileContainer &&source, - const std::vector &unsaved, - Utils::SmallString &&query) -{ - ClangQuery clangQuery(*filePathCache, std::move(query)); - - clangQuery.addFile(std::move(source.filePath), - std::move(source.unsavedFileContent), - std::move(source.commandLineArguments)); - - clangQuery.addUnsavedFiles(unsaved); - - clangQuery.findLocations(); - - return {clangQuery.takeSourceRanges()}; -} - -bool ClangQueryGatherer::canCreateSourceRanges() const -{ - return !m_sources.empty(); -} - -SourceRangesForQueryMessage ClangQueryGatherer::createNextSourceRanges() -{ - auto message = createSourceRangesForSource(m_filePathCache, - std::move(m_sources.back()), - m_unsaved, - m_query.clone()); - m_sources.pop_back(); - - return message; -} - -ClangQueryGatherer::Future ClangQueryGatherer::startCreateNextSourceRangesMessage() -{ - Future future = std::async(std::launch::async, - createSourceRangesForSource, - m_filePathCache, - std::move(m_sources.back()), - m_unsaved, - m_query.clone()); - - m_sources.pop_back(); - - return future; -} - -void ClangQueryGatherer::startCreateNextSourceRangesMessages() -{ - std::vector futures; - - while (!m_sources.empty() && m_sourceFutures.size() < m_processingSlotCount) - m_sourceFutures.push_back(startCreateNextSourceRangesMessage()); -} - -void ClangQueryGatherer::waitForFinished() -{ - for (Future &future : m_sourceFutures) - future.wait(); -} - -bool ClangQueryGatherer::isFinished() const -{ - return m_sources.empty() && m_sourceFutures.empty(); -} - -const std::vector &ClangQueryGatherer::sources() const -{ - return m_sources; -} - -const std::vector &ClangQueryGatherer::sourceFutures() const -{ - return m_sourceFutures; -} - -std::vector ClangQueryGatherer::allCurrentProcessedMessages() -{ - std::vector messages; - - for (Future &future : m_sourceFutures) - messages.push_back(m_sourceRangeFilter.removeDuplicates(future.get())); - - return messages; -} - -std::vector ClangQueryGatherer::finishedMessages() -{ - std::vector messages; - - for (auto &&future : finishedFutures()) - messages.push_back(m_sourceRangeFilter.removeDuplicates(future.get())); - - return messages; -} - -void ClangQueryGatherer::setProcessingSlotCount(uint count) -{ - m_processingSlotCount = count; -} - -std::vector ClangQueryGatherer::finishedFutures() -{ - std::vector finishedFutures; - finishedFutures.reserve(m_sourceFutures.size()); - - auto beginReady = std::partition(m_sourceFutures.begin(), - m_sourceFutures.end(), - [] (const Future &future) { - return future.wait_for(std::chrono::duration::zero()) != std::future_status::ready; - }); - - std::move(beginReady, m_sourceFutures.end(), std::back_inserter(finishedFutures)); - m_sourceFutures.erase(beginReady, m_sourceFutures.end()); - - return finishedFutures; -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/clangquerygatherer.h b/src/tools/clangrefactoringbackend/source/clangquerygatherer.h deleted file mode 100644 index f0e0e181f25..00000000000 --- a/src/tools/clangrefactoringbackend/source/clangquerygatherer.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "sourcerangefilter.h" - -#include -#include -#include - -#include - -namespace ClangBackEnd { - -class ClangQueryGatherer -{ -public: - using Future = std::future; - - ClangQueryGatherer() = default; - ClangQueryGatherer(FilePathCachingInterface *filePathCache, - std::vector &&sources, - std::vector &&unsaved, - Utils::SmallString &&query); - - static SourceRangesForQueryMessage createSourceRangesForSource( - FilePathCachingInterface *filePathCache, - V2::FileContainer &&source, - const std::vector &unsaved, - Utils::SmallString &&query); - bool canCreateSourceRanges() const; - SourceRangesForQueryMessage createNextSourceRanges(); - Future startCreateNextSourceRangesMessage(); - void startCreateNextSourceRangesMessages(); - void waitForFinished(); - bool isFinished() const; - - const std::vector &sources() const; - const std::vector &sourceFutures() const; - std::vector allCurrentProcessedMessages(); - std::vector finishedMessages(); - - void setProcessingSlotCount(uint count); - -protected: - std::vector finishedFutures(); - -private: - FilePathCachingInterface *m_filePathCache = nullptr; - SourceRangeFilter m_sourceRangeFilter; - std::vector m_sources; - std::vector m_unsaved; - Utils::SmallString m_query; - uint m_processingSlotCount = 1; - std::vector m_sourceFutures; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri b/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri deleted file mode 100644 index 407621b4be6..00000000000 --- a/src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri +++ /dev/null @@ -1,58 +0,0 @@ -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/clangrefactoringbackend_global.h \ - $$PWD/sourcerangefilter.h \ - $$PWD/symbolindexer.h \ - $$PWD/symbolentry.h \ - $$PWD/sourcelocationentry.h \ - $$PWD/symbolscollectorinterface.h \ - $$PWD/symbolstorageinterface.h \ - $$PWD/symbolstorage.h \ - $$PWD/symbolindexing.h \ - $$PWD/symbolindexinginterface.h \ - $$PWD/collectmacrospreprocessorcallbacks.h \ - $$PWD/projectpartentry.h \ - $$PWD/usedmacro.h \ - $$PWD/sourcedependency.h \ - $$PWD/sourcesmanager.h \ - $$PWD/symbolindexertaskqueue.h \ - $$PWD/symbolindexertaskqueueinterface.h \ - $$PWD/symbolindexertask.h - -!isEmpty(LIBTOOLING_LIBS) { -SOURCES += \ - $$PWD/refactoringcompilationdatabase.cpp \ - $$PWD/refactoringserver.cpp \ - $$PWD/macropreprocessorcallbacks.cpp \ - $$PWD/clangquery.cpp \ - $$PWD/clangtool.cpp \ - $$PWD/sourcerangeextractor.cpp \ - $$PWD/locationsourcefilecallbacks.cpp \ - $$PWD/collectsymbolsaction.cpp \ - $$PWD/collectmacrossourcefilecallbacks.cpp \ - $$PWD/symbolscollector.cpp \ - $$PWD/clangquerygatherer.cpp \ - $$PWD/symbolindexing.cpp \ - $$PWD/indexdataconsumer.cpp - -HEADERS += \ - $$PWD/refactoringcompilationdatabase.h \ - $$PWD/refactoringserver.h \ - $$PWD/macropreprocessorcallbacks.h \ - $$PWD/sourcelocationsutils.h \ - $$PWD/clangquery.h \ - $$PWD/clangtool.h \ - $$PWD/sourcerangeextractor.h \ - $$PWD/locationsourcefilecallbacks.h \ - $$PWD/collectsymbolsaction.h \ - $$PWD/collectmacrossourcefilecallbacks.h \ - $$PWD/symbolscollector.h \ - $$PWD/symbolsvisitorbase.h \ - $$PWD/indexdataconsumer.h \ - $$PWD/clangquerygatherer.h -} - -SOURCES += \ - $$PWD/sourcerangefilter.cpp \ - $$PWD/symbolindexer.cpp diff --git a/src/tools/clangrefactoringbackend/source/clangrefactoringbackend_global.h b/src/tools/clangrefactoringbackend/source/clangrefactoringbackend_global.h deleted file mode 100644 index 49796ef7b9d..00000000000 --- a/src/tools/clangrefactoringbackend/source/clangrefactoringbackend_global.h +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include - -namespace llvm { -template -class SmallVector; -} - -namespace ClangBackEnd { - -using USRName = llvm::SmallVector; - -// use std::filesystem::path if it is supported by all compilers - -static const char nativeSeparator = Utils::HostOsInfo::isWindowsHost() ? '\\' : '/'; - -} diff --git a/src/tools/clangrefactoringbackend/source/clangtool.cpp b/src/tools/clangrefactoringbackend/source/clangtool.cpp deleted file mode 100644 index 34c6b02c64b..00000000000 --- a/src/tools/clangrefactoringbackend/source/clangtool.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "clangtool.h" - -#include - -#include - -namespace ClangBackEnd { - -void ClangTool::addFile(FilePath &&filePath, - Utils::SmallString &&content, - Utils::SmallStringVector &&commandLine) -{ - NativeFilePath nativeFilePath{filePath}; - - if (commandLine.back() != nativeFilePath.path()) - commandLine.emplace_back(nativeFilePath.path()); - - m_compilationDatabase.addFile(nativeFilePath, std::move(commandLine)); - m_sourceFilePaths.push_back(Utils::SmallStringView{nativeFilePath}); - - m_fileContents.emplace_back(std::move(nativeFilePath), std::move(content)); -} - -void ClangTool::addFiles(const FilePaths &filePaths, const Utils::SmallStringVector &arguments) -{ - for (const FilePath &filePath : filePaths) - addFile(filePath.clone(), {}, arguments.clone()); -} - -void ClangTool::addUnsavedFiles(const V2::FileContainers &unsavedFiles) -{ - m_unsavedFileContents.reserve(m_unsavedFileContents.size() + unsavedFiles.size()); - - auto convertToUnsavedFileContent = [](const V2::FileContainer &unsavedFile) { - return UnsavedFileContent{NativeFilePath{unsavedFile.filePath}, - unsavedFile.unsavedFileContent.clone()}; - }; - - std::transform(unsavedFiles.begin(), - unsavedFiles.end(), - std::back_inserter(m_unsavedFileContents), - convertToUnsavedFileContent); -} - -namespace { -template -llvm::StringRef toStringRef(const String &string) -{ - return llvm::StringRef(string.data(), string.size()); -} - -llvm::StringRef toStringRef(const NativeFilePath &path) -{ - return llvm::StringRef(path.path().data(), path.path().size()); -} -} // namespace - -clang::tooling::ClangTool ClangTool::createTool() const -{ - clang::tooling::ClangTool tool(m_compilationDatabase, m_sourceFilePaths); - - for (const auto &fileContent : m_fileContents) { - if (fileContent.content.hasContent()) - tool.mapVirtualFile(toStringRef(fileContent.filePath), toStringRef(fileContent.content)); - } - - for (const auto &unsavedFileContent : m_unsavedFileContents) { - tool.mapVirtualFile(toStringRef(unsavedFileContent.filePath), - toStringRef(unsavedFileContent.content)); - } - - tool.mapVirtualFile("/dummyFile", "#pragma once"); - - return tool; -} - -clang::tooling::ClangTool ClangTool::createOutputTool() const -{ - clang::tooling::ClangTool tool = createTool(); - - tool.clearArgumentsAdjusters(); - - return tool; -} - -bool ClangTool::isClean() const -{ - return m_sourceFilePaths.empty() && m_fileContents.empty() - && m_compilationDatabase.getAllFiles().empty() && m_unsavedFileContents.empty(); -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/clangtool.h b/src/tools/clangrefactoringbackend/source/clangtool.h deleted file mode 100644 index 2abad0f49b5..00000000000 --- a/src/tools/clangrefactoringbackend/source/clangtool.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "refactoringcompilationdatabase.h" - -#include - -#include -#include -#include - -#include - -#include - -#include -#include - -namespace ClangBackEnd { - -struct FileContent -{ - FileContent(NativeFilePath &&filePath, const Utils::SmallString &content) - : filePath(std::move(filePath)) - , content(std::move(content)) - {} - - NativeFilePath filePath; - Utils::SmallString content; -}; - -struct UnsavedFileContent -{ - UnsavedFileContent(NativeFilePath &&filePath, Utils::SmallString &&content) - : filePath(std::move(filePath)) - , content(std::move(content)) - {} - - NativeFilePath filePath; - Utils::SmallString content; -}; - -class ClangTool -{ -public: - void addFile(FilePath &&filePath, - Utils::SmallString &&content, - Utils::SmallStringVector &&commandLine); - - void addFiles(const FilePaths &filePaths, const Utils::SmallStringVector &arguments); - - void addUnsavedFiles(const V2::FileContainers &unsavedFiles); - - clang::tooling::ClangTool createTool() const; - clang::tooling::ClangTool createOutputTool() const; - - bool isClean() const; - -private: - RefactoringCompilationDatabase m_compilationDatabase; - std::vector m_fileContents; - std::vector m_sourceFilePaths; - std::vector m_unsavedFileContents; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h b/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h deleted file mode 100644 index b0d59607e23..00000000000 --- a/src/tools/clangrefactoringbackend/source/collectmacrospreprocessorcallbacks.h +++ /dev/null @@ -1,230 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "filestatus.h" -#include "sourcedependency.h" -#include "sourcelocationsutils.h" -#include "sourcelocationentry.h" -#include "sourcesmanager.h" -#include "symbolentry.h" -#include "usedmacro.h" - -#include - -#include -#include - -#include -#include -#include - -namespace ClangBackEnd { - -class CollectMacrosPreprocessorCallbacks final : public clang::PPCallbacks, - public CollectUsedMacrosAndSourcesPreprocessorCallbacksBase -{ -public: - CollectMacrosPreprocessorCallbacks(SymbolEntries &symbolEntries, - SourceLocationEntries &sourceLocationEntries, - FilePathIds &sourceFiles, - UsedMacros &usedMacros, - FileStatuses &fileStatuses, - SourceDependencies &sourceDependencies, - FilePathCachingInterface &filePathCache, - const clang::SourceManager &sourceManager, - std::shared_ptr &&preprocessor) - : CollectUsedMacrosAndSourcesPreprocessorCallbacksBase(usedMacros, - filePathCache, - sourceManager, - std::move(preprocessor), - sourceDependencies, - sourceFiles, - fileStatuses) - , m_symbolEntries(symbolEntries) - , m_sourceLocationEntries(sourceLocationEntries) - { - } - - void FileChanged(clang::SourceLocation sourceLocation, - clang::PPCallbacks::FileChangeReason reason, - clang::SrcMgr::CharacteristicKind, - clang::FileID) override - { - if (reason == clang::PPCallbacks::EnterFile) - { - const clang::FileEntry *fileEntry = m_sourceManager->getFileEntryForID( - m_sourceManager->getFileID(sourceLocation)); - if (fileEntry) { - addFileStatus(fileEntry); - addSourceFile(fileEntry); - } - } - } - - void InclusionDirective(clang::SourceLocation hashLocation, - const clang::Token & /*includeToken*/, - llvm::StringRef /*fileName*/, - bool /*isAngled*/, - clang::CharSourceRange /*fileNameRange*/, - const clang::FileEntry *file, - llvm::StringRef /*searchPath*/, - llvm::StringRef /*relativePath*/, - const clang::Module * /*imported*/, - clang::SrcMgr::CharacteristicKind /*fileType*/ - ) override - { - if (!m_skipInclude && file) - addSourceDependency(file, hashLocation); - - m_skipInclude = false; - } - - bool FileNotFound(clang::StringRef /*fileNameRef*/, clang::SmallVectorImpl &/*recoveryPath*/) override - { - m_skipInclude = true; - - return true; - } - - void Ifndef(clang::SourceLocation, - const clang::Token ¯oNameToken, - const clang::MacroDefinition ¯oDefinition) override - { - addUsedMacro(macroNameToken, macroDefinition); - addMacroAsSymbol(macroNameToken, - firstMacroInfo(macroDefinition.getLocalDirective()), - SourceLocationKind::MacroUsage); - } - - void Ifdef(clang::SourceLocation, - const clang::Token ¯oNameToken, - const clang::MacroDefinition ¯oDefinition) override - { - addUsedMacro( macroNameToken, macroDefinition); - addMacroAsSymbol(macroNameToken, - firstMacroInfo(macroDefinition.getLocalDirective()), - SourceLocationKind::MacroUsage); - } - - void Defined(const clang::Token ¯oNameToken, - const clang::MacroDefinition ¯oDefinition, - clang::SourceRange) override - { - addUsedMacro(macroNameToken, macroDefinition); - addMacroAsSymbol(macroNameToken, - firstMacroInfo(macroDefinition.getLocalDirective()), - SourceLocationKind::MacroUsage); - } - - void MacroDefined(const clang::Token ¯oNameToken, - const clang::MacroDirective *macroDirective) override - { - addMacroAsSymbol(macroNameToken, firstMacroInfo(macroDirective), SourceLocationKind::MacroDefinition); - } - - void MacroUndefined(const clang::Token ¯oNameToken, - const clang::MacroDefinition ¯oDefinition, - const clang::MacroDirective *) override - { - addMacroAsSymbol(macroNameToken, - firstMacroInfo(macroDefinition.getLocalDirective()), - SourceLocationKind::MacroUndefinition); - } - - void MacroExpands(const clang::Token ¯oNameToken, - const clang::MacroDefinition ¯oDefinition, - clang::SourceRange, - const clang::MacroArgs *) override - { - addUsedMacro(macroNameToken, macroDefinition); - addMacroAsSymbol(macroNameToken, - firstMacroInfo(macroDefinition.getLocalDirective()), - SourceLocationKind::MacroUsage); - } - - void EndOfMainFile() override - { - filterOutHeaderGuards(); - mergeUsedMacros(); - } - - static const clang::MacroInfo *firstMacroInfo(const clang::MacroDirective *macroDirective) - { - if (macroDirective) { - const clang::MacroDirective *previousDirective = macroDirective; - do { - macroDirective = previousDirective; - previousDirective = macroDirective->getPrevious(); - } while (previousDirective); - - return macroDirective->getMacroInfo(); - } - - return nullptr; - } - - void addMacroAsSymbol(const clang::Token ¯oNameToken, - const clang::MacroInfo *macroInfo, - SourceLocationKind symbolType) - { - clang::SourceLocation sourceLocation = macroNameToken.getLocation(); - if (macroInfo && sourceLocation.isFileID() && !isInSystemHeader(sourceLocation)) { - FilePathId fileId = filePathId(sourceLocation); - if (fileId.isValid()) { - auto macroName = macroNameToken.getIdentifierInfo()->getName(); - SymbolIndex globalId = toSymbolIndex(macroInfo); - - auto found = m_symbolEntries.find(globalId); - if (found == m_symbolEntries.end()) { - Utils::optional usr = generateUSR(macroName, sourceLocation); - if (usr) { - m_symbolEntries.emplace(std::piecewise_construct, - std::forward_as_tuple(globalId), - std::forward_as_tuple(std::move(*usr), - macroName, - SymbolKind::Macro)); - } - } - - m_sourceLocationEntries.emplace_back(globalId, - fileId, - lineColum(sourceLocation), - symbolType); - } - - } - } - -private: - UsedMacros m_maybeUsedMacros; - std::shared_ptr m_preprocessor; - SymbolEntries &m_symbolEntries; - SourceLocationEntries &m_sourceLocationEntries; - bool m_skipInclude = false; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.cpp b/src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.cpp deleted file mode 100644 index d360b727c4b..00000000000 --- a/src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "collectmacrossourcefilecallbacks.h" -#include "collectmacrospreprocessorcallbacks.h" - -#include - - -namespace ClangBackEnd { - -bool CollectMacrosSourceFileCallbacks::handleBeginSource(clang::CompilerInstance &compilerInstance) -{ - auto callbacks = std::make_unique( - m_symbolEntries, - m_sourceLocationEntries, - m_sourceFiles, - m_usedMacros, - m_fileStatuses, - m_sourceDependencies, - m_filePathCache, - compilerInstance.getSourceManager(), - compilerInstance.getPreprocessorPtr()); - - compilerInstance.getPreprocessorPtr()->addPPCallbacks(std::move(callbacks)); - - return true; -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.h b/src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.h deleted file mode 100644 index 16ba5a4f536..00000000000 --- a/src/tools/clangrefactoringbackend/source/collectmacrossourcefilecallbacks.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "filestatus.h" -#include "sourcedependency.h" -#include "sourcelocationentry.h" -#include "symbolentry.h" -#include "usedmacro.h" - -#include - -#include - -namespace ClangBackEnd { - -class SourcesManager; - -class CollectMacrosSourceFileCallbacks : public clang::tooling::SourceFileCallbacks -{ -public: - CollectMacrosSourceFileCallbacks(SymbolEntries &symbolEntries, - SourceLocationEntries &sourceLocationEntries, - FilePathCachingInterface &filePathCache) - : m_symbolEntries(symbolEntries) - , m_sourceLocationEntries(sourceLocationEntries) - , m_filePathCache(filePathCache) - { - } - - bool handleBeginSource(clang::CompilerInstance &compilerInstance) override; - - const FilePathIds &sourceFiles() const - { - return m_sourceFiles; - } - - void addSourceFiles(const FilePathIds &filePathIds) - { - m_sourceFiles = filePathIds; - } - - void clear() - { - m_sourceFiles.clear(); - m_usedMacros.clear(); - m_fileStatuses.clear(); - m_sourceDependencies.clear(); - } - - const UsedMacros &usedMacros() const - { - return m_usedMacros; - } - - const FileStatuses &fileStatuses() const - { - return m_fileStatuses; - } - - const SourceDependencies &sourceDependencies() const - { - return m_sourceDependencies; - } - -private: - FilePathIds m_sourceFiles; - UsedMacros m_usedMacros; - FileStatuses m_fileStatuses; - SourceDependencies m_sourceDependencies; - SymbolEntries &m_symbolEntries; - SourceLocationEntries &m_sourceLocationEntries; - FilePathCachingInterface &m_filePathCache; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/collectsymbolsaction.cpp b/src/tools/clangrefactoringbackend/source/collectsymbolsaction.cpp deleted file mode 100644 index 301f50beaef..00000000000 --- a/src/tools/clangrefactoringbackend/source/collectsymbolsaction.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "collectsymbolsaction.h" - -#include - -namespace ClangBackEnd { - -std::unique_ptr CollectSymbolsAction::newASTConsumer( - clang::CompilerInstance &compilerInstance, - llvm::StringRef inFile) -{ - return clang::WrapperFrontendAction::CreateASTConsumer(compilerInstance, inFile); -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h b/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h deleted file mode 100644 index bf592502bc6..00000000000 --- a/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "clangrefactoringbackend_global.h" -#include "indexdataconsumer.h" -#include "sourcelocationentry.h" -#include "symbolentry.h" - -#include - -#include - -#include -#include -#include -#include - -#include - -namespace ClangBackEnd { - -class CollectSymbolsAction : public clang::WrapperFrontendAction -{ -public: - CollectSymbolsAction(std::shared_ptr indexDataConsumer) - : clang::WrapperFrontendAction( - clang::index::createIndexingAction(indexDataConsumer, createIndexingOptions())) - , m_indexDataConsumer(indexDataConsumer) - {} - - std::unique_ptr newASTConsumer(clang::CompilerInstance &compilerInstance, - llvm::StringRef inFile); - - static clang::index::IndexingOptions createIndexingOptions() - { - clang::index::IndexingOptions options; - - options.SystemSymbolFilter = clang::index::IndexingOptions::SystemSymbolFilterKind::None; - options.IndexFunctionLocals = true; - options.IndexMacrosInPreprocessor = true; - - return options; - } - - bool BeginInvocation(clang::CompilerInstance &compilerInstance) override - { - m_indexDataConsumer->setSourceManager(&compilerInstance.getSourceManager()); - compilerInstance.getPreprocessorOpts().AllowPCHWithCompilerErrors = true; - compilerInstance.getDiagnosticOpts().ErrorLimit = 1; - - return clang::WrapperFrontendAction::BeginInvocation(compilerInstance); - } - - bool BeginSourceFileAction(clang::CompilerInstance &compilerInstance) override - { - compilerInstance.getPreprocessor().SetSuppressIncludeNotFoundError(true); - - return clang::WrapperFrontendAction::BeginSourceFileAction(compilerInstance); - } - - void EndSourceFileAction() override { clang::WrapperFrontendAction::EndSourceFileAction(); } - - bool PrepareToExecuteAction(clang::CompilerInstance &instance) override - { - return clang::WrapperFrontendAction::PrepareToExecuteAction(instance); - } - - void ExecuteAction() override { clang::WrapperFrontendAction::ExecuteAction(); } - - std::unique_ptr CreateASTConsumer(clang::CompilerInstance &compilerInstance, - llvm::StringRef inFile) override - { - return WrapperFrontendAction::CreateASTConsumer(compilerInstance, inFile); - } - -private: - std::shared_ptr m_indexDataConsumer; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp b/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp deleted file mode 100644 index abb30d61b91..00000000000 --- a/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "indexdataconsumer.h" -#include "collectsymbolsaction.h" - -#include -#include -#include -#include - -#include - -#include - -namespace ClangBackEnd { - -namespace { -bool hasSymbolRole(clang::index::SymbolRole role, clang::index::SymbolRoleSet roleSet) -{ - return roleSet & static_cast(role); -} - -Utils::SmallString symbolName(const clang::NamedDecl *declaration) -{ - clang::DeclarationName declarationName(declaration->getIdentifier()); - - return declarationName.getAsString(); -} - -SourceLocationKind sourceLocationKind(clang::index::SymbolRoleSet roles) -{ - if (hasSymbolRole(clang::index::SymbolRole::Definition, roles)) - return SourceLocationKind::Definition; - else if (hasSymbolRole(clang::index::SymbolRole::Declaration, roles)) - return SourceLocationKind::Declaration; - else if (hasSymbolRole(clang::index::SymbolRole::Reference, roles)) - return SourceLocationKind::DeclarationReference; - - return SourceLocationKind::None; -} - -using SymbolKindAndTags = std::pair; - -class IndexingDeclVisitor : public clang::ConstDeclVisitor -{ -public: - SymbolKindAndTags VisitEnumDecl(const clang::EnumDecl * /*declaration*/) - { - return {SymbolKind::Enumeration, {}}; - } - SymbolKindAndTags VisitRecordDecl(const clang::RecordDecl *declaration) - { - SymbolKindAndTags result = {SymbolKind::Record, {}}; - switch (declaration->getTagKind()) { - case clang::TTK_Struct: result.second.push_back(SymbolTag::Struct); break; - case clang::TTK_Interface: result.second.push_back(SymbolTag::MsvcInterface); break; - case clang::TTK_Union: result.second.push_back(SymbolTag::Union); break; - case clang::TTK_Class: result.second.push_back(SymbolTag::Class); break; - case clang::TTK_Enum: break; // this case can never happen in a record but it is there to silent the warning - } - - return result; - } - - SymbolKindAndTags VisitFunctionDecl(const clang::FunctionDecl*) - { - return {SymbolKind::Function, {}}; - } - - SymbolKindAndTags VisitVarDecl(const clang::VarDecl*) - { - return {SymbolKind::Variable, {}}; - } -}; - -SymbolKindAndTags symbolKindAndTags(const clang::Decl *declaration) -{ - static IndexingDeclVisitor visitor; - return visitor.Visit(declaration); -} - -} // namespace - -bool IndexDataConsumer::skipSymbol(clang::FileID fileId) -{ - return isAlreadyParsed(fileId, m_symbolSourcesManager) - && !m_symbolSourcesManager.dependentFilesModified(); -} - -bool IndexDataConsumer::isAlreadyParsed(clang::FileID fileId, SourcesManager &sourcesManager) -{ - const clang::FileEntry *fileEntry = m_sourceManager->getFileEntryForID(fileId); - if (!fileEntry) - return false; - return sourcesManager.alreadyParsed(filePathId(fileEntry), fileEntry->getModificationTime()); -} - - bool IndexDataConsumer::handleDeclOccurrence( - const clang::Decl *declaration, - clang::index::SymbolRoleSet symbolRoles, - llvm::ArrayRef /*symbolRelations*/, - clang::SourceLocation sourceLocation, - IndexDataConsumer::ASTNodeInfo /*astNodeInfo*/) -{ - const auto *namedDeclaration = clang::dyn_cast(declaration); - if (namedDeclaration) { - if (!namedDeclaration->getIdentifier()) - return true; - - if (skipSymbol(m_sourceManager->getFileID(sourceLocation))) - return true; - - SymbolIndex globalId = toSymbolIndex(declaration->getCanonicalDecl()); - - auto found = m_symbolEntries.find(globalId); - if (found == m_symbolEntries.end()) { - Utils::optional usr = generateUSR(namedDeclaration); - if (usr) { - auto kindAndTags = symbolKindAndTags(declaration); - m_symbolEntries.emplace(std::piecewise_construct, - std::forward_as_tuple(globalId), - std::forward_as_tuple(std::move(*usr), - symbolName(namedDeclaration), - kindAndTags.first, - kindAndTags.second)); - } - } - - m_sourceLocationEntries.emplace_back(globalId, - filePathId(sourceLocation), - lineColum(sourceLocation), - sourceLocationKind(symbolRoles)); - } - - return true; -} - -namespace { - -SourceLocationKind macroSymbolType(clang::index::SymbolRoleSet roles) -{ - if (roles & static_cast(clang::index::SymbolRole::Definition)) - return SourceLocationKind::MacroDefinition; - - if (roles & static_cast(clang::index::SymbolRole::Undefinition)) - return SourceLocationKind::MacroUndefinition; - - if (roles & static_cast(clang::index::SymbolRole::Reference)) - return SourceLocationKind::MacroUsage; - - return SourceLocationKind::None; -} - -} // namespace - -bool IndexDataConsumer::handleMacroOccurrence( - const clang::IdentifierInfo *identifierInfo, - const clang::MacroInfo *macroInfo, - clang::index::SymbolRoleSet roles, - clang::SourceLocation sourceLocation) -{ - if (macroInfo && sourceLocation.isFileID() - && !isAlreadyParsed(m_sourceManager->getFileID(sourceLocation), m_macroSourcesManager) - && !isInSystemHeader(sourceLocation)) { - FilePathId fileId = filePathId(sourceLocation); - if (fileId.isValid()) { - auto macroName = identifierInfo->getName(); - SymbolIndex globalId = toSymbolIndex(macroInfo); - - auto found = m_symbolEntries.find(globalId); - if (found == m_symbolEntries.end()) { - Utils::optional usr = generateUSR(macroName, sourceLocation); - if (usr) { - m_symbolEntries.emplace(std::piecewise_construct, - std::forward_as_tuple(globalId), - std::forward_as_tuple(std::move(*usr), - macroName, - SymbolKind::Macro)); - } - } - - m_sourceLocationEntries.emplace_back(globalId, - fileId, - lineColum(sourceLocation), - macroSymbolType(roles)); - } - } - - return true; -} - -void IndexDataConsumer::finish() -{ - m_macroSourcesManager.updateModifiedTimeStamps(); - m_symbolSourcesManager.updateModifiedTimeStamps(); - m_filePathIndices.clear(); -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/indexdataconsumer.h b/src/tools/clangrefactoringbackend/source/indexdataconsumer.h deleted file mode 100644 index f3af3287444..00000000000 --- a/src/tools/clangrefactoringbackend/source/indexdataconsumer.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "clangrefactoringbackend_global.h" -#include "filestatus.h" -#include "sourcelocationentry.h" -#include "symbolentry.h" -#include "symbolsvisitorbase.h" - -#include - -#include - -namespace ClangBackEnd { - -class IndexDataConsumer : public clang::index::IndexDataConsumer, - public SymbolsVisitorBase -{ -public: - IndexDataConsumer(SymbolEntries &symbolEntries, - SourceLocationEntries &sourceLocationEntries, - FilePathCachingInterface &filePathCache, - SourcesManager &symbolSourcesManager, - SourcesManager ¯oSourcesManager) - : SymbolsVisitorBase(filePathCache, nullptr, m_filePathIndices) - , m_symbolEntries(symbolEntries) - , m_sourceLocationEntries(sourceLocationEntries) - , m_symbolSourcesManager(symbolSourcesManager) - , m_macroSourcesManager(macroSourcesManager) - - {} - - IndexDataConsumer(const IndexDataConsumer &) = delete; - IndexDataConsumer &operator=(const IndexDataConsumer &) = delete; - - bool handleDeclOccurrence( - const clang::Decl *declaration, - clang::index::SymbolRoleSet symbolRoles, - llvm::ArrayRef symbolRelations, - clang::SourceLocation sourceLocation, - ASTNodeInfo astNodeInfo) override; - - bool handleMacroOccurrence( - const clang::IdentifierInfo *identifierInfo, - const clang::MacroInfo *macroInfo, - clang::index::SymbolRoleSet roles, - clang::SourceLocation sourceLocation) override; - - void finish() override; - -private: - bool skipSymbol(clang::FileID fileId); - bool isAlreadyParsed(clang::FileID fileId, SourcesManager &sourcesManager); - -private: - FilePathIds m_filePathIndices; - SymbolEntries &m_symbolEntries; - SourceLocationEntries &m_sourceLocationEntries; - SourcesManager &m_symbolSourcesManager; - SourcesManager &m_macroSourcesManager; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/locationsourcefilecallbacks.cpp b/src/tools/clangrefactoringbackend/source/locationsourcefilecallbacks.cpp deleted file mode 100644 index 41e98558940..00000000000 --- a/src/tools/clangrefactoringbackend/source/locationsourcefilecallbacks.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "locationsourcefilecallbacks.h" - -#include "macropreprocessorcallbacks.h" - -#include -#include - -#include - -namespace ClangBackEnd { - -LocationSourceFileCallbacks::LocationSourceFileCallbacks(uint line, - uint column, - FilePathCachingInterface &filePathCache) - : m_filePathCache(filePathCache), - m_line(line), - m_column(column) -{ -} - -bool LocationSourceFileCallbacks::handleBeginSource(clang::CompilerInstance &compilerInstance) -{ - auto &preprocessor = compilerInstance.getPreprocessor(); - - m_macroPreprocessorCallbacks = new MacroPreprocessorCallbacks(m_sourceLocationsContainer, - m_symbolName, - preprocessor, - m_filePathCache, - m_line, - m_column); - - preprocessor.addPPCallbacks(std::unique_ptr(m_macroPreprocessorCallbacks)); - - return true; -} - -SourceLocationsContainer LocationSourceFileCallbacks::takeSourceLocations() -{ - return std::move(m_sourceLocationsContainer); -} - -Utils::SmallString LocationSourceFileCallbacks::takeSymbolName() -{ - return std::move(m_symbolName); -} - -bool LocationSourceFileCallbacks::hasSourceLocations() const -{ - return m_sourceLocationsContainer.hasContent(); -} - - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/locationsourcefilecallbacks.h b/src/tools/clangrefactoringbackend/source/locationsourcefilecallbacks.h deleted file mode 100644 index 85ce5b413dc..00000000000 --- a/src/tools/clangrefactoringbackend/source/locationsourcefilecallbacks.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include -#include - -#include - -namespace llvm { -class StringRef; -} - -namespace clang { -class CompilerInstance; -} - -namespace ClangBackEnd { - -class MacroPreprocessorCallbacks; -class SourceLocationsContainer; - -class LocationSourceFileCallbacks : public clang::tooling::SourceFileCallbacks -{ -public: - LocationSourceFileCallbacks(uint line, uint column, FilePathCachingInterface &filePathCache); - - bool handleBeginSource(clang::CompilerInstance &compilerInstance) override; - - SourceLocationsContainer takeSourceLocations(); - Utils::SmallString takeSymbolName(); - - bool hasSourceLocations() const; - -private: - SourceLocationsContainer m_sourceLocationsContainer; - Utils::SmallString m_symbolName; - MacroPreprocessorCallbacks *m_macroPreprocessorCallbacks; - FilePathCachingInterface &m_filePathCache; - uint m_line; - uint m_column; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/macropreprocessorcallbacks.cpp b/src/tools/clangrefactoringbackend/source/macropreprocessorcallbacks.cpp deleted file mode 100644 index 2d46efed287..00000000000 --- a/src/tools/clangrefactoringbackend/source/macropreprocessorcallbacks.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "macropreprocessorcallbacks.h" - -namespace ClangBackEnd { - -MacroPreprocessorCallbacks::MacroPreprocessorCallbacks(SourceLocationsContainer &sourceLocationsContainer, - Utils::SmallString &symbolName, - clang::Preprocessor &preprocessor, - FilePathCachingInterface &filePathCache, - uint line, - uint column) - : m_sourceLocationsContainer(sourceLocationsContainer), - m_symbolName(symbolName), - m_preprocessor(preprocessor), - m_filePathCache(filePathCache), - m_line(line), - m_column(column) -{ -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/macropreprocessorcallbacks.h b/src/tools/clangrefactoringbackend/source/macropreprocessorcallbacks.h deleted file mode 100644 index f94d993ef2d..00000000000 --- a/src/tools/clangrefactoringbackend/source/macropreprocessorcallbacks.h +++ /dev/null @@ -1,187 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "sourcelocationsutils.h" - -#include -#include - -#include -#include -#include -#include - -#include - -namespace ClangBackEnd { - -struct MacroDirectiveToken -{ - MacroDirectiveToken(const clang::MacroDirective *macroDirective, - const clang::Token &token) - : macroDirective(macroDirective), - token(token) - {} - - const clang::MacroDirective *macroDirective; - const clang::Token token; -}; - -class MacroPreprocessorCallbacks : public clang::PPCallbacks -{ -public: - MacroPreprocessorCallbacks(SourceLocationsContainer &m_sourceLocationsContainer, - Utils::SmallString &m_symbolName, - clang::Preprocessor &m_preprocessor, - FilePathCachingInterface &filePathCache, - uint m_line, - uint m_column); - - void FileChanged(clang::SourceLocation location, - FileChangeReason reason, - clang::SrcMgr::CharacteristicKind /*fileType*/, - clang::FileID /*previousFileIdentifier*/) final - { - if (!m_isMainFileEntered) { - updateLocations(); - updateIsMainFileEntered(location, reason); - } - } - - void MacroDefined(const clang::Token &token, const clang::MacroDirective *macroDirective) final - { - if (isInMainFile(token)) { - if (includesCursorPosition(token)) { - m_sourceLocations.push_back(token.getLocation()); - m_cursorMacroDirective = macroDirective; - m_symbolName = Utils::SmallString(token.getIdentifierInfo()->getNameStart(), - token.getIdentifierInfo()->getLength()); - } - } - } - - void MacroExpands(const clang::Token &token, - const clang::MacroDefinition ¯oDefinition, - clang::SourceRange /*sourceRange*/, - const clang::MacroArgs * /*macroArguments*/) final - { - if (includesCursorPosition(token)) { - appendSourceLocations(token, macroDefinition); - m_cursorMacroDirective = macroDefinition.getLocalDirective(); - m_symbolName = Utils::SmallString(token.getIdentifierInfo()->getNameStart(), - token.getIdentifierInfo()->getLength()); - } else if (isCurrentTokenExpansion(macroDefinition)) { - m_sourceLocations.push_back(token.getLocation()); - } else if (isBeforeCursorSourceLocation()) { - m_preCursorMacroDirectiveTokens.emplace_back(macroDefinition.getLocalDirective(), token); - } - } - - void EndOfMainFile() final - { - appendSourceLocationsToSourceLocationsContainer(m_sourceLocationsContainer, - m_sourceLocations, - sourceManager(), - m_filePathCache); - } - -private: - void appendSourceLocations(const clang::Token &token, - const clang::MacroDefinition ¯oDefinition) - { - m_sourceLocations.push_back(macroDefinition.getLocalDirective()->getLocation()); - for (const auto ¯oDirectiveToken : m_preCursorMacroDirectiveTokens) { - if (macroDirectiveToken.macroDirective == macroDefinition.getLocalDirective()) - m_sourceLocations.push_back(macroDirectiveToken.token.getLocation()); - } - m_sourceLocations.push_back(token.getLocation()); - } - - void updateLocations() - { - if (m_mainFileSourceLocation.isInvalid()) { - m_mainFileSourceLocation = sourceManager().getLocForStartOfFile(sourceManager().getMainFileID()); - m_cursorSourceLocation = sourceManager().translateLineCol(sourceManager().getMainFileID(), - m_line, - m_column); - } - } - - void updateIsMainFileEntered(clang::SourceLocation location, FileChangeReason reason) - { - if (location == m_mainFileSourceLocation && reason == PPCallbacks::EnterFile) - m_isMainFileEntered = true; - } - - const clang::SourceManager &sourceManager() const - { - return m_preprocessor.getSourceManager(); - } - - bool isInMainFile(const clang::Token &token) - { - return m_isMainFileEntered && sourceManager().isWrittenInMainFile(token.getLocation()); - } - - bool includesCursorPosition(const clang::Token &token) - { - auto start = token.getLocation(); - auto end = token.getEndLoc(); - - return m_cursorSourceLocation == start - || m_cursorSourceLocation == end - || (sourceManager().isBeforeInTranslationUnit(start, m_cursorSourceLocation) && - sourceManager().isBeforeInTranslationUnit(m_cursorSourceLocation, end)); - } - - bool isCurrentTokenExpansion(const clang::MacroDefinition ¯oDefinition) - { - return m_cursorMacroDirective - && m_cursorMacroDirective == macroDefinition.getLocalDirective(); - } - - bool isBeforeCursorSourceLocation() const - { - return !m_cursorMacroDirective; - } - -private: - std::vector m_sourceLocations; - std::vector m_preCursorMacroDirectiveTokens; - SourceLocationsContainer &m_sourceLocationsContainer; - Utils::SmallString &m_symbolName; - clang::Preprocessor &m_preprocessor; - const clang::MacroDirective *m_cursorMacroDirective = nullptr; - clang::SourceLocation m_mainFileSourceLocation; - clang::SourceLocation m_cursorSourceLocation; - FilePathCachingInterface &m_filePathCache; - uint m_line; - uint m_column; - bool m_isMainFileEntered = false; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/projectpartentry.h b/src/tools/clangrefactoringbackend/source/projectpartentry.h deleted file mode 100644 index e7f9bec7e67..00000000000 --- a/src/tools/clangrefactoringbackend/source/projectpartentry.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -#include - -namespace ClangBackEnd { - -class ProjectPartEntry -{ -public: - ProjectPartEntry(Utils::SmallStringView projectPathName, - const FilePathIds &filePathIds, - Utils::SmallStringVector &&compilerArguments) - : projectPathName(projectPathName) - , filePathIds(filePathIds) - , toolChainArguments(compilerArguments) - {} - - friend bool operator==(const ProjectPartEntry &first, const ProjectPartEntry &second) - { - return first.projectPathName == second.projectPathName - && first.filePathIds == second.filePathIds - && first.toolChainArguments == second.toolChainArguments; - } - -public: - Utils::PathString projectPathName; - FilePathIds filePathIds; - Utils::SmallStringVector toolChainArguments; -}; - -using ProjectPartEntries = std::vector; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/refactoringcompilationdatabase.cpp b/src/tools/clangrefactoringbackend/source/refactoringcompilationdatabase.cpp deleted file mode 100644 index 1e1609d1a4f..00000000000 --- a/src/tools/clangrefactoringbackend/source/refactoringcompilationdatabase.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "refactoringcompilationdatabase.h" - -#include "clangrefactoringbackend_global.h" - -#include -#include - -namespace ClangBackEnd { - -RefactoringCompilationDatabase::RefactoringCompilationDatabase() -{ -} - -std::vector -RefactoringCompilationDatabase::getCompileCommands(llvm::StringRef filePath) const -{ - std::vector foundCommands; - - std::copy_if(m_compileCommands.begin(), - m_compileCommands.end(), - std::back_inserter(foundCommands), - [&] (const clang::tooling::CompileCommand &compileCommand) { - return filePath == compileCommand.Filename; - }); - - return foundCommands; -} - -std::vector -RefactoringCompilationDatabase::getAllFiles() const -{ - std::vector filePaths; - filePaths.reserve(m_compileCommands.size()); - - std::transform(m_compileCommands.begin(), - m_compileCommands.end(), - std::back_inserter(filePaths), - [&] (const clang::tooling::CompileCommand &compileCommand) { - return compileCommand.Filename; - }); - - return filePaths; -} - -std::vector -RefactoringCompilationDatabase::getAllCompileCommands() const -{ - return m_compileCommands; -} - -void RefactoringCompilationDatabase::addFile(NativeFilePathView filePath, - Utils::SmallStringVector &&commandLine) -{ - m_compileCommands.emplace_back(std::string(filePath.directory()), - std::string(filePath), - std::vector(commandLine), - llvm::StringRef()); -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/refactoringcompilationdatabase.h b/src/tools/clangrefactoringbackend/source/refactoringcompilationdatabase.h deleted file mode 100644 index ad37c8a3e9c..00000000000 --- a/src/tools/clangrefactoringbackend/source/refactoringcompilationdatabase.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clang/Tooling/CompilationDatabase.h" - -#include - -namespace ClangBackEnd { - -class RefactoringCompilationDatabase : public clang::tooling::CompilationDatabase -{ -public: - RefactoringCompilationDatabase(); - - std::vector getCompileCommands(llvm::StringRef filePath) const override; - std::vector getAllFiles() const override; - std::vector getAllCompileCommands() const override; - - void addFile(NativeFilePathView filePath, Utils::SmallStringVector &&commandLine); - -private: - std::vector m_compileCommands; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/refactoringserver.cpp b/src/tools/clangrefactoringbackend/source/refactoringserver.cpp deleted file mode 100644 index b86a93ad326..00000000000 --- a/src/tools/clangrefactoringbackend/source/refactoringserver.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "refactoringserver.h" - -#include "clangquery.h" -#include "symbolindexing.h" - -#include -#include - -#include - -#include -#include - -namespace ClangBackEnd { - -RefactoringServer::RefactoringServer(SymbolIndexingInterface &symbolIndexing, - FilePathCachingInterface &filePathCache, - GeneratedFiles &generatedFiles) - : m_symbolIndexing(symbolIndexing), - m_filePathCache(filePathCache), - m_generatedFiles(generatedFiles) -{ - m_pollTimer.setInterval(100); - - QObject::connect(&m_pollTimer, - &QTimer::timeout, - std::bind(&RefactoringServer::pollSourceRangesForQueryMessages, this)); -} - -void RefactoringServer::end() -{ - QCoreApplication::exit(); -} - -void RefactoringServer::requestSourceRangesAndDiagnosticsForQueryMessage( - RequestSourceRangesAndDiagnosticsForQueryMessage &&message) -{ - ClangQuery clangQuery(m_filePathCache, message.takeQuery()); - - clangQuery.addFile(std::move(message.source.filePath), - std::move(message.source.unsavedFileContent), - std::move(message.source.commandLineArguments)); - - clangQuery.findLocations(); - - client()->sourceRangesAndDiagnosticsForQueryMessage({clangQuery.takeSourceRanges(), - clangQuery.takeDiagnosticContainers()}); -} - -void RefactoringServer::requestSourceRangesForQueryMessage(RequestSourceRangesForQueryMessage &&message) -{ - gatherSourceRangesForQueryMessages(message.takeSources(), - message.takeUnsavedContent(), - message.takeQuery()); -} - -void RefactoringServer::updateProjectParts(UpdateProjectPartsMessage &&message) -{ - m_filePathCache.populateIfEmpty(); - m_symbolIndexing.updateProjectParts(message.takeProjectsParts()); -} - -void RefactoringServer::updateGeneratedFiles(UpdateGeneratedFilesMessage &&message) -{ - m_generatedFiles.update(message.takeGeneratedFiles()); -} - -void RefactoringServer::removeProjectParts(RemoveProjectPartsMessage &&) -{ - // TODO -} - -void RefactoringServer::removeGeneratedFiles(RemoveGeneratedFilesMessage &&message) -{ - m_generatedFiles.remove(message.generatedFiles); -} - -void RefactoringServer::cancel() -{ - m_gatherer.waitForFinished(); - m_gatherer = ClangQueryGatherer(); - m_pollTimer.stop(); -} - -bool RefactoringServer::isCancelingJobs() const -{ - return m_gatherer.isFinished(); -} - -void RefactoringServer::pollSourceRangesForQueryMessages() -{ - for (auto &&message : m_gatherer.finishedMessages()) - client()->sourceRangesForQueryMessage(std::move(message)); - - if (!m_gatherer.isFinished()) - m_gatherer.startCreateNextSourceRangesMessages(); - else - m_pollTimer.stop(); -} - -void RefactoringServer::waitThatSourceRangesForQueryMessagesAreFinished() -{ - while (!m_gatherer.isFinished()) { - m_gatherer.waitForFinished(); - pollSourceRangesForQueryMessages(); - } -} - -bool RefactoringServer::pollTimerIsActive() const -{ - return m_pollTimer.isActive(); -} - -void RefactoringServer::setGathererProcessingSlotCount(uint count) -{ - m_gatherer.setProcessingSlotCount(count); -} - -void RefactoringServer::setProgress(int progress, int total) -{ - if (client()) - client()->progress({ProgressType::Indexing, progress, total}); -} - -void RefactoringServer::gatherSourceRangesForQueryMessages( - std::vector &&sources, - std::vector &&unsaved, - Utils::SmallString &&query) -{ -#ifdef _WIN32 - uint freeProcessors = 1; -#else - uint freeProcessors = std::thread::hardware_concurrency(); -#endif - - m_gatherer = ClangQueryGatherer(&m_filePathCache, std::move(sources), std::move(unsaved), std::move(query)); - m_gatherer.setProcessingSlotCount(freeProcessors); - - m_pollTimer.start(); -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/refactoringserver.h b/src/tools/clangrefactoringbackend/source/refactoringserver.h deleted file mode 100644 index 79347905180..00000000000 --- a/src/tools/clangrefactoringbackend/source/refactoringserver.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "clangquerygatherer.h" - -#include - -#include -#include -#include - -#include - -#include - -#include -#include -#include - -namespace ClangBackEnd { - -class SourceRangesForQueryMessage; -class SymbolIndexingInterface; - -namespace V2 { -class FileContainer; -} - -class RefactoringServer : public RefactoringServerInterface, - public IpcClientProvider -{ - using Future = std::future; -public: - RefactoringServer(SymbolIndexingInterface &symbolIndexing, - FilePathCachingInterface &filePathCache, - GeneratedFiles &generatedFiles); - - void end() override; - void requestSourceRangesAndDiagnosticsForQueryMessage(RequestSourceRangesAndDiagnosticsForQueryMessage &&message) override; - void requestSourceRangesForQueryMessage(RequestSourceRangesForQueryMessage &&message) override; - void updateProjectParts(UpdateProjectPartsMessage &&message) override; - void updateGeneratedFiles(UpdateGeneratedFilesMessage &&message) override; - void removeProjectParts(RemoveProjectPartsMessage &&message) override; - void removeGeneratedFiles(RemoveGeneratedFilesMessage &&message) override; - - void cancel() override; - - bool isCancelingJobs() const; - - void pollSourceRangesForQueryMessages(); - void waitThatSourceRangesForQueryMessagesAreFinished(); - - bool pollTimerIsActive() const; - - void setGathererProcessingSlotCount(uint count); - - void setProgress(int progress, int total); - -private: - void gatherSourceRangesForQueryMessages(std::vector &&sources, - std::vector &&unsaved, - Utils::SmallString &&query); - -private: - ClangQueryGatherer m_gatherer; - QTimer m_pollTimer; - SymbolIndexingInterface &m_symbolIndexing; - FilePathCachingInterface &m_filePathCache; - GeneratedFiles &m_generatedFiles; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/sourcedependency.h b/src/tools/clangrefactoringbackend/source/sourcedependency.h deleted file mode 100644 index ce9671342ed..00000000000 --- a/src/tools/clangrefactoringbackend/source/sourcedependency.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -#include - -namespace ClangBackEnd { - -class SourceDependency -{ -public: - SourceDependency(FilePathId filePathId, FilePathId dependencyFilePathId) - : filePathId(filePathId) - , dependencyFilePathId(dependencyFilePathId) - {} - - friend bool operator==(SourceDependency first, SourceDependency second) - { - return first.filePathId == second.filePathId - && first.dependencyFilePathId == second.dependencyFilePathId; - } - - friend bool operator!=(SourceDependency first, SourceDependency second) - { - return !(first == second); - } - - friend bool operator<(SourceDependency first, SourceDependency second) - { - return std::tie(first.filePathId, first.dependencyFilePathId) - < std::tie(second.filePathId, second.dependencyFilePathId); - } - -public: - FilePathId filePathId; - FilePathId dependencyFilePathId; -}; - -using SourceDependencies = std::vector; -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/sourcelocationentry.h b/src/tools/clangrefactoringbackend/source/sourcelocationentry.h deleted file mode 100644 index 5d4a4bbf77f..00000000000 --- a/src/tools/clangrefactoringbackend/source/sourcelocationentry.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -#include - -#include -#include - -using uint = unsigned int; - -namespace ClangBackEnd { - -using SymbolIndex = long long; - -class SourceLocationEntry -{ -public: - SourceLocationEntry(SymbolIndex symbolId, - FilePathId filePathId, - Utils::LineColumn lineColumn, - SourceLocationKind kind) - : symbolId(symbolId), - filePathId(filePathId), - lineColumn(lineColumn), - kind(kind) - {} - - SymbolIndex symbolId = 0; - FilePathId filePathId; - Utils::LineColumn lineColumn; - SourceLocationKind kind; - - friend bool operator==(const SourceLocationEntry &first, const SourceLocationEntry &second) - { - return first.symbolId == second.symbolId - && first.filePathId == second.filePathId - && first.lineColumn == second.lineColumn - && first.kind == second.kind; - } -}; - -using SourceLocationEntries = std::vector; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/sourcelocationsutils.h b/src/tools/clangrefactoringbackend/source/sourcelocationsutils.h deleted file mode 100644 index c4fc1bf645b..00000000000 --- a/src/tools/clangrefactoringbackend/source/sourcelocationsutils.h +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include - -namespace ClangBackEnd { - -inline -llvm::SmallString<256> absolutePath(clang::StringRef path) -{ - llvm::SmallString<256> absolutePath; - - if (llvm::sys::path::is_absolute(path)) { - absolutePath = path; - - llvm::sys::path::remove_dots(absolutePath, true); - - return absolutePath; - } - - std::error_code errorCode = llvm::sys::fs::real_path(path, absolutePath, true); - - if (!errorCode) - llvm::sys::fs::make_absolute(absolutePath); - - return absolutePath; -} - -inline -Utils::PathString fromNativePath(const llvm::SmallString<256> &string) -{ - Utils::PathString path(string.data(), string.size()); - - if (Utils::HostOsInfo::isWindowsHost()) - std::replace(path.begin(), path.end(), '\\', '/'); - - return path; -} - -inline -void appendSourceLocationsToSourceLocationsContainer( - ClangBackEnd::SourceLocationsContainer &sourceLocationsContainer, - const std::vector &sourceLocations, - const clang::SourceManager &sourceManager, - FilePathCachingInterface &filePathCache) -{ - sourceLocationsContainer.reserve(sourceLocations.size()); - - for (const auto &sourceLocation : sourceLocations) { - clang::FullSourceLoc fullSourceLocation(sourceLocation, sourceManager); - const auto decomposedLoction = fullSourceLocation.getDecomposedLoc(); - const auto fileId = decomposedLoction.first; - const auto offset = decomposedLoction.second; - const auto fileEntry = sourceManager.getFileEntryForID(fileId); - auto filePath = FilePath::fromNativeFilePath(absolutePath(fileEntry->getName())); - - sourceLocationsContainer.insertSourceLocation(filePathCache.filePathId(filePath), - fullSourceLocation.getSpellingLineNumber(), - fullSourceLocation.getSpellingColumnNumber(), - offset); - } -} - - - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp b/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp deleted file mode 100644 index 66f2e23fc71..00000000000 --- a/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "sourcerangeextractor.h" - -#include "sourcelocationsutils.h" - -#include -#include - -#include -#include -#include -#include -#include - -namespace ClangBackEnd { - -SourceRangeExtractor::SourceRangeExtractor( - const clang::SourceManager &sourceManager, - const clang::LangOptions &languageOptions, - FilePathCachingInterface &filePathCache, - SourceRangesContainer &sourceRangesContainer) - : sourceManager(sourceManager), - languageOptions(languageOptions), - filePathCache(filePathCache), - sourceRangesContainer(sourceRangesContainer) -{ -} - -namespace { -template -std::reverse_iterator make_reverse_iterator(Iterator iterator) -{ - return std::reverse_iterator(iterator); -} - -} - -const char *SourceRangeExtractor::findStartOfLineInBuffer(llvm::StringRef buffer, uint startOffset) -{ - auto beginText = buffer.begin() + startOffset; - auto reverseBegin = make_reverse_iterator(beginText); - auto reverseEnd = make_reverse_iterator(buffer.begin()); - - auto found = std::find_if(reverseBegin, - reverseEnd, - [] (const char character) { - return character == '\n' || character == '\r'; - }); - - if (found != reverseEnd) - return found.base(); - - return buffer.begin(); -} - -const char *SourceRangeExtractor::findEndOfLineInBuffer(llvm::StringRef buffer, uint endOffset) -{ - auto beginText = buffer.begin() + endOffset; - - auto found = std::find_if(beginText, - buffer.end(), - [] (const char character) { - return character == '\n' || character == '\r'; - }); - - if (found != buffer.end()) - return found; - - return buffer.end(); -} - -Utils::SmallString SourceRangeExtractor::getExpandedText(llvm::StringRef buffer, - uint startOffset, - uint endOffset) -{ - auto startBuffer = findStartOfLineInBuffer(buffer, startOffset); - auto endBuffer = findEndOfLineInBuffer(buffer, endOffset); - - return Utils::SmallString(startBuffer, endBuffer); -} - -const clang::SourceRange SourceRangeExtractor::extendSourceRangeToLastTokenEnd(const clang::SourceRange sourceRange) -{ - auto endLocation = sourceRange.getEnd(); - uint length = clang::Lexer::MeasureTokenLength(sourceManager.getSpellingLoc(endLocation), - sourceManager, - languageOptions); - endLocation = endLocation.getLocWithOffset(length); - - return {sourceRange.getBegin(), endLocation}; -} - -void SourceRangeExtractor::insertSourceRange(FilePathId filePathId, - const clang::FullSourceLoc &startLocation, - uint startOffset, - const clang::FullSourceLoc &endLocation, - uint endOffset, - Utils::SmallString &&lineSnippet) -{ - sourceRangesContainer.insertSourceRange(filePathId, - startLocation.getSpellingLineNumber(), - startLocation.getSpellingColumnNumber(), - startOffset, - endLocation.getSpellingLineNumber(), - endLocation.getSpellingColumnNumber(), - endOffset, - std::move(lineSnippet)); -} - -FilePathId SourceRangeExtractor::findFileId(clang::FileID fileId, const clang::FileEntry *fileEntry) const -{ - auto found = m_fileIdMapping.find(fileId.getHashValue()); - if (found != m_fileIdMapping.end()) { - return found->second; - } - - auto filePath = absolutePath(fileEntry->getName()); - return filePathCache.filePathId(FilePath::fromNativeFilePath(filePath)); -} - -void SourceRangeExtractor::addSourceRange(const clang::SourceRange &sourceRange) -{ - auto extendedSourceRange = extendSourceRangeToLastTokenEnd(sourceRange); - - clang::FullSourceLoc startSourceLocation(extendedSourceRange.getBegin(), sourceManager); - clang::FullSourceLoc endSourceLocation(extendedSourceRange.getEnd(), sourceManager); - if (startSourceLocation.isFileID() && endSourceLocation.isFileID()) { - const auto startDecomposedLoction = startSourceLocation.getDecomposedLoc(); - const auto endDecomposedLoction = endSourceLocation.getDecomposedLoc(); - const auto fileId = startDecomposedLoction.first; - const auto startOffset = startDecomposedLoction.second; - const auto endOffset = endDecomposedLoction.second; - const auto fileEntry = sourceManager.getFileEntryForID(fileId); - - Utils::SmallString lineSnippet = getExpandedText(startSourceLocation.getBufferData(), - startOffset, - endOffset); - - insertSourceRange(findFileId(fileId, fileEntry), - startSourceLocation, - startOffset, - endSourceLocation, - endOffset, - std::move(lineSnippet)); - } -} - -void SourceRangeExtractor::addSourceRanges(const std::vector &sourceRanges) -{ - sourceRangesContainer.reserve(sourceRanges.size() + sourceRangeWithTextContainers().size()); - - for (const clang::SourceRange &sourceRange : sourceRanges) - addSourceRange(sourceRange); -} - -const std::vector &SourceRangeExtractor::sourceRangeWithTextContainers() const -{ - return sourceRangesContainer.sourceRangeWithTextContainers; -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/sourcerangeextractor.h b/src/tools/clangrefactoringbackend/source/sourcerangeextractor.h deleted file mode 100644 index 85c277265d5..00000000000 --- a/src/tools/clangrefactoringbackend/source/sourcerangeextractor.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include - -#include -#include - -#include - -#include -#include - -using uint = unsigned int; - -namespace llvm { -class StringRef; -} - -namespace clang { -class SourceManager; -class LangOptions; -class SourceRange; -class FullSourceLoc; -class FileID; -class FileEntry; -} - -namespace ClangBackEnd { - -class SourceRangesContainer; -class SourceRangeWithTextContainer; - -class SourceRangeExtractor -{ -public: - SourceRangeExtractor(const clang::SourceManager &sourceManager, - const clang::LangOptions &languageOptions, - FilePathCachingInterface &filePathCache, - SourceRangesContainer &sourceRangesContainer); - - void addSourceRange(const clang::SourceRange &sourceRange); - void addSourceRanges(const std::vector &sourceRanges); - - const std::vector &sourceRangeWithTextContainers() const; - - static const char *findStartOfLineInBuffer(const llvm::StringRef buffer, uint startOffset); - static const char *findEndOfLineInBuffer(llvm::StringRef buffer, uint endOffset); - static Utils::SmallString getExpandedText(llvm::StringRef buffer, uint startOffset, uint endOffset); - - const clang::SourceRange extendSourceRangeToLastTokenEnd(const clang::SourceRange sourceRange); - -private: - void insertSourceRange(FilePathId filePathId, - const clang::FullSourceLoc &startLocation, - uint startOffset, - const clang::FullSourceLoc &endLocation, - uint endOffset, - Utils::SmallString &&lineSnippet); - - FilePathId findFileId(clang::FileID fileId, const clang::FileEntry *fileEntry) const; - -private: - mutable std::unordered_map m_fileIdMapping; - const clang::SourceManager &sourceManager; - const clang::LangOptions &languageOptions; - FilePathCachingInterface &filePathCache; - SourceRangesContainer &sourceRangesContainer; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/sourcerangefilter.cpp b/src/tools/clangrefactoringbackend/source/sourcerangefilter.cpp deleted file mode 100644 index fd13de10156..00000000000 --- a/src/tools/clangrefactoringbackend/source/sourcerangefilter.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "sourcerangefilter.h" - -#include - -namespace ClangBackEnd { - -SourceRangeFilter::SourceRangeFilter(std::size_t sourcesCount) -{ - m_collectedSourceRanges.reserve(sourcesCount * 100); -} - -SourceRangesForQueryMessage SourceRangeFilter::removeDuplicates(SourceRangesForQueryMessage &&message) -{ - auto sourceRanges = removeDuplicates(message.sourceRanges.takeSourceRangeWithTextContainers()); - - message.sourceRanges.sourceRangeWithTextContainers = std::move(sourceRanges); - - return std::move(message); -} - -SourceRangeWithTextContainers SourceRangeFilter::removeDuplicates(SourceRangeWithTextContainers &&sourceRanges) -{ - SourceRangeWithTextContainers newSourceRanges; - newSourceRanges.reserve(sourceRanges.size()); - - std::sort(sourceRanges.begin(), sourceRanges.end()); - auto sourceRangesNewEnd = std::unique(sourceRanges.begin(), sourceRanges.end()); - - std::set_difference(sourceRanges.begin(), - sourceRangesNewEnd, - m_collectedSourceRanges.begin(), - m_collectedSourceRanges.end(), - std::back_inserter(newSourceRanges)); - - V2::SourceRangeContainers collectedSourceRanges; - collectedSourceRanges.reserve(m_collectedSourceRanges.size() + newSourceRanges.size()); - - std::merge(m_collectedSourceRanges.begin(), - m_collectedSourceRanges.end(), - newSourceRanges.begin(), - newSourceRanges.end(), - std::back_inserter(collectedSourceRanges)); - - std::swap(m_collectedSourceRanges, collectedSourceRanges); - - return newSourceRanges; -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/sourcerangefilter.h b/src/tools/clangrefactoringbackend/source/sourcerangefilter.h deleted file mode 100644 index 1cddd95a756..00000000000 --- a/src/tools/clangrefactoringbackend/source/sourcerangefilter.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -#include - -namespace ClangBackEnd { - -class SourceRangeFilter -{ -public: - SourceRangeFilter(std::size_t sourcesCount = 0); - - SourceRangesForQueryMessage - removeDuplicates(SourceRangesForQueryMessage &&message); - SourceRangeWithTextContainers removeDuplicates(SourceRangeWithTextContainers &&sourceRanges); - -private: - V2::SourceRangeContainers m_collectedSourceRanges; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/sourcesmanager.h b/src/tools/clangrefactoringbackend/source/sourcesmanager.h deleted file mode 100644 index 91d2eb61438..00000000000 --- a/src/tools/clangrefactoringbackend/source/sourcesmanager.h +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -#include - -namespace ClangBackEnd { - -class SourcesManager -{ - struct FilePathIdTime - { - FilePathIdTime(FilePathId filePathId, std::time_t modifiedTime) - : filePathId(filePathId), - modifiedTime(modifiedTime) - {} - FilePathId filePathId; - std::time_t modifiedTime = 0; - }; - -public: - bool alreadyParsed(FilePathId filePathId, std::time_t modifiedTime) - { - auto found = std::lower_bound(m_modifiedTimeStamps.cbegin(), - m_modifiedTimeStamps.cend(), - filePathId, - [] (FilePathIdTime entry, FilePathId filePathId) { - return entry.filePathId < filePathId; - }); - - bool upToDate = found != m_modifiedTimeStamps.end() && found->filePathId == filePathId - && modifiedTime <= found->modifiedTime; - - if (!upToDate) - addOrUpdateNewEntry(filePathId, modifiedTime); - - m_dependentFilesModified = m_dependentFilesModified || !upToDate; - - return upToDate ; - } - - void updateModifiedTimeStamps() - { - std::vector mergedModifiedTimeStamps; - mergedModifiedTimeStamps.reserve(m_newModifiedTimeStamps.size() + m_modifiedTimeStamps.size()); - - auto compare = [](FilePathIdTime first, FilePathIdTime second) { - return first.filePathId < second.filePathId; - }; - - std::set_union(m_newModifiedTimeStamps.begin(), - m_newModifiedTimeStamps.end(), - m_modifiedTimeStamps.begin(), - m_modifiedTimeStamps.end(), - std::back_inserter(mergedModifiedTimeStamps), - compare); - - m_modifiedTimeStamps = std::move(mergedModifiedTimeStamps); - m_newModifiedTimeStamps.clear(); - m_dependentFilesModified = false; - } - - bool dependentFilesModified() const - { - return m_dependentFilesModified; - } - - bool alreadyParsedAllDependentFiles(FilePathId filePathId, std::time_t modifiedTime) - { - return alreadyParsed(filePathId, modifiedTime) && !dependentFilesModified(); - } - -private: - void addOrUpdateNewEntry(FilePathId filePathId, std::time_t modifiedTime) - { - auto found = std::lower_bound(m_newModifiedTimeStamps.begin(), - m_newModifiedTimeStamps.end(), - filePathId, - [] (FilePathIdTime entry, FilePathId filePathId) { - return entry.filePathId < filePathId; - }); - - if (found != m_newModifiedTimeStamps.end() && found->filePathId == filePathId) - found->modifiedTime = modifiedTime; - else - m_newModifiedTimeStamps.emplace(found, filePathId, modifiedTime); - } - -private: - std::vector m_modifiedTimeStamps; - std::vector m_newModifiedTimeStamps; - bool m_dependentFilesModified = false; -}; - -} diff --git a/src/tools/clangrefactoringbackend/source/symbolentry.h b/src/tools/clangrefactoringbackend/source/symbolentry.h deleted file mode 100644 index cc9669c6820..00000000000 --- a/src/tools/clangrefactoringbackend/source/symbolentry.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -#include - -#include -#include - -#include -#include -#include - -namespace ClangBackEnd { - -using SymbolIndex = long long; - -class SymbolEntry -{ -public: - SymbolEntry(Utils::PathString &&usr, - Utils::SmallString &&symbolName, - SymbolKind symbolKind, - SymbolTags symbolTags={}) - : usr(std::move(usr)), - symbolName(std::move(symbolName)), - symbolKind(symbolKind), - symbolTags(symbolTags) - {} - - Utils::PathString usr; - Utils::SmallString symbolName; - SymbolKind symbolKind; - SymbolTags symbolTags; - - friend bool operator==(const SymbolEntry &first, const SymbolEntry &second) - { - return first.usr == second.usr - && first.symbolName == second.symbolName - && first.symbolKind == second.symbolKind; - } -}; - -using SymbolEntries = std::unordered_map; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp deleted file mode 100644 index fb53a9d3a00..00000000000 --- a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp +++ /dev/null @@ -1,306 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "symbolindexer.h" - -#include "symbolscollectorinterface.h" -#include "symbolindexertaskqueue.h" - -#include -#include - -#include -#include - -namespace ClangBackEnd { - -using namespace std::chrono; - -class Timer -{ -public: - Timer(Utils::SmallStringView name) - : name(name) - {} - - void commit() - { - auto end = steady_clock::now(); - auto time_difference = duration_cast(end - begin); - begin = end; - std::cerr << name << " " << timePoint++ << ": " << time_difference.count() << "\n"; - } - -private: - Utils::SmallString name; - time_point begin{steady_clock::now()}; - int timePoint = 1; -}; - -SymbolIndexer::SymbolIndexer(SymbolIndexerTaskQueueInterface &symbolIndexerTaskQueue, - SymbolStorageInterface &symbolStorage, - BuildDependenciesStorageInterface &buildDependenciesStorage, - PrecompiledHeaderStorageInterface &precompiledHeaderStorage, - ClangPathWatcherInterface &pathWatcher, - FilePathCachingInterface &filePathCache, - FileStatusCache &fileStatusCache, - Sqlite::TransactionInterface &transactionInterface, - ProjectPartsStorageInterface &projectPartsStorage, - ModifiedTimeCheckerInterface &modifiedTimeChecker, - const Environment &environment) - : m_symbolIndexerTaskQueue(symbolIndexerTaskQueue) - , m_symbolStorage(symbolStorage) - , m_buildDependencyStorage(buildDependenciesStorage) - , m_precompiledHeaderStorage(precompiledHeaderStorage) - , m_pathWatcher(pathWatcher) - , m_filePathCache(filePathCache) - , m_fileStatusCache(fileStatusCache) - , m_transactionInterface(transactionInterface) - , m_projectPartsStorage(projectPartsStorage) - , m_modifiedTimeChecker(modifiedTimeChecker) - , m_environment(environment) -{ - pathWatcher.setNotifier(this); -} - -void SymbolIndexer::updateProjectParts(ProjectPartContainers &&projectParts) -{ - for (ProjectPartContainer &projectPart : projectParts) - updateProjectPart(std::move(projectPart)); -} - -namespace { - -void store(SymbolStorageInterface &symbolStorage, - BuildDependenciesStorageInterface &buildDependencyStorage, - Sqlite::TransactionInterface &transactionInterface, - SymbolsCollectorInterface &symbolsCollector, - const FilePathIds &dependentSources) -{ - try { - long long now = std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()) - .count(); - - Sqlite::ImmediateTransaction transaction{transactionInterface}; - buildDependencyStorage.insertOrUpdateIndexingTimeStampsWithoutTransaction(dependentSources, - now); - - symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(), - symbolsCollector.sourceLocations()); - transaction.commit(); - } catch (const Sqlite::StatementIsBusy &) { - store(symbolStorage, - buildDependencyStorage, - transactionInterface, - symbolsCollector, - dependentSources); - } -} - -FilePathIds toFilePathIds(const SourceTimeStamps &sourceTimeStamps) -{ - return Utils::transform(sourceTimeStamps, [](SourceTimeStamp sourceTimeStamp) { - return sourceTimeStamp.sourceId; - }); -} -} // namespace - -void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart) -{ - ProjectPartId projectPartId = projectPart.projectPartId; - - std::vector symbolIndexerTask; - symbolIndexerTask.reserve(projectPart.sourcePathIds.size()); - - for (FilePathId sourcePathId : projectPart.sourcePathIds) { - SourceTimeStamps dependentTimeStamps = m_buildDependencyStorage.fetchIncludedIndexingTimeStamps( - sourcePathId); - - if (!m_modifiedTimeChecker.isUpToDate(dependentTimeStamps)) { - auto indexing = [projectPart, - sourcePathId, - preIncludeSearchPath = m_environment.preIncludeSearchPath(), - dependentSources = toFilePathIds(dependentTimeStamps), - this](SymbolsCollectorInterface &symbolsCollector) { - auto collect = [&](const FilePath &pchPath) { - using Builder = CommandLineBuilder; - Builder commandLineBuilder{projectPart, - projectPart.toolChainArguments, - InputFileType::Source, - {}, - {}, - pchPath, - preIncludeSearchPath}; - symbolsCollector.setFile(sourcePathId, commandLineBuilder.commandLine); - - - return symbolsCollector.collectSymbols(); - }; - - const PchPaths pchPaths = m_precompiledHeaderStorage.fetchPrecompiledHeaders( - projectPart.projectPartId); - - if (pchPaths.projectPchPath.size() && collect(pchPaths.projectPchPath)) { - store(m_symbolStorage, - m_buildDependencyStorage, - m_transactionInterface, - symbolsCollector, - dependentSources); - } else if (pchPaths.systemPchPath.size() && collect(pchPaths.systemPchPath)) { - store(m_symbolStorage, - m_buildDependencyStorage, - m_transactionInterface, - symbolsCollector, - dependentSources); - } else if (collect({})) { - store(m_symbolStorage, - m_buildDependencyStorage, - m_transactionInterface, - symbolsCollector, - dependentSources); - } - }; - - symbolIndexerTask.emplace_back(sourcePathId, projectPartId, std::move(indexing)); - } - } - - m_pathWatcher.updateIdPaths({{{projectPartId, SourceType::Source}, - m_buildDependencyStorage.fetchPchSources(projectPartId)}}); - m_symbolIndexerTaskQueue.addOrUpdateTasks(std::move(symbolIndexerTask)); - m_symbolIndexerTaskQueue.processEntries(); -} - -void SymbolIndexer::pathsWithIdsChanged(const std::vector &) {} - -void SymbolIndexer::pathsChanged(const FilePathIds &filePathIds) -{ - m_modifiedTimeChecker.pathsChanged(filePathIds); -} - -void SymbolIndexer::updateChangedPath(FilePathId filePathId, - std::vector &symbolIndexerTask) -{ - m_fileStatusCache.update(filePathId); - - const Utils::optional - optionalArtefact = m_projectPartsStorage.fetchProjectPartArtefact(filePathId); - if (!optionalArtefact) - return; - - ProjectPartId projectPartId = optionalArtefact->projectPartId; - - SourceTimeStamps dependentTimeStamps = m_buildDependencyStorage.fetchIncludedIndexingTimeStamps( - filePathId); - - auto indexing = [optionalArtefact = std::move(optionalArtefact), - filePathId, - preIncludeSearchPath = m_environment.preIncludeSearchPath(), - dependentSources = toFilePathIds(dependentTimeStamps), - this](SymbolsCollectorInterface &symbolsCollector) { - auto collect = [&](const FilePath &pchPath) { - const ProjectPartArtefact &artefact = *optionalArtefact; - - using Builder = CommandLineBuilder; - Builder builder{artefact, - artefact.toolChainArguments, - InputFileType::Source, - {}, - {}, - pchPath, - preIncludeSearchPath}; - - symbolsCollector.setFile(filePathId, builder.commandLine); - - return symbolsCollector.collectSymbols(); - }; - - const PchPaths pchPaths = m_precompiledHeaderStorage.fetchPrecompiledHeaders( - optionalArtefact->projectPartId); - - if (pchPaths.projectPchPath.size() && collect(pchPaths.projectPchPath)) { - store(m_symbolStorage, - m_buildDependencyStorage, - m_transactionInterface, - symbolsCollector, - dependentSources); - } else if (pchPaths.systemPchPath.size() && collect(pchPaths.systemPchPath)) { - store(m_symbolStorage, - m_buildDependencyStorage, - m_transactionInterface, - symbolsCollector, - dependentSources); - } else if (collect({})) { - store(m_symbolStorage, - m_buildDependencyStorage, - m_transactionInterface, - symbolsCollector, - dependentSources); - } - }; - - symbolIndexerTask.emplace_back(filePathId, projectPartId, std::move(indexing)); -} - -bool SymbolIndexer::compilerMacrosOrIncludeSearchPathsAreDifferent( - const ProjectPartContainer &projectPart, - const Utils::optional &optionalArtefact) const -{ - if (optionalArtefact) { - const ProjectPartArtefact &artefact = optionalArtefact.value(); - return projectPart.compilerMacros != artefact.compilerMacros - || projectPart.systemIncludeSearchPaths != artefact.systemIncludeSearchPaths - || projectPart.projectIncludeSearchPaths != artefact.projectIncludeSearchPaths; - } - - return true; -} - -FilePathIds SymbolIndexer::filterChangedFiles(const ProjectPartContainer &projectPart) const -{ - FilePathIds ids; - ids.reserve(projectPart.sourcePathIds.size()); - - for (const FilePathId &sourceId : projectPart.sourcePathIds) { - long long oldLastModified = m_buildDependencyStorage.fetchLowestLastModifiedTime(sourceId); - long long currentLastModified = m_fileStatusCache.lastModifiedTime(sourceId); - if (oldLastModified < currentLastModified) - ids.push_back(sourceId); - } - - return ids; -} - -FilePathIds SymbolIndexer::updatableFilePathIds(const ProjectPartContainer &projectPart, - const Utils::optional &optionalArtefact) const -{ - if (compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart, optionalArtefact)) - return projectPart.sourcePathIds; - - return filterChangedFiles(projectPart); -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.h b/src/tools/clangrefactoringbackend/source/symbolindexer.h deleted file mode 100644 index 67da0c9774d..00000000000 --- a/src/tools/clangrefactoringbackend/source/symbolindexer.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "filestatuscache.h" -#include "symbolindexertaskqueueinterface.h" -#include "symbolstorageinterface.h" -#include "builddependenciesstorageinterface.h" - -#include -#include -#include -#include -#include -#include - -namespace ClangBackEnd { - -class SymbolsCollectorInterface; -class Environment; - -class SymbolIndexer final : public ClangPathWatcherNotifier -{ -public: - SymbolIndexer(SymbolIndexerTaskQueueInterface &symbolIndexerTaskQueue, - SymbolStorageInterface &symbolStorage, - BuildDependenciesStorageInterface &buildDependenciesStorage, - PrecompiledHeaderStorageInterface &precompiledHeaderStorage, - ClangPathWatcherInterface &pathWatcher, - FilePathCachingInterface &filePathCache, - FileStatusCache &fileStatusCache, - Sqlite::TransactionInterface &transactionInterface, - ProjectPartsStorageInterface &projectPartsStorage, - ModifiedTimeCheckerInterface &modifiedTimeChecker, - const Environment &environment); - - void updateProjectParts(ProjectPartContainers &&projectParts); - void updateProjectPart(ProjectPartContainer &&projectPart); - - void pathsWithIdsChanged(const std::vector &idPaths) override; - void pathsChanged(const FilePathIds &filePathIds) override; - void updateChangedPath(FilePathId filePath, - std::vector &symbolIndexerTask); - - bool compilerMacrosOrIncludeSearchPathsAreDifferent( - const ProjectPartContainer &projectPart, - const Utils::optional &optionalArtefact) const; - - FilePathIds filterChangedFiles( - const ProjectPartContainer &projectPart) const; - - FilePathIds updatableFilePathIds(const ProjectPartContainer &projectPart, - const Utils::optional &optionalArtefact) const; - -private: - FilePathIds filterProjectPartSources(const FilePathIds &filePathIds) const; - -private: - SymbolIndexerTaskQueueInterface &m_symbolIndexerTaskQueue; - SymbolStorageInterface &m_symbolStorage; - BuildDependenciesStorageInterface &m_buildDependencyStorage; - PrecompiledHeaderStorageInterface &m_precompiledHeaderStorage; - ClangPathWatcherInterface &m_pathWatcher; - FilePathCachingInterface &m_filePathCache; - FileStatusCache &m_fileStatusCache; - Sqlite::TransactionInterface &m_transactionInterface; - ProjectPartsStorageInterface &m_projectPartsStorage; - ModifiedTimeCheckerInterface &m_modifiedTimeChecker; - const Environment &m_environment; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolindexertask.h b/src/tools/clangrefactoringbackend/source/symbolindexertask.h deleted file mode 100644 index 1695642522d..00000000000 --- a/src/tools/clangrefactoringbackend/source/symbolindexertask.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include -#include - -#include - -namespace Sqlite { -class TransactionInterface; -} - -namespace ClangBackEnd { - -class SymbolsCollectorInterface; -class SymbolStorageInterface; - -class SymbolIndexerTask -{ -public: - using Callable = std::function; - - SymbolIndexerTask(FilePathId filePathId, ProjectPartId projectPartId, Callable &&callable) - : callable(std::move(callable)) - , filePathId(filePathId) - , projectPartId(projectPartId) - { - } - - SymbolIndexerTask clone() const - { - return *this; - } - - friend - bool operator==(const SymbolIndexerTask &first, const SymbolIndexerTask &second) - { - return first.filePathId == second.filePathId && first.projectPartId == second.projectPartId; - } - - friend - bool operator<(const SymbolIndexerTask &first, const SymbolIndexerTask &second) - { - return std::tie(first.filePathId, first.projectPartId) - < std::tie(second.filePathId, second.projectPartId); - } - - operator Callable&&() - { - return std::move(callable); - } - -public: - Callable callable; - FilePathId filePathId; - ProjectPartId projectPartId; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolindexertaskqueue.h b/src/tools/clangrefactoringbackend/source/symbolindexertaskqueue.h deleted file mode 100644 index aa74fb833b7..00000000000 --- a/src/tools/clangrefactoringbackend/source/symbolindexertaskqueue.h +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "symbolindexertaskqueueinterface.h" -#include "symbolindexertask.h" - -#include -#include -#include -#include - -#include -#include - -#include -#include - -namespace ClangBackEnd { - -class SymbolsCollectorInterface; -class SymbolStorageInterface; - -class SymbolIndexerTaskQueue final : public SymbolIndexerTaskQueueInterface -{ -public: - using Task = SymbolIndexerTask::Callable; - - SymbolIndexerTaskQueue(TaskSchedulerInterface &symbolIndexerTaskScheduler, - ProgressCounter &progressCounter, - Sqlite::DatabaseInterface &database) - : m_symbolIndexerScheduler(symbolIndexerTaskScheduler) - , m_progressCounter(progressCounter) - , m_database(database) - {} - - void addOrUpdateTasks(std::vector &&tasks) override - { - auto merge = [] (SymbolIndexerTask &&first, SymbolIndexerTask &&second) { - first.callable = std::move(second.callable); - - return std::move(first); - }; - - const std::size_t oldSize = m_tasks.size(); - - m_tasks = Utils::setUnionMerge>(tasks, m_tasks, merge); - - m_progressCounter.addTotal(int(m_tasks.size() - oldSize)); - } - void removeTasks(const ProjectPartIds &projectPartIds) override - { - auto shouldBeRemoved = [&] (const SymbolIndexerTask& task) { - return std::binary_search(projectPartIds.begin(), projectPartIds.end(), task.projectPartId); - }; - - const std::size_t oldSize = m_tasks.size(); - - auto newEnd = std::remove_if(m_tasks.begin(), m_tasks.end(), shouldBeRemoved); - - m_tasks.erase(newEnd, m_tasks.end()); - - m_progressCounter.removeTotal(int(oldSize -m_tasks.size())); - } - - const std::vector &tasks() const - { - return m_tasks; - } - - void processEntries() override - { - auto slotUsage = m_symbolIndexerScheduler.slotUsage(); - uint taskCount = slotUsage.free; - - auto newEnd = std::prev(m_tasks.end(), std::min(int(taskCount), int(m_tasks.size()))); - m_symbolIndexerScheduler.addTasks({std::make_move_iterator(newEnd), - std::make_move_iterator(m_tasks.end())}); - m_tasks.erase(newEnd, m_tasks.end()); - - if (m_tasks.empty() && slotUsage.used == 0) { - try { - m_database.walCheckpointFull(); - } catch (Sqlite::Exception &exception) { - exception.printWarning(); - } - } - } - void syncTasks(); - -private: - std::vector m_projectPartIds; - std::vector m_tasks; - TaskSchedulerInterface &m_symbolIndexerScheduler; - ProgressCounter &m_progressCounter; - Sqlite::DatabaseInterface &m_database; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolindexertaskqueueinterface.h b/src/tools/clangrefactoringbackend/source/symbolindexertaskqueueinterface.h deleted file mode 100644 index 3c5bc3479f9..00000000000 --- a/src/tools/clangrefactoringbackend/source/symbolindexertaskqueueinterface.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include - -#include - -#include - -namespace ClangBackEnd { - -class SymbolIndexerTask; - -class SymbolIndexerTaskQueueInterface : public QueueInterface -{ -public: - virtual void addOrUpdateTasks(std::vector &&tasks) = 0 - /* [[expects: std::is_sorted(tasks)]] */; - virtual void removeTasks(const ProjectPartIds &projectPartIds) = 0 - /* [[expects: std::is_sorted(projectPartIds)]] */; - -protected: - ~SymbolIndexerTaskQueueInterface() = default; -}; -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolindexing.cpp b/src/tools/clangrefactoringbackend/source/symbolindexing.cpp deleted file mode 100644 index 529396e9fa1..00000000000 --- a/src/tools/clangrefactoringbackend/source/symbolindexing.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "symbolindexing.h" - -namespace ClangBackEnd { - -void SymbolIndexing::updateProjectParts(ProjectPartContainers &&projectParts) -{ - m_indexer.updateProjectParts(std::move(projectParts)); -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolindexing.h b/src/tools/clangrefactoringbackend/source/symbolindexing.h deleted file mode 100644 index e680a45be03..00000000000 --- a/src/tools/clangrefactoringbackend/source/symbolindexing.h +++ /dev/null @@ -1,157 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "symbolindexinginterface.h" - -#include "symbolindexer.h" -#include "symbolscollector.h" -#include "processormanager.h" -#include "symbolindexertaskqueue.h" -#include "taskscheduler.h" -#include "symbolstorage.h" - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -#include - -namespace ClangBackEnd { - -class SymbolsCollectorManager; -class RefactoringServer; - -class SymbolsCollectorManager final : public ClangBackEnd::ProcessorManager -{ -public: - using Processor = SymbolsCollector; - SymbolsCollectorManager(const ClangBackEnd::GeneratedFiles &generatedFiles, - FilePathCaching &filePathCache) - : ProcessorManager(generatedFiles) - , m_filePathCache(filePathCache) - {} - -protected: - std::unique_ptr createProcessor() const - { - return std::make_unique(m_filePathCache); - } - -private: - FilePathCaching &m_filePathCache; -}; - -class SymbolIndexing final : public SymbolIndexingInterface -{ -public: - using BuildDependenciesStorage = ClangBackEnd::BuildDependenciesStorage; - using SymbolStorage = ClangBackEnd::SymbolStorage; - SymbolIndexing(Sqlite::Database &database, - FilePathCaching &filePathCache, - const GeneratedFiles &generatedFiles, - ProgressCounter::SetProgressCallback &&setProgressCallback, - const Environment &environment) - : m_filePathCache(filePathCache) - , m_buildDependencyStorage(database) - , m_precompiledHeaderStorage(database) - , m_projectPartsStorage(database) - , m_symbolStorage(database) - , m_collectorManger(generatedFiles, filePathCache) - , m_progressCounter(std::move(setProgressCallback)) - , m_indexer(m_indexerQueue, - m_symbolStorage, - m_buildDependencyStorage, - m_precompiledHeaderStorage, - m_sourceWatcher, - m_filePathCache, - m_fileStatusCache, - m_symbolStorage.database, - m_projectPartsStorage, - m_modifiedTimeChecker, - environment) - , m_indexerQueue(m_indexerScheduler, m_progressCounter, database) - , m_indexerScheduler(m_collectorManger, - m_indexerQueue, - m_progressCounter, - std::thread::hardware_concurrency(), - CallDoInMainThreadAfterFinished::Yes) - { - } - - ~SymbolIndexing() - { - syncTasks(); - } - - SymbolIndexer &indexer() - { - return m_indexer; - } - - void syncTasks() - { - m_indexerScheduler.disable(); - while (!m_indexerScheduler.futures().empty()) { - m_indexerScheduler.syncTasks(); - m_indexerScheduler.slotUsage(); - } - } - - void updateProjectParts(ProjectPartContainers &&projectParts) override; - -private: - using SymbolIndexerTaskScheduler = TaskScheduler; - FilePathCachingInterface &m_filePathCache; - BuildDependenciesStorage m_buildDependencyStorage; - PrecompiledHeaderStorage m_precompiledHeaderStorage; - ProjectPartsStorage m_projectPartsStorage; - SymbolStorage m_symbolStorage; - FileSystem m_fileSytem{m_filePathCache}; - ClangPathWatcher m_sourceWatcher{m_filePathCache, m_fileSytem}; - FileStatusCache m_fileStatusCache{m_fileSytem}; - SymbolsCollectorManager m_collectorManger; - ProgressCounter m_progressCounter; - ModifiedTimeChecker m_modifiedTimeChecker{m_fileSytem}; - SymbolIndexer m_indexer; - SymbolIndexerTaskQueue m_indexerQueue; - SymbolIndexerTaskScheduler m_indexerScheduler; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolindexinginterface.h b/src/tools/clangrefactoringbackend/source/symbolindexinginterface.h deleted file mode 100644 index 3feb9e1b9f7..00000000000 --- a/src/tools/clangrefactoringbackend/source/symbolindexinginterface.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include -#include - -namespace ClangBackEnd { - -class SymbolIndexingInterface -{ -public: - SymbolIndexingInterface() = default; - SymbolIndexingInterface(const SymbolIndexingInterface&) = delete; - SymbolIndexingInterface &operator=(const SymbolIndexingInterface&) = delete; - - virtual void updateProjectParts(ProjectPartContainers &&projectParts) = 0; - -protected: - ~SymbolIndexingInterface() = default; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolscollector.cpp b/src/tools/clangrefactoringbackend/source/symbolscollector.cpp deleted file mode 100644 index 8e01869b1d9..00000000000 --- a/src/tools/clangrefactoringbackend/source/symbolscollector.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "symbolscollector.h" - -#include -#include -#include - -namespace ClangBackEnd { - -SymbolsCollector::SymbolsCollector(FilePathCaching &filePathCache) - : m_filePathCache(filePathCache) - , m_indexDataConsumer(std::make_shared(m_symbolEntries, - m_sourceLocationEntries, - m_filePathCache, - m_symbolSourcesManager, - m_macroSourcesManager)) - , m_collectSymbolsAction(m_indexDataConsumer) -{ -} - -void SymbolsCollector::addFiles(const FilePathIds &filePathIds, - const Utils::SmallStringVector &arguments) -{ - m_clangTool.addFiles(m_filePathCache.filePaths(filePathIds), arguments); -} - -void SymbolsCollector::setFile(FilePathId filePathId, const Utils::SmallStringVector &arguments) -{ - addFiles({filePathId}, arguments); -} - -void SymbolsCollector::setUnsavedFiles(const V2::FileContainers &unsavedFiles) -{ - m_clangTool.addUnsavedFiles(unsavedFiles); -} - -void SymbolsCollector::clear() -{ - m_symbolEntries.clear(); - m_sourceLocationEntries.clear(); - m_clangTool = ClangTool(); -} - -std::unique_ptr newFrontendActionFactory(CollectSymbolsAction *action) -{ - class FrontendActionFactoryAdapter : public clang::tooling::FrontendActionFactory - { - public: - explicit FrontendActionFactoryAdapter(CollectSymbolsAction *consumerFactory) - : m_action(consumerFactory) - {} - - std::unique_ptr create() override { return std::make_unique(m_action); } - - private: - class AdaptorAction : public clang::ASTFrontendAction - { - public: - AdaptorAction(CollectSymbolsAction *action) - : m_action(action) - {} - - std::unique_ptr CreateASTConsumer(clang::CompilerInstance &instance, - llvm::StringRef inFile) override - { - return m_action->newASTConsumer(instance, inFile); - } - - bool BeginInvocation(clang::CompilerInstance &instance) override - { - return m_action->BeginInvocation(instance); - } - bool BeginSourceFileAction(clang::CompilerInstance &instance) override - { - return m_action->BeginSourceFileAction(instance); - } - - bool PrepareToExecuteAction(clang::CompilerInstance &instance) override - { - return m_action->PrepareToExecuteAction(instance); - } - void ExecuteAction() override { m_action->ExecuteAction(); } - void EndSourceFileAction() override { m_action->EndSourceFileAction(); } - - bool hasPCHSupport() const override { return m_action->hasPCHSupport(); } - bool hasASTFileSupport() const override { return m_action->hasASTFileSupport(); } - bool hasIRSupport() const override { return false; } - bool hasCodeCompletionSupport() const override { return false; } - - private: - CollectSymbolsAction *m_action; - }; - CollectSymbolsAction *m_action; - }; - - return std::unique_ptr( - new FrontendActionFactoryAdapter(action)); -} - -bool SymbolsCollector::collectSymbols() -{ - auto tool = m_clangTool.createTool(); - - auto actionFactory = ClangBackEnd::newFrontendActionFactory(&m_collectSymbolsAction); - - bool noErrors = tool.run(actionFactory.get()) != 1; - - m_clangTool = ClangTool(); - - return noErrors; -} - -void SymbolsCollector::doInMainThreadAfterFinished() -{ -} - -const SymbolEntries &SymbolsCollector::symbols() const -{ - return m_symbolEntries; -} - -const SourceLocationEntries &SymbolsCollector::sourceLocations() const -{ - return m_sourceLocationEntries; -} - -bool SymbolsCollector::isUsed() const -{ - return m_isUsed; -} - -void SymbolsCollector::setIsUsed(bool isUsed) -{ - m_isUsed = isUsed; -} - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolscollector.h b/src/tools/clangrefactoringbackend/source/symbolscollector.h deleted file mode 100644 index 824fe057fd8..00000000000 --- a/src/tools/clangrefactoringbackend/source/symbolscollector.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "clangtool.h" -#include "collectmacrossourcefilecallbacks.h" -#include "collectsymbolsaction.h" -#include "sourcesmanager.h" -#include "symbolscollectorinterface.h" - -#include - -namespace Sqlite { -class Database; -} - -namespace ClangBackEnd { - -class SymbolsCollector final : public SymbolsCollectorInterface -{ -public: - SymbolsCollector(FilePathCaching &filePathCache); - - void addFiles(const FilePathIds &filePathIds, - const Utils::SmallStringVector &arguments); - void setFile(FilePathId filePathId, const Utils::SmallStringVector &arguments) override; - - void setUnsavedFiles(const V2::FileContainers &unsavedFiles) override; - - void clear() override; - - bool collectSymbols() override; - - void doInMainThreadAfterFinished() override; - - const SymbolEntries &symbols() const override; - const SourceLocationEntries &sourceLocations() const override; - - bool isUsed() const override; - void setIsUsed(bool isUsed) override; - - bool isClean() const { return m_clangTool.isClean(); } - -private: - CopyableFilePathCaching m_filePathCache; - ClangTool m_clangTool; - SymbolEntries m_symbolEntries; - SourceLocationEntries m_sourceLocationEntries; - std::shared_ptr m_indexDataConsumer; - CollectSymbolsAction m_collectSymbolsAction; - SourcesManager m_symbolSourcesManager; - SourcesManager m_macroSourcesManager; - bool m_isUsed = false; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h b/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h deleted file mode 100644 index d90d4db5286..00000000000 --- a/src/tools/clangrefactoringbackend/source/symbolscollectorinterface.h +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "filestatus.h" -#include "symbolentry.h" -#include "sourcedependency.h" -#include "sourcelocationentry.h" -#include "usedmacro.h" - -#include - -#include - -#include -#include - -namespace ClangBackEnd { - -class SymbolsCollectorInterface : public ProcessorInterface -{ -public: - virtual void setFile(FilePathId filePathId, const Utils::SmallStringVector &arguments) = 0; - virtual bool collectSymbols() = 0; - - virtual const SymbolEntries &symbols() const = 0; - virtual const SourceLocationEntries &sourceLocations() const = 0; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolstorage.h b/src/tools/clangrefactoringbackend/source/symbolstorage.h deleted file mode 100644 index bc2d96b5f18..00000000000 --- a/src/tools/clangrefactoringbackend/source/symbolstorage.h +++ /dev/null @@ -1,198 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "symbolstorageinterface.h" - -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -namespace ClangBackEnd { - -template -class SymbolStorage final : public SymbolStorageInterface -{ - using Database = DatabaseType; - template - using ReadStatement = typename Database::template ReadStatement; - using WriteStatement = typename Database::WriteStatement; - -public: - SymbolStorage(Database &database) - : transaction(database) - , database(database) - { - transaction.commit(); - database.walCheckpointFull(); - } - - void addSymbolsAndSourceLocations(const SymbolEntries &symbolEntries, - const SourceLocationEntries &sourceLocations) override - { - fillTemporarySymbolsTable(symbolEntries); - fillTemporaryLocationsTable(sourceLocations); - addNewSymbolsToSymbols(); - syncNewSymbolsFromSymbols(); - syncSymbolsIntoNewLocations(); - deleteAllLocationsFromUpdatedFiles(); - insertNewLocationsInLocations(); - deleteNewSymbolsTable(); - deleteNewLocationsTable(); - } - - void fillTemporarySymbolsTable(const SymbolEntries &symbolEntries) - { - WriteStatement &statement = insertSymbolsToNewSymbolsStatement; - - for (const auto &symbolEntry : symbolEntries) { - statement.write(symbolEntry.first, - symbolEntry.second.usr, - symbolEntry.second.symbolName, - static_cast(symbolEntry.second.symbolKind)); - } - } - - void fillTemporaryLocationsTable(const SourceLocationEntries &sourceLocations) - { - WriteStatement &statement = insertLocationsToNewLocationsStatement; - - for (const auto &locationEntry : sourceLocations) { - statement.write(locationEntry.symbolId, - locationEntry.lineColumn.line, - locationEntry.lineColumn.column, - locationEntry.filePathId.filePathId, - int(locationEntry.kind)); - } - } - - void addNewSymbolsToSymbols() { addNewSymbolsToSymbolsStatement.execute(); } - - void syncNewSymbolsFromSymbols() { syncNewSymbolsFromSymbolsStatement.execute(); } - - void syncSymbolsIntoNewLocations() { syncSymbolsIntoNewLocationsStatement.execute(); } - - void deleteAllLocationsFromUpdatedFiles() - { - deleteAllLocationsFromUpdatedFilesStatement.execute(); - } - - void insertNewLocationsInLocations() { insertNewLocationsInLocationsStatement.execute(); } - - void deleteNewSymbolsTable() { deleteNewSymbolsTableStatement.execute(); } - - void deleteNewLocationsTable() { deleteNewLocationsTableStatement.execute(); } - - SourceLocationEntries sourceLocations() const - { - return SourceLocationEntries(); - } - - Sqlite::Table createNewSymbolsTable() const - { - Sqlite::Table table; - table.setName("newSymbols"); - table.setUseTemporaryTable(true); - table.addColumn("temporarySymbolId", Sqlite::ColumnType::Integer, {Sqlite::PrimaryKey{}}); - const Sqlite::Column &symbolIdColumn = table.addColumn("symbolId", Sqlite::ColumnType::Integer); - const Sqlite::Column &usrColumn = table.addColumn("usr", Sqlite::ColumnType::Text); - const Sqlite::Column &symbolNameColumn = table.addColumn("symbolName", Sqlite::ColumnType::Text); - table.addColumn("symbolKind", Sqlite::ColumnType::Integer); - table.addIndex({usrColumn, symbolNameColumn}); - table.addIndex({symbolIdColumn}); - - table.initialize(database); - - return table; - } - - Sqlite::Table createNewLocationsTable() const - { - Sqlite::Table table; - table.setName("newLocations"); - table.setUseTemporaryTable(true); - table.addColumn("temporarySymbolId", Sqlite::ColumnType::Integer); - table.addColumn("symbolId", Sqlite::ColumnType::Integer); - const Sqlite::Column &sourceIdColumn = table.addColumn("sourceId", Sqlite::ColumnType::Integer); - const Sqlite::Column &lineColumn = table.addColumn("line", Sqlite::ColumnType::Integer); - const Sqlite::Column &columnColumn = table.addColumn("column", Sqlite::ColumnType::Integer); - table.addColumn("locationKind", Sqlite::ColumnType::Integer); - table.addUniqueIndex({sourceIdColumn, lineColumn, columnColumn}); - - table.initialize(database); - - return table; - } - -public: - Sqlite::ImmediateNonThrowingDestructorTransaction transaction; - Database &database; - Sqlite::Table newSymbolsTablet{createNewSymbolsTable()}; - Sqlite::Table newLocationsTable{createNewLocationsTable()}; - WriteStatement insertSymbolsToNewSymbolsStatement{ - "INSERT INTO newSymbols(temporarySymbolId, usr, symbolName, symbolKind) VALUES(?,?,?,?)", - database}; - WriteStatement insertLocationsToNewLocationsStatement{ - "INSERT OR IGNORE INTO newLocations(temporarySymbolId, line, column, sourceId, " - "locationKind) VALUES(?,?,?,?,?)", - database}; - ReadStatement<1> selectNewSourceIdsStatement{ - "SELECT DISTINCT sourceId FROM newLocations WHERE NOT EXISTS (SELECT sourceId FROM sources " - "WHERE newLocations.sourceId == sources.sourceId)", - database}; - WriteStatement addNewSymbolsToSymbolsStatement{ - "INSERT INTO symbols(usr, symbolName, symbolKind) " - "SELECT usr, symbolName, symbolKind FROM newSymbols WHERE NOT EXISTS " - "(SELECT usr FROM symbols WHERE symbols.usr == newSymbols.usr)", - database}; - WriteStatement syncNewSymbolsFromSymbolsStatement{ - "UPDATE newSymbols SET symbolId = (SELECT symbolId FROM symbols WHERE newSymbols.usr = " - "symbols.usr)", - database}; - WriteStatement syncSymbolsIntoNewLocationsStatement{ - "UPDATE newLocations SET symbolId = (SELECT symbolId FROM newSymbols WHERE " - "newSymbols.temporarySymbolId = newLocations.temporarySymbolId)", - database}; - WriteStatement deleteAllLocationsFromUpdatedFilesStatement{ - "DELETE FROM locations WHERE sourceId IN (SELECT DISTINCT sourceId FROM newLocations)", - database}; - WriteStatement insertNewLocationsInLocationsStatement{ - "INSERT INTO locations(symbolId, line, column, sourceId, locationKind) SELECT symbolId, " - "line, column, sourceId, locationKind FROM newLocations", - database}; - WriteStatement deleteNewSymbolsTableStatement{"DELETE FROM newSymbols", database}; - WriteStatement deleteNewLocationsTableStatement{"DELETE FROM newLocations", database}; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolstorageinterface.h b/src/tools/clangrefactoringbackend/source/symbolstorageinterface.h deleted file mode 100644 index 1d0328e9f82..00000000000 --- a/src/tools/clangrefactoringbackend/source/symbolstorageinterface.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "sourcelocationentry.h" -#include "symbolentry.h" - -#include -#include - -#include -#include - -#include - -namespace ClangBackEnd { - -class SymbolStorageInterface -{ -public: - SymbolStorageInterface() = default; - SymbolStorageInterface(const SymbolStorageInterface &) = delete; - SymbolStorageInterface &operator=(const SymbolStorageInterface &) = delete; - - virtual void addSymbolsAndSourceLocations(const SymbolEntries &symbolEntries, - const SourceLocationEntries &sourceLocations) - = 0; - -protected: - ~SymbolStorageInterface() = default; -}; - -} // namespace ClangBackEnd diff --git a/src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h b/src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h deleted file mode 100644 index d5a609315ec..00000000000 --- a/src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h +++ /dev/null @@ -1,163 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "sourcelocationsutils.h" -#include "sourcesmanager.h" -#include "symbolentry.h" - -#include - -#include -#include - -#include -#include -#include -#include -#include - -namespace ClangBackEnd { - -class SymbolsVisitorBase -{ -public: - SymbolsVisitorBase(const FilePathCachingInterface &filePathCache, - const clang::SourceManager *sourceManager, - FilePathIds &filePathIndices) - : m_filePathCache(filePathCache) - , m_sourceManager(sourceManager) - , m_filePathIndices(filePathIndices) - {} - - FilePathId filePathId(clang::SourceLocation sourceLocation) - { - clang::FileID clangFileId = m_sourceManager->getFileID(sourceLocation); - const clang::FileEntry *fileEntry = m_sourceManager->getFileEntryForID(clangFileId); - - return filePathId(fileEntry); - } - - FilePathId filePathId(const clang::FileEntry *fileEntry) - { - if (fileEntry) { - uint fileId = fileEntry->getUID(); - - if (fileId >= m_filePathIndices.size()) - m_filePathIndices.resize(fileId + 1); - - FilePathId &filePathId = m_filePathIndices[fileId]; - - if (filePathId.isValid()) - return filePathId; - - auto filePath = fileEntry->getName(); - FilePathId newFilePathId = m_filePathCache.filePathId(FilePath::fromNativeFilePath(absolutePath(filePath))); - - filePathId = newFilePathId; - - return newFilePathId; - } - - return {}; - } - - Utils::LineColumn lineColum(clang::SourceLocation sourceLocation) - { - return {int(m_sourceManager->getSpellingLineNumber(sourceLocation)), - int(m_sourceManager->getSpellingColumnNumber(sourceLocation))}; - } - - static Utils::optional generateUSR(const clang::Decl *declaration) - { - llvm::SmallVector usr; - - Utils::optional usrOptional; - - bool wasNotWorking = clang::index::generateUSRForDecl(declaration, usr); - - if (!wasNotWorking) - usrOptional.emplace(usr.data(), usr.size()); - - return usrOptional; - } - - Utils::optional generateUSR(clang::StringRef macroName, - clang::SourceLocation sourceLocation) - { - llvm::SmallVector usr; - - Utils::optional usrOptional; - - bool wasNotWorking = clang::index::generateUSRForMacro(macroName, - sourceLocation, - *m_sourceManager, - usr); - - if (!wasNotWorking) - usrOptional.emplace(usr.data(), usr.size()); - - return usrOptional; - } - - static SymbolIndex toSymbolIndex(const void *pointer) - { - return SymbolIndex(reinterpret_cast(pointer)); - } - - void setSourceManager(clang::SourceManager *sourceManager) - { - m_sourceManager = sourceManager; - } - - bool isInSystemHeader(clang::FileID fileId) const - { - return isSystem(m_sourceManager->getSLocEntry(fileId).getFile().getFileCharacteristic()); - } - - bool isInSystemHeader(clang::SourceLocation sourceLocation) const - { - return m_sourceManager->isInSystemHeader(sourceLocation); - } - - static - bool isSystem(clang::SrcMgr::CharacteristicKind kind) - { - return clang::SrcMgr::isSystem(kind); - } - - const FilePathCachingInterface &filePathCache() const { return m_filePathCache; } - const clang::SourceManager *sourceManager() const { return m_sourceManager; } - -protected: - const FilePathCachingInterface &m_filePathCache; - const clang::SourceManager *m_sourceManager = nullptr; - -private: - FilePathIds &m_filePathIndices; -}; - -} // namespace ClangBackend diff --git a/src/tools/clangrefactoringbackend/source/usedmacro.h b/src/tools/clangrefactoringbackend/source/usedmacro.h deleted file mode 100644 index 8fc992e39b1..00000000000 --- a/src/tools/clangrefactoringbackend/source/usedmacro.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include - -#include - -#include - -namespace ClangBackEnd { - -class UsedMacro -{ -public: - constexpr UsedMacro() = default; - UsedMacro(Utils::SmallStringView macroName, FilePathId filePathId) - : macroName(macroName), - filePathId(filePathId) - {} - - UsedMacro(Utils::SmallStringView macroName, int filePathId) - : macroName(macroName), - filePathId(filePathId) - {} - - friend bool operator<(const UsedMacro &first, const UsedMacro &second) - { - return std::tie(first.filePathId, first.macroName) - < std::tie(second.filePathId, second.macroName); - } - - friend bool operator==(const UsedMacro &first, const UsedMacro &second) - { - return first.filePathId == second.filePathId && first.macroName == second.macroName; - } - - friend bool operator!=(const UsedMacro &first, const UsedMacro &second) - { - return !(first == second); - } - - operator Utils::SmallStringView() const { return macroName; } - operator const Utils::SmallString &() const { return macroName; } - -public: - Utils::SmallString macroName; - FilePathId filePathId; -}; - -using UsedMacros = std::vector; - -} // ClangBackEnd diff --git a/src/tools/tools.pro b/src/tools/tools.pro index b2ef50b040c..5bfe2195f41 100644 --- a/src/tools/tools.pro +++ b/src/tools/tools.pro @@ -27,12 +27,6 @@ mac { SUBDIRS += clangbackend -QTC_ENABLE_CLANG_REFACTORING=$$(QTC_ENABLE_CLANG_REFACTORING) -!isEmpty(QTC_ENABLE_CLANG_REFACTORING) { - SUBDIRS += clangrefactoringbackend - SUBDIRS += clangpchmanagerbackend -} - isEmpty(BUILD_CPLUSPLUS_TOOLS):BUILD_CPLUSPLUS_TOOLS=$$(BUILD_CPLUSPLUS_TOOLS) !isEmpty(BUILD_CPLUSPLUS_TOOLS) { SUBDIRS += cplusplus-ast2png \ diff --git a/src/tools/tools.qbs b/src/tools/tools.qbs index 6a30971da3d..36ced1a132d 100644 --- a/src/tools/tools.qbs +++ b/src/tools/tools.qbs @@ -6,8 +6,6 @@ Project { references: [ "buildoutputparser/buildoutputparser.qbs", "clangbackend/clangbackend.qbs", - "clangpchmanagerbackend/clangpchmanagerbackend.qbs", - "clangrefactoringbackend/clangrefactoringbackend.qbs", "cplusplustools.qbs", "qml2puppet/qml2puppet.qbs", "qtcdebugger/qtcdebugger.qbs", diff --git a/tests/unit/unittest/CMakeLists.txt b/tests/unit/unittest/CMakeLists.txt index c600016cf60..4bc5c1fc04f 100644 --- a/tests/unit/unittest/CMakeLists.txt +++ b/tests/unit/unittest/CMakeLists.txt @@ -37,15 +37,8 @@ add_qtc_test(unittest GTEST CPPTOOLS_JSON="${CMAKE_CURRENT_BINARY_DIR}/CppTools.json" SOURCES abstractviewmock.h - builddependenciesprovider-test.cpp - builddependenciesstorage-test.cpp - clangindexingsettingsmanager-test.cpp - clangpathwatcher-test.cpp - clangqueryexamplehighlightmarker-test.cpp - clangqueryhighlightmarker-test.cpp clientserverinprocess-test.cpp clientserveroutsideprocess-test.cpp - commandlinebuilder-test.cpp compare-operators.h compileroptionsbuilder-test.cpp conditionally-disabled-tests.h @@ -56,14 +49,7 @@ add_qtc_test(unittest GTEST dynamicastmatcherdiagnosticcontainer-matcher.h eventspy.cpp eventspy.h fakeprocess.cpp fakeprocess.h - filepathcache-test.cpp - filepathstoragesqlitestatementfactory-test.cpp - filepathstorage-test.cpp - filepath-test.cpp - filepathview-test.cpp - filestatuscache-test.cpp filesystem-utilities.h - generatedfiles-test.cpp googletest.h google-using-declarations.h gtest-creator-printing.cpp gtest-creator-printing.h @@ -73,102 +59,36 @@ add_qtc_test(unittest GTEST headerpathfilter-test.cpp highlightingresultreporter-test.cpp lineprefixer-test.cpp - locatorfilter-test.cpp matchingtext-test.cpp mimedatabase-utilities.cpp mimedatabase-utilities.h - mockbuilddependenciesprovider.h - mockbuilddependenciesstorage.h - mockbuilddependencygenerator.h mockclangcodemodelclient.h mockclangcodemodelserver.h - mockclangpathwatcher.h - mockclangpathwatchernotifier.h mockcppmodelmanager.h - mockeditormanager.h - mockfilepathcaching.h - mockfilepathstorage.h mockfutureinterface.h - mockgeneratedfiles.h - mockmodifiedtimechecker.h mockmutex.h - mockpchcreator.h - mockpchmanagerclient.h - mockpchmanagernotifier.h - mockpchmanagerserver.h - mockpchtaskgenerator.h - mockpchtaskqueue.h - mockpchtasksmerger.h - mockprecompiledheaderstorage.h - mockprocessor.h - mockprocessormanager.h - mockprogressmanager.h - mockprojectpartprovider.h - mockprojectpartqueue.h - mockprojectpartsmanager.h - mockprojectpartsstorage.h mockqfilesystemwatcher.h mockqueue.h - mocksearch.h - mocksearchhandle.h - mocksearchresult.h mocksqlitestatement.h mocksqlitetransactionbackend.h - mocksymbolindexertaskqueue.h - mocksymbolindexing.h - mocksymbolquery.h - mocksymbolscollector.h - mocksymbolstorage.h mocksyntaxhighligher.h - mocktaskscheduler.h mocktimer.cpp mocktimer.h - modifiedtimechecker-test.cpp - nativefilepath-test.cpp - nativefilepathview-test.cpp nodelistproperty-test.cpp - pchmanagerclientserverinprocess-test.cpp - pchmanagerclient-test.cpp - pchmanagerserver-test.cpp - pchtaskgenerator-test.cpp - pchtaskqueue-test.cpp - pchtasksmerger-test.cpp - precompiledheaderstorage-test.cpp - preprocessormacrocollector-test.cpp processcreator-test.cpp processevents-utilities.cpp processevents-utilities.h - processormanager-test.cpp - progresscounter-test.cpp - projectpartartefact-test.cpp - projectpartsmanager-test.cpp - projectpartsstorage-test.cpp - projectupdater-test.cpp readandwritemessageblock-test.cpp - refactoringdatabaseinitializer-test.cpp - refactoringprojectupdater-test.cpp rundocumentparse-utility.h sizedarray-test.cpp smallstring-test.cpp sourcerangecontainer-matcher.h - sourcerangefilter-test.cpp - sourcesmanager-test.cpp spydummy.cpp spydummy.h sqlitealgorithms-test.cpp sqliteindex-test.cpp sqliteteststatement.h sqlitetransaction-test.cpp - stringcache-test.cpp - symbolindexertaskqueue-test.cpp - symbolindexer-test.cpp - symbolquery-test.cpp - symbolsfindfilter-test.cpp - symbolstorage-test.cpp task.cpp - taskscheduler-test.cpp - testenvironment.h tokenprocessor-test.cpp - toolchainargumentscache-test.cpp unittests-main.cpp unittest-utility-functions.h - usedmacrofilter-test.cpp utf8-test.cpp sqlitecolumn-test.cpp sqlitedatabasebackend-test.cpp @@ -219,7 +139,7 @@ function(extend_qtc_test_with_target_sources target) ) endfunction() -foreach(clang_tools_library clangrefactoringbackend_lib clangbackend_lib clangpchmanagerbackend_lib) +foreach(clang_tools_library clangbackend_lib) extend_qtc_test_with_target_sources(${clang_tools_library} DEFINES CLANGSUPPORT_BUILD_LIB @@ -258,6 +178,7 @@ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CppTools.json" ${plugin_json_in}) extend_qtc_test(unittest CONDITION TARGET libclang INCLUDES "${CLANG_INCLUDE_DIRS}" + DEFINES CLANG_UNIT_TESTS DEPENDS libclang SOURCES activationsequencecontextprocessor-test.cpp @@ -298,6 +219,7 @@ extend_qtc_test(unittest diagnosticset-test.cpp diagnostic-test.cpp fixit-test.cpp + gtest-clang-printing.cpp gtest-clang-printing.h senddocumenttracker-test.cpp skippedsourceranges-test.cpp sourcelocation-test.cpp @@ -305,7 +227,6 @@ extend_qtc_test(unittest token-test.cpp translationunitupdater-test.cpp unsavedfiles-test.cpp - unsavedfile-test.cpp utf8positionfromlinecolumn-test.cpp chunksreportedmonitor.h clangasyncjob-base.h @@ -313,32 +234,6 @@ extend_qtc_test(unittest diagnosticcontainer-matcher.h ) -extend_qtc_test(unittest - CONDITION TARGET clangTooling - DEFINES CLANG_UNIT_TESTS - DEPENDS clangTooling clangIndex clangQuery - SOURCES - gtest-llvm-printing.cpp - clangquerygatherer-test.cpp - clangqueryprojectfindfilter-test.cpp - clangquery-test.cpp - gtest-clang-printing.cpp gtest-clang-printing.h - pchcreator-test.cpp - refactoringclientserverinprocess-test.cpp - refactoringclient-test.cpp - refactoringcompilationdatabase-test.cpp - refactoringengine-test.cpp - refactoringserver-test.cpp - sourcerangeextractor-test.cpp - symbolindexing-test.cpp - symbolscollector-test.cpp - testclangtool.cpp testclangtool.h - usedmacrocollector-test.cpp - builddependencycollector-test.cpp - mockrefactoringclient.h - mockrefactoringserver.h -) - extend_qtc_test(unittest CONDITION TARGET ClangFormat DEPENDS clangFormat @@ -358,8 +253,6 @@ finalize_qtc_gtest(unittest ".c$") # Path needs to be before CppTools target_include_directories(unittest PRIVATE - BEFORE $ - BEFORE ../../../src/plugins/clangrefactoring BEFORE ../../../src/plugins ) @@ -502,46 +395,6 @@ extend_qtc_test(unittest projectmacro.cpp projectmacro.h ) -extend_qtc_test(unittest - SOURCES_PREFIX ../../../src/plugins/clangrefactoring - SOURCES - clangqueryexamplehighlighter.cpp clangqueryexamplehighlighter.h - clangqueryexamplehighlightmarker.h - clangqueryhighlighter.cpp clangqueryhighlighter.h - clangqueryhighlightmarker.h - clangqueryprojectsfindfilter.cpp clangqueryprojectsfindfilter.h - projectpartutilities.cpp projectpartutilities.h - refactoringclient.cpp refactoringclient.h - refactoringconnectionclient.cpp refactoringconnectionclient.h - refactoringengine.cpp refactoringengine.h - refactoringprojectupdater.cpp refactoringprojectupdater.h - searchinterface.h - searchhandle.cpp searchhandle.h - clangsymbolsfindfilter.cpp clangsymbolsfindfilter.h - symbolqueryinterface.h - symbol.h - projectpartproviderinterface.h - editormanagerinterface.h - locatorfilter.cpp locatorfilter.h -) - -extend_qtc_test(unittest - SOURCES_PREFIX ../../../src/plugins/clangpchmanager - DEFINES CLANGPCHMANAGER_STATIC_LIB - SOURCES - clangindexingprojectsettings.cpp clangindexingprojectsettings.h - clangindexingsettingsmanager.cpp clangindexingsettingsmanager.h - pchmanagerclient.h pchmanagerclient.cpp - pchmanagernotifierinterface.h pchmanagernotifierinterface.cpp - pchmanagerconnectionclient.h pchmanagerconnectionclient.cpp - clangpchmanager_global.h - preprocessormacrocollector.cpp preprocessormacrocollector.h - projectupdater.h projectupdater.cpp - pchmanagerprojectupdater.h pchmanagerprojectupdater.cpp - progressmanager.h - progressmanagerinterface.h -) - extend_qtc_test(unittest SOURCES_PREFIX_FROM_TARGET ClangFormat DEFINES CLANGPCHMANAGER_STATIC_LIB diff --git a/tests/unit/unittest/builddependenciesprovider-test.cpp b/tests/unit/unittest/builddependenciesprovider-test.cpp deleted file mode 100644 index 69bc966c08a..00000000000 --- a/tests/unit/unittest/builddependenciesprovider-test.cpp +++ /dev/null @@ -1,274 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockbuilddependenciesstorage.h" -#include "mockmodifiedtimechecker.h" -#include "mockbuilddependencygenerator.h" -#include "mocksqlitetransactionbackend.h" - -#include - -namespace { - -using ClangBackEnd::BuildDependencies; -using ClangBackEnd::BuildDependency; -using ClangBackEnd::FilePathId; -using ClangBackEnd::FilePathIds; -using ClangBackEnd::ProjectPartId; -using ClangBackEnd::SourceEntries; -using ClangBackEnd::SourceEntry; -using ClangBackEnd::SourceType; -using ClangBackEnd::UsedMacro; -using ClangBackEnd::UsedMacros; - -MATCHER_P(HasSourceId, sourceId, std::string(negation ? "hasn't" : "has") - + " sourceId " + PrintToString(sourceId)) -{ - const SourceEntry & sourceEntry = arg; - - return sourceEntry.sourceId.filePathId == sourceId; -} - -class BuildDependenciesProvider : public testing::Test -{ -protected: - BuildDependenciesProvider() - { - provider.setEnsureAliveMessageIsSentCallback( - mockEnsureAliveMessageIsSentCallback.AsStdFunction()); - } - -protected: - NiceMock> mockEnsureAliveMessageIsSentCallback; - NiceMock mockSqliteTransactionBackend; - NiceMock mockBuildDependenciesStorage; - NiceMock mockModifiedTimeChecker; - NiceMock mockBuildDependenciesGenerator; - ClangBackEnd::BuildDependenciesProvider provider{mockBuildDependenciesStorage, - mockModifiedTimeChecker, - mockBuildDependenciesGenerator, - mockSqliteTransactionBackend}; - ClangBackEnd::ProjectPartContainer projectPart1{ - 1, - {"--yi"}, - {{"YI", "1", 1}}, - {{"/includes", 1, ClangBackEnd::IncludeSearchPathType::BuiltIn}}, - {{"/project/yi", 1, ClangBackEnd::IncludeSearchPathType::User}}, - {1}, - {2}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::All}; - ClangBackEnd::ProjectPartContainer projectPart2{ - 2, - {"--er"}, - {{"ER", "2", 1}}, - {{"/includes", 1, ClangBackEnd::IncludeSearchPathType::BuiltIn}}, - {{"/project/er", 1, ClangBackEnd::IncludeSearchPathType::User}}, - {1}, - {2, 3, 4}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::All}; - SourceEntries firstSources{{1, SourceType::UserInclude, 1}, - {2, SourceType::UserInclude, 1}, - {10, SourceType::UserInclude, 1}}; - SourceEntries secondSources{{1, SourceType::UserInclude, 1}, - {3, SourceType::UserInclude, 1}, - {8, SourceType::UserInclude, 1}}; - SourceEntries thirdSources{{4, SourceType::UserInclude, 1}, - {8, SourceType::UserInclude, 1}, - {10, SourceType::UserInclude, 1}}; - UsedMacros firstUsedMacros{{"YI", 1}}; - UsedMacros secondUsedMacros{{"LIANG", 2}, {"ER", 2}}; - UsedMacros thirdUsedMacros{{"SAN", 10}}; - FilePathIds sourceFiles{1, 3, 8}; - ClangBackEnd::SourceDependencies sourceDependencies{{1, 3}, {1, 8}}; - ClangBackEnd::FileStatuses fileStatuses{{1, 21, 12}, {3, 21, 12}, {8, 21, 12}}; - BuildDependency buildDependency{ - secondSources, - secondUsedMacros, - sourceFiles, - sourceDependencies, - fileStatuses - }; -}; - -TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromStorageIfTimeStampsAreUpToDate) -{ - InSequence s; - - EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin()); - EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, {1})) - .WillRepeatedly(Return(firstSources)); - EXPECT_CALL(mockSqliteTransactionBackend, commit()); - EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(true)); - EXPECT_CALL(mockBuildDependenciesGenerator, create(projectPart1)).Times(0); - EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0); - EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0); - EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin()); - EXPECT_CALL(mockSqliteTransactionBackend, commit()); - - provider.create(projectPart1); -} - -TEST_F(BuildDependenciesProvider, FetchDependSourcesFromStorage) -{ - ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, {2})).WillByDefault(Return(firstSources)); - ON_CALL(mockBuildDependenciesStorage, fetchDependSources({3}, {2})) - .WillByDefault(Return(secondSources)); - ON_CALL(mockBuildDependenciesStorage, fetchDependSources({4}, {2})).WillByDefault(Return(thirdSources)); - ON_CALL(mockModifiedTimeChecker, isUpToDate(_)).WillByDefault(Return(true)); - - auto buildDependency = provider.create(projectPart2); - - ASSERT_THAT(buildDependency.sources, - ElementsAre(HasSourceId(1), - HasSourceId(2), - HasSourceId(3), - HasSourceId(4), - HasSourceId(8), - HasSourceId(10))); -} - -TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromGeneratorIfTimeStampsAreNotUpToDate) -{ - InSequence s; - - EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin()); - EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq(1))) - .WillRepeatedly(Return(firstSources)); - EXPECT_CALL(mockSqliteTransactionBackend, commit()); - EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(false)); - EXPECT_CALL(mockBuildDependenciesGenerator, create(projectPart1)) - .WillOnce(Return(buildDependency)); - EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); - EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSources(Eq(secondSources), {1})); - EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(Eq(fileStatuses))); - EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); - EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(secondUsedMacros))); - EXPECT_CALL(mockSqliteTransactionBackend, commit()); - - provider.create(projectPart1); -} - -TEST_F(BuildDependenciesProvider, - CreateCallsFetchDependSourcesFromGeneratorIfProvidedTimeStampsAreNotUpToDate) -{ - InSequence s; - - EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(false)); - EXPECT_CALL(mockBuildDependenciesGenerator, create(projectPart1)).WillOnce(Return(buildDependency)); - EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); - EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSources(Eq(secondSources), {1})); - EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateFileStatuses(Eq(fileStatuses))); - EXPECT_CALL(mockBuildDependenciesStorage, - insertOrUpdateSourceDependencies(Eq(sourceDependencies))); - EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(secondUsedMacros))); - EXPECT_CALL(mockSqliteTransactionBackend, commit()); - - provider.create(projectPart1, std::move(firstSources)); -} - -TEST_F(BuildDependenciesProvider, FetchDependSourcesFromGenerator) -{ - ON_CALL(mockModifiedTimeChecker, isUpToDate(_)).WillByDefault(Return(false)); - ON_CALL(mockBuildDependenciesGenerator, create(projectPart1)).WillByDefault(Return(buildDependency)); - - auto buildDependency = provider.create(projectPart1, std::move(firstSources)); - - ASSERT_THAT(buildDependency.sources, ElementsAre(HasSourceId(1), HasSourceId(3), HasSourceId(8))); -} - -TEST_F(BuildDependenciesProvider, CreateCallsFetchUsedMacrosFromStorageIfTimeStampsAreUpToDate) -{ - InSequence s; - - EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(true)); - EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin()); - EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros({1})); - EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros({2})); - EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros({10})); - EXPECT_CALL(mockSqliteTransactionBackend, commit()); - - provider.create(projectPart1, std::move(firstSources)); -} - -TEST_F(BuildDependenciesProvider, FetchUsedMacrosFromStorageIfDependSourcesAreUpToDate) -{ - ON_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillByDefault(Return(true)); - ON_CALL(mockBuildDependenciesStorage, fetchUsedMacros({1})).WillByDefault(Return(firstUsedMacros)); - ON_CALL(mockBuildDependenciesStorage, fetchUsedMacros({2})).WillByDefault(Return(secondUsedMacros)); - ON_CALL(mockBuildDependenciesStorage, fetchUsedMacros({10})).WillByDefault(Return(thirdUsedMacros)); - - auto buildDependency = provider.create(projectPart1, std::move(firstSources)); - - ASSERT_THAT(buildDependency.usedMacros, - ElementsAre(UsedMacro{"YI", 1}, - UsedMacro{"ER", 2}, - UsedMacro{"LIANG", 2}, - UsedMacro{"SAN", 10})); -} - -TEST_F(BuildDependenciesProvider, CallEnsureAliveMessageIsSentCallback) -{ - EXPECT_CALL(mockEnsureAliveMessageIsSentCallback, Call()); - - provider.create(projectPart1, std::move(firstSources)); -} - -TEST_F(BuildDependenciesProvider, CreateSourceEntriesFromStorage) -{ - ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, {2})).WillByDefault(Return(firstSources)); - ON_CALL(mockBuildDependenciesStorage, fetchDependSources({3}, {2})) - .WillByDefault(Return(secondSources)); - ON_CALL(mockBuildDependenciesStorage, fetchDependSources({4}, {2})).WillByDefault(Return(thirdSources)); - ON_CALL(mockModifiedTimeChecker, isUpToDate(_)).WillByDefault(Return(true)); - - auto sources = provider.createSourceEntriesFromStorage(projectPart2.sourcePathIds, - projectPart2.projectPartId); - - ASSERT_THAT(sources, - ElementsAre(HasSourceId(1), - HasSourceId(2), - HasSourceId(3), - HasSourceId(4), - HasSourceId(8), - HasSourceId(10))); -} - -TEST_F(BuildDependenciesProvider, CreateSourceEntriesFromStorageCalls) -{ - EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin()); - EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, {1})) - .WillRepeatedly(Return(firstSources)); - EXPECT_CALL(mockSqliteTransactionBackend, commit()); - - auto sources = provider.createSourceEntriesFromStorage(projectPart1.sourcePathIds, - projectPart1.projectPartId); -} -} // namespace diff --git a/tests/unit/unittest/builddependenciesstorage-test.cpp b/tests/unit/unittest/builddependenciesstorage-test.cpp deleted file mode 100644 index 13a9a6b6ebd..00000000000 --- a/tests/unit/unittest/builddependenciesstorage-test.cpp +++ /dev/null @@ -1,468 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockfilepathcaching.h" -#include "sqlitedatabasemock.h" - -#include -#include -#include -#include -#include - -#include - -namespace { - -using ClangBackEnd::FilePathCachingInterface; -using ClangBackEnd::FilePathId; -using ClangBackEnd::ProjectPartId; -using ClangBackEnd::SourceEntries; -using ClangBackEnd::SourceType; -using ClangBackEnd::UsedMacro; -using Sqlite::Database; -using Sqlite::Table; -using Utils::PathString; - -using Storage = ClangBackEnd::BuildDependenciesStorage; - -class BuildDependenciesStorage : public testing::Test -{ -protected: - NiceMock databaseMock; - template - using ReadStatement = NiceMock::ReadStatement; - using WriteStatement = NiceMock::WriteStatement; - Storage storage{databaseMock}; - WriteStatement &insertIntoNewUsedMacrosStatement = storage.insertIntoNewUsedMacrosStatement; - WriteStatement &syncNewUsedMacrosStatement = storage.syncNewUsedMacrosStatement; - WriteStatement &deleteOutdatedUsedMacrosStatement = storage.deleteOutdatedUsedMacrosStatement; - WriteStatement &deleteNewUsedMacrosTableStatement = storage.deleteNewUsedMacrosTableStatement; - WriteStatement &insertOrUpdateFileStatusesStatement = storage.insertOrUpdateFileStatusesStatement; - WriteStatement &insertIntoNewSourceDependenciesStatement = storage.insertIntoNewSourceDependenciesStatement; - WriteStatement &syncNewSourceDependenciesStatement = storage.syncNewSourceDependenciesStatement; - WriteStatement &deleteOutdatedSourceDependenciesStatement = storage.deleteOutdatedSourceDependenciesStatement; - WriteStatement &deleteNewSourceDependenciesStatement = storage.deleteNewSourceDependenciesStatement; - ReadStatement<1> &getLowestLastModifiedTimeOfDependencies = storage.getLowestLastModifiedTimeOfDependencies; - WriteStatement &insertOrUpdateProjectPartsFilesStatement = storage.insertOrUpdateProjectPartsFilesStatement; - ReadStatement<4> &fetchSourceDependenciesStatement = storage.fetchSourceDependenciesStatement; - ReadStatement<1> &fetchProjectPartIdStatement = storage.fetchProjectPartIdStatement; - ReadStatement<2> &fetchUsedMacrosStatement = storage.fetchUsedMacrosStatement; - WriteStatement &insertProjectPartNameStatement = storage.insertProjectPartNameStatement; - WriteStatement &updatePchCreationTimeStampStatement = storage.updatePchCreationTimeStampStatement; - WriteStatement &deleteAllProjectPartsFilesWithProjectPartNameStatement - = storage.deleteAllProjectPartsFilesWithProjectPartNameStatement; - ReadStatement<1> &fetchPchSourcesStatement = storage.fetchPchSourcesStatement; - ReadStatement<1> &fetchSourcesStatement = storage.fetchSourcesStatement; - WriteStatement &inserOrUpdateIndexingTimesStampStatement = storage.inserOrUpdateIndexingTimesStampStatement; - ReadStatement<2> &fetchIndexingTimeStampsStatement = storage.fetchIndexingTimeStampsStatement; - ReadStatement<2> &fetchIncludedIndexingTimeStampsStatement = storage.fetchIncludedIndexingTimeStampsStatement; - ReadStatement<1> &fetchDependentSourceIdsStatement = storage.fetchDependentSourceIdsStatement; -}; - -TEST_F(BuildDependenciesStorage, ConvertStringsToJson) -{ - Utils::SmallStringVector strings{"foo", "bar", "foo"}; - - auto jsonText = storage.toJson(strings); - - ASSERT_THAT(jsonText, Eq("[\"foo\",\"bar\",\"foo\"]")); -} - -TEST_F(BuildDependenciesStorage, InsertOrUpdateUsedMacros) -{ - InSequence sequence; - - EXPECT_CALL(insertIntoNewUsedMacrosStatement, - write(TypedEq(42), TypedEq("FOO"))); - EXPECT_CALL(insertIntoNewUsedMacrosStatement, - write(TypedEq(43), TypedEq("BAR"))); - EXPECT_CALL(syncNewUsedMacrosStatement, execute()); - EXPECT_CALL(deleteOutdatedUsedMacrosStatement, execute()); - EXPECT_CALL(deleteNewUsedMacrosTableStatement, execute()); - - storage.insertOrUpdateUsedMacros({{"FOO", 42}, {"BAR", 43}}); -} - -TEST_F(BuildDependenciesStorage, InsertOrUpdateFileStatuses) -{ - EXPECT_CALL(insertOrUpdateFileStatusesStatement, - write(TypedEq(42), TypedEq(1), TypedEq(2))); - EXPECT_CALL(insertOrUpdateFileStatusesStatement, - write(TypedEq(43), TypedEq(4), TypedEq(5))); - - storage.insertOrUpdateFileStatuses({{42, 1, 2}, {43, 4, 5}}); -} - -TEST_F(BuildDependenciesStorage, InsertOrUpdateSourceDependencies) -{ - InSequence sequence; - - EXPECT_CALL(insertIntoNewSourceDependenciesStatement, write(TypedEq(42), TypedEq(1))); - EXPECT_CALL(insertIntoNewSourceDependenciesStatement, write(TypedEq(42), TypedEq(2))); - EXPECT_CALL(syncNewSourceDependenciesStatement, execute()); - EXPECT_CALL(deleteOutdatedSourceDependenciesStatement, execute()); - EXPECT_CALL(deleteNewSourceDependenciesStatement, execute()); - - storage.insertOrUpdateSourceDependencies({{42, 1}, {42, 2}}); -} - -TEST_F(BuildDependenciesStorage, AddTablesInConstructor) -{ - InSequence s; - - EXPECT_CALL(databaseMock, immediateBegin()); - EXPECT_CALL(databaseMock, - execute( - Eq("CREATE TEMPORARY TABLE newUsedMacros(sourceId INTEGER, macroName TEXT)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE INDEX IF NOT EXISTS index_newUsedMacros_sourceId_macroName ON " - "newUsedMacros(sourceId, macroName)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TEMPORARY TABLE newSourceDependencies(sourceId INTEGER, " - "dependencySourceId TEXT)"))); - EXPECT_CALL( - databaseMock, - execute( - Eq("CREATE INDEX IF NOT EXISTS index_newSourceDependencies_sourceId_dependencySourceId " - "ON newSourceDependencies(sourceId, dependencySourceId)"))); - EXPECT_CALL(databaseMock, commit()); - - Storage storage{databaseMock}; -} - -TEST_F(BuildDependenciesStorage, FetchLowestLastModifiedTimeIfNoModificationTimeExists) -{ - EXPECT_CALL(getLowestLastModifiedTimeOfDependencies, valueReturnInt64(Eq(1))); - - auto lowestLastModified = storage.fetchLowestLastModifiedTime(1); - - ASSERT_THAT(lowestLastModified, Eq(0)); -} - -TEST_F(BuildDependenciesStorage, FetchLowestLastModifiedTime) -{ - EXPECT_CALL(getLowestLastModifiedTimeOfDependencies, valueReturnInt64(Eq(21))) - .WillRepeatedly(Return(12)); - - auto lowestLastModified = storage.fetchLowestLastModifiedTime(21); - - ASSERT_THAT(lowestLastModified, Eq(12)); -} - -TEST_F(BuildDependenciesStorage, AddNewUsedMacroTable) -{ - InSequence s; - - EXPECT_CALL(databaseMock, - execute( - Eq("CREATE TEMPORARY TABLE newUsedMacros(sourceId INTEGER, macroName TEXT)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE INDEX IF NOT EXISTS index_newUsedMacros_sourceId_macroName ON " - "newUsedMacros(sourceId, macroName)"))); - - storage.createNewUsedMacrosTable(); -} - -TEST_F(BuildDependenciesStorage, AddNewSourceDependenciesTable) -{ - InSequence s; - - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TEMPORARY TABLE newSourceDependencies(sourceId INTEGER, " - "dependencySourceId TEXT)"))); - EXPECT_CALL( - databaseMock, - execute( - Eq("CREATE INDEX IF NOT EXISTS index_newSourceDependencies_sourceId_dependencySourceId " - "ON newSourceDependencies(sourceId, dependencySourceId)"))); - - storage.createNewSourceDependenciesTable(); -} - -TEST_F(BuildDependenciesStorage, UpdateSources) -{ - InSequence s; - SourceEntries entries{{1, SourceType::TopProjectInclude, 10, ClangBackEnd::HasMissingIncludes::Yes}, - {2, SourceType::TopSystemInclude, 20}}; - - EXPECT_CALL(deleteAllProjectPartsFilesWithProjectPartNameStatement, write(TypedEq(22))); - EXPECT_CALL(insertOrUpdateProjectPartsFilesStatement, - write(TypedEq(1), TypedEq(22), TypedEq(0), TypedEq(1))); - EXPECT_CALL(insertOrUpdateProjectPartsFilesStatement, - write(TypedEq(2), TypedEq(22), TypedEq(1), TypedEq(0))); - - storage.insertOrUpdateSources(entries, 22); -} - -TEST_F(BuildDependenciesStorage, UpdatePchCreationTimeStamp) -{ - InSequence s; - - EXPECT_CALL(databaseMock, immediateBegin()); - EXPECT_CALL(updatePchCreationTimeStampStatement, write(TypedEq(101), TypedEq(1))); - EXPECT_CALL(databaseMock, commit()); - - storage.updatePchCreationTimeStamp(101, 1); -} - -TEST_F(BuildDependenciesStorage, CallsFetchDependSources) -{ - EXPECT_CALL(fetchSourceDependenciesStatement, valuesReturnSourceEntries(_, 22, 20)); - - storage.fetchDependSources(22, 20); -} - -TEST_F(BuildDependenciesStorage, FetchDependSources) -{ - SourceEntries sourceEntries{{1, SourceType::TopProjectInclude, 10}, {2, SourceType::TopSystemInclude, 20}}; - EXPECT_CALL(fetchSourceDependenciesStatement, valuesReturnSourceEntries(_, 22, 20)).WillOnce(Return(sourceEntries)); - - auto entries = storage.fetchDependSources(22, 20); - - ASSERT_THAT(entries, sourceEntries); -} - -TEST_F(BuildDependenciesStorage, CallsFetchUsedMacros) -{ - EXPECT_CALL(fetchUsedMacrosStatement, valuesReturnUsedMacros(_, 22)); - - storage.fetchUsedMacros(22); -} - -TEST_F(BuildDependenciesStorage, FetchUsedMacros) -{ - ClangBackEnd::UsedMacros result{UsedMacro{"YI", 1}, UsedMacro{"ER", 2}}; - EXPECT_CALL(fetchUsedMacrosStatement, valuesReturnUsedMacros(_, 22)).WillOnce(Return(result)); - - auto usedMacros = storage.fetchUsedMacros(22); - - ASSERT_THAT(usedMacros, result); -} - -TEST_F(BuildDependenciesStorage, FetchPchSources) -{ - ClangBackEnd::FilePathIds result{3, 5, 7}; - EXPECT_CALL(fetchPchSourcesStatement, valuesReturnFilePathIds(_, 22)).WillOnce(Return(result)); - - auto sources = storage.fetchPchSources(22); - - ASSERT_THAT(sources, result); -} - -TEST_F(BuildDependenciesStorage, FetchPchSourcesCalls) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchPchSourcesStatement, valuesReturnFilePathIds(_, 22)); - EXPECT_CALL(databaseMock, commit()); - - auto sources = storage.fetchPchSources(22); -} - -TEST_F(BuildDependenciesStorage, FetchPchSourcesCallsIsBusy) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchPchSourcesStatement, valuesReturnFilePathIds(_, 22)) - .WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(databaseMock, rollback()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchPchSourcesStatement, valuesReturnFilePathIds(_, 22)); - EXPECT_CALL(databaseMock, commit()); - - auto sources = storage.fetchPchSources(22); -} - -TEST_F(BuildDependenciesStorage, FetchSources) -{ - ClangBackEnd::FilePathIds result{3, 5, 7}; - EXPECT_CALL(fetchSourcesStatement, valuesReturnFilePathIds(_, 22)).WillOnce(Return(result)); - - auto sources = storage.fetchSources(22); - - ASSERT_THAT(sources, result); -} - -TEST_F(BuildDependenciesStorage, FetchIndexingTimeStampsIsBusy) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchIndexingTimeStampsStatement, valuesReturnSourceTimeStamps(1024)) - .WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(databaseMock, rollback()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchIndexingTimeStampsStatement, valuesReturnSourceTimeStamps(1024)); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchIndexingTimeStamps(); -} - -TEST_F(BuildDependenciesStorage, InsertIndexingTimeStampWithoutTransaction) -{ - InSequence s; - - EXPECT_CALL(databaseMock, immediateBegin()).Times(0); - EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement, - write(TypedEq(1), TypedEq(34))); - EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement, - write(TypedEq(2), TypedEq(34))); - EXPECT_CALL(databaseMock, commit()).Times(0); - - storage.insertOrUpdateIndexingTimeStampsWithoutTransaction({1, 2}, 34); -} - -TEST_F(BuildDependenciesStorage, InsertIndexingTimeStamp) -{ - InSequence s; - - EXPECT_CALL(databaseMock, immediateBegin()); - EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement, - write(TypedEq(1), TypedEq(34))); - EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement, - write(TypedEq(2), TypedEq(34))); - EXPECT_CALL(databaseMock, commit()); - - storage.insertOrUpdateIndexingTimeStamps({1, 2}, 34); -} - -TEST_F(BuildDependenciesStorage, InsertIndexingTimeStampsIsBusy) -{ - InSequence s; - - EXPECT_CALL(databaseMock, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(databaseMock, immediateBegin()); - EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement, - write(TypedEq(1), TypedEq(34))); - EXPECT_CALL(inserOrUpdateIndexingTimesStampStatement, - write(TypedEq(2), TypedEq(34))); - EXPECT_CALL(databaseMock, commit()); - - storage.insertOrUpdateIndexingTimeStamps({1, 2}, 34); -} - -TEST_F(BuildDependenciesStorage, FetchIncludedIndexingTimeStampsIsBusy) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchIncludedIndexingTimeStampsStatement, - valuesReturnSourceTimeStamps(1024, TypedEq(1))) - .WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(databaseMock, rollback()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchIncludedIndexingTimeStampsStatement, - valuesReturnSourceTimeStamps(1024, TypedEq(1))); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchIncludedIndexingTimeStamps(1); -} - -TEST_F(BuildDependenciesStorage, FetchDependentSourceIdsIsBusy) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchDependentSourceIdsStatement, valuesReturnFilePathIds(1024, TypedEq(3))); - EXPECT_CALL(fetchDependentSourceIdsStatement, valuesReturnFilePathIds(1024, TypedEq(2))) - .WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(databaseMock, rollback()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchDependentSourceIdsStatement, valuesReturnFilePathIds(1024, TypedEq(3))); - EXPECT_CALL(fetchDependentSourceIdsStatement, valuesReturnFilePathIds(1024, TypedEq(2))); - EXPECT_CALL(fetchDependentSourceIdsStatement, valuesReturnFilePathIds(1024, TypedEq(7))); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchDependentSourceIds({3, 2, 7}); -} - -class BuildDependenciesStorageSlow : public testing::Test -{ -protected: - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer databaseInitializer{database}; - ClangBackEnd::BuildDependenciesStorage<> storage{database}; -}; - -TEST_F(BuildDependenciesStorageSlow, InsertIndexingTimeStamps) -{ - storage.insertOrUpdateIndexingTimeStamps({1, 2}, 34); - - ASSERT_THAT(storage.fetchIndexingTimeStamps(), - ElementsAre(SourceTimeStamp{1, 34}, SourceTimeStamp{2, 34})); -} - -TEST_F(BuildDependenciesStorageSlow, UpdateIndexingTimeStamps) -{ - storage.insertOrUpdateIndexingTimeStamps({1, 2}, 34); - - storage.insertOrUpdateIndexingTimeStamps({1}, 37); - - ASSERT_THAT(storage.fetchIndexingTimeStamps(), - ElementsAre(SourceTimeStamp{1, 37}, SourceTimeStamp{2, 34})); -} - -TEST_F(BuildDependenciesStorageSlow, UpdateIndexingTimeStamp) -{ - storage.insertOrUpdateIndexingTimeStamps({1, 2}, 34); - - storage.insertOrUpdateIndexingTimeStamps({2}, 37); - - ASSERT_THAT(storage.fetchIndexingTimeStamps(), - ElementsAre(SourceTimeStamp{1, 34}, SourceTimeStamp{2, 37})); -} - -TEST_F(BuildDependenciesStorageSlow, FetchIncludedIndexingTimeStamps) -{ - storage.insertOrUpdateIndexingTimeStamps({1, 2, 3, 4, 5}, 34); - database.lock(); - storage.insertOrUpdateSourceDependencies({{1, 2}, {1, 3}, {2, 3}, {3, 4}, {5, 3}}); - database.unlock(); - - auto timeStamps = storage.fetchIncludedIndexingTimeStamps(1); - - ASSERT_THAT(timeStamps, - ElementsAre(SourceTimeStamp{1, 34}, - SourceTimeStamp{2, 34}, - SourceTimeStamp{3, 34}, - SourceTimeStamp{4, 34})); -} - -TEST_F(BuildDependenciesStorageSlow, FetchDependentSourceIds) -{ - database.lock(); - storage.insertOrUpdateSourceDependencies({{1, 2}, {1, 3}, {2, 3}, {4, 2}, {5, 6}, {7, 6}}); - database.unlock(); - - auto sourceIds = storage.fetchDependentSourceIds({3, 2, 7}); - - ASSERT_THAT(sourceIds, ElementsAre(FilePathId{1}, FilePathId{4}, FilePathId{7})); -} -} // namespace diff --git a/tests/unit/unittest/builddependencycollector-test.cpp b/tests/unit/unittest/builddependencycollector-test.cpp deleted file mode 100644 index 8ca1f970e20..00000000000 --- a/tests/unit/unittest/builddependencycollector-test.cpp +++ /dev/null @@ -1,1042 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "testenvironment.h" - -#include -#include -#include -#include - -#include - -#include -#include - -using testing::AllOf; -using testing::Contains; -using testing::Not; -using testing::ElementsAre; -using testing::UnorderedElementsAre; - -using ClangBackEnd::BuildDependency; -using ClangBackEnd::FilePathId; -using ClangBackEnd::FilePathIds; -using ClangBackEnd::FilePathView; -using ClangBackEnd::HasMissingIncludes; -using ClangBackEnd::SourceDependency; -using ClangBackEnd::SourceType; -using ClangBackEnd::UsedMacro; - -namespace { - -MATCHER_P2(HasSource, - sourceId, - sourceType, - std::string(negation ? "hasn't " : "has ") - + PrintToString(ClangBackEnd::SourceEntry( - sourceId, sourceType, -1, ClangBackEnd::HasMissingIncludes::No))) -{ - const ClangBackEnd::SourceEntry &entry = arg; - - return entry.sourceId == sourceId && entry.sourceType == sourceType - && entry.hasMissingIncludes == ClangBackEnd::HasMissingIncludes::No; -} - -MATCHER_P3(HasSource, - sourceId, - sourceType, - hasMissingIncludes, - std::string(negation ? "hasn't " : "has ") - + PrintToString(ClangBackEnd::SourceEntry(sourceId, sourceType, -1, hasMissingIncludes))) -{ - const ClangBackEnd::SourceEntry &entry = arg; - - return entry.sourceId == sourceId && entry.sourceType == sourceType - && entry.hasMissingIncludes == hasMissingIncludes; -} - -static Utils::SmallString toNativePath(Utils::SmallStringView text) -{ - ClangBackEnd::FilePath path{text}; - - return Utils::SmallString{ClangBackEnd::NativeFilePath{path}.path()}; -} - -class BuildDependencyCollector : public ::testing::Test -{ -protected: - BuildDependencyCollector() - { - collector.addFiles({id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"), - id(TESTDATA_DIR "/builddependencycollector/project/main2.cpp")}, - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - collector.addUnsavedFiles( - {{{TESTDATA_DIR, "BuildDependencyCollector/project/generated_file.h"}, - id(TESTDATA_DIR "/BuildDependencyCollector/project/generated_file.h"), - "#pragma once", - {}}}); - - collector.setExcludedFilePaths(Utils::clone(excludePaths)); - emptyCollector.setExcludedFilePaths(Utils::clone(excludePaths)); - } - - FilePathId id(const Utils::SmallStringView &path) const - { - return filePathCache.filePathId(FilePathView{path}); - } - - static off_t fileSize(Utils::SmallStringView filePath) - { - return QFileInfo(QString(filePath)).size(); - } - - static std::time_t lastModified(Utils::SmallStringView filePath) - { - return QFileInfo(QString(filePath)).lastModified().toSecsSinceEpoch(); - } - - ClangBackEnd::FileStatus fileStatus(Utils::SmallStringView filePath) const - { - return {id(filePath), fileSize(filePath), lastModified(filePath)}; - } - - static FilePathIds filteredSources(const ClangBackEnd::SourceEntries &sources, - ClangBackEnd::SourceType sourceType) - { - FilePathIds filteredSources; - - for (const ClangBackEnd::SourceEntry &source : sources) { - if (source.sourceType == sourceType) - filteredSources.push_back(source.sourceId); - } - - return filteredSources; - } - - static FilePathIds topSources(const ClangBackEnd::SourceEntries &sources) - { - return filteredSources(sources, ClangBackEnd::SourceType::TopProjectInclude); - } - - static FilePathIds systemTopSources(const ClangBackEnd::SourceEntries &sources) - { - return filteredSources(sources, ClangBackEnd::SourceType::TopSystemInclude); - } - - static FilePathIds userSources(const ClangBackEnd::SourceEntries &sources) - { - return filteredSources(sources, ClangBackEnd::SourceType::UserInclude); - } - - static FilePathIds projectPartSources(const ClangBackEnd::SourceEntries &sources) - { - return filteredSources(sources, ClangBackEnd::SourceType::ProjectInclude); - } - - static FilePathIds sources(const ClangBackEnd::SourceEntries &sources) - { - FilePathIds filteredSources; - - for (const ClangBackEnd::SourceEntry &source : sources) - filteredSources.push_back(source.sourceId); - - return filteredSources; - } - -protected: - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - TestEnvironment environment; - ClangBackEnd::RefactoringDatabaseInitializer databaseInitializer{database}; - ClangBackEnd::FilePathCaching filePathCache{database}; - ClangBackEnd::GeneratedFiles generatedFiles; - ClangBackEnd::BuildDependencyCollector collector{filePathCache, generatedFiles, environment}; - ClangBackEnd::BuildDependencyCollector emptyCollector{filePathCache, generatedFiles, environment}; - ClangBackEnd::FilePaths excludePaths = { - TESTDATA_DIR "/builddependencycollector/project/main.cpp", - TESTDATA_DIR "/builddependencycollector/project/main2.cpp", - TESTDATA_DIR "/builddependencycollector/project/header1.h", - TESTDATA_DIR "/builddependencycollector/project/header2.h", - TESTDATA_DIR "/builddependencycollector/project/generated_file.h", - TESTDATA_DIR "/builddependencycollector/project/generated/generated_file.h"}; -}; - -TEST_F(BuildDependencyCollector, IncludesExternalHeader) -{ - collector.collect(); - - ASSERT_THAT(sources(collector.sourceEntries()), - AllOf(Contains(id(TESTDATA_DIR "/builddependencycollector/external/external1.h")), - Contains(id(TESTDATA_DIR "/builddependencycollector/external/external2.h")), - Contains(id(TESTDATA_DIR - "/builddependencycollector/external/indirect_external.h")), - Contains(id(TESTDATA_DIR - "/builddependencycollector/external/indirect_external2.h")))); -} - -TEST_F(BuildDependencyCollector, InternalHeaderAreUserIncludes) -{ - collector.collect(); - - ASSERT_THAT(userSources(collector.sourceEntries()), - Contains(id(TESTDATA_DIR "/builddependencycollector/project/header1.h"))); -} - -TEST_F(BuildDependencyCollector, NoDuplicate) -{ - collector.collect(); - - ASSERT_THAT(sources(collector.sourceEntries()), - UnorderedElementsAre( - id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"), - id(TESTDATA_DIR "/builddependencycollector/project/main2.cpp"), - id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external3.h"), - id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h"), - id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h"))); -} - -TEST_F(BuildDependencyCollector, IncludesAreSorted) -{ - collector.collect(); - - ASSERT_THAT(sources(collector.sourceEntries()), - ElementsAre(id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"), - id(TESTDATA_DIR "/builddependencycollector/project/main2.cpp"), - id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external3.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR - "/builddependencycollector/external/indirect_external.h"), - id(TESTDATA_DIR - "/builddependencycollector/external/indirect_external2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h"))); -} - -TEST_F(BuildDependencyCollector, If) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/if.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - emptyCollector.collect(); - - ASSERT_THAT(sources(emptyCollector.sourceEntries()), - ElementsAre(id(TESTDATA_DIR "/builddependencycollector/project/if.cpp"), - id(TESTDATA_DIR "/builddependencycollector/project/true.h"))); -} - -TEST_F(BuildDependencyCollector, LocalPath) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - emptyCollector.collect(); - - ASSERT_THAT(sources(emptyCollector.sourceEntries()), - UnorderedElementsAre( - id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"), - id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external3.h"), - id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h"), - id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h"))); -} - -TEST_F(BuildDependencyCollector, IgnoreMissingFile) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/missingfile.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - emptyCollector.collect(); - - ASSERT_THAT(sources(emptyCollector.sourceEntries()), - UnorderedElementsAre( - id(TESTDATA_DIR "/builddependencycollector/project/missingfile.cpp"), - id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h"), - id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h"))); -} - -TEST_F(BuildDependencyCollector, IncludesOnlyTopExternalHeader) -{ - collector.collect(); - - ASSERT_THAT( - topSources(collector.sourceEntries()), - UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external3.h"))); -} - -TEST_F(BuildDependencyCollector, TopIncludeInIfMacro) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/if.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - emptyCollector.setExcludedFilePaths({TESTDATA_DIR "/builddependencycollector/project/if.cpp"}); - - emptyCollector.collect(); - - ASSERT_THAT(topSources(emptyCollector.sourceEntries()), - ElementsAre(id(TESTDATA_DIR "/builddependencycollector/project/true.h"))); -} - -TEST_F(BuildDependencyCollector, TopIncludeWithLocalPath) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/main.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - emptyCollector.collect(); - - ASSERT_THAT( - topSources(emptyCollector.sourceEntries()), - UnorderedElementsAre(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external3.h"))); -} - -TEST_F(BuildDependencyCollector, TopIncludesIgnoreMissingFile) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/missingfile.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - emptyCollector.setExcludedFilePaths({TESTDATA_DIR "/builddependencycollector/project/missingfile.cpp"}); - - emptyCollector.collect(); - - ASSERT_THAT(topSources(emptyCollector.sourceEntries()), - UnorderedElementsAre( - id(TESTDATA_DIR "/builddependencycollector/external/external1.h"))); -} - -TEST_F(BuildDependencyCollector, SourceFiles) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector/main.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - emptyCollector.collect(); - - ASSERT_THAT(emptyCollector.sourceFiles(), - UnorderedElementsAre(id(TESTDATA_DIR "/symbolscollector/main.cpp"), - id(TESTDATA_DIR "/symbolscollector/header1.h"), - id(TESTDATA_DIR "/symbolscollector/header2.h"))); -} - -TEST_F(BuildDependencyCollector, MainFileInSourceFiles) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector/main.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - ASSERT_THAT(emptyCollector.sourceFiles(), - ElementsAre(id(TESTDATA_DIR "/symbolscollector/main.cpp"))); -} - -TEST_F(BuildDependencyCollector, ResetMainFileInSourceFiles) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector/main.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - ASSERT_THAT(emptyCollector.sourceFiles(), - ElementsAre(id(TESTDATA_DIR "/symbolscollector/main.cpp"))); -} - -TEST_F(BuildDependencyCollector, DontDuplicateSourceFiles) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector/main.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - emptyCollector.collect(); - - emptyCollector.collect(); - - ASSERT_THAT(emptyCollector.sourceFiles(), - UnorderedElementsAre(id(TESTDATA_DIR "/symbolscollector/main.cpp"), - id(TESTDATA_DIR "/symbolscollector/header1.h"), - id(TESTDATA_DIR "/symbolscollector/header2.h"))); -} - -TEST_F(BuildDependencyCollector, ClearSourceFiles) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector/main.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - emptyCollector.clear(); - - ASSERT_THAT(emptyCollector.sourceFiles(), IsEmpty()); -} - -TEST_F(BuildDependencyCollector, ClearFileStatus) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector/main.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - emptyCollector.collect(); - - emptyCollector.clear(); - - ASSERT_THAT(emptyCollector.fileStatuses(), IsEmpty()); -} - -TEST_F(BuildDependencyCollector, ClearUsedMacros) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector/defines.h"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - emptyCollector.collect(); - - emptyCollector.clear(); - - ASSERT_THAT(emptyCollector.usedMacros(), IsEmpty()); -} - -TEST_F(BuildDependencyCollector, ClearSourceDependencies) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector/main2.cpp"), {"cc", "-I" TESTDATA_DIR}); - emptyCollector.collect(); - - emptyCollector.clear(); - - ASSERT_THAT(emptyCollector.sourceDependencies(), IsEmpty()); -} - -TEST_F(BuildDependencyCollector, DontCollectSourceFilesAfterFilesAreCleared) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector/main.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - emptyCollector.clear(); - emptyCollector.collect(); - - ASSERT_THAT(emptyCollector.sourceFiles(), IsEmpty()); -} - -TEST_F(BuildDependencyCollector, DontCollectFileStatusAfterFilesAreCleared) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector/main.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - emptyCollector.clear(); - emptyCollector.collect(); - - ASSERT_THAT(emptyCollector.fileStatuses(), IsEmpty()); -} - -TEST_F(BuildDependencyCollector, DontCollectUsedMacrosAfterFilesAreCleared) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector/main.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - emptyCollector.clear(); - emptyCollector.collect(); - - ASSERT_THAT(emptyCollector.usedMacros(), IsEmpty()); -} - - -TEST_F(BuildDependencyCollector, DontCollectSourceDependenciesAfterFilesAreCleared) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector/main.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - emptyCollector.clear(); - emptyCollector.collect(); - - ASSERT_THAT(emptyCollector.sourceDependencies(), IsEmpty()); -} - -TEST_F(BuildDependencyCollector, CollectUsedMacrosWithExternalDefine) -{ - auto fileId = id(TESTDATA_DIR "/symbolscollector/defines.h"); - emptyCollector.addFile(fileId, {"cc", "-DCOMPILER_ARGUMENT"}); - - emptyCollector.collect(); - - ASSERT_THAT(emptyCollector.usedMacros(), - ElementsAre(Eq(UsedMacro{"DEFINED", fileId}), - Eq(UsedMacro{"IF_DEFINE", fileId}), - Eq(UsedMacro{"__clang__", fileId}), - Eq(UsedMacro{"IF_NOT_DEFINE", fileId}), - Eq(UsedMacro{"COMPILER_ARGUMENT", fileId}))); -} - -TEST_F(BuildDependencyCollector, CollectUsedMacrosWithoutExternalDefine) -{ - auto fileId = id(TESTDATA_DIR "/symbolscollector/defines.h"); - emptyCollector.addFile(fileId, - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - emptyCollector.collect(); - - ASSERT_THAT(emptyCollector.usedMacros(), - ElementsAre(Eq(UsedMacro{"DEFINED", fileId}), - Eq(UsedMacro{"IF_DEFINE", fileId}), - Eq(UsedMacro{"__clang__", fileId}), - Eq(UsedMacro{"IF_NOT_DEFINE", fileId}), - Eq(UsedMacro{"COMPILER_ARGUMENT", fileId}))); -} - -TEST_F(BuildDependencyCollector, DontCollectHeaderGuards) -{ - auto fileId = id(TESTDATA_DIR "/symbolscollector/defines.h"); - emptyCollector.addFile(fileId, - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - emptyCollector.collect(); - - ASSERT_THAT(emptyCollector.usedMacros(), - Not(Contains(Eq(UsedMacro{"SYMBOLSCOLLECTOR_DEFINES_H", fileId})))); -} - -TEST_F(BuildDependencyCollector, DISABLED_DontCollectDynamicLibraryExports) -{ - auto fileId = id(TESTDATA_DIR "/symbolscollector/defines.h"); - emptyCollector.addFile(fileId, - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - emptyCollector.collect(); - - ASSERT_THAT(emptyCollector.usedMacros(), - Not(Contains(Eq(UsedMacro{"CLASS_EXPORT", fileId})))); -} - -TEST_F(BuildDependencyCollector, CollectFileStatuses) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/symbolscollector/main.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - emptyCollector.collect(); - - ASSERT_THAT(emptyCollector.fileStatuses(), - ElementsAre(fileStatus(TESTDATA_DIR "/symbolscollector/main.cpp"), - fileStatus(TESTDATA_DIR "/symbolscollector/header1.h"), - fileStatus(TESTDATA_DIR "/symbolscollector/header2.h"))); -} - -TEST_F(BuildDependencyCollector, CollectSourceDependencies) -{ - auto mainFileId = id(TESTDATA_DIR "/symbolscollector/main2.cpp"); - auto header1FileId = id(TESTDATA_DIR "/symbolscollector/header1.h"); - auto header2FileId = id(TESTDATA_DIR "/symbolscollector/header2.h"); - auto header3FileId = id(TESTDATA_DIR "/symbolscollector/header3.h"); - emptyCollector.addFile(mainFileId, {"cc", "-I" TESTDATA_DIR}); - - emptyCollector.collect(); - - ASSERT_THAT(emptyCollector.sourceDependencies(), - UnorderedElementsAre(SourceDependency(mainFileId, header1FileId), - SourceDependency(mainFileId, header3FileId), - SourceDependency(header3FileId, header2FileId), - SourceDependency(header1FileId, header2FileId))); -} - -TEST_F(BuildDependencyCollector, MissingInclude) -{ - emptyCollector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/main5.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - - emptyCollector.collect(); - - ASSERT_THAT( - emptyCollector.sourceEntries(), - UnorderedElementsAre( - HasSource(id(TESTDATA_DIR "/builddependencycollector/project/main5.cpp"), - SourceType::Source, - HasMissingIncludes::Yes), - HasSource(id(TESTDATA_DIR "/builddependencycollector/project/missinginclude2.h"), - SourceType::ProjectInclude, - HasMissingIncludes::Yes), - HasSource(id(TESTDATA_DIR - "/builddependencycollector/project/indirect_missinginclude.h"), - SourceType::ProjectInclude, - HasMissingIncludes::Yes), - HasSource(id(TESTDATA_DIR - "/builddependencycollector/project/indirect_missinginclude3.h"), - SourceType::ProjectInclude, - HasMissingIncludes::Yes), - HasSource(id(TESTDATA_DIR - "/builddependencycollector/project/indirect_missinginclude4.h"), - SourceType::ProjectInclude, - HasMissingIncludes::Yes), - HasSource(id(TESTDATA_DIR "/builddependencycollector/project/missinginclude3.h"), - SourceType::ProjectInclude, - HasMissingIncludes::Yes), - HasSource(id(TESTDATA_DIR - "/builddependencycollector/project/indirect_missinginclude2.h"), - SourceType::ProjectInclude, - HasMissingIncludes::Yes), - HasSource(id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - SourceType::UserInclude, - HasMissingIncludes::No))); -} - - -TEST_F(BuildDependencyCollector, GeneratedFile) -{ - generatedFiles.update( - {{TESTDATA_DIR "/builddependencycollector/project/generated/generated_file.h", - id(TESTDATA_DIR "/builddependencycollector/project/generated/generated_file.h"), - "#pragma once"}}); - emptyCollector.addFile(id(TESTDATA_DIR "/builddependencycollector/project/main6.cpp"), - {"cc", - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system")}); - emptyCollector.addUnsavedFiles(generatedFiles.fileContainers()); - - emptyCollector.collect(); - - ASSERT_THAT(emptyCollector.sourceEntries(), - UnorderedElementsAre( - HasSource(id(TESTDATA_DIR "/builddependencycollector/project/main6.cpp"), - SourceType::Source), - HasSource(id(TESTDATA_DIR - "/builddependencycollector/project/generated/generated_file.h"), - SourceType::UserInclude))); -} - -TEST_F(BuildDependencyCollector, CreateFakeFileContent) -{ - auto content = collector.generateFakeFileContent( - {id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h")}); - - ASSERT_THAT(std::string(content), - AllOf(HasSubstr("#include \"" TESTDATA_DIR - "/builddependencycollector/project/header2.h\"\n"), - HasSubstr("#include \"" TESTDATA_DIR - "/builddependencycollector/external/external1.h\"\n"), - HasSubstr("#include \"" TESTDATA_DIR - "/builddependencycollector/external/external2.h\"\n"))); -} - -TEST_F(BuildDependencyCollector, Create) -{ - using ClangBackEnd::IncludeSearchPathType; - ClangBackEnd::BuildDependencyCollector collector{filePathCache, generatedFiles, environment}; - generatedFiles.update({{TESTDATA_DIR "/builddependencycollector/project/generated_file.h", - id(TESTDATA_DIR "/builddependencycollector/project/generated_file.h"), - "#pragma once"}}); - ClangBackEnd::ProjectPartContainer projectPart{ - 1, - {}, - {}, - {{toNativePath(TESTDATA_DIR "/builddependencycollector/system"), - 1, - ClangBackEnd::IncludeSearchPathType::System}}, - { - {toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - 1, - ClangBackEnd::IncludeSearchPathType::User}, - {toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - 2, - ClangBackEnd::IncludeSearchPathType::User}, - }, - { - id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - id(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"), - id(TESTDATA_DIR "/builddependencycollector/project/macros.h"), - }, - {id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp")}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None}; - - auto buildDependency = collector.create(projectPart); - - ASSERT_THAT( - buildDependency, - AllOf( - Field(&BuildDependency::fileStatuses, - UnorderedElementsAre( - fileStatus(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"), - fileStatus(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - fileStatus(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - fileStatus(TESTDATA_DIR "/builddependencycollector/external/external3.h"), - fileStatus(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - fileStatus(TESTDATA_DIR - "/builddependencycollector/external/indirect_external.h"), - fileStatus(TESTDATA_DIR - "/builddependencycollector/external/indirect_external2.h"), - fileStatus(TESTDATA_DIR "/builddependencycollector/external/external2.h"), - fileStatus(TESTDATA_DIR "/builddependencycollector/system/system1.h"), - fileStatus(TESTDATA_DIR "/preincludes/system1.h"), - fileStatus(TESTDATA_DIR "/builddependencycollector/system/indirect_system.h"), - fileStatus(TESTDATA_DIR - "/builddependencycollector/system/indirect_system2.h"), - fileStatus(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"), - fileStatus(TESTDATA_DIR "/builddependencycollector/project/macros.h"), - ClangBackEnd::FileStatus( - id(TESTDATA_DIR "/builddependencycollector/project/generated_file.h"), 12, 0))), - Field( - &BuildDependency::sources, - UnorderedElementsAre( - HasSource(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"), - SourceType::Source, - HasMissingIncludes::Yes), - HasSource(id(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"), - SourceType::UserInclude, - HasMissingIncludes::Yes), - HasSource(id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - SourceType::UserInclude), - HasSource(id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - SourceType::UserInclude), - HasSource(id(TESTDATA_DIR "/builddependencycollector/external/external3.h"), - SourceType::TopProjectInclude), - HasSource(id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - SourceType::TopProjectInclude), - HasSource(id(TESTDATA_DIR - "/builddependencycollector/external/indirect_external.h"), - SourceType::ProjectInclude), - HasSource(id(TESTDATA_DIR - "/builddependencycollector/external/indirect_external2.h"), - SourceType::ProjectInclude), - HasSource(id(TESTDATA_DIR "/builddependencycollector/external/external2.h"), - SourceType::TopProjectInclude), - HasSource(id(TESTDATA_DIR "/builddependencycollector/system/system1.h"), - SourceType::SystemInclude), - HasSource(id(TESTDATA_DIR "/builddependencycollector/system/indirect_system.h"), - SourceType::SystemInclude), - HasSource(id(TESTDATA_DIR - "/builddependencycollector/system/indirect_system2.h"), - SourceType::SystemInclude), - HasSource(id(TESTDATA_DIR "/builddependencycollector/project/macros.h"), - SourceType::UserInclude), - HasSource(id(TESTDATA_DIR "/builddependencycollector/project/generated_file.h"), - SourceType::UserInclude), - HasSource(id(TESTDATA_DIR "/preincludes/system1.h"), SourceType::TopSystemInclude))), - Field(&BuildDependency::usedMacros, - UnorderedElementsAre( - UsedMacro{"IFDEF", id(TESTDATA_DIR "/builddependencycollector/project/macros.h")}, - UsedMacro{"DEFINED", - id(TESTDATA_DIR "/builddependencycollector/project/macros.h")})), - Field(&BuildDependency::sourceFiles, - UnorderedElementsAre( - id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"), - id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external3.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h"), - id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h"), - id(TESTDATA_DIR "/builddependencycollector/system/system1.h"), - id(TESTDATA_DIR "/preincludes/system1.h"), - id(TESTDATA_DIR "/builddependencycollector/system/indirect_system.h"), - id(TESTDATA_DIR "/builddependencycollector/system/indirect_system2.h"), - id(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"), - id(TESTDATA_DIR "/builddependencycollector/project/macros.h"), - id(TESTDATA_DIR "/builddependencycollector/project/generated_file.h"))), - Field( - &BuildDependency::sourceDependencies, - UnorderedElementsAre( - SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"), - id(TESTDATA_DIR - "/builddependencycollector/project/header1.h")), - SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"), - id(TESTDATA_DIR - "/builddependencycollector/project/header2.h")), - SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"), - id(TESTDATA_DIR - "/builddependencycollector/project/missingfile.h")), - SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"), - id(TESTDATA_DIR - "/builddependencycollector/external/external1.h")), - SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"), - id(TESTDATA_DIR - "/builddependencycollector/external/external2.h")), - SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"), - id(TESTDATA_DIR "/preincludes/system1.h")), - SourceDependency(id(TESTDATA_DIR "/preincludes/system1.h"), - id(TESTDATA_DIR "/builddependencycollector/system/system1.h")), - SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"), - id(TESTDATA_DIR "/builddependencycollector/project/macros.h")), - SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp"), - id(TESTDATA_DIR - "/builddependencycollector/project/generated_file.h")), - SourceDependency(id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - id(TESTDATA_DIR - "/builddependencycollector/external/external3.h")), - SourceDependency( - id(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external1.h")), - SourceDependency( - id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h")), - SourceDependency( - id(TESTDATA_DIR "/builddependencycollector/external/indirect_external.h"), - id(TESTDATA_DIR "/builddependencycollector/external/indirect_external2.h")), - SourceDependency(id(TESTDATA_DIR "/builddependencycollector/system/system1.h"), - id(TESTDATA_DIR - "/builddependencycollector/system/indirect_system.h")), - SourceDependency( - id(TESTDATA_DIR "/builddependencycollector/system/indirect_system.h"), - id(TESTDATA_DIR "/builddependencycollector/system/indirect_system2.h")))))); -} - -TEST_F(BuildDependencyCollector, Clear) -{ - using ClangBackEnd::IncludeSearchPathType; - ClangBackEnd::BuildDependencyCollector collector{filePathCache, generatedFiles, environment}; - ClangBackEnd::ProjectPartContainer projectPart{ - 1, - {}, - {}, - {{toNativePath(TESTDATA_DIR "/builddependencycollector/system"), - 1, - ClangBackEnd::IncludeSearchPathType::System}}, - { - {toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - 1, - ClangBackEnd::IncludeSearchPathType::User}, - {toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - 2, - ClangBackEnd::IncludeSearchPathType::User}, - }, - { - id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - id(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"), - id(TESTDATA_DIR "/builddependencycollector/project/macros.h"), - }, - {id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp")}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None}; - collector.create(projectPart); - ClangBackEnd::ProjectPartContainer emptyProjectPart{ - 1, - {}, - {}, - {{toNativePath(TESTDATA_DIR "/builddependencycollector/system"), - 1, - ClangBackEnd::IncludeSearchPathType::System}}, - { - {toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - 1, - ClangBackEnd::IncludeSearchPathType::User}, - {toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - 2, - ClangBackEnd::IncludeSearchPathType::User}, - }, - { - id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - id(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"), - id(TESTDATA_DIR "/builddependencycollector/project/macros.h"), - }, - {}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None}; - - auto buildDependency = collector.create(emptyProjectPart); - - ASSERT_THAT(buildDependency.sources, IsEmpty()); -} - -TEST_F(BuildDependencyCollector, PreIncludes) -{ - using ClangBackEnd::IncludeSearchPathType; - ClangBackEnd::BuildDependencyCollector collector{filePathCache, generatedFiles, environment}; - ClangBackEnd::ProjectPartContainer projectPart{ - 1, - {}, - {}, - {{toNativePath(TESTDATA_DIR "/builddependencycollector/system"), - 1, - ClangBackEnd::IncludeSearchPathType::System}}, - { - {toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - 1, - ClangBackEnd::IncludeSearchPathType::User}, - {toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - 2, - ClangBackEnd::IncludeSearchPathType::User}, - }, - { - id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - id(TESTDATA_DIR "/builddependencycollector/project/missingfile.h"), - id(TESTDATA_DIR "/builddependencycollector/project/macros.h"), - }, - {id(TESTDATA_DIR "/builddependencycollector/project/main4.cpp")}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None}; - - auto buildDependency = collector.create(projectPart); - - ASSERT_THAT(buildDependency.sources, - Contains(HasSource(id(TESTDATA_DIR "/preincludes/system1.h"), - SourceType::TopSystemInclude))); -} -} // namespace diff --git a/tests/unit/unittest/clangindexingsettingsmanager-test.cpp b/tests/unit/unittest/clangindexingsettingsmanager-test.cpp deleted file mode 100644 index e3c4eb7c67d..00000000000 --- a/tests/unit/unittest/clangindexingsettingsmanager-test.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include -#include - -namespace { -class ClangIndexingSettingsManager : public testing::Test -{ -protected: - ClangPchManager::ClangIndexingSettingsManager manager; - ProjectExplorer::Project project; - ProjectExplorer::Project project2; -}; - -TEST_F(ClangIndexingSettingsManager, FetchSettings) -{ - auto setting = manager.settings(&project); - - ASSERT_THAT(setting, Not(IsNull())); -} - -TEST_F(ClangIndexingSettingsManager, SettingsAreTheSameForTheSameProject) -{ - auto setting1 = manager.settings(&project); - - auto setting2 = manager.settings(&project); - - ASSERT_THAT(setting1, Eq(setting2)); -} - -TEST_F(ClangIndexingSettingsManager, SettingsAreTheDifferentForDifferentProjects) -{ - manager.settings(&project); - manager.settings(&project2); - - auto setting1 = manager.settings(&project); - - auto setting2 = manager.settings(&project2); - - ASSERT_THAT(setting1, Not(Eq(setting2))); -} - -TEST_F(ClangIndexingSettingsManager, RemoveSettings) -{ - manager.settings(&project); - - manager.remove(&project); - - ASSERT_FALSE(manager.hasSettings(&project)); -} - -TEST_F(ClangIndexingSettingsManager, RemoveNonExistingSettings) -{ - manager.remove(&project); - - ASSERT_FALSE(manager.hasSettings(&project)); -} -} // namespace diff --git a/tests/unit/unittest/clangpathwatcher-test.cpp b/tests/unit/unittest/clangpathwatcher-test.cpp deleted file mode 100644 index 3105000ca18..00000000000 --- a/tests/unit/unittest/clangpathwatcher-test.cpp +++ /dev/null @@ -1,402 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockclangpathwatchernotifier.h" -#include "mockfilepathcaching.h" -#include "mockfilesystem.h" -#include "mockqfilesystemwatcher.h" -#include "mocktimer.h" - -#include - -#include - -namespace { - -using testing::_; -using testing::ElementsAre; -using testing::IsEmpty; -using testing::SizeIs; -using testing::NiceMock; - -using Watcher = ClangBackEnd::ClangPathWatcher, NiceMock>; -using ClangBackEnd::FilePath; -using ClangBackEnd::FilePathId; -using ClangBackEnd::FilePathIds; -using ClangBackEnd::FilePathView; -using ClangBackEnd::IdPaths; -using ClangBackEnd::ProjectChunkId; -using ClangBackEnd::ProjectPartId; -using ClangBackEnd::ProjectPartIds; -using ClangBackEnd::SourceType; -using ClangBackEnd::WatcherEntries; -using ClangBackEnd::WatcherEntry; - -class ClangPathWatcher : public testing::Test -{ -protected: - void SetUp() - { - ON_CALL(mockFilePathCache, filePathId(Eq(path1))).WillByDefault(Return(pathIds[0])); - ON_CALL(mockFilePathCache, filePathId(Eq(path2))).WillByDefault(Return(pathIds[1])); - ON_CALL(mockFilePathCache, filePathId(Eq(path3))).WillByDefault(Return(pathIds[2])); - ON_CALL(mockFilePathCache, filePathId(Eq(path4))).WillByDefault(Return(pathIds[3])); - ON_CALL(mockFilePathCache, filePathId(Eq(path5))).WillByDefault(Return(pathIds[4])); - ON_CALL(mockFilePathCache, filePath(Eq(pathIds[0]))).WillByDefault(Return(FilePath{path1})); - ON_CALL(mockFilePathCache, filePath(Eq(pathIds[1]))).WillByDefault(Return(FilePath{path2})); - ON_CALL(mockFilePathCache, filePath(Eq(pathIds[2]))).WillByDefault(Return(FilePath{path3})); - ON_CALL(mockFilePathCache, filePath(Eq(pathIds[3]))).WillByDefault(Return(FilePath{path4})); - ON_CALL(mockFilePathCache, filePath(Eq(pathIds[4]))).WillByDefault(Return(FilePath{path5})); - ON_CALL(mockFilePathCache, directoryPathId(TypedEq(pathIds[0]))) - .WillByDefault(Return(directoryPaths[0])); - ON_CALL(mockFilePathCache, directoryPathId(TypedEq(pathIds[1]))) - .WillByDefault(Return(directoryPaths[0])); - ON_CALL(mockFilePathCache, directoryPathId(TypedEq(pathIds[2]))) - .WillByDefault(Return(directoryPaths[1])); - ON_CALL(mockFilePathCache, directoryPathId(TypedEq(pathIds[3]))) - .WillByDefault(Return(directoryPaths[1])); - ON_CALL(mockFilePathCache, directoryPathId(TypedEq(pathIds[4]))) - .WillByDefault(Return(directoryPaths[2])); - ON_CALL(mockFileSystem, lastModified(_)).WillByDefault(Return(1)); - ON_CALL(mockFilePathCache, - directoryPathId(TypedEq(directoryPathString))) - .WillByDefault(Return(directoryPaths[0])); - ON_CALL(mockFilePathCache, - directoryPathId(TypedEq(directoryPathString2))) - .WillByDefault(Return(directoryPaths[1])); - ON_CALL(mockFilePathCache, directoryPath(Eq(directoryPaths[0]))) - .WillByDefault(Return(directoryPath)); - ON_CALL(mockFilePathCache, directoryPath(Eq(directoryPaths[1]))) - .WillByDefault(Return(directoryPath2)); - ON_CALL(mockFilePathCache, directoryPath(Eq(directoryPaths[2]))) - .WillByDefault(Return(directoryPath3)); - ON_CALL(mockFileSystem, directoryEntries(Eq(directoryPath))) - .WillByDefault(Return(FilePathIds{pathIds[0], pathIds[1]})); - ON_CALL(mockFileSystem, directoryEntries(Eq(directoryPath2))) - .WillByDefault(Return(FilePathIds{pathIds[2], pathIds[3]})); - ON_CALL(mockFileSystem, directoryEntries(Eq(directoryPath3))) - .WillByDefault(Return(FilePathIds{pathIds[4]})); - } - static WatcherEntries sorted(WatcherEntries &&entries) - { - std::stable_sort(entries.begin(), entries.end()); - - return std::move(entries); - } - -protected: - NiceMock mockFilePathCache; - NiceMock notifier; - NiceMock mockFileSystem; - Watcher watcher{mockFilePathCache, mockFileSystem, ¬ifier}; - NiceMock &mockQFileSytemWatcher = watcher.fileSystemWatcher(); - ProjectChunkId id1{2, SourceType::ProjectInclude}; - ProjectChunkId id2{2, SourceType::Source}; - ProjectChunkId id3{4, SourceType::SystemInclude}; - FilePathView path1{"/path/path1"}; - FilePathView path2{"/path/path2"}; - FilePathView path3{"/path2/path1"}; - FilePathView path4{"/path2/path2"}; - FilePathView path5{"/path3/path"}; - QString path1QString = QString(path1.toStringView()); - QString path2QString = QString(path2.toStringView()); - QString directoryPath = "/path"; - QString directoryPath2 = "/path2"; - QString directoryPath3 = "/path3"; - Utils::PathString directoryPathString = directoryPath; - Utils::PathString directoryPathString2 = directoryPath2; - FilePathIds pathIds = {1, 2, 3, 4, 5}; - ClangBackEnd::DirectoryPathIds directoryPaths = {1, 2, 3}; - ClangBackEnd::ProjectChunkIds ids{id1, id2, id3}; - WatcherEntry watcherEntry1{id1, directoryPaths[0], pathIds[0]}; - WatcherEntry watcherEntry2{id2, directoryPaths[0], pathIds[0]}; - WatcherEntry watcherEntry3{id1, directoryPaths[0], pathIds[1]}; - WatcherEntry watcherEntry4{id2, directoryPaths[0], pathIds[1]}; - WatcherEntry watcherEntry5{id3, directoryPaths[0], pathIds[1]}; - WatcherEntry watcherEntry6{id1, directoryPaths[1], pathIds[2]}; - WatcherEntry watcherEntry7{id2, directoryPaths[1], pathIds[3]}; - WatcherEntry watcherEntry8{id3, directoryPaths[1], pathIds[3]}; -}; - -TEST_F(ClangPathWatcher, AddIdPaths) -{ - EXPECT_CALL(mockQFileSytemWatcher, - addPaths(UnorderedElementsAre(QString(directoryPath), QString(directoryPath2)))); - - watcher.updateIdPaths( - {{id1, {pathIds[0], pathIds[1], pathIds[2]}}, {id2, {pathIds[0], pathIds[1], pathIds[3]}}}); -} - -TEST_F(ClangPathWatcher, UpdateIdPathsCallsAddPathInFileWatcher) -{ - watcher.updateIdPaths({{id1, {pathIds[0], pathIds[1]}}, {id2, {pathIds[0], pathIds[1]}}}); - - EXPECT_CALL(mockQFileSytemWatcher, addPaths(UnorderedElementsAre(QString(directoryPath2)))); - - watcher.updateIdPaths( - {{id1, {pathIds[0], pathIds[1], pathIds[2]}}, {id2, {pathIds[0], pathIds[1], pathIds[3]}}}); -} - -TEST_F(ClangPathWatcher, UpdateIdPathsAndRemoveUnusedPathsCallsRemovePathInFileWatcher) -{ - watcher.updateIdPaths( - {{id1, {pathIds[0], pathIds[1], pathIds[2]}}, {id2, {pathIds[0], pathIds[1], pathIds[3]}}}); - - EXPECT_CALL(mockQFileSytemWatcher, removePaths(UnorderedElementsAre(QString(directoryPath2)))); - - watcher.updateIdPaths({{id1, {pathIds[0], pathIds[1]}}, {id2, {pathIds[0], pathIds[1]}}}); -} - -TEST_F(ClangPathWatcher, UpdateIdPathsAndRemoveUnusedPathsDoNotCallsRemovePathInFileWatcher) -{ - watcher.updateIdPaths({{id1, {pathIds[0], pathIds[1], pathIds[2]}}, - {id2, {pathIds[0], pathIds[1], pathIds[3]}}, - {id3, {pathIds[0]}}}); - - EXPECT_CALL(mockQFileSytemWatcher, removePaths(_)).Times(0); - - watcher.updateIdPaths({{id1, {pathIds[1]}}, {id2, {pathIds[3]}}}); -} - -TEST_F(ClangPathWatcher, UpdateIdPathsAndRemoveUnusedPaths) -{ - watcher.updateIdPaths({{id1, {pathIds[0], pathIds[1]}}, {id2, {pathIds[0], pathIds[1]}}, {id3, {pathIds[1]}}}); - - watcher.updateIdPaths({{id1, {pathIds[0]}}, {id2, {pathIds[1]}}}); - - ASSERT_THAT(watcher.watchedEntries(), ElementsAre(watcherEntry1, watcherEntry4, watcherEntry5)); -} - -TEST_F(ClangPathWatcher, ExtractSortedEntriesFromConvertIdPaths) -{ - auto entriesAndIds = watcher.convertIdPathsToWatcherEntriesAndIds({{id2, {pathIds[0], pathIds[1]}}, {id1, {pathIds[0], pathIds[1]}}}); - - ASSERT_THAT(entriesAndIds.first, ElementsAre(watcherEntry1, watcherEntry2, watcherEntry3, watcherEntry4)); -} - -TEST_F(ClangPathWatcher, ExtractSortedIdsFromConvertIdPaths) -{ - auto entriesAndIds = watcher.convertIdPathsToWatcherEntriesAndIds({{id2, {}}, {id1, {}}, {id3, {}}}); - - ASSERT_THAT(entriesAndIds.second, ElementsAre(ids[0], ids[1], ids[2])); -} - -TEST_F(ClangPathWatcher, MergeEntries) -{ - watcher.updateIdPaths({{id1, {pathIds[0]}}, {id2, {pathIds[1]}}}); - - ASSERT_THAT(watcher.watchedEntries(), ElementsAre(watcherEntry1, watcherEntry4)); -} - -TEST_F(ClangPathWatcher, MergeMoreEntries) -{ - watcher.updateIdPaths({{id2, {pathIds[0], pathIds[1]}}}); - - watcher.updateIdPaths({{id1, {pathIds[0], pathIds[1]}}}); - - ASSERT_THAT(watcher.watchedEntries(), ElementsAre(watcherEntry1, watcherEntry2, watcherEntry3, watcherEntry4)); -} - -TEST_F(ClangPathWatcher, AddEmptyEntries) -{ - EXPECT_CALL(mockQFileSytemWatcher, addPaths(_)) - .Times(0); - - watcher.updateIdPaths({}); -} - -TEST_F(ClangPathWatcher, AddEntriesWithSameIdAndDifferentPaths) -{ - EXPECT_CALL(mockQFileSytemWatcher, - addPaths(ElementsAre(directoryPath, directoryPath2, directoryPath3))); - - watcher.updateIdPaths({{id1, {pathIds[0], pathIds[1], pathIds[2], pathIds[4]}}}); -} - -TEST_F(ClangPathWatcher, AddEntriesWithDifferentIdAndSamePaths) -{ - EXPECT_CALL(mockQFileSytemWatcher, addPaths(ElementsAre(directoryPath))); - - watcher.updateIdPaths({{id1, {pathIds[0], pathIds[1]}}}); -} - -TEST_F(ClangPathWatcher, DontAddNewEntriesWithSameIdAndSamePaths) -{ - watcher.updateIdPaths({{id1, {pathIds[0], pathIds[1], pathIds[2], pathIds[3], pathIds[4]}}}); - - EXPECT_CALL(mockQFileSytemWatcher, addPaths(_)).Times(0); - - watcher.updateIdPaths({{id1, {pathIds[0], pathIds[1], pathIds[2], pathIds[3], pathIds[4]}}}); -} - -TEST_F(ClangPathWatcher, DontAddNewEntriesWithDifferentIdAndSamePaths) -{ - watcher.updateIdPaths({{id1, {pathIds[0], pathIds[1], pathIds[2], pathIds[3], pathIds[4]}}}); - - EXPECT_CALL(mockQFileSytemWatcher, addPaths(_)).Times(0); - - watcher.updateIdPaths({{id2, {pathIds[0], pathIds[1], pathIds[2], pathIds[3], pathIds[4]}}}); -} - -TEST_F(ClangPathWatcher, RemoveEntriesWithId) -{ - watcher.updateIdPaths({{id1, {pathIds[0], pathIds[1]}}, - {id2, {pathIds[0], pathIds[1]}}, - {id3, {pathIds[1], pathIds[3]}}}); - - watcher.removeIds({2}); - - ASSERT_THAT(watcher.watchedEntries(), ElementsAre(watcherEntry5, watcherEntry8)); -} - -TEST_F(ClangPathWatcher, RemoveNoPathsForEmptyIds) -{ - EXPECT_CALL(mockQFileSytemWatcher, removePaths(_)) - .Times(0); - - watcher.removeIds({}); -} - -TEST_F(ClangPathWatcher, RemoveNoPathsForOneId) -{ - watcher.updateIdPaths( - {{id1, {pathIds[0], pathIds[1]}}, {id2, {pathIds[0], pathIds[1], pathIds[3]}}}); - - EXPECT_CALL(mockQFileSytemWatcher, removePaths(_)) - .Times(0); - - watcher.removeIds({id3.id}); -} - -TEST_F(ClangPathWatcher, RemovePathForOneId) -{ - watcher.updateIdPaths( - {{id1, {pathIds[0], pathIds[1]}}, {id3, {pathIds[0], pathIds[1], pathIds[3]}}}); - - EXPECT_CALL(mockQFileSytemWatcher, removePaths(ElementsAre(directoryPath2))); - - watcher.removeIds({id3.id}); -} - -TEST_F(ClangPathWatcher, RemoveNoPathSecondTime) -{ - watcher.updateIdPaths( - {{id1, {pathIds[0], pathIds[1]}}, {id2, {pathIds[0], pathIds[1], pathIds[3]}}}); - watcher.removeIds({id2.id}); - - EXPECT_CALL(mockQFileSytemWatcher, removePaths(_)).Times(0); - - watcher.removeIds({id2.id}); -} - -TEST_F(ClangPathWatcher, RemoveAllPathsForThreeId) -{ - watcher.updateIdPaths( - {{id1, {pathIds[0], pathIds[1], pathIds[2]}}, {id2, {pathIds[0], pathIds[1], pathIds[3]}}}); - - EXPECT_CALL(mockQFileSytemWatcher, removePaths(ElementsAre(directoryPath, directoryPath2))); - - watcher.removeIds({id1.id, id2.id, id3.id}); -} - -TEST_F(ClangPathWatcher, RemoveOnePathForTwoId) -{ - watcher.updateIdPaths( - {{id1, {pathIds[0], pathIds[1]}}, {id2, {pathIds[0], pathIds[1]}}, {id3, {pathIds[3]}}}); - - EXPECT_CALL(mockQFileSytemWatcher, removePaths(ElementsAre(directoryPath))); - - watcher.removeIds({id1.id, id2.id}); -} - -TEST_F(ClangPathWatcher, NotAnymoreWatchedEntriesWithId) -{ - watcher.addEntries(sorted({watcherEntry1, watcherEntry2, watcherEntry3, watcherEntry4, watcherEntry5})); - - auto oldEntries = watcher.notAnymoreWatchedEntriesWithIds({watcherEntry1, watcherEntry4}, {ids[0], ids[1]}); - - ASSERT_THAT(oldEntries, ElementsAre(watcherEntry2, watcherEntry3)); -} - -TEST_F(ClangPathWatcher, RemoveUnusedEntries) -{ - watcher.addEntries(sorted({watcherEntry1, watcherEntry2, watcherEntry3, watcherEntry4, watcherEntry5})); - - watcher.removeFromWatchedEntries({watcherEntry2, watcherEntry3}); - - ASSERT_THAT(watcher.watchedEntries(), ElementsAre(watcherEntry1, watcherEntry4, watcherEntry5)); -} - -TEST_F(ClangPathWatcher, TwoNotifyFileChanges) -{ - watcher.updateIdPaths({{id1, {pathIds[0], pathIds[1], pathIds[2]}}, - {id2, {pathIds[0], pathIds[1], pathIds[2], pathIds[3], pathIds[4]}}, - {id3, {pathIds[4]}}}); - ON_CALL(mockFileSystem, lastModified(Eq(pathIds[0]))).WillByDefault(Return(2)); - ON_CALL(mockFileSystem, lastModified(Eq(pathIds[1]))).WillByDefault(Return(2)); - ON_CALL(mockFileSystem, lastModified(Eq(pathIds[3]))).WillByDefault(Return(2)); - - EXPECT_CALL(notifier, - pathsWithIdsChanged(ElementsAre(IdPaths{id1, {1, 2}}, IdPaths{id2, {1, 2, 4}}))); - - mockQFileSytemWatcher.directoryChanged(directoryPath); - mockQFileSytemWatcher.directoryChanged(directoryPath2); -} - -TEST_F(ClangPathWatcher, NotifyForPathChanges) -{ - watcher.updateIdPaths( - {{id1, {pathIds[0], pathIds[1], pathIds[2]}}, {id2, {pathIds[0], pathIds[1], pathIds[3]}}}); - ON_CALL(mockFileSystem, lastModified(Eq(pathIds[0]))).WillByDefault(Return(2)); - ON_CALL(mockFileSystem, lastModified(Eq(pathIds[3]))).WillByDefault(Return(2)); - - EXPECT_CALL(notifier, pathsChanged(ElementsAre(pathIds[0]))); - - mockQFileSytemWatcher.directoryChanged(directoryPath); -} - -TEST_F(ClangPathWatcher, NoNotifyForUnwatchedPathChanges) -{ - watcher.updateIdPaths({{id1, {pathIds[3]}}, {id2, {pathIds[3]}}}); - - EXPECT_CALL(notifier, pathsChanged(IsEmpty())); - - mockQFileSytemWatcher.directoryChanged(directoryPath); -} - -TEST_F(ClangPathWatcher, NoDuplicatePathChanges) -{ - watcher.updateIdPaths( - {{id1, {pathIds[0], pathIds[1], pathIds[2]}}, {id2, {pathIds[0], pathIds[1], pathIds[3]}}}); - ON_CALL(mockFileSystem, lastModified(Eq(pathIds[0]))).WillByDefault(Return(2)); - - EXPECT_CALL(notifier, pathsChanged(ElementsAre(pathIds[0]))); - - mockQFileSytemWatcher.directoryChanged(directoryPath); - mockQFileSytemWatcher.directoryChanged(directoryPath); -} -} // namespace diff --git a/tests/unit/unittest/clangquery-test.cpp b/tests/unit/unittest/clangquery-test.cpp deleted file mode 100644 index f17d4166138..00000000000 --- a/tests/unit/unittest/clangquery-test.cpp +++ /dev/null @@ -1,238 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" -#include "sourcerangecontainer-matcher.h" -#include "dynamicastmatcherdiagnosticcontainer-matcher.h" -#include "filesystem-utilities.h" - -#include -#include - -#include - -#include - -#include - -#include - -using ClangBackEnd::ClangQuery; -using ClangBackEnd::FilePath; -using ClangBackEnd::FilePathCaching; -using ClangBackEnd::RefactoringDatabaseInitializer; - -using testing::AllOf; -using testing::Contains; -using testing::IsEmpty; -using testing::Not; - -namespace { - -class ClangQuery : public ::testing::Test -{ -protected: - void SetUp() override; - -protected: - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - RefactoringDatabaseInitializer initializer{database}; - FilePathCaching filePathCache{database}; - ::ClangQuery simpleFunctionQuery{filePathCache}; - ::ClangQuery simpleClassQuery{filePathCache}; -}; - -using ClangQuerySlowTest = ClangQuery; - -TEST_F(ClangQuery, NoSourceRangesForDefaultConstruction) -{ - auto sourceRanges = simpleFunctionQuery.takeSourceRanges(); - - ASSERT_THAT(sourceRanges.sourceRangeWithTextContainers, IsEmpty()); -} - -TEST_F(ClangQuerySlowTest, SourceRangesForSimpleFunctionDeclarationAreNotEmpty) -{ - simpleFunctionQuery.setQuery("functionDecl()"); - - simpleFunctionQuery.findLocations(); - - ASSERT_THAT(simpleFunctionQuery.takeSourceRanges().sourceRangeWithTextContainers, Not(IsEmpty())); -} - -TEST_F(ClangQuerySlowTest, RootSourceRangeForSimpleFunctionDeclarationRange) -{ - simpleFunctionQuery.setQuery("functionDecl()"); - - simpleFunctionQuery.findLocations(); - - ASSERT_THAT(simpleFunctionQuery.takeSourceRanges().sourceRangeWithTextContainers, - Contains(IsSourceRangeWithText(1, 1, 8, 2, "int function(int* pointer, int value)\n{\n if (pointer == nullptr) {\n return value + 1;\n } else {\n return value - 1;\n }\n}"))); -} - -TEST_F(ClangQuerySlowTest, SourceRangeInUnsavedFileDeclarationRange) -{ - ::ClangQuery query(filePathCache); - query.addFile({TESTDATA_DIR "/query_simplefunction.cpp"}, - "#include \"unsaved.h\"", - {"cc", "-std=c++14"}); - query.setQuery("functionDecl()"); - ClangBackEnd::V2::FileContainer unsavedFile{{TESTDATA_DIR, "unsaved.h"}, - filePathCache.filePathId( - FilePath{TESTDATA_DIR, "unsaved.h"}), - "void unsaved();", - {}}; - query.addUnsavedFiles({unsavedFile}); - - query.findLocations(); - - ASSERT_THAT(query.takeSourceRanges().sourceRangeWithTextContainers, - Contains(IsSourceRangeWithText(1, 1, 1, 15, "void unsaved();"))); -} - -TEST_F(ClangQuerySlowTest, FileIsNotExistingButTheUnsavedDataIsParsed) -{ - ::ClangQuery query(filePathCache); - query.addFile({TESTDATA_DIR "/foo.cpp"}, "void f() {}", {"cc", "-std=c++14"}); - query.setQuery("functionDecl()"); - - query.findLocations(); - - ASSERT_THAT(query.takeSourceRanges().sourceRangeWithTextContainers, - Contains(IsSourceRangeWithText(1, 1, 1, 12, "void f() {}"))); -} - -TEST_F(ClangQuerySlowTest, DISABLED_SourceRangeInUnsavedFileDeclarationRangeOverride) // seems not to work in Clang -{ - ::ClangQuery query(filePathCache); - query.addFile({TESTDATA_DIR "/query_simplefunction.cpp"}, "void f() {}", {"cc", "-std=c++14"}); - query.setQuery("functionDecl()"); - ClangBackEnd::V2::FileContainer unsavedFile{{TESTDATA_DIR "/query_simplefunction.cpp"}, - filePathCache.filePathId( - FilePath{TESTDATA_DIR, "query_simplefunction.cpp"}), - "void unsaved();", - {}}; - query.addUnsavedFiles({unsavedFile}); - - query.findLocations(); - - ASSERT_THAT(query.takeSourceRanges().sourceRangeWithTextContainers, - Contains(IsSourceRangeWithText(1, 1, 1, 15, "void unsaved();"))); -} - -TEST_F(ClangQuerySlowTest, RootSourceRangeForSimpleFieldDeclarationRange) -{ - simpleClassQuery.setQuery("fieldDecl(hasType(isInteger()))"); - - simpleClassQuery.findLocations(); - - ASSERT_THAT(simpleClassQuery.takeSourceRanges().sourceRangeWithTextContainers.at(0), - IsSourceRangeWithText(4, 5, 4, 10, " int x;")); -} - -TEST_F(ClangQuerySlowTest, NoSourceRangesForEmptyQuery) -{ - simpleClassQuery.findLocations(); - - ASSERT_THAT(simpleClassQuery.takeSourceRanges().sourceRangeWithTextContainers, IsEmpty()); -} - -TEST_F(ClangQuerySlowTest, NoSourceRangesForWrongQuery) -{ - simpleClassQuery.setQuery("wrongQuery()"); - - simpleClassQuery.findLocations(); - - ASSERT_THAT(simpleClassQuery.takeSourceRanges().sourceRangeWithTextContainers, IsEmpty()); -} - -TEST_F(ClangQuerySlowTest, NoDiagnosticsForDefaultConstruction) -{ - auto diagnostics = simpleFunctionQuery.takeDiagnosticContainers(); - - ASSERT_THAT(diagnostics, IsEmpty()); -} - -TEST_F(ClangQuerySlowTest, DiagnosticsForEmptyQuery) -{ - simpleFunctionQuery.findLocations(); - - ASSERT_THAT(simpleFunctionQuery.takeDiagnosticContainers(), - Not(IsEmpty())); -} - -TEST_F(ClangQuerySlowTest, DiagnosticsForWrongQuery) -{ - simpleClassQuery.setQuery("wrongQuery()"); - - simpleClassQuery.findLocations(); - - ASSERT_THAT(simpleClassQuery.takeDiagnosticContainers(), - Not(IsEmpty())); -} - -TEST_F(ClangQuerySlowTest, NoDiagnosticsForAccurateQuery) -{ - simpleFunctionQuery.setQuery("functionDecl()"); - - simpleFunctionQuery.findLocations(); - - ASSERT_THAT(simpleFunctionQuery.takeDiagnosticContainers(), - IsEmpty()); -} - -TEST_F(ClangQuerySlowTest, DiagnosticForWrongQuery) -{ - simpleClassQuery.setQuery("wrongQuery()"); - - simpleClassQuery.findLocations(); - - ASSERT_THAT(simpleClassQuery.takeDiagnosticContainers(), - HasDiagnosticMessage("RegistryMatcherNotFound", 1, 1, 1, 11)); -} - -TEST_F(ClangQuerySlowTest, DiagnosticForWrongArgumenType) -{ - simpleFunctionQuery.setQuery("functionDecl(1)"); - - simpleFunctionQuery.findLocations(); - - ASSERT_THAT(simpleFunctionQuery.takeDiagnosticContainers(), - AllOf(HasDiagnosticMessage("RegistryWrongArgType", 1, 14, 1, 15), - HasDiagnosticContext("MatcherConstruct", 1, 1, 1, 13))); -} - -void ClangQuery::SetUp() -{ - simpleFunctionQuery.addFile({TESTDATA_DIR "/query_simplefunction.cpp"}, - "", - {"cc", - "-std=c++14"}); - simpleClassQuery.addFile({TESTDATA_DIR "/query_simpleclass.cpp"}, - "", - {"cc", - "-std=c++14"}); -} -} // namespace diff --git a/tests/unit/unittest/clangqueryexamplehighlightmarker-test.cpp b/tests/unit/unittest/clangqueryexamplehighlightmarker-test.cpp deleted file mode 100644 index 8af631774fe..00000000000 --- a/tests/unit/unittest/clangqueryexamplehighlightmarker-test.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" -#include "filesystem-utilities.h" -#include "mocksyntaxhighligher.h" - -#include - -namespace { -using testing::AllOf; -using testing::Contains; -using testing::IsEmpty; -using testing::Not; -using testing::InSequence; -using testing::_; - -using SourceRange = ClangBackEnd::V2::SourceRangeContainer; -using SourceRanges = ClangBackEnd::SourceRangeWithTextContainers; -using Marker = ClangRefactoring::ClangQueryExampleHighlightMarker; -using TextFormats = std::array; - -class ClangQueryExampleHighlightMarker : public testing::Test -{ -protected: - void SetUp() override; - -protected: - TextFormats textFormats = {}; - MockSyntaxHighlighter highlighter; - Marker marker{highlighter}; - -}; - -TEST_F(ClangQueryExampleHighlightMarker, NoCallForNotSourceRanges) -{ - SourceRanges sourceRanges; - Marker marker(std::move(sourceRanges), highlighter, textFormats); - - EXPECT_CALL(highlighter, setFormat(_, _, _)).Times(0); - - marker.highlightBlock(1, "foo"); -} - -TEST_F(ClangQueryExampleHighlightMarker, SingleLineSourceRange) -{ - SourceRanges sourceRanges{{1, 1, 3, 3, 1, 10, 10, "function"}}; - Marker marker(std::move(sourceRanges), highlighter, textFormats); - - EXPECT_CALL(highlighter, setFormat(2, 7, textFormats[0])); - - marker.highlightBlock(1, " function"); -} - -TEST_F(ClangQueryExampleHighlightMarker, OtherSingleLineSourceRange) -{ - SourceRanges sourceRanges{{1, 2, 5, 5, 2, 11, 11, "function"}}; - Marker marker(std::move(sourceRanges), highlighter, textFormats); - marker.highlightBlock(1, "foo"); - - EXPECT_CALL(highlighter, setFormat(4, 6, textFormats[0])); - - marker.highlightBlock(2, "void function"); -} - -TEST_F(ClangQueryExampleHighlightMarker, CascadedSingleLineSourceRanges) -{ - InSequence sequence; - SourceRanges sourceRanges{{1, 1, 2, 2, 1, 15, 15, "void function"}, - {1, 1, 2, 2, 1, 6, 6, "void"}, - {1, 1, 7, 7, 1, 15, 15, "function"}}; - Marker marker(std::move(sourceRanges), highlighter, textFormats); - - EXPECT_CALL(highlighter, setFormat(1, 13, textFormats[0])); - EXPECT_CALL(highlighter, setFormat(1, 4, textFormats[1])); - EXPECT_CALL(highlighter, setFormat(6, 8, textFormats[1])); - - marker.highlightBlock(1, "void function"); -} - -TEST_F(ClangQueryExampleHighlightMarker, DualLineSourceRanges) -{ - InSequence sequence; - SourceRanges sourceRanges{{1, 1, 2, 2, 2, 4, 20, "void f()\n {}"}}; - Marker marker(std::move(sourceRanges), highlighter, textFormats); - - EXPECT_CALL(highlighter, setFormat(1, 7, textFormats[0])); - EXPECT_CALL(highlighter, setFormat(0, 3, textFormats[0])); - - marker.highlightBlock(1, "void f()"); - marker.highlightBlock(2, " {};"); -} - -TEST_F(ClangQueryExampleHighlightMarker, MultipleLineSourceRanges) -{ - InSequence sequence; - SourceRanges sourceRanges{{1, 1, 2, 2, 3, 3, 20, "void f()\n {\n }"}}; - Marker marker(std::move(sourceRanges), highlighter, textFormats); - - EXPECT_CALL(highlighter, setFormat(1, 7, textFormats[0])); - EXPECT_CALL(highlighter, setFormat(0, 2, textFormats[0])); - EXPECT_CALL(highlighter, setFormat(0, 2, textFormats[0])); - - marker.highlightBlock(1, "void f()"); - marker.highlightBlock(2, " {"); - marker.highlightBlock(3, " };"); -} - -TEST_F(ClangQueryExampleHighlightMarker, MoreMultipleLineSourceRanges) -{ - InSequence sequence; - SourceRanges sourceRanges{{1, 1, 1, 0, 4, 2, 0, ""}, - {1, 2, 2, 0, 2, 7, 0, ""}, - {1, 3, 2, 0, 3, 7, 0, ""}}; - Marker marker(std::move(sourceRanges), highlighter, textFormats); - - EXPECT_CALL(highlighter, setFormat(0, 10, textFormats[0])); - EXPECT_CALL(highlighter, setFormat(0, 7, textFormats[0])); - EXPECT_CALL(highlighter, setFormat(1, 5, textFormats[1])); - EXPECT_CALL(highlighter, setFormat(0, 7, textFormats[0])); - EXPECT_CALL(highlighter, setFormat(1, 5, textFormats[1])); - EXPECT_CALL(highlighter, setFormat(0, 1, textFormats[0])); - - marker.highlightBlock(1, "void f() {"); - marker.highlightBlock(2, " int x;"); - marker.highlightBlock(3, " int y;"); - marker.highlightBlock(4, "};"); -} - -TEST_F(ClangQueryExampleHighlightMarker, CascadedMultipleLineSourceRanges) -{ - InSequence sequence; - SourceRanges sourceRanges{{1, 1, 1, 0, 4, 2, 0, ""}, - {1, 2, 2, 0, 3, 4, 0, ""}, - {1, 2, 11, 0, 2, 16, 0, ""}}; - Marker marker(std::move(sourceRanges), highlighter, textFormats); - - EXPECT_CALL(highlighter, setFormat(0, 9, textFormats[0])); - EXPECT_CALL(highlighter, setFormat(0, 16, textFormats[0])); - EXPECT_CALL(highlighter, setFormat(1, 15, textFormats[1])); - EXPECT_CALL(highlighter, setFormat(10, 5, textFormats[2])); - EXPECT_CALL(highlighter, setFormat(0, 3, textFormats[0])); - EXPECT_CALL(highlighter, setFormat(0, 3, textFormats[1])); - EXPECT_CALL(highlighter, setFormat(0, 1, textFormats[0])); - - marker.highlightBlock(1, "class X {"); - marker.highlightBlock(2, " int f() { int y"); - marker.highlightBlock(3, " }"); - marker.highlightBlock(4, "};"); -} - -TEST_F(ClangQueryExampleHighlightMarker, FormatSingle) -{ - SourceRange sourceRange{1, 1, 3, 3, 1, 10, 10}; - - EXPECT_CALL(highlighter, setFormat(2, 7, textFormats[0])); - - marker.formatSourceRange(sourceRange, 1, 20, 0); -} - -TEST_F(ClangQueryExampleHighlightMarker, FormatMultipleStart) -{ - SourceRange sourceRange{1, 1, 3, 3, 2, 9, 20}; - - EXPECT_CALL(highlighter, setFormat(2, 8, textFormats[0])); - - marker.formatSourceRange(sourceRange, 1, 10, 0); -} - -TEST_F(ClangQueryExampleHighlightMarker, FormatMultipleEnd) -{ - SourceRange sourceRange{1, 1, 3, 3, 2, 8, 20}; - - EXPECT_CALL(highlighter, setFormat(0, 7, textFormats[1])); - - marker.formatSourceRange(sourceRange, 2, 10, 1); -} - -TEST_F(ClangQueryExampleHighlightMarker, FormatMultipleMiddle) -{ - SourceRange sourceRange{1, 1, 3, 3, 3, 8, 20}; - - EXPECT_CALL(highlighter, setFormat(0, 10, textFormats[2])); - - marker.formatSourceRange(sourceRange, 2, 10, 2); -} - -void ClangQueryExampleHighlightMarker::SetUp() -{ - textFormats[0].setFontItalic(true); - textFormats[1].setFontCapitalization(QFont::Capitalize); - textFormats[2].setFontItalic(true); - textFormats[2].setFontCapitalization(QFont::Capitalize); - textFormats[3].setFontOverline(true); - textFormats[4].setFontCapitalization(QFont::Capitalize); - textFormats[4].setFontOverline(true); - - marker.setTextFormats(TextFormats(textFormats)); -} - -} diff --git a/tests/unit/unittest/clangquerygatherer-test.cpp b/tests/unit/unittest/clangquerygatherer-test.cpp deleted file mode 100644 index c301af4ad05..00000000000 --- a/tests/unit/unittest/clangquerygatherer-test.cpp +++ /dev/null @@ -1,357 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "filesystem-utilities.h" - -#include "sourcerangecontainer-matcher.h" - -#include -#include -#include - -#include - -#include - -#include - -namespace { - -using testing::AllOf; -using testing::AtLeast; -using testing::AtMost; -using testing::Contains; -using testing::Each; -using testing::ElementsAre; -using testing::Eq; -using testing::Field; -using testing::Ge; -using testing::IsEmpty; -using testing::Le; -using testing::NiceMock; -using testing::Pair; -using testing::PrintToString; -using testing::SizeIs; -using testing::UnorderedElementsAre; -using testing::_; - -using ClangBackEnd::FilePath; -using ClangBackEnd::SourceRangesContainer; -using ClangBackEnd::SourceRangesForQueryMessage; -using ClangBackEnd::V2::FileContainer; - -MATCHER_P2(Contains, line, column, - std::string(negation ? "isn't " : "is ") - + "(" + PrintToString(line) - + ", " + PrintToString(column) - + ")" - ) -{ - return arg.line == uint(line) - && arg.column == uint(column); -} - -class ClangQueryGatherer : public ::testing::Test -{ -protected: - void SetUp() override; - -protected: - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer databaseInitializer{database}; - ClangBackEnd::FilePathCaching filePathCache{database}; - Utils::SmallString sourceContent{"#include \"query_simplefunction.h\"\nvoid f() {}"}; - FileContainer source{{TESTDATA_DIR, "query_simplefunction.cpp"}, - filePathCache.filePathId(FilePath{TESTDATA_DIR, "query_simplefunction.cpp"}), - sourceContent.clone(), - {"cc", "-I", TESTDATA_DIR}}; - FileContainer source2{{TESTDATA_DIR, "query_simplefunction2.cpp"}, - filePathCache.filePathId(FilePath{TESTDATA_DIR, "query_simplefunction2.cpp"}), - {}, - {"cc", "-I", TESTDATA_DIR}}; - FileContainer source3{{TESTDATA_DIR, "query_simplefunction3.cpp"}, - filePathCache.filePathId(FilePath{TESTDATA_DIR, "query_simplefunction3.cpp"}), - {}, - {"cc", "-I", TESTDATA_DIR}}; - Utils::SmallString unsavedContent{"void f();"}; - FileContainer unsaved{{TESTDATA_DIR, "query_simplefunction.h"}, - filePathCache.filePathId(FilePath{TESTDATA_DIR, "query_simplefunction.h"}), - unsavedContent.clone(), - {}}; - Utils::SmallString query{"functionDecl()"}; - ClangBackEnd::ClangQueryGatherer gatherer{&filePathCache, {source.clone()}, {unsaved.clone()}, query.clone()}; - ClangBackEnd::ClangQueryGatherer manyGatherer{&filePathCache, - {source3.clone(), source2.clone(), source.clone()}, - {unsaved.clone()}, - query.clone()}; -}; - -TEST_F(ClangQueryGatherer, CreateSourceRanges) -{ - auto sourceRangesAndDiagnostics = gatherer.createSourceRangesForSource(&filePathCache, source.clone(), {unsaved}, query.clone()); - - ASSERT_THAT(sourceRangesAndDiagnostics, - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - Contains(IsSourceRangeWithText(2, 1, 2, 12, "void f() {}"))))); -} - -TEST_F(ClangQueryGatherer, CreateSourceRangessWithUnsavedContent) -{ - auto sourceRangesAndDiagnostics = gatherer.createSourceRangesForSource(&filePathCache, source.clone(), {unsaved}, query.clone()); - - ASSERT_THAT(sourceRangesAndDiagnostics, - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - Contains(IsSourceRangeWithText(1, 1, 1, 9, "void f();"))))); -} - -TEST_F(ClangQueryGatherer, CanCreateSourceRangesIfItHasSources) -{ - ASSERT_TRUE(gatherer.canCreateSourceRanges()); -} - -TEST_F(ClangQueryGatherer, CanNotCreateSourceRangesIfItHasNoSources) -{ - ClangBackEnd::ClangQueryGatherer empthyGatherer{&filePathCache, {}, {unsaved.clone()}, query.clone()}; - - ASSERT_FALSE(empthyGatherer.canCreateSourceRanges()); -} - -TEST_F(ClangQueryGatherer, CreateSourceRangesForNextSource) -{ - auto sourceRangesAndDiagnostics = gatherer.createNextSourceRanges(); - - ASSERT_THAT(sourceRangesAndDiagnostics, - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - Contains(IsSourceRangeWithText(1, 1, 1, 9, "void f();"))))); -} - -TEST_F(ClangQueryGatherer, CreateSourceRangesForNextSourcePopsSource) -{ - manyGatherer.createNextSourceRanges(); - - ASSERT_THAT(manyGatherer.sources(), SizeIs(2)); -} - -TEST_F(ClangQueryGatherer, StartCreateSourceRangesForNextSource) -{ - auto future = gatherer.startCreateNextSourceRangesMessage(); - future.wait(); - - ASSERT_THAT(future.get(), - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - Contains(IsSourceRangeWithText(1, 1, 1, 9, "void f();"))))); -} - -TEST_F(ClangQueryGatherer, StartCreateSourceRangesForNextSourcePopsSource) -{ - manyGatherer.startCreateNextSourceRangesMessage(); - - ASSERT_THAT(manyGatherer.sources(), SizeIs(2)); -} - -TEST_F(ClangQueryGatherer, AfterStartCreateSourceRangesMessagesFutureCountIsTwos) -{ - manyGatherer.startCreateNextSourceRangesMessages(); - - ASSERT_THAT(manyGatherer.sourceFutures(), SizeIs(2)); -} - -TEST_F(ClangQueryGatherer, AfterRestartCreateSourceRangesMessagesFutureCountIsTwos) -{ - manyGatherer.startCreateNextSourceRangesMessages(); - - manyGatherer.startCreateNextSourceRangesMessages(); - - ASSERT_THAT(manyGatherer.sourceFutures(), SizeIs(2)); -} - -TEST_F(ClangQueryGatherer, AfterStartCreateSourceRangesMessagesGetCollected) -{ - manyGatherer.startCreateNextSourceRangesMessages(); - - ASSERT_THAT(manyGatherer.allCurrentProcessedMessages(), - UnorderedElementsAre( - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - UnorderedElementsAre(IsSourceRangeWithText(1, 1, 1, 9, "void f();"), - IsSourceRangeWithText(2, 1, 2, 12, "void f() {}")))), - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - UnorderedElementsAre( - IsSourceRangeWithText(1, 1, 1, 13, "int header();"), - IsSourceRangeWithText(3, 1, 3, 15, "int function();")))))); -} - -TEST_F(ClangQueryGatherer, GetFinishedMessages) -{ - manyGatherer.startCreateNextSourceRangesMessages(); - manyGatherer.waitForFinished(); - - auto messages = manyGatherer.finishedMessages(); - - ASSERT_THAT(messages, - AllOf(SizeIs(2), - UnorderedElementsAre( - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - UnorderedElementsAre( - IsSourceRangeWithText(1, 1, 1, 9, "void f();"), - IsSourceRangeWithText(2, 1, 2, 12, "void f() {}")))), - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - UnorderedElementsAre( - IsSourceRangeWithText(1, 1, 1, 13, "int header();"), - IsSourceRangeWithText(3, 1, 3, 15, "int function();"))))))); -} - -TEST_F(ClangQueryGatherer, GetFinishedMessagesAfterSecondPass) -{ - manyGatherer.startCreateNextSourceRangesMessages(); - manyGatherer.waitForFinished(); - manyGatherer.finishedMessages(); - manyGatherer.startCreateNextSourceRangesMessages(); - manyGatherer.waitForFinished(); - - auto messages = manyGatherer.finishedMessages(); - - ASSERT_THAT(messages, - AllOf(SizeIs(1), - ElementsAre( - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - UnorderedElementsAre( - IsSourceRangeWithText(3, 1, 3, 15, "int function();"))))))); -} - -TEST_F(ClangQueryGatherer, FilterDuplicates) -{ - manyGatherer.setProcessingSlotCount(3); - manyGatherer.startCreateNextSourceRangesMessages(); - manyGatherer.waitForFinished(); - - auto messages = manyGatherer.finishedMessages(); - - ASSERT_THAT(messages, - AllOf(SizeIs(3), - UnorderedElementsAre( - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - UnorderedElementsAre( - IsSourceRangeWithText(1, 1, 1, 9, "void f();"), - IsSourceRangeWithText(2, 1, 2, 12, "void f() {}")))), - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - UnorderedElementsAre( - IsSourceRangeWithText(1, 1, 1, 13, "int header();"), - IsSourceRangeWithText(3, 1, 3, 15, "int function();")))), - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - UnorderedElementsAre( - IsSourceRangeWithText(3, 1, 3, 15, "int function();"))))))); -} - -TEST_F(ClangQueryGatherer, AfterGetFinishedMessagesFuturesAreReduced) -{ - manyGatherer.startCreateNextSourceRangesMessages(); - manyGatherer.waitForFinished(); - - manyGatherer.finishedMessages(); - - ASSERT_THAT(manyGatherer.sourceFutures(), SizeIs(0)); -} - -TEST_F(ClangQueryGatherer, SourceFutureIsOneInTheSecondRun) -{ - manyGatherer.startCreateNextSourceRangesMessages(); - manyGatherer.waitForFinished(); - manyGatherer.finishedMessages(); - - manyGatherer.startCreateNextSourceRangesMessages(); - - ASSERT_THAT(manyGatherer.sourceFutures(), SizeIs(1)); -} - -TEST_F(ClangQueryGatherer, GetOneMessageInTheSecondRun) -{ - manyGatherer.startCreateNextSourceRangesMessages(); - manyGatherer.waitForFinished(); - manyGatherer.finishedMessages(); - manyGatherer.startCreateNextSourceRangesMessages(); - manyGatherer.waitForFinished(); - - auto messages = manyGatherer.finishedMessages(); - - ASSERT_THAT(messages, SizeIs(1)); -} - -TEST_F(ClangQueryGatherer, IsNotFinishedIfSourcesExists) -{ - manyGatherer.startCreateNextSourceRangesMessages(); - manyGatherer.waitForFinished(); - manyGatherer.finishedMessages(); - - bool isFinished = manyGatherer.isFinished(); - - ASSERT_FALSE(isFinished); -} - -TEST_F(ClangQueryGatherer, IsNotFinishedIfSourceFuturesExists) -{ - manyGatherer.startCreateNextSourceRangesMessages(); - manyGatherer.waitForFinished(); - manyGatherer.finishedMessages(); - manyGatherer.startCreateNextSourceRangesMessages(); - - bool isFinished = manyGatherer.isFinished(); - - ASSERT_FALSE(isFinished); -} - -TEST_F(ClangQueryGatherer, IsFinishedIfNoSourceAndSourceFuturesExists) -{ - manyGatherer.startCreateNextSourceRangesMessages(); - manyGatherer.waitForFinished(); - manyGatherer.finishedMessages(); - manyGatherer.startCreateNextSourceRangesMessages(); - manyGatherer.waitForFinished(); - manyGatherer.finishedMessages(); - - bool isFinished = manyGatherer.isFinished(); - - ASSERT_TRUE(isFinished); -} - -void ClangQueryGatherer::SetUp() -{ - manyGatherer.setProcessingSlotCount(2); -} - -} diff --git a/tests/unit/unittest/clangqueryhighlightmarker-test.cpp b/tests/unit/unittest/clangqueryhighlightmarker-test.cpp deleted file mode 100644 index 05e657b9eaa..00000000000 --- a/tests/unit/unittest/clangqueryhighlightmarker-test.cpp +++ /dev/null @@ -1,390 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" -#include "filesystem-utilities.h" -#include "mocksyntaxhighligher.h" - -#include - -namespace { -using testing::AllOf; -using testing::Contains; -using testing::ElementsAre; -using testing::Pointwise; -using testing::IsEmpty; -using testing::Not; -using testing::InSequence; -using testing::_; - -using SourceRange = ClangBackEnd::V2::SourceRangeContainer; -using Message = ClangBackEnd::DynamicASTMatcherDiagnosticMessageContainer; -using Context = ClangBackEnd::DynamicASTMatcherDiagnosticContextContainer; -using Messages = ClangBackEnd::DynamicASTMatcherDiagnosticMessageContainers; -using Contexts = ClangBackEnd::DynamicASTMatcherDiagnosticContextContainers; -using Marker = ClangRefactoring::ClangQueryHighlightMarker; -using ErrorType = ClangBackEnd::ClangQueryDiagnosticErrorType; -using ContextType = ClangBackEnd::ClangQueryDiagnosticContextType; - -class ClangQueryHighlightMarker : public testing::Test -{ -protected: - void SetUp() override; - -protected: - QTextCharFormat messageTextFormat; - QTextCharFormat contextTextFormat; - MockSyntaxHighlighter highlighter; - Marker marker{highlighter}; -}; - -TEST_F(ClangQueryHighlightMarker, NoCallForNoMessagesAndContexts) -{ - Messages messages; - Contexts contexts; - marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); - - EXPECT_CALL(highlighter, setFormat(_, _, _)).Times(0); - - marker.highlightBlock(1, "foo"); -} - -TEST_F(ClangQueryHighlightMarker, CallForMessagesAndContextsForASingleLine) -{ - InSequence sequence; - Messages messages{{{1, 1, 5, 0, 1, 10, 0}, ErrorType::RegistryMatcherNotFound, {}}, - {{1, 1, 30, 0, 1, 40, 0}, ErrorType::RegistryMatcherNotFound, {}}}; - Contexts contexts{{{1, 1, 2, 0, 1, 15, 0}, ContextType::MatcherArg, {}}, - {{1, 1, 20, 0, 1, 50, 0}, ContextType::MatcherArg, {}}}; - marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); - - EXPECT_CALL(highlighter, setFormat(1, 13, contextTextFormat)); - EXPECT_CALL(highlighter, setFormat(4, 5, messageTextFormat)); - EXPECT_CALL(highlighter, setFormat(19, 30, contextTextFormat)); - EXPECT_CALL(highlighter, setFormat(29, 10, messageTextFormat)); - - marker.highlightBlock(1, "foo"); -} - -TEST_F(ClangQueryHighlightMarker, CallForMessagesForAMultiLine) -{ - InSequence sequence; - Messages messages{{{1, 1, 5, 0, 3, 3, 0}, ErrorType::RegistryMatcherNotFound, {}}}; - Contexts contexts; - marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); - - EXPECT_CALL(highlighter, setFormat(4, 8, messageTextFormat)); - EXPECT_CALL(highlighter, setFormat(0, 8, messageTextFormat)); - EXPECT_CALL(highlighter, setFormat(0, 2, messageTextFormat)); - - marker.highlightBlock(1, "declFunction("); - marker.highlightBlock(2, " decl()"); - marker.highlightBlock(3, " )"); -} - -TEST_F(ClangQueryHighlightMarker, CallForMessagesAndContextForAMultiLine) -{ - InSequence sequence; - Messages messages{{{1, 1, 5, 0, 3, 3, 0}, ErrorType::RegistryMatcherNotFound, {}}}; - Contexts contexts{{{1, 1, 2, 0, 3, 4, 0}, ContextType::MatcherArg, {}}}; - marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); - - EXPECT_CALL(highlighter, setFormat(1, 11, contextTextFormat)); - EXPECT_CALL(highlighter, setFormat(4, 8, messageTextFormat)); - EXPECT_CALL(highlighter, setFormat(0, 8, contextTextFormat)); - EXPECT_CALL(highlighter, setFormat(0, 8, messageTextFormat)); - EXPECT_CALL(highlighter, setFormat(0, 3, contextTextFormat)); - EXPECT_CALL(highlighter, setFormat(0, 2, messageTextFormat)); - - marker.highlightBlock(1, "declFunction("); - marker.highlightBlock(2, " decl()"); - marker.highlightBlock(3, " ) "); -} - -TEST_F(ClangQueryHighlightMarker, NoMessagesIfEmpty) -{ - Messages messages; - Contexts contexts; - marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); - - auto foundMessages = marker.messagesForLineAndColumn(1, 1); - - ASSERT_THAT(foundMessages, IsEmpty()); -} - -TEST_F(ClangQueryHighlightMarker, NoMessagesForBeforePosition) -{ - Messages messages{{{1, 1, 5, 0, 3, 3, 0}, - ErrorType::RegistryMatcherNotFound, - {"foo"}}}; - Contexts contexts; - marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); - - auto foundMessages = marker.messagesForLineAndColumn(1, 4); - - ASSERT_THAT(foundMessages, IsEmpty()); -} - -TEST_F(ClangQueryHighlightMarker, NoMessagesForAfterPosition) -{ - Messages messages{{{1, 1, 5, 0, 3, 3, 0}, - ErrorType::RegistryMatcherNotFound, - {"foo"}}}; - Contexts contexts; - marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); - - auto foundMessages = marker.messagesForLineAndColumn(3, 4); - - ASSERT_THAT(foundMessages, IsEmpty()); -} - -TEST_F(ClangQueryHighlightMarker, OneMessagesForInsidePosition) -{ - Message message{{1, 1, 5, 0, 3, 3, 0}, - ErrorType::RegistryMatcherNotFound, - {"foo"}}; - Messages messages{message.clone()}; - Contexts contexts; - marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); - - auto foundMessages = marker.messagesForLineAndColumn(2, 3); - - ASSERT_THAT(foundMessages, ElementsAre(message)); -} - -TEST_F(ClangQueryHighlightMarker, NoMessagesForOutsidePosition) -{ - Message message{{1, 1, 5, 0, 3, 3, 0}, - ErrorType::RegistryMatcherNotFound, - {"foo"}}; - Messages messages{message.clone()}; - Contexts contexts; - marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); - - auto foundMessages = marker.messagesForLineAndColumn(3, 4); - - ASSERT_THAT(foundMessages, IsEmpty()); -} - -TEST_F(ClangQueryHighlightMarker, AfterStartColumnBeforeLine) -{ - SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; - - bool isAfterStartColumn = marker.isInsideRange(sourceRange, 1, 6); - - ASSERT_FALSE(isAfterStartColumn); -} - -TEST_F(ClangQueryHighlightMarker, AfterStartColumnBeforeColumn) -{ - SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; - - bool isAfterStartColumn = marker.isInsideRange(sourceRange, 2, 4); - - ASSERT_FALSE(isAfterStartColumn); -} - -TEST_F(ClangQueryHighlightMarker, AfterStartColumnAtColumn) -{ - SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; - - bool isAfterStartColumn = marker.isInsideRange(sourceRange, 2, 5); - - ASSERT_TRUE(isAfterStartColumn); -} - -TEST_F(ClangQueryHighlightMarker, AfterStartColumnAfterColumn) -{ - SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; - - bool isAfterStartColumn = marker.isInsideRange(sourceRange, 2, 6); - - ASSERT_TRUE(isAfterStartColumn); -} - -TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAfterLine) -{ - SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; - - bool isBeforeEndColumn = marker.isInsideRange(sourceRange, 4, 1); - - ASSERT_FALSE(isBeforeEndColumn); -} - -TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAfterColumn) -{ - SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; - - bool isBeforeEndColumn = marker.isInsideRange(sourceRange, 3, 4); - - ASSERT_FALSE(isBeforeEndColumn); -} - -TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAtColumn) -{ - SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; - - bool isBeforeEndColumn = marker.isInsideRange(sourceRange, 3, 3); - - ASSERT_TRUE(isBeforeEndColumn); -} - -TEST_F(ClangQueryHighlightMarker, BeforeEndColumnBeforeColumn) -{ - SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; - - bool isBeforeEndColumn = marker.isInsideRange(sourceRange, 3, 2); - - ASSERT_TRUE(isBeforeEndColumn); -} - -TEST_F(ClangQueryHighlightMarker, InBetweenLineBeforeLine) -{ - SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; - - bool isInBetween = marker.isInsideRange(sourceRange, 1, 6); - - ASSERT_FALSE(isInBetween); -} - -TEST_F(ClangQueryHighlightMarker, InBetweenLineAfterLine) -{ - SourceRange sourceRange{1, 2, 5, 0, 4, 3, 0}; - - bool isInBetween = marker.isInsideRange(sourceRange, 5, 1); - - ASSERT_FALSE(isInBetween); -} - -TEST_F(ClangQueryHighlightMarker, InBetweenLine) -{ - SourceRange sourceRange{1, 2, 5, 0, 4, 3, 0}; - - bool isInBetween = marker.isInsideRange(sourceRange, 3, 1); - - ASSERT_TRUE(isInBetween); -} - -TEST_F(ClangQueryHighlightMarker, SingleLineBefore) -{ - SourceRange sourceRange{1, 2, 5, 0, 2, 10, 0}; - - bool isInRange = marker.isInsideRange(sourceRange, 2, 4); - - ASSERT_FALSE(isInRange); -} - -TEST_F(ClangQueryHighlightMarker, SingleLineAfter) -{ - SourceRange sourceRange{1, 2, 5, 0, 2, 10, 0}; - - bool isInRange = marker.isInsideRange(sourceRange, 2, 11); - - ASSERT_FALSE(isInRange); -} - -TEST_F(ClangQueryHighlightMarker, SingleLineInRange) -{ - SourceRange sourceRange{1, 2, 5, 0, 2, 10, 0}; - - bool isInRange = marker.isInsideRange(sourceRange, 2, 6); - - ASSERT_TRUE(isInRange); -} - -TEST_F(ClangQueryHighlightMarker, NoContextsIfEmpty) -{ - Messages messages; - Contexts contexts; - marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); - - auto foundContexts = marker.contextsForLineAndColumn(1, 1); - - ASSERT_THAT(foundContexts, IsEmpty()); -} - -TEST_F(ClangQueryHighlightMarker, NoContextsForBeforePosition) -{ - Messages messages; - Contexts contexts{{{1, 1, 5, 0, 3, 3, 0}, - ContextType::MatcherArg, - {"foo"}}}; - marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); - - auto foundContexts = marker.contextsForLineAndColumn(1, 4); - - ASSERT_THAT(foundContexts, IsEmpty()); -} - -TEST_F(ClangQueryHighlightMarker, NoContextsForAfterPosition) -{ - Messages messages; - Contexts contexts{{{1, 1, 5, 0, 3, 3, 0}, - ContextType::MatcherArg, - {"foo"}}}; - marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); - - auto foundContexts = marker.contextsForLineAndColumn(3, 4); - - ASSERT_THAT(foundContexts, IsEmpty()); -} - -TEST_F(ClangQueryHighlightMarker, OneContextsForInsidePosition) -{ - Context context{{1, 1, 5, 0, 3, 3, 0}, - ContextType::MatcherArg, - {"foo"}}; - Messages messages; - Contexts contexts{context.clone()}; - marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); - - auto foundContexts = marker.contextsForLineAndColumn(2, 3); - - ASSERT_THAT(foundContexts, ElementsAre(context)); -} - -TEST_F(ClangQueryHighlightMarker, NoContextsForOutsidePosition) -{ - Context context{{1, 1, 5, 0, 3, 3, 0}, - ContextType::MatcherArg, - {"foo"}}; - Messages messages; - Contexts contexts{context.clone()}; - marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); - - auto foundContexts = marker.contextsForLineAndColumn(3, 4); - - ASSERT_THAT(foundContexts, IsEmpty()); -} - -void ClangQueryHighlightMarker::SetUp() -{ - messageTextFormat.setFontItalic(true); - contextTextFormat.setFontCapitalization(QFont::Capitalize); - - marker.setTextFormats(messageTextFormat, contextTextFormat); -} - -} diff --git a/tests/unit/unittest/clangqueryprojectfindfilter-test.cpp b/tests/unit/unittest/clangqueryprojectfindfilter-test.cpp deleted file mode 100644 index 65169cb745f..00000000000 --- a/tests/unit/unittest/clangqueryprojectfindfilter-test.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockprogressmanager.h" -#include "mockrefactoringserver.h" -#include "mocksearch.h" -#include "mocksearchhandle.h" - -#include -#include - -#include - -#include -#include -#include - -namespace { - -using testing::_; -using testing::AllOf; -using testing::Field; -using testing::NiceMock; -using testing::NotNull; -using testing::Return; -using testing::ReturnNew; -using testing::DefaultValue; -using testing::ByMove; - -using CppTools::CompilerOptionsBuilder; -using ClangBackEnd::V2::FileContainer; - -std::vector createCommandLines( - const std::vector &projectParts) -{ - using Filter = ClangRefactoring::ClangQueryProjectsFindFilter; - - std::vector commandLines; - - for (const CppTools::ProjectPart::Ptr &projectPart : projectParts) { - for (const CppTools::ProjectFile &projectFile : projectPart->files) { - Utils::SmallStringVector commandLine = Filter::compilerArguments(projectPart.data(), - projectFile.kind); - commandLine.emplace_back(projectFile.path); - commandLines.push_back(commandLine); - } - } - - return commandLines; -} - -class ClangQueryProjectFindFilter : public ::testing::Test -{ -protected: - void SetUp() - { - projectsParts = createProjectParts(); - commandLines = createCommandLines(projectsParts); - - findFilter.setProjectParts(projectsParts); - findFilter.setUnsavedContent({unsavedContent.clone()}); - - ON_CALL(mockSearch, startNewSearch(QStringLiteral("Clang Query"), findDeclQueryText)) - .WillByDefault(Return(ByMove(createSearchHandle()))); - } - std::unique_ptr createSearchHandle() - { - auto handle = std::make_unique>(); - handle->setRefactoringServer(&mockRefactoringServer); - - return handle; - } - - std::vector createProjectParts() - { - auto projectPart1 = CppTools::ProjectPart::Ptr(new CppTools::ProjectPart); - projectPart1->project = &project; - projectPart1->files.append({"/path/to/file1.h", CppTools::ProjectFile::CXXHeader}); - projectPart1->files.append({"/path/to/file1.cpp", CppTools::ProjectFile::CXXSource}); - - auto projectPart2 = CppTools::ProjectPart::Ptr(new CppTools::ProjectPart); - projectPart2->project = &project; - projectPart2->files.append({"/path/to/file2.cpp", CppTools::ProjectFile::CXXSource}); - projectPart2->files.append({"/path/to/unsaved.cpp", CppTools::ProjectFile::CXXSource}); - projectPart2->files.append({"/path/to/cheader.h", CppTools::ProjectFile::CHeader}); - - return {projectPart1, projectPart2}; - } - -protected: - NiceMock mockRefactoringServer; - NiceMock mockSearch; - NiceMock mockProgressManager; - ClangRefactoring::RefactoringClient refactoringClient{mockProgressManager}; - ClangRefactoring::ClangQueryProjectsFindFilter findFilter{mockRefactoringServer, mockSearch, refactoringClient}; - QString findDeclQueryText{"functionDecl()"}; - QString curentDocumentFilePath{"/path/to/file.cpp"}; - QString unsavedDocumentContent{"void f();"}; - std::vector commandLines; - std::vector projectsParts; - ClangBackEnd::V2::FileContainer unsavedContent{{"/path/to", "unsaved.cpp"}, 1, "void f();", {}}; - ProjectExplorer::Project project; -}; - -TEST_F(ClangQueryProjectFindFilter, SupportedFindFlags) -{ - auto findFlags = findFilter.supportedFindFlags(); - - ASSERT_FALSE(findFlags); -} - -TEST_F(ClangQueryProjectFindFilter, IsNotUsableForUnusableServer) -{ - auto isUsable = findFilter.isAvailable(); - - ASSERT_FALSE(isUsable); -} - -TEST_F(ClangQueryProjectFindFilter, IsUsableForUsableServer) -{ - mockRefactoringServer.setAvailable(true); - - auto isUsable = findFilter.isAvailable(); - - ASSERT_TRUE(isUsable); -} - -TEST_F(ClangQueryProjectFindFilter, ServerIsUsableForUsableFindFilter) -{ - findFilter.setAvailable(true); - - auto isUsable = mockRefactoringServer.isAvailable(); - - ASSERT_TRUE(isUsable); -} - -TEST_F(ClangQueryProjectFindFilter, SearchHandleSetIsSetAfterFindAll) -{ - findFilter.find(findDeclQueryText); - - auto searchHandle = refactoringClient.searchHandle(); - - ASSERT_THAT(searchHandle, NotNull()); -} - -TEST_F(ClangQueryProjectFindFilter, FindAllIsCallingStartNewSearch) -{ - EXPECT_CALL(mockSearch, startNewSearch(QStringLiteral("Clang Query"), - findDeclQueryText)); - - findFilter.find(findDeclQueryText); -} - -TEST_F(ClangQueryProjectFindFilter, FindAllIsSettingExprectedResultCountInTheRefactoringClient) -{ - findFilter.find(findDeclQueryText); - - ASSERT_THAT(refactoringClient.expectedResultCount(), 3); -} - -TEST_F(ClangQueryProjectFindFilter, FindAllIsCallingRequestSourceRangesAndDiagnosticsForQueryMessage) -{ - ClangBackEnd::RequestSourceRangesForQueryMessage message( - findDeclQueryText, - {{{"/path/to", "file1.h"}, 1, "", commandLines[0].clone()}, - {{"/path/to", "file1.cpp"}, 2, "", commandLines[1].clone()}, - {{"/path/to", "file2.cpp"}, 3, "", commandLines[2].clone()}}, - {unsavedContent.clone()}); - - EXPECT_CALL(mockRefactoringServer, requestSourceRangesForQueryMessage(message)); - - findFilter.find(findDeclQueryText); -} - -TEST_F(ClangQueryProjectFindFilter, CancelSearch) -{ - auto searchHandle = findFilter.find(findDeclQueryText); - - EXPECT_CALL(mockRefactoringServer, cancel()); - - searchHandle->cancel(); -} - -TEST_F(ClangQueryProjectFindFilter, CallingRequestSourceRangesAndDiagnostics) -{ - using Message = ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage; - Utils::SmallString queryText = "functionDecl()"; - Utils::SmallString exampleContent = "void foo();"; - - EXPECT_CALL(mockRefactoringServer, - requestSourceRangesAndDiagnosticsForQueryMessage( - AllOf( - Field(&Message::source, - Field(&FileContainer::unsavedFileContent, exampleContent)), - Field(&Message::query, queryText)))); - - findFilter.requestSourceRangesAndDiagnostics(QString(queryText), QString(exampleContent)); -} - -} diff --git a/tests/unit/unittest/commandlinebuilder-test.cpp b/tests/unit/unittest/commandlinebuilder-test.cpp deleted file mode 100644 index ee164380396..00000000000 --- a/tests/unit/unittest/commandlinebuilder-test.cpp +++ /dev/null @@ -1,660 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "filesystem-utilities.h" - -#include -#include -#include -#include - -namespace { -template -using Builder = ClangBackEnd::CommandLineBuilder; - -using ClangBackEnd::FilePath; -using ClangBackEnd::IncludeSearchPathType; -using ClangBackEnd::InputFileType; - -template -class CommandLineBuilder : public testing::Test -{ -}; - -template <> -class CommandLineBuilder : public testing::Test -{ -public: - CommandLineBuilder() { cppProjectInfo.language = Utils::Language::Cxx; } - -public: - ClangBackEnd::PchTask emptyProjectInfo{0, {}, {}, {}, {}, {}, {}, {}, {}, {}}; - ClangBackEnd::PchTask cppProjectInfo{1, {}, {}, {}, {}, {}, {}, {}, {}, {}}; -}; - -template <> -class CommandLineBuilder : public testing::Test -{ -public: - CommandLineBuilder() { cppProjectInfo.language = Utils::Language::Cxx; } - -public: - ClangBackEnd::ProjectPartContainer emptyProjectInfo{0, - {}, - {}, - {}, - {}, - {}, - {}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX98, - Utils::LanguageExtension::None}; - ClangBackEnd::ProjectPartContainer cppProjectInfo{1, - {}, - {}, - {}, - {}, - {}, - {}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX98, - Utils::LanguageExtension::None}; -}; - -template <> -class CommandLineBuilder : public testing::Test -{ -public: - CommandLineBuilder() { cppProjectInfo.language = Utils::Language::Cxx; } - -public: - ClangBackEnd::ProjectPartArtefact emptyProjectInfo{{}, - {}, - {}, - {}, - {}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX98, - Utils::LanguageExtension::None}; - ClangBackEnd::ProjectPartArtefact cppProjectInfo{{}, - {}, - {}, - {}, - {}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX98, - Utils::LanguageExtension::None}; -}; - -using ProjectInfos = testing::Types; -TYPED_TEST_SUITE(CommandLineBuilder, ProjectInfos); - -TYPED_TEST(CommandLineBuilder, AddToolChainArguments) -{ - Builder builder{this->emptyProjectInfo, {"-m64", "-PIC"}, InputFileType::Header, {}}; - - ASSERT_THAT(builder.commandLine, AllOf(Contains("-m64"), Contains("-PIC"))); -} - -TYPED_TEST(CommandLineBuilder, CHeader) -{ - this->emptyProjectInfo.language = Utils::Language::C; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C11; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; - - ASSERT_THAT(builder.commandLine, - ElementsAre("clang", - "-w", - "-DNOMINMAX", - "-x", - "c-header", - "-std=c11", - "-nostdinc", - toNativePath("/source/file.c"))); -} - -TYPED_TEST(CommandLineBuilder, CSource) -{ - this->emptyProjectInfo.language = Utils::Language::C; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C11; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Source, "/source/file.c"}; - - ASSERT_THAT(builder.commandLine, - ElementsAre("clang", - "-w", - "-DNOMINMAX", - "-x", - "c", - "-std=c11", - "-nostdinc", - toNativePath("/source/file.c"))); -} - -TYPED_TEST(CommandLineBuilder, ObjectiveCHeader) -{ - this->emptyProjectInfo.language = Utils::Language::C; - this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::ObjectiveC; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C11; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; - - ASSERT_THAT(builder.commandLine, - ElementsAre("clang", - "-w", - "-DNOMINMAX", - "-x", - "objective-c-header", - "-std=c11", - "-nostdinc", - toNativePath("/source/file.c"))); -} - -TYPED_TEST(CommandLineBuilder, ObjectiveCSource) -{ - this->emptyProjectInfo.language = Utils::Language::C; - this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::ObjectiveC; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C11; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Source, "/source/file.c"}; - - ASSERT_THAT(builder.commandLine, - ElementsAre("clang", - "-w", - "-DNOMINMAX", - "-x", - "objective-c", - "-std=c11", - "-nostdinc", - toNativePath("/source/file.c"))); -} - -TYPED_TEST(CommandLineBuilder, CppHeader) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX98; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, - ElementsAre("clang++", - "-w", - "-DNOMINMAX", - "-x", - "c++-header", - "-std=c++98", - "-nostdinc", - "-nostdinc++", - toNativePath("/source/file.cpp"))); -} - -TYPED_TEST(CommandLineBuilder, CppSource) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX98; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Source, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, - ElementsAre("clang++", - "-w", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++98", - "-nostdinc", - "-nostdinc++", - toNativePath("/source/file.cpp"))); -} - -TYPED_TEST(CommandLineBuilder, ObjectiveCppHeader) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::ObjectiveC; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX98; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, - ElementsAre("clang++", - "-w", - "-DNOMINMAX", - "-x", - "objective-c++-header", - "-std=c++98", - "-nostdinc", - "-nostdinc++", - toNativePath("/source/file.cpp"))); -} - -TYPED_TEST(CommandLineBuilder, ObjectiveCppSource) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::ObjectiveC; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX98; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Source, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, - ElementsAre("clang++", - "-w", - "-DNOMINMAX", - "-x", - "objective-c++", - "-std=c++98", - "-nostdinc", - "-nostdinc++", - toNativePath("/source/file.cpp"))); -} - -TYPED_TEST(CommandLineBuilder, Cpp98) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX98; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=c++98")); -} - -TYPED_TEST(CommandLineBuilder, Cpp03) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX03; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=c++03")); -} - -TYPED_TEST(CommandLineBuilder, Cpp11) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX11; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=c++11")); -} - -TYPED_TEST(CommandLineBuilder, Cpp14) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX14; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=c++14")); -} - -TYPED_TEST(CommandLineBuilder, Cpp17) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX17; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=c++17")); -} - -TYPED_TEST(CommandLineBuilder, Cpp20) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX2a; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=c++2a")); -} - -TYPED_TEST(CommandLineBuilder, GnuCpp98) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX98; - this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=gnu++98")); -} - -TYPED_TEST(CommandLineBuilder, GnuCpp03) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX03; - this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=gnu++03")); -} - -TYPED_TEST(CommandLineBuilder, GnuCpp11) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX11; - this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=gnu++11")); -} - -TYPED_TEST(CommandLineBuilder, GnuCpp14) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX14; - this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=gnu++14")); -} - -TYPED_TEST(CommandLineBuilder, GnuCpp17) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX17; - this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=gnu++17")); -} - -TYPED_TEST(CommandLineBuilder, GnuCpp20) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX2a; - this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=gnu++2a")); -} - -TYPED_TEST(CommandLineBuilder, C89) -{ - this->emptyProjectInfo.language = Utils::Language::C; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C89; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=c89")); -} - -TYPED_TEST(CommandLineBuilder, C99) -{ - this->emptyProjectInfo.language = Utils::Language::C; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C99; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=c99")); -} - -TYPED_TEST(CommandLineBuilder, C11) -{ - this->emptyProjectInfo.language = Utils::Language::C; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C11; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=c11")); -} - -TYPED_TEST(CommandLineBuilder, C18) -{ - this->emptyProjectInfo.language = Utils::Language::C; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C18; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=c17")); -} - -TYPED_TEST(CommandLineBuilder, GnuC89) -{ - this->emptyProjectInfo.language = Utils::Language::C; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C89; - this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=gnu89")); -} - -TYPED_TEST(CommandLineBuilder, GnuC99) -{ - this->emptyProjectInfo.language = Utils::Language::C; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C99; - this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=gnu99")); -} - -TYPED_TEST(CommandLineBuilder, GnuC11) -{ - this->emptyProjectInfo.language = Utils::Language::C; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C11; - this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=gnu11")); -} - -TYPED_TEST(CommandLineBuilder, GnuC18) -{ - this->emptyProjectInfo.language = Utils::Language::C; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C18; - this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; - - ASSERT_THAT(builder.commandLine, Contains("-std=gnu17")); -} - -TYPED_TEST(CommandLineBuilder, IncludesOrder) -{ - this->emptyProjectInfo.language = Utils::Language::Cxx; - this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX11; - this->emptyProjectInfo.projectIncludeSearchPaths = {{"/include/bar", 2, IncludeSearchPathType::User}, - {"/include/foo", 1, IncludeSearchPathType::User}}; - this->emptyProjectInfo.systemIncludeSearchPaths = {{"/system/bar", 4, IncludeSearchPathType::System}, - {"/system/foo", 3, IncludeSearchPathType::Framework}, - {"/builtin/bar", 2, IncludeSearchPathType::BuiltIn}, - {"/builtin/foo", 1, IncludeSearchPathType::BuiltIn}}; - Builder builder{this->emptyProjectInfo, - {}, - InputFileType::Header, - "/source/file.cpp", - {}, - {}, - ClangBackEnd::NativeFilePath{FilePath{"/resource/path"}}}; - - ASSERT_THAT(builder.commandLine, - ElementsAre("clang++", - "-w", - "-DNOMINMAX", - "-x", - "c++-header", - "-std=c++11", - "-nostdinc", - "-nostdinc++", - "-isystem", - toNativePath("/resource/path"), - "-I", - toNativePath("/include/foo"), - "-I", - toNativePath("/include/bar"), - "-F", - toNativePath("/system/foo"), - "-isystem", - toNativePath("/system/bar"), - "-isystem", - toNativePath("/builtin/foo"), - "-isystem", - toNativePath("/builtin/bar"), - toNativePath("/source/file.cpp"))); -} - -TYPED_TEST(CommandLineBuilder, EmptySourceFile) -{ - Builder builder{this->emptyProjectInfo, {}, {}}; - - ASSERT_THAT(builder.commandLine, - ElementsAre("clang++", - "-w", - "-DNOMINMAX", - "-x", - "c++-header", - "-std=c++98", - "-nostdinc", - "-nostdinc++")); -} - -TYPED_TEST(CommandLineBuilder, SourceFile) -{ - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; - - ASSERT_THAT(builder.commandLine, - ElementsAre("clang++", - "-w", - "-DNOMINMAX", - "-x", - "c++-header", - "-std=c++98", - "-nostdinc", - "-nostdinc++", - toNativePath("/source/file.cpp"))); -} - - -TYPED_TEST(CommandLineBuilder, EmptyOutputFile) -{ - Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp", ""}; - - ASSERT_THAT(builder.commandLine, - ElementsAre("clang++", - "-w", - "-DNOMINMAX", - "-x", - "c++-header", - "-std=c++98", - "-nostdinc", - "-nostdinc++", - toNativePath("/source/file.cpp"))); -} - -TYPED_TEST(CommandLineBuilder, OutputFile) -{ - Builder builder{this->emptyProjectInfo, - {}, - InputFileType::Header, - "/source/file.cpp", - "/output/file.o"}; - - ASSERT_THAT(builder.commandLine, - ElementsAre("clang++", - "-w", - "-DNOMINMAX", - "-x", - "c++-header", - "-std=c++98", - "-nostdinc", - "-nostdinc++", - "-o", - toNativePath("/output/file.o"), - toNativePath("/source/file.cpp"))); -} - -TYPED_TEST(CommandLineBuilder, PreIncludeSearchPath) -{ - Builder builder{this->emptyProjectInfo, - {}, - {}, - {}, - {}, - {}, - ClangBackEnd::NativeFilePath{FilePath{"/resource/path"}}}; - - ASSERT_THAT(builder.commandLine, Contains(toNativePath("/resource/path"))); -} - -TYPED_TEST(CommandLineBuilder, IncludePchPath) -{ - Builder builder{this->emptyProjectInfo, - {}, - InputFileType::Header, - "/source/file.cpp", - "/output/file.o", - "/pch/file.pch"}; - - ASSERT_THAT(builder.commandLine, - ElementsAre("clang++", - "-w", - "-DNOMINMAX", - "-x", - "c++-header", - "-std=c++98", - "-nostdinc", - "-nostdinc++", - "-Xclang", - "-include-pch", - "-Xclang", - toNativePath("/pch/file.pch"), - "-o", - toNativePath("/output/file.o"), - toNativePath("/source/file.cpp"))); -} - -TYPED_TEST(CommandLineBuilder, CompilerMacros) -{ - this->emptyProjectInfo.compilerMacros = {{"YI", "1", 2}, {"ER", "2", 1}, {"SAN"}}; - - Builder builder{this->emptyProjectInfo}; - - ASSERT_THAT(builder.commandLine, - ElementsAre("clang++", - "-w", - "-DNOMINMAX", - "-x", - "c++-header", - "-std=c++98", - "-nostdinc", - "-nostdinc++", - "-DER=2", - "-DYI=1")); -} - -} // namespace diff --git a/tests/unit/unittest/creator_dependency.pri b/tests/unit/unittest/creator_dependency.pri index 84d1f181845..739752649ce 100644 --- a/tests/unit/unittest/creator_dependency.pri +++ b/tests/unit/unittest/creator_dependency.pri @@ -9,10 +9,6 @@ include($$PWD/../../../src/libs/sqlite/sqlite-lib.pri) include($$PWD/../../../src/libs/clangsupport/clangsupport-lib.pri) include($$PWD/../../../src/plugins/coreplugin/corepluginunittestfiles.pri) include($$PWD/../../../src/plugins/projectexplorer/projectexplorerunittestfiles.pri) -include($$PWD/../../../src/tools/clangrefactoringbackend/source/clangrefactoringbackend-source.pri) -include($$PWD/../../../src/tools/clangpchmanagerbackend/source/clangpchmanagerbackend-source.pri) -include($$PWD/../../../src/plugins/clangrefactoring/clangrefactoring-source.pri) -include($$PWD/../../../src/plugins/clangpchmanager/clangpchmanager-source.pri) include($$PWD/../../../src/plugins/cpptools/cpptoolsunittestfiles.pri) include($$PWD/../../../src/plugins/debugger/debuggerunittestfiles.pri) include($$PWD/../../../src/plugins/compilationdatabaseprojectmanager/compilationdatabaseunittestfiles.pri) diff --git a/tests/unit/unittest/data/builddependencycollector/external/external1.h b/tests/unit/unittest/data/builddependencycollector/external/external1.h deleted file mode 100644 index 6bc9da6c80d..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/external/external1.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "indirect_external.h" diff --git a/tests/unit/unittest/data/builddependencycollector/external/external2.h b/tests/unit/unittest/data/builddependencycollector/external/external2.h deleted file mode 100644 index 6f70f09beec..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/external/external2.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/tests/unit/unittest/data/builddependencycollector/external/external3.h b/tests/unit/unittest/data/builddependencycollector/external/external3.h deleted file mode 100644 index 6f70f09beec..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/external/external3.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/tests/unit/unittest/data/builddependencycollector/external/indirect_external.h b/tests/unit/unittest/data/builddependencycollector/external/indirect_external.h deleted file mode 100644 index 33e9663b635..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/external/indirect_external.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "indirect_external2.h" diff --git a/tests/unit/unittest/data/builddependencycollector/external/indirect_external2.h b/tests/unit/unittest/data/builddependencycollector/external/indirect_external2.h deleted file mode 100644 index 3f59c932d39..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/external/indirect_external2.h +++ /dev/null @@ -1,2 +0,0 @@ -#pragma once - diff --git a/tests/unit/unittest/data/builddependencycollector/project/false.h b/tests/unit/unittest/data/builddependencycollector/project/false.h deleted file mode 100644 index 3f59c932d39..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/false.h +++ /dev/null @@ -1,2 +0,0 @@ -#pragma once - diff --git a/tests/unit/unittest/data/builddependencycollector/project/faulty.cpp b/tests/unit/unittest/data/builddependencycollector/project/faulty.cpp deleted file mode 100644 index e6697eb5d96..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/faulty.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "faulty.h" diff --git a/tests/unit/unittest/data/builddependencycollector/project/faulty.h b/tests/unit/unittest/data/builddependencycollector/project/faulty.h deleted file mode 100644 index 4a0601f95b1..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/faulty.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -IDENTIFICATION DIVISION. -PROGRAM-ID. HELLO-WORLD. -* simple hello world program -PROCEDURE DIVISION. - DISPLAY 'Hello world!'. - STOP RUN. diff --git a/tests/unit/unittest/data/builddependencycollector/project/header1.h b/tests/unit/unittest/data/builddependencycollector/project/header1.h deleted file mode 100644 index 3f59c932d39..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/header1.h +++ /dev/null @@ -1,2 +0,0 @@ -#pragma once - diff --git a/tests/unit/unittest/data/builddependencycollector/project/header2.h b/tests/unit/unittest/data/builddependencycollector/project/header2.h deleted file mode 100644 index 851c723be56..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/header2.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "external3.h" diff --git a/tests/unit/unittest/data/builddependencycollector/project/if.cpp b/tests/unit/unittest/data/builddependencycollector/project/if.cpp deleted file mode 100644 index f148f0bd9c8..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/if.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#if 0 -#include "false.h" -#endif - -#if 1 -#include "true.h" -#endif diff --git a/tests/unit/unittest/data/builddependencycollector/project/indirect_missinginclude.h b/tests/unit/unittest/data/builddependencycollector/project/indirect_missinginclude.h deleted file mode 100644 index 324bea5fb8f..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/indirect_missinginclude.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "indirect_missinginclude3.h" diff --git a/tests/unit/unittest/data/builddependencycollector/project/indirect_missinginclude2.h b/tests/unit/unittest/data/builddependencycollector/project/indirect_missinginclude2.h deleted file mode 100644 index 7f27dc6a301..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/indirect_missinginclude2.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "indirect_missinginclude4.h" diff --git a/tests/unit/unittest/data/builddependencycollector/project/indirect_missinginclude3.h b/tests/unit/unittest/data/builddependencycollector/project/indirect_missinginclude3.h deleted file mode 100644 index 7f27dc6a301..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/indirect_missinginclude3.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "indirect_missinginclude4.h" diff --git a/tests/unit/unittest/data/builddependencycollector/project/indirect_missinginclude4.h b/tests/unit/unittest/data/builddependencycollector/project/indirect_missinginclude4.h deleted file mode 100644 index 6aa39b59138..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/indirect_missinginclude4.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include "indirect_missinginclude3.h" - -#include "not_found" diff --git a/tests/unit/unittest/data/builddependencycollector/project/macros.h b/tests/unit/unittest/data/builddependencycollector/project/macros.h deleted file mode 100644 index 3b7d254ad87..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/macros.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#define DEFINE - -#ifdef IFDEF -#endif - -#if defined(DEFINED) -#endif -DEFINE - diff --git a/tests/unit/unittest/data/builddependencycollector/project/main.cpp b/tests/unit/unittest/data/builddependencycollector/project/main.cpp deleted file mode 100644 index caa808606ce..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/main.cpp +++ /dev/null @@ -1,4 +0,0 @@ -#include "header1.h" -#include "header2.h" -#include "external1.h" -#include "../external/external2.h" diff --git a/tests/unit/unittest/data/builddependencycollector/project/main2.cpp b/tests/unit/unittest/data/builddependencycollector/project/main2.cpp deleted file mode 100644 index fb7d23d9723..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/main2.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "header1.h" -#include "header2.h" -#include "external1.h" -#include "../external/external2.h" -#include "generated_file.h" diff --git a/tests/unit/unittest/data/builddependencycollector/project/main3.cpp b/tests/unit/unittest/data/builddependencycollector/project/main3.cpp deleted file mode 100644 index 7f206d44f72..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/main3.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include -#include -#include -#include -#include - diff --git a/tests/unit/unittest/data/builddependencycollector/project/main4.cpp b/tests/unit/unittest/data/builddependencycollector/project/main4.cpp deleted file mode 100644 index bb348e8a024..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/main4.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include "missingfile.h" -#include "missingfile.h" -#include -#include <../external/external1.h> -#include <../external/external2.h> -#include -#include "macros.h" -#include "generated_file.h" diff --git a/tests/unit/unittest/data/builddependencycollector/project/main5.cpp b/tests/unit/unittest/data/builddependencycollector/project/main5.cpp deleted file mode 100644 index 026355e1c36..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/main5.cpp +++ /dev/null @@ -1,4 +0,0 @@ -#include "missinginclude2.h" -#include "missinginclude3.h" - -#include "header1.h" diff --git a/tests/unit/unittest/data/builddependencycollector/project/main6.cpp b/tests/unit/unittest/data/builddependencycollector/project/main6.cpp deleted file mode 100644 index dfb8e42a3aa..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/main6.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "generated/generated_file.h" -#include "generated/generated_file.h" - diff --git a/tests/unit/unittest/data/builddependencycollector/project/missingfile.cpp b/tests/unit/unittest/data/builddependencycollector/project/missingfile.cpp deleted file mode 100644 index 6f3a7ea58cc..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/missingfile.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "missing_file.moc" -#include "foo/missing_file.moc" -#include -#include - -#include "external1.h" diff --git a/tests/unit/unittest/data/builddependencycollector/project/missingfile.h b/tests/unit/unittest/data/builddependencycollector/project/missingfile.h deleted file mode 100644 index 1ac1ed43d7c..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/missingfile.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "missing_file.moc" -#include "foo/missing_file.moc" -#include -#include - -#include "external1.h" diff --git a/tests/unit/unittest/data/builddependencycollector/project/missinginclude2.h b/tests/unit/unittest/data/builddependencycollector/project/missinginclude2.h deleted file mode 100644 index 13e50097a4c..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/missinginclude2.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "indirect_missinginclude.h" diff --git a/tests/unit/unittest/data/builddependencycollector/project/missinginclude3.h b/tests/unit/unittest/data/builddependencycollector/project/missinginclude3.h deleted file mode 100644 index ca6a11162db..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/missinginclude3.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "indirect_missinginclude2.h" diff --git a/tests/unit/unittest/data/builddependencycollector/project/true.h b/tests/unit/unittest/data/builddependencycollector/project/true.h deleted file mode 100644 index 3f59c932d39..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/project/true.h +++ /dev/null @@ -1,2 +0,0 @@ -#pragma once - diff --git a/tests/unit/unittest/data/builddependencycollector/system/indirect_system.h b/tests/unit/unittest/data/builddependencycollector/system/indirect_system.h deleted file mode 100644 index e0fa22c9d9e..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/system/indirect_system.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "indirect_system2.h" diff --git a/tests/unit/unittest/data/builddependencycollector/system/indirect_system2.h b/tests/unit/unittest/data/builddependencycollector/system/indirect_system2.h deleted file mode 100644 index 3f59c932d39..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/system/indirect_system2.h +++ /dev/null @@ -1,2 +0,0 @@ -#pragma once - diff --git a/tests/unit/unittest/data/builddependencycollector/system/system1.h b/tests/unit/unittest/data/builddependencycollector/system/system1.h deleted file mode 100644 index 98e09cd083a..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/system/system1.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "indirect_system.h" diff --git a/tests/unit/unittest/data/builddependencycollector/system/system2.h b/tests/unit/unittest/data/builddependencycollector/system/system2.h deleted file mode 100644 index 6f70f09beec..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/system/system2.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/tests/unit/unittest/data/builddependencycollector/system/system3.h b/tests/unit/unittest/data/builddependencycollector/system/system3.h deleted file mode 100644 index 6f70f09beec..00000000000 --- a/tests/unit/unittest/data/builddependencycollector/system/system3.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/tests/unit/unittest/data/filestatuscache_header.cpp b/tests/unit/unittest/data/filestatuscache_header.cpp deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/tests/unit/unittest/data/filestatuscache_header.h b/tests/unit/unittest/data/filestatuscache_header.h deleted file mode 100644 index 8b137891791..00000000000 --- a/tests/unit/unittest/data/filestatuscache_header.h +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/unit/unittest/data/preincludes/system1.h b/tests/unit/unittest/data/preincludes/system1.h deleted file mode 100644 index 005a65916e3..00000000000 --- a/tests/unit/unittest/data/preincludes/system1.h +++ /dev/null @@ -1 +0,0 @@ -#include_next diff --git a/tests/unit/unittest/data/query_simpleclass.cpp b/tests/unit/unittest/data/query_simpleclass.cpp deleted file mode 100644 index 635e9fb7940..00000000000 --- a/tests/unit/unittest/data/query_simpleclass.cpp +++ /dev/null @@ -1,8 +0,0 @@ -class Class -{ -public: - int x; - - - -}; diff --git a/tests/unit/unittest/data/query_simplefunction.cpp b/tests/unit/unittest/data/query_simplefunction.cpp deleted file mode 100644 index 189ac84d173..00000000000 --- a/tests/unit/unittest/data/query_simplefunction.cpp +++ /dev/null @@ -1,8 +0,0 @@ -int function(int* pointer, int value) -{ - if (pointer == nullptr) { - return value + 1; - } else { - return value - 1; - } -} diff --git a/tests/unit/unittest/data/query_simplefunction2.cpp b/tests/unit/unittest/data/query_simplefunction2.cpp deleted file mode 100644 index fbf4d8d8fd0..00000000000 --- a/tests/unit/unittest/data/query_simplefunction2.cpp +++ /dev/null @@ -1,4 +0,0 @@ -#include "query_simplefunction2.h" - -int function(); - diff --git a/tests/unit/unittest/data/query_simplefunction2.h b/tests/unit/unittest/data/query_simplefunction2.h deleted file mode 100644 index 9251cf100a9..00000000000 --- a/tests/unit/unittest/data/query_simplefunction2.h +++ /dev/null @@ -1,2 +0,0 @@ -int header(); - diff --git a/tests/unit/unittest/data/query_simplefunction3.cpp b/tests/unit/unittest/data/query_simplefunction3.cpp deleted file mode 100644 index fbf4d8d8fd0..00000000000 --- a/tests/unit/unittest/data/query_simplefunction3.cpp +++ /dev/null @@ -1,4 +0,0 @@ -#include "query_simplefunction2.h" - -int function(); - diff --git a/tests/unit/unittest/data/renamevariable.cpp b/tests/unit/unittest/data/renamevariable.cpp deleted file mode 100644 index 638fddf56ca..00000000000 --- a/tests/unit/unittest/data/renamevariable.cpp +++ /dev/null @@ -1,20 +0,0 @@ -int variable; - -int x = variable + 3; - -template -class TemplateKlasse { -public: - TemplateName value; -}; - -void function() -{ - TemplateKlasse instance; - - instance.value += 5; - - auto l = [x=instance] { - int k = x.value + 3; - }; -} diff --git a/tests/unit/unittest/data/sourcerangeextractor_location.cpp b/tests/unit/unittest/data/sourcerangeextractor_location.cpp deleted file mode 100644 index 8e63dcf97ec..00000000000 --- a/tests/unit/unittest/data/sourcerangeextractor_location.cpp +++ /dev/null @@ -1,2 +0,0 @@ -int value; - diff --git a/tests/unit/unittest/data/symbolfinder_macro.cpp b/tests/unit/unittest/data/symbolfinder_macro.cpp deleted file mode 100644 index 30f1caff9f5..00000000000 --- a/tests/unit/unittest/data/symbolfinder_macro.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#define Macro 40 - -int main(int argc, char *argv[]) -{ - int x = 5 + Macro; - -#undef Macro -#define Macro 70 - - x += Macro; - - x += Macro; -} - - diff --git a/tests/unit/unittest/data/symbolindexer_header1.h b/tests/unit/unittest/data/symbolindexer_header1.h deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/tests/unit/unittest/data/symbolindexer_header2.h b/tests/unit/unittest/data/symbolindexer_header2.h deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/tests/unit/unittest/data/symbolindexer_main1.cpp b/tests/unit/unittest/data/symbolindexer_main1.cpp deleted file mode 100644 index 8b137891791..00000000000 --- a/tests/unit/unittest/data/symbolindexer_main1.cpp +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/unit/unittest/data/symbolindexer_main2.cpp b/tests/unit/unittest/data/symbolindexer_main2.cpp deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/tests/unit/unittest/data/symbolindexer_pathChanged.cpp b/tests/unit/unittest/data/symbolindexer_pathChanged.cpp deleted file mode 100644 index 8b137891791..00000000000 --- a/tests/unit/unittest/data/symbolindexer_pathChanged.cpp +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/unit/unittest/data/symbolindexing_main1.cpp b/tests/unit/unittest/data/symbolindexing_main1.cpp deleted file mode 100644 index f0d60a58422..00000000000 --- a/tests/unit/unittest/data/symbolindexing_main1.cpp +++ /dev/null @@ -1,41 +0,0 @@ -void function(); - -void function() -{ - int x; - x = 20; -} - -template -T templateFunction(T t) -{ - return t; -} - -template <> -int templateFunction(int t) -{ - return t; -} - -extern template double templateFunction(double); -template double templateFunction(double); - -template -using TemplateFunctionType = T(&)(T); - - -TemplateFunctionType aliasToTemplateFunction = templateFunction; - -void f() -{ - aliasToTemplateFunction(1); -} - -void f(int); -void f(double); - -void f2() -{ - function(); -} diff --git a/tests/unit/unittest/data/symbolscollector/class.cpp b/tests/unit/unittest/data/symbolscollector/class.cpp deleted file mode 100644 index 5f393c44cd0..00000000000 --- a/tests/unit/unittest/data/symbolscollector/class.cpp +++ /dev/null @@ -1,14 +0,0 @@ -class Class -{ - Class(); - Class(int); - - void foo(); - - void bar() {} -}; - -void Class::foo() -{ - bar(); -} diff --git a/tests/unit/unittest/data/symbolscollector/defines.h b/tests/unit/unittest/data/symbolscollector/defines.h deleted file mode 100644 index 6cb2ee91ef9..00000000000 --- a/tests/unit/unittest/data/symbolscollector/defines.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef SYMBOLSCOLLECTOR_DEFINES_H -#define SYMBOLSCOLLECTOR_DEFINES_H - -#define IF_NOT_DEFINE 1 - -#ifndef IF_NOT_DEFINE -#endif - -#ifndef IF_NOT_DEFINE -#endif - -#ifndef COMPILER_ARGUMENT -#endif - -#define IF_DEFINE 1 - -#ifdef IF_DEFINE -#endif - -#define DEFINED 1 - -#if defined(DEFINED) -#endif - -#define MACRO_EXPANSION int - -void foo(MACRO_EXPANSION); - -#ifndef __clang__ -#endif - -#define UN_DEFINE - -#undef UN_DEFINE - -#define CLASS_EXPORT - -struct CLASS_EXPORT Foo -{ -}; - -#endif // SYMBOLSCOLLECTOR_DEFINES_H diff --git a/tests/unit/unittest/data/symbolscollector/error.cpp b/tests/unit/unittest/data/symbolscollector/error.cpp deleted file mode 100644 index 5df7507e2de..00000000000 --- a/tests/unit/unittest/data/symbolscollector/error.cpp +++ /dev/null @@ -1 +0,0 @@ -ERROR diff --git a/tests/unit/unittest/data/symbolscollector/header1.h b/tests/unit/unittest/data/symbolscollector/header1.h deleted file mode 100644 index 3d1ea4b7e04..00000000000 --- a/tests/unit/unittest/data/symbolscollector/header1.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "header2.h" diff --git a/tests/unit/unittest/data/symbolscollector/header2.h b/tests/unit/unittest/data/symbolscollector/header2.h deleted file mode 100644 index 6f70f09beec..00000000000 --- a/tests/unit/unittest/data/symbolscollector/header2.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once diff --git a/tests/unit/unittest/data/symbolscollector/header3.h b/tests/unit/unittest/data/symbolscollector/header3.h deleted file mode 100644 index 3d1ea4b7e04..00000000000 --- a/tests/unit/unittest/data/symbolscollector/header3.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "header2.h" diff --git a/tests/unit/unittest/data/symbolscollector/include/unmodified_header.h b/tests/unit/unittest/data/symbolscollector/include/unmodified_header.h deleted file mode 100644 index c4bf4e6d99f..00000000000 --- a/tests/unit/unittest/data/symbolscollector/include/unmodified_header.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#define HEADER_DEFINE - -void HeaderFunction(); -void HeaderFunctionReference(); -void HeaderFunctionReferenceInMainFile(); - -class Class -{ -public: - int Member = 20; - int MemberReference = 10; - - void InlineHeaderMemberFunction() - { - int FunctionLocalVariable = 90; - MemberReference = 30; - HeaderFunctionReference(); - } -}; - diff --git a/tests/unit/unittest/data/symbolscollector/include/unmodified_header2.h b/tests/unit/unittest/data/symbolscollector/include/unmodified_header2.h deleted file mode 100644 index 7905e974193..00000000000 --- a/tests/unit/unittest/data/symbolscollector/include/unmodified_header2.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -void TouchHeaderFunction(); diff --git a/tests/unit/unittest/data/symbolscollector/main.cpp b/tests/unit/unittest/data/symbolscollector/main.cpp deleted file mode 100644 index d85f515e18b..00000000000 --- a/tests/unit/unittest/data/symbolscollector/main.cpp +++ /dev/null @@ -1,4 +0,0 @@ -#include "header1.h" - -void function(); - diff --git a/tests/unit/unittest/data/symbolscollector/main2.cpp b/tests/unit/unittest/data/symbolscollector/main2.cpp deleted file mode 100644 index c6971f02996..00000000000 --- a/tests/unit/unittest/data/symbolscollector/main2.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "header1.h" -#include "header3.h" - -void function(); - diff --git a/tests/unit/unittest/data/symbolscollector/simple.cpp b/tests/unit/unittest/data/symbolscollector/simple.cpp deleted file mode 100644 index 494af8c8b48..00000000000 --- a/tests/unit/unittest/data/symbolscollector/simple.cpp +++ /dev/null @@ -1,15 +0,0 @@ -void function(); -void function(); -void function(int x); -void function() -{ - int x; - x = 4; - int y = 4; - y = x + 3; -} - -void f() -{ - function(); -} diff --git a/tests/unit/unittest/data/symbolscollector/symbolkind.cpp b/tests/unit/unittest/data/symbolscollector/symbolkind.cpp deleted file mode 100644 index e8f9bae5305..00000000000 --- a/tests/unit/unittest/data/symbolscollector/symbolkind.cpp +++ /dev/null @@ -1,13 +0,0 @@ -class Class {}; -struct Struct {}; -enum Enumeration {}; -enum ScopedEnumeration {}; -union Union {}; - -#ifdef _MSC_VER -__interface MsvcInterface {}; -#endif - -void Function() {} - -int Variable; diff --git a/tests/unit/unittest/data/symbolscollector/unmodified.cpp b/tests/unit/unittest/data/symbolscollector/unmodified.cpp deleted file mode 100644 index 3f9791bfbdd..00000000000 --- a/tests/unit/unittest/data/symbolscollector/unmodified.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include - -#define MAINFILE_DEFINE - -void MainFileFunction() -{ - HeaderFunctionReferenceInMainFile(); -} diff --git a/tests/unit/unittest/data/symbolscollector/unmodified2.cpp b/tests/unit/unittest/data/symbolscollector/unmodified2.cpp deleted file mode 100644 index 3f8256ced81..00000000000 --- a/tests/unit/unittest/data/symbolscollector/unmodified2.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -#define MAINFILE_DEFINE - -void MainFileFunction() -{ - HeaderFunctionReferenceInMainFile(); -} - diff --git a/tests/unit/unittest/data/symbolscollector/unmodified3.cpp b/tests/unit/unittest/data/symbolscollector/unmodified3.cpp deleted file mode 100644 index 3a5d8f9df99..00000000000 --- a/tests/unit/unittest/data/symbolscollector/unmodified3.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -#define MAINFILE_DEFINE - -void MainFileFunction() -{ - HeaderFunctionReferenceInMainFile(); -} diff --git a/tests/unit/unittest/data/symbolscollector/unsaved.cpp b/tests/unit/unittest/data/symbolscollector/unsaved.cpp deleted file mode 100644 index 0d0dc9fd518..00000000000 --- a/tests/unit/unittest/data/symbolscollector/unsaved.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "generated_file.h" diff --git a/tests/unit/unittest/directorypathcompressor-test.cpp b/tests/unit/unittest/directorypathcompressor-test.cpp deleted file mode 100644 index 50853e8e1c5..00000000000 --- a/tests/unit/unittest/directorypathcompressor-test.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockfilesystem.h" -#include "mocktimer.h" - -#include - -namespace { - -using testing::ElementsAre; -using testing::Invoke; -using testing::IsEmpty; -using testing::NiceMock; - -using ClangBackEnd::DirectoryPathId; -using ClangBackEnd::DirectoryPathIds; - -class DirectoryPathCompressor : public testing::Test -{ -protected: - void SetUp() - { - compressor.setCallback(mockCompressorCallback.AsStdFunction()); - } - -protected: - NiceMock> mockCompressorCallback; - ClangBackEnd::DirectoryPathCompressor> compressor; - NiceMock &mockTimer = compressor.timer(); - DirectoryPathId directoryPathId1{1}; - DirectoryPathId directoryPathId2{2}; -}; - -TEST_F(DirectoryPathCompressor, AddFilePath) -{ - compressor.addDirectoryPathId(directoryPathId1); - - ASSERT_THAT(compressor.takeDirectoryPathIds(), ElementsAre(directoryPathId1)); -} - -TEST_F(DirectoryPathCompressor, NoFilePathsAferTakenThem) -{ - compressor.addDirectoryPathId(directoryPathId1); - - compressor.takeDirectoryPathIds(); - - ASSERT_THAT(compressor.takeDirectoryPathIds(), IsEmpty()); -} - -TEST_F(DirectoryPathCompressor, CallRestartTimerAfterAddingPath) -{ - EXPECT_CALL(mockTimer, start(20)); - - compressor.addDirectoryPathId(directoryPathId1); -} - -TEST_F(DirectoryPathCompressor, CallTimeOutAfterAddingPath) -{ - EXPECT_CALL(mockCompressorCallback, Call(ElementsAre(directoryPathId1, directoryPathId2))); - - compressor.addDirectoryPathId(directoryPathId1); - compressor.addDirectoryPathId(directoryPathId2); -} - -TEST_F(DirectoryPathCompressor, RemoveDuplicates) -{ - EXPECT_CALL(mockCompressorCallback, Call(ElementsAre(directoryPathId1, directoryPathId2))); - - compressor.addDirectoryPathId(directoryPathId1); - compressor.addDirectoryPathId(directoryPathId2); - compressor.addDirectoryPathId(directoryPathId1); -} - -} diff --git a/tests/unit/unittest/filepath-test.cpp b/tests/unit/unittest/filepath-test.cpp deleted file mode 100644 index 39c23470ccc..00000000000 --- a/tests/unit/unittest/filepath-test.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include - -namespace { - -TEST(FilePath, CreateFromPathString) -{ - ClangBackEnd::FilePath filePath{Utils::PathString{"/file/pathOne"}}; - - ASSERT_THAT(filePath.directory(), "/file"); - ASSERT_THAT(filePath.name(), "pathOne"); -} - -TEST(FilePath, CreateFromDirectoryAndFileName) -{ - ClangBackEnd::FilePath filePath{Utils::PathString{"/file"}, Utils::PathString{"pathOne"}}; - - ASSERT_THAT(filePath.directory(), "/file"); - ASSERT_THAT(filePath.name(), "pathOne"); - ASSERT_THAT(filePath.path(), "/file/pathOne"); -} - -TEST(FilePath, CreateFromCString) -{ - ClangBackEnd::FilePath filePath{"/file/pathOne"}; - - ASSERT_THAT(filePath.directory(), "/file"); - ASSERT_THAT(filePath.name(), "pathOne"); -} - -TEST(FilePath, CreateFromFilePathView) -{ - ClangBackEnd::FilePath filePath{ClangBackEnd::FilePathView{"/file/pathOne"}}; - - ASSERT_THAT(filePath.directory(), "/file"); - ASSERT_THAT(filePath.name(), "pathOne"); -} - -TEST(FilePath, CreateFromQString) -{ - ClangBackEnd::FilePath filePath{QString{"/file/pathOne"}}; - - ASSERT_THAT(filePath.directory(), "/file"); - ASSERT_THAT(filePath.name(), "pathOne"); -} - -TEST(FilePath, DefaultFilePath) -{ - ClangBackEnd::FilePath filePath; - - ASSERT_THAT(filePath.directory(), ""); - ASSERT_THAT(filePath.name(), ""); -} - -TEST(FilePath, EmptyFilePath) -{ - ClangBackEnd::FilePath filePath(""); - - ASSERT_THAT(filePath.directory(), ""); - ASSERT_THAT(filePath.name(), ""); -} - -} diff --git a/tests/unit/unittest/filepathcache-test.cpp b/tests/unit/unittest/filepathcache-test.cpp deleted file mode 100644 index fce075ab46f..00000000000 --- a/tests/unit/unittest/filepathcache-test.cpp +++ /dev/null @@ -1,490 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockfilepathstorage.h" -#include "sqlitedatabasemock.h" - -#include - -namespace { - -using ClangBackEnd::DirectoryPathId; -using ClangBackEnd::FilePathId; -using Cache = ClangBackEnd::FilePathCache>; -using ClangBackEnd::FilePathId; -using NFP = ClangBackEnd::FilePath; -using ClangBackEnd::FilePathView; -using ClangBackEnd::FilePathViews; -using ClangBackEnd::Sources::SourceNameAndDirectoryId; - -class FilePathCache : public testing::Test -{ -protected: - void SetUp() - { - ON_CALL(mockStorage, fetchDirectoryId(Eq("/path/to"))) - .WillByDefault(Return(5)); - ON_CALL(mockStorage, fetchDirectoryId(Eq("/path2/to"))) - .WillByDefault(Return(6)); - ON_CALL(mockStorage, fetchSourceId(5, Eq("file.cpp"))) - .WillByDefault(Return(42)); - ON_CALL(mockStorage, fetchSourceId(5, Eq("file2.cpp"))) - .WillByDefault(Return(63)); - ON_CALL(mockStorage, fetchSourceId(6, Eq("file.cpp"))) - .WillByDefault(Return(72)); - ON_CALL(mockStorage, fetchDirectoryPath(5)).WillByDefault(Return(Utils::PathString("/path/to"))); - ON_CALL(mockStorage, fetchSourceNameAndDirectoryId(42)) - .WillByDefault(Return(SourceNameAndDirectoryId("file.cpp", 5))); - ON_CALL(mockStorageFilled, fetchAllSources()) - .WillByDefault(Return(std::vector({ - {"file.cpp", 6, 72}, - {"file2.cpp", 5, 63}, - {"file.cpp", 5, 42}, - }))); - ON_CALL(mockStorageFilled, fetchAllDirectories()) - .WillByDefault(Return( - std::vector({{"/path2/to", 6}, {"/path/to", 5}}))); - ON_CALL(mockStorageFilled, fetchDirectoryIdUnguarded(Eq("/path3/to"))).WillByDefault(Return(7)); - ON_CALL(mockStorageFilled, fetchSourceIdUnguarded(7, Eq("file.h"))).WillByDefault(Return(101)); - ON_CALL(mockStorageFilled, fetchSourceIdUnguarded(6, Eq("file2.h"))).WillByDefault(Return(106)); - ON_CALL(mockStorageFilled, fetchSourceIdUnguarded(5, Eq("file.h"))).WillByDefault(Return(99)); - } - -protected: - NiceMock databaseMock; - NiceMock mockStorage{databaseMock}; - Cache cache{mockStorage}; - NiceMock mockStorageFilled{databaseMock}; - Cache cacheNotFilled{mockStorageFilled}; -}; - -TEST_F(FilePathCache, FilePathIdWithOutAnyEntryCallDirectoryId) -{ - EXPECT_CALL(mockStorage, fetchDirectoryId(Eq("/path/to"))); - - cache.filePathId(FilePathView("/path/to/file.cpp")); -} - -TEST_F(FilePathCache, FilePathIdWithOutAnyEntryCalls) -{ - EXPECT_CALL(mockStorage, fetchSourceId(5, Eq("file.cpp"))); - - cache.filePathId(FilePathView("/path/to/file.cpp")); -} - -TEST_F(FilePathCache, FilePathIdOfFilePathIdWithOutAnyEntry) -{ - auto filePathId = cache.filePathId(FilePathView("/path/to/file.cpp")); - - ASSERT_THAT(filePathId.filePathId, 42); -} - -TEST_F(FilePathCache, IfEntryExistsDontCallInStrorage) -{ - cache.filePathId(FilePathView("/path/to/file.cpp")); - - EXPECT_CALL(mockStorage, fetchDirectoryId(Eq("/path/to"))).Times(0); - EXPECT_CALL(mockStorage, fetchSourceId(5, Eq("file.cpp"))).Times(0); - - cache.filePathId(FilePathView("/path/to/file.cpp")); -} - -TEST_F(FilePathCache, IfDirectoryEntryExistsDontCallFetchDirectoryIdButStillCallFetchSourceId) -{ - cache.filePathId(FilePathView("/path/to/file2.cpp")); - - EXPECT_CALL(mockStorage, fetchDirectoryId(Eq("/path/to"))).Times(0); - EXPECT_CALL(mockStorage, fetchSourceId(5, Eq("file.cpp"))); - - cache.filePathId(FilePathView("/path/to/file.cpp")); -} - -TEST_F(FilePathCache, GetFilePathIdWithCachedValue) -{ - cache.filePathId(FilePathView("/path/to/file.cpp")); - - auto filePathId = cache.filePathId(FilePathView("/path/to/file.cpp")); - - ASSERT_THAT(filePathId.filePathId, 42); -} - -TEST_F(FilePathCache, GetFilePathIdWithDirectoryIdCached) -{ - cache.filePathId(FilePathView("/path/to/file.cpp")); - - auto filePathId = cache.filePathId(FilePathView("/path/to/file2.cpp")); - - ASSERT_THAT(filePathId.filePathId, 63); -} - -TEST_F(FilePathCache, ThrowForGettingAFilePathWithAnInvalidId) -{ - FilePathId filePathId; - - ASSERT_THROW(cache.filePath(filePathId), ClangBackEnd::NoFilePathForInvalidFilePathId); -} - -TEST_F(FilePathCache, GetAFilePath) -{ - FilePathId filePathId = cache.filePathId(FilePathView("/path/to/file.cpp")); - - auto filePath = cache.filePath(filePathId); - - ASSERT_THAT(filePath, Eq(FilePathView{"/path/to/file.cpp"})); -} - -TEST_F(FilePathCache, GetAFilePathWithCachedFilePathId) -{ - FilePathId filePathId{42}; - - auto filePath = cache.filePath(filePathId); - - ASSERT_THAT(filePath, Eq(FilePathView{"/path/to/file.cpp"})); -} - -TEST_F(FilePathCache, FileNamesAreUniqueForEveryDirectory) -{ - FilePathId filePathId = cache.filePathId(FilePathView("/path/to/file.cpp")); - - FilePathId filePath2Id = cache.filePathId(FilePathView("/path2/to/file.cpp")); - - ASSERT_THAT(filePath2Id.filePathId, Ne(filePathId.filePathId)); -} - -TEST_F(FilePathCache, DuplicateFilePathsAreEqual) -{ - FilePathId filePath1Id = cache.filePathId(FilePathView("/path/to/file.cpp")); - - FilePathId filePath2Id = cache.filePathId(FilePathView("/path/to/file.cpp")); - - ASSERT_THAT(filePath2Id, Eq(filePath1Id)); -} - -TEST_F(FilePathCache, DirectoryPathIdCallsFetchDirectoryId) -{ - EXPECT_CALL(mockStorage, fetchDirectoryId(Eq("/path/to"))); - - cache.directoryPathId(Utils::SmallString("/path/to")); -} - -TEST_F(FilePathCache, SecondDirectoryPathIdCallsNotFetchDirectoryId) -{ - cache.directoryPathId(Utils::SmallString("/path/to")); - - EXPECT_CALL(mockStorage, fetchDirectoryId(Eq("/path/to"))).Times(0); - - cache.directoryPathId(Utils::SmallString("/path/to")); -} - -TEST_F(FilePathCache, DirectoryPathIdWithTrailingSlash) -{ - EXPECT_CALL(mockStorage, fetchDirectoryId(Eq("/path/to"))); - - cache.directoryPathId(Utils::SmallString("/path/to/")); -} - -TEST_F(FilePathCache, DirectoryPathId) -{ - auto id = cache.directoryPathId(Utils::SmallString("/path/to")); - - ASSERT_THAT(id, Eq(DirectoryPathId{5})); -} - -TEST_F(FilePathCache, DirectoryPathIdIsAlreadyInCache) -{ - auto firstId = cache.directoryPathId(Utils::SmallString("/path/to")); - - auto secondId = cache.directoryPathId(Utils::SmallString("/path/to")); - - ASSERT_THAT(secondId, firstId); -} - -TEST_F(FilePathCache, DirectoryPathIdIsAlreadyInCacheWithTrailingSlash) -{ - auto firstId = cache.directoryPathId(Utils::SmallString("/path/to/")); - - auto secondId = cache.directoryPathId(Utils::SmallString("/path/to/")); - - ASSERT_THAT(secondId, firstId); -} - -TEST_F(FilePathCache, DirectoryPathIdIsAlreadyInCacheWithAndWithoutTrailingSlash) -{ - auto firstId = cache.directoryPathId(Utils::SmallString("/path/to/")); - - auto secondId = cache.directoryPathId(Utils::SmallString("/path/to")); - - ASSERT_THAT(secondId, firstId); -} - -TEST_F(FilePathCache, DirectoryPathIdIsAlreadyInCacheWithoutAndWithTrailingSlash) -{ - auto firstId = cache.directoryPathId(Utils::SmallString("/path/to")); - - auto secondId = cache.directoryPathId(Utils::SmallString("/path/to/")); - - ASSERT_THAT(secondId, firstId); -} - -TEST_F(FilePathCache, ThrowForGettingADirectoryPathWithAnInvalidId) -{ - DirectoryPathId directoryPathId; - - ASSERT_THROW(cache.directoryPath(directoryPathId), - ClangBackEnd::NoDirectoryPathForInvalidDirectoryPathId); -} - -TEST_F(FilePathCache, GetADirectoryPath) -{ - DirectoryPathId directoryPathId{5}; - - auto directoryPath = cache.directoryPath(directoryPathId); - - ASSERT_THAT(directoryPath, Eq(Utils::SmallStringView{"/path/to"})); -} - -TEST_F(FilePathCache, GetADirectoryPathWithCachedDirectoryPathId) -{ - DirectoryPathId directoryPathId{5}; - cache.directoryPath(directoryPathId); - - auto directoryPath = cache.directoryPath(directoryPathId); - - ASSERT_THAT(directoryPath, Eq(Utils::SmallStringView{"/path/to"})); -} - -TEST_F(FilePathCache, DirectoryPathCallsFetchDirectoryPath) -{ - EXPECT_CALL(mockStorage, fetchDirectoryPath(Eq(DirectoryPathId{5}))); - - cache.directoryPath(5); -} - -TEST_F(FilePathCache, SecondDirectoryPathCallsNotFetchDirectoryPath) -{ - cache.directoryPath(5); - - EXPECT_CALL(mockStorage, fetchDirectoryPath(_)).Times(0); - - cache.directoryPath(5); -} - -TEST_F(FilePathCache, ThrowForGettingADirectoryPathIdWithAnInvalidFilePathId) -{ - FilePathId filePathId; - - ASSERT_THROW(cache.directoryPathId(filePathId), ClangBackEnd::NoFilePathForInvalidFilePathId); -} - -TEST_F(FilePathCache, FetchDirectoryPathIdByFilePathId) -{ - auto directoryId = cache.directoryPathId(42); - - ASSERT_THAT(directoryId, Eq(5)); -} - -TEST_F(FilePathCache, FetchDirectoryPathIdByFilePathIdCached) -{ - cache.directoryPathId(42); - - auto directoryId = cache.directoryPathId(42); - - ASSERT_THAT(directoryId, Eq(5)); -} - -TEST_F(FilePathCache, FetchFilePathAfterFetchingDirectoryIdByFilePathId) -{ - cache.directoryPathId(42); - - auto filePath = cache.filePath(42); - - ASSERT_THAT(filePath, Eq("/path/to/file.cpp")); -} - -TEST_F(FilePathCache, FetchDirectoryPathIdAfterFetchingFilePathByFilePathId) -{ - cache.filePath(42); - - auto directoryId = cache.directoryPathId(42); - - ASSERT_THAT(directoryId, Eq(5)); -} - -TEST_F(FilePathCache, FetchAllDirectoriesAndSourcesAtCreation) -{ - EXPECT_CALL(mockStorage, fetchAllDirectories()); - EXPECT_CALL(mockStorage, fetchAllSources()); - - Cache cache{mockStorage}; -} - -TEST_F(FilePathCache, GetFileIdInFilledCache) -{ - Cache cacheFilled{mockStorageFilled}; - - auto id = cacheFilled.filePathId("/path2/to/file.cpp"); - - ASSERT_THAT(id, Eq(72)); -} - -TEST_F(FilePathCache, GetDirectoryIdInFilledCache) -{ - Cache cacheFilled{mockStorageFilled}; - - auto id = cacheFilled.directoryPathId(42); - - ASSERT_THAT(id, Eq(5)); -} - -TEST_F(FilePathCache, GetDirectoryPathInFilledCache) -{ - Cache cacheFilled{mockStorageFilled}; - - auto path = cacheFilled.directoryPath(5); - - ASSERT_THAT(path, Eq("/path/to")); -} - -TEST_F(FilePathCache, GetFilePathInFilledCache) -{ - Cache cacheFilled{mockStorageFilled}; - - auto path = cacheFilled.filePath(42); - - ASSERT_THAT(path, Eq("/path/to/file.cpp")); -} - -TEST_F(FilePathCache, GetFileIdAfterAddFilePaths) -{ - Cache cacheFilled{mockStorageFilled}; - - cacheFilled.addFilePaths( - FilePathViews{"/path3/to/file.h", "/path/to/file.h", "/path2/to/file2.h", "/path/to/file.cpp"}); - - ASSERT_THAT(cacheFilled.filePath(101), Eq("/path3/to/file.h")); -} - -TEST_F(FilePathCache, GetFileIdAfterAddFilePathsWhichWasAlreadyAdded) -{ - Cache cacheFilled{mockStorageFilled}; - - cacheFilled.addFilePaths(FilePathViews{"/path3/to/file.h", "/path/to/file.h", "/path2/to/file2.h"}); - - ASSERT_THAT(cacheFilled.filePath(42), Eq("/path/to/file.cpp")); -} - -TEST_F(FilePathCache, AddFilePathsCalls) -{ - Cache cacheFilled{mockStorageFilled}; - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(mockStorageFilled, fetchDirectoryIdUnguarded(Eq("/path3/to"))).WillOnce(Return(7)); - EXPECT_CALL(mockStorageFilled, fetchDirectoryIdUnguarded(Eq("/path/to"))).Times(0); - EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(5, Eq("file.h"))).WillOnce(Return(99)); - EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(6, Eq("file2.h"))).WillOnce(Return(106)); - EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(7, Eq("file.h"))).WillOnce(Return(101)); - EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(5, Eq("file.cpp"))).Times(0); - EXPECT_CALL(databaseMock, commit()); - - cacheFilled.addFilePaths( - FilePathViews{"/path3/to/file.h", "/path/to/file.h", "/path2/to/file2.h", "/path/to/file.cpp"}); -} - -TEST_F(FilePathCache, DontUseTransactionIfNotAddingFilesInAddFilePathsCalls) -{ - Cache cacheFilled{mockStorageFilled}; - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()).Times(0); - EXPECT_CALL(mockStorageFilled, fetchDirectoryIdUnguarded(Eq("/path/to"))).Times(0); - EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(5, Eq("file.cpp"))).Times(0); - EXPECT_CALL(databaseMock, commit()).Times(0); - - cacheFilled.addFilePaths(FilePathViews{"/path/to/file.cpp"}); -} - -TEST_F(FilePathCache, UseTransactionIfAddingFilesOnlyInAddFilePathsCalls) -{ - Cache cacheFilled{mockStorageFilled}; - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(mockStorageFilled, fetchDirectoryIdUnguarded(Eq("/path/to"))).Times(0); - EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(5, Eq("file.h"))); - EXPECT_CALL(databaseMock, commit()); - - cacheFilled.addFilePaths(FilePathViews{"/path/to/file.h"}); -} - -TEST_F(FilePathCache, GetFileIdInAfterPopulateIfEmpty) -{ - cacheNotFilled.populateIfEmpty(); - - auto id = cacheNotFilled.filePathId("/path2/to/file.cpp"); - - ASSERT_THAT(id, Eq(72)); -} - -TEST_F(FilePathCache, DontPopulateIfNotEmpty) -{ - cacheNotFilled.filePathId("/path/to/file.cpp"); - - EXPECT_CALL(mockStorageFilled, fetchAllDirectories()).Times(0); - EXPECT_CALL(mockStorageFilled, fetchAllSources()).Times(0); - - cacheNotFilled.populateIfEmpty(); -} - -TEST_F(FilePathCache, GetDirectoryIdAfterPopulateIfEmpty) -{ - cacheNotFilled.populateIfEmpty(); - - auto id = cacheNotFilled.directoryPathId(42); - - ASSERT_THAT(id, Eq(5)); -} - -TEST_F(FilePathCache, GetDirectoryPathAfterPopulateIfEmpty) -{ - cacheNotFilled.populateIfEmpty(); - - auto path = cacheNotFilled.directoryPath(5); - - ASSERT_THAT(path, Eq("/path/to")); -} - -TEST_F(FilePathCache, GetFilePathAfterPopulateIfEmptye) -{ - cacheNotFilled.populateIfEmpty(); - - auto path = cacheNotFilled.filePath(42); - - ASSERT_THAT(path, Eq("/path/to/file.cpp")); -} - -} // namespace diff --git a/tests/unit/unittest/filepathstorage-test.cpp b/tests/unit/unittest/filepathstorage-test.cpp deleted file mode 100644 index b982156bcfa..00000000000 --- a/tests/unit/unittest/filepathstorage-test.cpp +++ /dev/null @@ -1,674 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockmutex.h" -#include "sqlitedatabasemock.h" - -#include -#include - -namespace { - -using StatementFactory = ClangBackEnd::FilePathStorageSqliteStatementFactory>; -using Storage = ClangBackEnd::FilePathStorage; -template -using ReadStatement = NiceMock::ReadStatement; -using WriteStatement = NiceMock::WriteStatement; -using ClangBackEnd::Sources::Directory; -using ClangBackEnd::Sources::Source; - -class FilePathStorage : public testing::Test -{ -protected: - void SetUp() - { - ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, - valueReturnInt32(A())) - .WillByDefault(Return(Utils::optional())); - ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, - valueReturnInt32(Utils::SmallStringView(""))) - .WillByDefault(Return(Utils::optional(0))); - ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, - valueReturnInt32(Utils::SmallStringView("/path/to"))) - .WillByDefault(Return(Utils::optional(5))); - ON_CALL(databaseMock, lastInsertedRowId()) - .WillByDefault(Return(12)); - ON_CALL(selectAllDirectories, valuesReturnStdVectorDirectory(_)) - .WillByDefault(Return(std::vector{{"/path/to", 1}, {"/other/path", 2}})); - ON_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, - valueReturnInt32(_, _)) - .WillByDefault(Return(Utils::optional())); - ON_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, - valueReturnInt32(0, Utils::SmallStringView(""))) - .WillByDefault(Return(Utils::optional(0))); - ON_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, - valueReturnInt32(5, Utils::SmallStringView("file.h"))) - .WillByDefault(Return(Utils::optional(42))); - ON_CALL(selectAllSources, valuesReturnStdVectorSource(_)) - .WillByDefault(Return(std::vector{{"file.h", 1, 1}, {"file.cpp", 2, 4}})); - ON_CALL(selectDirectoryPathFromDirectoriesByDirectoryId, - valueReturnPathString(5)) - .WillByDefault(Return(Utils::optional("/path/to"))); - ON_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId, - valueReturnSourceNameAndDirectoryId(42)) - .WillByDefault(Return(Utils::optional({"file.cpp", 5}))); - ON_CALL(selectDirectoryIdFromSourcesBySourceId, valueReturnInt32(TypedEq(42))) - .WillByDefault(Return(Utils::optional(5))); - - EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, - valueReturnInt32(A())) - .Times(AnyNumber()); - EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, valueReturnInt32(_, _)) - .Times(AnyNumber()); - EXPECT_CALL(insertIntoDirectories, write(An())) - .Times(AnyNumber()); - EXPECT_CALL(insertIntoSources, write(An(), A())) - .Times(AnyNumber()); - EXPECT_CALL(selectAllDirectories, valuesReturnStdVectorDirectory(_)) - .Times(AnyNumber()); - EXPECT_CALL(selectAllSources, valuesReturnStdVectorSource(_)) - .Times(AnyNumber()); - EXPECT_CALL(selectDirectoryPathFromDirectoriesByDirectoryId, valueReturnPathString(An())) - .Times(AnyNumber()); - EXPECT_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId, valueReturnSourceNameAndDirectoryId(_)) - .Times(AnyNumber()); - } - -protected: - NiceMock databaseMock; - StatementFactory factory{databaseMock}; - ReadStatement<1> &selectDirectoryIdFromDirectoriesByDirectoryPath = factory.selectDirectoryIdFromDirectoriesByDirectoryPath; - ReadStatement<1> &selectSourceIdFromSourcesByDirectoryIdAndSourceName = factory.selectSourceIdFromSourcesByDirectoryIdAndSourceName; - ReadStatement<1> &selectDirectoryPathFromDirectoriesByDirectoryId = factory.selectDirectoryPathFromDirectoriesByDirectoryId; - ReadStatement<2> &selectSourceNameAndDirectoryIdFromSourcesBySourceId = factory.selectSourceNameAndDirectoryIdFromSourcesBySourceId; - ReadStatement<2> &selectAllDirectories = factory.selectAllDirectories; - WriteStatement &insertIntoDirectories = factory.insertIntoDirectories; - WriteStatement &insertIntoSources = factory.insertIntoSources; - ReadStatement<3> &selectAllSources = factory.selectAllSources; - ReadStatement<1> &selectDirectoryIdFromSourcesBySourceId = factory.selectDirectoryIdFromSourcesBySourceId; - Storage storage{factory}; -}; - -TEST_F(FilePathStorage, ReadDirectoryIdForNotContainedPath) -{ - auto directoryId = storage.readDirectoryId("/some/not/known/path"); - - ASSERT_FALSE(directoryId); -} - -TEST_F(FilePathStorage, ReadSourceIdForNotContainedPathAndDirectoryId) -{ - auto sourceId = storage.readSourceId(23, "/some/not/known/path"); - - ASSERT_FALSE(sourceId); -} - -TEST_F(FilePathStorage, ReadDirectoryIdForEmptyPath) -{ - auto directoryId = storage.readDirectoryId(""); - - ASSERT_THAT(directoryId.value(), 0); -} - -TEST_F(FilePathStorage, ReadSourceIdForEmptyNameAndZeroDirectoryId) -{ - auto sourceId = storage.readSourceId(0, ""); - - ASSERT_THAT(sourceId.value(), 0); -} - -TEST_F(FilePathStorage, ReadDirectoryIdForPath) -{ - auto directoryId = storage.readDirectoryId("/path/to"); - - ASSERT_THAT(directoryId.value(), 5); -} - -TEST_F(FilePathStorage, ReadSourceIdForPathAndDirectoryId) -{ - auto sourceId = storage.readSourceId(5, "file.h"); - - ASSERT_THAT(sourceId.value(), 42); -} - -TEST_F(FilePathStorage, FetchDirectoryIdForEmptyPath) -{ - auto directoryId = storage.fetchDirectoryId(""); - - ASSERT_THAT(directoryId, 0); -} - -TEST_F(FilePathStorage, FetchSourceIdForEmptyNameAndZeroDirectoryId) -{ - auto sourceId = storage.fetchSourceId(0, ""); - - ASSERT_THAT(sourceId, 0); -} - -TEST_F(FilePathStorage, FetchDirectoryIdForPath) -{ - auto directoryId = storage.fetchDirectoryId("/path/to"); - - ASSERT_THAT(directoryId, 5); -} - -TEST_F(FilePathStorage, FetchSourceIdForPathAndDirectoryId) -{ - auto sourceId = storage.fetchSourceId(5, "file.h"); - - ASSERT_THAT(sourceId, 42); -} - -TEST_F(FilePathStorage, CallWriteForWriteDirectory) -{ - EXPECT_CALL(insertIntoDirectories, write(TypedEq("/some/not/known/path"))); - - storage.writeDirectoryId("/some/not/known/path"); -} - -TEST_F(FilePathStorage, CallWriteForWriteSource) -{ - EXPECT_CALL(insertIntoSources, - write(TypedEq(5), TypedEq("unknownfile.h"))); - - storage.writeSourceId(5, "unknownfile.h"); -} - -TEST_F(FilePathStorage, GetTheDirectoryIdBackAfterWritingANewEntryInDirectories) -{ - auto directoryId = storage.writeDirectoryId("/some/not/known/path"); - - ASSERT_THAT(directoryId, 12); -} - -TEST_F(FilePathStorage, GetTheSourceIdBackAfterWritingANewEntryInSources) -{ - auto sourceId = storage.writeSourceId(5, "unknownfile.h"); - - ASSERT_THAT(sourceId, 12); -} - -TEST_F(FilePathStorage, GetTheDirectoryIdBackAfterFetchingANewEntryFromDirectories) -{ - auto directoryId = storage.fetchDirectoryId("/some/not/known/path"); - - ASSERT_THAT(directoryId, 12); -} - -TEST_F(FilePathStorage, GetTheSourceIdBackAfterFetchingANewEntryFromSources) -{ - auto sourceId = storage.fetchSourceId(5, "unknownfile.h"); - - ASSERT_THAT(sourceId, 12); -} - -TEST_F(FilePathStorage, CallSelectForFetchingDirectoryIdForKnownPath) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, - valueReturnInt32(TypedEq("/path/to"))); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchDirectoryId("/path/to"); -} - -TEST_F(FilePathStorage, CallSelectForFetchingSourceIdForKnownPath) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, - valueReturnInt32(5, Eq("file.h"))); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchSourceId(5, "file.h"); -} - -TEST_F(FilePathStorage, CallNotWriteForFetchingDirectoryIdForKnownPath) -{ - EXPECT_CALL(insertIntoDirectories, write(An())).Times(0); - - storage.fetchDirectoryId("/path/to"); -} - -TEST_F(FilePathStorage, CallNotWriteForFetchingSoureIdForKnownEntry) -{ - EXPECT_CALL(insertIntoSources, write(An(), An())).Times(0); - - storage.fetchSourceId(5, "file.h"); -} - -TEST_F(FilePathStorage, CallSelectAndWriteForFetchingDirectoryIdForUnknownPath) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, - valueReturnInt32(TypedEq("/some/not/known/path"))); - EXPECT_CALL(insertIntoDirectories, write(TypedEq("/some/not/known/path"))); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchDirectoryId("/some/not/known/path"); -} - -TEST_F(FilePathStorage, CallSelectAndWriteForFetchingSourceIdForUnknownEntry) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, - valueReturnInt32(5, Eq("unknownfile.h"))); - EXPECT_CALL(insertIntoSources, - write(TypedEq(5), TypedEq("unknownfile.h"))); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchSourceId(5, "unknownfile.h"); -} - -TEST_F(FilePathStorage, RestartFetchDirectoryIDIfTheStatementIsBusyInBeginBecauseTheTableAlreadyChanged) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(databaseMock, rollback()).Times(0); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, - valueReturnInt32(TypedEq("/other/unknow/path"))); - EXPECT_CALL(insertIntoDirectories, write(TypedEq("/other/unknow/path"))); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchDirectoryId("/other/unknow/path"); -} - -TEST_F(FilePathStorage, - CallSelectAndWriteForFetchingDirectoryIdTwoTimesIfTheStatementIsBusyInWriteBecauseTheTableAlreadyChanged) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, - valueReturnInt32(TypedEq("/other/unknow/path"))); - EXPECT_CALL(insertIntoDirectories, write(TypedEq("/other/unknow/path"))) - .WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(databaseMock, rollback()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, - valueReturnInt32(TypedEq("/other/unknow/path"))); - EXPECT_CALL(insertIntoDirectories, write(TypedEq("/other/unknow/path"))); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchDirectoryId("/other/unknow/path"); -} - -TEST_F(FilePathStorage, CallSelectAndWriteForFetchingDirectoryIdTwoTimesIfTheIndexIsConstraintBecauseTheEntryExistsAlready) -{ - InSequence s; - - EXPECT_CALL(databaseMock,deferredBegin()); - EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, - valueReturnInt32(TypedEq("/other/unknow/path"))); - EXPECT_CALL(insertIntoDirectories, write(TypedEq("/other/unknow/path"))) - .WillOnce(Throw(Sqlite::ConstraintPreventsModification("busy"))); - EXPECT_CALL(databaseMock, rollback()); - EXPECT_CALL(databaseMock,deferredBegin()); - EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, - valueReturnInt32(TypedEq("/other/unknow/path"))); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchDirectoryId("/other/unknow/path"); -} - -TEST_F(FilePathStorage, RestartFetchSourceIdIfTheStatementIsBusyInBeginBecauseTheTableAlreadyChanged) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(databaseMock, rollback()).Times(0); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, - valueReturnInt32(5, Eq("otherunknownfile.h"))); - EXPECT_CALL(insertIntoSources, - write(TypedEq(5), TypedEq("otherunknownfile.h"))); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchSourceId(5, "otherunknownfile.h"); -} - -TEST_F(FilePathStorage, - CallSelectAndWriteForFetchingSourceTwoTimesIfTheStatementIsBusyInWriteBecauseTheTableAlreadyChanged) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, - valueReturnInt32(5, Eq("otherunknownfile.h"))); - EXPECT_CALL(insertIntoSources, - write(TypedEq(5), TypedEq("otherunknownfile.h"))) - .WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(databaseMock, rollback()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, - valueReturnInt32(5, Eq("otherunknownfile.h"))); - EXPECT_CALL(insertIntoSources, - write(TypedEq(5), TypedEq("otherunknownfile.h"))); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchSourceId(5, "otherunknownfile.h"); -} - -TEST_F(FilePathStorage, CallSelectAndWriteForFetchingSourceTwoTimesIfTheIndexIsConstraintBecauseTheEntryExistsAlready) -{ - InSequence s; - - EXPECT_CALL(databaseMock,deferredBegin()); - EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, - valueReturnInt32(5, Eq("otherunknownfile.h"))); - EXPECT_CALL(insertIntoSources, - write(TypedEq(5), TypedEq("otherunknownfile.h"))) - .WillOnce(Throw(Sqlite::ConstraintPreventsModification("busy"))); - EXPECT_CALL(databaseMock, rollback()); - EXPECT_CALL(databaseMock,deferredBegin()); - EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, - valueReturnInt32(5, Eq("otherunknownfile.h"))) - .WillOnce(Return(Utils::optional(42))); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchSourceId(5, "otherunknownfile.h"); -} - -TEST_F(FilePathStorage, SelectAllDirectories) -{ - auto directories = storage.fetchAllDirectories(); - - ASSERT_THAT(directories, ElementsAre(Directory{"/path/to", 1}, Directory{"/other/path", 2})); -} - -TEST_F(FilePathStorage, SelectAllSources) -{ - auto sources = storage.fetchAllSources(); - - ASSERT_THAT(sources, ElementsAre(Source{"file.h", 1, 1}, Source{"file.cpp", 2, 4})); -} - -TEST_F(FilePathStorage, CallSelectAllDirectories) -{ - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectAllDirectories, valuesReturnStdVectorDirectory(256)); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchAllDirectories(); -} - -TEST_F(FilePathStorage, CallSelectAllSources) -{ - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectAllSources, valuesReturnStdVectorSource(8192)); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchAllSources(); -} - -TEST_F(FilePathStorage, CallValueForFetchDirectoryPathForId) -{ - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectDirectoryPathFromDirectoriesByDirectoryId, valueReturnPathString(5)); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchDirectoryPath(5); -} - -TEST_F(FilePathStorage, FetchDirectoryPathForId) -{ - auto path = storage.fetchDirectoryPath(5); - - ASSERT_THAT(path, Eq("/path/to")); -} - -TEST_F(FilePathStorage, ThrowAsFetchingDirectoryPathForNonExistingId) -{ - ASSERT_THROW(storage.fetchDirectoryPath(12), ClangBackEnd::DirectoryPathIdDoesNotExists); -} - -TEST_F(FilePathStorage, CallValueForFetchSoureNameForId) -{ - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId, valueReturnSourceNameAndDirectoryId(42)); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchSourceNameAndDirectoryId(42); -} - -TEST_F(FilePathStorage, FetchSoureNameForId) -{ - auto entry = storage.fetchSourceNameAndDirectoryId(42); - - ASSERT_THAT(entry.sourceName, Eq("file.cpp")); - ASSERT_THAT(entry.directoryId, 5); -} - -TEST_F(FilePathStorage, ThrowAsFetchingSourceNameForNonExistingId) -{ - ASSERT_THROW(storage.fetchSourceNameAndDirectoryId(12), ClangBackEnd::SourceNameIdDoesNotExists); -} - -TEST_F(FilePathStorage, RestartFetchSourceNameIfTheStatementIsBusyInBegin) -{ - InSequence s; - - EXPECT_CALL(databaseMock, lock()); - EXPECT_CALL(databaseMock, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(databaseMock, rollback()).Times(0); - EXPECT_CALL(databaseMock, unlock()); - EXPECT_CALL(databaseMock, lock()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId, valueReturnSourceNameAndDirectoryId(42)); - EXPECT_CALL(databaseMock, commit()); - EXPECT_CALL(databaseMock, unlock()); - - storage.fetchSourceNameAndDirectoryId(42); -} - -TEST_F(FilePathStorage, RestartFetchDirectoryPathIfTheStatementIsBusyInBegin) -{ - InSequence s; - - EXPECT_CALL(databaseMock, lock()); - EXPECT_CALL(databaseMock, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(databaseMock, rollback()).Times(0); - EXPECT_CALL(databaseMock, unlock()); - EXPECT_CALL(databaseMock, lock()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectDirectoryPathFromDirectoriesByDirectoryId, valueReturnPathString(5)); - EXPECT_CALL(databaseMock, commit()); - EXPECT_CALL(databaseMock, unlock()); - - storage.fetchDirectoryPath(5); -} - -TEST_F(FilePathStorage, RestartFetchAllDirectoriesIfBeginIsBusy) -{ - InSequence s; - - EXPECT_CALL(databaseMock, lock()); - EXPECT_CALL(databaseMock, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(databaseMock, rollback()).Times(0); - EXPECT_CALL(databaseMock, unlock()); - EXPECT_CALL(databaseMock, lock()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectAllDirectories, valuesReturnStdVectorDirectory(256)); - EXPECT_CALL(databaseMock, commit()); - EXPECT_CALL(databaseMock, unlock()); - - storage.fetchAllDirectories(); -} - -TEST_F(FilePathStorage, RestartFetchAllSourcesIfBeginIsBusy) -{ - InSequence s; - - EXPECT_CALL(databaseMock, lock()); - EXPECT_CALL(databaseMock, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(databaseMock, rollback()).Times(0); - EXPECT_CALL(databaseMock, unlock()); - EXPECT_CALL(databaseMock, lock()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectAllSources, valuesReturnStdVectorSource(8192)); - EXPECT_CALL(databaseMock, commit()); - EXPECT_CALL(databaseMock, unlock()); - - storage.fetchAllSources(); -} - -TEST_F(FilePathStorage, FetchDirectoryIdForUnknownFileID) -{ - ASSERT_THROW(storage.fetchDirectoryId(1111), ClangBackEnd::SourceNameIdDoesNotExists); -} - -TEST_F(FilePathStorage, FetchDirectoryId) -{ - auto directoryId = storage.fetchDirectoryId(42); - - ASSERT_THAT(directoryId, 5); -} - -TEST_F(FilePathStorage, FetchDirectoryIdCalls) -{ - InSequence s; - - EXPECT_CALL(databaseMock, lock()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectDirectoryIdFromSourcesBySourceId, valueReturnInt32(TypedEq(42))); - EXPECT_CALL(databaseMock, commit()); - EXPECT_CALL(databaseMock, unlock()); - - storage.fetchDirectoryId(42); -} - -TEST_F(FilePathStorage, FetchDirectoryIdCallsDatabaseIsBusy) -{ - InSequence s; - - EXPECT_CALL(databaseMock, lock()); - EXPECT_CALL(databaseMock, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(databaseMock, rollback()).Times(0); - EXPECT_CALL(databaseMock, unlock()); - EXPECT_CALL(databaseMock, lock()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectDirectoryIdFromSourcesBySourceId, valueReturnInt32(TypedEq(42))); - EXPECT_CALL(databaseMock, commit()); - EXPECT_CALL(databaseMock, unlock()); - - storage.fetchDirectoryId(42); -} - -TEST_F(FilePathStorage, FetchDirectoryIdCallsThrows) -{ - InSequence s; - - EXPECT_CALL(databaseMock, lock()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(selectDirectoryIdFromSourcesBySourceId, valueReturnInt32(TypedEq(41))); - EXPECT_CALL(databaseMock, rollback()); - EXPECT_CALL(databaseMock, unlock()); - - ASSERT_ANY_THROW(storage.fetchDirectoryId(41)); -} - -TEST_F(FilePathStorage, GetTheDirectoryIdBackAfterFetchingANewEntryFromDirectoriesUnguarded) -{ - auto directoryId = storage.fetchDirectoryIdUnguarded("/some/not/known/path"); - - ASSERT_THAT(directoryId, 12); -} - -TEST_F(FilePathStorage, GetTheSourceIdBackAfterFetchingANewEntryFromSourcesUnguarded) -{ - auto sourceId = storage.fetchSourceIdUnguarded(5, "unknownfile.h"); - - ASSERT_THAT(sourceId, 12); -} - -TEST_F(FilePathStorage, CallSelectForFetchingDirectoryIdForKnownPathUnguarded) -{ - InSequence s; - - EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, - valueReturnInt32(TypedEq("/path/to"))); - - storage.fetchDirectoryIdUnguarded("/path/to"); -} - -TEST_F(FilePathStorage, CallSelectForFetchingSourceIdForKnownPathUnguarded) -{ - InSequence s; - - EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, - valueReturnInt32(5, Eq("file.h"))); - - storage.fetchSourceIdUnguarded(5, "file.h"); -} - -TEST_F(FilePathStorage, CallNotWriteForFetchingDirectoryIdForKnownPathUnguarded) -{ - EXPECT_CALL(insertIntoDirectories, write(An())).Times(0); - - storage.fetchDirectoryIdUnguarded("/path/to"); -} - -TEST_F(FilePathStorage, CallNotWriteForFetchingSoureIdForKnownEntryUnguarded) -{ - EXPECT_CALL(insertIntoSources, write(An(), An())).Times(0); - - storage.fetchSourceIdUnguarded(5, "file.h"); -} - -TEST_F(FilePathStorage, CallSelectAndWriteForFetchingDirectoryIdForUnknownPathUnguarded) -{ - InSequence s; - - EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, - valueReturnInt32(TypedEq("/some/not/known/path"))); - EXPECT_CALL(insertIntoDirectories, write(TypedEq("/some/not/known/path"))); - - storage.fetchDirectoryIdUnguarded("/some/not/known/path"); -} - -TEST_F(FilePathStorage, CallSelectAndWriteForFetchingSourceIdForUnknownEntryUnguarded) -{ - InSequence s; - - EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, - valueReturnInt32(5, Eq("unknownfile.h"))); - EXPECT_CALL(insertIntoSources, - write(TypedEq(5), TypedEq("unknownfile.h"))); - - storage.fetchSourceIdUnguarded(5, "unknownfile.h"); -} - -} // namespace diff --git a/tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp b/tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp deleted file mode 100644 index 0fb06aa87a8..00000000000 --- a/tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockmutex.h" -#include "sqlitedatabasemock.h" - -#include - -namespace { - -using StatementFactory = ClangBackEnd::FilePathStorageSqliteStatementFactory>; - -class FilePathStorageSqliteStatementFactory : public testing::Test -{ -protected: - NiceMock databaseMock; - StatementFactory factory{databaseMock}; -}; - -TEST_F(FilePathStorageSqliteStatementFactory, SelectDirectoryIdFromDirectoriesByDirectoryPath) -{ - ASSERT_THAT(factory.selectDirectoryIdFromDirectoriesByDirectoryPath.sqlStatement, - Eq("SELECT directoryId FROM directories WHERE directoryPath = ?")); -} - -TEST_F(FilePathStorageSqliteStatementFactory, SelectDirectoryPathFromDirectoriesByDirectoryId) -{ - ASSERT_THAT(factory.selectDirectoryPathFromDirectoriesByDirectoryId.sqlStatement, - Eq("SELECT directoryPath FROM directories WHERE directoryId = ?")); -} - -TEST_F(FilePathStorageSqliteStatementFactory, SelectSourceIdFromSourcesByDirectoryIdAndSourceName) -{ - ASSERT_THAT(factory.selectSourceIdFromSourcesByDirectoryIdAndSourceName.sqlStatement, - Eq("SELECT sourceId FROM sources WHERE directoryId = ? AND sourceName = ?")); -} - -TEST_F(FilePathStorageSqliteStatementFactory, SelectSourceNameAndDirectoryIdFromSourcesByAndSourceId) -{ - ASSERT_THAT(factory.selectSourceNameAndDirectoryIdFromSourcesBySourceId.sqlStatement, - Eq("SELECT sourceName, directoryId FROM sources WHERE sourceId = ?")); -} - -TEST_F(FilePathStorageSqliteStatementFactory, SelectSourceNameAndDirectoryIdBySourceId) -{ - ASSERT_THAT(factory.selectSourceNameAndDirectoryIdFromSourcesBySourceId.sqlStatement, - Eq("SELECT sourceName, directoryId FROM sources WHERE sourceId = ?")); -} - -TEST_F(FilePathStorageSqliteStatementFactory, InsertIntoDirectories) -{ - ASSERT_THAT(factory.insertIntoDirectories.sqlStatement, - Eq("INSERT INTO directories(directoryPath) VALUES (?)")); -} - -TEST_F(FilePathStorageSqliteStatementFactory, InsertIntoSources) -{ - ASSERT_THAT(factory.insertIntoSources.sqlStatement, - Eq("INSERT INTO sources(directoryId, sourceName) VALUES (?,?)")); -} - -} diff --git a/tests/unit/unittest/filepathview-test.cpp b/tests/unit/unittest/filepathview-test.cpp deleted file mode 100644 index 45d661dc37b..00000000000 --- a/tests/unit/unittest/filepathview-test.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include - -namespace { - -using ClangBackEnd::FilePathView; - -TEST(FilePathView, FilePathSlashForEmptyPath) -{ - FilePathView filePath(""); - - ASSERT_THAT(filePath.slashIndex(), -1); -} - -TEST(FilePathView, FilePathSlashForSingleSlash) -{ - FilePathView filePath("/"); - - ASSERT_THAT(filePath.slashIndex(), 0); -} - -TEST(FilePathView, FilePathSlashForFileInRoot) -{ - FilePathView filePath("/file.h"); - - ASSERT_THAT(filePath.slashIndex(), 0); -} - -TEST(FilePathView, FilePathSlashForSomeLongerPath) -{ - FilePathView filePath("/path/to/some/file.h"); - - ASSERT_THAT(filePath.slashIndex(), 13); -} - -TEST(FilePathView, FilePathSlashForFileNameOnly) -{ - FilePathView filePath("file.h"); - - ASSERT_THAT(filePath.slashIndex(), -1); -} - -TEST(FilePathView, DirectoryPathForEmptyPath) -{ - FilePathView filePath(""); - - ASSERT_THAT(filePath.directory(), ""); -} - -TEST(FilePathView, DirectoryPathForSingleSlashPath) -{ - FilePathView filePath{"/"}; - - ASSERT_THAT(filePath.directory(), ""); -} - -TEST(FilePathView, DirectoryPathForLongerPath) -{ - FilePathView filePath{"/path/to/some/file.h"}; - - ASSERT_THAT(filePath.directory(), "/path/to/some"); -} - -TEST(FilePathView, DirectoryPathForFileNameOnly) -{ - FilePathView filePath{"file.h"}; - - ASSERT_THAT(filePath.directory(), IsEmpty()); -} - -TEST(FilePathView, FileNameForEmptyPath) -{ - FilePathView filePath(""); - - ASSERT_THAT(filePath.name(), ""); -} - -TEST(FilePathView, FileNameForSingleSlashPath) -{ - FilePathView filePath{"/"}; - - ASSERT_THAT(filePath.name(), ""); -} - -TEST(FilePathView, FileNameForLongerPath) -{ - FilePathView filePath{"/path/to/some/file.h"}; - - ASSERT_THAT(filePath.name(), "file.h"); -} - -TEST(FilePathView, FileNameForFileNameOnly) -{ - FilePathView filePath{"file.h"}; - - ASSERT_THAT(filePath.name(), "file.h"); -} - -} diff --git a/tests/unit/unittest/filestatuscache-test.cpp b/tests/unit/unittest/filestatuscache-test.cpp deleted file mode 100644 index 07ba02655bc..00000000000 --- a/tests/unit/unittest/filestatuscache-test.cpp +++ /dev/null @@ -1,298 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" -#include "mockfilesystem.h" - -#include -#include -#include - -#include -#include - -#include - -namespace { - -using ClangBackEnd::FilePathId; -using ClangBackEnd::FilePathIds; - -class FileStatusCache : public testing::Test -{ -protected: - FileStatusCache() - { - ON_CALL(fileSystem, lastModified(Eq(header))).WillByDefault(Return(headerLastModifiedTime)); - ON_CALL(fileSystem, lastModified(Eq(source))).WillByDefault(Return(sourceLastModifiedTime)); - ON_CALL(fileSystem, lastModified(Eq(header2))).WillByDefault(Return(header2LastModifiedTime)); - ON_CALL(fileSystem, lastModified(Eq(source2))).WillByDefault(Return(source2LastModifiedTime)); - } - -protected: - NiceMock fileSystem; - ClangBackEnd::FileStatusCache cache{fileSystem}; - FilePathId header{1}; - FilePathId source{2}; - FilePathId header2{3}; - FilePathId source2{4}; - FilePathIds entries{header, source, header2, source2}; - long long headerLastModifiedTime = 100; - long long headerLastModifiedTime2 = 110; - long long header2LastModifiedTime = 300; - long long header2LastModifiedTime2 = 310; - long long sourceLastModifiedTime = 200; - long long source2LastModifiedTime = 400; -}; - -TEST_F(FileStatusCache, CreateEntry) -{ - cache.lastModifiedTime(header); - - ASSERT_THAT(cache, SizeIs(1)); -} - -TEST_F(FileStatusCache, AskCreatedEntryForLastModifiedTime) -{ - auto lastModified = cache.lastModifiedTime(header); - - ASSERT_THAT(lastModified, headerLastModifiedTime); -} - -TEST_F(FileStatusCache, AskCachedEntryForLastModifiedTime) -{ - cache.lastModifiedTime(header); - - auto lastModified = cache.lastModifiedTime(header); - - ASSERT_THAT(lastModified, headerLastModifiedTime); -} - -TEST_F(FileStatusCache, DontAddEntryTwice) -{ - cache.lastModifiedTime(header); - - cache.lastModifiedTime(header); - - ASSERT_THAT(cache, SizeIs(1)); -} - -TEST_F(FileStatusCache, AddNewEntry) -{ - cache.lastModifiedTime(header); - - cache.lastModifiedTime(source); - - ASSERT_THAT(cache, SizeIs(2)); -} - -TEST_F(FileStatusCache, AskNewEntryForLastModifiedTime) -{ - cache.lastModifiedTime(header); - - auto lastModified = cache.lastModifiedTime(source); - - ASSERT_THAT(lastModified, sourceLastModifiedTime); -} - -TEST_F(FileStatusCache, AddNewEntryReverseOrder) -{ - cache.lastModifiedTime(source); - - cache.lastModifiedTime(header); - - ASSERT_THAT(cache, SizeIs(2)); -} - -TEST_F(FileStatusCache, AskNewEntryReverseOrderAddedForLastModifiedTime) -{ - cache.lastModifiedTime(source); - - auto lastModified = cache.lastModifiedTime(header); - - ASSERT_THAT(lastModified, headerLastModifiedTime); -} - -TEST_F(FileStatusCache, UpdateFile) -{ - EXPECT_CALL(fileSystem, lastModified(Eq(header))) - .Times(2) - .WillOnce(Return(headerLastModifiedTime)) - .WillOnce(Return(headerLastModifiedTime2)); - cache.lastModifiedTime(header); - - cache.update(header); - - ASSERT_THAT(cache.lastModifiedTime(header), headerLastModifiedTime2); -} - -TEST_F(FileStatusCache, UpdateFileDoesNotChangeEntryCount) -{ - EXPECT_CALL(fileSystem, lastModified(Eq(header))) - .Times(2) - .WillOnce(Return(headerLastModifiedTime)) - .WillOnce(Return(headerLastModifiedTime2)); - cache.lastModifiedTime(header); - - cache.update(header); - - ASSERT_THAT(cache, SizeIs(1)); -} - -TEST_F(FileStatusCache, UpdateFileForNonExistingEntry) -{ - cache.update(header); - - ASSERT_THAT(cache, SizeIs(0)); -} - -TEST_F(FileStatusCache, UpdateFiles) -{ - EXPECT_CALL(fileSystem, lastModified(Eq(header))) - .Times(2) - .WillOnce(Return(headerLastModifiedTime)) - .WillOnce(Return(headerLastModifiedTime2)); - EXPECT_CALL(fileSystem, lastModified(Eq(header2))) - .Times(2) - .WillOnce(Return(header2LastModifiedTime)) - .WillOnce(Return(header2LastModifiedTime2)); - cache.lastModifiedTime(header); - cache.lastModifiedTime(header2); - - cache.update(entries); - - ASSERT_THAT(cache.lastModifiedTime(header), headerLastModifiedTime2); - ASSERT_THAT(cache.lastModifiedTime(header2), header2LastModifiedTime2); -} - -TEST_F(FileStatusCache, UpdateFilesDoesNotChangeEntryCount) -{ - EXPECT_CALL(fileSystem, lastModified(Eq(header))) - .Times(2) - .WillOnce(Return(headerLastModifiedTime)) - .WillOnce(Return(headerLastModifiedTime2)); - EXPECT_CALL(fileSystem, lastModified(Eq(header2))) - .Times(2) - .WillOnce(Return(header2LastModifiedTime)) - .WillOnce(Return(header2LastModifiedTime2)); - cache.lastModifiedTime(header); - cache.lastModifiedTime(header2); - - cache.update(entries); - - ASSERT_THAT(cache, SizeIs(2)); -} - -TEST_F(FileStatusCache, UpdateFilesForNonExistingEntry) -{ - cache.update(entries); - - ASSERT_THAT(cache, SizeIs(0)); -} - -TEST_F(FileStatusCache, NewModifiedEntries) -{ - auto modifiedIds = cache.modified(entries); - - ASSERT_THAT(modifiedIds, entries); -} - -TEST_F(FileStatusCache, NoNewModifiedEntries) -{ - cache.modified(entries); - - auto modifiedIds = cache.modified(entries); - - ASSERT_THAT(modifiedIds, IsEmpty()); -} - -TEST_F(FileStatusCache, SomeNewModifiedEntries) -{ - cache.modified({source, header2}); - - auto modifiedIds = cache.modified(entries); - - ASSERT_THAT(modifiedIds, ElementsAre(header, source2)); -} - -TEST_F(FileStatusCache, SomeAlreadyExistingModifiedEntries) -{ - EXPECT_CALL(fileSystem, lastModified(Eq(header))) - .Times(2) - .WillOnce(Return(headerLastModifiedTime)) - .WillOnce(Return(headerLastModifiedTime2)); - EXPECT_CALL(fileSystem, lastModified(Eq(header2))) - .Times(2) - .WillOnce(Return(header2LastModifiedTime)) - .WillOnce(Return(header2LastModifiedTime2)); - EXPECT_CALL(fileSystem, lastModified(Eq(source))).Times(2).WillRepeatedly(Return(sourceLastModifiedTime)); - EXPECT_CALL(fileSystem, lastModified(Eq(source2))) - .Times(2) - .WillRepeatedly(Return(source2LastModifiedTime)); - cache.modified(entries); - - auto modifiedIds = cache.modified(entries); - - ASSERT_THAT(modifiedIds, ElementsAre(header, header2)); -} - -TEST_F(FileStatusCache, SomeAlreadyExistingAndSomeNewModifiedEntries) -{ - EXPECT_CALL(fileSystem, lastModified(Eq(header))).WillRepeatedly(Return(headerLastModifiedTime)); - EXPECT_CALL(fileSystem, lastModified(Eq(header2))) - .Times(2) - .WillOnce(Return(header2LastModifiedTime)) - .WillOnce(Return(header2LastModifiedTime2)); - EXPECT_CALL(fileSystem, lastModified(Eq(source))).Times(2).WillRepeatedly(Return(sourceLastModifiedTime)); - EXPECT_CALL(fileSystem, lastModified(Eq(source2))).WillRepeatedly(Return(source2LastModifiedTime)); - cache.modified({source, header2}); - - auto modifiedIds = cache.modified(entries); - - ASSERT_THAT(modifiedIds, ElementsAre(header, header2, source2)); -} - -TEST_F(FileStatusCache, TimeIsUpdatedForSomeAlreadyExistingModifiedEntries) -{ - EXPECT_CALL(fileSystem, lastModified(Eq(header))) - .Times(2) - .WillOnce(Return(headerLastModifiedTime)) - .WillOnce(Return(headerLastModifiedTime2)); - EXPECT_CALL(fileSystem, lastModified(Eq(header2))) - .Times(2) - .WillOnce(Return(header2LastModifiedTime)) - .WillOnce(Return(header2LastModifiedTime2)); - EXPECT_CALL(fileSystem, lastModified(Eq(source))).Times(2).WillRepeatedly(Return(sourceLastModifiedTime)); - EXPECT_CALL(fileSystem, lastModified(Eq(source2))) - .Times(2) - .WillRepeatedly(Return(source2LastModifiedTime)); - cache.modified(entries); - - cache.modified(entries); - - ASSERT_THAT(cache.lastModifiedTime(header), headerLastModifiedTime2); -} - -} // namespace diff --git a/tests/unit/unittest/generatedfiles-test.cpp b/tests/unit/unittest/generatedfiles-test.cpp deleted file mode 100644 index 8e5a34ffd71..00000000000 --- a/tests/unit/unittest/generatedfiles-test.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include - -namespace { - -using ClangBackEnd::V2::FileContainer; -using ClangBackEnd::V2::FileContainers; - -class GeneratedFiles : public testing::Test -{ -protected: - FileContainer file1{"/file1", 1, "content1"}; - FileContainer file1b{"/file1", 1, "content1b"}; - FileContainer file2{"/file2", 2, "content2"}; - FileContainer file2b{"/file2", 2, "content2b"}; - FileContainer file3{"/file3", 3, "content3"}; - FileContainer file4{"/file4", 4, "content4"}; - ClangBackEnd::GeneratedFiles generatedFiles; -}; - -TEST_F(GeneratedFiles, AddGeneratedFiles) -{ - generatedFiles.update({file1, file2}); - - ASSERT_THAT(generatedFiles.fileContainers(), ElementsAre(file1, file2)); -} - -TEST_F(GeneratedFiles, UpdateGeneratedFiles) -{ - generatedFiles.update({{file1, file3}}); - - generatedFiles.update({file1b, file2b, file4}); - - ASSERT_THAT(generatedFiles.fileContainers(), ElementsAre(file1b, file2b, file3, file4)); -} - -TEST_F(GeneratedFiles, RemoveGeneratedFiles) -{ - generatedFiles.update({file1, file2, file3, file4}); - - generatedFiles.remove({"/file2", "/file4"}); - - ASSERT_THAT(generatedFiles.fileContainers(), ElementsAre(file1, file3)); -} - -TEST_F(GeneratedFiles, IsValidForNoGeneratedFiles) -{ - ASSERT_TRUE(generatedFiles.isValid()); -} - -TEST_F(GeneratedFiles, IsNotValidIfFilesWithNotContentExists) -{ - generatedFiles.update({{"/file2", 2, ""}}); - - ASSERT_FALSE(generatedFiles.isValid()); -} - -TEST_F(GeneratedFiles, IsValidIfAllFilesHasContent) -{ - generatedFiles.update({file1, file2, file3, file4}); - - ASSERT_TRUE(generatedFiles.isValid()); -} - -TEST_F(GeneratedFiles, GetFilePathIds) -{ - generatedFiles.update({file3, file2, file1, file4}); - - auto ids = generatedFiles.filePathIds(); - - ASSERT_THAT(ids, ElementsAre(1, 2, 3, 4)); -} - -} // namespace diff --git a/tests/unit/unittest/gtest-clang-printing.cpp b/tests/unit/unittest/gtest-clang-printing.cpp index 13d2d94e5b2..00bb0d2e443 100644 --- a/tests/unit/unittest/gtest-clang-printing.cpp +++ b/tests/unit/unittest/gtest-clang-printing.cpp @@ -29,7 +29,6 @@ #ifdef CLANG_UNIT_TESTS #include #include -#include #include #include diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp index 4aeeb0798de..3ec95c9ca2f 100644 --- a/tests/unit/unittest/gtest-creator-printing.cpp +++ b/tests/unit/unittest/gtest-creator-printing.cpp @@ -38,11 +38,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include @@ -466,11 +466,6 @@ std::ostream &operator<<(std::ostream &os, const EndMessage &/*message*/) return os << "()"; } -std::ostream &operator<<(std::ostream &os, const CancelMessage &/*message*/) -{ - return os << "()"; -} - std::ostream &operator<<(std::ostream &os, const AliveMessage &/*message*/) { return os << "()"; diff --git a/tests/unit/unittest/gtest-creator-printing.h b/tests/unit/unittest/gtest-creator-printing.h index ee12f01a559..cb33ac3cf40 100644 --- a/tests/unit/unittest/gtest-creator-printing.h +++ b/tests/unit/unittest/gtest-creator-printing.h @@ -111,7 +111,6 @@ void PrintTo(const Utils::PathString &text, ::std::ostream *os); } // namespace Utils namespace ClangBackEnd { -class CancelMessage; class AliveMessage; class CompletionsMessage; class EchoMessage; @@ -150,7 +149,6 @@ struct ExtraInfo; class TokenInfoContainer; class UnsavedFilesRemovedMessage; -std::ostream &operator<<(std::ostream &out, const CancelMessage &message); std::ostream &operator<<(std::ostream &out, const AliveMessage &message); std::ostream &operator<<(std::ostream &out, const CompletionsMessage &message); std::ostream &operator<<(std::ostream &out, const EchoMessage &message); diff --git a/tests/unit/unittest/locatorfilter-test.cpp b/tests/unit/unittest/locatorfilter-test.cpp deleted file mode 100644 index 1cc15b281c6..00000000000 --- a/tests/unit/unittest/locatorfilter-test.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockeditormanager.h" -#include "mocksymbolquery.h" - -#include -#include - -namespace { - -using ClangBackEnd::SymbolKind; -using ClangBackEnd::SourceLocationKind; -using ClangRefactoring::Symbol; - -MATCHER_P2(HasNameAndSymbol, name, symbol, - std::string(negation ? "hasn't " : "has ") - + PrintToString(name) - + " and " - + PrintToString(symbol)) -{ - const Core::LocatorFilterEntry &entry = arg; - - return entry.displayName == QString::fromUtf8(name) && entry.internalData.value() == symbol; -} - -class LocatorFilter : public ::testing::Test -{ -protected: - static Core::LocatorFilterEntry createSymbolLocatorFilterEntry() - { - ClangRefactoring::Symbol symbol{42, "symbolName"}; - Core::LocatorFilterEntry entry; - entry.internalData = QVariant::fromValue(symbol); - - return entry; - } - -protected: - MockEditorManager mockEditorManager; - NiceMock mockSymbolQuery; - ClangRefactoring::LocatorFilter filter{mockSymbolQuery, mockEditorManager, {SymbolKind::Record}, "", "", ""}; - Core::LocatorFilterEntry entry{createSymbolLocatorFilterEntry()}; - int start = 0; - int length = 0; - QString newText; - Utils::LineColumn lineColumn{4, 3}; - ClangBackEnd::FilePathId filePathId{64}; - ClangRefactoring::SourceLocation sourceLocation{filePathId, lineColumn}; -}; - -TEST_F(LocatorFilter, MatchesForCallSymbols) -{ - QFutureInterface dummy; - - EXPECT_CALL(mockSymbolQuery, symbols(ElementsAre(ClangBackEnd::SymbolKind::Record), Eq("search%Term%"))); - - filter.matchesFor(dummy, "search*Term"); -} - -TEST_F(LocatorFilter, MatchesForReturnsLocatorFilterEntries) -{ - ClangRefactoring::Symbols symbols{{12, "Foo", "class Foo final : public Bar"}, - {22, "Poo", "class Poo final : public Bar"}}; - ON_CALL(mockSymbolQuery, symbols(ElementsAre(ClangBackEnd::SymbolKind::Record), Eq("search%Term%"))) - .WillByDefault(Return(symbols)); - QFutureInterface dummy; - - auto entries = filter.matchesFor(dummy, "search*Term"); - - ASSERT_THAT(entries, - ElementsAre( - HasNameAndSymbol("Foo", symbols[0]), - HasNameAndSymbol("Poo", symbols[1]))); -} - -TEST_F(LocatorFilter, AcceptDontCallsLocationAndOpensEditorIfItGetInvalidResultFromDatabase) -{ - InSequence s; - - EXPECT_CALL(mockSymbolQuery, locationForSymbolId(42, SourceLocationKind::Definition)) - .WillOnce(Return(Utils::optional{})); - EXPECT_CALL(mockEditorManager, openEditorAt(Eq(filePathId), Eq(lineColumn))).Times(0); - - filter.accept(entry, &newText, &start, &length); -} - -TEST_F(LocatorFilter, AcceptCallsLocationAndOpensEditor) -{ - InSequence s; - - EXPECT_CALL(mockSymbolQuery, locationForSymbolId(42, SourceLocationKind::Definition)) - .WillOnce(Return(sourceLocation)); - EXPECT_CALL(mockEditorManager, openEditorAt(Eq(filePathId), Eq(lineColumn))); - - filter.accept(entry, &newText, &start, &length); -} - -} diff --git a/tests/unit/unittest/mockbuilddependenciesprovider.h b/tests/unit/unittest/mockbuilddependenciesprovider.h deleted file mode 100644 index 65dd7c53130..00000000000 --- a/tests/unit/unittest/mockbuilddependenciesprovider.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "googletest.h" - -#include - -class MockBuildDependenciesProvider : public ClangBackEnd::BuildDependenciesProviderInterface -{ -public: - MOCK_METHOD1( - create, - ClangBackEnd::BuildDependency(const ClangBackEnd::ProjectPartContainer &projectPart)); - MOCK_METHOD2(create, - ClangBackEnd::BuildDependency(const ClangBackEnd::ProjectPartContainer &projectPart, - const ClangBackEnd::SourceEntries &sourceEntries)); - MOCK_CONST_METHOD2(createSourceEntriesFromStorage, - ClangBackEnd::SourceEntries(const ClangBackEnd::FilePathIds &sourcePathIds, - ClangBackEnd::ProjectPartId projectPartId)); - ClangBackEnd::BuildDependency create(const ClangBackEnd::ProjectPartContainer &projectPart, - ClangBackEnd::SourceEntries &&sourceEntries) override - { - return create(projectPart, sourceEntries); - } -}; diff --git a/tests/unit/unittest/mockbuilddependenciesstorage.h b/tests/unit/unittest/mockbuilddependenciesstorage.h deleted file mode 100644 index c98b3fd3aeb..00000000000 --- a/tests/unit/unittest/mockbuilddependenciesstorage.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "googletest.h" - -#include - -class MockBuildDependenciesStorage : public ClangBackEnd::BuildDependenciesStorageInterface -{ -public: - MOCK_METHOD2(insertOrUpdateSources, - void(const ClangBackEnd::SourceEntries &sources, - ClangBackEnd::ProjectPartId projectPartId)); - MOCK_METHOD1(insertOrUpdateUsedMacros, - void (const ClangBackEnd::UsedMacros &usedMacros)); - MOCK_METHOD1(insertOrUpdateFileStatuses, void(const ClangBackEnd::FileStatuses &fileStatuses)); - MOCK_METHOD1(insertOrUpdateSourceDependencies, - void (const ClangBackEnd::SourceDependencies &sourceDependencies)); - MOCK_CONST_METHOD1(fetchLowestLastModifiedTime, - long long (ClangBackEnd::FilePathId sourceId)); - MOCK_CONST_METHOD2(fetchDependSources, - ClangBackEnd::SourceEntries(ClangBackEnd::FilePathId sourceId, - ClangBackEnd::ProjectPartId projectPartId)); - MOCK_CONST_METHOD1(fetchUsedMacros, - ClangBackEnd::UsedMacros (ClangBackEnd::FilePathId sourceId)); - MOCK_METHOD1(fetchProjectPartId, - ClangBackEnd::ProjectPartId(Utils::SmallStringView projectPartName)); - MOCK_METHOD2(updatePchCreationTimeStamp, - void(long long pchCreationTimeStamp, ClangBackEnd::ProjectPartId projectPartId)); - MOCK_CONST_METHOD1(fetchPchSources, - ClangBackEnd::FilePathIds(ClangBackEnd::ProjectPartId projectPartId)); - MOCK_CONST_METHOD1(fetchSources, - ClangBackEnd::FilePathIds(ClangBackEnd::ProjectPartId projectPartId)); - MOCK_METHOD2(insertOrUpdateIndexingTimeStamps, - void(const ClangBackEnd::FilePathIds &filePathIds, - ClangBackEnd::TimeStamp indexingTimeStamp)); - MOCK_METHOD2(insertOrUpdateIndexingTimeStampsWithoutTransaction, - void(const ClangBackEnd::FilePathIds &filePathIds, - ClangBackEnd::TimeStamp indexingTimeStamp)); - MOCK_METHOD1(insertOrUpdateIndexingTimeStamps, void(const ClangBackEnd::FileStatuses &)); - MOCK_CONST_METHOD0(fetchIndexingTimeStamps, ClangBackEnd::SourceTimeStamps()); - MOCK_CONST_METHOD1(fetchIncludedIndexingTimeStamps, - ClangBackEnd::SourceTimeStamps(ClangBackEnd::FilePathId sourcePathId)); - MOCK_CONST_METHOD1(fetchDependentSourceIds, - ClangBackEnd::FilePathIds(const ClangBackEnd::FilePathIds &sourcePathIds)); -}; - diff --git a/tests/unit/unittest/mockbuilddependencygenerator.h b/tests/unit/unittest/mockbuilddependencygenerator.h deleted file mode 100644 index abd6c223d03..00000000000 --- a/tests/unit/unittest/mockbuilddependencygenerator.h +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "googletest.h" - -#include - -class MockBuildDependencyGenerator : public ClangBackEnd::BuildDependencyGeneratorInterface -{ -public: - MOCK_METHOD1(create, - ClangBackEnd::BuildDependency (const ClangBackEnd::ProjectPartContainer &projectPart)); -}; - diff --git a/tests/unit/unittest/mockclangpathwatcher.h b/tests/unit/unittest/mockclangpathwatcher.h deleted file mode 100644 index 80f077f4750..00000000000 --- a/tests/unit/unittest/mockclangpathwatcher.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "googletest.h" - -#include - -class MockClangPathWatcher : public ClangBackEnd::ClangPathWatcherInterface -{ -public: - MOCK_METHOD1(updateIdPaths, - void (const std::vector &idPaths)); - MOCK_METHOD1(removeIds, void(const ClangBackEnd::ProjectPartIds &ids)); - MOCK_METHOD1(setNotifier, - void (ClangBackEnd::ClangPathWatcherNotifier *notifier)); - -}; diff --git a/tests/unit/unittest/mockclangpathwatchernotifier.h b/tests/unit/unittest/mockclangpathwatchernotifier.h deleted file mode 100644 index 8d8b8b1369a..00000000000 --- a/tests/unit/unittest/mockclangpathwatchernotifier.h +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "googletest.h" - -#include - -class MockClangPathWatcherNotifier : public ClangBackEnd::ClangPathWatcherNotifier -{ -public: - MOCK_METHOD1(pathsWithIdsChanged, void(const std::vector &idPaths)); - - MOCK_METHOD1(pathsChanged, - void (const ClangBackEnd::FilePathIds &filePathIds)); -}; - diff --git a/tests/unit/unittest/mockeditormanager.h b/tests/unit/unittest/mockeditormanager.h deleted file mode 100644 index 25ead76e9b3..00000000000 --- a/tests/unit/unittest/mockeditormanager.h +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "googletest.h" - -#include - -namespace Core { -class IEditor {}; -} - -class MockEditorManager final : public ClangRefactoring::EditorManagerInterface -{ -public: - MOCK_METHOD2(openEditorAt, - Core::IEditor*(ClangBackEnd::FilePathId filePathId, Utils::LineColumn lineColumn)); - -}; - diff --git a/tests/unit/unittest/mockfilepathcaching.h b/tests/unit/unittest/mockfilepathcaching.h deleted file mode 100644 index 155aa491c97..00000000000 --- a/tests/unit/unittest/mockfilepathcaching.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "googletest.h" - -#include - -class MockFilePathCaching : public ClangBackEnd::FilePathCachingInterface -{ -public: - MOCK_CONST_METHOD1(filePathId, - ClangBackEnd::FilePathId (ClangBackEnd::FilePathView filePath)); - MOCK_CONST_METHOD1(filePath, - ClangBackEnd::FilePath (ClangBackEnd::FilePathId filePathId)); - MOCK_CONST_METHOD1(directoryPathId, - ClangBackEnd::DirectoryPathId(Utils::SmallStringView directoryPath)); - MOCK_CONST_METHOD1(directoryPath, - Utils::PathString(ClangBackEnd::DirectoryPathId directoryPathId)); - MOCK_CONST_METHOD1(directoryPathId, - ClangBackEnd::DirectoryPathId(ClangBackEnd::FilePathId filePathId)); - MOCK_METHOD1(addFilePaths, void(const ClangBackEnd::FilePaths &filePaths)); - MOCK_METHOD0(populateIfEmpty, void()); -}; diff --git a/tests/unit/unittest/mockfilepathstorage.h b/tests/unit/unittest/mockfilepathstorage.h deleted file mode 100644 index 0ea6c1b16d7..00000000000 --- a/tests/unit/unittest/mockfilepathstorage.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "googletest.h" - -#include "sqlitedatabasemock.h" - -#include - -class MockFilePathStorage -{ -public: - MockFilePathStorage(SqliteDatabaseMock &databaseMock) - : databaseMock{databaseMock} - {} - - MOCK_METHOD1(fetchDirectoryId, int(Utils::SmallStringView directoryPath)); - MOCK_METHOD2(fetchSourceId, - int (int directoryId, Utils::SmallStringView sourceName)); - MOCK_METHOD1(fetchDirectoryIdUnguarded, int(Utils::SmallStringView directoryPath)); - MOCK_METHOD2(fetchSourceIdUnguarded, int(int directoryId, Utils::SmallStringView sourceName)); - MOCK_METHOD1(fetchDirectoryPath, - Utils::PathString (int directoryId)); - MOCK_METHOD1(fetchSourceNameAndDirectoryId, - ClangBackEnd::Sources::SourceNameAndDirectoryId (int sourceId)); - MOCK_METHOD0(fetchAllDirectories, std::vector()); - MOCK_METHOD0(fetchAllSources, std::vector()); - - SqliteDatabaseMock &database() { return databaseMock; } - - SqliteDatabaseMock &databaseMock; -}; - diff --git a/tests/unit/unittest/mockfilesystem.h b/tests/unit/unittest/mockfilesystem.h deleted file mode 100644 index fff5758cc62..00000000000 --- a/tests/unit/unittest/mockfilesystem.h +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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 - -#include "googletest.h" - -#include - -class MockFileSystem : public ClangBackEnd::FileSystemInterface -{ -public: - MOCK_CONST_METHOD1(directoryEntries, ClangBackEnd::FilePathIds(const QString &directoryPath)); - MOCK_CONST_METHOD1(lastModified, long long(ClangBackEnd::FilePathId filePathId)); - MOCK_METHOD1(remove, void(const ClangBackEnd::FilePathIds &filePathIds)); -}; diff --git a/tests/unit/unittest/mockgeneratedfiles.h b/tests/unit/unittest/mockgeneratedfiles.h deleted file mode 100644 index 481747c27ff..00000000000 --- a/tests/unit/unittest/mockgeneratedfiles.h +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "googletest.h" - -#include - -class MockGeneratedFiles : public ClangBackEnd::GeneratedFilesInterface -{ -public: - MOCK_METHOD1(update, - void (const ClangBackEnd::V2::FileContainers &fileContainers)); - MOCK_METHOD1(remove, - void (const ClangBackEnd::FilePaths &filePaths)); - MOCK_CONST_METHOD0(fileContainers, - const ClangBackEnd::V2::FileContainers &()); - MOCK_CONST_METHOD0(filePathIds, ClangBackEnd::FilePathIds()); - MOCK_CONST_METHOD0(isValid, bool()); - - void update(ClangBackEnd::V2::FileContainers &&fileContainers) - { - update(fileContainers); - } -}; diff --git a/tests/unit/unittest/mockmodifiedtimechecker.h b/tests/unit/unittest/mockmodifiedtimechecker.h deleted file mode 100644 index 1fa3dd497ca..00000000000 --- a/tests/unit/unittest/mockmodifiedtimechecker.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "googletest.h" - -#include - -class MockSourceEntriesModifiedTimeChecker - : public ClangBackEnd::ModifiedTimeCheckerInterface -{ -public: - MOCK_CONST_METHOD1(isUpToDate, - bool (const ClangBackEnd::SourceEntries &sourceEntries)); - MOCK_METHOD1(pathsChanged, void(const ClangBackEnd::FilePathIds &filePathIds)); -}; - -class MockSourceTimeStampsModifiedTimeChecker - : public ClangBackEnd::ModifiedTimeCheckerInterface -{ -public: - MOCK_CONST_METHOD1(isUpToDate, bool(const ClangBackEnd::SourceTimeStamps &sourceTimeStamps)); - MOCK_METHOD1(pathsChanged, void(const ClangBackEnd::FilePathIds &filePathIds)); -}; diff --git a/tests/unit/unittest/mockmutex.h b/tests/unit/unittest/mockmutex.h index 625efd713d3..9ca8e740899 100644 --- a/tests/unit/unittest/mockmutex.h +++ b/tests/unit/unittest/mockmutex.h @@ -27,8 +27,6 @@ #include "googletest.h" -#include - class MockMutex { public: @@ -40,7 +38,7 @@ public: MOCK_METHOD0(unlock_shared, void ()); }; -class MockMutexNonLocking : public ClangBackEnd::NonLockingMutex +class MockMutexNonLocking { public: using MutexType = MockMutexNonLocking; diff --git a/tests/unit/unittest/mockpchcreator.h b/tests/unit/unittest/mockpchcreator.h deleted file mode 100644 index 86a34ac04ff..00000000000 --- a/tests/unit/unittest/mockpchcreator.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "googletest.h" - -#include -#include -#include -#include - -class MockPchCreator : public ClangBackEnd::PchCreatorInterface -{ -public: - MOCK_METHOD1(generatePch, void(const ClangBackEnd::PchTask &pchTask)); - MOCK_METHOD0(projectPartPch, const ClangBackEnd::ProjectPartPch &()); - MOCK_METHOD1(setUnsavedFiles, void(const ClangBackEnd::V2::FileContainers &fileContainers)); - MOCK_METHOD0(clear, void()); - MOCK_METHOD0(doInMainThreadAfterFinished, void()); - MOCK_CONST_METHOD0(isUsed, bool()); - MOCK_METHOD1(setIsUsed, void(bool)); - - void generatePch(ClangBackEnd::PchTask &&pchTask) override - { - generatePch(pchTask); - } -}; diff --git a/tests/unit/unittest/mockpchmanagerclient.h b/tests/unit/unittest/mockpchmanagerclient.h deleted file mode 100644 index 9631f814070..00000000000 --- a/tests/unit/unittest/mockpchmanagerclient.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "googletest.h" - -#include -#include - -class MockPchManagerClient : public ClangBackEnd::PchManagerClientInterface -{ -public: - MOCK_METHOD0(alive, - void()); - MOCK_METHOD1(precompiledHeadersUpdated, - void(const ClangBackEnd::PrecompiledHeadersUpdatedMessage &message)); - MOCK_METHOD1(progress, - void(const ClangBackEnd::ProgressMessage &message)); - - void precompiledHeadersUpdated(ClangBackEnd::PrecompiledHeadersUpdatedMessage &&message) override - { - precompiledHeadersUpdated(message); - } - - void progress(ClangBackEnd::ProgressMessage &&message) override - { - progress(message); - } -}; diff --git a/tests/unit/unittest/mockpchmanagernotifier.h b/tests/unit/unittest/mockpchmanagernotifier.h deleted file mode 100644 index 8db9a63c40c..00000000000 --- a/tests/unit/unittest/mockpchmanagernotifier.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "googletest.h" - -#include - -class MockPchManagerNotifier : public ClangPchManager::PchManagerNotifierInterface -{ -public: - MockPchManagerNotifier(ClangPchManager::PchManagerClient &pchManagerClient) - : ClangPchManager::PchManagerNotifierInterface(pchManagerClient) - {} - - MOCK_METHOD1(precompiledHeaderUpdated, void(ClangBackEnd::ProjectPartId projectPartId)); - MOCK_METHOD1(precompiledHeaderRemoved, void(ClangBackEnd::ProjectPartId projectPartId)); -}; diff --git a/tests/unit/unittest/mockpchmanagerserver.h b/tests/unit/unittest/mockpchmanagerserver.h deleted file mode 100644 index 80dcf6690df..00000000000 --- a/tests/unit/unittest/mockpchmanagerserver.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "googletest.h" - -#include - -class MockPchManagerServer : public ClangBackEnd::PchManagerServerInterface -{ -public: - MOCK_METHOD0(end, - void()); - MOCK_METHOD1(updateProjectParts, - void (const ClangBackEnd::UpdateProjectPartsMessage&)); - MOCK_METHOD1(removeProjectParts, - void (const ClangBackEnd::RemoveProjectPartsMessage&)); - MOCK_METHOD1(updateGeneratedFiles, - void (const ClangBackEnd::UpdateGeneratedFilesMessage&)); - MOCK_METHOD1(removeGeneratedFiles, - void (const ClangBackEnd::RemoveGeneratedFilesMessage&)); - MOCK_METHOD2(setProgress, - void(int, int)); - - void updateProjectParts(ClangBackEnd::UpdateProjectPartsMessage &&message) override - { - updateProjectParts(message); - } - - void removeProjectParts(ClangBackEnd::RemoveProjectPartsMessage &&message) override - { - removeProjectParts(message); - } - - void updateGeneratedFiles(ClangBackEnd::UpdateGeneratedFilesMessage &&message) override - { - updateGeneratedFiles(message); - } - - void removeGeneratedFiles(ClangBackEnd::RemoveGeneratedFilesMessage &&message) override - { - removeGeneratedFiles(message); - } -}; diff --git a/tests/unit/unittest/mockpchtaskgenerator.h b/tests/unit/unittest/mockpchtaskgenerator.h deleted file mode 100644 index 492e320a33e..00000000000 --- a/tests/unit/unittest/mockpchtaskgenerator.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "googletest.h" - -#include - -class MockPchTaskGenerator : public ClangBackEnd::PchTaskGeneratorInterface -{ -public: - MOCK_METHOD2(addProjectParts, - void(const ClangBackEnd::ProjectPartContainers &projectParts, - const Utils::SmallStringVector &toolChainArguments)); - MOCK_METHOD2(addNonSystemProjectParts, - void(const ClangBackEnd::ProjectPartContainers &projectParts, - const Utils::SmallStringVector &toolChainArguments)); - MOCK_METHOD1(removeProjectParts, void(const ClangBackEnd::ProjectPartIds &projectsPartIds)); - - void addProjectParts(ClangBackEnd::ProjectPartContainers &&projectParts, - Utils::SmallStringVector &&toolChainArguments) override - { - addProjectParts(projectParts, toolChainArguments); - } - - void addNonSystemProjectParts(ClangBackEnd::ProjectPartContainers &&projectParts, - Utils::SmallStringVector &&toolChainArguments) override - { - addNonSystemProjectParts(projectParts, toolChainArguments); - } -}; diff --git a/tests/unit/unittest/mockpchtaskqueue.h b/tests/unit/unittest/mockpchtaskqueue.h deleted file mode 100644 index 3eccba4e0ca..00000000000 --- a/tests/unit/unittest/mockpchtaskqueue.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "googletest.h" - -#include - -class MockPchTaskQueue : public ClangBackEnd::PchTaskQueueInterface -{ -public: - MOCK_METHOD1(addSystemPchTasks, void(const ClangBackEnd::PchTasks &pchTasks)); - MOCK_METHOD1(addProjectPchTasks, void(const ClangBackEnd::PchTasks &pchTasks)); - MOCK_METHOD1(removePchTasks, void(const ClangBackEnd::ProjectPartIds &projectsPartIds)); - MOCK_METHOD0(processEntries, void ()); - - void addSystemPchTasks(ClangBackEnd::PchTasks &&pchTasks) override - { - addSystemPchTasks(pchTasks); - } - - void addProjectPchTasks(ClangBackEnd::PchTasks &&pchTasks) override - { - addProjectPchTasks(pchTasks); - } -}; diff --git a/tests/unit/unittest/mockpchtasksmerger.h b/tests/unit/unittest/mockpchtasksmerger.h deleted file mode 100644 index 0e6cbe1d4e7..00000000000 --- a/tests/unit/unittest/mockpchtasksmerger.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "googletest.h" - -#include - -class MockPchTasksMerger : public ClangBackEnd::PchTasksMergerInterface -{ -public: - MOCK_METHOD2(mergeTasks, - void(const ClangBackEnd::PchTaskSets &pchTaskSets, - const Utils::SmallStringVector &toolChainArguments)); - - MOCK_METHOD1(removePchTasks, void(const ClangBackEnd::ProjectPartIds &projectPartIds)); - - void mergeTasks(ClangBackEnd::PchTaskSets &&pchTaskSets, - Utils::SmallStringVector &&toolChainArguments) override - { - mergeTasks(pchTaskSets, toolChainArguments); - } -}; diff --git a/tests/unit/unittest/mockprecompiledheaderstorage.h b/tests/unit/unittest/mockprecompiledheaderstorage.h deleted file mode 100644 index 5dddf97fce8..00000000000 --- a/tests/unit/unittest/mockprecompiledheaderstorage.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "googletest.h" - -#include - -class MockPrecompiledHeaderStorage : public ClangBackEnd::PrecompiledHeaderStorageInterface -{ -public: - MOCK_METHOD3(insertProjectPrecompiledHeader, - void(ClangBackEnd::ProjectPartId projectPartId, - Utils::SmallStringView pchPath, - ClangBackEnd::TimeStamp pchBuildTime)); - MOCK_METHOD2(deleteProjectPrecompiledHeader, - void(ClangBackEnd::ProjectPartId projectPartId, ClangBackEnd::TimeStamp buildTime)); - MOCK_METHOD1(deleteProjectPrecompiledHeaders, - void(const ClangBackEnd::ProjectPartIds &projectPartIds)); - MOCK_METHOD3(insertSystemPrecompiledHeaders, - void(const ClangBackEnd::ProjectPartIds &projectPartIds, - Utils::SmallStringView pchPath, - ClangBackEnd::TimeStamp pchBuildTime)); - MOCK_METHOD1(deleteSystemPrecompiledHeaders, - void(const ClangBackEnd::ProjectPartIds &projectPartIds)); - MOCK_METHOD1(deleteSystemAndProjectPrecompiledHeaders, - void(const ClangBackEnd::ProjectPartIds &projectPartIds)); - MOCK_METHOD1(fetchSystemPrecompiledHeaderPath, - ClangBackEnd::FilePath(ClangBackEnd::ProjectPartId projectPartId)); - MOCK_CONST_METHOD1(fetchPrecompiledHeader, - ClangBackEnd::FilePath(ClangBackEnd::ProjectPartId projectPartId)); - MOCK_CONST_METHOD1(fetchPrecompiledHeaders, - ClangBackEnd::PchPaths(ClangBackEnd::ProjectPartId projectPartId)); - MOCK_CONST_METHOD1( - fetchTimeStamps, - ClangBackEnd::PrecompiledHeaderTimeStamps(ClangBackEnd::ProjectPartId projectPartId)); - MOCK_CONST_METHOD0(fetchAllPchPaths, ClangBackEnd::FilePaths()); -}; diff --git a/tests/unit/unittest/mockprocessor.h b/tests/unit/unittest/mockprocessor.h deleted file mode 100644 index 040d537ed42..00000000000 --- a/tests/unit/unittest/mockprocessor.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "googletest.h" - -#include - -namespace Sqlite { -class Database; -} - -class MockProcessor : public ClangBackEnd::ProcessorInterface -{ -public: - MockProcessor() - { - ON_CALL(*this, setIsUsed(_)).WillByDefault(Invoke(this, &MockProcessor::setIsUsed2)); - ON_CALL(*this, isUsed()).WillByDefault(Invoke(this, &MockProcessor::isUsed2)); - ON_CALL(*this, setUnsavedFiles(_)).WillByDefault(Invoke(this, &MockProcessor::setHasUnsavedFiles)); - } - - MOCK_METHOD1(setUnsavedFiles, - void(const ClangBackEnd::V2::FileContainers &unsavedFiles)); - - MOCK_METHOD0(clear, - void()); - - MOCK_CONST_METHOD0(isUsed, - bool()); - - MOCK_METHOD1(setIsUsed, - void(bool)); - - MOCK_METHOD0(doInMainThreadAfterFinished, - void()); - - void setIsUsed2(bool isUsed) - { - used = isUsed; - } - - bool isUsed2() const - { - return used; - } - - void setHasUnsavedFiles(const ClangBackEnd::V2::FileContainers &unsavedFiles) - { - hasUnsavedFiles = true; - } - -public: - bool used = false; - bool hasUnsavedFiles = false; -}; diff --git a/tests/unit/unittest/mockprocessormanager.h b/tests/unit/unittest/mockprocessormanager.h deleted file mode 100644 index 3252aada194..00000000000 --- a/tests/unit/unittest/mockprocessormanager.h +++ /dev/null @@ -1,36 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include - -class MockProcessorManager : public ClangBackEnd::ProcessorManagerInterface -{ -public: - using Processor = ClangBackEnd::ProcessorInterface; - - MOCK_METHOD0(unusedProcessor, ClangBackEnd::ProcessorInterface &()); -}; diff --git a/tests/unit/unittest/mockprogressmanager.h b/tests/unit/unittest/mockprogressmanager.h deleted file mode 100644 index 2d059fa9941..00000000000 --- a/tests/unit/unittest/mockprogressmanager.h +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "googletest.h" - -#include - -class MockProgressManager : public ClangPchManager::ProgressManagerInterface -{ -public: - MOCK_METHOD2(setProgress, - void (int, int)); -}; diff --git a/tests/unit/unittest/mockprojectpartprovider.h b/tests/unit/unittest/mockprojectpartprovider.h deleted file mode 100644 index 1bde9e082fd..00000000000 --- a/tests/unit/unittest/mockprojectpartprovider.h +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "googletest.h" - -#include - -class MockProjectPartProvider : public ClangRefactoring::ProjectPartProviderInterface -{ -public: - MOCK_CONST_METHOD0(generatedFiles, - ClangBackEnd::V2::FileContainers()); - MOCK_CONST_METHOD1(projectPart, - CppTools::ProjectPart*(const QString &projectPartId)); -}; diff --git a/tests/unit/unittest/mockprojectpartqueue.h b/tests/unit/unittest/mockprojectpartqueue.h deleted file mode 100644 index 022878c73a5..00000000000 --- a/tests/unit/unittest/mockprojectpartqueue.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "googletest.h" - -#include - -class MockProjectPartQueue : public ClangBackEnd::ProjectPartQueueInterface -{ -public: - MOCK_METHOD1(addProjectParts, - void (const ClangBackEnd::ProjectPartContainers &projectParts)); - MOCK_METHOD1(removeProjectParts, - void (const Utils::SmallStringVector &projectsPartIds)); - - MOCK_METHOD0(processEntries, void ()); - - void addProjectParts(ClangBackEnd::ProjectPartContainers &&projectParts) override - { - addProjectParts(projectParts); - } -}; diff --git a/tests/unit/unittest/mockprojectpartsmanager.h b/tests/unit/unittest/mockprojectpartsmanager.h deleted file mode 100644 index d458cb7231e..00000000000 --- a/tests/unit/unittest/mockprojectpartsmanager.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "googletest.h" - -#include - -class MockProjectPartsManager : public ClangBackEnd::ProjectPartsManagerInterface -{ -public: - MOCK_METHOD1(update, - ClangBackEnd::ProjectPartsManagerInterface::UpToDataProjectParts( - const ClangBackEnd::ProjectPartContainers &projectsParts)); - MOCK_METHOD1(remove, void(const ClangBackEnd::ProjectPartIds &projectPartIds)); - MOCK_CONST_METHOD1( - projects, - ClangBackEnd::ProjectPartContainers(const ClangBackEnd::ProjectPartIds &projectPartIds)); - MOCK_METHOD2(updateDeferred, - void(const ClangBackEnd::ProjectPartContainers &system, - const ClangBackEnd::ProjectPartContainers &project)); - MOCK_METHOD0(deferredSystemUpdates, ClangBackEnd::ProjectPartContainers()); - MOCK_METHOD0(deferredProjectUpdates, ClangBackEnd::ProjectPartContainers()); - - ClangBackEnd::ProjectPartsManagerInterface::UpToDataProjectParts update( - ClangBackEnd::ProjectPartContainers &&projectsParts) override - { - return update(projectsParts); - } - - void updateDeferred(ClangBackEnd::ProjectPartContainers &&system, - ClangBackEnd::ProjectPartContainers &&project) override - { - return updateDeferred(system, project); - } -}; diff --git a/tests/unit/unittest/mockprojectpartsstorage.h b/tests/unit/unittest/mockprojectpartsstorage.h deleted file mode 100644 index cdca4ef78e3..00000000000 --- a/tests/unit/unittest/mockprojectpartsstorage.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "googletest.h" - -#include - -class MockProjectPartsStorage : public ClangBackEnd::ProjectPartsStorageInterface -{ -public: - MOCK_CONST_METHOD0(fetchProjectParts, ClangBackEnd::ProjectPartContainers()); - MOCK_CONST_METHOD1( - fetchProjectParts, - ClangBackEnd::ProjectPartContainers(const ClangBackEnd::ProjectPartIds &projectPartIds)); - MOCK_CONST_METHOD0(fetchAllProjectPartNamesAndIds, ClangBackEnd::Internal::ProjectPartNameIds()); - MOCK_CONST_METHOD1(fetchProjectPartId, - ClangBackEnd::ProjectPartId(Utils::SmallStringView projectPartName)); - MOCK_CONST_METHOD1(fetchProjectPartIdUnguarded, - ClangBackEnd::ProjectPartId(Utils::SmallStringView projectPartName)); - MOCK_CONST_METHOD1(fetchProjectPartName, - Utils::PathString(ClangBackEnd::ProjectPartId projectPartId)); - MOCK_METHOD8(updateProjectPart, - void(ClangBackEnd::ProjectPartId projectPartId, - const Utils::SmallStringVector &commandLineArgument, - const ClangBackEnd::CompilerMacros &compilerMacros, - const ClangBackEnd::IncludeSearchPaths &systemIncludeSearchPaths, - const ClangBackEnd::IncludeSearchPaths &projectIncludeSearchPaths, - Utils::Language language, - Utils::LanguageVersion languageVersion, - Utils::LanguageExtension languageExtension)); - MOCK_METHOD1(updateProjectParts, void(const ClangBackEnd::ProjectPartContainers &projectParts)); - MOCK_CONST_METHOD1( - fetchProjectPartArtefact, - Utils::optional(ClangBackEnd::FilePathId sourceId)); - MOCK_CONST_METHOD1(fetchProjectPartArtefact, - Utils::optional( - ClangBackEnd::ProjectPartId projectPartId)); - MOCK_METHOD1(resetIndexingTimeStamps, - void(const ClangBackEnd::ProjectPartContainers &projectsParts)); - MOCK_METHOD0(transactionBackend, Sqlite::TransactionInterface &()); -}; diff --git a/tests/unit/unittest/mockrefactoringclient.h b/tests/unit/unittest/mockrefactoringclient.h deleted file mode 100644 index 11721bb7af2..00000000000 --- a/tests/unit/unittest/mockrefactoringclient.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "googletest.h" - -#include - -class MockRefactoringClient : public ClangBackEnd::RefactoringClientInterface -{ -public: - MOCK_METHOD0(alive, - void()); - MOCK_METHOD1(sourceRangesAndDiagnosticsForQueryMessage, - void (const ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage&)); - MOCK_METHOD1(sourceRangesForQueryMessage, - void (const ClangBackEnd::SourceRangesForQueryMessage&)); - MOCK_METHOD1(progress, - void (const ClangBackEnd::ProgressMessage&)); - - void sourceRangesAndDiagnosticsForQueryMessage(ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage &&message) override - { - sourceRangesAndDiagnosticsForQueryMessage(message); - } - - void sourceRangesForQueryMessage(ClangBackEnd::SourceRangesForQueryMessage &&message) override - { - sourceRangesForQueryMessage(message); - } - - void progress(ClangBackEnd::ProgressMessage &&message) override - { - progress(message); - } - -}; diff --git a/tests/unit/unittest/mockrefactoringserver.h b/tests/unit/unittest/mockrefactoringserver.h deleted file mode 100644 index dd32a331034..00000000000 --- a/tests/unit/unittest/mockrefactoringserver.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "googletest.h" - -#include - -class MockRefactoringServer : public ClangBackEnd::RefactoringServerInterface -{ -public: - MOCK_METHOD0(end, - void()); - - MOCK_METHOD1(requestSourceRangesAndDiagnosticsForQueryMessage, - void (const ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage&)); - - MOCK_METHOD1(requestSourceRangesForQueryMessage, - void (const ClangBackEnd::RequestSourceRangesForQueryMessage&)); - - MOCK_METHOD1(updateProjectParts, - void (const ClangBackEnd::UpdateProjectPartsMessage&)); - - MOCK_METHOD1(updateGeneratedFiles, - void (const ClangBackEnd::UpdateGeneratedFilesMessage&)); - - MOCK_METHOD1(removeProjectParts, - void (const ClangBackEnd::RemoveProjectPartsMessage&)); - - MOCK_METHOD1(removeGeneratedFiles, - void (const ClangBackEnd::RemoveGeneratedFilesMessage&)); - - MOCK_METHOD0(cancel, - void()); - - MOCK_METHOD2(setProgress, - void(int, int)); - - void requestSourceRangesAndDiagnosticsForQueryMessage(ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage &&message) override - { - requestSourceRangesAndDiagnosticsForQueryMessage(message); - } - - void requestSourceRangesForQueryMessage(ClangBackEnd::RequestSourceRangesForQueryMessage &&message) override - { - requestSourceRangesForQueryMessage(message); - } - - void updateProjectParts(ClangBackEnd::UpdateProjectPartsMessage &&message) override - { - updateProjectParts(message); - } - - void updateGeneratedFiles(ClangBackEnd::UpdateGeneratedFilesMessage &&message) override - { - updateGeneratedFiles(message); - } - - void removeProjectParts(ClangBackEnd::RemoveProjectPartsMessage &&message) override - { - removeProjectParts(message); - } - - void removeGeneratedFiles(ClangBackEnd::RemoveGeneratedFilesMessage &&message) override - { - removeGeneratedFiles(message); - } -}; diff --git a/tests/unit/unittest/mocksearch.h b/tests/unit/unittest/mocksearch.h deleted file mode 100644 index 539c07833dd..00000000000 --- a/tests/unit/unittest/mocksearch.h +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "googletest.h" - -#include - -class MockSearch : public ClangRefactoring::SearchInterface -{ -public: - MOCK_METHOD2(startNewSearch, - std::unique_ptr(const QString &searchLabel, - const QString &searchTerm)); -}; diff --git a/tests/unit/unittest/mocksearchhandle.h b/tests/unit/unittest/mocksearchhandle.h deleted file mode 100644 index f13b06b2a80..00000000000 --- a/tests/unit/unittest/mocksearchhandle.h +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "googletest.h" - -#include - -class MockSearchHandle : public ClangRefactoring::SearchHandle -{ -public: - MockSearchHandle() = default; - using ClangRefactoring::SearchHandle::SearchHandle; - - MOCK_METHOD3(addResult, - void(const QString &fileName, - const QString &lineText, - Core::Search::TextRange textRange)); - MOCK_METHOD1(setExpectedResultCount, void(uint count)); - MOCK_METHOD1(setResultCounter, void(uint counter)); - MOCK_METHOD0(finishSearch, void()); -}; diff --git a/tests/unit/unittest/mocksearchresult.h b/tests/unit/unittest/mocksearchresult.h deleted file mode 100644 index 9acc47b9603..00000000000 --- a/tests/unit/unittest/mocksearchresult.h +++ /dev/null @@ -1,28 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include "googletest.h" diff --git a/tests/unit/unittest/mocksymbolindexertaskqueue.h b/tests/unit/unittest/mocksymbolindexertaskqueue.h deleted file mode 100644 index cef60ac7765..00000000000 --- a/tests/unit/unittest/mocksymbolindexertaskqueue.h +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "googletest.h" - -#include - -class MockSymbolIndexerTaskQueue : public ClangBackEnd::SymbolIndexerTaskQueueInterface -{ -public: - MOCK_METHOD1(addOrUpdateTasks, - void (std::vector &&tasks)); - MOCK_METHOD1(removeTasks, void(const ClangBackEnd::ProjectPartIds &projectPartIds)); - MOCK_METHOD0(processEntries, void()); -}; diff --git a/tests/unit/unittest/mocksymbolindexing.h b/tests/unit/unittest/mocksymbolindexing.h deleted file mode 100644 index c502f62d77b..00000000000 --- a/tests/unit/unittest/mocksymbolindexing.h +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "googletest.h" - -#include - -class MockSymbolIndexing : public ClangBackEnd::SymbolIndexingInterface -{ -public: - MOCK_METHOD1(updateProjectParts, - void(const ClangBackEnd::ProjectPartContainers &projectParts)); - - void updateProjectParts(ClangBackEnd::ProjectPartContainers &&projectParts) override - { - updateProjectParts(projectParts); - } -}; - diff --git a/tests/unit/unittest/mocksymbolquery.h b/tests/unit/unittest/mocksymbolquery.h deleted file mode 100644 index f8333ed7aa0..00000000000 --- a/tests/unit/unittest/mocksymbolquery.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "googletest.h" - -#include - -class MockSymbolQuery : public ClangRefactoring::SymbolQueryInterface -{ -public: - MOCK_CONST_METHOD3(locationsAt, - ClangRefactoring::SourceLocations(ClangBackEnd::FilePathId filePathId, int line, int utf8Column)); - MOCK_CONST_METHOD3(sourceUsagesAt, - CppTools::Usages(ClangBackEnd::FilePathId filePathId, int line, int utf8Column)); - MOCK_CONST_METHOD2(symbols, - ClangRefactoring::Symbols(const ClangBackEnd::SymbolKinds &symbolKinds, Utils::SmallStringView searchTerm)); - MOCK_CONST_METHOD2(locationForSymbolId, - Utils::optional(ClangRefactoring::SymbolId symbolId, ClangBackEnd::SourceLocationKind kind)); - MOCK_CONST_METHOD4(sourceUsagesAtByLocationKind, - CppTools::Usages(ClangBackEnd::FilePathId filePathId, - int line, - int utf8Column, - ClangBackEnd::SourceLocationKind)); - MOCK_CONST_METHOD3(declarationsAt, - CppTools::Usages(ClangBackEnd::FilePathId filePathId, int line, int utf8Column)); -}; diff --git a/tests/unit/unittest/mocksymbolscollector.h b/tests/unit/unittest/mocksymbolscollector.h deleted file mode 100644 index 7c62e54e17f..00000000000 --- a/tests/unit/unittest/mocksymbolscollector.h +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "googletest.h" - -#include - -namespace Sqlite { -class Database; -} - -class MockSymbolsCollector : public ClangBackEnd::SymbolsCollectorInterface -{ -public: - MockSymbolsCollector() - { - } - - MockSymbolsCollector(const Sqlite::Database &) - { - ON_CALL(*this, setIsUsed(_)).WillByDefault(Invoke(this, &MockSymbolsCollector::setIsUsed2)); - ON_CALL(*this, isUsed()).WillByDefault(Invoke(this, &MockSymbolsCollector::isUsed2)); - ON_CALL(*this, setUnsavedFiles(_)).WillByDefault(Invoke(this, &MockSymbolsCollector::setHasUnsavedFiles)); - } - - MOCK_METHOD0(collectSymbols, bool()); - - MOCK_METHOD2(setFile, - void(ClangBackEnd::FilePathId filePathId, - const Utils::SmallStringVector &arguments)); - - MOCK_METHOD1(setUnsavedFiles, - void(const ClangBackEnd::V2::FileContainers &unsavedFiles)); - - MOCK_METHOD0(clear, - void()); - - MOCK_METHOD0(doInMainThreadAfterFinished, - void()); - - MOCK_CONST_METHOD0(symbols, - const ClangBackEnd::SymbolEntries &()); - - MOCK_CONST_METHOD0(sourceLocations, - const ClangBackEnd::SourceLocationEntries &()); - - MOCK_CONST_METHOD0(sourceFiles, - const ClangBackEnd::FilePathIds &()); - - MOCK_CONST_METHOD0(usedMacros, - const ClangBackEnd::UsedMacros &()); - - MOCK_CONST_METHOD0(sourceDependencies, - const ClangBackEnd::SourceDependencies &()); - - MOCK_CONST_METHOD0(isUsed, - bool()); - - MOCK_METHOD1(setIsUsed, - void(bool)); - - void setIsUsed2(bool isUsed) - { - used = isUsed; - } - - bool isUsed2() const - { - return used; - } - - void setHasUnsavedFiles(const ClangBackEnd::V2::FileContainers &unsavedFiles) - { - hasUnsavedFiles = true; - } - -public: - bool used = false; - bool hasUnsavedFiles = false; -}; diff --git a/tests/unit/unittest/mocksymbolstorage.h b/tests/unit/unittest/mocksymbolstorage.h deleted file mode 100644 index ae5c0f775ad..00000000000 --- a/tests/unit/unittest/mocksymbolstorage.h +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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 - -#include "googletest.h" - -#include "sqlitedatabasemock.h" - -#include - -class MockSymbolStorage : public ClangBackEnd::SymbolStorageInterface -{ -public: - MOCK_METHOD2(addSymbolsAndSourceLocations, - void(const ClangBackEnd::SymbolEntries &symbolEentries, - const ClangBackEnd::SourceLocationEntries &sourceLocations)); -}; diff --git a/tests/unit/unittest/mocktaskscheduler.h b/tests/unit/unittest/mocktaskscheduler.h deleted file mode 100644 index dde6211828c..00000000000 --- a/tests/unit/unittest/mocktaskscheduler.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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 - -#include "googletest.h" - -#include -#include - -template -class MockTaskScheduler : public ClangBackEnd::TaskSchedulerInterface -{ -public: - MOCK_METHOD1_T(addTasks, - void (const std::vector &)); - MOCK_METHOD0(slotUsage, - ClangBackEnd::SlotUsage ()); - - void addTasks(std::vector &&tasks) - { - addTasks(tasks); - } -}; diff --git a/tests/unit/unittest/modifiedtimechecker-test.cpp b/tests/unit/unittest/modifiedtimechecker-test.cpp deleted file mode 100644 index 7651039f93c..00000000000 --- a/tests/unit/unittest/modifiedtimechecker-test.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" -#include "mockfilesystem.h" - -#include -#include -#include - -namespace { - -using ClangBackEnd::SourceEntries; -using ClangBackEnd::SourceType; -using ClangBackEnd::FilePathView; - - -class ModifiedTimeChecker : public testing::Test -{ -protected: - ModifiedTimeChecker() - { - ON_CALL(mockFileSystem, lastModified(Eq(1))).WillByDefault(Return(50)); - ON_CALL(mockFileSystem, lastModified(Eq(2))).WillByDefault(Return(30)); - ON_CALL(mockFileSystem, lastModified(Eq(3))).WillByDefault(Return(50)); - ON_CALL(mockFileSystem, lastModified(Eq(4))).WillByDefault(Return(30)); - } - - NiceMock mockFileSystem; - ClangBackEnd::ModifiedTimeChecker<> checker{mockFileSystem}; - SourceEntries upToDateEntries = {{1, SourceType::UserInclude, 51}, - {2, SourceType::SystemInclude, 30}, - {3, SourceType::UserInclude, 50}, - {4, SourceType::SystemInclude, 31}}; - SourceEntries equalEntries = {{1, SourceType::UserInclude, 50}, - {2, SourceType::SystemInclude, 30}, - {3, SourceType::UserInclude, 50}, - {4, SourceType::SystemInclude, 30}}; - SourceEntries notUpToDateEntries = {{1, SourceType::UserInclude, 50}, - {2, SourceType::SystemInclude, 29}, - {3, SourceType::UserInclude, 50}, - {4, SourceType::SystemInclude, 30}}; -}; - -TEST_F(ModifiedTimeChecker, IsUpToDate) -{ - auto isUpToDate = checker.isUpToDate(upToDateEntries); - - ASSERT_TRUE(isUpToDate); -} - -TEST_F(ModifiedTimeChecker, EqualEntriesAreUpToDate) -{ - auto isUpToDate = checker.isUpToDate(equalEntries); - - ASSERT_TRUE(isUpToDate); -} - -TEST_F(ModifiedTimeChecker, IsUpToDateSecondRun) -{ - checker.isUpToDate(upToDateEntries); - - auto isUpToDate = checker.isUpToDate(upToDateEntries); - - ASSERT_TRUE(isUpToDate); -} - -TEST_F(ModifiedTimeChecker, IsNotUpToDateIfSourceEntriesAreEmpty) -{ - auto isUpToDate = checker.isUpToDate({}); - - ASSERT_FALSE(isUpToDate); -} - -TEST_F(ModifiedTimeChecker, IsNotUpToDate) -{ - auto isUpToDate = checker.isUpToDate(notUpToDateEntries); - - ASSERT_FALSE(isUpToDate); -} - -TEST_F(ModifiedTimeChecker, IsNotUpToDateSecondRun) -{ - checker.isUpToDate(notUpToDateEntries); - - auto isUpToDate = checker.isUpToDate(notUpToDateEntries); - - ASSERT_FALSE(isUpToDate); -} - -TEST_F(ModifiedTimeChecker, PathChangesUpdatesTimeStamps) -{ - checker.isUpToDate(upToDateEntries); - - EXPECT_CALL(mockFileSystem, lastModified(Eq(2))); - EXPECT_CALL(mockFileSystem, lastModified(Eq(3))); - - checker.pathsChanged({2, 3}); -} - -TEST_F(ModifiedTimeChecker, IsNotUpToDateAnyMoreAfterUpdating) -{ - checker.isUpToDate(upToDateEntries); - ON_CALL(mockFileSystem, lastModified(Eq(1))).WillByDefault(Return(120)); - ON_CALL(mockFileSystem, lastModified(Eq(2))).WillByDefault(Return(30)); - - checker.pathsChanged({1, 2, 3}); - - ASSERT_FALSE(checker.isUpToDate(upToDateEntries)); -} - -} // namespace diff --git a/tests/unit/unittest/nativefilepath-test.cpp b/tests/unit/unittest/nativefilepath-test.cpp deleted file mode 100644 index 327cff42dc6..00000000000 --- a/tests/unit/unittest/nativefilepath-test.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include -#include - -namespace { - -Utils::PathString native(Utils::PathString path) -{ - if (Utils::HostOsInfo::isWindowsHost()) - path.replace('/', '\\'); - - return path; -} - -TEST(NativeFilePath, CreateFromPathString) -{ - ClangBackEnd::NativeFilePath filePath{native("/file/pathOne")}; - - ASSERT_THAT(filePath.directory(), native("/file")); - ASSERT_THAT(filePath.name(), "pathOne"); -} - -TEST(NativeFilePath, CreateFromDirectoryAndFileName) -{ - ClangBackEnd::NativeFilePath filePath{Utils::PathString{native("/file")}, Utils::PathString{"pathOne"}}; - - ASSERT_THAT(filePath.directory(), native("/file")); - ASSERT_THAT(filePath.name(), "pathOne"); - ASSERT_THAT(filePath.path(), native("/file/pathOne")); -} - -TEST(NativeFilePath, CreateFromCString) -{ - ClangBackEnd::NativeFilePath filePath{"/file/pathOne"}; - if (Utils::HostOsInfo::isWindowsHost()) - filePath = ClangBackEnd::NativeFilePath{"\\file\\pathOne"}; - - ASSERT_THAT(filePath.directory(), native("/file")); - ASSERT_THAT(filePath.name(), "pathOne"); -} - -TEST(NativeFilePath, CreateFromFilePathView) -{ - ClangBackEnd::NativeFilePath filePath{ClangBackEnd::NativeFilePathView{native("/file/pathOne")}}; - - ASSERT_THAT(filePath.directory(), native("/file")); - ASSERT_THAT(filePath.name(), "pathOne"); -} - -TEST(NativeFilePath, CreateFromQString) -{ - ClangBackEnd::NativeFilePath filePath{QString{native("/file/pathOne")}}; - - ASSERT_THAT(filePath.directory(), native("/file")); - ASSERT_THAT(filePath.name(), "pathOne"); -} - -TEST(NativeFilePath, DefaultNativeFilePath) -{ - ClangBackEnd::NativeFilePath filePath; - - ASSERT_THAT(filePath.directory(), ""); - ASSERT_THAT(filePath.name(), ""); -} - -TEST(NativeFilePath, EmptyNativeFilePath) -{ - ClangBackEnd::NativeFilePath filePath{""}; - - ASSERT_THAT(filePath.directory(), ""); - ASSERT_THAT(filePath.name(), ""); -} - -} diff --git a/tests/unit/unittest/nativefilepathview-test.cpp b/tests/unit/unittest/nativefilepathview-test.cpp deleted file mode 100644 index 305fa80c4c7..00000000000 --- a/tests/unit/unittest/nativefilepathview-test.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include - -#include - -namespace { - -using ClangBackEnd::NativeFilePathView; - -Utils::PathString native(Utils::PathString path) -{ - if (Utils::HostOsInfo::isWindowsHost()) - path.replace('/', '\\'); - - return path; -} - -TEST(NativeFilePathView, FilePathSlashForEmptyPath) -{ - NativeFilePathView filePath(""); - - ASSERT_THAT(filePath.slashIndex(), -1); -} - -TEST(NativeFilePathView, FilePathSlashForSingleSlash) -{ - Utils::PathString nativePath = native("/"); - NativeFilePathView filePath(nativePath); - - ASSERT_THAT(filePath.slashIndex(), 0); -} - -TEST(NativeFilePathView, FilePathSlashForFileInRoot) -{ - Utils::PathString nativePath = native("/file.h"); - NativeFilePathView filePath(nativePath); - - ASSERT_THAT(filePath.slashIndex(), 0); -} - -TEST(NativeFilePathView, FilePathSlashForSomeLongerPath) -{ - Utils::PathString nativePath = native("/path/to/some/file.h"); - NativeFilePathView filePath(nativePath); - - ASSERT_THAT(filePath.slashIndex(), 13); -} - -TEST(NativeFilePathView, FilePathSlashForFileNameOnly) -{ - Utils::PathString nativePath = native("file.h"); - NativeFilePathView filePath(nativePath); - - ASSERT_THAT(filePath.slashIndex(), -1); -} - -TEST(NativeFilePathView, DirectoryPathForEmptyPath) -{ - NativeFilePathView filePath(""); - - ASSERT_THAT(filePath.directory(), ""); -} - -TEST(NativeFilePathView, DirectoryPathForSingleSlashPath) -{ - Utils::PathString nativePath = native("/"); - NativeFilePathView filePath(nativePath); - - ASSERT_THAT(filePath.directory(), ""); -} - -TEST(NativeFilePathView, DirectoryPathForLongerPath) -{ - Utils::PathString nativePath = native("/path/to/some/file.h"); - NativeFilePathView filePath(nativePath); - - ASSERT_THAT(filePath.directory(), native("/path/to/some")); -} - -TEST(NativeFilePathView, DirectoryPathForFileNameOnly) -{ - NativeFilePathView filePath{"file.h"}; - - ASSERT_THAT(filePath.directory(), IsEmpty()); -} - -TEST(NativeFilePathView, FileNameForEmptyPath) -{ - NativeFilePathView filePath(""); - - ASSERT_THAT(filePath.name(), ""); -} - -TEST(NativeFilePathView, FileNameForSingleSlashPath) -{ - Utils::PathString nativePath = native("/"); - NativeFilePathView filePath(nativePath); - - ASSERT_THAT(filePath.name(), ""); -} - -TEST(NativeFilePathView, FileNameForLongerPath) -{ - Utils::PathString nativePath = native("/path/to/some/file.h"); - NativeFilePathView filePath(nativePath); - - ASSERT_THAT(filePath.name(), "file.h"); -} - -TEST(NativeFilePathView, FileNameForFileNameOnly) -{ - NativeFilePathView filePath{"file.h"}; - - ASSERT_THAT(filePath.name(), "file.h"); -} - -} diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp deleted file mode 100644 index 04561a230b1..00000000000 --- a/tests/unit/unittest/pchcreator-test.cpp +++ /dev/null @@ -1,440 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "fakeprocess.h" -#include "filesystem-utilities.h" -#include "testenvironment.h" - -#include "mockbuilddependenciesstorage.h" -#include "mockclangpathwatcher.h" -#include "mockpchmanagerclient.h" -#include "testenvironment.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -namespace { - -using ClangBackEnd::FilePath; -using ClangBackEnd::FilePathId; -using ClangBackEnd::FilePathIds; -using ClangBackEnd::FilePathView; -using ClangBackEnd::GeneratedFiles; -using ClangBackEnd::IdPaths; -using ClangBackEnd::IncludeSearchPathType; -using ClangBackEnd::PchTask; -using ClangBackEnd::PrecompiledHeadersUpdatedMessage; -using ClangBackEnd::ProjectChunkId; -using ClangBackEnd::ProjectPartContainer; -using ClangBackEnd::ProjectPartPch; -using ClangBackEnd::SourceEntries; -using ClangBackEnd::SourceEntry; -using ClangBackEnd::SourceType; -using ClangBackEnd::V2::FileContainer; - -using Utils::PathString; -using Utils::SmallString; - -using UnitTests::EndsWith; - -MATCHER_P2(HasIdAndType, - sourceId, - sourceType, - std::string(negation ? "hasn't" : "has") - + PrintToString(ClangBackEnd::SourceEntry(sourceId, sourceType, -1))) -{ - const ClangBackEnd::SourceEntry &entry = arg; - return entry.sourceId == sourceId && entry.sourceType == sourceType; -} - -class PchCreator: public ::testing::Test -{ -protected: - PchCreator() - { - creator.setUnsavedFiles({generatedFile}); - pchTask1.preIncludeSearchPath = testEnvironment.preIncludeSearchPath(); - } - - ClangBackEnd::FilePathId id(ClangBackEnd::FilePathView path) - { - return filePathCache.filePathId(path); - } - - FilePathIds sorted(FilePathIds &&filePathIds) - { - std::sort(filePathIds.begin(), filePathIds.end()); - - return std::move(filePathIds); - } - -protected: - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer databaseInitializer{database}; - ClangBackEnd::FilePathCaching filePathCache{database}; - FilePath main1Path = TESTDATA_DIR "/builddependencycollector/project/main3.cpp"; - FilePath main2Path = TESTDATA_DIR "/builddependencycollector/project/main2.cpp"; - FilePath header1Path = TESTDATA_DIR "/builddependencycollector/project/header1.h"; - FilePath header2Path = TESTDATA_DIR "/builddependencycollector/project/header2.h"; - FilePath generatedFilePath = TESTDATA_DIR "/builddependencycollector/project/generated_file.h"; - TestEnvironment environment; - FileContainer generatedFile{generatedFilePath.clone(), id(generatedFilePath), "#pragma once", {}}; - NiceMock mockPchManagerClient; - NiceMock mockClangPathWatcher; - NiceMock mockBuildDependenciesStorage; - ClangBackEnd::PchCreator creator{environment, - filePathCache, - mockPchManagerClient, - mockClangPathWatcher, - mockBuildDependenciesStorage}; - PchTask pchTask1{ - 1, - sorted({id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h")}), - sorted({id(TESTDATA_DIR "/builddependencycollector/system/system1.h"), - id(TESTDATA_DIR "/builddependencycollector/system/system2.h"), - id(generatedFilePath)}), - sorted({id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h"), - id(generatedFilePath)}), - sorted({id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - id(TESTDATA_DIR "/builddependencycollector/project/header2.h"), - id(generatedFilePath)}), - sorted({id(main2Path), id(generatedFilePath)}), - {}, - {}, - {{TESTDATA_DIR "/builddependencycollector/system", 2, IncludeSearchPathType::BuiltIn}, - {TESTDATA_DIR "/builddependencycollector/external", 1, IncludeSearchPathType::System}}, - {{TESTDATA_DIR "/builddependencycollector/project", 1, IncludeSearchPathType::User}}, - }; - TestEnvironment testEnvironment; -}; -using PchCreatorSlowTest = PchCreator; -using PchCreatorVerySlowTest = PchCreator; - -TEST_F(PchCreator, CreateProjectPartPchFileContent) -{ - auto content = creator.generatePchIncludeFileContent(pchTask1.includes); - - ASSERT_THAT(std::string(content), - AllOf(HasSubstr("#include \"" TESTDATA_DIR "/builddependencycollector/project/header2.h\"\n"), - HasSubstr("#include \"" TESTDATA_DIR "/builddependencycollector/external/external1.h\"\n"), - HasSubstr("#include \"" TESTDATA_DIR "/builddependencycollector/external/external2.h\"\n"))); -} - -TEST_F(PchCreator, CreateProjectPartClangCompilerArguments) -{ - auto arguments = creator.generateClangCompilerArguments(std::move(pchTask1), "project.pch"); - - ASSERT_THAT(arguments, - ElementsAre("clang++", - "-w", - "-DNOMINMAX", - "-x", - "c++-header", - "-std=c++98", - "-nostdinc", - "-nostdinc++", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system"), - "-o", - "project.pch")); -} - -TEST_F(PchCreator, CreateProjectPartClangCompilerArgumentsWithSystemPch) -{ - pchTask1.systemPchPath = "system.pch"; - - auto arguments = creator.generateClangCompilerArguments(std::move(pchTask1), "project.pch"); - - ASSERT_THAT(arguments, - ElementsAre("clang++", - "-w", - "-DNOMINMAX", - "-x", - "c++-header", - "-std=c++98", - "-nostdinc", - "-nostdinc++", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath(TESTDATA_DIR "/builddependencycollector/project"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/external"), - "-isystem", - toNativePath(TESTDATA_DIR "/builddependencycollector/system"), - "-Xclang", - "-include-pch", - "-Xclang", - "system.pch", - "-o", - "project.pch")); -} - -TEST_F(PchCreatorVerySlowTest, ProjectPartPchsSendToPchManagerClient) -{ - creator.generatePch(std::move(pchTask1)); - - EXPECT_CALL(mockPchManagerClient, - precompiledHeadersUpdated( - Field(&ClangBackEnd::PrecompiledHeadersUpdatedMessage::projectPartIds, - ElementsAre(Eq(creator.projectPartPch().projectPartId))))); - - creator.doInMainThreadAfterFinished(); -} - -TEST_F(PchCreatorVerySlowTest, SourcesAreWatchedAfterSucess) -{ - creator.generatePch(std::move(pchTask1)); - - EXPECT_CALL( - mockClangPathWatcher, - updateIdPaths(UnorderedElementsAre( - AllOf(Field(&ClangBackEnd::IdPaths::id, ProjectChunkId{1, SourceType::Source}), - Field(&ClangBackEnd::IdPaths::filePathIds, UnorderedElementsAre(id(main2Path)))), - AllOf(Field(&ClangBackEnd::IdPaths::id, ProjectChunkId{1, SourceType::UserInclude}), - Field(&ClangBackEnd::IdPaths::filePathIds, - UnorderedElementsAre( - id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - id(TESTDATA_DIR "/builddependencycollector/project/header2.h")))), - AllOf(Field(&ClangBackEnd::IdPaths::id, ProjectChunkId{1, SourceType::ProjectInclude}), - Field(&ClangBackEnd::IdPaths::filePathIds, - UnorderedElementsAre( - id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h")))), - AllOf(Field(&ClangBackEnd::IdPaths::id, ProjectChunkId{1, SourceType::SystemInclude}), - Field(&ClangBackEnd::IdPaths::filePathIds, - UnorderedElementsAre( - id(TESTDATA_DIR "/builddependencycollector/system/system1.h"), - id(TESTDATA_DIR "/builddependencycollector/system/system2.h"))))))); - - creator.doInMainThreadAfterFinished(); -} - -TEST_F(PchCreatorVerySlowTest, SourcesAreWatchedAfterFail) -{ - pchTask1.systemIncludeSearchPaths = {}; - pchTask1.projectIncludeSearchPaths = {}; - creator.generatePch(std::move(pchTask1)); - - EXPECT_CALL( - mockClangPathWatcher, - updateIdPaths(UnorderedElementsAre( - AllOf(Field(&ClangBackEnd::IdPaths::id, ProjectChunkId{1, SourceType::Source}), - Field(&ClangBackEnd::IdPaths::filePathIds, UnorderedElementsAre(id(main2Path)))), - AllOf(Field(&ClangBackEnd::IdPaths::id, ProjectChunkId{1, SourceType::UserInclude}), - Field(&ClangBackEnd::IdPaths::filePathIds, - UnorderedElementsAre( - id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - id(TESTDATA_DIR "/builddependencycollector/project/header2.h")))), - AllOf(Field(&ClangBackEnd::IdPaths::id, ProjectChunkId{1, SourceType::ProjectInclude}), - Field(&ClangBackEnd::IdPaths::filePathIds, - UnorderedElementsAre( - id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h")))), - AllOf(Field(&ClangBackEnd::IdPaths::id, ProjectChunkId{1, SourceType::SystemInclude}), - Field(&ClangBackEnd::IdPaths::filePathIds, - UnorderedElementsAre( - id(TESTDATA_DIR "/builddependencycollector/system/system1.h"), - id(TESTDATA_DIR "/builddependencycollector/system/system2.h"))))))); - - creator.doInMainThreadAfterFinished(); -} - -TEST_F(PchCreatorVerySlowTest, PchCreationTimeStampsAreUpdated) -{ - creator.generatePch(std::move(pchTask1)); - - EXPECT_CALL(mockBuildDependenciesStorage, updatePchCreationTimeStamp(_, Eq(1))); - - creator.doInMainThreadAfterFinished(); -} - -TEST_F(PchCreator, DoNothingInTheMainThreadIfGenerateWasNotCalled) -{ - EXPECT_CALL(mockBuildDependenciesStorage, updatePchCreationTimeStamp(_, _)).Times(0); - EXPECT_CALL(mockClangPathWatcher, updateIdPaths(_)).Times(0); - EXPECT_CALL(mockPchManagerClient, precompiledHeadersUpdated(_)).Times(0); - - creator.doInMainThreadAfterFinished(); -} - -TEST_F(PchCreatorVerySlowTest, ProjectPartPchForCreatesPchForPchTask) -{ - creator.generatePch(std::move(pchTask1)); - - ASSERT_THAT(creator.projectPartPch(), - AllOf(Field(&ProjectPartPch::projectPartId, Eq(1)), - Field(&ProjectPartPch::pchPath, Not(IsEmpty())), - Field(&ProjectPartPch::lastModified, Not(Eq(-1))))); -} - -TEST_F(PchCreatorVerySlowTest, ProjectPartPchCleared) -{ - creator.generatePch(std::move(pchTask1)); - - creator.clear(); - - ASSERT_FALSE(creator.projectPartPch().isValid()); -} - -TEST_F(PchCreatorVerySlowTest, WatchedSystemIncludesCleared) -{ - creator.generatePch(std::move(pchTask1)); - - creator.clear(); - - ASSERT_THAT(creator.watchedSystemIncludes(), IsEmpty()); -} - -TEST_F(PchCreatorVerySlowTest, WatchedProjectIncludesCleared) -{ - creator.generatePch(std::move(pchTask1)); - - creator.clear(); - - ASSERT_THAT(creator.watchedProjectIncludes(), IsEmpty()); -} - -TEST_F(PchCreatorVerySlowTest, WatchedUserIncludesCleared) -{ - creator.generatePch(std::move(pchTask1)); - - creator.clear(); - - ASSERT_THAT(creator.watchedUserIncludes(), IsEmpty()); -} -TEST_F(PchCreatorVerySlowTest, WatchedSourcesCleared) -{ - creator.generatePch(std::move(pchTask1)); - - creator.clear(); - - ASSERT_THAT(creator.watchedSources(), IsEmpty()); -} -TEST_F(PchCreatorVerySlowTest, ClangToolCleared) -{ - creator.generatePch(std::move(pchTask1)); - - creator.clear(); - - ASSERT_TRUE(creator.clangTool().isClean()); -} - -TEST_F(PchCreatorVerySlowTest, DISABLED_FaultyProjectPartPchForCreatesFaultyPchForPchTask) -{ - PchTask faultyPchTask{ - 0, - {id(TESTDATA_DIR "/builddependencycollector/project/faulty.cpp")}, - {}, - {}, - {}, - {}, - {{"DEFINE", "1", 1}}, - {}, - {{TESTDATA_DIR "/builddependencycollector/external", 1, IncludeSearchPathType::System}}, - {{TESTDATA_DIR "/builddependencycollector/project", 1, IncludeSearchPathType::User}}}; - - creator.generatePch(std::move(faultyPchTask)); - - ASSERT_THAT(creator.projectPartPch(), - AllOf(Field(&ProjectPartPch::projectPartId, Eq(0)), - Field(&ProjectPartPch::pchPath, IsEmpty()), - Field(&ProjectPartPch::lastModified, Gt(0)))); -} - -TEST_F(PchCreatorSlowTest, NoIncludes) -{ - pchTask1.includes = {}; - - creator.generatePch(std::move(pchTask1)); - - ASSERT_THAT(creator.projectPartPch(), - AllOf(Field(&ProjectPartPch::projectPartId, Eq(pchTask1.projectPartId())), - Field(&ProjectPartPch::pchPath, IsEmpty()), - Field(&ProjectPartPch::lastModified, Gt(0)))); -} - -TEST_F(PchCreatorSlowTest, NoIncludesInTheMainThreadCalls) -{ - pchTask1.includes = {}; - creator.generatePch(std::move(pchTask1)); - EXPECT_CALL(mockPchManagerClient, - precompiledHeadersUpdated( - Field(&ClangBackEnd::PrecompiledHeadersUpdatedMessage::projectPartIds, - ElementsAre(Eq(creator.projectPartPch().projectPartId))))); - EXPECT_CALL( - mockClangPathWatcher, - updateIdPaths(UnorderedElementsAre( - AllOf(Field(&ClangBackEnd::IdPaths::id, ProjectChunkId{1, SourceType::Source}), - Field(&ClangBackEnd::IdPaths::filePathIds, UnorderedElementsAre(id(main2Path)))), - AllOf(Field(&ClangBackEnd::IdPaths::id, ProjectChunkId{1, SourceType::UserInclude}), - Field(&ClangBackEnd::IdPaths::filePathIds, - UnorderedElementsAre( - id(TESTDATA_DIR "/builddependencycollector/project/header1.h"), - id(TESTDATA_DIR "/builddependencycollector/project/header2.h")))), - AllOf(Field(&ClangBackEnd::IdPaths::id, ProjectChunkId{1, SourceType::ProjectInclude}), - Field(&ClangBackEnd::IdPaths::filePathIds, - UnorderedElementsAre( - id(TESTDATA_DIR "/builddependencycollector/external/external1.h"), - id(TESTDATA_DIR "/builddependencycollector/external/external2.h")))), - AllOf(Field(&ClangBackEnd::IdPaths::id, ProjectChunkId{1, SourceType::SystemInclude}), - Field(&ClangBackEnd::IdPaths::filePathIds, - UnorderedElementsAre( - id(TESTDATA_DIR "/builddependencycollector/system/system1.h"), - id(TESTDATA_DIR "/builddependencycollector/system/system2.h"))))))); - EXPECT_CALL(mockBuildDependenciesStorage, updatePchCreationTimeStamp(Gt(0), Eq(1))); - - creator.doInMainThreadAfterFinished(); -} - -TEST_F(PchCreatorVerySlowTest, GeneratedFile) -{ - creator.clear(); - - creator.setUnsavedFiles({generatedFile}); - - ASSERT_FALSE(creator.clangTool().isClean()); -} -} diff --git a/tests/unit/unittest/pchmanagerclient-test.cpp b/tests/unit/unittest/pchmanagerclient-test.cpp deleted file mode 100644 index 38b9757aa3a..00000000000 --- a/tests/unit/unittest/pchmanagerclient-test.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockpchmanagernotifier.h" -#include "mockpchmanagerserver.h" -#include "mockprecompiledheaderstorage.h" -#include "mockprogressmanager.h" -#include "mockprojectpartsstorage.h" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace { - -using ClangBackEnd::PrecompiledHeadersUpdatedMessage; - -class PchManagerClient : public ::testing::Test -{ -protected: - NiceMock mockPchCreationProgressManager; - NiceMock mockDependencyCreationProgressManager; - ClangPchManager::PchManagerClient client{mockPchCreationProgressManager, - mockDependencyCreationProgressManager}; - NiceMock mockPchManagerServer; - NiceMock mockProjectPartsStorage; - NiceMock mockPchManagerNotifier{client}; - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer initializer{database}; - ClangBackEnd::FilePathCaching filePathCache{database}; - ClangPchManager::ClangIndexingSettingsManager settingsManager; - ClangPchManager::PchManagerProjectUpdater projectUpdater{mockPchManagerServer, - client, - filePathCache, - mockProjectPartsStorage, - settingsManager}; - ClangBackEnd::ProjectPartId projectPartId{1}; - PrecompiledHeadersUpdatedMessage message{projectPartId}; - ClangBackEnd::ProjectPartId projectPartId2{2}; - PrecompiledHeadersUpdatedMessage message2{projectPartId2}; -}; - -TEST_F(PchManagerClient, NotifierAttached) -{ - MockPchManagerNotifier notifier(client); - - ASSERT_THAT(client.notifiers(), Contains(¬ifier)); -} - -TEST_F(PchManagerClient, NotifierDetached) -{ - MockPchManagerNotifier *notifierPointer = nullptr; - - { - MockPchManagerNotifier notifier(client); - notifierPointer = ¬ifier; - } - - ASSERT_THAT(client.notifiers(), Not(Contains(notifierPointer))); -} - -TEST_F(PchManagerClient, Update) -{ - EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderUpdated(projectPartId)); - - client.precompiledHeadersUpdated(message.clone()); -} - -TEST_F(PchManagerClient, Remove) -{ - EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderRemoved(projectPartId)).Times(2); - - projectUpdater.removeProjectParts({projectPartId, projectPartId}); -} - -TEST_F(PchManagerClient, SetPchCreationProgress) -{ - EXPECT_CALL(mockPchCreationProgressManager, setProgress(10, 20)); - - client.progress({ClangBackEnd::ProgressType::PrecompiledHeader, 10, 20}); -} - -TEST_F(PchManagerClient, SetDependencyCreationProgress) -{ - EXPECT_CALL(mockDependencyCreationProgressManager, setProgress(30, 40)); - - client.progress({ClangBackEnd::ProgressType::DependencyCreation, 30, 40}); -} -} // namespace diff --git a/tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp b/tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp deleted file mode 100644 index e468521a545..00000000000 --- a/tests/unit/unittest/pchmanagerclientserverinprocess-test.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockpchmanagerclient.h" -#include "mockpchmanagerserver.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -using ClangBackEnd::UpdateGeneratedFilesMessage; -using ClangBackEnd::UpdateProjectPartsMessage; -using ClangBackEnd::RemoveGeneratedFilesMessage; -using ClangBackEnd::RemoveProjectPartsMessage; -using ClangBackEnd::V2::FileContainer; -using ClangBackEnd::ProjectPartContainer; -using ClangBackEnd::PrecompiledHeadersUpdatedMessage; - -using ::testing::Args; -using ::testing::Property; -using ::testing::Eq; - -namespace { - -class PchManagerClientServerInProcess : public ::testing::Test -{ -protected: - PchManagerClientServerInProcess(); - - void SetUp(); - void TearDown(); - - void scheduleServerMessages(); - void scheduleClientMessages(); - -protected: - QBuffer buffer; - MockPchManagerClient mockPchManagerClient; - MockPchManagerServer mockPchManagerServer; - - ClangBackEnd::PchManagerServerProxy serverProxy; - ClangBackEnd::PchManagerClientProxy clientProxy; -}; - -TEST_F(PchManagerClientServerInProcess, SendEndMessage) -{ - EXPECT_CALL(mockPchManagerServer, end()); - - serverProxy.end(); - scheduleServerMessages(); -} - -TEST_F(PchManagerClientServerInProcess, SendAliveMessage) -{ - - EXPECT_CALL(mockPchManagerClient, alive()); - - clientProxy.alive(); - scheduleClientMessages(); -} - -TEST_F(PchManagerClientServerInProcess, SendUpdateProjectPartsMessage) -{ - ProjectPartContainer projectPart{1, - {"-x", "c++-header", "-Wno-pragma-once-outside-header"}, - {{"DEFINE", "1", 1}}, - {{"/includes", 1, ClangBackEnd::IncludeSearchPathType::BuiltIn}}, - {{"/project/includes", 1, ClangBackEnd::IncludeSearchPathType::User}}, - {{1, 1}}, - {{1, 2}}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::All}; - UpdateProjectPartsMessage message{{projectPart}, {"-m32"}}; - - EXPECT_CALL(mockPchManagerServer, updateProjectParts(message)); - - serverProxy.updateProjectParts(message.clone()); - scheduleServerMessages(); -} - -TEST_F(PchManagerClientServerInProcess, SendUpdateGeneratedFilesMessage) -{ - FileContainer fileContainer{{"/path/to/", "file"}, 1, "content", {}}; - UpdateGeneratedFilesMessage message{{fileContainer}}; - - EXPECT_CALL(mockPchManagerServer, updateGeneratedFiles(message)); - - serverProxy.updateGeneratedFiles(message.clone()); - scheduleServerMessages(); -} - -TEST_F(PchManagerClientServerInProcess, SendRemoveProjectPartsMessage) -{ - RemoveProjectPartsMessage message{{1, 2}}; - - EXPECT_CALL(mockPchManagerServer, removeProjectParts(message)); - - serverProxy.removeProjectParts(message.clone()); - scheduleServerMessages(); -} - -TEST_F(PchManagerClientServerInProcess, SendRemoveGeneratedFilesMessage) -{ - RemoveGeneratedFilesMessage message{{{"/path/to/", "file"}}}; - - EXPECT_CALL(mockPchManagerServer, removeGeneratedFiles(message)); - - serverProxy.removeGeneratedFiles(message.clone()); - scheduleServerMessages(); -} - -TEST_F(PchManagerClientServerInProcess, SendPrecompiledHeaderUpdatedMessage) -{ - PrecompiledHeadersUpdatedMessage message{1}; - - EXPECT_CALL(mockPchManagerClient, precompiledHeadersUpdated(message)); - - clientProxy.precompiledHeadersUpdated(message.clone()); - scheduleClientMessages(); -} - -TEST_F(PchManagerClientServerInProcess, SendProgressMessage) -{ - ClangBackEnd::ProgressMessage message{ClangBackEnd::ProgressType::PrecompiledHeader, 10, 50}; - - - EXPECT_CALL(mockPchManagerClient, progress(message)); - - clientProxy.progress(message.clone()); - scheduleClientMessages(); -} - -PchManagerClientServerInProcess::PchManagerClientServerInProcess() - : serverProxy(&mockPchManagerClient, &buffer), - clientProxy(&mockPchManagerServer, &buffer) -{ -} - -void PchManagerClientServerInProcess::SetUp() -{ - buffer.open(QIODevice::ReadWrite); -} - -void PchManagerClientServerInProcess::TearDown() -{ - buffer.close(); -} - -void PchManagerClientServerInProcess::scheduleServerMessages() -{ - buffer.seek(0); - clientProxy.readMessages(); - buffer.buffer().clear(); -} - -void PchManagerClientServerInProcess::scheduleClientMessages() -{ - buffer.seek(0); - serverProxy.readMessages(); - buffer.buffer().clear(); -} - -} diff --git a/tests/unit/unittest/pchmanagerserver-test.cpp b/tests/unit/unittest/pchmanagerserver-test.cpp deleted file mode 100644 index bf14b628b8d..00000000000 --- a/tests/unit/unittest/pchmanagerserver-test.cpp +++ /dev/null @@ -1,442 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockbuilddependenciesstorage.h" -#include "mockclangpathwatcher.h" -#include "mockfilepathcaching.h" -#include "mockgeneratedfiles.h" -#include "mockpchmanagerclient.h" -#include "mockpchtaskgenerator.h" -#include "mockprojectpartsmanager.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace { -using ClangBackEnd::FilePathId; -using ClangBackEnd::ProjectPartContainer; -using ClangBackEnd::ProjectPartContainers; -using ClangBackEnd::V2::FileContainer; -using ClangBackEnd::V2::FileContainers; -using Utils::PathString; -using Utils::SmallString; -using UpToDataProjectParts = ClangBackEnd::ProjectPartsManagerInterface::UpToDataProjectParts; - -class PchManagerServer : public ::testing::Test -{ - void SetUp() override - { - server.setClient(&mockPchManagerClient); - - ON_CALL(mockProjectPartsManager, update(projectParts)) - .WillByDefault(Return(UpToDataProjectParts{{}, projectParts, projectParts4})); - ON_CALL(mockGeneratedFiles, isValid()).WillByDefault(Return(true)); - } - - ClangBackEnd::FilePathId id(Utils::SmallStringView path) const - { - return filePathCache.filePathId(ClangBackEnd::FilePathView(path)); - } - -protected: - NiceMock mockPchTaskGenerator; - NiceMock mockClangPathWatcher; - NiceMock mockProjectPartsManager; - NiceMock mockGeneratedFiles; - NiceMock mockBuildDependenciesStorage; - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer initializer{database}; - ClangBackEnd::FilePathCaching filePathCache{database}; - NiceMock mockFilePathCache; - ClangBackEnd::PchManagerServer server{mockClangPathWatcher, - mockPchTaskGenerator, - mockProjectPartsManager, - mockGeneratedFiles, - mockBuildDependenciesStorage, - mockFilePathCache}; - NiceMock mockPchManagerClient; - ClangBackEnd::ProjectPartId projectPartId1{1}; - ClangBackEnd::ProjectPartId projectPartId2{2}; - ClangBackEnd::ProjectPartId projectPartId3{3}; - ClangBackEnd::ProjectPartId projectPartId4{4}; - ClangBackEnd::ProjectPartId projectPartId5{5}; - ClangBackEnd::ProjectPartId projectPartId6{6}; - PathString main1Path = TESTDATA_DIR "/BuildDependencyCollector_main3.cpp"; - PathString main2Path = TESTDATA_DIR "/BuildDependencyCollector_main2.cpp"; - PathString header1Path = TESTDATA_DIR "/BuildDependencyCollector_header1.h"; - PathString header2Path = TESTDATA_DIR "/BuildDependencyCollector_header2.h"; - ClangBackEnd::IdPaths idPath{{projectPartId1, ClangBackEnd::SourceType::Source}, {1, 2}}; - ProjectPartContainer projectPart1{ - projectPartId1, - {"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"}, - {{"DEFINE", "1", 1}}, - {{TESTDATA_DIR "/symbolscollector/include", 1, ClangBackEnd::IncludeSearchPathType::BuiltIn}}, - {{"/project/includes", 1, ClangBackEnd::IncludeSearchPathType::User}}, - {id(header1Path)}, - {id(main1Path)}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::All}; - ProjectPartContainer projectPart2{ - projectPartId2, - {"-x", "c++-header", "-Wno-pragma-once-outside-header"}, - {{"DEFINE", "1", 1}}, - {{"/includes", 1, ClangBackEnd::IncludeSearchPathType::BuiltIn}}, - {{TESTDATA_DIR "/builddependencycollector", 1, ClangBackEnd::IncludeSearchPathType::User}}, - {id(header2Path)}, - {id(main2Path)}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::All}; - ProjectPartContainer projectPart3{ - projectPartId3, - {"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"}, - {{"DEFINE", "1", 1}}, - {{"/includes", 1, ClangBackEnd::IncludeSearchPathType::BuiltIn}}, - {{"/project/includes", 1, ClangBackEnd::IncludeSearchPathType::User}}, - {id(header1Path)}, - {id(main1Path)}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::All}; - ProjectPartContainer projectPart4{ - projectPartId4, - {"-x", "c++-header", "-Wno-pragma-once-outside-header"}, - {{"DEFINE", "1", 1}}, - {{"/includes", 1, ClangBackEnd::IncludeSearchPathType::BuiltIn}}, - {{"/project/includes", 1, ClangBackEnd::IncludeSearchPathType::User}}, - {id(header2Path)}, - {id(main2Path)}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::All}; - ProjectPartContainer projectPart5{ - projectPartId5, - {"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"}, - {{"DEFINE", "1", 1}}, - {{"/includes", 1, ClangBackEnd::IncludeSearchPathType::BuiltIn}}, - {{"/project/includes", 1, ClangBackEnd::IncludeSearchPathType::User}}, - {id(header1Path)}, - {id(main1Path)}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::All}; - ProjectPartContainer projectPart6{ - projectPartId6, - {"-x", "c++-header", "-Wno-pragma-once-outside-header"}, - {{"DEFINE", "1", 1}}, - {{"/includes", 1, ClangBackEnd::IncludeSearchPathType::BuiltIn}}, - {{"/project/includes", 1, ClangBackEnd::IncludeSearchPathType::User}}, - {id(header2Path)}, - {id(main2Path)}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::All}; - std::vector projectParts{projectPart1, projectPart2}; - std::vector projectParts1{projectPart1}; - std::vector projectParts2{projectPart2}; - std::vector projectParts3{projectPart3}; - std::vector projectParts4{projectPart3, projectPart4}; - FileContainer generatedFile{{"/path/to/", "file"}, id("/path/to/file"), "content", {}}; - ClangBackEnd::UpdateProjectPartsMessage updateProjectPartsMessage{ - Utils::clone(projectParts), {"toolChainArgument"}}; - ClangBackEnd::RemoveProjectPartsMessage removeProjectPartsMessage{ - {projectPart1.projectPartId, projectPart2.projectPartId}}; -}; - -TEST_F(PchManagerServer, FilterProjectPartsAndSendThemToQueue) -{ - InSequence s; - - EXPECT_CALL(mockProjectPartsManager, update(updateProjectPartsMessage.projectsParts)) - .WillOnce(Return(UpToDataProjectParts{{}, projectParts2, projectParts4})); - EXPECT_CALL( - mockPchTaskGenerator, addProjectParts(Eq(projectParts2), ElementsAre("toolChainArgument"))); - EXPECT_CALL(mockPchTaskGenerator, - addNonSystemProjectParts(Eq(projectParts4), ElementsAre("toolChainArgument"))); - - server.updateProjectParts(updateProjectPartsMessage.clone()); -} - -TEST_F(PchManagerServer, UpdateGeneratedFilesCallsUpdate) -{ - ClangBackEnd::UpdateGeneratedFilesMessage updateGeneratedFilesMessage{{generatedFile}}; - - EXPECT_CALL(mockGeneratedFiles, update(updateGeneratedFilesMessage.generatedFiles)); - - server.updateGeneratedFiles(updateGeneratedFilesMessage.clone()); -} - -TEST_F(PchManagerServer, RemoveGeneratedFilesCallsRemove) -{ - ClangBackEnd::RemoveGeneratedFilesMessage removeGeneratedFilesMessage{{generatedFile.filePath}}; - - EXPECT_CALL(mockGeneratedFiles, remove(Utils::clone(removeGeneratedFilesMessage.generatedFiles))); - - server.removeGeneratedFiles(removeGeneratedFilesMessage.clone()); -} - -TEST_F(PchManagerServer, RemoveIncludesFromFileWatcher) -{ - EXPECT_CALL(mockClangPathWatcher, removeIds(removeProjectPartsMessage.projectsPartIds)); - - server.removeProjectParts(removeProjectPartsMessage.clone()); -} - -TEST_F(PchManagerServer, RemoveProjectPartsFromProjectParts) -{ - EXPECT_CALL(mockProjectPartsManager, remove(removeProjectPartsMessage.projectsPartIds)); - - server.removeProjectParts(removeProjectPartsMessage.clone()); -} - -TEST_F(PchManagerServer, SetPathWatcherNotifier) -{ - EXPECT_CALL(mockClangPathWatcher, setNotifier(_)); - - ClangBackEnd::PchManagerServer server{mockClangPathWatcher, - mockPchTaskGenerator, - mockProjectPartsManager, - mockGeneratedFiles, - mockBuildDependenciesStorage, - filePathCache}; -} - -TEST_F(PchManagerServer, UpdateProjectPartQueueByPathIds) -{ - InSequence s; - server.updateProjectParts(ClangBackEnd::UpdateProjectPartsMessage{ - {projectPart1, projectPart2, projectPart3, projectPart4, projectPart5, projectPart6}, - {"toolChainArgument"}}); - - EXPECT_CALL(mockProjectPartsManager, - projects(ElementsAre(projectPart1.projectPartId, projectPart2.projectPartId))) - .WillOnce( - Return(std::vector{{projectPart1, projectPart2}})); - EXPECT_CALL(mockPchTaskGenerator, - addProjectParts(ElementsAre(projectPart1, projectPart2), - ElementsAre("toolChainArgument"))); - EXPECT_CALL(mockProjectPartsManager, - projects(ElementsAre(projectPart4.projectPartId, projectPart5.projectPartId))) - .WillOnce( - Return(std::vector{{projectPart4, projectPart5}})); - EXPECT_CALL(mockPchTaskGenerator, - addNonSystemProjectParts(ElementsAre(projectPart4, projectPart5), - ElementsAre("toolChainArgument"))); - - server.pathsWithIdsChanged({{{projectPartId1, ClangBackEnd::SourceType::TopSystemInclude}, {}}, - {{projectPartId1, ClangBackEnd::SourceType::ProjectInclude}, {}}, - {{projectPartId1, ClangBackEnd::SourceType::UserInclude}, {}}, - {{projectPartId2, ClangBackEnd::SourceType::SystemInclude}, {}}, - {{projectPartId2, ClangBackEnd::SourceType::ProjectInclude}, {}}, - {{projectPartId3, ClangBackEnd::SourceType::UserInclude}, {}}, - {{projectPartId4, ClangBackEnd::SourceType::TopProjectInclude}, {}}, - {{projectPartId4, ClangBackEnd::SourceType::Source}, {}}, - {{projectPartId4, ClangBackEnd::SourceType::UserInclude}, {}}, - {{projectPartId5, ClangBackEnd::SourceType::ProjectInclude}, {}}, - {{projectPartId6, ClangBackEnd::SourceType::Source}, {}}}); -} - -TEST_F(PchManagerServer, DontUpdateProjectPartQueueByPathIdsIfItUserFile) -{ - server.updateProjectParts(ClangBackEnd::UpdateProjectPartsMessage{{projectPart1, projectPart2}, - {"toolChainArgument"}}); - - EXPECT_CALL(mockProjectPartsManager, projects(_)).Times(0); - EXPECT_CALL(mockPchTaskGenerator, addProjectParts(_, _)).Times(0); - EXPECT_CALL(mockPchTaskGenerator, addNonSystemProjectParts(_, _)).Times(0); - - server.pathsWithIdsChanged({{{projectPartId1, ClangBackEnd::SourceType::UserInclude}, {}}, - {{projectPartId2, ClangBackEnd::SourceType::Source}, {}}}); -} - -TEST_F(PchManagerServer, ShortcutPrecompiledHeaderGenerationForUserIncludesAndSources) -{ - EXPECT_CALL(mockPchManagerClient, - precompiledHeadersUpdated( - Field(&ClangBackEnd::PrecompiledHeadersUpdatedMessage::projectPartIds, - UnorderedElementsAre(projectPartId3, projectPartId6)))); - - server.pathsWithIdsChanged({{{projectPartId1, ClangBackEnd::SourceType::TopProjectInclude}, {}}, - {{projectPartId2, ClangBackEnd::SourceType::TopSystemInclude}, {}}, - {{projectPartId3, ClangBackEnd::SourceType::UserInclude}, {}}, - {{projectPartId4, ClangBackEnd::SourceType::ProjectInclude}, {}}, - {{projectPartId5, ClangBackEnd::SourceType::SystemInclude}, {}}, - {{projectPartId6, ClangBackEnd::SourceType::Source}, {}}}); -} -TEST_F(PchManagerServer, ResetTimeStampForChangedFilesInDatabase) -{ - EXPECT_CALL(mockBuildDependenciesStorage, - insertOrUpdateIndexingTimeStamps(ElementsAre(FilePathId{1}, FilePathId{3}, FilePathId{5}), - TypedEq(-1))); - - server.pathsChanged({1, 3, 5}); -} - -TEST_F(PchManagerServer, SetPchCreationProgress) -{ - EXPECT_CALL(mockPchManagerClient, - progress(AllOf(Field(&ClangBackEnd::ProgressMessage::progressType, - ClangBackEnd::ProgressType::PrecompiledHeader), - Field(&ClangBackEnd::ProgressMessage::progress, 20), - Field(&ClangBackEnd::ProgressMessage::total, 30)))); - - server.setPchCreationProgress(20, 30); -} - -TEST_F(PchManagerServer, SetDependencyCreationProgress) -{ - EXPECT_CALL(mockPchManagerClient, - progress(AllOf(Field(&ClangBackEnd::ProgressMessage::progressType, - ClangBackEnd::ProgressType::DependencyCreation), - Field(&ClangBackEnd::ProgressMessage::progress, 20), - Field(&ClangBackEnd::ProgressMessage::total, 30)))); - - server.setDependencyCreationProgress(20, 30); -} - -TEST_F(PchManagerServer, RemoveToolChainsArguments) -{ - server.updateProjectParts( - ClangBackEnd::UpdateProjectPartsMessage{{projectPart1}, {"toolChainArgument"}}); - - EXPECT_CALL(mockPchTaskGenerator, addProjectParts(_, _)).Times(0); - EXPECT_CALL(mockPchTaskGenerator, addNonSystemProjectParts(_, _)).Times(0); - server.removeProjectParts(removeProjectPartsMessage.clone()); - - server.pathsWithIdsChanged({{{projectPart1.projectPartId, ClangBackEnd::SourceType::Source}, {}}}); -} - -TEST_F(PchManagerServer, DontGeneratePchIfGeneratedFilesAreNotValid) -{ - InSequence s; - - EXPECT_CALL(mockProjectPartsManager, update(ElementsAre(projectPart1))) - .WillOnce(Return(UpToDataProjectParts{{}, {projectPart1}, {projectPart2}})); - EXPECT_CALL(mockGeneratedFiles, isValid()).WillOnce(Return(false)); - EXPECT_CALL(mockPchTaskGenerator, addProjectParts(_, _)).Times(0); - EXPECT_CALL(mockPchTaskGenerator, addNonSystemProjectParts(_, _)).Times(0); - EXPECT_CALL(mockProjectPartsManager, - updateDeferred(ElementsAre(projectPart1), ElementsAre(projectPart2))); - - server.updateProjectParts( - ClangBackEnd::UpdateProjectPartsMessage{{projectPart1}, {"toolChainArgument"}}); -} - -TEST_F(PchManagerServer, GeneratePchIfGeneratedFilesAreValid) -{ - InSequence s; - - EXPECT_CALL(mockProjectPartsManager, update(ElementsAre(projectPart1))) - .WillOnce(Return(UpToDataProjectParts{{}, {projectPart1}, {projectPart2}})); - EXPECT_CALL(mockGeneratedFiles, isValid()).WillOnce(Return(true)); - EXPECT_CALL(mockPchTaskGenerator, addProjectParts(_, _)); - EXPECT_CALL(mockPchTaskGenerator, addNonSystemProjectParts(_, _)); - EXPECT_CALL(mockProjectPartsManager, updateDeferred(_, _)).Times(0); - - server.updateProjectParts( - ClangBackEnd::UpdateProjectPartsMessage{{projectPart1}, {"toolChainArgument"}}); -} - -TEST_F(PchManagerServer, AfterUpdatingGeneratedFilesAreValidSoGeneratePchs) -{ - InSequence s; - ClangBackEnd::UpdateGeneratedFilesMessage updateGeneratedFilesMessage{{generatedFile}}; - ON_CALL(mockGeneratedFiles, isValid()).WillByDefault(Return(false)); - server.updateProjectParts(ClangBackEnd::UpdateProjectPartsMessage{{projectPart1, projectPart2}, - {"toolChainArgument"}}); - - EXPECT_CALL(mockGeneratedFiles, update(updateGeneratedFilesMessage.generatedFiles)); - EXPECT_CALL(mockGeneratedFiles, isValid()).WillOnce(Return(true)); - EXPECT_CALL(mockProjectPartsManager, deferredSystemUpdates()) - .WillOnce(Return(ClangBackEnd::ProjectPartContainers{projectPart1})); - EXPECT_CALL(mockPchTaskGenerator, - addProjectParts(ElementsAre(projectPart1), ElementsAre("toolChainArgument"))); - EXPECT_CALL(mockProjectPartsManager, deferredProjectUpdates()) - .WillOnce(Return(ClangBackEnd::ProjectPartContainers{projectPart2})); - EXPECT_CALL(mockPchTaskGenerator, - addNonSystemProjectParts(ElementsAre(projectPart2), ElementsAre("toolChainArgument"))); - - server.updateGeneratedFiles(updateGeneratedFilesMessage.clone()); -} - -TEST_F(PchManagerServer, AfterUpdatingGeneratedFilesAreStillInvalidSoNoPchsGeneration) -{ - InSequence s; - ClangBackEnd::UpdateGeneratedFilesMessage updateGeneratedFilesMessage{{generatedFile}}; - ON_CALL(mockGeneratedFiles, isValid()).WillByDefault(Return(false)); - server.updateProjectParts(ClangBackEnd::UpdateProjectPartsMessage{{projectPart1, projectPart2}, - {"toolChainArgument"}}); - - EXPECT_CALL(mockGeneratedFiles, update(updateGeneratedFilesMessage.generatedFiles)); - EXPECT_CALL(mockGeneratedFiles, isValid()).WillOnce(Return(false)); - EXPECT_CALL(mockProjectPartsManager, deferredSystemUpdates()).Times(0); - EXPECT_CALL(mockPchTaskGenerator, addProjectParts(_, _)).Times(0); - EXPECT_CALL(mockPchTaskGenerator, addNonSystemProjectParts(_, _)).Times(0); - - server.updateGeneratedFiles(updateGeneratedFilesMessage.clone()); -} - -TEST_F(PchManagerServer, SentUpToDateProjectPartIdsToClient) -{ - InSequence s; - - EXPECT_CALL(mockProjectPartsManager, update(updateProjectPartsMessage.projectsParts)) - .WillOnce(Return(UpToDataProjectParts{projectParts1, projectParts2, projectParts3})); - EXPECT_CALL(mockPchTaskGenerator, - addProjectParts(Eq(projectParts2), ElementsAre("toolChainArgument"))); - EXPECT_CALL(mockPchManagerClient, - precompiledHeadersUpdated( - Field(&ClangBackEnd::PrecompiledHeadersUpdatedMessage::projectPartIds, - ElementsAre(Eq(projectPart1.projectPartId))))); - - server.updateProjectParts(updateProjectPartsMessage.clone()); -} - -TEST_F(PchManagerServer, AddingIncludesToFileCacheForProjectUpdates) -{ - InSequence s; - - EXPECT_CALL(mockFilePathCache, populateIfEmpty()); - EXPECT_CALL(mockFilePathCache, - addFilePaths(AllOf( - Contains(Eq(TESTDATA_DIR "/symbolscollector/include/unmodified_header.h")), - Contains(Eq(TESTDATA_DIR "/symbolscollector/include/unmodified_header2.h")), - Contains(Eq(TESTDATA_DIR "/builddependencycollector/project/header2.h")), - Contains(Eq(TESTDATA_DIR "/builddependencycollector/external/external3.h"))))); - EXPECT_CALL(mockProjectPartsManager, update(_)); - - server.updateProjectParts(updateProjectPartsMessage.clone()); -} -} // namespace diff --git a/tests/unit/unittest/pchtaskgenerator-test.cpp b/tests/unit/unittest/pchtaskgenerator-test.cpp deleted file mode 100644 index 9dd2e09273a..00000000000 --- a/tests/unit/unittest/pchtaskgenerator-test.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockbuilddependenciesprovider.h" -#include "mockpchtaskqueue.h" -#include "mockpchtasksmerger.h" - -#include -#include - -namespace { - -using ClangBackEnd::BuildDependencies; -using ClangBackEnd::BuildDependency; -using ClangBackEnd::CompilerMacro; -using ClangBackEnd::FilePathId; -using ClangBackEnd::IncludeSearchPath; -using ClangBackEnd::IncludeSearchPathType; -using ClangBackEnd::PchTask; -using ClangBackEnd::PchTaskSet; -using ClangBackEnd::ProjectPartId; -using ClangBackEnd::SourceEntries; -using ClangBackEnd::SourceType; -using ClangBackEnd::UsedMacro; -using ClangBackEnd::UsedMacros; - -class PchTaskGenerator : public testing::Test -{ -protected: - NiceMock mockBuildDependenciesProvider; - NiceMock mockPchTaskMerger; - NiceMock mockPchTaskQueue; - NiceMock> mockProgressCounterCallback; - ClangBackEnd::ProgressCounter progressCounter{mockProgressCounterCallback.AsStdFunction()}; - ClangBackEnd::PchTaskGenerator generator{mockBuildDependenciesProvider, - mockPchTaskMerger, - progressCounter, - mockPchTaskQueue}; - ClangBackEnd::ProjectPartContainer projectPart1{ - 1, - {"--yi"}, - {{"YI", "1", 1}, - {"QI", "7", 1}, - {"ER", "2", 2}, - {"SAN", "3", 3}, - {"SE", "4", 4}, - {"BA", "8", 4}, - {"WU", "5", 5}, - {"LUI", "6", 6}, - {"JIU", "9", 9}, - {"SHI", "10", 10}}, - {IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System}, - IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn}, - IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System}}, - {IncludeSearchPath{"/to/path1", 1, IncludeSearchPathType::User}, - IncludeSearchPath{"/to/path2", 2, IncludeSearchPathType::User}}, - {{1, 1}}, - {{1, 2}}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::All}; - SourceEntries firstSources{{1, SourceType::ProjectInclude, 1}, - {2, SourceType::UserInclude, 1}, - {3, SourceType::TopProjectInclude, 1}, - {4, SourceType::SystemInclude, 1}, - {5, SourceType::TopSystemInclude, 1}, - {6, SourceType::Source, 1}}; - UsedMacros usedMacros{{"LIANG", 0},{"YI", 1}, {"ER", 2}, {"SAN", 3}, {"SE", 4}, {"WU", 5}}; - BuildDependency buildDependency{firstSources, usedMacros, {}, {}, {}}; -}; - -TEST_F(PchTaskGenerator, AddProjectParts) -{ - ON_CALL(mockBuildDependenciesProvider, create(_)).WillByDefault(Return(buildDependency)); - - EXPECT_CALL( - mockPchTaskMerger, - mergeTasks( - ElementsAre(AllOf( - Field(&PchTaskSet::system, - AllOf(Field(&PchTask::projectPartIds, ElementsAre(ProjectPartId{1})), - Field(&PchTask::includes, ElementsAre(5)), - Field(&PchTask::watchedSystemIncludes, IsEmpty()), - Field(&PchTask::watchedProjectIncludes, IsEmpty()), - Field(&PchTask::watchedUserIncludes, IsEmpty()), - Field(&PchTask::watchedUserSources, IsEmpty()), - Field(&PchTask::compilerMacros, - ElementsAre(CompilerMacro{"SE", "4", 4}, CompilerMacro{"WU", "5", 5})), - Field(&PchTask::systemIncludeSearchPaths, - ElementsAre( - IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System}, - IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn}, - IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System})), - Field(&PchTask::projectIncludeSearchPaths, IsEmpty()), - Field(&PchTask::toolChainArguments, ElementsAre("--yi")), - Field(&PchTask::language, Eq(Utils::Language::Cxx)), - Field(&PchTask::languageVersion, Eq(Utils::LanguageVersion::CXX11)), - Field(&PchTask::languageExtension, Eq(Utils::LanguageExtension::All)))), - AllOf(Field( - &PchTaskSet::project, - AllOf(Field(&PchTask::projectPartIds, ElementsAre(ProjectPartId{1})), - Field(&PchTask::includes, ElementsAre(3)), - Field(&PchTask::watchedSystemIncludes, ElementsAre(4, 5)), - Field(&PchTask::watchedProjectIncludes, ElementsAre(1, 3)), - Field(&PchTask::watchedUserIncludes, ElementsAre(2)), - Field(&PchTask::watchedUserSources, ElementsAre(6)), - Field(&PchTask::compilerMacros, - ElementsAre(CompilerMacro{"YI", "1", 1}, CompilerMacro{"SAN", "3", 3})), - Field(&PchTask::systemIncludeSearchPaths, - ElementsAre( - IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System}, - IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn}, - IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System})), - Field(&PchTask::projectIncludeSearchPaths, - ElementsAre( - IncludeSearchPath{"/to/path1", 1, IncludeSearchPathType::User}, - IncludeSearchPath{"/to/path2", 2, IncludeSearchPathType::User})), - Field(&PchTask::toolChainArguments, ElementsAre("--yi")), - Field(&PchTask::language, Eq(Utils::Language::Cxx)), - Field(&PchTask::languageVersion, Eq(Utils::LanguageVersion::CXX11)), - Field(&PchTask::languageExtension, Eq(Utils::LanguageExtension::All))))))), - ElementsAre(Eq("ToolChainArgument")))); - - generator.addProjectParts({projectPart1}, {"ToolChainArgument"}); -} - -TEST_F(PchTaskGenerator, AddNonSystemProjectParts) -{ - ON_CALL(mockBuildDependenciesProvider, create(_)).WillByDefault(Return(buildDependency)); - - EXPECT_CALL( - mockPchTaskQueue, - addProjectPchTasks(ElementsAre(AllOf( - Field(&PchTask::projectPartIds, ElementsAre(ProjectPartId{1})), - Field(&PchTask::includes, ElementsAre(3)), - Field(&PchTask::watchedSystemIncludes, ElementsAre(4, 5)), - Field(&PchTask::watchedProjectIncludes, ElementsAre(1, 3)), - Field(&PchTask::watchedUserIncludes, ElementsAre(2)), - Field(&PchTask::watchedUserSources, ElementsAre(6)), - Field(&PchTask::compilerMacros, - ElementsAre(CompilerMacro{"YI", "1", 1}, CompilerMacro{"SAN", "3", 3})), - Field(&PchTask::systemIncludeSearchPaths, - ElementsAre(IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System}, - IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn}, - IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System})), - Field(&PchTask::projectIncludeSearchPaths, - ElementsAre(IncludeSearchPath{"/to/path1", 1, IncludeSearchPathType::User}, - IncludeSearchPath{"/to/path2", 2, IncludeSearchPathType::User})), - Field(&PchTask::toolChainArguments, ElementsAre("--yi")), - Field(&PchTask::language, Eq(Utils::Language::Cxx)), - Field(&PchTask::languageVersion, Eq(Utils::LanguageVersion::CXX11)), - Field(&PchTask::languageExtension, Eq(Utils::LanguageExtension::All)))))); - - generator.addNonSystemProjectParts({projectPart1}, {"ToolChainArgument"}); -} - -TEST_F(PchTaskGenerator, ProgressCounter) -{ - ON_CALL(mockBuildDependenciesProvider, create(_)).WillByDefault(Return(buildDependency)); - - EXPECT_CALL(mockProgressCounterCallback, Call(0, 3)); - EXPECT_CALL(mockProgressCounterCallback, Call(1, 3)); - EXPECT_CALL(mockProgressCounterCallback, Call(2, 3)); - EXPECT_CALL(mockProgressCounterCallback, Call(3, 3)); - - generator.addProjectParts({projectPart1, projectPart1, projectPart1}, {"ToolChainArgument"}); -} - -TEST_F(PchTaskGenerator, RemoveProjectParts) -{ - ON_CALL(mockBuildDependenciesProvider, create(_)).WillByDefault(Return(buildDependency)); - - EXPECT_CALL(mockPchTaskMerger, removePchTasks(ElementsAre(ProjectPartId{1}, ProjectPartId{2}))); - - generator.removeProjectParts({1, 2}); -} - -} diff --git a/tests/unit/unittest/pchtaskqueue-test.cpp b/tests/unit/unittest/pchtaskqueue-test.cpp deleted file mode 100644 index 6a4a2211d89..00000000000 --- a/tests/unit/unittest/pchtaskqueue-test.cpp +++ /dev/null @@ -1,503 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockfilesystem.h" -#include "mockpchcreator.h" -#include "mockprecompiledheaderstorage.h" -#include "mocksqlitetransactionbackend.h" -#include "mocktaskscheduler.h" -#include "testenvironment.h" - -#include -#include -#include -#include -#include - -namespace { - -using ClangBackEnd::IncludeSearchPath; -using ClangBackEnd::IncludeSearchPaths; -using ClangBackEnd::IncludeSearchPathType; -using ClangBackEnd::PchTask; -using ClangBackEnd::SlotUsage; - -class PchTaskQueue : public testing::Test -{ -protected: - ClangBackEnd::FilePathId filePathId(Utils::SmallStringView path) - { - return filePathCache.filePathId(ClangBackEnd::FilePathView{path}); - } - - ClangBackEnd::FilePathIds filePathIds(const Utils::PathStringVector &paths) - { - return filePathCache.filePathIds(Utils::transform(paths, [](const Utils::PathString &path) { - return ClangBackEnd::FilePathView(path); - })); - } - -protected: - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer initializer{database}; - ClangBackEnd::FilePathCaching filePathCache{database}; - NiceMock> mockSytemPchTaskScheduler; - NiceMock> mockProjectPchTaskScheduler; - NiceMock mockPrecompiledHeaderStorage; - NiceMock mockFileSystem; - MockSqliteTransactionBackend mockSqliteTransactionBackend; - NiceMock> mockSetProgressCallback; - ClangBackEnd::ProgressCounter progressCounter{mockSetProgressCallback.AsStdFunction()}; - TestEnvironment testEnvironment; - ClangBackEnd::PchTaskQueue queue{mockSytemPchTaskScheduler, - mockProjectPchTaskScheduler, - progressCounter, - mockPrecompiledHeaderStorage, - mockSqliteTransactionBackend, - testEnvironment, - mockFileSystem, - filePathCache}; - IncludeSearchPaths systemIncludeSearchPaths{ - {"/includes", 1, IncludeSearchPathType::BuiltIn}, - {"/other/includes", 2, IncludeSearchPathType::System}}; - IncludeSearchPaths projectIncludeSearchPaths{ - {"/project/includes", 1, IncludeSearchPathType::User}, - {"/other/project/includes", 2, IncludeSearchPathType::User}}; - PchTask systemTask1{1, - {1, 2}, - {1, 2}, - {2, 3}, - {3, 4}, - {6, 7}, - {{"YI", "1", 1}, {"SAN", "3", 3}}, - {"--yi"}, - systemIncludeSearchPaths, - projectIncludeSearchPaths}; - PchTask systemTask2{2, - {1, 2}, - {1, 2}, - {2, 3}, - {3, 4}, - {6, 7}, - {{"YI", "1", 1}, {"SAN", "3", 3}}, - {"--yi"}, - systemIncludeSearchPaths, - projectIncludeSearchPaths}; - PchTask systemTask2b{2, - {3, 4}, - {3, 4}, - {5, 6}, - {4, 7}, - {8, 9}, - {{"YI", "1", 1}, {"SAN", "3", 3}}, - {"--yi"}, - systemIncludeSearchPaths, - projectIncludeSearchPaths}; - PchTask systemTask3{3, - {1, 2}, - {1, 2}, - {2, 3}, - {3, 4}, - {6, 7}, - {{"YI", "1", 1}, {"SAN", "3", 3}}, - {"--yi"}, - systemIncludeSearchPaths, - projectIncludeSearchPaths}; - PchTask projectTask1{1, - {11, 12}, - {11, 12}, - {12, 13}, - {13, 14}, - {16, 17}, - {{"SE", "4", 4}, {"WU", "5", 5}}, - {"--yi"}, - systemIncludeSearchPaths, - projectIncludeSearchPaths}; - PchTask projectTask2{2, - {11, 12}, - {11, 12}, - {12, 13}, - {13, 14}, - {16, 17}, - {{"SE", "4", 4}, {"WU", "5", 5}}, - {"--yi"}, - systemIncludeSearchPaths, - projectIncludeSearchPaths}; - PchTask projectTask2b{2, - {21, 22}, - {11, 12}, - {22, 23}, - {23, 24}, - {26, 27}, - {{"SE", "4", 4}, {"WU", "5", 5}}, - {"--yi"}, - systemIncludeSearchPaths, - projectIncludeSearchPaths}; - PchTask projectTask3{3, - {21, 22}, - {21, 22}, - {22, 23}, - {23, 24}, - {26, 27}, - {{"SE", "4", 4}, {"WU", "5", 5}}, - {"--yi"}, - systemIncludeSearchPaths, - projectIncludeSearchPaths}; - PchTask systemTask4{{1, 3}, - {1, 2}, - {1, 2}, - {2, 3}, - {3, 4}, - {5, 8}, - {{"YI", "1", 1}, {"SAN", "3", 3}}, - {"--yi"}, - systemIncludeSearchPaths, - projectIncludeSearchPaths}; -}; - -TEST_F(PchTaskQueue, AddProjectPchTask) -{ - queue.addProjectPchTasks({projectTask1}); - - queue.addProjectPchTasks({projectTask2}); - - ASSERT_THAT(queue.projectPchTasks(), ElementsAre(projectTask1, projectTask2)); -} - -TEST_F(PchTaskQueue, AddSystemPchTask) -{ - queue.addSystemPchTasks({systemTask1}); - - queue.addSystemPchTasks({systemTask2}); - - ASSERT_THAT(queue.systemPchTasks(), ElementsAre(systemTask1, systemTask2)); -} - -TEST_F(PchTaskQueue, AddProjectPchTasksCallsProcessEntriesForSystemTaskSchedulerIsNotBusy) -{ - InSequence s; - queue.addProjectPchTasks({projectTask1, projectTask2}); - - EXPECT_CALL(mockSytemPchTaskScheduler, slotUsage()).WillRepeatedly(Return(SlotUsage{2, 0})); - EXPECT_CALL(mockProjectPchTaskScheduler, slotUsage()).WillRepeatedly(Return(SlotUsage{2, 0})); - EXPECT_CALL(mockProjectPchTaskScheduler, addTasks(SizeIs(2))); - - queue.processEntries(); -} - -TEST_F(PchTaskQueue, AddProjectPchTasksCallsProcessEntriesForSystemTaskSchedulerIsBusy) -{ - InSequence s; - queue.addProjectPchTasks({projectTask1, projectTask2}); - - EXPECT_CALL(mockSytemPchTaskScheduler, slotUsage()).WillRepeatedly(Return(SlotUsage{2, 1})); - EXPECT_CALL(mockProjectPchTaskScheduler, slotUsage()).Times(0); - EXPECT_CALL(mockProjectPchTaskScheduler, addTasks(_)).Times(0); - - queue.processEntries(); -} - -TEST_F(PchTaskQueue, AddSystemPchTasksCallsProcessEntries) -{ - InSequence s; - queue.addSystemPchTasks({projectTask1, projectTask2}); - - EXPECT_CALL(mockSytemPchTaskScheduler, slotUsage()).WillRepeatedly(Return(SlotUsage{2, 0})); - EXPECT_CALL(mockSytemPchTaskScheduler, addTasks(SizeIs(2))); - EXPECT_CALL(mockSytemPchTaskScheduler, slotUsage()).WillRepeatedly(Return(SlotUsage{2, 1})); - EXPECT_CALL(mockProjectPchTaskScheduler, slotUsage()).Times(0); - EXPECT_CALL(mockProjectPchTaskScheduler, addTasks(_)).Times(0); - - queue.processEntries(); -} - -TEST_F(PchTaskQueue, AddProjectPchTasksCallsProgressCounter) -{ - queue.addProjectPchTasks({projectTask1, projectTask2}); - - EXPECT_CALL(mockSetProgressCallback, Call(0, 3)); - - queue.addProjectPchTasks({projectTask2b, projectTask3}); -} - -TEST_F(PchTaskQueue, AddSystemPchTasksCallsProgressCounter) -{ - queue.addSystemPchTasks({systemTask1, systemTask2}); - - EXPECT_CALL(mockSetProgressCallback, Call(0, 3)); - - queue.addSystemPchTasks({systemTask2b, systemTask3}); -} - -TEST_F(PchTaskQueue, AddPchCallsProgressCounter) -{ - queue.addSystemPchTasks({systemTask1, systemTask2}); - - EXPECT_CALL(mockSetProgressCallback, Call(0, 3)); - - queue.addSystemPchTasks({systemTask2b, systemTask3}); -} - -TEST_F(PchTaskQueue, ReplaceIdenticalProjectPchTasks) -{ - queue.addProjectPchTasks({projectTask1, projectTask2}); - - queue.addProjectPchTasks({projectTask1, projectTask2}); - - ASSERT_THAT(queue.projectPchTasks(), ElementsAre(projectTask1, projectTask2)); -} - -TEST_F(PchTaskQueue, ReplaceIdenticalSystemPchTasks) -{ - queue.addSystemPchTasks({systemTask1, systemTask2}); - - queue.addSystemPchTasks({systemTask1, systemTask2}); - - ASSERT_THAT(queue.systemPchTasks(), ElementsAre(systemTask1, systemTask2)); -} - -TEST_F(PchTaskQueue, ReplaceProjectPchTasksWithSameId) -{ - queue.addProjectPchTasks({projectTask1, projectTask2}); - - queue.addProjectPchTasks({projectTask1, projectTask2b, projectTask3}); - - ASSERT_THAT(queue.projectPchTasks(), ElementsAre(projectTask1, projectTask2b, projectTask3)); -} - -TEST_F(PchTaskQueue, ReplaceSystemPchTasksWithSameId) -{ - queue.addSystemPchTasks({systemTask1, systemTask2}); - - queue.addSystemPchTasks({systemTask1, systemTask2b, systemTask3}); - - ASSERT_THAT(queue.systemPchTasks(), ElementsAre(systemTask1, systemTask2b, systemTask3)); -} - -TEST_F(PchTaskQueue, RemoveProjectPchTasksByProjectPartId) -{ - queue.addProjectPchTasks({projectTask1, projectTask2, projectTask3}); - - queue.removePchTasks(projectTask2.projectPartIds); - - ASSERT_THAT(queue.projectPchTasks(), ElementsAre(projectTask1, projectTask3)); -} - -TEST_F(PchTaskQueue, DontRemoveSystemPchTasksByProjectPartId) -{ - queue.addSystemPchTasks({systemTask1, systemTask2, systemTask3}); - - queue.removePchTasks(systemTask2.projectPartIds); - - ASSERT_THAT(queue.systemPchTasks(), ElementsAre(systemTask1, systemTask2, systemTask3)); -} - -TEST_F(PchTaskQueue, RemovePchTasksCallsProgressCounter) -{ - queue.addSystemPchTasks({systemTask1, systemTask2, systemTask3}); - queue.addProjectPchTasks({projectTask1, projectTask2, projectTask3}); - - EXPECT_CALL(mockSetProgressCallback, Call(0, 5)); - - queue.removePchTasks(systemTask2.projectPartIds); -} - -TEST_F(PchTaskQueue, CreateProjectTasksSizeEqualsInputSize) -{ - auto tasks = queue.createProjectTasks({projectTask1, projectTask1}); - - ASSERT_THAT(tasks, SizeIs(2)); -} - -TEST_F(PchTaskQueue, CreateProjectTaskFromPchTask) -{ - InSequence s; - MockPchCreator mockPchCreator; - ClangBackEnd::ProjectPartPch projectPartPch{{}, "/path/to/pch", 99}; - auto tasks = queue.createProjectTasks({projectTask1}); - auto projectTask = projectTask1; - projectTask.systemPchPath = "/path/to/pch"; - projectTask.preIncludeSearchPath = testEnvironment.preIncludeSearchPath(); - - EXPECT_CALL(mockPrecompiledHeaderStorage, fetchSystemPrecompiledHeaderPath(Eq(1))) - .WillOnce(Return(ClangBackEnd::FilePath{"/path/to/pch"})); - EXPECT_CALL(mockPchCreator, generatePch(Eq(projectTask))); - EXPECT_CALL(mockPchCreator, projectPartPch()).WillOnce(ReturnRef(projectPartPch)); - EXPECT_CALL(mockPrecompiledHeaderStorage, - insertProjectPrecompiledHeader(Eq(1), Eq("/path/to/pch"), Eq(99))); - - tasks.front()(mockPchCreator); -} - -TEST_F(PchTaskQueue, DeleteProjectPchEntryInDatabaseIfNoPchIsGenerated) -{ - InSequence s; - MockPchCreator mockPchCreator; - ClangBackEnd::ProjectPartPch projectPartPch{{}, "", 34}; - auto tasks = queue.createProjectTasks({projectTask1}); - auto projectTask = projectTask1; - projectTask.systemPchPath = "/path/to/pch"; - projectTask.preIncludeSearchPath = testEnvironment.preIncludeSearchPath(); - - EXPECT_CALL(mockPrecompiledHeaderStorage, fetchSystemPrecompiledHeaderPath(Eq(1))) - .WillOnce(Return(ClangBackEnd::FilePath{"/path/to/pch"})); - EXPECT_CALL(mockPchCreator, generatePch(Eq(projectTask))); - EXPECT_CALL(mockPchCreator, projectPartPch()).WillOnce(ReturnRef(projectPartPch)); - EXPECT_CALL(mockPrecompiledHeaderStorage, deleteProjectPrecompiledHeader(Eq(1), Eq(34))); - - tasks.front()(mockPchCreator); -} - -TEST_F(PchTaskQueue, CreateSystemTasksSizeEqualsInputSize) -{ - auto tasks = queue.createSystemTasks({systemTask1, systemTask2}); - - ASSERT_THAT(tasks, SizeIs(2)); -} - -TEST_F(PchTaskQueue, CreateSystemTaskFromPchTask) -{ - InSequence s; - MockPchCreator mockPchCreator; - ClangBackEnd::ProjectPartPch projectPartPch{{}, "/path/to/pch", 99}; - auto tasks = queue.createSystemTasks({systemTask4}); - auto systemTask = systemTask4; - systemTask.preIncludeSearchPath = testEnvironment.preIncludeSearchPath(); - - EXPECT_CALL(mockPchCreator, generatePch(Eq(systemTask))); - EXPECT_CALL(mockPchCreator, projectPartPch()).WillOnce(ReturnRef(projectPartPch)); - EXPECT_CALL(mockPrecompiledHeaderStorage, - insertSystemPrecompiledHeaders(UnorderedElementsAre(1, 3), Eq("/path/to/pch"), Eq(99))); - - tasks.front()(mockPchCreator); -} - -TEST_F(PchTaskQueue, DeleteSystemPchEntryInDatabaseIfNoPchIsGenerated) -{ - InSequence s; - MockPchCreator mockPchCreator; - ClangBackEnd::ProjectPartPch projectPartPch{{}, "", 0}; - auto tasks = queue.createSystemTasks({systemTask4}); - auto systemTask = systemTask4; - systemTask.preIncludeSearchPath = testEnvironment.preIncludeSearchPath(); - - EXPECT_CALL(mockPchCreator, generatePch(Eq(systemTask))); - EXPECT_CALL(mockPchCreator, projectPartPch()).WillOnce(ReturnRef(projectPartPch)); - EXPECT_CALL(mockPrecompiledHeaderStorage, - deleteSystemPrecompiledHeaders(UnorderedElementsAre(1, 3))); - - tasks.front()(mockPchCreator); -} - -TEST_F(PchTaskQueue, DontDeleteUnusedPchsIfSystemTaskAreProcessed) -{ - QString pchsDirectory{testEnvironment.pchBuildDirectory()}; - ON_CALL(mockSytemPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 1})); - ON_CALL(mockProjectPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0})); - ON_CALL(mockFileSystem, directoryEntries(Eq(pchsDirectory))) - .WillByDefault(Return(filePathIds({"/tmp/foo", "/tmp/bar"}))); - ON_CALL(mockPrecompiledHeaderStorage, fetchAllPchPaths()) - .WillByDefault(Return(ClangBackEnd::FilePaths{"/tmp/foo", "/tmp/poo"})); - - EXPECT_CALL(mockFileSystem, remove(_)).Times(0); - - queue.processEntries(); -} - -TEST_F(PchTaskQueue, DontDeleteUnusedPchsIfProjectTaskAreProcessed) -{ - QString pchsDirectory{testEnvironment.pchBuildDirectory()}; - ON_CALL(mockSytemPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0})); - ON_CALL(mockProjectPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 1})); - ON_CALL(mockFileSystem, directoryEntries(Eq(pchsDirectory))) - .WillByDefault(Return(filePathIds({"/tmp/foo", "/tmp/bar"}))); - ON_CALL(mockPrecompiledHeaderStorage, fetchAllPchPaths()) - .WillByDefault(Return(ClangBackEnd::FilePaths{"/tmp/foo", "/tmp/poo"})); - - EXPECT_CALL(mockFileSystem, remove(_)).Times(0); - - queue.processEntries(); -} - -TEST_F(PchTaskQueue, DontDeleteUnusedPchsIfSystemTaskIsAdded) -{ - QString pchsDirectory{testEnvironment.pchBuildDirectory()}; - ON_CALL(mockSytemPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0})); - ON_CALL(mockProjectPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0})); - ON_CALL(mockFileSystem, directoryEntries(Eq(pchsDirectory))) - .WillByDefault(Return(filePathIds({"/tmp/foo", "/tmp/bar"}))); - ON_CALL(mockPrecompiledHeaderStorage, fetchAllPchPaths()) - .WillByDefault(Return(ClangBackEnd::FilePaths{"/tmp/foo", "/tmp/poo"})); - queue.addSystemPchTasks({systemTask1}); - - EXPECT_CALL(mockFileSystem, remove(_)).Times(0); - - queue.processEntries(); -} - -TEST_F(PchTaskQueue, DontDeleteUnusedPchsIfProjectTaskIsAdded) -{ - QString pchsDirectory{testEnvironment.pchBuildDirectory()}; - ON_CALL(mockSytemPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0})); - ON_CALL(mockProjectPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0})); - ON_CALL(mockFileSystem, directoryEntries(Eq(pchsDirectory))) - .WillByDefault(Return(filePathIds({"/tmp/foo", "/tmp/bar"}))); - ON_CALL(mockPrecompiledHeaderStorage, fetchAllPchPaths()) - .WillByDefault(Return(ClangBackEnd::FilePaths{"/tmp/foo", "/tmp/poo"})); - queue.addProjectPchTasks({projectTask1}); - - EXPECT_CALL(mockFileSystem, remove(_)).Times(0); - - queue.processEntries(); -} - -TEST_F(PchTaskQueue, DeleteUnusedPchs) -{ - QString pchsDirectory{testEnvironment.pchBuildDirectory()}; - ON_CALL(mockSytemPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0})); - ON_CALL(mockProjectPchTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0})); - ON_CALL(mockFileSystem, directoryEntries(Eq(pchsDirectory))) - .WillByDefault(Return(filePathIds({ - "/tmp/foo", - "/tmp/bar", - "/tmp/hoo", - "/tmp/too", - }))); - ON_CALL(mockPrecompiledHeaderStorage, fetchAllPchPaths()) - .WillByDefault(Return(ClangBackEnd::FilePaths{ - "/tmp/foo", - "/tmp/poo", - "/tmp/too", - })); - - EXPECT_CALL(mockFileSystem, - remove(UnorderedElementsAre(filePathId("/tmp/bar"), filePathId("/tmp/hoo")))); - - queue.processEntries(); -} - -} // namespace diff --git a/tests/unit/unittest/pchtasksmerger-test.cpp b/tests/unit/unittest/pchtasksmerger-test.cpp deleted file mode 100644 index a816a7f5cbd..00000000000 --- a/tests/unit/unittest/pchtasksmerger-test.cpp +++ /dev/null @@ -1,400 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockpchtaskqueue.h" - -#include - -namespace { - -using ClangBackEnd::CompilerMacro; -using ClangBackEnd::CompilerMacros; -using ClangBackEnd::IncludeSearchPath; -using ClangBackEnd::IncludeSearchPathType; -using ClangBackEnd::PchTask; -using ClangBackEnd::PchTaskSet; -using Merger = ClangBackEnd::PchTasksMerger; -using Id = ClangBackEnd::FilePathId; -class PchTasksMerger : public testing::Test -{ -protected: - PchTask clone(PchTask entry) const - { - // entry.toolChainArguments = toolChainArguments; - - return entry; - } - -protected: - NiceMock mockPchTaskQueue; - ClangBackEnd::PchTasksMerger merger{mockPchTaskQueue}; - PchTask systemTask1{1, - {1, 2}, - {}, - {}, - {}, - {}, - {{"YI", "1", 1}, {"SAN", "3", 3}}, - {"--yi"}, - {{"/system/path", 2, IncludeSearchPathType::System}, - {"/builtin/path2", 3, IncludeSearchPathType::BuiltIn}, - {"/framework/path", 1, IncludeSearchPathType::System}}, - {{"/to/path1", 1, IncludeSearchPathType::User}, - {"/to/path2", 2, IncludeSearchPathType::User}}}; - PchTask projectTask1{1, - {11, 12}, - {11, 12}, - {21, 22}, - {31, 32}, - {41, 42}, - {{"SE", "4", 4}, {"WU", "5", 5}}, - {"--yi"}, - {{"/system/path", 1, IncludeSearchPathType::System}, - {"/builtin/path", 2, IncludeSearchPathType::BuiltIn}}, - {{"/to/path1", 1, IncludeSearchPathType::User}, - {"/to/path2", 2, IncludeSearchPathType::User}}}; - PchTask systemTask2{2, - {11, 12}, - {}, - {}, - {}, - {}, - {{"SE", "4", 4}, {"WU", "5", 5}}, - {"--yi"}, - {{"/system/path", 2, IncludeSearchPathType::System}, - {"/builtin/path", 3, IncludeSearchPathType::BuiltIn}, - {"/framework/path", 1, IncludeSearchPathType::System}}, - {{"/to/path1", 1, IncludeSearchPathType::User}, - {"/to/path2", 2, IncludeSearchPathType::User}}}; - PchTask projectTask2{2, - {11, 12}, - {11, 12}, - {21, 22}, - {31, 32}, - {41, 42}, - {{"SE", "4", 4}, {"WU", "5", 5}}, - {"--yi"}, - {{"/system/path", 2, IncludeSearchPathType::System}, - {"/builtin/path", 3, IncludeSearchPathType::BuiltIn}, - {"/framework/path", 1, IncludeSearchPathType::System}}, - {{"/to/path1", 1, IncludeSearchPathType::User}, - {"/to/path2", 2, IncludeSearchPathType::User}}}; - PchTask systemTask3{3, - {1, 2}, - {}, - {}, - {}, - {}, - {{"YI", "2", 1}, {"SAN", "3", 3}}, - {"--yi"}, - {{"/system/path", 2, IncludeSearchPathType::System}, - {"/builtin/path", 3, IncludeSearchPathType::BuiltIn}, - {"/framework/path", 1, IncludeSearchPathType::System}}, - {{"/to/path1", 1, IncludeSearchPathType::User}, - {"/to/path2", 2, IncludeSearchPathType::User}}}; - Utils::SmallStringVector toolChainArguments = {"toolChainArguments"}; -}; - -TEST_F(PchTasksMerger, AddProjectTasks) -{ - InSequence s; - - EXPECT_CALL(mockPchTaskQueue, addProjectPchTasks(ElementsAre(projectTask1, projectTask2))); - EXPECT_CALL(mockPchTaskQueue, processEntries()); - - merger.mergeTasks({{clone(systemTask1), clone(projectTask1)}, - {clone(systemTask1), clone(projectTask2)}}, - std::move(toolChainArguments)); -} - -TEST_F(PchTasksMerger, AddSystemTasks) -{ - InSequence s; - - EXPECT_CALL(mockPchTaskQueue, addSystemPchTasks(ElementsAre(_, systemTask3))); - EXPECT_CALL(mockPchTaskQueue, processEntries()); - - merger.mergeTasks({{clone(systemTask1), clone(projectTask1)}, - {clone(systemTask2), clone(projectTask2)}, - {clone(systemTask3), clone(projectTask2)}}, - std::move(toolChainArguments)); -} - -TEST_F(PchTasksMerger, AddSystemOnlyOneTask) -{ - InSequence s; - - EXPECT_CALL(mockPchTaskQueue, addSystemPchTasks(ElementsAre(systemTask1))); - EXPECT_CALL(mockPchTaskQueue, processEntries()); - - merger.mergeTasks({{clone(systemTask1), clone(projectTask1)}}, - std::move(toolChainArguments)); -} - -TEST_F(PchTasksMerger, RemoveTasks) -{ - EXPECT_CALL(mockPchTaskQueue, removePchTasks(ElementsAre(1, 2))); - - merger.removePchTasks({1, 2}); -} - -TEST_F(PchTasksMerger, MergeMacros) -{ - CompilerMacros compilerMacros1{{"ER", "2", 2}, {"SE", "4", 1}, {"YI"}, {"SAN", "3", 3}}; - CompilerMacros compilerMacros2{{"BA"}, {"ER", "2", 2}, {"YI", "1", 1}, {"SAN", "3", 3}}; - - auto macros = Merger::mergeMacros(compilerMacros1, compilerMacros2); - - ASSERT_THAT(macros, - ElementsAre(CompilerMacro{"BA"}, - CompilerMacro{"ER", "2", 2}, - CompilerMacro{"SE", "4", 1}, - CompilerMacro{"YI", "1", 1}, - CompilerMacro{"YI"}, - CompilerMacro{"SAN", "3", 3})); -} - -TEST_F(PchTasksMerger, MacrosCanBeMerged) -{ - CompilerMacros compilerMacros1{{"ER", "2", 2}, {"QI"}, {"SE", "4", 1}, {"SAN", "3", 3}}; - CompilerMacros compilerMacros2{{"BA"}, {"ER", "2", 2}, {"YI", "1", 1}, {"SAN", "3", 3}}; - - auto canBeMerged = !Merger::hasDuplicates(Merger::mergeMacros(compilerMacros1, compilerMacros2)); - - ASSERT_TRUE(canBeMerged); -} - -TEST_F(PchTasksMerger, MacrosCannotBeMergedBecauseDifferentValue) -{ - CompilerMacros compilerMacros1{{"ER", "2", 2}, {"SE", "4", 1}, {"SAN", "3", 3}}; - CompilerMacros compilerMacros2{{"ER", "1", 2}, {"YI", "1", 1}, {"SAN", "3", 3}}; - - auto canBeMerged = !Merger::hasDuplicates(Merger::mergeMacros(compilerMacros1, compilerMacros2)); - - ASSERT_FALSE(canBeMerged); -} - -TEST_F(PchTasksMerger, MacrosCannotBeMergedBecauseUndefinedMacro) -{ - CompilerMacros compilerMacros1{{"ER", "2", 2}, {"SE", "4", 1}, {"YI"}, {"SAN", "3", 3}}; - CompilerMacros compilerMacros2{{"ER", "2", 2}, {"YI", "1", 1}, {"SAN", "3", 3}}; - - auto canBeMerged = !Merger::hasDuplicates(Merger::mergeMacros(compilerMacros1, compilerMacros2)); - - ASSERT_FALSE(canBeMerged); -} - -TEST_F(PchTasksMerger, CanMergePchTasks) -{ - auto canBeMerged = Merger::mergePchTasks(systemTask1, systemTask2); - - ASSERT_TRUE(canBeMerged); -} - -TEST_F(PchTasksMerger, CannotMergePchTasks) -{ - auto canBeMerged = Merger::mergePchTasks(systemTask1, systemTask3); - - ASSERT_FALSE(canBeMerged); -} - -TEST_F(PchTasksMerger, IsMergedIsSet) -{ - Merger::mergePchTasks(systemTask1, systemTask2); - - ASSERT_TRUE(systemTask2.isMerged); -} - -TEST_F(PchTasksMerger, IsMergedIsNotSet) -{ - Merger::mergePchTasks(systemTask1, systemTask3); - - ASSERT_FALSE(systemTask3.isMerged); -} - -TEST_F(PchTasksMerger, DontMergeLanguage) -{ - systemTask2.language = Utils::Language::C; - - Merger::mergePchTasks(systemTask1, systemTask2); - - ASSERT_FALSE(systemTask2.isMerged); -} - -TEST_F(PchTasksMerger, MergeCompilerMacros) -{ - Merger::mergePchTasks(systemTask1, systemTask2); - - ASSERT_THAT(systemTask1.compilerMacros, - ElementsAre(CompilerMacro{"SE", "4", 4}, - CompilerMacro{"WU", "5", 5}, - CompilerMacro{"YI", "1", 1}, - CompilerMacro{"SAN", "3", 3})); -} - -TEST_F(PchTasksMerger, DontMergeCompilerMacros) -{ - Merger::mergePchTasks(systemTask1, systemTask3); - - ASSERT_THAT(systemTask1.compilerMacros, - ElementsAre(CompilerMacro{"YI", "1", 1}, CompilerMacro{"SAN", "3", 3})); -} - -TEST_F(PchTasksMerger, MergeIncludes) -{ - Merger::mergePchTasks(systemTask1, systemTask2); - - ASSERT_THAT(systemTask1.includes, ElementsAre(1, 2, 11, 12)); -} - -TEST_F(PchTasksMerger, DontMergeIncludes) -{ - Merger::mergePchTasks(systemTask1, systemTask3); - - ASSERT_THAT(systemTask1.includes, ElementsAre(1, 2)); -} - -TEST_F(PchTasksMerger, DontMergeWatchedSystemSources) -{ - Merger::mergePchTasks(systemTask1, systemTask2); - - ASSERT_THAT(systemTask1.watchedSystemIncludes, IsEmpty()); -} - -TEST_F(PchTasksMerger, DontMergeWatchedProjectSources) -{ - Merger::mergePchTasks(systemTask1, systemTask3); - - ASSERT_THAT(systemTask1.watchedProjectIncludes, IsEmpty()); -} - -TEST_F(PchTasksMerger, DontMergeWatchedUserSources) -{ - Merger::mergePchTasks(systemTask1, systemTask3); - - ASSERT_THAT(systemTask1.watchedUserSources, IsEmpty()); -} - -TEST_F(PchTasksMerger, MergeProjectIds) -{ - Merger::mergePchTasks(systemTask1, systemTask2); - - ASSERT_THAT(systemTask1.projectPartIds, ElementsAre(1, 2)); -} - -TEST_F(PchTasksMerger, DontMergeProjectIds) -{ - Merger::mergePchTasks(systemTask1, systemTask3); - - ASSERT_THAT(systemTask1.projectPartIds, ElementsAre(1)); -} - -TEST_F(PchTasksMerger, MergeIncludeSearchPaths) -{ - Merger::mergePchTasks(systemTask1, systemTask2); - - ASSERT_THAT(systemTask1.systemIncludeSearchPaths, - ElementsAre(IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System}, - IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn}, - IncludeSearchPath{"/builtin/path2", 3, IncludeSearchPathType::BuiltIn}, - IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System})); -} - -TEST_F(PchTasksMerger, DontMergeIncludeSearchPaths) -{ - Merger::mergePchTasks(systemTask1, systemTask3); - - ASSERT_THAT(systemTask1.systemIncludeSearchPaths, - ElementsAre(IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System}, - IncludeSearchPath{"/builtin/path2", 3, IncludeSearchPathType::BuiltIn}, - IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System})); -} - -TEST_F(PchTasksMerger, ChooseLanguageVersionFromFirstTask) -{ - systemTask2.languageVersion = Utils::LanguageVersion::CXX17; - - Merger::mergePchTasks(systemTask1, systemTask2); - - ASSERT_THAT(systemTask1.languageVersion, Utils::LanguageVersion::CXX17); -} - -TEST_F(PchTasksMerger, ChooseLanguageVersionFromSecondTask) -{ - systemTask1.languageVersion = Utils::LanguageVersion::CXX17; - - Merger::mergePchTasks(systemTask1, systemTask2); - - ASSERT_THAT(systemTask1.languageVersion, Utils::LanguageVersion::CXX17); -} - -TEST_F(PchTasksMerger, DontChooseLanguageVersion) -{ - systemTask3.languageVersion = Utils::LanguageVersion::CXX17; - - Merger::mergePchTasks(systemTask1, systemTask3); - - ASSERT_THAT(systemTask1.languageVersion, Utils::LanguageVersion::CXX98); -} - -TEST_F(PchTasksMerger, FirstTaskIsNotMergedAgain) -{ - systemTask1.isMerged = true; - - Merger::mergePchTasks(systemTask1, systemTask2); - - ASSERT_FALSE(systemTask2.isMerged); -} - -TEST_F(PchTasksMerger, DontMergeAlreadyMergedFirstTask) -{ - systemTask1.isMerged = true; - - bool isMerged = Merger::mergePchTasks(systemTask1, systemTask2); - - ASSERT_FALSE(isMerged); -} - -TEST_F(PchTasksMerger, SecondTaskIsNotMergedAgain) -{ - systemTask2.isMerged = true; - - Merger::mergePchTasks(systemTask1, systemTask2); - - ASSERT_THAT(systemTask1.includes, ElementsAre(1, 2)); -} - -TEST_F(PchTasksMerger, DontMergeAlreadyMergedSecondTask) -{ - systemTask2.isMerged = true; - - bool isMerged = Merger::mergePchTasks(systemTask1, systemTask2); - - ASSERT_FALSE(isMerged); -} - -} // namespace diff --git a/tests/unit/unittest/precompiledheaderstorage-test.cpp b/tests/unit/unittest/precompiledheaderstorage-test.cpp deleted file mode 100644 index d388f5fb437..00000000000 --- a/tests/unit/unittest/precompiledheaderstorage-test.cpp +++ /dev/null @@ -1,525 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" -#include "sqlitedatabasemock.h" - -#include -#include -#include -#include -#include -#include - -namespace { - -using Storage = ClangBackEnd::PrecompiledHeaderStorage>; -template -using ReadStatement = NiceMock::ReadStatement; -using WriteStatement = NiceMock::WriteStatement; - -class PrecompiledHeaderStorage : public testing::Test -{ -protected: - NiceMock database; - Storage storage{database}; - WriteStatement &insertProjectPrecompiledHeaderStatement = storage.insertProjectPrecompiledHeaderStatement; - WriteStatement &deleteProjectPrecompiledHeaderStatement = storage.deleteProjectPrecompiledHeaderStatement; - WriteStatement &deleteProjectPrecompiledHeaderPathAndSetBuildTimeStatement - = storage.deleteProjectPrecompiledHeaderPathAndSetBuildTimeStatement; - WriteStatement &insertSystemPrecompiledHeaderStatement = storage.insertSystemPrecompiledHeaderStatement; - WriteStatement &deleteSystemPrecompiledHeaderStatement = storage.deleteSystemPrecompiledHeaderStatement; - WriteStatement &deleteSystemAndProjectPrecompiledHeaderStatement = storage.deleteSystemAndProjectPrecompiledHeaderStatement; - ReadStatement<1> &fetchSystemPrecompiledHeaderPathStatement = storage.fetchSystemPrecompiledHeaderPathStatement; - ReadStatement<1> &fetchPrecompiledHeaderStatement = storage.fetchPrecompiledHeaderStatement; - ReadStatement<2> &fetchPrecompiledHeadersStatement = storage.fetchPrecompiledHeadersStatement; - ReadStatement<2> &fetchTimeStampsStatement = storage.fetchTimeStampsStatement; - ReadStatement<1> &fetchAllPchPathsStatement = storage.fetchAllPchPathsStatement; -}; - -TEST_F(PrecompiledHeaderStorage, UseTransaction) -{ - InSequence s; - - EXPECT_CALL(database, immediateBegin()); - EXPECT_CALL(database, commit()); - - Storage storage{database}; -} - -TEST_F(PrecompiledHeaderStorage, InsertProjectPrecompiledHeader) -{ - InSequence s; - - EXPECT_CALL(database, immediateBegin()); - EXPECT_CALL(insertProjectPrecompiledHeaderStatement, - write(TypedEq(1), - TypedEq("/path/to/pch"), - TypedEq(22))); - EXPECT_CALL(database, commit()); - - storage.insertProjectPrecompiledHeader(1, "/path/to/pch", 22); -} - -TEST_F(PrecompiledHeaderStorage, InsertProjectPrecompiledHeaderStatementIsBusy) -{ - InSequence s; - - EXPECT_CALL(database, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(database, immediateBegin()); - EXPECT_CALL(insertProjectPrecompiledHeaderStatement, - write(TypedEq(1), - TypedEq("/path/to/pch"), - TypedEq(22))); - EXPECT_CALL(database, commit()); - - storage.insertProjectPrecompiledHeader(1, "/path/to/pch", 22); -} - -TEST_F(PrecompiledHeaderStorage, DeleteProjectPrecompiledHeader) -{ - InSequence s; - - EXPECT_CALL(database, immediateBegin()); - EXPECT_CALL(deleteProjectPrecompiledHeaderPathAndSetBuildTimeStatement, - write(TypedEq(1), TypedEq(13))); - EXPECT_CALL(database, commit()); - - storage.deleteProjectPrecompiledHeader(1, 13); -} - -TEST_F(PrecompiledHeaderStorage, DeleteProjectPrecompiledHeaderStatementIsBusy) -{ - InSequence s; - - EXPECT_CALL(database, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(database, immediateBegin()); - EXPECT_CALL(deleteProjectPrecompiledHeaderPathAndSetBuildTimeStatement, - write(TypedEq(1), TypedEq(13))); - EXPECT_CALL(database, commit()); - - storage.deleteProjectPrecompiledHeader(1, 13); -} - -TEST_F(PrecompiledHeaderStorage, DeleteProjectPrecompiledHeaders) -{ - InSequence s; - - EXPECT_CALL(database, immediateBegin()); - EXPECT_CALL(deleteProjectPrecompiledHeaderStatement, write(TypedEq(1))); - EXPECT_CALL(deleteProjectPrecompiledHeaderStatement, write(TypedEq(2))); - EXPECT_CALL(database, commit()); - - storage.deleteProjectPrecompiledHeaders({1, 2}); -} - -TEST_F(PrecompiledHeaderStorage, DeleteProjectPrecompiledHeadersStatementIsBusy) -{ - InSequence s; - - EXPECT_CALL(database, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(database, immediateBegin()); - EXPECT_CALL(deleteProjectPrecompiledHeaderStatement, write(TypedEq(1))); - EXPECT_CALL(deleteProjectPrecompiledHeaderStatement, write(TypedEq(2))); - EXPECT_CALL(database, commit()); - - storage.deleteProjectPrecompiledHeaders({1, 2}); -} - -TEST_F(PrecompiledHeaderStorage, InsertSystemPrecompiledHeaders) -{ - InSequence s; - - EXPECT_CALL(database, immediateBegin()); - EXPECT_CALL(insertSystemPrecompiledHeaderStatement, - write(TypedEq(1), - TypedEq("/path/to/pch"), - TypedEq(22))); - EXPECT_CALL(insertSystemPrecompiledHeaderStatement, - write(TypedEq(2), - TypedEq("/path/to/pch"), - TypedEq(22))); - EXPECT_CALL(database, commit()); - - storage.insertSystemPrecompiledHeaders({1, 2}, "/path/to/pch", 22); -} - -TEST_F(PrecompiledHeaderStorage, InsertSystemPrecompiledHeadersStatementIsBusy) -{ - InSequence s; - - EXPECT_CALL(database, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(database, immediateBegin()); - EXPECT_CALL(insertSystemPrecompiledHeaderStatement, - write(TypedEq(1), - TypedEq("/path/to/pch"), - TypedEq(22))); - EXPECT_CALL(insertSystemPrecompiledHeaderStatement, - write(TypedEq(2), - TypedEq("/path/to/pch"), - TypedEq(22))); - EXPECT_CALL(database, commit()); - - storage.insertSystemPrecompiledHeaders({1, 2}, "/path/to/pch", 22); -} - -TEST_F(PrecompiledHeaderStorage, DeleteSystemPrecompiledHeaders) -{ - InSequence s; - - EXPECT_CALL(database, immediateBegin()); - EXPECT_CALL(deleteSystemPrecompiledHeaderStatement, write(TypedEq(1))); - EXPECT_CALL(deleteSystemPrecompiledHeaderStatement, write(TypedEq(2))); - EXPECT_CALL(database, commit()); - - storage.deleteSystemPrecompiledHeaders({1, 2}); -} - -TEST_F(PrecompiledHeaderStorage, DeleteSystemPrecompiledHeadersStatementIsBusy) -{ - InSequence s; - - EXPECT_CALL(database, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(database, immediateBegin()); - EXPECT_CALL(deleteSystemPrecompiledHeaderStatement, write(TypedEq(1))); - EXPECT_CALL(deleteSystemPrecompiledHeaderStatement, write(TypedEq(2))); - EXPECT_CALL(database, commit()); - - storage.deleteSystemPrecompiledHeaders({1, 2}); -} - -TEST_F(PrecompiledHeaderStorage, DeleteSystemAndProjectPrecompiledHeaders) -{ - InSequence s; - - EXPECT_CALL(database, immediateBegin()); - EXPECT_CALL(deleteSystemAndProjectPrecompiledHeaderStatement, write(TypedEq(1))); - EXPECT_CALL(deleteSystemAndProjectPrecompiledHeaderStatement, write(TypedEq(2))); - EXPECT_CALL(database, commit()); - - storage.deleteSystemAndProjectPrecompiledHeaders({1, 2}); -} - -TEST_F(PrecompiledHeaderStorage, DeleteSystemAndProjectPrecompiledHeadersStatementIsBusy) -{ - InSequence s; - - EXPECT_CALL(database, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(database, immediateBegin()); - EXPECT_CALL(deleteSystemAndProjectPrecompiledHeaderStatement, write(TypedEq(1))); - EXPECT_CALL(deleteSystemAndProjectPrecompiledHeaderStatement, write(TypedEq(2))); - EXPECT_CALL(database, commit()); - - storage.deleteSystemAndProjectPrecompiledHeaders({1, 2}); -} - -TEST_F(PrecompiledHeaderStorage, CompilePrecompiledHeaderStatements) -{ - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer initializer{database}; - - ASSERT_NO_THROW(ClangBackEnd::PrecompiledHeaderStorage<>{database}); -} - -TEST_F(PrecompiledHeaderStorage, FetchSystemPrecompiledHeaderCalls) -{ - InSequence s; - - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchSystemPrecompiledHeaderPathStatement, valueReturnFilePath(TypedEq(1))); - EXPECT_CALL(database, commit()); - - storage.fetchSystemPrecompiledHeaderPath(1); -} - -TEST_F(PrecompiledHeaderStorage, FetchSystemPrecompiledHeaderCallsWithReturnValue) -{ - InSequence s; - - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchSystemPrecompiledHeaderPathStatement, valueReturnFilePath(TypedEq(1))) - .WillOnce(Return(ClangBackEnd::FilePath{})); - EXPECT_CALL(database, commit()); - - storage.fetchSystemPrecompiledHeaderPath(1); -} - -TEST_F(PrecompiledHeaderStorage, FetchSystemPrecompiledHeader) -{ - EXPECT_CALL(fetchSystemPrecompiledHeaderPathStatement, valueReturnFilePath(TypedEq(1))) - .WillOnce(Return(ClangBackEnd::FilePath{"/path/to/pch"})); - - auto path = storage.fetchSystemPrecompiledHeaderPath(1); - - ASSERT_THAT(path, "/path/to/pch"); -} - -TEST_F(PrecompiledHeaderStorage, FetchSystemPrecompiledHeaderReturnsEmptyPath) -{ - EXPECT_CALL(fetchSystemPrecompiledHeaderPathStatement, valueReturnFilePath(TypedEq(1))) - .WillOnce(Return(ClangBackEnd::FilePath{})); - - auto path = storage.fetchSystemPrecompiledHeaderPath(1); - - ASSERT_THAT(path, IsEmpty()); -} - -TEST_F(PrecompiledHeaderStorage, FetchSystemPrecompiledHeaderReturnsNullOptional) -{ - EXPECT_CALL(fetchSystemPrecompiledHeaderPathStatement, valueReturnFilePath(TypedEq(1))) - .WillOnce(Return(Utils::optional{})); - - auto path = storage.fetchSystemPrecompiledHeaderPath(1); - - ASSERT_THAT(path, IsEmpty()); -} - -TEST_F(PrecompiledHeaderStorage, FetchPrecompiledHeaderCallsValueInStatement) -{ - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchPrecompiledHeaderStatement, valueReturnFilePath(Eq(25))); - EXPECT_CALL(database, commit()); - - storage.fetchPrecompiledHeader(25); -} - -TEST_F(PrecompiledHeaderStorage, FetchPrecompiledHeaderCallsWithValue) -{ - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchPrecompiledHeaderStatement, valueReturnFilePath(Eq(25))) - .WillOnce(Return(ClangBackEnd::FilePath{})); - EXPECT_CALL(database, commit()); - - storage.fetchPrecompiledHeader(25); -} - -TEST_F(PrecompiledHeaderStorage, FetchPrecompiledHeaderIsBusy) -{ - InSequence s; - - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchPrecompiledHeaderStatement, valueReturnFilePath(Eq(25))) - .WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(database, rollback()); - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchPrecompiledHeaderStatement, valueReturnFilePath(Eq(25))); - EXPECT_CALL(database, commit()); - - storage.fetchPrecompiledHeader(25); -} - -TEST_F(PrecompiledHeaderStorage, FetchPrecompiledHeader) -{ - ClangBackEnd::FilePath pchFilePath{"/path/to/pch"}; - ON_CALL(fetchPrecompiledHeaderStatement, valueReturnFilePath(Eq(25))) - .WillByDefault(Return(pchFilePath)); - - auto path = storage.fetchPrecompiledHeader(25); - - ASSERT_THAT(path, Eq(pchFilePath)); -} - -TEST_F(PrecompiledHeaderStorage, FetchEmptyPrecompiledHeader) -{ - auto path = storage.fetchPrecompiledHeader(25); - - ASSERT_THAT(path, IsEmpty()); -} - -TEST_F(PrecompiledHeaderStorage, FetchPrecompiledHeaderCalls) -{ - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchPrecompiledHeadersStatement, valueReturnPchPaths(Eq(25))); - EXPECT_CALL(database, commit()); - - storage.fetchPrecompiledHeaders(25); -} - -TEST_F(PrecompiledHeaderStorage, FetchPrecompiledHeaderCallsWithReturnValue) -{ - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchPrecompiledHeadersStatement, valueReturnPchPaths(Eq(25))) - .WillOnce(Return(ClangBackEnd::PchPaths{})); - EXPECT_CALL(database, commit()); - - storage.fetchPrecompiledHeaders(25); -} - -TEST_F(PrecompiledHeaderStorage, FetchPrecompiledHeadersIsBusy) -{ - InSequence s; - - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchPrecompiledHeadersStatement, valueReturnPchPaths(Eq(25))) - .WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(database, rollback()); - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchPrecompiledHeadersStatement, valueReturnPchPaths(Eq(25))); - EXPECT_CALL(database, commit()); - - storage.fetchPrecompiledHeaders(25); -} - -TEST_F(PrecompiledHeaderStorage, FetchPrecompiledHeaders) -{ - ClangBackEnd::PchPaths pchFilePaths{"/project/pch", "/system/pch"}; - ON_CALL(fetchPrecompiledHeadersStatement, valueReturnPchPaths(Eq(25))) - .WillByDefault(Return(pchFilePaths)); - - auto paths = storage.fetchPrecompiledHeaders(25); - - ASSERT_THAT(paths, Eq(pchFilePaths)); -} - -TEST_F(PrecompiledHeaderStorage, FetchEmptyPrecompiledHeaders) -{ - auto paths = storage.fetchPrecompiledHeaders(25); - - ASSERT_THAT(paths, - AllOf(Field(&ClangBackEnd::PchPaths::projectPchPath, IsEmpty()), - Field(&ClangBackEnd::PchPaths::systemPchPath, IsEmpty()))); -} - -TEST_F(PrecompiledHeaderStorage, FetchTimeStamps) -{ - ClangBackEnd::PrecompiledHeaderTimeStamps precompiledHeaderTimeStamps{22, 33}; - ON_CALL(fetchTimeStampsStatement, valuesReturnPrecompiledHeaderTimeStamps(Eq(23))) - .WillByDefault(Return(precompiledHeaderTimeStamps)); - - auto timeStamps = storage.fetchTimeStamps(23); - - ASSERT_THAT(timeStamps, - AllOf(Field(&ClangBackEnd::PrecompiledHeaderTimeStamps::project, Eq(22)), - Field(&ClangBackEnd::PrecompiledHeaderTimeStamps::system, Eq(33)))); -} - -TEST_F(PrecompiledHeaderStorage, NoFetchTimeStamps) -{ - auto timeStamps = storage.fetchTimeStamps(23); - - ASSERT_THAT(timeStamps, - AllOf(Field(&ClangBackEnd::PrecompiledHeaderTimeStamps::project, Eq(-1)), - Field(&ClangBackEnd::PrecompiledHeaderTimeStamps::system, Eq(-1)))); -} - -TEST_F(PrecompiledHeaderStorage, FetchTimeStampsCalls) -{ - InSequence s; - - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchTimeStampsStatement, valuesReturnPrecompiledHeaderTimeStamps(Eq(23))); - EXPECT_CALL(database, commit()); - - storage.fetchTimeStamps(23); -} - -TEST_F(PrecompiledHeaderStorage, FetchTimeStampsCallsWithReturnValue) -{ - InSequence s; - - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchTimeStampsStatement, valuesReturnPrecompiledHeaderTimeStamps(Eq(23))) - .WillOnce(Return(ClangBackEnd::PrecompiledHeaderTimeStamps{})); - EXPECT_CALL(database, commit()); - - storage.fetchTimeStamps(23); -} - -TEST_F(PrecompiledHeaderStorage, FetchTimeStampsBusy) -{ - InSequence s; - - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchTimeStampsStatement, valuesReturnPrecompiledHeaderTimeStamps(Eq(23))) - .WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(database, rollback()); - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchTimeStampsStatement, valuesReturnPrecompiledHeaderTimeStamps(Eq(23))); - EXPECT_CALL(database, commit()); - - storage.fetchTimeStamps(23); -} - -TEST_F(PrecompiledHeaderStorage, FetchAllPchPaths) -{ - InSequence s; - - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchAllPchPathsStatement, valuesReturnFilePaths(_)); - EXPECT_CALL(database, commit()); - - storage.fetchAllPchPaths(); -} - -TEST_F(PrecompiledHeaderStorage, FetchAllPchPathsIsBusy) -{ - InSequence s; - - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchAllPchPathsStatement, valuesReturnFilePaths(_)) - .WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(database, rollback()); - EXPECT_CALL(database, deferredBegin()); - EXPECT_CALL(fetchAllPchPathsStatement, valuesReturnFilePaths(_)); - EXPECT_CALL(database, commit()); - - storage.fetchAllPchPaths(); -} - -class PrecompiledHeaderStorageSlowTest : public testing::Test -{ -protected: - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer initializer{database}; - ClangBackEnd::PrecompiledHeaderStorage<> storage{database}; -}; - -TEST_F(PrecompiledHeaderStorageSlowTest, NoFetchTimeStamps) -{ - storage.insertProjectPrecompiledHeader(23, {}, 22); - storage.insertSystemPrecompiledHeaders({23}, {}, 33); - - auto timeStamps = storage.fetchTimeStamps(23); - - ASSERT_THAT(timeStamps, - AllOf(Field(&ClangBackEnd::PrecompiledHeaderTimeStamps::project, Eq(22)), - Field(&ClangBackEnd::PrecompiledHeaderTimeStamps::system, Eq(33)))); -} - -TEST_F(PrecompiledHeaderStorageSlowTest, FetchAllPchPaths) -{ - storage.insertProjectPrecompiledHeader(11, "/tmp/yi", 22); - storage.insertProjectPrecompiledHeader(12, "/tmp/er", 22); - storage.insertSystemPrecompiledHeaders({11, 12}, "/tmp/se", 33); - storage.insertSystemPrecompiledHeaders({13}, "/tmp/wu", 33); - storage.insertProjectPrecompiledHeader(13, "/tmp/san", 22); - - auto filePathIds = storage.fetchAllPchPaths(); - - ASSERT_THAT(filePathIds, - UnorderedElementsAre("/tmp/er", "/tmp/san", "/tmp/se", "/tmp/wu", "/tmp/yi")); -} - -} // namespace diff --git a/tests/unit/unittest/preprocessormacrocollector-test.cpp b/tests/unit/unittest/preprocessormacrocollector-test.cpp deleted file mode 100644 index 94eaa01a8bd..00000000000 --- a/tests/unit/unittest/preprocessormacrocollector-test.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include - -namespace { - -using ProjectExplorer::Macros; -using ProjectExplorer::MacroType; -using PM = ClangPchManager::PreprocessorMacro; - -class PreprocessorMacrosManager : public testing::Test -{ -protected: - Macros macros1{{"yi", "1"}, {"er", "2"}}; - Macros macros2{{"san", "3"}, {"se", "4"}}; - Macros macrosWithDuplicates{{"yi", "1"}, {"san", "3"}, {"se", "4"}, {"er", "0"}}; - ClangPchManager::PreprocessorMacroCollector manager; -}; - -TEST_F(PreprocessorMacrosManager, Add) -{ - manager.add(macros1); - - ASSERT_THAT(manager.macros(), ElementsAre(PM{"er", "2"}, PM{"yi", "1"})); -} - -TEST_F(PreprocessorMacrosManager, AddMore) -{ - manager.add(macros1); - - manager.add(macros2); - - ASSERT_THAT(manager.macros(), - ElementsAre(PM{"er", "2"}, PM{"san", "3"}, PM{"se", "4"}, PM{"yi", "1"})); -} - -TEST_F(PreprocessorMacrosManager, FilterDuplicates) -{ - manager.add(macros1); - - manager.add(macrosWithDuplicates); - - ASSERT_THAT(manager.macros(), - ElementsAre(PM{"er", "0"}, PM{"er", "2"}, PM{"san", "3"}, PM{"se", "4"}, PM{"yi", "1"})); -} -} // namespace diff --git a/tests/unit/unittest/processormanager-test.cpp b/tests/unit/unittest/processormanager-test.cpp deleted file mode 100644 index c5da739b6ce..00000000000 --- a/tests/unit/unittest/processormanager-test.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockprocessor.h" - -#include -#include -#include - -namespace { -using ClangBackEnd::ProcessorInterface; - -class Manager final : public ClangBackEnd::ProcessorManager> -{ -public: - using Processor = NiceMock; - Manager(const ClangBackEnd::GeneratedFiles &generatedFiles) - : ClangBackEnd::ProcessorManager>(generatedFiles) - {} - -protected: - std::unique_ptr> createProcessor() const override - { - return std::make_unique>(); - } -}; - -class ProcessorManager : public testing::Test -{ -protected: - ClangBackEnd::GeneratedFiles generatedFiles; - Manager manager{generatedFiles}; -}; - -TEST_F(ProcessorManager, CreateUnsedProcessor) -{ - manager.unusedProcessor(); - - manager.unusedProcessor(); - - ASSERT_THAT(manager.processors(), SizeIs(2)); -} - -TEST_F(ProcessorManager, ReuseUnsedProcessor) -{ - auto &processor = manager.unusedProcessor(); - processor.setIsUsed(false); - - manager.unusedProcessor(); - - ASSERT_THAT(manager.processors(), SizeIs(1)); -} - -TEST_F(ProcessorManager, AsGetNewUnusedProcessorItIsSetUsed) -{ - auto &processor = manager.unusedProcessor(); - - ASSERT_TRUE(processor.isUsed()); -} - -TEST_F(ProcessorManager, AsGetReusedUnusedProcessorItIsSetUsed) -{ - auto &processor = manager.unusedProcessor(); - processor.setIsUsed(false); - - auto &processor2 = manager.unusedProcessor(); - - ASSERT_TRUE(processor2.isUsed()); -} - -TEST_F(ProcessorManager, UnusedProcessorIsInitializedWithUnsavedFiles) -{ - auto &processor = manager.unusedProcessor(); - - ASSERT_TRUE(processor.hasUnsavedFiles); -} - -TEST_F(ProcessorManager, ReusedProcessorIsInitializedWithUnsavedFiles) -{ - auto &processor = manager.unusedProcessor(); - processor.setIsUsed(false); - - auto &processor2 = manager.unusedProcessor(); - - ASSERT_TRUE(processor2.hasUnsavedFiles); -} - -} diff --git a/tests/unit/unittest/progresscounter-test.cpp b/tests/unit/unittest/progresscounter-test.cpp deleted file mode 100644 index dde6419cc60..00000000000 --- a/tests/unit/unittest/progresscounter-test.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include - -namespace { - -class ProgressCounter : public testing::Test -{ -protected: - NiceMock> mockSetProgressCallback; - ClangBackEnd::ProgressCounter counter{mockSetProgressCallback.AsStdFunction()}; -}; - -TEST_F(ProgressCounter, TotalAfterInitializing) -{ - ASSERT_THAT(counter.total(), 0); -} - -TEST_F(ProgressCounter, ProgressAfterInitializing) -{ - ASSERT_THAT(counter.progress(), 0); -} - -TEST_F(ProgressCounter, AddTotal) -{ - counter.addTotal(5); - counter.addProgress(3); - - EXPECT_CALL(mockSetProgressCallback, Call(3, 12)); - - counter.addTotal(7); -} - -TEST_F(ProgressCounter, AddTotalZero) -{ - counter.addTotal(5); - - EXPECT_CALL(mockSetProgressCallback, Call(_, _)).Times(0); - - counter.addTotal(0); -} - -TEST_F(ProgressCounter, RemoveTotal) -{ - counter.addTotal(11); - counter.addProgress(2); - - EXPECT_CALL(mockSetProgressCallback, Call(2, 4)); - - counter.removeTotal(7); -} - -TEST_F(ProgressCounter, RemoveTotalZero) -{ - counter.addTotal(11); - - EXPECT_CALL(mockSetProgressCallback, Call(_, _)).Times(0); - - counter.removeTotal(0); -} - -TEST_F(ProgressCounter, AddProgress) -{ - counter.addTotal(11); - counter.addProgress(3); - - EXPECT_CALL(mockSetProgressCallback, Call(7, 11)); - - counter.addProgress(4); -} - -TEST_F(ProgressCounter, AddProgressZero) -{ - counter.addTotal(11); - counter.addProgress(3); - - EXPECT_CALL(mockSetProgressCallback, Call(_, _)).Times(0); - - counter.addProgress(0); -} - -TEST_F(ProgressCounter, AddTotalAfterFinishingProgress) -{ - counter.addTotal(11); - counter.addProgress(3); - counter.addProgress(8); - - EXPECT_CALL(mockSetProgressCallback, Call(0, 9)); - - counter.addTotal(9); -} - -TEST_F(ProgressCounter, AddProgressAfterFinishingProgress) -{ - counter.addTotal(11); - counter.addProgress(3); - counter.addProgress(8); - counter.addTotal(9); - - EXPECT_CALL(mockSetProgressCallback, Call(4, 9)); - - counter.addProgress(4); -} - -TEST_F(ProgressCounter, AddTotalAfterFinishingProgressByRemoving) -{ - counter.addTotal(11); - counter.addProgress(3); - counter.removeTotal(8); - - EXPECT_CALL(mockSetProgressCallback, Call(0, 9)); - - counter.addTotal(9); -} - -TEST_F(ProgressCounter, AddProgressAfterFinishingProgressByRemoving) -{ - counter.addTotal(11); - counter.addProgress(3); - counter.removeTotal(8); - counter.addTotal(9); - - EXPECT_CALL(mockSetProgressCallback, Call(4, 9)); - - counter.addProgress(4); -} - -} diff --git a/tests/unit/unittest/projectpartartefact-test.cpp b/tests/unit/unittest/projectpartartefact-test.cpp deleted file mode 100644 index 7cb622f8bd8..00000000000 --- a/tests/unit/unittest/projectpartartefact-test.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include - -namespace { - -using ClangBackEnd::CompilerMacro; -using ClangBackEnd::IncludeSearchPath; -using ClangBackEnd::IncludeSearchPathType; - -TEST(ProjectPartArtefact, CompilerArguments) -{ - ClangBackEnd::ProjectPartArtefact artefact{"[\"-DFoo\",\"-DBar\"]", - "", - "", - "", - 1, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None}; - - ASSERT_THAT(artefact.toolChainArguments, ElementsAre(Eq("-DFoo"), Eq("-DBar"))); -} - -TEST(ProjectPartArtefact, EmptyCompilerArguments) -{ - ClangBackEnd::ProjectPartArtefact artefact{"", - "", - "", - "", - 1, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None}; - - ASSERT_THAT(artefact.toolChainArguments, IsEmpty()); -} - -TEST(ProjectPartArtefact, CompilerArgumentsParseError) -{ - ASSERT_THROW(ClangBackEnd::ProjectPartArtefact("\"-DFoo\",\"-DBar\"]", - "", - "", - "", - 1, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None), - ClangBackEnd::ProjectPartArtefactParseError); -} - -TEST(ProjectPartArtefact, CompilerMacros) -{ - ClangBackEnd::ProjectPartArtefact artefact{"", - R"([["Foo","1",1], ["Bar","42",2]])", - "", - "", - 1, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None}; - - ASSERT_THAT(artefact.compilerMacros, - UnorderedElementsAre(Eq(CompilerMacro{"Foo", "1", 1}), Eq(CompilerMacro{"Bar", "42", 2}))); -} - -TEST(ProjectPartArtefact, EmptyCompilerMacros) -{ - ClangBackEnd::ProjectPartArtefact artefact{"", - "", - "", - "", - 1, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None}; - - ASSERT_THAT(artefact.compilerMacros, IsEmpty()); -} - -TEST(ProjectPartArtefact, CompilerMacrosParseError) -{ - ASSERT_THROW(ClangBackEnd::ProjectPartArtefact("", - R"([["Foo":"1", 1], ["Bar", "42", 2]])", - "", - "", - 1, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None), - ClangBackEnd::ProjectPartArtefactParseError); -} - -TEST(ProjectPartArtefact, SystemIncludeSearchPaths) -{ - ClangBackEnd::ProjectPartArtefact artefact{"", - "", - R"([["/includes", 1, 2], ["/other/includes", 2, 3]])", - "", - 1, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None}; - - ASSERT_THAT( - artefact.systemIncludeSearchPaths, - ElementsAre(Eq(IncludeSearchPath("/includes", 1, IncludeSearchPathType::BuiltIn)), - Eq(IncludeSearchPath("/other/includes", 2, IncludeSearchPathType::System)))); -} - -TEST(ProjectPartArtefact, EmptySystemIncludeSearchPaths) -{ - ClangBackEnd::ProjectPartArtefact artefact{"", - "", - "", - "", - 1, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None}; - - ASSERT_THAT(artefact.systemIncludeSearchPaths, IsEmpty()); -} - -TEST(ProjectPartArtefact, ProjectIncludeSearchPaths) -{ - ClangBackEnd::ProjectPartArtefact artefact{ - "", - "", - R"([["/project/includes", 1, 1], ["/other/project/includes", 2, 1]])", - "", - 1, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None}; - - ASSERT_THAT( - artefact.systemIncludeSearchPaths, - ElementsAre( - Eq(IncludeSearchPath("/project/includes", 1, IncludeSearchPathType::User)), - Eq(IncludeSearchPath("/other/project/includes", 2, IncludeSearchPathType::User)))); -} - -TEST(ProjectPartArtefact, EmptyProjectIncludeSearchPaths) -{ - ClangBackEnd::ProjectPartArtefact artefact{"", - "", - "", - "", - 1, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None}; - - ASSERT_THAT(artefact.projectIncludeSearchPaths, IsEmpty()); -} - -TEST(ProjectPartArtefact, IncludeSystemSearchPathsParseError) -{ - ASSERT_THROW(ClangBackEnd::ProjectPartArtefact("", - "", - R"(["/includes", 1, 3], ["/other/includes", 2, 2]])", - "", - 1, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None), - ClangBackEnd::ProjectPartArtefactParseError); -} - -TEST(ProjectPartArtefact, IncludeProjectSearchPathsParseError) -{ - ASSERT_THROW(ClangBackEnd::ProjectPartArtefact( - "", - "", - R"(["/project/includes", 1, 1], ["/other/project/includes", 2, 1]])", - "", - 1, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None), - ClangBackEnd::ProjectPartArtefactParseError); -} -} diff --git a/tests/unit/unittest/projectpartsmanager-test.cpp b/tests/unit/unittest/projectpartsmanager-test.cpp deleted file mode 100644 index 2dd7a7afc44..00000000000 --- a/tests/unit/unittest/projectpartsmanager-test.cpp +++ /dev/null @@ -1,945 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" -#include "mockbuilddependenciesprovider.h" -#include "mockclangpathwatcher.h" -#include "mockfilepathcaching.h" -#include "mockgeneratedfiles.h" -#include "mockprecompiledheaderstorage.h" -#include "mockprojectpartsstorage.h" - -#include - -#include - -namespace { - -using ClangBackEnd::FilePathId; -using ClangBackEnd::FilePathIds; -using ClangBackEnd::ProjectPartContainer; -using ClangBackEnd::ProjectPartContainers; -using UpToDataProjectParts = ClangBackEnd::ProjectPartsManagerInterface::UpToDataProjectParts; -using ClangBackEnd::SourceEntries; -using ClangBackEnd::SourceEntry; -using ClangBackEnd::SourceType; - -MATCHER_P3(IsIdPaths, - projectPartId, - sourceIds, - sourceType, - std::string(negation ? "isn't " : "is ") - + PrintToString(ClangBackEnd::IdPaths{{projectPartId, sourceType}, - Utils::clone(sourceIds)})) -{ - const ClangBackEnd::IdPaths &idPaths = arg; - - return idPaths.filePathIds == sourceIds && idPaths.id.sourceType == sourceType - && idPaths.id.id == projectPartId; -} - -class ProjectPartsManager : public testing::Test -{ -protected: - ProjectPartsManager() - { - projectPartContainerWithoutPrecompiledHeader1.preCompiledHeaderWasGenerated = false; - ON_CALL(mockGeneratedFiles, fileContainers()).WillByDefault(ReturnRef(generatedFiles)); - } - NiceMock mockProjectPartsStorage; - NiceMock mockPrecompiledHeaderStorage; - NiceMock mockBuildDependenciesProvider; - NiceMock mockFilePathCaching; - NiceMock mockGeneratedFiles; - NiceMock mockClangPathWatcher; - ClangBackEnd::ProjectPartsManager manager{mockProjectPartsStorage, - mockPrecompiledHeaderStorage, - mockBuildDependenciesProvider, - mockFilePathCaching, - mockClangPathWatcher, - mockGeneratedFiles}; - FilePathId firstHeader{1}; - FilePathId secondHeader{2}; - FilePathId firstSource{11}; - FilePathId secondSource{12}; - FilePathId thirdSource{13}; - ProjectPartContainer projectPartContainer1{ - 1, - {"-DUNIX", "-O2"}, - {{"DEFINE", "1", 1}}, - {{"/includes", 1, ClangBackEnd::IncludeSearchPathType::BuiltIn}}, - {{"/project/includes", 1, ClangBackEnd::IncludeSearchPathType::User}}, - {firstHeader, secondHeader}, - {firstSource, secondSource}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::All}; - ProjectPartContainer updatedProjectPartContainer1{ - 1, - {"-DUNIX", "-O2"}, - {{"DEFINE", "1", 1}}, - {{"/includes", 1, ClangBackEnd::IncludeSearchPathType::BuiltIn}}, - {{"/project/includes", 1, ClangBackEnd::IncludeSearchPathType::User}}, - {firstHeader, secondHeader}, - {firstSource, secondSource, thirdSource}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::All}; - ProjectPartContainer nullProjectPartContainer1{1, - {}, - {}, - {}, - {}, - {}, - {}, - Utils::Language::C, - Utils::LanguageVersion::C89, - Utils::LanguageExtension::None}; - ProjectPartContainer projectPartContainerWithoutPrecompiledHeader1{ - 1, - {"-DUNIX", "-O2"}, - {{"DEFINE", "1", 1}}, - {{"/includes", 1, ClangBackEnd::IncludeSearchPathType::BuiltIn}}, - {{"/project/includes", 1, ClangBackEnd::IncludeSearchPathType::User}}, - {firstHeader, secondHeader}, - {firstSource, secondSource}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::All}; - ProjectPartContainer projectPartContainer2{ - 2, - {"-DUNIX", "-O2"}, - {{"DEFINE", "1", 1}}, - {{"/includes", 1, ClangBackEnd::IncludeSearchPathType::System}}, - {{"/project/includes", 1, ClangBackEnd::IncludeSearchPathType::User}}, - {firstHeader}, - {firstSource}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX14, - Utils::LanguageExtension::All}; - ProjectPartContainer projectPartContainer3{ - 3, - {"-DUNIX", "-O2"}, - {{"DEFINE", "1", 1}}, - {{"/includes", 1, ClangBackEnd::IncludeSearchPathType::Framework}}, - {{"/project/includes", 1, ClangBackEnd::IncludeSearchPathType::User}}, - {secondHeader}, - {firstSource}, - Utils::Language::C, - Utils::LanguageVersion::C18, - Utils::LanguageExtension::All}; - ProjectPartContainer projectPartContainer4{ - 4, - {"-DUNIX", "-O2"}, - {{"DEFINE", "1", 1}}, - {{"/includes", 1, ClangBackEnd::IncludeSearchPathType::User}}, - {{"/project/includes", 1, ClangBackEnd::IncludeSearchPathType::User}}, - {firstHeader}, - {firstSource}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX03, - Utils::LanguageExtension::All}; - ClangBackEnd::V2::FileContainers generatedFiles; -}; - -TEST_F(ProjectPartsManager, GetNoProjectPartsForAddingEmptyProjectParts) -{ - auto projectParts = manager.update({}); - - ASSERT_THAT(projectParts, - AllOf(Field(&UpToDataProjectParts::upToDate, IsEmpty()), - Field(&UpToDataProjectParts::updateSystem, IsEmpty()))); -} - -TEST_F(ProjectPartsManager, GetProjectPartForAddingProjectPart) -{ - auto projectParts = manager.update({projectPartContainer1}); - - ASSERT_THAT(projectParts, - AllOf(Field(&UpToDataProjectParts::upToDate, IsEmpty()), - Field(&UpToDataProjectParts::updateSystem, ElementsAre(projectPartContainer1)))); -} - -TEST_F(ProjectPartsManager, GetProjectPartForAddingProjectPartWithProjectPartAlreadyInTheDatabase) -{ - ON_CALL(mockProjectPartsStorage, fetchProjectParts(_)) - .WillByDefault(Return(ProjectPartContainers{projectPartContainer1})); - - auto projectParts = manager.update({projectPartContainer1, projectPartContainer2}); - - ASSERT_THAT(projectParts, - AllOf(Field(&UpToDataProjectParts::upToDate, ElementsAre(projectPartContainer1)), - Field(&UpToDataProjectParts::updateSystem, ElementsAre(projectPartContainer2)))); -} - -TEST_F(ProjectPartsManager, GetProjectPartForAddingProjectPartWithOlderProjectPartAlreadyInTheDatabase) -{ - ON_CALL(mockProjectPartsStorage, fetchProjectParts(_)) - .WillByDefault(Return(ProjectPartContainers{projectPartContainer1})); - - auto projectParts = manager.update({updatedProjectPartContainer1, projectPartContainer2}); - - ASSERT_THAT(projectParts, - AllOf(Field(&UpToDataProjectParts::upToDate, IsEmpty()), - Field(&UpToDataProjectParts::updateSystem, - ElementsAre(updatedProjectPartContainer1, projectPartContainer2)))); -} - -TEST_F(ProjectPartsManager, ProjectPartAdded) -{ - manager.update({projectPartContainer1}); - - ASSERT_THAT(manager.projectParts(), ElementsAre(projectPartContainer1)); -} - -TEST_F(ProjectPartsManager, ProjectPartAddedWithProjectPartAlreadyInTheDatabase) -{ - ON_CALL(mockProjectPartsStorage, fetchProjectParts(_)) - .WillByDefault(Return(ProjectPartContainers{projectPartContainer1})); - - manager.update({projectPartContainer1, projectPartContainer2}); - - ASSERT_THAT(manager.projectParts(), ElementsAre(projectPartContainer1, projectPartContainer2)); -} - -TEST_F(ProjectPartsManager, ProjectPartAddedWithOlderProjectPartAlreadyInTheDatabase) -{ - ON_CALL(mockProjectPartsStorage, fetchProjectParts(_)) - .WillByDefault(Return(ProjectPartContainers{projectPartContainer1})); - - manager.update({updatedProjectPartContainer1, projectPartContainer2}); - - ASSERT_THAT(manager.projectParts(), - ElementsAre(updatedProjectPartContainer1, projectPartContainer2)); -} - -TEST_F(ProjectPartsManager, FilteredProjectPartAdded) -{ - manager.update({projectPartContainer1}); - - manager.update({projectPartContainer1}); - - ASSERT_THAT(manager.projectParts(), ElementsAre(projectPartContainer1)); -} - -TEST_F(ProjectPartsManager, DoNotUpdateNotNewProjectPart) -{ - manager.update({projectPartContainer1}); - - auto projectParts = manager.update({projectPartContainer1}); - - ASSERT_THAT(projectParts, - AllOf(Field(&UpToDataProjectParts::upToDate, ElementsAre(projectPartContainer1)), - Field(&UpToDataProjectParts::updateSystem, IsEmpty()))); -} - -TEST_F(ProjectPartsManager, NoDuplicateProjectPartAfterUpdatingWithNotNewProjectPart) -{ - manager.update({projectPartContainer1}); - - auto updatedProjectParts = manager.update({projectPartContainer1}); - - ASSERT_THAT(manager.projectParts(), ElementsAre(projectPartContainer1)); -} - -TEST_F(ProjectPartsManager, MergeProjectParts) -{ - manager.mergeProjectParts({projectPartContainer1, projectPartContainer2}); - - ASSERT_THAT(manager.projectParts(), ElementsAre(projectPartContainer1, projectPartContainer2)); -} - -TEST_F(ProjectPartsManager, MergeProjectMultipleTimesParts) -{ - manager.mergeProjectParts({projectPartContainer2}); - - manager.mergeProjectParts({projectPartContainer1}); - - ASSERT_THAT(manager.projectParts(), ElementsAre(projectPartContainer1, projectPartContainer2)); -} - -TEST_F(ProjectPartsManager, GetNewProjectParts) -{ - auto newProjectParts = manager.filterProjectParts({projectPartContainer1, projectPartContainer2}, - {projectPartContainer2}); - - ASSERT_THAT(newProjectParts, ElementsAre(projectPartContainer1)); -} - -TEST_F(ProjectPartsManager, GetUpdatedProjectPart) -{ - manager.update({projectPartContainer1, projectPartContainer2}); - - auto projectParts = manager.update({updatedProjectPartContainer1}); - - ASSERT_THAT(projectParts, - AllOf(Field(&UpToDataProjectParts::upToDate, IsEmpty()), - Field(&UpToDataProjectParts::updateSystem, - ElementsAre(updatedProjectPartContainer1)))); -} - -TEST_F(ProjectPartsManager, ProjectPartIsReplacedWithUpdatedProjectPart) -{ - manager.update({projectPartContainer1, projectPartContainer2}); - - manager.update({updatedProjectPartContainer1}); - - ASSERT_THAT(manager.projectParts(), - ElementsAre(updatedProjectPartContainer1, projectPartContainer2)); -} - -TEST_F(ProjectPartsManager, Remove) -{ - manager.update({projectPartContainer1, projectPartContainer2}); - - manager.remove({projectPartContainer1.projectPartId}); - - ASSERT_THAT(manager.projectParts(), ElementsAre(projectPartContainer2)); -} - -TEST_F(ProjectPartsManager, RemoveSystemDeferred) -{ - manager.updateDeferred({projectPartContainer1, projectPartContainer2}, {}); - - manager.remove({projectPartContainer1.projectPartId}); - - ASSERT_THAT(manager.deferredSystemUpdates(), ElementsAre(projectPartContainer2)); -} - -TEST_F(ProjectPartsManager, RemoveProjectDeferred) -{ - manager.updateDeferred({}, {projectPartContainer1, projectPartContainer2}); - - manager.remove({projectPartContainer1.projectPartId}); - - ASSERT_THAT(manager.deferredProjectUpdates(), ElementsAre(projectPartContainer2)); -} - -TEST_F(ProjectPartsManager, GetProjectById) -{ - manager.update({projectPartContainer1, projectPartContainer2}); - - auto projectPartContainers = manager.projects({projectPartContainer1.projectPartId}); - - ASSERT_THAT(projectPartContainers, ElementsAre(projectPartContainer1)); -} - -TEST_F(ProjectPartsManager, GetProjectsByIds) -{ - manager.update({projectPartContainer1, projectPartContainer2}); - - auto projectPartContainers = manager.projects( - {projectPartContainer1.projectPartId, projectPartContainer2.projectPartId}); - - ASSERT_THAT(projectPartContainers, UnorderedElementsAre(projectPartContainer1, projectPartContainer2)); -} - -TEST_F(ProjectPartsManager, UpdateSystemDeferred) -{ - manager.updateDeferred({projectPartContainer1}, {}); - - ASSERT_THAT(manager.deferredSystemUpdates(), ElementsAre(projectPartContainer1)); -} - -TEST_F(ProjectPartsManager, UpdateProjectDeferred) -{ - manager.updateDeferred({}, {projectPartContainer1}); - - ASSERT_THAT(manager.deferredProjectUpdates(), ElementsAre(projectPartContainer1)); -} - -TEST_F(ProjectPartsManager, NotUpdateSystemDeferred) -{ - ASSERT_THAT(manager.deferredSystemUpdates(), IsEmpty()); -} - -TEST_F(ProjectPartsManager, NotUpdateProjectDeferred) -{ - ASSERT_THAT(manager.deferredProjectUpdates(), IsEmpty()); -} - -TEST_F(ProjectPartsManager, UpdateSystemDeferredCleansDeferredUpdates) -{ - manager.updateDeferred({projectPartContainer1}, {}); - - manager.deferredSystemUpdates(); - - ASSERT_THAT(manager.deferredSystemUpdates(), IsEmpty()); -} - -TEST_F(ProjectPartsManager, UpdateProjectDeferredCleansDeferredUpdates) -{ - manager.updateDeferred({}, {projectPartContainer1}); - - manager.deferredProjectUpdates(); - - ASSERT_THAT(manager.deferredProjectUpdates(), IsEmpty()); -} - -TEST_F(ProjectPartsManager, UpdateSystemDeferredMultiple) -{ - manager.updateDeferred({projectPartContainer1, projectPartContainer3}, {}); - - manager.updateDeferred({updatedProjectPartContainer1, projectPartContainer2, projectPartContainer4}, - {}); - - ASSERT_THAT(manager.deferredSystemUpdates(), - ElementsAre(updatedProjectPartContainer1, - projectPartContainer2, - projectPartContainer3, - projectPartContainer4)); -} - -TEST_F(ProjectPartsManager, UpdateProjectDeferredMultiple) -{ - manager.updateDeferred({}, {projectPartContainer1, projectPartContainer3}); - - manager.updateDeferred({}, - {updatedProjectPartContainer1, projectPartContainer2, projectPartContainer4}); - - ASSERT_THAT(manager.deferredProjectUpdates(), - ElementsAre(updatedProjectPartContainer1, - projectPartContainer2, - projectPartContainer3, - projectPartContainer4)); -} -TEST_F(ProjectPartsManager, UpdateCallsIfNewProjectPartIsAdded) -{ - EXPECT_CALL(mockProjectPartsStorage, - fetchProjectParts(ElementsAre(Eq(projectPartContainer1.projectPartId)))); - EXPECT_CALL(mockProjectPartsStorage, updateProjectParts(ElementsAre(projectPartContainer1))); - EXPECT_CALL(mockProjectPartsStorage, resetIndexingTimeStamps(ElementsAre(projectPartContainer1))); - EXPECT_CALL(mockPrecompiledHeaderStorage, - deleteSystemAndProjectPrecompiledHeaders( - ElementsAre(projectPartContainer1.projectPartId))); - - manager.update({projectPartContainer1}); -} - -TEST_F(ProjectPartsManager, UpdateCallsNotUpdateProjectPartsInStorageIfNoNewerProjectPartsExists) -{ - manager.update({projectPartContainer1}); - - EXPECT_CALL(mockProjectPartsStorage, updateProjectParts(ElementsAre(projectPartContainer1))).Times(0); - - manager.update({projectPartContainer1}); -} - -TEST_F(ProjectPartsManager, UpdateCallsNotFetchProjectPartsInStorageIfNoNewerProjectPartsExists) -{ - manager.update({projectPartContainer1}); - - EXPECT_CALL(mockProjectPartsStorage, - fetchProjectParts(ElementsAre(Eq(projectPartContainer1.projectPartId)))) - .Times(0); - - manager.update({projectPartContainer1}); -} - -TEST_F(ProjectPartsManager, UpdateCallsNotDeleteProjectPrecompiledHeadersIfNoNewerProjectPartsExists) -{ - manager.update({projectPartContainer1}); - - EXPECT_CALL(mockPrecompiledHeaderStorage, - deleteProjectPrecompiledHeaders(ElementsAre(projectPartContainer1.projectPartId))) - .Times(0); - - manager.update({projectPartContainer1}); -} - -TEST_F(ProjectPartsManager, - UpdateCallsNotDeleteSystemAndProjectPrecompiledHeadersIfNoNewerProjectPartsExists) -{ - manager.update({projectPartContainer1}); - - EXPECT_CALL(mockPrecompiledHeaderStorage, - deleteSystemAndProjectPrecompiledHeaders( - ElementsAre(projectPartContainer1.projectPartId))) - .Times(0); - - manager.update({projectPartContainer1}); -} - -TEST_F(ProjectPartsManager, UpdateCallsNotResetIndexingTimeStampsIfNoNewerProjectPartsExists) -{ - manager.update({projectPartContainer1}); - - EXPECT_CALL(mockProjectPartsStorage, resetIndexingTimeStamps(ElementsAre(projectPartContainer1))) - .Times(0); - - manager.update({projectPartContainer1}); -} - -TEST_F(ProjectPartsManager, UpdateCallsIfOldProjectPartIsAdded) -{ - EXPECT_CALL(mockProjectPartsStorage, - fetchProjectParts(ElementsAre(Eq(projectPartContainer1.projectPartId)))) - .WillRepeatedly(Return(ProjectPartContainers{projectPartContainer1})); - EXPECT_CALL(mockProjectPartsStorage, updateProjectParts(ElementsAre(projectPartContainer1))).Times(0); - EXPECT_CALL(mockPrecompiledHeaderStorage, - deleteProjectPrecompiledHeaders(ElementsAre(projectPartContainer1.projectPartId))) - .Times(0); - EXPECT_CALL(mockProjectPartsStorage, resetIndexingTimeStamps(ElementsAre(projectPartContainer1))) - .Times(0); - - manager.update({projectPartContainer1}); -} - -TEST_F(ProjectPartsManager, UpdateCallsIfUpdatedProjectPartIsAdded) -{ - manager.update({projectPartContainer1}); - - EXPECT_CALL(mockProjectPartsStorage, - fetchProjectParts(ElementsAre(Eq(projectPartContainer1.projectPartId)))) - .WillRepeatedly(Return(ProjectPartContainers{projectPartContainer1})); - EXPECT_CALL(mockProjectPartsStorage, - updateProjectParts(ElementsAre(updatedProjectPartContainer1))); - EXPECT_CALL(mockPrecompiledHeaderStorage, - deleteSystemAndProjectPrecompiledHeaders( - ElementsAre(projectPartContainer1.projectPartId))); - EXPECT_CALL(mockProjectPartsStorage, - resetIndexingTimeStamps(ElementsAre(updatedProjectPartContainer1))); - - manager.update({updatedProjectPartContainer1}); -} - -TEST_F(ProjectPartsManager, - GetProjectPartForAddingProjectPartWithProjectPartAlreadyInTheDatabaseButNoPrecompiledHeader) -{ - ON_CALL(mockProjectPartsStorage, fetchProjectParts(_)) - .WillByDefault(Return(ProjectPartContainers{projectPartContainerWithoutPrecompiledHeader1})); - - auto projectParts = manager.update({projectPartContainer1}); - - ASSERT_THAT(projectParts, - AllOf(Field(&UpToDataProjectParts::upToDate, IsEmpty()), - Field(&UpToDataProjectParts::updateSystem, ElementsAre(projectPartContainer1)))); -} - -TEST_F(ProjectPartsManager, ProjectPartAddedWithProjectPartAlreadyInTheDatabaseButWithoutEntries) -{ - ON_CALL(mockProjectPartsStorage, fetchProjectParts(_)) - .WillByDefault(Return(ProjectPartContainers{nullProjectPartContainer1})); - - manager.update({projectPartContainer1}); - - ASSERT_THAT(manager.projectParts(), ElementsAre(projectPartContainer1)); -} - -TEST_F(ProjectPartsManager, SystemSourcesTimeChanged) -{ - SourceEntries oldSources{{1, SourceType::SystemInclude, 100}, - {2, SourceType::ProjectInclude, 100}}; - SourceEntries newSources{{1, SourceType::SystemInclude, 101}, - {2, SourceType::ProjectInclude, 101}}; - manager.update({projectPartContainer1}); - ON_CALL(mockBuildDependenciesProvider, - createSourceEntriesFromStorage(Eq(projectPartContainer1.sourcePathIds), - Eq(projectPartContainer1.projectPartId))) - .WillByDefault(Return(oldSources)); - ON_CALL(mockBuildDependenciesProvider, create(Eq(projectPartContainer1), Eq(oldSources))) - .WillByDefault(Return(ClangBackEnd::BuildDependency{newSources, {}, {}, {}, {}})); - - auto upToDate = manager.update({projectPartContainer1}); - - ASSERT_THAT(upToDate.updateSystem, ElementsAre(projectPartContainer1)); - ASSERT_THAT(upToDate.updateProject, IsEmpty()); - ASSERT_THAT(upToDate.upToDate, IsEmpty()); -} - -TEST_F(ProjectPartsManager, TopSystemSourcesTimeChanged) -{ - SourceEntries oldSources{{1, SourceType::TopSystemInclude, 100}, - {2, SourceType::ProjectInclude, 100}}; - SourceEntries newSources{{1, SourceType::TopSystemInclude, 101}, - {2, SourceType::ProjectInclude, 101}}; - manager.update({projectPartContainer1}); - ON_CALL(mockBuildDependenciesProvider, - createSourceEntriesFromStorage(Eq(projectPartContainer1.sourcePathIds), - Eq(projectPartContainer1.projectPartId))) - .WillByDefault(Return(oldSources)); - ON_CALL(mockBuildDependenciesProvider, create(Eq(projectPartContainer1), Eq(oldSources))) - .WillByDefault(Return(ClangBackEnd::BuildDependency{newSources, {}, {}, {}, {}})); - - auto upToDate = manager.update({projectPartContainer1}); - - ASSERT_THAT(upToDate.updateSystem, ElementsAre(projectPartContainer1)); - ASSERT_THAT(upToDate.updateProject, IsEmpty()); - ASSERT_THAT(upToDate.upToDate, IsEmpty()); -} - -TEST_F(ProjectPartsManager, ProjectSourcesTimeChanged) -{ - SourceEntries oldSources{{1, SourceType::SystemInclude, 100}, - {2, SourceType::ProjectInclude, 100}}; - SourceEntries newSources{{1, SourceType::SystemInclude, 100}, - {2, SourceType::ProjectInclude, 101}}; - manager.update({projectPartContainer1}); - ON_CALL(mockBuildDependenciesProvider, - createSourceEntriesFromStorage(Eq(projectPartContainer1.sourcePathIds), - Eq(projectPartContainer1.projectPartId))) - .WillByDefault(Return(oldSources)); - ON_CALL(mockBuildDependenciesProvider, create(Eq(projectPartContainer1), Eq(oldSources))) - .WillByDefault(Return(ClangBackEnd::BuildDependency{newSources, {}, {}, {}, {}})); - - auto upToDate = manager.update({projectPartContainer1}); - - ASSERT_THAT(upToDate.updateProject, ElementsAre(projectPartContainer1)); - ASSERT_THAT(upToDate.updateSystem, IsEmpty()); - ASSERT_THAT(upToDate.upToDate, IsEmpty()); -} - -TEST_F(ProjectPartsManager, TopProjectSourcesTimeChanged) -{ - SourceEntries oldSources{{1, SourceType::SystemInclude, 100}, - {2, SourceType::TopProjectInclude, 100}}; - SourceEntries newSources{{1, SourceType::SystemInclude, 100}, - {2, SourceType::TopProjectInclude, 101}}; - manager.update({projectPartContainer1}); - ON_CALL(mockBuildDependenciesProvider, - createSourceEntriesFromStorage(Eq(projectPartContainer1.sourcePathIds), - Eq(projectPartContainer1.projectPartId))) - .WillByDefault(Return(oldSources)); - ON_CALL(mockBuildDependenciesProvider, create(Eq(projectPartContainer1), Eq(oldSources))) - .WillByDefault(Return(ClangBackEnd::BuildDependency{newSources, {}, {}, {}, {}})); - - auto upToDate = manager.update({projectPartContainer1}); - - ASSERT_THAT(upToDate.updateProject, ElementsAre(projectPartContainer1)); - ASSERT_THAT(upToDate.updateSystem, IsEmpty()); - ASSERT_THAT(upToDate.upToDate, IsEmpty()); -} - -TEST_F(ProjectPartsManager, UserIncludeSourcesTimeChanged) -{ - SourceEntries oldSources{{1, SourceType::SystemInclude, 100}, {2, SourceType::UserInclude, 100}}; - SourceEntries newSources{{1, SourceType::SystemInclude, 100}, {2, SourceType::UserInclude, 101}}; - manager.update({projectPartContainer1}); - ON_CALL(mockBuildDependenciesProvider, - createSourceEntriesFromStorage(Eq(projectPartContainer1.sourcePathIds), - Eq(projectPartContainer1.projectPartId))) - .WillByDefault(Return(oldSources)); - ON_CALL(mockBuildDependenciesProvider, create(Eq(projectPartContainer1), Eq(oldSources))) - .WillByDefault(Return(ClangBackEnd::BuildDependency{newSources, {}, {}, {}, {}})); - - auto upToDate = manager.update({projectPartContainer1}); - - ASSERT_THAT(upToDate.upToDate, ElementsAre(projectPartContainer1)); - ASSERT_THAT(upToDate.updateProject, IsEmpty()); - ASSERT_THAT(upToDate.updateSystem, IsEmpty()); -} - -TEST_F(ProjectPartsManager, SourcesTimeChanged) -{ - SourceEntries oldSources{{1, SourceType::SystemInclude, 100}, {2, SourceType::Source, 100}}; - SourceEntries newSources{{1, SourceType::SystemInclude, 100}, {2, SourceType::Source, 101}}; - manager.update({projectPartContainer1}); - ON_CALL(mockBuildDependenciesProvider, - createSourceEntriesFromStorage(Eq(projectPartContainer1.sourcePathIds), - Eq(projectPartContainer1.projectPartId))) - .WillByDefault(Return(oldSources)); - ON_CALL(mockBuildDependenciesProvider, create(Eq(projectPartContainer1), Eq(oldSources))) - .WillByDefault(Return(ClangBackEnd::BuildDependency{newSources, {}, {}, {}, {}})); - - auto upToDate = manager.update({projectPartContainer1}); - - ASSERT_THAT(upToDate.upToDate, ElementsAre(projectPartContainer1)); - ASSERT_THAT(upToDate.updateProject, IsEmpty()); - ASSERT_THAT(upToDate.updateSystem, IsEmpty()); -} - -TEST_F(ProjectPartsManager, SourcesTimeNotChanged) -{ - SourceEntries oldSources{{1, SourceType::SystemInclude, 100}}; - SourceEntries newSources{{1, SourceType::SystemInclude, 99}}; - manager.update({projectPartContainer1}); - ON_CALL(mockBuildDependenciesProvider, - createSourceEntriesFromStorage(Eq(projectPartContainer1.sourcePathIds), - Eq(projectPartContainer1.projectPartId))) - .WillByDefault(Return(oldSources)); - ON_CALL(mockBuildDependenciesProvider, create(Eq(projectPartContainer1), Eq(oldSources))) - .WillByDefault(Return(ClangBackEnd::BuildDependency{newSources, {}, {}, {}, {}})); - - auto upToDate = manager.update({projectPartContainer1}); - - ASSERT_THAT(upToDate.upToDate, ElementsAre(projectPartContainer1)); - ASSERT_THAT(upToDate.updateSystem, IsEmpty()); - ASSERT_THAT(upToDate.updateProject, IsEmpty()); -} - -TEST_F(ProjectPartsManager, TimeChangedForOneProject) -{ - manager.update({projectPartContainer1, projectPartContainer2}); - ON_CALL(mockBuildDependenciesProvider, - createSourceEntriesFromStorage(Eq(projectPartContainer1.sourcePathIds), - Eq(projectPartContainer1.projectPartId))) - .WillByDefault(Return(SourceEntries{{1, SourceType::SystemInclude, 100}})); - ON_CALL(mockBuildDependenciesProvider, - createSourceEntriesFromStorage(Eq(projectPartContainer2.sourcePathIds), - Eq(projectPartContainer2.projectPartId))) - .WillByDefault(Return(SourceEntries{{4, SourceType::SystemInclude, 100}})); - ON_CALL(mockBuildDependenciesProvider, - create(Eq(projectPartContainer1), Eq(SourceEntries{{1, SourceType::SystemInclude, 100}}))) - .WillByDefault(Return( - ClangBackEnd::BuildDependency{{{1, SourceType::SystemInclude, 101}}, {}, {}, {}, {}})); - ON_CALL(mockBuildDependenciesProvider, - create(Eq(projectPartContainer2), Eq(SourceEntries{{4, SourceType::SystemInclude, 100}}))) - .WillByDefault(Return( - ClangBackEnd::BuildDependency{{{4, SourceType::SystemInclude, 100}}, {}, {}, {}, {}})); - - auto upToDate = manager.update({projectPartContainer1, projectPartContainer2}); - - ASSERT_THAT(upToDate.updateSystem, ElementsAre(projectPartContainer1)); - ASSERT_THAT(upToDate.updateProject, IsEmpty()); - ASSERT_THAT(upToDate.upToDate, ElementsAre(projectPartContainer2)); -} - -TEST_F(ProjectPartsManager, AddSystemInclude) -{ - manager.update({projectPartContainer1}); - SourceEntries oldSources{{1, SourceType::SystemInclude, 100}}; - SourceEntries newSources{{1, SourceType::SystemInclude, 100}, {2, SourceType::SystemInclude, 100}}; - manager.update({projectPartContainer1}); - ON_CALL(mockBuildDependenciesProvider, - createSourceEntriesFromStorage(Eq(projectPartContainer1.sourcePathIds), - Eq(projectPartContainer1.projectPartId))) - .WillByDefault(Return(oldSources)); - ON_CALL(mockBuildDependenciesProvider, create(Eq(projectPartContainer1), Eq(oldSources))) - .WillByDefault(Return(ClangBackEnd::BuildDependency{newSources, {}, {}, {}, {}})); - - auto upToDate = manager.update({projectPartContainer1}); - - ASSERT_THAT(upToDate.updateSystem, ElementsAre(projectPartContainer1)); - ASSERT_THAT(upToDate.updateProject, IsEmpty()); - ASSERT_THAT(upToDate.upToDate, IsEmpty()); -} - -TEST_F(ProjectPartsManager, ChangeFromProjectToSystemInclude) -{ - manager.update({projectPartContainer1}); - SourceEntries oldSources{{1, SourceType::ProjectInclude, 100}}; - SourceEntries newSources{{1, SourceType::SystemInclude, 100}}; - manager.update({projectPartContainer1}); - ON_CALL(mockBuildDependenciesProvider, - createSourceEntriesFromStorage(Eq(projectPartContainer1.sourcePathIds), - Eq(projectPartContainer1.projectPartId))) - .WillByDefault(Return(oldSources)); - ON_CALL(mockBuildDependenciesProvider, create(Eq(projectPartContainer1), Eq(oldSources))) - .WillByDefault(Return(ClangBackEnd::BuildDependency{newSources, {}, {}, {}, {}})); - - auto upToDate = manager.update({projectPartContainer1}); - - ASSERT_THAT(upToDate.updateSystem, ElementsAre(projectPartContainer1)); - ASSERT_THAT(upToDate.updateProject, IsEmpty()); - ASSERT_THAT(upToDate.upToDate, IsEmpty()); -} - -TEST_F(ProjectPartsManager, ChangeFromSystemToProjectInclude) -{ - manager.update({projectPartContainer1}); - SourceEntries oldSources{{1, SourceType::SystemInclude, 100}}; - SourceEntries newSources{{1, SourceType::ProjectInclude, 100}}; - manager.update({projectPartContainer1}); - ON_CALL(mockBuildDependenciesProvider, - createSourceEntriesFromStorage(Eq(projectPartContainer1.sourcePathIds), - Eq(projectPartContainer1.projectPartId))) - .WillByDefault(Return(oldSources)); - ON_CALL(mockBuildDependenciesProvider, create(Eq(projectPartContainer1), Eq(oldSources))) - .WillByDefault(Return(ClangBackEnd::BuildDependency{newSources, {}, {}, {}, {}})); - - auto upToDate = manager.update({projectPartContainer1}); - - ASSERT_THAT(upToDate.updateSystem, ElementsAre(projectPartContainer1)); - ASSERT_THAT(upToDate.updateProject, IsEmpty()); - ASSERT_THAT(upToDate.upToDate, IsEmpty()); -} - -TEST_F(ProjectPartsManager, ChangeFromProjectToUserInclude) -{ - manager.update({projectPartContainer1}); - SourceEntries oldSources{{1, SourceType::ProjectInclude, 100}}; - SourceEntries newSources{{1, SourceType::UserInclude, 100}}; - manager.update({projectPartContainer1}); - ON_CALL(mockBuildDependenciesProvider, - createSourceEntriesFromStorage(Eq(projectPartContainer1.sourcePathIds), - Eq(projectPartContainer1.projectPartId))) - .WillByDefault(Return(oldSources)); - ON_CALL(mockBuildDependenciesProvider, create(Eq(projectPartContainer1), Eq(oldSources))) - .WillByDefault(Return(ClangBackEnd::BuildDependency{newSources, {}, {}, {}, {}})); - - auto upToDate = manager.update({projectPartContainer1}); - - ASSERT_THAT(upToDate.updateProject, ElementsAre(projectPartContainer1)); - ASSERT_THAT(upToDate.upToDate, IsEmpty()); - ASSERT_THAT(upToDate.updateSystem, IsEmpty()); -} - -TEST_F(ProjectPartsManager, ChangeFromSystemToUserInclude) -{ - manager.update({projectPartContainer1}); - SourceEntries oldSources{{1, SourceType::SystemInclude, 100}}; - SourceEntries newSources{{1, SourceType::UserInclude, 100}}; - manager.update({projectPartContainer1}); - ON_CALL(mockBuildDependenciesProvider, - createSourceEntriesFromStorage(Eq(projectPartContainer1.sourcePathIds), - Eq(projectPartContainer1.projectPartId))) - .WillByDefault(Return(oldSources)); - ON_CALL(mockBuildDependenciesProvider, create(Eq(projectPartContainer1), Eq(oldSources))) - .WillByDefault(Return(ClangBackEnd::BuildDependency{newSources, {}, {}, {}, {}})); - - auto upToDate = manager.update({projectPartContainer1}); - - ASSERT_THAT(upToDate.updateSystem, ElementsAre(projectPartContainer1)); - ASSERT_THAT(upToDate.upToDate, IsEmpty()); - ASSERT_THAT(upToDate.updateProject, IsEmpty()); -} - -TEST_F(ProjectPartsManager, ChangeFromSourceToUserInclude) -{ - manager.update({projectPartContainer1}); - SourceEntries oldSources{{1, SourceType::Source, 100}}; - SourceEntries newSources{{1, SourceType::UserInclude, 100}}; - manager.update({projectPartContainer1}); - ON_CALL(mockBuildDependenciesProvider, - createSourceEntriesFromStorage(Eq(projectPartContainer1.sourcePathIds), - Eq(projectPartContainer1.projectPartId))) - .WillByDefault(Return(oldSources)); - ON_CALL(mockBuildDependenciesProvider, create(Eq(projectPartContainer1), Eq(oldSources))) - .WillByDefault(Return(ClangBackEnd::BuildDependency{newSources, {}, {}, {}, {}})); - - auto upToDate = manager.update({projectPartContainer1}); - - ASSERT_THAT(upToDate.upToDate, ElementsAre(projectPartContainer1)); - ASSERT_THAT(upToDate.updateSystem, IsEmpty()); - ASSERT_THAT(upToDate.updateProject, IsEmpty()); -} - -TEST_F(ProjectPartsManager, ChangeFromUserIncludeToSource) -{ - manager.update({projectPartContainer1}); - SourceEntries oldSources{{1, SourceType::UserInclude, 100}}; - SourceEntries newSources{{1, SourceType::Source, 100}}; - manager.update({projectPartContainer1}); - ON_CALL(mockBuildDependenciesProvider, - createSourceEntriesFromStorage(Eq(projectPartContainer1.sourcePathIds), - Eq(projectPartContainer1.projectPartId))) - .WillByDefault(Return(oldSources)); - ON_CALL(mockBuildDependenciesProvider, create(Eq(projectPartContainer1), Eq(oldSources))) - .WillByDefault(Return(ClangBackEnd::BuildDependency{newSources, {}, {}, {}, {}})); - - auto upToDate = manager.update({projectPartContainer1}); - - ASSERT_THAT(upToDate.upToDate, ElementsAre(projectPartContainer1)); - ASSERT_THAT(upToDate.updateSystem, IsEmpty()); - ASSERT_THAT(upToDate.updateProject, IsEmpty()); -} - -TEST_F(ProjectPartsManager, DontWatchNewSources) -{ - EXPECT_CALL(mockClangPathWatcher, updateIdPaths(_)).Times(0); - - manager.update({projectPartContainer1}); -} - -TEST_F(ProjectPartsManager, DontWatchUpdatedSources) -{ - manager.update({projectPartContainer1}); - - EXPECT_CALL(mockClangPathWatcher, updateIdPaths(_)).Times(0); - - manager.update({updatedProjectPartContainer1}); -} - -TEST_F(ProjectPartsManager, DontWatchChangedTimeStamps) -{ - manager.update({projectPartContainer1}); - SourceEntries oldSources{{1, SourceType::SystemInclude, 100}}; - SourceEntries newSources{{1, SourceType::SystemInclude, 101}}; - ON_CALL(mockBuildDependenciesProvider, createSourceEntriesFromStorage(_, _)) - .WillByDefault(Return(oldSources)); - ON_CALL(mockBuildDependenciesProvider, create(_, _)) - .WillByDefault(Return(ClangBackEnd::BuildDependency{newSources, {}, {}, {}, {}})); - - EXPECT_CALL(mockClangPathWatcher, updateIdPaths(_)).Times(0); - - manager.update({projectPartContainer1}); -} - -TEST_F(ProjectPartsManager, DontWatchChangedSources) -{ - manager.update({projectPartContainer1}); - SourceEntries oldSources{{1, SourceType::SystemInclude, 100}}; - SourceEntries newSources{{1, SourceType::ProjectInclude, 100}}; - ON_CALL(mockBuildDependenciesProvider, createSourceEntriesFromStorage(_, _)) - .WillByDefault(Return(oldSources)); - ON_CALL(mockBuildDependenciesProvider, create(_, _)) - .WillByDefault(Return(ClangBackEnd::BuildDependency{newSources, {}, {}, {}, {}})); - - EXPECT_CALL(mockClangPathWatcher, updateIdPaths(_)).Times(0); - - manager.update({projectPartContainer1}); -} - -TEST_F(ProjectPartsManager, WatchNoUpdatedSources) -{ - manager.update({projectPartContainer1, projectPartContainer2}); - SourceEntries sources1{{1, SourceType::TopSystemInclude, 100}, - {2, SourceType::SystemInclude, 100}, - {3, SourceType::TopProjectInclude, 100}, - {4, SourceType::ProjectInclude, 100}, - {5, SourceType::UserInclude, 100}, - {6, SourceType::Source, 100}}; - SourceEntries sources2{{11, SourceType::TopSystemInclude, 100}, - {21, SourceType::SystemInclude, 100}, - {31, SourceType::TopProjectInclude, 100}, - {41, SourceType::ProjectInclude, 100}, - {51, SourceType::UserInclude, 100}, - {61, SourceType::Source, 100}}; - ON_CALL(mockBuildDependenciesProvider, createSourceEntriesFromStorage(_, Eq(1))) - .WillByDefault(Return(sources1)); - ON_CALL(mockBuildDependenciesProvider, - create(Field(&ProjectPartContainer::projectPartId, Eq(1)), _)) - .WillByDefault(Return(ClangBackEnd::BuildDependency{sources1, {}, {}, {}, {}})); - ON_CALL(mockBuildDependenciesProvider, createSourceEntriesFromStorage(_, Eq(2))) - .WillByDefault(Return(sources2)); - ON_CALL(mockBuildDependenciesProvider, - create(Field(&ProjectPartContainer::projectPartId, Eq(2)), _)) - .WillByDefault(Return(ClangBackEnd::BuildDependency{sources2, {}, {}, {}, {}})); - - EXPECT_CALL(mockClangPathWatcher, - updateIdPaths(UnorderedElementsAre( - IsIdPaths(1, FilePathIds{6}, SourceType::Source), - IsIdPaths(2, FilePathIds{61}, SourceType::Source), - IsIdPaths(1, FilePathIds{5}, SourceType::UserInclude), - IsIdPaths(2, FilePathIds{51}, SourceType::UserInclude), - IsIdPaths(1, FilePathIds{3, 4}, SourceType::ProjectInclude), - IsIdPaths(2, FilePathIds{31, 41}, SourceType::ProjectInclude), - IsIdPaths(1, FilePathIds{1, 2}, SourceType::SystemInclude), - IsIdPaths(2, FilePathIds{11, 21}, SourceType::SystemInclude)))); - - manager.update({projectPartContainer1, projectPartContainer2}); -} - -} // namespace diff --git a/tests/unit/unittest/projectpartsstorage-test.cpp b/tests/unit/unittest/projectpartsstorage-test.cpp deleted file mode 100644 index 06a08533231..00000000000 --- a/tests/unit/unittest/projectpartsstorage-test.cpp +++ /dev/null @@ -1,671 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "sqlitedatabasemock.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace { - -using ClangBackEnd::FilePathId; -using ClangBackEnd::IncludeSearchPath; -using ClangBackEnd::IncludeSearchPaths; -using ClangBackEnd::IncludeSearchPathType; -using ClangBackEnd::ProjectPartId; -using ClangBackEnd::ProjectPartIds; - -class Data -{ -protected: - ClangBackEnd::ProjectPartContainer projectPart1{1, - {"-m32"}, - {{"FOO", "1", 1}}, - {{"/include", 1, IncludeSearchPathType::System}}, - {{"/home/yi", 2, IncludeSearchPathType::User}}, - {1, 2}, - {3, 4}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX14, - Utils::LanguageExtension::Microsoft}; - ClangBackEnd::ProjectPartContainer projectPart2{2, - {"-m64"}, - {{"BAR", "2", 1}}, - {{"/usr/include", 1, IncludeSearchPathType::System}}, - {{"/home/er", 2, IncludeSearchPathType::User}}, - {5, 6}, - {7, 8}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::Gnu}; -}; - -class ProjectPartsStorage : public testing::Test, public Data -{ - using Storage = ClangBackEnd::ProjectPartsStorage; - template - using ReadStatement = NiceMock::ReadStatement; - using WriteStatement = NiceMock::WriteStatement; - -protected: - ProjectPartsStorage() - { - ON_CALL(fetchProjectPartByIdStatement, valueReturnProjectPartContainer(Eq(1))) - .WillByDefault(Return(projectPart1)); - ON_CALL(fetchProjectPartByIdStatement, valueReturnProjectPartContainer(Eq(2))) - .WillByDefault(Return(projectPart2)); - ON_CALL(fetchProjectPartsHeadersByIdStatement, valuesReturnFilePathIds(_, Eq(1))) - .WillByDefault(Return(projectPart1.headerPathIds)); - ON_CALL(fetchProjectPartsHeadersByIdStatement, valuesReturnFilePathIds(_, Eq(2))) - .WillByDefault(Return(projectPart2.headerPathIds)); - ON_CALL(fetchProjectPartsSourcesByIdStatement, valuesReturnFilePathIds(_, Eq(1))) - .WillByDefault(Return(projectPart1.sourcePathIds)); - ON_CALL(fetchProjectPartsSourcesByIdStatement, valuesReturnFilePathIds(_, Eq(2))) - .WillByDefault(Return(projectPart2.sourcePathIds)); - } - NiceMock databaseMock; - Storage storage{databaseMock}; - ReadStatement<1> &fetchProjectPartIdStatement = storage.fetchProjectPartIdStatement; - WriteStatement &insertProjectPartNameStatement = storage.insertProjectPartNameStatement; - ReadStatement<1> &fetchProjectPartNameStatement = storage.fetchProjectPartNameStatement; - ReadStatement<8> &fetchProjectPartsStatement = storage.fetchProjectPartsStatement; - ReadStatement<8> &fetchProjectPartByIdStatement = storage.fetchProjectPartByIdStatement; - WriteStatement &updateProjectPartStatement = storage.updateProjectPartStatement; - ReadStatement<8> &getProjectPartArtefactsBySourceId = storage.getProjectPartArtefactsBySourceId; - ReadStatement<8> &getProjectPartArtefactsByProjectPartId = storage.getProjectPartArtefactsByProjectPartId; - WriteStatement &deleteProjectPartsHeadersByIdStatement = storage.deleteProjectPartsHeadersByIdStatement; - WriteStatement &deleteProjectPartsSourcesByIdStatement = storage.deleteProjectPartsSourcesByIdStatement; - WriteStatement &insertProjectPartsHeadersStatement = storage.insertProjectPartsHeadersStatement; - WriteStatement &insertProjectPartsSourcesStatement = storage.insertProjectPartsSourcesStatement; - ReadStatement<1> &fetchProjectPartsHeadersByIdStatement = storage.fetchProjectPartsHeadersByIdStatement; - ReadStatement<1> &fetchProjectPartsSourcesByIdStatement = storage.fetchProjectPartsSourcesByIdStatement; - ReadStatement<1> &fetchProjectPrecompiledHeaderBuildTimeStatement = storage.fetchProjectPrecompiledHeaderBuildTimeStatement; - WriteStatement &resetDependentIndexingTimeStampsStatement = storage.resetDependentIndexingTimeStampsStatement; - ReadStatement<2> &fetchAllProjectPartNamesAndIdsStatement = storage.fetchAllProjectPartNamesAndIdsStatement; - IncludeSearchPaths systemIncludeSearchPaths{{"/includes", 1, IncludeSearchPathType::BuiltIn}, - {"/other/includes", 2, IncludeSearchPathType::System}}; - IncludeSearchPaths projectIncludeSearchPaths{{"/project/includes", 1, IncludeSearchPathType::User}, - {"/other/project/includes", - 2, - IncludeSearchPathType::User}}; - Utils::SmallString systemIncludeSearchPathsText{R"([["/includes",1,2],["/other/includes",2,3]])"}; - Utils::SmallString projectIncludeSearchPathsText{ - R"([["/project/includes",1,1],["/other/project/includes",2,1]])"}; - ClangBackEnd::ProjectPartArtefact artefact{R"(["-DFOO"])", - R"([["FOO","1",1]])", - systemIncludeSearchPathsText, - projectIncludeSearchPathsText, - 74, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX11, - Utils::LanguageExtension::None}; - ClangBackEnd::Internal::ProjectPartNameIds projectPartNameIds{{"projectPartName", 2}}; -}; - -TEST_F(ProjectPartsStorage, CallsFetchProjectIdWithNonExistingProjectPartName) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchProjectPartIdStatement, - valueReturnProjectPartId(TypedEq("test"))); - EXPECT_CALL(insertProjectPartNameStatement, write(TypedEq("test"))); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchProjectPartId("test"); -} - -TEST_F(ProjectPartsStorage, CallsFetchProjectIdWithNonExistingProjectPartNameUnguarded) -{ - InSequence s; - - EXPECT_CALL(fetchProjectPartIdStatement, - valueReturnProjectPartId(TypedEq("test"))); - EXPECT_CALL(insertProjectPartNameStatement, write(TypedEq("test"))); - - storage.fetchProjectPartIdUnguarded("test"); -} - -TEST_F(ProjectPartsStorage, CallsFetchProjectIdWithExistingProjectPart) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchProjectPartIdStatement, - valueReturnProjectPartId(TypedEq("test"))) - .WillOnce(Return(Utils::optional{20})); - EXPECT_CALL(insertProjectPartNameStatement, write(TypedEq("test"))).Times(0); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchProjectPartId("test"); -} - -TEST_F(ProjectPartsStorage, CallsFetchProjectIdWithExistingProjectPartUnguarded) -{ - InSequence s; - - EXPECT_CALL(fetchProjectPartIdStatement, - valueReturnProjectPartId(TypedEq("test"))) - .WillOnce(Return(Utils::optional{20})); - EXPECT_CALL(insertProjectPartNameStatement, write(TypedEq("test"))).Times(0); - - storage.fetchProjectPartIdUnguarded("test"); -} - -TEST_F(ProjectPartsStorage, CallsFetchProjectIdWithBusyDatabaset) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchProjectPartIdStatement, - valueReturnProjectPartId(TypedEq("test"))); - EXPECT_CALL(insertProjectPartNameStatement, write(TypedEq("test"))) - .WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(databaseMock, rollback()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchProjectPartIdStatement, - valueReturnProjectPartId(TypedEq("test"))); - EXPECT_CALL(insertProjectPartNameStatement, write(TypedEq("test"))); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchProjectPartId("test"); -} - -TEST_F(ProjectPartsStorage, FetchProjectIdWithNonExistingProjectPartName) -{ - ON_CALL(fetchProjectPartIdStatement, - valueReturnProjectPartId(TypedEq("test"))) - .WillByDefault(Return(Utils::optional{})); - ON_CALL(databaseMock, lastInsertedRowId()).WillByDefault(Return(21)); - - auto id = storage.fetchProjectPartId("test"); - - ASSERT_THAT(id.projectPathId, 21); -} - -TEST_F(ProjectPartsStorage, FetchProjectIdWithNonExistingProjectPartNameUnguarded) -{ - ON_CALL(fetchProjectPartIdStatement, - valueReturnProjectPartId(TypedEq("test"))) - .WillByDefault(Return(Utils::optional{})); - ON_CALL(databaseMock, lastInsertedRowId()).WillByDefault(Return(21)); - - auto id = storage.fetchProjectPartIdUnguarded("test"); - - ASSERT_THAT(id.projectPathId, 21); -} - -TEST_F(ProjectPartsStorage, FetchProjectIdWithNonExistingProjectPartNameAndIsBusy) -{ - InSequence s; - EXPECT_CALL(fetchProjectPartIdStatement, - valueReturnProjectPartId(TypedEq("test"))) - .WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); - EXPECT_CALL(fetchProjectPartIdStatement, - valueReturnProjectPartId(TypedEq("test"))) - .WillOnce(Return(ClangBackEnd::ProjectPartId{21})); - ON_CALL(databaseMock, lastInsertedRowId()).WillByDefault(Return(21)); - - auto id = storage.fetchProjectPartId("test"); - - ASSERT_THAT(id.projectPathId, 21); -} - -TEST_F(ProjectPartsStorage, FetchProjectIdWithExistingProjectPartName) -{ - ON_CALL(fetchProjectPartIdStatement, - valueReturnProjectPartId(TypedEq("test"))) - .WillByDefault(Return(Utils::optional{20})); - - auto id = storage.fetchProjectPartId("test"); - - ASSERT_THAT(id.projectPathId, 20); -} - -TEST_F(ProjectPartsStorage, FetchProjectIdWithExistingProjectPartNameUnguarded) -{ - ON_CALL(fetchProjectPartIdStatement, - valueReturnProjectPartId(TypedEq("test"))) - .WillByDefault(Return(Utils::optional{20})); - - auto id = storage.fetchProjectPartIdUnguarded("test"); - - ASSERT_THAT(id.projectPathId, 20); -} - -TEST_F(ProjectPartsStorage, FetchProjectPartName) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchProjectPartNameStatement, valueReturnPathString(TypedEq(12))) - .WillOnce(Return(Utils::optional{"test"})); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchProjectPartName(12); -} - -TEST_F(ProjectPartsStorage, FetchProjectPartNameStatementIsBusy) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchProjectPartNameStatement, valueReturnPathString(TypedEq(12))) - .WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(databaseMock, rollback()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchProjectPartNameStatement, valueReturnPathString(TypedEq(12))) - .WillOnce(Return(Utils::optional{"test"})); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchProjectPartName(12); -} - -TEST_F(ProjectPartsStorage, FetchProjectParts) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchProjectPartsStatement, valuesReturnProjectPartContainers(4096)); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchProjectParts(); -} - -TEST_F(ProjectPartsStorage, FetchProjectPartsByIds) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchProjectPartByIdStatement, valueReturnProjectPartContainer(Eq(1))); - EXPECT_CALL(fetchProjectPartsHeadersByIdStatement, valuesReturnFilePathIds(1024, Eq(1))); - EXPECT_CALL(fetchProjectPartsSourcesByIdStatement, valuesReturnFilePathIds(1024, Eq(1))); - EXPECT_CALL(fetchProjectPrecompiledHeaderBuildTimeStatement, valueReturnInt64(Eq(1))); - EXPECT_CALL(fetchProjectPartByIdStatement, valueReturnProjectPartContainer(Eq(2))); - EXPECT_CALL(fetchProjectPartsHeadersByIdStatement, valuesReturnFilePathIds(1024, Eq(2))); - EXPECT_CALL(fetchProjectPartsSourcesByIdStatement, valuesReturnFilePathIds(1024, Eq(2))); - EXPECT_CALL(fetchProjectPrecompiledHeaderBuildTimeStatement, valueReturnInt64(Eq(2))); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchProjectParts({1, 2}); -} - -TEST_F(ProjectPartsStorage, FetchProjectPartsByIdsIsBusy) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchProjectPartByIdStatement, valueReturnProjectPartContainer(Eq(1))); - EXPECT_CALL(fetchProjectPartByIdStatement, valueReturnProjectPartContainer(Eq(2))) - .WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(databaseMock, rollback()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchProjectPartByIdStatement, valueReturnProjectPartContainer(Eq(1))); - EXPECT_CALL(fetchProjectPartByIdStatement, valueReturnProjectPartContainer(Eq(2))); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchProjectParts({1, 2}); -} - -TEST_F(ProjectPartsStorage, FetchProjectPartsByIdsPreCompiledHeaderWasGeneratedNullOptional) -{ - ON_CALL(fetchProjectPrecompiledHeaderBuildTimeStatement, valueReturnInt64(Eq(1))) - .WillByDefault(Return(Utils::optional{})); - - auto projectParts = storage.fetchProjectParts({1}); - - ASSERT_FALSE(projectParts.front().preCompiledHeaderWasGenerated); -} - -TEST_F(ProjectPartsStorage, FetchProjectPartsByIdsPreCompiledHeaderWasGeneratedZero) -{ - ON_CALL(fetchProjectPrecompiledHeaderBuildTimeStatement, valueReturnInt64(Eq(1))) - .WillByDefault(Return(Utils::optional{0})); - - auto projectParts = storage.fetchProjectParts({1}); - - ASSERT_FALSE(projectParts.front().preCompiledHeaderWasGenerated); -} - -TEST_F(ProjectPartsStorage, FetchProjectPartsByIdsPreCompiledHeaderWasGeneratedSomeNumber) -{ - ON_CALL(fetchProjectPrecompiledHeaderBuildTimeStatement, valueReturnInt64(Eq(1))) - .WillByDefault(Return(Utils::optional{23})); - - auto projectParts = storage.fetchProjectParts({1}); - - ASSERT_TRUE(projectParts.front().preCompiledHeaderWasGenerated); -} - -TEST_F(ProjectPartsStorage, FetchProjectPartsByIdsHasMissingId) -{ - auto projectParts = storage.fetchProjectParts({1, 2, 3}); - - ASSERT_THAT(projectParts, ElementsAre(projectPart1, projectPart2)); -} - -TEST_F(ProjectPartsStorage, ConvertStringsToJson) -{ - Utils::SmallStringVector strings{"foo", "bar", "foo"}; - - auto jsonText = storage.toJson(strings); - - ASSERT_THAT(jsonText, Eq("[\"foo\",\"bar\",\"foo\"]")); -} - -TEST_F(ProjectPartsStorage, UpdateProjectParts) -{ - InSequence sequence; - - EXPECT_CALL(databaseMock, immediateBegin()); - EXPECT_CALL(updateProjectPartStatement, - write(TypedEq(1), - TypedEq(R"(["-m32"])"), - TypedEq(R"([["FOO","1",1]])"), - TypedEq(R"([["/include",1,3]])"), - TypedEq(R"([["/home/yi",2,1]])"), - 2, - 35, - 2)); - EXPECT_CALL(deleteProjectPartsHeadersByIdStatement, write(TypedEq(1))); - EXPECT_CALL(insertProjectPartsHeadersStatement, write(TypedEq(1), TypedEq(1))); - EXPECT_CALL(insertProjectPartsHeadersStatement, write(TypedEq(1), TypedEq(2))); - EXPECT_CALL(deleteProjectPartsSourcesByIdStatement, write(TypedEq(1))); - EXPECT_CALL(insertProjectPartsSourcesStatement, write(TypedEq(1), TypedEq(3))); - EXPECT_CALL(insertProjectPartsSourcesStatement, write(TypedEq(1), TypedEq(4))); - EXPECT_CALL(updateProjectPartStatement, - write(TypedEq(2), - TypedEq(R"(["-m64"])"), - TypedEq(R"([["BAR","2",1]])"), - TypedEq(R"([["/usr/include",1,3]])"), - TypedEq(R"([["/home/er",2,1]])"), - 1, - 3, - 1)); - EXPECT_CALL(deleteProjectPartsHeadersByIdStatement, write(TypedEq(2))); - EXPECT_CALL(insertProjectPartsHeadersStatement, write(TypedEq(2), TypedEq(5))); - EXPECT_CALL(insertProjectPartsHeadersStatement, write(TypedEq(2), TypedEq(6))); - EXPECT_CALL(deleteProjectPartsSourcesByIdStatement, write(TypedEq(2))); - EXPECT_CALL(insertProjectPartsSourcesStatement, write(TypedEq(2), TypedEq(7))); - EXPECT_CALL(insertProjectPartsSourcesStatement, write(TypedEq(2), TypedEq(8))); - EXPECT_CALL(databaseMock, commit()); - - storage.updateProjectParts({projectPart1, projectPart2}); -} - -TEST_F(ProjectPartsStorage, UpdateProjectPartsIsBusy) -{ - InSequence sequence; - - EXPECT_CALL(databaseMock, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(databaseMock, immediateBegin()); - EXPECT_CALL(updateProjectPartStatement, - write(TypedEq(1), - TypedEq(R"(["-m32"])"), - TypedEq(R"([["FOO","1",1]])"), - TypedEq(R"([["/include",1,3]])"), - TypedEq(R"([["/home/yi",2,1]])"), - 2, - 35, - 2)); - EXPECT_CALL(databaseMock, commit()); - - storage.updateProjectParts({projectPart1}); -} - -TEST_F(ProjectPartsStorage, FetchProjectPartArtefactBySourceIdCallsValueInStatement) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1)) - .WillRepeatedly(Return(artefact)); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchProjectPartArtefact(FilePathId{1}); -} - -TEST_F(ProjectPartsStorage, FetchProjectPartArtefactBySourceIdCallsValueInStatementIsBusy) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1)) - .WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(databaseMock, rollback()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1)) - .WillRepeatedly(Return(artefact)); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchProjectPartArtefact(FilePathId{1}); -} - -TEST_F(ProjectPartsStorage, FetchProjectPartArtefactBySourceIdReturnArtefact) -{ - EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1)) - .WillRepeatedly(Return(artefact)); - - auto result = storage.fetchProjectPartArtefact(FilePathId{1}); - - ASSERT_THAT(result, Eq(artefact)); -} - -TEST_F(ProjectPartsStorage, FetchProjectPartArtefactByProjectPartIdCallsValueInStatement) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(getProjectPartArtefactsByProjectPartId, valueReturnProjectPartArtefact(74)) - .WillRepeatedly(Return(artefact)); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchProjectPartArtefact(ProjectPartId{74}); -} - -TEST_F(ProjectPartsStorage, FetchProjectPartArtefactByProjectPartIdReturnArtefact) -{ - EXPECT_CALL(getProjectPartArtefactsByProjectPartId, valueReturnProjectPartArtefact(74)) - .WillRepeatedly(Return(artefact)); - - auto result = storage.fetchProjectPartArtefact(ProjectPartId{74}); - - ASSERT_THAT(result, Eq(artefact)); -} - -TEST_F(ProjectPartsStorage, FetchProjectPartArtefactByProjectPartIdReturnArtefactIsBusy) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(getProjectPartArtefactsByProjectPartId, valueReturnProjectPartArtefact(74)) - .WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(databaseMock, rollback()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(getProjectPartArtefactsByProjectPartId, valueReturnProjectPartArtefact(74)) - .WillRepeatedly(Return(artefact)); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchProjectPartArtefact(ProjectPartId{74}); -} - -TEST_F(ProjectPartsStorage, ResetDependentIndexingTimeStamps) -{ - InSequence s; - - EXPECT_CALL(databaseMock, immediateBegin()); - EXPECT_CALL(resetDependentIndexingTimeStampsStatement, write(TypedEq(3))); - EXPECT_CALL(resetDependentIndexingTimeStampsStatement, write(TypedEq(4))); - EXPECT_CALL(resetDependentIndexingTimeStampsStatement, write(TypedEq(7))); - EXPECT_CALL(resetDependentIndexingTimeStampsStatement, write(TypedEq(8))); - EXPECT_CALL(databaseMock, commit()); - - storage.resetIndexingTimeStamps({projectPart1, projectPart2}); -} - -TEST_F(ProjectPartsStorage, ResetDependentIndexingTimeStampsIsBusy) -{ - InSequence s; - - EXPECT_CALL(databaseMock, immediateBegin()).WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(databaseMock, immediateBegin()); - EXPECT_CALL(resetDependentIndexingTimeStampsStatement, write(TypedEq(3))); - EXPECT_CALL(resetDependentIndexingTimeStampsStatement, write(TypedEq(4))); - EXPECT_CALL(resetDependentIndexingTimeStampsStatement, write(TypedEq(7))); - EXPECT_CALL(resetDependentIndexingTimeStampsStatement, write(TypedEq(8))); - EXPECT_CALL(databaseMock, commit()); - - storage.resetIndexingTimeStamps({projectPart1, projectPart2}); -} - -TEST_F(ProjectPartsStorage, FetchAllProjectPartNamesAndIdsCalls) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchAllProjectPartNamesAndIdsStatement, valuesReturnProjectPartNameIds(_)) - .WillRepeatedly(Return(projectPartNameIds)); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchAllProjectPartNamesAndIds(); -} - -TEST_F(ProjectPartsStorage, FetchAllProjectPartNamesAndIdsCallsIsBusy) -{ - InSequence s; - - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchAllProjectPartNamesAndIdsStatement, valuesReturnProjectPartNameIds(_)) - .WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(databaseMock, rollback()); - EXPECT_CALL(databaseMock, deferredBegin()); - EXPECT_CALL(fetchAllProjectPartNamesAndIdsStatement, valuesReturnProjectPartNameIds(_)) - .WillRepeatedly(Return(projectPartNameIds)); - EXPECT_CALL(databaseMock, commit()); - - storage.fetchAllProjectPartNamesAndIds(); -} - -class ProjectPartsStorageSlow : public testing::Test, public Data -{ - using Storage = ClangBackEnd::ProjectPartsStorage; - -protected: - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer databaseInitializer{database}; - Storage storage{database}; - ClangBackEnd::BuildDependenciesStorage<> buildDependenciesStorage{database}; -}; - -TEST_F(ProjectPartsStorageSlow, FetchProjectPartName) -{ - auto id = storage.fetchProjectPartId("test"); - - auto name = storage.fetchProjectPartName(id); - - ASSERT_THAT(name, "test"); -} - -TEST_F(ProjectPartsStorageSlow, FetchNonExistingProjectPartName) -{ - ASSERT_THROW(storage.fetchProjectPartName(ClangBackEnd::ProjectPartId{1}), - ClangBackEnd::ProjectPartDoesNotExists); -} - -TEST_F(ProjectPartsStorageSlow, FetchProjectPartId) -{ - auto first = storage.fetchProjectPartId("test"); - - auto second = storage.fetchProjectPartId("test"); - - ASSERT_THAT(first, Eq(second)); -} - -TEST_F(ProjectPartsStorageSlow, FetchProjectPartIdUnguarded) -{ - auto first = storage.fetchProjectPartId("test"); - std::lock_guard lock{database}; - - auto second = storage.fetchProjectPartIdUnguarded("test"); - - ASSERT_THAT(first, Eq(second)); -} - -TEST_F(ProjectPartsStorageSlow, FetchProjectParts) -{ - projectPart1.projectPartId = storage.fetchProjectPartId("project1"); - projectPart2.projectPartId = storage.fetchProjectPartId("project2"); - storage.updateProjectParts({projectPart1, projectPart2}); - - auto projectParts = storage.fetchProjectParts( - {projectPart1.projectPartId, projectPart2.projectPartId}); - - ASSERT_THAT(projectParts, ElementsAre(projectPart1, projectPart2)); -} - -TEST_F(ProjectPartsStorageSlow, ResetDependentIndexingTimeStamps) -{ - buildDependenciesStorage.insertOrUpdateIndexingTimeStamps({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 34); - database.lock(); - buildDependenciesStorage.insertOrUpdateSourceDependencies( - {{3, 1}, {4, 1}, {1, 2}, {7, 5}, {8, 6}, {6, 5}, {9, 10}}); - database.unlock(); - - storage.resetIndexingTimeStamps({projectPart1, projectPart2}); - - ASSERT_THAT(buildDependenciesStorage.fetchIndexingTimeStamps(), - ElementsAre(SourceTimeStamp{1, 34}, - SourceTimeStamp{2, 34}, - SourceTimeStamp{3, 0}, - SourceTimeStamp{4, 0}, - SourceTimeStamp{5, 34}, - SourceTimeStamp{6, 34}, - SourceTimeStamp{7, 0}, - SourceTimeStamp{8, 0}, - SourceTimeStamp{9, 34}, - SourceTimeStamp{10, 34})); -} - -TEST_F(ProjectPartsStorageSlow, FetchAllProjectPartNamesAndIdsy) -{ - using ClangBackEnd::Internal::ProjectPartNameId; - auto id = storage.fetchProjectPartId("projectPartName"); - auto id2 = storage.fetchProjectPartId("projectPartName2"); - - auto values = storage.fetchAllProjectPartNamesAndIds(); - - ASSERT_THAT(values, - UnorderedElementsAre(ProjectPartNameId{"projectPartName", id}, - ProjectPartNameId{"projectPartName2", id2})); -} -} // namespace diff --git a/tests/unit/unittest/projectupdater-test.cpp b/tests/unit/unittest/projectupdater-test.cpp deleted file mode 100644 index b74a90877ac..00000000000 --- a/tests/unit/unittest/projectupdater-test.cpp +++ /dev/null @@ -1,542 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockfilepathcaching.h" -#include "mockpchmanagerclient.h" -#include "mockpchmanagernotifier.h" -#include "mockpchmanagerserver.h" -#include "mockprecompiledheaderstorage.h" -#include "mockprogressmanager.h" -#include "mockprojectpartsstorage.h" -#include "mocksqlitetransactionbackend.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -namespace { - -using testing::_; -using testing::ElementsAre; -using testing::SizeIs; -using testing::NiceMock; -using testing::AnyNumber; - -using ClangBackEnd::CompilerMacro; -using ClangBackEnd::FilePath; -using ClangBackEnd::IncludeSearchPath; -using ClangBackEnd::IncludeSearchPathType; -using ClangBackEnd::ProjectPartContainer; -using ClangBackEnd::V2::FileContainer; -using CppTools::CompilerOptionsBuilder; -using ProjectExplorer::HeaderPath; - -class ProjectUpdater : public testing::Test -{ -protected: - ClangBackEnd::FilePathId filePathId(Utils::SmallStringView path) - { - return filePathCache.filePathId(ClangBackEnd::FilePathView{path}); - } - - ClangBackEnd::FilePathIds filePathIds(const Utils::PathStringVector &paths) - { - return filePathCache.filePathIds(Utils::transform(paths, [] (const Utils::PathString &path) { - return ClangBackEnd::FilePathView(path); - })); - } - - void SetUp() override - { - project.rootProjectDirectoryPath = Utils::FilePath::fromString("project"); - projectPart.project = &project; - projectPart.files.push_back(header1ProjectFile); - projectPart.files.push_back(header2ProjectFile); - projectPart.files.push_back(source1ProjectFile); - projectPart.files.push_back(source2ProjectFile); - projectPart.files.push_back(nonActiveProjectFile); - projectPart.displayName = "projectb"; - projectPart.projectMacros = {{"FOO", "2"}, {"BAR", "1"}, {"POO", "3"}}; - projectPartId = projectPartsStorage.fetchProjectPartId(Utils::SmallString{projectPart.id()}); - - projectPart2.project = &project; - projectPart2.files.push_back(header2ProjectFile); - projectPart2.files.push_back(header1ProjectFile); - projectPart2.files.push_back(source2ProjectFile); - projectPart2.files.push_back(source1ProjectFile); - projectPart2.files.push_back(nonActiveProjectFile); - projectPart2.displayName = "projectaa"; - projectPart2.projectMacros = {{"BAR", "1"}, {"FOO", "2"}}; - projectPartId2 = projectPartsStorage.fetchProjectPartId(Utils::SmallString{projectPart2.id()}); - - nonBuildingProjectPart.files.push_back(cannotBuildSourceProjectFile); - nonBuildingProjectPart.displayName = "nonbuilding"; - nonBuildingProjectPart.selectedForBuilding = false; - - Utils::SmallStringVector arguments{ - ClangPchManager::ProjectUpdater::toolChainArguments(&projectPart)}; - Utils::SmallStringVector arguments2{ - ClangPchManager::ProjectUpdater::toolChainArguments(&projectPart2)}; - - expectedContainer = {projectPartId, - arguments.clone(), - Utils::clone(compilerMacros), - {{"project/.pre_includes", 1, ClangBackEnd::IncludeSearchPathType::System}, - {CLANG_INCLUDE_DIR, 2, ClangBackEnd::IncludeSearchPathType::BuiltIn}}, - {}, - {filePathId(headerPaths[1])}, - {filePathIds(sourcePaths)}, - Utils::Language::Cxx, - Utils::LanguageVersion::LatestCxx, - Utils::LanguageExtension::None}; - expectedContainer2 = {projectPartId2, - arguments2.clone(), - Utils::clone(compilerMacros), - {{"project/.pre_includes", 1, ClangBackEnd::IncludeSearchPathType::System}, - {CLANG_INCLUDE_DIR, 2, ClangBackEnd::IncludeSearchPathType::BuiltIn}}, - {}, - {filePathId(headerPaths[1])}, - {filePathIds(sourcePaths)}, - Utils::Language::Cxx, - Utils::LanguageVersion::LatestCxx, - Utils::LanguageExtension::None}; - - auto settings = settingsManager.settings(&project); - settings->saveMacros({{"POO", "3", Utils::NameValueItem::Unset}}); - } - -protected: - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer initializer{database}; - ClangBackEnd::FilePathCaching filePathCache{database}; - NiceMock mockPchCreationProgressManager; - NiceMock mockDependencyCreationProgressManager; - ClangBackEnd::ProjectPartsStorage projectPartsStorage{database}; - ClangPchManager::PchManagerClient pchManagerClient{mockPchCreationProgressManager, - mockDependencyCreationProgressManager}; - MockPchManagerNotifier mockPchManagerNotifier{pchManagerClient}; - NiceMock mockPchManagerServer; - ClangPchManager::ClangIndexingSettingsManager settingsManager; - ClangPchManager::ProjectUpdater updater{mockPchManagerServer, - filePathCache, - projectPartsStorage, - settingsManager}; - ClangBackEnd::ProjectPartId projectPartId; - ClangBackEnd::ProjectPartId projectPartId2; - Utils::PathStringVector headerPaths = {"/path/to/header1.h", "/path/to/header2.h"}; - Utils::PathStringVector sourcePaths = {"/path/to/source1.cpp", "/path/to/source2.cpp"}; - ClangBackEnd::CompilerMacros compilerMacros = {{"BAR", "1", 1}, {"FOO", "2", 2}}; - CppTools::ProjectFile header1ProjectFile{QString(headerPaths[0]), CppTools::ProjectFile::CXXHeader}; - CppTools::ProjectFile header2ProjectFile{QString(headerPaths[1]), CppTools::ProjectFile::CXXHeader}; - CppTools::ProjectFile source1ProjectFile{QString(sourcePaths[0]), CppTools::ProjectFile::CXXSource}; - CppTools::ProjectFile source2ProjectFile{QString(sourcePaths[1]), - CppTools::ProjectFile::CXXSource}; - CppTools::ProjectFile cannotBuildSourceProjectFile{QString("/cannot/build"), - CppTools::ProjectFile::CXXSource}; - CppTools::ProjectFile nonActiveProjectFile{QString("/foo"), CppTools::ProjectFile::CXXSource, false}; - ProjectExplorer::Project project; - CppTools::ProjectPart projectPart; - CppTools::ProjectPart projectPart2; - CppTools::ProjectPart nonBuildingProjectPart; - ProjectPartContainer expectedContainer; - ProjectPartContainer expectedContainer2; - FileContainer generatedFile{{"/path/to", "header1.h"}, - filePathCache.filePathId(FilePath{"/path/to", "header1.h"}), - "content", - {}}; - FileContainer generatedFile2{{"/path/to2", "header1.h"}, - filePathCache.filePathId(FilePath{"/path/to2", "header1.h"}), - "content", - {}}; - FileContainer generatedFile3{{"/path/to", "header2.h"}, - filePathCache.filePathId(FilePath{"/path/to", "header2.h"}), - "content", - {}}; -}; - -TEST_F(ProjectUpdater, CallUpdateProjectParts) -{ - std::vector projectParts = {&projectPart2, &projectPart}; - ClangBackEnd::UpdateProjectPartsMessage message{ - {expectedContainer.clone(), expectedContainer2.clone()}, {"toolChainArgument"}}; - updater.updateGeneratedFiles({generatedFile}); - - EXPECT_CALL(mockPchManagerServer, updateProjectParts(message)); - - updater.updateProjectParts(projectParts, {"toolChainArgument"}); -} - -TEST_F(ProjectUpdater, CallUpdateGeneratedFilesWithSortedEntries) -{ - ClangBackEnd::UpdateGeneratedFilesMessage message{{generatedFile, generatedFile3, generatedFile2}}; - - EXPECT_CALL(mockPchManagerServer, updateGeneratedFiles(message)); - - updater.updateGeneratedFiles({generatedFile2, generatedFile3, generatedFile}); -} - -TEST_F(ProjectUpdater, GeneratedFilesAddedAreSorted) -{ - updater.updateGeneratedFiles({generatedFile2, generatedFile3, generatedFile}); - - ASSERT_THAT(updater.generatedFiles().fileContainers(), - ElementsAre(generatedFile, generatedFile3, generatedFile2)); -} - -TEST_F(ProjectUpdater, GeneratedFilesAddedToExcludePaths) -{ - updater.updateGeneratedFiles({generatedFile2, generatedFile3, generatedFile}); - - ASSERT_THAT(updater.excludedPaths(), ElementsAre(generatedFile.filePath, - generatedFile3.filePath, - generatedFile2.filePath)); -} - -TEST_F(ProjectUpdater, CallRemoveGeneratedFiles) -{ - ClangBackEnd::RemoveGeneratedFilesMessage message{{{"/path/to/header1.h"}}}; - - EXPECT_CALL(mockPchManagerServer, removeGeneratedFiles(message)); - - updater.removeGeneratedFiles({{"/path/to/header1.h"}}); -} - -TEST_F(ProjectUpdater, GeneratedFilesRemovedFromExcludePaths) -{ - updater.updateGeneratedFiles({generatedFile}); - - updater.removeGeneratedFiles({generatedFile.filePath}); - - ASSERT_THAT(updater.excludedPaths(), IsEmpty()); -} - -TEST_F(ProjectUpdater, CallRemoveProjectParts) -{ - ClangBackEnd::RemoveProjectPartsMessage message{{projectPartId, projectPartId2}}; - - EXPECT_CALL(mockPchManagerServer, removeProjectParts(message)); - - updater.removeProjectParts({projectPartId2, projectPartId}); -} - -TEST_F(ProjectUpdater, CallPrecompiledHeaderRemovedInPchManagerProjectUpdater) -{ - ClangPchManager::ClangIndexingSettingsManager settingManager; - ClangPchManager::PchManagerProjectUpdater pchUpdater{mockPchManagerServer, - pchManagerClient, - filePathCache, - projectPartsStorage, - settingManager}; - ClangBackEnd::RemoveProjectPartsMessage message{{projectPartId, projectPartId2}}; - - EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderRemoved(projectPartId)); - EXPECT_CALL(mockPchManagerNotifier, precompiledHeaderRemoved(projectPartId2)); - - pchUpdater.removeProjectParts({projectPartId, projectPartId2}); -} - -TEST_F(ProjectUpdater, ConvertProjectPartToProjectPartContainer) -{ - updater.setExcludedPaths({"/path/to/header1.h"}); - updater.fetchProjectPartIds({&projectPart}); - - auto container = updater.toProjectPartContainer(&projectPart); - - ASSERT_THAT(container, expectedContainer); -} - -TEST_F(ProjectUpdater, ConvertProjectPartToProjectPartContainersHaveSameSizeLikeProjectParts) -{ - updater.fetchProjectPartIds({&projectPart, &nonBuildingProjectPart}); - - auto containers = updater.toProjectPartContainers( - {&projectPart, &projectPart, &nonBuildingProjectPart}); - - ASSERT_THAT(containers, SizeIs(2)); -} - -TEST_F(ProjectUpdater, ProjectPartIdsPrefetchingInsideTransaction) -{ - InSequence s; - CppTools::ProjectPart projectPart; - projectPart.project = &project; - projectPart.displayName = "project"; - Utils::SmallString projectPartName = projectPart.id(); - NiceMock mockSqliteTransactionBackend; - NiceMock mockProjectPartsStorage; - ON_CALL(mockProjectPartsStorage, transactionBackend()) - .WillByDefault(ReturnRef(mockSqliteTransactionBackend)); - ClangPchManager::ClangIndexingSettingsManager settingsManager; - ClangPchManager::ProjectUpdater updater{mockPchManagerServer, - filePathCache, - mockProjectPartsStorage, - settingsManager}; - - EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin()); - EXPECT_CALL(mockProjectPartsStorage, fetchProjectPartIdUnguarded(Eq(projectPartName))).WillOnce(Return(1)); - EXPECT_CALL(mockSqliteTransactionBackend, commit()); - - updater.fetchProjectPartIds({&projectPart}); -} - -TEST_F(ProjectUpdater, CreateSortedExcludedPaths) -{ - auto excludedPaths = updater.createExcludedPaths({generatedFile2, generatedFile3, generatedFile}); - - ASSERT_THAT(excludedPaths, ElementsAre(ClangBackEnd::FilePath{"/path/to/header1.h"}, - ClangBackEnd::FilePath{"/path/to/header2.h"}, - ClangBackEnd::FilePath{"/path/to2/header1.h"})); -} - -TEST_F(ProjectUpdater, CreateSortedCompilerMacros) -{ - auto paths = updater.createCompilerMacros({{"DEFINE", "1"}, {"FOO", "2"}, {"BAR", "1"}}, {}); - - ASSERT_THAT(paths, ElementsAre(CompilerMacro{"BAR", "1", 1}, - CompilerMacro{"FOO", "2", 2}, - CompilerMacro{"DEFINE", "1", 3})); -} - -TEST_F(ProjectUpdater, FilterCompilerMacros) -{ - auto paths = updater.createCompilerMacros({{"DEFINE", "1"}, - {"QT_TESTCASE_BUILDDIR", "2"}, - {"BAR", "1"}}, - {}); - - ASSERT_THAT(paths, ElementsAre(CompilerMacro{"BAR", "1", 1}, CompilerMacro{"DEFINE", "1", 3})); -} - -TEST_F(ProjectUpdater, FilterSettingsMacros) -{ - auto paths = updater.createCompilerMacros({{"YI", "1"}, {"SAN", "3"}, {"SE", "4"}, {"WU", "5"}}, - {{"SE", "44", Utils::NameValueItem::Unset}, - {"ER", "2", Utils::NameValueItem::SetEnabled}, - {"WU", "5", Utils::NameValueItem::Unset}}); - - ASSERT_THAT(paths, - ElementsAre(CompilerMacro{"ER", "2", 3}, - CompilerMacro{"SE", "4", 3}, - CompilerMacro{"YI", "1", 1}, - CompilerMacro{"SAN", "3", 2})); -} - -TEST_F(ProjectUpdater, CreateSortedIncludeSearchPaths) -{ - CppTools::ProjectPart projectPart; - projectPart.project = &project; - ProjectExplorer::HeaderPath includePath{"/to/path1", ProjectExplorer::HeaderPathType::User}; - ProjectExplorer::HeaderPath includePath2{"/to/path2", ProjectExplorer::HeaderPathType::User}; - ProjectExplorer::HeaderPath invalidPath; - ProjectExplorer::HeaderPath frameworkPath{"/framework/path", - ProjectExplorer::HeaderPathType::Framework}; - ProjectExplorer::HeaderPath builtInPath{"/builtin/path", ProjectExplorer::HeaderPathType::BuiltIn}; - ProjectExplorer::HeaderPath systemPath{"/system/path", ProjectExplorer::HeaderPathType::System}; - projectPart.headerPaths = { - systemPath, builtInPath, frameworkPath, includePath2, includePath, invalidPath}; - - auto paths = updater.createIncludeSearchPaths(projectPart); - - ASSERT_THAT( - paths.system, - ElementsAre(Eq(IncludeSearchPath{systemPath.path, 2, IncludeSearchPathType::System}), - Eq(IncludeSearchPath{builtInPath.path, 5, IncludeSearchPathType::BuiltIn}), - Eq(IncludeSearchPath{frameworkPath.path, 3, IncludeSearchPathType::Framework}), - Eq(IncludeSearchPath{"project/.pre_includes", 1, IncludeSearchPathType::System}), - Eq(IncludeSearchPath{CLANG_INCLUDE_DIR, - 4, - ClangBackEnd::IncludeSearchPathType::BuiltIn}))); - ASSERT_THAT(paths.project, - ElementsAre(Eq(IncludeSearchPath{includePath.path, 2, IncludeSearchPathType::User}), - Eq(IncludeSearchPath{includePath2.path, 1, IncludeSearchPathType::User}))); -} - -TEST_F(ProjectUpdater, ToolChainArguments) -{ - projectPart.toolChainTargetTriple = "target"; - projectPart.extraCodeModelFlags.push_back("extraflags"); - projectPart.compilerFlags.push_back("-fPIC"); - projectPart.projectConfigFile = "config.h"; - - auto arguments = updater.toolChainArguments(&projectPart); - - ASSERT_THAT(arguments, - ElementsAre(QString{"-m32"}, - QString{"extraflags"}, - QString{"-include"}, - QString{"config.h"})); -} - -TEST_F(ProjectUpdater, ToolChainArgumentsMSVC) -{ - projectPart.toolChainTargetTriple = "target"; - projectPart.extraCodeModelFlags.push_back("extraflags"); - projectPart.toolchainType = ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID; - projectPart.isMsvc2015Toolchain = true; - - auto arguments = updater.toolChainArguments(&projectPart); - - ASSERT_THAT(arguments, - ElementsAre(QString{"-m32"}, - QString{"extraflags"}, - QString{"-U__clang__"}, - QString{"-U__clang_major__"}, - QString{"-U__clang_minor__"}, - QString{"-U__clang_patchlevel__"}, - QString{"-U__clang_version__"}, - QString{"-U__cpp_aggregate_bases"}, - QString{"-U__cpp_aggregate_nsdmi"}, - QString{"-U__cpp_alias_templates"}, - QString{"-U__cpp_aligned_new"}, - QString{"-U__cpp_attributes"}, - QString{"-U__cpp_binary_literals"}, - QString{"-U__cpp_capture_star_this"}, - QString{"-U__cpp_constexpr"}, - QString{"-U__cpp_constexpr_in_decltype"}, - QString{"-U__cpp_decltype"}, - QString{"-U__cpp_decltype_auto"}, - QString{"-U__cpp_deduction_guides"}, - QString{"-U__cpp_delegating_constructors"}, - QString{"-U__cpp_digit_separators"}, - QString{"-U__cpp_enumerator_attributes"}, - QString{"-U__cpp_exceptions"}, - QString{"-U__cpp_fold_expressions"}, - QString{"-U__cpp_generic_lambdas"}, - QString{"-U__cpp_guaranteed_copy_elision"}, - QString{"-U__cpp_hex_float"}, - QString{"-U__cpp_if_constexpr"}, - QString{"-U__cpp_impl_destroying_delete"}, - QString{"-U__cpp_inheriting_constructors"}, - QString{"-U__cpp_init_captures"}, - QString{"-U__cpp_initializer_lists"}, - QString{"-U__cpp_inline_variables"}, - QString{"-U__cpp_lambdas"}, - QString{"-U__cpp_namespace_attributes"}, - QString{"-U__cpp_nested_namespace_definitions"}, - QString{"-U__cpp_noexcept_function_type"}, - QString{"-U__cpp_nontype_template_args"}, - QString{"-U__cpp_nontype_template_parameter_auto"}, - QString{"-U__cpp_nsdmi"}, - QString{"-U__cpp_range_based_for"}, - QString{"-U__cpp_raw_strings"}, - QString{"-U__cpp_ref_qualifiers"}, - QString{"-U__cpp_return_type_deduction"}, - QString{"-U__cpp_rtti"}, - QString{"-U__cpp_rvalue_references"}, - QString{"-U__cpp_static_assert"}, - QString{"-U__cpp_structured_bindings"}, - QString{"-U__cpp_template_auto"}, - QString{"-U__cpp_threadsafe_static_init"}, - QString{"-U__cpp_unicode_characters"}, - QString{"-U__cpp_unicode_literals"}, - QString{"-U__cpp_user_defined_literals"}, - QString{"-U__cpp_variable_templates"}, - QString{"-U__cpp_variadic_templates"}, - QString{"-U__cpp_variadic_using"})); -} - -TEST_F(ProjectUpdater, FetchProjectPartName) -{ - updater.updateProjectParts({&projectPart}, {}); - - auto projectPartName = updater.fetchProjectPartName(1); - - ASSERT_THAT(projectPartName, Eq(QString{" projectb"})); -} - -TEST_F(ProjectUpdater, AddProjectFilesToFilePathCache) -{ - NiceMock mockFilePathCaching; - ClangPchManager::ProjectUpdater updater{mockPchManagerServer, - mockFilePathCaching, - projectPartsStorage, - settingsManager}; - - EXPECT_CALL(mockFilePathCaching, - addFilePaths(UnorderedElementsAre(Eq(headerPaths[0]), - Eq(headerPaths[1]), - Eq(sourcePaths[0]), - Eq(sourcePaths[1])))); - - updater.updateProjectParts({&projectPart}, {}); -} - -TEST_F(ProjectUpdater, FillProjectPartIdCacheAtCreation) -{ - NiceMock mockProjectPartsStorage; - - EXPECT_CALL(mockProjectPartsStorage, fetchAllProjectPartNamesAndIds()); - - ClangPchManager::ProjectUpdater updater{mockPchManagerServer, - filePathCache, - mockProjectPartsStorage, - settingsManager}; -} - -TEST_F(ProjectUpdater, DontFetchProjectPartIdFromDatabaseIfItIsInCache) -{ - projectPart.files.clear(); - NiceMock mockSqliteTransactionBackend; - NiceMock mockProjectPartsStorage; - ON_CALL(mockProjectPartsStorage, transactionBackend()) - .WillByDefault(ReturnRef(mockSqliteTransactionBackend)); - ON_CALL(mockProjectPartsStorage, fetchAllProjectPartNamesAndIds()) - .WillByDefault(Return( - ClangBackEnd::Internal::ProjectPartNameIds{{Utils::PathString(projectPart.id()), 55}})); - ClangPchManager::ProjectUpdater updater{mockPchManagerServer, - filePathCache, - mockProjectPartsStorage, - settingsManager}; - - EXPECT_CALL(mockSqliteTransactionBackend, deferredBegin()).Times(0); - EXPECT_CALL(mockProjectPartsStorage, fetchProjectPartId(_)).Times(0); - EXPECT_CALL(mockProjectPartsStorage, fetchProjectPartIdUnguarded(_)).Times(0); - EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0); - - updater.updateProjectParts({&projectPart}, {}); -} - -} // namespace diff --git a/tests/unit/unittest/refactoringclient-test.cpp b/tests/unit/unittest/refactoringclient-test.cpp deleted file mode 100644 index a07f7cea147..00000000000 --- a/tests/unit/unittest/refactoringclient-test.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" -#include "mocksearchhandle.h" -#include "mockfilepathcaching.h" -#include "mockprogressmanager.h" -#include "mocksymbolquery.h" - -#include -#include -#include -#include - -#include - -#include -#include -#include - -#include - -#include -#include -#include - -namespace { - -using CppTools::CompilerOptionsBuilder; - -using ClangRefactoring::RefactoringEngine; - -using ClangBackEnd::FilePath; -using ClangBackEnd::FilePathId; -using ClangBackEnd::SourceLocationsForRenamingMessage; -using ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage; -using ClangBackEnd::SourceRangesForQueryMessage; - -using Utils::PathString; -using Utils::SmallString; -using Utils::SmallStringVector; - -class RefactoringClient : public ::testing::Test -{ - void SetUp() - { - using Filter = ClangRefactoring::ClangQueryProjectsFindFilter; - - client.setRefactoringEngine(&engine); - - projectPart = CppTools::ProjectPart::Ptr(new CppTools::ProjectPart); - projectPart->project = &project; - projectPart->files.push_back(projectFile); - - commandLine = Filter::compilerArguments(projectPart.data(), projectFile.kind); - - client.setSearchHandle(&mockSearchHandle); - client.setExpectedResultCount(1); - - ON_CALL(mockFilePathCaching, filePath(Eq(FilePathId{1}))) - .WillByDefault(Return(FilePath(PathString("/path/to/file")))); - ON_CALL(mockFilePathCaching, filePath(Eq(FilePathId{42}))) - .WillByDefault(Return(clangBackEndFilePath)); - } - -protected: - NiceMock mockFilePathCaching; - NiceMock mockSearchHandle; - NiceMock mockSymbolQuery; - QBuffer ioDevice; - MockFunction mockLocalRenaming; - NiceMock mockProgressManager; - ClangRefactoring::RefactoringClient client{mockProgressManager}; - ClangBackEnd::RefactoringServerProxy serverProxy{&client, &ioDevice}; - RefactoringEngine engine{serverProxy, client, mockFilePathCaching, mockSymbolQuery}; - QString fileContent{QStringLiteral("int x;\nint y;")}; - QTextDocument textDocument{fileContent}; - QTextCursor cursor{&textDocument}; - QString qStringFilePath{QStringLiteral("/home/user/file.cpp")}; - Utils::FilePath filePath{Utils::FilePath::fromString(qStringFilePath)}; - ClangBackEnd::FilePath clangBackEndFilePath{qStringFilePath}; - SmallStringVector commandLine; - ProjectExplorer::Project project; - CppTools::ProjectPart::Ptr projectPart; - CppTools::ProjectFile projectFile{qStringFilePath, CppTools::ProjectFile::CXXSource}; - SourceRangesForQueryMessage queryResultMessage{{{{42, 1, 1, 0, 1, 5, 4, ""}, - {42, 2, 1, 5, 2, 5, 10, ""}}}}; - SourceRangesForQueryMessage emptyQueryResultMessage; -}; - -TEST_F(RefactoringClient, CallAddResultsForEmptyQueryMessage) -{ - EXPECT_CALL(mockSearchHandle, addResult(_ ,_ ,_)) - .Times(0); - - client.sourceRangesForQueryMessage(std::move(emptyQueryResultMessage)); -} - -TEST_F(RefactoringClient, CallAddResultsForQueryMessage) -{ - EXPECT_CALL(mockSearchHandle, addResult(_ ,_ ,_)) - .Times(2); - - client.sourceRangesForQueryMessage(std::move(queryResultMessage)); -} - -TEST_F(RefactoringClient, CallFinishSearchForEmptyQueryMessage) -{ - EXPECT_CALL(mockSearchHandle, finishSearch()) - .Times(1); - - client.sourceRangesForQueryMessage(std::move(emptyQueryResultMessage)); -} - -TEST_F(RefactoringClient, CallFinishSearchQueryMessage) -{ - EXPECT_CALL(mockSearchHandle, finishSearch()) - .Times(1); - - client.sourceRangesForQueryMessage(std::move(queryResultMessage)); -} - -TEST_F(RefactoringClient, CallFinishSearchForTwoQueryMessages) -{ - client.setExpectedResultCount(2); - - EXPECT_CALL(mockSearchHandle, finishSearch()) - .Times(1); - - client.sourceRangesForQueryMessage(std::move(queryResultMessage)); - client.sourceRangesForQueryMessage(std::move(queryResultMessage)); -} - -TEST_F(RefactoringClient, CallSetExpectedResultCountInSearchHandle) -{ - EXPECT_CALL(mockSearchHandle, setExpectedResultCount(3)) - .Times(1); - - client.setExpectedResultCount(3); -} - -TEST_F(RefactoringClient, ResultCounterIsOneAfterQueryMessage) -{ - client.sourceRangesForQueryMessage(std::move(queryResultMessage)); - - ASSERT_THAT(client.resultCounter(), 1); -} - -TEST_F(RefactoringClient, ResultCounterIsSetInSearchHandleToOne) -{ - EXPECT_CALL(mockSearchHandle, setResultCounter(1)) - .Times(1); - - client.sourceRangesForQueryMessage(std::move(queryResultMessage)); -} - -TEST_F(RefactoringClient, ResultCounterIsSetInSearchHandleToTwo) -{ - client.sourceRangesForQueryMessage(std::move(queryResultMessage)); - - EXPECT_CALL(mockSearchHandle, setResultCounter(2)) - .Times(1); - - client.sourceRangesForQueryMessage(std::move(queryResultMessage)); -} - -TEST_F(RefactoringClient, ResultCounterIsZeroAfterSettingExpectedResultCount) -{ - client.sourceRangesForQueryMessage(std::move(queryResultMessage)); - - client.setExpectedResultCount(3); - - ASSERT_THAT(client.resultCounter(), 0); -} - -TEST_F(RefactoringClient, XXX) -{ - const Core::Search::TextRange textRange{{1,0},{1,0}}; - const ClangBackEnd::SourceRangeWithTextContainer sourceRange{1, 1, 1, 1, 1, 1, 1, "function"}; - - EXPECT_CALL(mockSearchHandle, addResult(QString("/path/to/file"), QString("function"), textRange)) - .Times(1); - - client.addSearchResult(sourceRange); -} - -TEST_F(RefactoringClient, SetProgress) -{ - EXPECT_CALL(mockProgressManager, setProgress(10, 20)); - - client.progress({ClangBackEnd::ProgressType::Indexing, 10, 20}); -} -} diff --git a/tests/unit/unittest/refactoringclientserverinprocess-test.cpp b/tests/unit/unittest/refactoringclientserverinprocess-test.cpp deleted file mode 100644 index 344eb08f03c..00000000000 --- a/tests/unit/unittest/refactoringclientserverinprocess-test.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockrefactoringclient.h" -#include "mockrefactoringserver.h" - -#include -#include -#include -#include - -#include -#include -#include - -#include - -using namespace ClangBackEnd; - -namespace { - -using ::testing::Args; -using ::testing::Property; -using ::testing::Eq; - -using ClangBackEnd::RemoveGeneratedFilesMessage; -using ClangBackEnd::RemoveProjectPartsMessage; -using ClangBackEnd::UpdateProjectPartsMessage; -using ClangBackEnd::UpdateGeneratedFilesMessage; -using ClangBackEnd::V2::FileContainer; -using ClangBackEnd::ProjectPartContainer; - -class RefactoringClientServerInProcess : public ::testing::Test -{ -protected: - RefactoringClientServerInProcess(); - - void SetUp(); - void TearDown(); - - void scheduleServerMessages(); - void scheduleClientMessages(); - -protected: - QBuffer buffer; - MockRefactoringClient mockRefactoringClient; - MockRefactoringServer mockRefactoringServer; - - ClangBackEnd::RefactoringServerProxy serverProxy; - ClangBackEnd::RefactoringClientProxy clientProxy; -}; - -TEST_F(RefactoringClientServerInProcess, SendEndMessage) -{ - EXPECT_CALL(mockRefactoringServer, end()); - - serverProxy.end(); - scheduleServerMessages(); -} - -TEST_F(RefactoringClientServerInProcess, SendAliveMessage) -{ - EXPECT_CALL(mockRefactoringClient, alive()); - - clientProxy.alive(); - scheduleClientMessages(); -} - -TEST_F(RefactoringClientServerInProcess, SourceRangesAndDiagnosticsForQueryMessage) -{ - ClangBackEnd::SourceRangesContainer sourceRangesContainer; - std::vector diagnosticContainers; - ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage message(std::move(sourceRangesContainer), - std::move(diagnosticContainers)); - - EXPECT_CALL(mockRefactoringClient, sourceRangesAndDiagnosticsForQueryMessage(message)); - - clientProxy.sourceRangesAndDiagnosticsForQueryMessage(message.clone()); - scheduleClientMessages(); -} - -TEST_F(RefactoringClientServerInProcess, SourceRangesForQueryMessage) -{ - ClangBackEnd::SourceRangesContainer sourceRangesContainer; - ClangBackEnd::SourceRangesForQueryMessage message(std::move(sourceRangesContainer)); - - EXPECT_CALL(mockRefactoringClient, sourceRangesForQueryMessage(message)); - - clientProxy.sourceRangesForQueryMessage(message.clone()); - scheduleClientMessages(); -} - -TEST_F(RefactoringClientServerInProcess, SendProgressMessage) -{ - ClangBackEnd::ProgressMessage message{ClangBackEnd::ProgressType::PrecompiledHeader, 10, 50}; - - - EXPECT_CALL(mockRefactoringClient, progress(message)); - - clientProxy.progress(message.clone()); - scheduleClientMessages(); -} - -TEST_F(RefactoringClientServerInProcess, RequestSourceRangesAndDiagnosticsForQueryMessage) -{ - RequestSourceRangesForQueryMessage message{ - "functionDecl()", - {{{TESTDATA_DIR, "query_simplefunction.cpp"}, 1, "void f();", {"cc"}, 1}}, - {{{TESTDATA_DIR, "query_simplefunction.h"}, 2, "void f();", {}, 1}}}; - - EXPECT_CALL(mockRefactoringServer, requestSourceRangesForQueryMessage(message)); - - serverProxy.requestSourceRangesForQueryMessage(message.clone()); - scheduleServerMessages(); -} - -TEST_F(RefactoringClientServerInProcess, RequestSourceRangesForQueryMessage) -{ - RequestSourceRangesForQueryMessage message{ - "functionDecl()", - {{{TESTDATA_DIR, "query_simplefunction.cpp"}, - 1, - "void f();", - { - "cc", - }, - 1}}, - {{{TESTDATA_DIR, "query_simplefunction.h"}, 2, "void f();", {}, 1}}}; - - EXPECT_CALL(mockRefactoringServer, requestSourceRangesForQueryMessage(message)); - - serverProxy.requestSourceRangesForQueryMessage(message.clone()); - scheduleServerMessages(); -} - -TEST_F(RefactoringClientServerInProcess, SendUpdateProjectPartsMessage) -{ - ProjectPartContainer projectPart2{ - 1, - {"-x", "c++-header", "-Wno-pragma-once-outside-header"}, - {{"DEFINE", "1", 1}}, - {IncludeSearchPath{"/system/path", 2, IncludeSearchPathType::System}, - IncludeSearchPath{"/builtin/path", 3, IncludeSearchPathType::BuiltIn}, - IncludeSearchPath{"/framework/path", 1, IncludeSearchPathType::System}}, - {IncludeSearchPath{"/to/path1", 1, IncludeSearchPathType::User}, - IncludeSearchPath{"/to/path2", 2, IncludeSearchPathType::User}}, - {{1, 1}}, - {{1, 2}}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::All}; - UpdateProjectPartsMessage message{{projectPart2}, {"toolChainArgument"}}; - - EXPECT_CALL(mockRefactoringServer, updateProjectParts(message)); - - serverProxy.updateProjectParts(message.clone()); - scheduleServerMessages(); -} - -TEST_F(RefactoringClientServerInProcess, SendUpdateGeneratedFilesMessage) -{ - FileContainer fileContainer{{"/path/to/", "file"}, 1, "content", {}}; - UpdateGeneratedFilesMessage message{{fileContainer}}; - - EXPECT_CALL(mockRefactoringServer, updateGeneratedFiles(message)); - - serverProxy.updateGeneratedFiles(message.clone()); - scheduleServerMessages(); -} - -TEST_F(RefactoringClientServerInProcess, SendRemoveProjectPartsMessage) -{ - RemoveProjectPartsMessage message{{1, 2}}; - - EXPECT_CALL(mockRefactoringServer, removeProjectParts(message)); - - serverProxy.removeProjectParts(message.clone()); - scheduleServerMessages(); -} - -TEST_F(RefactoringClientServerInProcess, SendRemoveGeneratedFilesMessage) -{ - RemoveGeneratedFilesMessage message{{{"/path/to/", "file"}}}; - - EXPECT_CALL(mockRefactoringServer, removeGeneratedFiles(message)); - - serverProxy.removeGeneratedFiles(message.clone()); - scheduleServerMessages(); -} - -TEST_F(RefactoringClientServerInProcess, CancelMessage) -{ - EXPECT_CALL(mockRefactoringServer, cancel()); - - serverProxy.cancel(); - scheduleServerMessages(); -} - - -RefactoringClientServerInProcess::RefactoringClientServerInProcess() - : serverProxy(&mockRefactoringClient, &buffer), - clientProxy(&mockRefactoringServer, &buffer) -{ -} - -void RefactoringClientServerInProcess::SetUp() -{ - buffer.open(QIODevice::ReadWrite); -} - -void RefactoringClientServerInProcess::TearDown() -{ - buffer.close(); -} - -void RefactoringClientServerInProcess::scheduleServerMessages() -{ - buffer.seek(0); - clientProxy.readMessages(); - buffer.buffer().clear(); -} - -void RefactoringClientServerInProcess::scheduleClientMessages() -{ - buffer.seek(0); - serverProxy.readMessages(); - buffer.buffer().clear(); -} - -} diff --git a/tests/unit/unittest/refactoringcompilationdatabase-test.cpp b/tests/unit/unittest/refactoringcompilationdatabase-test.cpp deleted file mode 100644 index 5af5325e488..00000000000 --- a/tests/unit/unittest/refactoringcompilationdatabase-test.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" -#include "filesystem-utilities.h" - -#include -#include - -#include - -#include - -using testing::Contains; -using testing::IsEmpty; -using testing::Not; -using testing::PrintToString; - -namespace { - -MATCHER_P3(IsCompileCommand, - directory, - filePath, - commandLine, - std::string(negation ? "isn't" : "is") + " compile command with directory " - + PrintToString(directory) + ", file name " + PrintToString(filePath) - + " and command line " + PrintToString(commandLine)) -{ - if (arg.Directory != std::string(directory) || arg.Filename != std::string(filePath) - || arg.CommandLine != commandLine) - return false; - - return true; -} - -class RefactoringCompilationDatabase : public ::testing::Test -{ -protected: - RefactoringCompilationDatabase() - { - database.addFile(ClangBackEnd::NativeFilePathView{temporarySourceFilePath}, - {"cc", toNativePath(temporaryDirectoryPath + "/data.cpp"), "-DNO_DEBUG"}); - } - -protected: - ClangBackEnd::RefactoringCompilationDatabase database; - Utils::SmallString temporaryDirectoryPath = QDir::toNativeSeparators(Utils::TemporaryDirectory::masterDirectoryPath()); - Utils::SmallString temporarySourceFilePath = QDir::toNativeSeparators(Utils::TemporaryDirectory::masterDirectoryPath() + "/data.cpp"); - -}; - -TEST_F(RefactoringCompilationDatabase, GetAllFilesContainsTranslationUnit) -{ - auto filePaths = database.getAllFiles(); - - ASSERT_THAT(filePaths, Contains(std::string(temporarySourceFilePath))); -} - -TEST_F(RefactoringCompilationDatabase, CompileCommandForFilePath) -{ - auto compileCommands = database.getAllCompileCommands(); - - ASSERT_THAT(compileCommands, - Contains(IsCompileCommand(temporaryDirectoryPath, - toNativePath(temporaryDirectoryPath + "/data.cpp"), - std::vector{"cc", - std::string(toNativePath( - temporaryDirectoryPath - + "/data.cpp")), - "-DNO_DEBUG"}))); -} - -TEST_F(RefactoringCompilationDatabase, NoCompileCommandForFilePath) -{ - auto compileCommands = database.getAllCompileCommands(); - - ASSERT_THAT(compileCommands, - Not(Contains(IsCompileCommand(temporaryDirectoryPath, - toNativePath(temporaryDirectoryPath + "/data.cpp2"), - std::vector{"cc", - std::string(toNativePath( - temporaryDirectoryPath - + "/data.cpp")), - "-DNO_DEBUG"})))); -} - -TEST_F(RefactoringCompilationDatabase, FilePaths) -{ - auto filePaths = database.getAllFiles(); - - ASSERT_THAT(filePaths, Contains(std::string(temporarySourceFilePath))); -} -} // namespace diff --git a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp deleted file mode 100644 index 89df28be9f2..00000000000 --- a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp +++ /dev/null @@ -1,368 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include - -#include - -namespace { - -using Initializer = ClangBackEnd::RefactoringDatabaseInitializer>; - -using Sqlite::Table; - -class RefactoringDatabaseInitializer : public testing::Test -{ -protected: - NiceMock databaseMock; - Initializer initializer{databaseMock}; -}; - -TEST_F(RefactoringDatabaseInitializer, AddSymbolsTable) -{ - InSequence s; - - EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS symbols(symbolId INTEGER PRIMARY KEY, usr TEXT, symbolName TEXT, symbolKind INTEGER, signature TEXT)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_usr ON symbols(usr)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_symbolKind_symbolName ON symbols(symbolKind, symbolName)"))); - - initializer.createSymbolsTable(); -} - -TEST_F(RefactoringDatabaseInitializer, AddLocationsTable) -{ - InSequence s; - - EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS locations(symbolId INTEGER, line INTEGER, column INTEGER, sourceId INTEGER, locationKind INTEGER)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_locations_sourceId_line_column ON locations(sourceId, line, column)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_locations_sourceId_locationKind ON locations(sourceId, locationKind)"))); - EXPECT_CALL(databaseMock, - execute(Eq( - "CREATE INDEX IF NOT EXISTS index_locations_symbolId ON locations(symbolId)"))); - initializer.createLocationsTable(); -} - -TEST_F(RefactoringDatabaseInitializer, AddSourcesTable) -{ - InSequence s; - - EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, directoryId INTEGER, sourceName TEXT)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_sources_directoryId_sourceName ON sources(directoryId, sourceName)"))); - - initializer.createSourcesTable(); -} - -TEST_F(RefactoringDatabaseInitializer, AddDirectoriesTable) -{ - InSequence s; - - EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS directories(directoryId INTEGER PRIMARY KEY, directoryPath TEXT)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_directories_directoryPath ON directories(directoryPath)"))); - - initializer.createDirectoriesTable(); -} - -TEST_F(RefactoringDatabaseInitializer, AddProjectPartsTable) -{ - InSequence s; - - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS projectParts(projectPartId INTEGER PRIMARY " - "KEY, projectPartName TEXT, toolChainArguments TEXT, compilerMacros " - "TEXT, systemIncludeSearchPaths TEXT, projectIncludeSearchPaths TEXT, " - "language INTEGER, languageVersion INTEGER, languageExtension INTEGER)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectParts_projectPartName ON projectParts(projectPartName)"))); - - initializer.createProjectPartsTable(); -} - -TEST_F(RefactoringDatabaseInitializer, AddProjectPartsFilesTable) -{ - InSequence s; - - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsFiles(projectPartId INTEGER, " - "sourceId INTEGER, sourceType INTEGER, pchCreationTimeStamp INTEGER, " - "hasMissingIncludes INTEGER)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsFiles_sourceId_projectPartId ON projectPartsFiles(sourceId, projectPartId)"))); - EXPECT_CALL(databaseMock, - execute(Eq( - "CREATE INDEX IF NOT EXISTS index_projectPartsFiles_projectPartId_sourceType " - "ON projectPartsFiles(projectPartId, sourceType)"))); - - initializer.createProjectPartsFilesTable(); -} - -TEST_F(RefactoringDatabaseInitializer, AddUsedMacrosTable) -{ - InSequence s; - - EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS usedMacros(usedMacroId INTEGER PRIMARY KEY, sourceId INTEGER, macroName TEXT)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_sourceId_macroName ON usedMacros(sourceId, macroName)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_macroName ON usedMacros(macroName)"))); - - initializer.createUsedMacrosTable(); -} - -TEST_F(RefactoringDatabaseInitializer, AddFileStatusesTable) -{ - InSequence s; - - EXPECT_CALL( - databaseMock, - execute(Eq( - "CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, " - "lastModified INTEGER, indexingTimeStamp INTEGER)"))); - - initializer.createFileStatusesTable(); -} - -TEST_F(RefactoringDatabaseInitializer, AddSourceDependenciesTable) -{ - InSequence s; - - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS sourceDependencies(sourceId INTEGER, " - "dependencySourceId INTEGER)"))); - EXPECT_CALL( - databaseMock, - execute( - Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_sourceId_dependencySourceId ON " - "sourceDependencies(sourceId, dependencySourceId)"))); - EXPECT_CALL( - databaseMock, - execute( - Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_dependencySourceId_sourceId ON " - "sourceDependencies(dependencySourceId, sourceId)"))); - - initializer.createSourceDependenciesTable(); -} - -TEST_F(RefactoringDatabaseInitializer, AddPrecompiledHeaderTable) -{ - InSequence s; - - EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS precompiledHeaders(projectPartId INTEGER PRIMARY KEY, projectPchPath TEXT, projectPchBuildTime INTEGER, systemPchPath TEXT, systemPchBuildTime INTEGER)"))); - - initializer.createPrecompiledHeadersTable(); -} - -TEST_F(RefactoringDatabaseInitializer, AddProjectPartsHeadersTable) -{ - InSequence s; - - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsHeaders(projectPartId INTEGER, " - "sourceId INTEGER)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsHeaders_projectPartId ON " - "projectPartsHeaders(projectPartId)"))); - - initializer.createProjectPartsHeadersTable(); -} - -TEST_F(RefactoringDatabaseInitializer, AddProjectPartsSourcesTable) -{ - InSequence s; - - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, " - "sourceId INTEGER)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsSources_projectPartId ON " - "projectPartsSources(projectPartId)"))); - - initializer.createProjectPartsSourcesTable(); -} - -TEST_F(RefactoringDatabaseInitializer, CreateInTheContructor) -{ - InSequence s; - - EXPECT_CALL(databaseMock, isInitialized()).WillOnce(Return(false)); - EXPECT_CALL(databaseMock, exclusiveBegin()); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS symbols(symbolId INTEGER PRIMARY KEY, usr " - "TEXT, symbolName TEXT, symbolKind INTEGER, signature TEXT)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_usr ON symbols(usr)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_symbolKind_symbolName ON " - "symbols(symbolKind, symbolName)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS locations(symbolId INTEGER, line INTEGER, " - "column INTEGER, sourceId INTEGER, locationKind INTEGER)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_locations_sourceId_line_column " - "ON locations(sourceId, line, column)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE INDEX IF NOT EXISTS index_locations_sourceId_locationKind ON " - "locations(sourceId, locationKind)"))); - EXPECT_CALL(databaseMock, - execute(Eq( - "CREATE INDEX IF NOT EXISTS index_locations_symbolId ON locations(symbolId)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, " - "directoryId INTEGER, sourceName TEXT)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_sources_directoryId_sourceName " - "ON sources(directoryId, sourceName)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS directories(directoryId INTEGER PRIMARY " - "KEY, directoryPath TEXT)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_directories_directoryPath ON " - "directories(directoryPath)"))); - EXPECT_CALL(databaseMock, - execute( - Eq("CREATE TABLE IF NOT EXISTS projectParts(projectPartId INTEGER PRIMARY " - "KEY, projectPartName TEXT, toolChainArguments TEXT, compilerMacros " - "TEXT, systemIncludeSearchPaths TEXT, projectIncludeSearchPaths TEXT, " - "language INTEGER, languageVersion INTEGER, languageExtension INTEGER)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectParts_projectPartName " - "ON projectParts(projectPartName)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsFiles(projectPartId INTEGER, " - "sourceId INTEGER, sourceType INTEGER, pchCreationTimeStamp INTEGER, " - "hasMissingIncludes INTEGER)"))); - EXPECT_CALL( - databaseMock, - execute( - Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsFiles_sourceId_projectPartId " - "ON projectPartsFiles(sourceId, projectPartId)"))); - EXPECT_CALL( - databaseMock, - execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsFiles_projectPartId_sourceType ON " - "projectPartsFiles(projectPartId, sourceType)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS usedMacros(usedMacroId INTEGER PRIMARY KEY, " - "sourceId INTEGER, macroName TEXT)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_sourceId_macroName ON " - "usedMacros(sourceId, macroName)"))); - EXPECT_CALL( - databaseMock, - execute( - Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_macroName ON usedMacros(macroName)"))); - EXPECT_CALL( - databaseMock, - execute(Eq( - "CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, " - "lastModified INTEGER, indexingTimeStamp INTEGER)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS sourceDependencies(sourceId INTEGER, " - "dependencySourceId INTEGER)"))); - EXPECT_CALL( - databaseMock, - execute( - Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_sourceId_dependencySourceId ON " - "sourceDependencies(sourceId, dependencySourceId)"))); - EXPECT_CALL( - databaseMock, - execute( - Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_dependencySourceId_sourceId ON " - "sourceDependencies(dependencySourceId, sourceId)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS precompiledHeaders(projectPartId INTEGER " - "PRIMARY KEY, projectPchPath TEXT, projectPchBuildTime INTEGER, " - "systemPchPath TEXT, systemPchBuildTime INTEGER)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsHeaders(projectPartId INTEGER, " - "sourceId INTEGER)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsHeaders_projectPartId ON " - "projectPartsHeaders(projectPartId)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, " - "sourceId INTEGER)"))); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsSources_projectPartId ON " - "projectPartsSources(projectPartId)"))); - EXPECT_CALL(databaseMock, commit()); - EXPECT_CALL(databaseMock, setIsInitialized(true)); - - Initializer initializer{databaseMock}; -} - -TEST_F(RefactoringDatabaseInitializer, DontCreateIfAlreadyInitialized) -{ - InSequence s; - - EXPECT_CALL(databaseMock, isInitialized()).WillOnce(Return(true)); - EXPECT_CALL(databaseMock, exclusiveBegin()).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS symbols(symbolId INTEGER PRIMARY KEY, usr TEXT, symbolName TEXT, symbolKind INTEGER, signature TEXT)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_usr ON symbols(usr)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_symbols_symbolKind_symbolName ON symbols(symbolKind, symbolName)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS locations(symbolId INTEGER, line INTEGER, column INTEGER, sourceId INTEGER, locationKind INTEGER)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_locations_sourceId_line_column ON locations(sourceId, line, column)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_locations_sourceId_locationKind ON locations(sourceId, locationKind)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, directoryId INTEGER, sourceName TEXT, sourceType INTEGER)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_sources_directoryId_sourceName ON sources(directoryId, sourceName)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS directories(directoryId INTEGER PRIMARY KEY, directoryPath TEXT)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_directories_directoryPath ON directories(directoryPath)"))).Times(0); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS projectParts(projectPartId INTEGER PRIMARY " - "KEY, projectPartName TEXT, toolChainArguments TEXT, compilerMacros " - "TEXT, includeSearchPaths TEXT)"))) - .Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectParts_projectPartName ON projectParts(projectPartName)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsFiles(projectPartId INTEGER, sourceId INTEGER)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsFiles_sourceId_projectPartId ON projectPartsFiles(sourceId, projectPartId)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsFiles_projectPartId ON projectPartsFiles(projectPartId)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS usedMacros(usedMacroId INTEGER PRIMARY KEY, sourceId INTEGER, macroName TEXT)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_sourceId_macroName ON usedMacros(sourceId, macroName)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_macroName ON usedMacros(macroName)"))).Times(0); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, " - "size INTEGER, lastModified INTEGER, indexingTimeStamp INTEGER)"))) - .Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS sourceDependencies(sourceId INTEGER, dependencySourceId INTEGER)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_sourceId_dependencySourceId ON sourceDependencies(sourceId, dependencySourceId)"))).Times(0); - EXPECT_CALL(databaseMock, execute(Eq("CREATE TABLE IF NOT EXISTS precompiledHeaders(projectPartId INTEGER PRIMARY KEY, pchPath TEXT, pchBuildTime INTEGER)"))).Times(0); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsHeaders(projectPartId INTEGER, " - "sourceId INTEGER)"))) - .Times(0); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsHeaders_projectPartId ON " - "projectPartsHeaders(projectPartId)"))) - .Times(0); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, " - "sourceId INTEGER)"))) - .Times(0); - EXPECT_CALL(databaseMock, - execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsSources_projectPartId ON " - "projectPartsSources(projectPartId)"))) - .Times(0); - EXPECT_CALL(databaseMock, commit()).Times(0); - - Initializer initializer{databaseMock}; -} - -} diff --git a/tests/unit/unittest/refactoringengine-test.cpp b/tests/unit/unittest/refactoringengine-test.cpp deleted file mode 100644 index 37cfde0d766..00000000000 --- a/tests/unit/unittest/refactoringengine-test.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockfilepathcaching.h" -#include "mockrefactoringserver.h" -#include "mockrefactoringclient.h" -#include "mocksymbolquery.h" - -#include - -#include - -#include -#include -#include - -#include - -#include -#include - -namespace { - -using testing::_; - -using CppTools::CompilerOptionsBuilder; - -using Utils::SmallString; -using Utils::SmallStringVector; - -class RefactoringEngine : public ::testing::Test -{ -protected: - void SetUp() - { - projectPart = CppTools::ProjectPart::Ptr(new CppTools::ProjectPart); - projectPart->project = &project; - projectPart->files.push_back(projectFile); - - CompilerOptionsBuilder optionsBuilder(*projectPart); - commandLine = Utils::SmallStringVector( - optionsBuilder.build(projectFile.kind, CppTools::UsePrecompiledHeaders::No)); - commandLine.push_back(qStringFilePath); - ON_CALL(mockFilePathCaching, filePathId(Eq(clangBackEndFilePath))).WillByDefault(Return(12)); - cursor.setPosition(11); - } - -protected: - NiceMock mockFilePathCaching; - MockRefactoringServer mockRefactoringServer; - MockRefactoringClient mockRefactoringClient; - NiceMock mockSymbolQuery; - ClangRefactoring::RefactoringEngine engine{mockRefactoringServer, - mockRefactoringClient, - mockFilePathCaching, - mockSymbolQuery}; - QString fileContent{QStringLiteral("int x;\nint y;")}; - QTextDocument textDocument{fileContent}; - QTextCursor cursor{&textDocument}; - QString qStringFilePath{QStringLiteral("/home/user/file.cpp")}; - Utils::FilePath filePath{Utils::FilePath::fromString(qStringFilePath)}; - ClangBackEnd::FilePath clangBackEndFilePath{qStringFilePath}; - SmallStringVector commandLine; - ProjectExplorer::Project project; - CppTools::ProjectPart::Ptr projectPart; - CppTools::Usages usages{{"/path1", 1, 3}, {"/path2", 4, 5}}; - CppTools::ProjectFile projectFile{qStringFilePath, CppTools::ProjectFile::CXXSource}; -}; - -TEST_F(RefactoringEngine, FindUsages) -{ - ON_CALL(mockSymbolQuery, sourceUsagesAt(Eq(12), 2, 5)).WillByDefault(Return(usages)); - NiceMock> mockCallback; - - EXPECT_CALL(mockCallback, Call(usages)); - - engine.findUsages(CppTools::CursorInEditor{cursor, filePath}, mockCallback.AsStdFunction()); -} - -TEST_F(RefactoringEngine, CallFindUsages) -{ - EXPECT_CALL(mockSymbolQuery, sourceUsagesAt(Eq(12), 2, 5)); - - engine.findUsages(CppTools::CursorInEditor{cursor, filePath}, [](const CppTools::Usages &) {}); -} - -TEST_F(RefactoringEngine, FindUsagesWithInvalidCursor) -{ - EXPECT_CALL(mockSymbolQuery, sourceUsagesAt(_, _, _)).Times(0); - - engine.findUsages(CppTools::CursorInEditor{{}, filePath}, [](const CppTools::Usages &) {}); -} - -TEST_F(RefactoringEngine, CallSourceUsagesInInGlobalRename) -{ - EXPECT_CALL(mockSymbolQuery, sourceUsagesAt(Eq(12), 2, 5)); - - engine.globalRename(CppTools::CursorInEditor{cursor, filePath}, - [](const CppTools::Usages &) {}, - {}); -} - -TEST_F(RefactoringEngine, CallSourceUsagesInInGlobalRenameWithInvalidCursor) -{ - EXPECT_CALL(mockSymbolQuery, sourceUsagesAt(_, _, _)).Times(0); - - engine.globalRename(CppTools::CursorInEditor{{}, filePath}, [](const CppTools::Usages &) {}, {}); -} - -TEST_F(RefactoringEngine, CallDeclarationsAtInInGlobalFollowSymbol) -{ - - EXPECT_CALL(mockSymbolQuery, declarationsAt(Eq(12), 2, 5)); - - engine.globalFollowSymbol( - CppTools::CursorInEditor{cursor, filePath}, [](const Utils::Link &) {}, {}, {}, {}, {}); -} - -TEST_F(RefactoringEngine, CallDeclarationsAtInInGlobalFollowSymbolWithInvalidCursor) -{ - EXPECT_CALL(mockSymbolQuery, declarationsAt(_, _, _)).Times(0); - - engine.globalFollowSymbol( - CppTools::CursorInEditor{{}, filePath}, [](const Utils::Link &) {}, {}, {}, {}, {}); -} - -TEST_F(RefactoringEngine, InGlobalFollowSymbol) -{ - using Utils::Link; - NiceMock> mockCallback; - ON_CALL(mockSymbolQuery, declarationsAt(Eq(12), 2, 5)).WillByDefault(Return(usages)); - - EXPECT_CALL(mockCallback, - Call(AllOf(Field(&Link::targetFilePath, Eq(Utils::FilePath::fromString("/path1"))), - Field(&Link::targetLine, Eq(1)), - Field(&Link::targetColumn, Eq(2))))); - - engine.globalFollowSymbol( - CppTools::CursorInEditor{cursor, filePath}, mockCallback.AsStdFunction(), {}, {}, {}, {}); -} - -TEST_F(RefactoringEngine, InGlobalFollowSymbolSkipCurrentFile) -{ - using Utils::Link; - NiceMock> mockCallback; - CppTools::Usages usages{{clangBackEndFilePath, 1, 3}, {"/path2", 4, 5}}; - ON_CALL(mockSymbolQuery, declarationsAt(Eq(12), 2, 5)).WillByDefault(Return(usages)); - - EXPECT_CALL(mockCallback, - Call(AllOf(Field(&Link::targetFilePath, Eq(Utils::FilePath::fromString("/path2"))), - Field(&Link::targetLine, Eq(4)), - Field(&Link::targetColumn, Eq(4))))); - - engine.globalFollowSymbol( - CppTools::CursorInEditor{cursor, filePath}, mockCallback.AsStdFunction(), {}, {}, {}, {}); -} - -TEST_F(RefactoringEngine, EngineIsNotUsableForUnusableServer) -{ - ASSERT_FALSE(engine.isRefactoringEngineAvailable()); -} - -TEST_F(RefactoringEngine, EngineIsUsableForUsableServer) -{ - mockRefactoringServer.setAvailable(true); - - ASSERT_TRUE(engine.isRefactoringEngineAvailable()); -} - -TEST_F(RefactoringEngine, ServerIsUsableForUsableEngine) -{ - engine.setRefactoringEngineAvailable(true); - - ASSERT_TRUE(mockRefactoringServer.isAvailable()); -} -} - diff --git a/tests/unit/unittest/refactoringprojectupdater-test.cpp b/tests/unit/unittest/refactoringprojectupdater-test.cpp deleted file mode 100644 index 8b16adc6196..00000000000 --- a/tests/unit/unittest/refactoringprojectupdater-test.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockcppmodelmanager.h" -#include "mockprogressmanager.h" -#include "mockprojectpartsstorage.h" -#include "mockrefactoringserver.h" - -#include - -#include -#include -#include -#include -#include - -#include - -#include - -#include - -#include - -namespace { - -using CppTools::ProjectPart; -using ClangBackEnd::UpdateProjectPartsMessage; -using ClangBackEnd::RemoveProjectPartsMessage; - -MATCHER_P(IsProjectPartContainer, - projectPartId, - std::string(negation ? "hasn't" : "has") + " id " + PrintToString(projectPartId)) -{ - const ClangBackEnd::ProjectPartContainer &container = arg; - - return container.projectPartId == projectPartId; -} - -class RefactoringProjectUpdater : public testing::Test -{ -protected: - RefactoringProjectUpdater() - { - ON_CALL(mockProjectPartsStorage, transactionBackend()).WillByDefault(ReturnRef(database)); - } - ProjectPart::Ptr createProjectPart(const char *name) - { - ProjectPart::Ptr projectPart{new ProjectPart}; - projectPart->project = &project; - projectPart->displayName = QString::fromUtf8(name, std::strlen(name)); - projectPartId = projectPart->id(); - return projectPart; - } - -protected: - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer initializer{database}; - ClangBackEnd::FilePathCaching filePathCache{database}; - NiceMock mockRefactoringServer; - NiceMock mockPchCreationProgressManager; - NiceMock mockDependencyCreationProgressManager; - NiceMock mockProjectPartsStorage; - ClangPchManager::PchManagerClient pchManagerClient{mockPchCreationProgressManager, - mockDependencyCreationProgressManager}; - MockCppModelManager mockCppModelManager; - ProjectExplorer::Project project; - ClangPchManager::ClangIndexingSettingsManager settingsManager; - ClangRefactoring::RefactoringProjectUpdater updater{mockRefactoringServer, - pchManagerClient, - mockCppModelManager, - filePathCache, - mockProjectPartsStorage, - settingsManager}; - Utils::SmallString projectPartId; -}; - -TEST_F(RefactoringProjectUpdater, DontUpdateProjectPartIfNoProjectPartExistsForId) -{ - InSequence s; - - EXPECT_CALL(mockProjectPartsStorage, fetchProjectPartName(Eq(3))) - .WillOnce(Return(QString("project1"))); - EXPECT_CALL(mockCppModelManager, projectPartForId(Eq(QString("project1")))); - EXPECT_CALL(mockRefactoringServer, updateProjectParts(_)).Times(0); - - pchManagerClient.precompiledHeadersUpdated({3}); -} - -TEST_F(RefactoringProjectUpdater, UpdateProjectPart) -{ - InSequence s; - - EXPECT_CALL(mockProjectPartsStorage, fetchProjectPartName(Eq(3))) - .WillRepeatedly(Return(QString(" project1"))); - EXPECT_CALL(mockCppModelManager, projectPartForId(Eq(QString(" project1")))) - .WillRepeatedly(Return(createProjectPart("project1"))); - EXPECT_CALL(mockRefactoringServer, - updateProjectParts(Field(&UpdateProjectPartsMessage::projectsParts, - ElementsAre(IsProjectPartContainer(3))))); - - pchManagerClient.precompiledHeadersUpdated({3}); -} - -TEST_F(RefactoringProjectUpdater, RemoveProjectPart) -{ - EXPECT_CALL(mockRefactoringServer, - removeProjectParts( - Field(&RemoveProjectPartsMessage::projectsPartIds, ElementsAre(Eq(1))))); - - pchManagerClient.precompiledHeaderRemoved(1); -} -} diff --git a/tests/unit/unittest/refactoringserver-test.cpp b/tests/unit/unittest/refactoringserver-test.cpp deleted file mode 100644 index 2cc3f26efd4..00000000000 --- a/tests/unit/unittest/refactoringserver-test.cpp +++ /dev/null @@ -1,361 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "filesystem-utilities.h" -#include "mockfilepathcaching.h" -#include "mockrefactoringclient.h" -#include "mocksymbolindexing.h" -#include "sourcerangecontainer-matcher.h" - -#include -#include -#include -#include -#include - -#include - -#include - -namespace { - -using testing::AllOf; -using testing::Contains; -using testing::Field; -using testing::IsEmpty; -using testing::NiceMock; -using testing::Not; -using testing::Pair; -using testing::PrintToString; -using testing::Property; -using testing::_; - -using ClangBackEnd::FilePath; -using ClangBackEnd::IncludeSearchPaths; -using ClangBackEnd::IncludeSearchPathType; -using ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage; -using ClangBackEnd::RequestSourceRangesForQueryMessage; -using ClangBackEnd::SourceLocationsContainer; -using ClangBackEnd::SourceRangesAndDiagnosticsForQueryMessage; -using ClangBackEnd::SourceRangesContainer; -using ClangBackEnd::SourceRangesForQueryMessage; -using ClangBackEnd::V2::FileContainer; -using ClangBackEnd::V2::FileContainers; -using ClangBackEnd::ProjectPartContainer; -using ClangBackEnd::ProjectPartContainers; - -MATCHER_P2(IsSourceLocation, line, column, - std::string(negation ? "isn't " : "is ") - + "(" + PrintToString(line) - + ", " + PrintToString(column) - + ")" - ) -{ - return arg.line == uint(line) - && arg.column == uint(column); -} - -class RefactoringServer : public ::testing::Test -{ -protected: - void SetUp() override; - void TearDown() override; - - ClangBackEnd::FilePathId filePathId(Utils::SmallStringView string) - { - return filePathCache.filePathId(ClangBackEnd::FilePathView{string}); - } - -protected: - NiceMock mockRefactoringClient; - NiceMock mockSymbolIndexing; - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer databaseInitializer{database}; - ClangBackEnd::FilePathCaching filePathCache{database}; - ClangBackEnd::GeneratedFiles generatedFiles; - ClangBackEnd::RefactoringServer refactoringServer{mockSymbolIndexing, filePathCache, generatedFiles}; - Utils::SmallString sourceContent{"void f()\n {}"}; - ClangBackEnd::FilePath filePath{TESTDATA_DIR, "query_simplefunction.cpp"}; - FileContainer source{filePath.clone(), - filePathCache.filePathId(filePath), - sourceContent.clone(), - {"cc"}}; - QTemporaryFile temporaryFile{Utils::TemporaryDirectory::masterDirectoryPath() - + "/clangQuery-XXXXXX.cpp"}; - int processingSlotCount = 2; -}; - -using RefactoringServerSlowTest = RefactoringServer; -using RefactoringServerVerySlowTest = RefactoringServer; - -TEST_F(RefactoringServerSlowTest, RequestSingleSourceRangesForQueryMessage) -{ - RequestSourceRangesForQueryMessage message{"functionDecl()", - {source.clone()}, - {}}; - - EXPECT_CALL(mockRefactoringClient, - sourceRangesForQueryMessage( - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - Contains(IsSourceRangeWithText(1, 1, 2, 4, sourceContent)))))); - - refactoringServer.requestSourceRangesForQueryMessage(std::move(message)); -} - -TEST_F(RefactoringServerSlowTest, RequestSingleSourceRangesAndDiagnosticsWithUnsavedContentForQueryMessage) -{ - Utils::SmallString unsavedContent{"void f();"}; - FileContainer source{{TESTDATA_DIR, "query_simplefunction.cpp"}, - filePathCache.filePathId(FilePath{TESTDATA_DIR, "query_simplefunction.cpp"}), - "#include \"query_simplefunction.h\"", - {"cc"}}; - FileContainer unsaved{{TESTDATA_DIR, "query_simplefunction.h"}, - filePathCache.filePathId(FilePath{TESTDATA_DIR, "query_simplefunction.h"}), - unsavedContent.clone(), - {}}; - RequestSourceRangesForQueryMessage message{"functionDecl()", {source.clone()}, {unsaved.clone()}}; - - EXPECT_CALL(mockRefactoringClient, - sourceRangesForQueryMessage( - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - Contains(IsSourceRangeWithText(1, 1, 1, 9, unsavedContent)))))); - - refactoringServer.requestSourceRangesForQueryMessage(std::move(message)); -} - -TEST_F(RefactoringServerSlowTest, RequestTwoSourceRangesForQueryMessage) -{ - RequestSourceRangesForQueryMessage message{"functionDecl()", - {source.clone(), source.clone()}, - {}}; - - EXPECT_CALL(mockRefactoringClient, - sourceRangesForQueryMessage( - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - Contains(IsSourceRangeWithText(1, 1, 2, 4, sourceContent)))))); - EXPECT_CALL(mockRefactoringClient, - sourceRangesForQueryMessage( - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - Not(Contains(IsSourceRangeWithText(1, 1, 2, 4, sourceContent))))))); - - refactoringServer.requestSourceRangesForQueryMessage(std::move(message)); -} - -TEST_F(RefactoringServerVerySlowTest, RequestManySourceRangesForQueryMessage) -{ - std::vector sources; - std::fill_n(std::back_inserter(sources), - processingSlotCount + 3, - source.clone()); - RequestSourceRangesForQueryMessage message{"functionDecl()", - std::move(sources), - {}}; - - EXPECT_CALL(mockRefactoringClient, - sourceRangesForQueryMessage( - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - Contains(IsSourceRangeWithText(1, 1, 2, 4, sourceContent)))))); - EXPECT_CALL(mockRefactoringClient, - sourceRangesForQueryMessage( - Field(&SourceRangesForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - Not(Contains(IsSourceRangeWithText(1, 1, 2, 4, sourceContent))))))) - .Times(processingSlotCount + 2); - - refactoringServer.requestSourceRangesForQueryMessage(std::move(message)); -} - -TEST_F(RefactoringServer, CancelJobs) -{ - std::vector sources; - std::fill_n(std::back_inserter(sources), - std::thread::hardware_concurrency() + 3, - source.clone()); - RequestSourceRangesForQueryMessage message{"functionDecl()", - std::move(sources), - {}}; - refactoringServer.requestSourceRangesForQueryMessage(std::move(message)); - - refactoringServer.cancel(); - - ASSERT_TRUE(refactoringServer.isCancelingJobs()); -} - -TEST_F(RefactoringServer, PollTimerIsActiveAfterStart) -{ - RequestSourceRangesForQueryMessage message{"functionDecl()", - {source}, - {}}; - - refactoringServer.requestSourceRangesForQueryMessage(std::move(message)); - - ASSERT_TRUE(refactoringServer.pollTimerIsActive()); -} - -TEST_F(RefactoringServer, PollTimerIsNotActiveAfterFinishing) -{ - RequestSourceRangesForQueryMessage message{"functionDecl()", - {source}, - {}}; - refactoringServer.requestSourceRangesForQueryMessage(std::move(message)); - - refactoringServer.waitThatSourceRangesForQueryMessagesAreFinished(); - - ASSERT_FALSE(refactoringServer.pollTimerIsActive()); -} - -TEST_F(RefactoringServer, PollTimerNotIsActiveAfterCanceling) -{ - RequestSourceRangesForQueryMessage message{"functionDecl()", - {source}, - {}}; - refactoringServer.requestSourceRangesForQueryMessage(std::move(message)); - - refactoringServer.cancel(); - - ASSERT_FALSE(refactoringServer.pollTimerIsActive()); -} - -TEST_F(RefactoringServerSlowTest, ForValidRequestSourceRangesAndDiagnosticsGetSourceRange) -{ - RequestSourceRangesAndDiagnosticsForQueryMessage message("functionDecl()", - {FilePath(temporaryFile.fileName()), - filePathCache.filePathId(FilePath( - temporaryFile.fileName())), - "void f() {}", - {"cc"}}); - - EXPECT_CALL(mockRefactoringClient, - sourceRangesAndDiagnosticsForQueryMessage( - AllOf( - Field(&SourceRangesAndDiagnosticsForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - Contains(IsSourceRangeWithText(1, 1, 1, 12, "void f() {}")))), - Field(&SourceRangesAndDiagnosticsForQueryMessage::diagnostics, - IsEmpty())))); - - refactoringServer.requestSourceRangesAndDiagnosticsForQueryMessage(std::move(message)); -} - -TEST_F(RefactoringServerSlowTest, ForInvalidRequestSourceRangesAndDiagnosticsGetDiagnostics) -{ - RequestSourceRangesAndDiagnosticsForQueryMessage message("func()", - {FilePath(temporaryFile.fileName()), - filePathCache.filePathId(FilePath( - temporaryFile.fileName())), - "void f() {}", - {"cc"}}); - - EXPECT_CALL(mockRefactoringClient, - sourceRangesAndDiagnosticsForQueryMessage( - AllOf( - Field(&SourceRangesAndDiagnosticsForQueryMessage::sourceRanges, - Field(&SourceRangesContainer::sourceRangeWithTextContainers, - IsEmpty())), - Field(&SourceRangesAndDiagnosticsForQueryMessage::diagnostics, - Not(IsEmpty()))))); - - refactoringServer.requestSourceRangesAndDiagnosticsForQueryMessage(std::move(message)); -} - -TEST_F(RefactoringServer, UpdateGeneratedFilesSetMemberWhichIsUsedForSymbolIndexing) -{ - FileContainers unsaved{{{TESTDATA_DIR, "query_simplefunction.h"}, - filePathCache.filePathId(FilePath{TESTDATA_DIR, "query_simplefunction.h"}), - "void f();", - {}}}; - - refactoringServer.updateGeneratedFiles(Utils::clone(unsaved)); - - ASSERT_THAT(generatedFiles.fileContainers(), ElementsAre(unsaved.front())); -} - -TEST_F(RefactoringServer, RemoveGeneratedFilesSetMemberWhichIsUsedForSymbolIndexing) -{ - FileContainers unsaved{{{TESTDATA_DIR, "query_simplefunction.h"}, - filePathCache.filePathId(FilePath{TESTDATA_DIR, "query_simplefunction.h"}), - "void f();", - {}}}; - refactoringServer.updateGeneratedFiles(Utils::clone(unsaved)); - - refactoringServer.removeGeneratedFiles({{{TESTDATA_DIR, "query_simplefunction.h"}}}); - - ASSERT_THAT(generatedFiles.fileContainers(), IsEmpty()); -} - -TEST_F(RefactoringServer, UpdateProjectPartsCalls) -{ - NiceMock mockFilePathCaching; - ClangBackEnd::RefactoringServer refactoringServer{mockSymbolIndexing, - mockFilePathCaching, - generatedFiles}; - ProjectPartContainers projectParts{ - {{1, - {"-I", TESTDATA_DIR}, - {{"DEFINE", "1", 1}}, - IncludeSearchPaths{{"/includes", 1, IncludeSearchPathType::BuiltIn}, - {"/other/includes", 2, IncludeSearchPathType::System}}, - IncludeSearchPaths{{"/project/includes", 1, IncludeSearchPathType::User}, - {"/other/project/includes", 2, IncludeSearchPathType::User}}, - {filePathId("header1.h")}, - {filePathId("main.cpp")}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::All}}}; - - EXPECT_CALL(mockFilePathCaching, populateIfEmpty()); - EXPECT_CALL(mockSymbolIndexing, updateProjectParts(projectParts)); - - refactoringServer.updateProjectParts({Utils::clone(projectParts), {}}); -} - -TEST_F(RefactoringServer, SetProgress) -{ - EXPECT_CALL(mockRefactoringClient, progress(AllOf(Field(&ClangBackEnd::ProgressMessage::progress, 20), - Field(&ClangBackEnd::ProgressMessage::total, 30)))); - - refactoringServer.setProgress(20, 30); -} - -void RefactoringServer::SetUp() -{ - temporaryFile.open(); - refactoringServer.setClient(&mockRefactoringClient); -} - -void RefactoringServer::TearDown() -{ - refactoringServer.setGathererProcessingSlotCount(uint(processingSlotCount)); - refactoringServer.waitThatSourceRangesForQueryMessagesAreFinished(); -} - -} diff --git a/tests/unit/unittest/sourcerangeextractor-test.cpp b/tests/unit/unittest/sourcerangeextractor-test.cpp deleted file mode 100644 index e9266542b9e..00000000000 --- a/tests/unit/unittest/sourcerangeextractor-test.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" -#include "sourcerangecontainer-matcher.h" -#include "testclangtool.h" - -#include -#include -#include -#include - -#include - -#include -#include - -#include - -#include - -using testing::Contains; -using ::testing::Eq; -using ::testing::StrEq; - -using ClangBackEnd::SourceRangeWithTextContainer; -using ClangBackEnd::SourceRangeExtractor; - -namespace { - -class SourceRangeExtractor : public ::testing::Test -{ -protected: - TestClangTool clangTool{{TESTDATA_DIR "/sourcerangeextractor_location.cpp"}, "", {"cc"}}; - ClangBackEnd::SourceRangesContainer sourceRangesContainer; - const clang::SourceManager &sourceManager{clangTool.sourceManager()}; - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer databaseInitializer{database}; - ClangBackEnd::FilePathCaching filePathCache{database}; - ClangBackEnd::SourceRangeExtractor extractor{sourceManager, clangTool.languageOptions(), filePathCache, sourceRangesContainer}; - clang::SourceLocation startLocation = sourceManager.getLocForStartOfFile(sourceManager.getMainFileID()); - clang::SourceLocation endLocation = sourceManager.getLocForStartOfFile(sourceManager.getMainFileID()).getLocWithOffset(4); - clang::SourceRange sourceRange{startLocation, endLocation}; - clang::SourceRange extendedSourceRange{startLocation, endLocation.getLocWithOffset(5)}; -}; - -using SourceRangeExtractorSlowTest = SourceRangeExtractor; - -TEST_F(SourceRangeExtractorSlowTest, ExtractSourceRangeContainer) -{ - SourceRangeWithTextContainer sourceRangeContainer{1, 1, 1, 0, 1, 10, 9, Utils::SmallString("int value;")}; - - extractor.addSourceRange(sourceRange); - - ASSERT_THAT(extractor.sourceRangeWithTextContainers(), - Contains(IsSourceRangeWithText(1, 1, 1, 10, "int value;"))); -} - -TEST_F(SourceRangeExtractorSlowTest, ExtendedSourceRange) -{ - auto range = extractor.extendSourceRangeToLastTokenEnd(sourceRange); - - ASSERT_THAT(range, extendedSourceRange); -} - -TEST_F(SourceRangeExtractorSlowTest, FindStartOfLineInEmptyBuffer) -{ - clang::StringRef text = ""; - - auto found = ::SourceRangeExtractor::findStartOfLineInBuffer(text, 0); - - ASSERT_THAT(found, StrEq("")); -} - -TEST_F(SourceRangeExtractorSlowTest, FindStartOfLineInBufferInFirstLine) -{ - clang::StringRef text = "first line"; - - auto found = ::SourceRangeExtractor::findStartOfLineInBuffer(text, 5); - - ASSERT_THAT(found, StrEq("first line")); -} - -TEST_F(SourceRangeExtractorSlowTest, FindStartOfNewLineInBufferInSecondLine) -{ - clang::StringRef text = "first line\nsecond line"; - - auto found = ::SourceRangeExtractor::findStartOfLineInBuffer(text, 15); - - ASSERT_THAT(found, StrEq("second line")); -} - -TEST_F(SourceRangeExtractorSlowTest, FindStartOfCarriageReturnInBufferInSecondLine) -{ - clang::StringRef text = "first line\rsecond line"; - - auto found = ::SourceRangeExtractor::findStartOfLineInBuffer(text, 15); - - ASSERT_THAT(found, StrEq("second line")); -} - -TEST_F(SourceRangeExtractorSlowTest, FindStartOfNewLineCarriageReturnInBufferInSecondLine) -{ - clang::StringRef text = "first line\n\rsecond line"; - - auto found = ::SourceRangeExtractor::findStartOfLineInBuffer(text, 15); - - ASSERT_THAT(found, StrEq("second line")); -} - -TEST_F(SourceRangeExtractorSlowTest, FindEndOfLineInEmptyBuffer) -{ - clang::StringRef text = ""; - - auto found = ::SourceRangeExtractor::findEndOfLineInBuffer(text, 0); - - ASSERT_THAT(found, StrEq("")); -} - -TEST_F(SourceRangeExtractorSlowTest, FindEndOfLineInBuffer) -{ - clang::StringRef text = "first line"; - - auto found = ::SourceRangeExtractor::findEndOfLineInBuffer(text, 5); - - ASSERT_THAT(found, StrEq("")); -} - -TEST_F(SourceRangeExtractorSlowTest, FindEndOfLineInBufferInFirstLineWithNewLine) -{ - clang::StringRef text = "first line\nsecond line\nthird line"; - - auto found = ::SourceRangeExtractor::findEndOfLineInBuffer(text, 15); - - ASSERT_THAT(found, StrEq("\nthird line")); -} - -TEST_F(SourceRangeExtractorSlowTest, FindEndOfLineInBufferInFirstLineWithCarriageReturn) -{ - clang::StringRef text = "first line\rsecond line\rthird line"; - - auto found = ::SourceRangeExtractor::findEndOfLineInBuffer(text, 15); - - ASSERT_THAT(found, StrEq("\rthird line")); -} - -TEST_F(SourceRangeExtractorSlowTest, EpandText) -{ - clang::StringRef text = "first line\nsecond line\nthird line\nforth line"; - - auto expandedText = ::SourceRangeExtractor::getExpandedText(text, 15, 25); - - ASSERT_THAT(expandedText, Eq("second line\nthird line")); -} -} - diff --git a/tests/unit/unittest/sourcerangefilter-test.cpp b/tests/unit/unittest/sourcerangefilter-test.cpp deleted file mode 100644 index 4b84f4b5f87..00000000000 --- a/tests/unit/unittest/sourcerangefilter-test.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include - -namespace { - -using testing::ContainerEq; -using testing::IsEmpty; - -using ClangBackEnd::SourceRangeWithTextContainer; -using ClangBackEnd::SourceRangeWithTextContainers; -using ClangBackEnd::SourceRangesForQueryMessage; - -class SourceRangeFilter : public ::testing::Test -{ -protected: - - -protected: - SourceRangeWithTextContainers sourceRanges1{{1, 1, 1, 1, 2, 1, 4, "foo"}, - {1, 1, 1, 1, 2, 2, 5, "foo"}, - {2, 1, 1, 1, 2, 1, 4, "foo"}}; - SourceRangeWithTextContainers sourceRanges2{{3, 1, 1, 1, 2, 1, 4, "foo"}, - {1, 1, 1, 1, 2, 1, 4, "foo"}, - {1, 1, 1, 1, 2, 3, 6, "foo"}}; - SourceRangeWithTextContainers sourceRanges3{{1, 1, 1, 1, 2, 3, 6, "foo"}, - {3, 1, 1, 1, 2, 1, 4, "foo"}}; - SourceRangeWithTextContainers sourceRanges4{{1, 1, 1, 1, 2, 3, 6, "foo"}, - {3, 1, 1, 1, 2, 1, 4, "foo"}, - {3, 1, 1, 1, 2, 1, 4, "foo"}}; - SourceRangeWithTextContainers sourceRanges5{{3, 1, 1, 1, 2, 1, 4, "foo"}, - {1, 1, 1, 1, 2, 3, 6, "foo"}}; - SourceRangesForQueryMessage message1{{Utils::clone(sourceRanges1)}}; - SourceRangesForQueryMessage message2{{Utils::clone(sourceRanges2)}}; - ClangBackEnd::SourceRangeFilter filter{3}; -}; - -TEST_F(SourceRangeFilter, DontChangeForFirstTimeIfElementsAreUnique) -{ - auto sourceRange = filter.removeDuplicates(Utils::clone(sourceRanges1)); - - ASSERT_THAT(sourceRange, ContainerEq(sourceRanges1)); -} - -TEST_F(SourceRangeFilter, DoNotFilterNonDuplicates) -{ - filter.removeDuplicates(Utils::clone(sourceRanges1)); - - auto sourceRange = filter.removeDuplicates(Utils::clone(sourceRanges3)); - - ASSERT_THAT(sourceRange, ContainerEq(sourceRanges3)); -} - -TEST_F(SourceRangeFilter, FilterDuplicates) -{ - filter.removeDuplicates(Utils::clone(sourceRanges1)); - - auto sourceRange = filter.removeDuplicates(Utils::clone(sourceRanges2)); - - ASSERT_THAT(sourceRange, ContainerEq(sourceRanges3)); -} - -TEST_F(SourceRangeFilter, FilterMoreDuplicates) -{ - filter.removeDuplicates(Utils::clone(sourceRanges1)); - filter.removeDuplicates(Utils::clone(sourceRanges2)); - - auto sourceRange = filter.removeDuplicates(Utils::clone(sourceRanges3)); - - ASSERT_THAT(sourceRange, IsEmpty()); -} - -TEST_F(SourceRangeFilter, FilterDuplicatesFromMessage) -{ - filter.removeDuplicates(std::move(message1)); - - auto filteredMessage = filter.removeDuplicates(std::move(message2)); - - ASSERT_THAT(filteredMessage.sourceRanges.sourceRangeWithTextContainers, - ContainerEq(sourceRanges3)); -} - -TEST_F(SourceRangeFilter, FilterDuplicatesInOneRangeSet) -{ - auto sourceRange = filter.removeDuplicates(Utils::clone(sourceRanges4)); - - ASSERT_THAT(sourceRange, ContainerEq(sourceRanges3)); -} - -TEST_F(SourceRangeFilter, SortSourceRanges) -{ - auto sourceRange = filter.removeDuplicates(Utils::clone(sourceRanges5)); - - ASSERT_THAT(sourceRange, ContainerEq(sourceRanges3)); -} - -} diff --git a/tests/unit/unittest/sourcesmanager-test.cpp b/tests/unit/unittest/sourcesmanager-test.cpp deleted file mode 100644 index 290139e7cfc..00000000000 --- a/tests/unit/unittest/sourcesmanager-test.cpp +++ /dev/null @@ -1,235 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include - -namespace { - -class SourcesManager : public testing::Test -{ -protected: - ClangBackEnd::SourcesManager sources; -}; - -TEST_F(SourcesManager, TouchFilePathIdFirstTime) -{ - ASSERT_FALSE(sources.alreadyParsed(1, 56)); -} - -TEST_F(SourcesManager, TouchFilePathIdTwoTimesWithSameTime) -{ - sources.alreadyParsed(1, 56); - - ASSERT_FALSE(sources.alreadyParsed(1, 56)); -} - -TEST_F(SourcesManager, TouchFilePathIdSecondTimeWithSameTime) -{ - sources.alreadyParsed(1, 56); - - sources.updateModifiedTimeStamps(); - - ASSERT_TRUE(sources.alreadyParsed(1, 56)); -} - -TEST_F(SourcesManager, TouchFilePathIdSecondTimeWithOlderTime) -{ - sources.alreadyParsed(1, 56); - - sources.updateModifiedTimeStamps(); - - ASSERT_TRUE(sources.alreadyParsed(1, 55)); -} - -TEST_F(SourcesManager, TouchFilePathIdSecondTimeWithNewerTime) -{ - sources.alreadyParsed(1, 56); - - sources.updateModifiedTimeStamps(); - - ASSERT_FALSE(sources.alreadyParsed(1, 57)); -} - -TEST_F(SourcesManager, MultipleFileIds) -{ - sources.alreadyParsed(1, 455); - sources.alreadyParsed(4, 56); - sources.alreadyParsed(3, 85); - sources.alreadyParsed(6, 56); - sources.alreadyParsed(2, 45); - - sources.updateModifiedTimeStamps(); - - ASSERT_TRUE(sources.alreadyParsed(3, 85)); -} - -TEST_F(SourcesManager, UpdateModifiedTimeStampsWithNewerTimeStamp) -{ - sources.alreadyParsed(1, 455); - sources.alreadyParsed(4, 56); - sources.alreadyParsed(3, 85); - sources.alreadyParsed(6, 56); - sources.alreadyParsed(2, 45); - sources.updateModifiedTimeStamps(); - - sources.alreadyParsed(3, 86); - sources.updateModifiedTimeStamps(); - - ASSERT_TRUE(sources.alreadyParsed(3, 86)); -} - -TEST_F(SourcesManager, DontUpdateModifiedTimeStampsWithOlderTimeStamp) -{ - sources.alreadyParsed(1, 455); - sources.alreadyParsed(4, 56); - sources.alreadyParsed(3, 85); - sources.alreadyParsed(6, 56); - sources.alreadyParsed(2, 45); - sources.updateModifiedTimeStamps(); - - sources.alreadyParsed(3, 84); - sources.updateModifiedTimeStamps(); - - ASSERT_TRUE(sources.alreadyParsed(3, 85)); -} - -TEST_F(SourcesManager, ZeroTime) -{ - sources.alreadyParsed(1, 0); - - sources.updateModifiedTimeStamps(); - - ASSERT_TRUE(sources.alreadyParsed(1, 0)); -} - -TEST_F(SourcesManager, TimeIsUpdated) -{ - sources.alreadyParsed(1, 56); - sources.alreadyParsed(1, 57); - - sources.updateModifiedTimeStamps(); - - ASSERT_TRUE(sources.alreadyParsed(1, 57)); -} - -TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterInitialization) -{ - ASSERT_FALSE(sources.dependentFilesModified()); -} - -TEST_F(SourcesManager, AnyDependFileIsModified) -{ - sources.alreadyParsed(1, 56); - - ASSERT_TRUE(sources.dependentFilesModified()); -} - -TEST_F(SourcesManager, AnyDependFileIsModifiedAfterParsingTwoTimesSameTimeStamp) -{ - sources.alreadyParsed(1, 56); - sources.alreadyParsed(1, 56); - - ASSERT_TRUE(sources.dependentFilesModified()); -} - -TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterUpdate) -{ - sources.alreadyParsed(1, 56); - sources.updateModifiedTimeStamps(); - - ASSERT_FALSE(sources.dependentFilesModified()); -} - -TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterNotAlreadyPared) -{ - sources.alreadyParsed(1, 56); - sources.updateModifiedTimeStamps(); - - sources.alreadyParsed(1, 56); - - ASSERT_FALSE(sources.dependentFilesModified()); -} - -TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterAlreadyPared) -{ - sources.alreadyParsed(1, 56); - sources.updateModifiedTimeStamps(); - - sources.alreadyParsed(1, 57); - - ASSERT_TRUE(sources.dependentFilesModified()); -} - -TEST_F(SourcesManager, AnyDependFileIsModifiedAfterUpdateNewTimeStamp) -{ - sources.alreadyParsed(1, 56); - sources.alreadyParsed(2, 56); - sources.updateModifiedTimeStamps(); - sources.alreadyParsed(1, 57); - - sources.alreadyParsed(2, 56); - - ASSERT_TRUE(sources.dependentFilesModified()); -} - -TEST_F(SourcesManager, AlreadyParsedWithDependencyAfterUpdateNewTimeStamp) -{ - sources.alreadyParsedAllDependentFiles(1, 56); - sources.alreadyParsedAllDependentFiles(2, 56); - sources.updateModifiedTimeStamps(); - sources.alreadyParsedAllDependentFiles(1, 57); - - bool alreadyParsed = sources.alreadyParsedAllDependentFiles(2, 56); - - ASSERT_FALSE(alreadyParsed); -} - -TEST_F(SourcesManager, AlreadyParsedWithDependencyAfterUpdateNewSecondTimeStamp) -{ - sources.alreadyParsedAllDependentFiles(1, 56); - sources.alreadyParsedAllDependentFiles(2, 56); - sources.updateModifiedTimeStamps(); - sources.alreadyParsedAllDependentFiles(1, 56); - - bool alreadyParsed = sources.alreadyParsedAllDependentFiles(2, 57); - - ASSERT_FALSE(alreadyParsed); -} - -TEST_F(SourcesManager, AlreadyParsedWithDependencyAfterUpdateSameTimeStamps) -{ - sources.alreadyParsedAllDependentFiles(1, 56); - sources.alreadyParsedAllDependentFiles(2, 56); - sources.updateModifiedTimeStamps(); - sources.alreadyParsedAllDependentFiles(1, 56); - - bool alreadyParsed = sources.alreadyParsedAllDependentFiles(2, 56); - - ASSERT_TRUE(alreadyParsed); -} - -} diff --git a/tests/unit/unittest/sqlitereadstatementmock.h b/tests/unit/unittest/sqlitereadstatementmock.h index 8b435207565..db7fb9896b0 100644 --- a/tests/unit/unittest/sqlitereadstatementmock.h +++ b/tests/unit/unittest/sqlitereadstatementmock.h @@ -28,21 +28,10 @@ #include "googletest.h" #include -#include -#include -#include -#include -#include -#include #include #include #include -#include -#include #include -#include -#include -#include #include #include @@ -52,21 +41,7 @@ #include #include -using ClangBackEnd::FilePathIds; -using ClangBackEnd::SourceEntries; -using ClangBackEnd::SourceEntry; -using ClangBackEnd::SourceTimeStamp; -using ClangBackEnd::SourceTimeStamps; -using ClangRefactoring::SourceLocation; -using ClangRefactoring::SourceLocations; using std::int64_t; -namespace Sources = ClangBackEnd::Sources; -using ClangBackEnd::PrecompiledHeaderTimeStamps; -using ClangBackEnd::UsedMacros; -using ClangBackEnd::Internal::ProjectPartNameId; -using ClangBackEnd::Internal::ProjectPartNameIds; -using ClangRefactoring::Symbol; -using ClangRefactoring::Symbols; class SqliteDatabaseMock; @@ -85,24 +60,10 @@ public: (Utils::SmallStringView, long long), ()); - MOCK_METHOD(SourceLocations, valuesReturnSourceLocations, (std::size_t, int, int, int), ()); - MOCK_METHOD(CppTools::Usages, valuesReturnSourceUsages, (std::size_t, int, int, int), ()); MOCK_METHOD(CppTools::Usages, valuesReturnSourceUsages, (std::size_t, int, int, int, int), ()); - MOCK_METHOD(std::vector, valuesReturnStdVectorDirectory, (std::size_t), ()); - - MOCK_METHOD(std::vector, valuesReturnStdVectorSource, (std::size_t), ()); - - MOCK_METHOD(SourceEntries, valuesReturnSourceEntries, (std::size_t, int, int), ()); - - MOCK_METHOD(UsedMacros, valuesReturnUsedMacros, (std::size_t, int), ()); - - MOCK_METHOD(FilePathIds, valuesReturnFilePathIds, (std::size_t, int), ()); - - MOCK_METHOD(ProjectPartNameIds, valuesReturnProjectPartNameIds, (std::size_t), ()); - MOCK_METHOD(Utils::optional, valueReturnInt32, (Utils::SmallStringView), ()); MOCK_METHOD(Utils::optional, valueReturnInt32, (int, Utils::SmallStringView), ()); @@ -115,54 +76,8 @@ public: MOCK_METHOD(Utils::optional, valueReturnPathString, (Utils::SmallStringView), ()); - MOCK_METHOD(Utils::optional, valueReturnFilePath, (int), ()); - - MOCK_METHOD(ClangBackEnd::FilePaths, valuesReturnFilePaths, (std::size_t), ()); - MOCK_METHOD(Utils::optional, valueReturnSmallString, (int), ()); - MOCK_METHOD(Utils::optional, - valueReturnSourceNameAndDirectoryId, - (int) ); - - MOCK_METHOD(Utils::optional, - valueReturnProjectPartArtefact, - (int) ); - - MOCK_METHOD(Utils::optional, - valueReturnProjectPartArtefact, - (Utils::SmallStringView)); - MOCK_METHOD(ClangBackEnd::ProjectPartArtefacts, valuesReturnProjectPartArtefacts, (std::size_t), ()); - MOCK_METHOD(Utils::optional, - valueReturnProjectPartContainer, - (int) ); - MOCK_METHOD(ClangBackEnd::ProjectPartContainers, - valuesReturnProjectPartContainers, - (std::size_t), - ()); - MOCK_METHOD(Utils::optional, valueReturnProjectPartPch, (int), ()); - - MOCK_METHOD(Utils::optional, valueReturnPchPaths, (int), ()); - - MOCK_METHOD(Symbols, valuesReturnSymbols, (std::size_t, int, Utils::SmallStringView), ()); - - MOCK_METHOD(Symbols, valuesReturnSymbols, (std::size_t, int, int, Utils::SmallStringView), ()); - - MOCK_METHOD(Symbols, valuesReturnSymbols, (std::size_t, int, int, int, Utils::SmallStringView), ()); - - MOCK_METHOD(SourceLocation, valueReturnSourceLocation, (long long, int), ()); - - MOCK_METHOD(Utils::optional, - valueReturnProjectPartId, - (Utils::SmallStringView)); - - MOCK_METHOD(SourceTimeStamps, valuesReturnSourceTimeStamps, (std::size_t), ()); - MOCK_METHOD(SourceTimeStamps, valuesReturnSourceTimeStamps, (std::size_t, int sourcePathId), ()); - - MOCK_METHOD(Utils::optional, - valuesReturnPrecompiledHeaderTimeStamps, - (int projectPartId)); - MOCK_METHOD(QmlDesigner::TypeId, valueReturnsTypeId, (Utils::SmallStringView name), ()); MOCK_METHOD(QmlDesigner::TypeId, valueWithTransactionReturnsTypeId, (long long, long long), ()); MOCK_METHOD(QmlDesigner::PropertyDeclarationId, @@ -241,32 +156,14 @@ public: { if constexpr (std::is_same_v) return valueReturnBlob(queryValues...); - else if constexpr (std::is_same_v) - return valueReturnProjectPartId(queryValues...); else if constexpr (std::is_same_v) return valueReturnInt32(queryValues...); else if constexpr (std::is_same_v) return valueReturnInt64(queryValues...); else if constexpr (std::is_same_v) return valueReturnPathString(queryValues...); - else if constexpr (std::is_same_v) - return valueReturnFilePath(queryValues...); - else if constexpr (std::is_same_v) - return valueReturnProjectPartArtefact(queryValues...); - else if constexpr (std::is_same_v) - return valueReturnProjectPartContainer(queryValues...); - else if constexpr (std::is_same_v) - return valueReturnProjectPartPch(queryValues...); - else if constexpr (std::is_same_v) - return valueReturnPchPaths(queryValues...); else if constexpr (std::is_same_v) return valueReturnSmallString(queryValues...); - else if constexpr (std::is_same_v) - return valueReturnSourceLocation(queryValues...); - else if constexpr (std::is_same_v) - return valueReturnSourceNameAndDirectoryId(queryValues...); - else if constexpr (std::is_same_v) - return valuesReturnPrecompiledHeaderTimeStamps(queryValues...); else static_assert(!std::is_same_v, "SqliteReadStatementMock::value does not handle result type!"); @@ -324,30 +221,8 @@ public: return valuesReturnStringVector(reserveSize); else if constexpr (std::is_same_v) return valuesReturnRowIds(reserveSize); - else if constexpr (std::is_same_v) - return valuesReturnSourceLocations(reserveSize, queryValues...); else if constexpr (std::is_same_v) return valuesReturnSourceUsages(reserveSize, queryValues...); - else if constexpr (std::is_same_v) - return valuesReturnSymbols(reserveSize, queryValues...); - else if constexpr (std::is_same_v) - return valuesReturnUsedMacros(reserveSize, queryValues...); - else if constexpr (std::is_same_v) - return valuesReturnFilePathIds(reserveSize, queryValues...); - else if constexpr (std::is_same_v) - return valuesReturnFilePaths(reserveSize); - else if constexpr (std::is_same_v) - return valuesReturnStdVectorDirectory(reserveSize); - else if constexpr (std::is_same_v) - return valuesReturnStdVectorSource(reserveSize); - else if constexpr (std::is_same_v) - return valuesReturnProjectPartNameIds(reserveSize); - else if constexpr (std::is_same_v) - return valuesReturnProjectPartContainers(reserveSize); - else if constexpr (std::is_same_v) - return valuesReturnSourceEntries(reserveSize, queryValues...); - else if constexpr (std::is_same_v) - return valuesReturnSourceTimeStamps(reserveSize, queryValues...); else if constexpr (std::is_same_v) return valuesReturnCacheSourceContexts(reserveSize); else if constexpr (std::is_same_v) diff --git a/tests/unit/unittest/stringcache-test.cpp b/tests/unit/unittest/stringcache-test.cpp deleted file mode 100644 index 625de6e5a51..00000000000 --- a/tests/unit/unittest/stringcache-test.cpp +++ /dev/null @@ -1,631 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockfilepathstorage.h" -#include "mockmutex.h" -#include "sqlitedatabasemock.h" - -#include - -#include - -namespace { - -using ClangBackEnd::StringCacheException; - -using uint64 = unsigned long long; - -using Utils::compare; -using Utils::reverseCompare; -using ClangBackEnd::findInSorted; -using StorageIdFunction = std::function; -using StorageStringFunction = std::function; - -using CacheWithMockLocking = ClangBackEnd::StringCache, - decltype(&Utils::reverseCompare), - Utils::reverseCompare>; - -using CacheWithoutLocking = ClangBackEnd::StringCache, - decltype(&Utils::reverseCompare), - Utils::reverseCompare>; - -template -class StringCache : public testing::Test -{ -protected: - void SetUp() - { - mockStorageFetchDirectyId = [&](Utils::SmallStringView string) { - return mockStorage.fetchDirectoryId(string); - }; - mockStorageFetchDirectyPath = [&](int id) { - return mockStorage.fetchDirectoryPath(id); - }; - std::sort(filePaths.begin(), filePaths.end(), [](auto &f, auto &l) { - return compare(f, l) < 0; - }); - std::sort(reverseFilePaths.begin(), reverseFilePaths.end(), [](auto &f, auto &l) { - return reverseCompare(f, l) < 0; - }); - - ON_CALL(this->mockStorage, fetchDirectoryId(Eq("foo"))).WillByDefault(Return(42)); - ON_CALL(this->mockStorage, fetchDirectoryId(Eq("bar"))).WillByDefault(Return(43)); - ON_CALL(this->mockStorage, fetchDirectoryId(Eq("poo"))).WillByDefault(Return(44)); - ON_CALL(this->mockStorage, fetchDirectoryId(Eq("taa"))).WillByDefault(Return(45)); - ON_CALL(this->mockStorage, fetchDirectoryPath(41)).WillByDefault(Return(Utils::PathString("bar"))); - } - -protected: - NiceMock databaseMock; - NiceMock mockStorage{databaseMock}; - StorageIdFunction mockStorageFetchDirectyId; - StorageStringFunction mockStorageFetchDirectyPath; - Cache cache; - typename Cache::MutexType &mockMutex = cache.mutex(); - Utils::PathString filePath1{"/file/pathOne"}; - Utils::PathString filePath2{"/file/pathTwo"}; - Utils::PathString filePath3{"/file/pathThree"}; - Utils::PathString filePath4{"/file/pathFour"}; - Utils::PathString filePath5{"/file/pathFife"}; - Utils::PathStringVector filePaths{filePath1, - filePath2, - filePath3, - filePath4, - filePath5}; - Utils::PathStringVector reverseFilePaths{filePath1, - filePath2, - filePath3, - filePath4, - filePath5}; -}; - -using CacheTypes = ::testing::Types; -TYPED_TEST_SUITE(StringCache, CacheTypes); - -TYPED_TEST(StringCache, AddFilePath) -{ - auto id = this->cache.stringId(this->filePath1); - - ASSERT_THAT(id, 0); -} - -TYPED_TEST(StringCache, AddSecondFilePath) -{ - this->cache.stringId(this->filePath1); - - auto id = this->cache.stringId(this->filePath2); - - ASSERT_THAT(id, 1); -} - -TYPED_TEST(StringCache, AddDuplicateFilePath) -{ - this->cache.stringId(this->filePath1); - - auto id = this->cache.stringId(this->filePath1); - - ASSERT_THAT(id, 0); -} - -TYPED_TEST(StringCache, AddDuplicateFilePathBetweenOtherEntries) -{ - this->cache.stringId(this->filePath1); - this->cache.stringId(this->filePath2); - this->cache.stringId(this->filePath3); - this->cache.stringId(this->filePath4); - - auto id = this->cache.stringId(this->filePath3); - - ASSERT_THAT(id, 2); -} - -TYPED_TEST(StringCache, ThrowForGettingPathForNoEntry) -{ - EXPECT_ANY_THROW(this->cache.string(0)); -} - -TYPED_TEST(StringCache, GetFilePathForIdWithOneEntry) -{ - this->cache.stringId(this->filePath1); - - auto filePath = this->cache.string(0); - - ASSERT_THAT(filePath, this->filePath1); -} - -TYPED_TEST(StringCache, GetFilePathForIdWithSomeEntries) -{ - this->cache.stringId(this->filePath1); - this->cache.stringId(this->filePath2); - this->cache.stringId(this->filePath3); - this->cache.stringId(this->filePath4); - - auto filePath = this->cache.string(2); - - ASSERT_THAT(filePath, this->filePath3); -} - -TYPED_TEST(StringCache, GetAllFilePaths) -{ - this->cache.stringId(this->filePath1); - this->cache.stringId(this->filePath2); - this->cache.stringId(this->filePath3); - this->cache.stringId(this->filePath4); - - auto filePaths = this->cache.strings({0, 1, 2, 3}); - - ASSERT_THAT(filePaths, - ElementsAre(this->filePath1, this->filePath2, this->filePath3, this->filePath4)); -} - -TYPED_TEST(StringCache, AddFilePaths) -{ - auto ids = this->cache.stringIds( - {this->filePath1, this->filePath2, this->filePath3, this->filePath4}); - - ASSERT_THAT(ids, ElementsAre(0, 1, 2, 3)); -} - -TYPED_TEST(StringCache, AddFilePathsWithStorageFunction) -{ - auto ids = this->cache.stringIds({"foo", "taa", "poo", "bar"}, this->mockStorageFetchDirectyId); - - ASSERT_THAT(ids, UnorderedElementsAre(42, 43, 44, 45)); -} - -TYPED_TEST(StringCache, IsEmpty) -{ - auto isEmpty = this->cache.isEmpty(); - - ASSERT_TRUE(isEmpty); -} - -TYPED_TEST(StringCache, IsNotEmpty) -{ - this->cache.stringId(this->filePath1); - - auto isEmpty = this->cache.isEmpty(); - - ASSERT_FALSE(isEmpty); -} - -TYPED_TEST(StringCache, PopulateWithEmptyVector) -{ - typename TypeParam::CacheEntries entries; - - this->cache.uncheckedPopulate(std::move(entries)); - - ASSERT_TRUE(this->cache.isEmpty()); -} - -TYPED_TEST(StringCache, IsNotEmptyAfterPopulateWithSomeEntries) -{ - typename TypeParam::CacheEntries entries{{this->filePath1.clone(), 0}, - {this->filePath2.clone(), 3}, - {this->filePath3.clone(), 2}, - {this->filePath4.clone(), 5}}; - - this->cache.uncheckedPopulate(std::move(entries)); - - ASSERT_TRUE(!this->cache.isEmpty()); -} - -TYPED_TEST(StringCache, GetEntryAfterPopulateWithSomeEntries) -{ - typename TypeParam::CacheEntries entries{{this->filePath1.clone(), 0}, - {this->filePath2.clone(), 1}, - {this->filePath3.clone(), 7}, - {this->filePath4.clone(), 3}}; - this->cache.uncheckedPopulate(std::move(entries)); - - auto string = this->cache.string(7); - - ASSERT_THAT(string, this->filePath3); -} - -TYPED_TEST(StringCache, EntriesHaveUniqueIds) -{ - typename TypeParam::CacheEntries entries{{this->filePath1.clone(), 0}, - {this->filePath2.clone(), 1}, - {this->filePath3.clone(), 2}, - {this->filePath4.clone(), 2}}; - - ASSERT_THROW(this->cache.populate(std::move(entries)), StringCacheException); -} - -TYPED_TEST(StringCache, MultipleEntries) -{ - typename TypeParam::CacheEntries entries{{this->filePath1.clone(), 0}, - {this->filePath1.clone(), 1}, - {this->filePath3.clone(), 2}, - {this->filePath4.clone(), 3}}; - - ASSERT_THROW(this->cache.populate(std::move(entries)), StringCacheException); -} - -TYPED_TEST(StringCache, DontFindInSorted) -{ - auto found = findInSorted(this->filePaths.cbegin(), this->filePaths.cend(), "/file/pathFoo", compare); - - ASSERT_FALSE(found.wasFound); -} - -TYPED_TEST(StringCache, FindInSortedOne) -{ - auto found = findInSorted(this->filePaths.cbegin(), this->filePaths.cend(), "/file/pathOne", compare); - - ASSERT_TRUE(found.wasFound); -} - -TYPED_TEST(StringCache, FindInSortedTwo) -{ - auto found = findInSorted(this->filePaths.cbegin(), this->filePaths.cend(), "/file/pathTwo", compare); - - ASSERT_TRUE(found.wasFound); -} - -TYPED_TEST(StringCache, FindInSortedTree) -{ - auto found = findInSorted(this->filePaths.cbegin(), - this->filePaths.cend(), - "/file/pathThree", - compare); - - ASSERT_TRUE(found.wasFound); -} - -TYPED_TEST(StringCache, FindInSortedFour) -{ - auto found = findInSorted(this->filePaths.cbegin(), this->filePaths.cend(), "/file/pathFour", compare); - - ASSERT_TRUE(found.wasFound); -} - -TYPED_TEST(StringCache, FindInSortedFife) -{ - auto found = findInSorted(this->filePaths.cbegin(), this->filePaths.cend(), "/file/pathFife", compare); - - ASSERT_TRUE(found.wasFound); -} - -TYPED_TEST(StringCache, DontFindInSortedReverse) -{ - auto found = findInSorted(this->reverseFilePaths.cbegin(), - this->reverseFilePaths.cend(), - "/file/pathFoo", - reverseCompare); - - ASSERT_FALSE(found.wasFound); -} - -TYPED_TEST(StringCache, FindInSortedOneReverse) -{ - auto found = findInSorted(this->reverseFilePaths.cbegin(), - this->reverseFilePaths.cend(), - "/file/pathOne", - reverseCompare); - - ASSERT_TRUE(found.wasFound); -} - -TYPED_TEST(StringCache, FindInSortedTwoReverse) -{ - auto found = findInSorted(this->reverseFilePaths.cbegin(), - this->reverseFilePaths.cend(), - "/file/pathTwo", - reverseCompare); - - ASSERT_TRUE(found.wasFound); -} - -TYPED_TEST(StringCache, FindInSortedTreeReverse) -{ - auto found = findInSorted(this->reverseFilePaths.cbegin(), - this->reverseFilePaths.cend(), - "/file/pathThree", - reverseCompare); - - ASSERT_TRUE(found.wasFound); -} - -TYPED_TEST(StringCache, FindInSortedFourReverse) -{ - auto found = findInSorted(this->reverseFilePaths.cbegin(), - this->reverseFilePaths.cend(), - "/file/pathFour", - reverseCompare); - - ASSERT_TRUE(found.wasFound); -} - -TYPED_TEST(StringCache, FindInSortedFifeReverse) -{ - auto found = findInSorted(this->reverseFilePaths.cbegin(), - this->reverseFilePaths.cend(), - "/file/pathFife", - reverseCompare); - - ASSERT_TRUE(found.wasFound); -} - -TYPED_TEST(StringCache, StringIdIsReadAndWriteLockedForUnknownEntry) -{ - InSequence s; - - EXPECT_CALL(this->mockMutex, lock_shared()); - EXPECT_CALL(this->mockMutex, unlock_shared()); - EXPECT_CALL(this->mockMutex, lock()); - EXPECT_CALL(this->mockMutex, unlock()); - - this->cache.stringId("foo"); -} - -TYPED_TEST(StringCache, StringIdWithStorageFunctionIsReadAndWriteLockedForUnknownEntry) -{ - InSequence s; - - EXPECT_CALL(this->mockMutex, lock_shared()); - EXPECT_CALL(this->mockMutex, unlock_shared()); - EXPECT_CALL(this->mockMutex, lock()); - EXPECT_CALL(this->mockStorage, fetchDirectoryId(Eq("foo"))); - EXPECT_CALL(this->mockMutex, unlock()); - - this->cache.stringId("foo", this->mockStorageFetchDirectyId); -} - -TYPED_TEST(StringCache, StringIdWithStorageFunctionIsReadLockedForKnownEntry) -{ - InSequence s; - this->cache.stringId("foo", this->mockStorageFetchDirectyId); - - EXPECT_CALL(this->mockMutex, lock_shared()); - EXPECT_CALL(this->mockMutex, unlock_shared()); - EXPECT_CALL(this->mockMutex, lock()).Times(0); - EXPECT_CALL(this->mockStorage, fetchDirectoryId(Eq("foo"))).Times(0); - EXPECT_CALL(this->mockMutex, unlock()).Times(0); - - this->cache.stringId("foo", this->mockStorageFetchDirectyId); -} - -TYPED_TEST(StringCache, StringIdIsReadLockedForKnownEntry) -{ - this->cache.stringId("foo"); - - EXPECT_CALL(this->mockMutex, lock_shared()); - EXPECT_CALL(this->mockMutex, unlock_shared()); - EXPECT_CALL(this->mockMutex, lock()).Times(0); - EXPECT_CALL(this->mockMutex, unlock()).Times(0); - - this->cache.stringId("foo"); -} - -TYPED_TEST(StringCache, StringIdsIsLocked) -{ - EXPECT_CALL(this->mockMutex, lock_shared()); - EXPECT_CALL(this->mockMutex, unlock_shared()); - - this->cache.stringIds({"foo"}); -} - -TYPED_TEST(StringCache, StringIdsWithStorageIsLocked) -{ - EXPECT_CALL(this->mockMutex, lock_shared()); - EXPECT_CALL(this->mockMutex, unlock_shared()); - - this->cache.stringIds({"foo"}, this->mockStorageFetchDirectyId); -} - -TYPED_TEST(StringCache, StringIsLocked) -{ - auto id = this->cache.stringId("foo"); - - EXPECT_CALL(this->mockMutex, lock_shared()); - EXPECT_CALL(this->mockMutex, unlock_shared()); - - this->cache.string(id); -} - -TYPED_TEST(StringCache, StringsIsLocked) -{ - auto ids = this->cache.stringIds({"foo", "bar"}); - - EXPECT_CALL(this->mockMutex, lock_shared()); - EXPECT_CALL(this->mockMutex, unlock_shared()); - - this->cache.strings(ids); -} - -TYPED_TEST(StringCache, StringWithStorageFunctionIsReadAndWriteLockedForUnknownId) -{ - InSequence s; - - EXPECT_CALL(this->mockMutex, lock_shared()); - EXPECT_CALL(this->mockMutex, unlock_shared()); - EXPECT_CALL(this->mockMutex, lock()); - EXPECT_CALL(this->mockStorage, fetchDirectoryPath(Eq(41))); - EXPECT_CALL(this->mockMutex, unlock()); - - this->cache.string(41, this->mockStorageFetchDirectyPath); -} - -TYPED_TEST(StringCache, StringWithStorageFunctionIsReadLockedForKnownId) -{ - InSequence s; - this->cache.string(41, this->mockStorageFetchDirectyPath); - - EXPECT_CALL(this->mockMutex, lock_shared()); - EXPECT_CALL(this->mockMutex, unlock_shared()); - EXPECT_CALL(this->mockMutex, lock()).Times(0); - EXPECT_CALL(this->mockStorage, fetchDirectoryPath(Eq(41))).Times(0); - EXPECT_CALL(this->mockMutex, unlock()).Times(0); - - this->cache.string(41, this->mockStorageFetchDirectyPath); -} - -TYPED_TEST(StringCache, StringIdWithStorageFunctionWhichHasNoEntryIsCallingStorageFunction) -{ - EXPECT_CALL(this->mockStorage, fetchDirectoryId(Eq("foo"))); - - this->cache.stringId("foo", this->mockStorageFetchDirectyId); -} - -TYPED_TEST(StringCache, StringIdWithStorageFunctionWhichHasEntryIsNotCallingStorageFunction) -{ - this->cache.stringId("foo", this->mockStorageFetchDirectyId); - - EXPECT_CALL(this->mockStorage, fetchDirectoryId(Eq("foo"))).Times(0); - - this->cache.stringId("foo", this->mockStorageFetchDirectyId); -} - -TYPED_TEST(StringCache, IndexOfStringIdWithStorageFunctionWhichHasEntry) -{ - this->cache.stringId("foo", this->mockStorageFetchDirectyId); - - auto index = this->cache.stringId("foo", this->mockStorageFetchDirectyId); - - ASSERT_THAT(index, 42); -} - -TYPED_TEST(StringCache, IndexOfStringIdWithStorageFunctionWhichHasNoEntry) -{ - auto index = this->cache.stringId("foo", this->mockStorageFetchDirectyId); - - ASSERT_THAT(index, 42); -} - -TYPED_TEST(StringCache, GetEntryByIndexAfterInsertingByCustomIndex) -{ - auto index = this->cache.stringId("foo", this->mockStorageFetchDirectyId); - - auto string = this->cache.string(index, this->mockStorageFetchDirectyPath); - - ASSERT_THAT(string, Eq("foo")); -} - -TYPED_TEST(StringCache, CallFetchDirectoryPathForLowerIndex) -{ - auto index = this->cache.stringId("foo", this->mockStorageFetchDirectyId); - - EXPECT_CALL(this->mockStorage, fetchDirectoryPath(Eq(index - 1))); - - this->cache.string(index - 1, this->mockStorageFetchDirectyPath); -} - -TYPED_TEST(StringCache, CallFetchDirectoryPathForUnknownIndex) -{ - EXPECT_CALL(this->mockStorage, fetchDirectoryPath(Eq(0))); - - this->cache.string(0, this->mockStorageFetchDirectyPath); -} - -TYPED_TEST(StringCache, FetchDirectoryPathForUnknownIndex) -{ - auto string = this->cache.string(41, this->mockStorageFetchDirectyPath); - - ASSERT_THAT(string, Eq("bar")); -} - -TYPED_TEST(StringCache, AddStringCalls) -{ - EXPECT_CALL(this->mockStorage, fetchDirectoryId(Eq("foo"))); - EXPECT_CALL(this->mockStorage, fetchDirectoryId(Eq("bar"))); - EXPECT_CALL(this->mockStorage, fetchDirectoryId(Eq("poo"))); - - this->cache.addStrings({"foo", "bar", "poo"}, this->mockStorageFetchDirectyId); -} - -TYPED_TEST(StringCache, AddStringCallsOnlyForNewStrings) -{ - this->cache.addStrings({"foo", "poo"}, this->mockStorageFetchDirectyId); - - EXPECT_CALL(this->mockStorage, fetchDirectoryId(Eq("taa"))); - EXPECT_CALL(this->mockStorage, fetchDirectoryId(Eq("bar"))); - - this->cache.addStrings({"foo", "bar", "poo", "taa"}, this->mockStorageFetchDirectyId); -} - -TYPED_TEST(StringCache, GetStringIdAfterAddingStrings) -{ - this->cache.addStrings({"foo", "bar", "poo", "taa"}, this->mockStorageFetchDirectyId); - - ASSERT_THAT(this->cache.string(this->cache.stringId("taa")), Eq("taa")); -} - -TYPED_TEST(StringCache, GetStringAfterAddingStrings) -{ - this->cache.addStrings({"foo", "bar", "poo", "taa"}, this->mockStorageFetchDirectyId); - - ASSERT_THAT(this->cache.string(this->cache.stringId("taa")), Eq("taa")); -} - -TYPED_TEST(StringCache, GetStringIdAfterAddingStringsMultipleTimes) -{ - this->cache.addStrings({"foo", "taa"}, this->mockStorageFetchDirectyId); - - this->cache.addStrings({"foo", "bar", "poo", "taa"}, this->mockStorageFetchDirectyId); - - ASSERT_THAT(this->cache.string(this->cache.stringId("taa")), Eq("taa")); -} - -TYPED_TEST(StringCache, GetStringIdAfterAddingTheSameStringsMultipleTimes) -{ - this->cache.addStrings({"foo", "taa", "poo", "taa", "bar", "taa"}, - this->mockStorageFetchDirectyId); - - ASSERT_THAT(this->cache.string(this->cache.stringId("taa")), Eq("taa")); -} - -TYPED_TEST(StringCache, AddingEmptyStrings) -{ - this->cache.addStrings({}, this->mockStorageFetchDirectyId); -} - -TYPED_TEST(StringCache, FetchStringIdsFromStorageCalls) -{ - InSequence s; - - EXPECT_CALL(this->mockMutex, lock_shared()); - EXPECT_CALL(this->mockMutex, unlock_shared()); - EXPECT_CALL(this->mockMutex, lock()); - EXPECT_CALL(this->mockStorage, fetchDirectoryId(Eq("foo"))); - EXPECT_CALL(this->mockMutex, unlock()); - EXPECT_CALL(this->mockMutex, lock_shared()); - EXPECT_CALL(this->mockMutex, unlock_shared()); - EXPECT_CALL(this->mockMutex, lock()); - EXPECT_CALL(this->mockStorage, fetchDirectoryId(Eq("bar"))); - EXPECT_CALL(this->mockMutex, unlock()); - - this->cache.stringIds({"foo", "bar"}, this->mockStorageFetchDirectyId); -} -} // namespace diff --git a/tests/unit/unittest/symbolindexer-test.cpp b/tests/unit/unittest/symbolindexer-test.cpp deleted file mode 100644 index 63c8d04f6dc..00000000000 --- a/tests/unit/unittest/symbolindexer-test.cpp +++ /dev/null @@ -1,1196 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "filesystem-utilities.h" -#include "googletest.h" -#include "mockbuilddependenciesstorage.h" -#include "mockclangpathwatcher.h" -#include "mockfilepathcaching.h" -#include "mockfilesystem.h" -#include "mockmodifiedtimechecker.h" -#include "mockprecompiledheaderstorage.h" -#include "mockprojectpartsstorage.h" -#include "mocksqlitetransactionbackend.h" -#include "mocksymbolscollector.h" -#include "mocksymbolstorage.h" -#include "testenvironment.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -namespace { - -using ClangBackEnd::CompilerMacro; -using ClangBackEnd::FilePathId; -using ClangBackEnd::FilePathIds; -using ClangBackEnd::FilePathView; -using ClangBackEnd::FileStatuses; -using ClangBackEnd::ProcessorManager; -using ClangBackEnd::ProjectPartContainer; -using ClangBackEnd::ProjectPartContainers; -using ClangBackEnd::ProjectPartId; -using ClangBackEnd::ProjectPartIds; -using ClangBackEnd::SourceDependencies; -using ClangBackEnd::SourceLocationEntries; -using ClangBackEnd::SourceLocationEntry; -using ClangBackEnd::SourceLocationKind; -using ClangBackEnd::SymbolEntries; -using ClangBackEnd::SymbolEntry; -using ClangBackEnd::SymbolIndexerTask; -using ClangBackEnd::SymbolIndexerTaskQueue; -using ClangBackEnd::SymbolKind; -using ClangBackEnd::TaskScheduler; -using ClangBackEnd::UsedMacros; -using ClangBackEnd::V2::FileContainers; -using Utils::PathString; -using OptionalProjectPartArtefact = Utils::optional; - -struct Data -{ - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer databaseInitializer{database}; - ClangBackEnd::FilePathCaching filePathCache{database}; -}; - -class Manager final : public ProcessorManager> -{ -public: - using Processor = NiceMock; - Manager(const ClangBackEnd::GeneratedFiles &generatedFiles) - : ProcessorManager(generatedFiles) - {} - -protected: - std::unique_ptr> createProcessor() const - { - return std::make_unique>(); - } -}; - -class SymbolIndexer : public testing::Test -{ -protected: - void SetUp() - { - ON_CALL(mockCollector, symbols()).WillByDefault(ReturnRef(symbolEntries)); - ON_CALL(mockCollector, sourceLocations()).WillByDefault(ReturnRef(sourceLocations)); - ON_CALL(mockCollector, sourceFiles()).WillByDefault(ReturnRef(sourceFileIds)); - ON_CALL(mockCollector, usedMacros()).WillByDefault(ReturnRef(usedMacros)); - ON_CALL(mockCollector, sourceDependencies()).WillByDefault(ReturnRef(sourceDependencies)); - ON_CALL(mockProjectPartsStorage, fetchProjectPartArtefact(A())) - .WillByDefault(Return(artefact)); - ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A())).WillByDefault(Return(-1)); - ON_CALL(mockCollector, collectSymbols()).WillByDefault(Return(true)); - ON_CALL(mockBuildDependenciesStorage, fetchDependentSourceIds(sourceFileIds)) - .WillByDefault(Return(sourceFileIds)); - ON_CALL(mockBuildDependenciesStorage, fetchDependentSourceIds(ElementsAre(sourceFileIds[0]))) - .WillByDefault(Return(FilePathIds{sourceFileIds[0]})); - ON_CALL(mockBuildDependenciesStorage, fetchDependentSourceIds(ElementsAre(main1PathId))) - .WillByDefault(Return(FilePathIds{main1PathId})); - mockCollector.setIsUsed(false); - - generatedFiles.update(unsaved); - } - - void TearDown() - { - syncTasks(); - } - - void syncTasks() - { - while (!indexerQueue.tasks().empty() || !indexerScheduler.futures().empty()) { - indexerScheduler.syncTasks(); - QCoreApplication::processEvents(); - } - } - - static void SetUpTestCase() - { - data = std::make_unique(); - } - - static void TearDownTestCase() - { - data.reset(); - } - - FilePathId filePathId(Utils::SmallStringView path) const - { - return filePathCache.filePathId(ClangBackEnd::FilePathView(path)); - } - -protected: - static std::unique_ptr data; // it can be non const because data holds no tested classes - using Scheduler = TaskScheduler; - ClangBackEnd::FilePathCaching &filePathCache = data->filePathCache; - ClangBackEnd::FilePathId main1PathId{filePathId(TESTDATA_DIR "/symbolindexer_main1.cpp")}; - ClangBackEnd::FilePathId main2PathId{filePathId(TESTDATA_DIR "/symbolindexer_main2.cpp")}; - ClangBackEnd::FilePathId header2PathId{filePathId(TESTDATA_DIR "/symbolindexer_header1.h")}; - ClangBackEnd::FilePathId header1PathId{filePathId(TESTDATA_DIR "/symbolindexer_header2.h")}; - PathString generatedFileName = "BuildDependencyCollector_generated_file.h"; - ClangBackEnd::FilePathId generatedFilePathId21; - ClangBackEnd::IncludeSearchPaths systemIncludeSearchPaths{ - {"/includes", 1, ClangBackEnd::IncludeSearchPathType::BuiltIn}, - {TESTDATA_DIR, 2, ClangBackEnd::IncludeSearchPathType::System}, - {"/other/includes", 3, ClangBackEnd::IncludeSearchPathType::System}}; - ClangBackEnd::IncludeSearchPaths projectIncludeSearchPaths{ - {"/project/includes", 1, ClangBackEnd::IncludeSearchPathType::User}, - {"/other/project/includes", 2, ClangBackEnd::IncludeSearchPathType::User}}; - ProjectPartContainer projectPart1{1, - {"-Wno-pragma-once-outside-header"}, - {{"BAR", "1", 1}, {"FOO", "1", 2}}, - Utils::clone(systemIncludeSearchPaths), - Utils::clone(projectIncludeSearchPaths), - {header1PathId}, - {main1PathId}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX14, - Utils::LanguageExtension::None}; - ProjectPartContainer projectPart2{2, - {"-Wno-pragma-once-outside-header"}, - {{"BAR", "1", 1}, {"FOO", "0", 2}}, - Utils::clone(systemIncludeSearchPaths), - Utils::clone(projectIncludeSearchPaths), - {header2PathId}, - {main2PathId}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX14, - Utils::LanguageExtension::None}; - ProjectPartContainer projectPart3{3, - {"-Wno-pragma-once-outside-header"}, - {{"BAR", "1", 1}, {"FOO", "1", 2}}, - Utils::clone(systemIncludeSearchPaths), - Utils::clone(projectIncludeSearchPaths), - {header1PathId}, - {main1PathId}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX14, - Utils::LanguageExtension::None}; - FileContainers unsaved{{{TESTDATA_DIR, "query_simplefunction.h"}, - filePathId(TESTDATA_DIR "/query_simplefunction.h"), - "void f();", - {}}}; - SymbolEntries symbolEntries{{1, {"function", "function", SymbolKind::Function}}}; - SourceLocationEntries sourceLocations{{1, 1, {42, 23}, SourceLocationKind::Declaration}}; - FilePathIds sourceFileIds{1, 23}; - UsedMacros usedMacros{{"Foo", 1}}; - FileStatuses fileStatus{{2, 3, 4}}; - SourceDependencies sourceDependencies{{1, 2}, {1, 3}}; - Utils::SmallString systemIncludeSearchPathsText{ - R"([["/includes", 1, 2], [")" TESTDATA_DIR R"(" ,2 , 3], ["/other/includes", 3, 3]])"}; - Utils::SmallString projectIncludeSearchPathsText{ - R"([["/project/includes", 1, 1], ["/other/project/includes", 2, 1]])"}; - ClangBackEnd::ProjectPartArtefact artefact{R"(["-DFOO"])", - R"([["FOO","1", 2],["BAR","1", 1]])", - systemIncludeSearchPathsText, - projectIncludeSearchPathsText, - 74, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX14, - Utils::LanguageExtension::None}; - ClangBackEnd::ProjectPartArtefact emptyArtefact{"", - "", - "", - "", - 1, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX14, - Utils::LanguageExtension::None}; - ClangBackEnd::SourceTimeStamps dependentSourceTimeStamps1{{1, 32}}; - ClangBackEnd::SourceTimeStamps dependentSourceTimeStamps2{{2, 35}}; - ClangBackEnd::FileStatuses fileStatuses1{{1, 0, 32}}; - ClangBackEnd::FileStatuses fileStatuses2{{2, 0, 35}}; - Utils::optional nullArtefact; - ClangBackEnd::PchPaths pchPaths{"/project/pch", "/system/pch"}; - NiceMock mockSqliteTransactionBackend; - NiceMock mockSymbolStorage; - NiceMock mockBuildDependenciesStorage; - NiceMock mockPrecompiledHeaderStorage; - NiceMock mockProjectPartsStorage; - NiceMock mockPathWatcher; - NiceMock mockFileSystem; - ClangBackEnd::FileStatusCache fileStatusCache{mockFileSystem}; - ClangBackEnd::GeneratedFiles generatedFiles; - Manager collectorManger{generatedFiles}; - NiceMock> mockSetProgressCallback; - ClangBackEnd::ProgressCounter progressCounter{mockSetProgressCallback.AsStdFunction()}; - NiceMock mockModifiedTimeChecker; - TestEnvironment testEnvironment; - ClangBackEnd::SymbolIndexer indexer{indexerQueue, - mockSymbolStorage, - mockBuildDependenciesStorage, - mockPrecompiledHeaderStorage, - mockPathWatcher, - filePathCache, - fileStatusCache, - mockSqliteTransactionBackend, - mockProjectPartsStorage, - mockModifiedTimeChecker, - testEnvironment}; - NiceMock mockSqliteDatabase; - SymbolIndexerTaskQueue indexerQueue{indexerScheduler, progressCounter, mockSqliteDatabase}; - Scheduler indexerScheduler{collectorManger, - indexerQueue, - progressCounter, - 1, - ClangBackEnd::CallDoInMainThreadAfterFinished::Yes}; - MockSymbolsCollector &mockCollector{static_cast(collectorManger.unusedProcessor())}; -}; - -std::unique_ptr SymbolIndexer::data; - -TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesInCollector) -{ - EXPECT_CALL(mockCollector, - setFile(main1PathId, - ElementsAre("clang++", - "-w", - "-Wno-pragma-once-outside-header", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes")))); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithPrecompiledHeaderInCollector) -{ - ON_CALL(mockPrecompiledHeaderStorage, fetchPrecompiledHeaders(Eq(projectPart1.projectPartId))) - .WillByDefault(Return(pchPaths)); - - EXPECT_CALL(mockCollector, - setFile(main1PathId, - ElementsAre("clang++", - "-w", - "-Wno-pragma-once-outside-header", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes"), - "-Xclang", - "-include-pch", - "-Xclang", - toNativePath("/project/pch")))); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithoutPrecompiledHeaderInCollector) -{ - ON_CALL(mockProjectPartsStorage, fetchProjectPartArtefact(TypedEq(1))) - .WillByDefault(Return(emptyArtefact)); - - EXPECT_CALL(mockCollector, - setFile(main1PathId, - ElementsAre("clang++", - "-w", - "-Wno-pragma-once-outside-header", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes")))); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsCallsClearInCollector) -{ - EXPECT_CALL(mockCollector, clear()).Times(2); - - indexer.updateProjectParts({projectPart1, projectPart2}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesInCollectorForEveryProjectPart) -{ - EXPECT_CALL(mockCollector, setFile(_, _)).Times(2); - - indexer.updateProjectParts({projectPart1, projectPart2}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsDoesNotCallAddFilesInCollectorForEmptyEveryProjectParts) -{ - EXPECT_CALL(mockCollector, setFile(_, _)) - .Times(0); - - indexer.updateProjectParts({}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsCallscollectSymbolsInCollector) -{ - EXPECT_CALL(mockCollector, collectSymbols()).Times(2); - - indexer.updateProjectParts({projectPart1, projectPart2}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsCallsSymbolsInCollector) -{ - EXPECT_CALL(mockCollector, symbols()).Times(2); - - indexer.updateProjectParts({projectPart1, projectPart2}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsCallsSourceLocationsInCollector) -{ - EXPECT_CALL(mockCollector, sourceLocations()).Times(2); - - indexer.updateProjectParts({projectPart1, projectPart2}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddUnsavedFilesInCollector) -{ - EXPECT_CALL(mockCollector, setUnsavedFiles(unsaved)).Times(2); - - indexer.updateProjectParts({projectPart1, projectPart2}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddSymbolsAndSourceLocationsInStorage) -{ - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)).Times(2); - - indexer.updateProjectParts({projectPart1, projectPart2}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrder) -{ - InSequence s; - - EXPECT_CALL(mockPrecompiledHeaderStorage, fetchPrecompiledHeaders(Eq(projectPart1.projectPartId))); - EXPECT_CALL(mockCollector, - setFile(main1PathId, - ElementsAre("clang++", - "-w", - "-Wno-pragma-once-outside-header", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes")))); - EXPECT_CALL(mockCollector, collectSymbols()); - EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)); - EXPECT_CALL(mockSqliteTransactionBackend, commit()); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsCallsGetsProjectAndSystemPchPathsAndHasNoError) -{ - InSequence s; - - EXPECT_CALL(mockPrecompiledHeaderStorage, fetchPrecompiledHeaders(Eq(projectPart1.projectPartId))) - .WillOnce(Return(ClangBackEnd::PchPaths{"/project/pch", "/system/pch"})); - EXPECT_CALL(mockCollector, - setFile(main1PathId, - ElementsAre("clang++", - "-w", - "-Wno-pragma-once-outside-header", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes"), - "-Xclang", - "-include-pch", - "-Xclang", - toNativePath("/project/pch")))); - EXPECT_CALL(mockCollector, collectSymbols()).WillOnce(Return(true)); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)); - EXPECT_CALL(mockCollector, collectSymbols()).Times(0); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsCallsGetsProjectAndSystemPchPathsAndHasErrorWithProjectPch) -{ - InSequence s; - - EXPECT_CALL(mockPrecompiledHeaderStorage, fetchPrecompiledHeaders(Eq(projectPart1.projectPartId))) - .WillOnce(Return(ClangBackEnd::PchPaths{"/project/pch", "/system/pch"})); - EXPECT_CALL(mockCollector, - setFile(main1PathId, - ElementsAre("clang++", - "-w", - "-Wno-pragma-once-outside-header", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes"), - "-Xclang", - "-include-pch", - "-Xclang", - toNativePath("/project/pch")))); - EXPECT_CALL(mockCollector, collectSymbols()).WillOnce(Return(false)); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)).Times(0); - EXPECT_CALL(mockCollector, - setFile(main1PathId, - ElementsAre("clang++", - "-w", - "-Wno-pragma-once-outside-header", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes"), - "-Xclang", - "-include-pch", - "-Xclang", - toNativePath("/system/pch")))); - EXPECT_CALL(mockCollector, collectSymbols()).WillOnce(Return(true)); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)); - EXPECT_CALL(mockCollector, collectSymbols()).Times(0); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, - UpdateProjectPartsCallsGetsProjectAndSystemPchPathsAndHasErrorWithProjectAndSystemPch) -{ - InSequence s; - - EXPECT_CALL(mockPrecompiledHeaderStorage, fetchPrecompiledHeaders(Eq(projectPart1.projectPartId))) - .WillOnce(Return(ClangBackEnd::PchPaths{"/project/pch", "/system/pch"})); - EXPECT_CALL(mockCollector, - setFile(main1PathId, - ElementsAre("clang++", - "-w", - "-Wno-pragma-once-outside-header", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes"), - "-Xclang", - "-include-pch", - "-Xclang", - toNativePath("/project/pch")))); - EXPECT_CALL(mockCollector, collectSymbols()).WillOnce(Return(false)); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)).Times(0); - EXPECT_CALL(mockCollector, - setFile(main1PathId, - ElementsAre("clang++", - "-w", - "-Wno-pragma-once-outside-header", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes"), - "-Xclang", - "-include-pch", - "-Xclang", - toNativePath("/system/pch")))); - EXPECT_CALL(mockCollector, collectSymbols()).WillOnce(Return(false)); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)).Times(0); - EXPECT_CALL(mockCollector, - setFile(main1PathId, - ElementsAre("clang++", - "-w", - "-Wno-pragma-once-outside-header", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes")))); - EXPECT_CALL(mockCollector, collectSymbols()).WillOnce(Return(true)); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsCallsGetsProjectAndSystemPchPathsAndHasOnlyError) -{ - InSequence s; - - EXPECT_CALL(mockPrecompiledHeaderStorage, fetchPrecompiledHeaders(Eq(projectPart1.projectPartId))) - .WillOnce(Return(ClangBackEnd::PchPaths{"/project/pch", "/system/pch"})); - EXPECT_CALL(mockCollector, - setFile(main1PathId, - ElementsAre("clang++", - "-w", - "-Wno-pragma-once-outside-header", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes"), - "-Xclang", - "-include-pch", - "-Xclang", - toNativePath("/project/pch")))); - EXPECT_CALL(mockCollector, collectSymbols()).WillOnce(Return(false)); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)).Times(0); - EXPECT_CALL(mockCollector, - setFile(main1PathId, - ElementsAre("clang++", - "-w", - "-Wno-pragma-once-outside-header", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes"), - "-Xclang", - "-include-pch", - "-Xclang", - toNativePath("/system/pch")))); - EXPECT_CALL(mockCollector, collectSymbols()).WillOnce(Return(false)); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)).Times(0); - EXPECT_CALL(mockCollector, - setFile(main1PathId, - ElementsAre("clang++", - "-w", - "-Wno-pragma-once-outside-header", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes")))); - EXPECT_CALL(mockCollector, collectSymbols()).WillOnce(Return(false)); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)).Times(0); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsCallsGetsSystemPchPathsAndHasErrorWithProjectPch) -{ - InSequence s; - - EXPECT_CALL(mockPrecompiledHeaderStorage, fetchPrecompiledHeaders(Eq(projectPart1.projectPartId))) - .WillOnce(Return(ClangBackEnd::PchPaths{{}, "/system/pch"})); - EXPECT_CALL(mockCollector, - setFile(main1PathId, - ElementsAre("clang++", - "-w", - "-Wno-pragma-once-outside-header", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes"), - "-Xclang", - "-include-pch", - "-Xclang", - toNativePath("/system/pch")))); - EXPECT_CALL(mockCollector, collectSymbols()).WillOnce(Return(true)); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)); - EXPECT_CALL(mockCollector, collectSymbols()).Times(0); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsCallsGetsNoPchPathsAndHasErrors) -{ - InSequence s; - - EXPECT_CALL(mockPrecompiledHeaderStorage, fetchPrecompiledHeaders(Eq(projectPart1.projectPartId))); - EXPECT_CALL(mockCollector, - setFile(main1PathId, - ElementsAre("clang++", - "-w", - "-Wno-pragma-once-outside-header", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes")))); - EXPECT_CALL(mockCollector, collectSymbols()).WillOnce(Return(true)); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)); - EXPECT_CALL(mockCollector, collectSymbols()).Times(0); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsFetchIncludedIndexingTimeStamps) -{ - InSequence s; - - EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); - EXPECT_CALL(mockBuildDependenciesStorage, - insertOrUpdateIndexingTimeStampsWithoutTransaction(_, _)); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)); - EXPECT_CALL(mockSqliteTransactionBackend, commit()); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, UpdateProjectPartsIsBusyInStoringData) -{ - InSequence s; - - EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()) - .WillOnce(Throw(Sqlite::StatementIsBusy{""})); - EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); - EXPECT_CALL(mockBuildDependenciesStorage, - insertOrUpdateIndexingTimeStampsWithoutTransaction(_, _)); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)); - EXPECT_CALL(mockSqliteTransactionBackend, commit()); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, DependentSourceAreNotUpToDate) -{ - InSequence s; - - EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(_)).WillOnce(Return(false)); - EXPECT_CALL(mockCollector, setFile(main1PathId, _)); - EXPECT_CALL(mockCollector, collectSymbols()).WillOnce(Return(true)); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, DependentSourceAreUpToDate) -{ - InSequence s; - - EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(_)).WillOnce(Return(true)); - EXPECT_CALL(mockCollector, setFile(main1PathId, _)).Times(0); - EXPECT_CALL(mockCollector, collectSymbols()).Times(0); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)).Times(0); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, CompilerMacrosAndIncludeSearchPathsAreNotDifferent) -{ - ON_CALL(mockProjectPartsStorage, fetchProjectPartArtefact(A())) - .WillByDefault(Return(artefact)); - - auto areDifferent = indexer.compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart1, - artefact); - - ASSERT_FALSE(areDifferent); -} - -TEST_F(SymbolIndexer, CompilerMacrosAreDifferent) -{ - ON_CALL(mockProjectPartsStorage, fetchProjectPartArtefact(A())) - .WillByDefault(Return(artefact)); - - auto areDifferent = indexer.compilerMacrosOrIncludeSearchPathsAreDifferent(projectPart2, - artefact); - - ASSERT_TRUE(areDifferent); -} - -TEST_F(SymbolIndexer, SystemIncludeSearchPathsAreDifferent) -{ - ClangBackEnd::IncludeSearchPaths newSystemIncludeSearchPaths{ - {"/includes", 1, ClangBackEnd::IncludeSearchPathType::BuiltIn}, - {"/other/includes2", 2, ClangBackEnd::IncludeSearchPathType::System}}; - ClangBackEnd::IncludeSearchPaths newProjectIncludeSearchPaths{ - {"/project/includes", 1, ClangBackEnd::IncludeSearchPathType::User}, - {"/other/project/includes2", 2, ClangBackEnd::IncludeSearchPathType::User}}; - ProjectPartContainer projectPart3{3, - {"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"}, - {{"BAR", "1", 1}, {"FOO", "1", 2}}, - {{"/includes", 1, ClangBackEnd::IncludeSearchPathType::BuiltIn}, - {"/other/includes2", - 2, - ClangBackEnd::IncludeSearchPathType::System}}, - Utils::clone(projectIncludeSearchPaths), - {header1PathId}, - {main1PathId}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::All}; - ON_CALL(mockProjectPartsStorage, fetchProjectPartArtefact(A())) - .WillByDefault(Return(artefact)); - - auto areDifferent = indexer.compilerMacrosOrIncludeSearchPathsAreDifferent( - projectPart3, artefact); - - ASSERT_TRUE(areDifferent); -} - -TEST_F(SymbolIndexer, ProjectIncludeSearchPathsAreDifferent) -{ - ProjectPartContainer projectPart3{ - 3, - {"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"}, - {{"BAR", "1", 1}, {"FOO", "1", 2}}, - Utils::clone(systemIncludeSearchPaths), - {{"/project/includes", 1, ClangBackEnd::IncludeSearchPathType::User}, - {"/other/project/includes2", 2, ClangBackEnd::IncludeSearchPathType::User}}, - {header1PathId}, - {main1PathId}, - Utils::Language::C, - Utils::LanguageVersion::C11, - Utils::LanguageExtension::All}; - ON_CALL(mockProjectPartsStorage, fetchProjectPartArtefact(A())) - .WillByDefault(Return(artefact)); - - auto areDifferent = indexer.compilerMacrosOrIncludeSearchPathsAreDifferent( - projectPart3, artefact); - - ASSERT_TRUE(areDifferent); -} - -TEST_F(SymbolIndexer, DISABLED_DontReparseInUpdateProjectPartsIfDefinesAreTheSame) -{ - InSequence s; - ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A())).WillByDefault(Return(QDateTime::currentSecsSinceEpoch())); - - EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); - EXPECT_CALL(mockProjectPartsStorage, fetchProjectPartArtefact(TypedEq(1))) - .WillRepeatedly(Return(artefact)); - EXPECT_CALL(mockProjectPartsStorage, - updateProjectPart(Eq(projectPart1.projectPartId), - Eq(projectPart1.toolChainArguments), - Eq(projectPart1.compilerMacros), - Eq(projectPart1.systemIncludeSearchPaths), - Eq(projectPart1.projectIncludeSearchPaths), - Eq(Utils::Language::Cxx), - Eq(Utils::LanguageVersion::CXX14), - Eq(Utils::LanguageExtension::None))); - EXPECT_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A())).WillRepeatedly(Return(QDateTime::currentSecsSinceEpoch())); - EXPECT_CALL(mockSqliteTransactionBackend, commit()); - EXPECT_CALL(mockCollector, setFile(_, _)).Times(0); - EXPECT_CALL(mockCollector, collectSymbols()).Times(0); - EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0); - EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)).Times(0); - EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0); - - indexer.updateProjectPart(std::move(projectPart1)); -} - -TEST_F(SymbolIndexer, PathsChangedUpdatesFileStatusCache) -{ - auto sourceId = filePathId(TESTDATA_DIR "/symbolindexer_pathChanged.cpp"); - ON_CALL(mockFileSystem, lastModified(Eq(sourceId))).WillByDefault(Return(65)); - ON_CALL(mockBuildDependenciesStorage, fetchDependentSourceIds(_)) - .WillByDefault(Return(FilePathIds{sourceId})); - - indexer.pathsChanged({sourceId}); - - ASSERT_THAT(fileStatusCache.lastModifiedTime(sourceId), 65); -} - -TEST_F(SymbolIndexer, PathsChangedCallsModifiedTimeChecker) -{ - auto sourceId = filePathId(TESTDATA_DIR "/symbolindexer_pathChanged.cpp"); - - EXPECT_CALL(mockModifiedTimeChecker, pathsChanged(ElementsAre(sourceId))); - - indexer.pathsChanged({sourceId}); -} - -TEST_F(SymbolIndexer, GetUpdatableFilePathIdsIfCompilerMacrosAreDifferent) -{ - ON_CALL(mockProjectPartsStorage, fetchProjectPartArtefact(A())) - .WillByDefault(Return(artefact)); - - auto filePathIds = indexer.updatableFilePathIds(projectPart2, artefact); - - ASSERT_THAT(filePathIds, projectPart2.sourcePathIds); -} - -TEST_F(SymbolIndexer, GetUpdatableFilePathIdsIfIncludeSearchPathsAreDifferent) -{ - ON_CALL(mockProjectPartsStorage, fetchProjectPartArtefact(A())) - .WillByDefault(Return(artefact)); - - auto filePathIds = indexer.updatableFilePathIds(projectPart3, artefact); - - ASSERT_THAT(filePathIds, projectPart3.sourcePathIds); -} - -TEST_F(SymbolIndexer, GetNoUpdatableFilePathIdsIfArtefactsAreTheSame) -{ - ON_CALL(mockProjectPartsStorage, fetchProjectPartArtefact(A())) - .WillByDefault(Return(artefact)); - ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A())).WillByDefault(Return(QDateTime::currentSecsSinceEpoch())); - - auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact); - - ASSERT_THAT(filePathIds, IsEmpty()); -} - -TEST_F(SymbolIndexer, OutdatedFilesPassUpdatableFilePathIds) -{ - ON_CALL(mockFileSystem, lastModified(Eq(main1PathId))).WillByDefault(Return(65)); - indexer.pathsChanged({main1PathId}); - ON_CALL(mockProjectPartsStorage, fetchProjectPartArtefact(A())) - .WillByDefault(Return(artefact)); - ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A())) - .WillByDefault(Return(0)); - - auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact); - - ASSERT_THAT(filePathIds, ElementsAre(main1PathId)); -} - -TEST_F(SymbolIndexer, UpToDateFilesDontPassFilteredUpdatableFilePathIds) -{ - indexer.pathsChanged({main1PathId}); - ON_CALL(mockProjectPartsStorage, fetchProjectPartArtefact(A())) - .WillByDefault(Return(artefact)); - ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A())) - .WillByDefault(Return(QDateTime::currentSecsSinceEpoch())); - - auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact); - - ASSERT_THAT(filePathIds, IsEmpty()); -} - -TEST_F(SymbolIndexer, OutdatedFilesAreParsedInUpdateProjectParts) -{ - indexer.pathsChanged({main1PathId}); - indexerScheduler.syncTasks(); - ON_CALL(mockProjectPartsStorage, fetchProjectPartArtefact(A())) - .WillByDefault(Return(artefact)); - ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A())) - .WillByDefault(Return(0)); - - EXPECT_CALL(mockCollector, setFile(Eq(main1PathId), _)); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, DISABLED_UpToDateFilesAreNotParsedInUpdateProjectParts) -{ - indexer.pathsChanged({main1PathId}); - - indexerScheduler.syncTasks(); - ON_CALL(mockProjectPartsStorage, fetchProjectPartArtefact(A())) - .WillByDefault(Return(artefact)); - ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A())) - .WillByDefault(Return(QDateTime::currentSecsSinceEpoch())); - - EXPECT_CALL(mockCollector, setFile(_, _)).Times(0); - - indexer.updateProjectParts({projectPart1}); -} - -TEST_F(SymbolIndexer, MultipleSourceFiles) -{ - ProjectPartContainer projectPart{0, - {}, - {{"BAR", "1", 1}, {"FOO", "1", 2}}, - Utils::clone(systemIncludeSearchPaths), - Utils::clone(projectIncludeSearchPaths), - {header1PathId, header2PathId}, - {main1PathId, main2PathId}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX14, - Utils::LanguageExtension::None}; - - EXPECT_CALL(mockCollector, - setFile(main1PathId, - ElementsAre("clang++", - "-w", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes")))); - EXPECT_CALL(mockCollector, - setFile(main2PathId, - ElementsAre("clang++", - "-w", - "-DNOMINMAX", - "-x", - "c++", - "-std=c++14", - "-nostdinc", - "-nostdinc++", - "-DBAR=1", - "-DFOO=1", - "-isystem", - toNativePath(TESTDATA_DIR "/preincludes"), - "-I", - toNativePath("/project/includes"), - "-I", - toNativePath("/other/project/includes"), - "-isystem", - toNativePath(TESTDATA_DIR), - "-isystem", - toNativePath("/other/includes"), - "-isystem", - toNativePath("/includes")))); - - indexer.updateProjectParts({projectPart}); -} -} // namespace diff --git a/tests/unit/unittest/symbolindexertaskqueue-test.cpp b/tests/unit/unittest/symbolindexertaskqueue-test.cpp deleted file mode 100644 index 7862231a66d..00000000000 --- a/tests/unit/unittest/symbolindexertaskqueue-test.cpp +++ /dev/null @@ -1,244 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "sqlitedatabasemock.h" -#include "mocktaskscheduler.h" - -#include - -namespace { - -using ClangBackEnd::FilePathId; -using ClangBackEnd::SymbolsCollectorInterface; -using ClangBackEnd::SymbolIndexerTask; -using ClangBackEnd::SymbolStorageInterface; -using ClangBackEnd::SlotUsage; - -using Callable = ClangBackEnd::SymbolIndexerTask::Callable; - -MATCHER_P2(IsTask, filePathId, projectPartId, - std::string(negation ? "is't" : "is") - + PrintToString(SymbolIndexerTask(filePathId, projectPartId, Callable{}))) -{ - const SymbolIndexerTask &task = arg; - - return task.filePathId == filePathId && task.projectPartId == projectPartId; -} - -class SymbolIndexerTaskQueue : public testing::Test -{ -protected: - NiceMock> mockSetProgressCallback; - ClangBackEnd::ProgressCounter progressCounter{mockSetProgressCallback.AsStdFunction()}; - NiceMock> mockTaskScheduler; - NiceMock mockSqliteDatabase; - ClangBackEnd::SymbolIndexerTaskQueue queue{mockTaskScheduler, progressCounter, mockSqliteDatabase}; -}; - -TEST_F(SymbolIndexerTaskQueue, AddTasks) -{ - queue.addOrUpdateTasks({{2, 1, Callable{}}, - {4, 1, Callable{}}}); - - queue.addOrUpdateTasks({{1, 1, Callable{}}, - {3, 1, Callable{}}, - {5, 1, Callable{}}}); - - ASSERT_THAT(queue.tasks(), - ElementsAre(IsTask(1, 1), - IsTask(2, 1), - IsTask(3, 1), - IsTask(4, 1), - IsTask(5, 1))); -} - -TEST_F(SymbolIndexerTaskQueue, AddTasksCallsProgressCounter) -{ - queue.addOrUpdateTasks({{1, 1, Callable{}}, - {3, 1, Callable{}}, - {5, 1, Callable{}}}); - - - EXPECT_CALL(mockSetProgressCallback, Call(0, 4)); - - queue.addOrUpdateTasks({{2, 1, Callable{}}, - {3, 1, Callable{}}}); - -} - -TEST_F(SymbolIndexerTaskQueue, ReplaceTask) -{ - queue.addOrUpdateTasks({{1, 1, Callable{}}, - {3, 1, Callable{}}, - {5, 1, Callable{}}}); - - queue.addOrUpdateTasks({{2, 1, Callable{}}, - {3, 1, Callable{}}}); - - ASSERT_THAT(queue.tasks(), - ElementsAre(IsTask(1, 1), - IsTask(2, 1), - IsTask(3, 1), - IsTask(5, 1))); -} - -TEST_F(SymbolIndexerTaskQueue, AddTaskWithDifferentProjectId) -{ - queue.addOrUpdateTasks({{1, 1, Callable{}}, - {3, 1, Callable{}}, - {5, 1, Callable{}}}); - - queue.addOrUpdateTasks({{2, 2, Callable{}}, - {3, 2, Callable{}}}); - - ASSERT_THAT(queue.tasks(), - ElementsAre(IsTask(1, 1), - IsTask(2, 2), - IsTask(3, 1), - IsTask(3, 2), - IsTask(5, 1))); -} - -TEST_F(SymbolIndexerTaskQueue, RemoveTaskByProjectParts) -{ - queue.addOrUpdateTasks({{1, 1, Callable{}}, - {3, 1, Callable{}}, - {5, 1, Callable{}}}); - queue.addOrUpdateTasks({{2, 2, Callable{}}, - {3, 2, Callable{}}}); - queue.addOrUpdateTasks({{2, 3, Callable{}}, - {3, 3, Callable{}}}); - queue.addOrUpdateTasks({{2, 4, Callable{}}, - {3, 4, Callable{}}}); - - queue.removeTasks({2, 3}); - - ASSERT_THAT(queue.tasks(), - ElementsAre(IsTask(1, 1), - IsTask(2, 4), - IsTask(3, 1), - IsTask(3, 4), - IsTask(5, 1))); -} - -TEST_F(SymbolIndexerTaskQueue, RemoveTasksCallsProgressCounter) -{ - queue.addOrUpdateTasks({{1, 1, Callable{}}, - {3, 1, Callable{}}, - {5, 1, Callable{}}}); - queue.addOrUpdateTasks({{2, 2, Callable{}}, - {3, 2, Callable{}}}); - queue.addOrUpdateTasks({{2, 3, Callable{}}, - {3, 3, Callable{}}}); - queue.addOrUpdateTasks({{2, 4, Callable{}}, - {3, 4, Callable{}}}); - - - EXPECT_CALL(mockSetProgressCallback, Call(0, 5)); - - queue.removeTasks({2, 3}); -} - -TEST_F(SymbolIndexerTaskQueue, ProcessTasksCallsFreeSlotsAndAddTasksInScheduler) -{ - InSequence s; - queue.addOrUpdateTasks({{1, 1, Callable{}}, - {3, 1, Callable{}}, - {5, 1, Callable{}}}); - - EXPECT_CALL(mockTaskScheduler, slotUsage()).WillRepeatedly(Return(SlotUsage{2, 0})); - EXPECT_CALL(mockTaskScheduler, addTasks(SizeIs(2))); - - queue.processEntries(); -} - -TEST_F(SymbolIndexerTaskQueue, ProcessTasksCallsFreeSlotsAndAddTasksWithNoTaskInSchedulerIfTaskAreEmpty) -{ - InSequence s; - - EXPECT_CALL(mockTaskScheduler, slotUsage()).WillRepeatedly(Return(SlotUsage{2, 0})); - EXPECT_CALL(mockTaskScheduler, addTasks(IsEmpty())); - - queue.processEntries(); -} - -TEST_F(SymbolIndexerTaskQueue, ProcessTasksCallsFreeSlotsAndMoveAllTasksInSchedulerIfMoreSlotsAreFree) -{ - InSequence s; - queue.addOrUpdateTasks({{1, 1, Callable{}}, - {3, 1, Callable{}}, - {5, 1, Callable{}}}); - - EXPECT_CALL(mockTaskScheduler, slotUsage()).WillRepeatedly(Return(SlotUsage{4, 0})); - EXPECT_CALL(mockTaskScheduler, addTasks(SizeIs(3))); - - queue.processEntries(); -} - -TEST_F(SymbolIndexerTaskQueue, ProcessTasksRemovesProcessedTasks) -{ - queue.addOrUpdateTasks({{1, 1, Callable{}}, - {3, 1, Callable{}}, - {5, 1, Callable{}}}); - ON_CALL(mockTaskScheduler, slotUsage()).WillByDefault(Return(SlotUsage{2, 0})); - - queue.processEntries(); - - ASSERT_THAT(queue.tasks(), SizeIs(1)); -} - -TEST_F(SymbolIndexerTaskQueue, - ProcessTasksWritesBackTheDatabaseLogIfTheQueueIsEmptyAndTheIndexerHasNothingToDo) -{ - InSequence s; - - EXPECT_CALL(mockTaskScheduler, slotUsage()).WillRepeatedly(Return(SlotUsage{2, 0})); - EXPECT_CALL(mockSqliteDatabase, walCheckpointFull()); - - queue.processEntries(); -} - -TEST_F(SymbolIndexerTaskQueue, ProcessTasksDoesNotWritesBackTheDatabaseLogIfTheIndexerHasSomethingToDo) -{ - InSequence s; - - EXPECT_CALL(mockTaskScheduler, slotUsage()).WillRepeatedly(Return(SlotUsage{1, 1})); - EXPECT_CALL(mockSqliteDatabase, walCheckpointFull()).Times(0); - - queue.processEntries(); -} - -TEST_F(SymbolIndexerTaskQueue, HandleExeptionInWalCheckPoint) -{ - InSequence s; - - EXPECT_CALL(mockTaskScheduler, slotUsage()).WillRepeatedly(Return(SlotUsage{2, 0})); - EXPECT_CALL(mockSqliteDatabase, walCheckpointFull()).WillOnce(Throw(Sqlite::DatabaseIsBusy{""})); - - queue.processEntries(); -} -} // namespace diff --git a/tests/unit/unittest/symbolindexing-test.cpp b/tests/unit/unittest/symbolindexing-test.cpp deleted file mode 100644 index d2233d95160..00000000000 --- a/tests/unit/unittest/symbolindexing-test.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" -#include "testenvironment.h" - -#include -#include -#include - -#include -#include -#include -#include - -#include - -namespace { - -using Sqlite::Database; -using Sqlite::ReadStatement; -using ClangBackEnd::SymbolIndexer; -using ClangBackEnd::SymbolsCollector; -using ClangBackEnd::SymbolStorage; -using ClangBackEnd::FilePathCaching; -using ClangBackEnd::FilePathId; -using ClangBackEnd::RefactoringDatabaseInitializer; -using ClangBackEnd::ProjectPartContainer; -using ClangBackEnd::ProjectPartContainer; -using ClangRefactoring::SymbolQuery; -using ClangRefactoring::QuerySqliteStatementFactory; -using Utils::PathString; -using SL = ClangRefactoring::SourceLocations; - -using StatementFactory = QuerySqliteStatementFactory; -using Query = SymbolQuery; - -MATCHER_P3(IsLocation, filePathId, line, column, - std::string(negation ? "isn't" : "is") - + " file path id " + PrintToString(filePathId) - + " line " + PrintToString(line) - + " and column " + PrintToString(column) - ) -{ - const ClangRefactoring::SourceLocation &location = arg; - - return location.filePathId == filePathId - && location.lineColumn.line == line - && location.lineColumn.column == column; -}; - -class SymbolIndexing : public testing::Test -{ -protected: - FilePathId filePathId(Utils::SmallStringView filePath) - { - return filePathCache.filePathId(ClangBackEnd::FilePathView{filePath}); - } - -protected: - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - RefactoringDatabaseInitializer initializer{database}; - FilePathCaching filePathCache{database}; - ClangBackEnd::GeneratedFiles generatedFiles; - NiceMock> mockSetProgressCallback; - ClangBackEnd::ProjectPartsStorage projectPartStorage{database}; - TestEnvironment testEnvironment; - ClangBackEnd::SymbolIndexing indexing{database, - filePathCache, - generatedFiles, - mockSetProgressCallback.AsStdFunction(), - testEnvironment}; - StatementFactory queryFactory{database}; - Query query{queryFactory}; - PathString main1Path = TESTDATA_DIR "/symbolindexing_main1.cpp"; - ProjectPartContainer projectPart1{projectPartStorage.fetchProjectPartId("project1"), - {}, - {{"DEFINE", "1", 1}}, - {{TESTDATA_DIR, 1, ClangBackEnd::IncludeSearchPathType::System}}, - {}, - {}, - {filePathId(main1Path)}, - Utils::Language::Cxx, - Utils::LanguageVersion::CXX14, - Utils::LanguageExtension::None}; -}; - -TEST_F(SymbolIndexing, Locations) -{ - indexing.indexer().updateProjectParts({projectPart1}); - indexing.syncTasks(); - - auto locations = query.locationsAt(filePathId(TESTDATA_DIR "/symbolindexing_main1.cpp"), 1, 6); - ASSERT_THAT(locations, - ElementsAre( - IsLocation(filePathId(TESTDATA_DIR "/symbolindexing_main1.cpp"), 1, 6), - IsLocation(filePathId(TESTDATA_DIR "/symbolindexing_main1.cpp"), 3, 6), - IsLocation(filePathId(TESTDATA_DIR "/symbolindexing_main1.cpp"), 40, 5))); -} - -TEST_F(SymbolIndexing, DISABLED_TemplateFunction) -{ - indexing.indexer().updateProjectParts({projectPart1}); - indexing.syncTasks(); - - auto locations = query.locationsAt(filePathId(TESTDATA_DIR "/symbolindexing_main1.cpp"), 21, 24); - ASSERT_THAT(locations, - ElementsAre( - IsLocation(filePathId(TESTDATA_DIR "/symbolindexing_main1.cpp"), 5, 9), - IsLocation(filePathId(TESTDATA_DIR "/symbolindexing_main1.cpp"), 6, 5))); -} - -TEST_F(SymbolIndexing, PathsAreUpdated) -{ - indexing.indexer().updateProjectParts({projectPart1}); - - indexing.indexer().pathsChanged({filePathId(main1Path)}); - indexing.indexer().pathsChanged({filePathId(main1Path)}); - indexing.syncTasks(); - - auto locations = query.locationsAt(filePathId(TESTDATA_DIR "/symbolindexing_main1.cpp"), 1, 6); - ASSERT_THAT(locations, - ElementsAre( - IsLocation(filePathId(TESTDATA_DIR "/symbolindexing_main1.cpp"), 1, 6), - IsLocation(filePathId(TESTDATA_DIR "/symbolindexing_main1.cpp"), 3, 6), - IsLocation(filePathId(TESTDATA_DIR "/symbolindexing_main1.cpp"), 40, 5))); -} - -} diff --git a/tests/unit/unittest/symbolquery-test.cpp b/tests/unit/unittest/symbolquery-test.cpp deleted file mode 100644 index 8484e827167..00000000000 --- a/tests/unit/unittest/symbolquery-test.cpp +++ /dev/null @@ -1,240 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "sqlitedatabasemock.h" - -#include -#include -#include - -#include -#include -#include - -namespace { - -using ClangRefactoring::QuerySqliteStatementFactory; -using Sqlite::Database; -using ClangBackEnd::SourceLocationKind; -using ClangBackEnd::SymbolKind; -using MockStatementFactory = QuerySqliteStatementFactory; -using MockQuery = ClangRefactoring::SymbolQuery; - -using RealStatementFactory = QuerySqliteStatementFactory; -using RealQuery = ClangRefactoring::SymbolQuery; - -class SymbolQuery : public testing::Test -{ - template - using ReadStatement = typename SqliteDatabaseMock::template ReadStatement; - -protected: - NiceMock databaseMock; - MockStatementFactory mockStatementFactory{databaseMock}; - ReadStatement<3> &selectLocationsForSymbolLocation = mockStatementFactory.selectLocationsForSymbolLocation; - ReadStatement<3> &selectSourceUsagesForSymbolLocation = mockStatementFactory - .selectSourceUsagesForSymbolLocation; - ReadStatement<3> &selectSymbolsForKindAndStartsWith = mockStatementFactory.selectSymbolsForKindAndStartsWith; - ReadStatement<3> &selectSymbolsForKindAndStartsWith2 = mockStatementFactory - .selectSymbolsForKindAndStartsWith2; - ReadStatement<3> &selectSymbolsForKindAndStartsWith3 = mockStatementFactory - .selectSymbolsForKindAndStartsWith3; - ReadStatement<3> &selectLocationOfSymbol = mockStatementFactory.selectLocationOfSymbol; - ReadStatement<3> &selectSourceUsagesOrderedForSymbolLocation = mockStatementFactory - .selectSourceUsagesOrderedForSymbolLocation; - ReadStatement<3> &selectSourceUsagesByLocationKindForSymbolLocation - = mockStatementFactory.selectSourceUsagesByLocationKindForSymbolLocation; - SourceLocations locations{{1, 1, 1}, {1, 2, 3}, {2, 1, 1}, {2, 3, 1}, {4, 1, 1}, {4, 1, 3}}; - MockQuery query{mockStatementFactory}; -}; - -class SymbolQuerySlowTest : public testing::Test -{ -protected: - SymbolQuerySlowTest() - { - database.execute("INSERT INTO sources VALUES (1, 1, 'filename.h')"); - database.execute("INSERT INTO sources VALUES (2, 1, 'filename.cpp')"); - database.execute("INSERT INTO directories VALUES (1, '/path/to')"); - database.execute("INSERT INTO locations VALUES (1, 2, 3, 1, 2)"); - database.execute("INSERT INTO locations VALUES (1, 4, 6, 2, 1)"); - database.execute("INSERT INTO locations VALUES (1, 20, 36, 2, 3)"); - database.execute( - "INSERT INTO symbols VALUES (1, 'functionusr', 'Function', 3, 'void function(int)')"); - database.execute( - "INSERT INTO symbols VALUES (2, 'classusr', 'Class', 2, 'class Class final')"); - database.execute( - "INSERT INTO symbols VALUES (3, 'enumusr', 'Enum', 1, 'enum Enum : char')"); - } - -protected: - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer initializer{database}; - std::lock_guard lock{database}; - RealStatementFactory realStatementFactory{database}; - RealQuery query{realStatementFactory}; -}; - -TEST_F(SymbolQuery, LocationsAtCallsValues) -{ - EXPECT_CALL(selectLocationsForSymbolLocation, valuesReturnSourceLocations(_, 42, 14, 7)); - - query.locationsAt(42, 14, 7); -} - -TEST_F(SymbolQuerySlowTest, LocationsAt) -{ - auto locations = query.locationsAt(2, 4, 6); - - ASSERT_THAT(locations, - UnorderedElementsAre(SourceLocation(1, 2, 3), - SourceLocation(2, 4, 6), - SourceLocation(2, 20, 36))); -} - -TEST_F(SymbolQuery, SourceUsagesAtCallsValues) -{ - EXPECT_CALL(selectSourceUsagesForSymbolLocation, valuesReturnSourceUsages(_, 42, 14, 7)); - - query.sourceUsagesAt(42, 14, 7); -} - -TEST_F(SymbolQuerySlowTest, SourceUsagesAt) -{ - auto usages = query.sourceUsagesAt(2, 4, 6); - - ASSERT_THAT(usages, - UnorderedElementsAre(CppTools::Usage("/path/to/filename.h", 2, 3), - CppTools::Usage("/path/to/filename.cpp", 4, 6), - CppTools::Usage("/path/to/filename.cpp", 20, 36))); -} - -TEST_F(SymbolQuery, SymbolsCallsValuesWithOneKindParameter) -{ - EXPECT_CALL(selectSymbolsForKindAndStartsWith, valuesReturnSymbols(100, int(SymbolKind::Record), Eq("foo"))); - - query.symbols({SymbolKind::Record}, "foo"); -} - -TEST_F(SymbolQuerySlowTest, SymbolsWithOneKindParameters) -{ - auto symbols = query.symbols({SymbolKind::Record}, "Cla%"); - - ASSERT_THAT(symbols, - UnorderedElementsAre(Symbol{2, "Class", "class Class final"})); -} - -TEST_F(SymbolQuerySlowTest, SymbolsWithEmptyKinds) -{ - auto symbols = query.symbols({}, "%"); - - ASSERT_THAT(symbols, IsEmpty()); -} - -TEST_F(SymbolQuery, SymbolsCallsValuesWithTwoKindParameters) -{ - EXPECT_CALL(selectSymbolsForKindAndStartsWith2, valuesReturnSymbols(100, int(SymbolKind::Record), int(SymbolKind::Function), Eq("foo"))); - - query.symbols({SymbolKind::Record, SymbolKind::Function}, "foo"); -} - -TEST_F(SymbolQuerySlowTest, SymbolsWithTwoKindParameters) -{ - auto symbols = query.symbols({SymbolKind::Record, SymbolKind::Function}, "%c%"); - - ASSERT_THAT(symbols, - UnorderedElementsAre(Symbol{2, "Class", "class Class final"}, - Symbol{1, "Function", "void function(int)"})); -} - -TEST_F(SymbolQuery, SymbolsCallsValuesWithThreeKindParameters) -{ - EXPECT_CALL(selectSymbolsForKindAndStartsWith3, valuesReturnSymbols(100, int(SymbolKind::Record), int(SymbolKind::Function), int(SymbolKind::Enumeration), Eq("foo"))); - - query.symbols({SymbolKind::Record, SymbolKind::Function, SymbolKind::Enumeration}, "foo"); -} - -TEST_F(SymbolQuerySlowTest, SymbolsWithThreeKindParameters) -{ - auto symbols = query.symbols({SymbolKind::Record, SymbolKind::Function, SymbolKind::Enumeration}, "%"); - - ASSERT_THAT(symbols, - UnorderedElementsAre(Symbol{2, "Class", "class Class final"}, - Symbol{1, "Function", "void function(int)"}, - Symbol{3, "Enum", "enum Enum : char"})); -} - -TEST_F(SymbolQuery, LocationForSymbolIdCallsValueReturningSourceLocation) -{ - EXPECT_CALL(selectLocationOfSymbol, valueReturnSourceLocation(1, int(SourceLocationKind::Definition))); - - query.locationForSymbolId(1, SourceLocationKind::Definition); -} - -TEST_F(SymbolQuerySlowTest, LocationForSymbolId) -{ - auto location = query.locationForSymbolId(1, SourceLocationKind::Definition); - - ASSERT_THAT(location.value(), Eq(SourceLocation(2, {4, 6}))); -} - -TEST_F(SymbolQuery, SourceUsagesAtByLocationKindCallsValues) -{ - EXPECT_CALL(selectSourceUsagesByLocationKindForSymbolLocation, - valuesReturnSourceUsages( - _, 42, 14, 7, static_cast(ClangBackEnd::SourceLocationKind::Definition))); - - query.sourceUsagesAtByLocationKind(42, 14, 7, ClangBackEnd::SourceLocationKind::Definition); -} - -TEST_F(SymbolQuerySlowTest, SourceUsagesAtByLocationKind) -{ - auto usages = query.sourceUsagesAtByLocationKind(2, - 4, - 6, - ClangBackEnd::SourceLocationKind::Definition); - - ASSERT_THAT(usages, ElementsAre(CppTools::Usage("/path/to/filename.cpp", 4, 6))); -} - -TEST_F(SymbolQuery, DeclarationsAtCallsValues) -{ - EXPECT_CALL(selectSourceUsagesOrderedForSymbolLocation, valuesReturnSourceUsages(_, 42, 14, 7)); - - query.declarationsAt(42, 14, 7); -} - -TEST_F(SymbolQuerySlowTest, DeclarationsAt) -{ - auto usages = query.declarationsAt(2, 4, 6); - - ASSERT_THAT(usages, - ElementsAre(CppTools::Usage("/path/to/filename.cpp", 4, 6), - CppTools::Usage("/path/to/filename.h", 2, 3))); -} - -} // namespace diff --git a/tests/unit/unittest/symbolscollector-test.cpp b/tests/unit/unittest/symbolscollector-test.cpp deleted file mode 100644 index 01f2895d1b7..00000000000 --- a/tests/unit/unittest/symbolscollector-test.cpp +++ /dev/null @@ -1,688 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "filesystem-utilities.h" - -#include -#include - -#include -#include - -#include -#include - -#ifdef _WIN32 -#include -#else -#include -#endif - -using testing::PrintToString; -using testing::AllOf; -using testing::Contains; -using testing::Not; -using testing::Field; -using testing::Key; -using testing::Pair; -using testing::Value; -using testing::_; - -using ClangBackEnd::FilePath; -using ClangBackEnd::FilePathCaching; -using ClangBackEnd::FilePathId; -using ClangBackEnd::FileStatus; -using ClangBackEnd::SourceDependency; -using ClangBackEnd::SourceLocationEntry; -using ClangBackEnd::SourceLocationKind; -using ClangBackEnd::SymbolEntry; -using ClangBackEnd::SymbolIndex; -using ClangBackEnd::SymbolKind; -using ClangBackEnd::SymbolTag; -using ClangBackEnd::UsedMacro; -using ClangBackEnd::V2::FileContainers; - -using Sqlite::Database; - -namespace { - -MATCHER_P5(IsSourceLocationEntry, symbolId, filePathId, line, column, kind, - std::string(negation ? "isn't" : "is") - + PrintToString(SourceLocationEntry{symbolId, filePathId, {line, column}, kind}) - ) -{ - const SourceLocationEntry &entry = arg; - - return entry.filePathId == filePathId - && entry.lineColumn.line == line - && entry.lineColumn.column == column - && entry.kind == kind - && entry.symbolId == symbolId; -} - -MATCHER_P2(HasLineColumn, line, column, - std::string(negation ? "isn't" : "is") - + PrintToString(Utils::LineColumn{line, column}) - ) -{ - const SourceLocationEntry &entry = arg; - - return entry.lineColumn.line == line - && entry.lineColumn.column == column; -} - -MATCHER_P(HasSymbolName, symbolName, - std::string(negation ? "hasn't" : "has") - + " symbol name: " - + symbolName - ) -{ - const SymbolEntry &entry = arg.second; - - return entry.symbolName == symbolName; -} - -MATCHER_P(HasSymbolKind, symbolKind, - std::string(negation ? "hasn't" : "has") - + " and symbol kind: " - + PrintToString(symbolKind) - ) -{ - const SymbolEntry &entry = arg.second; - - return entry.symbolKind == symbolKind; -} - -MATCHER_P(HasSymbolTag, symbolTag, - std::string(negation ? "hasn't" : "has") - + " and symbol tag: " - + PrintToString(symbolTag) - ) -{ - const SymbolEntry &entry = arg.second; - - return entry.symbolTags.contains(symbolTag); -} - -class SymbolsCollector : public testing::Test -{ -protected: - FilePathId filePathId(Utils::SmallStringView filePath) const - { - return filePathCache.filePathId(ClangBackEnd::FilePathView{filePath}); - } - - static off_t fileSize(Utils::SmallStringView filePath) - { - return QFileInfo(QString(filePath)).size(); - } - - static std::time_t lastModified(Utils::SmallStringView filePath) - { - return QFileInfo(QString(filePath)).lastModified().toSecsSinceEpoch(); - } - - ClangBackEnd::FileStatus fileStatus(Utils::SmallStringView filePath) const - { - return {filePathId(filePath), fileSize(filePath), lastModified(filePath)}; - } - - SymbolIndex symbolId(const Utils::SmallString &symbolName) - { - for (const auto &entry : collector.symbols()) { - if (entry.second.symbolName == symbolName) - return entry.first; - } - - return 0; - } - - void touchFile(const char *filePath) - { -#ifdef _WIN32 - QFile::resize(QString::fromUtf8(filePath), QFileInfo(QString::fromUtf8(filePath)).size()); -#else - utime(filePath, nullptr); -#endif - } - -protected: - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer initializer{database}; - FilePathCaching filePathCache{database}; - ClangBackEnd::SymbolsCollector collector{filePathCache}; -}; - -TEST_F(SymbolsCollector, CollectSymbolName) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/simple.cpp"), {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), - Contains(HasSymbolName("function"))); -} - -TEST_F(SymbolsCollector, DISABLED_SymbolMatchesLocation) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/simple.cpp"), {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.sourceLocations(), - Contains( - AllOf(Field(&SourceLocationEntry::symbolId, symbolId("function")), - HasLineColumn(1, 6)))); -} - -TEST_F(SymbolsCollector, DISABLED_OtherSymboldMatchesLocation) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/simple.cpp"), {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.sourceLocations(), - Contains( - AllOf(Field(&SourceLocationEntry::symbolId, symbolId("function")), - HasLineColumn(2, 6)))); -} - -TEST_F(SymbolsCollector, CollectFilePath) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/simple.cpp"), {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.sourceLocations(), - Contains(AllOf(Field(&SourceLocationEntry::filePathId, - filePathId(TESTDATA_DIR "/symbolscollector/simple.cpp")), - Field(&SourceLocationEntry::kind, SourceLocationKind::Declaration)))); -} - -TEST_F(SymbolsCollector, CollectLineColumn) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/simple.cpp"), {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.sourceLocations(), - Contains( - AllOf(HasLineColumn(1, 6), - Field(&SourceLocationEntry::kind, SourceLocationKind::Declaration)))); -} - -TEST_F(SymbolsCollector, CollectReference) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/simple.cpp"), {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.sourceLocations(), - Contains( - AllOf(HasLineColumn(14, 5), - Field(&SourceLocationEntry::kind, SourceLocationKind::DeclarationReference)))); -} - -TEST_F(SymbolsCollector, DISABLED_ReferencedSymboldMatchesLocation) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/simple.cpp"), {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.sourceLocations(), - Contains( - AllOf(Field(&SourceLocationEntry::symbolId, symbolId("function")), - HasLineColumn(14, 5)))); -} - -TEST_F(SymbolsCollector, DISABLED_ON_WINDOWS(CollectInUnsavedFile)) -{ - FileContainers unsaved{{{TESTDATA_DIR, "symbolscollector/generated_file.h"}, - filePathId({TESTDATA_DIR, "symbolscollector/generated_file.h"}), - "void function();", - {}}}; - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/unsaved.cpp"), {"cc"}); - collector.setUnsavedFiles(std::move(unsaved)); - - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), - Contains(HasSymbolName("function"))); -} - -TEST_F(SymbolsCollector, ClearSymbols) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - collector.collectSymbols(); - - collector.clear(); - - ASSERT_THAT(collector.symbols(), IsEmpty()); -} - -TEST_F(SymbolsCollector, ClearSourceLocations) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - collector.collectSymbols(); - - collector.clear(); - - ASSERT_THAT(collector.sourceLocations(), IsEmpty()); -} - -TEST_F(SymbolsCollector, DontCollectSymbolsAfterFilesAreCleared) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - - collector.clear(); - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), IsEmpty()); -} - -TEST_F(SymbolsCollector, CollectMacroDefinitionSourceLocation) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); - collector.setFile(fileId, {"cc", "-DCOMPILER_ARGUMENT"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("IF_NOT_DEFINE"), fileId, 4, 9, SourceLocationKind::MacroDefinition))); -} - -TEST_F(SymbolsCollector, DISABLED_CollectMacroUsageInIfNotDefSourceLocation) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); - collector.setFile(fileId, {"cc", "-DCOMPILER_ARGUMENT"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("IF_NOT_DEFINE"), fileId, 6, 9, SourceLocationKind::MacroUsage))); -} - -TEST_F(SymbolsCollector, DISABLED_CollectSecondMacroUsageInIfNotDefSourceLocation) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); - collector.setFile(fileId, {"cc", "-DCOMPILER_ARGUMENT"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("IF_NOT_DEFINE"), fileId, 9, 9, SourceLocationKind::MacroUsage))); -} - -TEST_F(SymbolsCollector, DISABLED_CollectMacroUsageCompilerArgumentSourceLocation) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); - collector.setFile(fileId, {"cc", "-DCOMPILER_ARGUMENT"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("COMPILER_ARGUMENT"), fileId, 12, 9, SourceLocationKind::MacroUsage))); -} - -TEST_F(SymbolsCollector, DISABLED_CollectMacroUsageInIfDefSourceLocation) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); - collector.setFile(fileId, {"cc", "-DCOMPILER_ARGUMENT"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("IF_DEFINE"), fileId, 17, 8, SourceLocationKind::MacroUsage))); -} - -TEST_F(SymbolsCollector, DISABLED_CollectMacroUsageInDefinedSourceLocation) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); - collector.setFile(fileId, {"cc", "-DCOMPILER_ARGUMENT"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("DEFINED"), fileId, 22, 13, SourceLocationKind::MacroUsage))); -} - -TEST_F(SymbolsCollector, CollectMacroUsageExpansionSourceLocation) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); - collector.setFile(fileId, {"cc", "-DCOMPILER_ARGUMENT"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("MACRO_EXPANSION"), fileId, 27, 10, SourceLocationKind::MacroUsage))); -} - -TEST_F(SymbolsCollector, CollectMacroUsageUndefSourceLocation) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); - collector.setFile(fileId, {"cc", "-DCOMPILER_ARGUMENT"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("UN_DEFINE"), fileId, 34, 8, SourceLocationKind::MacroUndefinition))); -} - -TEST_F(SymbolsCollector, DISABLED_CollectMacroUsageBuiltInSourceLocation) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); - collector.setFile(fileId, {"cc", "-DCOMPILER_ARGUMENT"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.sourceLocations(), - Contains(IsSourceLocationEntry(symbolId("__clang__"), fileId, 29, 9, SourceLocationKind::MacroUsage))); -} - -TEST_F(SymbolsCollector, CollectMacroDefinitionSymbols) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); - collector.setFile(fileId, {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), - Contains(AllOf(HasSymbolName("IF_NOT_DEFINE"), HasSymbolKind(SymbolKind::Macro)))); -} - -TEST_F(SymbolsCollector, DISABLED_CollectMacroBuiltInSymbols) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); - collector.setFile(fileId, {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), - Contains(AllOf(HasSymbolName("__clang__"), HasSymbolKind(SymbolKind::Macro)))); -} - -TEST_F(SymbolsCollector, DISABLED_CollectMacroCompilerArgumentSymbols) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); - collector.setFile(fileId, {"cc", "-DCOMPILER_ARGUMENT"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), - Contains(AllOf(HasSymbolName("COMPILER_ARGUMENT"), HasSymbolKind(SymbolKind::Macro)))); -} - -TEST_F(SymbolsCollector, IsClassSymbol) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/symbolkind.cpp"), {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), - Contains( - AllOf( - HasSymbolName("Class"), - HasSymbolKind(SymbolKind::Record), - HasSymbolTag(SymbolTag::Class)))); -} - -TEST_F(SymbolsCollector, IsStructSymbol) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/symbolkind.cpp"), {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), - Contains( - AllOf( - HasSymbolName("Struct"), - HasSymbolKind(SymbolKind::Record), - HasSymbolTag(SymbolTag::Struct)))); -} - -TEST_F(SymbolsCollector, IsEnumerationSymbol) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/symbolkind.cpp"), {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), - AllOf( - Contains( - AllOf( - HasSymbolName("Enumeration"), - HasSymbolKind(SymbolKind::Enumeration))), - Contains( - AllOf( - HasSymbolName("ScopedEnumeration"), - HasSymbolKind(SymbolKind::Enumeration))))); -} - -TEST_F(SymbolsCollector, IsUnionSymbol) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/symbolkind.cpp"), {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), - Contains( - AllOf( - HasSymbolName("Union"), - HasSymbolKind(SymbolKind::Record), - HasSymbolTag(SymbolTag::Union)))); -} - -TEST_F(SymbolsCollector, DISABLED_ON_NON_WINDOWS(IsMsvcInterfaceSymbol)) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/symbolkind.cpp"), {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), - Contains( - AllOf( - HasSymbolName("MsvcInterface"), - HasSymbolKind(SymbolKind::Record), - HasSymbolTag(SymbolTag::MsvcInterface)))); -} - -TEST_F(SymbolsCollector, IsFunctionSymbol) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/symbolkind.cpp"), {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), - Contains( - AllOf( - HasSymbolName("Function"), - HasSymbolKind(SymbolKind::Function)))); -} - -TEST_F(SymbolsCollector, IsVariableSymbol) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/symbolkind.cpp"), {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), - Contains( - AllOf( - HasSymbolName("Variable"), - HasSymbolKind(SymbolKind::Variable)))); -} - -TEST_F(SymbolsCollector, IndexUnmodifiedHeaderFilesAtFirstRun) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/unmodified.cpp"), - {"cc", "-I", {TESTDATA_DIR, "/symbolscollector/include"}}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), - AllOf( - Contains(HasSymbolName("MemberReference")), - Contains(HasSymbolName("HeaderFunction")), - Contains(HasSymbolName("HeaderFunctionReference")), - Contains(HasSymbolName("Class")), - Contains(HasSymbolName("Member")), - Contains(HasSymbolName("HEADER_DEFINE")), - Contains(HasSymbolName("FunctionLocalVariable")))); -} - -TEST_F(SymbolsCollector, DontIndexUnmodifiedHeaderFilesAtSecondRun) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/unmodified.cpp"), - {"cc", "-I", {TESTDATA_DIR, "/symbolscollector/include"}}); - collector.collectSymbols(); - collector.clear(); - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/unmodified2.cpp"), - {"cc", "-I", {TESTDATA_DIR, "/symbolscollector/include"}}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), - AllOf(Contains(HasSymbolName("HeaderFunctionReferenceInMainFile")), - Not(Contains(HasSymbolName("MemberReference"))), - Not(Contains(HasSymbolName("HeaderFunctionReference"))), - Not(Contains(HasSymbolName("HeaderFunction"))), - Not(Contains(HasSymbolName("Class"))), - Not(Contains(HasSymbolName("Member"))), - Not(Contains(HasSymbolName("HEADER_DEFINE"))))); -} - -TEST_F(SymbolsCollector, DontIndexUnmodifiedHeaderFilesAtTouchHeader) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/unmodified3.cpp"), - {"cc", "-I", {TESTDATA_DIR, "/symbolscollector/include"}}); - collector.collectSymbols(); - collector.clear(); - touchFile(TESTDATA_DIR "/symbolscollector/include/unmodified_header2.h"); - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/unmodified3.cpp"), - {"cc", "-I", {TESTDATA_DIR, "/symbolscollector/include"}}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), - AllOf(Contains(HasSymbolName("TouchHeaderFunction")), - Contains(HasSymbolName("HeaderFunctionReferenceInMainFile")), - Not(Contains(HasSymbolName("MemberReference"))), - Not(Contains(HasSymbolName("HeaderFunctionReference"))), - Not(Contains(HasSymbolName("HeaderFunction"))), - Not(Contains(HasSymbolName("Class"))), - Not(Contains(HasSymbolName("Member"))), - Not(Contains(HasSymbolName("HEADER_DEFINE"))))); -} - -TEST_F(SymbolsCollector, DontIndexSystemIncudes) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/unmodified.cpp"), - {"cc", "-isystem", {TESTDATA_DIR, "/symbolscollector/include"}}); - - collector.collectSymbols(); - - ASSERT_THAT(collector.symbols(), - AllOf( - Contains(HasSymbolName("MainFileFunction")), - Contains(HasSymbolName("HeaderFunctionReferenceInMainFile")), - Not(Contains(HasSymbolName("MemberReference"))), - Not(Contains(HasSymbolName("HeaderFunction"))), - Not(Contains(HasSymbolName("Class"))), - Not(Contains(HasSymbolName("Member"))), - Not(Contains(HasSymbolName("HEADER_DEFINE"))), - Not(Contains(HasSymbolName("FunctionLocalVariable"))))); -} - -TEST_F(SymbolsCollector, CollectReturnsFalseIfThereIsError) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/error.cpp"), {"cc"}); - - bool success = collector.collectSymbols(); - - ASSERT_FALSE(success); -} - -TEST_F(SymbolsCollector, CollectReturnsFalseIfThereIsNoError) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - - bool success = collector.collectSymbols(); - - ASSERT_TRUE(success); -} - -TEST_F(SymbolsCollector, ClearInputFilesAfterCollectingSymbols) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/main2.cpp"), {"cc"}); - collector.collectSymbols(); - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - - collector.collectSymbols(); - - ASSERT_TRUE(collector.isClean()); -} - -TEST_F(SymbolsCollector, ClassDeclarations) -{ - collector.setFile(filePathId(TESTDATA_DIR "/symbolscollector/class.cpp"), {"cc"}); - - collector.collectSymbols(); - - ASSERT_THAT( - collector.sourceLocations(), - AllOf(Contains(IsSourceLocationEntry(symbolId("Class"), - filePathId(TESTDATA_DIR "/symbolscollector/class.cpp"), - 1, - 7, - SourceLocationKind::Definition)), - Contains(IsSourceLocationEntry(symbolId("bar"), - filePathId(TESTDATA_DIR "/symbolscollector/class.cpp"), - 8, - 8, - SourceLocationKind::Definition)), - Contains(IsSourceLocationEntry(symbolId("foo"), - filePathId(TESTDATA_DIR "/symbolscollector/class.cpp"), - 11, - 13, - SourceLocationKind::Definition)), - Contains(IsSourceLocationEntry(symbolId("foo"), - filePathId(TESTDATA_DIR "/symbolscollector/class.cpp"), - 6, - 8, - SourceLocationKind::Declaration)), - Contains(IsSourceLocationEntry(symbolId("Class"), - filePathId(TESTDATA_DIR "/symbolscollector/class.cpp"), - 11, - 6, - SourceLocationKind::DeclarationReference)), - Contains(IsSourceLocationEntry(symbolId("bar"), - filePathId(TESTDATA_DIR "/symbolscollector/class.cpp"), - 13, - 5, - SourceLocationKind::DeclarationReference)))); -} -} // namespace diff --git a/tests/unit/unittest/symbolsfindfilter-test.cpp b/tests/unit/unittest/symbolsfindfilter-test.cpp deleted file mode 100644 index 38e43b717e9..00000000000 --- a/tests/unit/unittest/symbolsfindfilter-test.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include - -namespace { - -class SymbolsFindFilter : public ::testing::Test -{ -protected: - ClangRefactoring::SymbolsFindFilter symbolsFindFilter; -}; - -TEST_F(SymbolsFindFilter, FindAll) -{ - symbolsFindFilter.findAll("*", Core::FindRegularExpression); -} - -} diff --git a/tests/unit/unittest/symbolstorage-test.cpp b/tests/unit/unittest/symbolstorage-test.cpp deleted file mode 100644 index a73d261fcc1..00000000000 --- a/tests/unit/unittest/symbolstorage-test.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mockfilepathcaching.h" -#include "sqlitedatabasemock.h" - -#include -#include -#include -#include -#include -#include - -#include - -namespace { -using ClangBackEnd::FilePathCachingInterface; -using ClangBackEnd::FilePathId; -using ClangBackEnd::SourceLocationEntries; -using ClangBackEnd::SourceLocationEntry; -using ClangBackEnd::SourceLocationKind; -using ClangBackEnd::SourceTimeStamp; -using ClangBackEnd::SymbolEntries; -using ClangBackEnd::SymbolEntry; -using ClangBackEnd::SymbolIndex; -using ClangBackEnd::SymbolKind; -using Sqlite::Database; -using Sqlite::Table; -using Utils::PathString; - -using Storage = ClangBackEnd::SymbolStorage; -using DatabaseType = Database; -template -using ReadStatement = typename SqliteDatabaseMock::template ReadStatement; -using WriteStatement = typename SqliteDatabaseMock::WriteStatement; - -class SymbolStorage : public testing::Test -{ -protected: - NiceMock databaseMock; - Storage storage{databaseMock}; - WriteStatement &insertSymbolsToNewSymbolsStatement = storage.insertSymbolsToNewSymbolsStatement; - WriteStatement &insertLocationsToNewLocationsStatement = storage.insertLocationsToNewLocationsStatement; - ReadStatement<1> &selectNewSourceIdsStatement = storage.selectNewSourceIdsStatement; - WriteStatement &addNewSymbolsToSymbolsStatement = storage.addNewSymbolsToSymbolsStatement; - WriteStatement &syncNewSymbolsFromSymbolsStatement = storage.syncNewSymbolsFromSymbolsStatement; - WriteStatement &syncSymbolsIntoNewLocationsStatement = storage.syncSymbolsIntoNewLocationsStatement; - WriteStatement &deleteAllLocationsFromUpdatedFilesStatement = storage.deleteAllLocationsFromUpdatedFilesStatement; - WriteStatement &insertNewLocationsInLocationsStatement = storage.insertNewLocationsInLocationsStatement; - WriteStatement &deleteNewSymbolsTableStatement = storage.deleteNewSymbolsTableStatement; - WriteStatement &deleteNewLocationsTableStatement = storage.deleteNewLocationsTableStatement; - SymbolEntries symbolEntries{{1, {"functionUSR", "function", SymbolKind::Function}}, - {2, {"function2USR", "function2", SymbolKind::Function}}}; - SourceLocationEntries sourceLocations{{1, 3, {42, 23}, SourceLocationKind::Declaration}, - {2, 4, {7, 11}, SourceLocationKind::Definition}}; -}; - -TEST_F(SymbolStorage, CreateAndFillTemporaryLocationsTable) -{ - InSequence sequence; - - EXPECT_CALL(insertLocationsToNewLocationsStatement, write(TypedEq(1), TypedEq(42), TypedEq(23), TypedEq(3), TypedEq(int(SourceLocationKind::Declaration)))); - EXPECT_CALL(insertLocationsToNewLocationsStatement, write(TypedEq(2), TypedEq(7), TypedEq(11), TypedEq(4), TypedEq(int(SourceLocationKind::Definition)))); - - storage.fillTemporaryLocationsTable(sourceLocations); -} - -TEST_F(SymbolStorage, AddNewSymbolsToSymbols) -{ - EXPECT_CALL(addNewSymbolsToSymbolsStatement, execute()); - - storage.addNewSymbolsToSymbols(); -} - -TEST_F(SymbolStorage, SyncNewSymbolsFromSymbols) -{ - EXPECT_CALL(syncNewSymbolsFromSymbolsStatement, execute()); - - storage.syncNewSymbolsFromSymbols(); -} - -TEST_F(SymbolStorage, SyncSymbolsIntoNewLocations) -{ - EXPECT_CALL(syncSymbolsIntoNewLocationsStatement, execute()); - - storage.syncSymbolsIntoNewLocations(); -} - -TEST_F(SymbolStorage, DeleteAllLocationsFromUpdatedFiles) -{ - EXPECT_CALL(deleteAllLocationsFromUpdatedFilesStatement, execute()); - - storage.deleteAllLocationsFromUpdatedFiles(); -} - -TEST_F(SymbolStorage, InsertNewLocationsInLocations) -{ - EXPECT_CALL(insertNewLocationsInLocationsStatement, execute()); - - storage.insertNewLocationsInLocations(); -} - -TEST_F(SymbolStorage, DropNewSymbolsTable) -{ - EXPECT_CALL(deleteNewSymbolsTableStatement, execute()); - - storage.deleteNewSymbolsTable(); -} - -TEST_F(SymbolStorage, DropNewLocationsTable) -{ - EXPECT_CALL(deleteNewLocationsTableStatement, execute()); - - storage.deleteNewLocationsTable(); -} - -TEST_F(SymbolStorage, AddSymbolsAndSourceLocationsCallsWrite) -{ - InSequence sequence; - - EXPECT_CALL(insertSymbolsToNewSymbolsStatement, write(An(), An(), An(), An())).Times(2); - EXPECT_CALL(insertLocationsToNewLocationsStatement, write(TypedEq(1), TypedEq(42), TypedEq(23), TypedEq(3), TypedEq(int(SourceLocationKind::Declaration)))); - EXPECT_CALL(insertLocationsToNewLocationsStatement, write(TypedEq(2), TypedEq(7), TypedEq(11), TypedEq(4), TypedEq(int(SourceLocationKind::Definition)))); - EXPECT_CALL(addNewSymbolsToSymbolsStatement, execute()); - EXPECT_CALL(syncNewSymbolsFromSymbolsStatement, execute()); - EXPECT_CALL(syncSymbolsIntoNewLocationsStatement, execute()); - EXPECT_CALL(deleteAllLocationsFromUpdatedFilesStatement, execute()); - EXPECT_CALL(insertNewLocationsInLocationsStatement, execute()); - EXPECT_CALL(deleteNewSymbolsTableStatement, execute()); - EXPECT_CALL(deleteNewLocationsTableStatement, execute()); - - storage.addSymbolsAndSourceLocations(symbolEntries, sourceLocations); -} - -TEST_F(SymbolStorage, AddNewSymbolsTable) -{ - InSequence s; - - EXPECT_CALL(databaseMock, execute(Eq("CREATE TEMPORARY TABLE newSymbols(temporarySymbolId INTEGER PRIMARY KEY, symbolId INTEGER, usr TEXT, symbolName TEXT, symbolKind INTEGER)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_usr_symbolName ON newSymbols(usr, symbolName)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_symbolId ON newSymbols(symbolId)"))); - - storage.createNewSymbolsTable(); -} - -TEST_F(SymbolStorage, AddNewLocationsTable) -{ - InSequence s; - - EXPECT_CALL(databaseMock, execute(Eq("CREATE TEMPORARY TABLE newLocations(temporarySymbolId INTEGER, symbolId INTEGER, sourceId INTEGER, line INTEGER, column INTEGER, locationKind INTEGER)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_newLocations_sourceId_line_column ON newLocations(sourceId, line, column)"))); - - storage.createNewLocationsTable(); -} - -TEST_F(SymbolStorage, AddTablesInConstructor) -{ - InSequence s; - - EXPECT_CALL(databaseMock, immediateBegin()); - EXPECT_CALL(databaseMock, execute(Eq("CREATE TEMPORARY TABLE newSymbols(temporarySymbolId INTEGER PRIMARY KEY, symbolId INTEGER, usr TEXT, symbolName TEXT, symbolKind INTEGER)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_usr_symbolName ON newSymbols(usr, symbolName)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE INDEX IF NOT EXISTS index_newSymbols_symbolId ON newSymbols(symbolId)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE TEMPORARY TABLE newLocations(temporarySymbolId INTEGER, symbolId INTEGER, sourceId INTEGER, line INTEGER, column INTEGER, locationKind INTEGER)"))); - EXPECT_CALL(databaseMock, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_newLocations_sourceId_line_column ON newLocations(sourceId, line, column)"))); - EXPECT_CALL(databaseMock, commit()); - - Storage storage{databaseMock}; -} - -} // namespace diff --git a/tests/unit/unittest/taskscheduler-test.cpp b/tests/unit/unittest/taskscheduler-test.cpp deleted file mode 100644 index 7b6d0bbcbfe..00000000000 --- a/tests/unit/unittest/taskscheduler-test.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include "mocksymbolindexertaskqueue.h" -#include "mockprocessormanager.h" -#include "mocksymbolscollector.h" - -#include - -#include - -namespace { - -using Task = std::function; - -using ClangBackEnd::ProcessorInterface; -using ClangBackEnd::SymbolsCollectorInterface; -using ClangBackEnd::SymbolStorageInterface; -using ClangBackEnd::SlotUsage; -using NiceMockProcessorManager = NiceMock; -using Scheduler = ClangBackEnd::TaskScheduler; - -class TaskScheduler : public testing::Test -{ -protected: - void SetUp() - { - ON_CALL(mockProcessorManager, unusedProcessor()).WillByDefault(ReturnRef(mockSymbolsCollector)); - progressCounter.addTotal(100); - } - void TearDown() - { - scheduler.syncTasks(); - QCoreApplication::processEvents(); - } - -protected: - MockFunction mock; - Task call{[&] (ClangBackEnd::ProcessorInterface&) { mock.Call(); }}; - Task nocall{[&] (ClangBackEnd::ProcessorInterface&) {}}; - NiceMockProcessorManager mockProcessorManager; - NiceMock mockSymbolsCollector; - NiceMock mockSymbolIndexerTaskQueue; - NiceMock> mockSetProgressCallback; - ClangBackEnd::ProgressCounter progressCounter{mockSetProgressCallback.AsStdFunction()}; - Scheduler scheduler{mockProcessorManager, - mockSymbolIndexerTaskQueue, - progressCounter, - 4, - ClangBackEnd::CallDoInMainThreadAfterFinished::Yes}; - Scheduler deferredScheduler{mockProcessorManager, - mockSymbolIndexerTaskQueue, - progressCounter, - 4, - ClangBackEnd::CallDoInMainThreadAfterFinished::Yes, - std::launch::deferred}; -}; - -TEST_F(TaskScheduler, AddTasks) -{ - deferredScheduler.addTasks({nocall}); - - ASSERT_THAT(deferredScheduler.futures(), SizeIs(1)); -} - -TEST_F(TaskScheduler, AddTasksCallsFunction) -{ - EXPECT_CALL(mock, Call()).Times(2); - - scheduler.addTasks({call, call}); -} - -TEST_F(TaskScheduler, FreeSlots) -{ - deferredScheduler.addTasks({nocall, nocall}); - - auto slotUsage = deferredScheduler.slotUsage(); - - ASSERT_THAT(slotUsage, AllOf(Field(&SlotUsage::free, 2), Field(&SlotUsage::used, 2))); -} - -TEST_F(TaskScheduler, ReturnZeroFreeSlotsIfMoreCallsThanCores) -{ - deferredScheduler.addTasks({nocall, nocall, nocall, nocall, nocall, nocall}); - - auto slotUsage = deferredScheduler.slotUsage(); - - ASSERT_THAT(slotUsage, AllOf(Field(&SlotUsage::free, 0), Field(&SlotUsage::used, 6))); -} - -TEST_F(TaskScheduler, FreeSlotsAfterFinishing) -{ - scheduler.addTasks({nocall, nocall}); - scheduler.syncTasks(); - - auto slotUsage = scheduler.slotUsage(); - - ASSERT_THAT(slotUsage, AllOf(Field(&SlotUsage::free, 4), Field(&SlotUsage::used, 0))); -} - -TEST_F(TaskScheduler, NoFuturesAfterFreeSlots) -{ - scheduler.addTasks({nocall, nocall}); - scheduler.syncTasks(); - - scheduler.slotUsage(); - - ASSERT_THAT(scheduler.futures(), IsEmpty()); -} - -TEST_F(TaskScheduler, FreeSlotsCallsCleanupMethodsAfterTheWorkIsDone) -{ - scheduler.addTasks({nocall, nocall}); - scheduler.syncTasks(); - InSequence s; - - EXPECT_CALL(mockSymbolsCollector, doInMainThreadAfterFinished()); - EXPECT_CALL(mockSymbolsCollector, setIsUsed(false)); - EXPECT_CALL(mockSymbolsCollector, clear()); - EXPECT_CALL(mockSymbolsCollector, doInMainThreadAfterFinished()); - EXPECT_CALL(mockSymbolsCollector, setIsUsed(false)); - EXPECT_CALL(mockSymbolsCollector, clear()); - - scheduler.slotUsage(); -} - -TEST_F(TaskScheduler, FreeSlotsDoNotCallsDoInMainThreadAfterFinishedAfterTheWorkIsDoneIfForbidden) -{ - Scheduler scheduler{mockProcessorManager, - mockSymbolIndexerTaskQueue, - progressCounter, - 4, - ClangBackEnd::CallDoInMainThreadAfterFinished::No}; - scheduler.addTasks({nocall, nocall}); - scheduler.syncTasks(); - InSequence s; - - EXPECT_CALL(mockSymbolsCollector, doInMainThreadAfterFinished()).Times(0); - - scheduler.slotUsage(); - scheduler.syncTasks(); - QCoreApplication::processEvents(); -} - -TEST_F(TaskScheduler, FreeSlotsCallsProgressMethodsAfterTheWorkIsDone) -{ - scheduler.addTasks({nocall, nocall}); - scheduler.syncTasks(); - InSequence s; - - EXPECT_CALL(mockSetProgressCallback, Call(2, 100)); - - scheduler.slotUsage(); -} - -TEST_F(TaskScheduler, AddTaskCallSymbolsCollectorManagerUnusedSymbolsCollector) -{ - EXPECT_CALL(mockProcessorManager, unusedProcessor()).Times(2); - - scheduler.addTasks({nocall, nocall}); -} - -TEST_F(TaskScheduler, CallProcessTasksInQueueAfterFinishedTasks) -{ - InSequence s; - - EXPECT_CALL(mock, Call()); - EXPECT_CALL(mockSymbolIndexerTaskQueue, processEntries()); - - scheduler.addTasks({call}); - scheduler.syncTasks(); -} -} diff --git a/tests/unit/unittest/testclangtool.cpp b/tests/unit/unittest/testclangtool.cpp deleted file mode 100644 index bea5afeb4c8..00000000000 --- a/tests/unit/unittest/testclangtool.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "testclangtool.h" - -TestClangTool::TestClangTool(ClangBackEnd::FilePath &&filePath, - Utils::SmallString &&content, - Utils::SmallStringVector &&commandLine) -{ - addFile(std::move(filePath), std::move(content), std::move(commandLine)); - - auto clangTool = createTool(); - - clangTool.buildASTs(asts); -} - -const clang::ASTUnit *TestClangTool::ast() const -{ - return asts.front().get(); -} - -const clang::SourceManager &TestClangTool::sourceManager() const -{ - return ast()->getSourceManager(); -} - -const clang::LangOptions &TestClangTool::languageOptions() const -{ - return ast()->getLangOpts(); -} diff --git a/tests/unit/unittest/testclangtool.h b/tests/unit/unittest/testclangtool.h deleted file mode 100644 index 448c4e51ae8..00000000000 --- a/tests/unit/unittest/testclangtool.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include - -class TestClangTool : public ClangBackEnd::ClangTool -{ -public: - TestClangTool(ClangBackEnd::FilePath &&filePath, - Utils::SmallString &&content, - Utils::SmallStringVector &&commandLine); - - const clang::ASTUnit *ast() const; - const clang::SourceManager &sourceManager() const; - const clang::LangOptions &languageOptions() const; - -private: - std::vector> asts; -}; - diff --git a/tests/unit/unittest/testenvironment.h b/tests/unit/unittest/testenvironment.h deleted file mode 100644 index 1e6c7da862c..00000000000 --- a/tests/unit/unittest/testenvironment.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** -** -** 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 - -#include - -#include - -#include - -class TestEnvironment final : public ClangBackEnd::Environment -{ -public: - TestEnvironment() { temporaryDirectory.setAutoRemove(true); } - - Utils::PathString pchBuildDirectory() const override { return temporaryDirectory.path(); } - uint hardwareConcurrency() const { return 2; } - ClangBackEnd::NativeFilePathView preIncludeSearchPath() const override - { - return includeSearchPath; - } - -private: - QTemporaryDir temporaryDirectory; - ClangBackEnd::NativeFilePath includeSearchPath{ - ClangBackEnd::FilePath{TESTDATA_DIR "/preincludes"}}; -}; diff --git a/tests/unit/unittest/toolchainargumentscache-test.cpp b/tests/unit/unittest/toolchainargumentscache-test.cpp deleted file mode 100644 index de088f65374..00000000000 --- a/tests/unit/unittest/toolchainargumentscache-test.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include - -namespace { - -using ClangBackEnd::ProjectPartContainer; -using ClangBackEnd::ProjectPartIds; - -MATCHER_P2(IsEntry, - projectPartIds, - arguments, - std::string(negation ? "isn't " : "is ") - + PrintToString(ClangBackEnd::ArgumentsEntry(Utils::clone(projectPartIds), arguments))) -{ - const ClangBackEnd::ArgumentsEntry &entry= arg; - - return entry.ids == projectPartIds && entry.arguments == arguments; -} - -class ToolChainArgumentsCache : public testing::Test -{ -public: - ClangBackEnd::ToolChainsArgumentsCache cache; - ProjectPartContainer projectPart1{1, {}, {}, {}, {}, {}, {}, {}, {}, {}}; - ProjectPartContainer projectPart2{2, {}, {}, {}, {}, {}, {}, {}, {}, {}}; - ProjectPartContainer projectPart3{3, {}, {}, {}, {}, {}, {}, {}, {}, {}}; - ProjectPartContainer projectPart4{4, {}, {}, {}, {}, {}, {}, {}, {}, {}}; - Utils::SmallStringVector arguments1{"yi", "er"}; - Utils::SmallStringVector arguments2{"san", "se"}; -}; - -TEST_F(ToolChainArgumentsCache, ArgumentsDoesNotExistForProjectPartId) -{ - cache.update({projectPart2, projectPart4}, arguments2); - - ASSERT_THAT(cache.arguments({projectPart1.projectPartId}), IsEmpty()); -} - -TEST_F(ToolChainArgumentsCache, AddNewArguments) -{ - cache.update({projectPart2, projectPart4}, arguments2); - - cache.update({projectPart1, projectPart3}, arguments1); - - ASSERT_THAT(cache.arguments({projectPart1.projectPartId}), - ElementsAre(IsEntry(ProjectPartIds{projectPart1.projectPartId}, arguments1))); -} - -TEST_F(ToolChainArgumentsCache, AddDifferentProjectParts) -{ - cache.update({projectPart1, projectPart3}, arguments1); - - cache.update({projectPart2, projectPart4}, arguments1); - - ASSERT_THAT(cache.arguments(ProjectPartIds{projectPart2.projectPartId}), - ElementsAre(IsEntry(ProjectPartIds{projectPart2.projectPartId}, arguments1))); -} - -TEST_F(ToolChainArgumentsCache, AddDifferentProjectPartsReverseOrder) -{ - cache.update({projectPart2, projectPart3}, arguments1); - - cache.update({projectPart1, projectPart4}, arguments1); - - ASSERT_THAT(cache.arguments(ProjectPartIds{projectPart2.projectPartId}), - ElementsAre(IsEntry(ProjectPartIds{projectPart2.projectPartId}, arguments1))); -} - -TEST_F(ToolChainArgumentsCache, AddDifferentProjectPartsDoesNotRemoveOldEntry) -{ - cache.update({projectPart1, projectPart3}, arguments1); - - cache.update({projectPart2, projectPart4}, arguments1); - - ASSERT_THAT(cache.arguments(ProjectPartIds{projectPart1.projectPartId}), - ElementsAre(IsEntry(ProjectPartIds{projectPart1.projectPartId}, arguments1))); -} - -TEST_F(ToolChainArgumentsCache, AddSameArgumentsDoesNotIncreseEntryCount) -{ - cache.update({projectPart1, projectPart3}, arguments1); - - cache.update({projectPart2, projectPart4}, arguments1); - - ASSERT_THAT(cache.size(), 1); -} - -TEST_F(ToolChainArgumentsCache, AddDifferentArgumentsDoesIncreseEntryCount) -{ - cache.update({projectPart1, projectPart3}, arguments1); - - cache.update({projectPart2, projectPart4}, arguments2); - - ASSERT_THAT(cache.size(), 2); -} - -TEST_F(ToolChainArgumentsCache, RemoveIdsFromOtherEntries) -{ - cache.update({projectPart2, projectPart4}, arguments1); - cache.update({projectPart1, projectPart3}, arguments1); - - cache.update({projectPart2, projectPart4}, arguments2); - - ASSERT_THAT(cache.arguments(ProjectPartIds{projectPart2.projectPartId}), - ElementsAre(IsEntry(ProjectPartIds{projectPart2.projectPartId}, arguments2))); -} - -TEST_F(ToolChainArgumentsCache, RemoveIdsFromOtherEntriesWithArgumentsAlreadyExists) -{ - cache.update({projectPart2, projectPart4}, arguments1); - cache.update({projectPart1, projectPart3}, arguments2); - - cache.update({projectPart2, projectPart4}, arguments2); - - ASSERT_THAT(cache.arguments({projectPart2.projectPartId}), - ElementsAre(IsEntry(ProjectPartIds{projectPart2.projectPartId}, arguments2))); -} - -TEST_F(ToolChainArgumentsCache, RemoveEntryIfEmpty) -{ - cache.update({projectPart2, projectPart4}, arguments2); - cache.update({projectPart1, projectPart3}, arguments1); - - cache.update({projectPart2, projectPart4}, arguments1); - - ASSERT_THAT(cache.size(), 1); -} - -TEST_F(ToolChainArgumentsCache, GetMutipleEntries) -{ - cache.update({projectPart2, projectPart4}, arguments1); - cache.update({projectPart1, projectPart3}, arguments2); - - auto arguments = cache.arguments( - {projectPart1.projectPartId, projectPart2.projectPartId, projectPart3.projectPartId}); - - ASSERT_THAT(arguments, - ElementsAre(IsEntry(ProjectPartIds{projectPart2.projectPartId}, arguments1), - IsEntry(ProjectPartIds{projectPart1.projectPartId, - projectPart3.projectPartId}, - arguments2))); -} - -TEST_F(ToolChainArgumentsCache, RemoveMutipleIds) -{ - cache.update({projectPart2, projectPart4}, arguments1); - cache.update({projectPart1, projectPart3}, arguments2); - - cache.remove({projectPart1.projectPartId, projectPart2.projectPartId}); - - ASSERT_THAT(cache.arguments({projectPart1.projectPartId, - projectPart2.projectPartId, - projectPart3.projectPartId}), - ElementsAre(IsEntry(ProjectPartIds{projectPart3.projectPartId}, arguments2))); -} - -TEST_F(ToolChainArgumentsCache, RemoveEntriesIfEntryIsEmptyAfterRemovingIds) -{ - cache.update({projectPart2, projectPart4}, arguments1); - cache.update({projectPart1, projectPart3}, arguments2); - - cache.remove({projectPart1.projectPartId, projectPart3.projectPartId}); - - ASSERT_THAT(cache.size(), 1); -} - -} // namespace diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro index d9f1ba95178..2c4d4529379 100644 --- a/tests/unit/unittest/unittest.pro +++ b/tests/unit/unittest/unittest.pro @@ -54,19 +54,12 @@ QMAKE_SUBSTITUTES += cpptoolsjson DEFINES += CPPTOOLS_JSON=\"R\\\"xxx($${cpptoolsjson.output})xxx\\\"\" SOURCES += \ - clangindexingsettingsmanager-test.cpp \ - clangpathwatcher-test.cpp \ - clangqueryexamplehighlightmarker-test.cpp \ - clangqueryhighlightmarker-test.cpp \ clientserverinprocess-test.cpp \ clientserveroutsideprocess-test.cpp \ cppprojectfilecategorizer-test.cpp \ cppprojectinfogenerator-test.cpp \ cppprojectpartchooser-test.cpp \ - directorypathcompressor-test.cpp \ fakeprocess.cpp \ - filepath-test.cpp \ - filepathview-test.cpp \ gtest-creator-printing.cpp \ gtest-qt-printing.cpp \ asynchronousimagecache-test.cpp \ @@ -80,64 +73,25 @@ SOURCES += \ lastchangedrowid-test.cpp \ lineprefixer-test.cpp \ listmodeleditor-test.cpp \ - locatorfilter-test.cpp \ mimedatabase-utilities.cpp \ - pchmanagerclientserverinprocess-test.cpp \ - pchmanagerclient-test.cpp \ - pchmanagerserver-test.cpp \ - preprocessormacrocollector-test.cpp \ processevents-utilities.cpp \ - projectpartsmanager-test.cpp \ - projectpartsstorage-test.cpp \ - projectupdater-test.cpp \ readandwritemessageblock-test.cpp \ sizedarray-test.cpp \ smallstring-test.cpp \ - sourcerangefilter-test.cpp \ spydummy.cpp \ sqlitesessions-test.cpp \ sqlitevalue-test.cpp \ - symbolindexer-test.cpp \ - symbolsfindfilter-test.cpp \ - stringcache-test.cpp \ eventspy.cpp \ unittests-main.cpp \ utf8-test.cpp \ - symbolstorage-test.cpp \ - symbolquery-test.cpp \ sqliteindex-test.cpp \ sqlitetransaction-test.cpp \ - refactoringdatabaseinitializer-test.cpp \ - filepathcache-test.cpp \ - filepathstorage-test.cpp \ - filepathstoragesqlitestatementfactory-test.cpp \ processcreator-test.cpp \ - nativefilepath-test.cpp \ - nativefilepathview-test.cpp \ mocktimer.cpp \ - projectpartartefact-test.cpp \ - filestatuscache-test.cpp \ - precompiledheaderstorage-test.cpp \ - generatedfiles-test.cpp \ - sourcesmanager-test.cpp \ - symbolindexertaskqueue-test.cpp \ - refactoringprojectupdater-test.cpp \ - processormanager-test.cpp \ task.cpp \ - taskscheduler-test.cpp \ compileroptionsbuilder-test.cpp \ - progresscounter-test.cpp \ - pchtaskgenerator-test.cpp \ compilationdatabaseutils-test.cpp \ - builddependenciesprovider-test.cpp \ - builddependenciesstorage-test.cpp \ - usedmacrofilter-test.cpp \ - pchtasksmerger-test.cpp \ - pchtaskqueue-test.cpp \ - commandlinebuilder-test.cpp \ headerpathfilter-test.cpp \ - toolchainargumentscache-test.cpp \ - modifiedtimechecker-test.cpp \ sqlitecolumn-test.cpp \ sqlitedatabasebackend-test.cpp \ sqlitedatabase-test.cpp \ @@ -216,23 +170,6 @@ SOURCES += \ !isEmpty(LIBTOOLING_LIBS) { SOURCES += \ gtest-llvm-printing.cpp \ - clangquerygatherer-test.cpp \ - clangqueryprojectfindfilter-test.cpp \ - clangquery-test.cpp \ - pchcreator-test.cpp \ - refactoringclientserverinprocess-test.cpp \ - refactoringclient-test.cpp \ - refactoringcompilationdatabase-test.cpp \ - refactoringserver-test.cpp \ - sourcerangeextractor-test.cpp \ - symbolindexing-test.cpp \ - symbolscollector-test.cpp \ - testclangtool.cpp \ - usedmacrocollector-test.cpp \ - builddependencycollector-test.cpp - -!isEmpty(QTC_UNITTEST_BUILD_CPP_PARSER):SOURCES += refactoringengine-test.cpp - } !isEmpty(CLANGFORMAT_LIBS) { @@ -262,63 +199,28 @@ HEADERS += \ mimedatabase-utilities.h \ mockclangcodemodelclient.h \ mockclangcodemodelserver.h \ - mockclangpathwatcher.h \ - mockclangpathwatchernotifier.h \ mockfilesystem.h \ mockimagecachegenerator.h \ mockimagecachestorage.h \ mocklistmodeleditorview.h \ - mockpchcreator.h \ - mockpchmanagerclient.h \ - mockpchmanagernotifier.h \ - mockpchmanagerserver.h \ - mockprojectpartsmanager.h \ - mockprojectpartsstorage.h \ mockqfilesystemwatcher.h \ - mocksearch.h \ - mocksearchhandle.h \ - mocksearchresult.h \ mocksyntaxhighligher.h \ mocktimestampprovider.h \ notification.h \ processevents-utilities.h \ sourcerangecontainer-matcher.h \ spydummy.h \ - testenvironment.h \ - mocksymbolscollector.h \ - mocksymbolstorage.h \ google-using-declarations.h \ - mocksymbolindexing.h \ sqliteteststatement.h \ mockmutex.h \ - mockfilepathstorage.h \ - mockfilepathcaching.h \ mocksqlitestatement.h \ unittest-utility-functions.h \ - mocksymbolquery.h \ rundocumentparse-utility.h \ mocktimer.h \ mocksqlitetransactionbackend.h \ - mockprojectpartprovider.h \ - mockprecompiledheaderstorage.h \ - mockeditormanager.h \ - mocksymbolindexertaskqueue.h \ mockcppmodelmanager.h \ - mockgeneratedfiles.h \ mockqueue.h \ - mockprojectpartqueue.h \ - mockprocessor.h \ - mockprocessormanager.h \ - mocktaskscheduler.h \ - mockprogressmanager.h \ mockfutureinterface.h \ - mockbuilddependenciesprovider.h \ - mockmodifiedtimechecker.h \ - mockbuilddependenciesstorage.h \ - mockbuilddependencygenerator.h \ - mockpchtasksmerger.h \ - mockpchtaskqueue.h \ - mockpchtaskgenerator.h \ ../mockup/qmldesigner/designercore/include/nodeinstanceview.h \ ../mockup/qmldesigner/designercore/include/rewriterview.h \ ../mockup/qmldesigner/designercore/include/itemlibraryitem.h\ @@ -340,11 +242,4 @@ HEADERS += \ gtest-clang-printing.h } -!isEmpty(LIBTOOLING_LIBS) { -HEADERS += \ - mockrefactoringclient.h \ - mockrefactoringserver.h \ - testclangtool.h -} - OTHER_FILES += $$files(data/*) $$files(data/include/*) diff --git a/tests/unit/unittest/unittest.qbs b/tests/unit/unittest/unittest.qbs index 7f2bea7cf8a..436bb3080bf 100644 --- a/tests/unit/unittest/unittest.qbs +++ b/tests/unit/unittest/unittest.qbs @@ -84,7 +84,6 @@ Project { "QT_RESTRICTED_CAST_FROM_ASCII", "QT_USE_FAST_OPERATOR_PLUS", "QT_USE_FAST_CONCATENATION", - "CLANGPCHMANAGER_STATIC_LIB", "CLANGSUPPORT_BUILD_STATIC_LIB", "CLANGTOOLS_STATIC_LIBRARY", "CPPTOOLS_STATIC_LIBRARY", @@ -102,8 +101,6 @@ Project { ]; if (libclang.present) { defines.push("CLANG_UNIT_TESTS"); - if (libclang.toolingEnabled) - defines = defines.concat(libclang.llvmToolingDefines); } return defines; } @@ -124,8 +121,6 @@ Project { } if (qbs.toolchain.contains("gcc")) flags.push("-Wno-unused-parameter"); - if (libclang.present && libclang.toolingEnabled) - flags = flags.concat(libclang.llvmToolingCxxFlags); return flags; } cpp.cxxLanguageVersion: "c++17" @@ -133,8 +128,6 @@ Project { var libs = []; if (libclang.present) { libs = libs.concat(libclang.llvmLibs); - if (libclang.toolingEnabled) - libs = libs.concat(libclang.llvmToolingLibs); if (libclang.llvmFormattingLibs.length && (!qbs.targetOS.contains("windows") || libclang.llvmBuildModeMatches)) { libs = libs.concat(libclang.llvmFormattingLibs); @@ -151,17 +144,11 @@ Project { "../../../src/libs/clangsupport", "../../../src/plugins", "../../../src/plugins/clangcodemodel", - "../../../src/plugins/clangpchmanager", - "../../../src/plugins/clangrefactoring", "../../../src/tools/clangbackend/source", - "../../../src/tools/clangpchmanagerbackend/source", - "../../../src/tools/clangrefactoringbackend/source", "../../../share/qtcreator/qml/qmlpuppet/types", ]; if (libclang.present) { paths.push(libclang.llvmIncludeDir); - if (libclang.toolingEnabled) - paths = paths.concat(libclang.llvmToolingIncludes); } return paths; } @@ -182,15 +169,8 @@ Project { } files: [ - "builddependenciesprovider-test.cpp", - "builddependenciesstorage-test.cpp", - "clangindexingsettingsmanager-test.cpp", - "clangpathwatcher-test.cpp", - "clangqueryexamplehighlightmarker-test.cpp", - "clangqueryhighlightmarker-test.cpp", "clientserverinprocess-test.cpp", "clientserveroutsideprocess-test.cpp", - "commandlinebuilder-test.cpp", "compare-operators.h", "compilationdatabaseutils-test.cpp", "compileroptionsbuilder-test.cpp", @@ -199,21 +179,13 @@ Project { "cppprojectinfogenerator-test.cpp", "cppprojectpartchooser-test.cpp", "createtablesqlstatementbuilder-test.cpp", - "directorypathcompressor-test.cpp", "dummyclangipcclient.h", "dynamicastmatcherdiagnosticcontainer-matcher.h", "eventspy.cpp", "eventspy.h", "fakeprocess.cpp", "fakeprocess.h", - "filepath-test.cpp", - "filepathcache-test.cpp", - "filepathstorage-test.cpp", - "filepathstoragesqlitestatementfactory-test.cpp", - "filepathview-test.cpp", - "filestatuscache-test.cpp", "filesystem-utilities.h", - "generatedfiles-test.cpp", "google-using-declarations.h", "googletest.h", "gtest-creator-printing.cpp", @@ -223,86 +195,29 @@ Project { "gtest-qt-printing.h", "headerpathfilter-test.cpp", "lineprefixer-test.cpp", - "locatorfilter-test.cpp", "matchingtext-test.cpp", "mimedatabase-utilities.cpp", "mimedatabase-utilities.h", - "mockbuilddependenciesprovider.h", - "mockbuilddependenciesstorage.h", - "mockbuilddependencygenerator.h", "mockclangcodemodelclient.h", "mockclangcodemodelserver.h", - "mockclangpathwatcher.h", - "mockclangpathwatchernotifier.h", "mockcppmodelmanager.h", - "mockeditormanager.h", - "mockfilepathcaching.h", - "mockfilepathstorage.h", - "mockfilesystem.h", "mockfutureinterface.h", - "mockgeneratedfiles.h", - "mockmodifiedtimechecker.h", "mockmutex.h", - "mockpchcreator.h", - "mockpchmanagerclient.h", - "mockpchmanagernotifier.h", - "mockpchmanagerserver.h", - "mockpchtaskgenerator.h", - "mockpchtaskqueue.h", - "mockpchtasksmerger.h", - "mockprecompiledheaderstorage.h", - "mockprocessor.h", - "mockprocessormanager.h", - "mockprogressmanager.h", - "mockprojectpartprovider.h", - "mockprojectpartqueue.h", - "mockprojectpartsmanager.h", - "mockprojectpartsstorage.h", "mockqfilesystemwatcher.h", "mockqueue.h", - "mocksearch.h", - "mocksearchhandle.h", - "mocksearchresult.h", "mocksqlitestatement.h", "mocksqlitetransactionbackend.h", - "mocksymbolindexertaskqueue.h", - "mocksymbolindexing.h", - "mocksymbolquery.h", - "mocksymbolscollector.h", - "mocksymbolstorage.h", "mocksyntaxhighligher.h", - "mocktaskscheduler.h", "mocktimer.cpp", "mocktimer.h", - "modifiedtimechecker-test.cpp", - "nativefilepath-test.cpp", - "nativefilepathview-test.cpp", - "pchmanagerclient-test.cpp", - "pchmanagerclientserverinprocess-test.cpp", - "pchmanagerserver-test.cpp", - "pchtaskgenerator-test.cpp", - "pchtaskqueue-test.cpp", - "pchtasksmerger-test.cpp", - "precompiledheaderstorage-test.cpp", - "preprocessormacrocollector-test.cpp", "processcreator-test.cpp", "processevents-utilities.cpp", "processevents-utilities.h", - "processormanager-test.cpp", - "progresscounter-test.cpp", - "projectpartartefact-test.cpp", - "projectpartsmanager-test.cpp", - "projectpartsstorage-test.cpp", - "projectupdater-test.cpp", "readandwritemessageblock-test.cpp", - "refactoringdatabaseinitializer-test.cpp", - "refactoringprojectupdater-test.cpp", "rundocumentparse-utility.h", "sizedarray-test.cpp", "smallstring-test.cpp", "sourcerangecontainer-matcher.h", - "sourcerangefilter-test.cpp", - "sourcesmanager-test.cpp", "spydummy.cpp", "spydummy.h", "sqlitecolumn-test.cpp", @@ -320,19 +235,9 @@ Project { "sqlitewritestatementmock.cpp", "sqlitewritestatementmock.h", "sqlstatementbuilder-test.cpp", - "stringcache-test.cpp", - "symbolindexer-test.cpp", - "symbolindexertaskqueue-test.cpp", - "symbolquery-test.cpp", - "symbolsfindfilter-test.cpp", - "symbolstorage-test.cpp", "task.cpp", - "taskscheduler-test.cpp", - "testenvironment.h", - "toolchainargumentscache-test.cpp", "unittest-utility-functions.h", "unittests-main.cpp", - "usedmacrofilter-test.cpp", "utf8-test.cpp", ] @@ -397,34 +302,6 @@ Project { ] } - Group { - name: "clang tooling tests" - condition: libclang.present && libclang.toolingEnabled - files: [ - "builddependencycollector-test.cpp", - "clangdocumentsuspenderresumer-test.cpp", - "clangquery-test.cpp", - "clangquerygatherer-test.cpp", - "clangqueryprojectfindfilter-test.cpp", - "clangreferencescollector-test.cpp", - "gtest-llvm-printing.cpp", - "mockrefactoringclient.h", - "mockrefactoringserver.h", - "pchcreator-test.cpp", - "refactoringclient-test.cpp", - "refactoringclientserverinprocess-test.cpp", - "refactoringcompilationdatabase-test.cpp", - "refactoringengine-test.cpp", - "refactoringserver-test.cpp", - "sourcerangeextractor-test.cpp", - "symbolindexing-test.cpp", - "symbolscollector-test.cpp", - "testclangtool.cpp", - "testclangtool.h", - "usedmacrocollector-test.cpp", - ] - } - Group { name: "ClangFormat tests" condition: libclang.present @@ -454,155 +331,6 @@ Project { fileTags: "pluginJsonIn" } - Group { - name: "sources from pchmanager" - prefix: "../../../src/plugins/clangpchmanager/" - files: [ - "clangindexingprojectsettings.cpp", - "clangindexingprojectsettings.h", - "clangindexingsettingsmanager.cpp", - "clangindexingsettingsmanager.h", - "clangpchmanager_global.h", - "pchmanagerclient.cpp", - "pchmanagerclient.h", - "pchmanagerconnectionclient.cpp", - "pchmanagerconnectionclient.h", - "pchmanagernotifierinterface.cpp", - "pchmanagernotifierinterface.h", - "pchmanagerprojectupdater.cpp", - "pchmanagerprojectupdater.h", - "preprocessormacrocollector.cpp", - "preprocessormacrocollector.h", - "progressmanager.h", - "progressmanagerinterface.h", - "projectupdater.cpp", - "projectupdater.h", - ] - } - - Group { - name: "sources from pchmanager backend" - prefix: "../../../src/tools/clangpchmanagerbackend/source/" - files: [ - "builddependenciesprovider.cpp", - "builddependenciesprovider.h", - "builddependenciesproviderinterface.h", - "builddependenciesstorage.h", - "builddependenciesstorageinterface.h", - "builddependency.h", - "builddependencygeneratorinterface.h", - "clangpchmanagerbackend_global.h", - "generatepchactionfactory.h", - "pchcreatorinterface.h", - "pchmanagerserver.cpp", - "pchmanagerserver.h", - "pchnotcreatederror.h", - "pchtask.h", - "pchtaskgenerator.cpp", - "pchtaskgenerator.h", - "pchtaskgeneratorinterface.h", - "pchtaskqueue.cpp", - "pchtaskqueue.h", - "pchtaskqueueinterface.h", - "pchtasksmerger.cpp", - "pchtasksmerger.h", - "pchtasksmergerinterface.h", - "precompiledheaderstorage.h", - "precompiledheaderstorageinterface.h", - "processorinterface.h", - "processormanagerinterface.h", - "projectpartsmanager.cpp", - "projectpartsmanager.h", - "projectpartsmanagerinterface.h", - "queueinterface.h", - "taskscheduler.h", - "taskschedulerinterface.h", - "toolchainargumentscache.h", - "usedmacrofilter.h", - ] - - Group { - name: "tooling sources from pchmanager backend" - condition: libclang.toolingEnabled - files: [ - "builddependencycollector.cpp", - "builddependencycollector.h", - "collectbuilddependencyaction.h", - "collectbuilddependencypreprocessorcallbacks.h", - "collectbuilddependencytoolaction.h", - "collectusedmacroactionfactory.h", - "collectusedmacrosaction.h", - "collectusedmacrosandsourcespreprocessorcallbacks.h", - "pchcreator.cpp", - "pchcreator.h", - "processormanager.h", - "usedmacrosandsourcescollector.cpp", - "usedmacrosandsourcescollector.h", - ] - } - } - - Group { - name: "sources from clangrefactoring backend" - prefix: "../../../src/tools/clangrefactoringbackend/source/" - files: [ - "clangrefactoringbackend_global.h", - "collectmacrospreprocessorcallbacks.h", - "projectpartentry.h", - "sourcedependency.h", - "sourcelocationentry.h", - "sourcerangefilter.cpp", - "sourcerangefilter.h", - "sourcesmanager.h", - "symbolentry.h", - "symbolindexer.cpp", - "symbolindexer.h", - "symbolindexertask.h", - "symbolindexertaskqueue.h", - "symbolindexertaskqueueinterface.h", - "symbolindexing.h", - "symbolindexinginterface.h", - "symbolscollectorinterface.h", - "symbolstorage.h", - "symbolstorageinterface.h", - "usedmacro.h", - ] - - Group { - name: "tooling sources from clangrefactoring backend" - condition: libclang.toolingEnabled - files: [ - "clangquery.cpp", - "clangquery.h", - "clangquerygatherer.cpp", - "clangquerygatherer.h", - "clangtool.cpp", - "clangtool.h", - "collectmacrossourcefilecallbacks.cpp", - "collectmacrossourcefilecallbacks.h", - "collectsymbolsaction.cpp", - "collectsymbolsaction.h", - "indexdataconsumer.cpp", - "indexdataconsumer.h", - "locationsourcefilecallbacks.cpp", - "locationsourcefilecallbacks.h", - "macropreprocessorcallbacks.cpp", - "macropreprocessorcallbacks.h", - "refactoringcompilationdatabase.cpp", - "refactoringcompilationdatabase.h", - "refactoringserver.cpp", - "refactoringserver.h", - "sourcelocationsutils.h", - "sourcerangeextractor.cpp", - "sourcerangeextractor.h", - "symbolindexing.cpp", - "symbolscollector.cpp", - "symbolscollector.h", - "symbolsvisitorbase.h", - ] - } - } - Group { name: "sources from clangbackend" condition: libclang.present @@ -808,42 +536,6 @@ Project { ] } - Group { - name: "sources from ClangRefactoring" - prefix: "../../../src/plugins/clangrefactoring/" - files: [ - "clangqueryexamplehighlighter.cpp", - "clangqueryexamplehighlighter.h", - "clangqueryexamplehighlightmarker.h", - "clangqueryhighlighter.cpp", - "clangqueryhighlighter.h", - "clangqueryhighlightmarker.h", - "clangqueryprojectsfindfilter.cpp", - "clangqueryprojectsfindfilter.h", - "clangsymbolsfindfilter.cpp", - "clangsymbolsfindfilter.h", - "editormanagerinterface.h", - "locatorfilter.cpp", - "locatorfilter.h", - "projectpartproviderinterface.h", - "projectpartutilities.cpp", - "projectpartutilities.h", - "refactoringclient.cpp", - "refactoringclient.h", - "refactoringconnectionclient.cpp", - "refactoringconnectionclient.h", - "refactoringengine.cpp", - "refactoringengine.h", - "refactoringprojectupdater.cpp", - "refactoringprojectupdater.h", - "searchhandle.cpp", - "searchhandle.h", - "searchinterface.h", - "symbol.h", - "symbolqueryinterface.h", - ] - } - Group { name: "sources from ClangFormat" prefix: "../../../src/plugins/clangformat/" diff --git a/tests/unit/unittest/usedmacrocollector-test.cpp b/tests/unit/unittest/usedmacrocollector-test.cpp deleted file mode 100644 index 191662db6b0..00000000000 --- a/tests/unit/unittest/usedmacrocollector-test.cpp +++ /dev/null @@ -1,286 +0,0 @@ -/**************************************************************************** -** -** 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include -#include -#include - -#include - -#include -#include - -using testing::AllOf; -using testing::Contains; -using testing::Not; -using testing::ElementsAre; -using testing::UnorderedElementsAre; - -using ClangBackEnd::FilePathId; -using ClangBackEnd::FilePathIds; -using ClangBackEnd::FilePathView; -using ClangBackEnd::SourceDependency; -using ClangBackEnd::UsedMacro; - -namespace { - -class UsedMacroAndSourcesCollector : public ::testing::Test -{ -protected: - FilePathId filePathId(Utils::SmallStringView filePath) const - { - return filePathCache.filePathId(ClangBackEnd::FilePathView{filePath}); - } - - static off_t fileSize(Utils::SmallStringView filePath) - { - return QFileInfo(QString(filePath)).size(); - } - - static std::time_t lastModified(Utils::SmallStringView filePath) - { - return QFileInfo(QString(filePath)).lastModified().toSecsSinceEpoch(); - } - - ClangBackEnd::FileStatus fileStatus(Utils::SmallStringView filePath) const - { - return {filePathId(filePath), fileSize(filePath), lastModified(filePath)}; - } -protected: - Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; - ClangBackEnd::RefactoringDatabaseInitializer databaseInitializer{database}; - ClangBackEnd::FilePathCaching filePathCache{database}; - ClangBackEnd::UsedMacroAndSourcesCollector collector{filePathCache}; -}; - -TEST_F(UsedMacroAndSourcesCollector, SourceFiles) -{ - collector.addFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - - collector.collect(); - - ASSERT_THAT(collector.sourceFiles(), - UnorderedElementsAre(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), - filePathId(TESTDATA_DIR "/symbolscollector/header1.h"), - filePathId(TESTDATA_DIR "/symbolscollector/header2.h"))); -} - -TEST_F(UsedMacroAndSourcesCollector, MainFileInSourceFiles) -{ - collector.addFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - - ASSERT_THAT(collector.sourceFiles(), - ElementsAre(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"))); -} - -TEST_F(UsedMacroAndSourcesCollector, ResetMainFileInSourceFiles) -{ - collector.addFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - - ASSERT_THAT(collector.sourceFiles(), - ElementsAre(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"))); -} - -TEST_F(UsedMacroAndSourcesCollector, DontDuplicateSourceFiles) -{ - collector.addFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - collector.collect(); - - collector.collect(); - - ASSERT_THAT(collector.sourceFiles(), - UnorderedElementsAre(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), - filePathId(TESTDATA_DIR "/symbolscollector/header1.h"), - filePathId(TESTDATA_DIR "/symbolscollector/header2.h"))); -} - -TEST_F(UsedMacroAndSourcesCollector, ClearSourceFiles) -{ - collector.addFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - - collector.clear(); - - ASSERT_THAT(collector.sourceFiles(), IsEmpty()); -} - -TEST_F(UsedMacroAndSourcesCollector, ClearFileStatus) -{ - collector.addFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - collector.collect(); - - collector.clear(); - - ASSERT_THAT(collector.fileStatuses(), IsEmpty()); -} - -TEST_F(UsedMacroAndSourcesCollector, ClearUsedMacros) -{ - collector.addFile(filePathId(TESTDATA_DIR "/symbolscollector/defines.h"), {"cc"}); - collector.collect(); - - collector.clear(); - - ASSERT_THAT(collector.usedMacros(), IsEmpty()); -} - -TEST_F(UsedMacroAndSourcesCollector, ClearSourceDependencies) -{ - collector.addFile(filePathId(TESTDATA_DIR "/symbolscollector/main2.cpp"), {"cc", "-I" TESTDATA_DIR}); - collector.collect(); - - collector.clear(); - - ASSERT_THAT(collector.sourceDependencies(), IsEmpty()); -} - -TEST_F(UsedMacroAndSourcesCollector, DontCollectSourceFilesAfterFilesAreCleared) -{ - collector.addFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - - collector.clear(); - collector.collect(); - - ASSERT_THAT(collector.sourceFiles(), IsEmpty()); -} - -TEST_F(UsedMacroAndSourcesCollector, DontCollectFileStatusAfterFilesAreCleared) -{ - collector.addFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - - collector.clear(); - collector.collect(); - - ASSERT_THAT(collector.fileStatuses(), IsEmpty()); -} - -TEST_F(UsedMacroAndSourcesCollector, DontCollectUsedMacrosAfterFilesAreCleared) -{ - collector.addFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - - collector.clear(); - collector.collect(); - - ASSERT_THAT(collector.usedMacros(), IsEmpty()); -} - - -TEST_F(UsedMacroAndSourcesCollector, DontCollectSourceDependenciesAfterFilesAreCleared) -{ - collector.addFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - - collector.clear(); - collector.collect(); - - ASSERT_THAT(collector.sourceDependencies(), IsEmpty()); -} - -TEST_F(UsedMacroAndSourcesCollector, CollectUsedMacrosWithExternalDefine) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); - collector.addFile(fileId, {"cc", "-DCOMPILER_ARGUMENT"}); - - collector.collect(); - - ASSERT_THAT(collector.usedMacros(), - ElementsAre(Eq(UsedMacro{"DEFINED", fileId}), - Eq(UsedMacro{"IF_DEFINE", fileId}), - Eq(UsedMacro{"__clang__", fileId}), - Eq(UsedMacro{"CLASS_EXPORT", fileId}), - Eq(UsedMacro{"IF_NOT_DEFINE", fileId}), - Eq(UsedMacro{"MACRO_EXPANSION", fileId}), - Eq(UsedMacro{"COMPILER_ARGUMENT", fileId}))); -} - -TEST_F(UsedMacroAndSourcesCollector, CollectUsedMacrosWithoutExternalDefine) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); - collector.addFile(fileId, {"cc"}); - - collector.collect(); - - ASSERT_THAT(collector.usedMacros(), - ElementsAre(Eq(UsedMacro{"DEFINED", fileId}), - Eq(UsedMacro{"IF_DEFINE", fileId}), - Eq(UsedMacro{"__clang__", fileId}), - Eq(UsedMacro{"CLASS_EXPORT", fileId}), - Eq(UsedMacro{"IF_NOT_DEFINE", fileId}), - Eq(UsedMacro{"MACRO_EXPANSION", fileId}), - Eq(UsedMacro{"COMPILER_ARGUMENT", fileId}))); -} - -TEST_F(UsedMacroAndSourcesCollector, DontCollectHeaderGuards) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); - collector.addFile(fileId, {"cc"}); - - collector.collect(); - - ASSERT_THAT(collector.usedMacros(), - Not(Contains(Eq(UsedMacro{"SYMBOLSCOLLECTOR_DEFINES_H", fileId})))); -} - -TEST_F(UsedMacroAndSourcesCollector, DISABLED_DontCollectDynamicLibraryExports) -{ - auto fileId = filePathId(TESTDATA_DIR "/symbolscollector/defines.h"); - collector.addFile(fileId, {"cc"}); - - collector.collect(); - - ASSERT_THAT(collector.usedMacros(), - Not(Contains(Eq(UsedMacro{"CLASS_EXPORT", fileId})))); -} - -TEST_F(UsedMacroAndSourcesCollector, CollectFileStatuses) -{ - collector.addFile(filePathId(TESTDATA_DIR "/symbolscollector/main.cpp"), {"cc"}); - - collector.collect(); - - ASSERT_THAT(collector.fileStatuses(), - ElementsAre( - fileStatus(TESTDATA_DIR "/symbolscollector/main.cpp"), - fileStatus(TESTDATA_DIR "/symbolscollector/header1.h"), - fileStatus(TESTDATA_DIR "/symbolscollector/header2.h"))); -} - -TEST_F(UsedMacroAndSourcesCollector, CollectSourceDependencies) -{ - auto mainFileId = filePathId(TESTDATA_DIR "/symbolscollector/main2.cpp"); - auto header1FileId = filePathId(TESTDATA_DIR "/symbolscollector/header1.h"); - auto header2FileId = filePathId(TESTDATA_DIR "/symbolscollector/header2.h"); - auto header3FileId = filePathId(TESTDATA_DIR "/symbolscollector/header3.h"); - collector.addFile(mainFileId, {"cc", "-I" TESTDATA_DIR}); - - collector.collect(); - - ASSERT_THAT(collector.sourceDependencies(), - UnorderedElementsAre(SourceDependency(mainFileId, header1FileId), - SourceDependency(mainFileId, header3FileId), - SourceDependency(header3FileId, header2FileId), - SourceDependency(header1FileId, header2FileId))); -} -} diff --git a/tests/unit/unittest/usedmacrofilter-test.cpp b/tests/unit/unittest/usedmacrofilter-test.cpp deleted file mode 100644 index 0e6be5680eb..00000000000 --- a/tests/unit/unittest/usedmacrofilter-test.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 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. -** -****************************************************************************/ - -#include "googletest.h" - -#include - -namespace { - -using ClangBackEnd::FilePathId; -using ClangBackEnd::SourceEntries; -using ClangBackEnd::SourceEntry; -using ClangBackEnd::SourceType; -using ClangBackEnd::UsedMacro; -using ClangBackEnd::UsedMacros; -using ClangBackEnd::CompilerMacro; -using ClangBackEnd::CompilerMacros; - -class UsedMacroFilter : public testing::Test -{ -protected: - SourceEntries sources{{1, SourceType::UserInclude, 0}, - {2, SourceType::SystemInclude, 0}, - {3, SourceType::ProjectInclude, 0}, - {4, SourceType::TopSystemInclude, 0}, - {5, SourceType::TopProjectInclude, 0}, - {6, SourceType::Source, 0}, - {7, SourceType::TopProjectInclude, 0, ClangBackEnd::HasMissingIncludes::Yes}}; - UsedMacros usedMacros{{"YI", 1}, - {"ER", 2}, - {"SE", 2}, - {"LIU", 2}, - {"QI", 3}, - {"WU", 3}, - {"SAN", 3}, - {"SE", 4}, - {"WU", 5}}; - CompilerMacros compileMacros{{"YI", "1", 1}, - {"ER", "2", 2}, - {"SAN", "3", 3}, - {"SE", "4", 4}, - {"WU", "5", 5}, - {"LIANG", "2", 6}}; -}; - -TEST_F(UsedMacroFilter, SystemIncludes) -{ - ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); - - ASSERT_THAT(filter.systemIncludes, ElementsAre(FilePathId{2}, FilePathId{4})); -} - -TEST_F(UsedMacroFilter, ProjectIncludes) -{ - ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); - - ASSERT_THAT(filter.projectIncludes, ElementsAre(FilePathId{3}, FilePathId{5})); -} - -TEST_F(UsedMacroFilter, TopSystemIncludes) -{ - ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); - - ASSERT_THAT(filter.topSystemIncludes, ElementsAre(FilePathId{4})); -} - -TEST_F(UsedMacroFilter, TopProjectIncludes) -{ - ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); - - ASSERT_THAT(filter.topProjectIncludes, ElementsAre(FilePathId{5})); -} - -TEST_F(UsedMacroFilter, Sources) -{ - ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); - - ASSERT_THAT(filter.sources, ElementsAre(FilePathId{6})); -} - -TEST_F(UsedMacroFilter, UserIncludes) -{ - ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); - - ASSERT_THAT(filter.userIncludes, ElementsAre(FilePathId{1})); -} - -TEST_F(UsedMacroFilter, SystemUsedMacros) -{ - ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); - - ASSERT_THAT(filter.systemUsedMacros, ElementsAre("ER", "SE", "LIU")); -} - -TEST_F(UsedMacroFilter, ProjectUsedMacros) -{ - ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); - - ASSERT_THAT(filter.projectUsedMacros, ElementsAre("QI", "WU", "SAN")); -} - -TEST_F(UsedMacroFilter, SystemCompileMacros) -{ - ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); - - ASSERT_THAT(filter.systemCompilerMacros, - ElementsAre(CompilerMacro{"ER", "2", 2}, - CompilerMacro{"SE", "4", 4}, - CompilerMacro{"LIU"})); -} - -TEST_F(UsedMacroFilter, ProjectCompileMacros) -{ - ClangBackEnd::UsedMacroFilter filter(sources, usedMacros, compileMacros); - - ASSERT_THAT(filter.projectCompilerMacros, - ElementsAre(CompilerMacro{"QI"}, - CompilerMacro{"WU", "5", 5}, - CompilerMacro{"SAN", "3", 3})); -} - -} // namespace