• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 ABC2PROGRAM_ABC2PROGRAM_ENTITY_CONTAINER_H
17 #define ABC2PROGRAM_ABC2PROGRAM_ENTITY_CONTAINER_H
18 
19 #include <string>
20 #include <unordered_map>
21 #include <unordered_set>
22 #include <assembly-program.h>
23 #include <debug_info_extractor.h>
24 #include "file.h"
25 
26 namespace panda::abc2program {
27 
28 const panda::panda_file::SourceLang DEFUALT_SOURCE_LANG = panda::panda_file::DEFUALT_SOURCE_LANG;
29 
30 class Abc2ProgramEntityContainer {
31 public:
Abc2ProgramEntityContainer(const panda_file::File & file,pandasm::Program & program,const panda_file::DebugInfoExtractor & debug_info_extractor,uint32_t class_id,std::string bundle_name)32     Abc2ProgramEntityContainer(const panda_file::File &file,
33                                pandasm::Program &program,
34                                const panda_file::DebugInfoExtractor &debug_info_extractor,
35                                uint32_t class_id, std::string bundle_name)
36         : file_(file), program_(program), debug_info_extractor_(debug_info_extractor),
37           current_class_id_(class_id), bundle_name_(bundle_name) {}
38     const panda_file::File &GetAbcFile() const;
39     pandasm::Program &GetProgram() const;
40 
41     std::string GetStringById(const panda_file::File::EntityId &entity_id) const;
42     std::string GetFullRecordNameById(const panda_file::File::EntityId &class_id);
43     std::string GetFullMethodNameById(const panda_file::File::EntityId &method_id);
44     void AddProgramString(const std::string &str) const;
45 
46     const std::unordered_set<uint32_t> &GetMouleLiteralArrayIdSet() const;
47     const std::unordered_set<uint32_t> &GetModuleRequestPhaseIdSet() const;
48     const std::unordered_set<uint32_t> &GetUnnestedLiteralArrayIdSet() const;
49     std::unordered_set<uint32_t> &GetUnprocessedNestedLiteralArrayIdSet();
50     void AddModuleLiteralArrayId(uint32_t module_literal_array_id);
51     void AddUnnestedLiteralArrayId(uint32_t literal_array_id);
52     void AddModuleRequestPhaseId(uint32_t module_request_phase_id);
53     void AddProcessedNestedLiteralArrayId(uint32_t nested_literal_array_id);
54     void TryAddUnprocessedNestedLiteralArrayId(uint32_t nested_literal_array_id);
55     std::string GetLiteralArrayIdName(uint32_t literal_array_id);
56     const panda_file::DebugInfoExtractor &GetDebugInfoExtractor() const;
57     void ModifyRecordName(std::string &record_name);
58     void ModifyPkgNameForRecordName(std::string &record_name);
59     void ModifyPkgNameForFieldName(std::string &field_name);
60     bool IsSourceFileRecord(const std::string& record_name);
61 
SetModifyPkgName(const std::string & modify_pkg_name)62     void SetModifyPkgName(const std::string &modify_pkg_name)
63     {
64         modify_pkg_name_ = modify_pkg_name;
65     }
66 
67 private:
68     std::string ConcatFullMethodNameById(const panda_file::File::EntityId &method_id);
69     const panda_file::File &file_;
70     pandasm::Program &program_;
71     const panda_file::DebugInfoExtractor &debug_info_extractor_;
72     std::unordered_map<uint32_t, std::string> record_full_name_map_;
73     std::unordered_map<uint32_t, std::string> method_full_name_map_;
74     std::unordered_set<uint32_t> module_literal_array_id_set_;
75     std::unordered_set<uint32_t> module_request_phase_id_set_;
76     std::unordered_set<uint32_t> unnested_literal_array_id_set_;
77     std::unordered_set<uint32_t> processed_nested_literal_array_id_set_;
78     std::unordered_set<uint32_t> unprocessed_nested_literal_array_id_set_;
79     uint32_t current_class_id_{0};
80     // It should modify record name when the bundle_name_ is not empty
81     std::string bundle_name_ {};
82     std::string modify_pkg_name_ {};
83 };  // class Abc2ProgramEntityContainer
84 
85 }  // namespace panda::abc2program
86 
87 #endif  // ABC2PROGRAM_ABC2PROGRAM_ENTITY_CONTAINER_H