Imported Upstream version 1.9.8
[platform/upstream/doxygen.git] / src / commentcnv.l
index 036f830..85cec27 100644 (file)
@@ -1,12 +1,10 @@
 /*****************************************************************************
  *
- * 
- *
- * Copyright (C) 1997-2015 by Dimitri van Heesch.
+ * Copyright (C) 1997-2023 by Dimitri van Heesch.
  *
  * Permission to use, copy, modify, and distribute this software and its
- * documentation under the terms of the GNU General Public License is hereby 
- * granted. No representations are made about the suitability of this software 
+ * documentation under the terms of the GNU General Public License is hereby
+ * granted. No representations are made about the suitability of this software
  * for any purpose. It is provided "as is" without express or implied warranty.
  * See the GNU General Public License for more details.
  *
 %option extra-type="struct commentcnvYY_state *"
 %top{
 #include <stdint.h>
+// forward declare yyscan_t to improve type safety
+#define YY_TYPEDEF_YY_SCANNER_T
+struct yyguts_t;
+typedef yyguts_t *yyscan_t;
 }
 
 %{
 
-  
+
 #include <stdio.h>
 #include <stdlib.h>
-
-#include <qstack.h>
-#include <qregexp.h>
-#include <qtextstream.h>
-#include <qglobal.h>
+#include <stack>
+#include <algorithm>
 
 #include "bufstr.h"
 #include "debug.h"
@@ -39,6 +38,7 @@
 #include "config.h"
 #include "doxygen.h"
 #include "util.h"
+#include "aliases.h"
 #include "condparser.h"
 
 #include <assert.h>
 #define YY_NO_INPUT 1
 #define YY_NO_UNISTD_H 1
 
-#define ADDCHAR(c)    yyextra->outBuf->addChar(c)
-#define ADDARRAY(a,s) yyextra->outBuf->addArray(a,s)
+#define ADDCHAR(c)    yyextra->outBuf.addChar(c)
+#define ADDARRAY(a,s) yyextra->outBuf.addArray(a,s)
 
 #define USE_STATE2STRING 0
-  
-struct CondCtx
+
+struct commentcnvYY_CondCtx
 {
-  CondCtx(int line,QCString id,bool b) 
+  commentcnvYY_CondCtx(int line,const QCString &id,bool b)
     : lineNr(line),sectionId(id), skip(b) {}
   int lineNr;
   QCString sectionId;
   bool skip;
 };
-  
+
 struct CommentCtx
 {
-  CommentCtx(int line) 
+  CommentCtx(int line)
     : lineNr(line) {}
   int lineNr;
 };
-  
+
 struct commentcnvYY_state
 {
-  BufStr * inBuf = 0;
-  BufStr * outBuf = 0;
-  yy_size_t inBufPos = 0;
+  commentcnvYY_state(const BufStr &i,BufStr &o) : inBuf(i), outBuf(o) {}
+  const BufStr &inBuf;
+  BufStr &outBuf;
+  int      inBufPos = 0;
   int      col = 0;
   int      blockHeadCol = 0;
   bool     mlBrief = FALSE;
@@ -80,8 +81,8 @@ struct commentcnvYY_state
   QCString fileName;
   int      lineNr = 0;
   int      condCtx = 0;
-  QStack<CondCtx> condStack;
-  QStack<CommentCtx> commentStack;
+  std::stack<commentcnvYY_CondCtx> condStack;
+  std::stack<int> commentStack;
   QCString blockName;
   int      lastCommentContext = 0;
   bool     inSpecialComment = FALSE;
@@ -111,12 +112,13 @@ static inline int computeIndent(const char *s);
 
 static void replaceCommentMarker(yyscan_t yyscanner,const char *s,int len);
 static inline void copyToOutput(yyscan_t yyscanner,const char *s,int len);
-static void startCondSection(yyscan_t yyscanner,const char *sectId);
+static void startCondSection(yyscan_t yyscanner,const QCString &sectId);
 static void endCondSection(yyscan_t yyscanner);
 static void handleCondSectionId(yyscan_t yyscanner,const char *expression);
-static void replaceAliases(yyscan_t yyscanner,const char *s);
-static yy_size_t yyread(yyscan_t yyscanner,char *buf,yy_size_t max_size);
+static void replaceAliases(yyscan_t yyscanner,const QCString &s);
+static int yyread(yyscan_t yyscanner,char *buf,int max_size);
 static void replaceComment(yyscan_t yyscanner,int offset);
+static void clearCommentStack(yyscan_t yyscanner);
 
 
 
@@ -124,10 +126,13 @@ static void replaceComment(yyscan_t yyscanner,int offset);
 #undef  YY_INPUT
 #define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size);
 
+// otherwise the filename would be the name of the converted file (*.cpp instead of *.l)
+static inline const char *getLexerFILE() {return __FILE__;}
+#include "doxygen_lex.h"
 
 %}
 
-MAILADR   ("mailto:")?[a-z_A-Z0-9.+-]+"@"[a-z_A-Z0-9-]+("."[a-z_A-Z0-9\-]+)+[a-z_A-Z0-9\-]+
+MAILADDR   ("mailto:")?[a-z_A-Z0-9\x80-\xff.+-]+"@"[a-z_A-Z0-9\x80-\xff-]+("."[a-z_A-Z0-9\x80-\xff\-]+)+[a-z_A-Z0-9\x80-\xff\-]+
 
 %option noyywrap
 
@@ -136,6 +141,7 @@ MAILADR   ("mailto:")?[a-z_A-Z0-9.+-]+"@"[a-z_A-Z0-9-]+("."[a-z_A-Z0-9\-]+)+[a-z
 %x SkipChar
 %x SComment
 %x CComment
+%x CNComment
 %x Verbatim
 %x VerbatimCode
 %x ReadLine
@@ -170,16 +176,33 @@ FLOAT_NUMBER {FLOAT_DECIMAL}|{FLOAT_HEXADECIMAL}
 NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
   //- end: NUMBER ---------------------------------------------------------------------------
 
+  // C start comment
+CCS   "/\*"
+  // C end comment
+CCE   "*\/"
+  // Cpp comment
+CPPC  "/\/"
+
+  // Optional any character
+ANYopt .*
+
+  // Optional white space
+WSopt [ \t\r]*
+  // readline non special
+RLopt [^\\@\n\*\/]*
+  // Optional slash
+SLASHopt [/]*
+
 %%
 
 <Scan>{NUMBER}                     { //Note similar code in code.l
                                       if (yyextra->lang!=SrcLangExt_Cpp) REJECT;
-                                      copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                      copyToOutput(yyscanner,yytext,(int)yyleng);
                                     }
 <Scan>[^"'!\/\n\\#,\-=; \t]*        { /* eat anything that is not " / , or \n */
                                        copyToOutput(yyscanner,yytext,(int)yyleng);
                                     }
