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 174 of file namespacedef.cpp.

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

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 262 of file namespacedef.cpp.

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

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

◆ getResolvedNamespace()

NamespaceDef * getResolvedNamespace ( const QCString & name)

Definition at line 1799 of file namespacedef.cpp.

1800{
1801 //printf("> getResolvedNamespace(%s)\n",qPrint(name));
1802 if (name.isEmpty()) return nullptr;
1803 StringSet namespacesTried;
1804 auto ns = getResolvedNamespaceRec(namespacesTried,NamespaceAliasInfo(name.str()));
1805 //printf("< getResolvedNamespace(%s)=%s\n",qPrint(name),ns?qPrint(ns->qualifiedName()):"nullptr");
1806 return ns;
1807}
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
const std::string & str() const
Definition qcstring.h:552
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()

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

Definition at line 1750 of file namespacedef.cpp.

1751{
1752 size_t j = aliasInfo.context.length();
1753 for (;;)
1754 {
1755 if (j>0)
1756 {
1757 //printf("candidate %s|::%s\n",qPrint(aliasInfo.context.substr(0,j)),qPrint(aliasInfo.alias));
1758 auto candidate = replaceNamespaceAliasesRec(namespacesTried,aliasInfo.context.substr(0,j)+"::"+aliasInfo.alias);
1759 auto nd = Doxygen::namespaceLinkedMap->find(candidate);
1760 if (nd)
1761 {
1762 return nd;
1763 }
1764 }
1765 if (j>0) // strip one level from context, i.e. given N1::N2::N3
1766 // j==10 -> j==6 (N1::N2::N3->N1::N2), and then
1767 // j==6 -> j==2 (N1::N2->N1), and then
1768 // j==2 -> j==std::string::npos (N1->"")
1769 {
1770 j = aliasInfo.context.rfind("::",j-1);
1771 }
1772 else
1773 {
1774 j = std::string::npos;
1775 }
1776 if (j==std::string::npos)
1777 {
1778 //printf("candidate %s\n",qPrint(aliasInfo.alias));
1779 auto candidate = replaceNamespaceAliasesRec(namespacesTried,aliasInfo.alias);
1780 auto nd = Doxygen::namespaceLinkedMap->find(candidate);
1781 if (nd)
1782 {
1783 return nd;
1784 }
1785 break;
1786 }
1787 }
1788 return nullptr;
1789}
static NamespaceLinkedMap * namespaceLinkedMap
Definition doxygen.h:115
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()

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

Definition at line 1511 of file namespacedef.cpp.

1512{
1513 if (level>30)
1514 {
1515 err("Possible recursive namespace relation while inside {}\n",nd->name());
1516 return false;
1517 }
1518 bool found=nd->isLinkableInProject();
1519 if (found)
1520 {
1521 return true;
1522 }
1523 else
1524 {
1525 for (const auto &ind : nd->getNamespaces())
1526 {
1527 found = found || hasNonReferenceNestedNamespaceRec(ind,level+1);
1528 if (found) break;
1529 }
1530 }
1531 return found;
1532}
virtual bool isLinkableInProject() const =0
virtual const QCString & name() const =0
virtual NamespaceLinkedRefMap getNamespaces() const =0
#define err(fmt,...)
Definition message.h:127
static bool hasNonReferenceNestedNamespaceRec(const NamespaceDef *nd, int level)

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

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

◆ makeDisplayName()

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
This is an alternative implementation of QCString.
Definition qcstring.h:101
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:482
SrcLangExt
Definition types.h:207
QCString removeAnonymousScopes(const QCString &str)
Definition util.cpp:173
QCString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Returns the scope separator to use given the programming language lang.
Definition util.cpp:6416

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 1847 of file namespacedef.cpp.

1848{
1849 //printf(">namespaceHasNestedClass(%s,filterClasses=%d)\n",qPrint(nd->name()),filterClasses);
1850 for (const auto &cnd : nd->getNamespaces())
1851 {
1852 if (namespaceHasNestedClass(cnd,filterClasses,ct))
1853 {
1854 //printf("<namespaceHasNestedClass(%s,filterClasses=%d): case1\n",qPrint(nd->name()),filterClasses);
1855 return true;
1856 }
1857 }
1858
1859 ClassLinkedRefMap list = nd->getClasses();
1860 if (filterClasses)
1861 {
1862 switch (ct)
1863 {
1865 list = nd->getInterfaces();
1866 break;
1867 case ClassDef::Struct:
1868 list = nd->getStructs();
1869 break;
1871 list = nd->getExceptions();
1872 break;
1873 default:
1874 break;
1875 }
1876 }
1877
1878 for (const auto &cd : list)
1879 {
1880 //printf("candidate %s isLinkableInProject()=%d\n",qPrint(cd->name()),cd->isLinkableInProject());
1881 if (cd->isLinkableInProject())
1882 {
1883 //printf("<namespaceHasNestedClass(%s,filterClasses=%d): case2\n",qPrint(nd->name()),filterClasses);
1884 return true;
1885 }
1886 }
1887 //printf("<namespaceHasNestedClass(%s,filterClasses=%d): case3\n",qPrint(nd->name()),filterClasses);
1888 return false;
1889}
@ 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 1823 of file namespacedef.cpp.

