ctags 忽略 libc6、libstdc++ 的列表并提升

发布于 2024-10-31 18:53:37 字数 1475 浏览 1 评论 0原文

我将 ctags 与 vim 和 OmniCppComplete 插件一起使用。目前,在生成标签时,我为每个库单独生成标签。对于 libc6,我在名为 libc6-ignore 的文件中使用以下标记/宏列表来在处理过程中忽略:

__attribute__
__attribute_deprecated__
__attribute_format_arg__
__attribute_format_strfmon__
__attribute_malloc__
__attribute_noinline__
__attribute_pure__
__attribute_used__
__attribute_warn_unused_result__
__wur
__THROW
__nonnull+

我是否缺少任何其他我应该忽略的标记,以及在为 libstdc++ 生成标记时应该使用相同的列表还是不同的列表和提升?

对于任何感兴趣的人,我使用以下内容来生成我的标签文件:

# First make sure apt-file is install and then do:

$ sudo apt-file update

# set up tags for libc, the standard C library

$ apt-file list libc6-dev | grep -o '/usr/include/.*\.h'> ~/.vim/tags/libc6-filelist
$ ctags --sort=foldcase --c++-kinds=+p --fields=+iaS --extra=+q -I./libc6-ignore -f ~/.vim/tags/libc6 -L ~/.vim/tags/libc6-filelist 

# create tags for stdlibc++ and STL

$ apt-file list libstdc++6-4.4-dev | grep -E -o '/usr/include/.*\.(h|hpp)' > ~/.vim/tags/stdlibcpp-filelist
$ ctags --sort=foldcase -R --c++-kinds=+p --fields=+iaS --extra=+q -f ~/.vim/tags/stdlibcpp -L ~/.vim/tags/stdlibcpp-filelist

# For Boost

$ apt-file list boost | grep -E -o '/usr/include/.*\.(h|hpp)' | grep -v '/usr/include/boost/typeof/' > ~/.vim/tags/boost-filelist
$ ctags --sort=foldcase --c++-kinds=+p --fields=+iaS --extra=+q -f ~/.vim/tags/boost -L ~/.vim/tags/boost-filelist 

I use ctags with vim and the OmniCppComplete plugin. Currently when generating my tags I do it individually for each library. For libc6 I use the following list of tokens / macros in a file named libc6-ignore to ignore during processing:

__attribute__
__attribute_deprecated__
__attribute_format_arg__
__attribute_format_strfmon__
__attribute_malloc__
__attribute_noinline__
__attribute_pure__
__attribute_used__
__attribute_warn_unused_result__
__wur
__THROW
__nonnull+

Am I missing any other tokens I should be ignoring and should I be using this same list or a different one when generating tags for libstdc++ and boost?

For anyone who's interested I use the following to generate my tag files:

# First make sure apt-file is install and then do:

$ sudo apt-file update

# set up tags for libc, the standard C library

$ apt-file list libc6-dev | grep -o '/usr/include/.*\.h'> ~/.vim/tags/libc6-filelist
$ ctags --sort=foldcase --c++-kinds=+p --fields=+iaS --extra=+q -I./libc6-ignore -f ~/.vim/tags/libc6 -L ~/.vim/tags/libc6-filelist 

# create tags for stdlibc++ and STL

$ apt-file list libstdc++6-4.4-dev | grep -E -o '/usr/include/.*\.(h|hpp)' > ~/.vim/tags/stdlibcpp-filelist
$ ctags --sort=foldcase -R --c++-kinds=+p --fields=+iaS --extra=+q -f ~/.vim/tags/stdlibcpp -L ~/.vim/tags/stdlibcpp-filelist

# For Boost

$ apt-file list boost | grep -E -o '/usr/include/.*\.(h|hpp)' | grep -v '/usr/include/boost/typeof/' > ~/.vim/tags/boost-filelist
$ ctags --sort=foldcase --c++-kinds=+p --fields=+iaS --extra=+q -f ~/.vim/tags/boost -L ~/.vim/tags/boost-filelist 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

只为一人 2024-11-07 18:53:37

