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