Skip to content

Commit 09438a9

Browse files
committed
Fixed code folding issue (retry)
When STRIP_CODE_COMMENTS=YES and the current code block was directly followed by a (hidden) comment block, the code block did not end properly.
1 parent ddd687a commit 09438a9

File tree

3 files changed

+55
-38
lines changed

3 files changed

+55
-38
lines changed

src/code.l

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ static bool skipLanguageSpecificKeyword(yyscan_t yyscanner,const char *kw);
260260
static int yyread(yyscan_t yyscanner,char *buf,int max_size);
261261
static void addVariable(yyscan_t yyscanner,QCString type,QCString name);
262262
static bool startsWithKeyword(const QCString &str,const QCString &kw);
263+
static void endCodeFold(yyscan_t yyscanner);
264+
static void skipHiddenComment(yyscan_t yyscanner,const char *text);
263265

264266
/* -----------------------------------------------------------------
265267
*/
@@ -1976,12 +1978,12 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
19761978
yyextra->code->codify(yytext);
19771979
}
19781980
<RemoveSpecialCComment>{CCE}{B}*\n({B}*\n)*({B}*(({CPPC}"@"[{}])|({CCS}"@"[{}]{CCE})){B}*\n)?{B}*{CCS}[*!]/{NCOMM} {
1979-
yyextra->yyLineNr+=QCString(yytext).contains('\n');
1981+
skipHiddenComment(yyscanner,yytext);
19801982
}
19811983
<RemoveSpecialCComment>{CCE}{B}*\n({B}*\n)*({B}*(({CPPC}"@"[{}])|({CCS}"@"[{}]{CCE})){B}*\n)? {
19821984
if (yyextra->lastSpecialCContext==SkipCxxComment)
19831985
{ // force end of C++ comment here
1984-
yyextra->yyLineNr+=QCString(yytext).contains('\n');
1986+
skipHiddenComment(yyscanner,yytext);
19851987
nextCodeLine(yyscanner);
19861988
endFontClass(yyscanner);
19871989
BEGIN( yyextra->lastCContext ) ;
@@ -2006,7 +2008,7 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
20062008
}
20072009
<RemoveSpecialCComment>[^*\n]+
20082010
<RemoveSpecialCComment>{CPPC}|{CCS}
2009-
<RemoveSpecialCComment>\n { yyextra->yyLineNr++; }
2011+
<RemoveSpecialCComment>\n { yyextra->yyLineNr++; endCodeFold(yyscanner); }
20102012
<RemoveSpecialCComment>.
20112013
<MemberCall>[^a-z_A-Z0-9(\n] {
20122014
yyextra->code->codify(yytext);
@@ -2018,7 +2020,7 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
20182020
if (YY_START==SkipCPP) REJECT;
20192021
if (Config_getBool(STRIP_CODE_COMMENTS))
20202022
{
2021-
yyextra->yyLineNr+=QCString(yytext).contains('\n');
2023+
skipHiddenComment(yyscanner,yytext);
20222024
nextCodeLine(yyscanner);
20232025
}
20242026
else
@@ -2041,7 +2043,7 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
20412043
<*>\n{B}*{CPPC}"@"[{}].*\n { // remove one-line group marker
20422044
if (Config_getBool(STRIP_CODE_COMMENTS))
20432045
{
2044-
yyextra->yyLineNr+=2;
2046+
skipHiddenComment(yyscanner,yytext);
20452047
nextCodeLine(yyscanner);
20462048
}
20472049
else
@@ -2078,7 +2080,7 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
20782080
<*>^{B}*{CPPC}"@"[{}].*\n { // remove one-line group marker
20792081
if (Config_getBool(STRIP_CODE_COMMENTS))
20802082
{
2081-
yyextra->yyLineNr++;
2083+
skipHiddenComment(yyscanner,yytext);
20822084
nextCodeLine(yyscanner);
20832085
}
20842086
else
@@ -2123,11 +2125,11 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
21232125
endFontClass(yyscanner);
21242126
}
21252127
}
2126-
<*>\n{B}*{CCS}[!*]/{NCOMM} {
2128+
<*>\n{B}*{CCS}[!*]/{NCOMM} {
21272129
if (Config_getBool(STRIP_CODE_COMMENTS))
21282130
{
2131+
skipHiddenComment(yyscanner,yytext);
21292132
if (YY_START != RemoveSpecialCComment) yyextra->lastSpecialCContext = YY_START;
2130-
yyextra->yyLineNr++;
21312133
BEGIN(RemoveSpecialCComment);
21322134
}
21332135
else
@@ -2160,7 +2162,7 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
21602162
BEGIN(SkipComment);
21612163
}
21622164
}
2163-
<*>^{B}*{CCS}[!*]/{NCOMM} { // special C comment block at a new line
2165+
<*>^{B}*{CCS}[!*]/{NCOMM} { // special C comment block at a new line
21642166
if (Config_getBool(STRIP_CODE_COMMENTS))
21652167
{
21662168
if (YY_START != RemoveSpecialCComment) yyextra->lastSpecialCContext = YY_START;
@@ -2178,7 +2180,7 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
21782180
BEGIN(SkipComment);
21792181
}
21802182
}
2181-
<*>{CCS}[!*]/{NCOMM} { // special C comment block half way a line
2183+
<*>{CCS}[!*]/{NCOMM} { // special C comment block half way a line
21822184
if (YY_START==SkipString) REJECT;
21832185
if (Config_getBool(STRIP_CODE_COMMENTS))
21842186
{
@@ -2197,7 +2199,7 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
21972199
BEGIN(SkipComment);
21982200
}
21992201
}
2200-
<*>{CCS}("!"?){CCE} {
2202+
<*>{CCS}("!"?){CCE} {
22012203
if (YY_START==SkipString) REJECT;
22022204
if (!Config_getBool(STRIP_CODE_COMMENTS))
22032205
{
@@ -2209,7 +2211,7 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
22092211
<SkipComment>[^\*\n]+ {
22102212
yyextra->code->codify(yytext);
22112213
}
2212-
<*>{CCS} {
2214+
<*>{CCS} {
22132215
startFontClass(yyscanner,"comment");
22142216
yyextra->code->codify(yytext);
22152217
// check is to prevent getting stuck in skipping C++ comments
@@ -2251,15 +2253,6 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
22512253
yyextra->yyColNr++;
22522254
yyextra->code->codify(yytext);
22532255
}
2254-
/*
2255-
<*>([ \t\n]*"\n"){2,} { // combine multiple blank lines
2256-
//QCString sepLine=yytext;
2257-
//yyextra->code->codify("\n\n");
2258-
//yyextra->yyLineNr+=sepLine.contains('\n');
2259-
//char sepLine[3]="\n\n";
2260-
codifyLines(yyscanner,yytext);
2261-
}
2262-
*/
22632256
22642257
%%
22652258
@@ -2431,27 +2424,51 @@ static void setClassScope(yyscan_t yyscanner,const QCString &name)
24312424
DBG_CTX((stderr,"--->New class scope '%s'\n",qPrint(yyextra->classScope)));
24322425
}
24332426
2427+
static void endCodeFold(yyscan_t yyscanner)
2428+
{
2429+
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2430+
while (!yyextra->foldStack.empty())
2431+
{
2432+
const Definition *dd = yyextra->foldStack.back();
2433+
if (dd->getEndBodyLine()+1==yyextra->yyLineNr) // +1 to close the section after the end of the body
2434+
{
2435+
yyextra->code->endFold();
2436+
//fprintf(stderr,"%d: end codeFolding for %s [%d..%d]\n",yyextra->yyLineNr,qPrint(dd->name()),dd->getStartDefLine(),dd->getEndBodyLine());
2437+
yyextra->foldStack.pop_back();
2438+
}
2439+
else
2440+
{
2441+
//fprintf(stderr,"no end of block dd=%s end=%d\n",qPrint(dd->qualifiedName()),dd->getEndBodyLine());
2442+
break;
2443+
}
2444+
}
2445+
}
2446+
2447+
static void skipHiddenComment(yyscan_t yyscanner,const char *text)
2448+
{
2449+
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2450+
int count=QCString(text).contains('\n');
2451+
if (yyextra->insideCodeLine)
2452+
{
2453+
endCodeLine(yyscanner);
2454+
}
2455+
for (int i=0;i<count;i++)
2456+
{
2457+
yyextra->yyLineNr++;
2458+
endCodeFold(yyscanner);
2459+
}
2460+
}
2461+
2462+
24342463
static void codeFolding(yyscan_t yyscanner,const Definition *d)
24352464
{
24362465
if (Config_getBool(HTML_CODE_FOLDING))
24372466
{
24382467
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2468+
//fprintf(stderr,"codeFolding at %d\n",yyextra->yyLineNr);
24392469
//if (d)
2440-
// printf("%d: codeFolding: candidate=%s [%d..%d]\n",yyextra->yyLineNr,qPrint(d->qualifiedName()),d->getStartDefLine(),d->getEndBodyLine());
2441-
while (!yyextra->foldStack.empty())
2442-
{
2443-
const Definition *dd = yyextra->foldStack.back();
2444-
if (dd->getEndBodyLine()+1==yyextra->yyLineNr) // +1 to close the section after the end of the body
2445-
{
2446-
yyextra->code->endFold();
2447-
//printf("%d: end codeFolding for %s [%d..%d]\n",yyextra->yyLineNr,qPrint(dd->name()),dd->getStartDefLine(),dd->getEndBodyLine());
2448-
yyextra->foldStack.pop_back();
2449-
}
2450-
else
2451-
{
2452-
break;
2453-
}
2454-
}
2470+
// fprintf(stderr,"%d: codeFolding: candidate=%s [%d..%d]\n",yyextra->yyLineNr,qPrint(d->qualifiedName()),d->getStartDefLine(),d->getEndBodyLine());
2471+
endCodeFold(yyscanner);
24552472
if (d)
24562473
{
24572474
int startLine = d->getStartDefLine();

src/htmlgen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,7 @@ void HtmlGenerator::startMemberItem(const QCString &anchor,MemberItemType type,c
19981998
m_t << "<tr class=\"memitem:" << anchor;
19991999
if (!inheritId.isEmpty())
20002000
{
2001-
m_t << " inherit" << inheritId;
2001+
m_t << " inherit " << inheritId;
20022002
}
20032003
m_t << "\"";
20042004
if (!anchor.isEmpty())

src/scanner.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4129,7 +4129,7 @@ NONLopt [^\n]*
41294129
yyextra->current->program << yytext ;
41304130
--yyextra->curlyCount ;
41314131
}
4132-
<ReadBody,ReadNSBody>"}" { //err("ReadBody count=%d\n",yyextra->curlyCount);
4132+
<ReadBody,ReadNSBody>"}" { //err("%d:ReadBody count=%d\n",yyextra->yyLineNr,yyextra->curlyCount);
41334133
if ( yyextra->curlyCount>0 )
41344134
{
41354135
yyextra->current->program << yytext ;

0 commit comments

Comments
 (0)