File indexing completed on 2024-05-19 05:42:05

0001 // ct_lvtclp_toolexecutor.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 // much of this component is taken straight from clang source
0021 // that source is licenced as Apache-2.0 with llvm-exception
0022 // See https://llvm.org/LICENSE.txt
0023 //     clang/include/clang/Tooling/AllTUsExecution.h
0024 
0025 #ifndef INCLUDED_CT_LVTCLP_TOOLEXECUTOR
0026 #define INCLUDED_CT_LVTCLP_TOOLEXECUTOR
0027 
0028 //@PURPOSE: Re-implement clang::tooling::AllTUsToolExecutor using QThreadPool
0029 //          This component borrows generously from the clang implementation
0030 //
0031 //@CLASSES:
0032 //  lvtclp::ToolExecutor
0033 
0034 #include <lvtclp_export.h>
0035 
0036 #include <clang/Tooling/Execution.h>
0037 #include <clang/Tooling/Tooling.h>
0038 
0039 #include <functional>
0040 #include <memory>
0041 
0042 namespace Codethink::lvtmdb {
0043 class ObjectStore;
0044 }
0045 
0046 namespace Codethink::lvtclp {
0047 
0048 // =======================
0049 // class ToolExecutor
0050 // =======================
0051 
0052 class LVTCLP_EXPORT ToolExecutor : public clang::tooling::ToolExecutor {
0053   private:
0054     // TYPES
0055     struct Private;
0056     class RunnableThread;
0057 
0058     // DATA
0059     std::unique_ptr<Private> d;
0060 
0061   public:
0062     // CREATORS
0063     ToolExecutor(const clang::tooling::CompilationDatabase& compDb,
0064                  unsigned threadCount,
0065                  std::function<void(std::string, long)> messageCallback,
0066                  lvtmdb::ObjectStore& memDb);
0067 
0068     ~ToolExecutor() noexcept override;
0069 
0070     // MANIPULATORS
0071     using clang::tooling::ToolExecutor::execute;
0072 
0073     llvm::Error execute(llvm::ArrayRef<std::pair<std::unique_ptr<clang::tooling::FrontendActionFactory>,
0074                                                  clang::tooling::ArgumentsAdjuster>> actions) override;
0075 
0076     clang::tooling::ExecutionContext *getExecutionContext() override;
0077 
0078     clang::tooling::ToolResults *getToolResults() override;
0079 
0080     void mapVirtualFile(llvm::StringRef filePath, llvm::StringRef content) override;
0081 
0082     void cancelRun();
0083     // Cancel mid-execute
0084 
0085     // ACCESSORS
0086     [[nodiscard]] llvm::StringRef getExecutorName() const override;
0087 };
0088 
0089 } // namespace Codethink::lvtclp
0090 
0091 #endif // INCLUDED_CT_LVTCLP_TOOLEXECUTOR