我是 C++ 的初学者,试图用 clang 对 Objective-C 代码进行 lint。我知道在使用 AST 访问节点和属性之前首先扩展宏。
我有一个名为 的宏NIL_CHECK
,用于许多文件。在执行 lint 时,我想跳过扩展/使用此宏的行的变量声明。
例如,这个例子中的第一行应该被 linted,而第二行需要被跳过,这样当有一个宏扩展时就不会抛出误报:
// Must be checked
NSDictionary *playerParams = @{ @"videoId" : videoId, @"playerVars" : playerVars };
// Must be skipped since there's a macro
PlayerProfile *const playerProfile = [[PlayerProfile alloc] initWithData:NIL_CHECK(playerParams)];
这是VisitVarDecl
访问者方法,它遍历每个变量声明以执行适当的 lint 检查:
bool VisitVarDecl(VarDecl *node) {
if (isCollectionType(node -> getType()) && !hasTypeArguments(node -> getType())) {
addViolation(node, this, description(node -> getNameAsString()));
}
return true;
}
如何确定宏并跳过此类变量声明?