C++ 什么是clang中的无效SourceLocation,以及如何与之交互?

C++ 什么是clang中的无效SourceLocation,以及如何与之交互?,c++,clang,abstract-syntax-tree,C++,Clang,Abstract Syntax Tree,我需要用其他变量声明替换一些变量声明 比如说 inta=5; 变成 ta=5; 更一般 xa=\u const; 变成 ta=\u const; 我试图在叮当声中实现一个后代: bool VisitVarDecl(Decl*f){ 如果(VarDecl*VD=dyn_cast_或_null(f)){ Expr*init=VD->getInit(); SourceRange definition=VD->getDefinition()->getSourceRange(); FullSour

我需要用其他变量声明替换一些变量声明

比如说

inta=5;
变成

ta=5;
更一般

xa=\u const;
变成

ta=\u const;
我试图在叮当声中实现一个后代:

bool VisitVarDecl(Decl*f){
如果(VarDecl*VD=dyn_cast_或_null(f)){
Expr*init=VD->getInit();
SourceRange definition=VD->getDefinition()->getSourceRange();
FullSourceLoc exprLoc=ctx.getFullLoc(init->getLocStart());
FullSourceLoc vLoc=ctx.getFullLoc(VD->getLocStart());
...
我想用下一种方式替换变量的定义:

TheRewriter.ReplaceText(VD->getLocStart(),exprLoc.getSpellingColumnNumber()-vLoc.getSpellingColumnNumber(),someSting);
但任何调用exprLoc.getSpellingColumnNumber()都会导致分段错误。例如,我只是尝试打印exprLoc.getSpellingColumnNumber():


llvm::outs():如果未设置源位置,则该位置无效。是否接受libclang(c接口)中的解决方案?