blob: 30173d3e7edfab6cd25986c5d5cae3efa25d9616 [file] [log] [blame]
Ted Kremenek1b6869a2010-01-05 22:06:45 +00001//===- 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 Kremenekcf84aa42010-01-18 20:23:29 +000015#include "CXCursor.h"
Ted Kremeneked122732010-11-16 01:56:27 +000016#include "CXString.h"
Douglas Gregorfe72e9c2010-08-31 17:01:39 +000017#include "clang/AST/DeclTemplate.h"
Benjamin Kramer9895c6a2010-01-12 11:32:40 +000018#include "clang/AST/DeclVisitor.h"
Ted Kremenek6f153952010-04-15 21:51:13 +000019#include "clang/Frontend/ASTUnit.h"
Benjamin Kramerb846deb2010-04-12 19:45:50 +000020#include "clang/Lex/PreprocessingRecord.h"
Ted Kremenek87763822010-01-12 02:07:58 +000021#include "llvm/ADT/SmallString.h"
Benjamin Kramer9895c6a2010-01-12 11:32:40 +000022#include "llvm/Support/raw_ostream.h"
Ted Kremenek6f153952010-04-15 21:51:13 +000023
Benjamin Kramerb846deb2010-04-12 19:45:50 +000024using namespace clang;
Ted Kremenekee4db4f2010-02-17 00:41:08 +000025using namespace clang::cxstring;
26
Ted Kremenekc50277f2010-01-12 23:33:42 +000027//===----------------------------------------------------------------------===//
28// USR generation.
29//===----------------------------------------------------------------------===//
30
31namespace {
Ted Kremenek2fee4e62010-01-14 01:50:21 +000032class USRGenerator : public DeclVisitor<USRGenerator> {
Ted Kremenekf0199432010-11-16 08:15:38 +000033 llvm::OwningPtr<llvm::SmallString<128> > OwnedBuf;
34 llvm::SmallVectorImpl<char> &Buf;
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +000035 llvm::raw_svector_ostream Out;
Ted Kremenek3adca6d2010-01-18 22:02:49 +000036 bool IgnoreResults;
Ted Kremenek1865cfe2010-04-15 21:04:25 +000037 ASTUnit *AU;
Ted Kremenekcbd66f02010-05-06 23:38:28 +000038 bool generatedLoc;
Douglas Gregor66b7fbf2010-09-20 20:37:39 +000039
40 llvm::DenseMap<const Type *, unsigned> TypeSubstitutions;
41
Ted Kremenek2fee4e62010-01-14 01:50:21 +000042public:
Ted Kremenekf0199432010-11-16 08:15:38 +000043 USRGenerator(const CXCursor *C = 0, llvm::SmallVectorImpl<char> *extBuf = 0)
44 : OwnedBuf(extBuf ? 0 : new llvm::SmallString<128>()),
45 Buf(extBuf ? *extBuf : *OwnedBuf.get()),
46 Out(Buf),
47 IgnoreResults(false),
48 AU(C ? cxcursor::getCursorASTUnit(*C) : 0),
49 generatedLoc(false)
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +000050 {
51 // Add the USR space prefix.
52 Out << "c:";
53 }
54
55 llvm::StringRef str() {
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 Kremenek896b70f2010-03-13 02:50:34 +000066
Ted Kremenek3adca6d2010-01-18 22:02:49 +000067 bool ignoreResults() const { return IgnoreResults; }
Ted Kremenek896b70f2010-03-13 02:50:34 +000068
69 // Visitation methods from generating USRs from AST elements.
Ted Kremenek2fee4e62010-01-14 01:50:21 +000070 void VisitDeclContext(DeclContext *D);
Ted Kremenek3adca6d2010-01-18 22:02:49 +000071 void VisitFieldDecl(FieldDecl *D);
Ted Kremenek2fee4e62010-01-14 01:50:21 +000072 void VisitFunctionDecl(FunctionDecl *D);
73 void VisitNamedDecl(NamedDecl *D);
74 void VisitNamespaceDecl(NamespaceDecl *D);
Douglas Gregor69319002010-08-31 23:48:11 +000075 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Douglas Gregorfe72e9c2010-08-31 17:01:39 +000076 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Douglas Gregor39d6f072010-08-31 19:02:00 +000077 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Ted Kremeneke74ef122010-04-16 21:31:52 +000078 void VisitObjCClassDecl(ObjCClassDecl *CD);
Ted Kremenek896b70f2010-03-13 02:50:34 +000079 void VisitObjCContainerDecl(ObjCContainerDecl *CD);
Ted Kremeneke74ef122010-04-16 21:31:52 +000080 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *P);
Ted Kremeneke542f772010-04-20 23:15:40 +000081 void VisitObjCMethodDecl(ObjCMethodDecl *MD);
Ted Kremenek2fee4e62010-01-14 01:50:21 +000082 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
Ted Kremeneke542f772010-04-20 23:15:40 +000083 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
Ted Kremenekb82b3be2010-01-18 22:42:20 +000084 void VisitTagDecl(TagDecl *D);
Ted Kremenek2fee4e62010-01-14 01:50:21 +000085 void VisitTypedefDecl(TypedefDecl *D);
Douglas Gregorfe72e9c2010-08-31 17:01:39 +000086 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Ted Kremeneke542f772010-04-20 23:15:40 +000087 void VisitVarDecl(VarDecl *D);
Douglas Gregorfe72e9c2010-08-31 17:01:39 +000088 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
89 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Ted Kremenek8e672192010-05-07 01:04:32 +000090 void VisitLinkageSpecDecl(LinkageSpecDecl *D) {
91 IgnoreResults = true;
Ted Kremenek8e672192010-05-07 01:04:32 +000092 }
Douglas Gregor0a35bce2010-09-01 03:07:18 +000093 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
94 IgnoreResults = true;
95 }
Douglas Gregor7e242562010-09-01 19:52:22 +000096 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 Gregor0a35bce2010-09-01 03:07:18 +0000105
Ted Kremenek6f153952010-04-15 21:51:13 +0000106 /// Generate the string component containing the location of the
107 /// declaration.
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000108 bool GenLoc(const Decl *D);
Ted Kremenek6f153952010-04-15 21:51:13 +0000109
Ted Kremenek896b70f2010-03-13 02:50:34 +0000110 /// 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 Kremenek896b70f2010-03-13 02:50:34 +0000116 /// Generate a USR for an Objective-C class.
117 void GenObjCClass(llvm::StringRef cls);
118 /// Generate a USR for an Objective-C class category.
119 void GenObjCCategory(llvm::StringRef cls, llvm::StringRef cat);
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.
123 void GenObjCIvar(llvm::StringRef ivar);
124 /// Generate a USR fragment for an Objective-C method.
125 void GenObjCMethod(llvm::StringRef sel, bool isInstanceMethod);
126 /// Generate a USR fragment for an Objective-C property.
127 void GenObjCProperty(llvm::StringRef prop);
128 /// Generate a USR for an Objective-C protocol.
129 void GenObjCProtocol(llvm::StringRef prot);
Ted Kremenek8e672192010-05-07 01:04:32 +0000130
131 void VisitType(QualType T);
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000132 void VisitTemplateParameterList(const TemplateParameterList *Params);
133 void VisitTemplateName(TemplateName Name);
134 void VisitTemplateArgument(const TemplateArgument &Arg);
135
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000136 /// 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 Kremenek896b70f2010-03-13 02:50:34 +0000139};
140
Ted Kremenekc50277f2010-01-12 23:33:42 +0000141} // end anonymous namespace
142
Ted Kremenek896b70f2010-03-13 02:50:34 +0000143//===----------------------------------------------------------------------===//
144// Generating USRs from ASTS.
145//===----------------------------------------------------------------------===//
146
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000147bool 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 Kremenekcbd66f02010-05-06 23:38:28 +0000156static bool InAnonymousNamespace(const Decl *D) {
157 if (const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(D->getDeclContext()))
158 return ND->isAnonymousNamespace();
159 return false;
160}
161
162static inline bool ShouldGenerateLocation(const NamedDecl *D) {
163 return D->getLinkage() != ExternalLinkage && !InAnonymousNamespace(D);
164}
165
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000166void USRGenerator::VisitDeclContext(DeclContext *DC) {
167 if (NamedDecl *D = dyn_cast<NamedDecl>(DC))
168 Visit(D);
169}
170
Ted Kremenek3adca6d2010-01-18 22:02:49 +0000171void USRGenerator::VisitFieldDecl(FieldDecl *D) {
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000172 VisitDeclContext(D->getDeclContext());
173 Out << (isa<ObjCIvarDecl>(D) ? "@" : "@FI@");
174 if (EmitDeclName(D)) {
Ted Kremenek3adca6d2010-01-18 22:02:49 +0000175 // Bit fields can be anonymous.
176 IgnoreResults = true;
177 return;
178 }
Ted Kremenek3adca6d2010-01-18 22:02:49 +0000179}
180
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000181void USRGenerator::VisitFunctionDecl(FunctionDecl *D) {
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000182 if (ShouldGenerateLocation(D) && GenLoc(D))
183 return;
Ted Kremenekcf999102010-04-29 17:43:29 +0000184
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000185 VisitDeclContext(D->getDeclContext());
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000186 if (FunctionTemplateDecl *FunTmpl = D->getDescribedFunctionTemplate()) {
187 Out << "@FT@";
188 VisitTemplateParameterList(FunTmpl->getTemplateParameters());
189 } else
190 Out << "@F@";
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000191 D->printName(Out);
Ted Kremenek8e672192010-05-07 01:04:32 +0000192
193 ASTContext &Ctx = AU->getASTContext();
194 if (!Ctx.getLangOptions().CPlusPlus || D->isExternC())
195 return;
196
197 // Mangle in type information for the arguments.
198 for (FunctionDecl::param_iterator I = D->param_begin(), E = D->param_end();
199 I != E; ++I) {
200 Out << '#';
201 if (ParmVarDecl *PD = *I)
202 VisitType(PD->getType());
203 }
204 if (D->isVariadic())
205 Out << '.';
Ted Kremenek2ea5baf2010-05-07 20:39:40 +0000206 Out << '#';
207 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
208 if (MD->isStatic())
209 Out << 'S';
210 if (unsigned quals = MD->getTypeQualifiers())
211 Out << (char)('0' + quals);
212 }
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000213}
Ted Kremenekc50277f2010-01-12 23:33:42 +0000214
215void USRGenerator::VisitNamedDecl(NamedDecl *D) {
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000216 VisitDeclContext(D->getDeclContext());
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000217 Out << "@";
218
219 if (EmitDeclName(D)) {
220 // The string can be empty if the declaration has no name; e.g., it is
221 // the ParmDecl with no name for declaration of a function pointer type,
222 // e.g.: void (*f)(void *);
223 // In this case, don't generate a USR.
Ted Kremeneke74ef122010-04-16 21:31:52 +0000224 IgnoreResults = true;
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000225 }
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000226}
227
Ted Kremeneke542f772010-04-20 23:15:40 +0000228void USRGenerator::VisitVarDecl(VarDecl *D) {
229 // VarDecls can be declared 'extern' within a function or method body,
230 // but their enclosing DeclContext is the function, not the TU. We need
231 // to check the storage class to correctly generate the USR.
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000232 if (ShouldGenerateLocation(D) && GenLoc(D))
233 return;
234
235 VisitDeclContext(D->getDeclContext());
Ted Kremeneke542f772010-04-20 23:15:40 +0000236
Ted Kremenekcf999102010-04-29 17:43:29 +0000237 // Variables always have simple names.
238 llvm::StringRef s = D->getName();
239
Ted Kremeneke542f772010-04-20 23:15:40 +0000240 // The string can be empty if the declaration has no name; e.g., it is
241 // the ParmDecl with no name for declaration of a function pointer type, e.g.:
Eli Friedmana7e68452010-08-22 01:00:03 +0000242 // void (*f)(void *);
Ted Kremeneke542f772010-04-20 23:15:40 +0000243 // In this case, don't generate a USR.
244 if (s.empty())
245 IgnoreResults = true;
246 else
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000247 Out << '@' << s;
Ted Kremeneke542f772010-04-20 23:15:40 +0000248}
249
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000250void USRGenerator::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
251 GenLoc(D);
252 return;
253}
254
255void USRGenerator::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
256 GenLoc(D);
257 return;
258}
259
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000260void USRGenerator::VisitNamespaceDecl(NamespaceDecl *D) {
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000261 if (D->isAnonymousNamespace()) {
262 Out << "@aN";
263 return;
264 }
265
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000266 VisitDeclContext(D->getDeclContext());
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000267 if (!IgnoreResults)
268 Out << "@N@" << D->getName();
Ted Kremenekc50277f2010-01-12 23:33:42 +0000269}
270
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000271void USRGenerator::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
272 VisitFunctionDecl(D->getTemplatedDecl());
273}
274
Douglas Gregor39d6f072010-08-31 19:02:00 +0000275void USRGenerator::VisitClassTemplateDecl(ClassTemplateDecl *D) {
276 VisitTagDecl(D->getTemplatedDecl());
277}
278
Douglas Gregor69319002010-08-31 23:48:11 +0000279void USRGenerator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
280 VisitDeclContext(D->getDeclContext());
281 if (!IgnoreResults)
282 Out << "@NA@" << D->getName();
283}
Douglas Gregor39d6f072010-08-31 19:02:00 +0000284
Ted Kremenekc50277f2010-01-12 23:33:42 +0000285void USRGenerator::VisitObjCMethodDecl(ObjCMethodDecl *D) {
Ted Kremenek52d6bbe2011-02-05 01:10:26 +0000286 DeclContext *container = D->getDeclContext();
287 if (ObjCProtocolDecl *pd = dyn_cast<ObjCProtocolDecl>(container)) {
288 Visit(pd);
Ted Kremenek28a7f252010-08-24 23:13:41 +0000289 }
Ted Kremenek52d6bbe2011-02-05 01:10:26 +0000290 else {
291 // The USR for a method declared in a class extension or category is based on
292 // the ObjCInterfaceDecl, not the ObjCCategoryDecl.
293 ObjCInterfaceDecl *ID = D->getClassInterface();
294 if (!ID) {
295 IgnoreResults = true;
296 return;
297 }
298 Visit(ID);
299 }
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000300 // Ideally we would use 'GenObjCMethod', but this is such a hot path
301 // for Objective-C code that we don't want to use
302 // DeclarationName::getAsString().
303 Out << (D->isInstanceMethod() ? "(im)" : "(cm)");
304 DeclarationName N(D->getSelector());
305 N.printName(Out);
Ted Kremenekc50277f2010-01-12 23:33:42 +0000306}
307
Ted Kremeneke74ef122010-04-16 21:31:52 +0000308void USRGenerator::VisitObjCClassDecl(ObjCClassDecl *D) {
309 // FIXME: @class declarations can refer to multiple classes. We need
310 // to be able to traverse these.
311 IgnoreResults = true;
312}
313
314void USRGenerator::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
315 // FIXME: @protocol declarations can refer to multiple protocols. We need
316 // to be able to traverse these.
317 IgnoreResults = true;
318}
319
Ted Kremenekc50277f2010-01-12 23:33:42 +0000320void USRGenerator::VisitObjCContainerDecl(ObjCContainerDecl *D) {
321 switch (D->getKind()) {
322 default:
323 assert(false && "Invalid ObjC container.");
324 case Decl::ObjCInterface:
325 case Decl::ObjCImplementation:
Ted Kremenek896b70f2010-03-13 02:50:34 +0000326 GenObjCClass(D->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000327 break;
328 case Decl::ObjCCategory: {
329 ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(D);
Ted Kremenekebfa3392010-03-19 20:39:03 +0000330 ObjCInterfaceDecl *ID = CD->getClassInterface();
331 if (!ID) {
332 // Handle invalid code where the @interface might not
333 // have been specified.
334 // FIXME: We should be able to generate this USR even if the
335 // @interface isn't available.
336 IgnoreResults = true;
337 return;
338 }
Ted Kremenek28a7f252010-08-24 23:13:41 +0000339 // Specially handle class extensions, which are anonymous categories.
340 // We want to mangle in the location to uniquely distinguish them.
341 if (CD->IsClassExtension()) {
342 Out << "objc(ext)" << ID->getName() << '@';
343 GenLoc(CD);
344 }
345 else
346 GenObjCCategory(ID->getName(), CD->getName());
347
Ted Kremenekc50277f2010-01-12 23:33:42 +0000348 break;
349 }
350 case Decl::ObjCCategoryImpl: {
351 ObjCCategoryImplDecl *CD = cast<ObjCCategoryImplDecl>(D);
Ted Kremenekebfa3392010-03-19 20:39:03 +0000352 ObjCInterfaceDecl *ID = CD->getClassInterface();
353 if (!ID) {
354 // Handle invalid code where the @interface might not
355 // have been specified.
356 // FIXME: We should be able to generate this USR even if the
357 // @interface isn't available.
358 IgnoreResults = true;
359 return;
360 }
361 GenObjCCategory(ID->getName(), CD->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000362 break;
363 }
364 case Decl::ObjCProtocol:
Ted Kremenek896b70f2010-03-13 02:50:34 +0000365 GenObjCProtocol(cast<ObjCProtocolDecl>(D)->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000366 break;
367 }
368}
369
370void USRGenerator::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
371 Visit(cast<Decl>(D->getDeclContext()));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000372 GenObjCProperty(D->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000373}
374
Ted Kremeneke542f772010-04-20 23:15:40 +0000375void USRGenerator::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
376 if (ObjCPropertyDecl *PD = D->getPropertyDecl()) {
377 VisitObjCPropertyDecl(PD);
378 return;
379 }
380
381 IgnoreResults = true;
382}
383
Ted Kremenekb82b3be2010-01-18 22:42:20 +0000384void USRGenerator::VisitTagDecl(TagDecl *D) {
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000385 // Add the location of the tag decl to handle resolution across
386 // translation units.
387 if (ShouldGenerateLocation(D) && GenLoc(D))
388 return;
Ted Kremenek8e672192010-05-07 01:04:32 +0000389
Ted Kremenek6f153952010-04-15 21:51:13 +0000390 D = D->getCanonicalDecl();
Ted Kremenekb82b3be2010-01-18 22:42:20 +0000391 VisitDeclContext(D->getDeclContext());
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000392
Douglas Gregor74dbe642010-08-31 19:31:58 +0000393 bool AlreadyStarted = false;
394 if (CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(D)) {
Douglas Gregor39d6f072010-08-31 19:02:00 +0000395 if (ClassTemplateDecl *ClassTmpl = CXXRecord->getDescribedClassTemplate()) {
Douglas Gregor74dbe642010-08-31 19:31:58 +0000396 AlreadyStarted = true;
Douglas Gregor39d6f072010-08-31 19:02:00 +0000397
398 switch (D->getTagKind()) {
Douglas Gregor74dbe642010-08-31 19:31:58 +0000399 case TTK_Struct: Out << "@ST"; break;
400 case TTK_Class: Out << "@CT"; break;
401 case TTK_Union: Out << "@UT"; break;
402 case TTK_Enum: llvm_unreachable("enum template"); break;
Douglas Gregor39d6f072010-08-31 19:02:00 +0000403 }
404 VisitTemplateParameterList(ClassTmpl->getTemplateParameters());
Douglas Gregor74dbe642010-08-31 19:31:58 +0000405 } else if (ClassTemplatePartialSpecializationDecl *PartialSpec
406 = dyn_cast<ClassTemplatePartialSpecializationDecl>(CXXRecord)) {
407 AlreadyStarted = true;
408
409 switch (D->getTagKind()) {
410 case TTK_Struct: Out << "@SP"; break;
411 case TTK_Class: Out << "@CP"; break;
412 case TTK_Union: Out << "@UP"; break;
413 case TTK_Enum: llvm_unreachable("enum partial specialization"); break;
414 }
415 VisitTemplateParameterList(PartialSpec->getTemplateParameters());
Douglas Gregor39d6f072010-08-31 19:02:00 +0000416 }
Douglas Gregor74dbe642010-08-31 19:31:58 +0000417 }
Douglas Gregor39d6f072010-08-31 19:02:00 +0000418
Douglas Gregor74dbe642010-08-31 19:31:58 +0000419 if (!AlreadyStarted) {
Douglas Gregor39d6f072010-08-31 19:02:00 +0000420 switch (D->getTagKind()) {
421 case TTK_Struct: Out << "@S"; break;
422 case TTK_Class: Out << "@C"; break;
423 case TTK_Union: Out << "@U"; break;
424 case TTK_Enum: Out << "@E"; break;
425 }
Ted Kremeneke74ef122010-04-16 21:31:52 +0000426 }
Douglas Gregor39d6f072010-08-31 19:02:00 +0000427
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000428 Out << '@';
429 Out.flush();
430 assert(Buf.size() > 0);
431 const unsigned off = Buf.size() - 1;
Ted Kremenek896b70f2010-03-13 02:50:34 +0000432
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000433 if (EmitDeclName(D)) {
Richard Smith162e1c12011-04-15 14:24:37 +0000434 if (const TypedefNameDecl *TD = D->getTypedefNameForAnonDecl()) {
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000435 Buf[off] = 'A';
Benjamin Kramer900fc632010-04-17 09:33:03 +0000436 Out << '@' << TD;
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000437 }
438 else
439 Buf[off] = 'a';
Ted Kremenekc5b48b32010-01-15 23:34:31 +0000440 }
Douglas Gregor0ab1e9f2010-09-01 17:32:36 +0000441
442 // For a class template specialization, mangle the template arguments.
443 if (ClassTemplateSpecializationDecl *Spec
444 = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
445 const TemplateArgumentList &Args = Spec->getTemplateInstantiationArgs();
446 Out << '>';
447 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
448 Out << '#';
449 VisitTemplateArgument(Args.get(I));
450 }
451 }
Ted Kremenekc5b48b32010-01-15 23:34:31 +0000452}
453
Ted Kremenekc50277f2010-01-12 23:33:42 +0000454void USRGenerator::VisitTypedefDecl(TypedefDecl *D) {
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000455 if (ShouldGenerateLocation(D) && GenLoc(D))
456 return;
Ted Kremenekc50277f2010-01-12 23:33:42 +0000457 DeclContext *DC = D->getDeclContext();
458 if (NamedDecl *DCN = dyn_cast<NamedDecl>(DC))
Ted Kremenek896b70f2010-03-13 02:50:34 +0000459 Visit(DCN);
Ted Kremeneke74ef122010-04-16 21:31:52 +0000460 Out << "@T@";
Ted Kremenek6f153952010-04-15 21:51:13 +0000461 Out << D->getName();
462}
463
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000464void USRGenerator::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
465 GenLoc(D);
466 return;
467}
468
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000469bool USRGenerator::GenLoc(const Decl *D) {
470 if (generatedLoc)
471 return IgnoreResults;
472 generatedLoc = true;
473
Ted Kremenek6f153952010-04-15 21:51:13 +0000474 const SourceManager &SM = AU->getSourceManager();
475 SourceLocation L = D->getLocStart();
476 if (L.isInvalid()) {
477 IgnoreResults = true;
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000478 return true;
Ted Kremenek6f153952010-04-15 21:51:13 +0000479 }
480 L = SM.getInstantiationLoc(L);
481 const std::pair<FileID, unsigned> &Decomposed = SM.getDecomposedLoc(L);
482 const FileEntry *FE = SM.getFileEntryForID(Decomposed.first);
Ted Kremeneke74ef122010-04-16 21:31:52 +0000483 if (FE) {
Michael J. Spencer472ccff2010-12-18 00:19:12 +0000484 Out << llvm::sys::path::filename(FE->getName());
Ted Kremeneke74ef122010-04-16 21:31:52 +0000485 }
Ted Kremenek6f153952010-04-15 21:51:13 +0000486 else {
487 // This case really isn't interesting.
488 IgnoreResults = true;
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000489 return true;
Ted Kremenek6f153952010-04-15 21:51:13 +0000490 }
Ted Kremenekf48b5312010-07-22 11:14:15 +0000491 // Use the offest into the FileID to represent the location. Using
492 // a line/column can cause us to look back at the original source file,
493 // which is expensive.
494 Out << '@' << Decomposed.second;
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000495 return IgnoreResults;
Ted Kremenekc50277f2010-01-12 23:33:42 +0000496}
497
Ted Kremenek8e672192010-05-07 01:04:32 +0000498void USRGenerator::VisitType(QualType T) {
499 // This method mangles in USR information for types. It can possibly
500 // just reuse the naming-mangling logic used by codegen, although the
501 // requirements for USRs might not be the same.
Ted Kremenek2ea5baf2010-05-07 20:39:40 +0000502 ASTContext &Ctx = AU->getASTContext();
503
Ted Kremenek8e672192010-05-07 01:04:32 +0000504 do {
Ted Kremenek2ea5baf2010-05-07 20:39:40 +0000505 T = Ctx.getCanonicalType(T);
Ted Kremenek8e672192010-05-07 01:04:32 +0000506 Qualifiers Q = T.getQualifiers();
Ted Kremenek2ea5baf2010-05-07 20:39:40 +0000507 unsigned qVal = 0;
Ted Kremenek8e672192010-05-07 01:04:32 +0000508 if (Q.hasConst())
Ted Kremenek2ea5baf2010-05-07 20:39:40 +0000509 qVal |= 0x1;
Ted Kremenek8e672192010-05-07 01:04:32 +0000510 if (Q.hasVolatile())
Ted Kremenek2ea5baf2010-05-07 20:39:40 +0000511 qVal |= 0x2;
Ted Kremenek8e672192010-05-07 01:04:32 +0000512 if (Q.hasRestrict())
Ted Kremenek2ea5baf2010-05-07 20:39:40 +0000513 qVal |= 0x4;
514 if(qVal)
515 Out << ((char) ('0' + qVal));
Ted Kremenek8e672192010-05-07 01:04:32 +0000516
517 // Mangle in ObjC GC qualifiers?
518
Douglas Gregorba73ada2011-01-19 20:50:07 +0000519 if (const PackExpansionType *Expansion = T->getAs<PackExpansionType>()) {
520 Out << 'P';
521 T = Expansion->getPattern();
522 }
523
Ted Kremenek8e672192010-05-07 01:04:32 +0000524 if (const BuiltinType *BT = T->getAs<BuiltinType>()) {
525 unsigned char c = '\0';
526 switch (BT->getKind()) {
527 case BuiltinType::Void:
528 c = 'v'; break;
529 case BuiltinType::Bool:
530 c = 'b'; break;
531 case BuiltinType::Char_U:
532 case BuiltinType::UChar:
533 c = 'c'; break;
534 case BuiltinType::Char16:
535 c = 'q'; break;
536 case BuiltinType::Char32:
537 c = 'w'; break;
538 case BuiltinType::UShort:
539 c = 's'; break;
540 case BuiltinType::UInt:
541 c = 'i'; break;
542 case BuiltinType::ULong:
543 c = 'l'; break;
544 case BuiltinType::ULongLong:
545 c = 'k'; break;
546 case BuiltinType::UInt128:
547 c = 'j'; break;
548 case BuiltinType::Char_S:
549 case BuiltinType::SChar:
550 c = 'C'; break;
Chris Lattner3f59c972010-12-25 23:25:43 +0000551 case BuiltinType::WChar_S:
552 case BuiltinType::WChar_U:
Ted Kremenek8e672192010-05-07 01:04:32 +0000553 c = 'W'; break;
554 case BuiltinType::Short:
555 c = 'S'; break;
556 case BuiltinType::Int:
557 c = 'I'; break;
558 case BuiltinType::Long:
559 c = 'L'; break;
560 case BuiltinType::LongLong:
561 c = 'K'; break;
562 case BuiltinType::Int128:
563 c = 'J'; break;
564 case BuiltinType::Float:
565 c = 'f'; break;
566 case BuiltinType::Double:
567 c = 'd'; break;
568 case BuiltinType::LongDouble:
569 c = 'D'; break;
570 case BuiltinType::NullPtr:
571 c = 'n'; break;
572 case BuiltinType::Overload:
573 case BuiltinType::Dependent:
John McCall1de4d4e2011-04-07 08:22:57 +0000574 case BuiltinType::UnknownAny:
Ted Kremenek8e672192010-05-07 01:04:32 +0000575 IgnoreResults = true;
576 return;
577 case BuiltinType::ObjCId:
578 c = 'o'; break;
579 case BuiltinType::ObjCClass:
580 c = 'O'; break;
581 case BuiltinType::ObjCSel:
582 c = 'e'; break;
583 }
584 Out << c;
585 return;
586 }
Douglas Gregor66b7fbf2010-09-20 20:37:39 +0000587
588 // If we have already seen this (non-built-in) type, use a substitution
589 // encoding.
590 llvm::DenseMap<const Type *, unsigned>::iterator Substitution
591 = TypeSubstitutions.find(T.getTypePtr());
592 if (Substitution != TypeSubstitutions.end()) {
593 Out << 'S' << Substitution->second << '_';
594 return;
595 } else {
596 // Record this as a substitution.
597 unsigned Number = TypeSubstitutions.size();
598 TypeSubstitutions[T.getTypePtr()] = Number;
599 }
600
601 if (const PointerType *PT = T->getAs<PointerType>()) {
602 Out << '*';
603 T = PT->getPointeeType();
604 continue;
605 }
606 if (const ReferenceType *RT = T->getAs<ReferenceType>()) {
607 Out << '&';
608 T = RT->getPointeeType();
609 continue;
610 }
611 if (const FunctionProtoType *FT = T->getAs<FunctionProtoType>()) {
612 Out << 'F';
613 VisitType(FT->getResultType());
614 for (FunctionProtoType::arg_type_iterator
615 I = FT->arg_type_begin(), E = FT->arg_type_end(); I!=E; ++I) {
616 VisitType(*I);
617 }
618 if (FT->isVariadic())
619 Out << '.';
620 return;
621 }
622 if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) {
623 Out << 'B';
624 T = BT->getPointeeType();
625 continue;
626 }
Ted Kremenek8e672192010-05-07 01:04:32 +0000627 if (const ComplexType *CT = T->getAs<ComplexType>()) {
628 Out << '<';
629 T = CT->getElementType();
630 continue;
631 }
Ted Kremenek2ea5baf2010-05-07 20:39:40 +0000632 if (const TagType *TT = T->getAs<TagType>()) {
633 Out << '$';
634 VisitTagDecl(TT->getDecl());
635 return;
636 }
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000637 if (const TemplateTypeParmType *TTP = T->getAs<TemplateTypeParmType>()) {
638 Out << 't' << TTP->getDepth() << '.' << TTP->getIndex();
639 return;
640 }
641 if (const TemplateSpecializationType *Spec
642 = T->getAs<TemplateSpecializationType>()) {
643 Out << '>';
644 VisitTemplateName(Spec->getTemplateName());
645 Out << Spec->getNumArgs();
646 for (unsigned I = 0, N = Spec->getNumArgs(); I != N; ++I)
647 VisitTemplateArgument(Spec->getArg(I));
648 return;
649 }
650
Ted Kremenek8e672192010-05-07 01:04:32 +0000651 // Unhandled type.
652 Out << ' ';
653 break;
654 } while (true);
655}
656
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000657void USRGenerator::VisitTemplateParameterList(
658 const TemplateParameterList *Params) {
659 if (!Params)
660 return;
661 Out << '>' << Params->size();
662 for (TemplateParameterList::const_iterator P = Params->begin(),
663 PEnd = Params->end();
664 P != PEnd; ++P) {
665 Out << '#';
666 if (isa<TemplateTypeParmDecl>(*P)) {
Douglas Gregorba73ada2011-01-19 20:50:07 +0000667 if (cast<TemplateTypeParmDecl>(*P)->isParameterPack())
668 Out<< 'p';
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000669 Out << 'T';
670 continue;
671 }
672
673 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) {
Douglas Gregorba73ada2011-01-19 20:50:07 +0000674 if (NTTP->isParameterPack())
675 Out << 'p';
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000676 Out << 'N';
677 VisitType(NTTP->getType());
678 continue;
679 }
680
681 TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*P);
Douglas Gregorba73ada2011-01-19 20:50:07 +0000682 if (TTP->isParameterPack())
683 Out << 'p';
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000684 Out << 't';
685 VisitTemplateParameterList(TTP->getTemplateParameters());
686 }
687}
688
689void USRGenerator::VisitTemplateName(TemplateName Name) {
690 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
691 if (TemplateTemplateParmDecl *TTP
692 = dyn_cast<TemplateTemplateParmDecl>(Template)) {
693 Out << 't' << TTP->getDepth() << '.' << TTP->getIndex();
694 return;
695 }
696
697 Visit(Template);
698 return;
699 }
700
701 // FIXME: Visit dependent template names.
702}
703
704void USRGenerator::VisitTemplateArgument(const TemplateArgument &Arg) {
705 switch (Arg.getKind()) {
706 case TemplateArgument::Null:
707 break;
708
709 case TemplateArgument::Declaration:
Douglas Gregor97475832010-10-05 18:37:06 +0000710 if (Decl *D = Arg.getAsDecl())
711 Visit(D);
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000712 break;
713
Douglas Gregora7fc9012011-01-05 18:58:31 +0000714 case TemplateArgument::TemplateExpansion:
Douglas Gregorba73ada2011-01-19 20:50:07 +0000715 Out << 'P'; // pack expansion of...
716 // Fall through
717 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +0000718 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000719 break;
720
721 case TemplateArgument::Expression:
722 // FIXME: Visit expressions.
723 break;
724
725 case TemplateArgument::Pack:
Douglas Gregorba73ada2011-01-19 20:50:07 +0000726 Out << 'p' << Arg.pack_size();
727 for (TemplateArgument::pack_iterator P = Arg.pack_begin(), PEnd = Arg.pack_end();
728 P != PEnd; ++P)
729 VisitTemplateArgument(*P);
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000730 break;
731
732 case TemplateArgument::Type:
733 VisitType(Arg.getAsType());
734 break;
735
736 case TemplateArgument::Integral:
737 Out << 'V';
738 VisitType(Arg.getIntegralType());
739 Out << *Arg.getAsIntegral();
740 break;
741 }
742}
743
Ted Kremenek896b70f2010-03-13 02:50:34 +0000744//===----------------------------------------------------------------------===//
745// General purpose USR generation methods.
746//===----------------------------------------------------------------------===//
Ted Kremenekcf84aa42010-01-18 20:23:29 +0000747
Ted Kremenek896b70f2010-03-13 02:50:34 +0000748void USRGenerator::GenObjCClass(llvm::StringRef cls) {
749 Out << "objc(cs)" << cls;
750}
751
752void USRGenerator::GenObjCCategory(llvm::StringRef cls, llvm::StringRef cat) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000753 Out << "objc(cy)" << cls << '@' << cat;
Ted Kremenek896b70f2010-03-13 02:50:34 +0000754}
755
756void USRGenerator::GenObjCIvar(llvm::StringRef ivar) {
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000757 Out << '@' << ivar;
Ted Kremenek896b70f2010-03-13 02:50:34 +0000758}
759
760void USRGenerator::GenObjCMethod(llvm::StringRef meth, bool isInstanceMethod) {
761 Out << (isInstanceMethod ? "(im)" : "(cm)") << meth;
762}
763
764void USRGenerator::GenObjCProperty(llvm::StringRef prop) {
765 Out << "(py)" << prop;
766}
767
768void USRGenerator::GenObjCProtocol(llvm::StringRef prot) {
769 Out << "objc(pl)" << prot;
770}
771
772//===----------------------------------------------------------------------===//
773// API hooks.
774//===----------------------------------------------------------------------===//
Ted Kremenekcf84aa42010-01-18 20:23:29 +0000775
Benjamin Kramercfb51b62010-04-08 15:54:07 +0000776static inline llvm::StringRef extractUSRSuffix(llvm::StringRef s) {
777 return s.startswith("c:") ? s.substr(2) : "";
778}
779
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000780static CXString getDeclCursorUSR(const CXCursor &C) {
Ted Kremenek896b70f2010-03-13 02:50:34 +0000781 Decl *D = cxcursor::getCursorDecl(C);
Ted Kremeneke74ef122010-04-16 21:31:52 +0000782
783 // Don't generate USRs for things with invalid locations.
784 if (!D || D->getLocStart().isInvalid())
Ted Kremenek1af0a2a2010-04-17 00:21:38 +0000785 return createCXString("");
Ted Kremenek896b70f2010-03-13 02:50:34 +0000786
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000787 // Check if the cursor has 'NoLinkage'.
Ted Kremeneke74ef122010-04-16 21:31:52 +0000788 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000789 switch (ND->getLinkage()) {
790 case ExternalLinkage:
791 // Generate USRs for all entities with external linkage.
792 break;
793 case NoLinkage:
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000794 case UniqueExternalLinkage:
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000795 // We allow enums, typedefs, and structs that have no linkage to
796 // have USRs that are anchored to the file they were defined in
797 // (e.g., the header). This is a little gross, but in principal
798 // enums/anonymous structs/etc. defined in a common header file
799 // are referred to across multiple translation units.
Ted Kremenek6f153952010-04-15 21:51:13 +0000800 if (isa<TagDecl>(ND) || isa<TypedefDecl>(ND) ||
Ted Kremenekcf999102010-04-29 17:43:29 +0000801 isa<EnumConstantDecl>(ND) || isa<FieldDecl>(ND) ||
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000802 isa<VarDecl>(ND) || isa<NamespaceDecl>(ND))
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000803 break;
804 // Fall-through.
805 case InternalLinkage:
Ted Kremenekcf999102010-04-29 17:43:29 +0000806 if (isa<FunctionDecl>(ND))
807 break;
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000808 }
809
Ted Kremenekf0199432010-11-16 08:15:38 +0000810 CXTranslationUnit TU = cxcursor::getCursorTU(C);
811 if (!TU)
Ted Kremenekebfa3392010-03-19 20:39:03 +0000812 return createCXString("");
Ted Kremenek896b70f2010-03-13 02:50:34 +0000813
Ted Kremenekf0199432010-11-16 08:15:38 +0000814 CXStringBuf *buf = cxstring::getCXStringBuf(TU);
815 if (!buf)
816 return createCXString("");
817
818 {
819 USRGenerator UG(&C, &buf->Data);
820 UG->Visit(D);
Ted Kremeneke542f772010-04-20 23:15:40 +0000821
Ted Kremenekf0199432010-11-16 08:15:38 +0000822 if (UG->ignoreResults()) {
823 disposeCXStringBuf(buf);
824 return createCXString("");
825 }
826 }
827 // Return the C-string, but don't make a copy since it is already in
828 // the string buffer.
829 buf->Data.push_back('\0');
830 return createCXString(buf);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000831}
832
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000833extern "C" {
834
835CXString clang_getCursorUSR(CXCursor C) {
Ted Kremenekfa8231d2010-04-11 22:20:34 +0000836 const CXCursorKind &K = clang_getCursorKind(C);
837
838 if (clang_isDeclaration(K))
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000839 return getDeclCursorUSR(C);
Ted Kremenekfa8231d2010-04-11 22:20:34 +0000840
841 if (K == CXCursor_MacroDefinition) {
Ted Kremenekf0199432010-11-16 08:15:38 +0000842 CXTranslationUnit TU = cxcursor::getCursorTU(C);
843 if (!TU)
844 return createCXString("");
845
846 CXStringBuf *buf = cxstring::getCXStringBuf(TU);
847 if (!buf)
848 return createCXString("");
849
850 {
851 USRGenerator UG(&C, &buf->Data);
852 UG << "macro@"
853 << cxcursor::getCursorMacroDefinition(C)->getName()->getNameStart();
854 }
855 buf->Data.push_back('\0');
856 return createCXString(buf);
Ted Kremenekfa8231d2010-04-11 22:20:34 +0000857 }
858
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000859 return createCXString("");
860}
861
Ted Kremenek896b70f2010-03-13 02:50:34 +0000862CXString clang_constructUSR_ObjCIvar(const char *name, CXString classUSR) {
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000863 USRGenerator UG;
864 UG << extractUSRSuffix(clang_getCString(classUSR));
865 UG->GenObjCIvar(name);
866 return createCXString(UG.str(), true);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000867}
868
869CXString clang_constructUSR_ObjCMethod(const char *name,
870 unsigned isInstanceMethod,
871 CXString classUSR) {
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000872 USRGenerator UG;
873 UG << extractUSRSuffix(clang_getCString(classUSR));
874 UG->GenObjCMethod(name, isInstanceMethod);
875 return createCXString(UG.str(), true);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000876}
877
878CXString clang_constructUSR_ObjCClass(const char *name) {
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000879 USRGenerator UG;
880 UG->GenObjCClass(name);
881 return createCXString(UG.str(), true);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000882}
883
884CXString clang_constructUSR_ObjCProtocol(const char *name) {
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000885 USRGenerator UG;
886 UG->GenObjCProtocol(name);
887 return createCXString(UG.str(), true);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000888}
889
Ted Kremenek66ccaec2010-03-15 17:38:58 +0000890CXString clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000891 const char *category_name) {
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000892 USRGenerator UG;
893 UG->GenObjCCategory(class_name, category_name);
894 return createCXString(UG.str(), true);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000895}
896
897CXString clang_constructUSR_ObjCProperty(const char *property,
898 CXString classUSR) {
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000899 USRGenerator UG;
900 UG << extractUSRSuffix(clang_getCString(classUSR));
901 UG->GenObjCProperty(property);
902 return createCXString(UG.str(), true);
Ted Kremenekcf84aa42010-01-18 20:23:29 +0000903}
Ted Kremenek1b6869a2010-01-05 22:06:45 +0000904
Ted Kremenek1b6869a2010-01-05 22:06:45 +0000905} // end extern "C"