Browse Source

handle no headerfile/error in config (just generate empty ACID yml)

master
heck 5 years ago
parent
commit
d23288f4f1
  1. 6
      pEpACIDgen/__init__.py
  2. 4
      pEpACIDgen/__main__.py
  3. 15
      pEpACIDgen/c_2_ast.py

6
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):

4
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)

15
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)

Loading…
Cancel
Save