Doxygen
Loading...
Searching...
No Matches
namespacedef.cpp File Reference
#include "namespacedef.h"
#include "outputlist.h"
#include "util.h"
#include "language.h"
#include "classdef.h"
#include "classlist.h"
#include "memberlist.h"
#include "doxygen.h"
#include "message.h"
#include "docparser.h"
#include "searchindex.h"
#include "vhdldocgen.h"
#include "layout.h"
#include "membergroup.h"
#include "config.h"
#include "definitionimpl.h"
#include "membername.h"
#include "conceptdef.h"
+ Include dependency graph for namespacedef.cpp:

Go to the source code of this file.

Classes

class  NamespaceDefImpl
 
class  NamespaceDefAliasImpl
 

Functions

static QCString makeDisplayName (const NamespaceDef *nd, bool includeScope)
 
std::unique_ptr< NamespaceDefcreateNamespaceDef (const QCString &defFileName, int defLine, int defColumn, const QCString &name, const QCString &ref, const QCString &refFile, const QCString &type, bool isPublished)
 Factory method to create new NamespaceDef instance.
 
std::unique_ptr< NamespaceDefcreateNamespaceDefAlias (const Definition *newScope, const NamespaceDef *nd)
 Factory method to create an alias of an existing namespace.
 
static bool hasNonReferenceNestedNamespaceRec (const NamespaceDef *nd, int level)
 
NamespaceDeftoNamespaceDef (Definition *d)
 
NamespaceDeftoNamespaceDef (DefinitionMutable *md)
 
const NamespaceDeftoNamespaceDef (const Definition *d)
 
NamespaceDefMutabletoNamespaceDefMutable (Definition *d)
 
static NamespaceDefgetResolvedNamespaceRec (StringSet &namespacesTried, const NamespaceAliasInfo &aliasInfo)
 
static QCString replaceNamespaceAliasesRec (StringSet &namespacesTried, const QCString &name)
 
void replaceNamespaceAliases (QCString &name)
 
NamespaceDefgetResolvedNamespace (const QCString &name)
 
bool namespaceHasNestedNamespace (const NamespaceDef *nd)
 
bool namespaceHasNestedConcept (const NamespaceDef *nd)
 
bool namespaceHasNestedClass (const NamespaceDef *nd, bool filterClasses, ClassDef::CompoundType ct)
 

Function Documentation

◆ createNamespaceDef()

std::unique_ptr< NamespaceDef > createNamespaceDef ( const QCString & defFileName,
int defLine,
int defColumn,
const QCString & name,
const QCString & ref,
const QCString & refFile,
const QCString & type,
bool isPublished )

Factory method to create new NamespaceDef instance.

Definition at line 173 of file namespacedef.cpp.

177{
178 //printf("createNamespaceDef(%s)\n",qPrint(name));
179 return std::make_unique<NamespaceDefImpl>(defFileName,defLine,defColumn,name,ref,refFile,type,isPublished);
180}

Referenced by adjustConfiguration(), buildNamespaceList(), buildScopeFromQualifiedName(), findUsingDirectives(), and NamespaceDefMutable::setInline().

◆ createNamespaceDefAlias()

std::unique_ptr< NamespaceDef > createNamespaceDefAlias ( const Definition * newScope,
const NamespaceDef * nd )

Factory method to create an alias of an existing namespace.

Used for inline namespaces.

Definition at line 261 of file namespacedef.cpp.

262{
263 auto alnd = std::make_unique<NamespaceDefAliasImpl>(newScope,nd);
264 //printf("alnd name=%s localName=%s qualifiedName=%s displayName()=%s\n",
265 // qPrint(alnd->name()),qPrint(alnd->localName()),qPrint(alnd->qualifiedName()),
266 // qPrint(alnd->displayName()));
267 return alnd;
268}

Referenced by buildNamespaceList(), and NamespaceDefMutable::setInline().

◆ getResolvedNamespace()

NamespaceDef * getResolvedNamespace ( const QCString & name)

Definition at line 1780 of file namespacedef.cpp.

1781{
1782 //printf("> getResolvedNamespace(%s)\n",qPrint(name));
1783 if (name.isEmpty()) return nullptr;
1784 StringSet namespacesTried;
1785 auto ns = getResolvedNamespaceRec(namespacesTried,NamespaceAliasInfo(name.str()));
1786 //printf("< getResolvedNamespace(%s)=%s\n",qPrint(name),ns?qPrint(ns->qualifiedName()):"nullptr");
1787 return ns;
1788}
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
const std::string & str() const
Definition qcstring.h:537
std::set< std::string > StringSet
Definition containers.h:31
static NamespaceDef * getResolvedNamespaceRec(StringSet &namespacesTried, const NamespaceAliasInfo &aliasInfo)

