You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.4 KiB
Python

import os
import json
from clang.cindex import Index, CursorKind, Config
# Укажи путь к libclang, если нужно вручную
# Config.set_library_path("/usr/lib/llvm-17/lib")
def load_compile_flags(file, compile_commands_path):
with open(compile_commands_path) as f:
compile_commands = json.load(f)
for entry in compile_commands:
if os.path.abspath(entry['file']) == os.path.abspath(file):
cmd = entry['arguments'] if 'arguments' in entry else entry['command'].split()
return [arg for arg in cmd if not arg.endswith('g++') and not arg.endswith('clang++')]
return []
def is_exported_class(cursor):
for attr in cursor.get_attributes():
if attr.spelling == "export":
return True
return False
def main():
file = os.path.abspath("src/ICounter.hpp")
compile_commands = os.path.abspath("build/compile_commands.json")
args = load_compile_flags(file, compile_commands)
index = Index.create()
tu = index.parse(file, args=args)
for cursor in tu.cursor.get_children():
if cursor.kind == CursorKind.CLASS_DECL and is_exported_class(cursor):
print(f"Found exported class: {cursor.spelling}")
for c in cursor.get_children():
if c.kind == CursorKind.CXX_METHOD:
print(f" method: {c.spelling} (virtual={c.is_virtual_method()})")
if __name__ == "__main__":
main()