Tokenizer: simplify NULL to 0 in the normal token list
This commit is contained in:
parent
a7835c4054
commit
1b3a5ed0be
|
@ -2029,6 +2029,22 @@ bool Tokenizer::tokenize(std::istream &code,
|
|||
}
|
||||
}
|
||||
|
||||
// Replace NULL with 0..
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
if (tok->str() == "NULL" || tok->str() == "'\\0'" || tok->str() == "'\\x0'")
|
||||
{
|
||||
tok->str("0");
|
||||
}
|
||||
else if (tok->isNumber() &&
|
||||
MathLib::isInt(tok->str()) &&
|
||||
MathLib::toLongNumber(tok->str()) == 0)
|
||||
{
|
||||
tok->str("0");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// remove inline SQL (Oracle PRO*C). Ticket: #1959
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
|
@ -2422,6 +2438,8 @@ bool Tokenizer::tokenize(std::istream &code,
|
|||
// Change initialisation of variable to assignment
|
||||
simplifyInitVar();
|
||||
|
||||
|
||||
|
||||
if (!preprocessorCondition)
|
||||
{
|
||||
setVarId();
|
||||
|
@ -3987,22 +4005,6 @@ bool Tokenizer::simplifyTokenList()
|
|||
tok->deleteNext();
|
||||
}
|
||||
|
||||
|
||||
// Replace NULL with 0..
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
if (tok->str() == "NULL" || tok->str() == "'\\0'" || tok->str() == "'\\x0'")
|
||||
{
|
||||
tok->str("0");
|
||||
}
|
||||
else if (tok->isNumber() &&
|
||||
MathLib::isInt(tok->str()) &&
|
||||
MathLib::toLongNumber(tok->str()) == 0)
|
||||
{
|
||||
tok->str("0");
|
||||
}
|
||||
}
|
||||
|
||||
// simplify references
|
||||
simplifyReference();
|
||||
|
||||
|
|
|
@ -3776,19 +3776,19 @@ private:
|
|||
// ticket #346
|
||||
|
||||
const char code1[] = "void *p = NULL;";
|
||||
const char res1[] = "void * p ; p = NULL ;";
|
||||
const char res1[] = "void * p ; p = 0 ;";
|
||||
ASSERT_EQUALS(res1, tokenizeAndStringify(code1));
|
||||
|
||||
const char code2[] = "const void *p = NULL;";
|
||||
const char res2[] = "const void * p ; p = NULL ;";
|
||||
const char res2[] = "const void * p ; p = 0 ;";
|
||||
ASSERT_EQUALS(res2, tokenizeAndStringify(code2));
|
||||
|
||||
const char code3[] = "void * const p = NULL;";
|
||||
const char res3[] = "void * const p ; p = NULL ;";
|
||||
const char res3[] = "void * const p ; p = 0 ;";
|
||||
ASSERT_EQUALS(res3, tokenizeAndStringify(code3));
|
||||
|
||||
const char code4[] = "const void * const p = NULL;";
|
||||
const char res4[] = "const void * const p ; p = NULL ;";
|
||||
const char res4[] = "const void * const p ; p = 0 ;";
|
||||
ASSERT_EQUALS(res4, tokenizeAndStringify(code4));
|
||||
}
|
||||
|
||||
|
@ -3909,7 +3909,7 @@ private:
|
|||
{
|
||||
// ticket #696
|
||||
const char code[] = "char a[10]={'\\0'}, b[10]={'\\0'};";
|
||||
const char res[] = "char a [ 10 ] = { '\\0' } ; char b [ 10 ] = { '\\0' } ;";
|
||||
const char res[] = "char a [ 10 ] = { 0 } ; char b [ 10 ] = { 0 } ;";
|
||||
|
||||
ASSERT_EQUALS(res, tokenizeAndStringify(code));
|
||||
}
|
||||
|
@ -3917,7 +3917,7 @@ private:
|
|||
void vardecl9()
|
||||
{
|
||||
const char code[] = "char a[2] = {'A', '\\0'}, b[2] = {'B', '\\0'};";
|
||||
const char res[] = "char a [ 2 ] = { 'A' , '\\0' } ; char b [ 2 ] = { 'B' , '\\0' } ;";
|
||||
const char res[] = "char a [ 2 ] = { 'A' , 0 } ; char b [ 2 ] = { 'B' , 0 } ;";
|
||||
|
||||
ASSERT_EQUALS(res, tokenizeAndStringify(code));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue