Fix warnings

This commit is contained in:
Ilmir Usmanov
2014-07-10 11:01:40 +04:00
parent 74a0f470d2
commit 2d4b325d24
12 changed files with 162 additions and 152 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ UNITTESTS_SRC_DIR = ./tests/unit
# Add common-io.c and sensors.c # Add common-io.c and sensors.c
SOURCES = \ SOURCES = \
$(sort \ $(sort \
$(wildcard ./src/jerry-libc.c ./src/pretty-printer.c) \ $(wildcard ./src/jerry-libc.c ./src/pretty-printer.c ./src/error.c) \
$(wildcard ./src/libperipherals/actuators.c) \ $(wildcard ./src/libperipherals/actuators.c) \
$(wildcard ./src/libjsparser/*.c) \ $(wildcard ./src/libjsparser/*.c) \
$(wildcard ./src/libecmaobjects/*.c) \ $(wildcard ./src/libecmaobjects/*.c) \
+2 -9
View File
@@ -18,16 +18,9 @@
#include "mappings.h" #include "mappings.h"
extern void lexer_dump_buffer_state (); extern void lexer_dump_buffer_state (void);
static inline void void fatal (int);
fatal (int code)
{
printf ("FATAL: %d\n", code);
lexer_dump_buffer_state ();
JERRY_UNREACHABLE ();
exit (code);
}
#define ERR_IO (-1) #define ERR_IO (-1)
#define ERR_BUFFER_SIZE (-2) #define ERR_BUFFER_SIZE (-2)
+2 -2
View File
@@ -46,7 +46,7 @@ gen_bytecode ()
} }
void void
init_int () init_int (void)
{ {
#define INIT_OP_FUNC(name) __opfuncs[ name ] = opfunc_##name ; #define INIT_OP_FUNC(name) __opfuncs[ name ] = opfunc_##name ;
JERRY_STATIC_ASSERT (sizeof (OPCODE) <= 4); JERRY_STATIC_ASSERT (sizeof (OPCODE) <= 4);
@@ -55,7 +55,7 @@ init_int ()
} }
void void
run_int () run_int (void)
{ {
init_int (); init_int ();
+1
View File
@@ -38,6 +38,7 @@ struct __int_data
}; };
void gen_bytecode (void); void gen_bytecode (void);
void init_int (void);
void run_int (void); void run_int (void);
void run_int_from_pos (struct __int_data *); void run_int_from_pos (struct __int_data *);
+35 -36
View File
@@ -102,10 +102,11 @@ static char *token_start;
#define BUFFER_SIZE 1024 #define BUFFER_SIZE 1024
static char static char
get_char (int i) get_char (size_t i)
{ {
int error; size_t error;
const int tail_size = BUFFER_SIZE - (buffer - buffer_start); JERRY_ASSERT (buffer >= buffer_start);
const size_t tail_size = BUFFER_SIZE - (size_t) (buffer - buffer_start);
JERRY_ASSERT (file); JERRY_ASSERT (file);
@@ -113,8 +114,6 @@ get_char (int i)
{ {
buffer = (char *) malloc (BUFFER_SIZE); buffer = (char *) malloc (BUFFER_SIZE);
error = fread (buffer, 1, BUFFER_SIZE, file); error = fread (buffer, 1, BUFFER_SIZE, file);
if (error < 0)
fatal (ERR_IO);
if (error == 0) if (error == 0)
return '\0'; return '\0';
if (error < BUFFER_SIZE) if (error < BUFFER_SIZE)
@@ -127,7 +126,8 @@ get_char (int i)
/* We are almost at the end of the buffer. */ /* We are almost at the end of the buffer. */
if (token_start) if (token_start)
{ {
const int token_size = buffer - token_start; JERRY_ASSERT (buffer >= token_start);
const size_t token_size = (size_t) (buffer - token_start);
/* Whole buffer contains single token. */ /* Whole buffer contains single token. */
if (token_start == buffer_start) if (token_start == buffer_start)
fatal (ERR_BUFFER_SIZE); fatal (ERR_BUFFER_SIZE);
@@ -138,8 +138,6 @@ get_char (int i)
buffer = buffer_start + token_size; buffer = buffer_start + token_size;
/* Read more characters form input file. */ /* Read more characters form input file. */
error = fread (buffer + tail_size, 1, BUFFER_SIZE - tail_size - token_size, file); error = fread (buffer + tail_size, 1, BUFFER_SIZE - tail_size - token_size, file);
if (error < 0)
fatal (ERR_IO);
if (error == 0) if (error == 0)
return '\0'; return '\0';
if (error < BUFFER_SIZE - tail_size - token_size) if (error < BUFFER_SIZE - tail_size - token_size)
@@ -151,8 +149,6 @@ get_char (int i)
memmove (buffer_start, buffer, tail_size); memmove (buffer_start, buffer, tail_size);
buffer = buffer_start; buffer = buffer_start;
error = fread (buffer + tail_size, 1, BUFFER_SIZE - tail_size, file); error = fread (buffer + tail_size, 1, BUFFER_SIZE - tail_size, file);
if (error < 0)
fatal (ERR_IO);
if (error == 0) if (error == 0)
return '\0'; return '\0';
if (error < BUFFER_SIZE - tail_size) if (error < BUFFER_SIZE - tail_size)
@@ -179,7 +175,7 @@ static const char *token_start;
if TOKEN represents a Future Reserved Word, return KW_RESERVED, if TOKEN represents a Future Reserved Word, return KW_RESERVED,
otherwise return KW_NONE. */ otherwise return KW_NONE. */
static token static token
decode_keyword () decode_keyword (void)
{ {
size_t size = sizeof (keyword_tokens) / sizeof (string_and_token); size_t size = sizeof (keyword_tokens) / sizeof (string_and_token);
size_t i; size_t i;
@@ -194,7 +190,7 @@ decode_keyword ()
} }
static token static token
convert_seen_name_to_token () convert_seen_name_to_token (void)
{ {
size_t i; size_t i;
@@ -216,25 +212,26 @@ add_to_seen_tokens (string_and_token snt)
} }
static inline void static inline void
new_token () new_token (void)
{ {
JERRY_ASSERT (buffer); JERRY_ASSERT (buffer);
token_start = buffer; token_start = buffer;
} }
static inline void static void
consume_char () consume_char (void)
{ {
JERRY_ASSERT (buffer); JERRY_ASSERT (buffer);
buffer++; buffer++;
} }
static inline const char * static inline const char *
current_token () current_token (void)
{ {
JERRY_ASSERT (buffer); JERRY_ASSERT (buffer);
JERRY_ASSERT (token_start); JERRY_ASSERT (token_start);
int length = buffer - token_start; JERRY_ASSERT (token_start > buffer);
size_t length = (size_t) (buffer - token_start);
char *res = (char *) malloc (length + 1); char *res = (char *) malloc (length + 1);
strncpy (res, token_start, length); strncpy (res, token_start, length);
res[length] = '\0'; res[length] = '\0';
@@ -278,7 +275,7 @@ current_token ()
while (0) while (0)
static token static token
parse_name () parse_name (void)
{ {
char c = LA (0); char c = LA (0);
bool every_char_islower = islower (c); bool every_char_islower = islower (c);
@@ -360,13 +357,13 @@ hex_to_int (char hex)
/* In this function we cannot use strtol function /* In this function we cannot use strtol function
since there is no octal literals in ECMAscript. */ since there is no octal literals in ECMAscript. */
static token static token
parse_number () parse_number (void)
{ {
char c = LA (0); char c = LA (0);
bool is_hex = false; bool is_hex = false;
bool is_fp = false; bool is_fp = false;
bool is_exp = false; bool is_exp = false;
int tok_length = 0; size_t tok_length = 0, i;
int res = 0; int res = 0;
JERRY_ASSERT (isdigit (c) || c == '.'); JERRY_ASSERT (isdigit (c) || c == '.');
@@ -398,9 +395,9 @@ parse_number ()
if (isalpha (c) || c == '_' || c == '$') if (isalpha (c) || c == '_' || c == '$')
fatal (ERR_INT_LITERAL); fatal (ERR_INT_LITERAL);
tok_length = buffer - token_start; tok_length = (size_t) (buffer - token_start);
// OK, I know that integer overflow can occur here // OK, I know that integer overflow can occur here
for (int i = 0; i < tok_length; i++) for (i = 0; i < tok_length; i++)
res = (res << 4) + hex_to_int (token_start[i]); res = (res << 4) + hex_to_int (token_start[i]);
token_start = NULL; token_start = NULL;
@@ -459,8 +456,8 @@ parse_number ()
return (token) { .type = TOK_FLOAT, .data.fp_num = res }; return (token) { .type = TOK_FLOAT, .data.fp_num = res };
} }
tok_length = buffer - token_start; tok_length = (size_t) (buffer - token_start);;
for (int i = 0; i < tok_length; i++) for (i = 0; i < tok_length; i++)
res = res * 10 + hex_to_int (token_start[i]); res = res * 10 + hex_to_int (token_start[i]);
token_start = NULL; token_start = NULL;
@@ -487,13 +484,14 @@ escape_char (char c)
} }
static token static token
parse_string () parse_string (void)
{ {
char c = LA (0); char c = LA (0);
bool is_double_quoted; bool is_double_quoted;
char *tok = NULL; char *tok = NULL;
char *index = NULL; char *index = NULL;
int length; const char *i;
size_t length;
token res = empty_token; token res = empty_token;
JERRY_ASSERT (c == '\'' || c == '"'); JERRY_ASSERT (c == '\'' || c == '"');
@@ -532,11 +530,11 @@ parse_string ()
consume_char (); consume_char ();
} }
length = buffer - token_start; length = (size_t) (buffer - token_start);
tok = (char *) malloc (length); tok = (char *) malloc (length);
index = tok; index = tok;
for (const char *i = token_start; i < buffer; i++) for (i = token_start; i < buffer; i++)
{ {
if (*i == '\\') if (*i == '\\')
{ {
@@ -555,7 +553,7 @@ parse_string ()
index++; index++;
} }
memset (index, '\0', length - (index - tok)); memset (index, '\0', length - (size_t) (index - tok));
token_start = NULL; token_start = NULL;
// Eat up '"' // Eat up '"'
@@ -569,7 +567,7 @@ parse_string ()
} }
static void static void
grobble_whitespaces () grobble_whitespaces (void)
{ {
char c = LA (0); char c = LA (0);
@@ -600,7 +598,7 @@ lexer_set_source (const char * source)
#endif #endif
static bool static bool
replace_comment_by_newline () replace_comment_by_newline (void)
{ {
char c = LA (0); char c = LA (0);
bool multiline; bool multiline;
@@ -636,11 +634,12 @@ replace_comment_by_newline ()
} }
} }
token
#ifdef JERRY_NDEBUG #ifdef JERRY_NDEBUG
lexer_next_token_private () static token
lexer_next_token_private (void)
#else #else
lexer_next_token () token
lexer_next_token (void)
#endif #endif
{ {
char c = LA (0); char c = LA (0);
@@ -776,7 +775,7 @@ lexer_next_token ()
static int i = 0; static int i = 0;
token token
lexer_next_token () lexer_next_token (void)
{ {
token tok = lexer_next_token_private (); token tok = lexer_next_token_private ();
if (tok.type == TOK_NEWLINE) if (tok.type == TOK_NEWLINE)
@@ -802,7 +801,7 @@ lexer_save_token (token tok)
} }
void void
lexer_dump_buffer_state () lexer_dump_buffer_state (void)
{ {
printf ("%s\n", buffer); printf ("%s\n", buffer);
} }
+1 -1
View File
@@ -156,7 +156,7 @@ void lexer_set_file (FILE *);
#else #else
void lexer_set_source (const char *); void lexer_set_source (const char *);
#endif #endif
token lexer_next_token (); token lexer_next_token (void);
void lexer_save_token (token); void lexer_save_token (token);
#endif #endif
+1 -1
View File
@@ -58,7 +58,7 @@ putchar (int c)
static inline void static inline void
exit (int status) exit (int status)
{ {
return __exit (status); __exit (status);
} }
static inline int static inline int
+103 -54
View File
@@ -17,33 +17,82 @@
#include "error.h" #include "error.h"
#include "lexer.h" #include "lexer.h"
bool
is_formal_parameter_list_empty (formal_parameter_list list)
{
return list.names[0] == NULL;
}
bool
is_operand_empty (operand op)
{
return op.is_literal == false && op.data.none == NULL;
}
bool
is_operand_list_empty (operand_list list)
{
return is_operand_empty (list.ops[0]);
}
bool
is_property_empty (property prop)
{
return is_operand_empty (prop.name) && is_operand_empty (prop.value);
}
bool
is_property_list_empty (property_list list)
{
return is_property_empty (list.props[0]);
}
bool
is_expression_empty (assignment_expression expr)
{
return expr.oper == AO_NONE && expr.type == ET_NONE && expr.data.none == NULL;
}
bool
is_variable_declaration_empty (variable_declaration var_decl)
{
return var_decl.name == NULL && is_expression_empty (var_decl.assign_expr);
}
bool
is_statement_null (statement stmt)
{
return stmt.type == STMT_NULL && stmt.data.none == NULL;
}
static token tok; static token tok;
#ifdef JERRY_NDEBUG #ifdef JERRY_NDEBUG
FILE *debug_file; FILE *debug_file;
#endif #endif
static expression parse_expression (); static expression parse_expression (void);
static assignment_expression parse_assigment_expression (); static assignment_expression parse_assigment_expression (void);
typedef enum typedef enum
{ {
SCOPE_GLOBAL = 0, SCOPE_GLOBAL = 0,
SCOPE_IF = 1 << 0, SCOPE_IF = 1u << 0,
SCOPE_BLOCK = 1 << 1, SCOPE_BLOCK = 1u << 1,
SCOPE_DO = 1 << 2, SCOPE_DO = 1u << 2,
SCOPE_WHILE = 1 << 3, SCOPE_WHILE = 1u << 3,
SCOPE_FOR = 1 << 4, SCOPE_FOR = 1u << 4,
SCOPE_LOOP = SCOPE_WHILE | SCOPE_FOR | SCOPE_DO, SCOPE_LOOP = SCOPE_WHILE | SCOPE_FOR | SCOPE_DO,
SCOPE_WITH = 1 << 5, SCOPE_WITH = 1u << 5,
SCOPE_SWITCH = 1 << 6, SCOPE_SWITCH = 1u << 6,
SCOPE_CASE = 1 << 7, SCOPE_CASE = 1u << 7,
SCOPE_ELSE = 1 << 8, SCOPE_ELSE = 1u << 8,
SCOPE_TRY = 1 << 9, SCOPE_TRY = 1u << 9,
SCOPE_CATCH = 1 << 10, SCOPE_CATCH = 1u << 10,
SCOPE_FINALLY = 1 << 11, SCOPE_FINALLY = 1u << 11,
SCOPE_FUNCTION = 1 << 12, SCOPE_FUNCTION = 1u << 12,
SCOPE_SUBEXPRESSION = 1 << 13 SCOPE_SUBEXPRESSION = 1u << 13
} }
scope_type; scope_type;
@@ -58,12 +107,12 @@ scope;
static scope current_scopes[MAX_SCOPES]; static scope current_scopes[MAX_SCOPES];
static int scope_index; static unsigned int scope_index;
static inline void static void
scope_must_be (int scopes) scope_must_be (unsigned int scopes)
{ {
int i; size_t i;
for (i = 0; i < scope_index; i++) for (i = 0; i < scope_index; i++)
{ {
@@ -73,8 +122,8 @@ scope_must_be (int scopes)
fatal (ERR_PARSER); fatal (ERR_PARSER);
} }
static inline void static void
current_scope_must_be (int scopes) current_scope_must_be (unsigned int scopes)
{ {
if (scopes & current_scopes[scope_index - 1].type) if (scopes & current_scopes[scope_index - 1].type)
return; return;
@@ -82,7 +131,7 @@ current_scope_must_be (int scopes)
} }
static inline void static inline void
current_scope_must_be_global () current_scope_must_be_global (void)
{ {
if (scope_index != 0) if (scope_index != 0)
fatal (ERR_PARSER); fatal (ERR_PARSER);
@@ -98,7 +147,7 @@ push_scope (int type)
} }
static void static void
pop_scope () pop_scope (void)
{ {
#ifdef JERRY_NDEBUG #ifdef JERRY_NDEBUG
fprintf (debug_file, "pop_scope: 0x%x\n", current_scopes[scope_index - 1].type); fprintf (debug_file, "pop_scope: 0x%x\n", current_scopes[scope_index - 1].type);
@@ -106,7 +155,7 @@ pop_scope ()
scope_index--; scope_index--;
} }
static inline void static void
assert_keyword (keyword kw) assert_keyword (keyword kw)
{ {
if (tok.type != TOK_KEYWORD || tok.data.kw != kw) if (tok.type != TOK_KEYWORD || tok.data.kw != kw)
@@ -118,13 +167,13 @@ assert_keyword (keyword kw)
} }
} }
static inline bool static bool
is_keyword (keyword kw) is_keyword (keyword kw)
{ {
return tok.type == TOK_KEYWORD && tok.data.kw == kw; return tok.type == TOK_KEYWORD && tok.data.kw == kw;
} }
static inline void static void
current_token_must_be(token_type tt) current_token_must_be(token_type tt)
{ {
if (tok.type != tt) if (tok.type != tt)
@@ -136,15 +185,15 @@ current_token_must_be(token_type tt)
} }
} }
static inline void static void
skip_newlines () skip_newlines (void)
{ {
tok = lexer_next_token (); tok = lexer_next_token ();
while (tok.type == TOK_NEWLINE) while (tok.type == TOK_NEWLINE)
tok = lexer_next_token (); tok = lexer_next_token ();
} }
static inline void static void
next_token_must_be (token_type tt) next_token_must_be (token_type tt)
{ {
tok = lexer_next_token (); tok = lexer_next_token ();
@@ -157,7 +206,7 @@ next_token_must_be (token_type tt)
} }
} }
static inline void static void
token_after_newlines_must_be (token_type tt) token_after_newlines_must_be (token_type tt)
{ {
skip_newlines (); skip_newlines ();
@@ -173,8 +222,8 @@ token_after_newlines_must_be_keyword (keyword kw)
fatal (ERR_PARSER); fatal (ERR_PARSER);
} }
static inline void static void
insert_semicolon () insert_semicolon (void)
{ {
tok = lexer_next_token (); tok = lexer_next_token ();
if (tok.type != TOK_NEWLINE && tok.type != TOK_SEMICOLON) if (tok.type != TOK_NEWLINE && tok.type != TOK_SEMICOLON)
@@ -185,7 +234,7 @@ insert_semicolon ()
: LT!* Identifier (LT!* ',' LT!* Identifier)* : LT!* Identifier (LT!* ',' LT!* Identifier)*
; */ ; */
static formal_parameter_list static formal_parameter_list
parse_formal_parameter_list () parse_formal_parameter_list (void)
{ {
int i; int i;
formal_parameter_list res; formal_parameter_list res;
@@ -217,7 +266,7 @@ parse_formal_parameter_list ()
function_body function_body
: '{' LT!* sourceElements LT!* '}' */ : '{' LT!* sourceElements LT!* '}' */
static function_declaration static function_declaration
parse_function_declaration () parse_function_declaration (void)
{ {
function_declaration res; function_declaration res;
@@ -244,7 +293,7 @@ parse_function_declaration ()
: 'function' LT!* Identifier? LT!* '(' formal_parameter_list? LT!* ')' LT!* function_body : 'function' LT!* Identifier? LT!* '(' formal_parameter_list? LT!* ')' LT!* function_body
; */ ; */
static function_expression static function_expression
parse_function_expression () parse_function_expression (void)
{ {
function_expression res; function_expression res;
@@ -276,7 +325,7 @@ parse_function_expression ()
} }
static literal static literal
parse_literal () parse_literal (void)
{ {
literal res; literal res;
@@ -308,7 +357,7 @@ parse_literal ()
} }
static operand static operand
parse_operand () parse_operand (void)
{ {
operand res; operand res;
@@ -336,7 +385,7 @@ parse_operand ()
: operand LT!* ( ',' LT!* operand * LT!* )* : operand LT!* ( ',' LT!* operand * LT!* )*
;*/ ;*/
static argument_list static argument_list
parse_argument_list () parse_argument_list (void)
{ {
argument_list res; argument_list res;
int i; int i;
@@ -364,7 +413,7 @@ parse_argument_list ()
: identifier LT!* '(' LT!* arguments * LT!* ')' LT!* : identifier LT!* '(' LT!* arguments * LT!* ')' LT!*
;*/ ;*/
static call_expression static call_expression
parse_call_expression () parse_call_expression (void)
{ {
call_expression res; call_expression res;
@@ -396,7 +445,7 @@ parse_call_expression ()
: [ arguments ] : [ arguments ]
; */ ; */
static array_literal static array_literal
parse_array_literal () parse_array_literal (void)
{ {
array_literal res; array_literal res;
@@ -420,7 +469,7 @@ parse_array_literal ()
| NumericLiteral | NumericLiteral
; */ ; */
static inline property_name static inline property_name
parse_property_name () parse_property_name (void)
{ {
switch (tok.type) switch (tok.type)
{ {
@@ -438,7 +487,7 @@ parse_property_name ()
: property_name LT!* ':' LT!* operand : property_name LT!* ':' LT!* operand
; */ ; */
static property static property
parse_property () parse_property (void)
{ {
property res; property res;
@@ -455,7 +504,7 @@ parse_property ()
: LT!* property (LT!* ',' LT!* property)* LT!* : LT!* property (LT!* ',' LT!* property)* LT!*
; */ ; */
static object_literal static object_literal
parse_object_literal () parse_object_literal (void)
{ {
object_literal res; object_literal res;
int i; int i;
@@ -488,7 +537,7 @@ parse_unary_expression (assignment_expression *res, expression_type type)
} }
static assignment_expression static assignment_expression
parse_assigment_expression () parse_assigment_expression (void)
{ {
assignment_expression res; assignment_expression res;
@@ -780,7 +829,7 @@ parse_operator:
; ;
*/ */
static expression static expression
parse_expression () parse_expression (void)
{ {
expression res; expression res;
int i; int i;
@@ -808,7 +857,7 @@ parse_expression ()
: '=' LT!* assignment_expression : '=' LT!* assignment_expression
; */ ; */
static variable_declaration static variable_declaration
parse_variable_declaration () parse_variable_declaration (void)
{ {
variable_declaration res; variable_declaration res;
@@ -835,7 +884,7 @@ parse_variable_declaration ()
(LT!* ',' LT!* variable_declaration(_no_in))* (LT!* ',' LT!* variable_declaration(_no_in))*
; */ ; */
static variable_declaration_list static variable_declaration_list
parse_variable_declaration_list () parse_variable_declaration_list (void)
{ {
variable_declaration_list res; variable_declaration_list res;
int i; int i;
@@ -877,7 +926,7 @@ parse_variable_declaration_list ()
;*/ ;*/
static for_or_for_in_statement static for_or_for_in_statement
parse_for_or_for_in_statement () parse_for_or_for_in_statement (void)
{ {
for_or_for_in_statement res; for_or_for_in_statement res;
variable_declaration_list list; variable_declaration_list list;
@@ -985,7 +1034,7 @@ for_in:
return res; return res;
} }
static inline void static void
parse_expression_inside_parens (statement *res) parse_expression_inside_parens (statement *res)
{ {
token_after_newlines_must_be (TOK_OPEN_PAREN); token_after_newlines_must_be (TOK_OPEN_PAREN);
@@ -1058,7 +1107,7 @@ parse_expression_inside_parens (statement *res)
: 'try' LT!* '{' LT!* statement_list LT!* '}' LT!* (finally_clause | catch_clause (LT!* finally_clause)?) : 'try' LT!* '{' LT!* statement_list LT!* '}' LT!* (finally_clause | catch_clause (LT!* finally_clause)?)
;*/ ;*/
statement statement
parser_parse_statement () parser_parse_statement (void)
{ {
statement res; statement res;
res.data.none = NULL; res.data.none = NULL;
@@ -1168,7 +1217,7 @@ parser_parse_statement ()
res.type = STMT_VARIABLE; res.type = STMT_VARIABLE;
skip_newlines (); skip_newlines ();
res.data.var_stmt = parse_variable_declaration_list (true); res.data.var_stmt = parse_variable_declaration_list ();
return res; return res;
} }
if (tok.type == TOK_SEMICOLON) if (tok.type == TOK_SEMICOLON)
@@ -1231,7 +1280,7 @@ parser_parse_statement ()
tok = lexer_next_token (); tok = lexer_next_token ();
if (tok.type != TOK_SEMICOLON && tok.type != TOK_NEWLINE) if (tok.type != TOK_SEMICOLON && tok.type != TOK_NEWLINE)
{ {
int current_scope_index = scope_index; unsigned int current_scope_index = scope_index;
res.data.expr = parse_expression (); res.data.expr = parse_expression ();
if (current_scope_index == scope_index) if (current_scope_index == scope_index)
insert_semicolon (); insert_semicolon ();
@@ -1323,7 +1372,7 @@ parser_parse_statement ()
} }
void void
parser_init () parser_init (void)
{ {
scope_index = 0; scope_index = 0;
#ifdef JERRY_NDEBUG #ifdef JERRY_NDEBUG
+10 -42
View File
@@ -44,11 +44,7 @@ empty_formal_parameter_list =
.names = { [0] = NULL } .names = { [0] = NULL }
}; };
static inline bool bool is_formal_parameter_list_empty (formal_parameter_list);
is_formal_parameter_list_empty (formal_parameter_list list)
{
return list.names[0] == NULL;
}
/** @function_declaration represents both declaration and expression of a function. /** @function_declaration represents both declaration and expression of a function.
After this parser must return a block of statements. */ After this parser must return a block of statements. */
@@ -119,11 +115,7 @@ empty_operand =
.data.none = NULL .data.none = NULL
}; };
static inline bool bool is_operand_empty (operand);
is_operand_empty (operand op)
{
return op.is_literal == false && op.data.none == NULL;
}
typedef struct typedef struct
{ {
@@ -143,11 +135,7 @@ empty_operand_list =
.ops = { [0] = { .is_literal = false, .data.none = NULL } } .ops = { [0] = { .is_literal = false, .data.none = NULL } }
}; };
static inline bool bool is_operand_list_empty (operand_list);
is_operand_list_empty (operand_list list)
{
return is_operand_empty (list.ops[0]);
}
typedef operand_list array_literal; typedef operand_list array_literal;
typedef operand_list argument_list; typedef operand_list argument_list;
@@ -175,11 +163,7 @@ static const property empty_property =
.value = { .is_literal = false, .data.none = NULL } .value = { .is_literal = false, .data.none = NULL }
}; };
static inline bool bool is_property_empty (property);
is_property_empty (property prop)
{
return is_operand_empty (prop.name) && is_operand_empty (prop.value);
}
/** List of properties. Represents ObjectLiteral. */ /** List of properties. Represents ObjectLiteral. */
typedef struct typedef struct
@@ -200,11 +184,7 @@ empty_property_list =
{ .is_literal = false, .data.none = NULL }}} { .is_literal = false, .data.none = NULL }}}
}; };
static inline bool bool is_property_list_empty (property_list);
is_property_list_empty (property_list list)
{
return is_property_empty (list.props[0]);
}
typedef property_list object_literal; typedef property_list object_literal;
@@ -305,11 +285,7 @@ empty_expression =
.data.none = NULL .data.none = NULL
}; };
static inline bool bool is_expression_empty (assignment_expression);
is_expression_empty (assignment_expression expr)
{
return expr.oper == AO_NONE && expr.type == ET_NONE && expr.data.none == NULL;
}
/** Represents expression, array literal and list of argument. */ /** Represents expression, array literal and list of argument. */
typedef struct typedef struct
@@ -338,11 +314,7 @@ empty_variable_declaration =
.assign_expr = { .oper = AO_NONE, .type = ET_NONE, .data.none = NULL } .assign_expr = { .oper = AO_NONE, .type = ET_NONE, .data.none = NULL }
}; };
static inline bool bool is_variable_declaration_empty (variable_declaration);
is_variable_declaration_empty (variable_declaration var_decl)
{
return var_decl.name == NULL && is_expression_empty (var_decl.assign_expr);
}
typedef struct typedef struct
{ {
@@ -461,13 +433,9 @@ null_statement =
.data.none = NULL .data.none = NULL
}; };
static inline bool bool is_statement_null (statement);
is_statement_null (statement stmt)
{
return stmt.type == STMT_NULL && stmt.data.none == NULL;
}
void parser_init (); void parser_init (void);
statement parser_parse_statement (); statement parser_parse_statement (void);
#endif #endif
+1 -1
View File
@@ -28,7 +28,7 @@
#include "generated.h" #include "generated.h"
void fake_exit (); void fake_exit (void);
void void
fake_exit (void) fake_exit (void)
+3 -3
View File
@@ -23,7 +23,7 @@ static bool was_subexpression;
static statement_type prev_stmt; static statement_type prev_stmt;
void void
pp_reset () pp_reset (void)
{ {
prev_stmt = STMT_EOF; prev_stmt = STMT_EOF;
intendation = 0; intendation = 0;
@@ -404,7 +404,7 @@ pp_keyword (keyword kw)
} }
static void static void
intend () intend (void)
{ {
for (int i = 0; i < intendation; i++) for (int i = 0; i < intendation; i++)
putchar (' '); putchar (' ');
@@ -1087,7 +1087,7 @@ pp_statement (statement stmt)
prev_stmt = stmt.type; prev_stmt = stmt.type;
} }
void pp_finish () void pp_finish (void)
{ {
if (prev_stmt == STMT_BLOCK_END) if (prev_stmt == STMT_BLOCK_END)
putchar ('\n'); putchar ('\n');
+2 -2
View File
@@ -19,8 +19,8 @@
#include "lexer.h" #include "lexer.h"
#include "parser.h" #include "parser.h"
void pp_reset (); void pp_reset (void);
void pp_finish (); void pp_finish (void);
void pp_token (token); void pp_token (token);
void pp_keyword (keyword); void pp_keyword (keyword);
void pp_statement (statement); void pp_statement (statement);