Bugfixes in SymbolDatabase:
- Constant pointers are now detected as variable declarations - Probably fixed #3802
This commit is contained in:
parent
eacf74be8d
commit
1dee3b04b9
|
@ -811,9 +811,7 @@ void Variable::evaluate()
|
||||||
const Token* tok = _start;
|
const Token* tok = _start;
|
||||||
if (tok && tok->previous() && tok->previous()->isName())
|
if (tok && tok->previous() && tok->previous()->isName())
|
||||||
tok = tok->previous();
|
tok = tok->previous();
|
||||||
for (; tok != _name; tok = tok->next()) {
|
for (const Token* const end = _name?_name:_end; tok != end;) {
|
||||||
if (tok->str() == "<")
|
|
||||||
tok->findClosingBracket(tok);
|
|
||||||
if (tok->str() == "static")
|
if (tok->str() == "static")
|
||||||
setFlag(fIsStatic, true);
|
setFlag(fIsStatic, true);
|
||||||
else if (tok->str() == "mutable")
|
else if (tok->str() == "mutable")
|
||||||
|
@ -825,6 +823,11 @@ void Variable::evaluate()
|
||||||
setFlag(fIsConst, false); // Points to const, isn't necessarily const itself
|
setFlag(fIsConst, false); // Points to const, isn't necessarily const itself
|
||||||
} else if (tok->str() == "&")
|
} else if (tok->str() == "&")
|
||||||
setFlag(fIsReference, true);
|
setFlag(fIsReference, true);
|
||||||
|
|
||||||
|
if (tok->str() == "<")
|
||||||
|
tok->findClosingBracket(tok);
|
||||||
|
else
|
||||||
|
tok = tok->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_name)
|
if (_name)
|
||||||
|
@ -1995,6 +1998,9 @@ bool Scope::isVariableDeclaration(const Token* tok, const Token*& vartok, const
|
||||||
localVarTok = skipPointers(localTypeTok->strAt(1)=="const"?localTypeTok->tokAt(2):localTypeTok->next());
|
localVarTok = skipPointers(localTypeTok->strAt(1)=="const"?localTypeTok->tokAt(2):localTypeTok->next());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (localVarTok && localVarTok->str() == "const")
|
||||||
|
localVarTok = localVarTok->next();
|
||||||
|
|
||||||
if (Token::Match(localVarTok, "%var% ;|=")) {
|
if (Token::Match(localVarTok, "%var% ;|=")) {
|
||||||
vartok = localVarTok;
|
vartok = localVarTok;
|
||||||
typetok = localTypeTok;
|
typetok = localTypeTok;
|
||||||
|
|
|
@ -222,14 +222,34 @@ private:
|
||||||
void test_isVariableDeclarationIdentifiesPointers() {
|
void test_isVariableDeclarationIdentifiesPointers() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize pointer("int* p;");
|
givenACodeSampleToTokenize pointer("int* p;");
|
||||||
bool result = si.isVariableDeclaration(pointer.tokens(), vartok, typetok);
|
bool result1 = si.isVariableDeclaration(pointer.tokens(), vartok, typetok);
|
||||||
ASSERT_EQUALS(true, result);
|
ASSERT_EQUALS(true, result1);
|
||||||
ASSERT_EQUALS("p", vartok->str());
|
ASSERT_EQUALS("p", vartok->str());
|
||||||
ASSERT_EQUALS("int", typetok->str());
|
ASSERT_EQUALS("int", typetok->str());
|
||||||
Variable v(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
Variable v1(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
ASSERT(false == v.isArray());
|
ASSERT(false == v1.isArray());
|
||||||
ASSERT(true == v.isPointer());
|
ASSERT(true == v1.isPointer());
|
||||||
ASSERT(false == v.isReference());
|
ASSERT(false == v1.isReference());
|
||||||
|
|
||||||
|
reset();
|
||||||
|
givenACodeSampleToTokenize constpointer("const int* p;");
|
||||||
|
Variable v2(constpointer.tokens()->tokAt(3), constpointer.tokens()->next(), constpointer.tokens()->tokAt(2), 0, Public, 0, 0);
|
||||||
|
ASSERT(false == v2.isArray());
|
||||||
|
ASSERT(true == v2.isPointer());
|
||||||
|
ASSERT(false == v2.isConst());
|
||||||
|
ASSERT(false == v2.isReference());
|
||||||
|
|
||||||
|
reset();
|
||||||
|
givenACodeSampleToTokenize pointerconst("int* const p;");
|
||||||
|
bool result2 = si.isVariableDeclaration(pointerconst.tokens(), vartok, typetok);
|
||||||
|
ASSERT_EQUALS(true, result2);
|
||||||
|
ASSERT_EQUALS("p", vartok->str());
|
||||||
|
ASSERT_EQUALS("int", typetok->str());
|
||||||
|
Variable v3(vartok, typetok, vartok->previous(), 0, Public, 0, 0);
|
||||||
|
ASSERT(false == v3.isArray());
|
||||||
|
ASSERT(true == v3.isPointer());
|
||||||
|
ASSERT(true == v3.isConst());
|
||||||
|
ASSERT(false == v3.isReference());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_isVariableDeclarationDoesNotIdentifyConstness() {
|
void test_isVariableDeclarationDoesNotIdentifyConstness() {
|
||||||
|
|
Loading…
Reference in New Issue