blob: 58870b930b19d83174cdb50635ca010bcf6d8eac [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 VisitBlockDecl(BlockDecl *D);
42 void VisitDeclContext(DeclContext *D);
Ted Kremenek3adca6d2010-01-18 22:02:49 +000043 void VisitFieldDecl(FieldDecl *D);
Ted Kremenek2fee4e62010-01-14 01:50:21 +000044 void VisitFunctionDecl(FunctionDecl *D);
45 void VisitNamedDecl(NamedDecl *D);
46 void VisitNamespaceDecl(NamespaceDecl *D);
Ted Kremeneke74ef122010-04-16 21:31:52 +000047 void VisitObjCClassDecl(ObjCClassDecl *CD);
Ted Kremenek896b70f2010-03-13 02:50:34 +000048 void VisitObjCContainerDecl(ObjCContainerDecl *CD);
Ted Kremeneke74ef122010-04-16 21:31:52 +000049 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *P);
Ted Kremeneke542f772010-04-20 23:15:40 +000050 void VisitObjCMethodDecl(ObjCMethodDecl *MD);
Ted Kremenek2fee4e62010-01-14 01:50:21 +000051 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
Ted Kremeneke542f772010-04-20 23:15:40 +000052 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
Ted Kremenekb82b3be2010-01-18 22:42:20 +000053 void VisitTagDecl(TagDecl *D);
Ted Kremenek2fee4e62010-01-14 01:50:21 +000054 void VisitTypedefDecl(TypedefDecl *D);
Ted Kremeneke542f772010-04-20 23:15:40 +000055 void VisitVarDecl(VarDecl *D);
Ted Kremenek896b70f2010-03-13 02:50:34 +000056
Ted Kremenek6f153952010-04-15 21:51:13 +000057 /// Generate the string component containing the location of the
58 /// declaration.
59 void GenLoc(const Decl *D);
60
Ted Kremenek896b70f2010-03-13 02:50:34 +000061 /// String generation methods used both by the visitation methods
62 /// and from other clients that want to directly generate USRs. These
63 /// methods do not construct complete USRs (which incorporate the parents
64 /// of an AST element), but only the fragments concerning the AST element
65 /// itself.
66
67 /// Generate a USR fragment for a named declaration. This does
68 /// not include the USR component for the parent.
69 void GenNamedDecl(llvm::StringRef name);
70
71 /// Generate a USR for an Objective-C class.
72 void GenObjCClass(llvm::StringRef cls);
73 /// Generate a USR for an Objective-C class category.
74 void GenObjCCategory(llvm::StringRef cls, llvm::StringRef cat);
75 /// Generate a USR fragment for an Objective-C instance variable. The
76 /// complete USR can be created by concatenating the USR for the
77 /// encompassing class with this USR fragment.
78 void GenObjCIvar(llvm::StringRef ivar);
79 /// Generate a USR fragment for an Objective-C method.
80 void GenObjCMethod(llvm::StringRef sel, bool isInstanceMethod);
81 /// Generate a USR fragment for an Objective-C property.
82 void GenObjCProperty(llvm::StringRef prop);
83 /// Generate a USR for an Objective-C protocol.
84 void GenObjCProtocol(llvm::StringRef prot);
Ted Kremenek2fee4e62010-01-14 01:50:21 +000085};
Ted Kremenek896b70f2010-03-13 02:50:34 +000086
87class StringUSRGenerator {
88private:
89 llvm::SmallString<1024> StrBuf;
90 llvm::raw_svector_ostream Out;
91 USRGenerator UG;
92public:
Ted Kremenek1865cfe2010-04-15 21:04:25 +000093 StringUSRGenerator(const CXCursor *C = 0)
94 : Out(StrBuf), UG(C ? cxcursor::getCursorASTUnit(*C) : 0, Out) {
Ted Kremenek0c0fb412010-03-25 02:00:36 +000095 // Add the USR space prefix.
Ted Kremenek1865cfe2010-04-15 21:04:25 +000096 Out << "c:";
Ted Kremenek0c0fb412010-03-25 02:00:36 +000097 }
Ted Kremenek896b70f2010-03-13 02:50:34 +000098
99 llvm::StringRef str() {
100 return Out.str();
101 }
102
103 USRGenerator* operator->() { return &UG; }
104
105 template <typename T>
106 llvm::raw_svector_ostream &operator<<(const T &x) {
107 Out << x;
108 return Out;
109 }
110};
111
Ted Kremenekc50277f2010-01-12 23:33:42 +0000112} // end anonymous namespace
113
Ted Kremenek896b70f2010-03-13 02:50:34 +0000114//===----------------------------------------------------------------------===//
115// Generating USRs from ASTS.
116//===----------------------------------------------------------------------===//
117
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000118void USRGenerator::VisitBlockDecl(BlockDecl *D) {
119 VisitDeclContext(D->getDeclContext());
120 // FIXME: Better support for anonymous blocks.
Ted Kremeneke74ef122010-04-16 21:31:52 +0000121 Out << "@B@anon";
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000122}
123
124void USRGenerator::VisitDeclContext(DeclContext *DC) {
125 if (NamedDecl *D = dyn_cast<NamedDecl>(DC))
126 Visit(D);
127}
128
Ted Kremenek3adca6d2010-01-18 22:02:49 +0000129void USRGenerator::VisitFieldDecl(FieldDecl *D) {
130 const std::string &s = D->getNameAsString();
131 if (s.empty()) {
132 // Bit fields can be anonymous.
133 IgnoreResults = true;
134 return;
135 }
136 VisitDeclContext(D->getDeclContext());
Ted Kremeneke542f772010-04-20 23:15:40 +0000137 Out << (isa<ObjCIvarDecl>(D) ? "@" : "@FI@") << s;
Ted Kremenek3adca6d2010-01-18 22:02:49 +0000138}
139
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000140void USRGenerator::VisitFunctionDecl(FunctionDecl *D) {
141 VisitDeclContext(D->getDeclContext());
Benjamin Kramer900fc632010-04-17 09:33:03 +0000142 Out << "@F@" << D;
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000143}
Ted Kremenekc50277f2010-01-12 23:33:42 +0000144
145void USRGenerator::VisitNamedDecl(NamedDecl *D) {
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000146 VisitDeclContext(D->getDeclContext());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000147 const std::string &s = D->getNameAsString();
Ted Kremeneke74ef122010-04-16 21:31:52 +0000148 // The string can be empty if the declaration has no name; e.g., it is
149 // the ParmDecl with no name for declaration of a function pointer type, e.g.:
150 // void (*f)(void *);
151 // In this case, don't generate a USR.
152 if (s.empty())
153 IgnoreResults = true;
154 else
155 GenNamedDecl(s);
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000156}
157
Ted Kremeneke542f772010-04-20 23:15:40 +0000158void USRGenerator::VisitVarDecl(VarDecl *D) {
159 // VarDecls can be declared 'extern' within a function or method body,
160 // but their enclosing DeclContext is the function, not the TU. We need
161 // to check the storage class to correctly generate the USR.
162 if (!D->hasExternalStorage())
163 VisitDeclContext(D->getDeclContext());
164
165 const std::string &s = D->getNameAsString();
166 // The string can be empty if the declaration has no name; e.g., it is
167 // the ParmDecl with no name for declaration of a function pointer type, e.g.:
168 // void (*f)(void *);
169 // In this case, don't generate a USR.
170 if (s.empty())
171 IgnoreResults = true;
172 else
173 GenNamedDecl(s);
174}
175
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000176void USRGenerator::VisitNamespaceDecl(NamespaceDecl *D) {
177 VisitDeclContext(D->getDeclContext());
Benjamin Kramer900fc632010-04-17 09:33:03 +0000178 Out << "@N@" << D;
Ted Kremenekc50277f2010-01-12 23:33:42 +0000179}
180
Ted Kremenekc50277f2010-01-12 23:33:42 +0000181void USRGenerator::VisitObjCMethodDecl(ObjCMethodDecl *D) {
182 Visit(cast<Decl>(D->getDeclContext()));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000183 GenObjCMethod(DeclarationName(D->getSelector()).getAsString(),
184 D->isInstanceMethod());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000185}
186
Ted Kremeneke74ef122010-04-16 21:31:52 +0000187void USRGenerator::VisitObjCClassDecl(ObjCClassDecl *D) {
188 // FIXME: @class declarations can refer to multiple classes. We need
189 // to be able to traverse these.
190 IgnoreResults = true;
191}
192
193void USRGenerator::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
194 // FIXME: @protocol declarations can refer to multiple protocols. We need
195 // to be able to traverse these.
196 IgnoreResults = true;
197}
198
Ted Kremenekc50277f2010-01-12 23:33:42 +0000199void USRGenerator::VisitObjCContainerDecl(ObjCContainerDecl *D) {
200 switch (D->getKind()) {
201 default:
202 assert(false && "Invalid ObjC container.");
203 case Decl::ObjCInterface:
204 case Decl::ObjCImplementation:
Ted Kremenek896b70f2010-03-13 02:50:34 +0000205 GenObjCClass(D->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000206 break;
207 case Decl::ObjCCategory: {
208 ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(D);
Ted Kremenekebfa3392010-03-19 20:39:03 +0000209 ObjCInterfaceDecl *ID = CD->getClassInterface();
210 if (!ID) {
211 // Handle invalid code where the @interface might not
212 // have been specified.
213 // FIXME: We should be able to generate this USR even if the
214 // @interface isn't available.
215 IgnoreResults = true;
216 return;
217 }
218 GenObjCCategory(ID->getName(), CD->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000219 break;
220 }
221 case Decl::ObjCCategoryImpl: {
222 ObjCCategoryImplDecl *CD = cast<ObjCCategoryImplDecl>(D);
Ted Kremenekebfa3392010-03-19 20:39:03 +0000223 ObjCInterfaceDecl *ID = CD->getClassInterface();
224 if (!ID) {
225 // Handle invalid code where the @interface might not
226 // have been specified.
227 // FIXME: We should be able to generate this USR even if the
228 // @interface isn't available.
229 IgnoreResults = true;
230 return;
231 }
232 GenObjCCategory(ID->getName(), CD->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000233 break;
234 }
235 case Decl::ObjCProtocol:
Ted Kremenek896b70f2010-03-13 02:50:34 +0000236 GenObjCProtocol(cast<ObjCProtocolDecl>(D)->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000237 break;
238 }
239}
240
241void USRGenerator::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
242 Visit(cast<Decl>(D->getDeclContext()));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000243 GenObjCProperty(D->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000244}
245
Ted Kremeneke542f772010-04-20 23:15:40 +0000246void USRGenerator::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
247 if (ObjCPropertyDecl *PD = D->getPropertyDecl()) {
248 VisitObjCPropertyDecl(PD);
249 return;
250 }
251
252 IgnoreResults = true;
253}
254
Ted Kremenekb82b3be2010-01-18 22:42:20 +0000255void USRGenerator::VisitTagDecl(TagDecl *D) {
Ted Kremenek6f153952010-04-15 21:51:13 +0000256 D = D->getCanonicalDecl();
Ted Kremenekb82b3be2010-01-18 22:42:20 +0000257 VisitDeclContext(D->getDeclContext());
258 switch (D->getTagKind()) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000259 case TagDecl::TK_struct: Out << "@S"; break;
260 case TagDecl::TK_class: Out << "@C"; break;
261 case TagDecl::TK_union: Out << "@U"; break;
262 case TagDecl::TK_enum: Out << "@E"; break;
263 }
264
265 const std::string &s = D->getNameAsString();
266 const TypedefDecl *TD = 0;
267 if (s.empty()) {
268 TD = D->getTypedefForAnonDecl();
269 Out << (TD ? 'A' : 'a');
Ted Kremenekb82b3be2010-01-18 22:42:20 +0000270 }
Ted Kremenek896b70f2010-03-13 02:50:34 +0000271
Ted Kremenek6f153952010-04-15 21:51:13 +0000272 // Add the location of the tag decl to handle resolution across
273 // translation units.
274 if (D->getLinkage() == NoLinkage) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000275 Out << '@';
Ted Kremenek6f153952010-04-15 21:51:13 +0000276 GenLoc(D);
277 if (IgnoreResults)
278 return;
279 }
280
Ted Kremenekc5b48b32010-01-15 23:34:31 +0000281 if (s.empty()) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000282 if (TD)
Benjamin Kramer900fc632010-04-17 09:33:03 +0000283 Out << '@' << TD;
Ted Kremenekc5b48b32010-01-15 23:34:31 +0000284 }
285 else
Ted Kremeneke74ef122010-04-16 21:31:52 +0000286 Out << '@' << s;
Ted Kremenekc5b48b32010-01-15 23:34:31 +0000287}
288
Ted Kremenekc50277f2010-01-12 23:33:42 +0000289void USRGenerator::VisitTypedefDecl(TypedefDecl *D) {
290 DeclContext *DC = D->getDeclContext();
291 if (NamedDecl *DCN = dyn_cast<NamedDecl>(DC))
Ted Kremenek896b70f2010-03-13 02:50:34 +0000292 Visit(DCN);
Ted Kremeneke74ef122010-04-16 21:31:52 +0000293 Out << "@T@";
294 if (D->getLinkage() == NoLinkage) {
295 GenLoc(D);
296 if (IgnoreResults)
297 return;
298 Out << '@';
299 }
Ted Kremenek6f153952010-04-15 21:51:13 +0000300 Out << D->getName();
301}
302
303void USRGenerator::GenLoc(const Decl *D) {
304 const SourceManager &SM = AU->getSourceManager();
305 SourceLocation L = D->getLocStart();
306 if (L.isInvalid()) {
307 IgnoreResults = true;
308 return;
309 }
310 L = SM.getInstantiationLoc(L);
311 const std::pair<FileID, unsigned> &Decomposed = SM.getDecomposedLoc(L);
312 const FileEntry *FE = SM.getFileEntryForID(Decomposed.first);
Ted Kremeneke74ef122010-04-16 21:31:52 +0000313 if (FE) {
314 llvm::sys::Path P(FE->getName());
315 Out << P.getLast();
316 }
Ted Kremenek6f153952010-04-15 21:51:13 +0000317 else {
318 // This case really isn't interesting.
319 IgnoreResults = true;
320 return;
321 }
Ted Kremeneke74ef122010-04-16 21:31:52 +0000322 Out << '@'
323 << SM.getLineNumber(Decomposed.first, Decomposed.second) << ':'
324 << SM.getColumnNumber(Decomposed.first, Decomposed.second);
Ted Kremenekc50277f2010-01-12 23:33:42 +0000325}
326
Ted Kremenek896b70f2010-03-13 02:50:34 +0000327//===----------------------------------------------------------------------===//
328// General purpose USR generation methods.
329//===----------------------------------------------------------------------===//
Ted Kremenekcf84aa42010-01-18 20:23:29 +0000330
Ted Kremenek896b70f2010-03-13 02:50:34 +0000331void USRGenerator::GenNamedDecl(llvm::StringRef name) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000332 Out << "@" << name;
Ted Kremenek896b70f2010-03-13 02:50:34 +0000333}
334
335void USRGenerator::GenObjCClass(llvm::StringRef cls) {
336 Out << "objc(cs)" << cls;
337}
338
339void USRGenerator::GenObjCCategory(llvm::StringRef cls, llvm::StringRef cat) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000340 Out << "objc(cy)" << cls << '@' << cat;
Ted Kremenek896b70f2010-03-13 02:50:34 +0000341}
342
343void USRGenerator::GenObjCIvar(llvm::StringRef ivar) {
344 GenNamedDecl(ivar);
345}
346
347void USRGenerator::GenObjCMethod(llvm::StringRef meth, bool isInstanceMethod) {
348 Out << (isInstanceMethod ? "(im)" : "(cm)") << meth;
349}
350
351void USRGenerator::GenObjCProperty(llvm::StringRef prop) {
352 Out << "(py)" << prop;
353}
354
355void USRGenerator::GenObjCProtocol(llvm::StringRef prot) {
356 Out << "objc(pl)" << prot;
357}
358
359//===----------------------------------------------------------------------===//
360// API hooks.
361//===----------------------------------------------------------------------===//
Ted Kremenekcf84aa42010-01-18 20:23:29 +0000362
Benjamin Kramercfb51b62010-04-08 15:54:07 +0000363static inline llvm::StringRef extractUSRSuffix(llvm::StringRef s) {
364 return s.startswith("c:") ? s.substr(2) : "";
365}
366
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000367static CXString getDeclCursorUSR(const CXCursor &C) {
Ted Kremenek896b70f2010-03-13 02:50:34 +0000368 Decl *D = cxcursor::getCursorDecl(C);
Ted Kremeneke74ef122010-04-16 21:31:52 +0000369
370 // Don't generate USRs for things with invalid locations.
371 if (!D || D->getLocStart().isInvalid())
Ted Kremenek1af0a2a2010-04-17 00:21:38 +0000372 return createCXString("");
Ted Kremenek896b70f2010-03-13 02:50:34 +0000373
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000374 // Check if the cursor has 'NoLinkage'.
Ted Kremeneke74ef122010-04-16 21:31:52 +0000375 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000376 switch (ND->getLinkage()) {
377 case ExternalLinkage:
378 // Generate USRs for all entities with external linkage.
379 break;
380 case NoLinkage:
381 // We allow enums, typedefs, and structs that have no linkage to
382 // have USRs that are anchored to the file they were defined in
383 // (e.g., the header). This is a little gross, but in principal
384 // enums/anonymous structs/etc. defined in a common header file
385 // are referred to across multiple translation units.
Ted Kremenek6f153952010-04-15 21:51:13 +0000386 if (isa<TagDecl>(ND) || isa<TypedefDecl>(ND) ||
Ted Kremeneke74ef122010-04-16 21:31:52 +0000387 isa<EnumConstantDecl>(ND) || isa<FieldDecl>(ND))
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000388 break;
389 // Fall-through.
390 case InternalLinkage:
391 case UniqueExternalLinkage:
392 return createCXString("");
393 }
394
395 StringUSRGenerator SUG(&C);
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000396 SUG->Visit(D);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000397
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000398 if (SUG->ignoreResults())
Ted Kremenekebfa3392010-03-19 20:39:03 +0000399 return createCXString("");
Ted Kremenek896b70f2010-03-13 02:50:34 +0000400
Ted Kremeneke542f772010-04-20 23:15:40 +0000401 // For development testing.
402 // assert(SUG.str().size() > 2);
403
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000404 // Return a copy of the string that must be disposed by the caller.
Ted Kremenek896b70f2010-03-13 02:50:34 +0000405 return createCXString(SUG.str(), true);
406}
407
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000408extern "C" {
409
410CXString clang_getCursorUSR(CXCursor C) {
Ted Kremenekfa8231d2010-04-11 22:20:34 +0000411 const CXCursorKind &K = clang_getCursorKind(C);
412
413 if (clang_isDeclaration(K))
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000414 return getDeclCursorUSR(C);
Ted Kremenekfa8231d2010-04-11 22:20:34 +0000415
416 if (K == CXCursor_MacroDefinition) {
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000417 StringUSRGenerator SUG(&C);
Ted Kremenekfa8231d2010-04-11 22:20:34 +0000418 SUG << "macro@"
419 << cxcursor::getCursorMacroDefinition(C)->getName()->getNameStart();
420 return createCXString(SUG.str(), true);
421 }
422
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000423 return createCXString("");
424}
425
Ted Kremenek896b70f2010-03-13 02:50:34 +0000426CXString clang_constructUSR_ObjCIvar(const char *name, CXString classUSR) {
427 StringUSRGenerator SUG;
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000428 SUG << extractUSRSuffix(clang_getCString(classUSR));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000429 SUG->GenObjCIvar(name);
430 return createCXString(SUG.str(), true);
431}
432
433CXString clang_constructUSR_ObjCMethod(const char *name,
434 unsigned isInstanceMethod,
435 CXString classUSR) {
436 StringUSRGenerator SUG;
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000437 SUG << extractUSRSuffix(clang_getCString(classUSR));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000438 SUG->GenObjCMethod(name, isInstanceMethod);
439 return createCXString(SUG.str(), true);
440}
441
442CXString clang_constructUSR_ObjCClass(const char *name) {
443 StringUSRGenerator SUG;
444 SUG->GenObjCClass(name);
445 return createCXString(SUG.str(), true);
446}
447
448CXString clang_constructUSR_ObjCProtocol(const char *name) {
449 StringUSRGenerator SUG;
450 SUG->GenObjCProtocol(name);
451 return createCXString(SUG.str(), true);
452}
453
Ted Kremenek66ccaec2010-03-15 17:38:58 +0000454CXString clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000455 const char *category_name) {
Ted Kremenek896b70f2010-03-13 02:50:34 +0000456 StringUSRGenerator SUG;
457 SUG->GenObjCCategory(class_name, category_name);
458 return createCXString(SUG.str(), true);
459}
460
461CXString clang_constructUSR_ObjCProperty(const char *property,
462 CXString classUSR) {
463 StringUSRGenerator SUG;
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000464 SUG << extractUSRSuffix(clang_getCString(classUSR));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000465 SUG->GenObjCProperty(property);
466 return createCXString(SUG.str(), true);
Ted Kremenekcf84aa42010-01-18 20:23:29 +0000467}
Ted Kremenek1b6869a2010-01-05 22:06:45 +0000468
Ted Kremenek1b6869a2010-01-05 22:06:45 +0000469} // end extern "C"