Doxygen
Loading...
Searching...
No Matches
namespacedef.cpp File Reference
#include "namespacedef.h"
#include <map>
#include <memory>
#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< 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.
std::unique_ptr< NamespaceDef > createNamespaceDefAlias (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)
NamespaceDef * toNamespaceDef (Definition *d)
NamespaceDef * toNamespaceDef (DefinitionMutable *md)
const NamespaceDef * toNamespaceDef (const Definition *d)
NamespaceDefMutable * toNamespaceDefMutable (Definition *d)
static NamespaceDef * getResolvedNamespaceRec (StringSet &namespacesTried, const NamespaceAliasInfo &aliasInfo)
static DString replaceNamespaceAliasesRec (StringSet &namespacesTried, const DString &name)
void replaceNamespaceAliases (DString &name)
NamespaceDef * getResolvedNamespace (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 180 of file namespacedef.cpp.

184{
185 //printf("createNamespaceDef(%s)\n",qPrint(name));
186 return std::make_unique<NamespaceDefImpl>(defFileName,defLine,defColumn,name,ref,refFile,type,isPublished);
187}

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

269{
270 auto alnd = std::make_unique<NamespaceDefAliasImpl>(newScope,nd);
271 //printf("alnd name=%s localName=%s qualifiedName=%s displayName()=%s\n",
272 // qPrint(alnd->name()),qPrint(alnd->localName()),qPrint(alnd->qualifiedName()),
273 // qPrint(alnd->displayName()));
274 return alnd;
275}

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

◆ getResolvedNamespace()

NamespaceDef * getResolvedNamespace ( const DString & name)

Definition at line 1900 of file namespacedef.cpp.

1901{
1902 //printf("> getResolvedNamespace(%s)\n",qPrint(name));
1903 if (name.empty()) return nullptr;
1904 StringSet namespacesTried;
1905 auto ns = getResolvedNamespaceRec(namespacesTried,NamespaceAliasInfo(name.str()));
1906 //printf("< getResolvedNamespace(%s)=%s\n",qPrint(name),ns?qPrint(ns->qualifiedName()):"nullptr");
1907 return ns;
1908}
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 1851 of file namespacedef.cpp.

1852{
1853 size_t j = aliasInfo.context.length();
1854 for (;;)
1855 {
1856 if (j>0)
1857 {
1858 //printf("candidate %s|::%s\n",qPrint(aliasInfo.context.substr(0,j)),qPrint(aliasInfo.alias));
1859 auto candidate = replaceNamespaceAliasesRec(namespacesTried,aliasInfo.context.substr(0,j)+"::"+aliasInfo.alias);
1860 auto nd = Doxygen::namespaceLinkedMap->find(candidate);
1861 if (nd)
1862 {
1863 return nd;
1864 }
1865 }
1866 if (j>0) // strip one level from context, i.e. given N1::N2::N3
1867 // j==10 -> j==6 (N1::N2::N3->N1::N2), and then
1868 // j==6 -> j==2 (N1::N2->N1), and then
1869 // j==2 -> j==std::string::npos (N1->"")
1870 {
1871 j = aliasInfo.context.rfind("::",j-1);
1872 }
1873 else
1874 {
1875 j = std::string::npos;
1876 }
1877 if (j==std::string::npos)
1878 {
1879 //printf("candidate %s\n",qPrint(aliasInfo.alias));
1880 auto candidate = replaceNamespaceAliasesRec(namespacesTried,aliasInfo.alias);
1881 auto nd = Doxygen::namespaceLinkedMap->find(candidate);
1882 if (nd)
1883 {
1884 return nd;
1885 }
1886 break;
1887 }
1888 }
1889 return nullptr;
1890}
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 1612 of file namespacedef.cpp.

1613{
1614 if (level>30)
1615 {
1616 err("Possible recursive namespace relation while inside {}\n",nd->name());
1617 return false;
1618 }
1619 bool found=nd->isLinkableInProject();
1620 if (found)
1621 {
1622 return true;
1623 }
1624 else
1625 {
1626 for (const auto &ind : nd->getNamespaces())
1627 {
1628 found = found || hasNonReferenceNestedNamespaceRec(ind,level+1);
1629 if (found) break;
1630 }
1631 }
1632 return found;
1633}
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 40 of file namespacedef.cpp.

41{
42 DString result=includeScope ? nd->name() : nd->localName();
43 SrcLangExt lang = nd->getLanguage();
45 if (sep!="::")
46 {
47 result = substitute(result,"::",sep);
48 }
49 if (nd->isAnonymous())
50 {
51 result = removeAnonymousScopes(result);
52 }
53 //printf("makeDisplayName() %s->%s lang=%d\n",qPrint(name()),qPrint(result),lang);
54 return result;
55}
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:4630
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 1948 of file namespacedef.cpp.

1949{
1950 //printf(">namespaceHasNestedClass(%s,filterClasses=%d)\n",qPrint(nd->name()),filterClasses);
1951 for (const auto &cnd : nd->getNamespaces())
1952 {
1953 if (namespaceHasNestedClass(cnd,filterClasses,ct))
1954 {
1955 //printf("<namespaceHasNestedClass(%s,filterClasses=%d): case1\n",qPrint(nd->name()),filterClasses);
1956 return true;
1957 }
1958 }
1959
1960 ClassLinkedRefMap list = nd->getClasses();
1961 if (filterClasses)
1962 {
1963 switch (ct)
1964 {
1966 list = nd->getInterfaces();
1967 break;
1968 case ClassDef::Struct:
1969 list = nd->getStructs();
1970 break;
1972 list = nd->getExceptions();
1973 break;
1974 default:
1975 break;
1976 }
1977 }
1978
1979 for (const auto &cd : list)
1980 {
1981 //printf("candidate %s isLinkableInProject()=%d\n",qPrint(cd->name()),cd->isLinkableInProject());
1982 if (cd->isLinkableInProject())
1983 {
1984 //printf("<namespaceHasNestedClass(%s,filterClasses=%d): case2\n",qPrint(nd->name()),filterClasses);
1985 return true;
1986 }
1987 }
1988 //printf("<namespaceHasNestedClass(%s,filterClasses=%d): case3\n",qPrint(nd->name()),filterClasses);
1989 return false;
1990}
@ 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 1924 of file namespacedef.cpp.

1925{
1926 //printf(">namespaceHasNestedConcept(%s)\n",qPrint(nd->name()));
1927 for (const auto &cnd : nd->getNamespaces())
1928 {
1930 {
1931 //printf("<namespaceHasNestedConcept(%s): case1\n",qPrint(nd->name()));
1932 return true;
1933 }
1934 }
1935 for (const auto &cnd : nd->getConcepts())
1936 {
1937 //printf("candidate %s isLinkableInProject()=%d\n",qPrint(cnd->name()),cnd->isLinkableInProject());
1938 if (cnd->isLinkableInProject())
1939 {
1940 //printf("<namespaceHasNestedConcept(%s): case2\n",qPrint(nd->name()));
1941 return true;
1942 }
1943 }
1944 //printf("<namespaceHasNestedConcept(%s): case3\n",qPrint(nd->name()));
1945 return false;
1946}
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 1912 of file namespacedef.cpp.

1913{
1914 for (const auto &cnd : nd->getNamespaces())
1915 {
1916 if (cnd->isLinkableInProject() && !cnd->isAnonymous())
1917 {
1918 return true;
1919 }
1920 }
1921 return false;
1922}

References NamespaceDef::getNamespaces().

Referenced by writeNamespaceTreeElement().

◆ needsSorting()

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

Definition at line 1536 of file namespacedef.cpp.

1537{
1538 DString prev;
1539 bool allSame = true;
1540 for (const auto &c : container)
1541 {
1542 DString name = c->getDefFileName();
1543 if (!prev.empty() && prev!=name)
1544 {
1545 allSame = false;
1546 break;
1547 }
1548 prev = name;
1549 }
1550 return !allSame || Config_getBool(SORT_BRIEF_DOCS);
1551}
#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 1892 of file namespacedef.cpp.

1893{
1894 //printf("> replaceNamespaceAliases(%s)\n",qPrint(name));
1895 StringSet namespacesTried;
1896 name = replaceNamespaceAliasesRec(namespacesTried,name);
1897 //printf("< replaceNamespaceAliases: result=%s\n",qPrint(name));
1898}

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

1806{
1807 DString result = name;
1808 //printf("> replaceNamespaceAliasesRec(%s)\n",qPrint(name));
1809 if (namespacesTried.find(name.str())==namespacesTried.end())
1810 {
1811 namespacesTried.insert(name.str());
1812 size_t p = 0;
1813 for (;;)
1814 {
1815 size_t i = name.str().find("::",p);
1816 if (i==std::string::npos)
1817 {
1818 auto it = Doxygen::namespaceAliasMap.find(name.str());
1819 if (it != Doxygen::namespaceAliasMap.end())
1820 {
1821 //printf("found map %s->%s\n",qPrint(name),qPrint(it->second.alias));
1822 auto ns = getResolvedNamespaceRec(namespacesTried,it->second);
1823 if (ns)
1824 {
1825 result = replaceNamespaceAliasesRec(namespacesTried,ns->qualifiedName());
1826 }
1827 }
1828 break;
1829 }
1830 else
1831 {
1832 auto it = Doxygen::namespaceAliasMap.find(name.left(i).str());
1833 if (it != Doxygen::namespaceAliasMap.end())
1834 {
1835 //printf("found map %s|%s->%s\n",qPrint(name.left(i)),qPrint(name.mid(i)),qPrint(it->second.alias));
1836 auto ns = getResolvedNamespaceRec(namespacesTried,it->second);
1837 if (ns)
1838 {
1839 result = replaceNamespaceAliasesRec(namespacesTried,ns->qualifiedName()+name.mid(i));
1840 break;
1841 }
1842 }
1843 }
1844 p = i+2;
1845 }
1846 }
1847 //printf("< replaceNamespaceAliasesRec(%s)=%s\n",qPrint(name),qPrint(result));
1848 return result;
1849}
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 1777 of file namespacedef.cpp.

1778{
1779 if (d && (typeid(*d)==typeid(NamespaceDefImpl) || typeid(*d)==typeid(NamespaceDefAliasImpl)))
1780 {
1781 return static_cast<const NamespaceDef*>(d);
1782 }
1783 else
1784 {
1785 return nullptr;
1786 }
1787}
An abstract interface of a namespace symbol.

◆ toNamespaceDef() [2/3]

◆ toNamespaceDef() [3/3]

NamespaceDef * toNamespaceDef ( DefinitionMutable * md)

Definition at line 1763 of file namespacedef.cpp.

1764{
1765 Definition *d = toDefinition(md);
1766 if (d && typeid(*d)==typeid(NamespaceDefImpl))
1767 {
1768 return static_cast<NamespaceDef*>(d);
1769 }
1770 else
1771 {
1772 return nullptr;
1773 }
1774}
The common base class of all entity definitions found in the sources.
Definition definition.h:77
Definition * toDefinition(DefinitionMutable *dm)

References toDefinition().

◆ toNamespaceDefMutable()