File indexing completed on 2024-05-19 05:42:02
0001 // ct_lvtclp_logicaldepscanner.h -*-C++-*- 0002 0003 /* 0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk> 0005 // SPDX-License-Identifier: Apache-2.0 0006 // 0007 // Licensed under the Apache License, Version 2.0 (the "License"); 0008 // you may not use this file except in compliance with the License. 0009 // You may obtain a copy of the License at 0010 // 0011 // http://www.apache.org/licenses/LICENSE-2.0 0012 // 0013 // Unless required by applicable law or agreed to in writing, software 0014 // distributed under the License is distributed on an "AS IS" BASIS, 0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0016 // See the License for the specific language governing permissions and 0017 // limitations under the License. 0018 */ 0019 0020 #ifndef INCLUDED_CT_LVTCLP_LOGICALDEPSCANNER 0021 #define INCLUDED_CT_LVTCLP_LOGICALDEPSCANNER 0022 0023 //@PURPOSE: A factory for lvtclp::CodebaseDbAction 0024 // 0025 //@CLASSES: lvtclp::LogicalDepActionFactory Implements FrontendActionFactory 0026 // for scanning for logical dependencies 0027 // 0028 //@SEE_ALSO: clang::tooling::FrontendActionFactory 0029 0030 #include <lvtclp_export.h> 0031 0032 #include <clang/Tooling/Tooling.h> 0033 0034 #include <filesystem> 0035 #include <functional> 0036 #include <memory> 0037 #include <optional> 0038 #include <string> 0039 #include <vector> 0040 0041 #include <QString> 0042 0043 namespace Codethink::lvtmdb { 0044 class ObjectStore; 0045 } 0046 0047 namespace Codethink::lvtclp { 0048 0049 // ============================= 0050 // class LogicalDepActionFactory 0051 // ============================= 0052 0053 using HandleCppCommentsCallback_f = std::function<void( 0054 const std::string& filename, const std::string& briefText, unsigned startLine, unsigned endLine)>; 0055 0056 class LVTCLP_EXPORT LogicalDepActionFactory : public clang::tooling::FrontendActionFactory { 0057 // A factory for CodebaseDbFrontendAction 0058 0059 // DATA 0060 lvtmdb::ObjectStore& d_memDb; 0061 // Database session generator 0062 0063 std::filesystem::path d_prefix; 0064 0065 std::vector<std::filesystem::path> d_nonLakosianDirs; 0066 std::vector<std::pair<std::string, std::string>> d_thirdPartyDirs; 0067 0068 std::function<void(const std::string&)> d_filenameCallback; 0069 // Callback whenever we start to process a new file 0070 0071 std::optional<std::function<void(const std::string&, long)>> d_messageCallback; 0072 // Callback to send errors to the UI. 0073 0074 bool d_catchCodeAnalysisOutput; 0075 0076 std::optional<HandleCppCommentsCallback_f> d_handleCppCommentsCallback; 0077 0078 public: 0079 // CREATORS 0080 LogicalDepActionFactory(lvtmdb::ObjectStore& memDb, 0081 std::filesystem::path prefix, 0082 std::vector<std::filesystem::path> nonLakosians, 0083 std::vector<std::pair<std::string, std::string>> d_thirdPartyDirs, 0084 std::function<void(const std::string&)> filenameCallback, 0085 std::optional<std::function<void(const std::string&, long)>> messageCallback, 0086 bool catchCodeAnalysisOutput, 0087 std::optional<HandleCppCommentsCallback_f> handleCppCommentsCallback = std::nullopt); 0088 0089 // MANIPULATORS 0090 std::unique_ptr<clang::FrontendAction> create() override; 0091 // Construct a new clang::FrontendAction 0092 }; 0093 0094 } // end namespace Codethink::lvtclp 0095 0096 #endif