您还可以使用修改后的 libstdc++ 库:

http://www.vim.org/scripts/script.php?script_id=2358" rel="nofollow">http:// /www.vim.org/scripts/script.php?script_id=2358

这包含适用于 ctags 的 C++ 头文件的精简版本。

我制作了一个 Python 脚本,用于提取所有内容标签文件中以下划线开头的标签。您可以使用此脚本选择要排除的标签。
请随意定制脚本以满足您的需求或提出其他建议:

import re

tags=open('tags','r')
output=open('exclude','w')
regex=re.compile('^_[a-zA-Z0-9_]*')
results=set()

for line in tags:
    result=regex.match(line)
    if(result!=None):
        results.add(result.group(0))

tags.close()

for element in sorted(results):
    output.write('{0}\n'.format(element))

output.close()

You can also use the modified libstdc++ library:

http://www.vim.org/scripts/script.php?script_id=2358

This contains a stripped version of the C++ header files which works for ctags.

I made a Python script that extracts all tags beginning with an underscore from a tags file. You can choose with this script which tags to exclude.
Feel free to tailor the script to meet your needs or suggest anything else:

import re

tags=open('tags','r')
output=open('exclude','w')
regex=re.compile('^_[a-zA-Z0-9_]*')
results=set()

for line in tags:
    result=regex.match(line)
    if(result!=None):
        results.add(result.group(0))

tags.close()

for element in sorted(results):
    output.write('{0}\n'.format(element))

output.close()
梦里兽 2024-11-07 18:53:37

我已按照这些说明进行操作,并且我能够使所有 boost boost 参考工作,即

#include <iostream>

我可以直接跳转到 iostream

但是我仍然缺少的是转到例如

#include <stdio.h>

虽然在我的生成脚本中我已包含如您所提到的即

$ apt-file list libc6-dev | grep -o '/usr/include/.*\.h'> ~/.vim/tags/libc6-filelist
$ ctags --sort=foldcase --c++-kinds=+p --fields=+iaS --extra=+q -I./libc6-ignore -f ~/.vim/tags/libc6 -L ~/.vim/tags/libc6-filelist 

在我生成之后每当我尝试访问 stdio.h 时,标签“libc6”文件都会显示“E426:未找到标签:stdlib”。

以下是我添加到 .vimrc 中的内容,以便使所有这 3 个标记文件可见。

set tags+=~/.vim/tags/boost
set tags+=~/.vim/tags/libc6
set tags+=~/.vim/tags/stdlibcpp

我不是专家,但我可以说这对 boost 有效,但对 libc6-dev 无效。有人可以帮我解决这个问题吗?

这里的代码与上面的

sudo apt-file update相同

# set up tags for libc, the standard C library

apt-file list libc6-dev | grep -o '/usr/include/.*\.h'> ~/.vim/tags/libc6-filelist
ctags --sort=foldcase --c++-kinds=+p --fields=+iaS --extra=+q -I./libc6-ignore -f ~/.vim/tags/libc6 -L ~/.vim/tags/libc6-filelist

apt-file list libstdc++6-4.6-dev | grep -E -o '/usr/include/.*\.(h|hpp)' >> ~/.vim/tags/stdlibcpp-filelist
ctags --sort=foldcase -R --c++-kinds=+p --fields=+iaS --extra=+q -f ~/.vim/tags/stdlibcpp -L ~/.vim/tags/stdlibcpp-filelist

# For Boost
apt-file list boost | grep -E -o '/usr/include/.*\.(h|hpp)' | grep -v '/usr/include/boost/typeof/' > ~/.vim/tags/boost-filelist
ctags --sort=foldcase --c++-kinds=+p --fields=+iaS --extra=+q -f ~/.vim/tags/boost -L ~/.vim/tags/boost-filelist

I have followed those instructions and I am able to get all boost boost references working i.e.

#include <iostream>

I can jump directly to iostream

However what I am still missing is to go to for example

#include <stdio.h>

Although in my generate script I have included as you mentioned i.e.

