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

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

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

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

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

◆ getResolvedNamespace()

NamespaceDef * getResolvedNamespace ( const DString & name)

Definition at line 1940 of file namespacedef.cpp.

1941{
1942 //printf("> getResolvedNamespace(%s)\n",qPrint(name));
1943 if (name.empty()) return nullptr;
1944 StringSet namespacesTried;
1945 auto ns = getResolvedNamespaceRec(namespacesTried,NamespaceAliasInfo(name.str()));
1946 //printf("< getResolvedNamespace(%s)=%s\n",qPrint(name),ns?qPrint(ns->qualifiedName()):"nullptr");
1947 return ns;
1948}
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(), findFieldDocumentation(), 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 1891 of file namespacedef.cpp.

1892{
1893 size_t j = aliasInfo.context.length();
1894 for (;;)
1895 {
1896 if (j>0)
1897 {
1898 //printf("candidate %s|::%s\n",qPrint(aliasInfo.context.substr(0,j)),qPrint(aliasInfo.alias));
1899 auto candidate = replaceNamespaceAliasesRec(namespacesTried,aliasInfo.context.substr(0,j)+"::"+aliasInfo.alias);
1900 auto nd = Doxygen::namespaceLinkedMap->find(candidate);
1901 if (nd)
1902 {
1903 return nd;
1904 }
1905 }
1906 if (j>0) // strip one level from context, i.e. given N1::N2::N3
1907 // j==10 -> j==6 (N1::N2::N3->N1::N2), and then
1908 // j==6 -> j==2 (N1::N2->N1), and then
1909 // j==2 -> j==std::string::npos (N1->"")
1910 {
1911 j = aliasInfo.context.rfind("::",j-1);
1912 }
1913 else
1914 {
1915 j = std::string::npos;
1916 }
1917 if (j==std::string::npos)
1918 {
1919 //printf("candidate %s\n",qPrint(aliasInfo.alias));
1920 auto candidate = replaceNamespaceAliasesRec(namespacesTried,aliasInfo.alias);
1921 auto nd = Doxygen::namespaceLinkedMap->find(candidate);
1922 if (nd)
1923 {
1924 return nd;
1925 }
1926 break;
1927 }
1928 }
1929 return nullptr;
1930}
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 1648 of file namespacedef.cpp.

1649{
1650 if (level>30)
1651 {
1652 err("Possible recursive namespace relation while inside {}\n",nd->name());
1653 return false;
1654 }
1655 bool found=nd->isLinkableInProject();
1656 if (found)
1657 {
1658 return true;
1659 }
1660 else
1661 {
1662 for (const auto &ind : nd->getNamespaces())
1663 {
1664 found = found || hasNonReferenceNestedNamespaceRec(ind,level+1);
1665 if (found) break;
1666 }
1667 }
1668 return found;
1669}
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:4765
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 1988 of file namespacedef.cpp.

1989{
1990 //printf(">namespaceHasNestedClass(%s,filterClasses=%d)\n",qPrint(nd->name()),filterClasses);
1991 for (const auto &cnd : nd->getNamespaces())
1992 {
1993 if (namespaceHasNestedClass(cnd,filterClasses,ct))
1994 {
1995 //printf("<namespaceHasNestedClass(%s,filterClasses=%d): case1\n",qPrint(nd->name()),filterClasses);
1996 return true;
1997 }
1998 }
1999
2000 ClassLinkedRefMap list = nd->getClasses();
2001 if (filterClasses)
2002 {
2003 switch (ct)
2004 {
2006 list = nd->getInterfaces();
2007 break;
2008 case ClassDef::Struct:
2009 list = nd->getStructs();
2010 break;
2011 case ClassDef::Record:
2012 list = nd->getRecords();
2013 break;
2015 list = nd->getExceptions();
2016 break;
2017 default:
2018 break;
2019 }
2020 }
2021
2022 for (const auto &cd : list)
2023 {
2024 //printf("candidate %s isLinkableInProject()=%d\n",qPrint(cd->name()),cd->isLinkableInProject());
2025 if (cd->isLinkableInProject())
2026 {
2027 //printf("<namespaceHasNestedClass(%s,filterClasses=%d): case2\n",qPrint(nd->name()),filterClasses);
2028 return true;
2029 }
2030 }
2031 //printf("<namespaceHasNestedClass(%s,filterClasses=%d): case3\n",qPrint(nd->name()),filterClasses);
2032 return false;
2033}
@ Interface
Definition classdef.h:109
@ Exception
Definition classdef.h:112
virtual ClassLinkedRefMap getRecords() const =0
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::getRecords(), NamespaceDef::getStructs(), ClassDef::Interface, namespaceHasNestedClass(), ClassDef::Record, and ClassDef::Struct.

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

◆ namespaceHasNestedConcept()

bool namespaceHasNestedConcept ( const NamespaceDef * nd)

Definition at line 1964 of file namespacedef.cpp.

