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

Classes

class  Scope
 

Public Member Functions

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

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 10707 of file code.cpp.

Constructor & Destructor Documentation

VariableContext::VariableContext ( )
inline

Definition at line 10718 of file code.cpp.

10719  {
10720  m_scopes.setAutoDelete(TRUE);
10721  }
const bool TRUE
Definition: qglobal.h:371
QList< Scope > m_scopes
Definition: code.cpp:10764
virtual VariableContext::~VariableContext ( )
inlinevirtual

Definition at line 10722 of file code.cpp.

10723  {
10724  }

Member Function Documentation

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

Definition at line 10767 of file code.cpp.

10768 {
10769  //printf("VariableContext::addVariable(%s,%s)\n",type.data(),name.data());
10770  QCString ltype = type.simplifyWhiteSpace();
10771  QCString lname = name.simplifyWhiteSpace();
10772  if (ltype.left(7)=="struct ")
10773  {
10774  ltype = ltype.right(ltype.length()-7);
10775  }
10776  else if (ltype.left(6)=="union ")
10777  {
10778  ltype = ltype.right(ltype.length()-6);
10779  }
10780  if (ltype.isEmpty() || lname.isEmpty()) return;
10781  DBG_CTX((stderr,"** addVariable trying: type='%s' name='%s' g_currentDefinition=%s\n",
10782  ltype.data(),lname.data(),g_currentDefinition?g_currentDefinition->name().data():"<none>"));
10783  Scope *scope = m_scopes.count()==0 ? &m_globalScope : m_scopes.getLast();
10784  ClassDef *varType;
10785  int i=0;
10786  if (
10787  (varType=g_codeClassSDict->find(ltype)) || // look for class definitions inside the code block
10788  (varType=getResolvedClass(g_currentDefinition,g_sourceFileDef,ltype)) // look for global class definitions
10789  )
10790  {
10791  DBG_CTX((stderr,"** addVariable type='%s' name='%s'\n",ltype.data(),lname.data()));
10792  scope->append(lname,varType); // add it to a list
10793  }
10794  else if ((i=ltype.find('<'))!=-1)
10795  {
10796  // probably a template class
10797  QCString typeName(ltype.left(i));
10798  ClassDef* newDef = 0;
10799  QCString templateArgs(ltype.right(ltype.length() - i));
10800  if (
10801  ( // look for class definitions inside the code block
10802  (varType=g_codeClassSDict->find(typeName)) ||
10803  // otherwise look for global class definitions
10805  ) && // and it must be a template
10806  varType->templateArguments())
10807  {
10808  newDef = varType->getVariableInstance( templateArgs );
10809  }
10810  if (newDef)
10811  {
10812  DBG_CTX((stderr,"** addVariable type='%s' templ='%s' name='%s'\n",typeName.data(),templateArgs.data(),lname.data()));
10813  scope->append(lname, newDef);
10814  }
10815  else
10816  {
10817  // Doesn't seem to be a template. Try just the base name.
10818  addVariable(typeName,name);
10819  }
10820  }
10821  else
10822  {
10823  if (m_scopes.count()>0) // for local variables add a dummy entry so the name
10824  // is hidden to avoid false links to global variables with the same name
10825  // TODO: make this work for namespaces as well!
10826  {
10827  DBG_CTX((stderr,"** addVariable: dummy context for '%s'\n",lname.data()));
10828  scope->append(lname,dummyContext);
10829  }
10830  else
10831  {
10832  DBG_CTX((stderr,"** addVariable: not adding variable!\n"));
10833  }
10834  }
10835 }
void addVariable(const QCString &type, const QCString &name)
Definition: code.cpp:10767
static ClassSDict * g_codeClassSDict
Definition: code.cpp:10599
ClassDef * getVariableInstance(const char *templSpec)
Definition: classdef.cpp:3726
static QCString scope
Definition: declinfo.cpp:668
bool isEmpty() const
Definition: qcstring.h:189
uint length() const
Definition: qcstring.h:195
ArgumentList * templateArguments() const
Definition: classdef.cpp:4419
QCString left(uint len) const
Definition: qcstring.cpp:213
int find(char c, int index=0, bool cs=TRUE) const
Definition: qcstring.cpp:41
static FileDef * g_sourceFileDef
Definition: code.cpp:10626
const QCString & name() const
Definition: definition.h:114
QCString right(uint len) const
Definition: qcstring.cpp:231
const char * data() const
Definition: qcstring.h:207
#define DBG_CTX(x)
Definition: code.cpp:10585
static const ClassDef * dummyContext
Definition: code.cpp:10710
T * find(const char *key)
Definition: sortdict.h:232
ClassDef * getResolvedClass(Definition *scope, FileDef *fileScope, const char *n, MemberDef **pTypeDef, QCString *pTemplSpec, bool mayBeUnlinkable, bool mayBeHidden, QCString *pResolvedType)
Definition: util.cpp:1563
Scope m_globalScope
Definition: code.cpp:10763
const bool TRUE
Definition: qglobal.h:371
QCString simplifyWhiteSpace() const
Definition: qcstring.cpp:323
QList< Scope > m_scopes
Definition: code.cpp:10764
static Definition * g_currentDefinition
Definition: code.cpp:10628
void VariableContext::clear ( )
inline

