diff options
Diffstat (limited to 'clang/lib/AST/JSONNodeDumper.cpp')
-rw-r--r-- | clang/lib/AST/JSONNodeDumper.cpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp index 60f3c0f8601..04b933b0fb3 100644 --- a/clang/lib/AST/JSONNodeDumper.cpp +++ b/clang/lib/AST/JSONNodeDumper.cpp @@ -171,20 +171,28 @@ void JSONNodeDumper::Visit(const GenericSelectionExpr::ConstAssociation &A) { attributeOnlyIfTrue("selected", A.isSelected()); } -void JSONNodeDumper::writeBareSourceLocation(SourceLocation Loc) { +void JSONNodeDumper::writeBareSourceLocation(SourceLocation Loc, + bool IsSpelling) { PresumedLoc Presumed = SM.getPresumedLoc(Loc); - + unsigned ActualLine = IsSpelling ? SM.getSpellingLineNumber(Loc) + : SM.getExpansionLineNumber(Loc); if (Presumed.isValid()) { if (LastLocFilename != Presumed.getFilename()) { JOS.attribute("file", Presumed.getFilename()); - JOS.attribute("line", Presumed.getLine()); - } else if (LastLocLine != Presumed.getLine()) - JOS.attribute("line", Presumed.getLine()); + JOS.attribute("line", ActualLine); + } else if (LastLocLine != ActualLine) + JOS.attribute("line", ActualLine); + + unsigned PresumedLine = Presumed.getLine(); + if (ActualLine != PresumedLine && LastLocPresumedLine != PresumedLine) + JOS.attribute("presumedLine", PresumedLine); + JOS.attribute("col", Presumed.getColumn()); JOS.attribute("tokLen", Lexer::MeasureTokenLength(Loc, SM, Ctx.getLangOpts())); LastLocFilename = Presumed.getFilename(); - LastLocLine = Presumed.getLine(); + LastLocPresumedLine = PresumedLine; + LastLocLine = ActualLine; } } @@ -195,17 +203,18 @@ void JSONNodeDumper::writeSourceLocation(SourceLocation Loc) { if (Expansion != Spelling) { // If the expansion and the spelling are different, output subobjects // describing both locations. - JOS.attributeObject( - "spellingLoc", [Spelling, this] { writeBareSourceLocation(Spelling); }); + JOS.attributeObject("spellingLoc", [Spelling, this] { + writeBareSourceLocation(Spelling, /*IsSpelling*/ true); + }); JOS.attributeObject("expansionLoc", [Expansion, Loc, this] { - writeBareSourceLocation(Expansion); + writeBareSourceLocation(Expansion, /*IsSpelling*/ false); // If there is a macro expansion, add extra information if the interesting // bit is the macro arg expansion. if (SM.isMacroArgExpansion(Loc)) JOS.attribute("isMacroArgExpansion", true); }); } else - writeBareSourceLocation(Spelling); + writeBareSourceLocation(Spelling, /*IsSpelling*/ true); } void JSONNodeDumper::writeSourceRange(SourceRange R) { |