2008-09-08 126 views
2

是否有任何编辑人员对于goto行功能遵守C#line指令?#line并跳转至

语境: 我工作的一个代码生成器,需要跳转到一个线路输出,但该行相对载明的#line指令,我加入。 我可以删除他们,但随后发现输入线甚至更糟糕的疼痛

回答

2

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

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

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

+1

最佳回答日期: – BCS 2008-09-18 22:22:51

0

#line指令通常是通过预编译器插入,不进源代码,所以编辑器通常不会兑现,如果文件扩展名是.c

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

0

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

基本上,这利用了编译器输出 中输出的项目基本上被解析为“PATH(LINENUM):message”的事实。

这假定在微软编译器对“附注提醒”的处理上。

这不完全正是你所问......但它可能通常有帮助 在达到你可以让编译器发出的东西,一些编辑可能会荣幸。

 
    // 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") 

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

0

使用sed或类似的工具将#lines转换为其他未由编译器解释的东西,因此您会在实际行中获得C错误消息,但是会引用附近的原始输入文件。

+0

我是这样做的;为代码生成器添加一个标志以省略#lines和重建 – BCS 2008-09-18 22:22:12