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_ABC_FILE_UTILS_H 17 #define ABC2PROGRAM_ABC_FILE_UTILS_H 18 19 #include <string> 20 #include "assembly-program.h" 21 #include "file.h" 22 23 namespace panda::abc2program { 24 25 // type name 26 constexpr std::string_view GLOBAL_TYPE_NAME = "_GLOBAL"; 27 constexpr std::string_view ARRAY_TYPE_PREFIX = "["; 28 constexpr std::string_view ANY_TYPE_NAME = "any"; 29 constexpr std::string_view ES_TYPE_ANNOTATION_NAME = "_ESTypeAnnotation"; 30 constexpr std::string_view ES_MODULE_RECORD = "_ESModuleRecord"; 31 constexpr std::string_view ES_SCOPE_NAMES_RECORD = "_ESScopeNamesRecord"; 32 constexpr std::string_view JSON_FILE_CONTENT = "jsonFileContent"; 33 constexpr std::string_view MODULE_RECORD_IDX = "moduleRecordIdx"; 34 constexpr std::string_view SCOPE_NAMES = "scopeNames"; 35 constexpr std::string_view MODULE_REQUEST_PAHSE_IDX = "moduleRequestPhaseIdx"; 36 constexpr std::string_view CONCURRENT_MODULE_REQUEST_RECORD_NAME = "_ESConcurrentModuleRequestsAnnotation"; 37 constexpr std::string_view SLOT_NUMBER_RECORD_NAME = "_ESSlotNumberAnnotation"; 38 constexpr std::string_view EXPECTED_PROPERTY_COUNT_RECORD_NAME = "_ESExpectedPropertyCountAnnotation"; 39 constexpr std::string_view DOT = "."; 40 constexpr std::string_view RECORD_ANNOTATION_SEPARATOR = "."; 41 constexpr char AT_SEPARATOR = '@'; 42 constexpr char COLON_SEPARATOR = ':'; 43 constexpr char NORMALIZED_OHMURL_SEPARATOR = '&'; 44 constexpr char SLASH_TAG = '/'; 45 constexpr uint8_t ORIGINAL_PKG_NAME_POS = 0; 46 constexpr uint8_t TARGET_PKG_NAME_POS = 1; 47 constexpr uint8_t NORMALIZED_IMPORT_POS = 1; 48 const std::string FIELD_NAME_PREFIX = "pkgName@"; 49 50 // attribute constant 51 constexpr std::string_view ABC_ATTR_EXTERNAL = "external"; 52 constexpr std::string_view ABC_ATTR_STATIC = "static"; 53 54 // literal array name 55 constexpr std::string_view UNDERLINE = "_"; 56 57 // width constant 58 constexpr uint32_t LINE_WIDTH = 40; 59 constexpr uint32_t COLUMN_WIDTH = 10; 60 constexpr uint32_t START_WIDTH = 5; 61 constexpr uint32_t END_WIDTH = 6; 62 constexpr uint32_t REG_WIDTH = 8; 63 constexpr uint32_t NAME_WIDTH = 13; 64 65 // ins constant 66 constexpr std::string_view LABEL_PREFIX = "label@"; 67 68 // module literal 69 constexpr uint8_t LITERAL_NUM_OF_REGULAR_IMPORT = 3; 70 constexpr uint8_t LITERAL_NUM_OF_NAMESPACE_IMPORT = 2; 71 constexpr uint8_t LITERAL_NUM_OF_LOCAL_EXPORT = 2; 72 constexpr uint8_t LITERAL_NUM_OF_INDIRECT_EXPORT = 3; 73 constexpr uint8_t LITERAL_NUM_OF_STAR_EXPORT = 1; 74 constexpr uint8_t LITERAL_NUMS[] = { 75 LITERAL_NUM_OF_REGULAR_IMPORT, 76 LITERAL_NUM_OF_NAMESPACE_IMPORT, 77 LITERAL_NUM_OF_LOCAL_EXPORT, 78 LITERAL_NUM_OF_INDIRECT_EXPORT, 79 LITERAL_NUM_OF_STAR_EXPORT 80 }; 81 82 std::string GetPkgNameFromNormalizedImport(const std::string &normalizedImport); 83 std::string GetPkgNameFromRecordName(const std::string &recordName); 84 std::vector<std::string> Split(const std::string &str, const char delimiter); 85 class AbcFileUtils { 86 public: 87 static bool IsGlobalTypeName(const std::string &type_name); 88 static bool IsArrayTypeName(const std::string &type_name); 89 static bool IsSystemTypeName(const std::string &type_name); 90 static bool IsESTypeAnnotationName(const std::string &type_name); 91 static std::string GetLabelNameByInstIdx(size_t inst_idx); 92 }; // class AbcFileUtils 93 94 } // namespace panda::abc2program 95 96 #endif // ABC2PROGRAM_ABC_FILE_UTILS_H 97