• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022 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 "source_file.h"
20 
21 #include <algorithm>
22 #include <cstddef>
23 #include <string_view>
24 #include <utility>
25 #include <vector>
26 
27 namespace panda {
28 class JsonObject;
29 class JsonObjectBuilder;
30 class Method;
31 }  // namespace panda
32 
33 namespace panda::panda_file {
34 class DebugInfoExtractor;
35 class File;
36 }  // namespace panda::panda_file
37 
38 namespace panda::tooling::inspector {
39 class Server;
40 
41 class SourceManager {
42 public:
43     explicit SourceManager(Server &server);
44 
45     template <typename Function>
EnumerateSourceFiles(Function && function)46     void EnumerateSourceFiles(Function &&function) const
47     {
48         std::all_of(sourceFiles_.begin(), sourceFiles_.end(), std::forward<Function>(function));
49     }
50 
51     // Get debug info associated with panda file, loading new source files if needed.
52     const panda_file::DebugInfoExtractor &GetDebugInfo(const panda_file::File *pandaFile);
53 
54     // Get SourceFile associated with method, creating one if necessary.
55     const SourceFile &GetOrLoadSourceFile(Method *method);
56 
57     // Query loaded source files.
58     const SourceFile *GetSourceFile(size_t scriptId) const;
59     const SourceFile *GetSourceFile(std::string_view fileName) const;
60 
61 private:
62     void GetScriptSource(JsonObjectBuilder &result, const JsonObject &params);
63     const SourceFile *GetSourceFileInternal(std::string_view fileName) const;
64 
65     Server &server_;
66     std::vector<SourceFile> sourceFiles_;
67 };
68 }  // namespace panda::tooling::inspector
69 
70 #endif  // PANDA_TOOLING_INSPECTOR_SOURCE_MANAGER_H
71