From 4f4889061157838ef8b8c2d9197f80c9caabd926 Mon Sep 17 00:00:00 2001 From: zhangwuf Date: Mon, 18 Dec 2023 16:01:52 +0800 Subject: [PATCH] =?UTF-8?q?CAPI=E8=A7=A3=E6=9E=90=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=AE=8F=E5=AE=9A=E4=B9=89bug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangwuf --- .../src/coreImpl/parser/parse_include.py | 23 +++++++++--- .../capi_parser/src/coreImpl/parser/parser.py | 37 +++++++++++++++++-- .../capi_parser/src/typedef/check/check.py | 28 +++++++------- .../capi_parser/src/utils/constants.py | 1 + 4 files changed, 67 insertions(+), 22 deletions(-) diff --git a/build-tools/capi_parser/src/coreImpl/parser/parse_include.py b/build-tools/capi_parser/src/coreImpl/parser/parse_include.py index cf92d76c3..d6209d14a 100644 --- a/build-tools/capi_parser/src/coreImpl/parser/parse_include.py +++ b/build-tools/capi_parser/src/coreImpl/parser/parse_include.py @@ -78,10 +78,14 @@ def get_complex_def(tokens_new, count_token, tokens, data): count_com = 0 for token_2 in tokens_new: if token_2.spelling == ')': - logo = 1 break else: count += 1 + if count != count_token: + for token in tokens_new[count:]: + if token.spelling == '{' or token.spelling == '(' or token.spelling == '##': + logo = 1 + if count_token == count: pass elif logo == 1: # 获取复合型宏定义宏名 @@ -183,10 +187,19 @@ def processing_enum(cursor, data): # 获取枚举值 def processing_def(cursor, data): # 处理宏定义 - marco_ext = cursor.extent - tokens = cursor.translation_unit.get_tokens(extent=marco_ext) # 找到对应的宏定义位置 - tokens = list(tokens) # Generator转为list - processing_complex_def(tokens, data) # 获取宏名和宏文本 + if data['node_content']['content']: + split_data = data['node_content']['content'].split() + if len(split_data) == 2: + pattern = r'\((.*?), (.*?)\)' + if re.search(pattern, data['node_content']['content']): + data['name'] = data['node_content']['content'] + else: + marco_ext = cursor.extent + tokens = cursor.translation_unit.get_tokens(extent=marco_ext) # 找到对应的宏定义位置 + tokens = list(tokens) # Generator转为list + processing_complex_def(tokens, data) # 获取宏名和宏文本 + else: + print('mar_define error, its content is none') data["type"] = "def_no_type" diff --git a/build-tools/capi_parser/src/coreImpl/parser/parser.py b/build-tools/capi_parser/src/coreImpl/parser/parser.py index 5bc825b65..64e213613 100644 --- a/build-tools/capi_parser/src/coreImpl/parser/parser.py +++ b/build-tools/capi_parser/src/coreImpl/parser/parser.py @@ -253,6 +253,26 @@ def find_include(link_include_path): link_include_path.append(dir_path) +def copy_self_include(link_include_file, self_include_file): + std_include = StringConstant.SELF_INCLUDE.value + if not os.path.exists(std_include): + os.makedirs(std_include) + + for item in self_include_file: + shutil.copyfile(item, std_include) + + link_include_file.append(std_include) + + +def delete_typedef_child(child): + if child['kind'] == 'TYPEDEF_DECL': + if 'children' in child and len(child['children']) \ + and (child['children'][0]['kind'] == 'STRUCT_DECL' + or child['children'][0]['kind'] == 'ENUM_DECL' + or child['children'][0]['kind'] == 'UNION_DECL'): + child['children'] = [] + + def parser(directory_path): # 目录路径 function_name = StringConstant.FUNK_NAME.value # 匹配的函数名 @@ -265,9 +285,14 @@ def parser(directory_path): # 目录路径 return data_total -def parser_include_ast(gn_file_path, include_path): # 对于单独的.h解析接口 +def parser_include_ast(gn_file_path, include_path, self_include=None): # 对于单独的.h解析接口 correct_include_path = [] - link_path = [StringConstant.INCLUDE_LIB.value] + + link_include_path = [] + copy_std_lib(link_include_path) + find_include(link_include_path) + copy_self_include(link_include_path, self_include) + modes = stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU fd = os.open('include_file_suffix.txt', os.O_WRONLY | os.O_CREAT, mode=modes) for item in include_path: @@ -278,5 +303,11 @@ def parser_include_ast(gn_file_path, include_path): # 对于单独的.h exc = 'The file does not end with.h: {}\n'.format(item) os.write(fd, exc.encode()) os.close(fd) - data = parse_include.get_include_file(correct_include_path, link_path, gn_file_path) + + data = parse_include.get_include_file(correct_include_path, link_include_path, gn_file_path) + + for item in data: + if 'children' in item: + for child in item['children']: + delete_typedef_child(child) return data diff --git a/build-tools/capi_parser/src/typedef/check/check.py b/build-tools/capi_parser/src/typedef/check/check.py index 0f78875d3..0f7bf157d 100644 --- a/build-tools/capi_parser/src/typedef/check/check.py +++ b/build-tools/capi_parser/src/typedef/check/check.py @@ -45,15 +45,15 @@ class ErrorType(enum.Enum): 'description': 'error tag name', } MISSPELL_WORDS = { - 'id': 1, + 'id': 2, 'description': 'misspell words', } NAMING_ERRORS = { - 'id': 2, + 'id': 3, 'description': 'naming errors', } SYNTAX_ERRORS = { - 'id': 3, + 'id': 4, 'description': 'syntax errors', } UNKNOW_DEPRECATED = { @@ -61,11 +61,11 @@ class ErrorType(enum.Enum): 'description': 'unknow deprecated', } WRONG_VALUE = { - 'id': 7, + 'id': 6, 'description': 'wrong value', } WRONG_SCENE = { - 'id': 8, + 'id': 7, 'description': 'wrong scene', } @@ -89,24 +89,24 @@ class ErrorMessage(enum.Enum): REPEAT_FILE_TAG = 'the [$$] tag is repeat. Please check the tag in file' ERROR_INFO_VALUE_TAG = 'the [$$] tag value is incorrect. Please check the usage method' ERROR_INFO_VALUE_LIBRARY = 'the [library] tag value is incorrect. This tag must be end with .so or .a, \ - or is NA. Please check the usage method' + or is NA. Please check the usage method' ERROR_INFO_VALUE_PARAM = 'the value of the [$$] [param] tag is incorrect. Please check if it matches \ - the [$$] parameter name' + the [$$] parameter name' ERROR_INFO_COUNT_PARAM = 'the count of the [param] tag is wrong. Please check the parameters and Doc' ERROR_INFO_VALUE_PERMISSION = 'the [permission] tag value is incorrect. Please check if the permission \ - field has been configured or update the configuration file' + field has been configured or update the configuration file' ERROR_INFO_VALUE_SINCE = 'the [since] tag value is incorrect. Please check if the tag value is a numerical value' ERROR_INFO_VALUE_SYSCAP = 'the [syscap] tag value is incorrect. Please check if the syscap field is configured' ERROR_USE_LEFT_BRACE = 'the validity verification of the Doc tag failed. The [{] tag is not allowed to used \ - in Doc which not has addtogroup tag, or used in the wrong place.' + in Doc which not has addtogroup tag, or used in the wrong place.' ERROR_REPEAT_LEFT_BRACE = 'the validity verification of the Doc tag failed. The [{] tag is not allowed to \ - reuse in Doc which has addtogroup tag.' + reuse in Doc which has addtogroup tag.' ERROR_USE_RIGHT_BRACE = 'the validity verification of the JSDoc tag failed. The [}] tag is not allowed to \ - be reused please delete the extra tags.' + be reused please delete the extra tags.' ERROR_FILE_HAS_ONE_LOSE_OTHER = 'the file has the $$, but do not has the $$.' ERROR_FILE_LOSE_ONE = 'the file missing $$' FUNCTION_DECL = 'Function naming should use the big hump naming style or beginning with OH/OS,and \ - using "_" segmentation.' + using "_" segmentation.' STRUCT_DECL = 'Structure type naming should use the big hump naming style.' ENUM_DECL = 'Enum type naming should use the big hump naming style.' UNION_DECL = 'Consortium type naming should use the big hump naming style.' @@ -115,11 +115,11 @@ class ErrorMessage(enum.Enum): MACRO_PARAMETERS_TYPE_NAMING_ERROR = 'Macro parameters naming should use the small hump naming style.' FIELD_DECL = 'Fields in the structure naming should use the small hump naming style.' MEMBERS_OF_THE_CONSORTIUM_TYPE_NAMING_ERROR = 'Members of the consortium naming should use the \ - small hump naming style.' + small hump naming style.' MACRO_DEFINITION = 'Macro naming should use all uppercase, separated by underscores naming style.' ENUM_CONSTANT_DECL = 'Enum value naming should use all uppercase, separated by underscores naming style.' GOTO_LABEL_TYPE_NAMING_ERROR = 'Goto label value naming should use all uppercase, separated by \ - underscores naming style.' + underscores naming style.' GLOBAL_VARIABLE_TYPE_NAMING_ERROR = 'Global variable should increase "g_" prefix.' TRANSLATION_UNIT = 'File naming should be all lowercase, separated by underscores.' diff --git a/build-tools/capi_parser/src/utils/constants.py b/build-tools/capi_parser/src/utils/constants.py index 4142ef41f..d8c08425f 100644 --- a/build-tools/capi_parser/src/utils/constants.py +++ b/build-tools/capi_parser/src/utils/constants.py @@ -25,6 +25,7 @@ class StringConstant(enum.Enum): # 拉到本地仓的三方库绝对路径 INCLUDE_LIB = r'.\third_party\musl\ndk_musl_include' STD_INCLUDE = r'.\sysroot\ndk_musl_include_files' + SELF_INCLUDE = r'.\sysroot\self_include_files' RESULT_HEAD_NAME = "result_total.xlsx" -- Gitee