1965{
1966 //printf(">namespaceHasNestedConcept(%s)\n",qPrint(nd->name()));
1967 for (const auto &cnd : nd->getNamespaces())
1968 {
1970 {
1971 //printf("<namespaceHasNestedConcept(%s): case1\n",qPrint(nd->name()));
1972 return true;
1973 }
1974 }
1975 for (const auto &cnd : nd->getConcepts())
1976 {
1977 //printf("candidate %s isLinkableInProject()=%d\n",qPrint(cnd->name()),cnd->isLinkableInProject());
1978 if (cnd->isLinkableInProject())
1979 {
1980 //printf("<namespaceHasNestedConcept(%s): case2\n",qPrint(nd->name()));
1981 return true;
1982 }
1983 }
1984 //printf("<namespaceHasNestedConcept(%s): case3\n",qPrint(nd->name()));
1985 return false;
1986}
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 1952 of file namespacedef.cpp.

1953{
1954 for (const auto &cnd : nd->getNamespaces())
1955 {
1956 if (cnd->isLinkableInProject() && !cnd->isAnonymous())
1957 {
1958 return true;
1959 }
1960 }
1961 return false;
1962}

References NamespaceDef::getNamespaces().

Referenced by writeNamespaceTreeElement().

◆ needsSorting()

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

Definition at line 1571 of file namespacedef.cpp.

1572{
1573 DString prev;
1574 bool allSame = true;
1575 for (const auto &c : container)
1576 {
1577 DString name = c->getDefFileName();
1578 if (!prev.empty() && prev!=name)
1579 {
1580 allSame = false;
1581 break;
1582 }
1583 prev = name;
1584 }
1585 return !allSame || Config_getBool(SORT_BRIEF_DOCS);
1586}
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 1932 of file namespacedef.cpp.

1933{
1934 //printf("> replaceNamespaceAliases(%s)\n",qPrint(name));
1935 StringSet namespacesTried;
1936 name = replaceNamespaceAliasesRec(namespacesTried,name);
1937 //printf("< replaceNamespaceAliases: result=%s\n",qPrint(name));
1938}

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

1846{
1847 DString result = name;
1848 //printf("> replaceNamespaceAliasesRec(%s)\n",qPrint(name));
1849 if (namespacesTried.find(name.str())==namespacesTried.end())
1850 {
1851 namespacesTried.insert(name.str());
1852 size_t p = 0;
1853 for (;;)
1854 {
1855 size_t i = name.str().find("::",p);
1856 if (i==std::string::npos)
1857 {
1858 auto it = Doxygen::namespaceAliasMap.find(name.str());
1859 if (it != Doxygen::namespaceAliasMap.end())
1860 {
1861 //printf("found map %s->%s\n",qPrint(name),qPrint(it->second.alias));
1862 auto ns = getResolvedNamespaceRec(namespacesTried,it->second);
1863 if (ns)
1864 {
1865 result = replaceNamespaceAliasesRec(namespacesTried,ns->qualifiedName());
1866 }
1867 }
1868 break;
1869 }
1870 else
1871 {
1872 auto it = Doxygen::namespaceAliasMap.find(name.left(i).str());
1873 if (it != Doxygen::namespaceAliasMap.end())
1874 {
1875 //printf("found map %s|%s->%s\n",qPrint(name.left(i)),qPrint(name.mid(i)),qPrint(it->second.alias));
1876 auto ns = getResolvedNamespaceRec(namespacesTried,it->second);
1877 if (ns)
1878 {
1879 result = replaceNamespaceAliasesRec(namespacesTried,ns->qualifiedName()+name.mid(i));
1880 break;
1881 }
1882 }
1883 }
1884 p = i+2;
1885 }
1886 }
1887 //printf("< replaceNamespaceAliasesRec(%s)=%s\n",qPrint(name),qPrint(result));
1888 return result;
1889}
static NamespaceAliasInfoMap namespaceAliasMap
Definition doxygen.h:106
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:180

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

1818{
1819 if (d && (typeid(*d)==typeid(NamespaceDefImpl) || typeid(*d)==typeid(NamespaceDefAliasImpl)))
1820 {
1821 return static_cast<const NamespaceDef*>(d);
1822 }
1823 else
1824 {
1825 return nullptr;
1826 }
1827}
An abstract interface of a namespace symbol.

◆ toNamespaceDef() [2/3]

◆ toNamespaceDef() [3/3]

NamespaceDef * toNamespaceDef ( DefinitionMutable * md)

Definition at line 1803 of file namespacedef.cpp.

1804{
1805 Definition *d = toDefinition(md);
1806 if (d && typeid(*d)==typeid(NamespaceDefImpl))
1807 {
1808 return static_cast<NamespaceDef*>(d);
1809 }
1810 else
1811 {
1812 return nullptr;
1813 }
1814}
The common base class of all entity definitions found in the sources.
Definition definition.h:77
Definition * toDefinition(DefinitionMutable *dm)

References toDefinition().

◆ toNamespaceDefMutable()