Fix ticket #288 (Tokenizer::syntaxError should use error logger instead of std::cout)
http://apps.sourceforge.net/trac/cppcheck/ticket/288
This commit is contained in:
parent
fede702bf5
commit
e83db8ac7b
|
@ -375,7 +375,7 @@ unsigned int CppCheck::check()
|
||||||
|
|
||||||
void CppCheck::checkFile(const std::string &code, const char FileName[])
|
void CppCheck::checkFile(const std::string &code, const char FileName[])
|
||||||
{
|
{
|
||||||
Tokenizer _tokenizer(_settings);
|
Tokenizer _tokenizer(_settings, this);
|
||||||
|
|
||||||
// Tokenize the file
|
// Tokenize the file
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,13 +39,15 @@ Tokenizer::Tokenizer()
|
||||||
{
|
{
|
||||||
_tokens = 0;
|
_tokens = 0;
|
||||||
_tokensBack = 0;
|
_tokensBack = 0;
|
||||||
|
_errorLogger = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tokenizer::Tokenizer(const Settings &settings)
|
Tokenizer::Tokenizer(const Settings &settings, ErrorLogger *errorLogger)
|
||||||
{
|
{
|
||||||
_tokens = 0;
|
_tokens = 0;
|
||||||
_tokensBack = 0;
|
_tokensBack = 0;
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
|
_errorLogger = errorLogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tokenizer::~Tokenizer()
|
Tokenizer::~Tokenizer()
|
||||||
|
@ -2668,19 +2670,23 @@ const Token * Tokenizer::FindClassFunction(const Token *tok, const char classnam
|
||||||
|
|
||||||
void Tokenizer::syntaxError(const Token *tok, char c)
|
void Tokenizer::syntaxError(const Token *tok, char c)
|
||||||
{
|
{
|
||||||
std::cout << "### Error: Invalid number of character " << c << std::endl;
|
if (!_errorLogger)
|
||||||
/*
|
{
|
||||||
|
std::cout << "### Unlogged error at Tokenizer::syntaxError" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
ErrorLogger::ErrorMessage::FileLocation loc;
|
||||||
loc.line = tok->linenr();
|
loc.line = tok->linenr();
|
||||||
loc.file = tok->fileIndex();
|
loc.file = file(tok);
|
||||||
locationList.push_back(loc);
|
locationList.push_back(loc);
|
||||||
_errorLogger->reportErr(
|
_errorLogger->reportErr(
|
||||||
ErrorLogger::ErrorMessage(locationList,
|
ErrorLogger::ErrorMessage(locationList,
|
||||||
"error",
|
"error",
|
||||||
std::string("Invalid number of character (") + c + "). Can't process file. File is either invalid or unicode, which is currently not supported.",
|
std::string("Invalid number of character (") + c + "). Can't process file.",
|
||||||
"syntaxError"));
|
"syntaxError"));
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Tokenizer();
|
Tokenizer();
|
||||||
Tokenizer(const Settings &settings);
|
Tokenizer(const Settings &settings, ErrorLogger *errorLogger);
|
||||||
~Tokenizer();
|
~Tokenizer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -222,6 +222,7 @@ private:
|
||||||
std::vector<std::string> _files;
|
std::vector<std::string> _files;
|
||||||
Token *_tokens;
|
Token *_tokens;
|
||||||
Settings _settings;
|
Settings _settings;
|
||||||
|
ErrorLogger *_errorLogger;
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
|
@ -358,14 +358,17 @@ private:
|
||||||
|
|
||||||
void invalidcode()
|
void invalidcode()
|
||||||
{
|
{
|
||||||
|
errout.str("");
|
||||||
const std::string src = "void f()\n"
|
const std::string src = "void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" for ( \n"
|
" for ( \n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
Tokenizer tokenizer;
|
Settings s;
|
||||||
|
Tokenizer tokenizer(s, this);
|
||||||
std::istringstream istr(src);
|
std::istringstream istr(src);
|
||||||
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1730,28 +1730,33 @@ private:
|
||||||
|
|
||||||
void syntax_error()
|
void syntax_error()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Settings s;
|
||||||
{
|
{
|
||||||
|
errout.str("");
|
||||||
const char code[] = "void f() {}";
|
const char code[] = "void f() {}";
|
||||||
Tokenizer tokenizer;
|
Tokenizer tokenizer(s, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
ASSERT_EQUALS(true, tokenizer.tokenize(istr, "test.cpp"));
|
ASSERT_EQUALS(true, tokenizer.tokenize(istr, "test.cpp"));
|
||||||
ASSERT_EQUALS(std::string(""), errout.str());
|
ASSERT_EQUALS(std::string(""), errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
errout.str("");
|
||||||
const char code[] = "void f() {{}";
|
const char code[] = "void f() {{}";
|
||||||
Tokenizer tokenizer;
|
Tokenizer tokenizer(s, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
|
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
|
||||||
TODO_ASSERT_EQUALS(std::string("correct error message here"), errout.str());
|
ASSERT_EQUALS(std::string("[test.cpp:1]: (error) Invalid number of character ({). Can't process file.\n"), errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
errout.str("");
|
||||||
const char code[] = "void f()) {}";
|
const char code[] = "void f()) {}";
|
||||||
Tokenizer tokenizer;
|
Tokenizer tokenizer(s, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
|
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
|
||||||
TODO_ASSERT_EQUALS(std::string("correct error message here"), errout.str());
|
ASSERT_EQUALS(std::string("[test.cpp:1]: (error) Invalid number of character ((). Can't process file.\n"), errout.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue