forked from OSchip/llvm-project
Documentation comment parsing: allow \param and \returns on std::function,
boost::function and similar function-like objects llvm-svn: 197528
This commit is contained in:
parent
2553e49a5d
commit
fa68a57cf7
|
@ -266,6 +266,10 @@ void DeclInfo::fill() {
|
||||||
TL = MemberPointerTL.getPointeeLoc().getUnqualifiedLoc();
|
TL = MemberPointerTL.getPointeeLoc().getUnqualifiedLoc();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (ElaboratedTypeLoc ETL = TL.getAs<ElaboratedTypeLoc>()) {
|
||||||
|
TL = ETL.getNamedTypeLoc();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// Is this a typedef for a function type?
|
// Is this a typedef for a function type?
|
||||||
if (FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>()) {
|
if (FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>()) {
|
||||||
Kind = FunctionKind;
|
Kind = FunctionKind;
|
||||||
|
@ -275,6 +279,28 @@ void DeclInfo::fill() {
|
||||||
ResultType = FTL.getResultLoc().getType();
|
ResultType = FTL.getResultLoc().getType();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (TemplateSpecializationTypeLoc STL =
|
||||||
|
TL.getAs<TemplateSpecializationTypeLoc>()) {
|
||||||
|
// If we have a typedef to a template specialization with exactly one
|
||||||
|
// template argument of a function type, this looks like std::function,
|
||||||
|
// boost::function, or other function wrapper. Treat these typedefs as
|
||||||
|
// functions.
|
||||||
|
if (STL.getNumArgs() != 1)
|
||||||
|
break;
|
||||||
|
TemplateArgumentLoc MaybeFunction = STL.getArgLoc(0);
|
||||||
|
if (MaybeFunction.getArgument().getKind() != TemplateArgument::Type)
|
||||||
|
break;
|
||||||
|
TypeSourceInfo *MaybeFunctionTSI = MaybeFunction.getTypeSourceInfo();
|
||||||
|
TypeLoc TL = MaybeFunctionTSI->getTypeLoc().getUnqualifiedLoc();
|
||||||
|
if (FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>()) {
|
||||||
|
Kind = FunctionKind;
|
||||||
|
ArrayRef<ParmVarDecl *> Params = FTL.getParams();
|
||||||
|
ParamVars = ArrayRef<const ParmVarDecl *>(Params.data(),
|
||||||
|
Params.size());
|
||||||
|
ResultType = FTL.getResultLoc().getType();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -275,6 +275,21 @@ int test_param21(int a);
|
||||||
/// \param x2 Ccc.
|
/// \param x2 Ccc.
|
||||||
int test_param22(int x1, int x2, int x3);
|
int test_param22(int x1, int x2, int x3);
|
||||||
|
|
||||||
|
//===---
|
||||||
|
// Test that we treat typedefs to some non-function types as functions for the
|
||||||
|
// purposes of documentation comment parsing.
|
||||||
|
//===---
|
||||||
|
|
||||||
|
namespace foo {
|
||||||
|
inline namespace bar {
|
||||||
|
template<typename>
|
||||||
|
struct function_wrapper {};
|
||||||
|
|
||||||
|
template<unsigned>
|
||||||
|
struct not_a_function_wrapper {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
|
// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
|
||||||
/// \param aaa Meow.
|
/// \param aaa Meow.
|
||||||
/// \param bbb Bbb.
|
/// \param bbb Bbb.
|
||||||
|
@ -299,6 +314,19 @@ typedef int (* const test_function_like_typedef3)(int aaa, int ccc);
|
||||||
/// \returns aaa.
|
/// \returns aaa.
|
||||||
typedef int (C::*test_function_like_typedef4)(int aaa, int ccc);
|
typedef int (C::*test_function_like_typedef4)(int aaa, int ccc);
|
||||||
|
|
||||||
|
// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
|
||||||
|
/// \param aaa Meow.
|
||||||
|
/// \param bbb Bbb.
|
||||||
|
/// \returns aaa.
|
||||||
|
typedef foo::function_wrapper<int (int aaa, int ccc)> test_function_like_typedef5;
|
||||||
|
|
||||||
|
// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
|
||||||
|
/// \param aaa Meow.
|
||||||
|
/// \param bbb Bbb.
|
||||||
|
/// \returns aaa.
|
||||||
|
typedef foo::function_wrapper<int (int aaa, int ccc)> *test_function_like_typedef6;
|
||||||
|
|
||||||
|
|
||||||
typedef int (*test_not_function_like_typedef1)(int aaa);
|
typedef int (*test_not_function_like_typedef1)(int aaa);
|
||||||
|
|
||||||
// expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}}
|
// expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}}
|
||||||
|
@ -311,6 +339,9 @@ typedef test_not_function_like_typedef1 test_not_function_like_typedef2;
|
||||||
/// @param aaa Meow.
|
/// @param aaa Meow.
|
||||||
typedef unsigned int test_not_function_like_typedef3;
|
typedef unsigned int test_not_function_like_typedef3;
|
||||||
|
|
||||||
|
// expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}}
|
||||||
|
/// \param aaa Meow.
|
||||||
|
typedef foo::not_a_function_wrapper<1> test_not_function_like_typedef4;
|
||||||
|
|
||||||
/// \param aaa Aaa
|
/// \param aaa Aaa
|
||||||
/// \param ... Vararg
|
/// \param ... Vararg
|
||||||
|
|
Loading…
Reference in New Issue