Remove parser_init / parser_free interfaces (corresponding actions are now performed in parser_parse_program); introduce boolean return value in parser invocation interfaces that would indicate whether SyntaxError was raised during parse.

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:19 +03:00
parent 2bf25f10eb
commit 4e563932f1
8 changed files with 160 additions and 155 deletions
+59 -54
View File
@@ -2878,25 +2878,44 @@ parse_source_element_list (bool is_global) /**< flag indicating if we are parsin
* program
* : LT!* source_element_list LT!* EOF!
* ;
*
* @return true - if parse finished successfully (no SyntaxError was raised);
* false - otherwise.
*/
static void
parser_parse_program (const char *source, /**< source code buffer */
static bool
parser_parse_program (const char *source_p, /**< source code buffer */
size_t source_size, /**< source code size in bytes */
bool in_new_function) /**< flag indicating if we are parsing body of a function */
bool in_function, /**< flag indicating if we are parsing body of a function */
bool in_eval, /**< flag indicating if we are parsing body of eval code */
const opcode_t **out_opcodes_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
{
lexer_init_source (source, source_size);
JERRY_ASSERT (out_opcodes_p != NULL);
inside_function = in_function;
inside_eval = in_eval;
lexer_init (parser_show_opcodes);
lexer_init_source (source_p, source_size);
serializer_set_show_opcodes (parser_show_opcodes);
dumper_init ();
syntax_init ();
STACK_INIT (scopes);
STACK_PUSH (scopes, scopes_tree_init (NULL));
serializer_set_scope (STACK_TOP (scopes));
lexer_set_strict_mode (scopes_tree_strict_mode (STACK_TOP (scopes)));
jsp_label_init ();
skip_newlines ();
parse_source_element_list (true);
skip_newlines ();
JERRY_ASSERT (token_is (TOK_EOF));
if (in_new_function)
if (in_function)
{
dump_ret ();
}
@@ -2909,41 +2928,50 @@ parser_parse_program (const char *source, /**< source code buffer */
dump_exit ();
}
serializer_dump_literals ();
serializer_merge_scopes_into_bytecode ();
serializer_set_scope (NULL);
jsp_label_finalize ();
syntax_free ();
lexer_free ();
*out_opcodes_p = serializer_merge_scopes_into_bytecode ();
dumper_free ();
serializer_set_scope (NULL);
scopes_tree_free (STACK_TOP (scopes));
STACK_DROP (scopes, 1);
STACK_FREE (scopes);
return true;
} /* parser_parse_program */
/**
* Parse source script
*
* @return true - if parse finished successfully (no SyntaxError were raised);
* false - otherwise.
*/
void
bool
parser_parse_script (const char *source, /**< source script */
size_t source_size) /**< source script size it bytes */
size_t source_size, /**< source script size it bytes */
const opcode_t **opcodes_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
{
inside_eval = false;
inside_function = false;
parser_parse_program (source, source_size, false);
return parser_parse_program (source, source_size, false, false, opcodes_p);
} /* parser_parse_script */
/**
* Parse string passed to eval() call
*
* @return true if parse succeeds
* false otherwise
* @return true - if parse finished successfully (no SyntaxError were raised);
* false - otherwise.
*/
bool parser_parse_eval (const char *source, /**< string passed to eval() */
size_t source_size) /**< string size in bytes */
bool
parser_parse_eval (const char *source, /**< string passed to eval() */
size_t source_size, /**< string size in bytes */
const opcode_t **opcodes_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
{
TODO (implement syntax error processing);
inside_eval = true;
inside_function = false;
parser_parse_program (source, source_size, false);
return true;
return parser_parse_program (source, source_size, false, true, opcodes_p);
} /* parser_parse_eval */
/**
@@ -2952,14 +2980,16 @@ bool parser_parse_eval (const char *source, /**< string passed to eval() */
* NOTE: Array of arguments should contain at least one element.
* In case of new Function() call without parameters, empty string should be passed as argument to this
* function.
*
* @return true - if parse finished successfully (no SyntaxError were raised);
* false - otherwise.
*/
void
bool
parser_parse_new_function (const char **params, /**< array of arguments of new Function (p1, p2, ..., pn, body) call */
size_t params_count) /**< total number of arguments passed to new Function (...) */
size_t params_count, /**< total number of arguments passed to new Function (...) */
const opcode_t **out_opcodes_p) /**< out: generated byte-code array
* (in case there were no syntax errors) */
{
inside_eval = false;
inside_function = true;
// Process arguments
JERRY_ASSERT (params_count > 0);
for (size_t i = 0; i < params_count - 1; ++i)
@@ -2967,22 +2997,9 @@ parser_parse_new_function (const char **params, /**< array of arguments of new F
FIXME ("check parameter's name for syntax errors");
lit_find_or_create_literal_from_charset ((ecma_char_t *) params[i], (ecma_length_t) strlen (params[i]));
}
parser_parse_program (params[params_count - 1], strlen (params[params_count - 1]), true);
return parser_parse_program (params[params_count - 1], strlen (params[params_count - 1]), true, false, out_opcodes_p);
} /* parser_parse_new_function */
void
parser_init ()
{
lexer_init (parser_show_opcodes);
serializer_set_show_opcodes (parser_show_opcodes);
dumper_init ();
syntax_init ();
STACK_INIT (scopes);
jsp_label_init ();
}
/**
* Tell parser to dump bytecode
*/
@@ -2991,15 +3008,3 @@ parser_set_show_opcodes (bool show_opcodes) /**< flag indicating if to dump byte
{
parser_show_opcodes = show_opcodes;
} /* parser_set_show_opcodes */
void
parser_free (void)
{
jsp_label_finalize ();
STACK_FREE (scopes);
syntax_free ();
dumper_free ();
lexer_free ();
}