-<Scan>[,= ;\t]                      { /* eat , so we have a nice separator in long initialization lines */ 
+<Scan>[,= ;\t]                      { /* eat , so we have a nice separator in long initialization lines */
                                        copyToOutput(yyscanner,yytext,(int)yyleng);
                                     }
 <Scan>"\"\"\""!                     { /* start of python long comment */
@@ -191,10 +214,29 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                     {
                                        yyextra->pythonDocString = TRUE;
                                        yyextra->nestingCount=1;
-                                       yyextra->commentStack.clear(); /*  to be on the save side */
+                                       clearCommentStack(yyscanner); /*  to be on the save side */
+                                       copyToOutput(yyscanner,yytext,(int)yyleng);
+                                      BEGIN(CComment);
+                                       yyextra->commentStack.push(yyextra->lineNr);
+                                    }
+                                   }
+<Scan>"\"\"\""                     { /* start of python long comment */
+                                     if (yyextra->lang!=SrcLangExt_Python)
+                                    {
+                                      REJECT;
+                                    }
+                                     else if (Config_getBool(PYTHON_DOCSTRING))
+                                     {
+                                      REJECT;
+                                     }
+                                    else
+                                    { /* handle as if """! */
+                                       yyextra->pythonDocString = TRUE;
+                                       yyextra->nestingCount=1;
+                                       clearCommentStack(yyscanner); /*  to be on the save side */
                                        copyToOutput(yyscanner,yytext,(int)yyleng);
                                       BEGIN(CComment);
-                                       yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
+                                       yyextra->commentStack.push(yyextra->lineNr);
                                     }
                                    }
 <Scan>![><!]/.*\n         {
@@ -204,11 +246,11 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                     }
                                     else
                                     {
-                                       copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                       copyToOutput(yyscanner,yytext,(int)yyleng);
                                        yyextra->nestingCount=0; // Fortran doesn't have an end comment
-                                       yyextra->commentStack.clear(); /*  to be on the save side */
+                                       clearCommentStack(yyscanner); /*  to be on the save side */
                                       BEGIN(CComment);
-                                       yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
+                                       yyextra->commentStack.push(yyextra->lineNr);
                                     }
                                   }
 <Scan>[Cc\*][><!]/.*\n    {
@@ -221,11 +263,11 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                        /* check for fixed format; we might have some conditional as part of multiline if like C<5 .and. & */
                                        if (yyextra->isFixedForm && (yyextra->col == 0))
                                        {
-                                         copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                         copyToOutput(yyscanner,yytext,(int)yyleng);
                                          yyextra->nestingCount=0; // Fortran doesn't have an end comment
-                                         yyextra->commentStack.clear(); /* to be on the safe side */
+                                         clearCommentStack(yyscanner); /*  to be on the save side */
                                         BEGIN(CComment);
-                                         yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
+                                         yyextra->commentStack.push(yyextra->lineNr);
                                       }
                                       else
                                       {
@@ -240,7 +282,7 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                     }
                                     else
                                     {
-                                       copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                       copyToOutput(yyscanner,yytext,(int)yyleng);
                                     }
                                    }
 <Scan>[Cc\*].*\n                  {
@@ -252,7 +294,7 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                     {
                                        if (yyextra->col == 0)
                                        {
-                                         copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                         copyToOutput(yyscanner,yytext,(int)yyleng);
                                       }
                                       else
                                       {
@@ -260,25 +302,25 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                       }
                                     }
                                    }
-<Scan>"\""                         { /* start of a string */ 
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+<Scan>"\""                         { /* start of a string */
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                     yyextra->stringContext = YY_START;
-                                    BEGIN(SkipString); 
+                                    BEGIN(SkipString);
                                    }
 <Scan>'                                   {
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                     yyextra->charContext = YY_START;
                                      if (yyextra->lang!=SrcLangExt_VHDL)
                                      {
                                       BEGIN(SkipChar);
                                      }
                                   }
-<Scan>\n                           { /* new line */ 
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+<Scan>\n                           { /* new line */
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                    }
-<Scan>"//!"/.*\n[ \t]*"//"[\/!][^\/] | /* start C++ style special comment block */
-<Scan>("///"[/]*)/[^/].*\n[ \t]*"//"[\/!][^\/] { /* start C++ style special comment block */
-                                    if (yyextra->mlBrief) 
+<Scan>{CPPC}"!"/.*\n[ \t]*{CPPC}[\/!][^\/] | /* start C++ style special comment block */
+<Scan>({CPPC}"/"[/]*)/[^/].*\n[ \t]*{CPPC}[\/!][^\/] { /* start C++ style special comment block */
+                                    if (yyextra->mlBrief)
                                     {
                                       REJECT; // bail out if we do not need to convert
                                     }
@@ -290,49 +332,59 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                         while (i<(int)yyleng && yytext[i]=='/') i++;
                                       }
                                       yyextra->blockHeadCol=yyextra->col;
-                                      copyToOutput(yyscanner,"/**",3); 
-                                      replaceAliases(yyscanner,yytext+i);
+                                      copyToOutput(yyscanner,"/**",3);
+                                      replaceAliases(yyscanner,QCString(yytext+i));
                                       yyextra->inSpecialComment=TRUE;
-                                      //BEGIN(SComment); 
+                                      //BEGIN(SComment);
                                       yyextra->readLineCtx=SComment;
                                       BEGIN(ReadLine);
                                     }
                                    }
