From 8c0bb948329448cb88b208480e2048af3638aa45 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sun, 10 Jan 2021 13:34:07 +0100 Subject: Refactoring: modernize IncludeInfo list --- addon/doxyapp/doxyapp.cpp | 4 +- src/classdef.cpp | 14 ++-- src/classdef.h | 2 +- src/context.cpp | 14 ++-- src/context.h | 7 +- src/dirdef.cpp | 36 +++++------ src/dirdef.h | 12 ++-- src/docsets.cpp | 2 +- src/dotincldepgraph.cpp | 89 ++++++++++++------------- src/filedef.cpp | 162 +++++++++++++++++----------------------------- src/filedef.h | 23 ++++--- src/index.cpp | 2 +- src/perlmodgen.cpp | 35 ++++------ src/sqlite3gen.cpp | 139 +++++++++++++++++++-------------------- src/xmlgen.cpp | 40 +++++------- 15 files changed, 251 insertions(+), 330 deletions(-) diff --git a/addon/doxyapp/doxyapp.cpp b/addon/doxyapp/doxyapp.cpp index 5fc07be..06c7af3 100644 --- a/addon/doxyapp/doxyapp.cpp +++ b/addon/doxyapp/doxyapp.cpp @@ -179,8 +179,8 @@ static void lookupSymbol(Definition *d) case Definition::TypeFile: { FileDef *fd = dynamic_cast(d); - printf("Kind: File: #includes %d other files\n", - fd->includeFileList() ? fd->includeFileList()->count() : 0); + printf("Kind: File: #includes %zu other files\n", + fd->includeFileList().size()); } break; case Definition::TypeNamespace: diff --git a/src/classdef.cpp b/src/classdef.cpp index ec2642b..8af0b1c 100644 --- a/src/classdef.cpp +++ b/src/classdef.cpp @@ -199,7 +199,7 @@ class ClassDefImpl : public DefinitionMixin virtual const TemplateInstanceList &getTemplateInstances() const; virtual const ClassDef *templateMaster() const; virtual bool isTemplate() const; - virtual IncludeInfo *includeInfo() const; + virtual const IncludeInfo *includeInfo() const; virtual const UsesClassList &usedImplementationClasses() const; virtual const UsesClassList &usedByImplementationClasses() const; virtual const ConstraintClassList &templateTypeConstraints() const; @@ -446,7 +446,7 @@ class ClassDefAliasImpl : public DefinitionAliasMixin { return getCdAlias()->templateMaster(); } virtual bool isTemplate() const { return getCdAlias()->isTemplate(); } - virtual IncludeInfo *includeInfo() const + virtual const IncludeInfo *includeInfo() const { return getCdAlias()->includeInfo(); } virtual const UsesClassList &usedImplementationClasses() const { return getCdAlias()->usedImplementationClasses(); } @@ -589,7 +589,7 @@ class ClassDefImpl::IMPL /*! Include information about the header file should be included * in the documentation. 0 by default, set by setIncludeFile(). */ - IncludeInfo *incInfo = 0; + std::unique_ptr incInfo; /*! List of base class (or super-classes) from which this class derives * directly. @@ -719,7 +719,6 @@ void ClassDefImpl::IMPL::init(const char *defFileName, const char *name, { fileName=ctStr+name; } - incInfo=0; prot=Public; nspace=0; fileDef=0; @@ -758,7 +757,6 @@ ClassDefImpl::IMPL::IMPL() ClassDefImpl::IMPL::~IMPL() { - delete incInfo; } //------------------------------------------------------------------------------------------- @@ -1219,7 +1217,7 @@ void ClassDefImpl::setIncludeFile(FileDef *fd, const char *includeName,bool local, bool force) { //printf("ClassDefImpl::setIncludeFile(%p,%s,%d,%d)\n",fd,includeName,local,force); - if (!m_impl->incInfo) m_impl->incInfo=new IncludeInfo; + if (!m_impl->incInfo) m_impl->incInfo = std::make_unique(); if ((includeName && m_impl->incInfo->includeName.isEmpty()) || (fd!=0 && m_impl->incInfo->fileDef==0) ) @@ -4580,9 +4578,9 @@ bool ClassDefImpl::isTemplate() const return !m_impl->tempArgs.empty(); } -IncludeInfo *ClassDefImpl::includeInfo() const +const IncludeInfo *ClassDefImpl::includeInfo() const { - return m_impl->incInfo; + return m_impl->incInfo.get(); } const UsesClassList &ClassDefImpl::usedImplementationClasses() const diff --git a/src/classdef.h b/src/classdef.h index d745b1d..8e5d628 100644 --- a/src/classdef.h +++ b/src/classdef.h @@ -254,7 +254,7 @@ class ClassDef : public Definition /** Returns TRUE if this class is a template */ virtual bool isTemplate() const = 0; - virtual IncludeInfo *includeInfo() const = 0; + virtual const IncludeInfo *includeInfo() const = 0; virtual const UsesClassList &usedImplementationClasses() const = 0; diff --git a/src/context.cpp b/src/context.cpp index 8378e33..fe7bfa6 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -1765,18 +1765,16 @@ TemplateVariant IncludeInfoContext::get(const char *n) const class IncludeInfoListContext::Private : public GenericNodeListContext { public: - Private(const QList &list,SrcLangExt lang) + Private(const IncludeInfoList &list,SrcLangExt lang) { - QListIterator li(list); - IncludeInfo *ii; - for (li.toFirst();(ii=li.current());++li) + for (const auto &ii : list) { - append(IncludeInfoContext::alloc(ii,lang)); + append(IncludeInfoContext::alloc(&ii,lang)); } } }; -IncludeInfoListContext::IncludeInfoListContext(const QList &list,SrcLangExt lang) : RefCountedContext("IncludeListContext") +IncludeInfoListContext::IncludeInfoListContext(const IncludeInfoList &list,SrcLangExt lang) : RefCountedContext("IncludeListContext") { p = new Private(list,lang); } @@ -3031,10 +3029,10 @@ class FileContext::Private : public DefinitionContext TemplateVariant includeList() const { Cachable &cache = getCache(); - if (!cache.includeInfoList && m_fileDef->includeFileList()) + if (!cache.includeInfoList && !m_fileDef->includeFileList().empty()) { cache.includeInfoList.reset(IncludeInfoListContext::alloc( - *m_fileDef->includeFileList(),m_fileDef->getLanguage())); + m_fileDef->includeFileList(),m_fileDef->getLanguage())); } if (cache.includeInfoList) { diff --git a/src/context.h b/src/context.h index 1a3cfa3..03e502a 100644 --- a/src/context.h +++ b/src/context.h @@ -48,7 +48,10 @@ class DirList; class FileDef; class FileList; + struct IncludeInfo; +class IncludeInfoList; + class MemberList; class MemberDef; struct Argument; @@ -230,7 +233,7 @@ class IncludeInfoContext : public RefCountedContext, public TemplateStructIntf class IncludeInfoListContext : public RefCountedContext, public TemplateListIntf { public: - static IncludeInfoListContext *alloc(const QList &list,SrcLangExt lang) + static IncludeInfoListContext *alloc(const IncludeInfoList &list,SrcLangExt lang) { return new IncludeInfoListContext(list,lang); } // TemplateListIntf @@ -241,7 +244,7 @@ class IncludeInfoListContext : public RefCountedContext, public TemplateListIntf virtual int release() { return RefCountedContext::release(); } private: - IncludeInfoListContext(const QList &list,SrcLangExt lang); + IncludeInfoListContext(const IncludeInfoList &list,SrcLangExt lang); ~IncludeInfoListContext(); class Private; Private *p; diff --git a/src/dirdef.cpp b/src/dirdef.cpp index 73ba4f3..148985b 100644 --- a/src/dirdef.cpp +++ b/src/dirdef.cpp @@ -67,8 +67,8 @@ class DirDefImpl : public DefinitionMixin virtual void sort(); virtual void setParent(DirDef *parent); virtual void setLevel(); - virtual void addUsesDependency(DirDef *usedDir,FileDef *srcFd, - FileDef *dstFd,bool inherited); + virtual void addUsesDependency(const DirDef *usedDir,const FileDef *srcFd, + const FileDef *dstFd,bool inherited); virtual void computeDependencies(); public: @@ -635,8 +635,8 @@ void DirDefImpl::setLevel() /** Add as "uses" dependency between \a this dir and \a dir, * that was caused by a dependency on file \a fd. */ -void DirDefImpl::addUsesDependency(DirDef *dir,FileDef *srcFd, - FileDef *dstFd,bool inherited) +void DirDefImpl::addUsesDependency(const DirDef *dir,const FileDef *srcFd, + const FileDef *dstFd,bool inherited) { if (this==dir) return; // do not add self-dependencies //static int count=0; @@ -699,25 +699,19 @@ void DirDefImpl::computeDependencies() { //printf(" File %s\n",fd->name().data()); //printf("** dir=%s file=%s\n",shortName().data(),fd->name().data()); - QList *ifl = fd->includeFileList(); - if (ifl) + for (const auto &ii : fd->includeFileList()) { - QListIterator ifli(*ifl); - IncludeInfo *ii; - for (ifli.toFirst();(ii=ifli.current());++ifli) // foreach include file + //printf(" > %s\n",ii->includeName.data()); + //printf(" #include %s\n",ii->includeName.data()); + if (ii.fileDef && ii.fileDef->isLinkable()) // linkable file { - //printf(" > %s\n",ii->includeName.data()); - //printf(" #include %s\n",ii->includeName.data()); - if (ii->fileDef && ii->fileDef->isLinkable()) // linkable file + DirDef *usedDir = ii.fileDef->getDirDef(); + if (usedDir) { - DirDef *usedDir = ii->fileDef->getDirDef(); - if (usedDir) - { - // add dependency: thisDir->usedDir - //static int count=0; - //printf(" %d: add dependency %s->%s\n",count++,name().data(),usedDir->name().data()); - addUsesDependency(usedDir,fd,ii->fileDef,FALSE); - } + // add dependency: thisDir->usedDir + //static int count=0; + //printf(" %d: add dependency %s->%s\n",count++,name().data(),usedDir->name().data()); + addUsesDependency(usedDir,fd,ii.fileDef,FALSE); } } } @@ -761,7 +755,7 @@ UsedDir::~UsedDir() { } -void UsedDir::addFileDep(FileDef *srcFd,FileDef *dstFd) +void UsedDir::addFileDep(const FileDef *srcFd,const FileDef *dstFd) { m_filePairs.add(FilePair::key(srcFd,dstFd),std::make_unique(srcFd,dstFd)); } diff --git a/src/dirdef.h b/src/dirdef.h index 78b7929..35bb4fd 100644 --- a/src/dirdef.h +++ b/src/dirdef.h @@ -43,13 +43,13 @@ bool compareDirDefs(const DirDef *item1, const DirDef *item2); class FilePair { public: - FilePair(FileDef *src,FileDef *dst) : m_src(src), m_dst(dst) {} + FilePair(const FileDef *src,const FileDef *dst) : m_src(src), m_dst(dst) {} const FileDef *source() const { return m_src; } const FileDef *destination() const { return m_dst; } static QCString key(const FileDef *srcFd,const FileDef *dstFd); private: - FileDef *m_src; - FileDef *m_dst; + const FileDef *m_src; + const FileDef *m_dst; }; // ------------------ @@ -67,7 +67,7 @@ class UsedDir public: UsedDir(const DirDef *dir,bool inherited); virtual ~UsedDir(); - void addFileDep(FileDef *srcFd,FileDef *dstFd); + void addFileDep(const FileDef *srcFd,const FileDef *dstFd); FilePair *findFilePair(const char *name); const FilePairLinkedMap &filePairs() const { return m_filePairs; } const DirDef *dir() const { return m_dir; } @@ -120,8 +120,8 @@ class DirDef : public DefinitionMutable, public Definition virtual void sort() = 0; virtual void setParent(DirDef *parent) = 0; virtual void setLevel() = 0; - virtual void addUsesDependency(DirDef *usedDir,FileDef *srcFd, - FileDef *dstFd,bool inherited) = 0; + virtual void addUsesDependency(const DirDef *usedDir,const FileDef *srcFd, + const FileDef *dstFd,bool inherited) = 0; virtual void computeDependencies() = 0; }; diff --git a/src/docsets.cpp b/src/docsets.cpp index 091d2c2..4f04623 100644 --- a/src/docsets.cpp +++ b/src/docsets.cpp @@ -463,7 +463,7 @@ void DocSets::addIndexItem(const Definition *context,const MemberDef *md, { type = "cl"; } - IncludeInfo *ii = cd->includeInfo(); + const IncludeInfo *ii = cd->includeInfo(); if (ii) { decl=ii->includeName; diff --git a/src/dotincldepgraph.cpp b/src/dotincldepgraph.cpp index 85f7a51..9dceecb 100644 --- a/src/dotincldepgraph.cpp +++ b/src/dotincldepgraph.cpp @@ -20,60 +20,55 @@ void DotInclDepGraph::buildGraph(DotNode *n,const FileDef *fd,int distance) { - QList *includeFiles = m_inverse ? fd->includedByFileList() : fd->includeFileList(); - if (includeFiles) + const IncludeInfoList &includeFiles = m_inverse ? fd->includedByFileList() : fd->includeFileList(); + for (const auto &ii : includeFiles) { - QListIterator ili(*includeFiles); - IncludeInfo *ii; - for (;(ii=ili.current());++ili) + const FileDef *bfd = ii.fileDef; + QCString in = ii.includeName; + //printf(">>>> in='%s' bfd=%p\n",ii->includeName.data(),bfd); + bool doc=TRUE,src=FALSE; + if (bfd) { - const FileDef *bfd = ii->fileDef; - QCString in = ii->includeName; - //printf(">>>> in='%s' bfd=%p\n",ii->includeName.data(),bfd); - bool doc=TRUE,src=FALSE; - if (bfd) + in = bfd->absFilePath(); + doc = bfd->isLinkable() && !bfd->isHidden(); + src = bfd->generateSourceFile(); + } + if (doc || src || !Config_getBool(HIDE_UNDOC_RELATIONS)) + { + QCString url=""; + if (bfd) url=bfd->getOutputFileBase().copy(); + if (!doc && src) { - in = bfd->absFilePath(); - doc = bfd->isLinkable() && !bfd->isHidden(); - src = bfd->generateSourceFile(); + url=bfd->getSourceFileBase(); } - if (doc || src || !Config_getBool(HIDE_UNDOC_RELATIONS)) + DotNode *bn = m_usedNodes->find(in); + if (bn) // file is already a node in the graph { - QCString url=""; - if (bfd) url=bfd->getOutputFileBase().copy(); - if (!doc && src) - { - url=bfd->getSourceFileBase(); - } - DotNode *bn = m_usedNodes->find(in); - if (bn) // file is already a node in the graph - { - n->addChild(bn,0,0,0); - bn->addParent(n); - bn->setDistance(distance); - } - else + n->addChild(bn,0,0,0); + bn->addParent(n); + bn->setDistance(distance); + } + else + { + QCString tmp_url; + QCString tooltip; + if (bfd) { - QCString tmp_url; - QCString tooltip; - if (bfd) - { - tmp_url=doc || src ? bfd->getReference()+"$"+url : QCString(); - tooltip = bfd->briefDescriptionAsTooltip(); - } - bn = new DotNode(getNextNodeNumber(),// n - ii->includeName, // label - tooltip, // tip - tmp_url, // url - FALSE, // rootNode - 0); // cd - n->addChild(bn,0,0,0); - bn->addParent(n); - m_usedNodes->insert(in,bn); - bn->setDistance(distance); - - if (bfd) buildGraph(bn,bfd,distance+1); + tmp_url=doc || src ? bfd->getReference()+"$"+url : QCString(); + tooltip = bfd->briefDescriptionAsTooltip(); } + bn = new DotNode(getNextNodeNumber(),// n + ii.includeName, // label + tooltip, // tip + tmp_url, // url + FALSE, // rootNode + 0); // cd + n->addChild(bn,0,0,0); + bn->addParent(n); + m_usedNodes->insert(in,bn); + bn->setDistance(distance); + + if (bfd) buildGraph(bn,bfd,distance+1); } } } diff --git a/src/filedef.cpp b/src/filedef.cpp index 0e5ab3f..490b748 100644 --- a/src/filedef.cpp +++ b/src/filedef.cpp @@ -50,6 +50,7 @@ using DefinitionLineMap = std::unordered_map; using MemberDefLineMap = std::unordered_map; +using IncludeInfoMap = std::unordered_map; class FileDefImpl : public DefinitionMixin { @@ -83,8 +84,8 @@ class FileDefImpl : public DefinitionMixin virtual DirDef *getDirDef() const { return m_dir; } virtual LinkedRefMap getUsedNamespaces() const; virtual LinkedRefMap getUsedClasses() const { return m_usingDeclList; } - virtual QList *includeFileList() const { return m_includeList; } - virtual QList *includedByFileList() const { return m_includedByList; } + virtual const IncludeInfoList &includeFileList() const { return m_includeList; } + virtual const IncludeInfoList &includedByFileList() const { return m_includedByList; } virtual void getAllIncludeFilesRecursively(StringVector &incFiles) const; virtual MemberList *getMemberList(MemberListType lt) const; virtual const MemberLists &getMemberLists() const { return m_memberLists; } @@ -120,8 +121,8 @@ class FileDefImpl : public DefinitionMixin virtual void combineUsingRelations(); virtual bool generateSourceFile() const; virtual void sortMemberLists(); - virtual void addIncludeDependency(FileDef *fd,const char *incName,bool local,bool imported); - virtual void addIncludedByDependency(FileDef *fd,const char *incName,bool local,bool imported); + virtual void addIncludeDependency(const FileDef *fd,const char *incName,bool local,bool imported); + virtual void addIncludedByDependency(const FileDef *fd,const char *incName,bool local,bool imported); virtual void addMembersToMemberGroup(); virtual void distributeMemberGroupDocumentation(); virtual void findSectionsInDocumentation(); @@ -151,10 +152,10 @@ class FileDefImpl : public DefinitionMixin void writeBriefDescription(OutputList &ol); void writeClassesToTagFile(FTextStream &t,const ClassLinkedRefMap &list); - QDict *m_includeDict; - QList *m_includeList; - QDict *m_includedByDict; - QList *m_includedByList; + IncludeInfoMap m_includeMap; + IncludeInfoList m_includeList; + IncludeInfoMap m_includedByMap; + IncludeInfoList m_includedByList; LinkedRefMap m_usingDirList; LinkedRefMap m_usingDeclList; QCString m_path; @@ -228,10 +229,6 @@ FileDefImpl::FileDefImpl(const char *p,const char *nm, m_fileName=nm; setReference(lref); setDiskName(dn?dn:nm); - m_includeList = 0; - m_includeDict = 0; - m_includedByList = 0; - m_includedByDict = 0; m_package = 0; m_isSource = guessSection(nm)==Entry::SOURCE_SEC; m_docname = nm; @@ -248,10 +245,6 @@ FileDefImpl::FileDefImpl(const char *p,const char *nm, /*! destroy the file definition */ FileDefImpl::~FileDefImpl() { - delete m_includeDict; - delete m_includeList; - delete m_includedByDict; - delete m_includedByList; } void FileDefImpl::setDiskName(const QCString &name) @@ -320,29 +313,24 @@ void FileDefImpl::writeTagFile(FTextStream &tagFile) tagFile << " " << convertToXML(name()) << "" << endl; tagFile << " " << convertToXML(getPath()) << "" << endl; tagFile << " " << convertToXML(getOutputFileBase()) << Doxygen::htmlFileExtension << "" << endl; - if (m_includeList && m_includeList->count()>0) + for (const auto &ii : m_includeList) { - QListIterator ili(*m_includeList); - IncludeInfo *ii; - for (;(ii=ili.current());++ili) + const FileDef *fd=ii.fileDef; + if (fd && fd->isLinkable() && !fd->isReference()) { - FileDef *fd=ii->fileDef; - if (fd && fd->isLinkable() && !fd->isReference()) - { - bool isIDLorJava = FALSE; - SrcLangExt lang = fd->getLanguage(); - isIDLorJava = lang==SrcLangExt_IDL || lang==SrcLangExt_Java; - const char *locStr = (ii->local || isIDLorJava) ? "yes" : "no"; - const char *impStr = (ii->imported || isIDLorJava) ? "yes" : "no"; - tagFile << " getOutputFileBase()) << "\" " - << "name=\"" << convertToXML(fd->name()) << "\" " - << "local=\"" << locStr << "\" " - << "imported=\"" << impStr << "\">" - << convertToXML(ii->includeName) - << "" - << endl; - } + bool isIDLorJava = FALSE; + SrcLangExt lang = fd->getLanguage(); + isIDLorJava = lang==SrcLangExt_IDL || lang==SrcLangExt_Java; + const char *locStr = (ii.local || isIDLorJava) ? "yes" : "no"; + const char *impStr = (ii.imported || isIDLorJava) ? "yes" : "no"; + tagFile << " getOutputFileBase()) << "\" " + << "name=\"" << convertToXML(fd->name()) << "\" " + << "local=\"" << locStr << "\" " + << "imported=\"" << impStr << "\">" + << convertToXML(ii.includeName) + << "" + << endl; } } for (const auto &lde : LayoutDocManager::instance().docEntries(LayoutDocManager::File)) @@ -540,14 +528,12 @@ void FileDefImpl::writeClassesToTagFile(FTextStream &tagFile, const ClassLinkedR void FileDefImpl::writeIncludeFiles(OutputList &ol) { - if (m_includeList && m_includeList->count()>0) + if (!m_includeList.empty()) { ol.startTextBlock(TRUE); - QListIterator ili(*m_includeList); - IncludeInfo *ii; - for (;(ii=ili.current());++ili) + for (const auto &ii : m_includeList) { - FileDef *fd=ii->fileDef; + const FileDef *fd=ii.fileDef; bool isIDLorJava = FALSE; if (fd) { @@ -559,7 +545,7 @@ void FileDefImpl::writeIncludeFiles(OutputList &ol) { ol.docify("import "); } - else if (ii->imported) // Objective-C include + else if (ii.imported) // Objective-C include { ol.docify("#import "); } @@ -567,12 +553,12 @@ void FileDefImpl::writeIncludeFiles(OutputList &ol) { ol.docify("#include "); } - if (ii->local || isIDLorJava) + if (ii.local || isIDLorJava) ol.docify("\""); else ol.docify("<"); ol.disable(OutputGenerator::Html); - ol.docify(ii->includeName); + ol.docify(ii.includeName); ol.enableAll(); ol.disableAllBut(OutputGenerator::Html); @@ -583,15 +569,15 @@ void FileDefImpl::writeIncludeFiles(OutputList &ol) { ol.writeObjectLink(fd->getReference(), fd->generateSourceFile() ? fd->includeName() : fd->getOutputFileBase(), - 0,ii->includeName); + 0,ii.includeName); } else { - ol.docify(ii->includeName); + ol.docify(ii.includeName); } ol.enableAll(); - if (ii->local || isIDLorJava) + if (ii.local || isIDLorJava) ol.docify("\""); else ol.docify(">"); @@ -1393,25 +1379,14 @@ void FileDefImpl::addUsingDeclaration(const ClassDef *cd) m_usingDeclList.add(cd->qualifiedName(),cd); } -void FileDefImpl::addIncludeDependency(FileDef *fd,const char *incName,bool local,bool imported) +void FileDefImpl::addIncludeDependency(const FileDef *fd,const char *incName,bool local,bool imported) { //printf("FileDefImpl::addIncludeDependency(%p,%s,%d)\n",fd,incName,local); QCString iName = fd ? fd->absFilePath().data() : incName; - if (!iName.isEmpty() && (!m_includeDict || m_includeDict->find(iName)==0)) + if (!iName.isEmpty() && m_includeMap.find(iName.str())==m_includeMap.end()) { - if (m_includeDict==0) - { - m_includeDict = new QDict(61); - m_includeList = new QList; - m_includeList->setAutoDelete(TRUE); - } - IncludeInfo *ii = new IncludeInfo; - ii->fileDef = fd; - ii->includeName = incName; - ii->local = local; - ii->imported = imported; - m_includeList->append(ii); - m_includeDict->insert(iName,ii); + m_includeList.emplace_back(fd,incName,local,imported); + m_includeMap.insert(std::make_pair(iName.str(),&m_includeList.back())); } } @@ -1421,37 +1396,34 @@ void FileDefImpl::addIncludedUsingDirectives(FileDefSet &visitedFiles) visitedFiles.insert(this); //printf("( FileDefImpl::addIncludedUsingDirectives for file %s\n",name().data()); - if (m_includeList) // file contains #includes + if (!m_includeList.empty()) // file contains #includes { { - QListIterator iii(*m_includeList); - IncludeInfo *ii; - for (iii.toFirst();(ii=iii.current());++iii) // foreach #include... + for (const auto &ii : m_includeList) // foreach #include... { - if (ii->fileDef) // ...that is a known file + if (ii.fileDef) // ...that is a known file { // recurse into this file - ii->fileDef->addIncludedUsingDirectives(visitedFiles); + const_cast(ii.fileDef)->addIncludedUsingDirectives(visitedFiles); } } } { - QListIterator iii(*m_includeList); - IncludeInfo *ii; // iterate through list from last to first - for (iii.toLast();(ii=iii.current());--iii) + for (auto ii_it = m_includeList.rbegin(); ii_it!=m_includeList.rend(); ++ii_it) { - if (ii->fileDef && ii->fileDef!=this) + const auto &ii = *ii_it; + if (ii.fileDef && ii.fileDef!=this) { // add using directives - auto unl = ii->fileDef->getUsedNamespaces(); + auto unl = ii.fileDef->getUsedNamespaces(); for (auto it = unl.rbegin(); it!=unl.rend(); ++it) { const auto *nd = *it; m_usingDirList.prepend(nd->qualifiedName(),nd); } // add using declarations - auto udl = ii->fileDef->getUsedClasses(); + auto udl = ii.fileDef->getUsedClasses(); for (auto it = udl.rbegin(); it!=udl.rend(); ++it) { const auto *cd = *it; @@ -1465,33 +1437,22 @@ void FileDefImpl::addIncludedUsingDirectives(FileDefSet &visitedFiles) } -void FileDefImpl::addIncludedByDependency(FileDef *fd,const char *incName, +void FileDefImpl::addIncludedByDependency(const FileDef *fd,const char *incName, bool local,bool imported) { //printf("FileDefImpl::addIncludedByDependency(%p,%s,%d)\n",fd,incName,local); QCString iName = fd ? fd->absFilePath().data() : incName; - if (!iName.isEmpty() && (m_includedByDict==0 || m_includedByDict->find(iName)==0)) + if (!iName.isEmpty() && m_includedByMap.find(iName.str())==m_includedByMap.end()) { - if (m_includedByDict==0) - { - m_includedByDict = new QDict(61); - m_includedByList = new QList; - m_includedByList->setAutoDelete(TRUE); - } - IncludeInfo *ii = new IncludeInfo; - ii->fileDef = fd; - ii->includeName = incName; - ii->local = local; - ii->imported = imported; - m_includedByList->append(ii); - m_includedByDict->insert(iName,ii); + m_includedByList.emplace_back(fd,incName,local,imported); + m_includedByMap.insert(std::make_pair(iName.str(),&m_includedByList.back())); } } bool FileDefImpl::isIncluded(const QCString &name) const { if (name.isEmpty()) return FALSE; - return m_includeDict!=0 && m_includeDict->find(name)!=0; + return m_includeMap.find(name.str())!=m_includeMap.end(); } bool FileDefImpl::generateSourceFile() const @@ -1970,20 +1931,15 @@ bool FileDefImpl::isLinkableInProject() const static void getAllIncludeFilesRecursively( StringUnorderedSet &filesVisited,const FileDef *fd,StringVector &incFiles) { - if (fd->includeFileList()) + for (const auto &ii : fd->includeFileList()) { - QListIterator iii(*fd->includeFileList()); - IncludeInfo *ii; - for (iii.toFirst();(ii=iii.current());++iii) + if (ii.fileDef && !ii.fileDef->isReference() && + filesVisited.find(ii.fileDef->absFilePath().str())==filesVisited.end()) { - if (ii->fileDef && !ii->fileDef->isReference() && - filesVisited.find(ii->fileDef->absFilePath().str())==filesVisited.end()) - { - //printf("FileDefImpl::addIncludeDependency(%s)\n",ii->fileDef->absFilePath().data()); - incFiles.push_back(ii->fileDef->absFilePath().str()); - filesVisited.insert(ii->fileDef->absFilePath().str()); - getAllIncludeFilesRecursively(filesVisited,ii->fileDef,incFiles); - } + //printf("FileDefImpl::addIncludeDependency(%s)\n",ii->fileDef->absFilePath().data()); + incFiles.push_back(ii.fileDef->absFilePath().str()); + filesVisited.insert(ii.fileDef->absFilePath().str()); + getAllIncludeFilesRecursively(filesVisited,ii.fileDef,incFiles); } } } diff --git a/src/filedef.h b/src/filedef.h index b7d8847..6470ec3 100644 --- a/src/filedef.h +++ b/src/filedef.h @@ -49,12 +49,17 @@ using FileDefSet = std::set; /** Class representing the data associated with a \#include statement. */ struct IncludeInfo { - IncludeInfo() : fileDef(0), local(FALSE), imported(FALSE) {} - ~IncludeInfo() {} - FileDef *fileDef; + IncludeInfo() {} + IncludeInfo(const FileDef *fd,const QCString &in,bool loc,bool imp) + : fileDef(fd), includeName(in), local(loc), imported(imp) {} + const FileDef *fileDef = 0; QCString includeName; - bool local; - bool imported; + bool local = false; + bool imported = false; +}; + +class IncludeInfoList : public std::vector +{ }; /** A model of a file symbol. @@ -121,8 +126,8 @@ class FileDef : public DefinitionMutable, public Definition virtual DirDef *getDirDef() const = 0; virtual LinkedRefMap getUsedNamespaces() const = 0; virtual LinkedRefMap getUsedClasses() const = 0; - virtual QList *includeFileList() const = 0; - virtual QList *includedByFileList() const = 0; + virtual const IncludeInfoList &includeFileList() const = 0; + virtual const IncludeInfoList &includedByFileList() const = 0; virtual void getAllIncludeFilesRecursively(StringVector &incFiles) const = 0; virtual MemberList *getMemberList(MemberListType lt) const = 0; @@ -174,8 +179,8 @@ class FileDef : public DefinitionMutable, public Definition virtual bool generateSourceFile() const = 0; virtual void sortMemberLists() = 0; - virtual void addIncludeDependency(FileDef *fd,const char *incName,bool local,bool imported) = 0; - virtual void addIncludedByDependency(FileDef *fd,const char *incName,bool local,bool imported) = 0; + virtual void addIncludeDependency(const FileDef *fd,const char *incName,bool local,bool imported) = 0; + virtual void addIncludedByDependency(const FileDef *fd,const char *incName,bool local,bool imported) = 0; virtual void addMembersToMemberGroup() = 0; virtual void distributeMemberGroupDocumentation() = 0; diff --git a/src/index.cpp b/src/index.cpp index bf6ca03..d7a001d 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -1456,7 +1456,7 @@ static void writeFileIndex(OutputList &ol) { for (const auto &fn : *Doxygen::inputNameLinkedMap) { - for (const auto &fd : *fn) + for (const auto &fd : *fn) { writeSingleFileIndex(ol,fd.get()); } diff --git a/src/perlmodgen.cpp b/src/perlmodgen.cpp index fa23597..f74a003 100644 --- a/src/perlmodgen.cpp +++ b/src/perlmodgen.cpp @@ -1855,7 +1855,7 @@ void PerlModGenerator::generatePerlModForClass(const ClassDef *cd) m_output.closeList(); } - IncludeInfo *ii=cd->includeInfo(); + const IncludeInfo *ii=cd->includeInfo(); if (ii) { QCString nm = ii->includeName; @@ -2005,38 +2005,29 @@ void PerlModGenerator::generatePerlModForFile(const FileDef *fd) m_output.openHash() .addFieldQuotedString("name", fd->name()); - IncludeInfo *inc; m_output.openList("includes"); - if (fd->includeFileList()) + for (const auto &inc: fd->includeFileList()) { - QListIterator ili1(*fd->includeFileList()); - for (ili1.toFirst();(inc=ili1.current());++ili1) + m_output.openHash() + .addFieldQuotedString("name", inc.includeName); + if (inc.fileDef && !inc.fileDef->isReference()) { - m_output.openHash() - .addFieldQuotedString("name", inc->includeName); - if (inc->fileDef && !inc->fileDef->isReference()) - { - m_output.addFieldQuotedString("ref", inc->fileDef->getOutputFileBase()); - } - m_output.closeHash(); + m_output.addFieldQuotedString("ref", inc.fileDef->getOutputFileBase()); } + m_output.closeHash(); } m_output.closeList(); m_output.openList("included_by"); - if (fd->includedByFileList()) + for (const auto &inc : fd->includedByFileList()) { - QListIterator ili2(*fd->includedByFileList()); - for (ili2.toFirst();(inc=ili2.current());++ili2) + m_output.openHash() + .addFieldQuotedString("name", inc.includeName); + if (inc.fileDef && !inc.fileDef->isReference()) { - m_output.openHash() - .addFieldQuotedString("name", inc->includeName); - if (inc->fileDef && !inc->fileDef->isReference()) - { - m_output.addFieldQuotedString("ref", inc->fileDef->getOutputFileBase()); - } - m_output.closeHash(); + m_output.addFieldQuotedString("ref", inc.fileDef->getOutputFileBase()); } + m_output.closeHash(); } m_output.closeList(); diff --git a/src/sqlite3gen.cpp b/src/sqlite3gen.cpp index f59e3fa..def249a 100644 --- a/src/sqlite3gen.cpp +++ b/src/sqlite3gen.cpp @@ -1940,7 +1940,7 @@ static void generateSqlite3ForClass(const ClassDef *cd) other values if there's a solid heuristic for *when a class will have a header file*. */ - IncludeInfo *ii=cd->includeInfo(); + const IncludeInfo *ii=cd->includeInfo(); if (ii) { QCString nm = ii->includeName; @@ -2113,97 +2113,88 @@ static void generateSqlite3ForFile(const FileDef *fd) step(compounddef_insert); // + includes files - IncludeInfo *ii; - if (fd->includeFileList()) + for (const auto &ii : fd->includeFileList()) { - QListIterator ili(*fd->includeFileList()); - for (ili.toFirst();(ii=ili.current());++ili) - { - int src_id=insertPath(fd->absFilePath(),!fd->isReference()); - int dst_id; - QCString dst_path; + int src_id=insertPath(fd->absFilePath(),!fd->isReference()); + int dst_id; + QCString dst_path; - if(ii->fileDef) // found file + if(ii.fileDef) // found file + { + if(ii.fileDef->isReference()) { - if(ii->fileDef->isReference()) - { - // strip tagfile from path - QCString tagfile = ii->fileDef->getReference(); - dst_path = ii->fileDef->absFilePath().copy(); - dst_path.stripPrefix(tagfile+":"); - } - else - { - dst_path = ii->fileDef->absFilePath(); - } - dst_id = insertPath(dst_path,ii->local); + // strip tagfile from path + QCString tagfile = ii.fileDef->getReference(); + dst_path = ii.fileDef->absFilePath().copy(); + dst_path.stripPrefix(tagfile+":"); } - else // can't find file + else { - dst_id = insertPath(ii->includeName,ii->local,FALSE); + dst_path = ii.fileDef->absFilePath(); } + dst_id = insertPath(dst_path,ii.local); + } + else // can't find file + { + dst_id = insertPath(ii.includeName,ii.local,FALSE); + } - DBG_CTX(("-----> FileDef includeInfo for %s\n", ii->includeName.data())); - DBG_CTX((" local: %d\n", ii->local)); - DBG_CTX((" imported: %d\n", ii->imported)); - if(ii->fileDef) - { - DBG_CTX(("include: %s\n", ii->fileDef->absFilePath().data())); - } - DBG_CTX((" src_id : %d\n", src_id)); - DBG_CTX((" dst_id: %d\n", dst_id)); - - bindIntParameter(incl_select,":local",ii->local); - bindIntParameter(incl_select,":src_id",src_id); - bindIntParameter(incl_select,":dst_id",dst_id); - if (step(incl_select,TRUE,TRUE)==0) { - bindIntParameter(incl_insert,":local",ii->local); - bindIntParameter(incl_insert,":src_id",src_id); - bindIntParameter(incl_insert,":dst_id",dst_id); - step(incl_insert); - } + DBG_CTX(("-----> FileDef includeInfo for %s\n", ii.includeName.data())); + DBG_CTX((" local: %d\n", ii.local)); + DBG_CTX((" imported: %d\n", ii.imported)); + if(ii.fileDef) + { + DBG_CTX(("include: %s\n", ii.fileDef->absFilePath().data())); + } + DBG_CTX((" src_id : %d\n", src_id)); + DBG_CTX((" dst_id: %d\n", dst_id)); + + bindIntParameter(incl_select,":local",ii.local); + bindIntParameter(incl_select,":src_id",src_id); + bindIntParameter(incl_select,":dst_id",dst_id); + if (step(incl_select,TRUE,TRUE)==0) { + bindIntParameter(incl_insert,":local",ii.local); + bindIntParameter(incl_insert,":src_id",src_id); + bindIntParameter(incl_insert,":dst_id",dst_id); + step(incl_insert); } } // + includedby files - if (fd->includedByFileList()) + for (const auto &ii : fd->includedByFileList()) { - QListIterator ili(*fd->includedByFileList()); - for (ili.toFirst();(ii=ili.current());++ili) - { - int dst_id=insertPath(fd->absFilePath(),!fd->isReference()); - int src_id; - QCString src_path; + int dst_id=insertPath(fd->absFilePath(),!fd->isReference()); + int src_id; + QCString src_path; - if(ii->fileDef) // found file + if(ii.fileDef) // found file + { + if(ii.fileDef->isReference()) { - if(ii->fileDef->isReference()) - { - // strip tagfile from path - QCString tagfile = ii->fileDef->getReference(); - src_path = ii->fileDef->absFilePath().copy(); - src_path.stripPrefix(tagfile+":"); - } - else - { - src_path = ii->fileDef->absFilePath(); - } - src_id = insertPath(src_path,ii->local); + // strip tagfile from path + QCString tagfile = ii.fileDef->getReference(); + src_path = ii.fileDef->absFilePath().copy(); + src_path.stripPrefix(tagfile+":"); } - else // can't find file + else { - src_id = insertPath(ii->includeName,ii->local,FALSE); + src_path = ii.fileDef->absFilePath(); } + src_id = insertPath(src_path,ii.local); + } + else // can't find file + { + src_id = insertPath(ii.includeName,ii.local,FALSE); + } - bindIntParameter(incl_select,":local",ii->local); - bindIntParameter(incl_select,":src_id",src_id); - bindIntParameter(incl_select,":dst_id",dst_id); - if (step(incl_select,TRUE,TRUE)==0) { - bindIntParameter(incl_insert,":local",ii->local); - bindIntParameter(incl_insert,":src_id",src_id); - bindIntParameter(incl_insert,":dst_id",dst_id); - step(incl_insert); - } + bindIntParameter(incl_select,":local",ii.local); + bindIntParameter(incl_select,":src_id",src_id); + bindIntParameter(incl_select,":dst_id",dst_id); + if (step(incl_select,TRUE,TRUE)==0) { + bindIntParameter(incl_insert,":local",ii.local); + bindIntParameter(incl_insert,":src_id",src_id); + bindIntParameter(incl_insert,":dst_id",dst_id); + step(incl_insert); } } diff --git a/src/xmlgen.cpp b/src/xmlgen.cpp index 57e63f0..61fba77 100644 --- a/src/xmlgen.cpp +++ b/src/xmlgen.cpp @@ -1321,7 +1321,7 @@ static void generateXMLForClass(const ClassDef *cd,FTextStream &ti) << "" << endl; } - IncludeInfo *ii=cd->includeInfo(); + const IncludeInfo *ii=cd->includeInfo(); if (ii) { QCString nm = ii->includeName; @@ -1510,38 +1510,28 @@ static void generateXMLForFile(FileDef *fd,FTextStream &ti) writeXMLString(t,fd->name()); t << "" << endl; - IncludeInfo *inc; - - if (fd->includeFileList()) + for (const auto &inc : fd->includeFileList()) { - QListIterator ili1(*fd->includeFileList()); - for (ili1.toFirst();(inc=ili1.current());++ili1) + t << " isReference()) // TODO: support external references { - t << " fileDef && !inc->fileDef->isReference()) // TODO: support external references - { - t << " refid=\"" << inc->fileDef->getOutputFileBase() << "\""; - } - t << " local=\"" << (inc->local ? "yes" : "no") << "\">"; - t << inc->includeName; - t << "" << endl; + t << " refid=\"" << inc.fileDef->getOutputFileBase() << "\""; } + t << " local=\"" << (inc.local ? "yes" : "no") << "\">"; + t << inc.includeName; + t << "" << endl; } - if (fd->includedByFileList()) + for (const auto &inc : fd->includedByFileList()) { - QListIterator ili2(*fd->includedByFileList()); - for (ili2.toFirst();(inc=ili2.current());++ili2) + t << " isReference()) // TODO: support external references { - t << " fileDef && !inc->fileDef->isReference()) // TODO: support external references - { - t << " refid=\"" << inc->fileDef->getOutputFileBase() << "\""; - } - t << " local=\"" << (inc->local ? "yes" : "no") << "\">"; - t << inc->includeName; - t << "" << endl; + t << " refid=\"" << inc.fileDef->getOutputFileBase() << "\""; } + t << " local=\"" << (inc.local ? "yes" : "no") << "\">"; + t << inc.includeName; + t << "" << endl; } DotInclDepGraph incDepGraph(fd,FALSE); -- cgit v0.12