如何检测包含宏的C程序

时间:2014-05-10 20:33:36

标签: macros clang instrumentation

我正在尝试检测C程序中的所有if语句。例如

if(condition)
   statement1;
else
   statement2;

装备

if(condition)
{
   statement1;
}
else
{
   statement2;
}

我有以下用于检测的代码

void MyRecursiveASTVisitor::InstrumentStmt(Stmt *s)
{
    // Only perform if statement is not compound
    SourceLocation ST = s->getLocStart();
    if (!isa<CompoundStmt>(s)) {
        //insert an opening brace if not present
        Rewrite.InsertText(ST, "{\n", true, true);
        ST = s->getLocEnd();
        ST = ST.getLocWithOffset(1);
        Rewrite.InsertText(ST, "\n}\n", true, true);
    }
    return true;
}

这几乎适用于所有情况。但是,在声明是MACRO扩展的情况下

else
    WARN((stderr,"%s: %s is a directory -- ignored\n", progname, ifname));

我得到断言失败

Assertion `0 && "Invalid SLocOffset or bad function choice"' failed.

任何人都可以解释为什么会这样吗?在clang中处理宏有什么特殊情况吗?

0 个答案:

没有答案
相关问题