[cfe-commits] [PATCH] Comment parsing: add support for template parameter documentation

Douglas Gregor dgregor at apple.com
Tue Jul 31 10:39:13 PDT 2012


On Jul 30, 2012, at 1:31 PM, Dmitri Gribenko <gribozavr at gmail.com> wrote:

> Hello,
> 
> The attached patch adds support for \tparam command on all levels.

Cool. Some comments below.

> The only caveat is me renumbering CXCommentKind enum for aesthetic
> reasons -- this breaks binary compatibility, but should not be a
> problem since API is so new.


Yes, that's fine.

Index: include/clang/AST/Comment.h
===================================================================
--- include/clang/AST/Comment.h	(revision 160979)
+++ include/clang/AST/Comment.h	(working copy)
@@ -723,6 +723,73 @@
   }
 };
 
+/// Doxygen \\tparam command, describes a template parameter.
+class TParamCommandComment : public BlockCommandComment {
+private:
+  /// If this template parameter name was resolved (found in template parameter
+  /// list), then this stores a list of position indexes in all template
+  /// parameter lists.
+  ///
+  /// For example:
+  /// \verbatim
+  ///     template<typename C, template<typename T> class TT>
+  ///     void test(TT<int> aaa);
+  /// \endverbatim
+  /// For C:  Position = { 0 }
+  /// For TT: Position = { 1 }
+  /// For T:  Position = { 1, 0 }
+  llvm::SmallVector<unsigned, 2> Position;

The SmallVector here won't ever get destroyed, right? We'll need CommentSema to build up this vector itself and then provide a pointer to a BumpPtrAllocate'd array.

+  StringRef getParamName() const {
+    return Args[0].Text;
+  }
+
+  SourceRange getParamNameRange() const {
+    return Args[0].Range;
+  }

assert(hasParamName())?

Index: lib/Sema/SemaTemplate.cpp
===================================================================
--- lib/Sema/SemaTemplate.cpp	(revision 160979)
+++ lib/Sema/SemaTemplate.cpp	(working copy)
@@ -1139,6 +1139,8 @@
   if (PrevClassTemplate)
     mergeDeclAttributes(NewClass, PrevClassTemplate->getTemplatedDecl());
 
+  ActOnDocumentableDecl(NewTemplate);
+
   return NewTemplate;
 }
 
@@ -5568,7 +5570,9 @@
 Decl *Sema::ActOnTemplateDeclarator(Scope *S,
                               MultiTemplateParamsArg TemplateParameterLists,
                                     Declarator &D) {
-  return HandleDeclarator(S, D, move(TemplateParameterLists));
+  Decl *NewDecl = HandleDeclarator(S, D, move(TemplateParameterLists));
+  ActOnDocumentableDecl(NewDecl);
+  return NewDecl;
 }

Also need to handle class template (partial) specializations?

@@ -86,7 +93,8 @@
   // so we use the location of the identifier as the "declaration location".
   SourceLocation DeclLoc;
   if (isa<ObjCMethodDecl>(D) || isa<ObjCContainerDecl>(D) ||
-      isa<ObjCPropertyDecl>(D))
+      isa<ObjCPropertyDecl>(D) ||
+      isa<FunctionTemplateDecl>(D) || isa<ClassTemplateDecl>(D))
     DeclLoc = D->getLocStart();
   else
     DeclLoc = D->getLocation();

Also need to handle class template (partial) specializations here?

Looking great, thanks!

	- Doug



More information about the cfe-commits mailing list