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 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 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}

References createNamespaceDef().

Referenced by adjustConfiguration(), buildNamespaceList(), buildScopeFromQualifiedName(), createNamespaceDef(), 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}

References createNamespaceDefAlias().

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

◆ getResolvedNamespace()

NamespaceDef * getResolvedNamespace ( const DString & name)

Definition at line 1841 of file namespacedef.cpp.

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

References DString::empty(), getResolvedNamespace(), getResolvedNamespaceRec(), NamespaceAliasInfo::NamespaceAliasInfo(), and DString::str().

Referenced by addMemberFunction(), buildFunctionList(), buildTypedefList(), extractNamespaceName(), findUsedNamespace(), findUsingDeclImports(), findUsingDirectives(), generateClassOrGlobalLink(), generateClassOrGlobalLink(), getResolvedNamespace(), getResolvedNamespaceMutable(), CCodeParser::parseCode(), setCallContextForVar(), NamespaceDefMutable::setInline(), and writeAlphabeticalClassList().

◆ getResolvedNamespaceRec()

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

Definition at line 1792 of file namespacedef.cpp.

1793{
1794 size_t j = aliasInfo.context.length();
1795 for (;;)
1796 {
1797 if (j>0)
1798 {
1799 //printf("candidate %s|::%s\n",qPrint(aliasInfo.context.substr(0,j)),qPrint(aliasInfo.alias));
1800 auto candidate = replaceNamespaceAliasesRec(namespacesTried,aliasInfo.context.substr(0,j)+"::"+aliasInfo.alias);
1801 auto nd = Doxygen::namespaceLinkedMap->find(candidate);
1802 if (nd)
1803 {
1804 return nd;
1805 }
1806 }
1807 if (j>0) // strip one level from context, i.e. given N1::N2::N3
1808 // j==10 -> j==6 (N1::N2::N3->N1::N2), and then
1809 // j==6 -> j==2 (N1::N2->N1), and then
1810 // j==2 -> j==std::string::npos (N1->"")
1811 {
1812 j = aliasInfo.context.rfind("::",j-1);
1813 }
1814 else
1815 {
1816 j = std::string::npos;
1817 }
1818 if (j==std::string::npos)
1819 {
1820 //printf("candidate %s\n",qPrint(aliasInfo.alias));
1821 auto candidate = replaceNamespaceAliasesRec(namespacesTried,aliasInfo.alias);
1822 auto nd = Doxygen::namespaceLinkedMap->find(candidate);
1823 if (nd)
1824 {
1825 return nd;
1826 }
1827 break;
1828 }
1829 }
1830 return nullptr;
1831}
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(), getResolvedNamespaceRec(), Doxygen::namespaceLinkedMap, and replaceNamespaceAliasesRec().

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

◆ hasNonReferenceNestedNamespaceRec()

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

Definition at line 1553 of file namespacedef.cpp.

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

37{
38 DString 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}
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:88
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:481
SrcLangExt
Definition types.h:207
DString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Definition util.cpp:4631
DString removeAnonymousScopes(const DString &str)
Definition util.cpp:100

References Definition::getLanguage(), getLanguageSpecificSeparator(), Definition::isAnonymous(), Definition::localName(), makeDisplayName(), Definition::name(), removeAnonymousScopes(), and substitute().

Referenced by NamespaceDefAliasImpl::displayName(), NamespaceDefImpl::displayName(), and makeDisplayName().

◆ namespaceHasNestedClass()

bool namespaceHasNestedClass ( const NamespaceDef * nd,
bool filterClasses,
ClassDef::CompoundType ct )

Definition at line 1889 of file namespacedef.cpp.

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

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

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

References NamespaceDef::getNamespaces(), and namespaceHasNestedNamespace().

Referenced by namespaceHasNestedNamespace(), and writeNamespaceTreeElement().

◆ needsSorting()

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

Definition at line 1477 of file namespacedef.cpp.

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

References Config_getBool, DString::empty(), and needsSorting().

Referenced by needsSorting(), and NamespaceDefImpl::sortMemberLists().

◆ replaceNamespaceAliases()

void replaceNamespaceAliases ( DString & name)

Definition at line 1833 of file namespacedef.cpp.

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

References replaceNamespaceAliases(), and replaceNamespaceAliasesRec().

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

◆ replaceNamespaceAliasesRec()

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

Definition at line 1746 of file namespacedef.cpp.

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

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

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

References toNamespaceDef().

◆ toNamespaceDef() [2/3]

◆ toNamespaceDef() [3/3]

NamespaceDef * toNamespaceDef ( DefinitionMutable * md)

Definition at line 1704 of file namespacedef.cpp.

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

References toDefinition(), and toNamespaceDef().

◆ toNamespaceDefMutable()