diff options
author | Dimitri van Heesch <doxygen@gmail.com> | 2020-04-30 17:29:52 (GMT) |
---|---|---|
committer | Dimitri van Heesch <doxygen@gmail.com> | 2020-04-30 17:29:52 (GMT) |
commit | f07af121a870e909c1820cade76c502a44f99d23 (patch) | |
tree | 1861ef5c9e4a5a686dbe22088ff13eea40a599b9 | |
parent | 6ca67aa0e617816789f2a662c86ad82426377b71 (diff) | |
download | Doxygen-f07af121a870e909c1820cade76c502a44f99d23.zip Doxygen-f07af121a870e909c1820cade76c502a44f99d23.tar.gz Doxygen-f07af121a870e909c1820cade76c502a44f99d23.tar.bz2 |
Refactoring: modernize g_inputFiles and the parameters of readFileOrDirectory
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/doxygen.cpp | 234 | ||||
-rw-r--r-- | src/doxygen.h | 20 | ||||
-rw-r--r-- | src/util.cpp | 2 |
4 files changed, 147 insertions, 113 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 146f67f..e512ed5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -283,6 +283,10 @@ add_library(_doxygen STATIC xmlgen.cpp ) +# LLVM/clang headers give a lot of warnings with -Wshadow and -Wcast-align so we disable them for +# the one file that includes them +set_source_files_properties(clangparser.cpp PROPERTIES COMPILE_FLAGS "-Wno-shadow -Wno-cast-align") + ##foreach(lex_file ${LEX_FILES}) ##add_library(_doxygen STATIC ${GENERATED_SRC}/${lex_file}.l.h) ##endforeach() diff --git a/src/doxygen.cpp b/src/doxygen.cpp index 8c72b65..2709ea6 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -127,16 +127,16 @@ GroupSDict *Doxygen::groupSDict = 0; PageSDict *Doxygen::pageSDict = 0; PageSDict *Doxygen::exampleSDict = 0; StringDict Doxygen::aliasDict(257); // aliases -std::set<std::string> Doxygen::inputPaths; +StringSet Doxygen::inputPaths; FileNameLinkedMap *Doxygen::includeNameLinkedMap = 0; // include names FileNameLinkedMap *Doxygen::exampleNameLinkedMap = 0; // examples FileNameLinkedMap *Doxygen::imageNameLinkedMap = 0; // images FileNameLinkedMap *Doxygen::dotFileNameLinkedMap = 0; // dot files FileNameLinkedMap *Doxygen::mscFileNameLinkedMap = 0; // msc files FileNameLinkedMap *Doxygen::diaFileNameLinkedMap = 0; // dia files -StringMap Doxygen::namespaceAliasMap; // all namespace aliases +StringUnorderedMap Doxygen::namespaceAliasMap; // all namespace aliases StringDict Doxygen::tagDestinationDict(257); // all tag locations -std::unordered_set<std::string> Doxygen::expandAsDefinedSet; // all macros that should be expanded +StringUnorderedSet Doxygen::expandAsDefinedSet; // all macros that should be expanded QIntDict<MemberGroupInfo> Doxygen::memGrpInfoDict(1009); // dictionary of the member groups heading PageDef *Doxygen::mainPage = 0; bool Doxygen::insideMainPage = FALSE; // are we generating docs for the main page? @@ -168,7 +168,7 @@ Preprocessor *Doxygen::preprocessor = 0; // locally accessible globals static std::unordered_map< std::string, const Entry* > g_classEntries; -static StringList g_inputFiles; +static StringVector g_inputFiles; static QDict<void> g_compoundKeywordDict(7); // keywords recognised as compounds static OutputList *g_outputList = 0; // list of output generating objects static QDict<FileDef> g_usingDeclarations(1009); // used classes @@ -8435,7 +8435,7 @@ static void checkPageRelations() static void resolveUserReferences() { - for (auto &si : SectionManager::instance()) + for (const auto &si : SectionManager::instance()) { //printf("si->label='%s' si->definition=%s si->fileName='%s'\n", // si->label.data(),si->definition?si->definition->name().data():"<none>", @@ -9091,25 +9091,23 @@ static void parseFiles(const std::shared_ptr<Entry> &root) // create a dictionary with files to process QDict<void> g_filesToProcess(10007); - StringListIterator it(g_inputFiles); - QCString *s; - for (;(s=it.current());++it) + for (const auto &s : g_inputFiles) { - g_filesToProcess.insert(*s,(void*)0x8); + g_filesToProcess.insert(s.c_str(),(void*)0x8); } // process source files (and their include dependencies) - for (it.toFirst();(s=it.current());++it) + for (const auto &s : g_inputFiles) { bool ambig; - FileDef *fd=findFileDef(Doxygen::inputNameLinkedMap,s->data(),ambig); + FileDef *fd=findFileDef(Doxygen::inputNameLinkedMap,s.c_str(),ambig); ASSERT(fd!=0); if (fd->isSource() && !fd->isReference()) // this is a source file { QStrList filesInSameTu; - OutlineParserInterface &parser = getParserForFile(s->data()); - parser.startTranslationUnit(s->data()); - parseFile(parser,root,fd,s->data(),FALSE,filesInSameTu); + OutlineParserInterface &parser = getParserForFile(s.c_str()); + parser.startTranslationUnit(s.c_str()); + parseFile(parser,root,fd,s.c_str(),FALSE,filesInSameTu); //printf(" got %d extra files in tu\n",filesInSameTu.count()); // Now process any include files in the same translation unit @@ -9117,13 +9115,13 @@ static void parseFiles(const std::shared_ptr<Entry> &root) char *incFile = filesInSameTu.first(); while (incFile && g_filesToProcess.find(incFile)) { - if (qstrcmp(incFile,s->data()) && !g_processedFiles.find(incFile)) + if (qstrcmp(incFile,s.c_str()) && !g_processedFiles.find(incFile)) { FileDef *ifd=findFileDef(Doxygen::inputNameLinkedMap,incFile,ambig); if (ifd && !ifd->isReference()) { QStrList moreFiles; - //printf(" Processing %s in same translation unit as %s\n",incFile,s->data()); + //printf(" Processing %s in same translation unit as %s\n",incFile,s->c_str()); parseFile(parser,root,ifd,incFile,TRUE,moreFiles); g_processedFiles.insert(incFile,(void*)0x8); } @@ -9131,40 +9129,38 @@ static void parseFiles(const std::shared_ptr<Entry> &root) incFile = filesInSameTu.next(); } parser.finishTranslationUnit(); - g_processedFiles.insert(*s,(void*)0x8); + g_processedFiles.insert(s.c_str(),(void*)0x8); } } // process remaining files - for (it.toFirst();(s=it.current());++it) + for (const auto &s : g_inputFiles) { - if (!g_processedFiles.find(*s)) // not yet processed + if (!g_processedFiles.find(s.c_str())) // not yet processed { bool ambig; QStrList filesInSameTu; - FileDef *fd=findFileDef(Doxygen::inputNameLinkedMap,s->data(),ambig); + FileDef *fd=findFileDef(Doxygen::inputNameLinkedMap,s.c_str(),ambig); ASSERT(fd!=0); - OutlineParserInterface &parser = getParserForFile(s->data()); - parser.startTranslationUnit(s->data()); - parseFile(parser,root,fd,s->data(),FALSE,filesInSameTu); + OutlineParserInterface &parser = getParserForFile(s.c_str()); + parser.startTranslationUnit(s.c_str()); + parseFile(parser,root,fd,s.c_str(),FALSE,filesInSameTu); parser.finishTranslationUnit(); - g_processedFiles.insert(*s,(void*)0x8); + g_processedFiles.insert(s.c_str(),(void*)0x8); } } } else // normal processing #endif { - StringListIterator it(g_inputFiles); - QCString *s; - for (;(s=it.current());++it) + for (const auto &s : g_inputFiles) { bool ambig; QStrList filesInSameTu; - FileDef *fd=findFileDef(Doxygen::inputNameLinkedMap,s->data(),ambig); + FileDef *fd=findFileDef(Doxygen::inputNameLinkedMap,s.c_str(),ambig); ASSERT(fd!=0); - OutlineParserInterface &parser = getParserForFile(s->data()); - parser.startTranslationUnit(s->data()); - parseFile(parser,root,fd,s->data(),FALSE,filesInSameTu); + OutlineParserInterface &parser = getParserForFile(s.c_str()); + parser.startTranslationUnit(s.c_str()); + parseFile(parser,root,fd,s.c_str(),FALSE,filesInSameTu); } } } @@ -9247,15 +9243,15 @@ static QDict<void> g_pathsVisited(1009); static int readDir(QFileInfo *fi, FileNameLinkedMap *fnMap, - StringDict *exclDict, + StringUnorderedSet *exclSet, QStrList *patList, QStrList *exclPatList, - StringList *resultList, - StringDict *resultDict, + StringVector *resultList, + StringUnorderedSet *resultSet, bool errorIfNotExist, bool recursive, - std::unordered_set<std::string> *killSet, - std::set<std::string> *paths + StringUnorderedSet *killSet, + StringSet *paths ) { QCString dirName = fi->absFilePath().utf8(); @@ -9284,7 +9280,7 @@ static int readDir(QFileInfo *fi, while ((cfi=it.current())) { - if (exclDict==0 || exclDict->find(cfi->absFilePath().utf8())==0) + if (exclSet==0 || exclSet->find(cfi->absFilePath().utf8().data())==exclSet->end()) { // file should not be excluded //printf("killSet->find(%s)\n",cfi->absFilePath().data()); if (!cfi->exists() || !cfi->isReadable()) @@ -9314,13 +9310,8 @@ static int readDir(QFileInfo *fi, fn->push_back(std::move(fd)); } } - QCString *rs=0; - if (resultList || resultDict) - { - rs=new QCString(cfi->absFilePath().utf8()); - } - if (resultList) resultList->append(rs); - if (resultDict) resultDict->insert(cfi->absFilePath().utf8(),rs); + if (resultList) resultList->push_back(cfi->absFilePath().utf8().data()); + if (resultSet) resultSet->insert(cfi->absFilePath().utf8().data()); if (killSet) killSet->insert(cfi->absFilePath().utf8().data()); } else if (recursive && @@ -9330,8 +9321,8 @@ static int readDir(QFileInfo *fi, cfi->fileName().at(0)!='.') // skip "." ".." and ".dir" { cfi->setFile(cfi->absFilePath()); - totalSize+=readDir(cfi,fnMap,exclDict, - patList,exclPatList,resultList,resultDict,errorIfNotExist, + totalSize+=readDir(cfi,fnMap,exclSet, + patList,exclPatList,resultList,resultSet,errorIfNotExist, recursive,killSet,paths); } } @@ -9348,15 +9339,15 @@ static int readDir(QFileInfo *fi, int readFileOrDirectory(const char *s, FileNameLinkedMap *fnMap, - StringDict *exclDict, + StringUnorderedSet *exclSet, QStrList *patList, QStrList *exclPatList, - StringList *resultList, - StringDict *resultDict, + StringVector *resultList, + StringUnorderedSet *resultSet, bool recursive, bool errorIfNotExist, - std::unordered_set<std::string> *killSet, - std::set<std::string> *paths + StringUnorderedSet *killSet, + StringSet *paths ) { //printf("killSet count=%d\n",killSet ? (int)killSet->size() : -1); @@ -9370,7 +9361,7 @@ int readFileOrDirectory(const char *s, //printf("readFileOrDirectory(%s)\n",s); int totalSize=0; { - if (exclDict==0 || exclDict->find(fi.absFilePath().utf8())==0) + if (exclSet==0 || exclSet->find(fi.absFilePath().utf8().data())==exclSet->end()) { if (!fi.exists() || !fi.isReadable()) { @@ -9405,12 +9396,10 @@ int readFileOrDirectory(const char *s, fn->push_back(std::move(fd)); } } - QCString *rs=0; - if (resultList || resultDict) + if (resultList || resultSet) { - rs=new QCString(filePath); - if (resultList) resultList->append(rs); - if (resultDict) resultDict->insert(filePath,rs); + if (resultList) resultList->push_back(filePath.data()); + if (resultSet) resultSet->insert(filePath.data()); } if (killSet) killSet->insert(fi.absFilePath().utf8().data()); @@ -9418,8 +9407,8 @@ int readFileOrDirectory(const char *s, } else if (fi.isDir()) // readable dir { - totalSize+=readDir(&fi,fnMap,exclDict,patList, - exclPatList,resultList,resultDict,errorIfNotExist, + totalSize+=readDir(&fi,fnMap,exclSet,patList, + exclPatList,resultList,resultSet,errorIfNotExist, recursive,killSet,paths); } } @@ -10473,12 +10462,11 @@ static QCString getQchFileName() void searchInputFiles() { - std::unordered_set<std::string> killSet; + StringUnorderedSet killSet; QStrList &exclPatterns = Config_getList(EXCLUDE_PATTERNS); bool alwaysRecursive = Config_getBool(RECURSIVE); - StringDict excludeNameDict(1009); - excludeNameDict.setAutoDelete(TRUE); + StringUnorderedSet excludeNameSet; // gather names of all files in the include path g_s.begin("Searching for include files...\n"); @@ -10492,10 +10480,16 @@ void searchInputFiles() { pl = Config_getList(FILE_PATTERNS); } - readFileOrDirectory(s,Doxygen::includeNameLinkedMap,0,&pl, - &exclPatterns,0,0, - alwaysRecursive, - TRUE,&killSet); + readFileOrDirectory(s, // s + Doxygen::includeNameLinkedMap, // fnDict + 0, // exclSet + &pl, // patList + &exclPatterns, // exclPatList + 0, // resultList + 0, // resultSet + alwaysRecursive, // recursive + TRUE, // errorIfNotExist + &killSet); // killSet s=includePathList.next(); } g_s.end(); @@ -10506,11 +10500,16 @@ void searchInputFiles() s=examplePathList.first(); while (s) { - readFileOrDirectory(s,Doxygen::exampleNameLinkedMap,0, - &Config_getList(EXAMPLE_PATTERNS), - 0,0,0, - (alwaysRecursive || Config_getBool(EXAMPLE_RECURSIVE)), - TRUE,&killSet); + readFileOrDirectory(s, // s + Doxygen::exampleNameLinkedMap, // fnDict + 0, // exclSet + &Config_getList(EXAMPLE_PATTERNS), // patList + 0, // exclPatList + 0, // resultList + 0, // resultSet + (alwaysRecursive || Config_getBool(EXAMPLE_RECURSIVE)), // recursive + TRUE, // errorIfNotExist + &killSet); // killSet s=examplePathList.next(); } g_s.end(); @@ -10521,10 +10520,16 @@ void searchInputFiles() s=imagePathList.first(); while (s) { - readFileOrDirectory(s,Doxygen::imageNameLinkedMap,0,0, - 0,0,0, - alwaysRecursive, - TRUE,&killSet); + readFileOrDirectory(s, // s + Doxygen::imageNameLinkedMap, // fnDict + 0, // exclSet + 0, // patList + 0, // exclPatList + 0, // resultList + 0, // resultSet + alwaysRecursive, // recursive + TRUE, // errorIfNotExist + &killSet); // killSet s=imagePathList.next(); } g_s.end(); @@ -10535,10 +10540,16 @@ void searchInputFiles() s=dotFileList.first(); while (s) { - readFileOrDirectory(s,Doxygen::dotFileNameLinkedMap,0,0, - 0,0,0, - alwaysRecursive, - TRUE,&killSet); + readFileOrDirectory(s, // s + Doxygen::dotFileNameLinkedMap, // fnDict + 0, // exclSet + 0, // patList + 0, // exclPatList + 0, // resultList + 0, // resultSet + alwaysRecursive, // recursive + TRUE, // errorIfNotExist + &killSet); // killSet s=dotFileList.next(); } g_s.end(); @@ -10549,10 +10560,16 @@ void searchInputFiles() s=mscFileList.first(); while (s) { - readFileOrDirectory(s,Doxygen::mscFileNameLinkedMap,0,0, - 0,0,0, - alwaysRecursive, - TRUE,&killSet); + readFileOrDirectory(s, // s + Doxygen::mscFileNameLinkedMap, // fnDict + 0, // exclSet + 0, // patList + 0, // exclPatList + 0, // resultList + 0, // resultSet + alwaysRecursive, // recursive + TRUE, // errorIfNotExist + &killSet); // killSet s=mscFileList.next(); } g_s.end(); @@ -10563,10 +10580,16 @@ void searchInputFiles() s=diaFileList.first(); while (s) { - readFileOrDirectory(s,Doxygen::diaFileNameLinkedMap,0,0, - 0,0,0, - alwaysRecursive, - TRUE,&killSet); + readFileOrDirectory(s, // s + Doxygen::diaFileNameLinkedMap, // fnDict + 0, // exclSet + 0, // patList + 0, // exclPatList + 0, // resultList + 0, // resultSet + alwaysRecursive, // recursive + TRUE, // errorIfNotExist + &killSet); // killSet s=diaFileList.next(); } g_s.end(); @@ -10576,11 +10599,16 @@ void searchInputFiles() s=excludeList.first(); while (s) { - readFileOrDirectory(s,0,0,&Config_getList(FILE_PATTERNS), - 0,0,&excludeNameDict, - alwaysRecursive, - FALSE); - s=excludeList.next(); + readFileOrDirectory(s, // s + 0, // fnDict + 0, // exclSet + &Config_getList(FILE_PATTERNS), // patList + 0, // exclPatList + 0, // resultList + &excludeNameSet, // resultSet + alwaysRecursive, // recursive + FALSE); // errorIfNotExist + s=excludeList.next(); // killSet } g_s.end(); @@ -10592,7 +10620,6 @@ void searchInputFiles() killSet.clear(); Doxygen::inputPaths.clear(); QStrList &inputList=Config_getList(INPUT); - g_inputFiles.setAutoDelete(TRUE); s=inputList.first(); while (s) { @@ -10604,16 +10631,17 @@ void searchInputFiles() if (path.at(l-1)=='\\' || path.at(l-1)=='/') path=path.left(l-1); readFileOrDirectory( - path, - Doxygen::inputNameLinkedMap, - &excludeNameDict, - &Config_getList(FILE_PATTERNS), - &exclPatterns, - &g_inputFiles,0, - alwaysRecursive, - TRUE, - &killSet, - &Doxygen::inputPaths); + path, // s + Doxygen::inputNameLinkedMap, // fnDict + &excludeNameSet, // exclSet + &Config_getList(FILE_PATTERNS), // patList + &exclPatterns, // exclPatList + &g_inputFiles, // resultList + 0, // resultSet + alwaysRecursive, // recursive + TRUE, // errorIfNotExist + &killSet, // killSet + &Doxygen::inputPaths); // paths } s=inputList.next(); } diff --git a/src/doxygen.h b/src/doxygen.h index 30d136f..275e1b9 100644 --- a/src/doxygen.h +++ b/src/doxygen.h @@ -85,7 +85,10 @@ struct LookupInfo QCString resolvedType; }; -using StringMap = std::unordered_map<std::string,std::string>; +using StringUnorderedMap = std::unordered_map<std::string,std::string>; +using StringUnorderedSet = std::unordered_set<std::string>; +using StringSet = std::set<std::string>; +using StringVector = std::vector<std::string>; extern QCString g_spaces; @@ -113,13 +116,13 @@ class Doxygen static MemberNameLinkedMap *memberNameLinkedMap; static MemberNameLinkedMap *functionNameLinkedMap; static QStrList tagfileList; - static StringMap namespaceAliasMap; + static StringUnorderedMap namespaceAliasMap; static GroupSDict *groupSDict; static NamespaceSDict *namespaceSDict; static StringDict tagDestinationDict; static StringDict aliasDict; static QIntDict<MemberGroupInfo> memGrpInfoDict; - static std::unordered_set<std::string> expandAsDefinedSet; + static StringUnorderedSet expandAsDefinedSet; static NamespaceDef *globalScope; static QCString htmlFileExtension; static bool parseSourcesNeeded; @@ -151,7 +154,6 @@ void initDoxygen(); void readConfiguration(int argc, char **argv); void checkConfiguration(); void adjustConfiguration(); -void searchInputFiles(StringList &inputFiles); void parseInput(); void generateOutput(); void readAliases(); @@ -159,15 +161,15 @@ void readFormulaRepository(QCString dir, bool cmp = FALSE); void cleanUpDoxygen(); int readFileOrDirectory(const char *s, FileNameLinkedMap *fnDict, - StringDict *exclDict, + StringUnorderedSet *exclSet, QStrList *patList, QStrList *exclPatList, - StringList *resultList, - StringDict *resultDict, + StringVector *resultList, + StringUnorderedSet *resultSet, bool recursive, bool errorIfNotExist=TRUE, - std::unordered_set<std::string> *killSet = 0, - std::set<std::string> *paths = 0 + StringUnorderedSet *killSet = 0, + StringSet *paths = 0 ); void copyAndFilterFile(const char *fileName,BufStr &dest); diff --git a/src/util.cpp b/src/util.cpp index 9e6605a..58094d9 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -486,7 +486,7 @@ NamespaceDef *getResolvedNamespace(const char *name) if (it!=Doxygen::namespaceAliasMap.end()) { int count=0; // recursion detection guard - StringMap::iterator it2; + StringUnorderedMap::iterator it2; while ((it2=Doxygen::namespaceAliasMap.find(it->second))!=Doxygen::namespaceAliasMap.end() && count<10) { |