clang  14.0.0git
USRGeneration.h
Go to the documentation of this file.
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 MacroDefinitionRecord;
19 class Module;
20 class SourceLocation;
21 class SourceManager;
22 class QualType;
23 
24 namespace index {
25 
26 static inline StringRef getUSRSpacePrefix() {
27  return "c:";
28 }
29 
30 /// Generate a USR for a Decl, including the USR prefix.
31 /// \returns true if the results should be ignored, false otherwise.
32 bool generateUSRForDecl(const Decl *D, SmallVectorImpl<char> &Buf);
33 
34 /// Generate a USR fragment for an Objective-C class.
35 void generateUSRForObjCClass(StringRef Cls, raw_ostream &OS,
36  StringRef ExtSymbolDefinedIn = "",
37  StringRef CategoryContextExtSymbolDefinedIn = "");
38 
39 /// Generate a USR fragment for an Objective-C class category.
40 void generateUSRForObjCCategory(StringRef Cls, StringRef Cat, raw_ostream &OS,
41  StringRef ClsExtSymbolDefinedIn = "",
42  StringRef CatExtSymbolDefinedIn = "");
43 
44 /// Generate a USR fragment for an Objective-C instance variable. The
45 /// complete USR can be created by concatenating the USR for the
46 /// encompassing class with this USR fragment.
47 void generateUSRForObjCIvar(StringRef Ivar, raw_ostream &OS);
48 
49 /// Generate a USR fragment for an Objective-C method.
50 void generateUSRForObjCMethod(StringRef Sel, bool IsInstanceMethod,
51  raw_ostream &OS);
52 
53 /// Generate a USR fragment for an Objective-C property.
54 void generateUSRForObjCProperty(StringRef Prop, bool isClassProp, raw_ostream &OS);
55 
56 /// Generate a USR fragment for an Objective-C protocol.
57 void generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS,
58  StringRef ExtSymbolDefinedIn = "");
59 
60 /// Generate USR fragment for a global (non-nested) enum.
61 void generateUSRForGlobalEnum(StringRef EnumName, raw_ostream &OS,
62  StringRef ExtSymbolDefinedIn = "");
63 
64 /// Generate a USR fragment for an enum constant.
65 void generateUSRForEnumConstant(StringRef EnumConstantName, raw_ostream &OS);
66 
67 /// Generate a USR for a macro, including the USR prefix.
68 ///
69 /// \returns true on error, false on success.
72 bool generateUSRForMacro(StringRef MacroName, SourceLocation Loc,
74 
75 /// Generates a USR for a type.
76 ///
77 /// \return true on error, false on success.
79 
80 /// Generate a USR for a module, including the USR prefix.
81 /// \returns true on error, false on success.
82 bool generateFullUSRForModule(const Module *Mod, raw_ostream &OS);
83 
84 /// Generate a USR for a top-level module name, including the USR prefix.
85 /// \returns true on error, false on success.
86 bool generateFullUSRForTopLevelModuleName(StringRef ModName, raw_ostream &OS);
87 
88 /// Generate a USR fragment for a module.
89 /// \returns true on error, false on success.
90 bool generateUSRFragmentForModule(const Module *Mod, raw_ostream &OS);
91 
92 /// Generate a USR fragment for a module name.
93 /// \returns true on error, false on success.
94 bool generateUSRFragmentForModuleName(StringRef ModName, raw_ostream &OS);
95 
96 
97 } // namespace index
98 } // namespace clang
99 
100 #endif // LLVM_CLANG_INDEX_USRGENERATION_H
101 
clang::index::generateUSRForObjCMethod
void generateUSRForObjCMethod(StringRef Sel, bool IsInstanceMethod, raw_ostream &OS)
Generate a USR fragment for an Objective-C method.
Definition: USRGeneration.cpp:1051
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::index::generateFullUSRForModule
bool generateFullUSRForModule(const Module *Mod, raw_ostream &OS)
Generate a USR for a module, including the USR prefix.
Definition: USRGeneration.cpp:1135
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
clang::index::getUSRSpacePrefix
static StringRef getUSRSpacePrefix()
Definition: USRGeneration.h:26
clang::index::generateUSRForGlobalEnum
void generateUSRForGlobalEnum(StringRef EnumName, raw_ostream &OS, StringRef ExtSymbolDefinedIn="")
Generate USR fragment for a global (non-nested) enum.
Definition: USRGeneration.cpp:1069
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:626
clang::index::generateUSRForObjCProperty
void generateUSRForObjCProperty(StringRef Prop, bool isClassProp, raw_ostream &OS)
Generate a USR fragment for an Objective-C property.
Definition: USRGeneration.cpp:1057
clang::CodeGen::AlignmentSource::Decl
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
clang::Module
Describes a module or submodule.
Definition: Module.h:96
clang::index::generateFullUSRForTopLevelModuleName
bool generateFullUSRForTopLevelModuleName(StringRef ModName, raw_ostream &OS)
Generate a USR for a top-level module name, including the USR prefix.
Definition: USRGeneration.cpp:1144
clang::index::SymbolKind::Module
@ Module
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:212
clang::MacroDefinitionRecord
Record the location of a macro definition.
Definition: PreprocessingRecord.h:148
clang::index::generateUSRForObjCProtocol
void generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS, StringRef ExtSymbolDefinedIn="")
Generate a USR fragment for an Objective-C protocol.
Definition: USRGeneration.cpp:1062
clang::index::generateUSRFragmentForModule
bool generateUSRFragmentForModule(const Module *Mod, raw_ostream &OS)
Generate a USR fragment for a module.
Definition: USRGeneration.cpp:1150
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
clang::index::generateUSRFragmentForModuleName
bool generateUSRFragmentForModuleName(StringRef ModName, raw_ostream &OS)
Generate a USR fragment for a module name.
Definition: USRGeneration.cpp:1155
LLVM.h
clang::index::generateUSRForEnumConstant
void generateUSRForEnumConstant(StringRef EnumConstantName, raw_ostream &OS)
Generate a USR fragment for an enum constant.
Definition: USRGeneration.cpp:1076
clang::index::generateUSRForDecl
bool generateUSRForDecl(const Decl *D, SmallVectorImpl< char > &Buf)
Generate a USR for a Decl, including the USR prefix.
Definition: USRGeneration.cpp:1081
clang::index::generateUSRForObjCClass
void generateUSRForObjCClass(StringRef Cls, raw_ostream &OS, StringRef ExtSymbolDefinedIn="", StringRef CategoryContextExtSymbolDefinedIn="")
Generate a USR fragment for an Objective-C class.
Definition: USRGeneration.cpp:1031
clang
Definition: CalledOnceCheck.h:17
clang::index::generateUSRForObjCIvar
void generateUSRForObjCIvar(StringRef Ivar, raw_ostream &OS)
Generate a USR fragment for an Objective-C instance variable.
Definition: USRGeneration.cpp:1047
clang::index::generateUSRForMacro
bool generateUSRForMacro(const MacroDefinitionRecord *MD, const SourceManager &SM, SmallVectorImpl< char > &Buf)
Generate a USR for a macro, including the USR prefix.
Definition: USRGeneration.cpp:1094
clang::index::generateUSRForObjCCategory
void generateUSRForObjCCategory(StringRef Cls, StringRef Cat, raw_ostream &OS, StringRef ClsExtSymbolDefinedIn="", StringRef CatExtSymbolDefinedIn="")
Generate a USR fragment for an Objective-C class category.
Definition: USRGeneration.cpp:1039
llvm::SmallVectorImpl< char >
SM
#define SM(sm)
Definition: Cuda.cpp:78
clang::index::generateUSRForType
bool generateUSRForType(QualType T, ASTContext &Ctx, SmallVectorImpl< char > &Buf)
Generates a USR for a type.
Definition: USRGeneration.cpp:1124