• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "source_manager.h"
17 
18 #include <string>
19 #include <string_view>
20 
21 #include "types/numeric_id.h"
22 
23 namespace ark::tooling::inspector {
GetScriptId(std::string_view fileName)24 std::pair<ScriptId, bool> SourceManager::GetScriptId(std::string_view fileName)
25 {
26     os::memory::LockHolder lock(mutex_);
27 
28     auto p = fileNameToId_.emplace(std::string(fileName), fileNameToId_.size());
29     ScriptId id(p.first->second);
30     bool isNewForThread = knownSources_.insert(id).second;
31 
32     if (p.second) {
33         std::string_view name {p.first->first};
34         idToFileName_.emplace(id, name);
35     }
36 
37     return {id, isNewForThread};
38 }
39 
GetSourceFileName(ScriptId id) const40 std::string_view SourceManager::GetSourceFileName(ScriptId id) const
41 {
42     os::memory::LockHolder lock(mutex_);
43 
44     auto it = idToFileName_.find(id);
45     if (it != idToFileName_.end()) {
46         return it->second;
47     }
48 
49     LOG(ERROR, DEBUGGER) << "No file with script id " << id;
50 
51     return {};
52 }
53 
54 }  // namespace ark::tooling::inspector
55