1425bb815Sopenharmony_ci/* Copyright JS Foundation and other contributors, http://js.foundation
2425bb815Sopenharmony_ci *
3425bb815Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4425bb815Sopenharmony_ci * you may not use this file except in compliance with the License.
5425bb815Sopenharmony_ci * You may obtain a copy of the License at
6425bb815Sopenharmony_ci *
7425bb815Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8425bb815Sopenharmony_ci *
9425bb815Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10425bb815Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS
11425bb815Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12425bb815Sopenharmony_ci * See the License for the specific language governing permissions and
13425bb815Sopenharmony_ci * limitations under the License.
14425bb815Sopenharmony_ci */
15425bb815Sopenharmony_ci
16425bb815Sopenharmony_ci#ifndef JS_SCANNER_INTERNAL_H
17425bb815Sopenharmony_ci#define JS_SCANNER_INTERNAL_H
18425bb815Sopenharmony_ci
19425bb815Sopenharmony_ci/* \addtogroup parser Parser
20425bb815Sopenharmony_ci * @{
21425bb815Sopenharmony_ci *
22425bb815Sopenharmony_ci * \addtogroup jsparser JavaScript
23425bb815Sopenharmony_ci * @{
24425bb815Sopenharmony_ci *
25425bb815Sopenharmony_ci * \addtogroup jsparser_scanner Scanner
26425bb815Sopenharmony_ci * @{
27425bb815Sopenharmony_ci */
28425bb815Sopenharmony_ci
29425bb815Sopenharmony_ci/**
30425bb815Sopenharmony_ci * Scan mode types.
31425bb815Sopenharmony_ci */
32425bb815Sopenharmony_citypedef enum
33425bb815Sopenharmony_ci{
34425bb815Sopenharmony_ci  SCAN_MODE_PRIMARY_EXPRESSION,            /**< scanning primary expression */
35425bb815Sopenharmony_ci  SCAN_MODE_PRIMARY_EXPRESSION_AFTER_NEW,  /**< scanning primary expression after new */
36425bb815Sopenharmony_ci  SCAN_MODE_POST_PRIMARY_EXPRESSION,       /**< scanning post primary expression */
37425bb815Sopenharmony_ci  SCAN_MODE_PRIMARY_EXPRESSION_END,        /**< scanning primary expression end */
38425bb815Sopenharmony_ci  SCAN_MODE_STATEMENT,                     /**< scanning statement */
39425bb815Sopenharmony_ci  SCAN_MODE_STATEMENT_OR_TERMINATOR,       /**< scanning statement or statement end */
40425bb815Sopenharmony_ci  SCAN_MODE_STATEMENT_END,                 /**< scanning statement end */
41425bb815Sopenharmony_ci  SCAN_MODE_VAR_STATEMENT,                 /**< scanning var statement */
42425bb815Sopenharmony_ci  SCAN_MODE_PROPERTY_NAME,                 /**< scanning property name */
43425bb815Sopenharmony_ci  SCAN_MODE_FUNCTION_ARGUMENTS,            /**< scanning function arguments */
44425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
45425bb815Sopenharmony_ci  SCAN_MODE_CONTINUE_FUNCTION_ARGUMENTS,   /**< continue scanning function arguments */
46425bb815Sopenharmony_ci  SCAN_MODE_BINDING,                       /**< array or object binding */
47425bb815Sopenharmony_ci  SCAN_MODE_CLASS_DECLARATION,             /**< scanning class declaration */
48425bb815Sopenharmony_ci  SCAN_MODE_CLASS_METHOD,                  /**< scanning class method */
49425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
50425bb815Sopenharmony_ci} scan_modes_t;
51425bb815Sopenharmony_ci
52425bb815Sopenharmony_ci/**
53425bb815Sopenharmony_ci * Scan stack mode types.
54425bb815Sopenharmony_ci */
55425bb815Sopenharmony_citypedef enum
56425bb815Sopenharmony_ci{
57425bb815Sopenharmony_ci  SCAN_STACK_SCRIPT,                       /**< script */
58425bb815Sopenharmony_ci  SCAN_STACK_SCRIPT_FUNCTION,              /**< script is a function body */
59425bb815Sopenharmony_ci  SCAN_STACK_BLOCK_STATEMENT,              /**< block statement group */
60425bb815Sopenharmony_ci  SCAN_STACK_FUNCTION_STATEMENT,           /**< function statement */
61425bb815Sopenharmony_ci  SCAN_STACK_FUNCTION_EXPRESSION,          /**< function expression */
62425bb815Sopenharmony_ci  SCAN_STACK_FUNCTION_PROPERTY,            /**< function expression in an object literal or class */
63425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
64425bb815Sopenharmony_ci  SCAN_STACK_FUNCTION_ARROW,               /**< arrow function expression */
65425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
66425bb815Sopenharmony_ci  SCAN_STACK_SWITCH_BLOCK,                 /**< block part of "switch" statement */
67425bb815Sopenharmony_ci  SCAN_STACK_IF_STATEMENT,                 /**< statement part of "if" statements */
68425bb815Sopenharmony_ci  SCAN_STACK_WITH_STATEMENT,               /**< statement part of "with" statements */
69425bb815Sopenharmony_ci  SCAN_STACK_WITH_EXPRESSION,              /**< expression part of "with" statements */
70425bb815Sopenharmony_ci  SCAN_STACK_DO_STATEMENT,                 /**< statement part of "do" statements */
71425bb815Sopenharmony_ci  SCAN_STACK_DO_EXPRESSION,                /**< expression part of "do" statements */
72425bb815Sopenharmony_ci  SCAN_STACK_WHILE_EXPRESSION,             /**< expression part of "while" iterator */
73425bb815Sopenharmony_ci  SCAN_STACK_PAREN_EXPRESSION,             /**< expression in brackets */
74425bb815Sopenharmony_ci  SCAN_STACK_STATEMENT_WITH_EXPR,          /**< statement which starts with expression enclosed in brackets */
75425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
76425bb815Sopenharmony_ci  SCAN_STACK_BINDING_INIT,                 /**< post processing after a single initializer */
77425bb815Sopenharmony_ci  SCAN_STACK_BINDING_LIST_INIT,            /**< post processing after an initializer list */
78425bb815Sopenharmony_ci  SCAN_STACK_LET,                          /**< let statement */
79425bb815Sopenharmony_ci  SCAN_STACK_CONST,                        /**< const statement */
80425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
81425bb815Sopenharmony_ci  /* The SCANNER_IS_FOR_START macro needs to be updated when the following constants are reordered. */
82425bb815Sopenharmony_ci  SCAN_STACK_VAR,                          /**< var statement */
83425bb815Sopenharmony_ci  SCAN_STACK_FOR_VAR_START,                /**< start of "for" iterator with var statement */
84425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
85425bb815Sopenharmony_ci  SCAN_STACK_FOR_LET_START,                /**< start of "for" iterator with let statement */
86425bb815Sopenharmony_ci  SCAN_STACK_FOR_CONST_START,              /**< start of "for" iterator with const statement */
87425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
88425bb815Sopenharmony_ci  SCAN_STACK_FOR_START,                    /**< start of "for" iterator */
89425bb815Sopenharmony_ci  SCAN_STACK_FOR_CONDITION,                /**< condition part of "for" iterator */
90425bb815Sopenharmony_ci  SCAN_STACK_FOR_EXPRESSION,               /**< expression part of "for" iterator */
91425bb815Sopenharmony_ci  SCAN_STACK_SWITCH_EXPRESSION,            /**< expression part of "switch" statement */
92425bb815Sopenharmony_ci  SCAN_STACK_CASE_STATEMENT,               /**< case statement inside a switch statement */
93425bb815Sopenharmony_ci  SCAN_STACK_COLON_EXPRESSION,             /**< expression between a question mark and colon */
94425bb815Sopenharmony_ci  SCAN_STACK_TRY_STATEMENT,                /**< try statement */
95425bb815Sopenharmony_ci  SCAN_STACK_CATCH_STATEMENT,              /**< catch statement */
96425bb815Sopenharmony_ci  SCAN_STACK_ARRAY_LITERAL,                /**< array literal or destructuring assignment or binding */
97425bb815Sopenharmony_ci  SCAN_STACK_OBJECT_LITERAL,               /**< object literal group */
98425bb815Sopenharmony_ci  SCAN_STACK_PROPERTY_ACCESSOR,            /**< property accessor in square brackets */
99425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
100425bb815Sopenharmony_ci  /* These four must be in this order. */
101425bb815Sopenharmony_ci  SCAN_STACK_COMPUTED_PROPERTY,            /**< computed property name */
102425bb815Sopenharmony_ci  SCAN_STACK_COMPUTED_GENERATOR,           /**< computed generator function */
103425bb815Sopenharmony_ci  SCAN_STACK_COMPUTED_ASYNC,               /**< computed async function */
104425bb815Sopenharmony_ci  SCAN_STACK_COMPUTED_ASYNC_GENERATOR,     /**< computed async function */
105425bb815Sopenharmony_ci  SCAN_STACK_TEMPLATE_STRING,              /**< template string */
106425bb815Sopenharmony_ci  SCAN_STACK_TAGGED_TEMPLATE_LITERAL,      /**< tagged template literal */
107425bb815Sopenharmony_ci  SCAN_STACK_PRIVATE_BLOCK_EARLY,          /**< private block for single statements (force early declarations) */
108425bb815Sopenharmony_ci  SCAN_STACK_PRIVATE_BLOCK,                /**< private block for single statements */
109425bb815Sopenharmony_ci  SCAN_STACK_ARROW_ARGUMENTS,              /**< might be arguments of an arrow function */
110425bb815Sopenharmony_ci  SCAN_STACK_ARROW_EXPRESSION,             /**< expression body of an arrow function */
111425bb815Sopenharmony_ci  SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR,   /**< explicit class constructor */
112425bb815Sopenharmony_ci  SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR,   /**< implicit class constructor */
113425bb815Sopenharmony_ci  SCAN_STACK_CLASS_STATEMENT,              /**< class statement */
114425bb815Sopenharmony_ci  SCAN_STACK_CLASS_EXPRESSION,             /**< class expression */
115425bb815Sopenharmony_ci  SCAN_STACK_CLASS_EXTENDS,                /**< class extends expression */
116425bb815Sopenharmony_ci  SCAN_STACK_FUNCTION_PARAMETERS,          /**< function parameter initializer */
117425bb815Sopenharmony_ci  SCAN_STACK_USE_ASYNC,                    /**< an "async" identifier is used */
118425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
119425bb815Sopenharmony_ci} scan_stack_modes_t;
120425bb815Sopenharmony_ci
121425bb815Sopenharmony_ci/**
122425bb815Sopenharmony_ci * Scanner context flag types.
123425bb815Sopenharmony_ci */
124425bb815Sopenharmony_citypedef enum
125425bb815Sopenharmony_ci{
126425bb815Sopenharmony_ci  SCANNER_CONTEXT_NO_FLAGS = 0, /**< no flags are set */
127425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
128425bb815Sopenharmony_ci  SCANNER_CONTEXT_THROW_ERR_ASYNC_FUNCTION = (1 << 0), /**< throw async function error */
129425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
130425bb815Sopenharmony_ci#if ENABLED (JERRY_DEBUGGER)
131425bb815Sopenharmony_ci  SCANNER_CONTEXT_DEBUGGER_ENABLED = (1 << 1), /**< debugger is enabled */
132425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_DEBUGGER) */
133425bb815Sopenharmony_ci} scanner_context_flags_t;
134425bb815Sopenharmony_ci
135425bb815Sopenharmony_ci/**
136425bb815Sopenharmony_ci * Checks whether the stack top is a for statement start.
137425bb815Sopenharmony_ci */
138425bb815Sopenharmony_ci#define SCANNER_IS_FOR_START(stack_top) \
139425bb815Sopenharmony_ci  ((stack_top) >= SCAN_STACK_FOR_VAR_START && (stack_top) <= SCAN_STACK_FOR_START)
140425bb815Sopenharmony_ci
141425bb815Sopenharmony_ci/**
142425bb815Sopenharmony_ci * Generic descriptor which stores only the start position.
143425bb815Sopenharmony_ci */
144425bb815Sopenharmony_citypedef struct
145425bb815Sopenharmony_ci{
146425bb815Sopenharmony_ci  const uint8_t *source_p; /**< start source byte */
147425bb815Sopenharmony_ci} scanner_source_start_t;
148425bb815Sopenharmony_ci
149425bb815Sopenharmony_ci/**
150425bb815Sopenharmony_ci * Descriptor for storing a binding literal on stack.
151425bb815Sopenharmony_ci */
152425bb815Sopenharmony_citypedef struct
153425bb815Sopenharmony_ci{
154425bb815Sopenharmony_ci  lexer_lit_location_t *literal_p; /**< binding literal */
155425bb815Sopenharmony_ci} scanner_binding_literal_t;
156425bb815Sopenharmony_ci
157425bb815Sopenharmony_ci/**
158425bb815Sopenharmony_ci * Flags for type member of lexer_lit_location_t structure in the literal pool.
159425bb815Sopenharmony_ci */
160425bb815Sopenharmony_citypedef enum
161425bb815Sopenharmony_ci{
162425bb815Sopenharmony_ci  SCANNER_LITERAL_IS_ARG = (1 << 0), /**< literal is argument */
163425bb815Sopenharmony_ci  SCANNER_LITERAL_IS_VAR = (1 << 1), /**< literal is var */
164425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
165425bb815Sopenharmony_ci  /** literal is a destructured argument binding of a possible arrow function */
166425bb815Sopenharmony_ci  SCANNER_LITERAL_IS_ARROW_DESTRUCTURED_ARG = SCANNER_LITERAL_IS_VAR,
167425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
168425bb815Sopenharmony_ci  SCANNER_LITERAL_IS_FUNC = (1 << 2), /**< literal is function */
169425bb815Sopenharmony_ci  SCANNER_LITERAL_NO_REG = (1 << 3), /**< literal cannot be stored in a register */
170425bb815Sopenharmony_ci  SCANNER_LITERAL_IS_LET = (1 << 4), /**< literal is let */
171425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
172425bb815Sopenharmony_ci  /** literal is a function declared in this block (prevents declaring let/const with the same name) */
173425bb815Sopenharmony_ci  SCANNER_LITERAL_IS_FUNC_DECLARATION = SCANNER_LITERAL_IS_LET,
174425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
175425bb815Sopenharmony_ci  SCANNER_LITERAL_IS_CONST = (1 << 5), /**< literal is const */
176425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
177425bb815Sopenharmony_ci  /** literal is a destructured argument binding */
178425bb815Sopenharmony_ci  SCANNER_LITERAL_IS_DESTRUCTURED_ARG = SCANNER_LITERAL_IS_CONST,
179425bb815Sopenharmony_ci  SCANNER_LITERAL_IS_USED = (1 << 6), /**< literal is used */
180425bb815Sopenharmony_ci  SCANNER_LITERAL_EARLY_CREATE = (1 << 7), /**< binding should be created early with ECMA_VALUE_UNINITIALIZED */
181425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
182425bb815Sopenharmony_ci} scanner_literal_type_flags_t;
183425bb815Sopenharmony_ci
184425bb815Sopenharmony_ci/*
185425bb815Sopenharmony_ci * Known combinations:
186425bb815Sopenharmony_ci *
187425bb815Sopenharmony_ci *  SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_FUNC_DECLARATION :
188425bb815Sopenharmony_ci *         function declared in this block
189425bb815Sopenharmony_ci *  SCANNER_LITERAL_IS_LOCAL :
190425bb815Sopenharmony_ci *         module import on global scope, catch block variable otherwise
191425bb815Sopenharmony_ci *  SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_FUNC :
192425bb815Sopenharmony_ci *         a function argument which is reassigned to a function later
193425bb815Sopenharmony_ci *  SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_DESTRUCTURED_ARG :
194425bb815Sopenharmony_ci *         destructured binding argument
195425bb815Sopenharmony_ci *  SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_DESTRUCTURED_ARG | SCANNER_LITERAL_IS_FUNC :
196425bb815Sopenharmony_ci *         destructured binding argument which is reassigned to a function later
197425bb815Sopenharmony_ci */
198425bb815Sopenharmony_ci
199425bb815Sopenharmony_ci/**
200425bb815Sopenharmony_ci * Literal is a local declration (let, const, catch variable, etc.)
201425bb815Sopenharmony_ci */
202425bb815Sopenharmony_ci#define SCANNER_LITERAL_IS_LOCAL (SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_IS_CONST)
203425bb815Sopenharmony_ci
204425bb815Sopenharmony_ci/**
205425bb815Sopenharmony_ci * For statement descriptor.
206425bb815Sopenharmony_ci */
207425bb815Sopenharmony_citypedef struct
208425bb815Sopenharmony_ci{
209425bb815Sopenharmony_ci  /** shared fields of for statements */
210425bb815Sopenharmony_ci  union
211425bb815Sopenharmony_ci  {
212425bb815Sopenharmony_ci    const uint8_t *source_p; /**< start source byte */
213425bb815Sopenharmony_ci    scanner_for_info_t *for_info_p; /**< for info */
214425bb815Sopenharmony_ci  } u;
215425bb815Sopenharmony_ci} scanner_for_statement_t;
216425bb815Sopenharmony_ci
217425bb815Sopenharmony_ci/**
218425bb815Sopenharmony_ci * Switch statement descriptor.
219425bb815Sopenharmony_ci */
220425bb815Sopenharmony_citypedef struct
221425bb815Sopenharmony_ci{
222425bb815Sopenharmony_ci  scanner_case_info_t **last_case_p; /**< last case info */
223425bb815Sopenharmony_ci} scanner_switch_statement_t;
224425bb815Sopenharmony_ci
225425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
226425bb815Sopenharmony_ci
227425bb815Sopenharmony_ci/**
228425bb815Sopenharmony_ci * Types of scanner destructuring bindings.
229425bb815Sopenharmony_ci */
230425bb815Sopenharmony_citypedef enum
231425bb815Sopenharmony_ci{
232425bb815Sopenharmony_ci  /* Update SCANNER_NEEDS_BINDING_LIST after changing these values. */
233425bb815Sopenharmony_ci  SCANNER_BINDING_NONE, /**< not a destructuring binding expression */
234425bb815Sopenharmony_ci  SCANNER_BINDING_VAR, /**< destructuring var binding */
235425bb815Sopenharmony_ci  SCANNER_BINDING_LET, /**< destructuring let binding */
236425bb815Sopenharmony_ci  SCANNER_BINDING_CATCH, /**< destructuring catch binding */
237425bb815Sopenharmony_ci  SCANNER_BINDING_CONST, /**< destructuring const binding */
238425bb815Sopenharmony_ci  SCANNER_BINDING_ARG, /**< destructuring arg binding */
239425bb815Sopenharmony_ci  SCANNER_BINDING_ARROW_ARG, /**< possible destructuring arg binding of an arrow function */
240425bb815Sopenharmony_ci} scanner_binding_type_t;
241425bb815Sopenharmony_ci
242425bb815Sopenharmony_ci/**
243425bb815Sopenharmony_ci * Check whether a binding list is needed for the binding pattern.
244425bb815Sopenharmony_ci */
245425bb815Sopenharmony_ci#define SCANNER_NEEDS_BINDING_LIST(type) ((type) >= SCANNER_BINDING_LET)
246425bb815Sopenharmony_ci
247425bb815Sopenharmony_ci/**
248425bb815Sopenharmony_ci * Scanner binding items for destructuring binding patterns.
249425bb815Sopenharmony_ci */
250425bb815Sopenharmony_citypedef struct scanner_binding_item_t
251425bb815Sopenharmony_ci{
252425bb815Sopenharmony_ci  struct scanner_binding_item_t *next_p; /**< next binding in the list */
253425bb815Sopenharmony_ci  lexer_lit_location_t *literal_p; /**< binding literal */
254425bb815Sopenharmony_ci} scanner_binding_item_t;
255425bb815Sopenharmony_ci
256425bb815Sopenharmony_ci/**
257425bb815Sopenharmony_ci * Scanner binding lists for destructuring binding patterns.
258425bb815Sopenharmony_ci */
259425bb815Sopenharmony_citypedef struct scanner_binding_list_t
260425bb815Sopenharmony_ci{
261425bb815Sopenharmony_ci  struct scanner_binding_list_t *prev_p; /**< prev list */
262425bb815Sopenharmony_ci  scanner_binding_item_t *items_p; /**< list of bindings */
263425bb815Sopenharmony_ci  bool is_nested; /**< is nested binding declaration */
264425bb815Sopenharmony_ci} scanner_binding_list_t;
265425bb815Sopenharmony_ci
266425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
267425bb815Sopenharmony_ci
268425bb815Sopenharmony_ci/**
269425bb815Sopenharmony_ci * Flags for scanner_literal_pool_t structure.
270425bb815Sopenharmony_ci */
271425bb815Sopenharmony_citypedef enum
272425bb815Sopenharmony_ci{
273425bb815Sopenharmony_ci  SCANNER_LITERAL_POOL_FUNCTION = (1 << 0), /**< literal pool represents a function */
274425bb815Sopenharmony_ci  SCANNER_LITERAL_POOL_BLOCK = (1 << 1), /**< literal pool represents a code block */
275425bb815Sopenharmony_ci  SCANNER_LITERAL_POOL_IS_STRICT = (1 << 2), /**< literal pool represents a strict mode code block */
276425bb815Sopenharmony_ci  SCANNER_LITERAL_POOL_CAN_EVAL = (1 << 3), /**< prepare for executing eval in this block */
277425bb815Sopenharmony_ci  SCANNER_LITERAL_POOL_NO_ARGUMENTS = (1 << 4), /**< arguments object must not be constructed */
278425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
279425bb815Sopenharmony_ci  SCANNER_LITERAL_POOL_ARGUMENTS_UNMAPPED = (1 << 5), /**< arguments object should be unmapped */
280425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
281425bb815Sopenharmony_ci  SCANNER_LITERAL_POOL_IN_WITH = (1 << 6), /**< literal pool is in a with statement */
282425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
283425bb815Sopenharmony_ci  SCANNER_LITERAL_POOL_IN_EXPORT = (1 << 7), /**< the declared variables are exported by the module system */
284425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
285425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
286425bb815Sopenharmony_ci  SCANNER_LITERAL_POOL_FUNCTION_STATEMENT = (1 << 8), /**< function statement */
287425bb815Sopenharmony_ci  SCANNER_LITERAL_POOL_GENERATOR = (1 << 9), /**< generator function */
288425bb815Sopenharmony_ci  SCANNER_LITERAL_POOL_ASYNC = (1 << 10), /**< async function */
289425bb815Sopenharmony_ci  SCANNER_LITERAL_POOL_ASYNC_ARROW = (1 << 11), /**< can be an async arrow function */
290425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
291425bb815Sopenharmony_ci} scanner_literal_pool_flags_t;
292425bb815Sopenharmony_ci
293425bb815Sopenharmony_ci/**
294425bb815Sopenharmony_ci * Define a function where no arguments are allowed.
295425bb815Sopenharmony_ci */
296425bb815Sopenharmony_ci#define SCANNER_LITERAL_POOL_FUNCTION_WITHOUT_ARGUMENTS \
297425bb815Sopenharmony_ci  (SCANNER_LITERAL_POOL_FUNCTION | SCANNER_LITERAL_POOL_NO_ARGUMENTS)
298425bb815Sopenharmony_ci
299425bb815Sopenharmony_ci/**
300425bb815Sopenharmony_ci * Getting the generator and async properties of literal pool status flags.
301425bb815Sopenharmony_ci */
302425bb815Sopenharmony_ci#define SCANNER_FROM_LITERAL_POOL_TO_COMPUTED(status_flags) \
303425bb815Sopenharmony_ci  ((uint8_t) ((((status_flags) >> 9) & 0x3) + SCAN_STACK_COMPUTED_PROPERTY))
304425bb815Sopenharmony_ci
305425bb815Sopenharmony_ci/**
306425bb815Sopenharmony_ci * Setting the generator and async properties of literal pool status flags.
307425bb815Sopenharmony_ci */
308425bb815Sopenharmony_ci#define SCANNER_FROM_COMPUTED_TO_LITERAL_POOL(mode) \
309425bb815Sopenharmony_ci  (((mode) - SCAN_STACK_COMPUTED_PROPERTY) << 9)
310425bb815Sopenharmony_ci
311425bb815Sopenharmony_ci/**
312425bb815Sopenharmony_ci * Local literal pool.
313425bb815Sopenharmony_ci */
314425bb815Sopenharmony_citypedef struct scanner_literal_pool_t
315425bb815Sopenharmony_ci{
316425bb815Sopenharmony_ci  struct scanner_literal_pool_t *prev_p; /**< previous literal pool */
317425bb815Sopenharmony_ci  const uint8_t *source_p; /**< source position where the final data needs to be inserted */
318425bb815Sopenharmony_ci  parser_list_t literal_pool; /**< list of literal */
319425bb815Sopenharmony_ci  uint16_t status_flags; /**< combination of scanner_literal_pool_flags_t flags */
320425bb815Sopenharmony_ci  uint16_t no_declarations; /**< size of scope stack required during parsing */
321425bb815Sopenharmony_ci} scanner_literal_pool_t;
322425bb815Sopenharmony_ci
323425bb815Sopenharmony_ci/**
324425bb815Sopenharmony_ci * Scanner context.
325425bb815Sopenharmony_ci */
326425bb815Sopenharmony_cistruct scanner_context_t
327425bb815Sopenharmony_ci{
328425bb815Sopenharmony_ci  uint32_t context_status_flags; /**< original status flags of the context */
329425bb815Sopenharmony_ci  uint8_t mode; /**< scanner mode */
330425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
331425bb815Sopenharmony_ci  uint8_t binding_type; /**< current destructuring binding type */
332425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
333425bb815Sopenharmony_ci  uint16_t status_flags; /**< scanner status flags */
334425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
335425bb815Sopenharmony_ci  scanner_binding_list_t *active_binding_list_p; /**< currently active binding list */
336425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
337425bb815Sopenharmony_ci  scanner_literal_pool_t *active_literal_pool_p; /**< currently active literal pool */
338425bb815Sopenharmony_ci  scanner_switch_statement_t active_switch_statement; /**< currently active switch statement */
339425bb815Sopenharmony_ci  scanner_info_t *end_arguments_p; /**< position of end arguments */
340425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
341425bb815Sopenharmony_ci  const uint8_t *async_source_p; /**< source position for async functions */
342425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
343425bb815Sopenharmony_ci};
344425bb815Sopenharmony_ci
345425bb815Sopenharmony_ci/* Scanner utils. */
346425bb815Sopenharmony_ci
347425bb815Sopenharmony_civoid scanner_raise_error (parser_context_t *context_p);
348425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
349425bb815Sopenharmony_civoid scanner_raise_redeclaration_error (parser_context_t *context_p);
350425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
351425bb815Sopenharmony_ci
352425bb815Sopenharmony_civoid *scanner_malloc (parser_context_t *context_p, size_t size);
353425bb815Sopenharmony_civoid scanner_free (void *ptr, size_t size);
354425bb815Sopenharmony_ci
355425bb815Sopenharmony_cisize_t scanner_get_stream_size (scanner_info_t *info_p, size_t size);
356425bb815Sopenharmony_ciscanner_info_t *scanner_insert_info (parser_context_t *context_p, const uint8_t *source_p, size_t size);
357425bb815Sopenharmony_ciscanner_info_t *scanner_insert_info_before (parser_context_t *context_p, const uint8_t *source_p,
358425bb815Sopenharmony_ci                                            scanner_info_t *start_info_p, size_t size);
359425bb815Sopenharmony_ciscanner_literal_pool_t *scanner_push_literal_pool (parser_context_t *context_p, scanner_context_t *scanner_context_p,
360425bb815Sopenharmony_ci                                                   uint16_t status_flags);
361425bb815Sopenharmony_civoid scanner_pop_literal_pool (parser_context_t *context_p, scanner_context_t *scanner_context_p);
362425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
363425bb815Sopenharmony_civoid scanner_construct_global_block (parser_context_t *context_p, scanner_context_t *scanner_context_p);
364425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
365425bb815Sopenharmony_civoid scanner_filter_arguments (parser_context_t *context_p, scanner_context_t *scanner_context_p);
366425bb815Sopenharmony_cilexer_lit_location_t *scanner_add_custom_literal (parser_context_t *context_p, scanner_literal_pool_t *literal_pool_p,
367425bb815Sopenharmony_ci                                                  const lexer_lit_location_t *literal_location_p);
368425bb815Sopenharmony_cilexer_lit_location_t *scanner_add_literal (parser_context_t *context_p, scanner_context_t *scanner_context_p);
369425bb815Sopenharmony_civoid scanner_add_reference (parser_context_t *context_p, scanner_context_t *scanner_context_p);
370425bb815Sopenharmony_cilexer_lit_location_t *scanner_append_argument (parser_context_t *context_p, scanner_context_t *scanner_context_p);
371425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
372425bb815Sopenharmony_civoid scanner_detect_invalid_var (parser_context_t *context_p, scanner_context_t *scanner_context_p,
373425bb815Sopenharmony_ci                                 lexer_lit_location_t *var_literal_p);
374425bb815Sopenharmony_civoid scanner_detect_invalid_let (parser_context_t *context_p, lexer_lit_location_t *let_literal_p);
375425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
376425bb815Sopenharmony_civoid scanner_detect_eval_call (parser_context_t *context_p, scanner_context_t *scanner_context_p);
377425bb815Sopenharmony_ci
378425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
379425bb815Sopenharmony_civoid scanner_push_class_declaration (parser_context_t *context_p, scanner_context_t *scanner_context_p,
380425bb815Sopenharmony_ci                                     uint8_t stack_mode);
381425bb815Sopenharmony_civoid scanner_push_destructuring_pattern (parser_context_t *context_p, scanner_context_t *scanner_context_p,
382425bb815Sopenharmony_ci                                         uint8_t binding_type, bool is_nested);
383425bb815Sopenharmony_civoid scanner_pop_binding_list (scanner_context_t *scanner_context_p);
384425bb815Sopenharmony_civoid scanner_append_hole (parser_context_t *context_p, scanner_context_t *scanner_context_p);
385425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
386425bb815Sopenharmony_ci
387425bb815Sopenharmony_ci/* Scanner operations. */
388425bb815Sopenharmony_ci
389425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
390425bb815Sopenharmony_civoid scanner_add_async_literal (parser_context_t *context_p, scanner_context_t *scanner_context_p);
391425bb815Sopenharmony_civoid scanner_check_arrow (parser_context_t *context_p, scanner_context_t *scanner_context_p);
392425bb815Sopenharmony_civoid scanner_scan_simple_arrow (parser_context_t *context_p, scanner_context_t *scanner_context_p,
393425bb815Sopenharmony_ci                                const uint8_t *source_p);
394425bb815Sopenharmony_civoid scanner_check_arrow_arg (parser_context_t *context_p, scanner_context_t *scanner_context_p);
395425bb815Sopenharmony_cibool scanner_check_async_function (parser_context_t *context_p, scanner_context_t *scanner_context_p);
396425bb815Sopenharmony_civoid scanner_check_function_after_if (parser_context_t *context_p, scanner_context_t *scanner_context_p);
397425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
398425bb815Sopenharmony_civoid scanner_scan_bracket (parser_context_t *context_p, scanner_context_t *scanner_context_p);
399425bb815Sopenharmony_civoid scanner_check_directives (parser_context_t *context_p, scanner_context_t *scanner_context_p);
400425bb815Sopenharmony_ci
401425bb815Sopenharmony_ci/**
402425bb815Sopenharmony_ci * @}
403425bb815Sopenharmony_ci * @}
404425bb815Sopenharmony_ci * @}
405425bb815Sopenharmony_ci */
406425bb815Sopenharmony_ci
407425bb815Sopenharmony_ci#endif /* !JS_SCANNER_INTERNAL_H */
408