[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

Eli Friedman eli.friedman at gmail.com
Fri Aug 24 20:49:53 PDT 2012


On Fri, Aug 24, 2012 at 8:47 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
> On Thu, Aug 23, 2012 at 5:05 PM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
>> 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;
>> +      }
>
> Do we really want to look through typedefs?  We don't want to allow
> doc comments on "typedef foo bar;" just because foo happens to be a
> function type.

That wasn't clearly stated; let me try again:

Do we really want to look through typedefs?  Given "typedef foo bar;",
we don't want to allow a doc comment on bar to refer a parameter from
the definition of the typedef foo (which could be anywhere).

-Eli



More information about the cfe-commits mailing list