Ted Kremenek | 1b6869a | 2010-01-05 22:06:45 +0000 | [diff] [blame] | 1 | //===- CIndexUSR.cpp - Clang-C Source Indexing Library --------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the generation and use of USRs from CXEntities. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "CIndexer.h" |
Ted Kremenek | cf84aa4 | 2010-01-18 20:23:29 +0000 | [diff] [blame] | 15 | #include "CXCursor.h" |
Ted Kremenek | ed12273 | 2010-11-16 01:56:27 +0000 | [diff] [blame] | 16 | #include "CXString.h" |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclTemplate.h" |
Benjamin Kramer | 9895c6a | 2010-01-12 11:32:40 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclVisitor.h" |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 19 | #include "clang/Frontend/ASTUnit.h" |
Benjamin Kramer | b846deb | 2010-04-12 19:45:50 +0000 | [diff] [blame] | 20 | #include "clang/Lex/PreprocessingRecord.h" |
Ted Kremenek | 8776382 | 2010-01-12 02:07:58 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallString.h" |
Benjamin Kramer | 9895c6a | 2010-01-12 11:32:40 +0000 | [diff] [blame] | 22 | #include "llvm/Support/raw_ostream.h" |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 23 | |
Benjamin Kramer | b846deb | 2010-04-12 19:45:50 +0000 | [diff] [blame] | 24 | using namespace clang; |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 25 | using namespace clang::cxstring; |
| 26 | |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 27 | //===----------------------------------------------------------------------===// |
| 28 | // USR generation. |
| 29 | //===----------------------------------------------------------------------===// |
| 30 | |
| 31 | namespace { |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 32 | class USRGenerator : public DeclVisitor<USRGenerator> { |
Ted Kremenek | f019943 | 2010-11-16 08:15:38 +0000 | [diff] [blame] | 33 | llvm::OwningPtr<llvm::SmallString<128> > OwnedBuf; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 34 | SmallVectorImpl<char> &Buf; |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 35 | llvm::raw_svector_ostream Out; |
Ted Kremenek | 3adca6d | 2010-01-18 22:02:49 +0000 | [diff] [blame] | 36 | bool IgnoreResults; |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 37 | ASTContext *Context; |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 38 | bool generatedLoc; |
Douglas Gregor | 66b7fbf | 2010-09-20 20:37:39 +0000 | [diff] [blame] | 39 | |
| 40 | llvm::DenseMap<const Type *, unsigned> TypeSubstitutions; |
| 41 | |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 42 | public: |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 43 | explicit USRGenerator(ASTContext *Ctx = 0, SmallVectorImpl<char> *extBuf = 0) |
Ted Kremenek | f019943 | 2010-11-16 08:15:38 +0000 | [diff] [blame] | 44 | : OwnedBuf(extBuf ? 0 : new llvm::SmallString<128>()), |
| 45 | Buf(extBuf ? *extBuf : *OwnedBuf.get()), |
| 46 | Out(Buf), |
| 47 | IgnoreResults(false), |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 48 | Context(Ctx), |
Ted Kremenek | f019943 | 2010-11-16 08:15:38 +0000 | [diff] [blame] | 49 | generatedLoc(false) |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 50 | { |
| 51 | // Add the USR space prefix. |
| 52 | Out << "c:"; |
| 53 | } |
| 54 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 55 | StringRef str() { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 56 | return Out.str(); |
| 57 | } |
| 58 | |
| 59 | USRGenerator* operator->() { return this; } |
| 60 | |
| 61 | template <typename T> |
| 62 | llvm::raw_svector_ostream &operator<<(const T &x) { |
| 63 | Out << x; |
| 64 | return Out; |
| 65 | } |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 66 | |
Ted Kremenek | 3adca6d | 2010-01-18 22:02:49 +0000 | [diff] [blame] | 67 | bool ignoreResults() const { return IgnoreResults; } |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 68 | |
| 69 | // Visitation methods from generating USRs from AST elements. |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 70 | void VisitDeclContext(DeclContext *D); |
Ted Kremenek | 3adca6d | 2010-01-18 22:02:49 +0000 | [diff] [blame] | 71 | void VisitFieldDecl(FieldDecl *D); |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 72 | void VisitFunctionDecl(FunctionDecl *D); |
| 73 | void VisitNamedDecl(NamedDecl *D); |
| 74 | void VisitNamespaceDecl(NamespaceDecl *D); |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 75 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 76 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 77 | void VisitClassTemplateDecl(ClassTemplateDecl *D); |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 78 | void VisitObjCClassDecl(ObjCClassDecl *CD); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 79 | void VisitObjCContainerDecl(ObjCContainerDecl *CD); |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 80 | void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *P); |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 81 | void VisitObjCMethodDecl(ObjCMethodDecl *MD); |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 82 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 83 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
Ted Kremenek | b82b3be | 2010-01-18 22:42:20 +0000 | [diff] [blame] | 84 | void VisitTagDecl(TagDecl *D); |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 85 | void VisitTypedefDecl(TypedefDecl *D); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 86 | void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 87 | void VisitVarDecl(VarDecl *D); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 88 | void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 89 | void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 90 | void VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 91 | IgnoreResults = true; |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 92 | } |
Douglas Gregor | 0a35bce | 2010-09-01 03:07:18 +0000 | [diff] [blame] | 93 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 94 | IgnoreResults = true; |
| 95 | } |
Douglas Gregor | 7e24256 | 2010-09-01 19:52:22 +0000 | [diff] [blame] | 96 | void VisitUsingDecl(UsingDecl *D) { |
| 97 | IgnoreResults = true; |
| 98 | } |
| 99 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
| 100 | IgnoreResults = true; |
| 101 | } |
| 102 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) { |
| 103 | IgnoreResults = true; |
| 104 | } |
Douglas Gregor | 0a35bce | 2010-09-01 03:07:18 +0000 | [diff] [blame] | 105 | |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 106 | /// Generate the string component containing the location of the |
| 107 | /// declaration. |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 108 | bool GenLoc(const Decl *D); |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 109 | |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 110 | /// String generation methods used both by the visitation methods |
| 111 | /// and from other clients that want to directly generate USRs. These |
| 112 | /// methods do not construct complete USRs (which incorporate the parents |
| 113 | /// of an AST element), but only the fragments concerning the AST element |
| 114 | /// itself. |
| 115 | |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 116 | /// Generate a USR for an Objective-C class. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 117 | void GenObjCClass(StringRef cls); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 118 | /// Generate a USR for an Objective-C class category. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 119 | void GenObjCCategory(StringRef cls, StringRef cat); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 120 | /// Generate a USR fragment for an Objective-C instance variable. The |
| 121 | /// complete USR can be created by concatenating the USR for the |
| 122 | /// encompassing class with this USR fragment. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 123 | void GenObjCIvar(StringRef ivar); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 124 | /// Generate a USR fragment for an Objective-C method. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 125 | void GenObjCMethod(StringRef sel, bool isInstanceMethod); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 126 | /// Generate a USR fragment for an Objective-C property. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 127 | void GenObjCProperty(StringRef prop); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 128 | /// Generate a USR for an Objective-C protocol. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 129 | void GenObjCProtocol(StringRef prot); |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 130 | |
| 131 | void VisitType(QualType T); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 132 | void VisitTemplateParameterList(const TemplateParameterList *Params); |
| 133 | void VisitTemplateName(TemplateName Name); |
| 134 | void VisitTemplateArgument(const TemplateArgument &Arg); |
| 135 | |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 136 | /// Emit a Decl's name using NamedDecl::printName() and return true if |
| 137 | /// the decl had no name. |
| 138 | bool EmitDeclName(const NamedDecl *D); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 141 | } // end anonymous namespace |
| 142 | |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 143 | //===----------------------------------------------------------------------===// |
| 144 | // Generating USRs from ASTS. |
| 145 | //===----------------------------------------------------------------------===// |
| 146 | |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 147 | bool USRGenerator::EmitDeclName(const NamedDecl *D) { |
| 148 | Out.flush(); |
| 149 | const unsigned startSize = Buf.size(); |
| 150 | D->printName(Out); |
| 151 | Out.flush(); |
| 152 | const unsigned endSize = Buf.size(); |
| 153 | return startSize == endSize; |
| 154 | } |
| 155 | |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 156 | static bool InAnonymousNamespace(const Decl *D) { |
| 157 | if (const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(D->getDeclContext())) |
| 158 | return ND->isAnonymousNamespace(); |
| 159 | return false; |
| 160 | } |
| 161 | |
| 162 | static inline bool ShouldGenerateLocation(const NamedDecl *D) { |
| 163 | return D->getLinkage() != ExternalLinkage && !InAnonymousNamespace(D); |
| 164 | } |
| 165 | |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 166 | void USRGenerator::VisitDeclContext(DeclContext *DC) { |
| 167 | if (NamedDecl *D = dyn_cast<NamedDecl>(DC)) |
| 168 | Visit(D); |
| 169 | } |
| 170 | |
Ted Kremenek | 3adca6d | 2010-01-18 22:02:49 +0000 | [diff] [blame] | 171 | void USRGenerator::VisitFieldDecl(FieldDecl *D) { |
Argyrios Kyrtzidis | 87ec9c2 | 2011-11-01 17:14:12 +0000 | [diff] [blame] | 172 | // The USR for an ivar declared in a class extension is based on the |
| 173 | // ObjCInterfaceDecl, not the ObjCCategoryDecl. |
| 174 | if (ObjCInterfaceDecl *ID = Context->getObjContainingInterface(D)) |
| 175 | Visit(ID); |
| 176 | else |
| 177 | VisitDeclContext(D->getDeclContext()); |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 178 | Out << (isa<ObjCIvarDecl>(D) ? "@" : "@FI@"); |
| 179 | if (EmitDeclName(D)) { |
Ted Kremenek | 3adca6d | 2010-01-18 22:02:49 +0000 | [diff] [blame] | 180 | // Bit fields can be anonymous. |
| 181 | IgnoreResults = true; |
| 182 | return; |
| 183 | } |
Ted Kremenek | 3adca6d | 2010-01-18 22:02:49 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 186 | void USRGenerator::VisitFunctionDecl(FunctionDecl *D) { |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 187 | if (ShouldGenerateLocation(D) && GenLoc(D)) |
| 188 | return; |
Ted Kremenek | cf99910 | 2010-04-29 17:43:29 +0000 | [diff] [blame] | 189 | |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 190 | VisitDeclContext(D->getDeclContext()); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 191 | if (FunctionTemplateDecl *FunTmpl = D->getDescribedFunctionTemplate()) { |
| 192 | Out << "@FT@"; |
| 193 | VisitTemplateParameterList(FunTmpl->getTemplateParameters()); |
| 194 | } else |
| 195 | Out << "@F@"; |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 196 | D->printName(Out); |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 197 | |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 198 | ASTContext &Ctx = *Context; |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 199 | if (!Ctx.getLangOptions().CPlusPlus || D->isExternC()) |
| 200 | return; |
| 201 | |
| 202 | // Mangle in type information for the arguments. |
| 203 | for (FunctionDecl::param_iterator I = D->param_begin(), E = D->param_end(); |
| 204 | I != E; ++I) { |
| 205 | Out << '#'; |
| 206 | if (ParmVarDecl *PD = *I) |
| 207 | VisitType(PD->getType()); |
| 208 | } |
| 209 | if (D->isVariadic()) |
| 210 | Out << '.'; |
Ted Kremenek | 2ea5baf | 2010-05-07 20:39:40 +0000 | [diff] [blame] | 211 | Out << '#'; |
| 212 | if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) { |
| 213 | if (MD->isStatic()) |
| 214 | Out << 'S'; |
| 215 | if (unsigned quals = MD->getTypeQualifiers()) |
| 216 | Out << (char)('0' + quals); |
| 217 | } |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 218 | } |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 219 | |
| 220 | void USRGenerator::VisitNamedDecl(NamedDecl *D) { |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 221 | VisitDeclContext(D->getDeclContext()); |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 222 | Out << "@"; |
| 223 | |
| 224 | if (EmitDeclName(D)) { |
| 225 | // The string can be empty if the declaration has no name; e.g., it is |
| 226 | // the ParmDecl with no name for declaration of a function pointer type, |
| 227 | // e.g.: void (*f)(void *); |
| 228 | // In this case, don't generate a USR. |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 229 | IgnoreResults = true; |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 230 | } |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 233 | void USRGenerator::VisitVarDecl(VarDecl *D) { |
| 234 | // VarDecls can be declared 'extern' within a function or method body, |
| 235 | // but their enclosing DeclContext is the function, not the TU. We need |
| 236 | // to check the storage class to correctly generate the USR. |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 237 | if (ShouldGenerateLocation(D) && GenLoc(D)) |
| 238 | return; |
| 239 | |
| 240 | VisitDeclContext(D->getDeclContext()); |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 241 | |
Ted Kremenek | cf99910 | 2010-04-29 17:43:29 +0000 | [diff] [blame] | 242 | // Variables always have simple names. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 243 | StringRef s = D->getName(); |
Ted Kremenek | cf99910 | 2010-04-29 17:43:29 +0000 | [diff] [blame] | 244 | |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 245 | // The string can be empty if the declaration has no name; e.g., it is |
| 246 | // the ParmDecl with no name for declaration of a function pointer type, e.g.: |
Eli Friedman | a7e6845 | 2010-08-22 01:00:03 +0000 | [diff] [blame] | 247 | // void (*f)(void *); |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 248 | // In this case, don't generate a USR. |
| 249 | if (s.empty()) |
| 250 | IgnoreResults = true; |
| 251 | else |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 252 | Out << '@' << s; |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 255 | void USRGenerator::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 256 | GenLoc(D); |
| 257 | return; |
| 258 | } |
| 259 | |
| 260 | void USRGenerator::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 261 | GenLoc(D); |
| 262 | return; |
| 263 | } |
| 264 | |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 265 | void USRGenerator::VisitNamespaceDecl(NamespaceDecl *D) { |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 266 | if (D->isAnonymousNamespace()) { |
| 267 | Out << "@aN"; |
| 268 | return; |
| 269 | } |
| 270 | |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 271 | VisitDeclContext(D->getDeclContext()); |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 272 | if (!IgnoreResults) |
| 273 | Out << "@N@" << D->getName(); |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 276 | void USRGenerator::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 277 | VisitFunctionDecl(D->getTemplatedDecl()); |
| 278 | } |
| 279 | |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 280 | void USRGenerator::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 281 | VisitTagDecl(D->getTemplatedDecl()); |
| 282 | } |
| 283 | |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 284 | void USRGenerator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 285 | VisitDeclContext(D->getDeclContext()); |
| 286 | if (!IgnoreResults) |
| 287 | Out << "@NA@" << D->getName(); |
| 288 | } |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 289 | |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 290 | void USRGenerator::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
Ted Kremenek | 52d6bbe | 2011-02-05 01:10:26 +0000 | [diff] [blame] | 291 | DeclContext *container = D->getDeclContext(); |
| 292 | if (ObjCProtocolDecl *pd = dyn_cast<ObjCProtocolDecl>(container)) { |
| 293 | Visit(pd); |
Ted Kremenek | 28a7f25 | 2010-08-24 23:13:41 +0000 | [diff] [blame] | 294 | } |
Ted Kremenek | 52d6bbe | 2011-02-05 01:10:26 +0000 | [diff] [blame] | 295 | else { |
| 296 | // The USR for a method declared in a class extension or category is based on |
| 297 | // the ObjCInterfaceDecl, not the ObjCCategoryDecl. |
| 298 | ObjCInterfaceDecl *ID = D->getClassInterface(); |
| 299 | if (!ID) { |
| 300 | IgnoreResults = true; |
| 301 | return; |
| 302 | } |
| 303 | Visit(ID); |
| 304 | } |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 305 | // Ideally we would use 'GenObjCMethod', but this is such a hot path |
| 306 | // for Objective-C code that we don't want to use |
| 307 | // DeclarationName::getAsString(). |
| 308 | Out << (D->isInstanceMethod() ? "(im)" : "(cm)"); |
| 309 | DeclarationName N(D->getSelector()); |
| 310 | N.printName(Out); |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 313 | void USRGenerator::VisitObjCClassDecl(ObjCClassDecl *D) { |
| 314 | // FIXME: @class declarations can refer to multiple classes. We need |
| 315 | // to be able to traverse these. |
| 316 | IgnoreResults = true; |
| 317 | } |
| 318 | |
| 319 | void USRGenerator::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) { |
| 320 | // FIXME: @protocol declarations can refer to multiple protocols. We need |
| 321 | // to be able to traverse these. |
| 322 | IgnoreResults = true; |
| 323 | } |
| 324 | |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 325 | void USRGenerator::VisitObjCContainerDecl(ObjCContainerDecl *D) { |
| 326 | switch (D->getKind()) { |
| 327 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 328 | llvm_unreachable("Invalid ObjC container."); |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 329 | case Decl::ObjCInterface: |
| 330 | case Decl::ObjCImplementation: |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 331 | GenObjCClass(D->getName()); |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 332 | break; |
| 333 | case Decl::ObjCCategory: { |
| 334 | ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(D); |
Ted Kremenek | ebfa339 | 2010-03-19 20:39:03 +0000 | [diff] [blame] | 335 | ObjCInterfaceDecl *ID = CD->getClassInterface(); |
| 336 | if (!ID) { |
| 337 | // Handle invalid code where the @interface might not |
| 338 | // have been specified. |
| 339 | // FIXME: We should be able to generate this USR even if the |
| 340 | // @interface isn't available. |
| 341 | IgnoreResults = true; |
| 342 | return; |
| 343 | } |
Argyrios Kyrtzidis | 87ec9c2 | 2011-11-01 17:14:12 +0000 | [diff] [blame] | 344 | // Specially handle class extensions, which are anonymous categories. |
| 345 | // We want to mangle in the location to uniquely distinguish them. |
Ted Kremenek | 28a7f25 | 2010-08-24 23:13:41 +0000 | [diff] [blame] | 346 | if (CD->IsClassExtension()) { |
Argyrios Kyrtzidis | 87ec9c2 | 2011-11-01 17:14:12 +0000 | [diff] [blame] | 347 | Out << "objc(ext)" << ID->getName() << '@'; |
| 348 | GenLoc(CD); |
Ted Kremenek | 28a7f25 | 2010-08-24 23:13:41 +0000 | [diff] [blame] | 349 | } |
| 350 | else |
| 351 | GenObjCCategory(ID->getName(), CD->getName()); |
| 352 | |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 353 | break; |
| 354 | } |
| 355 | case Decl::ObjCCategoryImpl: { |
| 356 | ObjCCategoryImplDecl *CD = cast<ObjCCategoryImplDecl>(D); |
Ted Kremenek | ebfa339 | 2010-03-19 20:39:03 +0000 | [diff] [blame] | 357 | ObjCInterfaceDecl *ID = CD->getClassInterface(); |
| 358 | if (!ID) { |
| 359 | // Handle invalid code where the @interface might not |
| 360 | // have been specified. |
| 361 | // FIXME: We should be able to generate this USR even if the |
| 362 | // @interface isn't available. |
| 363 | IgnoreResults = true; |
| 364 | return; |
| 365 | } |
| 366 | GenObjCCategory(ID->getName(), CD->getName()); |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 367 | break; |
| 368 | } |
| 369 | case Decl::ObjCProtocol: |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 370 | GenObjCProtocol(cast<ObjCProtocolDecl>(D)->getName()); |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 371 | break; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | void USRGenerator::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Argyrios Kyrtzidis | 87ec9c2 | 2011-11-01 17:14:12 +0000 | [diff] [blame] | 376 | // The USR for a property declared in a class extension or category is based |
| 377 | // on the ObjCInterfaceDecl, not the ObjCCategoryDecl. |
| 378 | if (ObjCInterfaceDecl *ID = Context->getObjContainingInterface(D)) |
| 379 | Visit(ID); |
| 380 | else |
| 381 | Visit(cast<Decl>(D->getDeclContext())); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 382 | GenObjCProperty(D->getName()); |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 383 | } |
| 384 | |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 385 | void USRGenerator::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 386 | if (ObjCPropertyDecl *PD = D->getPropertyDecl()) { |
| 387 | VisitObjCPropertyDecl(PD); |
| 388 | return; |
| 389 | } |
| 390 | |
| 391 | IgnoreResults = true; |
| 392 | } |
| 393 | |
Ted Kremenek | b82b3be | 2010-01-18 22:42:20 +0000 | [diff] [blame] | 394 | void USRGenerator::VisitTagDecl(TagDecl *D) { |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 395 | // Add the location of the tag decl to handle resolution across |
| 396 | // translation units. |
| 397 | if (ShouldGenerateLocation(D) && GenLoc(D)) |
| 398 | return; |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 399 | |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 400 | D = D->getCanonicalDecl(); |
Ted Kremenek | b82b3be | 2010-01-18 22:42:20 +0000 | [diff] [blame] | 401 | VisitDeclContext(D->getDeclContext()); |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 402 | |
Douglas Gregor | 74dbe64 | 2010-08-31 19:31:58 +0000 | [diff] [blame] | 403 | bool AlreadyStarted = false; |
| 404 | if (CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(D)) { |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 405 | if (ClassTemplateDecl *ClassTmpl = CXXRecord->getDescribedClassTemplate()) { |
Douglas Gregor | 74dbe64 | 2010-08-31 19:31:58 +0000 | [diff] [blame] | 406 | AlreadyStarted = true; |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 407 | |
| 408 | switch (D->getTagKind()) { |
Douglas Gregor | 74dbe64 | 2010-08-31 19:31:58 +0000 | [diff] [blame] | 409 | case TTK_Struct: Out << "@ST"; break; |
| 410 | case TTK_Class: Out << "@CT"; break; |
| 411 | case TTK_Union: Out << "@UT"; break; |
| 412 | case TTK_Enum: llvm_unreachable("enum template"); break; |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 413 | } |
| 414 | VisitTemplateParameterList(ClassTmpl->getTemplateParameters()); |
Douglas Gregor | 74dbe64 | 2010-08-31 19:31:58 +0000 | [diff] [blame] | 415 | } else if (ClassTemplatePartialSpecializationDecl *PartialSpec |
| 416 | = dyn_cast<ClassTemplatePartialSpecializationDecl>(CXXRecord)) { |
| 417 | AlreadyStarted = true; |
| 418 | |
| 419 | switch (D->getTagKind()) { |
| 420 | case TTK_Struct: Out << "@SP"; break; |
| 421 | case TTK_Class: Out << "@CP"; break; |
| 422 | case TTK_Union: Out << "@UP"; break; |
| 423 | case TTK_Enum: llvm_unreachable("enum partial specialization"); break; |
| 424 | } |
| 425 | VisitTemplateParameterList(PartialSpec->getTemplateParameters()); |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 426 | } |
Douglas Gregor | 74dbe64 | 2010-08-31 19:31:58 +0000 | [diff] [blame] | 427 | } |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 428 | |
Douglas Gregor | 74dbe64 | 2010-08-31 19:31:58 +0000 | [diff] [blame] | 429 | if (!AlreadyStarted) { |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 430 | switch (D->getTagKind()) { |
| 431 | case TTK_Struct: Out << "@S"; break; |
| 432 | case TTK_Class: Out << "@C"; break; |
| 433 | case TTK_Union: Out << "@U"; break; |
| 434 | case TTK_Enum: Out << "@E"; break; |
| 435 | } |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 436 | } |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 437 | |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 438 | Out << '@'; |
| 439 | Out.flush(); |
| 440 | assert(Buf.size() > 0); |
| 441 | const unsigned off = Buf.size() - 1; |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 442 | |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 443 | if (EmitDeclName(D)) { |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 444 | if (const TypedefNameDecl *TD = D->getTypedefNameForAnonDecl()) { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 445 | Buf[off] = 'A'; |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 446 | Out << '@' << *TD; |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 447 | } |
| 448 | else |
| 449 | Buf[off] = 'a'; |
Ted Kremenek | c5b48b3 | 2010-01-15 23:34:31 +0000 | [diff] [blame] | 450 | } |
Douglas Gregor | 0ab1e9f | 2010-09-01 17:32:36 +0000 | [diff] [blame] | 451 | |
| 452 | // For a class template specialization, mangle the template arguments. |
| 453 | if (ClassTemplateSpecializationDecl *Spec |
| 454 | = dyn_cast<ClassTemplateSpecializationDecl>(D)) { |
| 455 | const TemplateArgumentList &Args = Spec->getTemplateInstantiationArgs(); |
| 456 | Out << '>'; |
| 457 | for (unsigned I = 0, N = Args.size(); I != N; ++I) { |
| 458 | Out << '#'; |
| 459 | VisitTemplateArgument(Args.get(I)); |
| 460 | } |
| 461 | } |
Ted Kremenek | c5b48b3 | 2010-01-15 23:34:31 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 464 | void USRGenerator::VisitTypedefDecl(TypedefDecl *D) { |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 465 | if (ShouldGenerateLocation(D) && GenLoc(D)) |
| 466 | return; |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 467 | DeclContext *DC = D->getDeclContext(); |
| 468 | if (NamedDecl *DCN = dyn_cast<NamedDecl>(DC)) |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 469 | Visit(DCN); |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 470 | Out << "@T@"; |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 471 | Out << D->getName(); |
| 472 | } |
| 473 | |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 474 | void USRGenerator::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 475 | GenLoc(D); |
| 476 | return; |
| 477 | } |
| 478 | |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 479 | bool USRGenerator::GenLoc(const Decl *D) { |
| 480 | if (generatedLoc) |
| 481 | return IgnoreResults; |
| 482 | generatedLoc = true; |
Ted Kremenek | 8c36758 | 2011-04-29 21:35:23 +0000 | [diff] [blame] | 483 | |
| 484 | // Guard against null declarations in invalid code. |
| 485 | if (!D) { |
| 486 | IgnoreResults = true; |
| 487 | return true; |
| 488 | } |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 489 | |
Ted Kremenek | 1d8052d | 2011-05-03 01:33:35 +0000 | [diff] [blame] | 490 | // Use the location of canonical decl. |
| 491 | D = D->getCanonicalDecl(); |
| 492 | |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 493 | const SourceManager &SM = Context->getSourceManager(); |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 494 | SourceLocation L = D->getLocStart(); |
| 495 | if (L.isInvalid()) { |
| 496 | IgnoreResults = true; |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 497 | return true; |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 498 | } |
Chandler Carruth | 4027853 | 2011-07-25 16:49:02 +0000 | [diff] [blame] | 499 | L = SM.getExpansionLoc(L); |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 500 | const std::pair<FileID, unsigned> &Decomposed = SM.getDecomposedLoc(L); |
| 501 | const FileEntry *FE = SM.getFileEntryForID(Decomposed.first); |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 502 | if (FE) { |
Michael J. Spencer | 472ccff | 2010-12-18 00:19:12 +0000 | [diff] [blame] | 503 | Out << llvm::sys::path::filename(FE->getName()); |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 504 | } |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 505 | else { |
| 506 | // This case really isn't interesting. |
| 507 | IgnoreResults = true; |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 508 | return true; |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 509 | } |
Ted Kremenek | f48b531 | 2010-07-22 11:14:15 +0000 | [diff] [blame] | 510 | // Use the offest into the FileID to represent the location. Using |
| 511 | // a line/column can cause us to look back at the original source file, |
| 512 | // which is expensive. |
| 513 | Out << '@' << Decomposed.second; |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 514 | return IgnoreResults; |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 515 | } |
| 516 | |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 517 | void USRGenerator::VisitType(QualType T) { |
| 518 | // This method mangles in USR information for types. It can possibly |
| 519 | // just reuse the naming-mangling logic used by codegen, although the |
| 520 | // requirements for USRs might not be the same. |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 521 | ASTContext &Ctx = *Context; |
Ted Kremenek | 2ea5baf | 2010-05-07 20:39:40 +0000 | [diff] [blame] | 522 | |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 523 | do { |
Ted Kremenek | 2ea5baf | 2010-05-07 20:39:40 +0000 | [diff] [blame] | 524 | T = Ctx.getCanonicalType(T); |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 525 | Qualifiers Q = T.getQualifiers(); |
Ted Kremenek | 2ea5baf | 2010-05-07 20:39:40 +0000 | [diff] [blame] | 526 | unsigned qVal = 0; |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 527 | if (Q.hasConst()) |
Ted Kremenek | 2ea5baf | 2010-05-07 20:39:40 +0000 | [diff] [blame] | 528 | qVal |= 0x1; |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 529 | if (Q.hasVolatile()) |
Ted Kremenek | 2ea5baf | 2010-05-07 20:39:40 +0000 | [diff] [blame] | 530 | qVal |= 0x2; |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 531 | if (Q.hasRestrict()) |
Ted Kremenek | 2ea5baf | 2010-05-07 20:39:40 +0000 | [diff] [blame] | 532 | qVal |= 0x4; |
| 533 | if(qVal) |
| 534 | Out << ((char) ('0' + qVal)); |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 535 | |
| 536 | // Mangle in ObjC GC qualifiers? |
| 537 | |
Douglas Gregor | ba73ada | 2011-01-19 20:50:07 +0000 | [diff] [blame] | 538 | if (const PackExpansionType *Expansion = T->getAs<PackExpansionType>()) { |
| 539 | Out << 'P'; |
| 540 | T = Expansion->getPattern(); |
| 541 | } |
| 542 | |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 543 | if (const BuiltinType *BT = T->getAs<BuiltinType>()) { |
| 544 | unsigned char c = '\0'; |
| 545 | switch (BT->getKind()) { |
| 546 | case BuiltinType::Void: |
| 547 | c = 'v'; break; |
| 548 | case BuiltinType::Bool: |
| 549 | c = 'b'; break; |
| 550 | case BuiltinType::Char_U: |
| 551 | case BuiltinType::UChar: |
| 552 | c = 'c'; break; |
| 553 | case BuiltinType::Char16: |
| 554 | c = 'q'; break; |
| 555 | case BuiltinType::Char32: |
| 556 | c = 'w'; break; |
| 557 | case BuiltinType::UShort: |
| 558 | c = 's'; break; |
| 559 | case BuiltinType::UInt: |
| 560 | c = 'i'; break; |
| 561 | case BuiltinType::ULong: |
| 562 | c = 'l'; break; |
| 563 | case BuiltinType::ULongLong: |
| 564 | c = 'k'; break; |
| 565 | case BuiltinType::UInt128: |
| 566 | c = 'j'; break; |
| 567 | case BuiltinType::Char_S: |
| 568 | case BuiltinType::SChar: |
| 569 | c = 'C'; break; |
Chris Lattner | 3f59c97 | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 570 | case BuiltinType::WChar_S: |
| 571 | case BuiltinType::WChar_U: |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 572 | c = 'W'; break; |
| 573 | case BuiltinType::Short: |
| 574 | c = 'S'; break; |
| 575 | case BuiltinType::Int: |
| 576 | c = 'I'; break; |
| 577 | case BuiltinType::Long: |
| 578 | c = 'L'; break; |
| 579 | case BuiltinType::LongLong: |
| 580 | c = 'K'; break; |
| 581 | case BuiltinType::Int128: |
| 582 | c = 'J'; break; |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 583 | case BuiltinType::Half: |
| 584 | c = 'h'; break; |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 585 | case BuiltinType::Float: |
| 586 | c = 'f'; break; |
| 587 | case BuiltinType::Double: |
| 588 | c = 'd'; break; |
| 589 | case BuiltinType::LongDouble: |
| 590 | c = 'D'; break; |
| 591 | case BuiltinType::NullPtr: |
| 592 | c = 'n'; break; |
John McCall | 2dde35b | 2011-10-18 22:28:37 +0000 | [diff] [blame] | 593 | #define BUILTIN_TYPE(Id, SingletonId) |
| 594 | #define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id: |
| 595 | #include "clang/AST/BuiltinTypes.def" |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 596 | case BuiltinType::Dependent: |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 597 | IgnoreResults = true; |
| 598 | return; |
| 599 | case BuiltinType::ObjCId: |
| 600 | c = 'o'; break; |
| 601 | case BuiltinType::ObjCClass: |
| 602 | c = 'O'; break; |
| 603 | case BuiltinType::ObjCSel: |
| 604 | c = 'e'; break; |
| 605 | } |
| 606 | Out << c; |
| 607 | return; |
| 608 | } |
Douglas Gregor | 66b7fbf | 2010-09-20 20:37:39 +0000 | [diff] [blame] | 609 | |
| 610 | // If we have already seen this (non-built-in) type, use a substitution |
| 611 | // encoding. |
| 612 | llvm::DenseMap<const Type *, unsigned>::iterator Substitution |
| 613 | = TypeSubstitutions.find(T.getTypePtr()); |
| 614 | if (Substitution != TypeSubstitutions.end()) { |
| 615 | Out << 'S' << Substitution->second << '_'; |
| 616 | return; |
| 617 | } else { |
| 618 | // Record this as a substitution. |
| 619 | unsigned Number = TypeSubstitutions.size(); |
| 620 | TypeSubstitutions[T.getTypePtr()] = Number; |
| 621 | } |
| 622 | |
| 623 | if (const PointerType *PT = T->getAs<PointerType>()) { |
| 624 | Out << '*'; |
| 625 | T = PT->getPointeeType(); |
| 626 | continue; |
| 627 | } |
| 628 | if (const ReferenceType *RT = T->getAs<ReferenceType>()) { |
| 629 | Out << '&'; |
| 630 | T = RT->getPointeeType(); |
| 631 | continue; |
| 632 | } |
| 633 | if (const FunctionProtoType *FT = T->getAs<FunctionProtoType>()) { |
| 634 | Out << 'F'; |
| 635 | VisitType(FT->getResultType()); |
| 636 | for (FunctionProtoType::arg_type_iterator |
| 637 | I = FT->arg_type_begin(), E = FT->arg_type_end(); I!=E; ++I) { |
| 638 | VisitType(*I); |
| 639 | } |
| 640 | if (FT->isVariadic()) |
| 641 | Out << '.'; |
| 642 | return; |
| 643 | } |
| 644 | if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) { |
| 645 | Out << 'B'; |
| 646 | T = BT->getPointeeType(); |
| 647 | continue; |
| 648 | } |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 649 | if (const ComplexType *CT = T->getAs<ComplexType>()) { |
| 650 | Out << '<'; |
| 651 | T = CT->getElementType(); |
| 652 | continue; |
| 653 | } |
Ted Kremenek | 2ea5baf | 2010-05-07 20:39:40 +0000 | [diff] [blame] | 654 | if (const TagType *TT = T->getAs<TagType>()) { |
| 655 | Out << '$'; |
| 656 | VisitTagDecl(TT->getDecl()); |
| 657 | return; |
| 658 | } |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 659 | if (const TemplateTypeParmType *TTP = T->getAs<TemplateTypeParmType>()) { |
| 660 | Out << 't' << TTP->getDepth() << '.' << TTP->getIndex(); |
| 661 | return; |
| 662 | } |
| 663 | if (const TemplateSpecializationType *Spec |
| 664 | = T->getAs<TemplateSpecializationType>()) { |
| 665 | Out << '>'; |
| 666 | VisitTemplateName(Spec->getTemplateName()); |
| 667 | Out << Spec->getNumArgs(); |
| 668 | for (unsigned I = 0, N = Spec->getNumArgs(); I != N; ++I) |
| 669 | VisitTemplateArgument(Spec->getArg(I)); |
| 670 | return; |
| 671 | } |
| 672 | |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 673 | // Unhandled type. |
| 674 | Out << ' '; |
| 675 | break; |
| 676 | } while (true); |
| 677 | } |
| 678 | |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 679 | void USRGenerator::VisitTemplateParameterList( |
| 680 | const TemplateParameterList *Params) { |
| 681 | if (!Params) |
| 682 | return; |
| 683 | Out << '>' << Params->size(); |
| 684 | for (TemplateParameterList::const_iterator P = Params->begin(), |
| 685 | PEnd = Params->end(); |
| 686 | P != PEnd; ++P) { |
| 687 | Out << '#'; |
| 688 | if (isa<TemplateTypeParmDecl>(*P)) { |
Douglas Gregor | ba73ada | 2011-01-19 20:50:07 +0000 | [diff] [blame] | 689 | if (cast<TemplateTypeParmDecl>(*P)->isParameterPack()) |
| 690 | Out<< 'p'; |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 691 | Out << 'T'; |
| 692 | continue; |
| 693 | } |
| 694 | |
| 695 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) { |
Douglas Gregor | ba73ada | 2011-01-19 20:50:07 +0000 | [diff] [blame] | 696 | if (NTTP->isParameterPack()) |
| 697 | Out << 'p'; |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 698 | Out << 'N'; |
| 699 | VisitType(NTTP->getType()); |
| 700 | continue; |
| 701 | } |
| 702 | |
| 703 | TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*P); |
Douglas Gregor | ba73ada | 2011-01-19 20:50:07 +0000 | [diff] [blame] | 704 | if (TTP->isParameterPack()) |
| 705 | Out << 'p'; |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 706 | Out << 't'; |
| 707 | VisitTemplateParameterList(TTP->getTemplateParameters()); |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | void USRGenerator::VisitTemplateName(TemplateName Name) { |
| 712 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 713 | if (TemplateTemplateParmDecl *TTP |
| 714 | = dyn_cast<TemplateTemplateParmDecl>(Template)) { |
| 715 | Out << 't' << TTP->getDepth() << '.' << TTP->getIndex(); |
| 716 | return; |
| 717 | } |
| 718 | |
| 719 | Visit(Template); |
| 720 | return; |
| 721 | } |
| 722 | |
| 723 | // FIXME: Visit dependent template names. |
| 724 | } |
| 725 | |
| 726 | void USRGenerator::VisitTemplateArgument(const TemplateArgument &Arg) { |
| 727 | switch (Arg.getKind()) { |
| 728 | case TemplateArgument::Null: |
| 729 | break; |
| 730 | |
| 731 | case TemplateArgument::Declaration: |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 732 | if (Decl *D = Arg.getAsDecl()) |
| 733 | Visit(D); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 734 | break; |
| 735 | |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 736 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | ba73ada | 2011-01-19 20:50:07 +0000 | [diff] [blame] | 737 | Out << 'P'; // pack expansion of... |
| 738 | // Fall through |
| 739 | case TemplateArgument::Template: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 740 | VisitTemplateName(Arg.getAsTemplateOrTemplatePattern()); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 741 | break; |
| 742 | |
| 743 | case TemplateArgument::Expression: |
| 744 | // FIXME: Visit expressions. |
| 745 | break; |
| 746 | |
| 747 | case TemplateArgument::Pack: |
Douglas Gregor | ba73ada | 2011-01-19 20:50:07 +0000 | [diff] [blame] | 748 | Out << 'p' << Arg.pack_size(); |
| 749 | for (TemplateArgument::pack_iterator P = Arg.pack_begin(), PEnd = Arg.pack_end(); |
| 750 | P != PEnd; ++P) |
| 751 | VisitTemplateArgument(*P); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 752 | break; |
| 753 | |
| 754 | case TemplateArgument::Type: |
| 755 | VisitType(Arg.getAsType()); |
| 756 | break; |
| 757 | |
| 758 | case TemplateArgument::Integral: |
| 759 | Out << 'V'; |
| 760 | VisitType(Arg.getIntegralType()); |
| 761 | Out << *Arg.getAsIntegral(); |
| 762 | break; |
| 763 | } |
| 764 | } |
| 765 | |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 766 | //===----------------------------------------------------------------------===// |
| 767 | // General purpose USR generation methods. |
| 768 | //===----------------------------------------------------------------------===// |
Ted Kremenek | cf84aa4 | 2010-01-18 20:23:29 +0000 | [diff] [blame] | 769 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 770 | void USRGenerator::GenObjCClass(StringRef cls) { |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 771 | Out << "objc(cs)" << cls; |
| 772 | } |
| 773 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 774 | void USRGenerator::GenObjCCategory(StringRef cls, StringRef cat) { |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 775 | Out << "objc(cy)" << cls << '@' << cat; |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 776 | } |
| 777 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 778 | void USRGenerator::GenObjCIvar(StringRef ivar) { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 779 | Out << '@' << ivar; |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 780 | } |
| 781 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 782 | void USRGenerator::GenObjCMethod(StringRef meth, bool isInstanceMethod) { |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 783 | Out << (isInstanceMethod ? "(im)" : "(cm)") << meth; |
| 784 | } |
| 785 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 786 | void USRGenerator::GenObjCProperty(StringRef prop) { |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 787 | Out << "(py)" << prop; |
| 788 | } |
| 789 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 790 | void USRGenerator::GenObjCProtocol(StringRef prot) { |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 791 | Out << "objc(pl)" << prot; |
| 792 | } |
| 793 | |
| 794 | //===----------------------------------------------------------------------===// |
| 795 | // API hooks. |
| 796 | //===----------------------------------------------------------------------===// |
Ted Kremenek | cf84aa4 | 2010-01-18 20:23:29 +0000 | [diff] [blame] | 797 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 798 | static inline StringRef extractUSRSuffix(StringRef s) { |
Benjamin Kramer | cfb51b6 | 2010-04-08 15:54:07 +0000 | [diff] [blame] | 799 | return s.startswith("c:") ? s.substr(2) : ""; |
| 800 | } |
| 801 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 802 | bool cxcursor::getDeclCursorUSR(const Decl *D, SmallVectorImpl<char> &Buf) { |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 803 | // Don't generate USRs for things with invalid locations. |
| 804 | if (!D || D->getLocStart().isInvalid()) |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 805 | return true; |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 806 | |
Ted Kremenek | 1865cfe | 2010-04-15 21:04:25 +0000 | [diff] [blame] | 807 | // Check if the cursor has 'NoLinkage'. |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 808 | if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) |
Ted Kremenek | 1865cfe | 2010-04-15 21:04:25 +0000 | [diff] [blame] | 809 | switch (ND->getLinkage()) { |
| 810 | case ExternalLinkage: |
| 811 | // Generate USRs for all entities with external linkage. |
| 812 | break; |
| 813 | case NoLinkage: |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 814 | case UniqueExternalLinkage: |
Ted Kremenek | 1865cfe | 2010-04-15 21:04:25 +0000 | [diff] [blame] | 815 | // We allow enums, typedefs, and structs that have no linkage to |
| 816 | // have USRs that are anchored to the file they were defined in |
| 817 | // (e.g., the header). This is a little gross, but in principal |
| 818 | // enums/anonymous structs/etc. defined in a common header file |
| 819 | // are referred to across multiple translation units. |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 820 | if (isa<TagDecl>(ND) || isa<TypedefDecl>(ND) || |
Ted Kremenek | cf99910 | 2010-04-29 17:43:29 +0000 | [diff] [blame] | 821 | isa<EnumConstantDecl>(ND) || isa<FieldDecl>(ND) || |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 822 | isa<VarDecl>(ND) || isa<NamespaceDecl>(ND)) |
Ted Kremenek | 1865cfe | 2010-04-15 21:04:25 +0000 | [diff] [blame] | 823 | break; |
| 824 | // Fall-through. |
| 825 | case InternalLinkage: |
Ted Kremenek | cf99910 | 2010-04-29 17:43:29 +0000 | [diff] [blame] | 826 | if (isa<FunctionDecl>(ND)) |
| 827 | break; |
Ted Kremenek | 1865cfe | 2010-04-15 21:04:25 +0000 | [diff] [blame] | 828 | } |
| 829 | |
Ted Kremenek | f019943 | 2010-11-16 08:15:38 +0000 | [diff] [blame] | 830 | { |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 831 | USRGenerator UG(&D->getASTContext(), &Buf); |
Benjamin Kramer | 854625f | 2011-10-28 13:37:11 +0000 | [diff] [blame] | 832 | UG->Visit(const_cast<Decl*>(D)); |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 833 | |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 834 | if (UG->ignoreResults()) |
| 835 | return true; |
Ted Kremenek | f019943 | 2010-11-16 08:15:38 +0000 | [diff] [blame] | 836 | } |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 837 | |
| 838 | return false; |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 839 | } |
| 840 | |
Ted Kremenek | c3ef91d | 2010-04-11 22:20:26 +0000 | [diff] [blame] | 841 | extern "C" { |
| 842 | |
| 843 | CXString clang_getCursorUSR(CXCursor C) { |
Ted Kremenek | fa8231d | 2010-04-11 22:20:34 +0000 | [diff] [blame] | 844 | const CXCursorKind &K = clang_getCursorKind(C); |
| 845 | |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 846 | if (clang_isDeclaration(K)) { |
| 847 | Decl *D = cxcursor::getCursorDecl(C); |
| 848 | CXTranslationUnit TU = cxcursor::getCursorTU(C); |
| 849 | if (!TU) |
| 850 | return createCXString(""); |
| 851 | |
| 852 | CXStringBuf *buf = cxstring::getCXStringBuf(TU); |
| 853 | if (!buf) |
| 854 | return createCXString(""); |
| 855 | |
| 856 | bool Ignore = cxcursor::getDeclCursorUSR(D, buf->Data); |
| 857 | if (Ignore) { |
| 858 | disposeCXStringBuf(buf); |
| 859 | return createCXString(""); |
| 860 | } |
| 861 | |
| 862 | // Return the C-string, but don't make a copy since it is already in |
| 863 | // the string buffer. |
| 864 | buf->Data.push_back('\0'); |
| 865 | return createCXString(buf); |
| 866 | } |
Ted Kremenek | fa8231d | 2010-04-11 22:20:34 +0000 | [diff] [blame] | 867 | |
| 868 | if (K == CXCursor_MacroDefinition) { |
Ted Kremenek | f019943 | 2010-11-16 08:15:38 +0000 | [diff] [blame] | 869 | CXTranslationUnit TU = cxcursor::getCursorTU(C); |
| 870 | if (!TU) |
| 871 | return createCXString(""); |
| 872 | |
| 873 | CXStringBuf *buf = cxstring::getCXStringBuf(TU); |
| 874 | if (!buf) |
| 875 | return createCXString(""); |
| 876 | |
| 877 | { |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 878 | USRGenerator UG(&cxcursor::getCursorASTUnit(C)->getASTContext(), |
| 879 | &buf->Data); |
Ted Kremenek | f019943 | 2010-11-16 08:15:38 +0000 | [diff] [blame] | 880 | UG << "macro@" |
| 881 | << cxcursor::getCursorMacroDefinition(C)->getName()->getNameStart(); |
| 882 | } |
| 883 | buf->Data.push_back('\0'); |
| 884 | return createCXString(buf); |
Ted Kremenek | fa8231d | 2010-04-11 22:20:34 +0000 | [diff] [blame] | 885 | } |
| 886 | |
Ted Kremenek | c3ef91d | 2010-04-11 22:20:26 +0000 | [diff] [blame] | 887 | return createCXString(""); |
| 888 | } |
| 889 | |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 890 | CXString clang_constructUSR_ObjCIvar(const char *name, CXString classUSR) { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 891 | USRGenerator UG; |
| 892 | UG << extractUSRSuffix(clang_getCString(classUSR)); |
| 893 | UG->GenObjCIvar(name); |
| 894 | return createCXString(UG.str(), true); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | CXString clang_constructUSR_ObjCMethod(const char *name, |
| 898 | unsigned isInstanceMethod, |
| 899 | CXString classUSR) { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 900 | USRGenerator UG; |
| 901 | UG << extractUSRSuffix(clang_getCString(classUSR)); |
| 902 | UG->GenObjCMethod(name, isInstanceMethod); |
| 903 | return createCXString(UG.str(), true); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | CXString clang_constructUSR_ObjCClass(const char *name) { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 907 | USRGenerator UG; |
| 908 | UG->GenObjCClass(name); |
| 909 | return createCXString(UG.str(), true); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | CXString clang_constructUSR_ObjCProtocol(const char *name) { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 913 | USRGenerator UG; |
| 914 | UG->GenObjCProtocol(name); |
| 915 | return createCXString(UG.str(), true); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 916 | } |
| 917 | |
Ted Kremenek | 66ccaec | 2010-03-15 17:38:58 +0000 | [diff] [blame] | 918 | CXString clang_constructUSR_ObjCCategory(const char *class_name, |
Ted Kremenek | 0c0fb41 | 2010-03-25 02:00:36 +0000 | [diff] [blame] | 919 | const char *category_name) { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 920 | USRGenerator UG; |
| 921 | UG->GenObjCCategory(class_name, category_name); |
| 922 | return createCXString(UG.str(), true); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | CXString clang_constructUSR_ObjCProperty(const char *property, |
| 926 | CXString classUSR) { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 927 | USRGenerator UG; |
| 928 | UG << extractUSRSuffix(clang_getCString(classUSR)); |
| 929 | UG->GenObjCProperty(property); |
| 930 | return createCXString(UG.str(), true); |
Ted Kremenek | cf84aa4 | 2010-01-18 20:23:29 +0000 | [diff] [blame] | 931 | } |
Ted Kremenek | 1b6869a | 2010-01-05 22:06:45 +0000 | [diff] [blame] | 932 | |
Ted Kremenek | 1b6869a | 2010-01-05 22:06:45 +0000 | [diff] [blame] | 933 | } // end extern "C" |