blob: 0f70a0a821c87862a9b363f4d83471ab9482f6ff [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"
Benjamin Kramer9895c6a2010-01-12 11:32:40 +000016#include "clang/AST/DeclVisitor.h"
Ted Kremenek6f153952010-04-15 21:51:13 +000017#include "clang/Frontend/ASTUnit.h"
Benjamin Kramerb846deb2010-04-12 19:45:50 +000018#include "clang/Lex/PreprocessingRecord.h"
Ted Kremenek87763822010-01-12 02:07:58 +000019#include "llvm/ADT/SmallString.h"
Benjamin Kramer9895c6a2010-01-12 11:32:40 +000020#include "llvm/Support/raw_ostream.h"
Ted Kremenek6f153952010-04-15 21:51:13 +000021
Benjamin Kramerb846deb2010-04-12 19:45:50 +000022using namespace clang;
Ted Kremenekee4db4f2010-02-17 00:41:08 +000023using namespace clang::cxstring;
24
Ted Kremenekc50277f2010-01-12 23:33:42 +000025//===----------------------------------------------------------------------===//
26// USR generation.
27//===----------------------------------------------------------------------===//
28
29namespace {
Ted Kremenek2fee4e62010-01-14 01:50:21 +000030class USRGenerator : public DeclVisitor<USRGenerator> {
31 llvm::raw_ostream &Out;
Ted Kremenek3adca6d2010-01-18 22:02:49 +000032 bool IgnoreResults;
Ted Kremenek1865cfe2010-04-15 21:04:25 +000033 ASTUnit *AU;
Ted Kremenek2fee4e62010-01-14 01:50:21 +000034public:
Ted Kremenek1865cfe2010-04-15 21:04:25 +000035 USRGenerator(ASTUnit *au, llvm::raw_ostream &out)
36 : Out(out), IgnoreResults(false), AU(au) {}
Ted Kremenek896b70f2010-03-13 02:50:34 +000037
Ted Kremenek3adca6d2010-01-18 22:02:49 +000038 bool ignoreResults() const { return IgnoreResults; }
Ted Kremenek896b70f2010-03-13 02:50:34 +000039
40 // Visitation methods from generating USRs from AST elements.
Ted Kremenek2fee4e62010-01-14 01:50:21 +000041 void VisitDeclContext(DeclContext *D);
Ted Kremenek3adca6d2010-01-18 22:02:49 +000042 void VisitFieldDecl(FieldDecl *D);
Ted Kremenek2fee4e62010-01-14 01:50:21 +000043 void VisitFunctionDecl(FunctionDecl *D);
44 void VisitNamedDecl(NamedDecl *D);
45 void VisitNamespaceDecl(NamespaceDecl *D);
Ted Kremeneke74ef122010-04-16 21:31:52 +000046 void VisitObjCClassDecl(ObjCClassDecl *CD);
Ted Kremenek896b70f2010-03-13 02:50:34 +000047 void VisitObjCContainerDecl(ObjCContainerDecl *CD);
Ted Kremeneke74ef122010-04-16 21:31:52 +000048 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *P);
Ted Kremeneke542f772010-04-20 23:15:40 +000049 void VisitObjCMethodDecl(ObjCMethodDecl *MD);
Ted Kremenek2fee4e62010-01-14 01:50:21 +000050 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
Ted Kremeneke542f772010-04-20 23:15:40 +000051 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
Ted Kremenekb82b3be2010-01-18 22:42:20 +000052 void VisitTagDecl(TagDecl *D);
Ted Kremenek2fee4e62010-01-14 01:50:21 +000053 void VisitTypedefDecl(TypedefDecl *D);
Ted Kremeneke542f772010-04-20 23:15:40 +000054 void VisitVarDecl(VarDecl *D);
Ted Kremenek896b70f2010-03-13 02:50:34 +000055
Ted Kremenek6f153952010-04-15 21:51:13 +000056 /// Generate the string component containing the location of the
57 /// declaration.
58 void GenLoc(const Decl *D);
59
Ted Kremenek896b70f2010-03-13 02:50:34 +000060 /// String generation methods used both by the visitation methods
61 /// and from other clients that want to directly generate USRs. These
62 /// methods do not construct complete USRs (which incorporate the parents
63 /// of an AST element), but only the fragments concerning the AST element
64 /// itself.
65
66 /// Generate a USR fragment for a named declaration. This does
67 /// not include the USR component for the parent.
68 void GenNamedDecl(llvm::StringRef name);
69
70 /// Generate a USR for an Objective-C class.
71 void GenObjCClass(llvm::StringRef cls);
72 /// Generate a USR for an Objective-C class category.
73 void GenObjCCategory(llvm::StringRef cls, llvm::StringRef cat);
74 /// Generate a USR fragment for an Objective-C instance variable. The
75 /// complete USR can be created by concatenating the USR for the
76 /// encompassing class with this USR fragment.
77 void GenObjCIvar(llvm::StringRef ivar);
78 /// Generate a USR fragment for an Objective-C method.
79 void GenObjCMethod(llvm::StringRef sel, bool isInstanceMethod);
80 /// Generate a USR fragment for an Objective-C property.
81 void GenObjCProperty(llvm::StringRef prop);
82 /// Generate a USR for an Objective-C protocol.
83 void GenObjCProtocol(llvm::StringRef prot);
Ted Kremenek2fee4e62010-01-14 01:50:21 +000084};
Ted Kremenek896b70f2010-03-13 02:50:34 +000085
86class StringUSRGenerator {
87private:
88 llvm::SmallString<1024> StrBuf;
89 llvm::raw_svector_ostream Out;
90 USRGenerator UG;
91public:
Ted Kremenek1865cfe2010-04-15 21:04:25 +000092 StringUSRGenerator(const CXCursor *C = 0)
93 : Out(StrBuf), UG(C ? cxcursor::getCursorASTUnit(*C) : 0, Out) {
Ted Kremenek0c0fb412010-03-25 02:00:36 +000094 // Add the USR space prefix.
Ted Kremenek1865cfe2010-04-15 21:04:25 +000095 Out << "c:";
Ted Kremenek0c0fb412010-03-25 02:00:36 +000096 }
Ted Kremenek896b70f2010-03-13 02:50:34 +000097
98 llvm::StringRef str() {
99 return Out.str();
100 }
101
102 USRGenerator* operator->() { return &UG; }
103
104 template <typename T>
105 llvm::raw_svector_ostream &operator<<(const T &x) {
106 Out << x;
107 return Out;
108 }
109};
110
Ted Kremenekc50277f2010-01-12 23:33:42 +0000111} // end anonymous namespace
112
Ted Kremenek896b70f2010-03-13 02:50:34 +0000113//===----------------------------------------------------------------------===//
114// Generating USRs from ASTS.
115//===----------------------------------------------------------------------===//
116
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000117void USRGenerator::VisitDeclContext(DeclContext *DC) {
118 if (NamedDecl *D = dyn_cast<NamedDecl>(DC))
119 Visit(D);
120}
121
Ted Kremenek3adca6d2010-01-18 22:02:49 +0000122void USRGenerator::VisitFieldDecl(FieldDecl *D) {
123 const std::string &s = D->getNameAsString();
124 if (s.empty()) {
125 // Bit fields can be anonymous.
126 IgnoreResults = true;
127 return;
128 }
129 VisitDeclContext(D->getDeclContext());
Ted Kremeneke542f772010-04-20 23:15:40 +0000130 Out << (isa<ObjCIvarDecl>(D) ? "@" : "@FI@") << s;
Ted Kremenek3adca6d2010-01-18 22:02:49 +0000131}
132
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000133void USRGenerator::VisitFunctionDecl(FunctionDecl *D) {
134 VisitDeclContext(D->getDeclContext());
Benjamin Kramer900fc632010-04-17 09:33:03 +0000135 Out << "@F@" << D;
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000136}
Ted Kremenekc50277f2010-01-12 23:33:42 +0000137
138void USRGenerator::VisitNamedDecl(NamedDecl *D) {
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000139 VisitDeclContext(D->getDeclContext());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000140 const std::string &s = D->getNameAsString();
Ted Kremeneke74ef122010-04-16 21:31:52 +0000141 // The string can be empty if the declaration has no name; e.g., it is
142 // the ParmDecl with no name for declaration of a function pointer type, e.g.:
143 // void (*f)(void *);
144 // In this case, don't generate a USR.
145 if (s.empty())
146 IgnoreResults = true;
147 else
148 GenNamedDecl(s);
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000149}
150
Ted Kremeneke542f772010-04-20 23:15:40 +0000151void USRGenerator::VisitVarDecl(VarDecl *D) {
152 // VarDecls can be declared 'extern' within a function or method body,
153 // but their enclosing DeclContext is the function, not the TU. We need
154 // to check the storage class to correctly generate the USR.
155 if (!D->hasExternalStorage())
156 VisitDeclContext(D->getDeclContext());
157
158 const std::string &s = D->getNameAsString();
159 // The string can be empty if the declaration has no name; e.g., it is
160 // the ParmDecl with no name for declaration of a function pointer type, e.g.:
161 // void (*f)(void *);
162 // In this case, don't generate a USR.
163 if (s.empty())
164 IgnoreResults = true;
165 else
166 GenNamedDecl(s);
167}
168
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000169void USRGenerator::VisitNamespaceDecl(NamespaceDecl *D) {
170 VisitDeclContext(D->getDeclContext());
Benjamin Kramer900fc632010-04-17 09:33:03 +0000171 Out << "@N@" << D;
Ted Kremenekc50277f2010-01-12 23:33:42 +0000172}
173
Ted Kremenekc50277f2010-01-12 23:33:42 +0000174void USRGenerator::VisitObjCMethodDecl(ObjCMethodDecl *D) {
175 Visit(cast<Decl>(D->getDeclContext()));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000176 GenObjCMethod(DeclarationName(D->getSelector()).getAsString(),
177 D->isInstanceMethod());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000178}
179
Ted Kremeneke74ef122010-04-16 21:31:52 +0000180void USRGenerator::VisitObjCClassDecl(ObjCClassDecl *D) {
181 // FIXME: @class declarations can refer to multiple classes. We need
182 // to be able to traverse these.
183 IgnoreResults = true;
184}
185
186void USRGenerator::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
187 // FIXME: @protocol declarations can refer to multiple protocols. We need
188 // to be able to traverse these.
189 IgnoreResults = true;
190}
191
Ted Kremenekc50277f2010-01-12 23:33:42 +0000192void USRGenerator::VisitObjCContainerDecl(ObjCContainerDecl *D) {
193 switch (D->getKind()) {
194 default:
195 assert(false && "Invalid ObjC container.");
196 case Decl::ObjCInterface:
197 case Decl::ObjCImplementation:
Ted Kremenek896b70f2010-03-13 02:50:34 +0000198 GenObjCClass(D->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000199 break;
200 case Decl::ObjCCategory: {
201 ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(D);
Ted Kremenekebfa3392010-03-19 20:39:03 +0000202 ObjCInterfaceDecl *ID = CD->getClassInterface();
203 if (!ID) {
204 // Handle invalid code where the @interface might not
205 // have been specified.
206 // FIXME: We should be able to generate this USR even if the
207 // @interface isn't available.
208 IgnoreResults = true;
209 return;
210 }
211 GenObjCCategory(ID->getName(), CD->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000212 break;
213 }
214 case Decl::ObjCCategoryImpl: {
215 ObjCCategoryImplDecl *CD = cast<ObjCCategoryImplDecl>(D);
Ted Kremenekebfa3392010-03-19 20:39:03 +0000216 ObjCInterfaceDecl *ID = CD->getClassInterface();
217 if (!ID) {
218 // Handle invalid code where the @interface might not
219 // have been specified.
220 // FIXME: We should be able to generate this USR even if the
221 // @interface isn't available.
222 IgnoreResults = true;
223 return;
224 }
225 GenObjCCategory(ID->getName(), CD->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000226 break;
227 }
228 case Decl::ObjCProtocol:
Ted Kremenek896b70f2010-03-13 02:50:34 +0000229 GenObjCProtocol(cast<ObjCProtocolDecl>(D)->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000230 break;
231 }
232}
233
234void USRGenerator::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
235 Visit(cast<Decl>(D->getDeclContext()));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000236 GenObjCProperty(D->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000237}
238
Ted Kremeneke542f772010-04-20 23:15:40 +0000239void USRGenerator::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
240 if (ObjCPropertyDecl *PD = D->getPropertyDecl()) {
241 VisitObjCPropertyDecl(PD);
242 return;
243 }
244
245 IgnoreResults = true;
246}
247
Ted Kremenekb82b3be2010-01-18 22:42:20 +0000248void USRGenerator::VisitTagDecl(TagDecl *D) {
Ted Kremenek6f153952010-04-15 21:51:13 +0000249 D = D->getCanonicalDecl();
Ted Kremenekb82b3be2010-01-18 22:42:20 +0000250 VisitDeclContext(D->getDeclContext());
251 switch (D->getTagKind()) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000252 case TagDecl::TK_struct: Out << "@S"; break;
253 case TagDecl::TK_class: Out << "@C"; break;
254 case TagDecl::TK_union: Out << "@U"; break;
255 case TagDecl::TK_enum: Out << "@E"; break;
256 }
257
258 const std::string &s = D->getNameAsString();
259 const TypedefDecl *TD = 0;
260 if (s.empty()) {
261 TD = D->getTypedefForAnonDecl();
262 Out << (TD ? 'A' : 'a');
Ted Kremenekb82b3be2010-01-18 22:42:20 +0000263 }
Ted Kremenek896b70f2010-03-13 02:50:34 +0000264
Ted Kremenek6f153952010-04-15 21:51:13 +0000265 // Add the location of the tag decl to handle resolution across
266 // translation units.
267 if (D->getLinkage() == NoLinkage) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000268 Out << '@';
Ted Kremenek6f153952010-04-15 21:51:13 +0000269 GenLoc(D);
270 if (IgnoreResults)
271 return;
272 }
273
Ted Kremenekc5b48b32010-01-15 23:34:31 +0000274 if (s.empty()) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000275 if (TD)
Benjamin Kramer900fc632010-04-17 09:33:03 +0000276 Out << '@' << TD;
Ted Kremenekc5b48b32010-01-15 23:34:31 +0000277 }
278 else
Ted Kremeneke74ef122010-04-16 21:31:52 +0000279 Out << '@' << s;
Ted Kremenekc5b48b32010-01-15 23:34:31 +0000280}
281
Ted Kremenekc50277f2010-01-12 23:33:42 +0000282void USRGenerator::VisitTypedefDecl(TypedefDecl *D) {
283 DeclContext *DC = D->getDeclContext();
284 if (NamedDecl *DCN = dyn_cast<NamedDecl>(DC))
Ted Kremenek896b70f2010-03-13 02:50:34 +0000285 Visit(DCN);
Ted Kremeneke74ef122010-04-16 21:31:52 +0000286 Out << "@T@";
287 if (D->getLinkage() == NoLinkage) {
288 GenLoc(D);
289 if (IgnoreResults)
290 return;
291 Out << '@';
292 }
Ted Kremenek6f153952010-04-15 21:51:13 +0000293 Out << D->getName();
294}
295
296void USRGenerator::GenLoc(const Decl *D) {
297 const SourceManager &SM = AU->getSourceManager();
298 SourceLocation L = D->getLocStart();
299 if (L.isInvalid()) {
300 IgnoreResults = true;
301 return;
302 }
303 L = SM.getInstantiationLoc(L);
304 const std::pair<FileID, unsigned> &Decomposed = SM.getDecomposedLoc(L);
305 const FileEntry *FE = SM.getFileEntryForID(Decomposed.first);
Ted Kremeneke74ef122010-04-16 21:31:52 +0000306 if (FE) {
307 llvm::sys::Path P(FE->getName());
308 Out << P.getLast();
309 }
Ted Kremenek6f153952010-04-15 21:51:13 +0000310 else {
311 // This case really isn't interesting.
312 IgnoreResults = true;
313 return;
314 }
Ted Kremeneke74ef122010-04-16 21:31:52 +0000315 Out << '@'
316 << SM.getLineNumber(Decomposed.first, Decomposed.second) << ':'
317 << SM.getColumnNumber(Decomposed.first, Decomposed.second);
Ted Kremenekc50277f2010-01-12 23:33:42 +0000318}
319
Ted Kremenek896b70f2010-03-13 02:50:34 +0000320//===----------------------------------------------------------------------===//
321// General purpose USR generation methods.
322//===----------------------------------------------------------------------===//
Ted Kremenekcf84aa42010-01-18 20:23:29 +0000323
Ted Kremenek896b70f2010-03-13 02:50:34 +0000324void USRGenerator::GenNamedDecl(llvm::StringRef name) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000325 Out << "@" << name;
Ted Kremenek896b70f2010-03-13 02:50:34 +0000326}
327
328void USRGenerator::GenObjCClass(llvm::StringRef cls) {
329 Out << "objc(cs)" << cls;
330}
331
332void USRGenerator::GenObjCCategory(llvm::StringRef cls, llvm::StringRef cat) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000333 Out << "objc(cy)" << cls << '@' << cat;
Ted Kremenek896b70f2010-03-13 02:50:34 +0000334}
335
336void USRGenerator::GenObjCIvar(llvm::StringRef ivar) {
337 GenNamedDecl(ivar);
338}
339
340void USRGenerator::GenObjCMethod(llvm::StringRef meth, bool isInstanceMethod) {
341 Out << (isInstanceMethod ? "(im)" : "(cm)") << meth;
342}
343
344void USRGenerator::GenObjCProperty(llvm::StringRef prop) {
345 Out << "(py)" << prop;
346}
347
348void USRGenerator::GenObjCProtocol(llvm::StringRef prot) {
349 Out << "objc(pl)" << prot;
350}
351
352//===----------------------------------------------------------------------===//
353// API hooks.
354//===----------------------------------------------------------------------===//
Ted Kremenekcf84aa42010-01-18 20:23:29 +0000355
Benjamin Kramercfb51b62010-04-08 15:54:07 +0000356static inline llvm::StringRef extractUSRSuffix(llvm::StringRef s) {
357 return s.startswith("c:") ? s.substr(2) : "";
358}
359
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000360static CXString getDeclCursorUSR(const CXCursor &C) {
Ted Kremenek896b70f2010-03-13 02:50:34 +0000361 Decl *D = cxcursor::getCursorDecl(C);
Ted Kremeneke74ef122010-04-16 21:31:52 +0000362
363 // Don't generate USRs for things with invalid locations.
364 if (!D || D->getLocStart().isInvalid())
Ted Kremenek1af0a2a2010-04-17 00:21:38 +0000365 return createCXString("");
Ted Kremenek896b70f2010-03-13 02:50:34 +0000366
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000367 // Check if the cursor has 'NoLinkage'.
Ted Kremeneke74ef122010-04-16 21:31:52 +0000368 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000369 switch (ND->getLinkage()) {
370 case ExternalLinkage:
371 // Generate USRs for all entities with external linkage.
372 break;
373 case NoLinkage:
374 // We allow enums, typedefs, and structs that have no linkage to
375 // have USRs that are anchored to the file they were defined in
376 // (e.g., the header). This is a little gross, but in principal
377 // enums/anonymous structs/etc. defined in a common header file
378 // are referred to across multiple translation units.
Ted Kremenek6f153952010-04-15 21:51:13 +0000379 if (isa<TagDecl>(ND) || isa<TypedefDecl>(ND) ||
Ted Kremeneke74ef122010-04-16 21:31:52 +0000380 isa<EnumConstantDecl>(ND) || isa<FieldDecl>(ND))
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000381 break;
382 // Fall-through.
383 case InternalLinkage:
384 case UniqueExternalLinkage:
385 return createCXString("");
386 }
387
388 StringUSRGenerator SUG(&C);
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000389 SUG->Visit(D);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000390
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000391 if (SUG->ignoreResults())
Ted Kremenekebfa3392010-03-19 20:39:03 +0000392 return createCXString("");
Ted Kremenek896b70f2010-03-13 02:50:34 +0000393
Ted Kremeneke542f772010-04-20 23:15:40 +0000394 // For development testing.
395 // assert(SUG.str().size() > 2);
396
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000397 // Return a copy of the string that must be disposed by the caller.
Ted Kremenek896b70f2010-03-13 02:50:34 +0000398 return createCXString(SUG.str(), true);
399}
400
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000401extern "C" {
402
403CXString clang_getCursorUSR(CXCursor C) {
Ted Kremenekfa8231d2010-04-11 22:20:34 +0000404 const CXCursorKind &K = clang_getCursorKind(C);
405
406 if (clang_isDeclaration(K))
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000407 return getDeclCursorUSR(C);
Ted Kremenekfa8231d2010-04-11 22:20:34 +0000408
409 if (K == CXCursor_MacroDefinition) {
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000410 StringUSRGenerator SUG(&C);
Ted Kremenekfa8231d2010-04-11 22:20:34 +0000411 SUG << "macro@"
412 << cxcursor::getCursorMacroDefinition(C)->getName()->getNameStart();
413 return createCXString(SUG.str(), true);
414 }
415
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000416 return createCXString("");
417}
418
Ted Kremenek896b70f2010-03-13 02:50:34 +0000419CXString clang_constructUSR_ObjCIvar(const char *name, CXString classUSR) {
420 StringUSRGenerator SUG;
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000421 SUG << extractUSRSuffix(clang_getCString(classUSR));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000422 SUG->GenObjCIvar(name);
423 return createCXString(SUG.str(), true);
424}
425
426CXString clang_constructUSR_ObjCMethod(const char *name,
427 unsigned isInstanceMethod,
428 CXString classUSR) {
429 StringUSRGenerator SUG;
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000430 SUG << extractUSRSuffix(clang_getCString(classUSR));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000431 SUG->GenObjCMethod(name, isInstanceMethod);
432 return createCXString(SUG.str(), true);
433}
434
435CXString clang_constructUSR_ObjCClass(const char *name) {
436 StringUSRGenerator SUG;
437 SUG->GenObjCClass(name);
438 return createCXString(SUG.str(), true);
439}
440
441CXString clang_constructUSR_ObjCProtocol(const char *name) {
442 StringUSRGenerator SUG;
443 SUG->GenObjCProtocol(name);
444 return createCXString(SUG.str(), true);
445}
446
Ted Kremenek66ccaec2010-03-15 17:38:58 +0000447CXString clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000448 const char *category_name) {
Ted Kremenek896b70f2010-03-13 02:50:34 +0000449 StringUSRGenerator SUG;
450 SUG->GenObjCCategory(class_name, category_name);
451 return createCXString(SUG.str(), true);
452}
453
454CXString clang_constructUSR_ObjCProperty(const char *property,
455 CXString classUSR) {
456 StringUSRGenerator SUG;
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000457 SUG << extractUSRSuffix(clang_getCString(classUSR));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000458 SUG->GenObjCProperty(property);
459 return createCXString(SUG.str(), true);
Ted Kremenekcf84aa42010-01-18 20:23:29 +0000460}
Ted Kremenek1b6869a2010-01-05 22:06:45 +0000461
Ted Kremenek1b6869a2010-01-05 22:06:45 +0000462} // end extern "C"