Definition at line 10745 of file code.cpp.

10746  {
10747  m_scopes.clear();
10748  m_globalScope.clear();
10749  }
void clear()
Definition: sortdict.h:276
Scope m_globalScope
Definition: code.cpp:10763
QList< Scope > m_scopes
Definition: code.cpp:10764
void VariableContext::clearExceptGlobal ( )
inline

Definition at line 10751 of file code.cpp.

10752  {
10753  DBG_CTX((stderr,"** Clear var context\n"));
10754  m_scopes.clear();
10755  }
#define DBG_CTX(x)
Definition: code.cpp:10585
QList< Scope > m_scopes
Definition: code.cpp:10764
int VariableContext::count ( ) const
inline

Definition at line 10760 of file code.cpp.

10760 { return m_scopes.count(); }
QList< Scope > m_scopes
Definition: code.cpp:10764
ClassDef * VariableContext::findVariable ( const QCString name)

Definition at line 10837 of file code.cpp.

10838 {
10839  if (name.isEmpty()) return 0;
10840  ClassDef *result = 0;
10842  Scope *scope;
10843  QCString key = name;
10844  // search from inner to outer scope
10845  for (sli.toLast();(scope=sli.current());--sli)
10846  {
10847  result = scope->find(key);
10848  if (result)
10849  {
10850  DBG_CTX((stderr,"** findVariable(%s)=%p\n",name.data(),result));
10851  return result;
10852  }
10853  }
10854  // nothing found -> also try the global scope
10855  result=m_globalScope.find(name);
10856  DBG_CTX((stderr,"** findVariable(%s)=%p\n",name.data(),result));
10857  return result;
10858 }
static QCString name
Definition: declinfo.cpp:673
static QCString scope
Definition: declinfo.cpp:668
static QCString result
bool isEmpty() const
Definition: qcstring.h:189
def key(type, name=None)
Definition: graph.py:13
const char * data() const
Definition: qcstring.h:207
#define DBG_CTX(x)
Definition: code.cpp:10585
T * find(const char *key)
Definition: sortdict.h:232
Scope m_globalScope
Definition: code.cpp:10763
QList< Scope > m_scopes
Definition: code.cpp:10764
void VariableContext::popScope ( )
inline

Definition at line 10732 of file code.cpp.

10733  {
10734  if (m_scopes.count()>0)
10735  {
10736  DBG_CTX((stderr,"** Pop var context %d\n",m_scopes.count()));
10737  m_scopes.remove(m_scopes.count()-1);
10738  }
10739  else
10740  {
10741  DBG_CTX((stderr,"** ILLEGAL: Pop var context\n"));
10742  }
10743  }
#define DBG_CTX(x)
Definition: code.cpp:10585
QList< Scope > m_scopes
Definition: code.cpp:10764
void VariableContext::pushScope ( )
inline

Definition at line 10726 of file code.cpp.

10727  {
10728  m_scopes.append(new Scope);
10729  DBG_CTX((stderr,"** Push var context %d\n",m_scopes.count()));
10730  }
#define DBG_CTX(x)
Definition: code.cpp:10585
QList< Scope > m_scopes
Definition: code.cpp:10764

Member Data Documentation

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

Definition at line 10710 of file code.cpp.

Scope VariableContext::m_globalScope
private

Definition at line 10763 of file code.cpp.

QList<Scope> VariableContext::m_scopes
private

Definition at line 10764 of file code.cpp.


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