summaryrefslogtreecommitdiff
path: root/src/commentcnv.l
diff options
context:
space:
mode:
Diffstat (limited to 'src/commentcnv.l')
-rw-r--r--src/commentcnv.l50
1 files changed, 47 insertions, 3 deletions
diff --git a/src/commentcnv.l b/src/commentcnv.l
index d59ef51..4cc9da9 100644
--- a/src/commentcnv.l
+++ b/src/commentcnv.l
@@ -2,7 +2,7 @@
*
*
*
- * Copyright (C) 1997-2013 by Dimitri van Heesch.
+ * Copyright (C) 1997-2014 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
@@ -52,6 +52,13 @@ struct CondCtx
bool skip;
};
+struct CommentCtx
+{
+ CommentCtx(int line)
+ : lineNr(line) {}
+ int lineNr;
+};
+
static BufStr * g_inBuf;
static BufStr * g_outBuf;
static int g_inBufPos;
@@ -64,6 +71,7 @@ static QCString g_fileName;
static int g_lineNr;
static int g_condCtx;
static QStack<CondCtx> g_condStack;
+static QStack<CommentCtx> g_commentStack;
static QCString g_blockName;
static int g_lastCommentContext;
static bool g_inSpecialComment;
@@ -256,8 +264,10 @@ void replaceComment(int offset);
{
g_pythonDocString = TRUE;
g_nestingCount=0;
+ g_commentStack.clear(); /* to be on the save side */
copyToOutput(yytext,(int)yyleng);
BEGIN(CComment);
+ g_commentStack.push(new CommentCtx(g_lineNr));
}
}
<Scan>![><!]/.*\n {
@@ -269,7 +279,9 @@ void replaceComment(int offset);
{
copyToOutput(yytext,(int)yyleng);
g_nestingCount=0;
+ g_commentStack.clear(); /* to be on the save side */
BEGIN(CComment);
+ g_commentStack.push(new CommentCtx(g_lineNr));
}
}
<Scan>[Cc\*][><!]/.*\n {
@@ -284,7 +296,9 @@ void replaceComment(int offset);
{
copyToOutput(yytext,(int)yyleng);
g_nestingCount=0;
+ g_commentStack.clear(); /* to be on the save side */
BEGIN(CComment);
+ g_commentStack.push(new CommentCtx(g_lineNr));
}
else
{
@@ -378,8 +392,10 @@ void replaceComment(int offset);
<Scan>"/*"[*!]? { /* start of a C comment */
g_specialComment=(int)yyleng==3;
g_nestingCount=0;
+ g_commentStack.clear(); /* to be on the save side */
copyToOutput(yytext,(int)yyleng);
BEGIN(CComment);
+ g_commentStack.push(new CommentCtx(g_lineNr));
}
<Scan>"#"("#")? {
if (g_lang!=SrcLangExt_Python)
@@ -390,7 +406,9 @@ void replaceComment(int offset);
{
copyToOutput(yytext,(int)yyleng);
g_nestingCount=0;
+ g_commentStack.clear(); /* to be on the save side */
BEGIN(CComment);
+ g_commentStack.push(new CommentCtx(g_lineNr));
}
}
<Scan>"--!" {
@@ -402,7 +420,9 @@ void replaceComment(int offset);
{
copyToOutput(yytext,(int)yyleng);
g_nestingCount=0;
+ g_commentStack.clear(); /* to be on the save side */
BEGIN(CComment);
+ g_commentStack.push(new CommentCtx(g_lineNr));
}
}
<Scan>![><!] {
@@ -414,7 +434,9 @@ void replaceComment(int offset);
{
copyToOutput(yytext,(int)yyleng);
g_nestingCount=0;
+ g_commentStack.clear(); /* to be on the save side */
BEGIN(CComment);
+ g_commentStack.push(new CommentCtx(g_lineNr));
}
}
<CComment>"{@code"/[ \t\n] {
@@ -606,6 +628,7 @@ void replaceComment(int offset);
}
<CComment>"/"+"*" { /* nested C comment */
g_nestingCount++;
+ g_commentStack.push(new CommentCtx(g_lineNr));
copyToOutput(yytext,(int)yyleng);
}
<CComment>"*"+"/" { /* end of C comment */
@@ -615,14 +638,15 @@ void replaceComment(int offset);
}
else
{
+ copyToOutput(yytext,(int)yyleng);
if (g_nestingCount<=0)
{
- copyToOutput(yytext,(int)yyleng);
BEGIN(Scan);
}
else
{
g_nestingCount--;
+ delete g_commentStack.pop();
}
}
}
@@ -731,7 +755,7 @@ void replaceComment(int offset);
<CComment,ReadLine>[\\@][\\@][~a-z_A-Z][a-z_A-Z0-9]*[ \t]* { // escaped command
copyToOutput(yytext,(int)yyleng);
}
-<CComment,ReadLine>[\\@]"cond"[ \t]+ { // conditional section
+<CComment,ReadLine>[\\@]"cond"/[^a-z_A-Z0-9] { // conditional section
g_condCtx = YY_START;
BEGIN(CondLine);
}
@@ -951,6 +975,8 @@ void convertCppComments(BufStr *inBuf,BufStr *outBuf,const char *fileName)
g_lineNr = 1;
g_condStack.clear();
g_condStack.setAutoDelete(TRUE);
+ g_commentStack.clear();
+ g_commentStack.setAutoDelete(TRUE);
printlex(yy_flex_debug, TRUE, __FILE__, fileName);
isFixedForm = FALSE;
@@ -963,6 +989,7 @@ void convertCppComments(BufStr *inBuf,BufStr *outBuf,const char *fileName)
{
g_nestingCount=0;
BEGIN(CComment);
+ g_commentStack.push(new CommentCtx(g_lineNr));
}
else
{
@@ -977,6 +1004,23 @@ void convertCppComments(BufStr *inBuf,BufStr *outBuf,const char *fileName)
warn(g_fileName,ctx->lineNr,"Conditional section%sdoes not have "
"a corresponding \\endcond command within this file.",sectionInfo.data());
}
+ if (g_nestingCount>0 || (YY_START==CComment && g_lang!=SrcLangExt_Markdown))
+ {
+ QCString tmp= "(probable line reference: ";
+ bool first = TRUE;
+ while (!g_commentStack.isEmpty())
+ {
+ CommentCtx *ctx = g_commentStack.pop();
+ if (!first) tmp += ", ";
+ tmp += QCString().setNum(ctx->lineNr);
+ first = FALSE;
+ delete ctx;
+ }
+ tmp += ")";
+ warn(g_fileName,g_lineNr,"Reached end of file while still inside a (nested) comment. "
+ "Nesting level %d %s",g_nestingCount+1,tmp.data()); // add one for "normal" expected end of comment
+ }
+ g_commentStack.clear();
if (Debug::isFlagSet(Debug::CommentCnv))
{
g_outBuf->at(g_outBuf->curPos())='\0';