blob: 36b91cf9786231e975f94ad00b9057b6064f02c4 [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 Kremenekcd9175d2011-02-04 07:13:40 +0000286 // The USR for a method declared in a class extension or category is based on
Ted Kremenek28a7f252010-08-24 23:13:41 +0000287 // the ObjCInterfaceDecl, not the ObjCCategoryDecl.
Ted Kremenekcd9175d2011-02-04 07:13:40 +0000288 ObjCInterfaceDecl *ID = D->getClassInterface();
289 if (!ID) {
290 IgnoreResults = true;
291 return;
Ted Kremenek28a7f252010-08-24 23:13:41 +0000292 }
Ted Kremenekcd9175d2011-02-04 07:13:40 +0000293 Visit(ID);
Ted Kremenek28a7f252010-08-24 23:13:41 +0000294
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000295 // Ideally we would use 'GenObjCMethod', but this is such a hot path
296 // for Objective-C code that we don't want to use
297 // DeclarationName::getAsString().
298 Out << (D->isInstanceMethod() ? "(im)" : "(cm)");
299 DeclarationName N(D->getSelector());
300 N.printName(Out);
Ted Kremenekc50277f2010-01-12 23:33:42 +0000301}
302
Ted Kremeneke74ef122010-04-16 21:31:52 +0000303void USRGenerator::VisitObjCClassDecl(ObjCClassDecl *D) {
304 // FIXME: @class declarations can refer to multiple classes. We need
305 // to be able to traverse these.
306 IgnoreResults = true;
307}
308
309void USRGenerator::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
310 // FIXME: @protocol declarations can refer to multiple protocols. We need
311 // to be able to traverse these.
312 IgnoreResults = true;
313}
314
Ted Kremenekc50277f2010-01-12 23:33:42 +0000315void USRGenerator::VisitObjCContainerDecl(ObjCContainerDecl *D) {
316 switch (D->getKind()) {
317 default:
318 assert(false && "Invalid ObjC container.");
319 case Decl::ObjCInterface:
320 case Decl::ObjCImplementation:
Ted Kremenek896b70f2010-03-13 02:50:34 +0000321 GenObjCClass(D->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000322 break;
323 case Decl::ObjCCategory: {
324 ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(D);
Ted Kremenekebfa3392010-03-19 20:39:03 +0000325 ObjCInterfaceDecl *ID = CD->getClassInterface();
326 if (!ID) {
327 // Handle invalid code where the @interface might not
328 // have been specified.
329 // FIXME: We should be able to generate this USR even if the
330 // @interface isn't available.
331 IgnoreResults = true;
332 return;
333 }
Ted Kremenek28a7f252010-08-24 23:13:41 +0000334 // Specially handle class extensions, which are anonymous categories.
335 // We want to mangle in the location to uniquely distinguish them.
336 if (CD->IsClassExtension()) {
337 Out << "objc(ext)" << ID->getName() << '@';
338 GenLoc(CD);
339 }
340 else
341 GenObjCCategory(ID->getName(), CD->getName());
342
Ted Kremenekc50277f2010-01-12 23:33:42 +0000343 break;
344 }
345 case Decl::ObjCCategoryImpl: {
346 ObjCCategoryImplDecl *CD = cast<ObjCCategoryImplDecl>(D);
Ted Kremenekebfa3392010-03-19 20:39:03 +0000347 ObjCInterfaceDecl *ID = CD->getClassInterface();
348 if (!ID) {
349 // Handle invalid code where the @interface might not
350 // have been specified.
351 // FIXME: We should be able to generate this USR even if the
352 // @interface isn't available.
353 IgnoreResults = true;
354 return;
355 }
356 GenObjCCategory(ID->getName(), CD->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000357 break;
358 }
359 case Decl::ObjCProtocol:
Ted Kremenek896b70f2010-03-13 02:50:34 +0000360 GenObjCProtocol(cast<ObjCProtocolDecl>(D)->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000361 break;
362 }
363}
364
365void USRGenerator::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
366 Visit(cast<Decl>(D->getDeclContext()));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000367 GenObjCProperty(D->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000368}
369
Ted Kremeneke542f772010-04-20 23:15:40 +0000370void USRGenerator::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
371 if (ObjCPropertyDecl *PD = D->getPropertyDecl()) {
372 VisitObjCPropertyDecl(PD);
373 return;
374 }
375
376 IgnoreResults = true;
377}
378
Ted Kremenekb82b3be2010-01-18 22:42:20 +0000379void USRGenerator::VisitTagDecl(TagDecl *D) {
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000380 // Add the location of the tag decl to handle resolution across
381 // translation units.
382 if (ShouldGenerateLocation(D) && GenLoc(D))
383 return;
Ted Kremenek8e672192010-05-07 01:04:32 +0000384
Ted Kremenek6f153952010-04-15 21:51:13 +0000385 D = D->getCanonicalDecl();
Ted Kremenekb82b3be2010-01-18 22:42:20 +0000386 VisitDeclContext(D->getDeclContext());
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000387
Douglas Gregor74dbe642010-08-31 19:31:58 +0000388 bool AlreadyStarted = false;
389 if (CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(D)) {
Douglas Gregor39d6f072010-08-31 19:02:00 +0000390 if (ClassTemplateDecl *ClassTmpl = CXXRecord->getDescribedClassTemplate()) {
Douglas Gregor74dbe642010-08-31 19:31:58 +0000391 AlreadyStarted = true;
Douglas Gregor39d6f072010-08-31 19:02:00 +0000392
393 switch (D->getTagKind()) {
Douglas Gregor74dbe642010-08-31 19:31:58 +0000394 case TTK_Struct: Out << "@ST"; break;
395 case TTK_Class: Out << "@CT"; break;
396 case TTK_Union: Out << "@UT"; break;
397 case TTK_Enum: llvm_unreachable("enum template"); break;
Douglas Gregor39d6f072010-08-31 19:02:00 +0000398 }
399 VisitTemplateParameterList(ClassTmpl->getTemplateParameters());
Douglas Gregor74dbe642010-08-31 19:31:58 +0000400 } else if (ClassTemplatePartialSpecializationDecl *PartialSpec
401 = dyn_cast<ClassTemplatePartialSpecializationDecl>(CXXRecord)) {
402 AlreadyStarted = true;
403
404 switch (D->getTagKind()) {
405 case TTK_Struct: Out << "@SP"; break;
406 case TTK_Class: Out << "@CP"; break;
407 case TTK_Union: Out << "@UP"; break;
408 case TTK_Enum: llvm_unreachable("enum partial specialization"); break;
409 }
410 VisitTemplateParameterList(PartialSpec->getTemplateParameters());
Douglas Gregor39d6f072010-08-31 19:02:00 +0000411 }
Douglas Gregor74dbe642010-08-31 19:31:58 +0000412 }
Douglas Gregor39d6f072010-08-31 19:02:00 +0000413
Douglas Gregor74dbe642010-08-31 19:31:58 +0000414 if (!AlreadyStarted) {
Douglas Gregor39d6f072010-08-31 19:02:00 +0000415 switch (D->getTagKind()) {
416 case TTK_Struct: Out << "@S"; break;
417 case TTK_Class: Out << "@C"; break;
418 case TTK_Union: Out << "@U"; break;
419 case TTK_Enum: Out << "@E"; break;
420 }
Ted Kremeneke74ef122010-04-16 21:31:52 +0000421 }
Douglas Gregor39d6f072010-08-31 19:02:00 +0000422
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000423 Out << '@';
424 Out.flush();
425 assert(Buf.size() > 0);
426 const unsigned off = Buf.size() - 1;
Ted Kremenek896b70f2010-03-13 02:50:34 +0000427
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000428 if (EmitDeclName(D)) {
429 if (const TypedefDecl *TD = D->getTypedefForAnonDecl()) {
430 Buf[off] = 'A';
Benjamin Kramer900fc632010-04-17 09:33:03 +0000431 Out << '@' << TD;
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000432 }
433 else
434 Buf[off] = 'a';
Ted Kremenekc5b48b32010-01-15 23:34:31 +0000435 }
Douglas Gregor0ab1e9f2010-09-01 17:32:36 +0000436
437 // For a class template specialization, mangle the template arguments.
438 if (ClassTemplateSpecializationDecl *Spec
439 = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
440 const TemplateArgumentList &Args = Spec->getTemplateInstantiationArgs();
441 Out << '>';
442 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
443 Out << '#';
444 VisitTemplateArgument(Args.get(I));
445 }
446 }
Ted Kremenekc5b48b32010-01-15 23:34:31 +0000447}
448
Ted Kremenekc50277f2010-01-12 23:33:42 +0000449void USRGenerator::VisitTypedefDecl(TypedefDecl *D) {
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000450 if (ShouldGenerateLocation(D) && GenLoc(D))
451 return;
Ted Kremenekc50277f2010-01-12 23:33:42 +0000452 DeclContext *DC = D->getDeclContext();
453 if (NamedDecl *DCN = dyn_cast<NamedDecl>(DC))
Ted Kremenek896b70f2010-03-13 02:50:34 +0000454 Visit(DCN);
Ted Kremeneke74ef122010-04-16 21:31:52 +0000455 Out << "@T@";
Ted Kremenek6f153952010-04-15 21:51:13 +0000456 Out << D->getName();
457}
458
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000459void USRGenerator::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
460 GenLoc(D);
461 return;
462}
463
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000464bool USRGenerator::GenLoc(const Decl *D) {
465 if (generatedLoc)
466 return IgnoreResults;
467 generatedLoc = true;
468
Ted Kremenek6f153952010-04-15 21:51:13 +0000469 const SourceManager &SM = AU->getSourceManager();
470 SourceLocation L = D->getLocStart();
471 if (L.isInvalid()) {
472 IgnoreResults = true;
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000473 return true;
Ted Kremenek6f153952010-04-15 21:51:13 +0000474 }
475 L = SM.getInstantiationLoc(L);
476 const std::pair<FileID, unsigned> &Decomposed = SM.getDecomposedLoc(L);
477 const FileEntry *FE = SM.getFileEntryForID(Decomposed.first);
Ted Kremeneke74ef122010-04-16 21:31:52 +0000478 if (FE) {
Michael J. Spencer472ccff2010-12-18 00:19:12 +0000479 Out << llvm::sys::path::filename(FE->getName());
Ted Kremeneke74ef122010-04-16 21:31:52 +0000480 }
Ted Kremenek6f153952010-04-15 21:51:13 +0000481 else {
482 // This case really isn't interesting.
483 IgnoreResults = true;
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000484 return true;
Ted Kremenek6f153952010-04-15 21:51:13 +0000485 }
Ted Kremenekf48b5312010-07-22 11:14:15 +0000486 // Use the offest into the FileID to represent the location. Using
487 // a line/column can cause us to look back at the original source file,
488 // which is expensive.
489 Out << '@' << Decomposed.second;
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000490 return IgnoreResults;
Ted Kremenekc50277f2010-01-12 23:33:42 +0000491}
492
Ted Kremenek8e672192010-05-07 01:04:32 +0000493void USRGenerator::VisitType(QualType T) {
494 // This method mangles in USR information for types. It can possibly
495 // just reuse the naming-mangling logic used by codegen, although the
496 // requirements for USRs might not be the same.
Ted Kremenek2ea5baf2010-05-07 20:39:40 +0000497 ASTContext &Ctx = AU->getASTContext();
498
Ted Kremenek8e672192010-05-07 01:04:32 +0000499 do {
Ted Kremenek2ea5baf2010-05-07 20:39:40 +0000500 T = Ctx.getCanonicalType(T);
Ted Kremenek8e672192010-05-07 01:04:32 +0000501 Qualifiers Q = T.getQualifiers();
Ted Kremenek2ea5baf2010-05-07 20:39:40 +0000502 unsigned qVal = 0;
Ted Kremenek8e672192010-05-07 01:04:32 +0000503 if (Q.hasConst())
Ted Kremenek2ea5baf2010-05-07 20:39:40 +0000504 qVal |= 0x1;
Ted Kremenek8e672192010-05-07 01:04:32 +0000505 if (Q.hasVolatile())
Ted Kremenek2ea5baf2010-05-07 20:39:40 +0000506 qVal |= 0x2;
Ted Kremenek8e672192010-05-07 01:04:32 +0000507 if (Q.hasRestrict())
Ted Kremenek2ea5baf2010-05-07 20:39:40 +0000508 qVal |= 0x4;
509 if(qVal)
510 Out << ((char) ('0' + qVal));
Ted Kremenek8e672192010-05-07 01:04:32 +0000511
512 // Mangle in ObjC GC qualifiers?
513
Douglas Gregorba73ada2011-01-19 20:50:07 +0000514 if (const PackExpansionType *Expansion = T->getAs<PackExpansionType>()) {
515 Out << 'P';
516 T = Expansion->getPattern();
517 }
518
Ted Kremenek8e672192010-05-07 01:04:32 +0000519 if (const BuiltinType *BT = T->getAs<BuiltinType>()) {
520 unsigned char c = '\0';
521 switch (BT->getKind()) {
522 case BuiltinType::Void:
523 c = 'v'; break;
524 case BuiltinType::Bool:
525 c = 'b'; break;
526 case BuiltinType::Char_U:
527 case BuiltinType::UChar:
528 c = 'c'; break;
529 case BuiltinType::Char16:
530 c = 'q'; break;
531 case BuiltinType::Char32:
532 c = 'w'; break;
533 case BuiltinType::UShort:
534 c = 's'; break;
535 case BuiltinType::UInt:
536 c = 'i'; break;
537 case BuiltinType::ULong:
538 c = 'l'; break;
539 case BuiltinType::ULongLong:
540 c = 'k'; break;
541 case BuiltinType::UInt128:
542 c = 'j'; break;
543 case BuiltinType::Char_S:
544 case BuiltinType::SChar:
545 c = 'C'; break;
Chris Lattner3f59c972010-12-25 23:25:43 +0000546 case BuiltinType::WChar_S:
547 case BuiltinType::WChar_U:
Ted Kremenek8e672192010-05-07 01:04:32 +0000548 c = 'W'; break;
549 case BuiltinType::Short:
550 c = 'S'; break;
551 case BuiltinType::Int:
552 c = 'I'; break;
553 case BuiltinType::Long:
554 c = 'L'; break;
555 case BuiltinType::LongLong:
556 c = 'K'; break;
557 case BuiltinType::Int128:
558 c = 'J'; break;
559 case BuiltinType::Float:
560 c = 'f'; break;
561 case BuiltinType::Double:
562 c = 'd'; break;
563 case BuiltinType::LongDouble:
564 c = 'D'; break;
565 case BuiltinType::NullPtr:
566 c = 'n'; break;
567 case BuiltinType::Overload:
568 case BuiltinType::Dependent:
569 case BuiltinType::UndeducedAuto:
570 IgnoreResults = true;
571 return;
572 case BuiltinType::ObjCId:
573 c = 'o'; break;
574 case BuiltinType::ObjCClass:
575 c = 'O'; break;
576 case BuiltinType::ObjCSel:
577 c = 'e'; break;
578 }
579 Out << c;
580 return;
581 }
Douglas Gregor66b7fbf2010-09-20 20:37:39 +0000582
583 // If we have already seen this (non-built-in) type, use a substitution
584 // encoding.
585 llvm::DenseMap<const Type *, unsigned>::iterator Substitution
586 = TypeSubstitutions.find(T.getTypePtr());
587 if (Substitution != TypeSubstitutions.end()) {
588 Out << 'S' << Substitution->second << '_';
589 return;
590 } else {
591 // Record this as a substitution.
592 unsigned Number = TypeSubstitutions.size();
593 TypeSubstitutions[T.getTypePtr()] = Number;
594 }
595
596 if (const PointerType *PT = T->getAs<PointerType>()) {
597 Out << '*';
598 T = PT->getPointeeType();
599 continue;
600 }
601 if (const ReferenceType *RT = T->getAs<ReferenceType>()) {
602 Out << '&';
603 T = RT->getPointeeType();
604 continue;
605 }
606 if (const FunctionProtoType *FT = T->getAs<FunctionProtoType>()) {
607 Out << 'F';
608 VisitType(FT->getResultType());
609 for (FunctionProtoType::arg_type_iterator
610 I = FT->arg_type_begin(), E = FT->arg_type_end(); I!=E; ++I) {
611 VisitType(*I);
612 }
613 if (FT->isVariadic())
614 Out << '.';
615 return;
616 }
617 if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) {
618 Out << 'B';
619 T = BT->getPointeeType();
620 continue;
621 }
Ted Kremenek8e672192010-05-07 01:04:32 +0000622 if (const ComplexType *CT = T->getAs<ComplexType>()) {
623 Out << '<';
624 T = CT->getElementType();
625 continue;
626 }
Ted Kremenek2ea5baf2010-05-07 20:39:40 +0000627 if (const TagType *TT = T->getAs<TagType>()) {
628 Out << '$';
629 VisitTagDecl(TT->getDecl());
630 return;
631 }
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000632 if (const TemplateTypeParmType *TTP = T->getAs<TemplateTypeParmType>()) {
633 Out << 't' << TTP->getDepth() << '.' << TTP->getIndex();
634 return;
635 }
636 if (const TemplateSpecializationType *Spec
637 = T->getAs<TemplateSpecializationType>()) {
638 Out << '>';
639 VisitTemplateName(Spec->getTemplateName());
640 Out << Spec->getNumArgs();
641 for (unsigned I = 0, N = Spec->getNumArgs(); I != N; ++I)
642 VisitTemplateArgument(Spec->getArg(I));
643 return;
644 }
645
Ted Kremenek8e672192010-05-07 01:04:32 +0000646 // Unhandled type.
647 Out << ' ';
648 break;
649 } while (true);
650}
651
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000652void USRGenerator::VisitTemplateParameterList(
653 const TemplateParameterList *Params) {
654 if (!Params)
655 return;
656 Out << '>' << Params->size();
657 for (TemplateParameterList::const_iterator P = Params->begin(),
658 PEnd = Params->end();
659 P != PEnd; ++P) {
660 Out << '#';
661 if (isa<TemplateTypeParmDecl>(*P)) {
Douglas Gregorba73ada2011-01-19 20:50:07 +0000662 if (cast<TemplateTypeParmDecl>(*P)->isParameterPack())
663 Out<< 'p';
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000664 Out << 'T';
665 continue;
666 }
667
668 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) {
Douglas Gregorba73ada2011-01-19 20:50:07 +0000669 if (NTTP->isParameterPack())
670 Out << 'p';
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000671 Out << 'N';
672 VisitType(NTTP->getType());
673 continue;
674 }
675
676 TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*P);
Douglas Gregorba73ada2011-01-19 20:50:07 +0000677 if (TTP->isParameterPack())
678 Out << 'p';
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000679 Out << 't';
680 VisitTemplateParameterList(TTP->getTemplateParameters());
681 }
682}
683
684void USRGenerator::VisitTemplateName(TemplateName Name) {
685 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
686 if (TemplateTemplateParmDecl *TTP
687 = dyn_cast<TemplateTemplateParmDecl>(Template)) {
688 Out << 't' << TTP->getDepth() << '.' << TTP->getIndex();
689 return;
690 }
691
692 Visit(Template);
693 return;
694 }
695
696 // FIXME: Visit dependent template names.
697}
698
699void USRGenerator::VisitTemplateArgument(const TemplateArgument &Arg) {
700 switch (Arg.getKind()) {
701 case TemplateArgument::Null:
702 break;
703
704 case TemplateArgument::Declaration:
Douglas Gregor97475832010-10-05 18:37:06 +0000705 if (Decl *D = Arg.getAsDecl())
706 Visit(D);
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000707 break;
708
Douglas Gregora7fc9012011-01-05 18:58:31 +0000709 case TemplateArgument::TemplateExpansion:
Douglas Gregorba73ada2011-01-19 20:50:07 +0000710 Out << 'P'; // pack expansion of...
711 // Fall through
712 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +0000713 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000714 break;
715
716 case TemplateArgument::Expression:
717 // FIXME: Visit expressions.
718 break;
719
720 case TemplateArgument::Pack:
Douglas Gregorba73ada2011-01-19 20:50:07 +0000721 Out << 'p' << Arg.pack_size();
722 for (TemplateArgument::pack_iterator P = Arg.pack_begin(), PEnd = Arg.pack_end();
723 P != PEnd; ++P)
724 VisitTemplateArgument(*P);
Douglas Gregorfe72e9c2010-08-31 17:01:39 +0000725 break;
726
727 case TemplateArgument::Type:
728 VisitType(Arg.getAsType());
729 break;
730
731 case TemplateArgument::Integral:
732 Out << 'V';
733 VisitType(Arg.getIntegralType());
734 Out << *Arg.getAsIntegral();
735 break;
736 }
737}
738
Ted Kremenek896b70f2010-03-13 02:50:34 +0000739//===----------------------------------------------------------------------===//
740// General purpose USR generation methods.
741//===----------------------------------------------------------------------===//
Ted Kremenekcf84aa42010-01-18 20:23:29 +0000742
Ted Kremenek896b70f2010-03-13 02:50:34 +0000743void USRGenerator::GenObjCClass(llvm::StringRef cls) {
744 Out << "objc(cs)" << cls;
745}
746
747void USRGenerator::GenObjCCategory(llvm::StringRef cls, llvm::StringRef cat) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000748 Out << "objc(cy)" << cls << '@' << cat;
Ted Kremenek896b70f2010-03-13 02:50:34 +0000749}
750
751void USRGenerator::GenObjCIvar(llvm::StringRef ivar) {
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000752 Out << '@' << ivar;
Ted Kremenek896b70f2010-03-13 02:50:34 +0000753}
754
755void USRGenerator::GenObjCMethod(llvm::StringRef meth, bool isInstanceMethod) {
756 Out << (isInstanceMethod ? "(im)" : "(cm)") << meth;
757}
758
759void USRGenerator::GenObjCProperty(llvm::StringRef prop) {
760 Out << "(py)" << prop;
761}
762
763void USRGenerator::GenObjCProtocol(llvm::StringRef prot) {
764 Out << "objc(pl)" << prot;
765}
766
767//===----------------------------------------------------------------------===//
768// API hooks.
769//===----------------------------------------------------------------------===//
Ted Kremenekcf84aa42010-01-18 20:23:29 +0000770
Benjamin Kramercfb51b62010-04-08 15:54:07 +0000771static inline llvm::StringRef extractUSRSuffix(llvm::StringRef s) {
772 return s.startswith("c:") ? s.substr(2) : "";
773}
774
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000775static CXString getDeclCursorUSR(const CXCursor &C) {
Ted Kremenek896b70f2010-03-13 02:50:34 +0000776 Decl *D = cxcursor::getCursorDecl(C);
Ted Kremeneke74ef122010-04-16 21:31:52 +0000777
778 // Don't generate USRs for things with invalid locations.
779 if (!D || D->getLocStart().isInvalid())
Ted Kremenek1af0a2a2010-04-17 00:21:38 +0000780 return createCXString("");
Ted Kremenek896b70f2010-03-13 02:50:34 +0000781
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000782 // Check if the cursor has 'NoLinkage'.
Ted Kremeneke74ef122010-04-16 21:31:52 +0000783 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000784 switch (ND->getLinkage()) {
785 case ExternalLinkage:
786 // Generate USRs for all entities with external linkage.
787 break;
788 case NoLinkage:
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000789 case UniqueExternalLinkage:
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000790 // We allow enums, typedefs, and structs that have no linkage to
791 // have USRs that are anchored to the file they were defined in
792 // (e.g., the header). This is a little gross, but in principal
793 // enums/anonymous structs/etc. defined in a common header file
794 // are referred to across multiple translation units.
Ted Kremenek6f153952010-04-15 21:51:13 +0000795 if (isa<TagDecl>(ND) || isa<TypedefDecl>(ND) ||
Ted Kremenekcf999102010-04-29 17:43:29 +0000796 isa<EnumConstantDecl>(ND) || isa<FieldDecl>(ND) ||
Ted Kremenekcbd66f02010-05-06 23:38:28 +0000797 isa<VarDecl>(ND) || isa<NamespaceDecl>(ND))
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000798 break;
799 // Fall-through.
800 case InternalLinkage:
Ted Kremenekcf999102010-04-29 17:43:29 +0000801 if (isa<FunctionDecl>(ND))
802 break;
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000803 }
804
Ted Kremenekf0199432010-11-16 08:15:38 +0000805 CXTranslationUnit TU = cxcursor::getCursorTU(C);
806 if (!TU)
Ted Kremenekebfa3392010-03-19 20:39:03 +0000807 return createCXString("");
Ted Kremenek896b70f2010-03-13 02:50:34 +0000808
Ted Kremenekf0199432010-11-16 08:15:38 +0000809 CXStringBuf *buf = cxstring::getCXStringBuf(TU);
810 if (!buf)
811 return createCXString("");
812
813 {
814 USRGenerator UG(&C, &buf->Data);
815 UG->Visit(D);
Ted Kremeneke542f772010-04-20 23:15:40 +0000816
Ted Kremenekf0199432010-11-16 08:15:38 +0000817 if (UG->ignoreResults()) {
818 disposeCXStringBuf(buf);
819 return createCXString("");
820 }
821 }
822 // Return the C-string, but don't make a copy since it is already in
823 // the string buffer.
824 buf->Data.push_back('\0');
825 return createCXString(buf);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000826}
827
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000828extern "C" {
829
830CXString clang_getCursorUSR(CXCursor C) {
Ted Kremenekfa8231d2010-04-11 22:20:34 +0000831 const CXCursorKind &K = clang_getCursorKind(C);
832
833 if (clang_isDeclaration(K))
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000834 return getDeclCursorUSR(C);
Ted Kremenekfa8231d2010-04-11 22:20:34 +0000835
836 if (K == CXCursor_MacroDefinition) {
Ted Kremenekf0199432010-11-16 08:15:38 +0000837 CXTranslationUnit TU = cxcursor::getCursorTU(C);
838 if (!TU)
839 return createCXString("");
840
841 CXStringBuf *buf = cxstring::getCXStringBuf(TU);
842 if (!buf)
843 return createCXString("");
844
845 {
846 USRGenerator UG(&C, &buf->Data);
847 UG << "macro@"
848 << cxcursor::getCursorMacroDefinition(C)->getName()->getNameStart();
849 }
850 buf->Data.push_back('\0');
851 return createCXString(buf);
Ted Kremenekfa8231d2010-04-11 22:20:34 +0000852 }
853
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000854 return createCXString("");
855}
856
Ted Kremenek896b70f2010-03-13 02:50:34 +0000857CXString clang_constructUSR_ObjCIvar(const char *name, CXString classUSR) {
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000858 USRGenerator UG;
859 UG << extractUSRSuffix(clang_getCString(classUSR));
860 UG->GenObjCIvar(name);
861 return createCXString(UG.str(), true);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000862}
863
864CXString clang_constructUSR_ObjCMethod(const char *name,
865 unsigned isInstanceMethod,
866 CXString classUSR) {
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000867 USRGenerator UG;
868 UG << extractUSRSuffix(clang_getCString(classUSR));
869 UG->GenObjCMethod(name, isInstanceMethod);
870 return createCXString(UG.str(), true);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000871}
872
873CXString clang_constructUSR_ObjCClass(const char *name) {
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000874 USRGenerator UG;
875 UG->GenObjCClass(name);
876 return createCXString(UG.str(), true);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000877}
878
879CXString clang_constructUSR_ObjCProtocol(const char *name) {
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000880 USRGenerator UG;
881 UG->GenObjCProtocol(name);
882 return createCXString(UG.str(), true);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000883}
884
Ted Kremenek66ccaec2010-03-15 17:38:58 +0000885CXString clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000886 const char *category_name) {
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000887 USRGenerator UG;
888 UG->GenObjCCategory(class_name, category_name);
889 return createCXString(UG.str(), true);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000890}
891
892CXString clang_constructUSR_ObjCProperty(const char *property,
893 CXString classUSR) {
Ted Kremenek3ebd8dc2010-05-07 20:07:23 +0000894 USRGenerator UG;
895 UG << extractUSRSuffix(clang_getCString(classUSR));
896 UG->GenObjCProperty(property);
897 return createCXString(UG.str(), true);
Ted Kremenekcf84aa42010-01-18 20:23:29 +0000898}
Ted Kremenek1b6869a2010-01-05 22:06:45 +0000899
Ted Kremenek1b6869a2010-01-05 22:06:45 +0000900} // end extern "C"