Bug 1282172 - Detect enum constants generated by macros when generating the Searchfox index. r?billm draft
authorKartikaya Gupta <kgupta@mozilla.com>
Sat, 18 Nov 2017 20:05:53 -0500
changeset 700209 aef7921b77ed178264591eaae8ffe024187b44d4
parent 700200 3a0aac55195fd50ca4b1b41be450bfbaaafc191c
child 740808 0a6ba3c274a274f9e91e6eb61d8a10f5cfe5a1a7
push id89764
push userkgupta@mozilla.com
push dateSun, 19 Nov 2017 01:06:35 +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
@@ -1035,16 +1035,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;