]> granicus.if.org Git - clang/commitdiff
[index] Provide a more general index::generateUSRForMacro() that doesn't depend on...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 2 Feb 2017 16:13:10 +0000 (16:13 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 2 Feb 2017 16:13:10 +0000 (16:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@293904 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Index/USRGeneration.h
lib/Index/USRGeneration.cpp

index be89068469c4d032e010244691d9e5f135fb9cb8..61f2c9d1ff13eb9bdf6d56dcaf2cac9929e56414 100644 (file)
@@ -16,6 +16,7 @@
 namespace clang {
 class Decl;
 class MacroDefinitionRecord;
+class SourceLocation;
 class SourceManager;
 
 namespace index {
@@ -54,6 +55,8 @@ void generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS);
 /// \returns true on error, false on success.
 bool generateUSRForMacro(const MacroDefinitionRecord *MD,
                          const SourceManager &SM, SmallVectorImpl<char> &Buf);
+bool generateUSRForMacro(StringRef MacroName, SourceLocation Loc,
+                         const SourceManager &SM, SmallVectorImpl<char> &Buf);
 
 } // namespace index
 } // namespace clang
index 58f61c3c65b73145a72667ed138b10692e03c903..f9ed3c47995582aed9569fb535f9e44d39990807 100644 (file)
@@ -911,21 +911,30 @@ bool clang::index::generateUSRForDecl(const Decl *D,
 bool clang::index::generateUSRForMacro(const MacroDefinitionRecord *MD,
                                        const SourceManager &SM,
                                        SmallVectorImpl<char> &Buf) {
+  if (!MD)
+    return true;
+  return generateUSRForMacro(MD->getName()->getName(), MD->getLocation(),
+                             SM, Buf);
+
+}
+
+bool clang::index::generateUSRForMacro(StringRef MacroName, SourceLocation Loc,
+                                       const SourceManager &SM,
+                                       SmallVectorImpl<char> &Buf) {
   // Don't generate USRs for things with invalid locations.
-  if (!MD || MD->getLocation().isInvalid())
+  if (MacroName.empty() || Loc.isInvalid())
     return true;
 
   llvm::raw_svector_ostream Out(Buf);
 
   // Assume that system headers are sane.  Don't put source location
   // information into the USR if the macro comes from a system header.
-  SourceLocation Loc = MD->getLocation();
   bool ShouldGenerateLocation = !SM.isInSystemHeader(Loc);
 
   Out << getUSRSpacePrefix();
   if (ShouldGenerateLocation)
     printLoc(Out, Loc, SM, /*IncludeOffset=*/true);
   Out << "@macro@";
-  Out << MD->getName()->getName();
+  Out << MacroName;
   return false;
 }