| 963 | } |
| 964 | |
| 965 | void SymbolDatabase::createSymbolDatabaseNeedInitialization() |
| 966 | { |
| 967 | if (mTokenizer.isC()) { |
| 968 | // For C code it is easy, as there are no constructors and no default values |
| 969 | for (const Scope& scope : scopeList) { |
| 970 | if (scope.definedType) |
| 971 | scope.definedType->needInitialization = Type::NeedInitialization::True; |
| 972 | } |
| 973 | } else { |
| 974 | // For C++, it is more difficult: Determine if user defined type needs initialization... |
| 975 | unsigned int unknowns = 0; // stop checking when there are no unknowns |
| 976 | unsigned int retry = 0; // bail if we don't resolve all the variable types for some reason |
| 977 | |
| 978 | do { |
| 979 | unknowns = 0; |
| 980 | |
| 981 | for (Scope& scope : scopeList) { |
| 982 | if (!scope.isClassOrStructOrUnion()) |
| 983 | continue; |
| 984 | if (scope.classDef && Token::simpleMatch(scope.classDef->previous(), ">")) // skip uninstantiated template |
| 985 | continue; |
| 986 | |
| 987 | if (!scope.definedType) { |
| 988 | mBlankTypes.emplace_back(); |
| 989 | scope.definedType = &mBlankTypes.back(); |
| 990 | } |
| 991 | |
| 992 | if (scope.isClassOrStruct() && scope.definedType->needInitialization == Type::NeedInitialization::Unknown) { |
| 993 | // check for default constructor |
| 994 | bool hasDefaultConstructor = false; |
| 995 | |
| 996 | for (const Function& func : scope.functionList) { |
| 997 | if (func.type == FunctionType::eConstructor) { |
| 998 | // check for no arguments: func ( ) |
| 999 | if (func.argCount() == 0) { |
| 1000 | hasDefaultConstructor = true; |
| 1001 | break; |
| 1002 | } |
| 1003 | |
| 1004 | /** check for arguments with default values */ |
| 1005 | if (func.argCount() == func.initializedArgCount()) { |
| 1006 | hasDefaultConstructor = true; |
| 1007 | break; |
| 1008 | } |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | // User defined types with user defined default constructor doesn't need initialization. |
| 1013 | // We assume the default constructor initializes everything. |
| 1014 | // Another check will figure out if the constructor actually initializes everything. |
| 1015 | if (hasDefaultConstructor) |
| 1016 | scope.definedType->needInitialization = Type::NeedInitialization::False; |
| 1017 | |
| 1018 | // check each member variable to see if it needs initialization |
| 1019 | else { |
| 1020 | bool needInitialization = false; |
| 1021 | bool unknown = false; |
| 1022 |
nothing calls this directly
no test coverage detected