Skip to content

Commit 1099c80

Browse files
committed
issue #10606 include command via ALIASES does not work anymore
1 parent 13e3779 commit 1099c80

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

doc_internal/commands_internal.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The following table gives an overview of the doxygen internal special commands
44
and the version in which they were introduced.
55

66
\secreflist
7+
\refitem cmdialias \\ialias
78
\refitem cmdendicode \\endicode
89
\refitem cmdendiliteral \\endiliteral
910
\refitem cmdendiverbatim \\endiverbatim
@@ -16,6 +17,16 @@ and the version in which they were introduced.
1617
\refitem cmdiverbatim \\iverbatim
1718
\endsecreflist
1819

20+
<hr>
21+
\section cmdialias \\ialias{name}
22+
23+
\addindex \\ialias
24+
This command is used to prevent endless recursive expansion of aliases. For an alias `name` the command `\ialias{name}` is
25+
inserted after its expansion, and then the expanded string is reparsed, but until the `\ialias` is processed the `name`
26+
is not considered for further alias expansion.
27+
28+
\since doxygen version 1.11.0
29+
1930
<hr>
2031
\section cmdianchor \\ianchor{title} anchor
2132

src/commentcnv.l

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ struct commentcnvYY_state
124124
SrcLangExt lang = SrcLangExt::Unknown;
125125
bool isFixedForm = FALSE; // For Fortran
126126
std::deque<std::unique_ptr<commentcnv_FileState>> includeStack;
127+
std::set<std::string> expandedAliases;
127128
};
128129

129130
[[maybe_unused]] static const char *stateToString(int state);
@@ -382,7 +383,7 @@ SLASHopt [/]*
382383
}
383384
yyextra->blockHeadCol=yyextra->col;
384385
copyToOutput(yyscanner,"/**",3);
385-
replaceAliases(yyscanner,yytext+i);
386+
if (i<yyleng) replaceAliases(yyscanner,yytext+i);
386387
yyextra->inSpecialComment=TRUE;
387388
//BEGIN(SComment);
388389
yyextra->readLineCtx=SComment;
@@ -394,7 +395,7 @@ SLASHopt [/]*
394395
int i=17; //=strlen("//##Documentation");
395396
yyextra->blockHeadCol=yyextra->col;
396397
copyToOutput(yyscanner,"/**",3);
397-
replaceAliases(yyscanner,yytext+i);
398+
if (i<yyleng) replaceAliases(yyscanner,yytext+i);
398399
yyextra->inRoseComment=TRUE;
399400
BEGIN(SComment);
400401
}
@@ -1486,9 +1487,39 @@ static bool readIncludeFile(yyscan_t yyscanner,const QCString &inc,const QCStrin
14861487
*/
14871488
static void replaceAliases(yyscan_t yyscanner,std::string_view s)
14881489
{
1490+
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1491+
if (s.empty()) return;
1492+
size_t pos = s.find('{');
1493+
std::string cmd { s.substr(1, pos!=std::string::npos ? pos-1 : s.length()-1) };
1494+
if (yyextra->expandedAliases.find(cmd)!=yyextra->expandedAliases.end())
1495+
{
1496+
copyToOutput(yyscanner,s.data(),s.length());
1497+
return; // prevent recursive expansion
1498+
}
1499+
else if (cmd=="ialias")
1500+
{
1501+
if (s.length()>cmd.length()+3) // \cmd{value}
1502+
{
1503+
std::string value { s.substr(cmd.length()+2,s.length()-cmd.length()-3) };
1504+
//printf("removing value '%s'\n",qPrint(value));
1505+
yyextra->expandedAliases.erase(value);
1506+
}
1507+
return;
1508+
}
14891509
std::string result = resolveAliasCmd(s);
14901510
//printf("replaceAliases(%s)->'%s'\n",qPrint(s),qPrint(result));
1491-
copyToOutput(yyscanner,result.data(),result.length());
1511+
if (result!=s)
1512+
{
1513+
yyextra->expandedAliases.insert(cmd);
1514+
result += " \\ialias{";
1515+
result += cmd;
1516+
result += "}";
1517+
for (int i=(int)result.length()-1;i>=0;i--) unput(result[i]);
1518+
}
1519+
else
1520+
{
1521+
copyToOutput(yyscanner,result.data(),result.length());
1522+
}
14921523
}
14931524
14941525
@@ -1551,6 +1582,7 @@ void convertCppComments(const BufStr &inBuf,BufStr &outBuf,const QCString &fileN
15511582
yyextra->lang = getLanguageFromFileName(fileName);
15521583
yyextra->pythonDocString = FALSE;
15531584
yyextra->lineNr = 1;
1585+
yyextra->expandedAliases.clear();
15541586
while (!yyextra->condStack.empty()) yyextra->condStack.pop();
15551587
clearCommentStack(yyscanner);
15561588
yyextra->vhdl = FALSE;

0 commit comments

Comments
 (0)