-<Scan>"//##Documentation".*/\n    { /* Start of Rational Rose ANSI C++ comment block */
+<Scan>{CPPC}"##Documentation"{ANYopt}/\n          { /* Start of Rational Rose ANSI C++ comment block */
                                      if (yyextra->mlBrief) REJECT;
                                      int i=17; //=strlen("//##Documentation");
                                     yyextra->blockHeadCol=yyextra->col;
                                     copyToOutput(yyscanner,"/**",3);
-                                    replaceAliases(yyscanner,yytext+i);
+                                    replaceAliases(yyscanner,QCString(yytext+i));
                                     yyextra->inRoseComment=TRUE;
                                     BEGIN(SComment);
                                   }
-<Scan>"//"[!\/]/.*\n[ \t]*"//"[|\/][ \t]*[@\\]"}" { // next line contains an end marker, see bug 752712
+<Scan>{CPPC}[!\/]/.*\n[ \t]*{CPPC}[|\/][ \t]*[@\\]"}" { // next line contains an end marker, see bug 752712
                                     yyextra->inSpecialComment=yytext[2]=='/' || yytext[2]=='!';
-                                    copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                    copyToOutput(yyscanner,yytext,(int)yyleng);
                                     yyextra->readLineCtx=YY_START;
                                     BEGIN(ReadLine);
                                    }
-<Scan>"//"/.*\n                           { /* one line C++ comment */ 
+<Scan>{CPPC}/.*\n                         { /* one line C++ comment */
                                     yyextra->inSpecialComment=yytext[2]=='/' || yytext[2]=='!';
-                                    copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                    copyToOutput(yyscanner,yytext,(int)yyleng);
                                     yyextra->readLineCtx=YY_START;
                                     BEGIN(ReadLine);
                                   }
-<Scan>"/**/"                       { /* avoid matching next rule for empty C comment, see bug 711723 */
+<Scan>{CCS}{CCE}                       { /* avoid matching next rule for empty C comment, see bug 711723 */
                                      copyToOutput(yyscanner,yytext,(int)yyleng);
                                    }
-<Scan>"/*"[*!]?                           { /* start of a C comment */
+<Scan>{CCS}[*!]?                          { /* start of a C comment */
                                      if (yyextra->lang==SrcLangExt_Python)
                                     {
                                       REJECT;
                                      }
                                     yyextra->specialComment=(int)yyleng==3;
                                      yyextra->nestingCount=1;
-                                     yyextra->commentStack.clear(); /*  to be on the save side */
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
-                                    BEGIN(CComment); 
-                                     yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
+                                     clearCommentStack(yyscanner); /*  to be on the save side */
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
+                                     if (yyextra->specialComment)
+                                      BEGIN(CComment);
+                                     else
+                                      BEGIN(CNComment);
+                                     yyextra->commentStack.push(yyextra->lineNr);
+                                   }
+<Scan>"#"[^\n]*\n                  {
+                                     if (yyextra->lang!=SrcLangExt_PHP)
+                                    {
+                                      REJECT;
+                                    }
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                    }
 <Scan>"#"("#")?                           {
                                      if (yyextra->lang!=SrcLangExt_Python)
@@ -341,11 +393,21 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                     }
                                     else
                                     {
-                                       copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                       copyToOutput(yyscanner,yytext,(int)yyleng);
                                        yyextra->nestingCount=0; // Python doesn't have an end comment for #
-                                       yyextra->commentStack.clear(); /*  to be on the save side */
+                                       clearCommentStack(yyscanner); /*  to be on the save side */
                                       BEGIN(CComment);
-                                       yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
+                                       yyextra->commentStack.push(yyextra->lineNr);
+                                    }
+                                  }
+<Scan>"--"[^!][^\n]*              {
+                                     if (yyextra->lang!=SrcLangExt_VHDL)
+                                    {
+                                      REJECT;
+                                    }
+                                    else
+                                    {
+                                       copyToOutput(yyscanner,yytext,(int)yyleng);
                                     }
                                   }
 <Scan>"--!"                       {
@@ -356,11 +418,11 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                     else
                                     {
                                        yyextra->vhdl = TRUE;
-                                       copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                       copyToOutput(yyscanner,yytext,(int)yyleng);
                                        yyextra->nestingCount=0;  // VHDL doesn't have an end comment
-                                       yyextra->commentStack.clear(); /*  to be on the save side */
+                                       clearCommentStack(yyscanner); /*  to be on the save side */
                                       BEGIN(CComment);
-                                       yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
+                                       yyextra->commentStack.push(yyextra->lineNr);
                                     }
                                   }
 <Scan>![><!]                      {
@@ -370,19 +432,26 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                     }
                                     else
                                     {
-                                       copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                       copyToOutput(yyscanner,yytext,(int)yyleng);
                                        yyextra->nestingCount=0;  // Fortran doesn't have an end comment
-                                       yyextra->commentStack.clear(); /*  to be on the save side */
+                                       clearCommentStack(yyscanner); /*  to be on the save side */
                                       BEGIN(CComment);
-                                       yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
+                                       yyextra->commentStack.push(yyextra->lineNr);
                                     }
                                   }
-<CComment,ReadLine>{MAILADR}      |
-<CComment,ReadLine>"<"{MAILADR}">" { // Mail address, to prevent seeing e.g x@code-factory.org as start of a code block
+<CComment,CNComment,ReadLine>{MAILADDR}       |
+<CComment,CNComment,ReadLine>"<"{MAILADDR}">" { // Mail address, to prevent seeing e.g x@code-factory.org as start of a code block
                                      copyToOutput(yyscanner,yytext,(int)yyleng);
                                    }
-<CComment>"{@code"/[ \t\n]        {
-                                     copyToOutput(yyscanner,"@code",5); 
+<CComment>"{"[ \t]*"@code"/[ \t\n] {
+                                     copyToOutput(yyscanner,"@iliteral{code}",15);
+                                    yyextra->lastCommentContext = YY_START;
+                                    yyextra->javaBlock=1;
+                                    yyextra->blockName=&yytext[1];
+                                     BEGIN(VerbatimCode);
+                                  }
+<CComment>"{"[ \t]*"@literal"/[ \t\n] {
+                                     copyToOutput(yyscanner,"@iliteral",9);
                                     yyextra->lastCommentContext = YY_START;
                                     yyextra->javaBlock=1;
                                     yyextra->blockName=&yytext[1];
@@ -396,11 +465,11 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                      copyToOutput(yyscanner,yytext,(int)yyleng);
                                      yyextra->lastCommentContext = YY_START;
                                      yyextra->javaBlock=0;
-                                     yyextra->blockName=QCString(yytext).stripWhiteSpace().left(3);
+                                     yyextra->blockName=QCString(yytext).stripWhiteSpace().left(3); // take the ``` or ~~~ part
                                      BEGIN(VerbatimCode);
                                    }
 <CComment,ReadLine>[\\@]("dot"|"code"|"msc"|"startuml")/[^a-z_A-Z0-9] { /* start of a verbatim block */
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                     yyextra->lastCommentContext = YY_START;
                                     yyextra->javaBlock=0;
                                      if (qstrcmp(&yytext[1],"startuml")==0)
@@ -413,8 +482,8 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                      }
                                      BEGIN(VerbatimCode);
                                   }
-<CComment,ReadLine>[\\@]("f$"|"f["|"f{") {
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+<CComment,ReadLine>[\\@]("f$"|"f["|"f{"|"f(") {
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                     yyextra->blockName=&yytext[1];
                                     if (yyextra->blockName.at(1)=='[')
                                     {
@@ -424,19 +493,29 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                     {
                                       yyextra->blockName.at(1)='}';
                                     }
+                                    else if (yyextra->blockName.at(1)=='(')
+                                    {
+                                      yyextra->blockName.at(1)=')';
+                                    }
                                     yyextra->lastCommentContext = YY_START;
                                     BEGIN(Verbatim);
                                   }
-<CComment,ReadLine>[\\@]("verbatim"|"latexonly"|"htmlonly"|"xmlonly"|"docbookonly"|"rtfonly"|"manonly")/[^a-z_A-Z0-9] { /* start of a verbatim block */
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+<CComment,ReadLine>[\\@]("verbatim"|"iliteral"|"latexonly"|"htmlonly"|"xmlonly"|"docbookonly"|"rtfonly"|"manonly")/[^a-z_A-Z0-9] { /* start of a verbatim block */
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                     yyextra->blockName=&yytext[1];
                                     yyextra->lastCommentContext = YY_START;
                                      BEGIN(Verbatim);
                                    }
+<Scan>"\\\""                       { /* escaped double quote */
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
+                                   }
+<Scan>"\\\\"                       { /* escaped backslash */
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
+                                   }
 <Scan>.                            { /* any other character */
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                    }
-<Verbatim>[\\@]("endverbatim"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"f$"|"f]"|"f}") { /* end of verbatim block */
+<Verbatim>[\\@]("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"f$"|"f]"|"f}"|"f)") { /* end of verbatim block */
                                      copyToOutput(yyscanner,yytext,(int)yyleng);
                                     if (&yytext[1]==yyextra->blockName) // end of formula
                                     {
@@ -468,7 +547,7 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                       yyextra->javaBlock--;
                                       if (yyextra->javaBlock==0)
                                       {
-                                         copyToOutput(yyscanner," @endcode ",10);
+                                         copyToOutput(yyscanner," @endiliteral ",14);
                                         BEGIN(yyextra->lastCommentContext);
                                       }
                                       else
@@ -491,10 +570,10 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                       BEGIN(yyextra->lastCommentContext);
                                     }
                                    }
-<VerbatimCode>^[ \t]*"//"[\!\/]?   { /* skip leading comments */
+<VerbatimCode>^[ \t]*{CPPC}[\!\/]?   { /* skip leading comments */
                                     if (!yyextra->inSpecialComment)
                                     {
-                                       copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                       copyToOutput(yyscanner,yytext,(int)yyleng);
                                     }
                                      else
                                      {
@@ -515,12 +594,12 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                      }
                                   }
 <Verbatim,VerbatimCode>[^`~@\/\\\n{}]* { /* any character not a backslash or new line or } */
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                    }
 <Verbatim,VerbatimCode>\n         { /* new line in verbatim block */
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                    }
-<Verbatim>^[ \t]*"//"[/!]          {
+<Verbatim>^[ \t]*{CPPC}[/!]          {
                                     if (yyextra->blockName=="dot" || yyextra->blockName=="msc" || yyextra->blockName=="uml" || yyextra->blockName.at(0)=='f')
                                     {
                                       // see bug 487871, strip /// from dot images and formulas.
@@ -538,10 +617,10 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                     }
                                   }
 <Verbatim,VerbatimCode>.          { /* any other character */
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                    }
 <SkipString>\\.                    { /* escaped character in string */
-                                     if (yyextra->lang==SrcLangExt_Fortran)
+                                     if (yyextra->lang==SrcLangExt_Fortran || yyextra->lang==SrcLangExt_VHDL)
                                      {
                                        unput(yytext[1]);
                                        copyToOutput(yyscanner,yytext,1);
@@ -551,18 +630,18 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                        copyToOutput(yyscanner,yytext,(int)yyleng);
                                      }
                                    }
-<SkipString>"\""                          { /* end of string */ 
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
-                                    BEGIN(yyextra->stringContext); 
+<SkipString>"\""                          { /* end of string */
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
+                                    BEGIN(yyextra->stringContext);
                                    }
-<SkipString>.                      { /* any other string character */ 
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+<SkipString>.                      { /* any other string character */
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                    }
-<SkipString>\n                     { /* new line inside string (illegal for some compilers) */ 
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+<SkipString>\n                     { /* new line inside string (illegal for some compilers) */
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                    }
 <SkipChar>\\.                     { /* escaped character */
-                                     if (yyextra->lang==SrcLangExt_Fortran)
+                                     if (yyextra->lang==SrcLangExt_Fortran || yyextra->lang==SrcLangExt_VHDL)
                                      {
                                        unput(yytext[1]);
                                        copyToOutput(yyscanner,yytext,1);
@@ -572,22 +651,22 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                        copyToOutput(yyscanner,yytext,(int)yyleng);
                                      }
                                    }
-<SkipChar>'                        { /* end of character literal */ 
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+<SkipChar>'                        { /* end of character literal */
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                      BEGIN(yyextra->charContext);
                                    }
-<SkipChar>.                        { /* any other string character */ 
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+<SkipChar>.                        { /* any other string character */
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                    }
 <SkipChar>\n                       { /* new line character */
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                    }
 
-<CComment>[^ `~<\\!@*\n{\"\/]*     { /* anything that is not a '*' or command */ 
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+<CComment,CNComment>[^ `~<\\!@*\n{\"\/]*     { /* anything that is not a '*' or command */
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                    }
-<CComment>"*"+[^*/\\@\n{\"]*       { /* stars without slashes */
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+<CComment,CNComment>"*"+[^*\/\\@\n{\"]*      { /* stars without slashes */
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                    }
 <CComment>"\"\"\""                 { /* end of Python docstring */
                                      if (yyextra->lang!=SrcLangExt_Python)
@@ -602,7 +681,7 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                       BEGIN(Scan);
                                     }
                                   }
-<CComment>\n                       { /* new line in comment */
+<CComment,CNComment>\n                       { /* new line in comment */
                                      copyToOutput(yyscanner,yytext,(int)yyleng);
                                      /* in case of Fortran always end of comment */
                                     if (yyextra->lang==SrcLangExt_Fortran)
@@ -610,17 +689,21 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                       BEGIN(Scan);
                                     }
                                    }
-<CComment>"/"+"*"                  { /* nested C comment */
+<CComment,CNComment>"/""/"+/"*/"   { /* we are already in C-comment so not a start of a nested comment but
+                                      * just the end of the comment (the end part is handled later). */
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
+                                   }
+<CComment,CNComment>"/"+"*"                  { /* nested C comment */
                                      if (yyextra->lang==SrcLangExt_Python ||
                                          yyextra->lang==SrcLangExt_Markdown)
                                     {
                                       REJECT;
                                      }
                                      yyextra->nestingCount++;
-                                     yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
+                                     yyextra->commentStack.push(yyextra->lineNr);
                                      copyToOutput(yyscanner,yytext,(int)yyleng);
                                    }
-<CComment>"*"+"/"                  { /* end of C comment */
+<CComment,CNComment>"*"+"/"                  { /* end of C comment */
                                      if (yyextra->lang==SrcLangExt_Python ||
                                          yyextra->lang==SrcLangExt_Markdown)
                                     {
@@ -637,12 +720,12 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                        else
                                        {
                                          //yyextra->nestingCount--;
-                                         delete yyextra->commentStack.pop();
+                                         yyextra->commentStack.pop();
                                        }
                                     }
                                    }
-  /* Python an VHDL share CComment, so special attention for ending comments is required */
-<CComment>"\n"/[ \t]*"#"          {
+  /* Python an VHDL share CComment,CNComment, so special attention for ending comments is required */
+<CComment,CNComment>"\n"/[ \t]*"#"        {
                                      if (yyextra->lang!=SrcLangExt_VHDL)
                                      {
                                        REJECT;
@@ -661,7 +744,7 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                        }
                                      }
                                    }
-<CComment>"\n"/[ \t]*"-"          {
+<CComment,CNComment>"\n"/[ \t]*"-"        {
                                      if (yyextra->lang!=SrcLangExt_Python || yyextra->pythonDocString)
                                     {
                                       REJECT;
@@ -672,7 +755,7 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                       BEGIN(Scan);
                                     }
                                    }
-<CComment>"\n"/[ \t]*[^ \t#\-]            {
+<CComment,CNComment>"\n"/[ \t]*[^ \t#\-]          {
                                      if (yyextra->lang==SrcLangExt_Python)
                                      {
                                        if (yyextra->pythonDocString)
@@ -704,59 +787,59 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                      }
                                    }
    /* removed for bug 674842 (bug was introduced in rev 768)
-<CComment>"'"                     {
+<CComment,CNComment>"'"                           {
                                     yyextra->charContext = YY_START;
                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                     BEGIN(SkipChar);
                                   }
-<CComment>"\""                    {
+<CComment,CNComment>"\""                          {
                                     yyextra->stringContext = YY_START;
                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                     BEGIN(SkipString);
                                   }
    */
-<CComment>.                       {
-                                     copyToOutput(yyscanner,yytext,(int)yyleng); 
+<CComment,CNComment>.                     {
+                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                   }
-<SComment>^[ \t]*"///"[\/]*/\n     {
+<SComment>^[ \t]*{CPPC}"/"{SLASHopt}/\n     {
                                     replaceComment(yyscanner,0);
                                   }
-<SComment>\n[ \t]*"///"[\/]*/\n    {
-                                     replaceComment(yyscanner,1); 
+<SComment>\n[ \t]*{CPPC}"/"{SLASHopt}/\n    {
+                                     replaceComment(yyscanner,1);
                                    }
-<SComment>^[ \t]*"///"[^\/\n]/.*\n { 
+<SComment>^[ \t]*{CPPC}"/"[^\/\n]/.*\n {
                                     replaceComment(yyscanner,0);
                                     yyextra->readLineCtx=YY_START;
                                     BEGIN(ReadLine);
                                   }
-<SComment>\n[ \t]*"//"[\/!]("<")?[ \t]*[\\@]"}".*\n {   
+<SComment>\n[ \t]*{CPPC}[\/!]("<")?[ \t]*[\\@]"}".*\n {
                                      /* See Bug 752712: end the multiline comment when finding a @} or \} command */
-                                     copyToOutput(yyscanner," */",3); 
-                                    copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                     copyToOutput(yyscanner," */",3);
+                                    copyToOutput(yyscanner,yytext,(int)yyleng);
                                     yyextra->inSpecialComment=FALSE;
                                     yyextra->inRoseComment=FALSE;
-                                    BEGIN(Scan); 
+                                    BEGIN(Scan);
                                    }
-<SComment>\n[ \t]*"///"[^\/\n]/.*\n  { 
-                                     replaceComment(yyscanner,1); 
+<SComment>\n[ \t]*{CPPC}"/"[^\/\n]/.*\n  {
+                                     replaceComment(yyscanner,1);
                                     yyextra->readLineCtx=YY_START;
                                     BEGIN(ReadLine);
                                   }
-<SComment>^[ \t]*"//!"             |    // just //!
-<SComment>^[ \t]*"//!<"/.*\n       |    // or   //!< something
-<SComment>^[ \t]*"//!"[^<]/.*\n    {    // or   //!something
+<SComment>^[ \t]*{CPPC}"!"             |    // just //!
+<SComment>^[ \t]*{CPPC}"!<"/.*\n       |    // or   //!< something
+<SComment>^[ \t]*{CPPC}"!"[^<]/.*\n    {    // or   //!something
                                     replaceComment(yyscanner,0);
                                     yyextra->readLineCtx=YY_START;
                                     BEGIN(ReadLine);
                                    }
-<SComment>\n[ \t]*"//!"            |
-<SComment>\n[ \t]*"//!<"/.*\n      |
-<SComment>\n[ \t]*"//!"[^<\n]/.*\n { 
-                                     replaceComment(yyscanner,1); 
+<SComment>\n[ \t]*{CPPC}"!"            |
+<SComment>\n[ \t]*{CPPC}"!<"/.*\n      |
+<SComment>\n[ \t]*{CPPC}"!"[^<\n]/.*\n {
+                                     replaceComment(yyscanner,1);
                                     yyextra->readLineCtx=YY_START;
                                     BEGIN(ReadLine);
                                    }
-<SComment>^[ \t]*"//##"/.*\n       {
+<SComment>^[ \t]*{CPPC}"##"/.*\n       {
                                      if (!yyextra->inRoseComment)
                                     {
                                       REJECT;
@@ -768,52 +851,54 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
                                       BEGIN(ReadLine);
                                     }
                                    }
-<SComment>\n[ \t]*"//##"/.*\n      {
+<SComment>\n[ \t]*{CPPC}"##"/.*\n      {
                                      if (!yyextra->inRoseComment)
                                     {
                                       REJECT;
                                     }
                                     else
                                     {
-                                       replaceComment(yyscanner,1); 
+                                       replaceComment(yyscanner,1);
                                       yyextra->readLineCtx=YY_START;
                                       BEGIN(ReadLine);
                                     }
                                    }
 <SComment>\n                      { /* end of special comment */
-                                     copyToOutput(yyscanner," */",3); 
-                                    copyToOutput(yyscanner,yytext,(int)yyleng); 
+                                     copyToOutput(yyscanner," */",3);
+                                    copyToOutput(yyscanner,yytext,(int)yyleng);
                                     yyextra->inSpecialComment=FALSE;
                                     yyextra->inRoseComment=FALSE;
-                                    BEGIN(Scan); 
+                                     yyextra->readLineCtx = Scan; // reset, otherwise there will be problems with:
+                                                                  //   static void handleCondSectionId
+                                    BEGIN(Scan);
                                    }
-<ReadLine>"/**"                    {
+<ReadLine>{CCS}"*"                    {
                                     copyToOutput(yyscanner,"/&zwj;**",8);
                                   }
-<ReadLine>"*/"                     {
+<ReadLine>{CCE}                     {
                                     copyToOutput(yyscanner,"*&zwj;/",7);
                                   }
 <ReadLine>"*"                      {
                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                   }
-<ReadLine>[^\\@\n\*/]*             {
+<ReadLine>{RLopt}                  {
                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                   }
-<ReadLine>[^\\@\n\*/]*/\n          {
+<ReadLine>{RLopt}/\n               {
                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                     BEGIN(yyextra->readLineCtx);
                                   }
-<CComment,ReadLine>[\\@][\\@][~a-z_A-Z][a-z_A-Z0-9]*[ \t]* { // escaped command
+<CComment,CNComment,ReadLine>[\\@][\\@][~a-z_A-Z][a-z_A-Z0-9]*[ \t]* { // escaped command
                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                   }
 <CComment,ReadLine>[\\@]"cond"/[^a-z_A-Z0-9]      { // conditional section
-                                    yyextra->condCtx = YY_START; 
+                                    yyextra->condCtx = YY_START;
                                     BEGIN(CondLine);
                                   }
 <CComment,ReadLine>[\\@]"endcond"/[^a-z_A-Z0-9] { // end of conditional section
                                     bool oldSkip=yyextra->skip;
                                     endCondSection(yyscanner);
-                                    if (YY_START==CComment && oldSkip && !yyextra->skip) 
+                                    if (YY_START==CComment && oldSkip && !yyextra->skip)
                                     {
                                       //printf("** Adding start of comment!\n");
                                       if (yyextra->lang!=SrcLangExt_Python &&
@@ -833,34 +918,35 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
 <CondLine>[!()&| \ta-z_A-Z0-9.\-]+ {
                                      handleCondSectionId(yyscanner,yytext);
                                   }
-<CComment,ReadLine>[\\@]"cond"[ \t\r]*/\n {
+<CComment,ReadLine>[\\@]"cond"{WSopt}/\n {
                                     yyextra->condCtx=YY_START;
                                      handleCondSectionId(yyscanner," "); // fake section id causing the section to be hidden unconditionally
                                    }
+<CondLine>\n                      |
 <CondLine>.                       { // forgot section id?
                                      handleCondSectionId(yyscanner," "); // fake section id causing the section to be hidden unconditionally
-                                    if (*yytext=='\n') yyextra->lineNr++;
+                                    if (*yytext=='\n') { yyextra->lineNr++; copyToOutput(yyscanner,"\n",1);}
                                   }
-<CComment,ReadLine>[\\@][a-z_A-Z][a-z_A-Z0-9]*  { // expand alias without arguments
-                                    replaceAliases(yyscanner,yytext);
+<CComment,ReadLine>[\\@][a-z_A-Z][a-z_A-Z0-9-]*  { // expand alias without arguments
+                                    replaceAliases(yyscanner,QCString(yytext));
                                   }
-<CComment,ReadLine>[\\@][a-z_A-Z][a-z_A-Z0-9]*"{" { // expand alias with arguments
+<CComment,ReadLine>[\\@][a-z_A-Z][a-z_A-Z0-9-]*"{" { // expand alias with arguments
                                      yyextra->lastBlockContext=YY_START;
                                     yyextra->blockCount=1;
                                     yyextra->aliasString=yytext;
                                     yyextra->lastEscaped=0;
                                     BEGIN( ReadAliasArgs );
                                   }
-<ReadAliasArgs>^[ \t]*"//"[/!]/[^\n]+   { // skip leading special comments (see bug 618079)
+<ReadAliasArgs>^[ \t]*{CPPC}[/!]/[^\n]+   { // skip leading special comments (see bug 618079)
                                   }
-<ReadAliasArgs>"*/"               { // oops, end of comment in the middle of an alias?
+<ReadAliasArgs>{CCE}              { // oops, end of comment in the middle of an alias?
                                      if (yyextra->lang==SrcLangExt_Python)
                                     {
                                       REJECT;
                                     }
                                     else // abort the alias, restart scanning
                                     {
-                                      copyToOutput(yyscanner,yyextra->aliasString,yyextra->aliasString.length());
+                                      copyToOutput(yyscanner,yyextra->aliasString.data(),yyextra->aliasString.length());
                                       copyToOutput(yyscanner,yytext,(int)yyleng);
                                       BEGIN(Scan);
                                     }
@@ -905,6 +991,9 @@ NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
 <*>.                               {
                                     copyToOutput(yyscanner,yytext,(int)yyleng);
                                    }
+  /*
+<*>\n  { fprintf(stderr,"Lex scanner %s (%s) default rule newline for state %s.\n", __FILE__, qPrint(yyextra->fileName),stateToString(YY_START));}
+  */
 %%
 
 static void replaceCommentMarker(yyscan_t yyscanner,const char *s,int len)
@@ -913,7 +1002,7 @@ static void replaceCommentMarker(yyscan_t yyscanner,const char *s,int len)
   const char *p=s;
   char c;
   // copy leading blanks
-  while ((c=*p) && (c==' ' || c=='\t' || c=='\n')) 
+  while ((c=*p) && (c==' ' || c=='\t' || c=='\n'))
   {
     ADDCHAR(c);
     yyextra->lineNr += c=='\n';
@@ -921,14 +1010,14 @@ static void replaceCommentMarker(yyscan_t yyscanner,const char *s,int len)
   }
   // replace start of comment marker by blanks and the last character by a *
   int blanks=0;
-  while ((c=*p) && (c=='/' || c=='!' || c=='#')) 
+  while ((c=*p) && (c=='/' || c=='!' || c=='#'))
   {
     blanks++;
     p++;
-    if (*p=='<') // comment-after-item marker 
-    { 
+    if (*p=='<') // comment-after-item marker
+    {
       blanks++;
-      p++; 
+      p++;
     }
     if (c=='!') // end after first !
     {
@@ -952,13 +1041,13 @@ static void replaceCommentMarker(yyscan_t yyscanner,const char *s,int len)
 static inline int computeIndent(const char *s)
 {
   int col=0;
-  static int tabSize=Config_getInt(TAB_SIZE);
+  int tabSize=Config_getInt(TAB_SIZE);
   const char *p=s;
   char c;
   while ((c=*p++))
   {
     if (c==' ') col++;
-    else if (c=='\t') col+=tabSize-(col%tabSize); 
+    else if (c=='\t') col+=tabSize-(col%tabSize);
     else break;
   }
   return col;
@@ -992,11 +1081,11 @@ static inline void copyToOutput(yyscan_t yyscanner,const char *s,int len)
   else if (len>0)
   {
     ADDARRAY(s,len);
-    for (i=0;i<len;i++) 
+    for (i=0;i<len;i++)
     {
       switch (s[i])
       {
-       case '\n': yyextra->col=0; 
+       case '\n': yyextra->col=0;
                   //fprintf(stderr,"---> copy %d\n",g_lineNr);
                   yyextra->lineNr++; break;
        case '\t': yyextra->col+=tabSize-(yyextra->col%tabSize); break;
@@ -1006,13 +1095,19 @@ static inline void copyToOutput(yyscan_t yyscanner,const char *s,int len)
   }
 }
 
-static void startCondSection(yyscan_t yyscanner,const char *sectId)
+static void clearCommentStack(yyscan_t yyscanner)
+{
+  struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
+  while (!yyextra->commentStack.empty()) yyextra->commentStack.pop();
+}
+
+static void startCondSection(yyscan_t yyscanner,const QCString &sectId)
 {
   struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
   //printf("startCondSection: skip=%d stack=%d\n",g_skip,g_condStack.count());
   CondParser prs;
   bool expResult = prs.parse(yyextra->fileName,yyextra->lineNr,sectId);
-  yyextra->condStack.push(new CondCtx(yyextra->lineNr,sectId,yyextra->skip));
+  yyextra->condStack.push(commentcnvYY_CondCtx(yyextra->lineNr,sectId,yyextra->skip));
   if (!expResult) // not enabled
   {
     yyextra->skip=TRUE;
@@ -1022,15 +1117,16 @@ static void startCondSection(yyscan_t yyscanner,const char *sectId)
 static void endCondSection(yyscan_t yyscanner)
 {
   struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
-  if (yyextra->condStack.isEmpty())
+  if (yyextra->condStack.empty())
   {
     warn(yyextra->fileName,yyextra->lineNr,"Found \\endcond command without matching \\cond");
     yyextra->skip=FALSE;
   }
   else
   {
-    CondCtx *ctx = yyextra->condStack.pop();
-    yyextra->skip=ctx->skip;
+    const commentcnvYY_CondCtx &ctx = yyextra->condStack.top();
+    yyextra->skip=ctx.skip;
+    yyextra->condStack.pop();
   }
   //printf("endCondSection: skip=%d stack=%d\n",g_skip,g_condStack.count());
 }
@@ -1039,9 +1135,9 @@ static void handleCondSectionId(yyscan_t yyscanner,const char *expression)
 {
   struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
   bool oldSkip=yyextra->skip;
-  startCondSection(yyscanner,expression);
-  if ((yyextra->condCtx==CComment || yyextra->readLineCtx==SComment) && 
-      !oldSkip && yyextra->skip) 
+  startCondSection(yyscanner,QCString(expression));
+  if ((yyextra->condCtx==CComment || yyextra->readLineCtx==SComment) &&
+      !oldSkip && yyextra->skip)
   {
     if (yyextra->lang!=SrcLangExt_Python &&
         yyextra->lang!=SrcLangExt_VHDL &&
@@ -1062,23 +1158,23 @@ static void handleCondSectionId(yyscan_t yyscanner,const char *expression)
   }
 }
 
-/** copies string \a s with length \a len to the output, while 
+/** copies string \a s with length \a len to the output, while
  *  replacing any alias commands found in the string.
  */
-static void replaceAliases(yyscan_t yyscanner,const char *s)
+static void replaceAliases(yyscan_t yyscanner,const QCString &s)
 {
   QCString result = resolveAliasCmd(s);
-  //printf("replaceAliases(%s)->'%s'\n",s,result.data());
-  copyToOutput(yyscanner,result,result.length());
+  //printf("replaceAliases(%s)->'%s'\n",qPrint(s),qPrint(result));
+  copyToOutput(yyscanner,result.data(),result.length());
 }
 
 
-static yy_size_t yyread(yyscan_t yyscanner,char *buf,yy_size_t max_size)
+static int yyread(yyscan_t yyscanner,char *buf,int max_size)
 {
   struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
-  yy_size_t bytesInBuf = yyextra->inBuf->curPos()-yyextra->inBufPos;
-  yy_size_t bytesToCopy = QMIN(max_size,bytesInBuf);
-  memcpy(buf,yyextra->inBuf->data()+yyextra->inBufPos,bytesToCopy);
+  int bytesInBuf = static_cast<int>(yyextra->inBuf.curPos())-yyextra->inBufPos;
+  int bytesToCopy = std::min(max_size,bytesInBuf);
+  memcpy(buf,yyextra->inBuf.data()+yyextra->inBufPos,bytesToCopy);
   yyextra->inBufPos+=bytesToCopy;
   return bytesToCopy;
 }
@@ -1114,18 +1210,16 @@ static void replaceComment(yyscan_t yyscanner,int offset)
  *  -# It replaces aliases with their definition (see ALIASES)
  *  -# It handles conditional sections (cond...endcond blocks)
  */
-void convertCppComments(BufStr *inBuf,BufStr *outBuf,const char *fileName)
+void convertCppComments(const BufStr &inBuf,BufStr &outBuf,const QCString &fileName)
 {
   yyscan_t yyscanner;
-  commentcnvYY_state extra;
+  commentcnvYY_state extra(inBuf,outBuf);
   commentcnvYYlex_init_extra(&extra,&yyscanner);
 #ifdef FLEX_DEBUG
-  commentcnvYYset_debug(1,yyscanner);
+  commentcnvYYset_debug(Debug::isFlagSet(Debug::Lex_commentcnv)?1:0,yyscanner);
 #endif
   struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
   //printf("convertCppComments(%s)\n",fileName);
-  yyextra->inBuf    = inBuf;
-  yyextra->outBuf   = outBuf;
   yyextra->inBufPos = 0;
   yyextra->col      = 0;
   yyextra->mlBrief = Config_getBool(MULTILINE_CPP_IS_BRIEF);
@@ -1134,65 +1228,62 @@ void convertCppComments(BufStr *inBuf,BufStr *outBuf,const char *fileName)
   yyextra->lang = getLanguageFromFileName(fileName);
   yyextra->pythonDocString = FALSE;
   yyextra->lineNr   = 1;
-  yyextra->condStack.clear();
-  yyextra->condStack.setAutoDelete(TRUE);
-  yyextra->commentStack.clear();
-  yyextra->commentStack.setAutoDelete(TRUE);
+  while (!yyextra->condStack.empty()) yyextra->condStack.pop();
+  clearCommentStack(yyscanner);
   yyextra->vhdl = FALSE;
 
-  printlex(yy_flex_debug, TRUE, __FILE__, fileName);
+  DebugLex debugLex(Debug::Lex_commentcnv,__FILE__, qPrint(fileName));
   yyextra->isFixedForm = FALSE;
   if (yyextra->lang==SrcLangExt_Fortran)
   {
     FortranFormat fmt = convertFileNameFortranParserCode(fileName);
-    yyextra->isFixedForm = recognizeFixedForm(inBuf->data(),fmt);
+    yyextra->isFixedForm = recognizeFixedForm(QCString(inBuf.data()),fmt);
   }
 
   if (yyextra->lang==SrcLangExt_Markdown)
   {
     yyextra->nestingCount=0;
     BEGIN(CComment);
-    yyextra->commentStack.push(new CommentCtx(yyextra->lineNr));
+    yyextra->commentStack.push(yyextra->lineNr);
   }
   else
   {
     BEGIN(Scan);
   }
   yylex(yyscanner);
-  while (!yyextra->condStack.isEmpty())
+  while (!yyextra->condStack.empty())
   {
-    CondCtx *ctx = yyextra->condStack.pop();
-    QCString sectionInfo = " ";
-    if (ctx->sectionId!=" ") sectionInfo.sprintf(" with label '%s' ",ctx->sectionId.stripWhiteSpace().data());
-    warn(yyextra->fileName,ctx->lineNr,"Conditional section%sdoes not have "
+    const commentcnvYY_CondCtx &ctx = yyextra->condStack.top();
+    QCString sectionInfo(" ");
+    if (ctx.sectionId!=" ") sectionInfo.sprintf(" with label '%s' ",ctx.sectionId.stripWhiteSpace().data());
+    warn(yyextra->fileName,ctx.lineNr,"Conditional section%sdoes not have "
        "a corresponding \\endcond command within this file.",sectionInfo.data());
+    yyextra->condStack.pop();
   }
   if (yyextra->nestingCount>0 && yyextra->lang!=SrcLangExt_Markdown && yyextra->lang!=SrcLangExt_Fortran)
   {
-    QCString tmp= "(probable line reference: ";
+    QCString tmp("(probable line reference: ");
     bool first = TRUE;
-    while (!yyextra->commentStack.isEmpty())
+    while (!yyextra->commentStack.empty())
     {
-      CommentCtx *ctx = yyextra->commentStack.pop();
+      int lineNr = yyextra->commentStack.top();
       if (!first) tmp += ", ";
-      tmp += QCString().setNum(ctx->lineNr);
+      tmp += QCString().setNum(lineNr);
       first = FALSE;
-      delete ctx;
+      yyextra->commentStack.pop();
     }
     tmp += ")";
     warn(yyextra->fileName,yyextra->lineNr,"Reached end of file while still inside a (nested) comment. "
         "Nesting level %d %s",yyextra->nestingCount,tmp.data());
   }
-  yyextra->commentStack.clear();
   yyextra->nestingCount = 0;
   if (Debug::isFlagSet(Debug::CommentCnv))
   {
-    yyextra->outBuf->at(yyextra->outBuf->curPos())='\0';
+    yyextra->outBuf.at(yyextra->outBuf.curPos())='\0';
     Debug::print(Debug::CommentCnv,0,"-----------\nCommentCnv: %s\n"
-                 "output=[\n%s]\n-----------\n",fileName,yyextra->outBuf->data()
+                 "output=[\n%s]\n-----------\n",qPrint(fileName),yyextra->outBuf.data()
                 );
   }
-  printlex(yy_flex_debug, FALSE, __FILE__, fileName);
   commentcnvYYlex_destroy(yyscanner);
 }