diff --git a/build-tools/capi_parser/src/coreImpl/diff/diff_processor_node.py b/build-tools/capi_parser/src/coreImpl/diff/diff_processor_node.py index 765bdacf34c2709b64e7ada80d3996ca4e1871c7..dc8362526cdc1fed1a3e3f98da1de49b2674c325 100644 --- a/build-tools/capi_parser/src/coreImpl/diff/diff_processor_node.py +++ b/build-tools/capi_parser/src/coreImpl/diff/diff_processor_node.py @@ -26,6 +26,8 @@ current_file = os.path.dirname(__file__) def wrap_diff_info(old_info, new_info, diff_info: DiffInfo): if old_info is not None: + if 'temporary_name' in old_info['name']: + old_info['name'] = '' diff_info.set_api_name(old_info['name']) diff_info.set_api_type(old_info['kind']) diff_info.set_api_line(old_info['location']['location_line']) @@ -34,6 +36,8 @@ def wrap_diff_info(old_info, new_info, diff_info: DiffInfo): if 'content' in old_info['node_content']: diff_info.set_old_api_full_text(old_info['node_content']['content']) if new_info is not None: + if 'temporary_name' in new_info['name']: + new_info['name'] = '' diff_info.set_api_name(new_info['name']) diff_info.set_api_type(new_info['kind']) diff_info.set_api_line(new_info['location']['location_line']) @@ -47,9 +51,12 @@ def wrap_diff_info(old_info, new_info, diff_info: DiffInfo): def parse_file_result(result): result_map = {} + key = 1 for member in result: if member["name"] == '': - continue + name = 'temporary_name' + member["name"] = '{}{}'.format(name, key) + key += 1 result_map.setdefault(f'{member["name"]}-{member["kind"]}', member) return result_map @@ -192,10 +199,12 @@ def process_struct_member_scene(old_member, new_member, diff_struct_list): special_data = process_enum(old_member, new_member) diff_struct_list.extend(special_data) - if old_member['type'] != new_member['type']: - diff_info = wrap_diff_info(old_member, new_member, - DiffInfo(DiffType.STRUCT_MEMBER_TYPE_CHANGE)) - diff_struct_list.append(diff_info) + if (not(old_member['location']['location_path'] in old_member['type'])) and \ + (not(new_member['location']['location_path'] in new_member['type'])): + if old_member['type'] != new_member['type']: + diff_info = wrap_diff_info(old_member, new_member, + DiffInfo(DiffType.STRUCT_MEMBER_TYPE_CHANGE)) + diff_struct_list.append(diff_info) if old_member['name'] != new_member['name']: diff_info = wrap_diff_info(old_member, new_member, @@ -257,10 +266,12 @@ def process_union_member_scene(old_member, new_member, diff_union_list): special_data = process_enum(old_member, new_member) diff_union_list.extend(special_data) - if old_member['type'] != new_member['type']: - diff_info = wrap_diff_info(old_member, new_member, - DiffInfo(DiffType.UNION_MEMBER_TYPE_CHANGE)) - diff_union_list.append(diff_info) + if (not(old_member['location']['location_path'] in old_member['type'])) and \ + (not(new_member['location']['location_path'] in new_member['type'])): + if old_member['type'] != new_member['type']: + diff_info = wrap_diff_info(old_member, new_member, + DiffInfo(DiffType.UNION_MEMBER_TYPE_CHANGE)) + diff_union_list.append(diff_info) if old_member['name'] != new_member['name']: diff_info = wrap_diff_info(old_member, new_member, @@ -401,7 +412,7 @@ def process_typedef(old, new): diff_typedef_list = [] process_typedef_name(old, new, diff_typedef_list) # 处理命名 - if 'children' in old and 'children' in old: # 处理子节点 + if 'children' in old and 'children' in new: # 处理子节点 process_typedef_child(old['children'], new['children'], diff_typedef_list) return diff_typedef_list @@ -699,10 +710,10 @@ def process_doc_list(old_doc_list: list, new_doc_list: list, old_info, new_info) new_length = len(new_doc_list) index = 0 while index < max(old_length, new_length): - if index > old_length: + if index >= old_length != new_length: diff_info_list.append(wrap_diff_info(old_info, new_info, DiffInfo(DiffType.ADD_DOC))) break - if index > new_length: + if index >= new_length != old_length: diff_info_list.append(wrap_diff_info(old_info, new_info, DiffInfo(DiffType.REDUCE_DOC))) break diff_info_list.extend(process_doc(old_doc_list[index], new_doc_list[index], old_info, new_info)) diff --git a/build-tools/capi_parser/src/coreImpl/parser/generating_tables.py b/build-tools/capi_parser/src/coreImpl/parser/generating_tables.py index 9e14eade616920581e63432b44cae4cb41c50ceb..80a89d675ad8ae1cd48eb79dce9018a1cfe18c1c 100644 --- a/build-tools/capi_parser/src/coreImpl/parser/generating_tables.py +++ b/build-tools/capi_parser/src/coreImpl/parser/generating_tables.py @@ -88,6 +88,7 @@ def get_parm(item, parm): def filter_func(item): del item["is_extern"] # 剔除is_extern键值对,过滤后都是extern del item["comment"] + del item["syscap"] if "type_ref" in list(item.keys()): del item["type_ref"] if "children" in list(item.keys()): @@ -117,7 +118,7 @@ def generate_excel(array, name, only_file1, only_file2): 'location': '位置行', 'return_type': '返回类型', 'parm': '参数', - 'location_path': '文件相对路径', + 'location_path': '文件相对路径' } workbook = openpyxl.Workbook() 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 14c84d2ceabeeeb0028472b0b8d4ab0c709a02f8..c5825cfeaba462cd6f53bc5577b522bb813a7b4e 100644 --- a/build-tools/capi_parser/src/coreImpl/parser/parse_include.py +++ b/build-tools/capi_parser/src/coreImpl/parser/parse_include.py @@ -241,6 +241,17 @@ def node_extent(cursor, current_file): return extent +def define_comment(cursor, current_file, data): + line = cursor.location.line + with open(current_file, mode='r', encoding='utf-8') as file: + file_content = file.readlines()[:line] + file_content = ''.join(file_content) + pattern = '{} {})'.format(RegularExpressions.DEFINE_COMMENT.value, cursor.spelling) + matches = re.search(pattern, file_content) + if matches: + data['comment'] = matches.group() + + def ast_to_dict(cursor, current_file, gn_path=None, comment=None, key=0): # 解析数据的整理 # 通用 data = { @@ -249,13 +260,10 @@ def ast_to_dict(cursor, current_file, gn_path=None, comment=None, key=0): # 解 "type": cursor.type.spelling, "gn_path": gn_path, "node_content": {}, - "comment": '' + "comment": '', + "syscap": '' } - if cursor.raw_comment: # 是否有注释信息,有就取,没有过 - data["comment"] = cursor.raw_comment - else: - data["comment"] = 'none_comment' - + get_comment(cursor, data) if key == 0: data["kind"] = CursorKind.TRANSLATION_UNIT.name if comment: @@ -267,7 +275,9 @@ def ast_to_dict(cursor, current_file, gn_path=None, comment=None, key=0): # 解 content = node_extent(cursor, current_file) data["node_content"] = content data["kind"] = cursor.kind.name - + if cursor.kind.name == CursorKind.MACRO_DEFINITION.name: + define_comment(cursor, current_file, data) + get_syscap_value(data) processing_special_node(cursor, data, key, gn_path) # 节点处理 children = list(cursor.get_children()) # 判断是否有子节点,有就追加children,没有根据情况来 if len(children) > 0: @@ -286,14 +296,29 @@ def ast_to_dict(cursor, current_file, gn_path=None, comment=None, key=0): # 解 for child in children: # 剔除多余宏定义和跳过UNEXPOSED_ATTR节点 - if child.location.file is not None and child.kind != CursorKind.UNEXPOSED_ATTR \ - and child.location.file.name == current_file: + if (child.location.file is not None) and (not child.kind.is_attribute()) \ + and (child.location.file.name == current_file): processing_ast_node(child, current_file, data, name, gn_path) else: processing_no_child(cursor, data) # 处理没有子节点的节点 return data +def get_syscap_value(data: dict): + if 'none_comment' != data["comment"]: + pattern = r'@([Ss]yscap).*?(?=\n)' + matches = re.search(pattern, data['comment']) + if matches: + data["syscap"] = matches.group(0) + + +def get_comment(cursor, data: dict): + if cursor.raw_comment: # 是否有注释信息,有就取,没有过 + data["comment"] = cursor.raw_comment + else: + data["comment"] = 'none_comment' + + def processing_ast_node(child, current_file, data, name, gn_path): child_data = ast_to_dict(child, current_file, gn_path, key=1) if child.kind == CursorKind.TYPE_REF: @@ -331,17 +356,21 @@ def get_start_comments(include_path): # 获取每个头文件的最开始注释 def open_file(include_path): with open(include_path, 'r', encoding='utf-8') as f: content = '' - loge = 0 + mark = 0 + if 'ffrt' in include_path: + end_line_mark = r'#ifndef' + else: + end_line_mark = r'#endif' for line in f: - if line.startswith('#ifdef __cplusplus'): - loge = 1 + if line.startswith(end_line_mark): + mark = 1 break else: inside_ifdef = True if inside_ifdef: content += line - if loge == 0: + if mark == 0: content = '' f.close() return content @@ -386,5 +415,4 @@ def get_include_file(include_file_path, link_path, gn_path=None): # 库路径 # 头文件链接路径 link_include_path = link_path # 可以通过列表传入 data = api_entrance(libclang_path, file_path, gn_path, link_include_path) # 调用接口 - return data diff --git a/build-tools/capi_parser/src/utils/constants.py b/build-tools/capi_parser/src/utils/constants.py index 628741ec36b4dcb626297248f9e999ec0ce3c270..9c606194f1c93fdd153320affffc1cc0edf5d2c5 100644 --- a/build-tools/capi_parser/src/utils/constants.py +++ b/build-tools/capi_parser/src/utils/constants.py @@ -39,3 +39,4 @@ class RegularExpressions(enum.Enum): SOURCES = r'sources\s*=\s*\[[^\]]*\]' DEST_DIR = r'dest_dir\s*=\s*"([^"]*)"' INCLUDE_H = r'"([^"]+h)"' + DEFINE_COMMENT = r'/\*[^/]*\*/\s*(?=#define'