extend symbol database Variable with more information

This commit is contained in:
Robert Reif 2011-02-26 09:08:59 -05:00
parent 3529014924
commit abbd37d380
2 changed files with 101 additions and 10 deletions

View File

@ -1071,10 +1071,31 @@ Scope::hasDefaultConstructor() const
return false; return false;
} }
AccessControl Scope::defaultAccess() const
{
switch (type)
{
case eGlobal:
return Global;
case eClass:
return Private;
case eStruct:
return Public;
case eUnion:
return Public;
case eNamespace:
return Namespace;
case eFunction:
return Local;
}
return Public;
}
// Get variable list.. // Get variable list..
void Scope::getVariableList() void Scope::getVariableList()
{ {
AccessControl varaccess = type == eClass ? Private : Public; AccessControl varaccess = defaultAccess();
const Token *start; const Token *start;
if (classStart) if (classStart)
@ -1242,7 +1263,7 @@ void Scope::getVariableList()
if (typetok) if (typetok)
scope = check->findVariableType(this, typetok); scope = check->findVariableType(this, typetok);
addVariable(vartok, typestart, varaccess, isMutable, isStatic, isConst, isClass, scope); addVariable(vartok, typestart, vartok->previous(), varaccess, isMutable, isStatic, isConst, isClass, scope, this);
} }
} }
} }

View File

@ -38,7 +38,7 @@ class SymbolDatabase;
/** /**
* @brief Access control enumerations. * @brief Access control enumerations.
*/ */
enum AccessControl { Public, Protected, Private }; enum AccessControl { Public, Protected, Private, Global, Namespace, Argument, Local };
/** @brief Information about a member variable. */ /** @brief Information about a member variable. */
class Variable class Variable
@ -73,15 +73,18 @@ class Variable
} }
public: public:
Variable(const Token *name_, const Token *start_, std::size_t index_, Variable(const Token *name_, const Token *start_, const Token *end_,
AccessControl access_, bool mutable_, bool static_, bool const_, std::size_t index_, AccessControl access_, bool mutable_,
bool class_, const Scope *type_) bool static_, bool const_, bool class_, const Scope *type_,
const Scope *scope_)
: _name(name_), : _name(name_),
_start(start_), _start(start_),
_end(end_),
_index(index_), _index(index_),
_access(access_), _access(access_),
_flags(0), _flags(0),
_type(type_) _type(type_),
_scope(scope_)
{ {
setFlag(fIsMutable, mutable_); setFlag(fIsMutable, mutable_);
setFlag(fIsStatic, static_); setFlag(fIsStatic, static_);
@ -107,6 +110,15 @@ public:
return _start; return _start;
} }
/**
* Get type end token.
* @return type end token
*/
const Token *typeEndToken() const
{
return _end;
}
/** /**
* Get name string. * Get name string.
* @return name string * @return name string
@ -161,6 +173,42 @@ public:
return _access == Private; return _access == Private;
} }
/**
* Is variable global.
* @return true if global, false if not
*/
bool isGlobal() const
{
return _access == Global;
}
/**
* Is variable in a namespace.
* @return true if in a namespace, false if not
*/
bool isNamespace() const
{
return _access == Namespace;
}
/**
* Is variable a function argument.
* @return true if a function argument, false if not
*/
bool isArgument() const
{
return _access == Argument;
}
/**
* Is variable local.
* @return true if local, false if not
*/
bool isLocal() const
{
return _access == Local;
}
/** /**
* Is variable mutable. * Is variable mutable.
* @return true if mutable, false if not * @return true if mutable, false if not
@ -206,6 +254,15 @@ public:
return _type; return _type;
} }
/**
* Get Scope pointer of enclosing scope.
* @return pointer to enclosing scope
*/
const Scope *scope() const
{
return _scope;
}
private: private:
/** @brief variable name token */ /** @brief variable name token */
const Token *_name; const Token *_name;
@ -213,6 +270,9 @@ private:
/** @brief variable type start token */ /** @brief variable type start token */
const Token *_start; const Token *_start;
/** @brief variable type end token */
const Token *_end;
/** @brief order declared */ /** @brief order declared */
std::size_t _index; std::size_t _index;
@ -224,6 +284,9 @@ private:
/** @brief pointer to user defined type info (for known types) */ /** @brief pointer to user defined type info (for known types) */
const Scope *_type; const Scope *_type;
/** @brief pointer to scope this variable is in */
const Scope *_scope;
}; };
class Function class Function
@ -313,7 +376,7 @@ public:
AccessControl access; AccessControl access;
unsigned int numConstructors; unsigned int numConstructors;
NeedInitialization needInitialization; NeedInitialization needInitialization;
Scope * functionOf; // class/struct this function belongs to Scope *functionOf; // class/struct this function belongs to
bool isClassOrStruct() const bool isClassOrStruct() const
{ {
@ -332,9 +395,14 @@ public:
*/ */
Scope * findInNestedListRecursive(const std::string & name); Scope * findInNestedListRecursive(const std::string & name);
void addVariable(const Token *token_, const Token *start_, AccessControl access_, bool mutable_, bool static_, bool const_, bool class_, const Scope *type_) void addVariable(const Token *token_, const Token *start_,
const Token *end_, AccessControl access_, bool mutable_,
bool static_, bool const_, bool class_, const Scope *type_,
const Scope *scope_)
{ {
varlist.push_back(Variable(token_, start_, varlist.size(), access_, mutable_, static_, const_, class_, type_)); varlist.push_back(Variable(token_, start_, end_, varlist.size(),
access_, mutable_, static_, const_, class_,
type_, scope_));
} }
/** @brief initialize varlist */ /** @brief initialize varlist */
@ -352,6 +420,8 @@ public:
bool hasDefaultConstructor() const; bool hasDefaultConstructor() const;
AccessControl defaultAccess() const;
private: private:
/** /**
* @brief helper function for getVariableList() * @brief helper function for getVariableList()