File indexing completed on 2024-11-17 05:06:09
0001 /* 0002 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk> 0003 // SPDX-License-Identifier: Apache-2.0 0004 // 0005 // Licensed under the Apache License, Version 2.0 (the "License"); 0006 // you may not use this file except in compliance with the License. 0007 // You may obtain a copy of the License at 0008 // 0009 // http://www.apache.org/licenses/LICENSE-2.0 0010 // 0011 // Unless required by applicable law or agreed to in writing, software 0012 // distributed under the License is distributed on an "AS IS" BASIS, 0013 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0014 // See the License for the specific language governing permissions and 0015 // limitations under the License. 0016 */ 0017 0018 #ifndef CODEVIS_CT_LVTCLP_TOOL_H 0019 #define CODEVIS_CT_LVTCLP_TOOL_H 0020 0021 #include <clang/Tooling/CompilationDatabase.h> 0022 #include <ct_lvtmdb_objectstore.h> 0023 #include <filesystem> 0024 #include <lvtclp_export.h> 0025 0026 namespace Codethink::lvtclp::fortran { 0027 0028 class LVTCLP_EXPORT Tool { 0029 public: 0030 explicit Tool(std::unique_ptr<clang::tooling::CompilationDatabase> compilationDatabase); 0031 0032 static std::unique_ptr<Tool> fromCompileCommands(std::filesystem::path const& compileCommandsJson); 0033 0034 bool runPhysical(bool skipScan = false); 0035 bool runFull(bool skipPhysical = false); 0036 0037 lvtmdb::ObjectStore& getObjectStore(); 0038 void setSharedMemDb(std::shared_ptr<lvtmdb::ObjectStore> const& sharedMemDb); 0039 0040 private: 0041 std::unique_ptr<clang::tooling::CompilationDatabase> compilationDatabase; 0042 0043 // The tool can be used either with a local memory database or with a 0044 // shared one. Only one can be used at a time. The default is to use 0045 // localMemDb. If setMemDb(other) is called, will ignore the local one. 0046 lvtmdb::ObjectStore localMemDb; 0047 std::shared_ptr<lvtmdb::ObjectStore> sharedMemDb = nullptr; 0048 [[nodiscard]] inline lvtmdb::ObjectStore& memDb() 0049 { 0050 return this->sharedMemDb ? *this->sharedMemDb : this->localMemDb; 0051 } 0052 }; 0053 0054 } // namespace Codethink::lvtclp::fortran 0055 0056 #endif // CODEVIS_CT_LVTCLP_TOOL_H