Coverage for src/rejuvenation/walk_compilation_database.py: 0%
16 statements
« prev ^ index » next coverage.py v7.17.0, created at 2026-11-16 16:04 +0000
« prev ^ index » next coverage.py v7.17.0, created at 2026-11-16 16:04 +0000
1# Copyright (C) 2024-2026 TNO
2#
3# Licensed under the terms specified in the LICENSE file in the root directory
4# of this repository, also available at:
5# https://github.com/TNO/Renaissance.Py/blob/main/LICENSE
7"""AI: Example script demonstrating loading and walking a Clang compilation database."""
9# use clang to load and walk a compilation database
11from pathlib import Path
13import targets
14from renaissance.integrations.clang import ClangASTNode, CompilationDatabase
15from renaissance.integrations.clang.clang_json_ast_node import ClangJsonASTNode
16from renaissance.syntax_tree import ASTProcessor, ASTShower
17from renaissance.syntax_tree.semantic_kind import SemanticKind
20def main(args) -> None:
21 """AI: Walk the compilation database given in `args` for each Clang integration and show its AST."""
22 # the first argument is the code to be parsed
23 database = args[0] if len(args) > 0 else ""
24 for impl_type in [ClangASTNode, ClangJsonASTNode]:
25 # load the compilation database by specifying the path to the folder
26 # and the implementation type
27 db = CompilationDatabase.walk(impl_type, Path(database))
28 for factory, atu in db:
29 # show atu
30 ASTShower.show_node(atu, include_properties=True)
31 # do something with the factory and atu
32 ast_refactor = ASTProcessor(atu, factory, in_memory=True)
33 [print(n.text) for n in ast_refactor.find_semantic_kind(SemanticKind.FUNCTION)]
36if __name__ == "__main__":
37 # fill in your own path
38 main([targets.__file__.replace("__init__.py", "compile_commands.json")])