From 4f9e7c5f629955bc0db6b80a9852c9730401b340 Mon Sep 17 00:00:00 2001 From: jwx1102601 Date: Thu, 9 Nov 2023 15:17:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?CAPI=E5=91=BD=E5=90=8D=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jwx1102601 --- capi_parser/src/bin/config.py | 4 + .../src/coreImpl/parser/check/check.py | 78 + .../src/coreImpl/parser/check/check_name.py | 85 + .../src/coreImpl/parser/check/data.json | 1387 +++++++++++++++++ capi_parser/src/typedef/check/check.py | 255 +++ 5 files changed, 1809 insertions(+) create mode 100644 capi_parser/src/coreImpl/parser/check/check.py create mode 100644 capi_parser/src/coreImpl/parser/check/check_name.py create mode 100644 capi_parser/src/coreImpl/parser/check/data.json create mode 100644 capi_parser/src/typedef/check/check.py diff --git a/capi_parser/src/bin/config.py b/capi_parser/src/bin/config.py index 5fbb32e5d..72c385c93 100644 --- a/capi_parser/src/bin/config.py +++ b/capi_parser/src/bin/config.py @@ -1,10 +1,12 @@ import enum from coreImpl.parser import parser +from coreImpl.check import check class ToolNameType(enum.Enum): COLLECT = 'collect' DIFF = 'diff' + CHECK = 'check' toolNameTypeSet = [member.value for name, @@ -26,6 +28,8 @@ def run_tools(options): parser.parser(options.parser_path) elif tool_name == ToolNameType["DIFF"].value: print("开发中。。。") + elif tool_name == ToolNameType['CHECK'].value: + check.curr_entry(options.parser_path) else: print("工具名称错误") diff --git a/capi_parser/src/coreImpl/parser/check/check.py b/capi_parser/src/coreImpl/parser/check/check.py new file mode 100644 index 000000000..43ce2b6df --- /dev/null +++ b/capi_parser/src/coreImpl/parser/check/check.py @@ -0,0 +1,78 @@ +import json +from typedef.check.check import ApiResultInfo, FileDocInfo, OutputTxt +from coreImpl.check.check_doc import process_comment, process_file_doc_info +from coreImpl.check.check_name import check_file_name, check_ndk_name + + +def process_api_json(api_info, file_doc_info: FileDocInfo, api_result_info_list): + api_result_info_list.extend(check_ndk_name(api_info)) + if 'comment' in api_info.keys(): + comment = api_info['comment'] + api_result_info_list.extend( + process_comment(comment, file_doc_info, api_info)) + child_node = get_api_info_child(api_info) + if len(child_node) > 0: + for index in range(len(child_node)): + process_api_json( + child_node[index], file_doc_info, api_result_info_list) + + +def get_api_info_child(api_info): + if 'children' in api_info.keys(): + return api_info['children'] + if 'members' in api_info.keys(): + return api_info['members'] + if 'parm' in api_info.keys(): + return api_info['parm'] + return [] + + +def process_file_json(file_info, api_result_info_list): + api_result_info_list.extend(check_file_name(file_info['name'])) + apis = file_info['children'] + file_doc_info = FileDocInfo() + for index in range(len(apis)): + api = apis[index] + process_api_json(api, file_doc_info, api_result_info_list) + api_result_info_list.extend(process_file_doc_info(file_doc_info, file_info)) + + +def process_all_json(python_obj) -> list[ApiResultInfo]: + api_result_info_list = [] + for index in range(len(python_obj)): + file_info = python_obj[index] + process_file_json(file_info, api_result_info_list) + return api_result_info_list + + +def write_in_txt(check_result): + txtResul = [] + for result in check_result: + location = '{}(line:{}, col:{})'.format(result.location, result.locationLine, result.locationColumn) + message = 'API check error of [{}]:{}'.format(result.errorType['description'], result.errorInfo) + txtResul.append(OutputTxt(result.errorType['id'], result.level, location, result.fileName, message)) + txtResul.append('api_check: false') + result_json = json.dumps(txtResul, default=lambda obj: obj.__dict__, indent=4) + fs = open(r'./Error.txt', 'w', encoding='utf-8') + fs.write(result_json) + fs.close() + + +def curr_entry(file_path): + with open('./src/coreImpl/check/data.json') as json_file: + python_obj = json.load(json_file) + check_result = process_all_json(python_obj) + if len(check_result) == 0: + return + write_in_txt(check_result) + + +def get_md_files(url) -> list[str]: + file = open(url, "r") + file_list = [] + line = file.readline() + while line: + file_list.append(line) + line = file.readline() + file.close() + return file_list diff --git a/capi_parser/src/coreImpl/parser/check/check_name.py b/capi_parser/src/coreImpl/parser/check/check_name.py new file mode 100644 index 000000000..2de6d143e --- /dev/null +++ b/capi_parser/src/coreImpl/parser/check/check_name.py @@ -0,0 +1,85 @@ +import enum +import os.path +import re +from typedef.check.check import ApiResultInfo, ErrorMessage, ErrorType, LogType + + +def check_large_hump(api_info): + return processing_check_data('LARGE_HUMP', api_info) + + +def check_function_name(api_info): + return processing_check_data('CHECK_FUNCTION_NAME', api_info) + + +def check_small_hump(api_info): + return processing_check_data('SMALL_HUMP', api_info) + + +def check_all_uppercase_hump(api_info): + return processing_check_data('ALL_UPPERCASE_HUMP', api_info) + + +def check_global_variable(api_info): + return processing_check_data('GLOBAL_VARIABLE', api_info) + + +def check_file_name(file_path): + api_result_info_list = [] + file_name = os.path.basename(file_path) + result = re.match(CheckName['FILE_NAME'].value, file_name) + if result is None: + error_info = ErrorMessage.TRANSLATION_UNIT.value + api_result_info = ApiResultInfo(ErrorType.NAMING_ERRORS.value, error_info, '') + api_result_info.set_type(LogType.LOG_FILE.value) + api_result_info.set_level(2) + api_result_info_list.append(api_result_info) + return api_result_info_list + + +def processing_check_data(function_type, api_info): + api_result_info_list = [] + name = api_info['name'] + result = re.match(CheckName[function_type].value, name) + if result is None: + api_result_info = ApiResultInfo(ErrorType.NAMING_ERRORS.value, + ErrorMessage[api_info['kind']].value, name) + api_result_info.set_location_line(api_info['location']['location_line']) + api_result_info.set_location_column(api_info['location']['location_column']) + api_result_info.set_location(api_info['location']['location_path']) + api_result_info.set_type(LogType.LOG_API.value) + api_result_info.set_level(2) + api_result_info.set_file_name(api_info['location']['location_path']) + api_result_info_list.append(api_result_info) + return api_result_info_list + + +class CheckName(enum.Enum): + LARGE_HUMP = r'^([A-Z][a-z0-9]*)*$' + SMALL_HUMP = r'^([a-z][A-Z0-9]*)*$' + ALL_UPPERCASE_HUMP = r'^[A-Z]+[0-9]*([\_][A-Z0-9]+)*$' + GLOBAL_VARIABLE = r'^g_([a-z][A-Z0-9]*)*$' + FILE_NAME = r'^[a-z]+[a-z0-9]+([\_][a-z0-9]+)*\.h$' + CHECK_FUNCTION_NAME = r'^([OH|OS]+([\_]([A-Z]+[a-z0-9]*)+)*)|(([A-Z][a-z0-9]*)*)$' + + +process_tag_function = { + 'FUNCTION_DECL': check_function_name, + 'STRUCT_DECL': check_large_hump, + 'ENUM_DECL': check_large_hump, + 'UNION_DECL': check_large_hump, + 'VAR_DECL': check_small_hump, + 'PARM_DECL': check_small_hump, + 'FIELD_DECL': check_small_hump, + 'MACRO_DEFINITION': check_all_uppercase_hump, + 'ENUM_CONSTANT_DECL': check_all_uppercase_hump, +} + + +def check_ndk_name(api_info) -> list[ApiResultInfo]: + api_result_info_list = [] + kind = api_info['kind'] + if kind not in process_tag_function.keys(): + return api_result_info_list + name_process = process_tag_function[kind] + return name_process(api_info) diff --git a/capi_parser/src/coreImpl/parser/check/data.json b/capi_parser/src/coreImpl/parser/check/data.json new file mode 100644 index 000000000..5681b08b0 --- /dev/null +++ b/capi_parser/src/coreImpl/parser/check/data.json @@ -0,0 +1,1387 @@ +[ + { + "name": "C:\\Users\\Administrator\\Desktop\\test\\drawing_aypes.h", + "kind": "TRANSLATION_UNIT", + "type": "", + "children": [ + { + "name": "C_INCLUDE_DRAWING_TYPES_H", + "kind": "FUNCTION_DECL", + "type": "def_no_type", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 17, + "location_column": 9 + } + }, + { + "name": "stdint.h", + "kind": "INCLUSION_DIRECTIVE", + "type": "inclusion_no_type", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 46, + "location_column": 1 + } + }, + { + "name": "VN_LIST", + "kind": "VAR_DECL", + "type": "const int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 20, + "location_column": 11 + }, + "is_extern": false, + "children": [ + { + "name": "var_int_no_spelling", + "kind": "INTEGER_LITERAL", + "type": "int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 20, + "location_column": 21 + }, + "integer_value": "5" + } + ] + }, + { + "name": "g_xxxBaseValue", + "kind": "VAR_DECL", + "type": "const int[4]", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 23, + "location_column": 11 + }, + "is_extern": false, + "children": [ + { + "name": "var_int_no_spelling", + "kind": "INTEGER_LITERAL", + "type": "int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 23, + "location_column": 26 + }, + "integer_value": "4" + }, + { + "name": "", + "kind": "INIT_LIST_EXPR", + "type": "const int[4]", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 23, + "location_column": 31 + }, + "children": [ + { + "name": "integer_no_spelling", + "kind": "INTEGER_LITERAL", + "type": "int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 23, + "location_column": 33 + }, + "integer_value": "1" + }, + { + "name": "integer_no_spelling", + "kind": "INTEGER_LITERAL", + "type": "int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 23, + "location_column": 36 + }, + "integer_value": "2" + }, + { + "name": "integer_no_spelling", + "kind": "INTEGER_LITERAL", + "type": "int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 23, + "location_column": 39 + }, + "integer_value": "4" + }, + { + "name": "integer_no_spelling", + "kind": "INTEGER_LITERAL", + "type": "int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 23, + "location_column": 42 + }, + "integer_value": "8" + } + ] + } + ] + }, + { + "name": "OSIdleCtr", + "kind": "VAR_DECL", + "type": "int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 53, + "location_column": 12 + }, + "is_extern": true + }, + { + "name": "_Node", + "kind": "STRUCT_DECL", + "type": "struct _Node", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 56, + "location_column": 16 + }, + "members": [ + { + "name": "dataParse", + "kind": "FIELD_DECL", + "type": "int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 58, + "location_column": 7 + }, + "member": "struct_member" + }, + { + "name": "next", + "kind": "FIELD_DECL", + "type": "struct _Node *", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 59, + "location_column": 16 + }, + "member": "struct_member", + "children": [ + { + "name": "struct _Node", + "kind": "TYPE_REF", + "type": "struct _Node", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 59, + "location_column": 9 + } + } + ] + } + ] + }, + { + "name": "Node", + "kind": "TYPEDEF_DECL", + "type": "Node", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 60, + "location_column": 2 + }, + "children": [ + { + "name": "_Node", + "kind": "STRUCT_DECL", + "type": "struct _Node", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 56, + "location_column": 16 + }, + "members": [ + { + "name": "dataParse", + "kind": "FIELD_DECL", + "type": "int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 58, + "location_column": 7 + }, + "member": "struct_member" + }, + { + "name": "next", + "kind": "FIELD_DECL", + "type": "struct _Node *", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 59, + "location_column": 16 + }, + "member": "struct_member", + "children": [ + { + "name": "struct _Node", + "kind": "TYPE_REF", + "type": "struct _Node", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 59, + "location_column": 9 + } + } + ] + } + ] + } + ] + }, + { + "name": "Un", + "kind": "UNION_DECL", + "type": "union Un", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 63, + "location_column": 7 + }, + "members": [ + { + "name": "numSize", + "kind": "FIELD_DECL", + "type": "int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 65, + "location_column": 6 + }, + "member": "union_member" + } + ] + }, + { + "name": "NoteCome", + "kind": "FUNCTION_DECL", + "type": "int (char)", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 69, + "location_column": 5 + }, + "return_type": "int", + "is_extern": false, + "parm": [ + { + "name": "AgetNote", + "kind": "PARM_DECL", + "type": "char", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 69, + "location_column": 19 + } + }, + { + "name": "", + "kind": "COMPOUND_STMT", + "type": "", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 69, + "location_column": 28 + }, + "children": [ + { + "name": "", + "kind": "DECL_STMT", + "type": "", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 71, + "location_column": 5 + }, + "children": [ + { + "name": "PowerBoardStatus", + "kind": "ENUM_DECL", + "type": "enum PowerBoardStatus", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 71, + "location_column": 10 + } + }, + { + "name": "powerBoardStatusOfSlot", + "kind": "VAR_DECL", + "type": "enum PowerBoardStatus", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 71, + "location_column": 27 + }, + "is_extern": false, + "children": [ + { + "name": "enum PowerBoardStatus", + "kind": "TYPE_REF", + "type": "enum PowerBoardStatus", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 71, + "location_column": 10 + } + } + ] + } + ] + }, + { + "name": "", + "kind": "DECL_STMT", + "type": "", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 72, + "location_column": 5 + }, + "children": [ + { + "name": "name", + "kind": "VAR_DECL", + "type": "char[17]", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 72, + "location_column": 10 + }, + "is_extern": false, + "children": [ + { + "name": "\"CSDN_Author:Xa_L\"", + "kind": "STRING_LITERAL", + "type": "char[17]", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 72, + "location_column": 17 + } + } + ] + } + ] + }, + { + "name": "", + "kind": "DECL_STMT", + "type": "", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 73, + "location_column": 2 + }, + "children": [ + { + "name": "ch", + "kind": "VAR_DECL", + "type": "char", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 73, + "location_column": 7 + }, + "is_extern": false, + "children": [ + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "char", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 73, + "location_column": 10 + }, + "children": [ + { + "name": "A", + "kind": "CHARACTER_LITERAL", + "type": "int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 73, + "location_column": 10 + } + } + ] + } + ] + } + ] + }, + { + "name": "", + "kind": "DECL_STMT", + "type": "", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 74, + "location_column": 2 + }, + "children": [ + { + "name": "ret", + "kind": "VAR_DECL", + "type": "char", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 74, + "location_column": 7 + }, + "is_extern": false + } + ] + }, + { + "name": "binary_ope_no_spelling", + "kind": "BINARY_OPERATOR", + "type": "char", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 2 + }, + "children": [ + { + "name": "ret", + "kind": "DECL_REF_EXPR", + "type": "char", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 2 + } + }, + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "char", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 8 + }, + "children": [ + { + "name": "memchr", + "kind": "CALL_EXPR", + "type": "void *", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 8 + }, + "children": [ + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "void *(*)(const void *, int, unsigned long long)", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 8 + }, + "children": [ + { + "name": "memchr", + "kind": "DECL_REF_EXPR", + "type": "void *(const void *, int, unsigned long long)", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 8 + } + } + ] + }, + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "const void *", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 15 + }, + "children": [ + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "char *", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 15 + }, + "children": [ + { + "name": "name", + "kind": "DECL_REF_EXPR", + "type": "char[17]", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 15 + } + } + ] + } + ] + }, + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 21 + }, + "children": [ + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "char", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 21 + }, + "children": [ + { + "name": "ch", + "kind": "DECL_REF_EXPR", + "type": "char", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 21 + } + } + ] + } + ] + }, + { + "name": "strlen", + "kind": "CALL_EXPR", + "type": "unsigned long long", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 25 + }, + "children": [ + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "unsigned long long (*)(const char *)", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 25 + }, + "children": [ + { + "name": "strlen", + "kind": "DECL_REF_EXPR", + "type": "unsigned long long (const char *)", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 25 + } + } + ] + }, + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "const char *", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 32 + }, + "children": [ + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "char *", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 32 + }, + "children": [ + { + "name": "name", + "kind": "DECL_REF_EXPR", + "type": "char[17]", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 75, + "location_column": 32 + } + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "", + "kind": "IF_STMT", + "type": "", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 76, + "location_column": 2 + }, + "children": [ + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "_Bool", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 76, + "location_column": 5 + } + }, + { + "name": "", + "kind": "COMPOUND_STMT", + "type": "", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 77, + "location_column": 2 + }, + "children": [ + { + "name": "printf", + "kind": "CALL_EXPR", + "type": "int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 78, + "location_column": 3 + }, + "children": [ + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "int (*)(const char *, ...)", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 78, + "location_column": 3 + }, + "children": [ + { + "name": "printf", + "kind": "DECL_REF_EXPR", + "type": "int (const char *, ...)", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 78, + "location_column": 3 + } + } + ] + }, + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "const char *", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 78, + "location_column": 10 + }, + "children": [ + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "char *", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 78, + "location_column": 10 + }, + "children": [ + { + "name": "\"Success found %c\"", + "kind": "STRING_LITERAL", + "type": "char[17]", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 78, + "location_column": 10 + } + } + ] + } + ] + }, + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 78, + "location_column": 29 + }, + "children": [ + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "char", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 78, + "location_column": 29 + }, + "children": [ + { + "name": "ch", + "kind": "DECL_REF_EXPR", + "type": "char", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 78, + "location_column": 29 + } + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "", + "kind": "COMPOUND_STMT", + "type": "", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 81, + "location_column": 2 + }, + "children": [ + { + "name": "printf", + "kind": "CALL_EXPR", + "type": "int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 82, + "location_column": 3 + }, + "children": [ + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "int (*)(const char *, ...)", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 82, + "location_column": 3 + }, + "children": [ + { + "name": "printf", + "kind": "DECL_REF_EXPR", + "type": "int (const char *, ...)", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 82, + "location_column": 3 + } + } + ] + }, + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "const char *", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 82, + "location_column": 10 + }, + "children": [ + { + "name": "unexposed_expr_no_spelling", + "kind": "UNEXPOSED_EXPR", + "type": "char *", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 82, + "location_column": 10 + }, + "children": [ + { + "name": "\"No success\"", + "kind": "STRING_LITERAL", + "type": "char[11]", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 82, + "location_column": 10 + } + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "name": "", + "kind": "RETURN_STMT", + "type": "", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 84, + "location_column": 2 + }, + "children": [ + { + "name": "integer_no_spelling", + "kind": "INTEGER_LITERAL", + "type": "int", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 84, + "location_column": 9 + }, + "integer_value": "0" + } + ] + } + ] + } + ] + }, + { + "name": "OH_Drawing_Canvas", + "kind": "STRUCT_DECL", + "type": "struct OH_Drawing_Canvas", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 95, + "location_column": 16 + } + }, + { + "name": "OH_Drawing_Canvas", + "kind": "TYPEDEF_DECL", + "type": "OH_Drawing_Canvas", + "comment": "/**\n * @brief Defines a rectangular canvas on which various shapes, images,\n * and texts can be drawn by using the brush and pen.\n * \n * @since 8\n * @version 1.0\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 95, + "location_column": 34 + }, + "children": [ + { + "name": "struct OH_Drawing_Canvas", + "kind": "TYPE_REF", + "type": "struct OH_Drawing_Canvas", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 95, + "location_column": 16 + } + } + ] + }, + { + "name": "OH_Drawing_Pen", + "kind": "STRUCT_DECL", + "type": "struct OH_Drawing_Pen", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 103, + "location_column": 16 + } + }, + { + "name": "OH_Drawing_Pen", + "kind": "TYPEDEF_DECL", + "type": "OH_Drawing_Pen", + "comment": "/**\n * @brief Defines a pen, which is used to describe the style and color to outline a shape.\n * \n * @since 8\n * @version 1.0\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 103, + "location_column": 31 + }, + "children": [ + { + "name": "struct OH_Drawing_Pen", + "kind": "TYPE_REF", + "type": "struct OH_Drawing_Pen", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 103, + "location_column": 16 + } + } + ] + }, + { + "name": "OH_Drawing_Brush", + "kind": "STRUCT_DECL", + "type": "struct OH_Drawing_Brush", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 111, + "location_column": 16 + } + }, + { + "name": "OH_Drawing_Brush", + "kind": "TYPEDEF_DECL", + "type": "OH_Drawing_Brush", + "comment": "/**\n * @brief Defines as a brush, which is used to describe the style and color to fill in a shape.\n * \n * @since 8\n * @version 1.0\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 111, + "location_column": 33 + }, + "children": [ + { + "name": "struct OH_Drawing_Brush", + "kind": "TYPE_REF", + "type": "struct OH_Drawing_Brush", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 111, + "location_column": 16 + } + } + ] + }, + { + "name": "OH_Drawing_Path", + "kind": "STRUCT_DECL", + "type": "struct OH_Drawing_Path", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 119, + "location_column": 16 + } + }, + { + "name": "OH_Drawing_Path", + "kind": "FUNCTION_DECL", + "type": "OH_Drawing_Path", + "parm": [{"name": "AAA", + "kind": "param_DECL", + "type": "AAA" + }], + "comment": "/**\n * @param name Defines a path, which is used to customize various shapes.\n * \n * @since 8\n * @version 1.0\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 119, + "location_column": 32 + }, + "children": [ + { + "name": "struct OH_Drawing_Path", + "kind": "TYPE_REF", + "type": "struct OH_Drawing_Path", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 119, + "location_column": 16 + } + } + ] + }, + { + "name": "OH_Drawing_Bitmap", + "kind": "STRUCT_DECL", + "type": "struct OH_Drawing_Bitmap", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 127, + "location_column": 16 + } + }, + { + "name": "OH_Drawing_Bitmap", + "kind": "TYPEDEF_DECL", + "type": "OH_Drawing_Bitmap", + "comment": "/**\n * @brief Defines a bitmap, which is a memory that contains the pixel data of a shape.\n * \n * @since 8\n * @version 1.0\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 127, + "location_column": 34 + }, + "children": [ + { + "name": "struct OH_Drawing_Bitmap", + "kind": "TYPE_REF", + "type": "struct OH_Drawing_Bitmap", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 127, + "location_column": 16 + } + } + ] + }, + { + "name": "OH_Drawing_ColorFormat", + "kind": "ENUM_DECL", + "type": "OH_Drawing_ColorFormat", + "comment": "/**\n * @brief Enumerates storage formats of bitmap pixels.\n * \n * @since 8\n * @version 1.0\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 135, + "location_column": 9 + }, + "members": [ + { + "name": "COLOR_FORMAT_UNKNOWN", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/** Unknown format. */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 137, + "location_column": 5 + }, + "value": 0 + }, + { + "name": "COLOR_FORMAT_ALPHA_8", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/** Each pixel is represented by 8 bits, which together indicate alpha. */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 139, + "location_column": 5 + }, + "value": 1 + }, + { + "name": "COLOR_FORMAT_RGB_565", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/**\n * Each pixel is represented by 16 bits. From the most significant bit to the least significant bit,\n * the first 5 bits indicate red, the subsequent 6 bits indicate green, and the last 5 bits indicate blue.\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 144, + "location_column": 5 + }, + "value": 2 + }, + { + "name": "COLOR_FORMAT_ARGB_4444", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/**\n * Each pixel is represented by 16 bits. From the most significant bit to the least significant bit,\n * every 4 bits indicate alpha, red, green, and blue, respectively.\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 149, + "location_column": 5 + }, + "value": 3 + }, + { + "name": "COLOR_FORMAT_RGBA_8888", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/**\n * Each pixel is represented by 32 bits. From the most significant bit to the least significant bit,\n * every 8 bits indicate alpha, red, green, and blue, respectively.\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 154, + "location_column": 5 + }, + "value": 4 + }, + { + "name": "COLOR_FORMAT_BGRA_8888", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/**\n * Each pixel is represented by 32 bits. From the most significant bit to the least significant bit,\n * every 8 bits indicate blue, green, red, and alpha, respectively.\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 159, + "location_column": 5 + }, + "value": 5 + } + ] + }, + { + "name": "OH_Drawing_ColorFormat", + "kind": "TYPEDEF_DECL", + "type": "OH_Drawing_ColorFormat", + "comment": "/**\n * @brief Enumerates storage formats of bitmap pixels.\n * \n * @since 8\n * @version 1.0\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 160, + "location_column": 3 + }, + "children": [ + { + "name": "OH_Drawing_ColorFormat", + "kind": "ENUM_DECL", + "type": "OH_Drawing_ColorFormat", + "comment": "/**\n * @brief Enumerates storage formats of bitmap pixels.\n * \n * @since 8\n * @version 1.0\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 135, + "location_column": 9 + }, + "members": [ + { + "name": "COLOR_FORMAT_UNKNOWN", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/** Unknown format. */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 137, + "location_column": 5 + }, + "value": 0 + }, + { + "name": "COLOR_FORMAT_ALPHA_8", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/** Each pixel is represented by 8 bits, which together indicate alpha. */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 139, + "location_column": 5 + }, + "value": 1 + }, + { + "name": "COLOR_FORMAT_RGB_565", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/**\n * Each pixel is represented by 16 bits. From the most significant bit to the least significant bit,\n * the first 5 bits indicate red, the subsequent 6 bits indicate green, and the last 5 bits indicate blue.\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 144, + "location_column": 5 + }, + "value": 2 + }, + { + "name": "COLOR_FORMAT_ARGB_4444", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/**\n * Each pixel is represented by 16 bits. From the most significant bit to the least significant bit,\n * every 4 bits indicate alpha, red, green, and blue, respectively.\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 149, + "location_column": 5 + }, + "value": 3 + }, + { + "name": "COLOR_FORMAT_RGBA_8888", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/**\n * Each pixel is represented by 32 bits. From the most significant bit to the least significant bit,\n * every 8 bits indicate alpha, red, green, and blue, respectively.\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 154, + "location_column": 5 + }, + "value": 4 + }, + { + "name": "COLOR_FORMAT_BGRA_8888", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/**\n * Each pixel is represented by 32 bits. From the most significant bit to the least significant bit,\n * every 8 bits indicate blue, green, red, and alpha, respectively.\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 159, + "location_column": 5 + }, + "value": 5 + } + ] + } + ] + }, + { + "name": "OH_Drawing_AlphaFormat", + "kind": "ENUM_DECL", + "type": "OH_Drawing_AlphaFormat", + "comment": "/**\n * @brief Enumerates alpha formats of bitmap pixels.\n * \n * @since 8\n * @version 1.0\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 168, + "location_column": 9 + }, + "members": [ + { + "name": "ALPHA_FORMAT_UNKNOWN", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/** Unknown format. */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 170, + "location_column": 5 + }, + "value": 0 + }, + { + "name": "ALPHA_FORMAT_OPAQUE", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/** The bitmap does not have the alpha component. */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 172, + "location_column": 5 + }, + "value": 1 + }, + { + "name": "ALPHA_FORMAT_PREMUL", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/** The color component of each pixel is premultiplied by the alpha component. */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 174, + "location_column": 5 + }, + "value": 2 + }, + { + "name": "ALPHA_FORMAT_UNPREMUL", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/** The color component of each pixel is not premultiplied by the alpha component. */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 176, + "location_column": 5 + }, + "value": 3 + } + ] + }, + { + "name": "OH_Drawing_AlphaFormat", + "kind": "TYPEDEF_DECL", + "type": "OH_Drawing_AlphaFormat", + "comment": "/**\n * @brief Enumerates alpha formats of bitmap pixels.\n * \n * @since 8\n * @version 1.0\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 177, + "location_column": 3 + }, + "children": [ + { + "name": "OH_Drawing_AlphaFormat", + "kind": "ENUM_DECL", + "type": "OH_Drawing_AlphaFormat", + "comment": "/**\n * @brief Enumerates alpha formats of bitmap pixels.\n * \n * @since 8\n * @version 1.0\n */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 168, + "location_column": 9 + }, + "members": [ + { + "name": "ALPHA_FORMAT_UNKNOWN", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/** Unknown format. */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 170, + "location_column": 5 + }, + "value": 0 + }, + { + "name": "ALPHA_FORMAT_OPAQUE", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/** The bitmap does not have the alpha component. */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 172, + "location_column": 5 + }, + "value": 1 + }, + { + "name": "ALPHA_FORMAT_PREMUL", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/** The color component of each pixel is premultiplied by the alpha component. */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 174, + "location_column": 5 + }, + "value": 2 + }, + { + "name": "ALPHA_FORMAT_UNPREMUL", + "kind": "ENUM_CONSTANT_DECL", + "type": "int", + "comment": "/** The color component of each pixel is not premultiplied by the alpha component. */", + "location": { + "location_path": "C:\\Users\\Administrator\\Desktop\\test\\drawing_types.h", + "location_line": 176, + "location_column": 5 + }, + "value": 3 + } + ] + } + ] + } + ] + } +] \ No newline at end of file diff --git a/capi_parser/src/typedef/check/check.py b/capi_parser/src/typedef/check/check.py new file mode 100644 index 000000000..3ed2b991c --- /dev/null +++ b/capi_parser/src/typedef/check/check.py @@ -0,0 +1,255 @@ +import enum + + +class TAGS(enum.Enum): + ADD_TO_GROUP = 'addtogroup' + BRIEF = 'brief' + DEPRECATED = 'deprecated' + FILE = 'file' + LIBRARY = 'library' + PARAM = 'param' + PERMISSION = 'permission' + RETURN = 'return' + SINCE = 'since' + SYSCAP = 'syscap' + LEFT_BRACE = '{' + RIGHT_BRACE = '}' + + +class ErrorType(enum.Enum): + DEFAULT = { + 'id': -1, + 'description': '', + } + EMPTY_TAG = { + 'id': 0, + 'description': "空标签", + } + MISSPELL_WORDS = { + 'id': 1, + 'description': 'misspell words', + } + NAMING_ERRORS = { + 'id': 2, + 'description': 'naming errors', + } + UNKNOW_DEPRECATED = { + 'id': 5, + 'description': 'unknow deprecated', + } + WRONG_VALUE = { + 'id': 7, + 'description': 'wrong value', + } + WRONG_SCENE = { + 'id': 8, + 'description': 'wrong scene', + } + + +class LogType(enum.Enum): + DEFAULT = '' + LOG_API = 'Api' + LOG_JSDOC = 'JsDoc' + LOG_FILE = 'File' + + +class ErrorLevel(enum.Enum): + HIGH = 3 + MIDDLE = 2 + LOW = 1 + + +class ErrorMessage(enum.Enum): + EMPTY_TAG = 'the [$$] tag value is empty. Please supplement the default value' + 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' + ERROR_INFO_VALUE_PARAM = 'the value of the [$$] [param] tag is incorrect. Please check if it matches 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' + 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.' + 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.' + 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.' + 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.' + 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.' + VAR_DECL = 'Variable naming should use the small hump naming style.' + PARM_DECL = 'Function parameters naming should use the small hump naming style.' + 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.' + 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.' + GLOBAL_VARIABLE_TYPE_NAMING_ERROR = 'Global variable should increase "g_" prefix.' + TRANSLATION_UNIT = 'File naming should be all lowercase, separated by underscores.' + + +class OutputTxt: + id = -1 + level = -1 + location = '' + filePath = '' + message = '' + + def __init__(self, id, level, location, file_path, message): + self.id = id + self.level = level + self.location = location + self.filePath = file_path + self.message = message + + def get_id(self): + return self.id + + def set_id(self, id): + self.id = id + + def get_level(self): + return self.level + + def set_level(self, level): + self.level = level + + def get_location(self): + return self.location + + def set_location(self, location): + self.location = location + + def get_file_path(self): + return self.filePath + + def set_file_path(self, file_path): + self.filePath = file_path + + def get_message(self): + return self.message + + def set_message(self, message): + self.message = message + + +class ApiResultInfo: + errorType: ErrorType = ErrorType.DEFAULT.value + errorInfo = '' + level: ErrorLevel = -1 + apiName = '' + apiFullText = '' + fileName = '' + location = '' + locationLine = -1 + locationColumn = -1 + type: LogType = LogType.DEFAULT.value + version = -1 + basename = '' + + def __init__(self, error_type=None, error_info='', api_name=''): + if error_type is None: + error_type = ErrorType.DEFAULT.value + self.errorType = error_type + self.errorInfo = error_info + self.apiName = api_name + + def get_error_type(self): + return self.errorType + + def set_error_type(self, error_type): + self.errorType = error_type + + def get_file_name(self): + return self.fileName + + def set_file_name(self, file_name): + self.fileName = file_name + + def get_type(self): + return self.type + + def set_type(self, type): + self.type = type + + def get_error_info(self): + return self.errorInfo + + def set_error_info(self, error_info): + self.errorInfo = error_info + + def get_version(self): + return self.version + + def set_version(self, version): + self.version = version + + def get_basename(self): + return self.basename + + def set_basename(self, basename): + self.basename = basename + + def get_level(self): + return self.level + + def set_level(self, level): + self.level = level + + def get_api_name(self): + return self.apiName + + def set_api_name(self, api_name): + self.apiName = api_name + + def get_api_full_text(self): + return self.apiFullText + + def set_api_full_text(self, api_full_text): + self.apiFullText = api_full_text + + def get_location_line(self): + return self.locationLine + + def set_location_line(self, location_line): + self.locationLine = location_line + + def get_location_column(self): + return self.locationColumn + + def set_location_column(self, location_column): + self.locationColumn = location_column + + def get_location(self): + return self.location + + def set_location(self, location): + self.location = location + + +class DocInfo: + group = '' + brief = '' + deprecated = '' + file = '' + permission = '' + since = '' + syscap = '' + param_index = -1 + throw_index = -1 + + +class FileDocInfo: + is_in_group_tag = False + group_name = None + has_group_start = False + has_group_end = False + is_in_file_tag = False + file_name = None + file_brief = None + file_library = None + file_syscap = None + curr_doc_info = DocInfo() -- Gitee From 57174c8e3be00c9671176280741a1f8595723d01 Mon Sep 17 00:00:00 2001 From: jwx1102601 Date: Fri, 10 Nov 2023 10:14:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=B8=E5=8F=AF?= =?UTF-8?q?=E8=AF=81=E5=A4=B4=E5=92=8C=E7=89=88=E6=9D=83=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jwx1102601 --- capi_parser/src/bin/config.py | 15 ++++++++++ .../src/coreImpl/parser/check/check.py | 29 +++++++++++++------ .../src/coreImpl/parser/check/check_name.py | 15 ++++++++++ capi_parser/src/typedef/check/check.py | 16 +++++++++- 4 files changed, 65 insertions(+), 10 deletions(-) diff --git a/capi_parser/src/bin/config.py b/capi_parser/src/bin/config.py index 72c385c93..ddc419c6f 100644 --- a/capi_parser/src/bin/config.py +++ b/capi_parser/src/bin/config.py @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import enum from coreImpl.parser import parser from coreImpl.check import check diff --git a/capi_parser/src/coreImpl/parser/check/check.py b/capi_parser/src/coreImpl/parser/check/check.py index 43ce2b6df..d15f1e573 100644 --- a/capi_parser/src/coreImpl/parser/check/check.py +++ b/capi_parser/src/coreImpl/parser/check/check.py @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import json from typedef.check.check import ApiResultInfo, FileDocInfo, OutputTxt from coreImpl.check.check_doc import process_comment, process_file_doc_info @@ -10,11 +25,9 @@ def process_api_json(api_info, file_doc_info: FileDocInfo, api_result_info_list) comment = api_info['comment'] api_result_info_list.extend( process_comment(comment, file_doc_info, api_info)) - child_node = get_api_info_child(api_info) - if len(child_node) > 0: - for index in range(len(child_node)): - process_api_json( - child_node[index], file_doc_info, api_result_info_list) + child_node_list = get_api_info_child(api_info) + for child_node in child_node_list: + process_api_json(child_node, file_doc_info, api_result_info_list) def get_api_info_child(api_info): @@ -31,16 +44,14 @@ def process_file_json(file_info, api_result_info_list): api_result_info_list.extend(check_file_name(file_info['name'])) apis = file_info['children'] file_doc_info = FileDocInfo() - for index in range(len(apis)): - api = apis[index] + for api in apis: process_api_json(api, file_doc_info, api_result_info_list) api_result_info_list.extend(process_file_doc_info(file_doc_info, file_info)) def process_all_json(python_obj) -> list[ApiResultInfo]: api_result_info_list = [] - for index in range(len(python_obj)): - file_info = python_obj[index] + for file_info in python_obj: process_file_json(file_info, api_result_info_list) return api_result_info_list diff --git a/capi_parser/src/coreImpl/parser/check/check_name.py b/capi_parser/src/coreImpl/parser/check/check_name.py index 2de6d143e..3cbdd67f7 100644 --- a/capi_parser/src/coreImpl/parser/check/check_name.py +++ b/capi_parser/src/coreImpl/parser/check/check_name.py @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import enum import os.path import re diff --git a/capi_parser/src/typedef/check/check.py b/capi_parser/src/typedef/check/check.py index 3ed2b991c..63d192dbd 100644 --- a/capi_parser/src/typedef/check/check.py +++ b/capi_parser/src/typedef/check/check.py @@ -1,5 +1,19 @@ -import enum +/* + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import enum class TAGS(enum.Enum): ADD_TO_GROUP = 'addtogroup' -- Gitee