@@ -695,12 +695,19 @@ namespace {
695
695
// / single quotes when printing substitution maps in full.
696
696
char Quote = ' \" ' ;
697
697
698
+ // / Tracks the source buffer ID of the main source file, which subclasses
699
+ // / can use to distinguish ranges/locations in that file vs. ranges in other
700
+ // / buffers, like macro expansions.
701
+ unsigned MainBufferID;
702
+
698
703
public:
699
704
virtual ~PrintWriterBase () {}
700
705
701
706
char quote () const { return Quote; }
702
707
void setQuote (char quote) { Quote = quote; }
703
708
709
+ void setMainBufferID (unsigned bufferID) { MainBufferID = bufferID; }
710
+
704
711
// / Call `body` in a context where the printer is ready for a child to be
705
712
// / printed.
706
713
virtual void printRecArbitrary (std::function<void (Label)> body,
@@ -945,6 +952,12 @@ namespace {
945
952
unsigned endOffset = srcMgr.getLocOffsetInBuffer (R.End , endBufferID);
946
953
OS.attribute (" end" , endOffset);
947
954
955
+ // Only print the buffer ID when it doesn't match the main ID, so that we
956
+ // distinguish macro expansions but don't bloat the output with the main
957
+ // file name repeated over and over.
958
+ if (startBufferID != MainBufferID)
959
+ OS.attribute (" buffer_id" , srcMgr.getIdentifierForBuffer (startBufferID));
960
+
948
961
OS.objectEnd ();
949
962
OS.attributeEnd ();
950
963
}
@@ -2170,15 +2183,25 @@ namespace {
2170
2183
2171
2184
printAttributes (IDC->getDecl ());
2172
2185
2173
- auto members = ParseIfNeeded ? IDC->getMembers ()
2174
- : IDC->getCurrentMembersWithoutLoading ();
2175
- printList (members, [&](Decl *D, Label label) {
2176
- printRec (D, label);
2177
- }, Label::optional (" members" ));
2186
+ if (Writer.isParsable ()) {
2187
+ // Parsable outputs are meant to be used for semantic analysis, so we
2188
+ // want the full list of members, including macro-generated ones.
2189
+ printList (IDC->getABIMembers (), [&](Decl *D, Label label) {
2190
+ printRec (D, label);
2191
+ }, Label::optional (" members" ));
2192
+ } else {
2193
+ auto members = ParseIfNeeded ? IDC->getMembers ()
2194
+ : IDC->getCurrentMembersWithoutLoading ();
2195
+ printList (members, [&](Decl *D, Label label) {
2196
+ printRec (D, label);
2197
+ }, Label::optional (" members" ));
2198
+ }
2178
2199
printFoot ();
2179
2200
}
2180
2201
2181
2202
void visitSourceFile (const SourceFile &SF) {
2203
+ Writer.setMainBufferID (SF.getBufferID ());
2204
+
2182
2205
printHead (" source_file" , ASTNodeColor, Label::optional (" " ));
2183
2206
printNameRaw ([&](raw_ostream &OS) {
2184
2207
OS << SF.getFilename ();
0 commit comments