Ted Kremenek | 1b6869a | 2010-01-05 22:06:45 +0000 | [diff] [blame] | 1 | //===- 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 Kremenek | cf84aa4 | 2010-01-18 20:23:29 +0000 | [diff] [blame] | 15 | #include "CXCursor.h" |
Ted Kremenek | ed12273 | 2010-11-16 01:56:27 +0000 | [diff] [blame] | 16 | #include "CXString.h" |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclTemplate.h" |
Benjamin Kramer | 9895c6a | 2010-01-12 11:32:40 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclVisitor.h" |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 19 | #include "clang/Frontend/ASTUnit.h" |
Benjamin Kramer | b846deb | 2010-04-12 19:45:50 +0000 | [diff] [blame] | 20 | #include "clang/Lex/PreprocessingRecord.h" |
Ted Kremenek | 8776382 | 2010-01-12 02:07:58 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallString.h" |
Benjamin Kramer | 9895c6a | 2010-01-12 11:32:40 +0000 | [diff] [blame] | 22 | #include "llvm/Support/raw_ostream.h" |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 23 | |
Benjamin Kramer | b846deb | 2010-04-12 19:45:50 +0000 | [diff] [blame] | 24 | using namespace clang; |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 25 | using namespace clang::cxstring; |
| 26 | |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 27 | //===----------------------------------------------------------------------===// |
| 28 | // USR generation. |
| 29 | //===----------------------------------------------------------------------===// |
| 30 | |
| 31 | namespace { |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 32 | class USRGenerator : public DeclVisitor<USRGenerator> { |
Dylan Noblesmith | 36d5927 | 2012-02-13 12:32:26 +0000 | [diff] [blame] | 33 | OwningPtr<SmallString<128> > OwnedBuf; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 34 | SmallVectorImpl<char> &Buf; |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 35 | llvm::raw_svector_ostream Out; |
Ted Kremenek | 3adca6d | 2010-01-18 22:02:49 +0000 | [diff] [blame] | 36 | bool IgnoreResults; |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 37 | ASTContext *Context; |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 38 | bool generatedLoc; |
Douglas Gregor | 66b7fbf | 2010-09-20 20:37:39 +0000 | [diff] [blame] | 39 | |
| 40 | llvm::DenseMap<const Type *, unsigned> TypeSubstitutions; |
| 41 | |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 42 | public: |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 43 | explicit USRGenerator(ASTContext *Ctx = 0, SmallVectorImpl<char> *extBuf = 0) |
Dylan Noblesmith | 36d5927 | 2012-02-13 12:32:26 +0000 | [diff] [blame] | 44 | : OwnedBuf(extBuf ? 0 : new SmallString<128>()), |
Ted Kremenek | f019943 | 2010-11-16 08:15:38 +0000 | [diff] [blame] | 45 | Buf(extBuf ? *extBuf : *OwnedBuf.get()), |
| 46 | Out(Buf), |
| 47 | IgnoreResults(false), |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 48 | Context(Ctx), |
Ted Kremenek | f019943 | 2010-11-16 08:15:38 +0000 | [diff] [blame] | 49 | generatedLoc(false) |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 50 | { |
| 51 | // Add the USR space prefix. |
| 52 | Out << "c:"; |
| 53 | } |
| 54 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 55 | StringRef str() { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 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 Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 66 | |
Ted Kremenek | 3adca6d | 2010-01-18 22:02:49 +0000 | [diff] [blame] | 67 | bool ignoreResults() const { return IgnoreResults; } |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 68 | |
| 69 | // Visitation methods from generating USRs from AST elements. |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 70 | void VisitDeclContext(DeclContext *D); |
Ted Kremenek | 3adca6d | 2010-01-18 22:02:49 +0000 | [diff] [blame] | 71 | void VisitFieldDecl(FieldDecl *D); |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 72 | void VisitFunctionDecl(FunctionDecl *D); |
| 73 | void VisitNamedDecl(NamedDecl *D); |
| 74 | void VisitNamespaceDecl(NamespaceDecl *D); |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 75 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 76 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 77 | void VisitClassTemplateDecl(ClassTemplateDecl *D); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 78 | void VisitObjCContainerDecl(ObjCContainerDecl *CD); |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 79 | void VisitObjCMethodDecl(ObjCMethodDecl *MD); |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 80 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 81 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
Ted Kremenek | b82b3be | 2010-01-18 22:42:20 +0000 | [diff] [blame] | 82 | void VisitTagDecl(TagDecl *D); |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 83 | void VisitTypedefDecl(TypedefDecl *D); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 84 | void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 85 | void VisitVarDecl(VarDecl *D); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 86 | void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
| 87 | void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 88 | void VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
| 89 | IgnoreResults = true; |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 90 | } |
Douglas Gregor | 0a35bce | 2010-09-01 03:07:18 +0000 | [diff] [blame] | 91 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
| 92 | IgnoreResults = true; |
| 93 | } |
Douglas Gregor | 7e24256 | 2010-09-01 19:52:22 +0000 | [diff] [blame] | 94 | void VisitUsingDecl(UsingDecl *D) { |
| 95 | IgnoreResults = true; |
| 96 | } |
| 97 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
| 98 | IgnoreResults = true; |
| 99 | } |
| 100 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) { |
| 101 | IgnoreResults = true; |
| 102 | } |
Douglas Gregor | 0a35bce | 2010-09-01 03:07:18 +0000 | [diff] [blame] | 103 | |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 104 | /// Generate the string component containing the location of the |
| 105 | /// declaration. |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 106 | bool GenLoc(const Decl *D); |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 107 | |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 108 | /// String generation methods used both by the visitation methods |
| 109 | /// and from other clients that want to directly generate USRs. These |
| 110 | /// methods do not construct complete USRs (which incorporate the parents |
| 111 | /// of an AST element), but only the fragments concerning the AST element |
| 112 | /// itself. |
| 113 | |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 114 | /// Generate a USR for an Objective-C class. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 115 | void GenObjCClass(StringRef cls); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 116 | /// Generate a USR for an Objective-C class category. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 117 | void GenObjCCategory(StringRef cls, StringRef cat); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 118 | /// Generate a USR fragment for an Objective-C instance variable. The |
| 119 | /// complete USR can be created by concatenating the USR for the |
| 120 | /// encompassing class with this USR fragment. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 121 | void GenObjCIvar(StringRef ivar); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 122 | /// Generate a USR fragment for an Objective-C method. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 123 | void GenObjCMethod(StringRef sel, bool isInstanceMethod); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 124 | /// Generate a USR fragment for an Objective-C property. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 125 | void GenObjCProperty(StringRef prop); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 126 | /// Generate a USR for an Objective-C protocol. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 127 | void GenObjCProtocol(StringRef prot); |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 128 | |
| 129 | void VisitType(QualType T); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 130 | void VisitTemplateParameterList(const TemplateParameterList *Params); |
| 131 | void VisitTemplateName(TemplateName Name); |
| 132 | void VisitTemplateArgument(const TemplateArgument &Arg); |
| 133 | |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 134 | /// Emit a Decl's name using NamedDecl::printName() and return true if |
| 135 | /// the decl had no name. |
| 136 | bool EmitDeclName(const NamedDecl *D); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 139 | } // end anonymous namespace |
| 140 | |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 141 | //===----------------------------------------------------------------------===// |
| 142 | // Generating USRs from ASTS. |
| 143 | //===----------------------------------------------------------------------===// |
| 144 | |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 145 | bool USRGenerator::EmitDeclName(const NamedDecl *D) { |
| 146 | Out.flush(); |
| 147 | const unsigned startSize = Buf.size(); |
| 148 | D->printName(Out); |
| 149 | Out.flush(); |
| 150 | const unsigned endSize = Buf.size(); |
| 151 | return startSize == endSize; |
| 152 | } |
| 153 | |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 154 | static bool InAnonymousNamespace(const Decl *D) { |
| 155 | if (const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(D->getDeclContext())) |
| 156 | return ND->isAnonymousNamespace(); |
| 157 | return false; |
| 158 | } |
| 159 | |
| 160 | static inline bool ShouldGenerateLocation(const NamedDecl *D) { |
| 161 | return D->getLinkage() != ExternalLinkage && !InAnonymousNamespace(D); |
| 162 | } |
| 163 | |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 164 | void USRGenerator::VisitDeclContext(DeclContext *DC) { |
| 165 | if (NamedDecl *D = dyn_cast<NamedDecl>(DC)) |
| 166 | Visit(D); |
| 167 | } |
| 168 | |
Ted Kremenek | 3adca6d | 2010-01-18 22:02:49 +0000 | [diff] [blame] | 169 | void USRGenerator::VisitFieldDecl(FieldDecl *D) { |
Argyrios Kyrtzidis | 87ec9c2 | 2011-11-01 17:14:12 +0000 | [diff] [blame] | 170 | // The USR for an ivar declared in a class extension is based on the |
| 171 | // ObjCInterfaceDecl, not the ObjCCategoryDecl. |
| 172 | if (ObjCInterfaceDecl *ID = Context->getObjContainingInterface(D)) |
| 173 | Visit(ID); |
| 174 | else |
| 175 | VisitDeclContext(D->getDeclContext()); |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 176 | Out << (isa<ObjCIvarDecl>(D) ? "@" : "@FI@"); |
| 177 | if (EmitDeclName(D)) { |
Ted Kremenek | 3adca6d | 2010-01-18 22:02:49 +0000 | [diff] [blame] | 178 | // Bit fields can be anonymous. |
| 179 | IgnoreResults = true; |
| 180 | return; |
| 181 | } |
Ted Kremenek | 3adca6d | 2010-01-18 22:02:49 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 184 | void USRGenerator::VisitFunctionDecl(FunctionDecl *D) { |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 185 | if (ShouldGenerateLocation(D) && GenLoc(D)) |
| 186 | return; |
Ted Kremenek | cf99910 | 2010-04-29 17:43:29 +0000 | [diff] [blame] | 187 | |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 188 | VisitDeclContext(D->getDeclContext()); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 189 | if (FunctionTemplateDecl *FunTmpl = D->getDescribedFunctionTemplate()) { |
| 190 | Out << "@FT@"; |
| 191 | VisitTemplateParameterList(FunTmpl->getTemplateParameters()); |
| 192 | } else |
| 193 | Out << "@F@"; |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 194 | D->printName(Out); |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 195 | |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 196 | ASTContext &Ctx = *Context; |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 197 | if (!Ctx.getLangOpts().CPlusPlus || D->isExternC()) |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 198 | return; |
| 199 | |
Argyrios Kyrtzidis | ad133ea | 2012-02-10 20:10:32 +0000 | [diff] [blame] | 200 | if (const TemplateArgumentList * |
| 201 | SpecArgs = D->getTemplateSpecializationArgs()) { |
| 202 | Out << '<'; |
| 203 | for (unsigned I = 0, N = SpecArgs->size(); I != N; ++I) { |
| 204 | Out << '#'; |
| 205 | VisitTemplateArgument(SpecArgs->get(I)); |
| 206 | } |
| 207 | Out << '>'; |
| 208 | } |
| 209 | |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 210 | // Mangle in type information for the arguments. |
| 211 | for (FunctionDecl::param_iterator I = D->param_begin(), E = D->param_end(); |
| 212 | I != E; ++I) { |
| 213 | Out << '#'; |
| 214 | if (ParmVarDecl *PD = *I) |
| 215 | VisitType(PD->getType()); |
| 216 | } |
| 217 | if (D->isVariadic()) |
| 218 | Out << '.'; |
Ted Kremenek | 2ea5baf | 2010-05-07 20:39:40 +0000 | [diff] [blame] | 219 | Out << '#'; |
| 220 | if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) { |
| 221 | if (MD->isStatic()) |
| 222 | Out << 'S'; |
| 223 | if (unsigned quals = MD->getTypeQualifiers()) |
| 224 | Out << (char)('0' + quals); |
| 225 | } |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 226 | } |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 227 | |
| 228 | void USRGenerator::VisitNamedDecl(NamedDecl *D) { |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 229 | VisitDeclContext(D->getDeclContext()); |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 230 | Out << "@"; |
| 231 | |
| 232 | if (EmitDeclName(D)) { |
| 233 | // The string can be empty if the declaration has no name; e.g., it is |
| 234 | // the ParmDecl with no name for declaration of a function pointer type, |
| 235 | // e.g.: void (*f)(void *); |
| 236 | // In this case, don't generate a USR. |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 237 | IgnoreResults = true; |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 238 | } |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 241 | void USRGenerator::VisitVarDecl(VarDecl *D) { |
| 242 | // VarDecls can be declared 'extern' within a function or method body, |
| 243 | // but their enclosing DeclContext is the function, not the TU. We need |
| 244 | // to check the storage class to correctly generate the USR. |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 245 | if (ShouldGenerateLocation(D) && GenLoc(D)) |
| 246 | return; |
| 247 | |
| 248 | VisitDeclContext(D->getDeclContext()); |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 249 | |
Ted Kremenek | cf99910 | 2010-04-29 17:43:29 +0000 | [diff] [blame] | 250 | // Variables always have simple names. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 251 | StringRef s = D->getName(); |
Ted Kremenek | cf99910 | 2010-04-29 17:43:29 +0000 | [diff] [blame] | 252 | |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 253 | // The string can be empty if the declaration has no name; e.g., it is |
| 254 | // the ParmDecl with no name for declaration of a function pointer type, e.g.: |
Eli Friedman | a7e6845 | 2010-08-22 01:00:03 +0000 | [diff] [blame] | 255 | // void (*f)(void *); |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 256 | // In this case, don't generate a USR. |
| 257 | if (s.empty()) |
| 258 | IgnoreResults = true; |
| 259 | else |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 260 | Out << '@' << s; |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 263 | void USRGenerator::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
| 264 | GenLoc(D); |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | void USRGenerator::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
| 269 | GenLoc(D); |
| 270 | return; |
| 271 | } |
| 272 | |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 273 | void USRGenerator::VisitNamespaceDecl(NamespaceDecl *D) { |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 274 | if (D->isAnonymousNamespace()) { |
| 275 | Out << "@aN"; |
| 276 | return; |
| 277 | } |
| 278 | |
Ted Kremenek | 2fee4e6 | 2010-01-14 01:50:21 +0000 | [diff] [blame] | 279 | VisitDeclContext(D->getDeclContext()); |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 280 | if (!IgnoreResults) |
| 281 | Out << "@N@" << D->getName(); |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 284 | void USRGenerator::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
| 285 | VisitFunctionDecl(D->getTemplatedDecl()); |
| 286 | } |
| 287 | |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 288 | void USRGenerator::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
| 289 | VisitTagDecl(D->getTemplatedDecl()); |
| 290 | } |
| 291 | |
Douglas Gregor | 6931900 | 2010-08-31 23:48:11 +0000 | [diff] [blame] | 292 | void USRGenerator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
| 293 | VisitDeclContext(D->getDeclContext()); |
| 294 | if (!IgnoreResults) |
| 295 | Out << "@NA@" << D->getName(); |
| 296 | } |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 297 | |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 298 | void USRGenerator::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
Ted Kremenek | 52d6bbe | 2011-02-05 01:10:26 +0000 | [diff] [blame] | 299 | DeclContext *container = D->getDeclContext(); |
| 300 | if (ObjCProtocolDecl *pd = dyn_cast<ObjCProtocolDecl>(container)) { |
| 301 | Visit(pd); |
Ted Kremenek | 28a7f25 | 2010-08-24 23:13:41 +0000 | [diff] [blame] | 302 | } |
Ted Kremenek | 52d6bbe | 2011-02-05 01:10:26 +0000 | [diff] [blame] | 303 | else { |
| 304 | // The USR for a method declared in a class extension or category is based on |
| 305 | // the ObjCInterfaceDecl, not the ObjCCategoryDecl. |
| 306 | ObjCInterfaceDecl *ID = D->getClassInterface(); |
| 307 | if (!ID) { |
| 308 | IgnoreResults = true; |
| 309 | return; |
| 310 | } |
| 311 | Visit(ID); |
| 312 | } |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 313 | // Ideally we would use 'GenObjCMethod', but this is such a hot path |
| 314 | // for Objective-C code that we don't want to use |
| 315 | // DeclarationName::getAsString(). |
| 316 | Out << (D->isInstanceMethod() ? "(im)" : "(cm)"); |
| 317 | DeclarationName N(D->getSelector()); |
| 318 | N.printName(Out); |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void USRGenerator::VisitObjCContainerDecl(ObjCContainerDecl *D) { |
| 322 | switch (D->getKind()) { |
| 323 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 324 | llvm_unreachable("Invalid ObjC container."); |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 325 | case Decl::ObjCInterface: |
| 326 | case Decl::ObjCImplementation: |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 327 | GenObjCClass(D->getName()); |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 328 | break; |
| 329 | case Decl::ObjCCategory: { |
| 330 | ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(D); |
Ted Kremenek | ebfa339 | 2010-03-19 20:39:03 +0000 | [diff] [blame] | 331 | ObjCInterfaceDecl *ID = CD->getClassInterface(); |
| 332 | if (!ID) { |
| 333 | // Handle invalid code where the @interface might not |
| 334 | // have been specified. |
| 335 | // FIXME: We should be able to generate this USR even if the |
| 336 | // @interface isn't available. |
| 337 | IgnoreResults = true; |
| 338 | return; |
| 339 | } |
Argyrios Kyrtzidis | 87ec9c2 | 2011-11-01 17:14:12 +0000 | [diff] [blame] | 340 | // Specially handle class extensions, which are anonymous categories. |
| 341 | // We want to mangle in the location to uniquely distinguish them. |
Ted Kremenek | 28a7f25 | 2010-08-24 23:13:41 +0000 | [diff] [blame] | 342 | if (CD->IsClassExtension()) { |
Argyrios Kyrtzidis | 87ec9c2 | 2011-11-01 17:14:12 +0000 | [diff] [blame] | 343 | Out << "objc(ext)" << ID->getName() << '@'; |
| 344 | GenLoc(CD); |
Ted Kremenek | 28a7f25 | 2010-08-24 23:13:41 +0000 | [diff] [blame] | 345 | } |
| 346 | else |
| 347 | GenObjCCategory(ID->getName(), CD->getName()); |
| 348 | |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 349 | break; |
| 350 | } |
| 351 | case Decl::ObjCCategoryImpl: { |
| 352 | ObjCCategoryImplDecl *CD = cast<ObjCCategoryImplDecl>(D); |
Ted Kremenek | ebfa339 | 2010-03-19 20:39:03 +0000 | [diff] [blame] | 353 | ObjCInterfaceDecl *ID = CD->getClassInterface(); |
| 354 | if (!ID) { |
| 355 | // Handle invalid code where the @interface might not |
| 356 | // have been specified. |
| 357 | // FIXME: We should be able to generate this USR even if the |
| 358 | // @interface isn't available. |
| 359 | IgnoreResults = true; |
| 360 | return; |
| 361 | } |
| 362 | GenObjCCategory(ID->getName(), CD->getName()); |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 363 | break; |
| 364 | } |
| 365 | case Decl::ObjCProtocol: |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 366 | GenObjCProtocol(cast<ObjCProtocolDecl>(D)->getName()); |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 367 | break; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | void USRGenerator::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Argyrios Kyrtzidis | 87ec9c2 | 2011-11-01 17:14:12 +0000 | [diff] [blame] | 372 | // The USR for a property declared in a class extension or category is based |
| 373 | // on the ObjCInterfaceDecl, not the ObjCCategoryDecl. |
| 374 | if (ObjCInterfaceDecl *ID = Context->getObjContainingInterface(D)) |
| 375 | Visit(ID); |
| 376 | else |
| 377 | Visit(cast<Decl>(D->getDeclContext())); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 378 | GenObjCProperty(D->getName()); |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 381 | void USRGenerator::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
| 382 | if (ObjCPropertyDecl *PD = D->getPropertyDecl()) { |
| 383 | VisitObjCPropertyDecl(PD); |
| 384 | return; |
| 385 | } |
| 386 | |
| 387 | IgnoreResults = true; |
| 388 | } |
| 389 | |
Ted Kremenek | b82b3be | 2010-01-18 22:42:20 +0000 | [diff] [blame] | 390 | void USRGenerator::VisitTagDecl(TagDecl *D) { |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 391 | // Add the location of the tag decl to handle resolution across |
| 392 | // translation units. |
| 393 | if (ShouldGenerateLocation(D) && GenLoc(D)) |
| 394 | return; |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 395 | |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 396 | D = D->getCanonicalDecl(); |
Ted Kremenek | b82b3be | 2010-01-18 22:42:20 +0000 | [diff] [blame] | 397 | VisitDeclContext(D->getDeclContext()); |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 398 | |
Douglas Gregor | 74dbe64 | 2010-08-31 19:31:58 +0000 | [diff] [blame] | 399 | bool AlreadyStarted = false; |
| 400 | if (CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(D)) { |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 401 | if (ClassTemplateDecl *ClassTmpl = CXXRecord->getDescribedClassTemplate()) { |
Douglas Gregor | 74dbe64 | 2010-08-31 19:31:58 +0000 | [diff] [blame] | 402 | AlreadyStarted = true; |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 403 | |
| 404 | switch (D->getTagKind()) { |
Douglas Gregor | 74dbe64 | 2010-08-31 19:31:58 +0000 | [diff] [blame] | 405 | case TTK_Struct: Out << "@ST"; break; |
| 406 | case TTK_Class: Out << "@CT"; break; |
| 407 | case TTK_Union: Out << "@UT"; break; |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 408 | case TTK_Enum: llvm_unreachable("enum template"); |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 409 | } |
| 410 | VisitTemplateParameterList(ClassTmpl->getTemplateParameters()); |
Douglas Gregor | 74dbe64 | 2010-08-31 19:31:58 +0000 | [diff] [blame] | 411 | } else if (ClassTemplatePartialSpecializationDecl *PartialSpec |
| 412 | = dyn_cast<ClassTemplatePartialSpecializationDecl>(CXXRecord)) { |
| 413 | AlreadyStarted = true; |
| 414 | |
| 415 | switch (D->getTagKind()) { |
| 416 | case TTK_Struct: Out << "@SP"; break; |
| 417 | case TTK_Class: Out << "@CP"; break; |
| 418 | case TTK_Union: Out << "@UP"; break; |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 419 | case TTK_Enum: llvm_unreachable("enum partial specialization"); |
Douglas Gregor | 74dbe64 | 2010-08-31 19:31:58 +0000 | [diff] [blame] | 420 | } |
| 421 | VisitTemplateParameterList(PartialSpec->getTemplateParameters()); |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 422 | } |
Douglas Gregor | 74dbe64 | 2010-08-31 19:31:58 +0000 | [diff] [blame] | 423 | } |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 424 | |
Douglas Gregor | 74dbe64 | 2010-08-31 19:31:58 +0000 | [diff] [blame] | 425 | if (!AlreadyStarted) { |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 426 | switch (D->getTagKind()) { |
| 427 | case TTK_Struct: Out << "@S"; break; |
| 428 | case TTK_Class: Out << "@C"; break; |
| 429 | case TTK_Union: Out << "@U"; break; |
| 430 | case TTK_Enum: Out << "@E"; break; |
| 431 | } |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 432 | } |
Douglas Gregor | 39d6f07 | 2010-08-31 19:02:00 +0000 | [diff] [blame] | 433 | |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 434 | Out << '@'; |
| 435 | Out.flush(); |
| 436 | assert(Buf.size() > 0); |
| 437 | const unsigned off = Buf.size() - 1; |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 438 | |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 439 | if (EmitDeclName(D)) { |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 440 | if (const TypedefNameDecl *TD = D->getTypedefNameForAnonDecl()) { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 441 | Buf[off] = 'A'; |
Benjamin Kramer | b8989f2 | 2011-10-14 18:45:37 +0000 | [diff] [blame] | 442 | Out << '@' << *TD; |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 443 | } |
| 444 | else |
| 445 | Buf[off] = 'a'; |
Ted Kremenek | c5b48b3 | 2010-01-15 23:34:31 +0000 | [diff] [blame] | 446 | } |
Douglas Gregor | 0ab1e9f | 2010-09-01 17:32:36 +0000 | [diff] [blame] | 447 | |
| 448 | // For a class template specialization, mangle the template arguments. |
| 449 | if (ClassTemplateSpecializationDecl *Spec |
| 450 | = dyn_cast<ClassTemplateSpecializationDecl>(D)) { |
| 451 | const TemplateArgumentList &Args = Spec->getTemplateInstantiationArgs(); |
| 452 | Out << '>'; |
| 453 | for (unsigned I = 0, N = Args.size(); I != N; ++I) { |
| 454 | Out << '#'; |
| 455 | VisitTemplateArgument(Args.get(I)); |
| 456 | } |
| 457 | } |
Ted Kremenek | c5b48b3 | 2010-01-15 23:34:31 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 460 | void USRGenerator::VisitTypedefDecl(TypedefDecl *D) { |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 461 | if (ShouldGenerateLocation(D) && GenLoc(D)) |
| 462 | return; |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 463 | DeclContext *DC = D->getDeclContext(); |
| 464 | if (NamedDecl *DCN = dyn_cast<NamedDecl>(DC)) |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 465 | Visit(DCN); |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 466 | Out << "@T@"; |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 467 | Out << D->getName(); |
| 468 | } |
| 469 | |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 470 | void USRGenerator::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
| 471 | GenLoc(D); |
| 472 | return; |
| 473 | } |
| 474 | |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 475 | bool USRGenerator::GenLoc(const Decl *D) { |
| 476 | if (generatedLoc) |
| 477 | return IgnoreResults; |
| 478 | generatedLoc = true; |
Ted Kremenek | 8c36758 | 2011-04-29 21:35:23 +0000 | [diff] [blame] | 479 | |
| 480 | // Guard against null declarations in invalid code. |
| 481 | if (!D) { |
| 482 | IgnoreResults = true; |
| 483 | return true; |
| 484 | } |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 485 | |
Ted Kremenek | 1d8052d | 2011-05-03 01:33:35 +0000 | [diff] [blame] | 486 | // Use the location of canonical decl. |
| 487 | D = D->getCanonicalDecl(); |
| 488 | |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 489 | const SourceManager &SM = Context->getSourceManager(); |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 490 | SourceLocation L = D->getLocStart(); |
| 491 | if (L.isInvalid()) { |
| 492 | IgnoreResults = true; |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 493 | return true; |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 494 | } |
Chandler Carruth | 4027853 | 2011-07-25 16:49:02 +0000 | [diff] [blame] | 495 | L = SM.getExpansionLoc(L); |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 496 | const std::pair<FileID, unsigned> &Decomposed = SM.getDecomposedLoc(L); |
| 497 | const FileEntry *FE = SM.getFileEntryForID(Decomposed.first); |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 498 | if (FE) { |
Michael J. Spencer | 472ccff | 2010-12-18 00:19:12 +0000 | [diff] [blame] | 499 | Out << llvm::sys::path::filename(FE->getName()); |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 500 | } |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 501 | else { |
| 502 | // This case really isn't interesting. |
| 503 | IgnoreResults = true; |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 504 | return true; |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 505 | } |
Ted Kremenek | f48b531 | 2010-07-22 11:14:15 +0000 | [diff] [blame] | 506 | // Use the offest into the FileID to represent the location. Using |
| 507 | // a line/column can cause us to look back at the original source file, |
| 508 | // which is expensive. |
| 509 | Out << '@' << Decomposed.second; |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 510 | return IgnoreResults; |
Ted Kremenek | c50277f | 2010-01-12 23:33:42 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 513 | void USRGenerator::VisitType(QualType T) { |
| 514 | // This method mangles in USR information for types. It can possibly |
| 515 | // just reuse the naming-mangling logic used by codegen, although the |
| 516 | // requirements for USRs might not be the same. |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 517 | ASTContext &Ctx = *Context; |
Ted Kremenek | 2ea5baf | 2010-05-07 20:39:40 +0000 | [diff] [blame] | 518 | |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 519 | do { |
Ted Kremenek | 2ea5baf | 2010-05-07 20:39:40 +0000 | [diff] [blame] | 520 | T = Ctx.getCanonicalType(T); |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 521 | Qualifiers Q = T.getQualifiers(); |
Ted Kremenek | 2ea5baf | 2010-05-07 20:39:40 +0000 | [diff] [blame] | 522 | unsigned qVal = 0; |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 523 | if (Q.hasConst()) |
Ted Kremenek | 2ea5baf | 2010-05-07 20:39:40 +0000 | [diff] [blame] | 524 | qVal |= 0x1; |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 525 | if (Q.hasVolatile()) |
Ted Kremenek | 2ea5baf | 2010-05-07 20:39:40 +0000 | [diff] [blame] | 526 | qVal |= 0x2; |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 527 | if (Q.hasRestrict()) |
Ted Kremenek | 2ea5baf | 2010-05-07 20:39:40 +0000 | [diff] [blame] | 528 | qVal |= 0x4; |
| 529 | if(qVal) |
| 530 | Out << ((char) ('0' + qVal)); |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 531 | |
| 532 | // Mangle in ObjC GC qualifiers? |
| 533 | |
Douglas Gregor | ba73ada | 2011-01-19 20:50:07 +0000 | [diff] [blame] | 534 | if (const PackExpansionType *Expansion = T->getAs<PackExpansionType>()) { |
| 535 | Out << 'P'; |
| 536 | T = Expansion->getPattern(); |
| 537 | } |
| 538 | |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 539 | if (const BuiltinType *BT = T->getAs<BuiltinType>()) { |
| 540 | unsigned char c = '\0'; |
| 541 | switch (BT->getKind()) { |
| 542 | case BuiltinType::Void: |
| 543 | c = 'v'; break; |
| 544 | case BuiltinType::Bool: |
| 545 | c = 'b'; break; |
| 546 | case BuiltinType::Char_U: |
| 547 | case BuiltinType::UChar: |
| 548 | c = 'c'; break; |
| 549 | case BuiltinType::Char16: |
| 550 | c = 'q'; break; |
| 551 | case BuiltinType::Char32: |
| 552 | c = 'w'; break; |
| 553 | case BuiltinType::UShort: |
| 554 | c = 's'; break; |
| 555 | case BuiltinType::UInt: |
| 556 | c = 'i'; break; |
| 557 | case BuiltinType::ULong: |
| 558 | c = 'l'; break; |
| 559 | case BuiltinType::ULongLong: |
| 560 | c = 'k'; break; |
| 561 | case BuiltinType::UInt128: |
| 562 | c = 'j'; break; |
| 563 | case BuiltinType::Char_S: |
| 564 | case BuiltinType::SChar: |
| 565 | c = 'C'; break; |
Chris Lattner | 3f59c97 | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 566 | case BuiltinType::WChar_S: |
| 567 | case BuiltinType::WChar_U: |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 568 | c = 'W'; break; |
| 569 | case BuiltinType::Short: |
| 570 | c = 'S'; break; |
| 571 | case BuiltinType::Int: |
| 572 | c = 'I'; break; |
| 573 | case BuiltinType::Long: |
| 574 | c = 'L'; break; |
| 575 | case BuiltinType::LongLong: |
| 576 | c = 'K'; break; |
| 577 | case BuiltinType::Int128: |
| 578 | c = 'J'; break; |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 579 | case BuiltinType::Half: |
| 580 | c = 'h'; break; |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 581 | case BuiltinType::Float: |
| 582 | c = 'f'; break; |
| 583 | case BuiltinType::Double: |
| 584 | c = 'd'; break; |
| 585 | case BuiltinType::LongDouble: |
| 586 | c = 'D'; break; |
| 587 | case BuiltinType::NullPtr: |
| 588 | c = 'n'; break; |
John McCall | 2dde35b | 2011-10-18 22:28:37 +0000 | [diff] [blame] | 589 | #define BUILTIN_TYPE(Id, SingletonId) |
| 590 | #define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id: |
| 591 | #include "clang/AST/BuiltinTypes.def" |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 592 | case BuiltinType::Dependent: |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 593 | IgnoreResults = true; |
| 594 | return; |
| 595 | case BuiltinType::ObjCId: |
| 596 | c = 'o'; break; |
| 597 | case BuiltinType::ObjCClass: |
| 598 | c = 'O'; break; |
| 599 | case BuiltinType::ObjCSel: |
| 600 | c = 'e'; break; |
| 601 | } |
| 602 | Out << c; |
| 603 | return; |
| 604 | } |
Douglas Gregor | 66b7fbf | 2010-09-20 20:37:39 +0000 | [diff] [blame] | 605 | |
| 606 | // If we have already seen this (non-built-in) type, use a substitution |
| 607 | // encoding. |
| 608 | llvm::DenseMap<const Type *, unsigned>::iterator Substitution |
| 609 | = TypeSubstitutions.find(T.getTypePtr()); |
| 610 | if (Substitution != TypeSubstitutions.end()) { |
| 611 | Out << 'S' << Substitution->second << '_'; |
| 612 | return; |
| 613 | } else { |
| 614 | // Record this as a substitution. |
| 615 | unsigned Number = TypeSubstitutions.size(); |
| 616 | TypeSubstitutions[T.getTypePtr()] = Number; |
| 617 | } |
| 618 | |
| 619 | if (const PointerType *PT = T->getAs<PointerType>()) { |
| 620 | Out << '*'; |
| 621 | T = PT->getPointeeType(); |
| 622 | continue; |
| 623 | } |
| 624 | if (const ReferenceType *RT = T->getAs<ReferenceType>()) { |
| 625 | Out << '&'; |
| 626 | T = RT->getPointeeType(); |
| 627 | continue; |
| 628 | } |
| 629 | if (const FunctionProtoType *FT = T->getAs<FunctionProtoType>()) { |
| 630 | Out << 'F'; |
| 631 | VisitType(FT->getResultType()); |
| 632 | for (FunctionProtoType::arg_type_iterator |
| 633 | I = FT->arg_type_begin(), E = FT->arg_type_end(); I!=E; ++I) { |
| 634 | VisitType(*I); |
| 635 | } |
| 636 | if (FT->isVariadic()) |
| 637 | Out << '.'; |
| 638 | return; |
| 639 | } |
| 640 | if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) { |
| 641 | Out << 'B'; |
| 642 | T = BT->getPointeeType(); |
| 643 | continue; |
| 644 | } |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 645 | if (const ComplexType *CT = T->getAs<ComplexType>()) { |
| 646 | Out << '<'; |
| 647 | T = CT->getElementType(); |
| 648 | continue; |
| 649 | } |
Ted Kremenek | 2ea5baf | 2010-05-07 20:39:40 +0000 | [diff] [blame] | 650 | if (const TagType *TT = T->getAs<TagType>()) { |
| 651 | Out << '$'; |
| 652 | VisitTagDecl(TT->getDecl()); |
| 653 | return; |
| 654 | } |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 655 | if (const TemplateTypeParmType *TTP = T->getAs<TemplateTypeParmType>()) { |
| 656 | Out << 't' << TTP->getDepth() << '.' << TTP->getIndex(); |
| 657 | return; |
| 658 | } |
| 659 | if (const TemplateSpecializationType *Spec |
| 660 | = T->getAs<TemplateSpecializationType>()) { |
| 661 | Out << '>'; |
| 662 | VisitTemplateName(Spec->getTemplateName()); |
| 663 | Out << Spec->getNumArgs(); |
| 664 | for (unsigned I = 0, N = Spec->getNumArgs(); I != N; ++I) |
| 665 | VisitTemplateArgument(Spec->getArg(I)); |
| 666 | return; |
| 667 | } |
| 668 | |
Ted Kremenek | 8e67219 | 2010-05-07 01:04:32 +0000 | [diff] [blame] | 669 | // Unhandled type. |
| 670 | Out << ' '; |
| 671 | break; |
| 672 | } while (true); |
| 673 | } |
| 674 | |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 675 | void USRGenerator::VisitTemplateParameterList( |
| 676 | const TemplateParameterList *Params) { |
| 677 | if (!Params) |
| 678 | return; |
| 679 | Out << '>' << Params->size(); |
| 680 | for (TemplateParameterList::const_iterator P = Params->begin(), |
| 681 | PEnd = Params->end(); |
| 682 | P != PEnd; ++P) { |
| 683 | Out << '#'; |
| 684 | if (isa<TemplateTypeParmDecl>(*P)) { |
Douglas Gregor | ba73ada | 2011-01-19 20:50:07 +0000 | [diff] [blame] | 685 | if (cast<TemplateTypeParmDecl>(*P)->isParameterPack()) |
| 686 | Out<< 'p'; |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 687 | Out << 'T'; |
| 688 | continue; |
| 689 | } |
| 690 | |
| 691 | if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) { |
Douglas Gregor | ba73ada | 2011-01-19 20:50:07 +0000 | [diff] [blame] | 692 | if (NTTP->isParameterPack()) |
| 693 | Out << 'p'; |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 694 | Out << 'N'; |
| 695 | VisitType(NTTP->getType()); |
| 696 | continue; |
| 697 | } |
| 698 | |
| 699 | TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*P); |
Douglas Gregor | ba73ada | 2011-01-19 20:50:07 +0000 | [diff] [blame] | 700 | if (TTP->isParameterPack()) |
| 701 | Out << 'p'; |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 702 | Out << 't'; |
| 703 | VisitTemplateParameterList(TTP->getTemplateParameters()); |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | void USRGenerator::VisitTemplateName(TemplateName Name) { |
| 708 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 709 | if (TemplateTemplateParmDecl *TTP |
| 710 | = dyn_cast<TemplateTemplateParmDecl>(Template)) { |
| 711 | Out << 't' << TTP->getDepth() << '.' << TTP->getIndex(); |
| 712 | return; |
| 713 | } |
| 714 | |
| 715 | Visit(Template); |
| 716 | return; |
| 717 | } |
| 718 | |
| 719 | // FIXME: Visit dependent template names. |
| 720 | } |
| 721 | |
| 722 | void USRGenerator::VisitTemplateArgument(const TemplateArgument &Arg) { |
| 723 | switch (Arg.getKind()) { |
| 724 | case TemplateArgument::Null: |
| 725 | break; |
| 726 | |
| 727 | case TemplateArgument::Declaration: |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 728 | if (Decl *D = Arg.getAsDecl()) |
| 729 | Visit(D); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 730 | break; |
| 731 | |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 732 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | ba73ada | 2011-01-19 20:50:07 +0000 | [diff] [blame] | 733 | Out << 'P'; // pack expansion of... |
| 734 | // Fall through |
| 735 | case TemplateArgument::Template: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 736 | VisitTemplateName(Arg.getAsTemplateOrTemplatePattern()); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 737 | break; |
| 738 | |
| 739 | case TemplateArgument::Expression: |
| 740 | // FIXME: Visit expressions. |
| 741 | break; |
| 742 | |
| 743 | case TemplateArgument::Pack: |
Douglas Gregor | ba73ada | 2011-01-19 20:50:07 +0000 | [diff] [blame] | 744 | Out << 'p' << Arg.pack_size(); |
| 745 | for (TemplateArgument::pack_iterator P = Arg.pack_begin(), PEnd = Arg.pack_end(); |
| 746 | P != PEnd; ++P) |
| 747 | VisitTemplateArgument(*P); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 748 | break; |
| 749 | |
| 750 | case TemplateArgument::Type: |
| 751 | VisitType(Arg.getAsType()); |
| 752 | break; |
| 753 | |
| 754 | case TemplateArgument::Integral: |
| 755 | Out << 'V'; |
| 756 | VisitType(Arg.getIntegralType()); |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame^] | 757 | Out << Arg.getAsIntegral(); |
Douglas Gregor | fe72e9c | 2010-08-31 17:01:39 +0000 | [diff] [blame] | 758 | break; |
| 759 | } |
| 760 | } |
| 761 | |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 762 | //===----------------------------------------------------------------------===// |
| 763 | // General purpose USR generation methods. |
| 764 | //===----------------------------------------------------------------------===// |
Ted Kremenek | cf84aa4 | 2010-01-18 20:23:29 +0000 | [diff] [blame] | 765 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 766 | void USRGenerator::GenObjCClass(StringRef cls) { |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 767 | Out << "objc(cs)" << cls; |
| 768 | } |
| 769 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 770 | void USRGenerator::GenObjCCategory(StringRef cls, StringRef cat) { |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 771 | Out << "objc(cy)" << cls << '@' << cat; |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 772 | } |
| 773 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 774 | void USRGenerator::GenObjCIvar(StringRef ivar) { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 775 | Out << '@' << ivar; |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 776 | } |
| 777 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 778 | void USRGenerator::GenObjCMethod(StringRef meth, bool isInstanceMethod) { |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 779 | Out << (isInstanceMethod ? "(im)" : "(cm)") << meth; |
| 780 | } |
| 781 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 782 | void USRGenerator::GenObjCProperty(StringRef prop) { |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 783 | Out << "(py)" << prop; |
| 784 | } |
| 785 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 786 | void USRGenerator::GenObjCProtocol(StringRef prot) { |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 787 | Out << "objc(pl)" << prot; |
| 788 | } |
| 789 | |
| 790 | //===----------------------------------------------------------------------===// |
| 791 | // API hooks. |
| 792 | //===----------------------------------------------------------------------===// |
Ted Kremenek | cf84aa4 | 2010-01-18 20:23:29 +0000 | [diff] [blame] | 793 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 794 | static inline StringRef extractUSRSuffix(StringRef s) { |
Benjamin Kramer | cfb51b6 | 2010-04-08 15:54:07 +0000 | [diff] [blame] | 795 | return s.startswith("c:") ? s.substr(2) : ""; |
| 796 | } |
| 797 | |
Argyrios Kyrtzidis | 4e7064f | 2011-10-17 19:48:19 +0000 | [diff] [blame] | 798 | bool cxcursor::getDeclCursorUSR(const Decl *D, SmallVectorImpl<char> &Buf) { |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 799 | // Don't generate USRs for things with invalid locations. |
| 800 | if (!D || D->getLocStart().isInvalid()) |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 801 | return true; |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 802 | |
Ted Kremenek | 1865cfe | 2010-04-15 21:04:25 +0000 | [diff] [blame] | 803 | // Check if the cursor has 'NoLinkage'. |
Ted Kremenek | e74ef12 | 2010-04-16 21:31:52 +0000 | [diff] [blame] | 804 | if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) |
Ted Kremenek | 1865cfe | 2010-04-15 21:04:25 +0000 | [diff] [blame] | 805 | switch (ND->getLinkage()) { |
| 806 | case ExternalLinkage: |
| 807 | // Generate USRs for all entities with external linkage. |
| 808 | break; |
| 809 | case NoLinkage: |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 810 | case UniqueExternalLinkage: |
Ted Kremenek | 1865cfe | 2010-04-15 21:04:25 +0000 | [diff] [blame] | 811 | // We allow enums, typedefs, and structs that have no linkage to |
| 812 | // have USRs that are anchored to the file they were defined in |
| 813 | // (e.g., the header). This is a little gross, but in principal |
| 814 | // enums/anonymous structs/etc. defined in a common header file |
| 815 | // are referred to across multiple translation units. |
Ted Kremenek | 6f15395 | 2010-04-15 21:51:13 +0000 | [diff] [blame] | 816 | if (isa<TagDecl>(ND) || isa<TypedefDecl>(ND) || |
Ted Kremenek | cf99910 | 2010-04-29 17:43:29 +0000 | [diff] [blame] | 817 | isa<EnumConstantDecl>(ND) || isa<FieldDecl>(ND) || |
Ted Kremenek | cbd66f0 | 2010-05-06 23:38:28 +0000 | [diff] [blame] | 818 | isa<VarDecl>(ND) || isa<NamespaceDecl>(ND)) |
Ted Kremenek | 1865cfe | 2010-04-15 21:04:25 +0000 | [diff] [blame] | 819 | break; |
| 820 | // Fall-through. |
| 821 | case InternalLinkage: |
Ted Kremenek | cf99910 | 2010-04-29 17:43:29 +0000 | [diff] [blame] | 822 | if (isa<FunctionDecl>(ND)) |
| 823 | break; |
Ted Kremenek | 1865cfe | 2010-04-15 21:04:25 +0000 | [diff] [blame] | 824 | } |
| 825 | |
Ted Kremenek | f019943 | 2010-11-16 08:15:38 +0000 | [diff] [blame] | 826 | { |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 827 | USRGenerator UG(&D->getASTContext(), &Buf); |
Benjamin Kramer | 854625f | 2011-10-28 13:37:11 +0000 | [diff] [blame] | 828 | UG->Visit(const_cast<Decl*>(D)); |
Ted Kremenek | e542f77 | 2010-04-20 23:15:40 +0000 | [diff] [blame] | 829 | |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 830 | if (UG->ignoreResults()) |
| 831 | return true; |
Ted Kremenek | f019943 | 2010-11-16 08:15:38 +0000 | [diff] [blame] | 832 | } |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 833 | |
| 834 | return false; |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 835 | } |
| 836 | |
Ted Kremenek | c3ef91d | 2010-04-11 22:20:26 +0000 | [diff] [blame] | 837 | extern "C" { |
| 838 | |
| 839 | CXString clang_getCursorUSR(CXCursor C) { |
Ted Kremenek | fa8231d | 2010-04-11 22:20:34 +0000 | [diff] [blame] | 840 | const CXCursorKind &K = clang_getCursorKind(C); |
| 841 | |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 842 | if (clang_isDeclaration(K)) { |
| 843 | Decl *D = cxcursor::getCursorDecl(C); |
Argyrios Kyrtzidis | 16ed0e6 | 2011-12-10 02:36:25 +0000 | [diff] [blame] | 844 | if (!D) |
| 845 | return createCXString(""); |
| 846 | |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 847 | CXTranslationUnit TU = cxcursor::getCursorTU(C); |
| 848 | if (!TU) |
| 849 | return createCXString(""); |
| 850 | |
| 851 | CXStringBuf *buf = cxstring::getCXStringBuf(TU); |
| 852 | if (!buf) |
| 853 | return createCXString(""); |
| 854 | |
| 855 | bool Ignore = cxcursor::getDeclCursorUSR(D, buf->Data); |
| 856 | if (Ignore) { |
| 857 | disposeCXStringBuf(buf); |
| 858 | return createCXString(""); |
| 859 | } |
| 860 | |
| 861 | // Return the C-string, but don't make a copy since it is already in |
| 862 | // the string buffer. |
| 863 | buf->Data.push_back('\0'); |
| 864 | return createCXString(buf); |
| 865 | } |
Ted Kremenek | fa8231d | 2010-04-11 22:20:34 +0000 | [diff] [blame] | 866 | |
| 867 | if (K == CXCursor_MacroDefinition) { |
Ted Kremenek | f019943 | 2010-11-16 08:15:38 +0000 | [diff] [blame] | 868 | CXTranslationUnit TU = cxcursor::getCursorTU(C); |
| 869 | if (!TU) |
| 870 | return createCXString(""); |
| 871 | |
| 872 | CXStringBuf *buf = cxstring::getCXStringBuf(TU); |
| 873 | if (!buf) |
| 874 | return createCXString(""); |
| 875 | |
| 876 | { |
Argyrios Kyrtzidis | b6a4ac4 | 2011-10-12 07:07:36 +0000 | [diff] [blame] | 877 | USRGenerator UG(&cxcursor::getCursorASTUnit(C)->getASTContext(), |
| 878 | &buf->Data); |
Ted Kremenek | f019943 | 2010-11-16 08:15:38 +0000 | [diff] [blame] | 879 | UG << "macro@" |
| 880 | << cxcursor::getCursorMacroDefinition(C)->getName()->getNameStart(); |
| 881 | } |
| 882 | buf->Data.push_back('\0'); |
| 883 | return createCXString(buf); |
Ted Kremenek | fa8231d | 2010-04-11 22:20:34 +0000 | [diff] [blame] | 884 | } |
| 885 | |
Ted Kremenek | c3ef91d | 2010-04-11 22:20:26 +0000 | [diff] [blame] | 886 | return createCXString(""); |
| 887 | } |
| 888 | |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 889 | CXString clang_constructUSR_ObjCIvar(const char *name, CXString classUSR) { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 890 | USRGenerator UG; |
| 891 | UG << extractUSRSuffix(clang_getCString(classUSR)); |
| 892 | UG->GenObjCIvar(name); |
| 893 | return createCXString(UG.str(), true); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | CXString clang_constructUSR_ObjCMethod(const char *name, |
| 897 | unsigned isInstanceMethod, |
| 898 | CXString classUSR) { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 899 | USRGenerator UG; |
| 900 | UG << extractUSRSuffix(clang_getCString(classUSR)); |
| 901 | UG->GenObjCMethod(name, isInstanceMethod); |
| 902 | return createCXString(UG.str(), true); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | CXString clang_constructUSR_ObjCClass(const char *name) { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 906 | USRGenerator UG; |
| 907 | UG->GenObjCClass(name); |
| 908 | return createCXString(UG.str(), true); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | CXString clang_constructUSR_ObjCProtocol(const char *name) { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 912 | USRGenerator UG; |
| 913 | UG->GenObjCProtocol(name); |
| 914 | return createCXString(UG.str(), true); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 915 | } |
| 916 | |
Ted Kremenek | 66ccaec | 2010-03-15 17:38:58 +0000 | [diff] [blame] | 917 | CXString clang_constructUSR_ObjCCategory(const char *class_name, |
Ted Kremenek | 0c0fb41 | 2010-03-25 02:00:36 +0000 | [diff] [blame] | 918 | const char *category_name) { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 919 | USRGenerator UG; |
| 920 | UG->GenObjCCategory(class_name, category_name); |
| 921 | return createCXString(UG.str(), true); |
Ted Kremenek | 896b70f | 2010-03-13 02:50:34 +0000 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | CXString clang_constructUSR_ObjCProperty(const char *property, |
| 925 | CXString classUSR) { |
Ted Kremenek | 3ebd8dc | 2010-05-07 20:07:23 +0000 | [diff] [blame] | 926 | USRGenerator UG; |
| 927 | UG << extractUSRSuffix(clang_getCString(classUSR)); |
| 928 | UG->GenObjCProperty(property); |
| 929 | return createCXString(UG.str(), true); |
Ted Kremenek | cf84aa4 | 2010-01-18 20:23:29 +0000 | [diff] [blame] | 930 | } |
Ted Kremenek | 1b6869a | 2010-01-05 22:06:45 +0000 | [diff] [blame] | 931 | |
Ted Kremenek | 1b6869a | 2010-01-05 22:06:45 +0000 | [diff] [blame] | 932 | } // end extern "C" |