Tokenizer: If syntax errors are found then don't return a token list. Ticket: #1961
This commit is contained in:
parent
6c8287913c
commit
ca9cdf5bf5
|
@ -1826,7 +1826,11 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[], const std::s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (level > 0)
|
if (level > 0)
|
||||||
|
{
|
||||||
syntaxError(tok);
|
syntaxError(tok);
|
||||||
|
deallocateTokens();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -837,10 +837,10 @@ private:
|
||||||
{
|
{
|
||||||
const char code[] =
|
const char code[] =
|
||||||
"const char * names[2];"
|
"const char * names[2];"
|
||||||
"for (int i = 0; i < sizeof(names[0]); i++)"
|
"for (int i = 0; i != sizeof(names[0]); i++)"
|
||||||
"{}";
|
"{}";
|
||||||
std::ostringstream expected;
|
std::ostringstream expected;
|
||||||
expected << "const char * names [ 2 ] ; for ( int i = 0 ; i < " << sizeofFromTokenizer("*") << " ; i ++ ) { }";
|
expected << "const char * names [ 2 ] ; for ( int i = 0 ; i != " << sizeofFromTokenizer("*") << " ; i ++ ) { }";
|
||||||
ASSERT_EQUALS(expected.str(), sizeof_(code));
|
ASSERT_EQUALS(expected.str(), sizeof_(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -679,12 +679,12 @@ private:
|
||||||
{
|
{
|
||||||
// ticket #990
|
// ticket #990
|
||||||
const char code[] =
|
const char code[] =
|
||||||
"{"
|
"void f() {"
|
||||||
" for (int k=0; k<VectorSize; k++)"
|
" for (int k=0; k<VectorSize; k++)"
|
||||||
" LOG_OUT(ID_Vector[k])"
|
" LOG_OUT(ID_Vector[k])"
|
||||||
"}";
|
"}";
|
||||||
const char expected[] =
|
const char expected[] =
|
||||||
"{ "
|
"void f ( ) { "
|
||||||
"for ( int k = 0 ; k < VectorSize ; k ++ ) { "
|
"for ( int k = 0 ; k < VectorSize ; k ++ ) { "
|
||||||
"LOG_OUT ( ID_Vector [ k ] ) "
|
"LOG_OUT ( ID_Vector [ k ] ) "
|
||||||
"} "
|
"} "
|
||||||
|
@ -3518,12 +3518,16 @@ private:
|
||||||
void vardecl7()
|
void vardecl7()
|
||||||
{
|
{
|
||||||
// ticket #603
|
// ticket #603
|
||||||
const char code[] = "for (int c = 0; c < 0; ++c) {}\n"
|
const char code[] = "void f() {\n"
|
||||||
"int t;\n"
|
" for (int c = 0; c < 0; ++c) {}\n"
|
||||||
"D(3 > t, \"T\");";
|
" int t;\n"
|
||||||
const char res[] = "for ( int c = 0 ; c < 0 ; ++ c ) { }\n"
|
" D(3 > t, \"T\");\n"
|
||||||
|
"}";
|
||||||
|
const char res[] = "void f ( ) {\n"
|
||||||
|
"for ( int c = 0 ; c < 0 ; ++ c ) { }\n"
|
||||||
"int t ;\n"
|
"int t ;\n"
|
||||||
"D ( 3 > t , \"T\" ) ;";
|
"D ( 3 > t , \"T\" ) ;\n"
|
||||||
|
"}";
|
||||||
|
|
||||||
ASSERT_EQUALS(res, tokenizeAndStringify(code));
|
ASSERT_EQUALS(res, tokenizeAndStringify(code));
|
||||||
}
|
}
|
||||||
|
@ -3740,8 +3744,8 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const char code1[] = "for (signed i=0; i<10; i++)";
|
const char code1[] = "void f() { for (signed i=0; i<10; i++) {} }";
|
||||||
const char code2[] = "for ( signed int i = 0 ; i < 10 ; i ++ )";
|
const char code2[] = "void f ( ) { for ( signed int i = 0 ; i < 10 ; i ++ ) { } }";
|
||||||
ASSERT_EQUALS(code2, tokenizeAndStringify(code1));
|
ASSERT_EQUALS(code2, tokenizeAndStringify(code1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3773,8 +3777,8 @@ private:
|
||||||
|
|
||||||
// insert "int" after "unsigned"..
|
// insert "int" after "unsigned"..
|
||||||
{
|
{
|
||||||
const char code1[] = "for (unsigned i=0; i<10; i++)";
|
const char code1[] = "void f() { for (unsigned i=0; i<10; i++) {} }";
|
||||||
const char code2[] = "for ( unsigned int i = 0 ; i < 10 ; i ++ )";
|
const char code2[] = "void f ( ) { for ( unsigned int i = 0 ; i < 10 ; i ++ ) { } }";
|
||||||
ASSERT_EQUALS(code2, tokenizeAndStringify(code1));
|
ASSERT_EQUALS(code2, tokenizeAndStringify(code1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue