Skip to content

Commit 8a6c107

Browse files
committed
bug 683051 Template parameter cannot be commented inline
Adding possibilities for inline documentation of template arguments with classes and functions
1 parent c661656 commit 8a6c107

File tree

8 files changed

+94
-5
lines changed

8 files changed

+94
-5
lines changed

src/arguments.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,10 @@ bool ArgumentList::hasDocumentation() const
2323
return std::any_of(begin(),end(),[](const Argument &a){ return a.hasDocumentation(); });
2424
}
2525

26+
/*! the template argument list is documented if one of its
27+
* template arguments is documented
28+
*/
29+
bool ArgumentList::hasTemplateDocumentation() const
30+
{
31+
return std::any_of(begin(),end(),[](const Argument &a){ return a.hasTemplateDocumentation(); });
32+
}

src/arguments.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ struct Argument
3333
return !name.isEmpty() && !docs.isEmpty();
3434
}
3535

36+
bool hasTemplateDocumentation() const
37+
{
38+
return (!name.isEmpty() || !type.isEmpty()) && !docs.isEmpty();
39+
}
40+
3641
QCString attrib; /*!< Argument's attribute (IDL only) */
3742
QCString type; /*!< Argument's type */
3843
QCString canType; /*!< Cached value of canonical type (after type resolution). Empty initially. */
@@ -65,6 +70,8 @@ class ArgumentList
6570

6671
/*! Does any argument of this list have documentation? */
6772
bool hasDocumentation() const;
73+
/*! Does any template argument of this list have documentation? */
74+
bool hasTemplateDocumentation() const;
6875
/*! Does this list have zero or more parameters */
6976
bool hasParameters() const
7077
{

src/classdef.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,16 @@ void ClassDefImpl::writeDetailedDocumentationBody(OutputList &ol) const
16151615
// write type constraints
16161616
writeTypeConstraints(ol,this,m_typeConstraints);
16171617

1618+
ol.generateDoc(
1619+
docFile(),docLine(),
1620+
this,
1621+
nullptr, // memberDef
1622+
inlineTemplateArgListToDoc(m_tempArgs), // docStr
1623+
TRUE, // indexWords
1624+
FALSE, // isExample
1625+
QCString(),FALSE,FALSE,Config_getBool(MARKDOWN_SUPPORT)
1626+
);
1627+
16181628
// write examples
16191629
if (hasExamples())
16201630
{
@@ -1633,7 +1643,7 @@ bool ClassDefImpl::hasDetailedDescription() const
16331643
bool repeatBrief = Config_getBool(REPEAT_BRIEF);
16341644
bool sourceBrowser = Config_getBool(SOURCE_BROWSER);
16351645
return ((!briefDescription().isEmpty() && repeatBrief) ||
1636-
!documentation().isEmpty() ||
1646+
(!documentation().isEmpty() || m_tempArgs.hasTemplateDocumentation()) ||
16371647
(sourceBrowser && getStartBodyLine()!=-1 && getBodyDef()));
16381648
}
16391649

@@ -3556,15 +3566,15 @@ bool ClassDefImpl::isLinkableInProject() const
35563566
// !isAnonymous(),
35573567
// m_prot,
35583568
// !m_isLocal || extractLocal,
3559-
// hasDocumentation() || !hideUndoc,
3569+
// hasDocumentation() || m_tempArgs.hasTemplateDocumentation() || !hideUndoc,
35603570
// !m_isStatic || extractStatic,
35613571
// !isReference());
35623572
return
35633573
!isArtificial() && !isHidden() && /* not hidden */
35643574
!isAnonymous() && /* not anonymous */
35653575
protectionLevelVisible(m_prot) && /* private/internal */
35663576
(!m_isLocal || extractLocal) && /* local */
3567-
(hasDocumentation() || !hideUndoc) && /* documented */
3577+
(hasDocumentation() || m_tempArgs.hasTemplateDocumentation() || !hideUndoc) && /* documented */
35683578
(!m_isStatic || extractStatic) && /* static */
35693579
!isReference(); /* not an external reference */
35703580
}

src/memberdef.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,7 +2692,10 @@ bool MemberDefImpl::hasDetailedDescription() const
26922692
// has one or more documented arguments
26932693
(m_templateMaster ?
26942694
m_templateMaster->argumentList().hasDocumentation() :
2695-
m_defArgList.hasDocumentation());
2695+
m_defArgList.hasDocumentation()) ||
2696+
(m_templateMaster ?
2697+
m_templateMaster->templateArguments().hasTemplateDocumentation() :
2698+
m_tArgList.hasTemplateDocumentation());
26962699

26972700
// generate function guard
26982701
// ================== =======
@@ -3874,6 +3877,19 @@ void MemberDefImpl::writeDocumentation(const MemberList *ml,
38743877
QCString(),FALSE,FALSE,Config_getBool(MARKDOWN_SUPPORT)
38753878
);
38763879

