Dmitri Gribenko | ec92531 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 1 | //===--- Comment.cpp - Comment AST node implementation --------------------===// |
| 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 | |
Dmitri Gribenko | 7acbf00 | 2012-09-10 20:32:42 +0000 | [diff] [blame] | 10 | #include "clang/AST/ASTContext.h" |
Dmitri Gribenko | ec92531 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 11 | #include "clang/AST/Comment.h" |
Dmitri Gribenko | 527ab21 | 2012-08-01 23:08:09 +0000 | [diff] [blame] | 12 | #include "clang/AST/Decl.h" |
| 13 | #include "clang/AST/DeclObjC.h" |
| 14 | #include "clang/AST/DeclTemplate.h" |
Dmitri Gribenko | db6adab | 2013-08-23 17:45:43 +0000 | [diff] [blame] | 15 | #include "clang/Basic/CharInfo.h" |
Dmitri Gribenko | ec92531 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 16 | #include "llvm/Support/ErrorHandling.h" |
Dmitri Gribenko | 761447c | 2012-07-18 16:30:42 +0000 | [diff] [blame] | 17 | #include "llvm/Support/raw_ostream.h" |
Dmitri Gribenko | ec92531 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 18 | |
| 19 | namespace clang { |
| 20 | namespace comments { |
| 21 | |
| 22 | const char *Comment::getCommentKindName() const { |
| 23 | switch (getCommentKind()) { |
| 24 | case NoCommentKind: return "NoCommentKind"; |
| 25 | #define ABSTRACT_COMMENT(COMMENT) |
| 26 | #define COMMENT(CLASS, PARENT) \ |
| 27 | case CLASS##Kind: \ |
| 28 | return #CLASS; |
| 29 | #include "clang/AST/CommentNodes.inc" |
| 30 | #undef COMMENT |
| 31 | #undef ABSTRACT_COMMENT |
| 32 | } |
| 33 | llvm_unreachable("Unknown comment kind!"); |
| 34 | } |
| 35 | |
| 36 | namespace { |
| 37 | struct good {}; |
| 38 | struct bad {}; |
| 39 | |
| 40 | template <typename T> |
| 41 | good implements_child_begin_end(Comment::child_iterator (T::*)() const) { |
| 42 | return good(); |
| 43 | } |
| 44 | |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 45 | LLVM_ATTRIBUTE_UNUSED |
Dmitri Gribenko | ec92531 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 46 | static inline bad implements_child_begin_end( |
| 47 | Comment::child_iterator (Comment::*)() const) { |
| 48 | return bad(); |
| 49 | } |
| 50 | |
| 51 | #define ASSERT_IMPLEMENTS_child_begin(function) \ |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 52 | (void) good(implements_child_begin_end(function)) |
Dmitri Gribenko | ec92531 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 53 | |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 54 | LLVM_ATTRIBUTE_UNUSED |
Dmitri Gribenko | ec92531 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 55 | static inline void CheckCommentASTNodes() { |
| 56 | #define ABSTRACT_COMMENT(COMMENT) |
| 57 | #define COMMENT(CLASS, PARENT) \ |
| 58 | ASSERT_IMPLEMENTS_child_begin(&CLASS::child_begin); \ |
| 59 | ASSERT_IMPLEMENTS_child_begin(&CLASS::child_end); |
| 60 | #include "clang/AST/CommentNodes.inc" |
| 61 | #undef COMMENT |
| 62 | #undef ABSTRACT_COMMENT |
| 63 | } |
| 64 | |
| 65 | #undef ASSERT_IMPLEMENTS_child_begin |
| 66 | |
| 67 | } // end unnamed namespace |
| 68 | |
| 69 | Comment::child_iterator Comment::child_begin() const { |
| 70 | switch (getCommentKind()) { |
| 71 | case NoCommentKind: llvm_unreachable("comment without a kind"); |
| 72 | #define ABSTRACT_COMMENT(COMMENT) |
| 73 | #define COMMENT(CLASS, PARENT) \ |
| 74 | case CLASS##Kind: \ |
| 75 | return static_cast<const CLASS *>(this)->child_begin(); |
| 76 | #include "clang/AST/CommentNodes.inc" |
| 77 | #undef COMMENT |
| 78 | #undef ABSTRACT_COMMENT |
| 79 | } |
Matt Beaumont-Gay | 4106ea3 | 2012-07-06 21:13:09 +0000 | [diff] [blame] | 80 | llvm_unreachable("Unknown comment kind!"); |
Dmitri Gribenko | ec92531 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | Comment::child_iterator Comment::child_end() const { |
| 84 | switch (getCommentKind()) { |
| 85 | case NoCommentKind: llvm_unreachable("comment without a kind"); |
| 86 | #define ABSTRACT_COMMENT(COMMENT) |
| 87 | #define COMMENT(CLASS, PARENT) \ |
| 88 | case CLASS##Kind: \ |
| 89 | return static_cast<const CLASS *>(this)->child_end(); |
| 90 | #include "clang/AST/CommentNodes.inc" |
| 91 | #undef COMMENT |
| 92 | #undef ABSTRACT_COMMENT |
| 93 | } |
Matt Beaumont-Gay | 4106ea3 | 2012-07-06 21:13:09 +0000 | [diff] [blame] | 94 | llvm_unreachable("Unknown comment kind!"); |
Dmitri Gribenko | ec92531 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Dmitri Gribenko | 05c3c75 | 2012-07-18 20:54:32 +0000 | [diff] [blame] | 97 | bool TextComment::isWhitespaceNoCache() const { |
Dmitri Gribenko | f26054f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 98 | for (StringRef::const_iterator I = Text.begin(), E = Text.end(); |
| 99 | I != E; ++I) { |
Dmitri Gribenko | db6adab | 2013-08-23 17:45:43 +0000 | [diff] [blame] | 100 | if (!clang::isWhitespace(*I)) |
Dmitri Gribenko | f26054f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 101 | return false; |
| 102 | } |
| 103 | return true; |
| 104 | } |
| 105 | |
Dmitri Gribenko | 05c3c75 | 2012-07-18 20:54:32 +0000 | [diff] [blame] | 106 | bool ParagraphComment::isWhitespaceNoCache() const { |
Dmitri Gribenko | f26054f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 107 | for (child_iterator I = child_begin(), E = child_end(); I != E; ++I) { |
| 108 | if (const TextComment *TC = dyn_cast<TextComment>(*I)) { |
| 109 | if (!TC->isWhitespace()) |
| 110 | return false; |
Dmitri Gribenko | 7b2ca3e | 2012-07-19 00:01:56 +0000 | [diff] [blame] | 111 | } else |
| 112 | return false; |
Dmitri Gribenko | f26054f | 2012-07-11 21:38:39 +0000 | [diff] [blame] | 113 | } |
| 114 | return true; |
| 115 | } |
| 116 | |
| 117 | const char *ParamCommandComment::getDirectionAsString(PassDirection D) { |
| 118 | switch (D) { |
| 119 | case ParamCommandComment::In: |
| 120 | return "[in]"; |
| 121 | case ParamCommandComment::Out: |
| 122 | return "[out]"; |
| 123 | case ParamCommandComment::InOut: |
| 124 | return "[in,out]"; |
| 125 | } |
| 126 | llvm_unreachable("unknown PassDirection"); |
| 127 | } |
Dmitri Gribenko | ec92531 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 128 | |
Dmitri Gribenko | 527ab21 | 2012-08-01 23:08:09 +0000 | [diff] [blame] | 129 | void DeclInfo::fill() { |
| 130 | assert(!IsFilled); |
| 131 | |
| 132 | // Set defaults. |
Dmitri Gribenko | 6430583 | 2012-08-03 21:15:32 +0000 | [diff] [blame] | 133 | Kind = OtherKind; |
Dmitri Gribenko | 8e5d5f1 | 2012-08-06 21:31:15 +0000 | [diff] [blame] | 134 | TemplateKind = NotTemplate; |
Dmitri Gribenko | 558babc | 2012-08-06 16:29:26 +0000 | [diff] [blame] | 135 | IsObjCMethod = false; |
Dmitri Gribenko | 527ab21 | 2012-08-01 23:08:09 +0000 | [diff] [blame] | 136 | IsInstanceMethod = false; |
| 137 | IsClassMethod = false; |
Dmitri Gribenko | 44ebbd5 | 2013-05-05 00:41:58 +0000 | [diff] [blame] | 138 | ParamVars = None; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame^] | 139 | TemplateParameters = nullptr; |
Dmitri Gribenko | 527ab21 | 2012-08-01 23:08:09 +0000 | [diff] [blame] | 140 | |
Fariborz Jahanian | 1c883b9 | 2012-10-10 18:34:52 +0000 | [diff] [blame] | 141 | if (!CommentDecl) { |
Dmitri Gribenko | 0567de8 | 2012-08-03 00:01:01 +0000 | [diff] [blame] | 142 | // If there is no declaration, the defaults is our only guess. |
| 143 | IsFilled = true; |
| 144 | return; |
| 145 | } |
Fariborz Jahanian | a7d76d2 | 2012-10-17 21:58:03 +0000 | [diff] [blame] | 146 | CurrentDecl = CommentDecl; |
Fariborz Jahanian | bbd469b | 2012-10-15 20:57:52 +0000 | [diff] [blame] | 147 | |
Fariborz Jahanian | 1c883b9 | 2012-10-10 18:34:52 +0000 | [diff] [blame] | 148 | Decl::Kind K = CommentDecl->getKind(); |
Dmitri Gribenko | 0567de8 | 2012-08-03 00:01:01 +0000 | [diff] [blame] | 149 | switch (K) { |
| 150 | default: |
| 151 | // Defaults are should be good for declarations we don't handle explicitly. |
| 152 | break; |
| 153 | case Decl::Function: |
| 154 | case Decl::CXXMethod: |
| 155 | case Decl::CXXConstructor: |
| 156 | case Decl::CXXDestructor: |
| 157 | case Decl::CXXConversion: { |
Fariborz Jahanian | 1c883b9 | 2012-10-10 18:34:52 +0000 | [diff] [blame] | 158 | const FunctionDecl *FD = cast<FunctionDecl>(CommentDecl); |
Dmitri Gribenko | 37a7faf | 2012-08-02 21:45:39 +0000 | [diff] [blame] | 159 | Kind = FunctionKind; |
Dmitri Gribenko | 527ab21 | 2012-08-01 23:08:09 +0000 | [diff] [blame] | 160 | ParamVars = ArrayRef<const ParmVarDecl *>(FD->param_begin(), |
| 161 | FD->getNumParams()); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 162 | ReturnType = FD->getReturnType(); |
Dmitri Gribenko | 527ab21 | 2012-08-01 23:08:09 +0000 | [diff] [blame] | 163 | unsigned NumLists = FD->getNumTemplateParameterLists(); |
| 164 | if (NumLists != 0) { |
Dmitri Gribenko | 8e5d5f1 | 2012-08-06 21:31:15 +0000 | [diff] [blame] | 165 | TemplateKind = TemplateSpecialization; |
Dmitri Gribenko | 527ab21 | 2012-08-01 23:08:09 +0000 | [diff] [blame] | 166 | TemplateParameters = |
| 167 | FD->getTemplateParameterList(NumLists - 1); |
| 168 | } |
| 169 | |
Dmitri Gribenko | 6430583 | 2012-08-03 21:15:32 +0000 | [diff] [blame] | 170 | if (K == Decl::CXXMethod || K == Decl::CXXConstructor || |
| 171 | K == Decl::CXXDestructor || K == Decl::CXXConversion) { |
Fariborz Jahanian | 1c883b9 | 2012-10-10 18:34:52 +0000 | [diff] [blame] | 172 | const CXXMethodDecl *MD = cast<CXXMethodDecl>(CommentDecl); |
Dmitri Gribenko | 527ab21 | 2012-08-01 23:08:09 +0000 | [diff] [blame] | 173 | IsInstanceMethod = MD->isInstance(); |
| 174 | IsClassMethod = !IsInstanceMethod; |
| 175 | } |
Dmitri Gribenko | 0567de8 | 2012-08-03 00:01:01 +0000 | [diff] [blame] | 176 | break; |
| 177 | } |
| 178 | case Decl::ObjCMethod: { |
Fariborz Jahanian | 1c883b9 | 2012-10-10 18:34:52 +0000 | [diff] [blame] | 179 | const ObjCMethodDecl *MD = cast<ObjCMethodDecl>(CommentDecl); |
Dmitri Gribenko | 37a7faf | 2012-08-02 21:45:39 +0000 | [diff] [blame] | 180 | Kind = FunctionKind; |
Dmitri Gribenko | 527ab21 | 2012-08-01 23:08:09 +0000 | [diff] [blame] | 181 | ParamVars = ArrayRef<const ParmVarDecl *>(MD->param_begin(), |
| 182 | MD->param_size()); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 183 | ReturnType = MD->getReturnType(); |
Dmitri Gribenko | 558babc | 2012-08-06 16:29:26 +0000 | [diff] [blame] | 184 | IsObjCMethod = true; |
Dmitri Gribenko | 527ab21 | 2012-08-01 23:08:09 +0000 | [diff] [blame] | 185 | IsInstanceMethod = MD->isInstanceMethod(); |
| 186 | IsClassMethod = !IsInstanceMethod; |
Dmitri Gribenko | 0567de8 | 2012-08-03 00:01:01 +0000 | [diff] [blame] | 187 | break; |
| 188 | } |
| 189 | case Decl::FunctionTemplate: { |
Fariborz Jahanian | 1c883b9 | 2012-10-10 18:34:52 +0000 | [diff] [blame] | 190 | const FunctionTemplateDecl *FTD = cast<FunctionTemplateDecl>(CommentDecl); |
Dmitri Gribenko | 37a7faf | 2012-08-02 21:45:39 +0000 | [diff] [blame] | 191 | Kind = FunctionKind; |
Dmitri Gribenko | 8e5d5f1 | 2012-08-06 21:31:15 +0000 | [diff] [blame] | 192 | TemplateKind = Template; |
Dmitri Gribenko | 527ab21 | 2012-08-01 23:08:09 +0000 | [diff] [blame] | 193 | const FunctionDecl *FD = FTD->getTemplatedDecl(); |
| 194 | ParamVars = ArrayRef<const ParmVarDecl *>(FD->param_begin(), |
| 195 | FD->getNumParams()); |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 196 | ReturnType = FD->getReturnType(); |
Dmitri Gribenko | 527ab21 | 2012-08-01 23:08:09 +0000 | [diff] [blame] | 197 | TemplateParameters = FTD->getTemplateParameters(); |
Dmitri Gribenko | 0567de8 | 2012-08-03 00:01:01 +0000 | [diff] [blame] | 198 | break; |
| 199 | } |
| 200 | case Decl::ClassTemplate: { |
Fariborz Jahanian | 1c883b9 | 2012-10-10 18:34:52 +0000 | [diff] [blame] | 201 | const ClassTemplateDecl *CTD = cast<ClassTemplateDecl>(CommentDecl); |
Dmitri Gribenko | 37a7faf | 2012-08-02 21:45:39 +0000 | [diff] [blame] | 202 | Kind = ClassKind; |
Dmitri Gribenko | 8e5d5f1 | 2012-08-06 21:31:15 +0000 | [diff] [blame] | 203 | TemplateKind = Template; |
Dmitri Gribenko | 527ab21 | 2012-08-01 23:08:09 +0000 | [diff] [blame] | 204 | TemplateParameters = CTD->getTemplateParameters(); |
Dmitri Gribenko | 0567de8 | 2012-08-03 00:01:01 +0000 | [diff] [blame] | 205 | break; |
| 206 | } |
| 207 | case Decl::ClassTemplatePartialSpecialization: { |
| 208 | const ClassTemplatePartialSpecializationDecl *CTPSD = |
Fariborz Jahanian | 1c883b9 | 2012-10-10 18:34:52 +0000 | [diff] [blame] | 209 | cast<ClassTemplatePartialSpecializationDecl>(CommentDecl); |
Dmitri Gribenko | 37a7faf | 2012-08-02 21:45:39 +0000 | [diff] [blame] | 210 | Kind = ClassKind; |
Dmitri Gribenko | 8e5d5f1 | 2012-08-06 21:31:15 +0000 | [diff] [blame] | 211 | TemplateKind = TemplatePartialSpecialization; |
Dmitri Gribenko | 527ab21 | 2012-08-01 23:08:09 +0000 | [diff] [blame] | 212 | TemplateParameters = CTPSD->getTemplateParameters(); |
Dmitri Gribenko | 0567de8 | 2012-08-03 00:01:01 +0000 | [diff] [blame] | 213 | break; |
| 214 | } |
| 215 | case Decl::ClassTemplateSpecialization: |
Dmitri Gribenko | 37a7faf | 2012-08-02 21:45:39 +0000 | [diff] [blame] | 216 | Kind = ClassKind; |
Dmitri Gribenko | 8e5d5f1 | 2012-08-06 21:31:15 +0000 | [diff] [blame] | 217 | TemplateKind = TemplateSpecialization; |
Dmitri Gribenko | 0567de8 | 2012-08-03 00:01:01 +0000 | [diff] [blame] | 218 | break; |
| 219 | case Decl::Record: |
Dmitri Gribenko | 6430583 | 2012-08-03 21:15:32 +0000 | [diff] [blame] | 220 | case Decl::CXXRecord: |
Dmitri Gribenko | 37a7faf | 2012-08-02 21:45:39 +0000 | [diff] [blame] | 221 | Kind = ClassKind; |
Dmitri Gribenko | 0567de8 | 2012-08-03 00:01:01 +0000 | [diff] [blame] | 222 | break; |
| 223 | case Decl::Var: |
| 224 | case Decl::Field: |
Dmitri Gribenko | 94ef635 | 2012-08-07 18:12:22 +0000 | [diff] [blame] | 225 | case Decl::EnumConstant: |
Dmitri Gribenko | 0567de8 | 2012-08-03 00:01:01 +0000 | [diff] [blame] | 226 | case Decl::ObjCIvar: |
| 227 | case Decl::ObjCAtDefsField: |
Dmitri Gribenko | 37a7faf | 2012-08-02 21:45:39 +0000 | [diff] [blame] | 228 | Kind = VariableKind; |
Dmitri Gribenko | 0567de8 | 2012-08-03 00:01:01 +0000 | [diff] [blame] | 229 | break; |
| 230 | case Decl::Namespace: |
Dmitri Gribenko | 37a7faf | 2012-08-02 21:45:39 +0000 | [diff] [blame] | 231 | Kind = NamespaceKind; |
Dmitri Gribenko | 0567de8 | 2012-08-03 00:01:01 +0000 | [diff] [blame] | 232 | break; |
Dmitri Gribenko | 907f6b8 | 2012-08-24 00:05:30 +0000 | [diff] [blame] | 233 | case Decl::Typedef: { |
| 234 | Kind = TypedefKind; |
| 235 | // If this is a typedef to something we consider a function, extract |
| 236 | // arguments and return type. |
Fariborz Jahanian | 1c883b9 | 2012-10-10 18:34:52 +0000 | [diff] [blame] | 237 | const TypedefDecl *TD = cast<TypedefDecl>(CommentDecl); |
Dmitri Gribenko | 907f6b8 | 2012-08-24 00:05:30 +0000 | [diff] [blame] | 238 | const TypeSourceInfo *TSI = TD->getTypeSourceInfo(); |
| 239 | if (!TSI) |
| 240 | break; |
| 241 | TypeLoc TL = TSI->getTypeLoc().getUnqualifiedLoc(); |
| 242 | while (true) { |
| 243 | TL = TL.IgnoreParens(); |
Dmitri Gribenko | 907f6b8 | 2012-08-24 00:05:30 +0000 | [diff] [blame] | 244 | // Look through qualified types. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 245 | if (QualifiedTypeLoc QualifiedTL = TL.getAs<QualifiedTypeLoc>()) { |
| 246 | TL = QualifiedTL.getUnqualifiedLoc(); |
Dmitri Gribenko | 907f6b8 | 2012-08-24 00:05:30 +0000 | [diff] [blame] | 247 | continue; |
| 248 | } |
| 249 | // Look through pointer types. |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 250 | if (PointerTypeLoc PointerTL = TL.getAs<PointerTypeLoc>()) { |
| 251 | TL = PointerTL.getPointeeLoc().getUnqualifiedLoc(); |
Dmitri Gribenko | 907f6b8 | 2012-08-24 00:05:30 +0000 | [diff] [blame] | 252 | continue; |
| 253 | } |
Dmitri Gribenko | e8bc31f | 2013-12-17 22:22:14 +0000 | [diff] [blame] | 254 | // Look through reference types. |
| 255 | if (ReferenceTypeLoc ReferenceTL = TL.getAs<ReferenceTypeLoc>()) { |
| 256 | TL = ReferenceTL.getPointeeLoc().getUnqualifiedLoc(); |
| 257 | continue; |
| 258 | } |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 259 | // Look through adjusted types. |
| 260 | if (AdjustedTypeLoc ATL = TL.getAs<AdjustedTypeLoc>()) { |
| 261 | TL = ATL.getOriginalLoc(); |
| 262 | continue; |
| 263 | } |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 264 | if (BlockPointerTypeLoc BlockPointerTL = |
| 265 | TL.getAs<BlockPointerTypeLoc>()) { |
| 266 | TL = BlockPointerTL.getPointeeLoc().getUnqualifiedLoc(); |
Dmitri Gribenko | 907f6b8 | 2012-08-24 00:05:30 +0000 | [diff] [blame] | 267 | continue; |
| 268 | } |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 269 | if (MemberPointerTypeLoc MemberPointerTL = |
| 270 | TL.getAs<MemberPointerTypeLoc>()) { |
| 271 | TL = MemberPointerTL.getPointeeLoc().getUnqualifiedLoc(); |
Dmitri Gribenko | 907f6b8 | 2012-08-24 00:05:30 +0000 | [diff] [blame] | 272 | continue; |
| 273 | } |
Dmitri Gribenko | fa68a57 | 2013-12-17 22:06:11 +0000 | [diff] [blame] | 274 | if (ElaboratedTypeLoc ETL = TL.getAs<ElaboratedTypeLoc>()) { |
| 275 | TL = ETL.getNamedTypeLoc(); |
| 276 | continue; |
| 277 | } |
Dmitri Gribenko | 907f6b8 | 2012-08-24 00:05:30 +0000 | [diff] [blame] | 278 | // Is this a typedef for a function type? |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 279 | if (FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>()) { |
Dmitri Gribenko | 907f6b8 | 2012-08-24 00:05:30 +0000 | [diff] [blame] | 280 | Kind = FunctionKind; |
David Blaikie | 6adc78e | 2013-02-18 22:06:02 +0000 | [diff] [blame] | 281 | ArrayRef<ParmVarDecl *> Params = FTL.getParams(); |
Dmitri Gribenko | 907f6b8 | 2012-08-24 00:05:30 +0000 | [diff] [blame] | 282 | ParamVars = ArrayRef<const ParmVarDecl *>(Params.data(), |
| 283 | Params.size()); |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 284 | ReturnType = FTL.getReturnLoc().getType(); |
Dmitri Gribenko | 907f6b8 | 2012-08-24 00:05:30 +0000 | [diff] [blame] | 285 | break; |
| 286 | } |
Dmitri Gribenko | fa68a57 | 2013-12-17 22:06:11 +0000 | [diff] [blame] | 287 | if (TemplateSpecializationTypeLoc STL = |
| 288 | TL.getAs<TemplateSpecializationTypeLoc>()) { |
| 289 | // If we have a typedef to a template specialization with exactly one |
| 290 | // template argument of a function type, this looks like std::function, |
| 291 | // boost::function, or other function wrapper. Treat these typedefs as |
| 292 | // functions. |
| 293 | if (STL.getNumArgs() != 1) |
| 294 | break; |
| 295 | TemplateArgumentLoc MaybeFunction = STL.getArgLoc(0); |
| 296 | if (MaybeFunction.getArgument().getKind() != TemplateArgument::Type) |
| 297 | break; |
| 298 | TypeSourceInfo *MaybeFunctionTSI = MaybeFunction.getTypeSourceInfo(); |
| 299 | TypeLoc TL = MaybeFunctionTSI->getTypeLoc().getUnqualifiedLoc(); |
| 300 | if (FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>()) { |
| 301 | Kind = FunctionKind; |
| 302 | ArrayRef<ParmVarDecl *> Params = FTL.getParams(); |
| 303 | ParamVars = ArrayRef<const ParmVarDecl *>(Params.data(), |
| 304 | Params.size()); |
Alp Toker | 42a16a6 | 2014-01-25 23:51:36 +0000 | [diff] [blame] | 305 | ReturnType = FTL.getReturnLoc().getType(); |
Dmitri Gribenko | fa68a57 | 2013-12-17 22:06:11 +0000 | [diff] [blame] | 306 | } |
| 307 | break; |
| 308 | } |
Dmitri Gribenko | 907f6b8 | 2012-08-24 00:05:30 +0000 | [diff] [blame] | 309 | break; |
| 310 | } |
| 311 | break; |
| 312 | } |
Dmitri Gribenko | 0567de8 | 2012-08-03 00:01:01 +0000 | [diff] [blame] | 313 | case Decl::TypeAlias: |
Dmitri Gribenko | 37a7faf | 2012-08-02 21:45:39 +0000 | [diff] [blame] | 314 | Kind = TypedefKind; |
Dmitri Gribenko | 0567de8 | 2012-08-03 00:01:01 +0000 | [diff] [blame] | 315 | break; |
| 316 | case Decl::TypeAliasTemplate: { |
Fariborz Jahanian | 1c883b9 | 2012-10-10 18:34:52 +0000 | [diff] [blame] | 317 | const TypeAliasTemplateDecl *TAT = cast<TypeAliasTemplateDecl>(CommentDecl); |
Dmitri Gribenko | 37a7faf | 2012-08-02 21:45:39 +0000 | [diff] [blame] | 318 | Kind = TypedefKind; |
Dmitri Gribenko | 8e5d5f1 | 2012-08-06 21:31:15 +0000 | [diff] [blame] | 319 | TemplateKind = Template; |
Dmitri Gribenko | baeb60e | 2012-08-02 21:36:57 +0000 | [diff] [blame] | 320 | TemplateParameters = TAT->getTemplateParameters(); |
Dmitri Gribenko | 0567de8 | 2012-08-03 00:01:01 +0000 | [diff] [blame] | 321 | break; |
Dmitri Gribenko | 527ab21 | 2012-08-01 23:08:09 +0000 | [diff] [blame] | 322 | } |
Dmitri Gribenko | 168d234 | 2012-08-07 18:59:04 +0000 | [diff] [blame] | 323 | case Decl::Enum: |
| 324 | Kind = EnumKind; |
| 325 | break; |
Dmitri Gribenko | 0567de8 | 2012-08-03 00:01:01 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Dmitri Gribenko | 527ab21 | 2012-08-01 23:08:09 +0000 | [diff] [blame] | 328 | IsFilled = true; |
| 329 | } |
| 330 | |
Dmitri Gribenko | 923f305 | 2012-10-19 16:51:38 +0000 | [diff] [blame] | 331 | StringRef ParamCommandComment::getParamName(const FullComment *FC) const { |
Fariborz Jahanian | 9d2f1e7 | 2012-10-18 21:42:42 +0000 | [diff] [blame] | 332 | assert(isParamIndexValid()); |
Dmitri Gribenko | 02489eb | 2013-06-24 04:41:32 +0000 | [diff] [blame] | 333 | if (isVarArgParam()) |
| 334 | return "..."; |
Fariborz Jahanian | e405569 | 2013-07-05 23:20:55 +0000 | [diff] [blame] | 335 | return FC->getDeclInfo()->ParamVars[getParamIndex()]->getName(); |
Fariborz Jahanian | 42e3132 | 2012-10-11 23:52:50 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Dmitri Gribenko | 923f305 | 2012-10-19 16:51:38 +0000 | [diff] [blame] | 338 | StringRef TParamCommandComment::getParamName(const FullComment *FC) const { |
Fariborz Jahanian | 9d2f1e7 | 2012-10-18 21:42:42 +0000 | [diff] [blame] | 339 | assert(isPositionValid()); |
Fariborz Jahanian | e405569 | 2013-07-05 23:20:55 +0000 | [diff] [blame] | 340 | const TemplateParameterList *TPL = FC->getDeclInfo()->TemplateParameters; |
Fariborz Jahanian | 9d2f1e7 | 2012-10-18 21:42:42 +0000 | [diff] [blame] | 341 | for (unsigned i = 0, e = getDepth(); i != e; ++i) { |
| 342 | if (i == e-1) |
| 343 | return TPL->getParam(getIndex(i))->getName(); |
| 344 | const NamedDecl *Param = TPL->getParam(getIndex(i)); |
| 345 | if (const TemplateTemplateParmDecl *TTP = |
Fariborz Jahanian | 14ec3f3 | 2012-10-15 18:58:50 +0000 | [diff] [blame] | 346 | dyn_cast<TemplateTemplateParmDecl>(Param)) |
Fariborz Jahanian | 9d2f1e7 | 2012-10-18 21:42:42 +0000 | [diff] [blame] | 347 | TPL = TTP->getTemplateParameters(); |
Fariborz Jahanian | 14ec3f3 | 2012-10-15 18:58:50 +0000 | [diff] [blame] | 348 | } |
Fariborz Jahanian | 9d2f1e7 | 2012-10-18 21:42:42 +0000 | [diff] [blame] | 349 | return ""; |
Fariborz Jahanian | 14ec3f3 | 2012-10-15 18:58:50 +0000 | [diff] [blame] | 350 | } |
Dmitri Gribenko | 923f305 | 2012-10-19 16:51:38 +0000 | [diff] [blame] | 351 | |
Dmitri Gribenko | ec92531 | 2012-07-06 00:28:32 +0000 | [diff] [blame] | 352 | } // end namespace comments |
| 353 | } // end namespace clang |
Dmitri Gribenko | 37a7faf | 2012-08-02 21:45:39 +0000 | [diff] [blame] | 354 | |