diff options
Diffstat (limited to 'src/namespacedef.cpp')
-rw-r--r-- | src/namespacedef.cpp | 304 |
1 files changed, 165 insertions, 139 deletions
diff --git a/src/namespacedef.cpp b/src/namespacedef.cpp index 88eea5d..4b8b4d8 100644 --- a/src/namespacedef.cpp +++ b/src/namespacedef.cpp @@ -34,8 +34,21 @@ #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 DefinitionImpl, public NamespaceDef +class NamespaceDefImpl : public DefinitionMixin<NamespaceDefMutable> { public: NamespaceDefImpl(const char *defFileName,int defLine,int defColumn, @@ -58,10 +71,10 @@ class NamespaceDefImpl : public DefinitionImpl, public NamespaceDef virtual void countMembers(); virtual int numDocMembers() const; virtual void addUsingDirective(const NamespaceDef *nd); - virtual const NamespaceSDict *getUsedNamespaces() const; - virtual void addUsingDeclaration(const Definition *def); - virtual const SDict<Definition> *getUsedClasses() const { return usingDeclList; } - virtual void combineUsingRelations(); + virtual LinkedRefMap<const NamespaceDef> getUsedNamespaces() const { return m_usingDirList; } + virtual void addUsingDeclaration(const ClassDef *cd); + virtual LinkedRefMap<const ClassDef> getUsedClasses() const { return m_usingDeclList; } + virtual void combineUsingRelations(NamespaceDefSet &visitedNamespace); virtual QCString displayName(bool=TRUE) const; virtual QCString localName() const; virtual void setInline(bool isInline) { m_inline = isInline; } @@ -76,7 +89,7 @@ class NamespaceDefImpl : public DefinitionImpl, public NamespaceDef virtual void distributeMemberGroupDocumentation(); virtual void findSectionsInDocumentation(); virtual void sortMemberLists(); - virtual Definition *findInnerCompound(const char *name) const; + virtual const Definition *findInnerCompound(const char *name) const; virtual void addInnerCompound(const Definition *d); virtual void addListReferences(); virtual void setFileName(const QCString &fn); @@ -95,11 +108,8 @@ class NamespaceDefImpl : public DefinitionImpl, public NamespaceDef virtual QCString compoundTypeString() const; virtual void setMetaData(const QCString &m); - void setVisited(bool v) { m_visited = v; } - bool isVisited() const { return m_visited; } private: - bool m_visited; MemberList *createMemberList(MemberListType lt); void addMemberToList(MemberListType lt,MemberDef *md); void writeMemberDeclarations(OutputList &ol,MemberListType lt,const QCString &title); @@ -124,8 +134,8 @@ class NamespaceDefImpl : public DefinitionImpl, public NamespaceDef QCString fileName; FileList files; - NamespaceSDict *usingDirList = 0; - SDict<Definition> *usingDeclList = 0; + LinkedRefMap<const NamespaceDef> m_usingDirList; + LinkedRefMap<const ClassDef> m_usingDeclList; SDict<Definition> *m_innerCompounds = 0; MemberSDict *m_allMembersDict = 0; @@ -143,7 +153,7 @@ class NamespaceDefImpl : public DefinitionImpl, public NamespaceDef bool m_inline = false; }; -NamespaceDef *createNamespaceDef(const char *defFileName,int defLine,int defColumn, +NamespaceDefMutable *createNamespaceDef(const char *defFileName,int defLine,int defColumn, const char *name,const char *ref, const char *refFile,const char*type, bool isPublished) @@ -153,14 +163,15 @@ NamespaceDef *createNamespaceDef(const char *defFileName,int defLine,int defColu //------------------------------------------------------------------ -class NamespaceDefAliasImpl : public DefinitionAliasImpl, public NamespaceDef +class NamespaceDefAliasImpl : public DefinitionAliasMixin<NamespaceDef> { public: - NamespaceDefAliasImpl(const Definition *newScope,const NamespaceDef *nd) : DefinitionAliasImpl(newScope,nd) {} - virtual ~NamespaceDefAliasImpl() {} + NamespaceDefAliasImpl(const Definition *newScope,const NamespaceDef *nd) + : DefinitionAliasMixin(newScope,nd) { init(); } + virtual ~NamespaceDefAliasImpl() { deinit(); } virtual DefType definitionType() const { return TypeNamespace; } - const NamespaceDef *getNSAlias() const { return dynamic_cast<const NamespaceDef*>(getAlias()); } + const NamespaceDef *getNSAlias() const { return toNamespaceDef(getAlias()); } // ---- getters virtual QCString getOutputFileBase() const @@ -169,18 +180,14 @@ class NamespaceDefAliasImpl : public DefinitionAliasImpl, public NamespaceDef { return getNSAlias()->anchor(); } virtual int numDocMembers() const { return getNSAlias()->numDocMembers(); } - virtual void addUsingDirective(const NamespaceDef *nd) {} - virtual const NamespaceSDict *getUsedNamespaces() const + virtual LinkedRefMap<const NamespaceDef> getUsedNamespaces() const { return getNSAlias()->getUsedNamespaces(); } - virtual void addUsingDeclaration(const Definition *def) {} - virtual const SDict<Definition> *getUsedClasses() const + virtual LinkedRefMap<const ClassDef> getUsedClasses() const { return getNSAlias()->getUsedClasses(); } - virtual void combineUsingRelations() {} virtual QCString displayName(bool b=TRUE) const - { return getNSAlias()->displayName(b); } + { return makeDisplayName(this,b); } virtual QCString localName() const { return getNSAlias()->localName(); } - virtual void setInline(bool isInline) { } virtual bool isConstantGroup() const { return getNSAlias()->isConstantGroup(); } virtual bool isModule() const @@ -195,7 +202,7 @@ class NamespaceDefAliasImpl : public DefinitionAliasImpl, public NamespaceDef { return getNSAlias()->isLinkable(); } virtual bool hasDetailedDescription() const { return getNSAlias()->hasDetailedDescription(); } - virtual Definition *findInnerCompound(const char *name) const + virtual const Definition *findInnerCompound(const char *name) const { return getNSAlias()->findInnerCompound(name); } virtual bool subGrouping() const { return getNSAlias()->subGrouping(); } @@ -221,37 +228,15 @@ class NamespaceDefAliasImpl : public DefinitionAliasImpl, public NamespaceDef { return getNSAlias()->title(); } virtual QCString compoundTypeString() const { return getNSAlias()->compoundTypeString(); } - - // --- setters/actions - virtual void setMetaData(const QCString &m) {} - virtual void insertUsedFile(FileDef *fd) { } - virtual void writeDocumentation(OutputList &ol) {} - virtual void writeMemberPages(OutputList &ol) {} - virtual void writeQuickMemberLinks(OutputList &ol,const MemberDef *currentMd) const {} - virtual void writeTagFile(FTextStream &) {} - virtual void insertClass(const ClassDef *cd) {} - virtual void insertNamespace(const NamespaceDef *nd) {} - virtual void insertMember(MemberDef *md) {} - virtual void computeAnchors() {} - virtual void countMembers() {} - virtual void addMembersToMemberGroup() {} - virtual void distributeMemberGroupDocumentation() {} - virtual void findSectionsInDocumentation() {} - virtual void sortMemberLists() {} - virtual void addInnerCompound(const Definition *d) {} - virtual void addListReferences() {} - virtual void setFileName(const QCString &fn) {} - - void setVisited(bool v) { m_visited = v; } - bool isVisited() const { return m_visited; } - - private: - bool m_visited = false; }; 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; } //------------------------------------------------------------------ @@ -260,7 +245,7 @@ NamespaceDefImpl::NamespaceDefImpl(const char *df,int dl,int dc, const char *name,const char *lref, const char *fName, const char*type, bool isPublished) : - DefinitionImpl(df,dl,dc,name) + DefinitionMixin(df,dl,dc,name) ,m_isPublished(isPublished) { if (fName) @@ -284,13 +269,10 @@ NamespaceDefImpl::NamespaceDefImpl(const char *df,int dl,int dc, exceptionSDict = new ClassSDict(17); namespaceSDict = new NamespaceSDict(17); m_innerCompounds = new SDict<Definition>(17); - usingDirList = 0; - usingDeclList = 0; m_allMembersDict = 0; setReference(lref); memberGroupSDict = new MemberGroupSDict; memberGroupSDict->setAutoDelete(TRUE); - m_visited=FALSE; m_inline=FALSE; m_subGrouping=Config_getBool(SUBGROUPING); if (type && !strcmp("module", type)) @@ -319,8 +301,6 @@ NamespaceDefImpl::~NamespaceDefImpl() delete exceptionSDict; delete namespaceSDict; delete m_innerCompounds; - delete usingDirList; - delete usingDeclList; delete memberGroupSDict; delete m_allMembersDict; } @@ -349,6 +329,7 @@ void NamespaceDefImpl::distributeMemberGroupDocumentation() void NamespaceDefImpl::findSectionsInDocumentation() { + docFindSections(briefDescription(),this,docFile()); docFindSections(documentation(),this,docFile()); MemberGroupSDict::Iterator mgli(*memberGroupSDict); MemberGroup *mg; @@ -384,11 +365,11 @@ void NamespaceDefImpl::addInnerCompound(const Definition *d) m_innerCompounds->append(d->localName(),d); if (d->definitionType()==Definition::TypeNamespace) { - insertNamespace(dynamic_cast<const NamespaceDef *>(d)); + insertNamespace(toNamespaceDef(d)); } else if (d->definitionType()==Definition::TypeClass) { - insertClass(dynamic_cast<const ClassDef *>(d)); + insertClass(toClassDef(d)); } } @@ -470,6 +451,7 @@ void NamespaceDefImpl::insertMember(MemberDef *md) //printf("%s::insertMember(%s) isInline=%d hasDocs=%d\n",qPrint(name()),qPrint(md->name()), // isInline(),hasDocumentation()); if (md->isHidden()) return; + MemberDefMutable *mdm = toMemberDefMutable(md); // if this is an inline namespace that is not documented, then insert the // member in the parent scope instead @@ -480,16 +462,25 @@ void NamespaceDefImpl::insertMember(MemberDef *md) { if (outerScope->definitionType()==Definition::TypeNamespace) { - NamespaceDef *nd = dynamic_cast<NamespaceDef*>(outerScope); - nd->insertMember(md); - md->setNamespace(nd); + NamespaceDefMutable *nd = toNamespaceDefMutable(outerScope); + if (nd) + { + nd->insertMember(md); + if (mdm) + { + mdm->setNamespace(nd); + } + } } else if (outerScope->definitionType()==Definition::TypeFile) { - FileDef *fd = dynamic_cast<FileDef*>(outerScope); + FileDef *fd = toFileDef(outerScope); fd->insertMember(md); - md->setFileDef(fd); - md->setOuterScope(fd); + if (mdm) + { + mdm->setFileDef(fd); + mdm->setOuterScope(fd); + } } } } @@ -559,12 +550,16 @@ void NamespaceDefImpl::insertMember(MemberDef *md) if (outerScope->definitionType()==Definition::TypeNamespace) { aliasMd.reset(createMemberDefAlias(outerScope,md)); - dynamic_cast<NamespaceDef*>(outerScope)->insertMember(aliasMd.get()); + NamespaceDefMutable *ndm = toNamespaceDefMutable(outerScope); + if (ndm) + { + ndm->insertMember(aliasMd.get()); + } } else if (outerScope->definitionType()==Definition::TypeFile) { aliasMd.reset(createMemberDefAlias(outerScope,md)); - dynamic_cast<FileDef*>(outerScope)->insertMember(aliasMd.get()); + toFileDef(outerScope)->insertMember(aliasMd.get()); } if (aliasMd) { @@ -581,7 +576,7 @@ void NamespaceDefImpl::insertMember(MemberDef *md) void NamespaceDefImpl::computeAnchors() { MemberList *allMemberList = getMemberList(MemberListType_allMembersList); - if (allMemberList) setAnchors(allMemberList); + if (allMemberList) allMemberList->setAnchors(); } bool NamespaceDefImpl::hasDetailedDescription() const @@ -1208,33 +1203,13 @@ int NamespaceDefImpl::numDocMembers() const void NamespaceDefImpl::addUsingDirective(const NamespaceDef *nd) { - if (usingDirList==0) - { - usingDirList = new NamespaceSDict; - } - if (usingDirList->find(nd->qualifiedName())==0) - { - usingDirList->append(nd->qualifiedName(),nd); - } - //printf("%p: NamespaceDefImpl::addUsingDirective: %s:%d\n",this,name().data(),usingDirList->count()); -} - -const NamespaceSDict *NamespaceDefImpl::getUsedNamespaces() const -{ - //printf("%p: NamespaceDefImpl::getUsedNamespace: %s:%d\n",this,name().data(),usingDirList?usingDirList->count():0); - return usingDirList; + m_usingDirList.add(nd->qualifiedName(),nd); + //printf("%p: NamespaceDefImpl::addUsingDirective: %s:%d\n",this,name().data(),m_usingDirList->count()); } -void NamespaceDefImpl::addUsingDeclaration(const Definition *d) +void NamespaceDefImpl::addUsingDeclaration(const ClassDef *cd) { - if (usingDeclList==0) - { - usingDeclList = new SDict<Definition>(17); - } - if (usingDeclList->find(d->qualifiedName())==0) - { - usingDeclList->append(d->qualifiedName(),d); - } + m_usingDeclList.add(cd->qualifiedName(),cd); } QCString NamespaceDefImpl::getOutputFileBase() const @@ -1242,19 +1217,19 @@ QCString NamespaceDefImpl::getOutputFileBase() const return fileName; } -Definition *NamespaceDefImpl::findInnerCompound(const char *n) const +const Definition *NamespaceDefImpl::findInnerCompound(const char *n) const { if (n==0) return 0; - Definition *d = m_innerCompounds->find(n); + const Definition *d = m_innerCompounds->find(n); if (d==0) { - if (usingDirList) + if (!m_usingDirList.empty()) { - d = usingDirList->find(n); + d = m_usingDirList.find(n); } - if (d==0 && usingDeclList) + if (d==0 && !m_usingDeclList.empty()) { - d = usingDeclList->find(n); + d = m_usingDeclList.find(n); } } return d; @@ -1294,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 @@ -1316,42 +1283,32 @@ QCString NamespaceDefImpl::localName() const return result; } -void NamespaceDefImpl::combineUsingRelations() +void NamespaceDefImpl::combineUsingRelations(NamespaceDefSet &visitedNamespaces) { - if (m_visited) return; // already done - m_visited=TRUE; - if (usingDirList) + if (visitedNamespaces.find(this)!=visitedNamespaces.end()) return; // already processed + visitedNamespaces.insert(this); + + LinkedRefMap<const NamespaceDef> usingDirList = m_usingDirList; + for (auto &nd : usingDirList) { - NamespaceSDict::Iterator nli(*usingDirList); - NamespaceDef *nd; - for (nli.toFirst();(nd=nli.current());++nli) + NamespaceDefMutable *ndm = toNamespaceDefMutable(nd); + if (ndm) { - nd->combineUsingRelations(); + ndm->combineUsingRelations(visitedNamespaces); } - for (nli.toFirst();(nd=nli.current());++nli) + } + + for (auto &nd : usingDirList) + { + // add used namespaces of namespace nd to this namespace + for (const auto &und : nd->getUsedNamespaces()) { - // add used namespaces of namespace nd to this namespace - if (nd->getUsedNamespaces()) - { - NamespaceSDict::Iterator unli(*nd->getUsedNamespaces()); - NamespaceDef *und; - for (unli.toFirst();(und=unli.current());++unli) - { - //printf("Adding namespace %s to the using list of %s\n",und->qualifiedName().data(),qualifiedName().data()); - addUsingDirective(und); - } - } - // add used classes of namespace nd to this namespace - if (nd->getUsedClasses()) - { - SDict<Definition>::Iterator cli(*nd->getUsedClasses()); - Definition *ucd; - for (cli.toFirst();(ucd=cli.current());++cli) - { - //printf("Adding class %s to the using list of %s\n",cd->qualifiedName().data(),qualifiedName().data()); - addUsingDeclaration(ucd); - } - } + addUsingDirective(und); + } + // add used classes of namespace nd to this namespace + for (const auto &ucd : nd->getUsedClasses()) + { + addUsingDeclaration(ucd); } } } @@ -1483,7 +1440,11 @@ void NamespaceDefImpl::addMemberToList(MemberListType lt,MemberDef *md) if (ml->listType()&MemberListType_declarationLists) { - md->setSectionList(this,ml); + MemberDefMutable *mdm = toMemberDefMutable(md); + if (mdm) + { + mdm->setSectionList(this,ml); + } } } @@ -1644,3 +1605,68 @@ void NamespaceDefImpl::setMetaData(const QCString &m) { metaData = m; } + +// --- Cast functions +// +NamespaceDef *toNamespaceDef(Definition *d) +{ + if (d && (typeid(*d)==typeid(NamespaceDefImpl) || typeid(*d)==typeid(NamespaceDefAliasImpl))) + { + return static_cast<NamespaceDef*>(d); + } + else + { + return 0; + } +} + +NamespaceDef *toNamespaceDef(DefinitionMutable *md) +{ + Definition *d = toDefinition(md); + if (d && typeid(*d)==typeid(NamespaceDefImpl)) + { + return static_cast<NamespaceDef*>(d); + } + else + { + return 0; + } +} + + +const NamespaceDef *toNamespaceDef(const Definition *d) +{ + if (d && (typeid(*d)==typeid(NamespaceDefImpl) || typeid(*d)==typeid(NamespaceDefAliasImpl))) + { + return static_cast<const NamespaceDef*>(d); + } + else + { + return 0; + } +} + +NamespaceDefMutable *toNamespaceDefMutable(Definition *d) +{ + if (d && typeid(*d)==typeid(NamespaceDefImpl)) + { + return static_cast<NamespaceDefMutable*>(d); + } + else + { + return 0; + } +} + +NamespaceDefMutable *toNamespaceDefMutable(const Definition *d) +{ + if (d && typeid(*d)==typeid(NamespaceDefImpl)) + { + return const_cast<NamespaceDefMutable*>(static_cast<const NamespaceDefMutable*>(d)); + } + else + { + return 0; + } +} + |