我一直在尝试使用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));
}