USRGeneration.h 4.0 KB

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