in facebook-clang-plugins/libtooling/ASTExporter.h [555:594]
void ASTExporter<ATDWriter>::dumpSourceLocation(SourceLocation Loc) {
const SourceManager &SM = Context.getSourceManager();
SourceLocation ExpLoc =
Options.useMacroExpansionLocation ? SM.getExpansionLoc(Loc) : Loc;
SourceLocation SpellingLoc = SM.getSpellingLoc(ExpLoc);
// The general format we print out is filename:line:col, but we drop pieces
// that haven't changed since the last loc printed.
PresumedLoc PLoc = SM.getPresumedLoc(SpellingLoc);
if (PLoc.isInvalid()) {
ObjectScope Scope(OF, 0);
return;
}
if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) {
ObjectScope Scope(OF, 3);
OF.emitTag("file");
// Normalizing filenames matters because the current directory may change
// during the compilation of large projects.
OF.emitString(Options.normalizeSourcePath(PLoc.getFilename()));
OF.emitTag("line");
OF.emitInteger(PLoc.getLine());
OF.emitTag("column");
OF.emitInteger(PLoc.getColumn());
} else if (PLoc.getLine() != LastLocLine) {
ObjectScope Scope(OF, 2);
OF.emitTag("line");
OF.emitInteger(PLoc.getLine());
OF.emitTag("column");
OF.emitInteger(PLoc.getColumn());
} else {
ObjectScope Scope(OF, 1);
OF.emitTag("column");
OF.emitInteger(PLoc.getColumn());
}
LastLocFilename = PLoc.getFilename();
LastLocLine = PLoc.getLine();
// TODO: lastLocColumn
}