Improved detection of Type::needInitialization:

- Implement shortcut for C code - all types need initialization there
- Break out of loop faster if we encounter a type that needs initialization (it is sufficient if one member needs initialization)
This commit is contained in:
PKEuS 2015-01-21 10:34:58 +01:00
parent 3274a00b82
commit 5f36c7c914
1 changed files with 86 additions and 79 deletions

View File

@ -897,7 +897,15 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
}
}
// determine if user defined type needs initialization
if (tokenizer->isC()) {
// For C code it is easy, as there are no constructors and no default values
for (std::list<Scope>::iterator it = scopeList.begin(); it != scopeList.end(); ++it) {
scope = &(*it);
if (scope->definedType)
scope->definedType->needInitialization = Type::True;
}
} else {
// For C++, it is more difficult: Determine if user defined type needs initialization...
unsigned int unknowns = 0; // stop checking when there are no unknowns
unsigned int retry = 0; // bail if we don't resolve all the variable types for some reason
@ -946,7 +954,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
bool unknown = false;
std::list<Variable>::const_iterator var;
for (var = scope->varlist.begin(); var != scope->varlist.end(); ++var) {
for (var = scope->varlist.begin(); var != scope->varlist.end() && !needInitialization; ++var) {
if (var->isClass()) {
if (var->type()) {
// does this type need initialization?
@ -959,12 +967,10 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
needInitialization = true;
}
if (!unknown) {
if (needInitialization)
scope->definedType->needInitialization = Type::True;
else
else if (!unknown)
scope->definedType->needInitialization = Type::False;
}
if (scope->definedType->needInitialization == Type::Unknown)
unknowns++;
@ -985,6 +991,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
debugMessage(scope->classDef, "SymbolDatabase::SymbolDatabase couldn't resolve all user defined types.");
}
}
}
// create variable symbol table
_variableList.resize(_tokenizer->varIdCount() + 1);