我对CLang和Libtooling还是比较陌生。我想在终端上显示源代码中的行。我在RecursiveASTVisitor中有一个* VisitFunctionDecl(FunctionDecl func)。对于每个函数,我都会获取SourceRange并从该SourceLocation中获取。但我不知道如何显示。我有事要做
最佳答案
您需要FullSourceLoc:
FullSourceLoc functionDeclFullLocation = Context->getFullLoc(func.getLocStart());
if (functionDeclFullLocation.isValid())
llvm::outs() << "Found FunctionDecl at "
<< functionDeclFullLocation.getManager().getFilename(functionDeclFullLocation) << ":"
<< functionDeclFullLocation.getSpellingLineNumber() << ":"
<< functionDeclFullLocation.getSpellingColumnNumber() << "\n";
关于c++ - 如何使用Clang Libtooling在终端上打印行?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31267516/