Symbol database: improved type handling (fix problems in previous commit). Ticket: #4952
This commit is contained in:
parent
33a948f816
commit
b777388fb8
|
@ -836,7 +836,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
if (varId)
|
if (varId)
|
||||||
_variableList[varId] = &(*var);
|
_variableList[varId] = &(*var);
|
||||||
// fix up variables without type
|
// fix up variables without type
|
||||||
if (var->isClass() && !var->type()) {
|
if (!var->type() && !var->typeStartToken()->isStandardType()) {
|
||||||
const Type *type = findType(var->typeStartToken(), scope);
|
const Type *type = findType(var->typeStartToken(), scope);
|
||||||
if (type)
|
if (type)
|
||||||
var->type(type);
|
var->type(type);
|
||||||
|
@ -854,7 +854,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
if (declarationId > 0U)
|
if (declarationId > 0U)
|
||||||
_variableList[declarationId] = &(*arg);
|
_variableList[declarationId] = &(*arg);
|
||||||
// fix up parameters without type
|
// fix up parameters without type
|
||||||
if (arg->isClass() && !arg->type()) {
|
if (!arg->type() && !arg->typeStartToken()->isStandardType()) {
|
||||||
const Type *type = findType(arg->typeStartToken(), scope);
|
const Type *type = findType(arg->typeStartToken(), scope);
|
||||||
if (type)
|
if (type)
|
||||||
arg->type(type);
|
arg->type(type);
|
||||||
|
|
|
@ -122,6 +122,20 @@ void TestFixture::assert_(const char *filename, unsigned int linenr, bool condit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestFixture::todoAssert(const char *filename, unsigned int linenr, bool condition) const
|
||||||
|
{
|
||||||
|
if (condition) {
|
||||||
|
if (gcc_style_errors) {
|
||||||
|
errmsg << filename << ':' << linenr << ": Assertion succeeded unexpectedly." << std::endl;
|
||||||
|
} else {
|
||||||
|
errmsg << "Assertion succeeded unexpectedly in " << filename << " at line " << linenr << std::endl;
|
||||||
|
}
|
||||||
|
++succeeded_todos_counter;
|
||||||
|
} else {
|
||||||
|
++todos_counter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TestFixture::assertEquals(const char *filename, unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg) const
|
void TestFixture::assertEquals(const char *filename, unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg) const
|
||||||
{
|
{
|
||||||
if (expected != actual) {
|
if (expected != actual) {
|
||||||
|
|
|
@ -46,6 +46,7 @@ protected:
|
||||||
bool runTest(const char testname[]);
|
bool runTest(const char testname[]);
|
||||||
|
|
||||||
void assert_(const char *filename, unsigned int linenr, bool condition) const;
|
void assert_(const char *filename, unsigned int linenr, bool condition) const;
|
||||||
|
void todoAssert(const char *filename, unsigned int linenr, bool condition) const;
|
||||||
|
|
||||||
void assertEquals(const char *filename, unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg = "") const;
|
void assertEquals(const char *filename, unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg = "") const;
|
||||||
void assertEquals(const char *filename, unsigned int linenr, long long expected, long long actual, const std::string &msg="") const;
|
void assertEquals(const char *filename, unsigned int linenr, long long expected, long long actual, const std::string &msg="") const;
|
||||||
|
@ -72,6 +73,7 @@ public:
|
||||||
|
|
||||||
#define TEST_CASE( NAME ) if ( runTest(#NAME) ) { currentTest = classname + "::" + #NAME; if (quiet_tests) { REDIRECT; NAME(); } else { NAME ();} }
|
#define TEST_CASE( NAME ) if ( runTest(#NAME) ) { currentTest = classname + "::" + #NAME; if (quiet_tests) { REDIRECT; NAME(); } else { NAME ();} }
|
||||||
#define ASSERT( CONDITION ) assert_(__FILE__, __LINE__, CONDITION)
|
#define ASSERT( CONDITION ) assert_(__FILE__, __LINE__, CONDITION)
|
||||||
|
#define TODO_ASSERT( CONDITION ) todoAssert(__FILE__, __LINE__, CONDITION)
|
||||||
#define ASSERT_EQUALS( EXPECTED , ACTUAL ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL)
|
#define ASSERT_EQUALS( EXPECTED , ACTUAL ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL)
|
||||||
#define ASSERT_EQUALS_DOUBLE( EXPECTED , ACTUAL ) assertEqualsDouble(__FILE__, __LINE__, EXPECTED, ACTUAL)
|
#define ASSERT_EQUALS_DOUBLE( EXPECTED , ACTUAL ) assertEqualsDouble(__FILE__, __LINE__, EXPECTED, ACTUAL)
|
||||||
#define ASSERT_EQUALS_MSG( EXPECTED , ACTUAL, MSG ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL, MSG)
|
#define ASSERT_EQUALS_MSG( EXPECTED , ACTUAL, MSG ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL, MSG)
|
||||||
|
|
|
@ -1586,29 +1586,34 @@ private:
|
||||||
void symboldatabase37() {
|
void symboldatabase37() {
|
||||||
GET_SYMBOL_DB("class Fred {\n"
|
GET_SYMBOL_DB("class Fred {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
|
" struct Wilma { };\n"
|
||||||
" struct Barney {\n"
|
" struct Barney {\n"
|
||||||
" bool operator == (const struct Barney & b) const { return true; }\n"
|
" bool operator == (const struct Barney & b) const { return true; }\n"
|
||||||
|
" bool operator == (const struct Wilma & w) const { return true; }\n"
|
||||||
" };\n"
|
" };\n"
|
||||||
" Fred(const struct Barney & b) { barney = b; }\n"
|
" Fred(const struct Barney & b) { barney = b; }\n"
|
||||||
"private:\n"
|
"private:\n"
|
||||||
" struct Barney barney;\n"
|
" struct Barney barney;\n"
|
||||||
"};\n");
|
"};\n");
|
||||||
ASSERT(db && db->typeList.size() == 2);
|
ASSERT(db && db->typeList.size() == 3);
|
||||||
ASSERT(db && db->isClassOrStruct("Fred"));
|
ASSERT(db && db->isClassOrStruct("Fred"));
|
||||||
|
ASSERT(db && db->isClassOrStruct("Wilma"));
|
||||||
ASSERT(db && db->isClassOrStruct("Barney"));
|
ASSERT(db && db->isClassOrStruct("Barney"));
|
||||||
if (!db || db->typeList.size() == 2)
|
if (!db || db->typeList.size() != 3)
|
||||||
return;
|
return;
|
||||||
std::list<Type>::const_iterator i = db->typeList.begin();
|
std::list<Type>::const_iterator i = db->typeList.begin();
|
||||||
const Type* Fred = &(*i++);
|
const Type* Fred = &(*i++);
|
||||||
|
const Type* Wilma = &(*i++);
|
||||||
const Type* Barney = &(*i++);
|
const Type* Barney = &(*i++);
|
||||||
ASSERT(Fred && Fred->classDef && Fred->classScope && Fred->enclosingScope && Fred->name() == "Fred");
|
ASSERT(Fred && Fred->classDef && Fred->classScope && Fred->enclosingScope && Fred->name() == "Fred");
|
||||||
|
ASSERT(Wilma && Wilma->classDef && Wilma->classScope && Wilma->enclosingScope && Wilma->name() == "Wilma");
|
||||||
ASSERT(Barney && Barney->classDef && Barney->classScope && Barney->enclosingScope && Barney->name() == "Barney");
|
ASSERT(Barney && Barney->classDef && Barney->classScope && Barney->enclosingScope && Barney->name() == "Barney");
|
||||||
|
ASSERT(db && db->getVariableListSize() == 5);
|
||||||
ASSERT(db && db->getVariableListSize() == 4);
|
if (!db || db->getVariableListSize() != 5)
|
||||||
if (!db || db->getVariableListSize() == 4)
|
|
||||||
return;
|
return;
|
||||||
ASSERT(db && db->getVariableFromVarId(1) && db->getVariableFromVarId(1)->type() && db->getVariableFromVarId(1)->type()->name() == "Barney");
|
ASSERT(db && db->getVariableFromVarId(1) && db->getVariableFromVarId(1)->type() && db->getVariableFromVarId(1)->type()->name() == "Barney");
|
||||||
ASSERT(db && db->getVariableFromVarId(2) && db->getVariableFromVarId(2)->type() && db->getVariableFromVarId(2)->type()->name() == "Barney");
|
TODO_ASSERT(db && db->getVariableFromVarId(2) && db->getVariableFromVarId(2)->type() && db->getVariableFromVarId(2)->type()->name() == "Wilma");
|
||||||
|
ASSERT(db && db->getVariableFromVarId(3) && db->getVariableFromVarId(3)->type() && db->getVariableFromVarId(3)->type()->name() == "Barney");
|
||||||
}
|
}
|
||||||
|
|
||||||
void isImplicitlyVirtual() {
|
void isImplicitlyVirtual() {
|
||||||
|
|
Loading…
Reference in New Issue