Skip to main content

The VariableContext Class Reference

Declaration

class VariableContext { ... }

Included Headers

Public Member Typedefs Index

usingScope = std::unordered_map< std::string, ScopedTypeVariant >

Public Member Functions Index

voidpushScope ()
voidpopScope ()
voidclear ()
voidclearExceptGlobal ()
voidaddVariable (const QCString &name, ScopedTypeVariant stv)
const ScopedTypeVariant *findVariable (const QCString &name)
boolatGlobalScope () const

Private Member Attributes Index

Scopem_globalScope
std::vector< Scope >m_scopes

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.

Public Member Typedefs

Scope

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

Definition at line 77 of file scopedtypevariant.h.

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

Public Member Functions

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 }

References m_globalScope, m_scopes and QCString::str.

atGlobalScope()

bool VariableContext::atGlobalScope ()
inline

Definition at line 129 of file scopedtypevariant.h.

129 bool atGlobalScope() const { return m_scopes.empty(); }

Reference m_scopes.

clear()

void VariableContext::clear ()
inline

Definition at line 90 of file scopedtypevariant.h.

90 void clear()
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 }

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

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

popScope()

void VariableContext::popScope ()
inline

Definition at line 83 of file scopedtypevariant.h.

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

Reference m_scopes.

pushScope()

void VariableContext::pushScope ()
inline

Definition at line 79 of file scopedtypevariant.h.

79 void pushScope()
80 {
81 m_scopes.emplace_back();
82 }

Reference m_scopes.

Private Member Attributes

m_globalScope

Scope VariableContext::m_globalScope

Definition at line 132 of file scopedtypevariant.h.

Referenced by addVariable, clear and findVariable.

m_scopes

std::vector<Scope> VariableContext::m_scopes

Definition at line 133 of file scopedtypevariant.h.

133 std::vector<Scope> m_scopes;

Referenced by addVariable, atGlobalScope, clear, clearExceptGlobal, findVariable, popScope and pushScope.


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


Generated via doxygen2docusaurus by Doxygen 1.14.0.