Skip to content

Merge the js-parser and parser files #859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jerry-core/ecma/builtin-objects/ecma-builtin-function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "ecma-lex-env.h"
#include "ecma-try-catch-macro.h"
#include "lit-magic-strings.h"
#include "parser.h"
#include "js-parser.h"

#define ECMA_BUILTINS_INTERNAL
#include "ecma-builtins-internal.h"
Expand Down
2 changes: 1 addition & 1 deletion jerry-core/ecma/operations/ecma-eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-lex-env.h"
#include "parser.h"
#include "js-parser.h"
#include "vm.h"

/** \addtogroup ecma ECMA
Expand Down
2 changes: 1 addition & 1 deletion jerry-core/jerry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "lit-literal.h"
#include "lit-magic-strings.h"
#include "lit-snapshot.h"
#include "parser.h"
#include "js-parser.h"
#include "re-compiler.h"

#define JERRY_INTERNAL
Expand Down
49 changes: 45 additions & 4 deletions jerry-core/parser/js/js-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1815,10 +1815,12 @@ parser_free_literals (parser_list_t *literal_pool_p) /**< literals */
/**
* Parse and compile EcmaScript source code
*
* Note: source must be a valid UTF-8 string
*
* @return compiled code
*/
ecma_compiled_code_t *
parser_parse_script (const uint8_t *source_p, /**< valid UTF-8 source code */
static ecma_compiled_code_t *
parser_parse_source (const uint8_t *source_p, /**< valid UTF-8 source code */
size_t size, /**< size of the source code */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong indentation

int strict_mode, /**< strict mode */
parser_error_location *error_location) /**< error location */
Expand Down Expand Up @@ -1947,7 +1949,7 @@ parser_parse_script (const uint8_t *source_p, /**< valid UTF-8 source code */
parser_stack_free (&context);

return compiled_code;
} /* parser_parse_script */
} /* parser_parse_source */

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

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


/**
* Parse EcamScript source code
*/
jsp_status_t
parser_parse_script (const jerry_api_char_t *source_p, /**< source code */
size_t size, /**< size of the source code */
ecma_compiled_code_t **bytecode_data_p) /**< result */
{
*bytecode_data_p = parser_parse_source (source_p, size, false, NULL);

if (!*bytecode_data_p)
{
return JSP_STATUS_SYNTAX_ERROR;
}

return JSP_STATUS_OK;
} /* parser_parse_script */

/**
* Parse EcamScript eval source code
*/
jsp_status_t
parser_parse_eval (const jerry_api_char_t *source_p, /**< source code */
size_t size, /**< size of the source code */
bool is_strict, /**< strict mode */
ecma_compiled_code_t **bytecode_data_p) /**< result */
{
*bytecode_data_p = parser_parse_source (source_p, size, is_strict, NULL);

if (!*bytecode_data_p)
{
return JSP_STATUS_SYNTAX_ERROR;
}

return JSP_STATUS_OK;
} /* parser_parse_eval */


/**
* @}
* @}
Expand Down
20 changes: 18 additions & 2 deletions jerry-core/parser/js/js-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,24 @@ typedef struct
parser_line_counter_t column; /**< column where the error occured */
} parser_error_location;

/* Note: source must be a valid UTF-8 string. */
ecma_compiled_code_t * parser_parse_script (const uint8_t *, size_t, int, parser_error_location *);
/**
* Parser completion status
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should be kept.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is not fixed. After that, LGTM

*/
typedef enum
{
JSP_STATUS_OK, /**< parse finished successfully, no early errors occured */
JSP_STATUS_SYNTAX_ERROR, /**< SyntaxError early error occured */
JSP_STATUS_REFERENCE_ERROR /**< ReferenceError early error occured */
} jsp_status_t;

extern void parser_set_show_instrs (int);

/* Note: source must be a valid UTF-8 string */
extern jsp_status_t parser_parse_script (const jerry_api_char_t *, size_t,
ecma_compiled_code_t **);
extern jsp_status_t parser_parse_eval (const jerry_api_char_t *, size_t, bool,
ecma_compiled_code_t **);

const char *parser_error_to_string (parser_error_t);

extern void parser_set_show_instrs (int);
Expand Down
71 changes: 0 additions & 71 deletions jerry-core/parser/js/parser.cpp

This file was deleted.

55 changes: 0 additions & 55 deletions jerry-core/parser/js/parser.h

This file was deleted.