Classes | Public Member Functions | Static Public Attributes | Private Attributes | List of all members
PyVariableContext Class Reference

Classes

class  Scope
 

Public Member Functions

 PyVariableContext ()
 
virtual ~PyVariableContext ()
 
void pushScope ()
 
void popScope ()
 
void clear ()
 
void clearExceptGlobal ()
 
void addVariable (const QCString &type, const QCString &name)
 
ClassDeffindVariable (const QCString &name)
 

Static Public Attributes

static const ClassDefdummyContext = (ClassDef*)0x8
 

Private Attributes

Scope m_globalScope
 
QList< 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 1275 of file pycode.cpp.

Constructor & Destructor Documentation

PyVariableContext::PyVariableContext ( )
inline

Definition at line 1285 of file pycode.cpp.

1286  {
1287  m_scopes.setAutoDelete(TRUE);
1288  }
QList< Scope > m_scopes
Definition: pycode.cpp:1323
const bool TRUE
Definition: qglobal.h:371
virtual PyVariableContext::~PyVariableContext ( )
inlinevirtual

Definition at line 1290 of file pycode.cpp.

1291  {
1292  }

Member Function Documentation

void PyVariableContext::addVariable ( const QCString type,
const QCString name 
)

Definition at line 1326 of file pycode.cpp.

1327 {
1328  //printf("PyVariableContext::addVariable(%s,%s)\n",type.data(),name.data());
1329  QCString ltype = type.simplifyWhiteSpace();
1330  QCString lname = name.simplifyWhiteSpace();
1331 
1332  Scope *scope = m_scopes.count()==0 ? &m_globalScope : m_scopes.getLast();
1333  ClassDef *varType;
1334  if (
1335  (varType=g_codeClassSDict[ltype]) || // look for class definitions inside the code block
1336  (varType=getResolvedClass(g_currentDefinition,g_sourceFileDef,ltype)) // look for global class definitions
1337  )
1338  {
1339  scope->append(lname,varType); // add it to a list
1340  }
1341  else
1342  {
1343  if (m_scopes.count()>0) // for local variables add a dummy entry so the name
1344  // is hidden to avoid FALSE links to global variables with the same name
1345  // TODO: make this work for namespaces as well!
1346  {
1347  scope->append(lname,dummyContext);
1348  }
1349  }
1350 }
static QCString scope
Definition: declinfo.cpp:668
static ClassSDict g_codeClassSDict(17)
static Definition * g_currentDefinition
Definition: pycode.cpp:1239
static const ClassDef * dummyContext
Definition: pycode.cpp:1278
static FileDef * g_sourceFileDef
Definition: pycode.cpp:1238
QList< Scope > m_scopes
Definition: pycode.cpp:1323
ClassDef * getResolvedClass(Definition *scope, FileDef *fileScope, const char *n, MemberDef **pTypeDef, QCString *pTemplSpec, bool mayBeUnlinkable, bool mayBeHidden, QCString *pResolvedType)
Definition: util.cpp:1563
QCString simplifyWhiteSpace() const
Definition: qcstring.cpp:323
void PyVariableContext::clear ( )
inline

Definition at line 1307 of file pycode.cpp.

1308  {
1309  m_scopes.clear();
1310  m_globalScope.clear();
1311  }
void clear()
Definition: sortdict.h:276
QList< Scope > m_scopes
Definition: pycode.cpp:1323
void PyVariableContext::clearExceptGlobal ( )
inline

Definition at line 1313 of file pycode.cpp.

1314  {
1315  m_scopes.clear();
1316  }
QList< Scope > m_scopes
Definition: pycode.cpp:1323
ClassDef * PyVariableContext::findVariable ( const QCString name)

Definition at line 1352 of file pycode.cpp.

1353 {
1354  if (name.isEmpty()) return 0;
1355  ClassDef *result = 0;
1357  Scope *scope;
1358  // search from inner to outer scope
1359  for (sli.toLast();(scope=sli.current());--sli)
1360  {
1361  result = scope->find(name);
1362  if (result)
1363  {
1364  return result;
1365  }
1366  }
1367  // nothing found -> also try the global scope
1368  result=m_globalScope.find(name);
1369  return result;
1370 }
static QCString scope
Definition: declinfo.cpp:668
static QCString result
bool isEmpty() const
Definition: qcstring.h:189
T * find(const char *key)
Definition: sortdict.h:232
QList< Scope > m_scopes
Definition: pycode.cpp:1323
void PyVariableContext::popScope ( )
inline

Definition at line 1299 of file pycode.cpp.

1300  {
1301  if (m_scopes.count()>0)
1302  {
1303  m_scopes.remove(m_scopes.count()-1);
1304  }
1305  }
QList< Scope > m_scopes
Definition: pycode.cpp:1323
void PyVariableContext::pushScope ( )
inline

Definition at line 1294 of file pycode.cpp.

1295  {
1296  m_scopes.append(new Scope);
1297  }
QList< Scope > m_scopes
Definition: pycode.cpp:1323

Member Data Documentation

const ClassDef * PyVariableContext::dummyContext = (ClassDef*)0x8
static

Definition at line 1278 of file pycode.cpp.

Scope PyVariableContext::m_globalScope
private

Definition at line 1322 of file pycode.cpp.

QList<Scope> PyVariableContext::m_scopes
private

Definition at line 1323 of file pycode.cpp.


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