diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2019-10-15 17:30:19 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2019-10-15 17:30:19 +0000 |
commit | 27c7a9b157555e53fb3887e87a492f74fa8bcc56 (patch) | |
tree | 1136454856d43e17a301a1b62a6aa1bc1cc7aaa9 /clang/lib/AST/JSONNodeDumper.cpp | |
parent | 3de89f3416bfa78079136ea6566c8f82b1b64292 (diff) | |
download | bcm5719-llvm-27c7a9b157555e53fb3887e87a492f74fa8bcc56.tar.gz bcm5719-llvm-27c7a9b157555e53fb3887e87a492f74fa8bcc56.zip |
Add more information to JSON AST dumping of source locations.
This adds information about the offset within the source file to the given source location as well as information about the include file a location is from. These pieces of information allow for more efficient post-processing of JSON AST dumps.
llvm-svn: 374921
Diffstat (limited to 'clang/lib/AST/JSONNodeDumper.cpp')
-rw-r--r-- | clang/lib/AST/JSONNodeDumper.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp index 2f76a176672..f60d761c996 100644 --- a/clang/lib/AST/JSONNodeDumper.cpp +++ b/clang/lib/AST/JSONNodeDumper.cpp @@ -180,12 +180,30 @@ void JSONNodeDumper::Visit(const GenericSelectionExpr::ConstAssociation &A) { attributeOnlyIfTrue("selected", A.isSelected()); } +void JSONNodeDumper::writeIncludeStack(PresumedLoc Loc, bool JustFirst) { + if (Loc.isInvalid()) + return; + + JOS.attributeBegin("includedFrom"); + JOS.objectBegin(); + + if (!JustFirst) { + // Walk the stack recursively, then print out the presumed location. + writeIncludeStack(SM.getPresumedLoc(Loc.getIncludeLoc())); + } + + JOS.attribute("file", Loc.getFilename()); + JOS.objectEnd(); + JOS.attributeEnd(); +} + void JSONNodeDumper::writeBareSourceLocation(SourceLocation Loc, bool IsSpelling) { PresumedLoc Presumed = SM.getPresumedLoc(Loc); unsigned ActualLine = IsSpelling ? SM.getSpellingLineNumber(Loc) : SM.getExpansionLineNumber(Loc); if (Presumed.isValid()) { + JOS.attribute("offset", SM.getDecomposedLoc(Loc).second); if (LastLocFilename != Presumed.getFilename()) { JOS.attribute("file", Presumed.getFilename()); JOS.attribute("line", ActualLine); @@ -202,6 +220,12 @@ void JSONNodeDumper::writeBareSourceLocation(SourceLocation Loc, LastLocFilename = Presumed.getFilename(); LastLocPresumedLine = PresumedLine; LastLocLine = ActualLine; + + // Orthogonal to the file, line, and column de-duplication is whether the + // given location was a result of an include. If so, print where the + // include location came from. + writeIncludeStack(SM.getPresumedLoc(Presumed.getIncludeLoc()), + /*JustFirst*/ true); } } |