Skip to content

Commit 85f149d

Browse files
committed
Merge branch 'dmccabe-jt-trailing-return-type-pure'
2 parents 5111e92 + bfe3edb commit 85f149d

File tree

3 files changed

+167
-0
lines changed

3 files changed

+167
-0
lines changed

src/xmlgen.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,54 @@ static QCString memberOutputFileBase(const MemberDef *md)
583583
return md->getOutputFileBase();
584584
}
585585

586+
// Removes a keyword from a given string
587+
// @param str string from which to strip the keyword
588+
// @param needSpace true if spacing is required around the keyword
589+
// @return true if the keyword was removed, false otherwise
590+
static bool stripKeyword(QCString& str, const char *keyword, bool needSpace)
591+
{
592+
bool found = false;
593+
int searchStart = 0;
594+
int len = static_cast<int>(strlen(keyword));
595+
int searchEnd = static_cast<int>(str.size());
596+
while (searchStart<searchEnd)
597+
{
598+
int index = str.find(keyword, searchStart);
599+
if (index==-1)
600+
{
601+
break; // no more occurrences found
602+
}
603+
int end = index + len;
604+
if (needSpace)
605+
{
606+
if ((index>0 && str[index-1]!=' ') || // at the start of the string or preceded by a space, or
607+
(end!=searchEnd && str[end] !=' ') // at the end of the string or followed by a space.
608+
)
609+
{
610+
searchStart = end;
611+
continue; // no a standalone word
612+
}
613+
}
614+
if (needSpace && index>0) // strip with space before keyword
615+
{
616+
str.remove(index-1, len+1);
617+
searchEnd -= (len+1);
618+
}
619+
else if (needSpace && end<searchEnd) // strip with space after string starting with keyword
620+
{
621+
str.remove(index, len+1);
622+
searchEnd -= (len+1);
623+
}
624+
else // strip just keyword
625+
{
626+
str.remove(index, len);
627+
searchEnd -= len;
628+
}
629+
found = true;
630+
}
631+
return found;
632+
}
633+
586634
static QCString extractNoExcept(QCString &argsStr)
587635
{
588636
QCString expr;
@@ -689,6 +737,18 @@ static void generateXMLForMember(const MemberDef *md,TextStream &ti,TextStream &
689737
{
690738
typeStr=argsStr.mid(i+2).stripWhiteSpace();
691739
argsStr=argsStr.left(i).stripWhiteSpace();
740+
if (stripKeyword(typeStr, "override", true))
741+
{
742+
argsStr += " override";
743+
}
744+
if (stripKeyword(typeStr, "final", true))
745+
{
746+
argsStr += " final";
747+
}
748+
if (stripKeyword(typeStr, "=0", false))
749+
{
750+
argsStr += "=0";
751+
}
692752
i=defStr.find("auto ");
693753
if (i!=-1)
694754
{

testing/108/class_c.xml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="" xml:lang="en-US">
3+
<compounddef id="class_c" kind="class" language="C++" prot="public" abstract="yes">
4+
<compoundname>C</compoundname>
5+
<sectiondef kind="public-func">
6+
<memberdef kind="function" id="class_c_1a0b664e9b999fca39643fe34a77579794" prot="public" static="no" const="no" explicit="no" inline="no" virt="pure-virtual">
7+
<type>int</type>
8+
<definition>virtual int C::f_pure</definition>
9+
<argsstring>()=0</argsstring>
10+
<name>f_pure</name>
11+
<qualifiedname>C::f_pure</qualifiedname>
12+
<briefdescription>
13+
<para>Pure. </para>
14+
</briefdescription>
15+
<detaileddescription>
16+
</detaileddescription>
17+
<inbodydescription>
18+
</inbodydescription>
19+
<location file="108_trailing_return_types.cpp" line="8" column="18"/>
20+
</memberdef>
21+
<memberdef kind="function" id="class_c_1a0c18882ecf4845fe4c4b36700f2494df" prot="public" static="no" const="no" explicit="no" inline="no" virt="non-virtual">
22+
<type>int</type>
23+
<definition>int C::f_override</definition>
24+
<argsstring>() override</argsstring>
25+
<name>f_override</name>
26+
<qualifiedname>C::f_override</qualifiedname>
27+
<briefdescription>
28+
<para>Override. </para>
29+
</briefdescription>
30+
<detaileddescription>
31+
</detaileddescription>
32+
<inbodydescription>
33+
</inbodydescription>
34+
<location file="108_trailing_return_types.cpp" line="10" column="10"/>
35+
</memberdef>
36+
<memberdef kind="function" id="class_c_1a04dd9ca5948792c146024e91dc007446" prot="public" static="no" const="no" explicit="no" inline="no" final="yes" virt="virtual">
37+
<type>int</type>
38+
<definition>virtual int C::f_final</definition>
39+
<argsstring>() final</argsstring>
40+
<name>f_final</name>
41+
<qualifiedname>C::f_final</qualifiedname>
42+
<briefdescription>
43+
<para>Final. </para>
44+
</briefdescription>
45+
<detaileddescription>
46+
</detaileddescription>
47+
<inbodydescription>
48+
</inbodydescription>
49+
<location file="108_trailing_return_types.cpp" line="12" column="18"/>
50+
</memberdef>
51+
<memberdef kind="function" id="class_c_1a67f38ea378777e64ac87f0f50c619be9" prot="public" static="no" const="no" explicit="no" inline="no" final="yes" virt="virtual">
52+
<type>int</type>
53+
<definition>virtual int C::f_override_final</definition>
54+
<argsstring>() override final</argsstring>
55+
<name>f_override_final</name>
56+
<qualifiedname>C::f_override_final</qualifiedname>
57+
<briefdescription>
58+
<para>Final and override. </para>
59+
</briefdescription>
60+
<detaileddescription>
61+
</detaileddescription>
62+
<inbodydescription>
63+
</inbodydescription>
64+
<location file="108_trailing_return_types.cpp" line="14" column="18"/>
65+
</memberdef>
66+
</sectiondef>
67+
<briefdescription>
68+
<para>A structure. </para>
69+
</briefdescription>
70+
<detaileddescription>
71+
</detaileddescription>
72+
<location file="108_trailing_return_types.cpp" line="5" column="1" bodyfile="108_trailing_return_types.cpp" bodystart="5" bodyend="15"/>
73+
<listofallmembers>
74+
<member refid="class_c_1a04dd9ca5948792c146024e91dc007446" prot="public" virt="virtual">
75+
<scope>C</scope>
76+
<name>f_final</name>
77+
</member>
78+
<member refid="class_c_1a0c18882ecf4845fe4c4b36700f2494df" prot="public" virt="non-virtual">
79+
<scope>C</scope>
80+
<name>f_override</name>
81+
</member>
82+
<member refid="class_c_1a67f38ea378777e64ac87f0f50c619be9" prot="public" virt="virtual">
83+
<scope>C</scope>
84+
<name>f_override_final</name>
85+
</member>
86+
<member refid="class_c_1a0b664e9b999fca39643fe34a77579794" prot="public" virt="pure-virtual">
87+
<scope>C</scope>
88+
<name>f_pure</name>
89+
</member>
90+
</listofallmembers>
91+
</compounddef>
92+
</doxygen>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// objective: check that modifiers are correctly parsed with trailing return types
2+
// check: class_c.xml
3+
4+
/** @brief A structure. */
5+
class C {
6+
public:
7+
/** @brief Pure. */
8+
virtual auto f_pure() -> int = 0;
9+
/** @brief Override. */
10+
auto f_override() -> int override;
11+
/** @brief Final. */
12+
virtual auto f_final() -> int final;
13+
/** @brief Final and override. */
14+
virtual auto f_override_final() -> int override final;
15+
};

0 commit comments

Comments
 (0)