Refactorizations in SymbolDatabase:
- Moved complete evaluation of variables type into one function executed when the variable is constructed - Moved SymbolDatabase::ArrayDimensions to Variable::ArrayDimensions
This commit is contained in:
parent
11a296cb02
commit
0452b03f53
|
@ -121,25 +121,14 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
Scope *new_scope = &scopeList.back();
|
Scope *new_scope = &scopeList.back();
|
||||||
access[new_scope] = Public;
|
access[new_scope] = Public;
|
||||||
|
|
||||||
std::vector<Dimension> dimensions;
|
|
||||||
|
|
||||||
bool isPointer = false;
|
|
||||||
bool isReference = false;
|
|
||||||
bool isArray = false;
|
|
||||||
|
|
||||||
const Token* varNameTok = tok->next()->link()->next();
|
const Token* varNameTok = tok->next()->link()->next();
|
||||||
if (varNameTok->str() == "*") {
|
if (varNameTok->str() == "*") {
|
||||||
isPointer = true;
|
|
||||||
varNameTok = varNameTok->next();
|
varNameTok = varNameTok->next();
|
||||||
} else if (varNameTok->str() == "&") {
|
} else if (varNameTok->str() == "&") {
|
||||||
isReference = true;
|
|
||||||
varNameTok = varNameTok->next();
|
varNameTok = varNameTok->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (varNameTok->next()->str() == "[")
|
scope->addVariable(varNameTok, tok, tok, access[scope], new_scope, scope);
|
||||||
isArray = arrayDimensions(dimensions, varNameTok->next());
|
|
||||||
|
|
||||||
scope->addVariable(varNameTok, tok, tok, access[scope], false, false, false, true, new_scope, scope, isArray, isPointer, isReference, dimensions);
|
|
||||||
|
|
||||||
const Token *tok2 = tok->next();
|
const Token *tok2 = tok->next();
|
||||||
|
|
||||||
|
@ -817,6 +806,39 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Variable::evaluate()
|
||||||
|
{
|
||||||
|
const Token* tok = _start;
|
||||||
|
if (tok && tok->previous() && tok->previous()->isName())
|
||||||
|
tok = tok->previous();
|
||||||
|
for (; tok != _name; tok = tok->next()) {
|
||||||
|
if (tok->str() == "<")
|
||||||
|
tok->findClosingBracket(tok);
|
||||||
|
if (tok->str() == "static")
|
||||||
|
setFlag(fIsStatic, true);
|
||||||
|
else if (tok->str() == "mutable")
|
||||||
|
setFlag(fIsMutable, true);
|
||||||
|
else if (tok->str() == "const")
|
||||||
|
setFlag(fIsConst, true);
|
||||||
|
else if (tok->str() == "*") {
|
||||||
|
setFlag(fIsPointer, true);
|
||||||
|
setFlag(fIsConst, false); // Points to const, isn't necessarily const itself
|
||||||
|
} else if (tok->str() == "&")
|
||||||
|
setFlag(fIsReference, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_name)
|
||||||
|
setFlag(fIsArray, arrayDimensions(_dimensions, _name->next()));
|
||||||
|
if (_start)
|
||||||
|
setFlag(fIsClass, !_start->isStandardType() && !isPointer() && !isReference());
|
||||||
|
if (_access == Argument && _name) {
|
||||||
|
const Token* tok = _name->next();
|
||||||
|
while (tok->str() == "[")
|
||||||
|
tok = tok->link();
|
||||||
|
setFlag(fHasDefault, tok->str() == "=");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Function::argsMatch(const Scope *scope, const Token *first, const Token *second, const std::string &path, unsigned int depth)
|
bool Function::argsMatch(const Scope *scope, const Token *first, const Token *second, const std::string &path, unsigned int depth)
|
||||||
{
|
{
|
||||||
while (first->str() == second->str()) {
|
while (first->str() == second->str()) {
|
||||||
|
@ -1233,7 +1255,7 @@ void SymbolDatabase::debugMessage(const Token *tok, const std::string &msg) cons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SymbolDatabase::arrayDimensions(std::vector<Dimension> &dimensions, const Token *tok) const
|
bool Variable::arrayDimensions(std::vector<Dimension> &dimensions, const Token *tok)
|
||||||
{
|
{
|
||||||
bool isArray = false;
|
bool isArray = false;
|
||||||
|
|
||||||
|
@ -1524,18 +1546,12 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
|
||||||
const Token* startTok = tok;
|
const Token* startTok = tok;
|
||||||
const Token* endTok = NULL;
|
const Token* endTok = NULL;
|
||||||
const Token* nameTok = NULL;
|
const Token* nameTok = NULL;
|
||||||
bool isConstVar = bool(tok->str() == "const");
|
|
||||||
bool isArrayVar = false;
|
|
||||||
bool hasDefault = false;
|
|
||||||
std::vector<Dimension> dimensions;
|
|
||||||
|
|
||||||
while (tok->str() != "," && tok->str() != ")" && tok->str() != "=") {
|
while (tok->str() != "," && tok->str() != ")" && tok->str() != "=") {
|
||||||
if (tok->varId() != 0) {
|
if (tok->varId() != 0) {
|
||||||
nameTok = tok;
|
nameTok = tok;
|
||||||
endTok = tok->previous();
|
endTok = tok->previous();
|
||||||
} else if (tok->str() == "[") {
|
} else if (tok->str() == "[") {
|
||||||
isArrayVar = symbolDatabase->arrayDimensions(dimensions, tok);
|
|
||||||
|
|
||||||
// skip array dimension(s)
|
// skip array dimension(s)
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
while (tok->next()->str() == "[")
|
while (tok->next()->str() == "[")
|
||||||
|
@ -1552,7 +1568,7 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Token *typeTok = startTok->tokAt(isConstVar ? 1 : 0);
|
const Token *typeTok = startTok->tokAt(startTok->str() == "const" ? 1 : 0);
|
||||||
if (typeTok->str() == "struct")
|
if (typeTok->str() == "struct")
|
||||||
typeTok = typeTok->next();
|
typeTok = typeTok->next();
|
||||||
|
|
||||||
|
@ -1575,19 +1591,13 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s
|
||||||
if (!typeTok->isStandardType())
|
if (!typeTok->isStandardType())
|
||||||
argType = symbolDatabase->findVariableType(scope, typeTok);
|
argType = symbolDatabase->findVariableType(scope, typeTok);
|
||||||
|
|
||||||
bool isClassVar = startTok == endTok && !startTok->isStandardType();
|
|
||||||
bool isPointerVar = nameTok->strAt(-1) == "*" || nameTok->strAt(-2) == "*";
|
|
||||||
bool isReferenceVar = nameTok->strAt(-1) == "&";
|
|
||||||
|
|
||||||
// skip default values
|
// skip default values
|
||||||
if (tok->str() == "=") {
|
if (tok->str() == "=") {
|
||||||
hasDefault = true;
|
|
||||||
|
|
||||||
while (tok->str() != "," && tok->str() != ")")
|
while (tok->str() != "," && tok->str() != ")")
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
argumentList.push_back(Variable(nameTok, startTok, endTok, count++, Argument, false, false, isConstVar, isClassVar, argType, functionScope, isArrayVar, isPointerVar, isReferenceVar, hasDefault, dimensions));
|
argumentList.push_back(Variable(nameTok, startTok, endTok, count++, Argument, argType, functionScope));
|
||||||
|
|
||||||
if (tok->str() == ")")
|
if (tok->str() == ")")
|
||||||
break;
|
break;
|
||||||
|
@ -1883,56 +1893,38 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is it const..?
|
// Is it const..?
|
||||||
bool isConst(tok->str() == "const");
|
if (tok->str() == "const") {
|
||||||
if (isConst) {
|
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is it a static variable?
|
// Is it a static variable?
|
||||||
const bool isStatic(tok->str() == "static");
|
if (tok->str() == "static") {
|
||||||
if (isStatic) {
|
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is it a mutable variable?
|
// Is it a mutable variable?
|
||||||
const bool isMutable(tok->str() == "mutable");
|
if (tok->str() == "mutable") {
|
||||||
if (isMutable) {
|
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is it const..?
|
// Is it const..?
|
||||||
if (tok->str() == "const") {
|
if (tok->str() == "const") {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
isConst = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// the start of the type tokens does not include the above modifiers
|
// the start of the type tokens does not include the above modifiers
|
||||||
const Token *typestart = tok;
|
const Token *typestart = tok;
|
||||||
|
|
||||||
bool isClass = false;
|
|
||||||
|
|
||||||
if (Token::Match(tok, "struct|union")) {
|
if (Token::Match(tok, "struct|union")) {
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isArray = false;
|
if (tok && isVariableDeclaration(tok, vartok, typetok)) {
|
||||||
bool isPointer = false;
|
// If the vartok was set in the if-blocks above, create a entry for this variable..
|
||||||
bool isReference = false;
|
tok = vartok->next();
|
||||||
std::vector<Dimension> dimensions;
|
while (tok && tok->str() == "[")
|
||||||
|
tok = tok->link()->next();
|
||||||
|
|
||||||
if (tok && isVariableDeclaration(tok, vartok, typetok, isArray, isPointer, isReference)) {
|
|
||||||
isClass = (!typetok->isStandardType() && !isPointer && vartok->previous()->str() != "&");
|
|
||||||
if (isArray) {
|
|
||||||
isArray = check->arrayDimensions(dimensions, vartok->next());
|
|
||||||
tok = vartok->next();
|
|
||||||
while (tok && tok->str() == "[")
|
|
||||||
tok = tok->link()->next();
|
|
||||||
} else
|
|
||||||
tok = vartok->next();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the vartok was set in the if-blocks above, create a entry for this variable..
|
|
||||||
if (vartok && vartok->str() != "operator") {
|
|
||||||
if (vartok->varId() == 0 && !vartok->isBoolean())
|
if (vartok->varId() == 0 && !vartok->isBoolean())
|
||||||
check->debugMessage(vartok, "Scope::checkVariable found variable \'" + vartok->str() + "\' with varid 0.");
|
check->debugMessage(vartok, "Scope::checkVariable found variable \'" + vartok->str() + "\' with varid 0.");
|
||||||
|
|
||||||
|
@ -1941,7 +1933,7 @@ const Token *Scope::checkVariable(const Token *tok, AccessControl varaccess)
|
||||||
if (typetok)
|
if (typetok)
|
||||||
scope = check->findVariableType(this, typetok);
|
scope = check->findVariableType(this, typetok);
|
||||||
|
|
||||||
addVariable(vartok, typestart, vartok->previous(), varaccess, isMutable, isStatic, isConst, isClass, scope, this, isArray, isPointer, isReference, dimensions);
|
addVariable(vartok, typestart, vartok->previous(), varaccess, scope, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tok;
|
return tok;
|
||||||
|
@ -1980,7 +1972,7 @@ static const Token* skipPointers(const Token* tok)
|
||||||
return tok;
|
return tok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Scope::isVariableDeclaration(const Token* tok, const Token*& vartok, const Token*& typetok, bool &isArray, bool &isPointer, bool &isReference) const
|
bool Scope::isVariableDeclaration(const Token* tok, const Token*& vartok, const Token*& typetok) const
|
||||||
{
|
{
|
||||||
if (tok && tok->str() == "throw" && check->_tokenizer->isCPP())
|
if (tok && tok->str() == "throw" && check->_tokenizer->isCPP())
|
||||||
return false;
|
return false;
|
||||||
|
@ -2006,28 +1998,21 @@ bool Scope::isVariableDeclaration(const Token* tok, const Token*& vartok, const
|
||||||
if (Token::Match(localVarTok, "%var% ;|=")) {
|
if (Token::Match(localVarTok, "%var% ;|=")) {
|
||||||
vartok = localVarTok;
|
vartok = localVarTok;
|
||||||
typetok = localTypeTok;
|
typetok = localTypeTok;
|
||||||
isArray = false;
|
|
||||||
} else if (Token::Match(localVarTok, "%var% [") && localVarTok->str() != "operator") {
|
} else if (Token::Match(localVarTok, "%var% [") && localVarTok->str() != "operator") {
|
||||||
vartok = localVarTok;
|
vartok = localVarTok;
|
||||||
typetok = localTypeTok;
|
typetok = localTypeTok;
|
||||||
isArray = true;
|
|
||||||
} else if ((isLocal() || type == Scope::eFunction) &&
|
} else if ((isLocal() || type == Scope::eFunction) &&
|
||||||
Token::Match(localVarTok, "%var% (") &&
|
Token::Match(localVarTok, "%var% (") &&
|
||||||
Token::simpleMatch(localVarTok->next()->link(), ") ;")) {
|
Token::simpleMatch(localVarTok->next()->link(), ") ;")) {
|
||||||
vartok = localVarTok;
|
vartok = localVarTok;
|
||||||
typetok = localTypeTok;
|
typetok = localTypeTok;
|
||||||
isArray = false;
|
|
||||||
} else if (type == eCatch &&
|
} else if (type == eCatch &&
|
||||||
(Token::Match(localTypeTok, "%var% )") ||
|
(Token::Match(localTypeTok, "%var% )") ||
|
||||||
Token::Match(localTypeTok, "%var% &| %var% )"))) {
|
Token::Match(localTypeTok, "%var% &| %var% )"))) {
|
||||||
vartok = localVarTok;
|
vartok = localVarTok;
|
||||||
typetok = localTypeTok;
|
typetok = localTypeTok;
|
||||||
isArray = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isPointer = vartok && (vartok->strAt(-1) == "*" || Token::simpleMatch(vartok->tokAt(-2), "* const"));
|
|
||||||
isReference = vartok && vartok->strAt(-1) == "&";
|
|
||||||
|
|
||||||
return NULL != vartok;
|
return NULL != vartok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,12 +84,18 @@ class Variable {
|
||||||
_flags = state_ ? _flags | flag_ : _flags & ~flag_;
|
_flags = state_ ? _flags | flag_ : _flags & ~flag_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief parse and save array dimension information
|
||||||
|
* @param dimensions array dimensions vector
|
||||||
|
* @param tok the first '[' token of array declaration
|
||||||
|
* @return true if array, false if not
|
||||||
|
*/
|
||||||
|
static bool arrayDimensions(std::vector<Dimension> &dimensions, const Token *tok);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Variable(const Token *name_, const Token *start_, const Token *end_,
|
Variable(const Token *name_, const Token *start_, const Token *end_,
|
||||||
std::size_t index_, AccessControl access_, bool mutable_,
|
std::size_t index_, AccessControl access_, const Scope *type_,
|
||||||
bool static_, bool const_, bool class_, const Scope *type_,
|
const Scope *scope_)
|
||||||
const Scope *scope_, bool array_, bool pointer_, bool reference_,
|
|
||||||
bool default_, const std::vector<Dimension> &dimensions_)
|
|
||||||
: _name(name_),
|
: _name(name_),
|
||||||
_start(start_),
|
_start(start_),
|
||||||
_end(end_),
|
_end(end_),
|
||||||
|
@ -98,15 +104,7 @@ public:
|
||||||
_flags(0),
|
_flags(0),
|
||||||
_type(type_),
|
_type(type_),
|
||||||
_scope(scope_) {
|
_scope(scope_) {
|
||||||
setFlag(fIsMutable, mutable_);
|
evaluate();
|
||||||
setFlag(fIsStatic, static_);
|
|
||||||
setFlag(fIsConst, const_);
|
|
||||||
setFlag(fIsClass, class_);
|
|
||||||
setFlag(fIsArray, array_);
|
|
||||||
setFlag(fIsPointer, pointer_);
|
|
||||||
setFlag(fIsReference, reference_);
|
|
||||||
setFlag(fHasDefault, default_);
|
|
||||||
_dimensions = dimensions_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -354,6 +352,9 @@ private:
|
||||||
|
|
||||||
/** @brief array dimensions */
|
/** @brief array dimensions */
|
||||||
std::vector<Dimension> _dimensions;
|
std::vector<Dimension> _dimensions;
|
||||||
|
|
||||||
|
/** @brief fill in information, depending on Tokens given at instanciation */
|
||||||
|
void evaluate();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Function {
|
class Function {
|
||||||
|
@ -384,7 +385,6 @@ public:
|
||||||
std::size_t argCount() const {
|
std::size_t argCount() const {
|
||||||
return argumentList.size();
|
return argumentList.size();
|
||||||
}
|
}
|
||||||
/** @brief get a pointer to the variable instance associated with the given argument number */
|
|
||||||
const Variable* getArgumentVar(unsigned int num) const;
|
const Variable* getArgumentVar(unsigned int num) const;
|
||||||
unsigned int initializedArgCount() const;
|
unsigned int initializedArgCount() const;
|
||||||
void addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope);
|
void addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope);
|
||||||
|
@ -486,13 +486,11 @@ public:
|
||||||
const Scope * findQualifiedScope(const std::string & name) const;
|
const Scope * findQualifiedScope(const std::string & name) const;
|
||||||
|
|
||||||
void addVariable(const Token *token_, const Token *start_,
|
void addVariable(const Token *token_, const Token *start_,
|
||||||
const Token *end_, AccessControl access_, bool mutable_,
|
const Token *end_, AccessControl access_, const Scope *type_,
|
||||||
bool static_, bool const_, bool class_, const Scope *type_,
|
const Scope *scope_) {
|
||||||
const Scope *scope_, bool array_, bool pointer_, bool reference_,
|
|
||||||
const std::vector<Dimension> &dimensions_) {
|
|
||||||
varlist.push_back(Variable(token_, start_, end_, varlist.size(),
|
varlist.push_back(Variable(token_, start_, end_, varlist.size(),
|
||||||
access_, mutable_, static_, const_, class_,
|
access_,
|
||||||
type_, scope_, array_, pointer_, reference_, false, dimensions_));
|
type_, scope_));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief initialize varlist */
|
/** @brief initialize varlist */
|
||||||
|
@ -537,7 +535,7 @@ private:
|
||||||
* @param isPointer reference to variable to set if pointer is found
|
* @param isPointer reference to variable to set if pointer is found
|
||||||
* @return true if tok points to a variable declaration, false otherwise
|
* @return true if tok points to a variable declaration, false otherwise
|
||||||
*/
|
*/
|
||||||
bool isVariableDeclaration(const Token* tok, const Token*& vartok, const Token*& typetok, bool &isArray, bool &isPointer, bool &isReference) const;
|
bool isVariableDeclaration(const Token* tok, const Token*& vartok, const Token*& typetok) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SymbolDatabase {
|
class SymbolDatabase {
|
||||||
|
@ -578,14 +576,6 @@ public:
|
||||||
*/
|
*/
|
||||||
void debugMessage(const Token *tok, const std::string &msg) const;
|
void debugMessage(const Token *tok, const std::string &msg) const;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief parse and save array dimension information
|
|
||||||
* @param dimensions array dimensions vector
|
|
||||||
* @param tok the first '[' token of array declaration
|
|
||||||
* @return true if array, false if not
|
|
||||||
*/
|
|
||||||
bool arrayDimensions(std::vector<Dimension> &dimensions, const Token *tok) const;
|
|
||||||
|
|
||||||
void printOut(const char * title = NULL) const;
|
void printOut(const char * title = NULL) const;
|
||||||
void printVariable(const Variable *var, const char *indent) const;
|
void printVariable(const Variable *var, const char *indent) const;
|
||||||
|
|
||||||
|
|
|
@ -44,31 +44,21 @@ public:
|
||||||
,vartok(NULL)
|
,vartok(NULL)
|
||||||
,typetok(NULL)
|
,typetok(NULL)
|
||||||
,t(NULL)
|
,t(NULL)
|
||||||
,isArray(false)
|
,found(false)
|
||||||
,isPointer(false)
|
|
||||||
,isReference(false)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
virtual void reportOut(const std::string &outmsg) {
|
|
||||||
errout << outmsg << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Scope si;
|
const Scope si;
|
||||||
const Token* vartok;
|
const Token* vartok;
|
||||||
const Token* typetok;
|
const Token* typetok;
|
||||||
const Token* t;
|
const Token* t;
|
||||||
bool isArray;
|
bool found;
|
||||||
bool isPointer;
|
|
||||||
bool isReference;
|
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
vartok = NULL;
|
vartok = NULL;
|
||||||
typetok = NULL;
|
typetok = NULL;
|
||||||
t = NULL;
|
t = NULL;
|
||||||
isArray = false;
|
found = false;
|
||||||
isPointer = false;
|
|
||||||
isReference = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void run() {
|
void run() {
|
||||||
|
@ -157,287 +147,301 @@ private:
|
||||||
|
|
||||||
void test_isVariableDeclarationCanHandleNull() {
|
void test_isVariableDeclarationCanHandleNull() {
|
||||||
reset();
|
reset();
|
||||||
bool result = si.isVariableDeclaration(NULL, vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(NULL, vartok, typetok);
|
||||||
ASSERT_EQUALS(false, result);
|
ASSERT_EQUALS(false, result);
|
||||||
ASSERT(NULL == vartok);
|
ASSERT(NULL == vartok);
|
||||||
ASSERT(NULL == typetok);
|
ASSERT(NULL == typetok);
|
||||||
ASSERT(false == isArray);
|
Variable v(NULL, NULL, NULL, 0, Public, 0, 0);
|
||||||
ASSERT(false == isPointer);
|
|
||||||
ASSERT(false == isReference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_isVariableDeclarationIdentifiesSimpleDeclaration() {
|
void test_isVariableDeclarationIdentifiesSimpleDeclaration() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize simpleDeclaration("int x;");
|
givenACodeSampleToTokenize simpleDeclaration("int x;");
|
||||||
bool result = si.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("x", vartok->str());
|
ASSERT_EQUALS("x", vartok->str());
|
||||||
ASSERT_EQUALS("int", typetok->str());
|
ASSERT_EQUALS("int", typetok->str());
|
||||||
ASSERT(false == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(false == isPointer);
|
ASSERT(false == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(false == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_isVariableDeclarationIdentifiesScopedDeclaration() {
|
void test_isVariableDeclarationIdentifiesScopedDeclaration() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize ScopedDeclaration("::int x;");
|
givenACodeSampleToTokenize ScopedDeclaration("::int x;");
|
||||||
bool result = si.isVariableDeclaration(ScopedDeclaration.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(ScopedDeclaration.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("x", vartok->str());
|
ASSERT_EQUALS("x", vartok->str());
|
||||||
ASSERT_EQUALS("int", typetok->str());
|
ASSERT_EQUALS("int", typetok->str());
|
||||||
ASSERT(false == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(false == isPointer);
|
ASSERT(false == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(false == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_isVariableDeclarationIdentifiesStdDeclaration() {
|
void test_isVariableDeclarationIdentifiesStdDeclaration() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize StdDeclaration("std::string x;");
|
givenACodeSampleToTokenize StdDeclaration("std::string x;");
|
||||||
bool result = si.isVariableDeclaration(StdDeclaration.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(StdDeclaration.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("x", vartok->str());
|
ASSERT_EQUALS("x", vartok->str());
|
||||||
ASSERT_EQUALS("string", typetok->str());
|
ASSERT_EQUALS("string", typetok->str());
|
||||||
ASSERT(false == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(false == isPointer);
|
ASSERT(false == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(false == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_isVariableDeclarationIdentifiesScopedStdDeclaration() {
|
void test_isVariableDeclarationIdentifiesScopedStdDeclaration() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize StdDeclaration("::std::string x;");
|
givenACodeSampleToTokenize StdDeclaration("::std::string x;");
|
||||||
bool result = si.isVariableDeclaration(StdDeclaration.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(StdDeclaration.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("x", vartok->str());
|
ASSERT_EQUALS("x", vartok->str());
|
||||||
ASSERT_EQUALS("string", typetok->str());
|
ASSERT_EQUALS("string", typetok->str());
|
||||||
ASSERT(false == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(false == isPointer);
|
ASSERT(false == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(false == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_isVariableDeclarationIdentifiesManyScopes() {
|
void test_isVariableDeclarationIdentifiesManyScopes() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize manyScopes("AA::BB::CC::DD::EE x;");
|
givenACodeSampleToTokenize manyScopes("AA::BB::CC::DD::EE x;");
|
||||||
bool result = si.isVariableDeclaration(manyScopes.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(manyScopes.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("x", vartok->str());
|
ASSERT_EQUALS("x", vartok->str());
|
||||||
ASSERT_EQUALS("EE", typetok->str());
|
ASSERT_EQUALS("EE", typetok->str());
|
||||||
ASSERT(false == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(false == isPointer);
|
ASSERT(false == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(false == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_isVariableDeclarationIdentifiesPointers() {
|
void test_isVariableDeclarationIdentifiesPointers() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize pointer("int* p;");
|
givenACodeSampleToTokenize pointer("int* p;");
|
||||||
bool result = si.isVariableDeclaration(pointer.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(pointer.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("p", vartok->str());
|
ASSERT_EQUALS("p", vartok->str());
|
||||||
ASSERT_EQUALS("int", typetok->str());
|
ASSERT_EQUALS("int", typetok->str());
|
||||||
ASSERT(false == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(true == isPointer);
|
ASSERT(false == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(true == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_isVariableDeclarationDoesNotIdentifyConstness() {
|
void test_isVariableDeclarationDoesNotIdentifyConstness() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize constness("const int* cp;");
|
givenACodeSampleToTokenize constness("const int* cp;");
|
||||||
bool result = si.isVariableDeclaration(constness.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(constness.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(false, result);
|
ASSERT_EQUALS(false, result);
|
||||||
ASSERT(NULL == vartok);
|
ASSERT(NULL == vartok);
|
||||||
ASSERT(NULL == typetok);
|
ASSERT(NULL == typetok);
|
||||||
ASSERT(false == isArray);
|
|
||||||
ASSERT(false == isPointer);
|
|
||||||
ASSERT(false == isReference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_isVariableDeclarationIdentifiesFirstOfManyVariables() {
|
void test_isVariableDeclarationIdentifiesFirstOfManyVariables() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize multipleDeclaration("int first, second;");
|
givenACodeSampleToTokenize multipleDeclaration("int first, second;");
|
||||||
bool result = si.isVariableDeclaration(multipleDeclaration.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(multipleDeclaration.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("first", vartok->str());
|
ASSERT_EQUALS("first", vartok->str());
|
||||||
ASSERT_EQUALS("int", typetok->str());
|
ASSERT_EQUALS("int", typetok->str());
|
||||||
ASSERT(false == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(false == isPointer);
|
ASSERT(false == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(false == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_isVariableDeclarationIdentifiesScopedPointerDeclaration() {
|
void test_isVariableDeclarationIdentifiesScopedPointerDeclaration() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize manyScopes("AA::BB::CC::DD::EE* p;");
|
givenACodeSampleToTokenize manyScopes("AA::BB::CC::DD::EE* p;");
|
||||||
bool result = si.isVariableDeclaration(manyScopes.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(manyScopes.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("p", vartok->str());
|
ASSERT_EQUALS("p", vartok->str());
|
||||||
ASSERT_EQUALS("EE", typetok->str());
|
ASSERT_EQUALS("EE", typetok->str());
|
||||||
ASSERT(false == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(true == isPointer);
|
ASSERT(false == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(true == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_isVariableDeclarationIdentifiesDeclarationWithIndirection() {
|
void test_isVariableDeclarationIdentifiesDeclarationWithIndirection() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize pointerToPointer("int** pp;");
|
givenACodeSampleToTokenize pointerToPointer("int** pp;");
|
||||||
bool result = si.isVariableDeclaration(pointerToPointer.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(pointerToPointer.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("pp", vartok->str());
|
ASSERT_EQUALS("pp", vartok->str());
|
||||||
ASSERT_EQUALS("int", typetok->str());
|
ASSERT_EQUALS("int", typetok->str());
|
||||||
ASSERT(false == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(true == isPointer);
|
ASSERT(false == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(true == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_isVariableDeclarationIdentifiesDeclarationWithMultipleIndirection() {
|
void test_isVariableDeclarationIdentifiesDeclarationWithMultipleIndirection() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize pointerToPointer("int***** p;");
|
givenACodeSampleToTokenize pointerToPointer("int***** p;");
|
||||||
bool result = si.isVariableDeclaration(pointerToPointer.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(pointerToPointer.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("p", vartok->str());
|
ASSERT_EQUALS("p", vartok->str());
|
||||||
ASSERT_EQUALS("int", typetok->str());
|
ASSERT_EQUALS("int", typetok->str());
|
||||||
ASSERT(false == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(true == isPointer);
|
ASSERT(false == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(true == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_isVariableDeclarationIdentifiesArray() {
|
void test_isVariableDeclarationIdentifiesArray() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize array("::std::string v[3];");
|
givenACodeSampleToTokenize array("::std::string v[3];");
|
||||||
bool result = si.isVariableDeclaration(array.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(array.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("v", vartok->str());
|
ASSERT_EQUALS("v", vartok->str());
|
||||||
ASSERT_EQUALS("string", typetok->str());
|
ASSERT_EQUALS("string", typetok->str());
|
||||||
ASSERT(true == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(false == isPointer);
|
ASSERT(true == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(false == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_isVariableDeclarationIdentifiesOfArrayPointers() {
|
void test_isVariableDeclarationIdentifiesOfArrayPointers() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize array("A *a[5];");
|
givenACodeSampleToTokenize array("A *a[5];");
|
||||||
bool result = si.isVariableDeclaration(array.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(array.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("a", vartok->str());
|
ASSERT_EQUALS("a", vartok->str());
|
||||||
ASSERT_EQUALS("A", typetok->str());
|
ASSERT_EQUALS("A", typetok->str());
|
||||||
ASSERT(true == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(true == isPointer);
|
ASSERT(true == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(true == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void isVariableDeclarationIdentifiesTemplatedPointerVariable() {
|
void isVariableDeclarationIdentifiesTemplatedPointerVariable() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize var("std::set<char>* chars;");
|
givenACodeSampleToTokenize var("std::set<char>* chars;");
|
||||||
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("chars", vartok->str());
|
ASSERT_EQUALS("chars", vartok->str());
|
||||||
ASSERT_EQUALS("set", typetok->str());
|
ASSERT_EQUALS("set", typetok->str());
|
||||||
ASSERT(false == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(true == isPointer);
|
ASSERT(false == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(true == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable() {
|
void isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize var("std::deque<int>*** ints;");
|
givenACodeSampleToTokenize var("std::deque<int>*** ints;");
|
||||||
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("ints", vartok->str());
|
ASSERT_EQUALS("ints", vartok->str());
|
||||||
ASSERT_EQUALS("deque", typetok->str());
|
ASSERT_EQUALS("deque", typetok->str());
|
||||||
ASSERT(false == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(true == isPointer);
|
ASSERT(false == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(true == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void isVariableDeclarationIdentifiesTemplatedArrayVariable() {
|
void isVariableDeclarationIdentifiesTemplatedArrayVariable() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize var("std::deque<int> ints[3];");
|
givenACodeSampleToTokenize var("std::deque<int> ints[3];");
|
||||||
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("ints", vartok->str());
|
ASSERT_EQUALS("ints", vartok->str());
|
||||||
ASSERT_EQUALS("deque", typetok->str());
|
ASSERT_EQUALS("deque", typetok->str());
|
||||||
ASSERT(true == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(false == isPointer);
|
ASSERT(true == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(false == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void isVariableDeclarationIdentifiesTemplatedVariable() {
|
void isVariableDeclarationIdentifiesTemplatedVariable() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize var("std::vector<int> ints;");
|
givenACodeSampleToTokenize var("std::vector<int> ints;");
|
||||||
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("ints", vartok->str());
|
ASSERT_EQUALS("ints", vartok->str());
|
||||||
ASSERT_EQUALS("vector", typetok->str());
|
ASSERT_EQUALS("vector", typetok->str());
|
||||||
ASSERT(false == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(false == isPointer);
|
ASSERT(false == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(false == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void isVariableDeclarationIdentifiesTemplatedVariableIterator() {
|
void isVariableDeclarationIdentifiesTemplatedVariableIterator() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize var("std::list<int>::const_iterator floats;");
|
givenACodeSampleToTokenize var("std::list<int>::const_iterator floats;");
|
||||||
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("floats", vartok->str());
|
ASSERT_EQUALS("floats", vartok->str());
|
||||||
ASSERT_EQUALS("const_iterator", typetok->str());
|
ASSERT_EQUALS("const_iterator", typetok->str());
|
||||||
ASSERT(false == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(false == isPointer);
|
ASSERT(false == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(false == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void isVariableDeclarationIdentifiesNestedTemplateVariable() {
|
void isVariableDeclarationIdentifiesNestedTemplateVariable() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");
|
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");
|
||||||
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT_EQUALS("intsets", vartok->str());
|
ASSERT_EQUALS("intsets", vartok->str());
|
||||||
ASSERT_EQUALS("deque", typetok->str());
|
ASSERT_EQUALS("deque", typetok->str());
|
||||||
ASSERT(false == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(false == isPointer);
|
ASSERT(false == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(false == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void isVariableDeclarationIdentifiesReference() {
|
void isVariableDeclarationIdentifiesReference() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize var1("int& foo;");
|
givenACodeSampleToTokenize var1("int& foo;");
|
||||||
bool result1 = si.isVariableDeclaration(var1.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result1 = si.isVariableDeclaration(var1.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result1);
|
ASSERT_EQUALS(true, result1);
|
||||||
ASSERT(false == isArray);
|
Variable v1(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(false == isPointer);
|
ASSERT(false == v1.isArray());
|
||||||
ASSERT(true == isReference);
|
ASSERT(false == v1.isPointer());
|
||||||
|
ASSERT(true == v1.isReference());
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize var2("foo*& bar;");
|
givenACodeSampleToTokenize var2("foo*& bar;");
|
||||||
bool result2 = si.isVariableDeclaration(var2.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result2 = si.isVariableDeclaration(var2.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result2);
|
ASSERT_EQUALS(true, result2);
|
||||||
ASSERT(false == isArray);
|
Variable v2(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(false == isPointer);
|
ASSERT(false == v2.isArray());
|
||||||
ASSERT(true == isReference);
|
ASSERT(true == v2.isPointer());
|
||||||
|
ASSERT(true == v2.isReference());
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize var3("std::vector<int>& foo;");
|
givenACodeSampleToTokenize var3("std::vector<int>& foo;");
|
||||||
bool result3 = si.isVariableDeclaration(var3.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result3 = si.isVariableDeclaration(var3.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result3);
|
ASSERT_EQUALS(true, result3);
|
||||||
ASSERT(false == isArray);
|
Variable v3(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(false == isPointer);
|
ASSERT(false == v3.isArray());
|
||||||
ASSERT(true == isReference);
|
ASSERT(false == v3.isPointer());
|
||||||
|
ASSERT(true == v3.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void isVariableDeclarationDoesNotIdentifyTemplateClass() {
|
void isVariableDeclarationDoesNotIdentifyTemplateClass() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize var("template <class T> class SomeClass{};");
|
givenACodeSampleToTokenize var("template <class T> class SomeClass{};");
|
||||||
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(false, result);
|
ASSERT_EQUALS(false, result);
|
||||||
ASSERT(false == isArray);
|
|
||||||
ASSERT(false == isPointer);
|
|
||||||
ASSERT(false == isReference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void isVariableDeclarationPointerConst() {
|
void isVariableDeclarationPointerConst() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize var("std::string const* s;");
|
givenACodeSampleToTokenize var("std::string const* s;");
|
||||||
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok, isArray, isPointer, isReference);
|
bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result);
|
||||||
ASSERT(false == isArray);
|
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(true == isPointer);
|
ASSERT(false == v.isArray());
|
||||||
ASSERT(false == isReference);
|
ASSERT(true == v.isPointer());
|
||||||
|
ASSERT(false == v.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void hasRegularFunction() {
|
void hasRegularFunction() {
|
||||||
|
@ -450,12 +454,14 @@ private:
|
||||||
const Scope *scope = db->findFunctionScopeByToken(tokenizer.tokens()->next());
|
const Scope *scope = db->findFunctionScopeByToken(tokenizer.tokens()->next());
|
||||||
|
|
||||||
ASSERT(scope && scope->className == "func");
|
ASSERT(scope && scope->className == "func");
|
||||||
|
ASSERT(scope && scope->functionOf == 0);
|
||||||
|
|
||||||
const Function *function = db->findFunctionByToken(tokenizer.tokens()->next());
|
const Function *function = db->findFunctionByToken(tokenizer.tokens()->next());
|
||||||
|
|
||||||
ASSERT(function && function->token->str() == "func");
|
ASSERT(function && function->token->str() == "func");
|
||||||
ASSERT(function && function->token == tokenizer.tokens()->next());
|
ASSERT(function && function->token == tokenizer.tokens()->next());
|
||||||
ASSERT(function && function->hasBody);
|
ASSERT(function && function->hasBody);
|
||||||
|
ASSERT(function && function->functionScope == scope && scope->function == function);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,12 +475,14 @@ private:
|
||||||
const Scope *scope = db->findFunctionScopeByToken(tokenizer.tokens()->tokAt(4));
|
const Scope *scope = db->findFunctionScopeByToken(tokenizer.tokens()->tokAt(4));
|
||||||
|
|
||||||
ASSERT(scope && scope->className == "func");
|
ASSERT(scope && scope->className == "func");
|
||||||
|
ASSERT(scope && scope->functionOf && scope->functionOf == db->findScopeByName("Fred"));
|
||||||
|
|
||||||
const Function *function = db->findFunctionByToken(tokenizer.tokens()->tokAt(4));
|
const Function *function = db->findFunctionByToken(tokenizer.tokens()->tokAt(4));
|
||||||
|
|
||||||
ASSERT(function && function->token->str() == "func");
|
ASSERT(function && function->token->str() == "func");
|
||||||
ASSERT(function && function->token == tokenizer.tokens()->tokAt(4));
|
ASSERT(function && function->token == tokenizer.tokens()->tokAt(4));
|
||||||
ASSERT(function && function->hasBody && function->isInline);
|
ASSERT(function && function->hasBody && function->isInline);
|
||||||
|
ASSERT(function && function->functionScope == scope && scope->function == function);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,12 +515,14 @@ private:
|
||||||
const Scope *scope = db->findFunctionScopeByToken(tokenizer.tokens()->tokAt(12));
|
const Scope *scope = db->findFunctionScopeByToken(tokenizer.tokens()->tokAt(12));
|
||||||
|
|
||||||
ASSERT(scope && scope->className == "func");
|
ASSERT(scope && scope->className == "func");
|
||||||
|
ASSERT(scope && scope->functionOf && scope->functionOf == db->findScopeByName("Fred"));
|
||||||
|
|
||||||
const Function *function = db->findFunctionByToken(tokenizer.tokens()->tokAt(12));
|
const Function *function = db->findFunctionByToken(tokenizer.tokens()->tokAt(12));
|
||||||
|
|
||||||
ASSERT(function && function->token->str() == "func");
|
ASSERT(function && function->token->str() == "func");
|
||||||
ASSERT(function && function->token == tokenizer.tokens()->tokAt(12));
|
ASSERT(function && function->token == tokenizer.tokens()->tokAt(12));
|
||||||
ASSERT(function && function->hasBody && !function->isInline);
|
ASSERT(function && function->hasBody && !function->isInline);
|
||||||
|
ASSERT(function && function->functionScope == scope && scope->function == function);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -712,13 +722,26 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void functionArgs1() {
|
void functionArgs1() {
|
||||||
check("void f(std::vector<std::string s>, const std::vector<int> & v) { }\n");
|
{
|
||||||
|
GET_SYMBOL_DB("void f(std::vector<std::string>, const std::vector<int> & v) { }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
TODO_ASSERT_EQUALS(1+1, 1+2, db->getVariableListSize());
|
||||||
|
const Variable* v = db->getVariableFromVarId(2); // TODO: varId 1
|
||||||
check("void f(std::map<std::string, std::vector<int> > m) { }\n");
|
ASSERT(v && v->isReference() && v->isConst() && v->isArgument());
|
||||||
|
const Scope* f = db->findScopeByName("f");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT(f && f->type == Scope::eFunction && f->function);
|
||||||
|
if (f && f->function)
|
||||||
|
ASSERT(f->function->argumentList.size() == 2 && f->function->argumentList.front().index() == 0 && f->function->argumentList.front().name() == "" && f->function->argumentList.back().index() == 1);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
GET_SYMBOL_DB("void g(std::map<std::string, std::vector<int> > m) { }");
|
||||||
|
ASSERT_EQUALS(1+1, db->getVariableListSize());
|
||||||
|
const Variable* m = db->getVariableFromVarId(1);
|
||||||
|
ASSERT(m && !m->isReference() && !m->isConst() && m->isArgument() && m->isClass());
|
||||||
|
const Scope* g = db->findScopeByName("g");
|
||||||
|
ASSERT(g && g->type == Scope::eFunction && g->function && g->function->argumentList.size() == 1 && g->function->argumentList.front().index() == 0);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void functionArgs2() {
|
void functionArgs2() {
|
||||||
|
|
Loading…
Reference in New Issue