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 LIBARK_DEFECT_SCAN_AUX_INCLUDE_MODULE_RECORD_H 17 #define LIBARK_DEFECT_SCAN_AUX_INCLUDE_MODULE_RECORD_H 18 19 #include <string> 20 #include <vector> 21 22 namespace panda::defect_scan_aux { 23 struct ImportEntry { 24 std::string module_request_; 25 std::string import_name_; 26 std::string local_name_; 27 }; 28 29 struct ExportEntry { 30 std::string export_name_; 31 std::string module_request_; 32 std::string import_name_; 33 std::string local_name_; 34 }; 35 36 class ModuleRecord { 37 public: ModuleRecord(std::string_view module_filename)38 explicit ModuleRecord(std::string_view module_filename) : module_filename_(module_filename) {} 39 ~ModuleRecord() = default; 40 41 void SetModuleFilename(std::string_view module_filename); 42 void SetRequestModules(std::vector<std::string> &request_modules); 43 void AddImportEntry(const ImportEntry &import_entry); 44 void AddExportEntry(const ExportEntry &export_entry); 45 void SetRegularImportNum(size_t regular_import_num); 46 void SetLocalExportNum(size_t local_export_num); 47 size_t GetRegularImportNum() const; 48 size_t GetLocalExportNum() const; 49 const std::string &GetImportLocalNameByIndex(size_t index) const; 50 const std::string &GetImportNamespaceNameByIndex(size_t index) const; 51 const std::string &GetExportNameByIndex(size_t index) const; 52 std::string GetLocalNameByExportName(std::string_view export_name) const; 53 std::string GetImportNameByExportName(std::string_view export_name) const; 54 std::string GetModuleNameByExportName(std::string_view export_name) const; 55 std::string GetModuleNameByLocalName(std::string_view local_name) const; 56 std::string GetImportNameByLocalName(std::string_view local_name) const; 57 58 private: 59 std::string module_filename_; 60 size_t regular_import_num_ {0}; 61 size_t local_export_num_ {0}; 62 std::vector<std::string> request_modules_; 63 std::vector<ImportEntry> import_entries_; 64 std::vector<ExportEntry> export_entries_; 65 }; 66 } // namespace panda::defect_scan_aux 67 68 #endif // LIBARK_DEFECT_SCAN_AUX_INCLUDE_MODULE_RECORD_H