Bug 1282172 - Detect enum constants generated by macros when generating the Searchfox index. r=billm
authorKartikaya Gupta <kgupta@mozilla.com>
Sat, 18 Nov 2017 20:05:53 -0500
changeset 437144 db0886825a54e3e600bc6ddbf7162f7266eac299
parent 437134 b056526be38e96b3e381b7e90cd8254ad1d96d9d
child 437145 77ad85e8bfac43a2fffe185a8007461cba22a9c6
child 437160 237e09de43a1c7967f7a8b5a9343ab37f9ac5a77
push id117
push userfmarier@mozilla.com
push dateTue, 28 Nov 2017 20:17:16 +0000
reviewersbillm
bugs1282172
milestone59.0a1
Bug 1282172 - Detect enum constants generated by macros when generating the Searchfox index. r=billm MozReview-Commit-ID: 5RUsVSMTU8
build/clang-plugin/mozsearch-plugin/MozsearchIndexer.cpp
--- a/build/clang-plugin/mozsearch-plugin/MozsearchIndexer.cpp
+++ b/build/clang-plugin/mozsearch-plugin/MozsearchIndexer.cpp
@@ -1037,16 +1037,26 @@ public:
       return SourceRange();
     }
 
     return Range;
   }
 
   bool VisitNamedDecl(NamedDecl *D) {
     SourceLocation Loc = D->getLocation();
+
+    if (isa<EnumConstantDecl>(D) && SM.isMacroBodyExpansion(Loc)) {
+      // for enum constants generated by macro expansion, update location
+      // to point to the expansion location as that is more useful. We might
+      // want to do this for more token types but until we have good regression
+      // testing for the Indexer it's best to be as conservative and explicit
+      // as possible with the changes.
+      Loc = SM.getFileLoc(Loc);
+    }
+
     normalizeLocation(&Loc);
     if (!isInterestingLocation(Loc)) {
       return true;
     }
 
     if (isa<ParmVarDecl>(D) && !D->getDeclName().getAsIdentifierInfo()) {
       // Unnamed parameter in function proto.
       return true;