Support syntax error feedback in parser.

Now, parser correctly finishes parse procedure if syntax of source code is incorrect (syntax correctness is indicated using return value):
 - parser-internal memory management is performed using jsp_mm_alloc / jsp_mm_free;
 - upon detection of incorrect syntax, all parser-allocated memory regions are deallocated using jsp_mm_free_all and parse finishes with corresponding return value.

JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
Ruben Ayrapetyan
2015-06-19 00:11:31 +03:00
parent 85f12de139
commit a4e54e736e
46 changed files with 227 additions and 173 deletions
+20 -14
View File
@@ -71,18 +71,19 @@ main (int __attr_unused___ argc,
{
TEST_INIT ();
char program[] = "a=1;var a;";
bool is_ok;
const opcode_t *opcodes_p;
bool is_syntax_correct;
mem_init ();
// #1
char program1[] = "a=1;var a;";
serializer_init ();
parser_set_show_opcodes (true);
is_syntax_correct = parser_parse_script (program, strlen (program), &opcodes_p);
is_syntax_correct = parser_parse_script (program1, strlen (program1), &opcodes_p);
JERRY_ASSERT (is_syntax_correct);
JERRY_ASSERT (is_syntax_correct && opcodes_p != NULL);
opcode_t opcodes[] =
{
@@ -97,17 +98,22 @@ main (int __attr_unused___ argc,
getop_exitval (0) // exit 0;
};
if (!opcodes_equal (opcodes_p, opcodes, 5))
{
is_ok = false;
}
else
{
is_ok = true;
}
JERRY_ASSERT (opcodes_equal (opcodes_p, opcodes, 5));
serializer_free ();
// #2
char program2[] = "var var;";
serializer_init ();
parser_set_show_opcodes (true);
is_syntax_correct = parser_parse_script (program2, strlen (program2), &opcodes_p);
JERRY_ASSERT (!is_syntax_correct && opcodes_p == NULL);
serializer_free ();
mem_finalize (false);
return (is_ok ? 0 : 1);
return 0;
} /* main */