Skip to content

Commit 67c641e

Browse files
authored
Generate lit-magic-strings.inc.h (#1690)
Currently, `lit-magic-strings.inc.h` is manually maintained. This has several drawbacks: - keeping the list of magic strings sorted first by length then alphabetically is error prone, - it is easy to leave unused magic strings in the list by accident (e.g., `LIT_MAGIC_STRING_JERRY_UL` is defined as a magic string but not used anywhere in the code) and, - it is very hard to add `CONFIG_DISABLE_*_BUILTIN` guards to the list, even though there are several magic strings, which are used in some of the configurations only (e.g, "setPrototypeOf" is used in ES2015 only). To ease the maintenance of magic strings, this commit moves the definition of magic strings to a config file (`lit-magic-strings.ini`), and adds `tools/gen-magic-strings.py` to generate the `.inc.h` file from this config file and from the use cases of the strings in the code. - The magic strings in the config file can appear in any order, the generator will ensure that they are correctly sorted. - The generator skips those definitions that are not used anywhere (and emits a warning to signal that such definitions can be removed). - The generator applies the same guards to the definitions in the `.inc.h` file as found in the code around the use of the strings to optimize for size. The commit also changes some builtin-related `.inc.h` files by adding guards that don't affect functionality but improve the results of the generator. To ensure that the invocation of the generator does not get forgotten, the commit also adds `tools/check-magic-strings.sh` and binds it into the testing infrastructure. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
1 parent 5231829 commit 67c641e

File tree

57 files changed

+1161
-38
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1161
-38
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sudo: required
66

77
env:
88
matrix:
9-
- OPTS="--check-signed-off-travis --check-cppcheck --check-doxygen --check-vera --check-license"
9+
- OPTS="--check-signed-off-travis --check-cppcheck --check-doxygen --check-vera --check-license --check-magic-strings"
1010
- OPTS="--jerry-debugger"
1111
- OPTS="--jerry-tests --jerry-test-suite"
1212
- OPTS="--jerry-tests --jerry-test-suite --toolchain=cmake/toolchain_linux_armv7l.cmake" TIMEOUT=300 INSTALL_QEMU_ARM=yes

docs/04.INTERNALS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ Several references to single allocated number are not supported. Each reference
261261

262262
### String
263263

264-
Strings in JerryScript are not just character sequences, but can hold numbers and so-called magic ids too. For common character sequences there is a table in the read only memory that contains magic id and character sequence pairs. If a string is already in this table, the magic id of its string is stored, not the character sequence itself. Using numbers speeds up the property access. These techniques save memory.
264+
Strings in JerryScript are not just character sequences, but can hold numbers and so-called magic ids too. For common character sequences (defined in `./jerry-core/lit/lit-magic-strings.ini`) there is a table in the read only memory that contains magic id and character sequence pairs. If a string is already in this table, the magic id of its string is stored, not the character sequence itself. Using numbers speeds up the property access. These techniques save memory.
265265

266266
### Object / Lexical Environment
267267

jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.inc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "ecma-builtin-helpers-macro-defines.inc.h"
2121

22+
#ifndef CONFIG_DISABLE_ARRAY_BUILTIN
23+
2224
/* Object properties:
2325
* (property name, object pointer getter) */
2426

@@ -59,4 +61,6 @@ ROUTINE (LIT_MAGIC_STRING_FILTER, ecma_builtin_array_prototype_object_filter, 2,
5961
ROUTINE (LIT_MAGIC_STRING_REDUCE, ecma_builtin_array_prototype_object_reduce, NON_FIXED, 1)
6062
ROUTINE (LIT_MAGIC_STRING_REDUCE_RIGHT_UL, ecma_builtin_array_prototype_object_reduce_right, NON_FIXED, 1)
6163

64+
#endif /* !CONFIG_DISABLE_ARRAY_BUILTIN */
65+
6266
#include "ecma-builtin-helpers-macro-undefs.inc.h"

jerry-core/ecma/builtin-objects/ecma-builtin-array.inc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "ecma-builtin-helpers-macro-defines.inc.h"
2121

22+
#ifndef CONFIG_DISABLE_ARRAY_BUILTIN
23+
2224
/* Object properties:
2325
* (property name, object pointer getter) */
2426

@@ -39,4 +41,6 @@ NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
3941
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
4042
ROUTINE (LIT_MAGIC_STRING_IS_ARRAY_UL, ecma_builtin_array_object_is_array, 1, 1)
4143

44+
#endif /* !CONFIG_DISABLE_ARRAY_BUILTIN */
45+
4246
#include "ecma-builtin-helpers-macro-undefs.inc.h"

jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer-prototype.inc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "ecma-builtin-helpers-macro-defines.inc.h"
2121

22+
#ifndef CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN
23+
2224
/* Object properties:
2325
* (property name, object pointer getter) */
2426

@@ -35,4 +37,6 @@ ACCESSOR_READ_ONLY (LIT_MAGIC_STRING_BYTE_LENGTH_UL,
3537
* (property name, C routine name, arguments number or NON_FIXED, value of the routine's length property) */
3638
ROUTINE (LIT_MAGIC_STRING_SLICE, ecma_builtin_arraybuffer_prototype_object_slice, 2, 2)
3739

40+
#endif /* !CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN */
41+
3842
#include "ecma-builtin-helpers-macro-undefs.inc.h"

jerry-core/ecma/builtin-objects/ecma-builtin-arraybuffer.inc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "ecma-builtin-helpers-macro-defines.inc.h"
2121

22+
#ifndef CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN
23+
2224
/* Number properties:
2325
* (property name, number value, writable, enumerable, configurable) */
2426

@@ -39,4 +41,6 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
3941
/* ES2015 24.1.3.1 */
4042
ROUTINE (LIT_MAGIC_STRING_IS_VIEW_UL, ecma_builtin_arraybuffer_object_is_view, 1, 1)
4143

44+
#endif /* !CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN */
45+
4246
#include "ecma-builtin-helpers-macro-undefs.inc.h"

jerry-core/ecma/builtin-objects/ecma-builtin-boolean-prototype.inc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "ecma-builtin-helpers-macro-defines.inc.h"
2121

22+
#ifndef CONFIG_DISABLE_BOOLEAN_BUILTIN
23+
2224
/* Object properties:
2325
* (property name, object pointer getter) */
2426

@@ -32,4 +34,6 @@ OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
3234
ROUTINE (LIT_MAGIC_STRING_TO_STRING_UL, ecma_builtin_boolean_prototype_object_to_string, 0, 0)
3335
ROUTINE (LIT_MAGIC_STRING_VALUE_OF_UL, ecma_builtin_boolean_prototype_object_value_of, 0, 0)
3436

37+
#endif /* !CONFIG_DISABLE_BOOLEAN_BUILTIN */
38+
3539
#include "ecma-builtin-helpers-macro-undefs.inc.h"

jerry-core/ecma/builtin-objects/ecma-builtin-boolean.inc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "ecma-builtin-helpers-macro-defines.inc.h"
2121

22+
#ifndef CONFIG_DISABLE_BOOLEAN_BUILTIN
23+
2224
/* Object properties:
2325
* (property name, object pointer getter) */
2426

@@ -35,4 +37,6 @@ NUMBER_VALUE (LIT_MAGIC_STRING_LENGTH,
3537
1,
3638
ECMA_PROPERTY_FIXED)
3739

40+
#endif /* !CONFIG_DISABLE_BOOLEAN_BUILTIN */
41+
3842
#include "ecma-builtin-helpers-macro-undefs.inc.h"

jerry-core/ecma/builtin-objects/ecma-builtin-date-prototype.inc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "ecma-builtin-helpers-macro-defines.inc.h"
2121

22+
#ifndef CONFIG_DISABLE_DATE_BUILTIN
23+
2224
OBJECT_VALUE (LIT_MAGIC_STRING_CONSTRUCTOR,
2325
ECMA_BUILTIN_ID_DATE,
2426
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
@@ -75,4 +77,6 @@ ROUTINE (LIT_MAGIC_STRING_TO_GMT_STRING_UL, ECMA_DATE_PROTOTYPE_TO_UTC_STRING, 0
7577

7678
#endif /* !CONFIG_DISABLE_ANNEXB_BUILTIN */
7779

80+
#endif /* !CONFIG_DISABLE_DATE_BUILTIN */
81+
7882
#include "ecma-builtin-helpers-macro-undefs.inc.h"

jerry-core/ecma/builtin-objects/ecma-builtin-date.inc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "ecma-builtin-helpers-macro-defines.inc.h"
2121

22+
#ifndef CONFIG_DISABLE_DATE_BUILTIN
23+
2224
/* ECMA-262 v5, 15.9.4.1 */
2325
OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
2426
ECMA_BUILTIN_ID_DATE_PROTOTYPE,
@@ -32,4 +34,6 @@ ROUTINE (LIT_MAGIC_STRING_PARSE, ecma_builtin_date_parse, 1, 1)
3234
ROUTINE (LIT_MAGIC_STRING_UTC_U, ecma_builtin_date_utc, NON_FIXED, 7)
3335
ROUTINE (LIT_MAGIC_STRING_NOW, ecma_builtin_date_now, 0, 0)
3436

37+
#endif /* !CONFIG_DISABLE_DATE_BUILTIN */
38+
3539
#include "ecma-builtin-helpers-macro-undefs.inc.h"

0 commit comments

Comments
 (0)