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

1907{
1908 //printf("> getResolvedNamespace(%s)\n",qPrint(name));
1909 if (name.empty()) return nullptr;
1910 StringSet namespacesTried;
1911 auto ns = getResolvedNamespaceRec(namespacesTried,NamespaceAliasInfo(name.str()));
1912 //printf("< getResolvedNamespace(%s)=%s\n",qPrint(name),ns?qPrint(ns->qualifiedName()):"nullptr");
1913 return ns;
1914}
std::set< std::string > StringSet
Definition containers.h:31
const char * name(int level)
Definition latexgen.h:368
static NamespaceDef * getResolvedNamespaceRec(StringSet &namespacesTried, const NamespaceAliasInfo &aliasInfo)

References getResolvedNamespaceRec().

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

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

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

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

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

1919{
1920 for (const auto &cnd : nd->getNamespaces())
1921 {
1922 if (cnd->isLinkableInProject() && !cnd->isAnonymous())
1923 {
1924 return true;
1925 }
1926 }
1927 return false;
1928}

References NamespaceDef::getNamespaces().

Referenced by writeNamespaceTreeElement().

◆ needsSorting()

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

Definition at line 1542 of file namespacedef.cpp.

1543{
1544 DString prev;
1545 bool allSame = true;
1546 for (const auto &c : container)
1547 {
1548 DString name = c->getDefFileName();
1549 if (!prev.empty() && prev!=name)
1550 {
1551 allSame = false;
1552 break;
1553 }
1554 prev = name;
1555 }
1556 return !allSame || Config_getBool(SORT_BRIEF_DOCS);
1557}
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
#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 1898 of file namespacedef.cpp.

1899{
1900 //printf("> replaceNamespaceAliases(%s)\n",qPrint(name));
1901 StringSet namespacesTried;
1902 name = replaceNamespaceAliasesRec(namespacesTried,name);
1903 //printf("< replaceNamespaceAliases: result=%s\n",qPrint(name));
1904}

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

1812{
1813 DString result = name;
1814 //printf("> replaceNamespaceAliasesRec(%s)\n",qPrint(name));
1815 if (namespacesTried.find(name.str())==namespacesTried.end())
1816 {
1817 namespacesTried.insert(name.str());
1818 size_t p = 0;
1819 for (;;)
1820 {
1821 size_t i = name.str().find("::",p);
1822 if (i==std::string::npos)
1823 {
1824 auto it = Doxygen::namespaceAliasMap.find(name.str());
1825 if (it != Doxygen::namespaceAliasMap.end())
1826 {
1827 //printf("found map %s->%s\n",qPrint(name),qPrint(it->second.alias));
1828 auto ns = getResolvedNamespaceRec(namespacesTried,it->second);
1829 if (ns)
1830 {
1831 result = replaceNamespaceAliasesRec(namespacesTried,ns->qualifiedName());
1832 }
1833 }
1834 break;
1835 }
1836 else
1837 {
1838 auto it = Doxygen::namespaceAliasMap.find(name.left(i).str());
1839 if (it != Doxygen::namespaceAliasMap.end())
1840 {
1841 //printf("found map %s|%s->%s\n",qPrint(name.left(i)),qPrint(name.mid(i)),qPrint(it->second.alias));
1842 auto ns = getResolvedNamespaceRec(namespacesTried,it->second);
1843 if (ns)
1844 {
1845 result = replaceNamespaceAliasesRec(namespacesTried,ns->qualifiedName()+name.mid(i));
1846 break;
1847 }
1848 }
1849 }
1850 p = i+2;
1851 }
1852 }
1853 //printf("< replaceNamespaceAliasesRec(%s)=%s\n",qPrint(name),qPrint(result));
1854 return result;
1855}
static NamespaceAliasInfoMap namespaceAliasMap
Definition doxygen.h:106
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:181

References end(), getResolvedNamespaceRec(), Doxygen::namespaceAliasMap, and replaceNamespaceAliasesRec().

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

◆ toNamespaceDef() [1/3]

const NamespaceDef * toNamespaceDef ( const Definition * d)

Definition at line 1783 of file namespacedef.cpp.

1784{
1785 if (d && (typeid(*d)==typeid(NamespaceDefImpl) || typeid(*d)==typeid(NamespaceDefAliasImpl)))
1786 {
1787 return static_cast<const NamespaceDef*>(d);
1788 }
1789 else
1790 {
1791 return nullptr;
1792 }
1793}
An abstract interface of a namespace symbol.

◆ toNamespaceDef() [2/3]

◆ toNamespaceDef() [3/3]

NamespaceDef * toNamespaceDef ( DefinitionMutable * md)

Definition at line 1769 of file namespacedef.cpp.

1770{
1771 Definition *d = toDefinition(md);
1772 if (d && typeid(*d)==typeid(NamespaceDefImpl))
1773 {
1774 return static_cast<NamespaceDef*>(d);
1775 }
1776 else
1777 {
1778 return nullptr;
1779 }
1780}
The common base class of all entity definitions found in the sources.
Definition definition.h:77
Definition * toDefinition(DefinitionMutable *dm)

References toDefinition().

◆ toNamespaceDefMutable()