References getResolvedNamespaceRec(), QCString::isEmpty(), and QCString::str().

Referenced by addMemberFunction(), buildFunctionList(), buildTypedefList(), extractNamespaceName(), findUsedNamespace(), findUsingDeclImports(), findUsingDirectives(), generateClassOrGlobalLink(), generateClassOrGlobalLink(), getResolvedNamespaceMutable(), CCodeParser::parseCode(), setCallContextForVar(), NamespaceDefMutable::setInline(), and writeAlphabeticalClassList().

◆ getResolvedNamespaceRec()

static NamespaceDef * getResolvedNamespaceRec ( StringSet & namespacesTried,
const NamespaceAliasInfo & aliasInfo )
static

Definition at line 1731 of file namespacedef.cpp.

1732{
1733 size_t j = aliasInfo.context.length();
1734 for (;;)
1735 {
1736 if (j>0)
1737 {
1738 //printf("candidate %s|::%s\n",qPrint(aliasInfo.context.substr(0,j)),qPrint(aliasInfo.alias));
1739 auto candidate = replaceNamespaceAliasesRec(namespacesTried,aliasInfo.context.substr(0,j)+"::"+aliasInfo.alias);
1740 auto nd = Doxygen::namespaceLinkedMap->find(candidate);
1741 if (nd)
1742 {
1743 return nd;
1744 }
1745 }
1746 if (j>0) // strip one level from context, i.e. given N1::N2::N3
1747 // j==10 -> j==6 (N1::N2::N3->N1::N2), and then
1748 // j==6 -> j==2 (N1::N2->N1), and then
1749 // j==2 -> j==std::string::npos (N1->"")
1750 {
1751 j = aliasInfo.context.rfind("::",j-1);
1752 }
1753 else
1754 {
1755 j = std::string::npos;
1756 }
1757 if (j==std::string::npos)
1758 {
1759 //printf("candidate %s\n",qPrint(aliasInfo.alias));
1760 auto candidate = replaceNamespaceAliasesRec(namespacesTried,QCString(aliasInfo.alias));
1761 auto nd = Doxygen::namespaceLinkedMap->find(candidate);
1762 if (nd)
1763 {
1764 return nd;
1765 }
1766 break;
1767 }
1768 }
1769 return nullptr;
1770}
static NamespaceLinkedMap * namespaceLinkedMap
Definition doxygen.h:115
This is an alternative implementation of QCString.
Definition qcstring.h:101
static QCString replaceNamespaceAliasesRec(StringSet &namespacesTried, const QCString &name)
std::string context
Definition doxygen.h:78
std::string alias
Definition doxygen.h:77

References NamespaceAliasInfo::alias, NamespaceAliasInfo::context, Doxygen::namespaceLinkedMap, and replaceNamespaceAliasesRec().

Referenced by getResolvedNamespace(), and replaceNamespaceAliasesRec().

◆ hasNonReferenceNestedNamespaceRec()

static bool hasNonReferenceNestedNamespaceRec ( const NamespaceDef * nd,
int level )
static

Definition at line 1504 of file namespacedef.cpp.

1505{
1506 if (level>30)
1507 {
1508 err("Possible recursive namespace relation while inside %s\n",qPrint(nd->name()));
1509 return false;
1510 }
1511 bool found=nd->isLinkableInProject();
1512 if (found)
1513 {
1514 return true;
1515 }
1516 else
1517 {
1518 for (const auto &ind : nd->getNamespaces())
1519 {
1521 if (found) break;
1522 }
1523 }
1524 return found;
1525}
virtual bool isLinkableInProject() const =0
virtual const QCString & name() const =0
virtual NamespaceLinkedRefMap getNamespaces() const =0
#define err(fmt,...)
Definition message.h:84
static bool hasNonReferenceNestedNamespaceRec(const NamespaceDef *nd, int level)
const char * qPrint(const char *s)
Definition qcstring.h:672
bool found
Definition util.cpp:984

References err, found, NamespaceDef::getNamespaces(), hasNonReferenceNestedNamespaceRec(), Definition::isLinkableInProject(), Definition::name(), and qPrint().

Referenced by hasNonReferenceNestedNamespaceRec(), and NamespaceDefImpl::isVisibleInHierarchy().

◆ makeDisplayName()

static QCString makeDisplayName ( const NamespaceDef * nd,
bool includeScope )
static

Definition at line 38 of file namespacedef.cpp.

39{
40 QCString result=includeScope ? nd->name() : nd->localName();
41 SrcLangExt lang = nd->getLanguage();
43 if (sep!="::")
44 {
45 result = substitute(result,"::",sep);
46 }
47 if (nd->isAnonymous())
48 {
49 result = removeAnonymousScopes(result);
50 }
51 //printf("makeDisplayName() %s->%s lang=%d\n",qPrint(name()),qPrint(result),lang);
52 return result;
53}
virtual const QCString & localName() const =0
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
virtual bool isAnonymous() const =0
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:477
SrcLangExt
Language as given by extension.
Definition types.h:42
QCString removeAnonymousScopes(const QCString &str)
Definition util.cpp:172
QCString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Returns the scope separator to use given the programming language lang.
Definition util.cpp:6230

