[cfe-dev] Libclang. Cross-referencing translation units with Unified Symbol Resolution USR.
Juan Jose Lopez Villarejo
jj.lopezvillarejo at cern.ch
Wed Jan 8 00:51:59 PST 2014
Hello,
I have spent the last months in developing a documentation tool based on lib clang & its python bindings, which can generate activity diagrams from annotated C++ code. It works for a single translation unit, which in my case is a single .cpp source file (e.g., ‘main.cpp’). Now I would like to make this tool work properly for a code consisting of several source files.
Statement of the issue
==========
In this tool, calls to functions (or class methods) can be displayed on the generated diagrams, and a hyperlink allows access to the diagram for the called function from the ‘caller diagram’.
>From the call_node, I can get the function_node (inside the same translation unit) with a simple
call_node.get_definition()
(this is with the python bindings to libclang). The call_node does not have an associated Unified Symbol Resultion USR, while the associated function_node does:
call_node.get_usr() —> displays ‘’, nothing
call_node.get_definition().get_usr() —> displays ‘function’s USR’
The problem comes when there is a call from a given source file to a function (method) that is defined in another source file. In that case,
call_node.get_definition() —> None
So, I have no way to establish a (hyper)link between the caller and the callee.
Attempts of resolution
============
I have tried to put several translation units into the libclang index, with:
index = clang.cindex.Index.create()
args=["-c","-x","c++","-Wall","-ansi","-I./include"]
tu_aux1=index.parse("./include/t.h",args, None, 2)
tu_aux2=index.parse("./src/t.cpp",args)
tu = index.parse("./simple_demo_src.cpp",args)
find_functions(tu.cursor)
In this example, the file being explored is ‘simple_demo_src.cpp’. Some of the functions that are called from ‘simple_demo_src.cpp’ are defined in "./include/t.h" and "./src/t.cpp ».
I get the same behavior as explained before:
call_node.get_definition() —> None
Any Ideas?
===========
(not preferred solution might involve combining all source files into a single one. How?)
Your ideas will be greatly appreciated. I’m hoping to contribute this tool to the community.
Regards,
Juan Lopez-Villarejo
More information about the cfe-dev
mailing list