Example #1
0
def process_header(file, is_legacy=False):
    print("Processing file " + file)
    cpp_header = cppheaderparser.CppHeader(file)

    for function in cpp_header.functions:
        process_method(function, False, is_legacy)

    for class_name in cpp_header.classes:
        print("Processing class " + class_name)
        class_data = cpp_header.classes[class_name]
        # pprint(class_data)

        class_name_with_namespace = class_data[
            "namespace"] + "::" + class_data["name"]
        if class_name_with_namespace.startswith("::"):
            class_name_with_namespace = class_name_with_namespace[2:]

        # pprint(class_data)
        for member_vis in class_data["properties"]:
            for member in class_data["properties"][member_vis]:
                if not member["static"]:
                    continue
                mangled_name = get_mangled_member(member,
                                                  class_name_with_namespace)
                if "doxygen" in member:
                    props = get_doxygen_properties(member["doxygen"])
                    if "symbol" in props:
                        mangled_name = props["symbol"]
                m_type = member["type"]
                if m_type.startswith("static "):
                    m_type = m_type[len("static "):]
                output(m_type + " " + class_name_with_namespace + "::" +
                       member["name"] + ";")
                symbol_list.append({
                    "name":
                    class_name_with_namespace + "::" + member["name"],
                    "symbol":
                    mangled_name,
                    "is_legacy":
                    is_legacy
                })

        for method_vis in class_data["methods"]:
            for method in class_data["methods"][method_vis]:
                if method["defined"] or method["pure_virtual"]:
                    continue
                process_method(method, True, is_legacy)
                for inherit in clazz["inherits"]
                if inherit["class"] == "CustomCommandContext"
            )
        ]


if len(sys.argv) != 2:
    debug("%s <filename>" % sys.argv[0])
    exit(1)

filename = sys.argv[1]

try:
    basename: str = os.path.basename(filename)
    debug(" PARSE %s" % filename)
    header = cppheaderparser.CppHeader(filename)
    defined = [
        func
        for func in header.functions
        if func["returns"] == "command_register_function"
        and len(func["parameters"]) == 0
    ]
    if len(defined) != 1:
        debug("Failed to find command_register_function")
        exit(1)
    command_register_function = defined[0]["name"]
    debug(" SCAN dynamic enum")
    dynenums: List[DynEnum] = DynEnum.scan(header)
    debug("\n".join(str(item) for item in dynenums))
    debug(" SCAN enums")
    enums: List[Enum] = Enum.scan(header)