From 000df8a64b70b7e31f166163b69d35757a3821aa Mon Sep 17 00:00:00 2001 From: GRayHook Date: Mon, 21 Apr 2025 19:54:42 +0700 Subject: [PATCH] fup --- CMakeLists.txt | 4 +++- src/{ICounter.hpp => ICounter.cpp} | 0 tools/parse_exported.py | 39 ++++++++++++++++++++------------------ 3 files changed, 24 insertions(+), 19 deletions(-) rename src/{ICounter.hpp => ICounter.cpp} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4dd7ec..7e3d065 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,4 +6,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) include_directories(${CMAKE_SOURCE_DIR}/src) -add_library(dummy STATIC src/ICounter.hpp) +add_library(dummy STATIC src/ICounter.cpp) + +set_target_properties(dummy PROPERTIES LINKER_LANGUAGE CXX) diff --git a/src/ICounter.hpp b/src/ICounter.cpp similarity index 100% rename from src/ICounter.hpp rename to src/ICounter.cpp diff --git a/tools/parse_exported.py b/tools/parse_exported.py index bf137a6..1bba973 100644 --- a/tools/parse_exported.py +++ b/tools/parse_exported.py @@ -1,40 +1,43 @@ import os import json -from clang.cindex import Index, CursorKind, Config +from clang.cindex import Index, CursorKind -# Укажи путь к libclang, если нужно вручную -# Config.set_library_path("/usr/lib/llvm-17/lib") - -def load_compile_flags(file, compile_commands_path): +def load_compile_flags(compile_commands_path, cpp_stub_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): + if os.path.abspath(entry['file']) == os.path.abspath(cpp_stub_path): 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 [] -def is_exported_class(cursor): - for attr in cursor.get_attributes(): - if attr.spelling == "export": - return True - return False +def has_annotation(cursor, annotation_text): + return any( + c.kind == CursorKind.ANNOTATE_ATTR and annotation_text in c.spelling + for c in cursor.get_children() + ) 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) + cpp_stub_path = os.path.abspath("src/ICounter.cpp") + compile_commands_path = os.path.abspath("build/compile_commands.json") + + args = load_compile_flags(compile_commands_path, cpp_stub_path) + print(args) 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(): - if cursor.kind == CursorKind.CLASS_DECL and is_exported_class(cursor): + for cursor in tu.cursor.walk_preorder(): + if cursor.kind == CursorKind.CLASS_DECL and has_annotation(cursor, "export"): 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()})") + is_virtual = c.is_virtual_method() + print(f" method: {c.spelling} (virtual={is_virtual})") if __name__ == "__main__": main()