Skip to content

Commit b864438

Browse files
committed
Merged the parser-js and parser files.
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka [email protected]
1 parent 0f37828 commit b864438

File tree

7 files changed

+63
-135
lines changed

7 files changed

+63
-135
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-function.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "ecma-lex-env.h"
2323
#include "ecma-try-catch-macro.h"
2424
#include "lit-magic-strings.h"
25-
#include "parser.h"
25+
#include "js-parser.h"
2626

2727
#define ECMA_BUILTINS_INTERNAL
2828
#include "ecma-builtins-internal.h"

jerry-core/ecma/operations/ecma-eval.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "ecma-globals.h"
2121
#include "ecma-helpers.h"
2222
#include "ecma-lex-env.h"
23-
#include "parser.h"
23+
#include "js-parser.h"
2424
#include "vm.h"
2525

2626
/** \addtogroup ecma ECMA

jerry-core/jerry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "lit-literal.h"
3232
#include "lit-magic-strings.h"
3333
#include "lit-snapshot.h"
34-
#include "parser.h"
34+
#include "js-parser.h"
3535
#include "re-compiler.h"
3636

3737
#define JERRY_INTERNAL

jerry-core/parser/js/js-parser.cpp

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,8 +1817,8 @@ parser_free_literals (parser_list_t *literal_pool_p) /**< literals */
18171817
*
18181818
* @return compiled code
18191819
*/
1820-
ecma_compiled_code_t *
1821-
parser_parse_script (const uint8_t *source_p, /**< valid UTF-8 source code */
1820+
static ecma_compiled_code_t *
1821+
parse_script (const uint8_t *source_p, /**< valid UTF-8 source code */
18221822
size_t size, /**< size of the source code */
18231823
int strict_mode, /**< strict mode */
18241824
parser_error_location *error_location) /**< error location */
@@ -1947,7 +1947,7 @@ parser_parse_script (const uint8_t *source_p, /**< valid UTF-8 source code */
19471947
parser_stack_free (&context);
19481948

19491949
return compiled_code;
1950-
} /* parser_parse_script */
1950+
} /* parse_script */
19511951

19521952
/**
19531953
* Parse function code
@@ -2219,7 +2219,7 @@ parser_raise_error (parser_context_t *context_p, /**< context */
22192219
/* First the current literal pool is freed, and then it is replaced
22202220
* by the literal pool coming from the saved context. Since literals
22212221
* are not used anymore, this is a valid replacement. The last pool
2222-
* is freed by parser_parse_script. */
2222+
* is freed by parse_script. */
22232223

22242224
parser_free_literals (&context_p->literal_pool);
22252225
context_p->literal_pool.data = saved_context_p->literal_pool_data;
@@ -2251,6 +2251,45 @@ parser_set_show_instrs (int show_instrs) /**< flag indicating whether to dump by
22512251
#endif /* PARSER_DUMP_BYTE_CODE */
22522252
} /* parser_set_show_instrs */
22532253

2254+
2255+
/**
2256+
* Parse EcamScript source code
2257+
*/
2258+
jsp_status_t
2259+
parser_parse_script (const jerry_api_char_t *source_p, /**< source code */
2260+
size_t size, /**< size of the source code */
2261+
ecma_compiled_code_t **bytecode_data_p) /**< result */
2262+
{
2263+
*bytecode_data_p = parse_script (source_p, size, false, NULL);
2264+
2265+
if (!*bytecode_data_p)
2266+
{
2267+
return JSP_STATUS_SYNTAX_ERROR;
2268+
}
2269+
2270+
return JSP_STATUS_OK;
2271+
} /* parser_parse_script */
2272+
2273+
/**
2274+
* Parse EcamScript eval source code
2275+
*/
2276+
jsp_status_t
2277+
parser_parse_eval (const jerry_api_char_t *source_p, /**< source code */
2278+
size_t size, /**< size of the source code */
2279+
bool is_strict, /**< strict mode */
2280+
ecma_compiled_code_t **bytecode_data_p) /**< result */
2281+
{
2282+
*bytecode_data_p = parse_script (source_p, size, is_strict, NULL);
2283+
2284+
if (!*bytecode_data_p)
2285+
{
2286+
return JSP_STATUS_SYNTAX_ERROR;
2287+
}
2288+
2289+
return JSP_STATUS_OK;
2290+
} /* parser_parse_eval */
2291+
2292+
22542293
/**
22552294
* @}
22562295
* @}

jerry-core/parser/js/js-parser.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,23 @@ typedef struct
128128
parser_line_counter_t column; /**< column where the error occured */
129129
} parser_error_location;
130130

131-
/* Note: source must be a valid UTF-8 string. */
132-
ecma_compiled_code_t * parser_parse_script (const uint8_t *, size_t, int, parser_error_location *);
131+
/**
132+
* Parser completion status
133+
*/
134+
typedef enum
135+
{
136+
JSP_STATUS_OK, /**< parse finished successfully, no early errors occured */
137+
JSP_STATUS_SYNTAX_ERROR, /**< SyntaxError early error occured */
138+
JSP_STATUS_REFERENCE_ERROR /**< ReferenceError early error occured */
139+
} jsp_status_t;
140+
141+
extern void parser_set_show_instrs (int);
142+
143+
extern jsp_status_t parser_parse_script (const jerry_api_char_t *, size_t,
144+
ecma_compiled_code_t **);
145+
extern jsp_status_t parser_parse_eval (const jerry_api_char_t *, size_t, bool,
146+
ecma_compiled_code_t **);
147+
133148
const char *parser_error_to_string (parser_error_t);
134149

135150
extern void parser_set_show_instrs (int);

jerry-core/parser/js/parser.cpp

Lines changed: 0 additions & 71 deletions
This file was deleted.

jerry-core/parser/js/parser.h

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)