Fix ticket #294 (### Error: Invalid number of character ()
http://apps.sourceforge.net/trac/cppcheck/ticket/294
This commit is contained in:
parent
e9eba16053
commit
63da926ed2
|
@ -599,7 +599,7 @@ public:
|
||||||
{
|
{
|
||||||
// Tokenize the macro to make it easier to handle
|
// Tokenize the macro to make it easier to handle
|
||||||
std::istringstream istr(macro.c_str());
|
std::istringstream istr(macro.c_str());
|
||||||
tokenizer.tokenize(istr, "");
|
tokenizer.createTokens(istr);
|
||||||
|
|
||||||
// macro name..
|
// macro name..
|
||||||
if (tokens() && tokens()->isName())
|
if (tokens() && tokens()->isName())
|
||||||
|
|
|
@ -153,11 +153,8 @@ void Tokenizer::InsertTokens(Token *dest, Token *src, unsigned int n)
|
||||||
// Tokenize - tokenizes a given file.
|
// 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
|
// line number in parsed code
|
||||||
unsigned int lineno = 1;
|
unsigned int lineno = 1;
|
||||||
|
|
||||||
|
@ -336,6 +333,15 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
|
||||||
}
|
}
|
||||||
addtoken(CurrentToken.c_str(), lineno, FileIndex);
|
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())
|
if (!createLinks())
|
||||||
{
|
{
|
||||||
// Source has syntax errors, can't proceed
|
// Source has syntax errors, can't proceed
|
||||||
|
|
|
@ -49,6 +49,12 @@ public:
|
||||||
*/
|
*/
|
||||||
bool tokenize(std::istream &code, const char FileName[]);
|
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 */
|
/** Set variable id */
|
||||||
void setVarId();
|
void setVarId();
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,7 @@ private:
|
||||||
TEST_CASE(missing_doublequote);
|
TEST_CASE(missing_doublequote);
|
||||||
|
|
||||||
TEST_CASE(unicode1);
|
TEST_CASE(unicode1);
|
||||||
|
TEST_CASE(define_part_of_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -888,6 +889,26 @@ private:
|
||||||
std::istringstream istr(filedata);
|
std::istringstream istr(filedata);
|
||||||
ASSERT_THROW(Preprocessor::read(istr), std::runtime_error);
|
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)
|
REGISTER_TEST(TestPreprocessor)
|
||||||
|
|
Loading…
Reference in New Issue