def parse_folder(of_root, folder, files, is_addon=False):
    for name in files:
        filepath = os.path.join(folder, name)
        if name.split(".")[0] not in json_data.keys() and name.startswith("of") and os.path.splitext(name)[1] == ".h":
            tu = clang_utils.get_tu_from_file(filepath, of_root)
            for child in tu.cursor.get_children():
                parse_file_child(child, of_root)
Exemple #2
0
def parse_folder(root, files, is_addon=False):
    file_count = 0
    for name in files:
        file_count += 1
        filename = os.path.join(root, name)
        if name.find('of') == 0 and os.path.splitext(name)[1] == '.h':
            tu = clang_utils.get_tu_from_file(filename, of_root)
            num_functions = 0
            for child in tu.cursor.get_children():
                if is_class(child) and child.spelling.find('of') == 0:
                    i = 0
                    for c in child.get_children():
                        if is_variable(c) or is_method(
                                c) or c.kind == CursorKind.CXX_BASE_SPECIFIER:
                            i += 1
                    if i > 0 and child.spelling not in visited_classes:
                        serialize_class(child, is_addon)
                        visited_classes.append(child.spelling)
                if is_function(child) and child.spelling.find('of') == 0:
                    num_functions += 1
            functions_name = os.path.splitext(name)[0]
            if num_functions > 0 and functions_name not in visited_function_files and functions_name != "ofMain":
                serialize_functionsfile(tu.cursor, functions_name, is_addon)
                visited_function_files.append(functions_name)
    return file_count
def parse_folder(root, files, is_addon=False):
    file_count=0
    for name in files:       
        file_count+=1
        filename = os.path.join(root, name)
        if name.find('of')==0 and os.path.splitext(name)[1]=='.h':
            tu = clang_utils.get_tu_from_file(filename, of_root)
            num_functions = 0
            for child in tu.cursor.get_children():
                if is_class(child) and child.spelling.find('of')==0:
                    i=0
                    for c in child.get_children():
                        if is_variable(c) or is_method(c) or c.kind == CursorKind.CXX_BASE_SPECIFIER:
                            i+=1
                    if i>0 and child.spelling not in visited_classes:
                        serialize_class(child, is_addon)
                        visited_classes.append(child.spelling)
                if is_function(child) and child.spelling.find('of')==0:
                    num_functions+=1
            functions_name = os.path.splitext(name)[0]
            if num_functions>0 and functions_name not in visited_function_files and functions_name != "ofMain":
                serialize_functionsfile(tu.cursor, functions_name, is_addon)
                visited_function_files.append(functions_name)
    return file_count
def parse_folder(root, base, files, is_addon=False, is_glm = False):
    file_count=0
    prefix = ""
    if root != base:
        prefix = os.path.relpath(root, base) + "_"
    for name in files:
        file_count+=1
        filename = os.path.join(root, name)
        if (name.find('of')==0 and os.path.splitext(name)[1]=='.h') or os.path.splitext(name)[1]=='.hpp':
            tu = clang_utils.get_tu_from_file(filename, of_root)
            num_functions = 0
            # filter so it only parses elements from this unit not includes
            def f(child): return str(child.location.file) == str(tu.spelling)
            for child in filter(f, tu.cursor.get_children()):
                if child.spelling.find("glm") != -1 and child.kind == CursorKind.NAMESPACE:
                    for ns_child in child.get_children():
                        if is_glm_class(ns_child):
                            i=0
                            for c in ns_child.get_children():
                                if is_variable(c) or is_method(c) or c.kind == CursorKind.CXX_BASE_SPECIFIER:
                                    i+=1
                            if i>0 and ns_child.spelling not in visited_classes:
                                serialize_class(ns_child, is_addon, "glm", substitute_glm_spelling(ns_child.spelling))
                                visited_classes.append(ns_child.spelling)

                        if is_function(ns_child):
                            num_functions+=1

                if is_class(child) and child.spelling.find('of')==0:
                    i=0
                    for c in child.get_children():
                        if is_variable(c) or is_method(c) or c.kind == CursorKind.CXX_BASE_SPECIFIER:
                            i+=1
                    if i>0 and child.spelling not in visited_classes:
                        serialize_class(child, is_addon)
                        visited_classes.append(child.spelling)

                if is_function(child) and child.spelling.find('of')==0:
                    num_functions+=1

            functions_fromcode = []
            functions_name = os.path.splitext(name)[0]
            functionsfile = getfunctionsfile(prefix + functions_name)
            if num_functions>0 and functions_name not in visited_function_files and functions_name != "ofMain":
                if is_glm:
                    for child in tu.cursor.get_children():
                        if child.spelling == "glm" and child.kind == CursorKind.NAMESPACE:
                            functions_fromcode += serialize_functionsfile(child, functionsfile, is_addon, str(tu.cursor.spelling), False, "glm")
                    if len(functions_fromcode) > 0:
                        visited_function_files.append(functions_name)
                else:
                    functions_fromcode = serialize_functionsfile(tu.cursor, functionsfile, is_addon)
                    visited_function_files.append(functions_name)


            # We need to do this check outside of serialize_functionsfile cause glm is calling it several times per function
            thisfile_missing_functions = []
            for function in functionsfile.function_list:
                if not function in functions_fromcode:
                    missing_functions.append(function)
                    thisfile_missing_functions.append(function)

            for function in thisfile_missing_functions:
                functionsfile.function_list.remove(function)

            functionsfile.function_list.sort(key=lambda function: function.syntax)
            if len(functionsfile.function_list)>0:
                setfunctionsfile(functionsfile, is_addon)
            else:
                remove_functionsfile(functionsfile, is_addon)


    return file_count