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

Go to the source code of this file.

Classes

class  NamespaceDefImpl
class  NamespaceDefAliasImpl

Functions

static DString makeDisplayName (const NamespaceDef *nd, bool includeScope)
std::unique_ptr< NamespaceDefcreateNamespaceDef (const DString &defFileName, int defLine, size_t defColumn, const DString &name, const DString &ref, const DString &refFile, const DString &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.
template<class Container>
bool needsSorting (const Container &container)
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 DString replaceNamespaceAliasesRec (StringSet &namespacesTried, const DString &name)
void replaceNamespaceAliases (DString &name)
NamespaceDefgetResolvedNamespace (const DString &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 DString & defFileName,
int defLine,
size_t defColumn,
const DString & name,
const DString & ref,
const DString & refFile,
const DString & 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 DString & name)

Definition at line 1842 of file namespacedef.cpp.

1843{
1844 //printf("> getResolvedNamespace(%s)\n",qPrint(name));
1845 if (name.empty()) return nullptr;
1846 StringSet namespacesTried;
1847 auto ns = getResolvedNamespaceRec(namespacesTried,NamespaceAliasInfo(name.str()));
1848 //printf("< getResolvedNamespace(%s)=%s\n",qPrint(name),ns?qPrint(ns->qualifiedName()):"nullptr");
1849 return ns;
1850}
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
const std::string & str() const
Definition dstring.h:645
std::set< std::string > StringSet
Definition containers.h:31
static NamespaceDef * getResolvedNamespaceRec(StringSet &namespacesTried, const NamespaceAliasInfo &aliasInfo)

References DString::empty(), getResolvedNamespaceRec(), and DString::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 1793 of file namespacedef.cpp.

1794{
1795 size_t j = aliasInfo.context.length();
1796 for (;;)
1797 {
1798 if (j>0)
1799 {
1800 //printf("candidate %s|::%s\n",qPrint(aliasInfo.context.substr(0,j)),qPrint(aliasInfo.alias));
1801 auto candidate = replaceNamespaceAliasesRec(namespacesTried,aliasInfo.context.substr(0,j)+"::"+aliasInfo.alias);
1802 auto nd = Doxygen::namespaceLinkedMap->find(candidate);
1803 if (nd)
1804 {
1805 return nd;
1806 }
1807 }
1808 if (j>0) // strip one level from context, i.e. given N1::N2::N3
1809 // j==10 -> j==6 (N1::N2::N3->N1::N2), and then
1810 // j==6 -> j==2 (N1::N2->N1), and then
1811 // j==2 -> j==std::string::npos (N1->"")
1812 {
1813 j = aliasInfo.context.rfind("::",j-1);
1814 }
1815 else
1816 {
1817 j = std::string::npos;
1818 }
1819 if (j==std::string::npos)
1820 {
1821 //printf("candidate %s\n",qPrint(aliasInfo.alias));
1822 auto candidate = replaceNamespaceAliasesRec(namespacesTried,aliasInfo.alias);
1823 auto nd = Doxygen::namespaceLinkedMap->find(candidate);
1824 if (nd)
1825 {
1826 return nd;
1827 }
1828 break;
1829 }
1830 }
1831 return nullptr;
1832}
static NamespaceLinkedMap * namespaceLinkedMap
Definition doxygen.h:108
const T * find(const std::string &key) const
Definition linkedmap.h:47
static DString replaceNamespaceAliasesRec(StringSet &namespacesTried, const DString &name)
std::string context
Definition doxygen.h:70
std::string alias
Definition doxygen.h:69

References NamespaceAliasInfo::alias, NamespaceAliasInfo::context, LinkedMap< T, Hash, KeyEqual, Map >::find(), Doxygen::namespaceLinkedMap, and replaceNamespaceAliasesRec().

Referenced by getResolvedNamespace(), and replaceNamespaceAliasesRec().

◆ hasNonReferenceNestedNamespaceRec()

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

Definition at line 1554 of file namespacedef.cpp.

1555{
1556 if (level>30)
1557 {
1558 err("Possible recursive namespace relation while inside {}\n",nd->name());
1559 return false;
1560 }
1561 bool found=nd->isLinkableInProject();
1562 if (found)
1563 {
1564 return true;
1565 }
1566 else
1567 {
1568 for (const auto &ind : nd->getNamespaces())
1569 {
1570 found = found || hasNonReferenceNestedNamespaceRec(ind,level+1);
1571 if (found) break;
1572 }
1573 }
1574 return found;
1575}
virtual const DString & name() const =0
virtual bool isLinkableInProject() 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()

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

Definition at line 37 of file namespacedef.cpp.

38{
39 DString result=includeScope ? nd->name() : nd->localName();
40 SrcLangExt lang = nd->getLanguage();
42 if (sep!="::")
43 {
44 result = substitute(result,"::",sep);
45 }
46 if (nd->isAnonymous())
47 {
48 result = removeAnonymousScopes(result);
49 }
50 //printf("makeDisplayName() %s->%s lang=%d\n",qPrint(name()),qPrint(result),lang);
51 return result;
52}
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
virtual const DString & localName() const =0
virtual bool isAnonymous() const =0
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
Definition dstring.cpp:485
SrcLangExt
Definition types.h:207
DString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Definition util.cpp:4629
DString removeAnonymousScopes(const DString &str)
Definition util.cpp:98

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

1891{
1892 //printf(">namespaceHasNestedClass(%s,filterClasses=%d)\n",qPrint(nd->name()),filterClasses);
1893 for (const auto &cnd : nd->getNamespaces())
1894 {
1895 if (namespaceHasNestedClass(cnd,filterClasses,ct))
1896 {
1897 //printf("<namespaceHasNestedClass(%s,filterClasses=%d): case1\n",qPrint(nd->name()),filterClasses);
1898 return true;
1899 }
1900 }
1901
1902 ClassLinkedRefMap list = nd->getClasses();
1903 if (filterClasses)
1904 {
1905 switch (ct)
1906 {
1908 list = nd->getInterfaces();
1909 break;
1910 case ClassDef::Struct:
1911 list = nd->getStructs();
1912 break;
1914 list = nd->getExceptions();
1915 break;
1916 default:
1917 break;
1918 }
1919 }
1920
1921 for (const auto &cd : list)
1922 {
1923 //printf("candidate %s isLinkableInProject()=%d\n",qPrint(cd->name()),cd->isLinkableInProject());
1924 if (cd->isLinkableInProject())
1925 {
1926 //printf("<namespaceHasNestedClass(%s,filterClasses=%d): case2\n",qPrint(nd->name()),filterClasses);
1927 return true;
1928 }
1929 }
1930 //printf("<namespaceHasNestedClass(%s,filterClasses=%d): case3\n",qPrint(nd->name()),filterClasses);
1931 return false;
1932}
@ Interface
Definition classdef.h:108
@ Exception
Definition classdef.h:111
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 1866 of file namespacedef.cpp.

1867{
1868 //printf(">namespaceHasNestedConcept(%s)\n",qPrint(nd->name()));
1869 for (const auto &cnd : nd->getNamespaces())
1870 {
1872 {
1873 //printf("<namespaceHasNestedConcept(%s): case1\n",qPrint(nd->name()));
1874 return true;
1875 }
1876 }
1877 for (const auto &cnd : nd->getConcepts())
1878 {
1879 //printf("candidate %s isLinkableInProject()=%d\n",qPrint(cnd->name()),cnd->isLinkableInProject());
1880 if (cnd->isLinkableInProject())
1881 {
1882 //printf("<namespaceHasNestedConcept(%s): case2\n",qPrint(nd->name()));
1883 return true;
1884 }
1885 }
1886 //printf("<namespaceHasNestedConcept(%s): case3\n",qPrint(nd->name()));
1887 return false;
1888}
virtual ConceptLinkedRefMap getConcepts() const =0
bool namespaceHasNestedConcept(const NamespaceDef *nd)

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

Referenced by namespaceHasNestedConcept(), and writeNamespaceTreeElement().

◆ namespaceHasNestedNamespace()

bool namespaceHasNestedNamespace ( const NamespaceDef * nd)

Definition at line 1854 of file namespacedef.cpp.

1855{
1856 for (const auto &cnd : nd->getNamespaces())
1857 {
1858 if (cnd->isLinkableInProject() && !cnd->isAnonymous())
1859 {
1860 return true;
1861 }
1862 }
1863 return false;
1864}

References NamespaceDef::getNamespaces().

Referenced by writeNamespaceTreeElement().

◆ needsSorting()

template<class Container>
bool needsSorting ( const Container & container)

Definition at line 1478 of file namespacedef.cpp.

1479{
1480 DString prev;
1481 bool allSame = true;
1482 for (const auto &c : container)
1483 {
1484 DString name = c->getDefFileName();
1485 if (!prev.empty() && prev!=name)
1486 {
1487 allSame = false;
1488 break;
1489 }
1490 prev = name;
1491 }
1492 return !allSame || Config_getBool(SORT_BRIEF_DOCS);
1493}
#define Config_getBool(name)
Definition config.h:33

References Config_getBool, and DString::empty().

Referenced by NamespaceDefImpl::sortMemberLists().

◆ replaceNamespaceAliases()

void replaceNamespaceAliases ( DString & name)

Definition at line 1834 of file namespacedef.cpp.

1835{
1836 //printf("> replaceNamespaceAliases(%s)\n",qPrint(name));
1837 StringSet namespacesTried;
1838 name = replaceNamespaceAliasesRec(namespacesTried,name);
1839 //printf("< replaceNamespaceAliases: result=%s\n",qPrint(name));
1840}

References replaceNamespaceAliasesRec().

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

◆ replaceNamespaceAliasesRec()

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

Definition at line 1747 of file namespacedef.cpp.

1748{
1749 DString result = name;
1750 //printf("> replaceNamespaceAliasesRec(%s)\n",qPrint(name));
1751 if (namespacesTried.find(name.str())==namespacesTried.end())
1752 {
1753 namespacesTried.insert(name.str());
1754 size_t p = 0;
1755 for (;;)
1756 {
1757 size_t i = name.str().find("::",p);
1758 if (i==std::string::npos)
1759 {
1760 auto it = Doxygen::namespaceAliasMap.find(name.str());
1761 if (it != Doxygen::namespaceAliasMap.end())
1762 {
1763 //printf("found map %s->%s\n",qPrint(name),qPrint(it->second.alias));
1764 auto ns = getResolvedNamespaceRec(namespacesTried,it->second);
1765 if (ns)
1766 {
1767 result = replaceNamespaceAliasesRec(namespacesTried,ns->qualifiedName());
1768 }
1769 }
1770 break;
1771 }
1772 else
1773 {
1774 auto it = Doxygen::namespaceAliasMap.find(name.left(i).str());
1775 if (it != Doxygen::namespaceAliasMap.end())
1776 {
1777 //printf("found map %s|%s->%s\n",qPrint(name.left(i)),qPrint(name.mid(i)),qPrint(it->second.alias));
1778 auto ns = getResolvedNamespaceRec(namespacesTried,it->second);
1779 if (ns)
1780 {
1781 result = replaceNamespaceAliasesRec(namespacesTried,ns->qualifiedName()+name.mid(i));
1782 break;
1783 }
1784 }
1785 }
1786 p = i+2;
1787 }
1788 }
1789 //printf("< replaceNamespaceAliasesRec(%s)=%s\n",qPrint(name),qPrint(result));
1790 return result;
1791}
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:318
DString left(size_t len) const
Definition dstring.h:306
static NamespaceAliasInfoMap namespaceAliasMap
Definition doxygen.h:106
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:181

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

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

◆ toNamespaceDef() [1/3]

const NamespaceDef * toNamespaceDef ( const Definition * d)

Definition at line 1719 of file namespacedef.cpp.

1720{
1721 if (d && (typeid(*d)==typeid(NamespaceDefImpl) || typeid(*d)==typeid(NamespaceDefAliasImpl)))
1722 {
1723 return static_cast<const NamespaceDef*>(d);
1724 }
1725 else
1726 {
1727 return nullptr;
1728 }
1729}
An abstract interface of a namespace symbol.

◆ toNamespaceDef() [2/3]

◆ toNamespaceDef() [3/3]

NamespaceDef * toNamespaceDef ( DefinitionMutable * md)

Definition at line 1705 of file namespacedef.cpp.

1706{
1707 Definition *d = toDefinition(md);
1708 if (d && typeid(*d)==typeid(NamespaceDefImpl))
1709 {
1710 return static_cast<NamespaceDef*>(d);
1711 }
1712 else
1713 {
1714 return nullptr;
1715 }
1716}
The common base class of all entity definitions found in the sources.
Definition definition.h:77
Definition * toDefinition(DefinitionMutable *dm)

References toDefinition().

◆ toNamespaceDefMutable()