@@ -703,12 +703,19 @@ namespace {
703
703
// / single quotes when printing substitution maps in full.
704
704
char Quote = ' \" ' ;
705
705
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
+
706
711
public:
707
712
virtual ~PrintWriterBase () {}
708
713
709
714
char quote () const { return Quote; }
710
715
void setQuote (char quote) { Quote = quote; }
711
716
717
+ void setMainBufferID (unsigned bufferID) { MainBufferID = bufferID; }
718
+
712
719
// / Call `body` in a context where the printer is ready for a child to be
713
720
// / printed.
714
721
virtual void printRecArbitrary (std::function<void (Label)> body,
@@ -953,6 +960,12 @@ namespace {
953
960
unsigned endOffset = srcMgr.getLocOffsetInBuffer (R.End , endBufferID);
954
961
OS.attribute (" end" , endOffset);
955
962
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
+
956
969
OS.objectEnd ();
957
970
OS.attributeEnd ();
958
971
}
@@ -2178,15 +2191,25 @@ namespace {
2178
2191
2179
2192
printAttributes (IDC->getDecl ());
2180
2193
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
+ }
2186
2207
printFoot ();
2187
2208
}
2188
2209
2189
2210
void visitSourceFile (const SourceFile &SF) {
2211
+ Writer.setMainBufferID (SF.getBufferID ());
2212
+
2190
2213
printHead (" source_file" , ASTNodeColor, Label::optional (" " ));
2191
2214
printNameRaw ([&](raw_ostream &OS) {
2192
2215
OS << SF.getFilename ();
0 commit comments