Skip to content

Commit f77c8ff

Browse files
committed
WIP: Generate lit-magic-strings.inc.h
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. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
1 parent da07252 commit f77c8ff

File tree

51 files changed

+1070
-32
lines changed

Some content is hidden

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

51 files changed

+1070
-32
lines changed

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_ARRAYBUFFER_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_ARRAYBUFFER_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_ARRAYBUFFER_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_ARRAYBUFFER_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"

jerry-core/ecma/builtin-objects/ecma-builtin-evalerror-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_ERROR_BUILTINS
23+
2224
/* Object properties:
2325
* (property name, object pointer getter) */
2426

@@ -37,4 +39,6 @@ STRING_VALUE (LIT_MAGIC_STRING_MESSAGE,
3739
LIT_MAGIC_STRING__EMPTY,
3840
ECMA_PROPERTY_CONFIGURABLE_WRITABLE)
3941

42+
#endif /* !CONFIG_DISABLE_ERROR_BUILTINS */
43+
4044
#include "ecma-builtin-helpers-macro-undefs.inc.h"

jerry-core/ecma/builtin-objects/ecma-builtin-evalerror.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_ERROR_BUILTINS
23+
2224
/* Number properties:
2325
* (property name, number value, writable, enumerable, configurable) */
2426

@@ -35,4 +37,6 @@ OBJECT_VALUE (LIT_MAGIC_STRING_PROTOTYPE,
3537
ECMA_BUILTIN_ID_EVAL_ERROR_PROTOTYPE,
3638
ECMA_PROPERTY_FIXED)
3739

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

0 commit comments

Comments
 (0)