Move fatal from lexer.c to parser.c, rename it to parser_fatal, replace calls from main.c to parser_fatal with calls to jerry_Exit.
This commit is contained in:
+13
-22
@@ -17,6 +17,7 @@
|
||||
#include "globals.h"
|
||||
#include "jerry-libc.h"
|
||||
#include "lexer.h"
|
||||
#include "parser.h"
|
||||
|
||||
static token saved_token;
|
||||
static token empty_token = { .type = TOK_EMPTY, .data.none = NULL };
|
||||
@@ -131,7 +132,7 @@ get_char (size_t i)
|
||||
const size_t token_size = (size_t) (buffer - token_start);
|
||||
/* Whole buffer contains single token. */
|
||||
if (token_start == buffer_start)
|
||||
fatal (ERR_BUFFER_SIZE);
|
||||
parser_fatal (ERR_BUFFER_SIZE);
|
||||
/* Move parsed token and tail of buffer to head. */
|
||||
__memmove (buffer_start, token_start, tail_size + token_size);
|
||||
/* Adjust pointers. */
|
||||
@@ -394,7 +395,7 @@ parse_number (void)
|
||||
}
|
||||
|
||||
if (__isalpha (c) || c == '_' || c == '$')
|
||||
fatal (ERR_INT_LITERAL);
|
||||
parser_fatal (ERR_INT_LITERAL);
|
||||
|
||||
tok_length = (size_t) (buffer - token_start);
|
||||
// OK, I know that integer overflow can occur here
|
||||
@@ -417,14 +418,14 @@ parse_number (void)
|
||||
{
|
||||
c = LA (0);
|
||||
if (is_fp && c == '.')
|
||||
fatal (ERR_INT_LITERAL);
|
||||
parser_fatal (ERR_INT_LITERAL);
|
||||
if (is_exp && (c == 'e' || c == 'E'))
|
||||
fatal (ERR_INT_LITERAL);
|
||||
parser_fatal (ERR_INT_LITERAL);
|
||||
|
||||
if (c == '.')
|
||||
{
|
||||
if (__isalpha (LA (1)) || LA (1) == '_' || LA (1) == '$')
|
||||
fatal (ERR_INT_LITERAL);
|
||||
parser_fatal (ERR_INT_LITERAL);
|
||||
is_fp = true;
|
||||
consume_char ();
|
||||
continue;
|
||||
@@ -435,14 +436,14 @@ parse_number (void)
|
||||
if (LA (1) == '-' || LA (1) == '+')
|
||||
consume_char ();
|
||||
if (!__isdigit (LA (1)))
|
||||
fatal (ERR_INT_LITERAL);
|
||||
parser_fatal (ERR_INT_LITERAL);
|
||||
is_exp = true;
|
||||
consume_char ();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (__isalpha (c) || c == '_' || c == '$')
|
||||
fatal (ERR_INT_LITERAL);
|
||||
parser_fatal (ERR_INT_LITERAL);
|
||||
|
||||
if (!__isdigit (c))
|
||||
break;
|
||||
@@ -507,14 +508,14 @@ parse_string (void)
|
||||
{
|
||||
c = LA (0);
|
||||
if (c == '\0')
|
||||
fatal (ERR_UNCLOSED);
|
||||
parser_fatal (ERR_UNCLOSED);
|
||||
if (c == '\n')
|
||||
fatal (ERR_STRING);
|
||||
parser_fatal (ERR_STRING);
|
||||
if (c == '\\')
|
||||
{
|
||||
/* Only single escape character is allowed. */
|
||||
if (LA (1) == 'x' || LA (1) == 'u' || __isdigit (LA (1)))
|
||||
fatal (ERR_STRING);
|
||||
parser_fatal (ERR_STRING);
|
||||
if ((LA (1) == '\'' && !is_double_quoted)
|
||||
|| (LA (1) == '"' && is_double_quoted)
|
||||
|| LA (1) == '\n')
|
||||
@@ -630,7 +631,7 @@ replace_comment_by_newline (void)
|
||||
if (multiline && c == '\n')
|
||||
was_newlines = true;
|
||||
if (multiline && c == '\0')
|
||||
fatal (ERR_UNCLOSED);
|
||||
parser_fatal (ERR_UNCLOSED);
|
||||
consume_char ();
|
||||
}
|
||||
}
|
||||
@@ -769,7 +770,7 @@ lexer_next_token (void)
|
||||
default:
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
fatal (ERR_NON_CHAR);
|
||||
parser_fatal (ERR_NON_CHAR);
|
||||
}
|
||||
|
||||
#ifdef __HOST
|
||||
@@ -806,13 +807,3 @@ lexer_dump_buffer_state (void)
|
||||
{
|
||||
__printf ("%s\n", buffer);
|
||||
}
|
||||
|
||||
void
|
||||
fatal (int code)
|
||||
{
|
||||
__printf ("FATAL: %d\n", code);
|
||||
lexer_dump_buffer_state ();
|
||||
JERRY_UNREACHABLE ();
|
||||
__exit( -code);
|
||||
}
|
||||
|
||||
|
||||
@@ -161,6 +161,4 @@ void lexer_save_token (token);
|
||||
|
||||
void lexer_dump_buffer_state (void);
|
||||
|
||||
void fatal(int);
|
||||
|
||||
#endif
|
||||
|
||||
+19
-11
@@ -119,7 +119,7 @@ scope_must_be (unsigned int scopes)
|
||||
if (scopes & current_scopes[i].type)
|
||||
return;
|
||||
}
|
||||
fatal (ERR_PARSER);
|
||||
parser_fatal (ERR_PARSER);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -127,14 +127,14 @@ current_scope_must_be (unsigned int scopes)
|
||||
{
|
||||
if (scopes & current_scopes[scope_index - 1].type)
|
||||
return;
|
||||
fatal (ERR_PARSER);
|
||||
parser_fatal (ERR_PARSER);
|
||||
}
|
||||
|
||||
static inline void
|
||||
current_scope_must_be_global (void)
|
||||
{
|
||||
if (scope_index != 1)
|
||||
fatal (ERR_PARSER);
|
||||
parser_fatal (ERR_PARSER);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -181,7 +181,7 @@ current_token_must_be(token_type tt)
|
||||
#ifdef __HOST
|
||||
__printf ("current_token_must_be: 0x%x\n", tt);
|
||||
#endif
|
||||
fatal (ERR_PARSER);
|
||||
parser_fatal (ERR_PARSER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ next_token_must_be (token_type tt)
|
||||
#ifdef __HOST
|
||||
__printf ("next_token_must_be: 0x%x\n", tt);
|
||||
#endif
|
||||
fatal (ERR_PARSER);
|
||||
parser_fatal (ERR_PARSER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ token_after_newlines_must_be (token_type tt)
|
||||
{
|
||||
skip_newlines ();
|
||||
if (tok.type != tt)
|
||||
fatal (ERR_PARSER);
|
||||
parser_fatal (ERR_PARSER);
|
||||
}
|
||||
|
||||
static inline void
|
||||
@@ -219,7 +219,7 @@ token_after_newlines_must_be_keyword (keyword kw)
|
||||
{
|
||||
skip_newlines ();
|
||||
if (!is_keyword (kw))
|
||||
fatal (ERR_PARSER);
|
||||
parser_fatal (ERR_PARSER);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -227,7 +227,7 @@ insert_semicolon (void)
|
||||
{
|
||||
tok = lexer_next_token ();
|
||||
if (tok.type != TOK_NEWLINE && tok.type != TOK_SEMICOLON)
|
||||
fatal (ERR_PARSER);
|
||||
parser_fatal (ERR_PARSER);
|
||||
}
|
||||
|
||||
/* formal_parameter_list
|
||||
@@ -959,7 +959,7 @@ parse_for_or_for_in_statement (void)
|
||||
else if (is_keyword (KW_IN))
|
||||
goto for_in;
|
||||
else
|
||||
fatal (ERR_PARSER);
|
||||
parser_fatal (ERR_PARSER);
|
||||
}
|
||||
}
|
||||
JERRY_ASSERT (is_variable_declaration_empty(list.decls[0]));
|
||||
@@ -973,7 +973,7 @@ parse_for_or_for_in_statement (void)
|
||||
else if (is_keyword (KW_IN))
|
||||
goto for_in;
|
||||
else
|
||||
fatal (ERR_PARSER);
|
||||
parser_fatal (ERR_PARSER);
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
|
||||
@@ -1267,7 +1267,7 @@ parser_parse_statement (void)
|
||||
if (tok.type == TOK_NAME)
|
||||
{
|
||||
if (current_scopes[scope_index - 1].type == SCOPE_CASE)
|
||||
fatal (ERR_PARSER);
|
||||
parser_fatal (ERR_PARSER);
|
||||
res.data.name = tok.data.name;
|
||||
}
|
||||
else
|
||||
@@ -1382,3 +1382,11 @@ parser_init (void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
parser_fatal (jerry_Status_t code)
|
||||
{
|
||||
__printf ("FATAL: %d\n", code);
|
||||
lexer_dump_buffer_state ();
|
||||
|
||||
jerry_Exit( code);
|
||||
}
|
||||
|
||||
@@ -438,4 +438,6 @@ bool is_statement_null (statement);
|
||||
void parser_init (void);
|
||||
statement parser_parse_statement (void);
|
||||
|
||||
void parser_fatal (jerry_Status_t code);
|
||||
|
||||
#endif
|
||||
|
||||
+4
-4
@@ -108,14 +108,14 @@ main (int argc, char **argv)
|
||||
else if (file_name == NULL)
|
||||
file_name = argv[i];
|
||||
else
|
||||
fatal (ERR_SEVERAL_FILES);
|
||||
jerry_Exit (ERR_SEVERAL_FILES);
|
||||
}
|
||||
|
||||
if (file_name == NULL)
|
||||
fatal (ERR_NO_FILES);
|
||||
jerry_Exit (ERR_NO_FILES);
|
||||
|
||||
if (dump_tokens && dump_ast)
|
||||
fatal (ERR_SEVERAL_FILES);
|
||||
jerry_Exit (ERR_SEVERAL_FILES);
|
||||
|
||||
if (!dump_tokens)
|
||||
dump_ast = true;
|
||||
@@ -125,7 +125,7 @@ main (int argc, char **argv)
|
||||
|
||||
if (file == NULL)
|
||||
{
|
||||
fatal (ERR_IO);
|
||||
jerry_Exit (ERR_IO);
|
||||
}
|
||||
|
||||
lexer_set_file (file);
|
||||
|
||||
Reference in New Issue
Block a user