Comments (2)
Something similar to this script, that I used for ScreenPlay:
import clang.cindex
from clang.cindex import CompilationDatabase
from pathlib import Path
def find_methods_with_locations(node, methods, source_file):
"""
Recursively find all the method declarations in the node, capturing their names and start locations,
but only if they are declared in the specified source file.
"""
# Check if the node location is in the main file
if node.location.file and Path(node.location.file.name) == source_file:
if node.kind == clang.cindex.CursorKind.CXX_METHOD:
# Access the extent directly, not via get_extent()
start_location = node.extent.start
methods.append((node.spelling, start_location.line))
for child_node in node.get_children():
find_methods_with_locations(child_node, methods, source_file)
def parse_cpp_methods(file_path: Path, compilation_database_path: str, source_file: Path):
"""
Parse the C++ file using compilation commands from the specified compilation database and return a list of all method names along with their start locations.
"""
# Load the compilation database
compdb = CompilationDatabase.fromDirectory(compilation_database_path)
# Retrieve the compilation commands for the file
compile_commands = compdb.getCompileCommands(str(file_path))
file_args = []
for command in compile_commands:
for argument in command.arguments:
file_args.append(argument)
file_args = file_args[3:-3] # Skip the compiler command itself
# Initialize Clang index and parse the file
index = clang.cindex.Index.create()
translation_unit = index.parse(str(file_path), args=file_args)
methods_with_locations = []
find_methods_with_locations(translation_unit.cursor, methods_with_locations, source_file)
return methods_with_locations
def main():
clang.cindex.Config.set_library_file('C:/Program Files/LLVM/bin/libclang.dll')
file_path = Path("C:/Code/Cpp/ScreenPlay/ScreenPlay/ScreenPlay/src/create.cpp")
# Path to compile_commands.json
compilation_database_path = "C:/Code/Cpp/ScreenPlay/build_ScreenPlay_Clang_Debug"
print(f"Processing File: ", file_path.is_file(), file_path)
methods_with_locations = parse_cpp_methods(file_path.absolute(), compilation_database_path, file_path)
print("Found methods with locations:", methods_with_locations)
main()
from arewemodulesyet.
Now we have https://github.com/ChuanqiXu9/clang-modules-converter
from arewemodulesyet.
Related Issues (17)
- Add tools status page HOT 1
- Should we add a support level to the list?
- Should we also add the import statement for every lib? Aka import ffmpeg; HOT 1
- Flux library has modules support HOT 1
- some more projects provide modules HOT 3
- Remove help wanted on libs that already have modules support
- Add list of code pattern that are hostile to modules HOT 1
- Typos on website HOT 1
- Fix filter by splitting into help wanted and feature support
- Ask for more library metrics at vcpkg like used c++ version and build systems
- Add Zork++ to the build systems HOT 1
- Add progress_overwrite info for Arrow HOT 1
- Add tutorials about using C++ modules HOT 3
- The website may be out of sync HOT 1
- Get rid of progress.yml from the repo
- Meson does not have modules yet HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arewemodulesyet.