diff options
author | Dimitri van Heesch <doxygen@gmail.com> | 2020-10-11 17:07:23 (GMT) |
---|---|---|
committer | Dimitri van Heesch <doxygen@gmail.com> | 2020-10-11 17:07:23 (GMT) |
commit | 8a93f4e00b6922526935909312dabbd9a566d5cc (patch) | |
tree | 285bbb4442d94fc6fb8d71c0d354cdccbca90572 /src/util.h | |
parent | 02cdddb491739a18413025ddd587879bd8f5305f (diff) | |
download | Doxygen-8a93f4e00b6922526935909312dabbd9a566d5cc.zip Doxygen-8a93f4e00b6922526935909312dabbd9a566d5cc.tar.gz Doxygen-8a93f4e00b6922526935909312dabbd9a566d5cc.tar.bz2 |
Refactoring: Remove use of globals/statics in isAccessibleFrom*
- Also moved AccessStack to util.h and modernized it.
Diffstat (limited to 'src/util.h')
-rw-r--r-- | src/util.h | 66 |
1 files changed, 62 insertions, 4 deletions
@@ -23,6 +23,7 @@ */ #include <memory> +#include <unordered_map> #include <qlist.h> #include <ctype.h> @@ -119,6 +120,56 @@ class LetterToIndexMap : public SIntDict<T> //-------------------------------------------------------------------- +const int MAX_STACK_SIZE = 100; + +/** Helper class representing the stack of items considered while resolving + * the scope. + */ +class AccessStack +{ + /** Element in the stack. */ + struct AccessElem + { + AccessElem(const Definition *d,const FileDef *f,const Definition *i,QCString e = QCString()) : scope(d), fileScope(f), item(i), expScope(e) {} + const Definition *scope; + const FileDef *fileScope; + const Definition *item; + QCString expScope; + }; + public: + void push(const Definition *scope,const FileDef *fileScope,const Definition *item) + { + m_elements.push_back(AccessElem(scope,fileScope,item)); + } + void push(const Definition *scope,const FileDef *fileScope,const Definition *item,const QCString &expScope) + { + m_elements.push_back(AccessElem(scope,fileScope,item,expScope)); + } + void pop() + { + if (!m_elements.empty()) m_elements.pop_back(); + } + bool find(const Definition *scope,const FileDef *fileScope, const Definition *item) + { + auto it = std::find_if(m_elements.begin(),m_elements.end(), + [&](const AccessElem &e) { return e.scope==scope && e.fileScope==fileScope && e.item==item; }); + return it!=m_elements.end(); + } + bool find(const Definition *scope,const FileDef *fileScope, const Definition *item,const QCString &expScope) + { + auto it = std::find_if(m_elements.begin(),m_elements.end(), + [&](const AccessElem &e) { return e.scope==scope && e.fileScope==fileScope && e.item==item && e.expScope==expScope; }); + return it!=m_elements.end(); + } + + private: + std::vector<AccessElem> m_elements; +}; + +using VisitedNamespaces = std::unordered_map<std::string,const Definition *>; + +//-------------------------------------------------------------------- + QCString langToString(SrcLangExt lang); QCString getLanguageSpecificSeparator(SrcLangExt lang,bool classScope=FALSE); @@ -378,10 +429,17 @@ QCString stripExtension(const char *fName); void replaceNamespaceAliases(QCString &scope,int i); -int isAccessibleFrom(const Definition *scope,const FileDef *fileScope,const Definition *item); - -int isAccessibleFromWithExpScope(const Definition *scope,const FileDef *fileScope,const Definition *item, - const QCString &explicitScopePart); +int isAccessibleFrom(AccessStack &accessStack, + const Definition *scope, + const FileDef *fileScope, + const Definition *item); + +int isAccessibleFromWithExpScope(VisitedNamespaces &visitedNamespaces, + AccessStack &accessStack, + const Definition *scope, + const FileDef *fileScope, + const Definition *item, + const QCString &explicitScopePart); int computeQualifiedIndex(const QCString &name); |