Libclang API to get function definitions defined in a different file

被刻印的时光 ゝ 提交于 2019-12-06 16:03:12

问题


Suppose I have two files main.c and func.c func.c is called from main.c's main function. Normally, I would generate main.o and func.o and linker would find definition of func and tie it up to it's call in main .c

Now, I want to do same thing through libclang APIs. This is for a Doxygen type code browsing utility I am making. I am able to parse the two files. From here, I don't know how to proceed. Should I generate *.o files and make clang link them?

Thanks, I hope I am clear in asking the question


回答1:


No, there is no need for actually compiling your code to object files.

The link between symbols in both translation units can be established using USR (Unified Symbol Resolution). When you find an interesting place in the AST of a translation unit (represented by a CXCursor in libclang), call clang_getCursorUSR() to get the associated USR.

If two CXCursor have the same USR, even in two different translation units, they are associated to the same symbol.



来源:https://stackoverflow.com/questions/18037538/libclang-api-to-get-function-definitions-defined-in-a-different-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!