【发布时间】:2020-12-03 01:03:37
【问题描述】:
我是 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 visitor 方法,它遍历每个变量声明以执行适当的 lint 检查:
bool VisitVarDecl(VarDecl *node) {
if (isCollectionType(node -> getType()) && !hasTypeArguments(node -> getType())) {
addViolation(node, this, description(node -> getNameAsString()));
}
return true;
}
如何确定宏并跳过此类变量声明?
【问题讨论】: