我对CLang和Libtooling相对较新。我想在终端上显示源代码中的一行。我在 RecursiveASTVisitor 中有一个* VisitFunctionDecl(FunctionDecl func)。对于每个函数,我都会获得 SourceRange 以及 SourceLocation 。但我不明白如何显示它。我有事可做
答案 0 :(得分:0)
您需要FullSourceLoc:
FullSourceLoc functionDeclFullLocation = Context->getFullLoc(func.getLocStart());
if (functionDeclFullLocation.isValid())
llvm::outs() << "Found FunctionDecl at "
<< functionDeclFullLocation.getManager().getFilename(functionDeclFullLocation) << ":"
<< functionDeclFullLocation.getSpellingLineNumber() << ":"
<< functionDeclFullLocation.getSpellingColumnNumber() << "\n";