2010-11-13 08:08:45 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2011-01-09 20:33:36 +01:00
|
|
|
* Copyright (C) 2007-2011 Daniel Marjamäki and Cppcheck team.
|
2010-11-13 08:08:45 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#ifndef SymbolDatabaseH
|
|
|
|
#define SymbolDatabaseH
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
#include <vector>
|
2011-01-16 19:57:29 +01:00
|
|
|
#include <set>
|
2010-11-13 08:08:45 +01:00
|
|
|
|
2011-01-18 07:32:06 +01:00
|
|
|
#include "token.h"
|
|
|
|
|
2010-11-13 08:08:45 +01:00
|
|
|
class Tokenizer;
|
|
|
|
class Settings;
|
|
|
|
class ErrorLogger;
|
|
|
|
|
2011-01-17 18:29:19 +01:00
|
|
|
class Scope;
|
2011-01-17 07:21:59 +01:00
|
|
|
class SymbolDatabase;
|
|
|
|
|
|
|
|
/**
|
2011-01-18 07:32:06 +01:00
|
|
|
* @brief Access control enumerations.
|
2011-01-17 07:21:59 +01:00
|
|
|
*/
|
2011-02-26 15:08:59 +01:00
|
|
|
enum AccessControl { Public, Protected, Private, Global, Namespace, Argument, Local };
|
2011-01-17 07:21:59 +01:00
|
|
|
|
|
|
|
/** @brief Information about a member variable. */
|
2011-01-17 18:29:19 +01:00
|
|
|
class Variable
|
2010-11-13 08:08:45 +01:00
|
|
|
{
|
2011-01-18 07:32:06 +01:00
|
|
|
/** @brief flags mask used to access specific bit. */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
fIsMutable = (1 << 0), /** @brief mutable variable */
|
|
|
|
fIsStatic = (1 << 1), /** @brief static variable */
|
|
|
|
fIsConst = (1 << 2), /** @brief const variable */
|
2011-02-27 16:21:14 +01:00
|
|
|
fIsClass = (1 << 3), /** @brief user defined type */
|
|
|
|
fIsArray = (1 << 4) /** @brief array variable */
|
2011-01-18 07:32:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get specified flag state.
|
|
|
|
* @param flag_ flag to get state of
|
|
|
|
* @return true if flag set or false in flag not set
|
|
|
|
*/
|
|
|
|
bool getFlag(int flag_) const
|
|
|
|
{
|
2011-01-19 07:33:38 +01:00
|
|
|
return bool((_flags & flag_) != 0);
|
2011-01-18 07:32:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set specified flag state.
|
|
|
|
* @param flag_ flag to set state
|
|
|
|
* @param state_ new state of flag
|
|
|
|
*/
|
|
|
|
void setFlag(int flag_, bool state_)
|
|
|
|
{
|
|
|
|
_flags = state_ ? _flags | flag_ : _flags & ~flag_;
|
|
|
|
}
|
|
|
|
|
2010-11-13 08:08:45 +01:00
|
|
|
public:
|
2011-02-26 15:08:59 +01:00
|
|
|
Variable(const Token *name_, const Token *start_, const Token *end_,
|
|
|
|
std::size_t index_, AccessControl access_, bool mutable_,
|
|
|
|
bool static_, bool const_, bool class_, const Scope *type_,
|
2011-02-27 16:21:14 +01:00
|
|
|
const Scope *scope_, bool array_)
|
2011-01-18 07:32:06 +01:00
|
|
|
: _name(name_),
|
2011-02-20 14:25:42 +01:00
|
|
|
_start(start_),
|
2011-02-26 15:08:59 +01:00
|
|
|
_end(end_),
|
2011-01-18 07:32:06 +01:00
|
|
|
_index(index_),
|
|
|
|
_access(access_),
|
|
|
|
_flags(0),
|
2011-02-26 15:08:59 +01:00
|
|
|
_type(type_),
|
|
|
|
_scope(scope_)
|
2011-01-17 07:21:59 +01:00
|
|
|
{
|
2011-01-18 07:32:06 +01:00
|
|
|
setFlag(fIsMutable, mutable_);
|
|
|
|
setFlag(fIsStatic, static_);
|
|
|
|
setFlag(fIsConst, const_);
|
|
|
|
setFlag(fIsClass, class_);
|
2011-02-27 16:21:14 +01:00
|
|
|
setFlag(fIsArray, array_);
|
2011-01-17 07:21:59 +01:00
|
|
|
}
|
2010-11-13 08:08:45 +01:00
|
|
|
|
2011-01-18 07:32:06 +01:00
|
|
|
/**
|
|
|
|
* Get name token.
|
|
|
|
* @return name token
|
|
|
|
*/
|
|
|
|
const Token *nameToken() const
|
|
|
|
{
|
|
|
|
return _name;
|
|
|
|
}
|
2010-11-13 08:08:45 +01:00
|
|
|
|
2011-02-20 14:25:42 +01:00
|
|
|
/**
|
|
|
|
* Get type start token.
|
|
|
|
* @return type start token
|
|
|
|
*/
|
|
|
|
const Token *typeStartToken() const
|
|
|
|
{
|
|
|
|
return _start;
|
|
|
|
}
|
|
|
|
|
2011-02-26 15:08:59 +01:00
|
|
|
/**
|
|
|
|
* Get type end token.
|
|
|
|
* @return type end token
|
|
|
|
*/
|
|
|
|
const Token *typeEndToken() const
|
|
|
|
{
|
|
|
|
return _end;
|
|
|
|
}
|
|
|
|
|
2011-01-18 07:32:06 +01:00
|
|
|
/**
|
|
|
|
* Get name string.
|
|
|
|
* @return name string
|
|
|
|
*/
|
|
|
|
const std::string &name() const
|
|
|
|
{
|
2011-02-27 00:34:17 +01:00
|
|
|
static const std::string noname;
|
|
|
|
|
|
|
|
// name may not exist for function arguments
|
|
|
|
if (_name)
|
|
|
|
return _name->str();
|
|
|
|
|
|
|
|
return noname;
|
2011-01-18 07:32:06 +01:00
|
|
|
}
|
2010-12-02 07:35:01 +01:00
|
|
|
|
2011-01-18 07:32:06 +01:00
|
|
|
/**
|
|
|
|
* Get variable ID.
|
|
|
|
* @return variable ID
|
|
|
|
*/
|
|
|
|
unsigned int varId() const
|
|
|
|
{
|
2011-02-27 00:34:17 +01:00
|
|
|
// name may not exist for function arguments
|
|
|
|
if (_name)
|
|
|
|
return _name->varId();
|
|
|
|
|
|
|
|
return 0;
|
2011-01-18 07:32:06 +01:00
|
|
|
}
|
2010-11-13 08:08:45 +01:00
|
|
|
|
2011-01-18 07:32:06 +01:00
|
|
|
/**
|
|
|
|
* Get index of variable in declared order.
|
|
|
|
* @return varaible index
|
|
|
|
*/
|
|
|
|
std::size_t index() const
|
|
|
|
{
|
|
|
|
return _index;
|
|
|
|
}
|
2010-11-13 08:08:45 +01:00
|
|
|
|
2011-01-18 07:32:06 +01:00
|
|
|
/**
|
|
|
|
* Is variable public.
|
|
|
|
* @return true if public, false if not
|
|
|
|
*/
|
|
|
|
bool isPublic() const
|
|
|
|
{
|
|
|
|
return _access == Public;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is variable protected.
|
|
|
|
* @return true if protected, false if not
|
|
|
|
*/
|
|
|
|
bool isProtected() const
|
|
|
|
{
|
|
|
|
return _access == Protected;
|
|
|
|
}
|
2010-11-13 08:08:45 +01:00
|
|
|
|
2011-01-18 07:32:06 +01:00
|
|
|
/**
|
|
|
|
* Is variable private.
|
|
|
|
* @return true if private, false if not
|
|
|
|
*/
|
|
|
|
bool isPrivate() const
|
|
|
|
{
|
|
|
|
return _access == Private;
|
|
|
|
}
|
|
|
|
|
2011-02-26 15:08:59 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2011-01-18 07:32:06 +01:00
|
|
|
/**
|
|
|
|
* Is variable mutable.
|
|
|
|
* @return true if mutable, false if not
|
|
|
|
*/
|
|
|
|
bool isMutable() const
|
|
|
|
{
|
|
|
|
return getFlag(fIsMutable);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is variable static.
|
|
|
|
* @return true if static, false if not
|
|
|
|
*/
|
|
|
|
bool isStatic() const
|
|
|
|
{
|
|
|
|
return getFlag(fIsStatic);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is variable const.
|
|
|
|
* @return true if const, false if not
|
|
|
|
*/
|
|
|
|
bool isConst() const
|
|
|
|
{
|
|
|
|
return getFlag(fIsConst);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is variable a user defined (or unknown) type.
|
|
|
|
* @return true if user defined type, false if not
|
|
|
|
*/
|
|
|
|
bool isClass() const
|
|
|
|
{
|
|
|
|
return getFlag(fIsClass);
|
|
|
|
}
|
|
|
|
|
2011-02-27 16:21:14 +01:00
|
|
|
/**
|
|
|
|
* Is variable an array.
|
|
|
|
* @return true if array, false if not
|
|
|
|
*/
|
|
|
|
bool isArray() const
|
|
|
|
{
|
|
|
|
return getFlag(fIsArray);
|
|
|
|
}
|
|
|
|
|
2011-01-18 07:32:06 +01:00
|
|
|
/**
|
|
|
|
* Get Scope pointer of known type.
|
|
|
|
* @return pointer to type if known, NULL if not known
|
|
|
|
*/
|
|
|
|
const Scope *type() const
|
|
|
|
{
|
|
|
|
return _type;
|
|
|
|
}
|
|
|
|
|
2011-02-26 15:08:59 +01:00
|
|
|
/**
|
|
|
|
* Get Scope pointer of enclosing scope.
|
|
|
|
* @return pointer to enclosing scope
|
|
|
|
*/
|
|
|
|
const Scope *scope() const
|
|
|
|
{
|
|
|
|
return _scope;
|
|
|
|
}
|
|
|
|
|
2011-01-18 07:32:06 +01:00
|
|
|
private:
|
|
|
|
/** @brief variable name token */
|
|
|
|
const Token *_name;
|
|
|
|
|
2011-02-20 14:25:42 +01:00
|
|
|
/** @brief variable type start token */
|
|
|
|
const Token *_start;
|
|
|
|
|
2011-02-26 15:08:59 +01:00
|
|
|
/** @brief variable type end token */
|
|
|
|
const Token *_end;
|
|
|
|
|
2011-01-18 07:32:06 +01:00
|
|
|
/** @brief order declared */
|
|
|
|
std::size_t _index;
|
|
|
|
|
|
|
|
/** @brief what section is this variable declared in? */
|
|
|
|
AccessControl _access; // public/protected/private
|
2010-11-16 07:30:55 +01:00
|
|
|
|
2011-01-18 07:32:06 +01:00
|
|
|
/** @brief flags */
|
|
|
|
int _flags;
|
2010-12-02 07:35:01 +01:00
|
|
|
|
2011-01-17 07:21:59 +01:00
|
|
|
/** @brief pointer to user defined type info (for known types) */
|
2011-01-18 07:32:06 +01:00
|
|
|
const Scope *_type;
|
2011-02-26 15:08:59 +01:00
|
|
|
|
|
|
|
/** @brief pointer to scope this variable is in */
|
|
|
|
const Scope *_scope;
|
2011-01-17 07:21:59 +01:00
|
|
|
};
|
2010-11-13 08:08:45 +01:00
|
|
|
|
2011-01-17 18:29:19 +01:00
|
|
|
class Function
|
2011-01-17 07:21:59 +01:00
|
|
|
{
|
|
|
|
public:
|
2011-01-17 18:29:19 +01:00
|
|
|
enum Type { eConstructor, eCopyConstructor, eOperatorEqual, eDestructor, eFunction };
|
2011-01-17 07:21:59 +01:00
|
|
|
|
2011-01-17 18:29:19 +01:00
|
|
|
Function()
|
2011-01-17 07:21:59 +01:00
|
|
|
: tokenDef(NULL),
|
|
|
|
argDef(NULL),
|
|
|
|
token(NULL),
|
|
|
|
arg(NULL),
|
2011-02-20 14:25:42 +01:00
|
|
|
start(NULL),
|
2011-01-17 07:21:59 +01:00
|
|
|
access(Public),
|
|
|
|
hasBody(false),
|
|
|
|
isInline(false),
|
|
|
|
isConst(false),
|
|
|
|
isVirtual(false),
|
|
|
|
isPure(false),
|
|
|
|
isStatic(false),
|
|
|
|
isFriend(false),
|
|
|
|
isExplicit(false),
|
|
|
|
isOperator(false),
|
|
|
|
retFuncPtr(false),
|
2011-01-17 18:29:19 +01:00
|
|
|
type(eFunction)
|
2010-11-13 08:08:45 +01:00
|
|
|
{
|
2011-01-17 07:21:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int argCount() const;
|
|
|
|
unsigned int initializedArgCount() const;
|
2011-02-26 21:51:12 +01:00
|
|
|
void addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope);
|
2011-01-17 07:21:59 +01:00
|
|
|
|
|
|
|
const Token *tokenDef; // function name token in class definition
|
|
|
|
const Token *argDef; // function argument start '(' in class definition
|
|
|
|
const Token *token; // function name token in implementation
|
|
|
|
const Token *arg; // function argument start '('
|
2011-02-20 14:25:42 +01:00
|
|
|
const Token *start; // function start '{'
|
2011-01-17 07:21:59 +01:00
|
|
|
AccessControl access; // public/protected/private
|
|
|
|
bool hasBody; // has implementation
|
|
|
|
bool isInline; // implementation in class definition
|
|
|
|
bool isConst; // is const
|
|
|
|
bool isVirtual; // is virtual
|
|
|
|
bool isPure; // is pure virtual
|
|
|
|
bool isStatic; // is static
|
|
|
|
bool isFriend; // is friend
|
|
|
|
bool isExplicit; // is explicit
|
|
|
|
bool isOperator; // is operator
|
|
|
|
bool retFuncPtr; // returns function pointer
|
|
|
|
Type type; // constructor, destructor, ...
|
2011-02-26 21:51:12 +01:00
|
|
|
std::list<Variable> argumentList; // argument list
|
2011-01-17 07:21:59 +01:00
|
|
|
};
|
|
|
|
|
2011-01-17 18:29:19 +01:00
|
|
|
class Scope
|
2011-01-17 07:21:59 +01:00
|
|
|
{
|
2011-01-17 18:29:19 +01:00
|
|
|
// let tests access private function for testing
|
|
|
|
friend class TestSymbolDatabase;
|
|
|
|
|
2011-01-17 07:21:59 +01:00
|
|
|
public:
|
2010-11-13 08:08:45 +01:00
|
|
|
struct BaseInfo
|
|
|
|
{
|
|
|
|
AccessControl access; // public/protected/private
|
|
|
|
std::string name;
|
2011-01-21 07:42:41 +01:00
|
|
|
Scope *scope;
|
2010-11-13 08:08:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct FriendInfo
|
|
|
|
{
|
|
|
|
std::string name;
|
2011-01-21 07:42:41 +01:00
|
|
|
Scope *scope;
|
2010-11-13 08:08:45 +01:00
|
|
|
};
|
|
|
|
|
2011-02-26 21:53:57 +01:00
|
|
|
enum ScopeType { eGlobal, eClass, eStruct, eUnion, eNamespace, eFunction, eIf, eElse, eElseIf, eFor, eWhile, eDo, eSwitch, eUnconditional };
|
2011-01-17 07:21:59 +01:00
|
|
|
enum NeedInitialization { Unknown, True, False };
|
|
|
|
|
2011-01-17 18:29:19 +01:00
|
|
|
Scope(SymbolDatabase *check_, const Token *classDef_, Scope *nestedIn_);
|
2011-02-26 21:53:57 +01:00
|
|
|
Scope(SymbolDatabase *check_, const Token *classDef_, Scope *nestedIn_, ScopeType type_, const Token *start_);
|
2011-01-17 07:21:59 +01:00
|
|
|
|
|
|
|
SymbolDatabase *check;
|
2011-01-21 07:42:41 +01:00
|
|
|
ScopeType type;
|
2011-01-17 07:21:59 +01:00
|
|
|
std::string className;
|
|
|
|
const Token *classDef; // class/struct/union/namespace token
|
|
|
|
const Token *classStart; // '{' token
|
|
|
|
const Token *classEnd; // '}' token
|
2011-01-17 18:29:19 +01:00
|
|
|
std::list<Function> functionList;
|
|
|
|
std::list<Variable> varlist;
|
2011-01-17 07:21:59 +01:00
|
|
|
std::vector<BaseInfo> derivedFrom;
|
|
|
|
std::list<FriendInfo> friendList;
|
2011-01-17 18:29:19 +01:00
|
|
|
Scope *nestedIn;
|
|
|
|
std::list<Scope *> nestedList;
|
2011-01-17 07:21:59 +01:00
|
|
|
AccessControl access;
|
|
|
|
unsigned int numConstructors;
|
|
|
|
NeedInitialization needInitialization;
|
2011-02-26 15:08:59 +01:00
|
|
|
Scope *functionOf; // class/struct this function belongs to
|
2011-01-17 07:21:59 +01:00
|
|
|
|
|
|
|
bool isClassOrStruct() const
|
2010-11-13 08:08:45 +01:00
|
|
|
{
|
2011-01-17 18:29:19 +01:00
|
|
|
return (type == eClass || type == eStruct);
|
2011-01-17 07:21:59 +01:00
|
|
|
}
|
|
|
|
|
2011-02-26 21:53:57 +01:00
|
|
|
bool isLocal() const
|
|
|
|
{
|
|
|
|
return (type == eIf || type == eElse || type == eElseIf ||
|
|
|
|
type == eFor || type == eWhile || type == eDo ||
|
|
|
|
type == eSwitch || type == eUnconditional);
|
|
|
|
}
|
2011-01-17 07:21:59 +01:00
|
|
|
/**
|
|
|
|
* @brief find if name is in nested list
|
2011-01-21 07:42:41 +01:00
|
|
|
* @param name name of nested scope
|
2011-01-17 07:21:59 +01:00
|
|
|
*/
|
2011-01-17 18:29:19 +01:00
|
|
|
Scope * findInNestedList(const std::string & name);
|
2011-01-17 07:21:59 +01:00
|
|
|
|
2011-02-03 07:57:10 +01:00
|
|
|
/**
|
|
|
|
* @brief find if name is in nested list
|
|
|
|
* @param name name of nested scope
|
|
|
|
*/
|
|
|
|
Scope * findInNestedListRecursive(const std::string & name);
|
|
|
|
|
2011-02-26 15:08:59 +01:00
|
|
|
void addVariable(const Token *token_, const Token *start_,
|
|
|
|
const Token *end_, AccessControl access_, bool mutable_,
|
|
|
|
bool static_, bool const_, bool class_, const Scope *type_,
|
2011-02-27 16:21:14 +01:00
|
|
|
const Scope *scope_, bool array_)
|
2011-01-17 07:21:59 +01:00
|
|
|
{
|
2011-02-26 15:08:59 +01:00
|
|
|
varlist.push_back(Variable(token_, start_, end_, varlist.size(),
|
|
|
|
access_, mutable_, static_, const_, class_,
|
2011-02-27 16:21:14 +01:00
|
|
|
type_, scope_, array_));
|
2011-01-17 07:21:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @brief initialize varlist */
|
2011-01-17 18:29:19 +01:00
|
|
|
void getVariableList();
|
2011-01-17 07:21:59 +01:00
|
|
|
|
2011-01-17 18:29:19 +01:00
|
|
|
const Function *getDestructor() const;
|
2011-01-17 07:21:59 +01:00
|
|
|
|
|
|
|
/**
|
2011-01-21 07:42:41 +01:00
|
|
|
* @brief get the number of nested scopes that are not functions
|
2011-01-17 07:21:59 +01:00
|
|
|
*
|
|
|
|
* This returns the number of user defined types (class, struct, union)
|
|
|
|
* that are defined in this user defined type or namespace.
|
|
|
|
*/
|
|
|
|
unsigned int getNestedNonFunctions() const;
|
|
|
|
|
|
|
|
bool hasDefaultConstructor() const;
|
|
|
|
|
2011-02-26 15:08:59 +01:00
|
|
|
AccessControl defaultAccess() const;
|
|
|
|
|
2011-01-17 07:21:59 +01:00
|
|
|
private:
|
|
|
|
/**
|
2011-01-17 18:29:19 +01:00
|
|
|
* @brief helper function for getVariableList()
|
2011-01-17 07:21:59 +01:00
|
|
|
* @param tok pointer to token to check
|
|
|
|
* @param vartok populated with pointer to the variable token, if found
|
|
|
|
* @param typetok populated with pointer to the type token, if found
|
2011-02-27 16:21:14 +01:00
|
|
|
* @param isArray reference to variable to set if array is found
|
2011-01-17 07:21:59 +01:00
|
|
|
* @return true if tok points to a variable declaration, false otherwise
|
|
|
|
*/
|
2011-02-27 16:21:14 +01:00
|
|
|
bool isVariableDeclaration(const Token* tok, const Token*& vartok, const Token*& typetok, bool &isArray) const;
|
2011-01-17 07:21:59 +01:00
|
|
|
bool isSimpleVariable(const Token* tok) const;
|
|
|
|
bool isArrayVariable(const Token* tok) const;
|
|
|
|
bool findClosingBracket(const Token* tok, const Token*& close) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SymbolDatabase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SymbolDatabase(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger);
|
|
|
|
~SymbolDatabase();
|
2010-11-13 08:08:45 +01:00
|
|
|
|
|
|
|
/** @brief Information about all namespaces/classes/structrues */
|
2011-01-21 07:42:41 +01:00
|
|
|
std::list<Scope *> scopeList;
|
2010-11-13 08:08:45 +01:00
|
|
|
|
2010-12-21 08:13:40 +01:00
|
|
|
/**
|
|
|
|
* @brief find a variable type if it's a user defined type
|
|
|
|
* @param start scope to start looking in
|
|
|
|
* @param type token containing variable type
|
|
|
|
* @return pointer to type if found or NULL if not found
|
|
|
|
*/
|
2011-01-17 18:29:19 +01:00
|
|
|
const Scope *findVariableType(const Scope *start, const Token *type) const;
|
2010-12-21 08:13:40 +01:00
|
|
|
|
2011-01-28 08:33:02 +01:00
|
|
|
const Scope *findFunctionScopeByToken(const Token *tok) const;
|
|
|
|
|
|
|
|
const Function *findFunctionByToken(const Token *tok) const;
|
|
|
|
|
2011-01-17 18:29:19 +01:00
|
|
|
bool argsMatch(const Scope *info, const Token *first, const Token *second, const std::string &path, unsigned int depth) const;
|
2011-01-16 11:18:12 +01:00
|
|
|
|
2011-01-16 19:57:29 +01:00
|
|
|
bool isClassOrStruct(const std::string &type) const
|
|
|
|
{
|
|
|
|
return bool(classAndStructTypes.find(type) != classAndStructTypes.end());
|
|
|
|
}
|
|
|
|
|
2011-02-26 21:57:16 +01:00
|
|
|
const Variable *getVariableFromVarId(unsigned int varId) const
|
|
|
|
{
|
|
|
|
return _variableList[varId];
|
|
|
|
}
|
|
|
|
|
2011-03-03 03:08:27 +01:00
|
|
|
/**
|
|
|
|
* @brief output a debug message
|
|
|
|
*/
|
|
|
|
void debugMessage(const Token *tok, const std::string &msg) const;
|
|
|
|
|
2010-11-13 08:08:45 +01:00
|
|
|
private:
|
2010-12-31 10:24:51 +01:00
|
|
|
|
|
|
|
// Needed by Borland C++:
|
2011-01-17 18:29:19 +01:00
|
|
|
friend class Scope;
|
2010-12-31 10:24:51 +01:00
|
|
|
|
2011-01-17 18:29:19 +01:00
|
|
|
void addFunction(Scope **info, const Token **tok, const Token *argStart);
|
|
|
|
void addNewFunction(Scope **info, const Token **tok);
|
|
|
|
const Token *initBaseInfo(Scope *info, const Token *tok);
|
2010-11-13 08:08:45 +01:00
|
|
|
bool isFunction(const Token *tok, const Token **funcStart, const Token **argStart) const;
|
|
|
|
|
2011-01-16 19:57:29 +01:00
|
|
|
/** class/struct types */
|
|
|
|
std::set<std::string> classAndStructTypes;
|
|
|
|
|
2010-11-13 08:08:45 +01:00
|
|
|
const Tokenizer *_tokenizer;
|
|
|
|
const Settings *_settings;
|
|
|
|
ErrorLogger *_errorLogger;
|
2011-02-26 21:57:16 +01:00
|
|
|
|
|
|
|
/** variable symbol table */
|
|
|
|
std::vector<const Variable *> _variableList;
|
2010-11-13 08:08:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|