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