References Definition::getLanguage(), getLanguageSpecificSeparator(), Definition::isAnonymous(), Definition::localName(), Definition::name(), removeAnonymousScopes(), and substitute().

Referenced by NamespaceDefAliasImpl::displayName(), and NamespaceDefImpl::displayName().

◆ namespaceHasNestedClass()

bool namespaceHasNestedClass ( const NamespaceDef * nd,
bool filterClasses,
ClassDef::CompoundType ct )

Definition at line 1828 of file namespacedef.cpp.

1829{
1830 //printf(">namespaceHasNestedClass(%s,filterClasses=%d)\n",qPrint(nd->name()),filterClasses);
1831 for (const auto &cnd : nd->getNamespaces())
1832 {
1833 if (namespaceHasNestedClass(cnd,filterClasses,ct))
1834 {
1835 //printf("<namespaceHasNestedClass(%s,filterClasses=%d): case1\n",qPrint(nd->name()),filterClasses);
1836 return true;
1837 }
1838 }
1839
1840 ClassLinkedRefMap list = nd->getClasses();
1841 if (filterClasses)
1842 {
1843 switch (ct)
1844 {
1846 list = nd->getInterfaces();
1847 break;
1848 case ClassDef::Struct:
1849 list = nd->getStructs();
1850 break;
1852 list = nd->getExceptions();
1853 break;
1854 default:
1855 break;
1856 }
1857 }
1858
1859 for (const auto &cd : list)
1860 {
1861 //printf("candidate %s isLinkableInProject()=%d\n",qPrint(cd->name()),cd->isLinkableInProject());
1862 if (cd->isLinkableInProject())
1863 {
1864 //printf("<namespaceHasNestedClass(%s,filterClasses=%d): case2\n",qPrint(nd->name()),filterClasses);
1865 return true;
1866 }
1867 }
1868 //printf("<namespaceHasNestedClass(%s,filterClasses=%d): case3\n",qPrint(nd->name()),filterClasses);
1869 return false;
1870}
@ Interface
Definition classdef.h:112
@ Exception
Definition classdef.h:115
virtual ClassLinkedRefMap getStructs() const =0
virtual ClassLinkedRefMap getExceptions() const =0
virtual ClassLinkedRefMap getClasses() const =0
virtual ClassLinkedRefMap getInterfaces() const =0
bool namespaceHasNestedClass(const NamespaceDef *nd, bool filterClasses, ClassDef::CompoundType ct)

References ClassDef::Exception, NamespaceDef::getClasses(), NamespaceDef::getExceptions(), NamespaceDef::getInterfaces(), NamespaceDef::getNamespaces(), NamespaceDef::getStructs(), ClassDef::Interface, namespaceHasNestedClass(), and ClassDef::Struct.

Referenced by namespaceHasNestedClass(), writeClassTreeInsideNamespaceElement(), and writeNamespaceTreeElement().

◆ namespaceHasNestedConcept()

bool namespaceHasNestedConcept ( const NamespaceDef * nd)

Definition at line 1804 of file namespacedef.cpp.

1805{
1806 //printf(">namespaceHasNestedConcept(%s)\n",qPrint(nd->name()));
1807 for (const auto &cnd : nd->getNamespaces())
1808 {
1810 {
1811 //printf("<namespaceHasNestedConcept(%s): case1\n",qPrint(nd->name()));
1812 return true;
1813 }
1814 }
1815 for (const auto &cnd : nd->getConcepts())
1816 {
1817 //printf("candidate %s isLinkableInProject()=%d\n",qPrint(cnd->name()),cnd->isLinkableInProject());
1818 if (cnd->isLinkableInProject())
1819 {
1820 //printf("<namespaceHasNestedConcept(%s): case2\n",qPrint(nd->name()));
1821 return true;
1822 }
1823 }
1824 //printf("<namespaceHasNestedConcept(%s): case3\n",qPrint(nd->name()));
1825 return false;
1826}
virtual ConceptLinkedRefMap getConcepts() const =0
bool namespaceHasNestedConcept(const NamespaceDef *nd)

References NamespaceDef::getConcepts(), NamespaceDef::getNamespaces(), and namespaceHasNestedConcept().

Referenced by namespaceHasNestedConcept(), writeConceptTreeInsideNamespaceElement(), and writeNamespaceTreeElement().

◆ namespaceHasNestedNamespace()

bool namespaceHasNestedNamespace ( const NamespaceDef * nd)

