summaryrefslogtreecommitdiffstats
path: root/src/pre.l
diff options
context:
space:
mode:
Diffstat (limited to 'src/pre.l')
-rw-r--r--src/pre.l34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/pre.l b/src/pre.l
index 7685853..fbf7bde 100644
--- a/src/pre.l
+++ b/src/pre.l
@@ -18,6 +18,9 @@
%option prefix="preYY"
%option reentrant
%option extra-type="struct preYY_state *"
+%top{
+#include <stdint.h>
+}
%{
@@ -2379,6 +2382,8 @@ static int getNextId(const QCString &expr,int p,int *l)
return -1;
}
+#define MAX_EXPANSION_DEPTH 50
+
/*! performs recursive macro expansion on the string \a expr
* starting at position \a pos.
* May read additional characters from the input while re-scanning!
@@ -2392,7 +2397,7 @@ static bool expandExpression(yyscan_t yyscanner,QCString &expr,QCString *rest,in
//printf("<expandExpression: empty\n");
return TRUE;
}
- if (state->expansionDict.find(expr)!=0) // check for recursive expansions
+ if (state->expansionDict.find(expr)!=0 && level>MAX_EXPANSION_DEPTH) // check for too deep recursive expansions
{
//printf("<expandExpression: already expanded expr='%s'\n",expr.data());
return FALSE;
@@ -2405,6 +2410,8 @@ static bool expandExpression(yyscan_t yyscanner,QCString &expr,QCString *rest,in
QCString expMacro;
bool definedTest=FALSE;
int i=pos,l,p,len;
+ int startPos = pos;
+ int samePosCount=0;
while ((p=getNextId(expr,i,&l))!=-1) // search for an macro name
{
bool replaced=FALSE;
@@ -2492,6 +2499,20 @@ static bool expandExpression(yyscan_t yyscanner,QCString &expr,QCString *rest,in
i=p+l+2;
//i=p+l;
}
+ // check for too many inplace expansions without making progress
+ if (i==startPos)
+ {
+ samePosCount++;
+ }
+ else
+ {
+ startPos=i;
+ samePosCount=0;
+ }
+ if (samePosCount>MAX_EXPANSION_DEPTH)
+ {
+ break;
+ }
}
else // no re-scan marker found, skip the macro name
{
@@ -2780,7 +2801,6 @@ static void addDefine(yyscan_t yyscanner)
YY_EXTRA_TYPE state = preYYget_extra(yyscanner);
if (state->skip) return; // do not add this define as it is inside a
// conditional section (cond command) that is disabled.
- if (!Doxygen::gatherDefines) return;
//printf("addDefine '%s' '%s'\n",state->defName.data(),state->defArgsStr.data());
//ArgumentList *al = new ArgumentList;
@@ -3194,9 +3214,8 @@ void Preprocessor::addSearchDir(const char *dir)
if (fi.isDir()) state->pathList->append(fi.absFilePath().utf8());
}
-Preprocessor::Preprocessor()
+Preprocessor::Preprocessor() : p(std::make_unique<Private>())
{
- p = new Private;
preYYlex_init_extra(&p->state,&p->yyscanner);
YY_EXTRA_TYPE state = preYYget_extra(p->yyscanner);
state->pathList = new QStrList;
@@ -3212,7 +3231,6 @@ Preprocessor::~Preprocessor()
delete state->pathList;
state->pathList=0;
preYYlex_destroy(p->yyscanner);
- delete p;
}
void Preprocessor::processFile(const char *fileName,BufStr &input,BufStr &output)
@@ -3417,7 +3435,7 @@ void Preprocessor::processFile(const char *fileName,BufStr &input,BufStr &output
{
char *orgPos=output.data()+orgOffset;
char *newPos=output.data()+output.curPos();
- Debug::print(Debug::Preprocessor,0,"Preprocessor output (size: %d bytes):\n",newPos-orgPos);
+ Debug::print(Debug::Preprocessor,0,"Preprocessor output of %s (size: %d bytes):\n",fileName,newPos-orgPos);
int line=1;
Debug::print(Debug::Preprocessor,0,"---------\n00001 ");
while (orgPos<newPos)
@@ -3429,7 +3447,7 @@ void Preprocessor::processFile(const char *fileName,BufStr &input,BufStr &output
Debug::print(Debug::Preprocessor,0,"\n---------\n");
if (state->defineManager.defineContext().count()>0)
{
- Debug::print(Debug::Preprocessor,0,"Macros accessible in this file:\n");
+ Debug::print(Debug::Preprocessor,0,"Macros accessible in this file (%s):\n", fileName);
Debug::print(Debug::Preprocessor,0,"---------\n");
QDictIterator<Define> di(state->defineManager.defineContext());
Define *def;
@@ -3441,7 +3459,7 @@ void Preprocessor::processFile(const char *fileName,BufStr &input,BufStr &output
}
else
{
- Debug::print(Debug::Preprocessor,0,"No macros accessible in this file.\n");
+ Debug::print(Debug::Preprocessor,0,"No macros accessible in this file (%s).\n", fileName);
}
}
state->defineManager.endContext();