From 907f6b8c06f0bfdb345dd2ee480a50d1e489c7d8 Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Fri, 24 Aug 2012 00:05:30 +0000 Subject: Comment semantic analysis: treat function typedefs as functions so that one can use \param and \returns in documentation. Fixes PR13533. llvm-svn: 162507 --- clang/lib/AST/Comment.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'clang/lib/AST/Comment.cpp') diff --git a/clang/lib/AST/Comment.cpp b/clang/lib/AST/Comment.cpp index 8a711f0c1f8..2af38961563 100644 --- a/clang/lib/AST/Comment.cpp +++ b/clang/lib/AST/Comment.cpp @@ -240,7 +240,58 @@ void DeclInfo::fill() { 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(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(&TL)) { + TSI = TypedefTL->getTypedefNameDecl()->getTypeSourceInfo(); + if (TSI) + break; + TL = TSI->getTypeLoc().getUnqualifiedLoc(); + continue; + } + // Look through qualified types. + if (QualifiedTypeLoc *QualifiedTL = dyn_cast(&TL)) { + TL = QualifiedTL->getUnqualifiedLoc(); + continue; + } + // Look through pointer types. + if (PointerTypeLoc *PointerTL = dyn_cast(&TL)) { + TL = PointerTL->getPointeeLoc().getUnqualifiedLoc(); + continue; + } + if (BlockPointerTypeLoc *BlockPointerTL = + dyn_cast(&TL)) { + TL = BlockPointerTL->getPointeeLoc().getUnqualifiedLoc(); + continue; + } + if (MemberPointerTypeLoc *MemberPointerTL = + dyn_cast(&TL)) { + TL = MemberPointerTL->getPointeeLoc().getUnqualifiedLoc(); + continue; + } + // Is this a typedef for a function type? + if (FunctionTypeLoc *FTL = dyn_cast(&TL)) { + Kind = FunctionKind; + ArrayRef Params = FTL->getParams(); + ParamVars = ArrayRef(Params.data(), + Params.size()); + ResultType = FTL->getResultLoc().getType(); + break; + } + break; + } + break; + } case Decl::TypeAlias: Kind = TypedefKind; break; -- cgit v1.2.3