clang - symbol(variable, function, type, etc..) definition or declaration or reference

老子叫甜甜 提交于 2019-12-11 00:56:49

问题


Please do anyone know if clang has option to return symbol definition or declaration(or reference)?

I mean: there is option for clang executable called -code-completion-at=path_to_file:line:coloumn the clang will look into code and returns you completion strings(ie if there is for example std::string_type_variable. ..it returns to you all the methods and attributes you can call from std::string.

Now what i want is, for clang to return the file and coordinates, where the definition of the symbols starts .. so if it std::string_type_variable - i want to return to me coordinates, where i have writte std::string variable; in the code.

I want to use it in vim instead of cscope/ctags obsolete functionality(tags system using ctags/cscope in vim doesnt know context - its not usable at all in bigger projects) I know there is clang followup(http://blog.wuwon.id.au/2011/10/vim-plugin-for-navigating-c-with.html) but it doesnt work correctly(actually doesnt work for me at all)

Is it even possible? it shouldn't be that hard, if it can return the completion, it probably already knows, where from he read the definition of the variable...


回答1:


Clang provides such functionality by libclang shared library, but there is a simple example on how to use it. If you built clang from source, take a look at c-index-test executable. It's source located in tools/c-index-test.



来源:https://stackoverflow.com/questions/7889053/clang-symbolvariable-function-type-etc-definition-or-declaration-or-ref

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