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:
parent
3274a00b82
commit
5f36c7c914
|
@ -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 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
|
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;
|
bool unknown = false;
|
||||||
|
|
||||||
std::list<Variable>::const_iterator var;
|
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->isClass()) {
|
||||||
if (var->type()) {
|
if (var->type()) {
|
||||||
// does this type need initialization?
|
// does this type need initialization?
|
||||||
|
@ -959,12 +967,10 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
|
||||||
needInitialization = true;
|
needInitialization = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!unknown) {
|
|
||||||
if (needInitialization)
|
if (needInitialization)
|
||||||
scope->definedType->needInitialization = Type::True;
|
scope->definedType->needInitialization = Type::True;
|
||||||
else
|
else if (!unknown)
|
||||||
scope->definedType->needInitialization = Type::False;
|
scope->definedType->needInitialization = Type::False;
|
||||||
}
|
|
||||||
|
|
||||||
if (scope->definedType->needInitialization == Type::Unknown)
|
if (scope->definedType->needInitialization == Type::Unknown)
|
||||||
unknowns++;
|
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.");
|
debugMessage(scope->classDef, "SymbolDatabase::SymbolDatabase couldn't resolve all user defined types.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// create variable symbol table
|
// create variable symbol table
|
||||||
_variableList.resize(_tokenizer->varIdCount() + 1);
|
_variableList.resize(_tokenizer->varIdCount() + 1);
|
||||||
|
|
Loading…
Reference in New Issue