From 17008879ac59bf715d8e936f4fcae6e760ded7bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 13 Jul 2009 19:11:31 +0200 Subject: [PATCH] minor refactoring: header cleanup. use forward declarations instead of includes --- src/check.h | 1 + src/checkheaders.cpp | 1 + src/checkunusedfunctions.cpp | 1 + src/cppcheck.cpp | 2 +- src/tokenize.cpp | 14 ++++++++------ src/tokenize.h | 16 ++++++++-------- test/testpreprocessor.cpp | 1 + test/testsimplifytokens.cpp | 1 + test/teststl.cpp | 3 +-- test/testtokenize.cpp | 11 +++++------ 10 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/check.h b/src/check.h index 38e016c4f..84233583e 100644 --- a/src/check.h +++ b/src/check.h @@ -19,6 +19,7 @@ #ifndef checkH #define checkH +#include "token.h" #include "tokenize.h" #include "settings.h" #include "errorlogger.h" diff --git a/src/checkheaders.cpp b/src/checkheaders.cpp index 193b07387..23b61438f 100644 --- a/src/checkheaders.cpp +++ b/src/checkheaders.cpp @@ -21,6 +21,7 @@ #include "checkheaders.h" #include "tokenize.h" #include "filelister.h" +#include "token.h" #include #include diff --git a/src/checkunusedfunctions.cpp b/src/checkunusedfunctions.cpp index 9bd9265bb..16fe2f26f 100644 --- a/src/checkunusedfunctions.cpp +++ b/src/checkunusedfunctions.cpp @@ -20,6 +20,7 @@ //--------------------------------------------------------------------------- #include "checkunusedfunctions.h" #include "tokenize.h" +#include "token.h" //--------------------------------------------------------------------------- diff --git a/src/cppcheck.cpp b/src/cppcheck.cpp index 3ae9f726f..ed4033ced 100644 --- a/src/cppcheck.cpp +++ b/src/cppcheck.cpp @@ -411,7 +411,7 @@ unsigned int CppCheck::check() void CppCheck::checkFile(const std::string &code, const char FileName[]) { - Tokenizer _tokenizer(_settings, this); + Tokenizer _tokenizer(&_settings, this); // Tokenize the file { diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 85e305a70..8fecff96d 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -19,8 +19,11 @@ //--------------------------------------------------------------------------- #include "tokenize.h" +#include "token.h" #include "filelister.h" #include "mathlib.h" +#include "settings.h" +#include "errorlogger.h" #include #include @@ -35,18 +38,17 @@ //--------------------------------------------------------------------------- Tokenizer::Tokenizer() + : _settings(0), _errorLogger(0) { _tokens = 0; _tokensBack = 0; - _errorLogger = 0; } -Tokenizer::Tokenizer(const Settings &settings, ErrorLogger *errorLogger) +Tokenizer::Tokenizer(const Settings *settings, ErrorLogger *errorLogger) + : _settings(settings), _errorLogger(errorLogger) { _tokens = 0; _tokensBack = 0; - _settings = settings; - _errorLogger = errorLogger; } Tokenizer::~Tokenizer() @@ -1496,7 +1498,7 @@ void Tokenizer::simplifyTokenList() simplifyComma(); createLinks(); - if (_settings._debug) + if (_settings && _settings->_debug) { _tokens->printOut(); } @@ -2988,7 +2990,7 @@ const Token * Tokenizer::findClassFunction(const Token *tok, const char classnam void Tokenizer::syntaxError(const Token *tok, char c) { - if (_settings._debug) + if (_settings && _settings->_debug) { _tokens->printOut(); } diff --git a/src/tokenize.h b/src/tokenize.h index 8dc2f7360..9f3707063 100644 --- a/src/tokenize.h +++ b/src/tokenize.h @@ -25,9 +25,10 @@ #include #include #include -#include "settings.h" -#include "errorlogger.h" -#include "token.h" + +class Token; +class ErrorLogger; +class Settings; class Tokenizer { @@ -37,7 +38,7 @@ private: public: Tokenizer(); - Tokenizer(const Settings &settings, ErrorLogger *errorLogger); + Tokenizer(const Settings * settings, ErrorLogger *errorLogger); ~Tokenizer(); /** @@ -265,12 +266,11 @@ private: void syntaxError(const Token *tok, char c); - Token *_tokensBack; + Token *_tokens, *_tokensBack; std::map _typeSize; std::vector _files; - Token *_tokens; - Settings _settings; - ErrorLogger *_errorLogger; + const Settings * const _settings; + ErrorLogger * const _errorLogger; }; //--------------------------------------------------------------------------- diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index e6611f014..2fae104c6 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -24,6 +24,7 @@ #include "testsuite.h" #include "../src/preprocessor.h" #include "../src/tokenize.h" +#include "../src/token.h" #include #include #include diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 106117270..a3a04e170 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -20,6 +20,7 @@ #include "testsuite.h" #include "../src/tokenize.h" +#include "../src/token.h" #include extern std::ostringstream errout; diff --git a/test/teststl.cpp b/test/teststl.cpp index bb1c65848..14546788c 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -363,8 +363,7 @@ private: " for ( \n" "}\n"; - Settings s; - Tokenizer tokenizer(s, this); + Tokenizer tokenizer(0, this); std::istringstream istr(src); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid number of character ((). Can't process file.\n", errout.str()); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index e0aceaab2..33a01bc6b 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -24,6 +24,7 @@ #include #include "testsuite.h" #include "../src/tokenize.h" +#include "../src/token.h" extern std::ostringstream errout; class TestTokenizer : public TestFixture @@ -2134,12 +2135,10 @@ private: void syntax_error() { - - Settings s; { errout.str(""); const char code[] = "void f() {}"; - Tokenizer tokenizer(s, this); + Tokenizer tokenizer(0, this); std::istringstream istr(code); ASSERT_EQUALS(true, tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS("", errout.str()); @@ -2148,7 +2147,7 @@ private: { errout.str(""); const char code[] = "void f() {{}"; - Tokenizer tokenizer(s, this); + Tokenizer tokenizer(0, this); std::istringstream istr(code); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid number of character ({). Can't process file.\n", errout.str()); @@ -2157,7 +2156,7 @@ private: { errout.str(""); const char code[] = "void f()) {}"; - Tokenizer tokenizer(s, this); + Tokenizer tokenizer(0, this); std::istringstream istr(code); ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp")); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid number of character ((). Can't process file.\n", errout.str()); @@ -2166,7 +2165,7 @@ private: { errout.str(""); const char code[] = "namespace extract{\nB(weighted_moment)\n}\nusing extract::weighted_moment;\n"; - Tokenizer tokenizer(s, this); + Tokenizer tokenizer(0, this); std::istringstream istr(code); ASSERT_EQUALS(true, tokenizer.tokenize(istr, "test.cpp")); tokenizer.simplifyTokenList();