1824{
1825 //printf(">namespaceHasNestedConcept(%s)\n",qPrint(nd->name()));
1826 for (const auto &cnd : nd->getNamespaces())
1827 {
1829 {
1830 //printf("<namespaceHasNestedConcept(%s): case1\n",qPrint(nd->name()));
1831 return true;
1832 }
1833 }
1834 for (const auto &cnd : nd->getConcepts())
1835 {
1836 //printf("candidate %s isLinkableInProject()=%d\n",qPrint(cnd->name()),cnd->isLinkableInProject());
1837 if (cnd->isLinkableInProject())
1838 {
1839 //printf("<namespaceHasNestedConcept(%s): case2\n",qPrint(nd->name()));
1840 return true;
1841 }
1842 }
1843 //printf("<namespaceHasNestedConcept(%s): case3\n",qPrint(nd->name()));
1844 return false;
1845}
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 1811 of file namespacedef.cpp.

1812{
1813 for (const auto &cnd : nd->getNamespaces())
1814 {
1815 if (cnd->isLinkableInProject() && !cnd->isAnonymous())
1816 {
1817 return true;
1818 }
1819 }
1820 return false;
1821}

References NamespaceDef::getNamespaces().

Referenced by writeNamespaceTreeElement().

◆ replaceNamespaceAliases()

void replaceNamespaceAliases ( QCString & name)

Definition at line 1791 of file namespacedef.cpp.

1792{
1793 //printf("> replaceNamespaceAliases(%s)\n",qPrint(name));
1794 StringSet namespacesTried;
1795 name = replaceNamespaceAliasesRec(namespacesTried,name);
1796 //printf("< replaceNamespaceAliases: result=%s\n",qPrint(name));
1797}

References replaceNamespaceAliasesRec().

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

◆ replaceNamespaceAliasesRec()

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

Definition at line 1704 of file namespacedef.cpp.

1705{
1706 QCString result = name;
1707 //printf("> replaceNamespaceAliasesRec(%s)\n",qPrint(name));
1708 if (namespacesTried.find(name.str())==namespacesTried.end())
1709 {
1710 namespacesTried.insert(name.str());
1711 size_t p = 0;
1712 for (;;)
1713 {
1714 size_t i = name.str().find("::",p);
1715 if (i==std::string::npos)
1716 {
1717 auto it = Doxygen::namespaceAliasMap.find(name.str());
1718 if (it != Doxygen::namespaceAliasMap.end())
1719 {
1720 //printf("found map %s->%s\n",qPrint(name),qPrint(it->second.alias));
1721 auto ns = getResolvedNamespaceRec(namespacesTried,it->second);
1722 if (ns)
1723 {
1724 result = replaceNamespaceAliasesRec(namespacesTried,ns->qualifiedName());
1725 }
1726 }
1727 break;
1728 }
1729 else
1730 {
1731 auto it = Doxygen::namespaceAliasMap.find(name.left(i).str());
1732 if (it != Doxygen::namespaceAliasMap.end())
1733 {
1734 //printf("found map %s|%s->%s\n",qPrint(name.left(i)),qPrint(name.mid(i)),qPrint(it->second.alias));
1735 auto ns = getResolvedNamespaceRec(namespacesTried,it->second);
1736 if (ns)
1737 {
1738 result = replaceNamespaceAliasesRec(namespacesTried,ns->qualifiedName()+name.mid(i));
1739 break;
1740 }
1741 }
1742 }
1743 p = i+2;
1744 }
1745 }
1746 //printf("< replaceNamespaceAliasesRec(%s)=%s\n",qPrint(name),qPrint(result));
1747 return result;
1748}
static NamespaceAliasInfoMap namespaceAliasMap
Definition doxygen.h:113
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:241
QCString left(size_t len) const
Definition qcstring.h:229
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 1676 of file namespacedef.cpp.

1677{
1678 if (d && (typeid(*d)==typeid(NamespaceDefImpl) || typeid(*d)==typeid(NamespaceDefAliasImpl)))
1679 {
1680 return static_cast<const NamespaceDef*>(d);
1681 }
1682 else
1683 {
1684 return nullptr;
1685 }
1686}
An abstract interface of a namespace symbol.

◆ toNamespaceDef() [2/3]

◆ toNamespaceDef() [3/3]

NamespaceDef * toNamespaceDef ( DefinitionMutable * md)

Definition at line 1662 of file namespacedef.cpp.

1663{
1664 Definition *d = toDefinition(md);
1665 if (d && typeid(*d)==typeid(NamespaceDefImpl))
1666 {
1667 return static_cast<NamespaceDef*>(d);
1668 }
1669 else
1670 {
1671 return nullptr;
1672 }
1673}
The common base class of all entity definitions found in the sources.
Definition definition.h:76
Definition * toDefinition(DefinitionMutable *dm)

References toDefinition().

◆ toNamespaceDefMutable()