From 1a182670efe4f8587d5123900c1e5fffa9bf0ea2 Mon Sep 17 00:00:00 2001 From: zhangwuf Date: Fri, 29 Dec 2023 15:14:34 +0800 Subject: [PATCH] =?UTF-8?q?CAPI=E8=A7=A3=E6=9E=90=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=AE=8F=E5=AE=9A=E4=B9=89=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=92=8Ccheck=E8=AF=AD=E6=B3=95=E6=8C=87?= =?UTF-8?q?=E4=BB=A4bug=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/check/check_syntax.py | 7 +- .../src/coreImpl/parser/parse_include.py | 102 ++++-------------- .../capi_parser/src/coreImpl/parser/parser.py | 9 +- 3 files changed, 33 insertions(+), 85 deletions(-) diff --git a/build-tools/capi_parser/src/coreImpl/check/check_syntax.py b/build-tools/capi_parser/src/coreImpl/check/check_syntax.py index b06307628..70572b31a 100644 --- a/build-tools/capi_parser/src/coreImpl/check/check_syntax.py +++ b/build-tools/capi_parser/src/coreImpl/check/check_syntax.py @@ -14,12 +14,17 @@ # limitations under the License. import re +import os import subprocess from typedef.check.check import ApiResultInfo, ErrorMessage, ErrorType, LogType, ErrorLevel def check_syntax(file_path): - cmd_list = ['clang', r'-I sysroot\ndk_musl_include_files', '-std=c99'] + cmd_list = ['clang'] + if os.path.exists(r'.\sysroot'): + args = ['-I{}'.format(dir_path) for dir_path, _, _ in os.walk(r'.\sysroot')] + cmd_list.extend(args) + cmd_list.append('-std=c99') result_list = [] command = cmd_list + [file_path] run_result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 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 ec4132637..14c84d2ce 100644 --- a/build-tools/capi_parser/src/coreImpl/parser/parse_include.py +++ b/build-tools/capi_parser/src/coreImpl/parser/parse_include.py @@ -71,59 +71,6 @@ def processing_no_child(cursor, data): # 处理没有子节点的节点 data["integer_value"] = token.spelling # 获取整型变量值 -def get_complex_def(tokens_new, count_token, tokens, data): - count = 1 - logo = 0 - logo_com = 0 - count_com = 0 - for token_2 in tokens_new: - if token_2.spelling == ')': - 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: # 获取复合型宏定义宏名 - logo_com = logo - count_com = count + 1 - tokens_name = tokens[:count + 1] - data["name"] = ''.join([token.spelling for token in tokens_name]) - return logo_com, count_com - - -def processing_complex_def(tokens, data): # 处理复合型宏 - tokens_new = tokens[1:] # 跳过正常宏名 - logo_com = 0 # 记录复合型,复合型文本也得根据这个 - count_com = 0 - count_token = len(tokens_new) # value () - for token in tokens_new: - if token.kind.name == 'KEYWORD': - break - if token.kind.name == 'IDENTIFIER': - logo_com, count_com = get_complex_def(tokens_new, count_token, tokens, data) - get_def_text(tokens, data, logo_com, count_com) # 获取宏文本 - - -def get_def_text(tokens, data, logo_compose, count_compose): # 获取宏文本 - if logo_compose == 1: - marco_expansion = ''.join([token.spelling for token in tokens[count_compose:]]) # 获取宏文本,有就记录,没有不管 - if marco_expansion: - data["text"] = marco_expansion - else: - pass - else: - marco_expansion = ''.join([token.spelling for token in tokens[1:]]) # 获取宏文本,有就记录,没有不管 - if marco_expansion: - data["text"] = marco_expansion - else: - pass - - def get_token(cursor): tokens = [] for token in cursor.get_tokens(): @@ -187,39 +134,30 @@ def processing_enum(cursor, data): # 获取枚举值 def processing_def(cursor, data): # 处理宏定义 - if data['node_content']['content']: - split_data = data['node_content']['content'].split() - split_data_three = data['node_content']['content'].split('\t') - if len(split_data) == 2: - pattern = r'\((.*?), (.*?)\)' - if re.search(pattern, data['node_content']['content']): - data['name'] = data['node_content']['content'] + data['is_def_func'] = False + data['name'] = cursor.spelling + name_len = len(data['name']) + str1_len = len(data['node_content']['content']) + text = '' + if name_len != str1_len: + if data['node_content']['content']: + if data['node_content']['content'][name_len] == '(': + right_index = data['node_content']['content'].index(')') + param = data['node_content']['content'][name_len:right_index + 1] + text = data['node_content']['content'][right_index + 1:] + data['is_def_func'] = True + data['def_func_name'] = data['name'] + data['def_func_param'] = param + data['name'] = ''.join(data['name'] + param) else: - data['name'] = split_data[0] - data['text'] = split_data[1] - elif len(split_data_three) == 2: - data['name'] = split_data_three[0] - data['text'] = split_data_three[1] + text = data['node_content']['content'][name_len:] 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') + print('mar_define error, its content is none') + if text: + text = text.strip() # 删除两边的字符(默认是删除左右空格) + data['text'] = text data["type"] = "def_no_type" - judgment_def_func(data) - - -def judgment_def_func(data): - data['is_def_func'] = False - if '(' in data['name'] and ')' in data['name']: - data['is_def_func'] = True - index = data['name'].index('(') - data['def_func_name'] = data['name'][:index] - data['def_func_param'] = data['name'][index:] - def processing_func(cursor, data): # 处理函数 data["return_type"] = cursor.result_type.spelling # 增加返回类型键值对 diff --git a/build-tools/capi_parser/src/coreImpl/parser/parser.py b/build-tools/capi_parser/src/coreImpl/parser/parser.py index 45d5696dd..33d49d083 100644 --- a/build-tools/capi_parser/src/coreImpl/parser/parser.py +++ b/build-tools/capi_parser/src/coreImpl/parser/parser.py @@ -264,8 +264,12 @@ def copy_self_include(link_include_path, self_include_file, flag=-1): if std_include and not os.path.exists(std_include): shutil.copytree(self_include_file, std_include) - for dir_path, _, _ in os.walk(std_include): - link_include_path.append(dir_path) + for dir_path, _, files in os.walk(std_include): + for file in files: + if not file.endswith('.h'): + os.remove(os.path.join(dir_path, file)) + elif dir_path not in link_include_path: + link_include_path.append(dir_path) def delete_typedef_child(child): @@ -295,6 +299,7 @@ def parser_include_ast(gn_file_path, include_path, flag=-1): # 对于单 link_include_path = [] copy_std_lib(link_include_path) find_include(link_include_path) + link_include(gn_file_path, StringConstant.FUNK_NAME.value, link_include_path) copy_self_include(link_include_path, gn_file_path, flag) modes = stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU -- Gitee