Doxygen
Loading...
Searching...
No Matches
VariableContext Class Reference

#include <src/scopedtypevariant.h>

Public Types

using Scope = std::unordered_map<std::string,ScopedTypeVariant>
 

Public Member Functions

void pushScope ()
 
void popScope ()
 
void clear ()
 
void clearExceptGlobal ()
 
void addVariable (const QCString &name, ScopedTypeVariant stv)
 
const ScopedTypeVariantfindVariable (const QCString &name)
 
bool atGlobalScope () const
 

Private Attributes

Scope m_globalScope
 
std::vector< Scopem_scopes
 

Detailed Description

Represents a stack of variable to class mappings as found in the code. Each scope is enclosed in pushScope() and popScope() calls. Variables are added by calling addVariables() and one can search for variable using findVariable().

Definition at line 74 of file scopedtypevariant.h.

Member Typedef Documentation

◆ Scope

using VariableContext::Scope = std::unordered_map<std::string,ScopedTypeVariant>

Definition at line 77 of file scopedtypevariant.h.

Member Function Documentation

◆ addVariable()

void VariableContext::addVariable ( const QCString & name,
ScopedTypeVariant stv )
inline

Definition at line 99 of file scopedtypevariant.h.

100 {
101 Scope *scope = m_scopes.empty() ? &m_globalScope : &m_scopes.back();
102 scope->emplace(name.str(),std::move(stv)); // add it to a list
103 }
const std::string & str() const
Definition qcstring.h:537
std::vector< Scope > m_scopes
std::unordered_map< std::string, ScopedTypeVariant > Scope

References m_globalScope, m_scopes, and QCString::str().

◆ atGlobalScope()

bool VariableContext::atGlobalScope ( ) const
inline

Definition at line 129 of file scopedtypevariant.h.

129{ return m_scopes.empty(); }

References m_scopes.

◆ clear()

void VariableContext::clear ( )
inline

Definition at line 90 of file scopedtypevariant.h.

91 {
92 m_scopes.clear();
93 m_globalScope.clear();
94 }

References m_globalScope, and m_scopes.

◆ clearExceptGlobal()

void VariableContext::clearExceptGlobal ( )
inline

Definition at line 95 of file scopedtypevariant.h.

96 {
97 m_scopes.clear();
98 }

References m_scopes.

◆ findVariable()

const ScopedTypeVariant * VariableContext::findVariable ( const QCString & name)
inline

Definition at line 104 of file scopedtypevariant.h.

105 {
106 const ScopedTypeVariant *result = nullptr;
107 if (name.isEmpty()) return result;
108
109 // search from inner to outer scope
110 auto it = std::rbegin(m_scopes);
111 while (it != std::rend(m_scopes))
112 {
113 auto it2 = it->find(name.str());
114 if (it2 != std::end(*it))
115 {
116 result = &it2->second;
117 return result;
118 }
119 ++it;
120 }
121 // nothing found -> also try the global scope
122 auto it2 = m_globalScope.find(name.str());
123 if (it2 != m_globalScope.end())
124 {
125 result = &it2->second;
126 }
127 return result;
128 }
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150

References QCString::isEmpty(), m_globalScope, m_scopes, and QCString::str().

◆ popScope()

void VariableContext::popScope ( )
inline

Definition at line 83 of file scopedtypevariant.h.

84 {
85 if (!m_scopes.empty())
86 {
87 m_scopes.pop_back();
88 }
89 }

References m_scopes.

◆ pushScope()

void VariableContext::pushScope ( )
inline

Definition at line 79 of file scopedtypevariant.h.

80 {
81 m_scopes.emplace_back();
82 }

References m_scopes.

Member Data Documentation

◆ m_globalScope

Scope VariableContext::m_globalScope
private

Definition at line 132 of file scopedtypevariant.h.

Referenced by addVariable(), clear(), and findVariable().

◆ m_scopes

std::vector<Scope> VariableContext::m_scopes
private

The documentation for this class was generated from the following file: