diff --git a/gen/ast_parser.py b/gen/ast_parser.py index 5fe88d6..8edbd12 100644 --- a/gen/ast_parser.py +++ b/gen/ast_parser.py @@ -10,7 +10,7 @@ class ASTParser: clang.cindex.Config.set_library_file(library_file) import sys sys.setrecursionlimit(10000) - print("max recursion limit:", sys.getrecursionlimit()) + print("max recursion limit set to:", sys.getrecursionlimit()) def parse(self, filename, content=None, follow_includes=False): index = clang.cindex.Index.create() @@ -30,11 +30,20 @@ class ASTParser: 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): - item = {} - + item = None + dont_recurse = False; # dont parse excluded CursorKinds excluded_cursortypes = [CursorKind.INTEGER_LITERAL] if not cursor.kind in excluded_cursortypes: + item = {"" + "tokens" : "", + "kind" : "", + "name" : "", + "type" : "", + "file" : "", + "is_definition" : "", + } + # generic info for all CursorKinds if str(cursor.get_tokens()): str_tok = "" @@ -48,6 +57,7 @@ class ASTParser: if cursor.spelling: item["name"] = cursor.spelling + # optional "displayname" if cursor.displayname: if cursor.displayname != item["name"]: item["displayname"] = cursor.displayname @@ -55,9 +65,13 @@ class ASTParser: if cursor.type.spelling: item["type"] = cursor.type.spelling - if cursor.result_type.spelling: + # optional "result_type" + if cursor.result_type.spelling != "": item["result_type"] = cursor.result_type.spelling + item["file"] = str(cursor.location.file) + + # optional "semantic_parent" if cursor.semantic_parent: if cursor.semantic_parent.kind.is_translation_unit(): item["semantic_parent"] = "global" @@ -68,36 +82,35 @@ class ASTParser: if cursor.is_definition(): item["is_definition"] = cursor.is_definition() - - # TODO: Ever occrus? - if cursor.canonical: - if cursor.canonical.spelling != cursor.spelling: - item["canonical"] = cursor.canonical.spelling - - # TYPE_REF specific info - # if cursor.kind == CursorKind.TYPE_REF: - # if cursor.get_definition(): - # definition = cursor.get_definition() - # item["definition"] = self._parse(definition, path, follow_includes=follow_includes) - # ENUM specific info + # optional "value" if cursor.kind == CursorKind.ENUM_CONSTANT_DECL: item["value"] = cursor.enum_value # TYPEDEF specific info + # optional "utype" if cursor.kind == CursorKind.TYPEDEF_DECL: item["utype"] = cursor.underlying_typedef_type.spelling + item["utypekind"] = cursor.underlying_typedef_type.kind.spelling + dont_recurse = True - # get direct children - child_cursors = self._get_children(cursor, path, follow_includes) - if len(child_cursors) > 0: - child_arr = [] - for child_cursor in child_cursors: - child_result = self._parse(child_cursor, path, follow_includes=follow_includes) - if child_result: - child_arr.append(child_result) - - if child_arr: - item["children"] = child_arr + # TYPE_REF specific info + # optional "typekind" + if cursor.kind == CursorKind.TYPE_REF: + item["utypekind"] = cursor.type.kind.spelling + + + if not dont_recurse: + # get direct children + child_cursors = self._get_children(cursor, path, follow_includes) + if len(child_cursors) > 0: + child_arr = [] + for child_cursor in child_cursors: + child_result = self._parse(child_cursor, path, follow_includes=follow_includes) + if child_result: + child_arr.append(child_result) + + if child_arr: + item["children"] = child_arr return item