[cfe-commits] r162507 - in /cfe/trunk: include/clang/AST/Comment.h lib/AST/Comment.cpp test/Sema/warn-documentation.cpp test/Sema/warn-documentation.m

Dmitri Gribenko gribozavr at gmail.com
Thu Aug 23 17:05:31 PDT 2012


Author: gribozavr
Date: Thu Aug 23 19:05:30 2012
New Revision: 162507

URL: http://llvm.org/viewvc/llvm-project?rev=162507&view=rev
Log:
Comment semantic analysis: treat function typedefs as functions so that one can
use \param and \returns in documentation.

Fixes PR13533.

Modified:
    cfe/trunk/include/clang/AST/Comment.h
    cfe/trunk/lib/AST/Comment.cpp
    cfe/trunk/test/Sema/warn-documentation.cpp
    cfe/trunk/test/Sema/warn-documentation.m

Modified: cfe/trunk/include/clang/AST/Comment.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Comment.h?rev=162507&r1=162506&r2=162507&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Comment.h (original)
+++ cfe/trunk/include/clang/AST/Comment.h Thu Aug 23 19:05:30 2012
@@ -942,7 +942,9 @@
     /// \li member function,
     /// \li member function template,
     /// \li member function template specialization,
-    /// \li ObjC method.
+    /// \li ObjC method,
+    /// \li a typedef for a function pointer, member function pointer,
+    ///     ObjC block.
     FunctionKind,
 
     /// Something that we consider a "class":

Modified: cfe/trunk/lib/AST/Comment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Comment.cpp?rev=162507&r1=162506&r2=162507&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Comment.cpp (original)
+++ cfe/trunk/lib/AST/Comment.cpp Thu Aug 23 19:05:30 2012
@@ -240,7 +240,58 @@
   case Decl::Namespace:
     Kind = NamespaceKind;
     break;
-  case Decl::Typedef:
+  case Decl::Typedef: {
+    Kind = TypedefKind;
+    // If this is a typedef to something we consider a function, extract
+    // arguments and return type.
+    const TypedefDecl *TD = cast<TypedefDecl>(ThisDecl);
+    const TypeSourceInfo *TSI = TD->getTypeSourceInfo();
+    if (!TSI)
+      break;
+    TypeLoc TL = TSI->getTypeLoc().getUnqualifiedLoc();
+    while (true) {
+      TL = TL.IgnoreParens();
+      // Look through typedefs.
+      if (TypedefTypeLoc *TypedefTL = dyn_cast<TypedefTypeLoc>(&TL)) {
+        TSI = TypedefTL->getTypedefNameDecl()->getTypeSourceInfo();
+        if (TSI)
+          break;
+        TL = TSI->getTypeLoc().getUnqualifiedLoc();
+        continue;
+      }
+      // Look through qualified types.
+      if (QualifiedTypeLoc *QualifiedTL = dyn_cast<QualifiedTypeLoc>(&TL)) {
+        TL = QualifiedTL->getUnqualifiedLoc();
+        continue;
+      }
+      // Look through pointer types.
+      if (PointerTypeLoc *PointerTL = dyn_cast<PointerTypeLoc>(&TL)) {
+        TL = PointerTL->getPointeeLoc().getUnqualifiedLoc();
+        continue;
+      }
+      if (BlockPointerTypeLoc *BlockPointerTL =
+              dyn_cast<BlockPointerTypeLoc>(&TL)) {
+        TL = BlockPointerTL->getPointeeLoc().getUnqualifiedLoc();
+        continue;
+      }
+      if (MemberPointerTypeLoc *MemberPointerTL =
+              dyn_cast<MemberPointerTypeLoc>(&TL)) {
+        TL = MemberPointerTL->getPointeeLoc().getUnqualifiedLoc();
+        continue;
+      }
+      // Is this a typedef for a function type?
+      if (FunctionTypeLoc *FTL = dyn_cast<FunctionTypeLoc>(&TL)) {
+        Kind = FunctionKind;
+        ArrayRef<ParmVarDecl *> Params = FTL->getParams();
+        ParamVars = ArrayRef<const ParmVarDecl *>(Params.data(),
+                                                  Params.size());
+        ResultType = FTL->getResultLoc().getType();
+        break;
+      }
+      break;
+    }
+    break;
+  }
   case Decl::TypeAlias:
     Kind = TypedefKind;
     break;

Modified: cfe/trunk/test/Sema/warn-documentation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation.cpp?rev=162507&r1=162506&r2=162507&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-documentation.cpp (original)
+++ cfe/trunk/test/Sema/warn-documentation.cpp Thu Aug 23 19:05:30 2012
@@ -250,6 +250,29 @@
 /// \param x2 Ccc.
 int test_param18(int x1, int x2, int x3);
 
+// expected-warning at +2 {{parameter 'bbb' not found in the function declaration}} expected-note at +2 {{did you mean 'aaa'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \returns aaa.
+typedef int test_param19(int aaa);
+
+// expected-warning at +2 {{parameter 'bbb' not found in the function declaration}} expected-note at +2 {{did you mean 'aaa'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \returns aaa.
+typedef int (*test_param20)(int aaa);
+
+// expected-warning at +2 {{parameter 'bbb' not found in the function declaration}} expected-note at +2 {{did you mean 'aaa'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \returns aaa.
+typedef int (* const test_param21)(int aaa);
+
+// expected-warning at +2 {{parameter 'bbb' not found in the function declaration}} expected-note at +2 {{did you mean 'aaa'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \returns aaa.
+typedef int (C::*test_param22)(int aaa);
 
 // expected-warning at +1 {{'\tparam' command used in a comment that is not attached to a template declaration}}
 /// \tparam T Aaa

Modified: cfe/trunk/test/Sema/warn-documentation.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-documentation.m?rev=162507&r1=162506&r2=162507&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-documentation.m (original)
+++ cfe/trunk/test/Sema/warn-documentation.m Thu Aug 23 19:05:30 2012
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wno-objc-root-class -Wdocumentation -Wdocumentation-pedantic -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-objc-root-class -Wdocumentation -Wdocumentation-pedantic -verify %s
 
 @class NSString;
 
@@ -91,3 +91,9 @@
 - (void)test2:(NSString *)aaa;
 @end
 
+// expected-warning at +2 {{parameter 'bbb' not found in the function declaration}} expected-note at +2 {{did you mean 'aaa'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \returns aaa.
+typedef int (^test_param1)(int aaa);
+





More information about the cfe-commits mailing list