Skip to content

Commit

Permalink
Make multi-line macro definitions foldable
Browse files Browse the repository at this point in the history
  • Loading branch information
doxygen committed Aug 2, 2023
1 parent ee4b4a8 commit ea305c6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
27 changes: 24 additions & 3 deletions src/code.l
Expand Up @@ -2408,9 +2408,30 @@ static void codeFolding(yyscan_t yyscanner,const Definition *d)
(yyextra->foldStack.empty() || yyextra->foldStack.back()->getEndBodyLine()!=startLine))
{
//printf("%d: start codeFolding for %s [%d..%d]\n",yyextra->yyLineNr,qPrint(d->name()),d->getStartDefLine(),d->getEndBodyLine());
bool needsSemi = d->definitionType()==Definition::TypeClass ||
(d->definitionType()==Definition::TypeMember && !toMemberDef(d)->isCallable());
yyextra->code->startFold(yyextra->yyLineNr,"{",needsSemi ? "};" : "}");
if (d->definitionType()==Definition::TypeMember)
{
const MemberDef *md = toMemberDef(d);
if (md && md->isDefine())
{
yyextra->code->startFold(yyextra->yyLineNr,"",""); // #define X ...
}
else if (md && md->isCallable())
{
yyextra->code->startFold(yyextra->yyLineNr,"{","}"); // func() { ... }
}
else
{
yyextra->code->startFold(yyextra->yyLineNr,"{","};"); // enum X { ... }
}
}
else if (d->definitionType()==Definition::TypeClass)
{
yyextra->code->startFold(yyextra->yyLineNr,"{","};"); // class X { ... };
}
else
{
yyextra->code->startFold(yyextra->yyLineNr,"{","}"); // namespace X {...}
}
yyextra->foldStack.push_back(d);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dispatcher.h
Expand Up @@ -73,7 +73,7 @@ struct Dispatcher<true>
//! \tparam As the parameter types used to invoke the method
//! \param v a object of the variant type for which to invoke the method
//! \param args the parameters to pass to the method
//! \note This implementation assumes a maximum of 10 types in the variant (easy to extend though by adding more cases).
//! \note This implementation assumes a maximum of 20 types in the variant (easy to extend though by adding more cases).
template<template<class> class W,class V, class...As>
static constexpr void dispatch_call(V &&v,As &&... args)
{
Expand Down
11 changes: 9 additions & 2 deletions src/pre.l
Expand Up @@ -1682,13 +1682,20 @@ WSopt [ \t\r]*
"expected formal parameter after # in macro definition '%s': '%s'",
qPrint(yyextra->defName),qPrint(yyextra->defLitText.stripWhiteSpace()));
}
yyextra->defLitText+=yytext;
if (!comment.isEmpty())
{
outputString(yyscanner,comment);
yyextra->defLitText=yyextra->defLitText.left(yyextra->defLitText.length()-comment.length()-1);
}
outputChar(yyscanner,'\n');
if (yyextra->defLitText.find('\n')!=-1)
{
outputString(yyscanner,"/*#end#*/\n");
}
else
{
outputChar(yyscanner,'\n');
}
yyextra->defLitText+=yytext;
Define *def=0;
//printf("Define name='%s' text='%s' litTexti='%s'\n",qPrint(yyextra->defName),qPrint(yyextra->defText),qPrint(yyextra->defLitText));
if (yyextra->includeStack.empty() || yyextra->curlyCount>0)
Expand Down
10 changes: 8 additions & 2 deletions src/scanner.l
Expand Up @@ -2582,7 +2582,7 @@ NONLopt [^\n]*
yyextra->current->name = yytext;
BEGIN(DefineEnd);
}
<DefineEnd>\n {
<DefineEnd>({BN}*{B}*"/*#end#*/")?\n {
//printf("End define: doc=%s docFile=%s docLine=%d\n",qPrint(yyextra->current->doc),qPrint(yyextra->current->docFile),yyextra->current->docLine);
yyextra->current->fileName = yyextra->fileName;
yyextra->current->startLine = yyextra->yyLineNr;
Expand All @@ -2591,8 +2591,14 @@ NONLopt [^\n]*
yyextra->current->args = yyextra->current->args.simplifyWhiteSpace();
yyextra->current->name = yyextra->current->name.stripWhiteSpace();
yyextra->current->section = Entry::DEFINE_SEC;
yyextra->current_root->moveToSubEntryAndRefresh(yyextra->current);
lineCount(yyscanner);
if (yyleng>1) // multiline define
{
yyextra->current->endBodyLine = yyextra->yyLineNr-1;
//printf("found multiline define %s body=[%d..%d]\n",
// qPrint(yyextra->current->name),yyextra->current->bodyLine,yyextra->current->endBodyLine);
}
yyextra->current_root->moveToSubEntryAndRefresh(yyextra->current);
initEntry(yyscanner);
BEGIN(yyextra->lastDefineContext);
}
Expand Down
4 changes: 2 additions & 2 deletions testing/085/085__tooltip_8cpp.xml
Expand Up @@ -34,7 +34,7 @@
</detaileddescription>
<inbodydescription>
</inbodydescription>
<location file="085_tooltip.cpp" line="11" column="9" bodyfile="085_tooltip.cpp" bodystart="11" bodyend="-1"/>
<location file="085_tooltip.cpp" line="11" column="9" bodyfile="085_tooltip.cpp" bodystart="11" bodyend="15"/>
</memberdef>
<memberdef kind="define" id="085__tooltip_8cpp_1a11a2c0486e2bbd915f975a3517817de6" prot="public" static="no">
<name>FCLOSE_MACRO</name>
Expand All @@ -49,7 +49,7 @@
</detaileddescription>
<inbodydescription>
</inbodydescription>
<location file="085_tooltip.cpp" line="18" column="9" bodyfile="085_tooltip.cpp" bodystart="18" bodyend="-1"/>
<location file="085_tooltip.cpp" line="18" column="9" bodyfile="085_tooltip.cpp" bodystart="18" bodyend="22"/>
</memberdef>
</sectiondef>
<sectiondef kind="var">
Expand Down

0 comments on commit ea305c6

Please sign in to comment.