From d23288f4f1531a16a31a0105247e2d0145a1f3f9 Mon Sep 17 00:00:00 2001 From: heck Date: Thu, 14 Jan 2021 00:47:46 +0100 Subject: [PATCH] handle no headerfile/error in config (just generate empty ACID yml) --- pEpACIDgen/__init__.py | 6 +++++- pEpACIDgen/__main__.py | 4 +--- pEpACIDgen/c_2_ast.py | 15 +++++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pEpACIDgen/__init__.py b/pEpACIDgen/__init__.py index fd3125d..16fd702 100644 --- a/pEpACIDgen/__init__.py +++ b/pEpACIDgen/__init__.py @@ -36,7 +36,11 @@ class pEpACIDGen: if out_dir: model["out_dir"] = out_dir - model["sourcecode"] = utils.read_file(path) + try: + model["sourcecode"] = utils.read_file(path) + except: + pass + return model def extract(self, var_names, func_names, debug_ast=False, debug_acid=False, debug_yml=False): diff --git a/pEpACIDgen/__main__.py b/pEpACIDgen/__main__.py index 8e0db08..4dc5170 100644 --- a/pEpACIDgen/__main__.py +++ b/pEpACIDgen/__main__.py @@ -45,12 +45,10 @@ def gen(): print_indent("CONFIG:") print_indent("module_name:", pymodule_name, indent=1) - print_indent("libclang_path:", libclang_path, indent=1) - print_indent("header_filename:", header_filename, indent=1) - print_indent("variables:", indent=1) + for var in vars: print_indent(var, indent=2) diff --git a/pEpACIDgen/c_2_ast.py b/pEpACIDgen/c_2_ast.py index a9a6385..3483bdb 100644 --- a/pEpACIDgen/c_2_ast.py +++ b/pEpACIDgen/c_2_ast.py @@ -15,6 +15,7 @@ class C2AST: sys.setrecursionlimit(10000) # print("max recursion limit set to:", sys.getrecursionlimit()) + def parse(self, filename, content=None, follow_includes=False): index = clang.cindex.Index.create() arguments = ["-x", "c"] @@ -22,16 +23,23 @@ class C2AST: if content: content = [(filename, content)] - translation_unit = index.parse(filename, unsaved_files=content, args=arguments, options=options) - ret = self._parse(translation_unit.cursor, filename, follow_includes) + ret = [] + try: + translation_unit = index.parse(filename, unsaved_files=content, args=arguments, options=options) + ret = self._parse(translation_unit.cursor, filename, follow_includes) + except: + print(__file__,":: warning: error while processing header file: ", filename) + return ret + def _get_children(self, cursor, path, follow_includes=False): if follow_includes: return [c for c in cursor.get_children()] else: return [c for c in cursor.get_children() if c.location.file and c.location.file.name == path] + def _parse(self, cursor, path, follow_includes=False, parent_cursor=None): item = None dont_recurse = False @@ -103,11 +111,10 @@ class C2AST: item["utypekind"] = cursor.type.kind.spelling if parent_cursor: - if( not cursor.kind == CursorKind.TYPE_REF + if (not cursor.kind == CursorKind.TYPE_REF and parent_cursor.kind == CursorKind.FIELD_DECL): return None - if not dont_recurse: # get direct children child_cursors = self._get_children(cursor, path, follow_includes)