@@ -118,34 +118,38 @@ current_token_equals_to (const char *str)
118
118
return false ;
119
119
}
120
120
121
+ /* *
122
+ * Compare specified string to literal
123
+ *
124
+ * @return true - if the literal contains exactly the specified string,
125
+ * false - otherwise.
126
+ */
121
127
static bool
122
- current_token_equals_to_literal (literal lit)
128
+ string_equals_to_literal (const ecma_char_t *str_p, /* *< characters buffer */
129
+ ecma_length_t length, /* *< string's length */
130
+ literal lit) /* *< literal */
123
131
{
124
132
if (lit.type == LIT_STR)
125
133
{
126
- if (lit.data .lp .length != (ecma_length_t ) (buffer - token_start))
127
- {
128
- return false ;
129
- }
130
- if (!strncmp ((const char *) lit.data .lp .str , token_start, lit.data .lp .length ))
134
+ if (lit.data .lp .length == length
135
+ && strncmp ((const char *) lit.data .lp .str , (const char *) str_p, length) == 0 )
131
136
{
132
137
return true ;
133
138
}
134
139
}
135
140
else if (lit.type == LIT_MAGIC_STR)
136
141
{
137
- const char *str = (const char *) ecma_get_magic_string_zt (lit.data .magic_str_id );
138
- if (strlen (str) != (size_t ) (buffer - token_start))
139
- {
140
- return false ;
141
- }
142
- if (!strncmp (str, token_start, strlen (str)))
142
+ const char *magic_str_p = (const char *) ecma_get_magic_string_zt (lit.data .magic_str_id );
143
+
144
+ if (strlen (magic_str_p) == length
145
+ && strncmp (magic_str_p, (const char *) str_p, length) == 0 )
143
146
{
144
147
return true ;
145
148
}
146
149
}
150
+
147
151
return false ;
148
- }
152
+ } /* string_equals_to_literal */
149
153
150
154
static literal
151
155
adjust_string_ptrs (literal lit, size_t diff)
@@ -189,39 +193,53 @@ add_string_to_string_cache (const ecma_char_t* str, ecma_length_t length)
189
193
return res;
190
194
}
191
195
192
- static literal
193
- add_current_token_to_string_cache (void )
194
- {
195
- return add_string_to_string_cache ((ecma_char_t *) token_start, (ecma_length_t ) (buffer - token_start));
196
- }
197
-
196
+ /* *
197
+ * Convert string to token of specified type
198
+ *
199
+ * @return token descriptor
200
+ */
198
201
static token
199
- convert_current_token_to_token (token_type tt)
202
+ convert_string_to_token (token_type tt, /* *< token type */
203
+ const ecma_char_t *str_p, /* *< characters buffer */
204
+ ecma_length_t length) /* *< string's length */
200
205
{
201
- JERRY_ASSERT (token_start );
206
+ JERRY_ASSERT (str_p != NULL );
202
207
203
208
for (literal_index_t i = 0 ; i < STACK_SIZE (literals); i++)
204
209
{
205
210
const literal lit = STACK_ELEMENT (literals, i);
206
211
if ((lit.type == LIT_STR || lit.type == LIT_MAGIC_STR)
207
- && current_token_equals_to_literal ( lit))
212
+ && string_equals_to_literal (str_p, length, lit))
208
213
{
209
214
return create_token (tt, i);
210
215
}
211
216
}
212
217
213
- literal lit = create_literal_from_str (token_start, ( ecma_length_t ) (buffer - token_start) );
218
+ literal lit = create_literal_from_str (str_p, length );
214
219
JERRY_ASSERT (lit.type == LIT_STR || lit.type == LIT_MAGIC_STR);
215
220
if (lit.type == LIT_STR)
216
221
{
217
- lit = add_current_token_to_string_cache ( );
222
+ lit = add_string_to_string_cache (str_p, length );
218
223
}
219
224
220
225
STACK_PUSH (literals, lit);
221
226
222
227
return create_token (tt, (literal_index_t ) (STACK_SIZE (literals) - 1 ));
223
228
}
224
229
230
+ /* *
231
+ * Convert string, currently processed by lexer (see also: token_start, buffer) to token of specified type
232
+ *
233
+ * @return token descriptor
234
+ */
235
+ static token
236
+ convert_current_token_to_token (token_type tt) /* *< token type */
237
+ {
238
+ JERRY_ASSERT (token_start != NULL );
239
+
240
+ return convert_string_to_token (tt, (const ecma_char_t *) token_start, (ecma_length_t ) (buffer - token_start));
241
+ } /* convert_current_token_to_token */
242
+
225
243
/* If TOKEN represents a keyword, return decoded keyword,
226
244
if TOKEN represents a Future Reserved Word, return KW_RESERVED,
227
245
otherwise return KW_NONE. */
0 commit comments