Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在clang tidy中从CStyleCastExpr matcher获取宏名?_C++_Macros_Clang_Llvm_Clang Tidy - Fatal编程技术网

C++ 如何在clang tidy中从CStyleCastExpr matcher获取宏名?

C++ 如何在clang tidy中从CStyleCastExpr matcher获取宏名?,c++,macros,clang,llvm,clang-tidy,C++,Macros,Clang,Llvm,Clang Tidy,我使用了一段时间的叮当声整理,并创建了一些自己的检查。但现在我陷入了这个问题。我有一个cstyle cast表达式,我想从中获得一个宏名称作为字符串 #define H_KEY 5; float *a; a = (float *)H_KEY; // I want to print out "H_KEY" from this expression 所以我注册了一个像这样的匹配者 void PointersCastCheck::registerMatchers(MatchFinder *Fi

我使用了一段时间的叮当声整理,并创建了一些自己的检查。但现在我陷入了这个问题。我有一个cstyle cast表达式,我想从中获得一个宏名称作为字符串

#define H_KEY 5;
float *a;   
a = (float *)H_KEY; // I want to print out "H_KEY" from this expression
所以我注册了一个像这样的匹配者

void PointersCastCheck::registerMatchers(MatchFinder *Finder) {
    Finder->addMatcher(cStyleCastExpr().bind("cStyleCastExpr"), this);
}
我能够捕捉到每一个cstyle演员,并从中获得一个这样的子表达式

const Expr * subExpr = cStyleCast->getSubExpr();
if (subExpr->getExprLoc().isMacroID()) {
                SourceManager &SM = *Result.SourceManager;
                LangOptions LangOpts = getLangOpts();
                StringRef subExprText = Lexer::getSourceText(CharSourceRange::getTokenRange(subExpr->getSourceRange()), SM, LangOpts);}
现在,叮当声告诉我,我有“int”类型的子表达式,这是正确的,但我不知道如何得到它的名称

我尝试的是动态强制转换为DeclRefExpr,但没有通过。还尝试了动态转换到内置类型,然后我想得到一个声明,但没有运气

所以请帮忙。我认为这应该不难


谢谢大家!

如果有人卷入这个问题,我会这样解决

const Expr * subExpr = cStyleCast->getSubExpr();
if (subExpr->getExprLoc().isMacroID()) {
                SourceManager &SM = *Result.SourceManager;
                LangOptions LangOpts = getLangOpts();
                StringRef subExprText = Lexer::getSourceText(CharSourceRange::getTokenRange(subExpr->getSourceRange()), SM, LangOpts);}
也许有更好的方法,但这一个适合我的需要