diff options
author | dimitri <dimitri@afe2bf4a-e733-0410-8a33-86f594647bc7> | 2010-02-16 21:11:17 (GMT) |
---|---|---|
committer | dimitri <dimitri@afe2bf4a-e733-0410-8a33-86f594647bc7> | 2010-02-16 21:11:17 (GMT) |
commit | 20e951b95073ef5c1b76e9336c6281928e5c5a4d (patch) | |
tree | 524eebded0dbf9efbc5b02ab15856f10f914ff99 /src/pre.l | |
parent | d5dec476be2805b7b82893dcb5c147473b6740c4 (diff) | |
download | Doxygen-20e951b95073ef5c1b76e9336c6281928e5c5a4d.zip Doxygen-20e951b95073ef5c1b76e9336c6281928e5c5a4d.tar.gz Doxygen-20e951b95073ef5c1b76e9336c6281928e5c5a4d.tar.bz2 |
Release-1.6.2-20100216
Diffstat (limited to 'src/pre.l')
-rw-r--r-- | src/pre.l | 109 |
1 files changed, 85 insertions, 24 deletions
@@ -53,7 +53,7 @@ struct FileState { - FileState(int size) : fileBuf(size), oldFileBuf(0), oldFileBufPos(0) {} + FileState(int size) : fileBuf(size), oldFileBuf(0), oldFileBufPos(0),fileDef(0) {} int lineNr; //FILE *filePtr; BufStr fileBuf; @@ -63,6 +63,7 @@ struct FileState //bool isPlainFile; YY_BUFFER_STATE bufState; QCString fileName; + FileDef *fileDef; }; /* ----------------------------------------------------------------- @@ -121,6 +122,7 @@ DefineDict* getFileDefineDict() return g_fileDefineDict; } +#if 0 static void setFileName(const char *name) { bool ambig; @@ -130,6 +132,16 @@ static void setFileName(const char *name) if (g_yyFileDef && g_yyFileDef->isReference()) g_yyFileDef=0; g_insideCS = g_yyFileName.right(3)==".cs"; } +#endif + +static void setFileName(FileState *fs) +{ + g_yyFileName=fs->fileName; + g_yyFileDef=fs->fileDef; + //printf("^^ setFileName: %s->%p\n",g_yyFileName.data(),g_yyFileDef); + if (g_yyFileDef && g_yyFileDef->isReference()) g_yyFileDef=0; + g_insideCS = g_yyFileName.right(3)==".cs"; +} static void incrLevel() { @@ -173,18 +185,42 @@ static void setCaseDone(bool value) g_levelGuard[g_level-1]=value; } +static bool macroIsAccessible(Define *def) +{ + //printf("macroIsAccessible(%s) input=%s def=%s\n", + // def->name.data(),g_inputFileDef?g_inputFileDef->name().data():"<none>", + // def->fileDef ? def->fileDef->name().data() : "<none>"); + if (def && def->isPredefined) // predefined macro -> globally accessible + { + //printf("%s: predefined macro %s\n",g_inputFileDef->name().data(),def->name.data()); + return TRUE; + } + if (g_inputFileDef && def && def->fileDef) // check if g_inputFileDef actually includes def->fileDef + { + QDict<FileDef> includedFiles(257); + bool b = g_inputFileDef->includes(def->fileDef,&includedFiles); + //printf("%s: Checking for accessibility of define '%s' (defined in %s): result=%d\n", + // g_inputFileDef->name().data(),def->name.data(),def->fileDef->name().data(),b); + return b; + } + return FALSE; +} + static Define *isDefined(const char *name) { + Define *def=0; if (name) { - Define *def; + def=g_fileDefineDict->find(name); //if ((def=fileDefineCache->findDefine(g_yyFileName,name)) && !def->undef) // return def; - if ((def=g_fileDefineDict->find(name)) && !def->undef) return def; + if (def && def->undef) def=0; + if (def && !macroIsAccessible(def)) def=0; } - return 0; + return def; } + static QDict<void> g_allIncludes(10009); static FileState *checkAndOpenFile(const QCString &fileName,bool &alreadyIncluded) @@ -245,6 +281,8 @@ static FileState *checkAndOpenFile(const QCString &fileName,bool &alreadyInclude { fs->oldFileBuf = g_inputBuf; fs->oldFileBufPos = g_inputBufPos; + fs->fileDef = g_yyFileDef; + fs->fileName = g_yyFileName; } } return fs; @@ -262,7 +300,7 @@ static FileState *findFile(const char *fileName,bool localInclude,bool &alreadyI FileState *fs = checkAndOpenFile(absName,alreadyIncluded); if (fs) { - setFileName(absName); + setFileName(fs); g_yyLineNr=1; return fs; } @@ -283,7 +321,7 @@ static FileState *findFile(const char *fileName,bool localInclude,bool &alreadyI FileState *fs = checkAndOpenFile(absName,alreadyIncluded); if (fs) { - setFileName(absName); + setFileName(fs); g_yyLineNr=1; return fs; } @@ -1062,12 +1100,15 @@ QCString expandMacro(const QCString &name) Define *newDefine() { Define *def=new Define; - def->name = g_defName; + def->name = g_defName; def->definition = g_defText.stripWhiteSpace(); - def->nargs = g_defArgs; - def->fileName = g_yyFileName; - def->lineNr = g_yyLineNr; - def->varArgs = g_defVarArgs; + def->nargs = g_defArgs; + def->fileName = g_yyFileName; + def->fileDef = g_yyFileDef; + def->lineNr = g_yyLineNr; + def->varArgs = g_defVarArgs; + //printf("newDefine: %s->%s\n",def->name.data(), + // def->fileDef ? def->fileDef->name().data() : "<none>"); //printf("newDefine: `%s'->`%s'\n",def->name.data(),def->definition.data()); if (!def->name.isEmpty() && Doxygen::expandAsDefinedDict[def->name]) { @@ -1124,7 +1165,10 @@ void addDefine() Doxygen::functionNameSDict->append(g_defName,mn); } mn->append(md); - if (g_yyFileDef) g_yyFileDef->insertMember(md); + if (g_yyFileDef) + { + g_yyFileDef->insertMember(md); + } //Define *d; //if ((d=defineDict[g_defName])==0) defineDict.insert(g_defName,newDefine()); @@ -1190,9 +1234,10 @@ static void readIncludeFile(const QCString &inc) g_yyFileDef->addIncludedByDependency(oldFileDef,oldFileDef->docName(),localInclude,g_isImported); } } - fs->bufState=YY_CURRENT_BUFFER; - fs->lineNr=oldLineNr; - fs->fileName=oldFileName; + fs->bufState = YY_CURRENT_BUFFER; + fs->lineNr = oldLineNr; + fs->fileName = oldFileName; + fs->fileDef = oldFileDef; // push the state on the stack g_includeStack.push(fs); // set the scanner to the include file @@ -1398,6 +1443,7 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'")) (g_includeStack.isEmpty() || g_curlyCount>0) && g_macroExpansion && (def=g_fileDefineDict->find(name)) && + macroIsAccessible(def) && (!g_expandOnlyPredef || def->isPredefined) ) ) @@ -1470,10 +1516,11 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'")) if ((g_includeStack.isEmpty() || g_curlyCount>0) && g_macroExpansion && (def=g_fileDefineDict->find(yytext)) && + macroIsAccessible(def) && (!g_expandOnlyPredef || def->isPredefined) ) { - //printf("Found it!\n"); + //printf("Found it! #args=%d\n",def->nargs); g_roundCount=0; g_defArgsStr=yytext; if (def->nargs==-1) // no function macro @@ -1499,6 +1546,7 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'")) g_macroExpansion && (def=g_fileDefineDict->find(yytext)) && def->nargs==-1 && + macroIsAccessible(def) && (!g_expandOnlyPredef || def->isPredefined) ) { @@ -2181,7 +2229,8 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'")) //printf("new define!\n"); g_fileDefineDict->insert(g_defName,newDefine()); } - else if (def)// name already exists + else if (def && macroIsAccessible(def)) + // name already exists { //printf("existing define!\n"); //printf("define found\n"); @@ -2271,11 +2320,11 @@ CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^'\\\n]{1,4}"'")) YY_BUFFER_STATE oldBuf = YY_CURRENT_BUFFER; yy_switch_to_buffer( fs->bufState ); yy_delete_buffer( oldBuf ); - g_yyLineNr=fs->lineNr; + g_yyLineNr = fs->lineNr; //preYYin = fs->oldYYin; - g_inputBuf = fs->oldFileBuf; + g_inputBuf = fs->oldFileBuf; g_inputBufPos = fs->oldFileBufPos; - setFileName(fs->fileName.copy()); + setFileName(fs); //fprintf(stderr,"######## FileName %s\n",g_yyFileName.data()); // Deal with file changes due to @@ -2454,6 +2503,7 @@ void preprocessFile(const char *fileName,BufStr &input,BufStr &output) i_obrace<i_cbrace ) // predefined function macro definition { + //printf("predefined function macro '%s'\n",defStr); QRegExp reId("[a-z_A-Z][a-z_A-Z0-9]*"); // regexp matching an id QDict<int> argDict(17); argDict.setAutoDelete(TRUE); @@ -2493,11 +2543,13 @@ void preprocessFile(const char *fileName,BufStr &input,BufStr &output) if (!dname.isEmpty()) { Define *def = new Define; - def->name = dname; - def->definition = definition; - def->nargs = count; + def->name = dname; + def->definition = definition; + def->nargs = count; def->isPredefined = TRUE; def->nonRecursive = nonRecursive; + def->fileDef = g_yyFileDef; + def->fileName = fileName; g_fileDefineDict->insert(def->name,def); } @@ -2509,6 +2561,7 @@ void preprocessFile(const char *fileName,BufStr &input,BufStr &output) !ds.isEmpty() && (int)ds.length()>i_equals ) // predefined non-function macro definition { + //printf("predefined normal macro '%s'\n",defStr); Define *def = new Define; if (i_equals==-1) // simple define without argument { @@ -2526,6 +2579,8 @@ void preprocessFile(const char *fileName,BufStr &input,BufStr &output) def->nargs = -1; def->isPredefined = TRUE; def->nonRecursive = nonRecursive; + def->fileDef = g_yyFileDef; + def->fileName = fileName; g_fileDefineDict->insert(def->name,def); } else @@ -2566,8 +2621,14 @@ void preprocessFile(const char *fileName,BufStr &input,BufStr &output) g_yyLineNr = 1; g_level = 0; g_ifcount = 0; - setFileName(fileName); + QFileInfo fi(fileName); + bool ambig; + g_yyFileName = convertToQCString(fi.absFilePath()); + g_yyFileDef = findFileDef(Doxygen::inputNameDict,g_yyFileName,ambig); + if (g_yyFileDef && g_yyFileDef->isReference()) g_yyFileDef=0; + g_insideCS = g_yyFileName.right(3)==".cs"; g_inputFileDef = g_yyFileDef; + BEGIN( Start ); g_expectGuard = TRUE; |