1 /** 2 * Copyright (c) 2022-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PANDA_TOOLING_INSPECTOR_SOURCE_MANAGER_H 17 #define PANDA_TOOLING_INSPECTOR_SOURCE_MANAGER_H 18 19 #include <map> 20 #include <string> 21 #include <string_view> 22 #include <unordered_map> 23 #include <unordered_set> 24 #include <utility> 25 26 #include "include/tooling/pt_thread.h" 27 #include "os/mutex.h" 28 29 #include "types/numeric_id.h" 30 31 namespace ark::tooling::inspector { 32 class SourceManager final { 33 public: 34 SourceManager() = default; 35 ~SourceManager() = default; 36 37 NO_COPY_SEMANTIC(SourceManager); 38 NO_MOVE_SEMANTIC(SourceManager); 39 40 std::pair<ScriptId, bool> GetScriptId(std::string_view fileName); 41 [[nodiscard]] std::string_view GetSourceFileName(ScriptId id) const; 42 43 private: 44 mutable os::memory::Mutex mutex_; 45 std::unordered_map<std::string, ScriptId> fileNameToId_ GUARDED_BY(mutex_); 46 std::unordered_map<ScriptId, std::string_view> idToFileName_ GUARDED_BY(mutex_); 47 std::unordered_set<ScriptId> knownSources_ GUARDED_BY(mutex_); 48 }; 49 } // namespace ark::tooling::inspector 50 51 #endif // PANDA_TOOLING_INSPECTOR_SOURCE_MANAGER_H 52