• 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_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 char AT_SEPARATOR = '@';
41 constexpr char COLON_SEPARATOR = ':';
42 constexpr char NORMALIZED_OHMURL_SEPARATOR = '&';
43 constexpr char SLASH_TAG = '/';
44 constexpr uint8_t ORIGINAL_PKG_NAME_POS = 0;
45 constexpr uint8_t TARGET_PKG_NAME_POS = 1;
46 constexpr uint8_t NORMALIZED_IMPORT_POS = 1;
47 const std::string FIELD_NAME_PREFIX = "pkgName@";
48 
49 // attribute constant
50 constexpr std::string_view ABC_ATTR_EXTERNAL = "external";
51 constexpr std::string_view ABC_ATTR_STATIC = "static";
52 
53 // literal array name
54 constexpr std::string_view UNDERLINE = "_";
55 
56 // width constant
57 constexpr uint32_t LINE_WIDTH = 40;
58 constexpr uint32_t COLUMN_WIDTH = 10;
59 constexpr uint32_t START_WIDTH = 5;
60 constexpr uint32_t END_WIDTH = 6;
61 constexpr uint32_t REG_WIDTH = 8;
62 constexpr uint32_t NAME_WIDTH = 13;
63 
64 // ins constant
65 constexpr std::string_view LABEL_PREFIX = "label@";
66 
67 // module literal
68 constexpr uint8_t LITERAL_NUM_OF_REGULAR_IMPORT = 3;
69 constexpr uint8_t LITERAL_NUM_OF_NAMESPACE_IMPORT = 2;
70 constexpr uint8_t LITERAL_NUM_OF_LOCAL_EXPORT = 2;
71 constexpr uint8_t LITERAL_NUM_OF_INDIRECT_EXPORT = 3;
72 constexpr uint8_t LITERAL_NUM_OF_STAR_EXPORT = 1;
73 constexpr uint8_t LITERAL_NUMS[] = {
74     LITERAL_NUM_OF_REGULAR_IMPORT,
75     LITERAL_NUM_OF_NAMESPACE_IMPORT,
76     LITERAL_NUM_OF_LOCAL_EXPORT,
77     LITERAL_NUM_OF_INDIRECT_EXPORT,
78     LITERAL_NUM_OF_STAR_EXPORT
79 };
80 
81 std::string GetPkgNameFromNormalizedImport(const std::string &normalizedImport);
82 std::string GetPkgNameFromRecordName(const std::string &recordName);
83 std::vector<std::string> Split(const std::string &str, const char delimiter);
84 class AbcFileUtils {
85 public:
86     static bool IsGlobalTypeName(const std::string &type_name);
87     static bool IsArrayTypeName(const std::string &type_name);
88     static bool IsSystemTypeName(const std::string &type_name);
89     static bool IsESTypeAnnotationName(const std::string &type_name);
90     static std::string GetLabelNameByInstIdx(size_t inst_idx);
91 };  // class AbcFileUtils
92 
93 }  // namespace panda::abc2program
94 
95 #endif  // ABC2PROGRAM_ABC_FILE_UTILS_H
96