简体   繁体   English

Eclipse CDT:不显示宏出现的名称

[英]Eclipse CDT: doesn't show name a macro appears in

When searching for macro references, Eclipse displays file+line the macro is referenced it. 在搜索宏引用时,Eclipse显示文件+行,宏引用它。 I would like to file+line+ function . 我想文件+行+ 功能

Searching for a other type of data (eg function) will display file+line+ function as expected, so maybe something should be tweaked in Eclipse configuration for macros? 搜索其他类型的数据(例如函数)将按预期显示文件+行+ 函数 ,所以也许应该在Eclipse配置中为宏调整某些东西?

Any ideas? 有任何想法吗?

Update - Jan 2017 更新 - 2017年1月

The next release of CDT (CDT 9.3, part of Eclipse Oxygen to be released in June 2017) will have support for showing function containing the macro reference. CDT的下一个版本(CDT 9.3,将于2017年6月发布的Eclipse Oxygen的一部分)将支持显示包含宏引用的函数。 See Bug 508216 for more details. 有关详细信息,请参阅错误508216

The rest of this answer is the original answer. 这个答案的其余部分是原始答案。

TL;DR TL; DR

There is no way in Eclipse CDT to display the function a macro is referenced in because such information is not included in the index when the index is built. Eclipse CDT中没有办法显示引用宏的函数,因为构建索引时索引中不包含此类信息。

Pictures 图片

To ensure that we are talking about the same thing I provide some visuals. 为了确保我们谈论同样的事情,我提供了一些视觉效果。

Given a simplified C file containing functions, macros and globals: 给定一个包含函数,宏和全局变量的简化C文件:

Example Code 示例代码

#define MACRO(X) ((X) + 2)
int function(int);
int global;

int function_results_are_in(void) {
    int i = 0;
    i = MACRO(i);
    i = function(i);
    i += global;
    return i;
}

Doing a search using one of the following methods that uses the C/C++ Index (as opposed to a file/grep style search): 使用以下使用C / C ++索引的方法之一进行搜索(而不是文件/ grep样式搜索):

Setup 建立

  • References in Workspace of selection using one of: 使用以下方法之一在工作区引用选择:
    • Shift + Ctrl + G Shift + Ctrl + G.
    • Right-click -> References -> Workspace 右键单击 - > 引用 - > 工作区
  • Search menu -> C/C++ Search and search for references, like this picture: 搜索菜单 - > C / C ++搜索并搜索参考资料,如下图所示: 在此输入图像描述

Results - Function search 结果 - 功能搜索

As you can see with searches for functions, the result shows the containing function name: 正如您在搜索函数时看到的那样,结果显示包含函数名称:

功能搜索

Results - Macro search 结果 - 宏搜索

But for the macro search, there is no containing function name: 但是对于宏搜索,没有包含函数名称:

宏搜索

Under the hood 在引擎盖下

Each search result in the C/C++ Search results is LineSearchElement.Match . C / C ++搜索结果中的每个搜索结果都是LineSearchElement.Match If its fEnclosingElement is null then there is no function to display. 如果其fEnclosingElementnull ,则无法显示任何函数。

Taking one step back you can see that the match is created from a matching IIndexName . 退后一步,您可以看到匹配是从匹配的IIndexName 创建的 The Match.fEnclosingElement field is filled from the result of IIndexName.getEnclosingDefinition() . Match.fEnclosingElement字段由IIndexName.getEnclosingDefinition()的结果填充。

In the case of a macro reference the concrete type of IIndexName is a PDOMMacroReferenceName , and the implementation of getEnclosingDefinition is simply return null . 在宏引用的情况下, IIndexName的具体类型是PDOMMacroReferenceName ,而getEnclosingDefinition 的实现只是return null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM