blob: f3c74e85316f5f074f6a74f04d4eff06a07bc2c9 [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) {
Ted Kremenekcf999102010-04-29 17:43:29 +0000134 if (D->getLinkage() != ExternalLinkage) {
135 GenLoc(D);
136 if (IgnoreResults)
137 return;
138 }
139 else
140 VisitDeclContext(D->getDeclContext());
141
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.
Ted Kremenekcf999102010-04-29 17:43:29 +0000162 if (D->getLinkage() != ExternalLinkage) {
163 GenLoc(D);
164 if (IgnoreResults)
165 return;
166 }
Ted Kremeneke542f772010-04-20 23:15:40 +0000167
Ted Kremenekcf999102010-04-29 17:43:29 +0000168 // Variables always have simple names.
169 llvm::StringRef s = D->getName();
170
Ted Kremeneke542f772010-04-20 23:15:40 +0000171 // The string can be empty if the declaration has no name; e.g., it is
172 // the ParmDecl with no name for declaration of a function pointer type, e.g.:
173 // void (*f)(void *);
174 // In this case, don't generate a USR.
175 if (s.empty())
176 IgnoreResults = true;
177 else
178 GenNamedDecl(s);
179}
180
Ted Kremenek2fee4e62010-01-14 01:50:21 +0000181void USRGenerator::VisitNamespaceDecl(NamespaceDecl *D) {
182 VisitDeclContext(D->getDeclContext());
Benjamin Kramer900fc632010-04-17 09:33:03 +0000183 Out << "@N@" << D;
Ted Kremenekc50277f2010-01-12 23:33:42 +0000184}
185
Ted Kremenekc50277f2010-01-12 23:33:42 +0000186void USRGenerator::VisitObjCMethodDecl(ObjCMethodDecl *D) {
187 Visit(cast<Decl>(D->getDeclContext()));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000188 GenObjCMethod(DeclarationName(D->getSelector()).getAsString(),
189 D->isInstanceMethod());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000190}
191
Ted Kremeneke74ef122010-04-16 21:31:52 +0000192void USRGenerator::VisitObjCClassDecl(ObjCClassDecl *D) {
193 // FIXME: @class declarations can refer to multiple classes. We need
194 // to be able to traverse these.
195 IgnoreResults = true;
196}
197
198void USRGenerator::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) {
199 // FIXME: @protocol declarations can refer to multiple protocols. We need
200 // to be able to traverse these.
201 IgnoreResults = true;
202}
203
Ted Kremenekc50277f2010-01-12 23:33:42 +0000204void USRGenerator::VisitObjCContainerDecl(ObjCContainerDecl *D) {
205 switch (D->getKind()) {
206 default:
207 assert(false && "Invalid ObjC container.");
208 case Decl::ObjCInterface:
209 case Decl::ObjCImplementation:
Ted Kremenek896b70f2010-03-13 02:50:34 +0000210 GenObjCClass(D->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000211 break;
212 case Decl::ObjCCategory: {
213 ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(D);
Ted Kremenekebfa3392010-03-19 20:39:03 +0000214 ObjCInterfaceDecl *ID = CD->getClassInterface();
215 if (!ID) {
216 // Handle invalid code where the @interface might not
217 // have been specified.
218 // FIXME: We should be able to generate this USR even if the
219 // @interface isn't available.
220 IgnoreResults = true;
221 return;
222 }
223 GenObjCCategory(ID->getName(), CD->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000224 break;
225 }
226 case Decl::ObjCCategoryImpl: {
227 ObjCCategoryImplDecl *CD = cast<ObjCCategoryImplDecl>(D);
Ted Kremenekebfa3392010-03-19 20:39:03 +0000228 ObjCInterfaceDecl *ID = CD->getClassInterface();
229 if (!ID) {
230 // Handle invalid code where the @interface might not
231 // have been specified.
232 // FIXME: We should be able to generate this USR even if the
233 // @interface isn't available.
234 IgnoreResults = true;
235 return;
236 }
237 GenObjCCategory(ID->getName(), CD->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000238 break;
239 }
240 case Decl::ObjCProtocol:
Ted Kremenek896b70f2010-03-13 02:50:34 +0000241 GenObjCProtocol(cast<ObjCProtocolDecl>(D)->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000242 break;
243 }
244}
245
246void USRGenerator::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
247 Visit(cast<Decl>(D->getDeclContext()));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000248 GenObjCProperty(D->getName());
Ted Kremenekc50277f2010-01-12 23:33:42 +0000249}
250
Ted Kremeneke542f772010-04-20 23:15:40 +0000251void USRGenerator::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
252 if (ObjCPropertyDecl *PD = D->getPropertyDecl()) {
253 VisitObjCPropertyDecl(PD);
254 return;
255 }
256
257 IgnoreResults = true;
258}
259
Ted Kremenekb82b3be2010-01-18 22:42:20 +0000260void USRGenerator::VisitTagDecl(TagDecl *D) {
Ted Kremenek6f153952010-04-15 21:51:13 +0000261 D = D->getCanonicalDecl();
Ted Kremenekb82b3be2010-01-18 22:42:20 +0000262 VisitDeclContext(D->getDeclContext());
263 switch (D->getTagKind()) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000264 case TagDecl::TK_struct: Out << "@S"; break;
265 case TagDecl::TK_class: Out << "@C"; break;
266 case TagDecl::TK_union: Out << "@U"; break;
267 case TagDecl::TK_enum: Out << "@E"; break;
268 }
269
270 const std::string &s = D->getNameAsString();
271 const TypedefDecl *TD = 0;
272 if (s.empty()) {
273 TD = D->getTypedefForAnonDecl();
274 Out << (TD ? 'A' : 'a');
Ted Kremenekb82b3be2010-01-18 22:42:20 +0000275 }
Ted Kremenek896b70f2010-03-13 02:50:34 +0000276
Ted Kremenek6f153952010-04-15 21:51:13 +0000277 // Add the location of the tag decl to handle resolution across
278 // translation units.
279 if (D->getLinkage() == NoLinkage) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000280 Out << '@';
Ted Kremenek6f153952010-04-15 21:51:13 +0000281 GenLoc(D);
282 if (IgnoreResults)
283 return;
284 }
285
Ted Kremenekc5b48b32010-01-15 23:34:31 +0000286 if (s.empty()) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000287 if (TD)
Benjamin Kramer900fc632010-04-17 09:33:03 +0000288 Out << '@' << TD;
Ted Kremenekc5b48b32010-01-15 23:34:31 +0000289 }
290 else
Ted Kremeneke74ef122010-04-16 21:31:52 +0000291 Out << '@' << s;
Ted Kremenekc5b48b32010-01-15 23:34:31 +0000292}
293
Ted Kremenekc50277f2010-01-12 23:33:42 +0000294void USRGenerator::VisitTypedefDecl(TypedefDecl *D) {
295 DeclContext *DC = D->getDeclContext();
296 if (NamedDecl *DCN = dyn_cast<NamedDecl>(DC))
Ted Kremenek896b70f2010-03-13 02:50:34 +0000297 Visit(DCN);
Ted Kremeneke74ef122010-04-16 21:31:52 +0000298 Out << "@T@";
299 if (D->getLinkage() == NoLinkage) {
300 GenLoc(D);
301 if (IgnoreResults)
302 return;
303 Out << '@';
304 }
Ted Kremenek6f153952010-04-15 21:51:13 +0000305 Out << D->getName();
306}
307
308void USRGenerator::GenLoc(const Decl *D) {
309 const SourceManager &SM = AU->getSourceManager();
310 SourceLocation L = D->getLocStart();
311 if (L.isInvalid()) {
312 IgnoreResults = true;
313 return;
314 }
315 L = SM.getInstantiationLoc(L);
316 const std::pair<FileID, unsigned> &Decomposed = SM.getDecomposedLoc(L);
317 const FileEntry *FE = SM.getFileEntryForID(Decomposed.first);
Ted Kremeneke74ef122010-04-16 21:31:52 +0000318 if (FE) {
319 llvm::sys::Path P(FE->getName());
320 Out << P.getLast();
321 }
Ted Kremenek6f153952010-04-15 21:51:13 +0000322 else {
323 // This case really isn't interesting.
324 IgnoreResults = true;
325 return;
326 }
Ted Kremeneke74ef122010-04-16 21:31:52 +0000327 Out << '@'
328 << SM.getLineNumber(Decomposed.first, Decomposed.second) << ':'
329 << SM.getColumnNumber(Decomposed.first, Decomposed.second);
Ted Kremenekc50277f2010-01-12 23:33:42 +0000330}
331
Ted Kremenek896b70f2010-03-13 02:50:34 +0000332//===----------------------------------------------------------------------===//
333// General purpose USR generation methods.
334//===----------------------------------------------------------------------===//
Ted Kremenekcf84aa42010-01-18 20:23:29 +0000335
Ted Kremenek896b70f2010-03-13 02:50:34 +0000336void USRGenerator::GenNamedDecl(llvm::StringRef name) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000337 Out << "@" << name;
Ted Kremenek896b70f2010-03-13 02:50:34 +0000338}
339
340void USRGenerator::GenObjCClass(llvm::StringRef cls) {
341 Out << "objc(cs)" << cls;
342}
343
344void USRGenerator::GenObjCCategory(llvm::StringRef cls, llvm::StringRef cat) {
Ted Kremeneke74ef122010-04-16 21:31:52 +0000345 Out << "objc(cy)" << cls << '@' << cat;
Ted Kremenek896b70f2010-03-13 02:50:34 +0000346}
347
348void USRGenerator::GenObjCIvar(llvm::StringRef ivar) {
349 GenNamedDecl(ivar);
350}
351
352void USRGenerator::GenObjCMethod(llvm::StringRef meth, bool isInstanceMethod) {
353 Out << (isInstanceMethod ? "(im)" : "(cm)") << meth;
354}
355
356void USRGenerator::GenObjCProperty(llvm::StringRef prop) {
357 Out << "(py)" << prop;
358}
359
360void USRGenerator::GenObjCProtocol(llvm::StringRef prot) {
361 Out << "objc(pl)" << prot;
362}
363
364//===----------------------------------------------------------------------===//
365// API hooks.
366//===----------------------------------------------------------------------===//
Ted Kremenekcf84aa42010-01-18 20:23:29 +0000367
Benjamin Kramercfb51b62010-04-08 15:54:07 +0000368static inline llvm::StringRef extractUSRSuffix(llvm::StringRef s) {
369 return s.startswith("c:") ? s.substr(2) : "";
370}
371
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000372static CXString getDeclCursorUSR(const CXCursor &C) {
Ted Kremenek896b70f2010-03-13 02:50:34 +0000373 Decl *D = cxcursor::getCursorDecl(C);
Ted Kremeneke74ef122010-04-16 21:31:52 +0000374
375 // Don't generate USRs for things with invalid locations.
376 if (!D || D->getLocStart().isInvalid())
Ted Kremenek1af0a2a2010-04-17 00:21:38 +0000377 return createCXString("");
Ted Kremenek896b70f2010-03-13 02:50:34 +0000378
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000379 // Check if the cursor has 'NoLinkage'.
Ted Kremeneke74ef122010-04-16 21:31:52 +0000380 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000381 switch (ND->getLinkage()) {
382 case ExternalLinkage:
383 // Generate USRs for all entities with external linkage.
384 break;
385 case NoLinkage:
386 // We allow enums, typedefs, and structs that have no linkage to
387 // have USRs that are anchored to the file they were defined in
388 // (e.g., the header). This is a little gross, but in principal
389 // enums/anonymous structs/etc. defined in a common header file
390 // are referred to across multiple translation units.
Ted Kremenek6f153952010-04-15 21:51:13 +0000391 if (isa<TagDecl>(ND) || isa<TypedefDecl>(ND) ||
Ted Kremenekcf999102010-04-29 17:43:29 +0000392 isa<EnumConstantDecl>(ND) || isa<FieldDecl>(ND) ||
393 isa<VarDecl>(ND))
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000394 break;
395 // Fall-through.
396 case InternalLinkage:
Ted Kremenekcf999102010-04-29 17:43:29 +0000397 if (isa<FunctionDecl>(ND))
398 break;
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000399 case UniqueExternalLinkage:
400 return createCXString("");
401 }
402
403 StringUSRGenerator SUG(&C);
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000404 SUG->Visit(D);
Ted Kremenek896b70f2010-03-13 02:50:34 +0000405
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000406 if (SUG->ignoreResults())
Ted Kremenekebfa3392010-03-19 20:39:03 +0000407 return createCXString("");
Ted Kremenek896b70f2010-03-13 02:50:34 +0000408
Ted Kremeneke542f772010-04-20 23:15:40 +0000409 // For development testing.
410 // assert(SUG.str().size() > 2);
411
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000412 // Return a copy of the string that must be disposed by the caller.
Ted Kremenek896b70f2010-03-13 02:50:34 +0000413 return createCXString(SUG.str(), true);
414}
415
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000416extern "C" {
417
418CXString clang_getCursorUSR(CXCursor C) {
Ted Kremenekfa8231d2010-04-11 22:20:34 +0000419 const CXCursorKind &K = clang_getCursorKind(C);
420
421 if (clang_isDeclaration(K))
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000422 return getDeclCursorUSR(C);
Ted Kremenekfa8231d2010-04-11 22:20:34 +0000423
424 if (K == CXCursor_MacroDefinition) {
Ted Kremenek1865cfe2010-04-15 21:04:25 +0000425 StringUSRGenerator SUG(&C);
Ted Kremenekfa8231d2010-04-11 22:20:34 +0000426 SUG << "macro@"
427 << cxcursor::getCursorMacroDefinition(C)->getName()->getNameStart();
428 return createCXString(SUG.str(), true);
429 }
430
Ted Kremenekc3ef91d2010-04-11 22:20:26 +0000431 return createCXString("");
432}
433
Ted Kremenek896b70f2010-03-13 02:50:34 +0000434CXString clang_constructUSR_ObjCIvar(const char *name, CXString classUSR) {
435 StringUSRGenerator SUG;
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000436 SUG << extractUSRSuffix(clang_getCString(classUSR));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000437 SUG->GenObjCIvar(name);
438 return createCXString(SUG.str(), true);
439}
440
441CXString clang_constructUSR_ObjCMethod(const char *name,
442 unsigned isInstanceMethod,
443 CXString classUSR) {
444 StringUSRGenerator SUG;
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000445 SUG << extractUSRSuffix(clang_getCString(classUSR));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000446 SUG->GenObjCMethod(name, isInstanceMethod);
447 return createCXString(SUG.str(), true);
448}
449
450CXString clang_constructUSR_ObjCClass(const char *name) {
451 StringUSRGenerator SUG;
452 SUG->GenObjCClass(name);
453 return createCXString(SUG.str(), true);
454}
455
456CXString clang_constructUSR_ObjCProtocol(const char *name) {
457 StringUSRGenerator SUG;
458 SUG->GenObjCProtocol(name);
459 return createCXString(SUG.str(), true);
460}
461
Ted Kremenek66ccaec2010-03-15 17:38:58 +0000462CXString clang_constructUSR_ObjCCategory(const char *class_name,
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000463 const char *category_name) {
Ted Kremenek896b70f2010-03-13 02:50:34 +0000464 StringUSRGenerator SUG;
465 SUG->GenObjCCategory(class_name, category_name);
466 return createCXString(SUG.str(), true);
467}
468
469CXString clang_constructUSR_ObjCProperty(const char *property,
470 CXString classUSR) {
471 StringUSRGenerator SUG;
Ted Kremenek0c0fb412010-03-25 02:00:36 +0000472 SUG << extractUSRSuffix(clang_getCString(classUSR));
Ted Kremenek896b70f2010-03-13 02:50:34 +0000473 SUG->GenObjCProperty(property);
474 return createCXString(SUG.str(), true);
Ted Kremenekcf84aa42010-01-18 20:23:29 +0000475}
Ted Kremenek1b6869a2010-01-05 22:06:45 +0000476
Ted Kremenek1b6869a2010-01-05 22:06:45 +0000477} // end extern "C"