是否有编辑器尊重 C #line 指令的 goto line 功能?

语境:我正在开发代码生成器,需要跳转到输出的一行,但该行是相对于我添加的 #line 指令指定的。我可以把它们扔掉,但找到输入线就更痛苦了

有帮助吗?

解决方案

如果编辑器是可编写脚本的,则应该可以编写脚本来进行导航。甚至可能有一个 Vim 或 Emacs 脚本已经做了类似的事情。

FWIW 当我写了很多 Bison/Flexx 时,我写了一个 宙斯 Lua 宏脚本尝试做类似的事情(即通过搜索 #line 标记从输入文件移动到输出文件的相应行)。

对于任何可能感兴趣的人 这是 那个特定的宏脚本。

其他提示

#line 指令通常由预编译器插入,而不是插入源代码中,因此如果文件扩展名是,编辑器通常不会遵守这一点 .c.

但是,后编译文件的正常文件扩展名是 .i 或者 .gch, ,所以你可以尝试使用它,看看会发生什么。

我偶尔在标头文件中使用以下内容,以在VC6和最近的VS(2003+)编译器Ouptut窗口中产生可单击的项目。

基本上,这利用了以下事实:编译器输出中的项目基本上是为“路径(Linenum):信息”。

这假定了 Microsoft 编译器对“pragma Remember”的处理。

这不完全是你问的...但是通常,这可能有助于到达某些东西,您可以让编译器发出一些编辑可能会尊重的东西。

    // The following definitions will allow you to insert
    // clickable items in the output stream of the Microsoft compiler.
    // The error and warning variants will be reported by the
    // IDE as actual warnings and errors... which means you can make
    // them occur in the task list.

    // In theory, the coding standards could be checked to some extent
    // in this way and reminders that show up as warnings or even
    // errors inserted...


    #define strify0(X) #X
    #define strify(X) strify0(X)
    #define remind(S) message(__FILE__ "(" strify( __LINE__ ) ") : " S)

    // example usage
    #pragma remind("warning:  fake warning")
    #pragma remind("error:  fake error")

我有一段时间没有尝试过,但它应该仍然有效。

使用 sed 或类似的工具将 #lines 转换为编译器无法解释的其他内容,这样您就会在实际行上收到 C 错误消息,但会引用附近的原始输入文件。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top