本文介绍了由于#ifdef,ctags在源文件上用不平衡的括号阻塞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ctags为正在处理的C项目生成tags文件,但是文件中缺少许多功能.这似乎是由于使用#ifdef而导致源文件中的花括号不平衡所致.一个(简化的)示例:

I am using ctags to generate a tags file for a C project I am working on, but many functions are missing in the file. This appears to be caused by unbalanced braces in the source files due to using #ifdef. A (simplified) example:

#include <stdio.h>

struct mystruct {
        long member;
#ifndef _MSC_VER
}__attribute__ ((packed));
#else /* _MSC_VER */
};
#pragma pack(pop)
#endif /* _MSC_VER */

char* greeting_text(){
  return "Hello world\n";
}

int main( int argc, const char* argv[] ){
  char * greeting = greeting_text();
  printf(greeting);
  return 0;
}

它可以在Linux下的gcc -Wall编译并完美地工作.但是,如果我使用ctags problem.c进行解析,则tags文件仅包含mystruct的条目-函数会丢失.

This compiles and works flawlessly with gcc -Wall under Linux. However, if I parse it using ctags problem.c, the tags file only contains entries for mystruct -- the functions are missing.

ctags --verbose报告:

OPENING problem.c as C language file
problem.c: unexpected closing brace at line 8
problem.c: retrying file with fallback brace matching algorithm
OPENING problem.c as C language file
problem.c: unexpected closing brace at line 8

因此,显然ctags不喜欢文件中的预处理器技巧.

so apparently ctags does not like the preprocessor tricks in the file.

有没有办法让ctags处理这个问题?

Is there a way to make ctags handle this?

ctags的联机帮助页甚至明确提到了此问题,但表示ctags可以解决此问题.但是,这似乎不起作用...

The manpage of ctags even explicitly mentions this problem, but indicates ctags can work around this. However, this does not appear to work...

这是带有旺盛Ctags 5.8的(Debian软件包1:5.8-4).

This is with Exuberant Ctags 5.8 (Debian package 1:5.8-4).

我也对处理此类构造的ctags的替代品感兴趣.

I'm also interested in alternatives to ctags that handle these kinds of constructs.

推荐答案

由于ctags的问题,我最终使用了 cscope .

Because of the problems with ctags, I ended up using cscope instead.

虽然它并不完美,但是它比ctags处理宏更好,并且可以像ctags一样与vim集成(请参见 http://vimdoc.sourceforge.net/htmldoc/if_cscop.html#:cscope ).

While it's not perfect, it handles macros better than ctags, and it can integrate with vim just like ctags can (see http://vimdoc.sourceforge.net/htmldoc/if_cscop.html#:cscope ).

这篇关于由于#ifdef,ctags在源文件上用不平衡的括号阻塞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-17 00:04