Definition at line 1792 of file namespacedef.cpp.

1793{
1794 for (const auto &cnd : nd->getNamespaces())
1795 {
1796 if (cnd->isLinkableInProject() && !cnd->isAnonymous())
1797 {
1798 return true;
1799 }
1800 }
1801 return false;
1802}

References NamespaceDef::getNamespaces().

Referenced by writeNamespaceTreeElement().

◆ replaceNamespaceAliases()

void replaceNamespaceAliases ( QCString & name)

Definition at line 1772 of file namespacedef.cpp.

1773{
1774 //printf("> replaceNamespaceAliases(%s)\n",qPrint(name));
1775 StringSet namespacesTried;
1776 name = replaceNamespaceAliasesRec(namespacesTried,name);
1777 //printf("< replaceNamespaceAliases: result=%s\n",qPrint(name));
1778}

References replaceNamespaceAliasesRec().

Referenced by findClassRelation(), findUsedClassesForClass(), getMemberFromSymbol(), SymbolResolver::Private::getResolvedSymbolRec(), SymbolResolver::Private::getResolvedTypeRec(), and NamespaceDefMutable::setInline().

◆ replaceNamespaceAliasesRec()

static QCString replaceNamespaceAliasesRec ( StringSet & namespacesTried,
const QCString & name )
static

Definition at line 1685 of file namespacedef.cpp.

1686{
1687 QCString result = name;
1688 //printf("> replaceNamespaceAliasesRec(%s)\n",qPrint(name));
1689 if (namespacesTried.find(name.str())==namespacesTried.end())
1690 {
1691 namespacesTried.insert(name.str());
1692 size_t p = 0;
1693 for (;;)
1694 {
1695 size_t i = name.str().find("::",p);
1696 if (i==std::string::npos)
1697 {
1698 auto it = Doxygen::namespaceAliasMap.find(name.str());
1699 if (it != Doxygen::namespaceAliasMap.end())
1700 {
1701 //printf("found map %s->%s\n",qPrint(name),qPrint(it->second.alias));
1702 auto ns = getResolvedNamespaceRec(namespacesTried,it->second);
1703 if (ns)
1704 {
1705 result = replaceNamespaceAliasesRec(namespacesTried,ns->qualifiedName());
1706 }
1707 }
1708 break;
1709 }
1710 else
1711 {
1712 auto it = Doxygen::namespaceAliasMap.find(name.left(i).str());
1713 if (it != Doxygen::namespaceAliasMap.end())
1714 {
1715 //printf("found map %s|%s->%s\n",qPrint(name.left(i)),qPrint(name.mid(i)),qPrint(it->second.alias));
1716 auto ns = getResolvedNamespaceRec(namespacesTried,it->second);
1717 if (ns)
1718 {
1719 result = replaceNamespaceAliasesRec(namespacesTried,ns->qualifiedName()+name.mid(i));
1720 break;
1721 }
1722 }
1723 }
1724 p = i+2;
1725 }
1726 }
1727 //printf("< replaceNamespaceAliasesRec(%s)=%s\n",qPrint(name),qPrint(result));
1728 return result;
1729}
static NamespaceAliasInfoMap namespaceAliasMap
Definition doxygen.h:113
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:226
QCString left(size_t len) const
Definition qcstring.h:214
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:175

References end(), getResolvedNamespaceRec(), QCString::left(), QCString::mid(), Doxygen::namespaceAliasMap, replaceNamespaceAliasesRec(), and QCString::str().

Referenced by getResolvedNamespaceRec(), replaceNamespaceAliases(), and replaceNamespaceAliasesRec().

◆ toNamespaceDef() [1/3]

const NamespaceDef * toNamespaceDef ( const Definition * d)

Definition at line 1657 of file namespacedef.cpp.

1658{
1659 if (d && (typeid(*d)==typeid(NamespaceDefImpl) || typeid(*d)==typeid(NamespaceDefAliasImpl)))
1660 {
1661 return static_cast<const NamespaceDef*>(d);
1662 }
1663 else
1664 {
1665 return nullptr;
1666 }
1667}
An abstract interface of a namespace symbol.

◆ toNamespaceDef() [2/3]

◆ toNamespaceDef() [3/3]

NamespaceDef * toNamespaceDef ( DefinitionMutable * md)

Definition at line 1643 of file namespacedef.cpp.

1644{
1645 Definition *d = toDefinition(md);
1646 if (d && typeid(*d)==typeid(NamespaceDefImpl))
1647 {
1648 return static_cast<NamespaceDef*>(d);
1649 }
1650 else
1651 {
1652 return nullptr;
1653 }
1654}
The common base class of all entity definitions found in the sources.
Definition definition.h:76
Definition * toDefinition(DefinitionMutable *dm)

References toDefinition().

◆ toNamespaceDefMutable()