Skip to content

Commit e1f20ad

Browse files
committed
Use code unit instead of code point
JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]
1 parent 005f73a commit e1f20ad

File tree

7 files changed

+70
-72
lines changed

7 files changed

+70
-72
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-global.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
1+
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
22
* Copyright 2015-2016 University of Szeged.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -96,25 +96,25 @@ ecma_builtin_global_object_print (ecma_value_t this_arg __attr_unused___, /**< t
9696

9797
while (utf8_str_curr_p < utf8_str_end_p)
9898
{
99-
ecma_char_t code_point = lit_utf8_read_next (&utf8_str_curr_p);
99+
ecma_char_t code_unit = lit_utf8_read_next (&utf8_str_curr_p);
100100

101-
if (code_point == LIT_CHAR_NULL)
101+
if (code_unit == LIT_CHAR_NULL)
102102
{
103103
printf ("\\u0000");
104104
}
105-
else if (code_point <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
105+
else if (code_unit <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
106106
{
107-
printf ("%c", (char) code_point);
107+
printf ("%c", (char) code_unit);
108108
}
109109
else
110110
{
111-
JERRY_STATIC_ASSERT (sizeof (code_point) == 2,
111+
JERRY_STATIC_ASSERT (sizeof (code_unit) == 2,
112112
size_of_code_point_must_be_equal_to_2_bytes);
113113

114-
uint32_t byte_high = (uint32_t) JRT_EXTRACT_BIT_FIELD (ecma_char_t, code_point,
114+
uint32_t byte_high = (uint32_t) JRT_EXTRACT_BIT_FIELD (ecma_char_t, code_unit,
115115
JERRY_BITSINBYTE,
116116
JERRY_BITSINBYTE);
117-
uint32_t byte_low = (uint32_t) JRT_EXTRACT_BIT_FIELD (ecma_char_t, code_point,
117+
uint32_t byte_low = (uint32_t) JRT_EXTRACT_BIT_FIELD (ecma_char_t, code_unit,
118118
0,
119119
JERRY_BITSINBYTE);
120120

@@ -801,9 +801,9 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri __attr_unused___,
801801
continue;
802802
}
803803

804-
lit_code_point_t decoded_byte;
804+
ecma_char_t decoded_byte;
805805

806-
if (!lit_read_code_point_from_hex (input_char_p + 1, 2, &decoded_byte))
806+
if (!lit_read_code_unit_from_hex (input_char_p + 1, 2, &decoded_byte))
807807
{
808808
ret_value = ecma_raise_uri_error (ECMA_ERR_MSG (""));
809809
break;
@@ -857,9 +857,9 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri __attr_unused___,
857857
continue;
858858
}
859859

860-
lit_code_point_t decoded_byte;
860+
ecma_char_t decoded_byte;
861861

862-
if (!lit_read_code_point_from_hex (input_char_p + 1, 2, &decoded_byte))
862+
if (!lit_read_code_unit_from_hex (input_char_p + 1, 2, &decoded_byte))
863863
{
864864
ret_value = ecma_raise_uri_error (ECMA_ERR_MSG (""));
865865
break;
@@ -916,16 +916,16 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri __attr_unused___,
916916
}
917917
else
918918
{
919-
lit_code_point_t cp;
919+
ecma_char_t chr;
920920

921-
if (!lit_read_code_point_from_hex (input_char_p + 1, 2, &cp)
922-
|| ((cp & LIT_UTF8_EXTRA_BYTE_MASK) != LIT_UTF8_EXTRA_BYTE_MARKER))
921+
if (!lit_read_code_unit_from_hex (input_char_p + 1, 2, &chr)
922+
|| ((chr & LIT_UTF8_EXTRA_BYTE_MASK) != LIT_UTF8_EXTRA_BYTE_MARKER))
923923
{
924924
is_valid = false;
925925
break;
926926
}
927927

928-
octets[i] = (lit_utf8_byte_t) cp;
928+
octets[i] = (lit_utf8_byte_t) chr;
929929
input_char_p += URI_ENCODED_BYTE_SIZE;
930930
}
931931
}

jerry-core/ecma/builtin-objects/ecma-builtin-json.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,15 @@ ecma_builtin_json_parse_string (ecma_json_token_t *token_p) /**< token argument
178178
}
179179
case LIT_CHAR_LOWERCASE_U:
180180
{
181-
lit_code_point_t code_point;
181+
ecma_char_t code_unit;
182182

183-
if (!(lit_read_code_point_from_hex (current_p + 1, 4, &code_point)))
183+
if (!(lit_read_code_unit_from_hex (current_p + 1, 4, &code_unit)))
184184
{
185185
return;
186186
}
187187

188188
current_p += 5;
189-
write_p += lit_code_point_to_cesu8 (code_point, write_p);
189+
write_p += lit_code_unit_to_utf8 (code_unit, write_p);
190190
continue;
191191
}
192192
default:

jerry-core/lit/lit-char-helpers.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* Copyright 2015 Samsung Electronics Co., Ltd.
1+
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
2+
* Copyright 2016 University of Szeged.
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* you may not use this file except in compliance with the License.
@@ -283,38 +284,38 @@ lit_char_hex_to_int (ecma_char_t c) /**< code unit, corresponding to
283284

284285
/**
285286
* Parse the next number_of_characters hexadecimal character,
286-
* and construct a code point from them. The buffer must
287+
* and construct a code unit from them. The buffer must
287288
* be zero terminated.
288289
*
289290
* @return true if decoding was successful, false otherwise
290291
*/
291292
bool
292-
lit_read_code_point_from_hex (lit_utf8_byte_t *buf_p, /**< buffer with characters */
293-
lit_utf8_size_t number_of_characters, /**< number of characters to be read */
294-
lit_code_point_t *out_code_point_p) /**< [out] decoded result */
293+
lit_read_code_unit_from_hex (lit_utf8_byte_t *buf_p, /**< buffer with characters */
294+
lit_utf8_size_t number_of_characters, /**< number of characters to be read */
295+
ecma_char_ptr_t out_code_unit_p) /**< [out] decoded result */
295296
{
296-
lit_code_point_t code_point = 0;
297+
ecma_char_t code_unit = LIT_CHAR_NULL;
297298

298299
JERRY_ASSERT (number_of_characters >= 2 && number_of_characters <= 4);
299300

300301
for (lit_utf8_size_t i = 0; i < number_of_characters; i++)
301302
{
302-
code_point <<= 4;
303+
code_unit = (ecma_char_t) (code_unit << 4u);
303304

304305
if (*buf_p >= LIT_CHAR_ASCII_DIGITS_BEGIN
305306
&& *buf_p <= LIT_CHAR_ASCII_DIGITS_END)
306307
{
307-
code_point |= (uint32_t) (*buf_p - LIT_CHAR_ASCII_DIGITS_BEGIN);
308+
code_unit |= (ecma_char_t) (*buf_p - LIT_CHAR_ASCII_DIGITS_BEGIN);
308309
}
309310
else if (*buf_p >= LIT_CHAR_ASCII_LOWERCASE_LETTERS_HEX_BEGIN
310311
&& *buf_p <= LIT_CHAR_ASCII_LOWERCASE_LETTERS_HEX_END)
311312
{
312-
code_point |= (uint32_t) (*buf_p - (LIT_CHAR_ASCII_LOWERCASE_LETTERS_HEX_BEGIN - 10));
313+
code_unit |= (ecma_char_t) (*buf_p - (LIT_CHAR_ASCII_LOWERCASE_LETTERS_HEX_BEGIN - 10));
313314
}
314315
else if (*buf_p >= LIT_CHAR_ASCII_UPPERCASE_LETTERS_HEX_BEGIN
315316
&& *buf_p <= LIT_CHAR_ASCII_UPPERCASE_LETTERS_HEX_END)
316317
{
317-
code_point |= (uint32_t) (*buf_p - (LIT_CHAR_ASCII_UPPERCASE_LETTERS_HEX_BEGIN - 10));
318+
code_unit |= (ecma_char_t) (*buf_p - (LIT_CHAR_ASCII_UPPERCASE_LETTERS_HEX_BEGIN - 10));
318319
}
319320
else
320321
{
@@ -324,9 +325,9 @@ lit_read_code_point_from_hex (lit_utf8_byte_t *buf_p, /**< buffer with character
324325
buf_p++;
325326
}
326327

327-
*out_code_point_p = code_point;
328+
*out_code_unit_p = code_unit;
328329
return true;
329-
} /* lit_read_code_point_from_hex */
330+
} /* lit_read_code_unit_from_hex */
330331

331332
/**
332333
* Check if specified character is a word character (part of IsWordChar abstract operation)

jerry-core/lit/lit-char-helpers.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
2+
* Copyright 2016 University of Szeged.
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* you may not use this file except in compliance with the License.
@@ -18,6 +19,8 @@
1819

1920
#include "lit-globals.h"
2021

22+
#define LIT_CHAR_UNDEF ((ecma_char_t) 0xFFFF) /* undefined character */
23+
2124
/*
2225
* Format control characters (ECMA-262 v5, Table 1)
2326
*/
@@ -213,7 +216,7 @@ extern bool lit_char_is_hex_digit (ecma_char_t);
213216
extern uint32_t lit_char_hex_to_int (ecma_char_t);
214217

215218
/* read a hex encoded code point from a zero terminated buffer */
216-
bool lit_read_code_point_from_hex (lit_utf8_byte_t *, lit_utf8_size_t, lit_code_point_t *);
219+
bool lit_read_code_unit_from_hex (lit_utf8_byte_t *, lit_utf8_size_t, ecma_char_ptr_t);
217220

218221
/**
219222
* Null character

jerry-core/parser/regexp/re-compiler.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@
4141
*/
4242
static void
4343
re_append_char_class (void *re_ctx_p, /**< RegExp compiler context */
44-
uint32_t start, /**< character class range from */
45-
uint32_t end) /**< character class range to */
44+
ecma_char_t start, /**< character class range from */
45+
ecma_char_t end) /**< character class range to */
4646
{
4747
re_compiler_ctx_t *ctx_p = (re_compiler_ctx_t *) re_ctx_p;
48-
re_append_char (ctx_p->bytecode_ctx_p, (ecma_char_t) start);
49-
re_append_char (ctx_p->bytecode_ctx_p, (ecma_char_t) end);
48+
re_append_char (ctx_p->bytecode_ctx_p, start);
49+
re_append_char (ctx_p->bytecode_ctx_p, end);
5050
ctx_p->parser_ctx_p->num_of_classes++;
5151
} /* re_append_char_class */
5252

0 commit comments

Comments
 (0)