$ apt-file list libc6-dev | grep -o '/usr/include/.*\.h'> ~/.vim/tags/libc6-filelist
$ ctags --sort=foldcase --c++-kinds=+p --fields=+iaS --extra=+q -I./libc6-ignore -f ~/.vim/tags/libc6 -L ~/.vim/tags/libc6-filelist 

After i generate the tag "libc6" file whenever I try to go to stdio.h it is saying “E426: tag not found: stdlib”.

Here is what I have included additionally to my .vimrc in order to make all those 3 tag files visible.

set tags+=~/.vim/tags/boost
set tags+=~/.vim/tags/libc6
set tags+=~/.vim/tags/stdlibcpp

I am not an expert however I can say that this worked somehow for boost but not for libc6-dev. Can someone assist me with the solution

here is the same code as above

sudo apt-file update

# set up tags for libc, the standard C library

apt-file list libc6-dev | grep -o '/usr/include/.*\.h'> ~/.vim/tags/libc6-filelist
ctags --sort=foldcase --c++-kinds=+p --fields=+iaS --extra=+q -I./libc6-ignore -f ~/.vim/tags/libc6 -L ~/.vim/tags/libc6-filelist

apt-file list libstdc++6-4.6-dev | grep -E -o '/usr/include/.*\.(h|hpp)' >> ~/.vim/tags/stdlibcpp-filelist
ctags --sort=foldcase -R --c++-kinds=+p --fields=+iaS --extra=+q -f ~/.vim/tags/stdlibcpp -L ~/.vim/tags/stdlibcpp-filelist

# For Boost
apt-file list boost | grep -E -o '/usr/include/.*\.(h|hpp)' | grep -v '/usr/include/boost/typeof/' > ~/.vim/tags/boost-filelist
ctags --sort=foldcase --c++-kinds=+p --fields=+iaS --extra=+q -f ~/.vim/tags/boost -L ~/.vim/tags/boost-filelist
预谋 2024-11-07 18:53:37

抱歉——我以前从未使用过 ctags——但我会尝试一下这个问题。

如果我理解正确的话,您可以使用 GCC 本身的关键字列表。我在 gcc/gcc/c 中找到了这个 https://gist.github.com/959484 -family/c-common.c。看起来它包含所有 C(c/c++/obj-c 变体)的保留字。我想有些对所有编译器都有效,当然这些是针对 gcc 的。

至于找出要忽略的其他符号,在 OS X 上我会使用 nm 转储相关库的符号,并将所有标记为私有的符号(例如“s”而不是“S”)添加到我的符号列表中忽略。 Linux 有类似的库转储工具吗?

希望这有用。

Sorry--I've never used ctags before--but I'll take a stab at this question.

If I understand correctly, you can use the list of keywords from GCC itself. I found this https://gist.github.com/959484 inside gcc/gcc/c-family/c-common.c. Looks like it includes reserved words for all the C (c/c++/obj-c variants). I guess some are valid for all compilers, these are for gcc of course.

As for figuring out other symbols to ignore, on OS X I'd use nm to dump the symbols of the library in question an add all symbols marked as private ('s' instead of 'S' for example) to my list of symbols to ignore. Linux has a similar library-dumping tool?

Hope that's useful.

阳光的暖冬 2024-11-07 18:53:37

我有自己的清单,但从未想过添加您已经列出的内容!

这是我提出的 libc6 的更新忽略列表(Ubuntu 14.04 和 GCC 4.8.4),用作 ctags 的 -I 选项的输入:

__attribute__
__attribute_deprecated__
__attribute_format_arg__+
__attribute_format_strfmon__+
__attribute_malloc__
__attribute_noinline__
__attribute_pure__
__attribute_used__
__attribute_warn_unused_result__
__attribute_alloc_size__+
__attribute_const__
__attribute_artificial__
__wur
__THROW
__THROWNL
__BEGIN_DECLS
__END_DECLS
__BEGIN_NAMESPACE_STD
__END_NAMESPACE_STD
__USING_NAMESPACE_STD+
__BEGIN_NAMESPACE_C99
__END_NAMESPACE_C99
__USING_NAMESPACE_C99+
__warndecl+
__warnattr+
__errordecl+
__flexarr=[]
__fortify_function
__REDICRECT+
__REDIRECT_NTH+
__REDIRECT_NTHNL+
__ASMNAME+
__ASMNAME2+
__nonnull+
__always_inline
__extern_inline=extern
__extern_always_inline=extern
__extension__
__restrict
__restrict_arr

