From 684453ed955daf5bcddff39b9d046db72d1f2a60 Mon Sep 17 00:00:00 2001 From: GRayHook Date: Mon, 21 Apr 2025 17:58:08 +0700 Subject: [PATCH] Init by ChatGPT --- CMakeLists.txt | 9 +++++++++ src/ICounter.hpp | 10 ++++++++++ tools/parse_exported.py | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 src/ICounter.hpp create mode 100644 tools/parse_exported.py diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d4dd7ec --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.12) +project(RemoteAPIExample LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +include_directories(${CMAKE_SOURCE_DIR}/src) + +add_library(dummy STATIC src/ICounter.hpp) diff --git a/src/ICounter.hpp b/src/ICounter.hpp new file mode 100644 index 0000000..ee4b91a --- /dev/null +++ b/src/ICounter.hpp @@ -0,0 +1,10 @@ +#pragma once + +class __attribute__((annotate("export"))) ICounter { +public: + virtual int getval() const = 0; + virtual void inc() = 0; + + void helper(); // не виртуальный — не экспортируем +}; + diff --git a/tools/parse_exported.py b/tools/parse_exported.py new file mode 100644 index 0000000..bf137a6 --- /dev/null +++ b/tools/parse_exported.py @@ -0,0 +1,40 @@ +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()