[英]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? 有任何想法吗?
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. 这个答案的其余部分是原始答案。
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中没有办法显示引用宏的函数,因为构建索引时索引中不包含此类信息。
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 建立
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: 但是对于宏搜索,没有包含函数名称:
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. 如果其
fEnclosingElement
为null
,则无法显示任何函数。
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.