diff --git a/lib/preprocessor.h b/lib/preprocessor.h index ad08b6bcc..ee0e5f24c 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -33,8 +33,8 @@ class Settings; /** * @brief A preprocessor directive - * Each preprocessor directive (#include, #define, #undef,#if, #ifdef, - * #else, #endif) will be recorded as an instance of this class. + * Each preprocessor directive (\#include, \#define, \#undef, \#if, \#ifdef, \#else, \#endif) + * will be recorded as an instance of this class. * * file and linenr denote the location where where the directive is defined. * diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index ddbd7924e..c084c8961 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1372,25 +1372,39 @@ bool SymbolDatabase::isFunction(const Token *tok, const Scope* outerScope, const return false; } +void SymbolDatabase::validateExecutableScopes() const +{ + const std::size_t functions = functionScopes.size(); + for (std::size_t i = 0; i < functions; ++i) { + const Scope* const scope = functionScopes[i]; + const Function* const function = scope->function; + if (scope->isExecutable() && !function) { + const std::list callstack(1, scope->classDef); + const std::string msg = std::string("Executable scope '") + scope->classDef->str() + "' with unknown function."; + const ErrorLogger::ErrorMessage errmsg(callstack, &_tokenizer->list, Severity::debug, + "symbolDatabaseWarning", + msg, + false); + _errorLogger->reportErr(errmsg); + } + } +} + +void SymbolDatabase::validateVariables() const +{ + for (std::vector::const_iterator iter = _variableList.begin(); iter!=_variableList.end(); ++iter) { + if (*iter && !(*iter)->scope()) { + throw InternalError((*iter)->nameToken(), "Analysis failed (variable without scope). If the code is valid then please report this failure.", InternalError::INTERNAL); + } + } +} + void SymbolDatabase::validate() const { if (_settings->debugwarnings) { - const std::size_t functions = functionScopes.size(); - for (std::size_t i = 0; i < functions; ++i) { - const Scope* scope = functionScopes[i]; - const Function* function = scope->function; - if (scope->isExecutable() && !function) { - const std::list callstack(1, scope->classDef); - const std::string msg = std::string("Executable scope '") + scope->classDef->str() + "' with unknown function."; - const ErrorLogger::ErrorMessage errmsg(callstack, &_tokenizer->list, Severity::debug, - "symbolDatabaseWarning", - msg, - false); - _errorLogger->reportErr(errmsg); - } - - } + validateExecutableScopes(); } + //validateVariables(); } bool Variable::isPointerArray() const diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index 9eea44b8f..b737290df 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -1026,6 +1026,12 @@ public: */ void validate() const; + void validateExecutableScopes() const; + /** + * @brief Check variable list, e.g. variables w/o scope + */ + void validateVariables() const; + /** Set valuetype in provided tokenlist */ static void setValueTypeInTokenList(Token *tokens, bool cpp, char defaultSignedness);