Skip to content

Commit f701874

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 f701874

File tree

7 files changed

+66
-135
lines changed

7 files changed

+66
-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: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,10 +1815,12 @@ parser_free_literals (parser_list_t *literal_pool_p) /**< literals */
18151815
/**
18161816
* Parse and compile EcmaScript source code
18171817
*
1818+
* Note: source must be a valid UTF-8 string
1819+
*
18181820
* @return compiled code
18191821
*/
1820-
ecma_compiled_code_t *
1821-
parser_parse_script (const uint8_t *source_p, /**< valid UTF-8 source code */
1822+
static ecma_compiled_code_t *
1823+
parser_parse_source (const uint8_t *source_p, /**< valid UTF-8 source code */
18221824
size_t size, /**< size of the source code */
18231825
int strict_mode, /**< strict mode */
18241826
parser_error_location *error_location) /**< error location */
@@ -1947,7 +1949,7 @@ parser_parse_script (const uint8_t *source_p, /**< valid UTF-8 source code */
19471949
parser_stack_free (&context);
19481950

19491951
return compiled_code;
1950-
} /* parser_parse_script */
1952+
} /* parser_parse_source */
19511953

19521954
/**
19531955
* Parse function code
@@ -2219,7 +2221,7 @@ parser_raise_error (parser_context_t *context_p, /**< context */
22192221
/* First the current literal pool is freed, and then it is replaced
22202222
* by the literal pool coming from the saved context. Since literals
22212223
* are not used anymore, this is a valid replacement. The last pool
2222-
* is freed by parser_parse_script. */
2224+
* is freed by parser_parse_source. */
22232225

22242226
parser_free_literals (&context_p->literal_pool);
22252227
context_p->literal_pool.data = saved_context_p->literal_pool_data;
@@ -2251,6 +2253,45 @@ parser_set_show_instrs (int show_instrs) /**< flag indicating whether to dump by
22512253
#endif /* PARSER_DUMP_BYTE_CODE */
22522254
} /* parser_set_show_instrs */
22532255

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

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,24 @@ 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+
/* Note: source must be a valid UTF-8 string */
144+
extern jsp_status_t parser_parse_script (const jerry_api_char_t *, size_t,
145+
ecma_compiled_code_t **);
146+
extern jsp_status_t parser_parse_eval (const jerry_api_char_t *, size_t, bool,
147+
ecma_compiled_code_t **);
148+
133149
const char *parser_error_to_string (parser_error_t);
134150

135151
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)