1 //===- USRGeneration.h - Routines for USR generation ------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_CLANG_INDEX_USRGENERATION_H 10 #define LLVM_CLANG_INDEX_USRGENERATION_H 11 12 #include "clang/Basic/LLVM.h" 13 #include "llvm/ADT/StringRef.h" 14 15 namespace clang { 16 class ASTContext; 17 class Decl; 18 class LangOptions; 19 class MacroDefinitionRecord; 20 class Module; 21 class SourceLocation; 22 class SourceManager; 23 class QualType; 24 25 namespace index { 26 27 static inline StringRef getUSRSpacePrefix() { 28 return "c:"; 29 } 30 31 /// Generate a USR for a Decl, including the USR prefix. 32 /// \returns true if the results should be ignored, false otherwise. 33 bool generateUSRForDecl(const Decl *D, SmallVectorImpl<char> &Buf); 34 bool generateUSRForDecl(const Decl *D, SmallVectorImpl<char> &Buf, 35 const LangOptions &LangOpts); 36 37 /// Generate a USR fragment for an Objective-C class. 38 void generateUSRForObjCClass(StringRef Cls, raw_ostream &OS, 39 StringRef ExtSymbolDefinedIn = "", 40 StringRef CategoryContextExtSymbolDefinedIn = ""); 41 42 /// Generate a USR fragment for an Objective-C class category. 43 void generateUSRForObjCCategory(StringRef Cls, StringRef Cat, raw_ostream &OS, 44 StringRef ClsExtSymbolDefinedIn = "", 45 StringRef CatExtSymbolDefinedIn = ""); 46 47 /// Generate a USR fragment for an Objective-C instance variable. The 48 /// complete USR can be created by concatenating the USR for the 49 /// encompassing class with this USR fragment. 50 void generateUSRForObjCIvar(StringRef Ivar, raw_ostream &OS); 51 52 /// Generate a USR fragment for an Objective-C method. 53 void generateUSRForObjCMethod(StringRef Sel, bool IsInstanceMethod, 54 raw_ostream &OS); 55 56 /// Generate a USR fragment for an Objective-C property. 57 void generateUSRForObjCProperty(StringRef Prop, bool isClassProp, raw_ostream &OS); 58 59 /// Generate a USR fragment for an Objective-C protocol. 60 void generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS, 61 StringRef ExtSymbolDefinedIn = ""); 62 63 /// Generate USR fragment for a global (non-nested) enum. 64 void generateUSRForGlobalEnum(StringRef EnumName, raw_ostream &OS, 65 StringRef ExtSymbolDefinedIn = ""); 66 67 /// Generate a USR fragment for an enum constant. 68 void generateUSRForEnumConstant(StringRef EnumConstantName, raw_ostream &OS); 69 70 /// Generate a USR for a macro, including the USR prefix. 71 /// 72 /// \returns true on error, false on success. 73 bool generateUSRForMacro(const MacroDefinitionRecord *MD, 74 const SourceManager &SM, SmallVectorImpl<char> &Buf); 75 bool generateUSRForMacro(StringRef MacroName, SourceLocation Loc, 76 const SourceManager &SM, SmallVectorImpl<char> &Buf); 77 78 /// Generates a USR for a type. 79 /// 80 /// \return true on error, false on success. 81 bool generateUSRForType(QualType T, ASTContext &Ctx, 82 SmallVectorImpl<char> &Buf); 83 bool generateUSRForType(QualType T, ASTContext &Ctx, SmallVectorImpl<char> &Buf, 84 const LangOptions &LangOpts); 85 86 /// Generate a USR for a module, including the USR prefix. 87 /// \returns true on error, false on success. 88 bool generateFullUSRForModule(const Module *Mod, raw_ostream &OS); 89 90 /// Generate a USR for a top-level module name, including the USR prefix. 91 /// \returns true on error, false on success. 92 bool generateFullUSRForTopLevelModuleName(StringRef ModName, raw_ostream &OS); 93 94 /// Generate a USR fragment for a module. 95 /// \returns true on error, false on success. 96 bool generateUSRFragmentForModule(const Module *Mod, raw_ostream &OS); 97 98 /// Generate a USR fragment for a module name. 99 /// \returns true on error, false on success. 100 bool generateUSRFragmentForModuleName(StringRef ModName, raw_ostream &OS); 101 102 103 } // namespace index 104 } // namespace clang 105 106 #endif // LLVM_CLANG_INDEX_USRGENERATION_H 107 108