summaryrefslogtreecommitdiffstats
path: root/src/pre.l
diff options
context:
space:
mode:
Diffstat (limited to 'src/pre.l')
-rw-r--r--src/pre.l59
1 files changed, 42 insertions, 17 deletions
diff --git a/src/pre.l b/src/pre.l
index 63c38d1..50ba69b 100644
--- a/src/pre.l
+++ b/src/pre.l
@@ -92,7 +92,8 @@ static int g_inputBufPos;
static BufStr *g_outputBuf;
static int g_roundCount;
static bool g_quoteArg;
-static DefineDict *g_fileDefineDict = new DefineDict(10009);
+static DefineDict *g_globalDefineDict = new DefineDict(10009);
+static DefineDict *g_fileDefineDict = new DefineDict(1009);
static DefineDict *g_expandedDict;
static int g_findDefArgContext;
static bool g_expectGuard;
@@ -112,12 +113,13 @@ static int g_condCtx;
static bool g_skip;
static QStack<bool> g_condStack;
static bool g_insideCS; // C# has simpler preprocessor
+static bool g_isSource;
static bool g_lexInit = FALSE;
-DefineDict* getFileDefineDict()
+DefineDict* getGlobalDefineDict()
{
- return g_fileDefineDict;
+ return g_globalDefineDict;
}
static void setFileName(const char *name)
@@ -135,6 +137,7 @@ static void setFileName(const char *name)
// name,g_yyFileName.data(),g_yyFileDef);
if (g_yyFileDef && g_yyFileDef->isReference()) g_yyFileDef=0;
g_insideCS = getLanguageFromFileName(g_yyFileName)==SrcLangExt_CSharp;
+ g_isSource = guessSection(g_yyFileName);
}
static void incrLevel()
@@ -210,7 +213,7 @@ static Define *isDefined(const char *name)
Define *def=0;
if (name)
{
- def=g_fileDefineDict->find(name);
+ def=g_globalDefineDict->find(name);
//if ((def=fileDefineCache->findDefine(g_yyFileName,name)) && !def->undef)
// return def;
if (def && def->undef) def=0;
@@ -1485,7 +1488,7 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'"))
!(
(g_includeStack.isEmpty() || g_curlyCount>0) &&
g_macroExpansion &&
- (def=g_fileDefineDict->find(name)) &&
+ (def=g_globalDefineDict->find(name)) &&
macroIsAccessible(def) &&
(!g_expandOnlyPredef || def->isPredefined)
)
@@ -1549,7 +1552,7 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'"))
<CopyLine>{ID}/{BN}{0,80}"(" {
g_expectGuard = FALSE;
Define *def=0;
- //def=g_fileDefineDict->find(yytext);
+ //def=g_globalDefineDict->find(yytext);
//printf("Search for define %s found=%d g_includeStack.isEmpty()=%d "
// "g_curlyCount=%d g_macroExpansion=%d g_expandOnlyPredef=%d "
// "isPreDefined=%d\n",yytext,def ? 1 : 0,
@@ -1558,7 +1561,7 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'"))
// );
if ((g_includeStack.isEmpty() || g_curlyCount>0) &&
g_macroExpansion &&
- (def=g_fileDefineDict->find(yytext)) &&
+ (def=g_globalDefineDict->find(yytext)) &&
(def->isPredefined || macroIsAccessible(def)) &&
(!g_expandOnlyPredef || def->isPredefined)
)
@@ -1586,7 +1589,7 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'"))
Define *def=0;
if ((g_includeStack.isEmpty() || g_curlyCount>0) &&
g_macroExpansion &&
- (def=g_fileDefineDict->find(yytext)) &&
+ (def=g_globalDefineDict->find(yytext)) &&
def->nargs==-1 &&
(def->isPredefined || macroIsAccessible(def)) &&
(!g_expandOnlyPredef || def->isPredefined)
@@ -2130,11 +2133,15 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'"))
outputArray(yytext,yyleng);
BEGIN(g_condCtx);
}
-<SkipCComment,SkipCPPComment>[\\@]"cond"[ \t\r]*\n |
+<SkipCComment,SkipCPPComment>[\\@]"cond"[ \t\r]*/\n {
+ g_condCtx = YY_START;
+ outputArray(yytext,yyleng);
+ BEGIN(CondLine);
+ }
<CondLine>. {
unput(*yytext);
startCondSection(" ");
- if (YY_START==CondLine) BEGIN(g_condCtx);
+ BEGIN(g_condCtx);
}
<SkipCComment,SkipCPPComment>[\\@]"endcond"/[^a-z_A-Z0-9] {
outputArray(yytext,yyleng);
@@ -2278,11 +2285,17 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'"))
{
addDefine();
}
- def=g_fileDefineDict->find(g_defName);
+ def=g_globalDefineDict->find(g_defName);
if (def==0) // new define
{
//printf("new define!\n");
- g_fileDefineDict->insert(g_defName,newDefine());
+ Define *nd = newDefine();
+ g_globalDefineDict->insert(g_defName,nd);
+ // also add it to the local file list if it is a source file
+ if (g_isSource && g_includeStack.isEmpty())
+ {
+ g_fileDefineDict->insert(g_defName,nd);
+ }
}
else if (def && macroIsAccessible(def))
// name already exists
@@ -2508,10 +2521,10 @@ void preprocessFile(const char *fileName,BufStr &input,BufStr &output)
g_expandedDict->clear();
g_condStack.clear();
g_condStack.setAutoDelete(TRUE);
- g_fileDefineDict->clear(); // add due to bug 641346
+ g_fileDefineDict->clear();
- //static bool firstTime=TRUE;
- //if (firstTime)
+ static bool firstTime=TRUE;
+ if (firstTime)
{
// add predefined macros
char *defStr;
@@ -2579,7 +2592,7 @@ void preprocessFile(const char *fileName,BufStr &input,BufStr &output)
def->nonRecursive = nonRecursive;
def->fileDef = g_yyFileDef;
def->fileName = fileName;
- g_fileDefineDict->insert(def->name,def);
+ g_globalDefineDict->insert(def->name,def);
}
//printf("#define `%s' `%s' #nargs=%d\n",
@@ -2610,7 +2623,7 @@ void preprocessFile(const char *fileName,BufStr &input,BufStr &output)
def->nonRecursive = nonRecursive;
def->fileDef = g_yyFileDef;
def->fileName = fileName;
- g_fileDefineDict->insert(def->name,def);
+ g_globalDefineDict->insert(def->name,def);
}
else
{
@@ -2642,6 +2655,18 @@ void preprocessFile(const char *fileName,BufStr &input,BufStr &output)
// make sure we don't extend a \cond with missing \endcond over multiple files (see bug 624829)
forceEndCondSection();
+ // remove locally defined macros so they can be redefined in another source file
+ if (g_fileDefineDict->count()>0)
+ {
+ QDictIterator<Define> di(*g_fileDefineDict);
+ Define *d;
+ for (di.toFirst();(d=di.current());++di)
+ {
+ g_globalDefineDict->remove(di.currentKey());
+ }
+ g_fileDefineDict->clear();
+ }
+
if (Debug::isFlagSet(Debug::Preprocessor))
{
char *orgPos=output.data()+orgOffset;