@@ -703,12 +703,19 @@ namespace {
703703 // / single quotes when printing substitution maps in full.
704704 char Quote = ' \" ' ;
705705
706+ // / Tracks the source buffer ID of the main source file, which subclasses
707+ // / can use to distinguish ranges/locations in that file vs. ranges in other
708+ // / buffers, like macro expansions.
709+ unsigned MainBufferID;
710+
706711 public:
707712 virtual ~PrintWriterBase () {}
708713
709714 char quote () const { return Quote; }
710715 void setQuote (char quote) { Quote = quote; }
711716
717+ void setMainBufferID (unsigned bufferID) { MainBufferID = bufferID; }
718+
712719 // / Call `body` in a context where the printer is ready for a child to be
713720 // / printed.
714721 virtual void printRecArbitrary (std::function<void (Label)> body,
@@ -953,6 +960,12 @@ namespace {
953960 unsigned endOffset = srcMgr.getLocOffsetInBuffer (R.End , endBufferID);
954961 OS.attribute (" end" , endOffset);
955962
963+ // Only print the buffer ID when it doesn't match the main ID, so that we
964+ // distinguish macro expansions but don't bloat the output with the main
965+ // file name repeated over and over.
966+ if (startBufferID != MainBufferID)
967+ OS.attribute (" buffer_id" , srcMgr.getIdentifierForBuffer (startBufferID));
968+
956969 OS.objectEnd ();
957970 OS.attributeEnd ();
958971 }
@@ -2178,15 +2191,25 @@ namespace {
21782191
21792192 printAttributes (IDC->getDecl ());
21802193
2181- auto members = ParseIfNeeded ? IDC->getMembers ()
2182- : IDC->getCurrentMembersWithoutLoading ();
2183- printList (members, [&](Decl *D, Label label) {
2184- printRec (D, label);
2185- }, Label::optional (" members" ));
2194+ if (Writer.isParsable ()) {
2195+ // Parsable outputs are meant to be used for semantic analysis, so we
2196+ // want the full list of members, including macro-generated ones.
2197+ printList (IDC->getABIMembers (), [&](Decl *D, Label label) {
2198+ printRec (D, label);
2199+ }, Label::optional (" members" ));
2200+ } else {
2201+ auto members = ParseIfNeeded ? IDC->getMembers ()
2202+ : IDC->getCurrentMembersWithoutLoading ();
2203+ printList (members, [&](Decl *D, Label label) {
2204+ printRec (D, label);
2205+ }, Label::optional (" members" ));
2206+ }
21862207 printFoot ();
21872208 }
21882209
21892210 void visitSourceFile (const SourceFile &SF) {
2211+ Writer.setMainBufferID (SF.getBufferID ());
2212+
21902213 printHead (" source_file" , ASTNodeColor, Label::optional (" " ));
21912214 printNameRaw ([&](raw_ostream &OS) {
21922215 OS << SF.getFilename ();
0 commit comments