Fix ticket #294 (### Error: Invalid number of character ()

http://apps.sourceforge.net/trac/cppcheck/ticket/294
This commit is contained in:
Reijo Tomperi 2009-05-09 22:32:29 +03:00
parent e9eba16053
commit 63da926ed2
4 changed files with 38 additions and 5 deletions

View File

@ -599,7 +599,7 @@ public:
{
// Tokenize the macro to make it easier to handle
std::istringstream istr(macro.c_str());
tokenizer.tokenize(istr, "");
tokenizer.createTokens(istr);
// macro name..
if (tokens() && tokens()->isName())

View File

@ -153,11 +153,8 @@ void Tokenizer::InsertTokens(Token *dest, Token *src, unsigned int n)
// Tokenize - tokenizes a given file.
//---------------------------------------------------------------------------
bool Tokenizer::tokenize(std::istream &code, const char FileName[])
void Tokenizer::createTokens(std::istream &code)
{
// The "_files" vector remembers what files have been tokenized..
_files.push_back(FileLister::simplifyPath(FileName));
// line number in parsed code
unsigned int lineno = 1;
@ -336,6 +333,15 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
}
addtoken(CurrentToken.c_str(), lineno, FileIndex);
}
bool Tokenizer::tokenize(std::istream &code, const char FileName[])
{
// The "_files" vector remembers what files have been tokenized..
_files.push_back(FileLister::simplifyPath(FileName));
createTokens(code);
if (!createLinks())
{
// Source has syntax errors, can't proceed

View File

@ -49,6 +49,12 @@ public:
*/
bool tokenize(std::istream &code, const char FileName[]);
/**
* Create tokens from code.
* @param code input stream for code
*/
void createTokens(std::istream &code);
/** Set variable id */
void setVarId();

View File

@ -120,6 +120,7 @@ private:
TEST_CASE(missing_doublequote);
TEST_CASE(unicode1);
TEST_CASE(define_part_of_func);
}
@ -888,6 +889,26 @@ private:
std::istringstream istr(filedata);
ASSERT_THROW(Preprocessor::read(istr), std::runtime_error);
}
void define_part_of_func()
{
const char filedata[] = "#define A g(\n"
"void f() {\n"
" A );\n"
" }\n";
// Preprocess => actual result..
std::istringstream istr(filedata);
std::map<std::string, std::string> actual;
Preprocessor preprocessor;
preprocessor.preprocess(istr, actual, "file.c");
// Compare results..
ASSERT_EQUALS(1, static_cast<unsigned int>(actual.size()));
ASSERT_EQUALS("\nvoid f() {\ng( );\n}\n", actual[""]);
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestPreprocessor)