如何在clang AST中获取函数的结果类型的SourceLocation

时间:2014-02-26 19:57:39

标签: clang

我一直在尝试使用libtooling来重命名源代码中的类,并且遇到了函数返回的问题:似乎没有一个API来获取返回类型的源范围。

我可以通过假设返回类型在函数id之前来破解它,但这不能处理C ++ 11中的尾随返回类型。 有人有更好的建议吗?

谢谢!

// simplified example replacing only value type returns
virtual void run(const ast_matchers::MatchFinder::MatchResult& Result) {
    SourceManager& src = *result_.SourceManager;
    const FunctionDecl* const function =
        result_.Nodes.getDeclAs<FunctionDecl>("function");

    CharSourceRange range = Lexer::makeFileCharRange(
        CharSourceRange::getTokenRange(function->getLocStart(), 
        function->getLocation.getLocWithOffset(-1)),
        src, LangOptions());
    _replace->insert(Replacement(src, range, "newClass));
}

0 个答案:

没有答案