From 9c7f8b12d0af44b8e4cee42e68fd5553563231a1 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sat, 1 May 2021 13:51:57 +0200 Subject: Cleanup util.h by moving some functions to other files --- src/classdef.cpp | 113 ++++++++++++++++++++ src/classdef.h | 13 +++ src/conceptdef.cpp | 22 ++++ src/conceptdef.h | 10 ++ src/dotgfxhierarchytable.cpp | 1 + src/htags.cpp | 1 + src/language.cpp | 1 + src/namespacedef.cpp | 104 +++++++++++++++++++ src/namespacedef.h | 11 ++ src/plantuml.cpp | 1 + src/translator.h | 1 - src/util.cpp | 240 +------------------------------------------ src/util.h | 39 +------ 13 files changed, 282 insertions(+), 275 deletions(-) diff --git a/src/classdef.cpp b/src/classdef.cpp index 152c316..9f2fe12 100644 --- a/src/classdef.cpp +++ b/src/classdef.cpp @@ -4950,3 +4950,116 @@ ClassDefMutable *toClassDefMutable(const Definition *d) } +// --- Helpers + +/*! Get a class definition given its name. + * Returns 0 if the class is not found. + */ +ClassDef *getClass(const QCString &n) +{ + if (n.isEmpty()) return 0; + return Doxygen::classLinkedMap->find(n); +} + +bool hasVisibleRoot(const BaseClassList &bcl) +{ + for (const auto &bcd : bcl) + { + const ClassDef *cd=bcd.classDef; + if (cd->isVisibleInHierarchy()) return true; + if (hasVisibleRoot(cd->baseClasses())) return true; + } + return false; +} + +bool classHasVisibleChildren(const ClassDef *cd) +{ + BaseClassList bcl; + + if (cd->getLanguage()==SrcLangExt_VHDL) // reverse baseClass/subClass relation + { + if (cd->baseClasses().empty()) return FALSE; + bcl=cd->baseClasses(); + } + else + { + if (cd->subClasses().empty()) return FALSE; + bcl=cd->subClasses(); + } + + for (const auto &bcd : bcl) + { + if (bcd.classDef->isVisibleInHierarchy()) + { + return TRUE; + } + } + return FALSE; +} + +bool classVisibleInIndex(const ClassDef *cd) +{ + bool allExternals = Config_getBool(ALLEXTERNALS); + return (allExternals && cd->isLinkable()) || cd->isLinkableInProject(); +} + +//---------------------------------------------------------------------- +// recursive function that returns the number of branches in the +// inheritance tree that the base class 'bcd' is below the class 'cd' + +int minClassDistance(const ClassDef *cd,const ClassDef *bcd,int level) +{ + const int maxInheritanceDepth = 100000; + if (bcd->categoryOf()) // use class that is being extended in case of + // an Objective-C category + { + bcd=bcd->categoryOf(); + } + if (cd==bcd) return level; + if (level==256) + { + warn_uncond("class %s seem to have a recursive " + "inheritance relation!\n",qPrint(cd->name())); + return -1; + } + int m=maxInheritanceDepth; + for (const auto &bcdi : cd->baseClasses()) + { + int mc=minClassDistance(bcdi.classDef,bcd,level+1); + if (mccategoryOf()) // use class that is being extended in case of + // an Objective-C category + { + bcd=bcd->categoryOf(); + } + if (cd==bcd) + { + goto exit; + } + if (level==256) + { + err("Internal inconsistency: found class %s seem to have a recursive " + "inheritance relation! Please send a bug report to doxygen@gmail.com\n",qPrint(cd->name())); + } + else if (prot!=Private) + { + for (const auto &bcdi : cd->baseClasses()) + { + Protection baseProt = classInheritedProtectionLevel(bcdi.classDef,bcd,bcdi.prot,level+1); + if (baseProt==Private) prot=Private; + else if (baseProt==Protected) prot=Protected; + } + } +exit: + //printf("classInheritedProtectionLevel(%s,%s)=%d\n",qPrint(cd->name()),qPrint(bcd->name()),prot); + return prot; +} + + diff --git a/src/classdef.h b/src/classdef.h index 2c8f870..c1c66b5 100644 --- a/src/classdef.h +++ b/src/classdef.h @@ -479,6 +479,19 @@ const ClassDef *toClassDef(const Definition *d); ClassDefMutable *toClassDefMutable(Definition *d); ClassDefMutable *toClassDefMutable(const Definition *d); +// --- Helpers +// +ClassDef *getClass(const QCString &key); +inline ClassDefMutable *getClassMutable(const QCString &key) +{ + return toClassDefMutable(getClass(key)); +} +bool hasVisibleRoot(const BaseClassList &bcl); +bool classHasVisibleChildren(const ClassDef *cd); +bool classVisibleInIndex(const ClassDef *cd); +int minClassDistance(const ClassDef *cd,const ClassDef *bcd,int level=0); +Protection classInheritedProtectionLevel(const ClassDef *cd,const ClassDef *bcd,Protection prot=Public,int level=0); + //------------------------------------------------------------------------ /** Class that contains information about a usage relation. diff --git a/src/conceptdef.cpp b/src/conceptdef.cpp index b9dd085..3047f4a 100644 --- a/src/conceptdef.cpp +++ b/src/conceptdef.cpp @@ -23,6 +23,8 @@ #include "searchindex.h" #include "message.h" #include "parserintf.h" +#include "layout.h" +#include "namespacedef.h" //------------------------------------------------------------------------------------ @@ -729,5 +731,25 @@ ConceptDefMutable *toConceptDefMutable(const Definition *d) } } +// -- helpers + +ConceptDef *getConcept(const QCString &n) +{ + if (n.isEmpty()) return 0; + return Doxygen::conceptLinkedMap->find(n); +} + +ConceptDef *getResolvedConcept(const Definition *d,const QCString &name) +{ + ConceptDef *cd=0; + while (d && d!=Doxygen::globalScope) + { + cd = getConcept(d->name()+"::"+name); + if (cd) return cd; + d = d->getOuterScope(); + } + cd = getConcept(name); + return cd; +} diff --git a/src/conceptdef.h b/src/conceptdef.h index 9a2075c..82f097f 100644 --- a/src/conceptdef.h +++ b/src/conceptdef.h @@ -79,4 +79,14 @@ const ConceptDef *toConceptDef(const Definition *d); ConceptDefMutable *toConceptDefMutable(Definition *d); ConceptDefMutable *toConceptDefMutable(const Definition *d); +// --- Helpers + +ConceptDef *getConcept(const QCString &key); +inline ConceptDefMutable *getConceptMutable(const QCString &key) +{ + return toConceptDefMutable(getConcept(key)); +} +ConceptDef *getResolvedConcept(const Definition *scope,const QCString &name); + + #endif diff --git a/src/dotgfxhierarchytable.cpp b/src/dotgfxhierarchytable.cpp index f7b95d9..025e7cb 100644 --- a/src/dotgfxhierarchytable.cpp +++ b/src/dotgfxhierarchytable.cpp @@ -22,6 +22,7 @@ #include "doxygen.h" #include "classlist.h" #include "dir.h" +#include "vhdldocgen.h" QCString DotGfxHierarchyTable::getBaseName() const { diff --git a/src/htags.cpp b/src/htags.cpp index cb7b99c..03a8686 100644 --- a/src/htags.cpp +++ b/src/htags.cpp @@ -24,6 +24,7 @@ #include "config.h" #include "portable.h" #include "fileinfo.h" +#include "dir.h" bool Htags::useHtags = FALSE; diff --git a/src/language.cpp b/src/language.cpp index af2ca3d..c7cf204 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -20,6 +20,7 @@ #include "util.h" #include "language.h" #include "lang_cfg.h" +#include "vhdldocgen.h" #include "translator.h" #include "translator_en.h" #if !defined(ENGLISH_ONLY) diff --git a/src/namespacedef.cpp b/src/namespacedef.cpp index db855ba..fee5dc9 100644 --- a/src/namespacedef.cpp +++ b/src/namespacedef.cpp @@ -1596,3 +1596,107 @@ NamespaceDefMutable *toNamespaceDefMutable(const Definition *d) } } +// --- Helpers + + +NamespaceDef *getResolvedNamespace(const QCString &name) +{ + if (name.isEmpty()) return 0; + auto it = Doxygen::namespaceAliasMap.find(name.str()); + if (it!=Doxygen::namespaceAliasMap.end()) + { + int count=0; // recursion detection guard + StringUnorderedMap::iterator it2; + while ((it2=Doxygen::namespaceAliasMap.find(it->second))!=Doxygen::namespaceAliasMap.end() && + count<10) + { + it=it2; + count++; + } + if (count==10) + { + warn_uncond("possible recursive namespace alias detected for %s!\n",qPrint(name)); + } + return Doxygen::namespaceLinkedMap->find(it->second); + } + else + { + return Doxygen::namespaceLinkedMap->find(name); + } +} + +//-------------------------------------------------------------------------------------- +// +bool namespaceHasNestedNamespace(const NamespaceDef *nd) +{ + for (const auto &cnd : nd->getNamespaces()) + { + if (cnd->isLinkableInProject() && !cnd->isAnonymous()) + { + return true; + } + } + return false; +} + +bool namespaceHasNestedConcept(const NamespaceDef *nd) +{ + for (const auto &cnd : nd->getNamespaces()) + { + if (namespaceHasNestedConcept(cnd)) + { + //printf("name()),includeClasses); + return true; + } + } + for (const auto &cnd : nd->getConcepts()) + { + if (cnd->isLinkableInProject()) + { + return true; + } + } + return false; +} + +bool namespaceHasNestedClass(const NamespaceDef *nd,bool filterClasses,ClassDef::CompoundType ct) +{ + //printf(">namespaceHasVisibleChild(%s,includeClasses=%d)\n",qPrint(nd->name()),includeClasses); + for (const auto &cnd : nd->getNamespaces()) + { + if (namespaceHasNestedClass(cnd,filterClasses,ct)) + { + //printf("name()),includeClasses); + return TRUE; + } + } + + ClassLinkedRefMap list = nd->getClasses(); + if (filterClasses) + { + if (ct == ClassDef::Interface) + { + list = nd->getInterfaces(); + } + else if (ct == ClassDef::Struct) + { + list = nd->getStructs(); + } + else if (ct == ClassDef::Exception) + { + list = nd->getExceptions(); + } + } + + for (const auto &cd : list) + { + if (cd->isLinkableInProject() && cd->templateMaster()==0) + { + //printf("name()),includeClasses); + return TRUE; + } + } + return FALSE; +} + + diff --git a/src/namespacedef.h b/src/namespacedef.h index 93fff75..3c80470 100644 --- a/src/namespacedef.h +++ b/src/namespacedef.h @@ -151,6 +151,17 @@ const NamespaceDef *toNamespaceDef(const Definition *d); NamespaceDefMutable *toNamespaceDefMutable(Definition *d); NamespaceDefMutable *toNamespaceDefMutable(const Definition *d); +// --- Helpers + +NamespaceDef *getResolvedNamespace(const QCString &key); +inline NamespaceDefMutable *getResolvedNamespaceMutable(const QCString &key) +{ + return toNamespaceDefMutable(getResolvedNamespace(key)); +} +bool namespaceHasNestedNamespace(const NamespaceDef *nd); +bool namespaceHasNestedConcept(const NamespaceDef *nd); +bool namespaceHasNestedClass(const NamespaceDef *nd,bool filterClasses,ClassDef::CompoundType ct); + //------------------------------------------------------------------------ #endif diff --git a/src/plantuml.cpp b/src/plantuml.cpp index 81f7df8..a88289a 100644 --- a/src/plantuml.cpp +++ b/src/plantuml.cpp @@ -21,6 +21,7 @@ #include "message.h" #include "debug.h" #include "fileinfo.h" +#include "dir.h" QCString PlantumlManager::writePlantUMLSource(const QCString &outDirArg,const QCString &fileName,const QCString &content,OutputFormat format) { diff --git a/src/translator.h b/src/translator.h index 02f2ccf..e7372d2 100644 --- a/src/translator.h +++ b/src/translator.h @@ -20,7 +20,6 @@ #include "classdef.h" #include "config.h" -#include "vhdldocgen.h" /** Abstract base class for all translatable text fragments. */ class Translator diff --git a/src/util.cpp b/src/util.cpp index 75e82f0..f2d06ee 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -483,62 +483,6 @@ QCString resolveTypeDef(const Definition *context,const QCString &qualifiedName, } - -/*! Get a class definition given its name. - * Returns 0 if the class is not found. - */ -ClassDef *getClass(const QCString &n) -{ - if (n.isEmpty()) return 0; - return Doxygen::classLinkedMap->find(n); -} - - -ConceptDef *getConcept(const QCString &n) -{ - if (n.isEmpty()) return 0; - return Doxygen::conceptLinkedMap->find(n); -} - -ConceptDef *getResolvedConcept(const Definition *d,const QCString &name) -{ - ConceptDef *cd=0; - while (d && d!=Doxygen::globalScope) - { - cd = getConcept(d->name()+"::"+name); - if (cd) return cd; - d = d->getOuterScope(); - } - cd = getConcept(name); - return cd; -} - -NamespaceDef *getResolvedNamespace(const QCString &name) -{ - if (name.isEmpty()) return 0; - auto it = Doxygen::namespaceAliasMap.find(name.str()); - if (it!=Doxygen::namespaceAliasMap.end()) - { - int count=0; // recursion detection guard - StringUnorderedMap::iterator it2; - while ((it2=Doxygen::namespaceAliasMap.find(it->second))!=Doxygen::namespaceAliasMap.end() && - count<10) - { - it=it2; - count++; - } - if (count==10) - { - warn_uncond("possible recursive namespace alias detected for %s!\n",qPrint(name)); - } - return Doxygen::namespaceLinkedMap->find(it->second); - } - else - { - return Doxygen::namespaceLinkedMap->find(name); - } -} - int computeQualifiedIndex(const QCString &name) { int i = name.find('<'); @@ -1280,7 +1224,7 @@ QCString tempArgListToString(const ArgumentList &al,SrcLangExt lang,bool include * converted content (i.e. the same as \a len (Unix, MAC) or * smaller (DOS). */ -int filterCRLF(char *buf,int len) +static int filterCRLF(char *buf,int len) { int src = 0; // source index int dest = 0; // destination index @@ -1519,64 +1463,6 @@ QCString yearToString() return QCString().setNum(current.tm_year+1900); } -//---------------------------------------------------------------------- -// recursive function that returns the number of branches in the -// inheritance tree that the base class 'bcd' is below the class 'cd' - -int minClassDistance(const ClassDef *cd,const ClassDef *bcd,int level) -{ - if (bcd->categoryOf()) // use class that is being extended in case of - // an Objective-C category - { - bcd=bcd->categoryOf(); - } - if (cd==bcd) return level; - if (level==256) - { - warn_uncond("class %s seem to have a recursive " - "inheritance relation!\n",qPrint(cd->name())); - return -1; - } - int m=maxInheritanceDepth; - for (const auto &bcdi : cd->baseClasses()) - { - int mc=minClassDistance(bcdi.classDef,bcd,level+1); - if (mccategoryOf()) // use class that is being extended in case of - // an Objective-C category - { - bcd=bcd->categoryOf(); - } - if (cd==bcd) - { - goto exit; - } - if (level==256) - { - err("Internal inconsistency: found class %s seem to have a recursive " - "inheritance relation! Please send a bug report to doxygen@gmail.com\n",qPrint(cd->name())); - } - else if (prot!=Private) - { - for (const auto &bcdi : cd->baseClasses()) - { - Protection baseProt = classInheritedProtectionLevel(bcdi.classDef,bcd,bcdi.prot,level+1); - if (baseProt==Private) prot=Private; - else if (baseProt==Protected) prot=Protected; - } - } -exit: - //printf("classInheritedProtectionLevel(%s,%s)=%d\n",qPrint(cd->name()),qPrint(bcd->name()),prot); - return prot; -} - void trimBaseClassScope(const BaseClassList &bcl,QCString &s,int level=0) { //printf("trimBaseClassScope level=%d '%s'\n",level,qPrint(s)); @@ -3465,44 +3351,6 @@ int getPrefixIndex(const QCString &name) //---------------------------------------------------------------------------- -bool classHasVisibleChildren(const ClassDef *cd) -{ - BaseClassList bcl; - - if (cd->getLanguage()==SrcLangExt_VHDL) // reverse baseClass/subClass relation - { - if (cd->baseClasses().empty()) return FALSE; - bcl=cd->baseClasses(); - } - else - { - if (cd->subClasses().empty()) return FALSE; - bcl=cd->subClasses(); - } - - for (const auto &bcd : bcl) - { - if (bcd.classDef->isVisibleInHierarchy()) - { - return TRUE; - } - } - return FALSE; -} - -//---------------------------------------------------------------------------- - -bool hasVisibleRoot(const BaseClassList &bcl) -{ - for (const auto &bcd : bcl) - { - const ClassDef *cd=bcd.classDef; - if (cd->isVisibleInHierarchy()) return true; - if (hasVisibleRoot(cd->baseClasses())) return true; - } - return false; -} - //---------------------------------------------------------------------- #if 0 @@ -5333,9 +5181,9 @@ QCString rtfFormatBmkStr(const QCString &name) return tag; } -bool checkExtension(const char *fName, const char *ext) +bool checkExtension(const QCString &fName, const QCString &ext) { - return (QCString(fName).right(QCString(ext).length())==ext); + return fName.right(ext.length())==ext; } QCString addHtmlExtensionIfMissing(const QCString &fName) @@ -6827,88 +6675,6 @@ uint getUtf8CodeToUpper( const QCString& s, int idx ) -//-------------------------------------------------------------------------------------- -// -bool namespaceHasNestedNamespace(const NamespaceDef *nd) -{ - for (const auto &cnd : nd->getNamespaces()) - { - if (cnd->isLinkableInProject() && !cnd->isAnonymous()) - { - return true; - } - } - return false; -} - -bool namespaceHasNestedConcept(const NamespaceDef *nd) -{ - for (const auto &cnd : nd->getNamespaces()) - { - if (namespaceHasNestedConcept(cnd)) - { - //printf("name()),includeClasses); - return true; - } - } - for (const auto &cnd : nd->getConcepts()) - { - if (cnd->isLinkableInProject()) - { - return true; - } - } - return false; -} - -bool namespaceHasNestedClass(const NamespaceDef *nd,bool filterClasses,ClassDef::CompoundType ct) -{ - //printf(">namespaceHasVisibleChild(%s,includeClasses=%d)\n",qPrint(nd->name()),includeClasses); - for (const auto &cnd : nd->getNamespaces()) - { - if (namespaceHasNestedClass(cnd,filterClasses,ct)) - { - //printf("name()),includeClasses); - return TRUE; - } - } - - ClassLinkedRefMap list = nd->getClasses(); - if (filterClasses) - { - if (ct == ClassDef::Interface) - { - list = nd->getInterfaces(); - } - else if (ct == ClassDef::Struct) - { - list = nd->getStructs(); - } - else if (ct == ClassDef::Exception) - { - list = nd->getExceptions(); - } - } - - for (const auto &cd : list) - { - if (cd->isLinkableInProject() && cd->templateMaster()==0) - { - //printf("name()),includeClasses); - return TRUE; - } - } - return FALSE; -} - -//---------------------------------------------------------------------------- - -bool classVisibleInIndex(const ClassDef *cd) -{ - static bool allExternals = Config_getBool(ALLEXTERNALS); - return (allExternals && cd->isLinkable()) || cd->isLinkableInProject(); -} - //---------------------------------------------------------------------------- /** Strip the direction part from docs and return it as a string in canonical form diff --git a/src/util.h b/src/util.h index 3034c23..aaa240c 100644 --- a/src/util.h +++ b/src/util.h @@ -29,13 +29,9 @@ #include #include "types.h" #include "docparser.h" -#include "classdef.h" -#include "arguments.h" #include "containers.h" -#include "namespacedef.h" #include "outputgen.h" #include "regex.h" -#include "dir.h" #include "conceptdef.h" //-------------------------------------------------------------------- @@ -56,6 +52,7 @@ class SectionInfo; class Definition; class BufStr; class FileInfo; +class Dir; //-------------------------------------------------------------------- @@ -140,9 +137,6 @@ bool resolveLink(/* in */ const QCString &scName, /* out */ QCString &resAnchor ); -//bool generateRef(OutputDocInterface &od,const char *, -// const char *,bool inSeeBlock,const char * =0); - bool generateLink(OutputDocInterface &od,const QCString &, const QCString &,bool inSeeBlock,const QCString &); @@ -167,23 +161,6 @@ QCString clearBlock(const char *s,const char *begin,const char *end); QCString selectBlock(const QCString& s,const QCString &name,bool enable, OutputGenerator::OutputType o); QCString removeEmptyLines(const QCString &s); -ClassDef *getClass(const QCString &key); -inline ClassDefMutable *getClassMutable(const QCString &key) -{ - return toClassDefMutable(getClass(key)); -} -ConceptDef *getConcept(const QCString &key); -inline ConceptDefMutable *getConceptMutable(const QCString &key) -{ - return toConceptDefMutable(getConcept(key)); -} -ConceptDef *getResolvedConcept(const Definition *scope,const QCString &name); - -NamespaceDef *getResolvedNamespace(const QCString &key); -inline NamespaceDefMutable *getResolvedNamespaceMutable(const QCString &key) -{ - return toNamespaceDefMutable(getResolvedNamespace(key)); -} FileDef *findFileDef(const FileNameLinkedMap *fnMap,const QCString &n, bool &ambig); @@ -230,16 +207,6 @@ QCString removeAnonymousScopes(const QCString &s); QCString replaceAnonymousScopes(const QCString &s,const QCString &replacement=QCString()); -bool hasVisibleRoot(const BaseClassList &bcl); -bool classHasVisibleChildren(const ClassDef *cd); -bool namespaceHasNestedNamespace(const NamespaceDef *nd); -bool namespaceHasNestedConcept(const NamespaceDef *nd); -bool namespaceHasNestedClass(const NamespaceDef *nd,bool filterClasses,ClassDef::CompoundType ct); -bool classVisibleInIndex(const ClassDef *cd); - -int minClassDistance(const ClassDef *cd,const ClassDef *bcd,int level=0); -Protection classInheritedProtectionLevel(const ClassDef *cd,const ClassDef *bcd,Protection prot=Public,int level=0); - QCString convertNameToFile(const QCString &name,bool allowDots=FALSE,bool allowUnderscore=FALSE); void extractNamespaceName(const QCString &scopeName, @@ -295,8 +262,6 @@ QCString mergeScopes(const QCString &leftScope,const QCString &rightScope); int getScopeFragment(const QCString &s,int p,int *l); -int filterCRLF(char *buf,int len); - void addRefItem(const RefItemVector &sli, const QCString &key, const QCString &prefix, @@ -339,7 +304,7 @@ QCString rtfFormatBmkStr(const QCString &name); QCString linkToText(SrcLangExt lang,const QCString &link,bool isFileName); -bool checkExtension(const char *fName, const char *ext); +bool checkExtension(const QCString &fName, const QCString &ext); QCString addHtmlExtensionIfMissing(const QCString &fName); -- cgit v0.12