我还创建了以下忽略列表,用于生成 libstdc++ 的标签文件( Ubuntu 14.04 上的 GCC 4.8.2)(同样,这是 -I 选项的输入):

_GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_END_NAMESPACE_VERSION
_GLIBCXX_BEGIN_NAMESPACE_ALGO
_GLIBCXX_END_NAMESPACE_ALGO
_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_GLIBCXX_END_NAMESPACE_CONTAINER
_GLIBCXX_BEGIN_EXTERN_C
_GLIBCXX_END_EXTERN_C
_GLIBCXX_VISIBILITY+
_GLIBCXX_PURE
_GLIBCXX_CONST
_GLIBCXX_NORETURN
_GLIBCXX_CONSTEXPR=constexpr
_GLIBCXX_USE_CONSTEXPR=constexpr
_GLIBCXX_THROW_OR_ABORT+
_GLIBCXX_NOEXCEPT
_GLIBCXX_USE_NOEXCEPT
_GLIBCXX_THROW+
_GLIBCXX_NOTHROW

我将 __attribute__ 更改为:__attribute__+ 以指示它看起来像一个函数并且应该被忽略。

当然,我也为 Boost 创建了一个,但我想在有人需要之前我不会发布它。

I had my own list and never thought about adding what you've already listed!

Here's that updated ignore list for libc6 that I've come up with (Ubuntu 14.04 and GCC 4.8.4) to use as input to the -I option of ctags:

__attribute__
__attribute_deprecated__
__attribute_format_arg__+
__attribute_format_strfmon__+
__attribute_malloc__
__attribute_noinline__
__attribute_pure__
__attribute_used__
__attribute_warn_unused_result__
__attribute_alloc_size__+
__attribute_const__
__attribute_artificial__
__wur
__THROW
__THROWNL
__BEGIN_DECLS
__END_DECLS
__BEGIN_NAMESPACE_STD
__END_NAMESPACE_STD
__USING_NAMESPACE_STD+
__BEGIN_NAMESPACE_C99
__END_NAMESPACE_C99
__USING_NAMESPACE_C99+
__warndecl+
__warnattr+
__errordecl+
__flexarr=[]
__fortify_function
__REDICRECT+
__REDIRECT_NTH+
__REDIRECT_NTHNL+
__ASMNAME+
__ASMNAME2+
__nonnull+
__always_inline
__extern_inline=extern
__extern_always_inline=extern
__extension__
__restrict
__restrict_arr

I also created the following ignore list for generating a tags file for libstdc++ (GCC 4.8.2 on Ubuntu 14.04) (again, this is input to the -I option):

_GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_END_NAMESPACE_VERSION
_GLIBCXX_BEGIN_NAMESPACE_ALGO
_GLIBCXX_END_NAMESPACE_ALGO
_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_GLIBCXX_END_NAMESPACE_CONTAINER
_GLIBCXX_BEGIN_EXTERN_C
_GLIBCXX_END_EXTERN_C
_GLIBCXX_VISIBILITY+
_GLIBCXX_PURE
_GLIBCXX_CONST
_GLIBCXX_NORETURN
_GLIBCXX_CONSTEXPR=constexpr
_GLIBCXX_USE_CONSTEXPR=constexpr
_GLIBCXX_THROW_OR_ABORT+
_GLIBCXX_NOEXCEPT
_GLIBCXX_USE_NOEXCEPT
_GLIBCXX_THROW+
_GLIBCXX_NOTHROW

I changed __attribute__ to be: __attribute__+ to indicate it looks like a function and should be ignored.

Of course, I have created one for Boost as well, but I think I'll refrain from posting it until someone has a need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文