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

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

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

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

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

◆ getResolvedNamespace()

NamespaceDef * getResolvedNamespace ( const QCString & name)

Definition at line 1845 of file namespacedef.cpp.

1846{
1847 //printf("> getResolvedNamespace(%s)\n",qPrint(name));
1848 if (name.isEmpty()) return nullptr;
1849 StringSet namespacesTried;
1850 auto ns = getResolvedNamespaceRec(namespacesTried,NamespaceAliasInfo(name.str()));
1851 //printf("< getResolvedNamespace(%s)=%s\n",qPrint(name),ns?qPrint(ns->qualifiedName()):"nullptr");
1852 return ns;
1853}
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(), NamespaceDefMutable::setInline(), and writeAlphabeticalClassList().

◆ getResolvedNamespaceRec()

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

Definition at line 1796 of file namespacedef.cpp.

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

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

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

37{
38 QCString result=includeScope ? nd->name() : nd->localName();
39 SrcLangExt lang = nd->getLanguage();
41 if (sep!="::")
42 {
43 result = substitute(result,"::",sep);
44 }
45 if (nd->isAnonymous())
46 {
47 result = removeAnonymousScopes(result);
48 }
49 //printf("makeDisplayName() %s->%s lang=%d\n",qPrint(name()),qPrint(result),lang);
50 return result;
51}
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:571
SrcLangExt
Definition types.h:207
QCString removeAnonymousScopes(const QCString &str)
Definition util.cpp:162
QCString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Returns the scope separator to use given the programming language lang.
Definition util.cpp:5900

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

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

1870{
1871 //printf(">namespaceHasNestedConcept(%s)\n",qPrint(nd->name()));
1872 for (const auto &cnd : nd->getNamespaces())
1873 {
1875 {
1876 //printf("<namespaceHasNestedConcept(%s): case1\n",qPrint(nd->name()));
1877 return true;
1878 }
1879 }
1880 for (const auto &cnd : nd->getConcepts())
1881 {
1882 //printf("candidate %s isLinkableInProject()=%d\n",qPrint(cnd->name()),cnd->isLinkableInProject());
1883 if (cnd->isLinkableInProject())
1884 {
1885 //printf("<namespaceHasNestedConcept(%s): case2\n",qPrint(nd->name()));
1886 return true;
1887 }
1888 }
1889 //printf("<namespaceHasNestedConcept(%s): case3\n",qPrint(nd->name()));
1890 return false;
1891}
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 1857 of file namespacedef.cpp.

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

References NamespaceDef::getNamespaces().

Referenced by writeNamespaceTreeElement().

◆ needsSorting()

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

Definition at line 1481 of file namespacedef.cpp.

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

References Config_getBool, and QCString::isEmpty().

Referenced by NamespaceDefImpl::sortMemberLists().

◆ replaceNamespaceAliases()

void replaceNamespaceAliases ( QCString & name)

Definition at line 1837 of file namespacedef.cpp.

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

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

1751{
1752 QCString result = name;
1753 //printf("> replaceNamespaceAliasesRec(%s)\n",qPrint(name));
1754 if (namespacesTried.find(name.str())==namespacesTried.end())
1755 {
1756 namespacesTried.insert(name.str());
1757 size_t p = 0;
1758 for (;;)
1759 {
1760 size_t i = name.str().find("::",p);
1761 if (i==std::string::npos)
1762 {
1763 auto it = Doxygen::namespaceAliasMap.find(name.str());
1764 if (it != Doxygen::namespaceAliasMap.end())
1765 {
1766 //printf("found map %s->%s\n",qPrint(name),qPrint(it->second.alias));
1767 auto ns = getResolvedNamespaceRec(namespacesTried,it->second);
1768 if (ns)
1769 {
1770 result = replaceNamespaceAliasesRec(namespacesTried,ns->qualifiedName());
1771 }
1772 }
1773 break;
1774 }
1775 else
1776 {
1777 auto it = Doxygen::namespaceAliasMap.find(name.left(i).str());
1778 if (it != Doxygen::namespaceAliasMap.end())
1779 {
1780 //printf("found map %s|%s->%s\n",qPrint(name.left(i)),qPrint(name.mid(i)),qPrint(it->second.alias));
1781 auto ns = getResolvedNamespaceRec(namespacesTried,it->second);
1782 if (ns)
1783 {
1784 result = replaceNamespaceAliasesRec(namespacesTried,ns->qualifiedName()+name.mid(i));
1785 break;
1786 }
1787 }
1788 }
1789 p = i+2;
1790 }
1791 }
1792 //printf("< replaceNamespaceAliasesRec(%s)=%s\n",qPrint(name),qPrint(result));
1793 return result;
1794}
static NamespaceAliasInfoMap namespaceAliasMap
Definition doxygen.h:112
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 1722 of file namespacedef.cpp.

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

◆ toNamespaceDef() [2/3]

◆ toNamespaceDef() [3/3]

NamespaceDef * toNamespaceDef ( DefinitionMutable * md)

Definition at line 1708 of file namespacedef.cpp.

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

References toDefinition().

◆ toNamespaceDefMutable()