Init by ChatGPT
commit
684453ed95
@ -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)
|
||||
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
class __attribute__((annotate("export"))) ICounter {
|
||||
public:
|
||||
virtual int getval() const = 0;
|
||||
virtual void inc() = 0;
|
||||
|
||||
void helper(); // не виртуальный — не экспортируем
|
||||
};
|
||||
|
||||
@ -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()
|
||||
Loading…
Reference in New Issue