微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

clang :: ast_matchers :: thisPointerType对重载函数的模棱两可的调用

如何解决clang :: ast_matchers :: thisPointerType对重载函数的模棱两可的调用

我正在从事一个涉及Clang AST匹配器的项目。这就是我正在使用的AST匹配器。

tidyr::complete(df_error,date,company = unique_company,fill = list(value = 0))

我正在使用Microsoft Visual Studio编译器在Windows上编译项目。我检查了一下,匹配器在语法上看起来还不错。但是编译器抱怨。

StatementMatcher getNumUses_matcher1 = binaryOperator(
    hasOperatorName(">"),hasLHS(ignoringParenImpCasts(
        cxxMemberCallExpr(
            thisPointerType(hasDeclaration(cxxRecordDecl(isSameOrDerivedFrom("Value")))),hasDeclaration(cxxMethodDecl(hasName("getNumUses")))
        )
    )),hasRHS(ignoringParenImpCasts(
        integerLiteral(equals(0))
    ))
).bind("type1");

enter image description here

enter image description here

因此,这似乎是编译器语法错误。但这是奇怪的部分。

每当我通过cxxMemberCallExpr term does not evaluate to a function taking 2 arguments thisPointerType more than one instance of overloaded function "thisPointerType" matches the argument list thisPointerType 'clang::ast_matchers::thisPointerType': ambiguous call to overloaded function 运行这个完全相同的ast匹配器时,它就起作用了! clang-query还会检查语法,但是这里没有报告语法错误。它运行ast匹配器,并按预期成功匹配所需的表达式。

clang-query

如果我尝试使用clang-query> match binaryOperator(hasOperatorName(">"),hasLHS(ignoringParenImpCasts(cxxMemberCallExpr(thisPointerType(hasDeclaration(cxxRecordDecl(isSameOrDerivedFrom("Value")))),hasDeclaration(cxxMethodDecl(hasName("getNumUses")))))),hasRHS(ignoringParenImpCasts(integerLiteral(equals(0))))) Match #1: C:\work\sample_example\sample_example.cpp:77:9: note: "root" binds here pGlobalVar->getNumUses() > 0 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ 编译器编译相同的代码

clang++

解决方法

我不确定clang-query为什么接受上述AST匹配器,而clang++和Microsoft Visual Studio cl编译器都将其标记为语法错误。我找到了解决办法。

我重组了AST匹配器。我使用了稍微不同的语法。现在,此代码进行编译,clang-query也接受它,生成与上面的AST匹配器相同的结果。

StatementMatcher getNumUses_matcher1 = binaryOperator(
    hasOperatorName(">"),hasLHS(ignoringParenImpCasts(
        cxxMemberCallExpr(hasDeclaration(cxxMethodDecl(
            hasName("getNumUses"),ofClass(isSameOrDerivedFrom("Value"))
        )))
    )),hasRHS(ignoringParenImpCasts(
        integerLiteral(equals(0))
    ))
).bind("type1");

现在,在这种方法中,我通过将ofClass()应用于cxxMethodDecl()而不是在thisPointerType()上使用cxxMemberCallExpr()来搜索类的名称。

问题可能出在thisPointerType()有两个重载。根据{{​​3}}。

Return type                 Name             Parameters

Matcher<CXXMemberCallExpr>  thisPointerType Matcher<Decl> InnerMatcher

Matcher<CXXMemberCallExpr>  thisPointerType Matcher<QualType> InnerMatcher

但是我对此一无所知。谁能向我解释为什么?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。