From 4372054e0b7af9c0cd1c1390859d8fef3581d8bb Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Wed, 2 Dec 2020 19:49:52 +0100 Subject: Improve handling of inline namespace members in LateX/RTF output --- src/classdef.cpp | 206 +++++++++++++++++++++------------------ src/definition.cpp | 26 ++++- src/definition.h | 2 +- src/definitionimpl.h | 23 +++-- src/docbookgen.cpp | 4 +- src/doxygen.cpp | 1 + src/filedef.cpp | 4 +- src/filedef.h | 2 +- src/latexgen.cpp | 4 +- src/memberdef.cpp | 8 +- src/namespacedef.cpp | 31 +++--- src/rtfgen.cpp | 4 +- testing/057/namespacelibrary.xml | 4 +- 13 files changed, 190 insertions(+), 129 deletions(-) diff --git a/src/classdef.cpp b/src/classdef.cpp index 98cfc86..9586731 100644 --- a/src/classdef.cpp +++ b/src/classdef.cpp @@ -54,6 +54,109 @@ //----------------------------------------------------------------------------- +static QCString makeQualifiedNameWithTemplateParameters(const ClassDef *cd, + const ArgumentLists *actualParams,uint *actualParamIndex) +{ + //static bool optimizeOutputJava = Config_getBool(OPTIMIZE_OUTPUT_JAVA); + bool hideScopeNames = Config_getBool(HIDE_SCOPE_NAMES); + //printf("qualifiedNameWithTemplateParameters() localName=%s\n",localName().data()); + QCString scName; + const Definition *d=cd->getOuterScope(); + if (d) + { + if (d->definitionType()==Definition::TypeClass) + { + const ClassDef *ocd=toClassDef(d); + scName = ocd->qualifiedNameWithTemplateParameters(actualParams,actualParamIndex); + } + else if (!hideScopeNames) + { + scName = d->qualifiedName(); + } + } + + SrcLangExt lang = cd->getLanguage(); + QCString scopeSeparator = getLanguageSpecificSeparator(lang); + if (!scName.isEmpty()) scName+=scopeSeparator; + + bool isSpecialization = cd->localName().find('<')!=-1; + + QCString clName = cd->className(); + //bool isGeneric = getLanguage()==SrcLangExt_CSharp; + //if (isGeneric && clName.right(2)=="-g") + //{ + // clName = clName.left(clName.length()-2); + //} + //printf("m_impl->lang=%d clName=%s isSpecialization=%d\n",getLanguage(),clName.data(),isSpecialization); + scName+=clName; + if (!cd->templateArguments().empty()) + { + if (actualParams && *actualParamIndexsize()) + { + const ArgumentList &al = actualParams->at(*actualParamIndex); + if (!isSpecialization) + { + scName+=tempArgListToString(al,lang); + } + (*actualParamIndex)++; + } + else + { + if (!isSpecialization) + { + scName+=tempArgListToString(cd->templateArguments(),lang); + } + } + } + //printf("qualifiedNameWithTemplateParameters: scope=%s qualifiedName=%s\n",name().data(),scName.data()); + return scName; +} + +static QCString makeDisplayName(const ClassDef *cd,bool includeScope) +{ + //static bool optimizeOutputForJava = Config_getBool(OPTIMIZE_OUTPUT_JAVA); + SrcLangExt lang = cd->getLanguage(); + //static bool vhdlOpt = Config_getBool(OPTIMIZE_OUTPUT_VHDL); + QCString n; + if (lang==SrcLangExt_VHDL) + { + n = VhdlDocGen::getClassName(cd); + } + else + { + if (includeScope) + { + n=cd->qualifiedNameWithTemplateParameters(); + } + else + { + n=cd->className(); + } + } + if (cd->isAnonymous()) + { + n = removeAnonymousScopes(n); + } + QCString sep=getLanguageSpecificSeparator(lang); + if (sep!="::") + { + n=substitute(n,"::",sep); + } + if (cd->compoundType()==ClassDef::Protocol && n.right(2)=="-p") + { + n="<"+n.left(n.length()-2)+">"; + } + //else if (n.right(2)=="-g") + //{ + // n = n.left(n.length()-2); + //} + //printf("ClassDefImpl::displayName()=%s\n",n.data()); + return n; +} + + +//----------------------------------------------------------------------------- + /** Implementation of the ClassDef interface */ class ClassDefImpl : public DefinitionMixin @@ -314,7 +417,7 @@ class ClassDefAliasImpl : public DefinitionAliasMixin virtual QCString inheritanceGraphFileName() const { return getCdAlias()->inheritanceGraphFileName(); } virtual QCString displayName(bool includeScope=TRUE) const - { return getCdAlias()->displayName(includeScope); } + { return makeDisplayName(this,includeScope); } virtual CompoundType compoundType() const { return getCdAlias()->compoundType(); } virtual QCString compoundTypeString() const @@ -373,7 +476,7 @@ class ClassDefAliasImpl : public DefinitionAliasMixin { return getCdAlias()->getTemplateParameterLists(); } virtual QCString qualifiedNameWithTemplateParameters( const ArgumentLists *actualParams=0,uint *actualParamIndex=0) const - { return getCdAlias()->qualifiedNameWithTemplateParameters(actualParams,actualParamIndex); } + { return makeQualifiedNameWithTemplateParameters(this,actualParams,actualParamIndex); } virtual bool isAbstract() const { return getCdAlias()->isAbstract(); } virtual bool isObjectiveC() const @@ -472,7 +575,11 @@ class ClassDefAliasImpl : public DefinitionAliasMixin ClassDef *createClassDefAlias(const Definition *newScope,const ClassDef *cd) { - return new ClassDefAliasImpl(newScope,cd); + ClassDef *acd = new ClassDefAliasImpl(newScope,cd); + //printf("cd name=%s localName=%s qualifiedName=%s qualifiedNameWith=%s displayName()=%s\n", + // acd->name().data(),acd->localName().data(),acd->qualifiedName().data(), + // acd->qualifiedNameWithTemplateParameters().data(),acd->displayName().data()); + return acd; } //----------------------------------------------------------------------------- @@ -747,44 +854,7 @@ QCString ClassDefImpl::getMemberListFileName() const QCString ClassDefImpl::displayName(bool includeScope) const { - //static bool optimizeOutputForJava = Config_getBool(OPTIMIZE_OUTPUT_JAVA); - SrcLangExt lang = getLanguage(); - //static bool vhdlOpt = Config_getBool(OPTIMIZE_OUTPUT_VHDL); - QCString n; - if (lang==SrcLangExt_VHDL) - { - n = VhdlDocGen::getClassName(this); - } - else - { - if (includeScope) - { - n=qualifiedNameWithTemplateParameters(); - } - else - { - n=className(); - } - } - if (isAnonymous()) - { - n = removeAnonymousScopes(n); - } - QCString sep=getLanguageSpecificSeparator(lang); - if (sep!="::") - { - n=substitute(n,"::",sep); - } - if (m_impl->compType==ClassDef::Protocol && n.right(2)=="-p") - { - n="<"+n.left(n.length()-2)+">"; - } - //else if (n.right(2)=="-g") - //{ - // n = n.left(n.length()-2); - //} - //printf("ClassDefImpl::displayName()=%s\n",n.data()); - return n; + return makeDisplayName(this,includeScope); } // inserts a base/super class in the inheritance list @@ -4138,59 +4208,7 @@ ArgumentLists ClassDefImpl::getTemplateParameterLists() const QCString ClassDefImpl::qualifiedNameWithTemplateParameters( const ArgumentLists *actualParams,uint *actualParamIndex) const { - //static bool optimizeOutputJava = Config_getBool(OPTIMIZE_OUTPUT_JAVA); - static bool hideScopeNames = Config_getBool(HIDE_SCOPE_NAMES); - //printf("qualifiedNameWithTemplateParameters() localName=%s\n",localName().data()); - QCString scName; - Definition *d=getOuterScope(); - if (d) - { - if (d->definitionType()==Definition::TypeClass) - { - ClassDef *cd=toClassDef(d); - scName = cd->qualifiedNameWithTemplateParameters(actualParams,actualParamIndex); - } - else if (!hideScopeNames) - { - scName = d->qualifiedName(); - } - } - - SrcLangExt lang = getLanguage(); - QCString scopeSeparator = getLanguageSpecificSeparator(lang); - if (!scName.isEmpty()) scName+=scopeSeparator; - - bool isSpecialization = localName().find('<')!=-1; - - QCString clName = className(); - //bool isGeneric = getLanguage()==SrcLangExt_CSharp; - //if (isGeneric && clName.right(2)=="-g") - //{ - // clName = clName.left(clName.length()-2); - //} - //printf("m_impl->lang=%d clName=%s isSpecialization=%d\n",getLanguage(),clName.data(),isSpecialization); - scName+=clName; - if (!templateArguments().empty()) - { - if (actualParams && *actualParamIndexsize()) - { - const ArgumentList &al = actualParams->at(*actualParamIndex); - if (!isSpecialization) - { - scName+=tempArgListToString(al,lang); - } - (*actualParamIndex)++; - } - else - { - if (!isSpecialization) - { - scName+=tempArgListToString(templateArguments(),lang); - } - } - } - //printf("qualifiedNameWithTemplateParameters: scope=%s qualifiedName=%s\n",name().data(),scName.data()); - return scName; + return makeQualifiedNameWithTemplateParameters(this,actualParams,actualParamIndex); } QCString ClassDefImpl::className() const diff --git a/src/definition.cpp b/src/definition.cpp index 615506f..b719388 100644 --- a/src/definition.cpp +++ b/src/definition.cpp @@ -2137,7 +2137,7 @@ QCString DefinitionImpl::externalReference(const QCString &relPath) const return relPath; } -const QCString &DefinitionImpl::name() const +QCString DefinitionImpl::name() const { return m_impl->name; } @@ -2178,8 +2178,8 @@ void DefinitionImpl::writeSummaryLinks(OutputList &) const //--------------------------------------------------------------------------------- -DefinitionAliasImpl::DefinitionAliasImpl(Definition *def,const Definition *alias) - : m_def(def), m_symbolName(alias->_symbolName()) +DefinitionAliasImpl::DefinitionAliasImpl(Definition *def,const Definition *scope, const Definition *alias) + : m_def(def), m_scope(scope), m_symbolName(alias->_symbolName()) { } @@ -2198,6 +2198,26 @@ void DefinitionAliasImpl::deinit() removeFromMap(m_symbolName,m_def); } +QCString DefinitionAliasImpl::qualifiedName() const +{ + //printf("start %s::qualifiedName() localName=%s\n",name().data(),m_impl->localName.data()); + if (m_scope==0) + { + return m_def->localName(); + } + else + { + return m_scope->qualifiedName()+ + getLanguageSpecificSeparator(m_scope->getLanguage())+ + m_def->localName(); + } +} + +QCString DefinitionAliasImpl::name() const +{ + return qualifiedName(); +} + //--------------------------------------------------------------------------------- Definition *toDefinition(DefinitionMutable *dm) diff --git a/src/definition.h b/src/definition.h index 50a481d..204e6f6 100644 --- a/src/definition.h +++ b/src/definition.h @@ -108,7 +108,7 @@ class Definition virtual bool isAlias() const = 0; /*! Returns the name of the definition */ - virtual const QCString &name() const = 0; + virtual QCString name() const = 0; /*! Returns TRUE iff this definition has an artificially generated name * (typically starting with a @) that is used for nameless definitions diff --git a/src/definitionimpl.h b/src/definitionimpl.h index 710611e..e455dc4 100644 --- a/src/definitionimpl.h +++ b/src/definitionimpl.h @@ -33,7 +33,7 @@ class DefinitionImpl bool isSymbol=TRUE); virtual ~DefinitionImpl(); - const QCString &name() const; + QCString name() const; bool isAnonymous() const; QCString localName() const; QCString qualifiedName() const; @@ -150,7 +150,9 @@ class DefinitionMixin : public Base virtual ~DefinitionMixin() {} virtual bool isAlias() const { return FALSE; } - virtual const QCString &name() const { return m_impl.name(); } + + //======== Definition + virtual QCString name() const { return m_impl.name(); } virtual bool isAnonymous() const { return m_impl.isAnonymous(); } virtual QCString localName() const { return m_impl.localName(); } virtual QCString qualifiedName() const { return m_impl.qualifiedName(); } @@ -198,6 +200,7 @@ class DefinitionMixin : public Base virtual QCString id() const { return m_impl.id(); } virtual const SectionRefs &getSectionRefs() const { return m_impl.getSectionRefs(); } + //======== DefinitionMutable virtual void setName(const char *name) { m_impl.setName(name); } virtual void setId(const char *name) { m_impl.setId(name); } virtual void setDefFile(const QCString& df,int defLine,int defColumn) @@ -292,13 +295,17 @@ class DefinitionMixin : public Base class DefinitionAliasImpl { public: - DefinitionAliasImpl(Definition *def,const Definition *alias); + DefinitionAliasImpl(Definition *def,const Definition *scope,const Definition *alias); virtual ~DefinitionAliasImpl(); void init(); void deinit(); + QCString name() const; + QCString qualifiedName() const; private: Definition *m_def; + const Definition *m_scope; QCString m_symbolName; + QCString m_qualifiedName; }; template @@ -306,7 +313,7 @@ class DefinitionAliasMixin : public Base { public: DefinitionAliasMixin(const Definition *scope,const Definition *alias) - : m_impl(this,alias), m_scope(scope), m_alias(alias), m_cookie(0) {} + : m_impl(this,scope,alias), m_scope(scope), m_alias(alias), m_cookie(0) {} void init() { m_impl.init(); } void deinit() { m_impl.deinit(); } @@ -314,14 +321,16 @@ class DefinitionAliasMixin : public Base virtual ~DefinitionAliasMixin() = default; virtual bool isAlias() const { return TRUE; } - virtual const QCString &name() const - { return m_alias->name(); } + + //======== Definition + virtual QCString name() const + { return m_impl.name(); } virtual bool isAnonymous() const { return m_alias->isAnonymous(); } virtual QCString localName() const { return m_alias->localName(); } virtual QCString qualifiedName() const - { return m_alias->qualifiedName(); } + { return m_impl.qualifiedName(); } virtual QCString symbolName() const { return m_alias->symbolName(); } virtual QCString getSourceFileBase() const diff --git a/src/docbookgen.cpp b/src/docbookgen.cpp index 7656b9e..385c2ef 100644 --- a/src/docbookgen.cpp +++ b/src/docbookgen.cpp @@ -537,7 +537,7 @@ DB_GEN_C2("IndexSections " << is) bool found=FALSE; for (nli.toFirst();(nd=nli.current()) && !found;++nli) { - if (nd->isLinkableInProject()) + if (nd->isLinkableInProject() && !nd->isAlias()) { t << "getOutputFileBase() << ".xml\" xmlns:xi=\"http://www.w3.org/2001/XInclude\"/>" << endl; found=TRUE; @@ -545,7 +545,7 @@ DB_GEN_C2("IndexSections " << is) } while ((nd=nli.current())) { - if (nd->isLinkableInProject()) + if (nd->isLinkableInProject() && !nd->isAlias()) { t << "getOutputFileBase() << ".xml\" xmlns:xi=\"http://www.w3.org/2001/XInclude\"/>" << endl; } diff --git a/src/doxygen.cpp b/src/doxygen.cpp index 2468306..4667cba 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -1607,6 +1607,7 @@ static void buildNamespaceList(const Entry *root) NamespaceDef *aliasNd = createNamespaceDefAlias(d,nd); //printf("adding %s to %s\n",qPrint(aliasNd->name()),qPrint(d->name())); dm->addInnerCompound(aliasNd); + Doxygen::namespaceSDict->inSort(aliasNd->name(),aliasNd); } } } diff --git a/src/filedef.cpp b/src/filedef.cpp index 0fdcdd3..68c2218 100644 --- a/src/filedef.cpp +++ b/src/filedef.cpp @@ -55,7 +55,7 @@ class FileDefImpl : public DefinitionMixin virtual ~FileDefImpl(); virtual DefType definitionType() const { return TypeFile; } - virtual const QCString &name() const; + virtual QCString name() const; virtual QCString displayName(bool=TRUE) const { return name(); } virtual QCString fileName() const { return m_fileName; } @@ -1435,7 +1435,7 @@ void FileDefImpl::insertNamespace(NamespaceDef *nd) } } -const QCString &FileDefImpl::name() const +QCString FileDefImpl::name() const { if (Config_getBool(FULL_PATH_NAMES)) return m_fileName; diff --git a/src/filedef.h b/src/filedef.h index ac3d729..055078f 100644 --- a/src/filedef.h +++ b/src/filedef.h @@ -79,7 +79,7 @@ class FileDef : public DefinitionMutable, public Definition virtual DefType definitionType() const = 0; /*! Returns the unique file name (this may include part of the path). */ - virtual const QCString &name() const = 0; + virtual QCString name() const = 0; virtual QCString displayName(bool=TRUE) const = 0; virtual QCString fileName() const = 0; diff --git a/src/latexgen.cpp b/src/latexgen.cpp index 05141a9..3f4435f 100644 --- a/src/latexgen.cpp +++ b/src/latexgen.cpp @@ -1035,7 +1035,7 @@ void LatexGenerator::startIndexSection(IndexSections is) bool found=FALSE; for (nli.toFirst();(nd=nli.current()) && !found;++nli) { - if (nd->isLinkableInProject()) + if (nd->isLinkableInProject() && !nd->isAlias()) { if (compactLatex) t << "\\doxysection"; else t << "\\chapter"; t << "{"; // Namespace Documentation}\n": @@ -1205,7 +1205,7 @@ void LatexGenerator::endIndexSection(IndexSections is) bool found=FALSE; for (nli.toFirst();(nd=nli.current()) && !found;++nli) { - if (nd->isLinkableInProject()) + if (nd->isLinkableInProject() && !nd->isAlias()) { t << "}\n\\input{" << nd->getOutputFileBase() << "}\n"; found=TRUE; diff --git a/src/memberdef.cpp b/src/memberdef.cpp index be57ad9..ca6026e 100644 --- a/src/memberdef.cpp +++ b/src/memberdef.cpp @@ -357,7 +357,7 @@ class MemberDefImpl : public DefinitionMixin IMPL *m_impl; uchar m_isLinkableCached; // 0 = not cached, 1=FALSE, 2=TRUE uchar m_isConstructorCached; // 0 = not cached, 1=FALSE, 2=TRUE - uchar m_isDestructorCached; // 0 = not cached, 1=FALSE, 2=TRUE + uchar m_isDestructorCached; // 1 = not cached, 1=FALSE, 2=TRUE }; MemberDefMutable *createMemberDef(const char *defFileName,int defLine,int defColumn, @@ -389,6 +389,8 @@ class MemberDefAliasImpl : public DefinitionAliasMixin } virtual void moveTo(Definition *) {} + virtual QCString name() const + { return getMdAlias()->name(); } virtual QCString getOutputFileBase() const { return getMdAlias()->getOutputFileBase(); } virtual QCString getReference() const @@ -760,7 +762,9 @@ class MemberDefAliasImpl : public DefinitionAliasMixin MemberDef *createMemberDefAlias(const Definition *newScope,const MemberDef *aliasMd) { - return new MemberDefAliasImpl(newScope,aliasMd); + MemberDef *amd = new MemberDefAliasImpl(newScope,aliasMd); + //printf("amd: name=%s displayName=%s\n",amd->name().data(),amd->displayName().data()); + return amd; } //----------------------------------------------------------------------------- diff --git a/src/namespacedef.cpp b/src/namespacedef.cpp index 0c55573..4b8b4d8 100644 --- a/src/namespacedef.cpp +++ b/src/namespacedef.cpp @@ -34,6 +34,19 @@ #include "membername.h" //------------------------------------------------------------------ +static QCString makeDisplayName(const NamespaceDef *nd,bool includeScope) +{ + QCString result=includeScope ? nd->name() : nd->localName(); + SrcLangExt lang = nd->getLanguage(); + QCString sep = getLanguageSpecificSeparator(lang); + if (sep!="::") + { + result = substitute(result,"::",sep); + } + //printf("makeDisplayName() %s->%s lang=%d\n",name().data(),result.data(),lang); + return result; +} +//------------------------------------------------------------------ class NamespaceDefImpl : public DefinitionMixin { @@ -172,7 +185,7 @@ class NamespaceDefAliasImpl : public DefinitionAliasMixin virtual LinkedRefMap getUsedClasses() const { return getNSAlias()->getUsedClasses(); } virtual QCString displayName(bool b=TRUE) const - { return getNSAlias()->displayName(b); } + { return makeDisplayName(this,b); } virtual QCString localName() const { return getNSAlias()->localName(); } virtual bool isConstantGroup() const @@ -219,7 +232,11 @@ class NamespaceDefAliasImpl : public DefinitionAliasMixin NamespaceDef *createNamespaceDefAlias(const Definition *newScope,const NamespaceDef *nd) { - return new NamespaceDefAliasImpl(newScope,nd); + NamespaceDef *alnd = new NamespaceDefAliasImpl(newScope,nd); + //printf("alnd name=%s localName=%s qualifiedName=%s displayName()=%s\n", + // alnd->name().data(),alnd->localName().data(),alnd->qualifiedName().data(), + // alnd->displayName().data()); + return alnd; } //------------------------------------------------------------------ @@ -1252,15 +1269,7 @@ void NamespaceDefImpl::addListReferences() QCString NamespaceDefImpl::displayName(bool includeScope) const { - QCString result=includeScope ? name() : localName(); - SrcLangExt lang = getLanguage(); - QCString sep = getLanguageSpecificSeparator(lang); - if (sep!="::") - { - result = substitute(result,"::",sep); - } - //printf("NamespaceDefImpl::displayName() %s->%s lang=%d\n",name().data(),result.data(),lang); - return result; + return makeDisplayName(this,includeScope); } QCString NamespaceDefImpl::localName() const diff --git a/src/rtfgen.cpp b/src/rtfgen.cpp index 8fd50ef..17ed794 100644 --- a/src/rtfgen.cpp +++ b/src/rtfgen.cpp @@ -784,7 +784,7 @@ void RTFGenerator::endIndexSection(IndexSections is) bool found=FALSE; for (nli.toFirst();(nd=nli.current()) && !found;++nli) { - if (nd->isLinkableInProject()) + if (nd->isLinkableInProject() && !nd->isAlias()) { t << "\\par " << rtf_Style_Reset << endl; t << "{\\field\\fldedit{\\*\\fldinst INCLUDETEXT \""; @@ -795,7 +795,7 @@ void RTFGenerator::endIndexSection(IndexSections is) } while ((nd=nli.current())) { - if (nd->isLinkableInProject()) + if (nd->isLinkableInProject() && !nd->isAlias()) { t << "\\par " << rtf_Style_Reset << endl; beginRTFSection(); diff --git a/testing/057/namespacelibrary.xml b/testing/057/namespacelibrary.xml index 8509524..5321ad7 100644 --- a/testing/057/namespacelibrary.xml +++ b/testing/057/namespacelibrary.xml @@ -2,10 +2,10 @@ library - library::v2::foo + library::foo + library::NS library::v1 library::v2 - library::v2::NS void -- cgit v0.12