3880+
const ArgumentList &docTemplateArgList = m_templateMaster ?
3881+
m_templateMaster->templateArguments() :
3882+
m_tArgList;
3883+
ol.generateDoc(
3884+
docFile(),docLine(),
3885+
scopedContainer,
3886+
this, // memberDef
3887+
inlineTemplateArgListToDoc(docTemplateArgList), // docStr
3888+
TRUE, // indexWords
3889+
FALSE, // isExample
3890+
QCString(),FALSE,FALSE,Config_getBool(MARKDOWN_SUPPORT)
3891+
);
3892+
38773893
_writeEnumValues(ol,scopedContainer,cfname,ciname,cname);
38783894
_writeReimplements(ol);
38793895
_writeReimplementedBy(ol);
@@ -4300,7 +4316,7 @@ bool MemberDefImpl::hasDocumentation() const
43004316
{
43014317
return DefinitionMixin::hasDocumentation() ||
43024318
(m_mtype==MemberType::Enumeration && m_docEnumValues) || // has enum values
4303-
(m_defArgList.hasDocumentation()); // has doc arguments
4319+
(m_defArgList.hasDocumentation()|| m_tArgList.hasTemplateDocumentation()); // has doc (template) arguments
43044320
}
43054321

43064322

src/scanner.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5034,6 +5034,7 @@ NONLopt [^\n]*
50345034
yyextra->fullArgString+=*yytext;
50355035
//printf("end template list '%s'\n",qPrint(*yyextra->copyArgString));
50365036
*yyextra->currentArgumentList = *stringToArgumentList(yyextra->language, yyextra->fullArgString);
5037+
handleParametersCommentBlocks(yyscanner,yyextra->current->tArgLists.back());
50375038
BEGIN( yyextra->currentArgumentContext );
50385039
}
50395040
<CopyArgRound>"(" {

src/util.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,33 @@ QCString inlineArgListToDoc(const ArgumentList &al)
11711171
return paramDocs;
11721172
}
11731173

1174+
QCString inlineTemplateArgListToDoc(const ArgumentList &al)
1175+
{
1176+
QCString paramDocs;
1177+
if (al.hasTemplateDocumentation())
1178+
{
1179+
for (const Argument &a : al)
1180+
{
1181+
if (!a.docs.isEmpty())
1182+
{
1183+
if (!a.name.isEmpty())
1184+
{
1185+
paramDocs+=" \\ilinebr @tparam "+a.name+" "+a.docs;
1186+
}
1187+
else if (!a.type.isEmpty())
1188+
{
1189+
QCString type = a.type;
1190+
type.stripPrefix("class ");
1191+
type.stripPrefix("typename ");
1192+
type = type.stripWhiteSpace();
1193+
paramDocs+=" \\ilinebr @tparam "+type+" "+a.docs;
1194+
}
1195+
}
1196+
}
1197+
}
1198+
return paramDocs;
1199+
}
1200+
11741201
QCString argListToString(const ArgumentList &al,bool useCanonicalType,bool showDefVals)
11751202
{
11761203
QCString result;

src/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ inline bool isIdJS(int c)
215215
QCString removeRedundantWhiteSpace(const QCString &s);
216216

217217
QCString inlineArgListToDoc(const ArgumentList &al);
218+
QCString inlineTemplateArgListToDoc(const ArgumentList &al);
218219

219220
QCString argListToString(const ArgumentList &al,bool useCanonicalType=FALSE,bool showDefVals=TRUE);
220221

src/xmlgen.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
// debug inside output
6060
//#define XML_DB(x) QCString __t;__t.sprintf x;m_t << __t
6161

62+
static void writeXMLDocBlock(TextStream &t,
63+
const QCString &fileName,
64+
int lineNr,
65+
const Definition *scope,
66+
const MemberDef * md,
67+
const QCString &text);
6268
//------------------
6369

6470
inline void writeXMLString(TextStream &t,const QCString &s)
@@ -403,6 +409,20 @@ static void writeTemplateArgumentList(TextStream &t,
403409
linkifyText(TextGeneratorXMLImpl(t),scope,fileScope,nullptr,a.typeConstraint);
404410
t << "</typeconstraint>\n";
405411
}
412+
if (a.hasTemplateDocumentation())
413+
{
414+
t << indentStr << " <briefdescription>\n";
415+
t << indentStr << " ";
416+
if (scope)
417+
{
418+
writeXMLDocBlock(t,scope->briefFile(),scope->briefLine(),scope,nullptr,a.docs);
419+
}
420+
else
421+
{
422+
writeXMLDocBlock(t,fileScope->briefFile(),fileScope->briefLine(),fileScope,nullptr,a.docs);
423+
}
424+
t << indentStr << " </briefdescription>\n";
425+
}
406426
t << indentStr << " </param>\n";
407427
}
408428
t << indentStr << "</templateparamlist>\n";

0 commit comments

Comments
 (0)