Create function variables using the data produced by the pre-scanner. (#3199)

The pre-scanner now is able to track all variable declarations and produces a compressed
stream which store this data for each function and catch block. When a function or
catch block is parsed, this information is decoded and the appropriate variables are
created. Furthermore a stack scope is created which contains the currently available
local variables and their register or literal index.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2019-10-17 15:20:04 +02:00
committed by GitHub
parent fd1f7eab9f
commit 7df87b7778
20 changed files with 2098 additions and 1219 deletions
+66 -3
View File
@@ -16,7 +16,7 @@
#ifndef JS_SCANNER_INTERNAL_H
#define JS_SCANNER_INTERNAL_H
/** \addtogroup parser Parser
/* \addtogroup parser Parser
* @{
*
* \addtogroup jsparser JavaScript
@@ -34,6 +34,19 @@ typedef struct
const uint8_t *source_p; /**< start source byte */
} scanner_source_start_t;
/**
* Flags for type member of lexer_lit_location_t structure in the literal pool.
*/
typedef enum
{
SCANNER_LITERAL_IS_ARG = (1 << 0), /**< literal is argument */
SCANNER_LITERAL_IS_LOCAL = (1 << 1), /**< literal is local (similar to let,
* but var is allowed with the same identifier) */
SCANNER_LITERAL_IS_VAR = (1 << 2), /**< literal is var */
SCANNER_LITERAL_IS_FUNC = (1 << 3), /**< literal is function */
SCANNER_LITERAL_NO_REG = (1 << 4), /**< literal cannot be stored in register */
} scanner_literal_type_flags_t;
/**
* For statement descriptor.
*/
@@ -55,14 +68,64 @@ typedef struct
scanner_case_info_t **last_case_p; /**< last case info */
} scanner_switch_statement_t;
/**
* Flags for scanner_literal_pool_t structure.
*/
typedef enum
{
SCANNER_LITERAL_POOL_FUNCTION = (1 << 0), /**< literal pool represents a function */
SCANNER_LITERAL_POOL_BLOCK = (1 << 1), /**< literal pool represents a code block */
SCANNER_LITERAL_POOL_NO_REG = (1 << 2), /**< variable declarations cannot be kept in registers */
SCANNER_LITERAL_POOL_NO_ARGUMENTS = (1 << 3), /**< arguments object should not be constructed */
SCANNER_LITERAL_POOL_IN_WITH = (1 << 4), /**< literal pool is in a with statement */
} scanner_literal_pool_flags_t;
/**
* Define a function where no arguments are allowed.
*/
#define SCANNER_LITERAL_POOL_FUNCTION_WITHOUT_ARGUMENTS \
(SCANNER_LITERAL_POOL_FUNCTION | SCANNER_LITERAL_POOL_NO_ARGUMENTS)
/**
* Local literal pool.
*/
typedef struct scanner_literal_pool_t
{
struct scanner_literal_pool_t *prev_p; /**< previous literal pool */
const uint8_t *source_p; /**< source position where the final data needs to be inserted */
parser_list_t literal_pool; /**< list of literal */
uint16_t status_flags; /**< combination of scanner_literal_pool_flags_t flags */
uint16_t no_declarations; /**< size of scope stack required during parsing */
} scanner_literal_pool_t;
/**
* Scanner context.
*/
typedef struct
struct scanner_context_t
{
uint8_t mode; /**< scanner mode */
#if ENABLED (JERRY_DEBUGGER)
uint8_t debugger_enabled; /**< debugger is enabled */
#endif /* ENABLED (JERRY_DEBUGGER) */
scanner_literal_pool_t *active_literal_pool_p; /**< currently active literal pool */
scanner_switch_statement_t active_switch_statement; /**< currently active switch statement */
} scanner_context_t;
scanner_info_t *end_arguments_p; /**< position of end arguments */
};
size_t scanner_get_stream_size (scanner_info_t *info_p, size_t size);
scanner_info_t *scanner_insert_info (parser_context_t *context_p, const uint8_t *source_p, size_t size);
scanner_info_t *scanner_insert_info_before (parser_context_t *context_p, const uint8_t *source_p,
scanner_info_t *start_info_p, size_t size);
scanner_literal_pool_t *scanner_push_literal_pool (parser_context_t *context_p, scanner_context_t *scanner_context_p,
uint16_t status_flags);
void scanner_pop_literal_pool (parser_context_t *context_p, scanner_context_t *scanner_context_p);
void scanner_filter_arguments (parser_context_t *context_p, scanner_context_t *scanner_context_p);
lexer_lit_location_t *scanner_add_custom_literal (parser_context_t *context_p, scanner_literal_pool_t *literal_pool_p,
const lexer_lit_location_t *literal_location_p);
lexer_lit_location_t *scanner_add_literal (parser_context_t *context_p, scanner_context_t *scanner_context_p);
void scanner_add_reference (parser_context_t *context_p, scanner_context_t *scanner_context_p);
void scanner_append_argument (parser_context_t *context_p, scanner_context_t *scanner_context_p);
void scanner_detect_eval_call (parser_context_t *context_p, scanner_context_t *scanner_context_p);
/**
* @}