@@ -107,7 +107,8 @@ struct commentcnvYY_state
107
107
int javaBlock = 0 ;
108
108
bool specialComment = FALSE ;
109
109
bool inVerbatim = false ;
110
- QCString incPrefix;
110
+ bool firstIncludeLine = false ;
111
+ bool insertCppCommentMarker = false ;
111
112
QCString aliasCmd;
112
113
QCString aliasString;
113
114
int blockCount = 0 ;
@@ -251,7 +252,6 @@ SLASHopt [/]*
251
252
clearCommentStack (yyscanner); /* to be on the save side */
252
253
copyToOutput (yyscanner,yytext,yyleng);
253
254
BEGIN (CComment);
254
- yyextra->incPrefix = " " ;
255
255
yyextra->commentStack .push (yyextra->lineNr );
256
256
}
257
257
}
@@ -273,7 +273,6 @@ SLASHopt [/]*
273
273
clearCommentStack (yyscanner); /* to be on the save side */
274
274
copyToOutput (yyscanner,yytext,yyleng);
275
275
BEGIN (CComment);
276
- yyextra->incPrefix = " " ;
277
276
yyextra->commentStack .push (yyextra->lineNr );
278
277
}
279
278
}
@@ -287,9 +286,10 @@ SLASHopt [/]*
287
286
copyToOutput (yyscanner,yytext,yyleng);
288
287
yyextra->nestingCount =0 ; // Fortran doesn't have an end comment
289
288
clearCommentStack (yyscanner); /* to be on the save side */
290
- BEGIN (CComment) ;
291
- yyextra->incPrefix = yytext ;
289
+ yyextra-> specialComment = true ;
290
+ yyextra->insertCommentCol =yyextra-> col ;
292
291
yyextra->commentStack .push (yyextra->lineNr );
292
+ BEGIN (CComment);
293
293
}
294
294
}
295
295
<Scan>[Cc\*][><!]/.*\n {
@@ -305,9 +305,10 @@ SLASHopt [/]*
305
305
copyToOutput (yyscanner,yytext,yyleng);
306
306
yyextra->nestingCount =0 ; // Fortran doesn't have an end comment
307
307
clearCommentStack (yyscanner); /* to be on the save side */
308
- BEGIN (CComment) ;
309
- yyextra->incPrefix = yytext ;
308
+ yyextra-> specialComment = true ;
309
+ yyextra->insertCommentCol =yyextra-> col ;
310
310
yyextra->commentStack .push (yyextra->lineNr );
311
+ BEGIN (CComment);
311
312
}
312
313
else
313
314
{
@@ -403,6 +404,8 @@ SLASHopt [/]*
403
404
}
404
405
<Scan>{CPPC}[!/]/.*\n { /* one line special C++ comment */
405
406
yyextra->inSpecialComment=true;
407
+ yyextra->insertCommentCol=yyextra->col+yyleng;
408
+ yyextra->insertCppCommentMarker=true;
406
409
copyToOutput(yyscanner,yytext,yyleng);
407
410
yyextra->readLineCtx=YY_START;
408
411
BEGIN(ReadLine);
@@ -426,9 +429,14 @@ SLASHopt [/]*
426
429
clearCommentStack(yyscanner); /* to be on the save side */
427
430
copyToOutput(yyscanner,yytext,yyleng);
428
431
if (yyextra->specialComment)
432
+ {
433
+ yyextra->insertCommentCol=yyextra->col;
429
434
BEGIN(CComment);
435
+ }
430
436
else
437
+ {
431
438
BEGIN(CNComment);
439
+ }
432
440
yyextra->commentStack.push(yyextra->lineNr);
433
441
}
434
442
<Scan>"#"[^\n ]*\n {
@@ -448,8 +456,13 @@ SLASHopt [/]*
448
456
copyToOutput(yyscanner,yytext,yyleng);
449
457
yyextra->nestingCount=0; // Python doesn' t have an end comment for #
450
458
clearCommentStack (yyscanner); /* to be on the save side */
451
- BEGIN (CComment);
459
+ yyextra->specialComment=(int )yyleng==2 ;
460
+ if (yyextra->specialComment)
461
+ {
462
+ yyextra->insertCommentCol =yyextra->col ;
463
+ }
452
464
yyextra->commentStack.push(yyextra->lineNr);
465
+ BEGIN (CComment);
453
466
}
454
467
}
455
468
<Scan>" --" [^!][^\n]* {
@@ -473,8 +486,8 @@ SLASHopt [/]*
473
486
copyToOutput (yyscanner,yytext,yyleng);
474
487
yyextra->nestingCount =0 ; // VHDL doesn't have an end comment
475
488
clearCommentStack (yyscanner); /* to be on the save side */
476
- BEGIN (CComment);
477
489
yyextra->commentStack .push (yyextra->lineNr );
490
+ BEGIN (CComment);
478
491
}
479
492
}
480
493
<Scan>{B}*![><!] {
@@ -487,9 +500,10 @@ SLASHopt [/]*
487
500
copyToOutput (yyscanner,yytext,yyleng);
488
501
yyextra->nestingCount =0 ; // Fortran doesn't have an end comment
489
502
clearCommentStack (yyscanner); /* to be on the save side */
490
- BEGIN (CComment) ;
491
- yyextra->incPrefix = yytext ;
503
+ yyextra-> specialComment = true ;
504
+ yyextra->insertCommentCol =yyextra-> col ;
492
505
yyextra->commentStack .push (yyextra->lineNr );
506
+ BEGIN (CComment);
493
507
}
494
508
}
495
509
<CComment,CNComment,ReadLine,IncludeFile>{MAILADDR} |
@@ -684,7 +698,10 @@ SLASHopt [/]*
684
698
}
685
699
<Verbatim,VerbatimCode>\n { /* new line in verbatim block */
686
700
copyToOutput (yyscanner,yytext,yyleng);
687
- insertCommentStart (yyscanner);
701
+ if (yyextra->lastCommentContext == IncludeFile)
702
+ {
703
+ insertCommentStart (yyscanner);
704
+ }
688
705
}
689
706
<Verbatim>^[ \t]*{CPPC}[/!] {
690
707
if (yyextra->blockName ==" enddot" || yyextra->blockName ==" endmsc" || yyextra->blockName ==" enduml" || yyextra->blockName .at (0 )==' f' )
@@ -765,17 +782,6 @@ SLASHopt [/]*
765
782
copyToOutput(yyscanner,yytext,yyleng);
766
783
}
767
784
768
- <CComment>{B}*"#"("#")? {
769
- if (yyextra->lang!=SrcLangExt::Python)
770
- {
771
- REJECT;
772
- }
773
- else
774
- {
775
- yyextra->incPrefix = yytext;
776
- copyToOutput(yyscanner,yytext,yyleng);
777
- }
778
- }
779
785
<CComment,CNComment>[^ `~<\\ !@*\n {\" ' \/]* { /* anything that is not a '*' or command */
780
786
copyToOutput (yyscanner,yytext,yyleng);
781
787
}
@@ -918,7 +924,7 @@ SLASHopt [/]*
918
924
BEGIN(SkipString);
919
925
}
920
926
*/
921
- <CComment,CNComment>. {
927
+ <CComment,CNComment>. {
922
928
copyToOutput (yyscanner,yytext,yyleng);
923
929
}
924
930
<SComment>^[ \t]*{CPPC}" /" {SLASHopt}/\n {
@@ -936,8 +942,8 @@ SLASHopt [/]*
936
942
/* See Bug 752712: end the multiline comment when finding a @} or \} command */
937
943
copyToOutput (yyscanner," */" );
938
944
copyToOutput (yyscanner,yytext,yyleng);
939
- yyextra->inSpecialComment =FALSE ;
940
- yyextra->inRoseComment =FALSE ;
945
+ yyextra->inSpecialComment =false ;
946
+ yyextra->inRoseComment =false ;
941
947
BEGIN (Scan);
942
948
}
943
949
<SComment>\n[ \t]*{CPPC}" /" [^\/\n]/.*\n {
@@ -988,6 +994,7 @@ SLASHopt [/]*
988
994
copyToOutput (yyscanner,yytext,yyleng);
989
995
yyextra->inSpecialComment =FALSE ;
990
996
yyextra->inRoseComment =FALSE ;
997
+ yyextra->insertCppCommentMarker =false ;
991
998
yyextra->readLineCtx = Scan; // reset, otherwise there will be problems with:
992
999
// static void handleCondSectionId
993
1000
BEGIN (Scan);
@@ -1006,6 +1013,7 @@ SLASHopt [/]*
1006
1013
}
1007
1014
<ReadLine,CopyLine>{RLopt}/\n {
1008
1015
copyToOutput (yyscanner,yytext,yyleng);
1016
+ yyextra->insertCppCommentMarker =false ;
1009
1017
BEGIN (yyextra->readLineCtx );
1010
1018
}
1011
1019
<CComment,CNComment,ReadLine>" \\ <" { /* escaped html comment */
@@ -1016,10 +1024,22 @@ SLASHopt [/]*
1016
1024
}
1017
1025
<CComment,ReadLine,IncludeFile>[\\@](" include{" {B}*" doc" {B}*" }" |" includedoc" ) {
1018
1026
yyextra->includeCtx = YY_START;
1027
+ yyextra->firstIncludeLine = true ;
1028
+ if (!yyextra->insertCppCommentMarker && (yyextra->includeCtx ==ReadLine || yyextra->includeCtx ==IncludeFile))
1029
+ {
1030
+ yyextra->insertCommentCol = yyextra->blockHeadCol +3 ;
1031
+ yyextra->insertCppCommentMarker = yyextra->mlBrief ;
1032
+ }
1019
1033
BEGIN (IncludeDoc);
1020
1034
}
1021
1035
<CComment,ReadLine,IncludeFile>[\\@](" snippet{" {B}*" doc" {B}*" }" |" snippetdoc" ) {
1022
1036
yyextra->includeCtx = YY_START;
1037
+ yyextra->firstIncludeLine = true ;
1038
+ if (!yyextra->insertCppCommentMarker && (yyextra->includeCtx ==ReadLine || yyextra->includeCtx ==IncludeFile))
1039
+ {
1040
+ yyextra->insertCommentCol = yyextra->blockHeadCol +3 ;
1041
+ yyextra->insertCppCommentMarker = yyextra->mlBrief ;
1042
+ }
1023
1043
BEGIN (SnippetDoc);
1024
1044
}
1025
1045
<IncludeDoc,SnippetDoc>{B}*
@@ -1029,14 +1049,6 @@ SLASHopt [/]*
1029
1049
{
1030
1050
fileName=fileName.mid (1 ,fileName.length ()-2 ); // strip quotes
1031
1051
}
1032
- if (yyextra->includeCtx ==ReadLine)
1033
- {
1034
- yyextra->insertCommentCol = yyextra->blockHeadCol +3 ;
1035
- }
1036
- else
1037
- {
1038
- yyextra->insertCommentCol = 0 ;
1039
- }
1040
1052
if (readIncludeFile (yyscanner,fileName," " ))
1041
1053
{
1042
1054
BEGIN (IncludeFile);
@@ -1054,14 +1066,6 @@ SLASHopt [/]*
1054
1066
fileName=fileName.left (i).stripWhiteSpace ();
1055
1067
// printf("yytext='%s' i=%d fileName='%s' blockId='%s'\n",yytext,i,qPrint(fileName),qPrint(blockId));
1056
1068
if (fileName == " this" ) fileName=yyextra->fileName ;
1057
- if (yyextra->includeCtx ==ReadLine)
1058
- {
1059
- yyextra->insertCommentCol = yyextra->blockHeadCol +3 ;
1060
- }
1061
- else
1062
- {
1063
- yyextra->insertCommentCol = 0 ;
1064
- }
1065
1069
if (readIncludeFile (yyscanner,fileName,blockId))
1066
1070
{
1067
1071
BEGIN (IncludeFile);
@@ -1192,6 +1196,7 @@ SLASHopt [/]*
1192
1196
}
1193
1197
<CopyLine>\n {
1194
1198
copyToOutput (yyscanner,yytext,yyleng);
1199
+ yyextra->insertCppCommentMarker =false ;
1195
1200
BEGIN (yyextra->readLineCtx );
1196
1201
}
1197
1202
<ReadLine>``` {
@@ -1222,6 +1227,7 @@ SLASHopt [/]*
1222
1227
}
1223
1228
if (yyextra->includeStack .empty ())
1224
1229
{
1230
+ yyextra->insertCppCommentMarker =false ;
1225
1231
yyterminate ();
1226
1232
}
1227
1233
else // switch back to parent file
@@ -1236,10 +1242,8 @@ SLASHopt [/]*
1236
1242
yyextra->inBuf = fs->oldFileBuf ;
1237
1243
yyextra->inBufPos = fs->oldFileBufPos ;
1238
1244
yyextra->includeCtx = fs->oldIncludeCtx ;
1239
- yyextra->incPrefix = fs->oldIncPrefix ;
1240
- QCString lineStr=yyextra->incPrefix + " \\ ilinebr \\ ifile \" " +yyextra->fileName +" \" \\ iline " +QCString ().setNum (yyextra->lineNr )+" " ;
1245
+ QCString lineStr= " \\ ilinebr \\ ifile \" " +yyextra->fileName +" \" \\ iline " +QCString ().setNum (yyextra->lineNr )+" " ;
1241
1246
copyToOutput (yyscanner,lineStr.view ());
1242
- yyextra->incPrefix = " " ;
1243
1247
yyextra->includeStack .pop_back ();
1244
1248
// printf("<<EOF>> switch back to %s line %d inbufPos=%d outbufPos=%d\n",
1245
1249
// qPrint(yyextra->fileName),yyextra->lineNr,yyextra->inBufPos,yyextra->outBuf.curPos());
@@ -1468,13 +1472,35 @@ static QCString extractBlock(const QCString &text,const QCString &marker,int &bl
1468
1472
static void insertCommentStart (yyscan_t yyscanner)
1469
1473
{
1470
1474
struct yyguts_t *yyg = (struct yyguts_t *)yyscanner;
1471
- if (yyextra->insertCommentCol>=3 )
1475
+ // printf("insertCommentStart col=%d mlBrief=%d insertCppCommentMarker=%d\n",yyextra->insertCommentCol,yyextra->mlBrief,yyextra->insertCppCommentMarker);
1476
+ if (yyextra->insertCommentCol>=2 )
1472
1477
{
1473
- for (int i=0 ;i<yyextra->insertCommentCol -3 ;i++)
1478
+ int count=yyextra->insertCommentCol -2 ;
1479
+ std::string marker;
1480
+ if (yyextra->lang ==SrcLangExt::Python) // need to insert #
1481
+ {
1482
+ marker=" # " ;
1483
+ }
1484
+ else if (yyextra->lang ==SrcLangExt::Fortran) // need to insert !!
1485
+ {
1486
+ marker=" !! " ;
1487
+ }
1488
+ else if (yyextra->insertCppCommentMarker ) // need to insert ///
1489
+ {
1490
+ count--;
1491
+ marker=" /// " ;
1492
+ }
1493
+ else // need to insert *
1494
+ {
1495
+ marker=" * " ;
1496
+ }
1497
+ for (int i=0 ;i<count;i++)
1474
1498
{
1475
1499
copyToOutput (yyscanner," " );
1476
1500
}
1477
- copyToOutput (yyscanner," * " );
1501
+ // first line is placed after \ilinebr, so omit the *
1502
+ copyToOutput (yyscanner,yyextra->firstIncludeLine ? " " : marker);
1503
+ yyextra->firstIncludeLine = false ;
1478
1504
}
1479
1505
}
1480
1506
@@ -1553,7 +1579,6 @@ static bool readIncludeFile(yyscan_t yyscanner,const QCString &inc,const QCStrin
1553
1579
fs->oldFileBuf = yyextra->inBuf ;
1554
1580
fs->oldFileBufPos = yyextra->inBufPos ;
1555
1581
fs->oldIncludeCtx = yyextra->includeCtx ;
1556
- fs->oldIncPrefix = yyextra->incPrefix ;
1557
1582
yy_switch_to_buffer (yy_create_buffer (0 , YY_BUF_SIZE, yyscanner),yyscanner);
1558
1583
yyextra->fileName = absFileName;
1559
1584
yyextra->lineNr = lineNr;
@@ -1704,6 +1729,7 @@ void convertCppComments(const std::string &inBuf,std::string &outBuf,const std::
1704
1729
yyextra->lang = getLanguageFromFileName(fileName);
1705
1730
yyextra->pythonDocString = FALSE;
1706
1731
yyextra->lineNr = 1;
1732
+ yyextra->insertCppCommentMarker=false;
1707
1733
yyextra->expandedAliases.clear();
1708
1734
while (!yyextra->condStack.empty()) yyextra->condStack.pop();
1709
1735
clearCommentStack(yyscanner);
0 commit comments