From d0143adc82f688da5afed64529da8cb78e4add3e Mon Sep 17 00:00:00 2001 From: Akos Kiss Date: Tue, 17 Oct 2017 17:11:54 +0200 Subject: [PATCH] Replace JERRY_JS_PARSER feature guard with JERRY_DISABLE_JS_PARSER (#2036) * Replace JERRY_JS_PARSER feature guard with JERRY_DISABLE_JS_PARSER All feature guards of jerry-core are deciding about the inclusion or exclusion of a feature based on the state (defined or undefined) of a macro -- except for the JS parser guard, which requires `JERRY_JS_PARSER` to be defined with a value of either 0 or 1. This has some issues: - The engine cannot be built with a "clean" compiler invocation, i.e., without any `-D` command line macro definitions. This is painful for targets that must use a different build system from the project's own python/cmake-based one. - Some build systems in targets and even some code in jerry-code are already confused about the different semantics of `JERRY_JS_PARSER`, and simply define it without a value and make decisions based on the macro being simply defined or not. This patch renames the guard to `JERRY_DISABLE_JS_PARSER` and makes use of it in jerry-core based on its state, not based on its value. As obvious from the guard name, the default for the JS parser is that it is included in the build. The patch also touches those targets in the repository that explicitly defined the original macro (correctly or incorrectly). * Make cppcheck verbose Cppcheck can be quite slow sometimes, especially on Travis CI, which has a "10 mins without output means failure" rule. As the code base of the project grows, we start to undeterministically fall over that limit. Thus, this PR makes cppcheck verbose to ensure that it keeps Travis CI continuously fed with output. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu --- jerry-core/CMakeLists.txt | 6 ++-- jerry-core/api/jerry.c | 36 +++++++++---------- jerry-core/ecma/operations/ecma-eval.c | 6 ++-- jerry-core/parser/js/byte-code.c | 4 +-- jerry-core/parser/js/common.c | 4 +-- jerry-core/parser/js/js-lexer.c | 4 +-- jerry-core/parser/js/js-parser-expr.c | 4 +-- jerry-core/parser/js/js-parser-mem.c | 4 +-- jerry-core/parser/js/js-parser-scanner.c | 4 +-- jerry-core/parser/js/js-parser-statm.c | 4 +-- jerry-core/parser/js/js-parser-util.c | 4 +-- jerry-core/parser/js/js-parser.c | 10 +++--- targets/curie_bsp/setup.py | 1 - targets/mbedos5/mbed_app.json | 3 +- targets/nuttx-stm32f4/Makefile | 2 +- .../apps/jerryscript/Makefile | 2 +- tools/check-cppcheck.sh | 2 +- 17 files changed, 47 insertions(+), 53 deletions(-) diff --git a/jerry-core/CMakeLists.txt b/jerry-core/CMakeLists.txt index 6bd36d467..13688953b 100644 --- a/jerry-core/CMakeLists.txt +++ b/jerry-core/CMakeLists.txt @@ -168,10 +168,8 @@ if(FEATURE_EXTERNAL_CONTEXT) endif() # JS-Parser -if(FEATURE_JS_PARSER) - set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_JS_PARSER=1) -else() - set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_JS_PARSER=0) +if(NOT FEATURE_JS_PARSER) + set(DEFINES_JERRY ${DEFINES_JERRY} JERRY_DISABLE_JS_PARSER) endif() # Memory statistics diff --git a/jerry-core/api/jerry.c b/jerry-core/api/jerry.c index 1032881ac..8c2c8bee6 100644 --- a/jerry-core/api/jerry.c +++ b/jerry-core/api/jerry.c @@ -55,11 +55,9 @@ JERRY_STATIC_ASSERT ((int) ECMA_INIT_EMPTY == (int) JERRY_INIT_EMPTY && (int) ECMA_INIT_MEM_STATS == (int) JERRY_INIT_MEM_STATS, ecma_init_flag_t_must_be_equal_to_jerry_init_flag_t); -#ifndef JERRY_JS_PARSER -#error JERRY_JS_PARSER must be defined with 0 (disabled) or 1 (enabled) -#elif !JERRY_JS_PARSER && !defined (JERRY_ENABLE_SNAPSHOT_EXEC) -#error JERRY_JS_PARSER or JERRY_ENABLE_SNAPSHOT_EXEC must be defined! -#endif /* !JERRY_JS_PARSER */ +#if defined JERRY_DISABLE_JS_PARSER && !defined JERRY_ENABLE_SNAPSHOT_EXEC +#error JERRY_ENABLE_SNAPSHOT_EXEC must be defined if JERRY_DISABLE_JS_PARSER is defined! +#endif /* JERRY_DISABLE_JS_PARSER && !JERRY_ENABLE_SNAPSHOT_EXEC */ #ifdef JERRY_ENABLE_ERROR_MESSAGES @@ -342,7 +340,7 @@ jerry_parse (const jerry_char_t *source_p, /**< script source */ size_t source_size, /**< script source size */ bool is_strict) /**< strict mode */ { -#if JERRY_JS_PARSER +#ifndef JERRY_DISABLE_JS_PARSER jerry_assert_api_available (); ecma_compiled_code_t *bytecode_data_p; @@ -368,13 +366,13 @@ jerry_parse (const jerry_char_t *source_p, /**< script source */ ecma_bytecode_deref (bytecode_data_p); return ecma_make_object_value (func_obj_p); -#else /* !JERRY_JS_PARSER */ +#else /* JERRY_DISABLE_JS_PARSER */ JERRY_UNUSED (source_p); JERRY_UNUSED (source_size); JERRY_UNUSED (is_strict); return ecma_raise_syntax_error (ECMA_ERR_MSG ("The parser has been disabled.")); -#endif /* JERRY_JS_PARSER */ +#endif /* !JERRY_DISABLE_JS_PARSER */ } /* jerry_parse */ /** @@ -393,7 +391,7 @@ jerry_parse_named_resource (const jerry_char_t *resource_name_p, /**< resource n size_t source_size, /**< script source size */ bool is_strict) /**< strict mode */ { -#if defined JERRY_DEBUGGER && defined JERRY_JS_PARSER +#if defined JERRY_DEBUGGER && !defined JERRY_DISABLE_JS_PARSER if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) { jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE_NAME, @@ -401,10 +399,10 @@ jerry_parse_named_resource (const jerry_char_t *resource_name_p, /**< resource n resource_name_p, resource_name_length); } -#else /* !(JERRY_DEBUGGER && JERRY_JS_PARSER) */ +#else /* !(JERRY_DEBUGGER && !JERRY_DISABLE_JS_PARSER) */ JERRY_UNUSED (resource_name_p); JERRY_UNUSED (resource_name_length); -#endif /* JERRY_DEBUGGER && JERRY_JS_PARSER */ +#endif /* JERRY_DEBUGGER && !JERRY_DISABLE_JS_PARSER */ return jerry_parse (source_p, source_size, is_strict); } /* jerry_parse_named_resource */ @@ -425,7 +423,7 @@ jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (u size_t source_size, /**< script source size */ bool is_strict) /**< strict mode */ { -#if defined JERRY_DEBUGGER && defined JERRY_JS_PARSER +#if defined JERRY_DEBUGGER && !defined JERRY_DISABLE_JS_PARSER if (JERRY_CONTEXT (debugger_flags) & JERRY_DEBUGGER_CONNECTED) { jerry_debugger_send_string (JERRY_DEBUGGER_SOURCE_CODE_NAME, @@ -433,12 +431,12 @@ jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (u resource_name_p, resource_name_length); } -#else /* !(JERRY_DEBUGGER && JERRY_JS_PARSER) */ +#else /* !(JERRY_DEBUGGER && !JERRY_DISABLE_JS_PARSER) */ JERRY_UNUSED (resource_name_p); JERRY_UNUSED (resource_name_length); -#endif /* JERRY_DEBUGGER && JERRY_JS_PARSER */ +#endif /* JERRY_DEBUGGER && !JERRY_DISABLE_JS_PARSER */ -#if JERRY_JS_PARSER +#ifndef JERRY_DISABLE_JS_PARSER jerry_assert_api_available (); ecma_compiled_code_t *bytecode_data_p; @@ -470,7 +468,7 @@ jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (u ecma_bytecode_deref (bytecode_data_p); return ecma_make_object_value (func_obj_p); -#else /* !JERRY_JS_PARSER */ +#else /* JERRY_DISABLE_JS_PARSER */ JERRY_UNUSED (arg_list_p); JERRY_UNUSED (arg_list_size); JERRY_UNUSED (source_p); @@ -478,7 +476,7 @@ jerry_parse_function (const jerry_char_t *resource_name_p, /**< resource name (u JERRY_UNUSED (is_strict); return ecma_raise_syntax_error (ECMA_ERR_MSG ("The parser has been disabled.")); -#endif /* JERRY_JS_PARSER */ +#endif /* !JERRY_DISABLE_JS_PARSER */ } /* jerry_parse_function */ /** @@ -745,9 +743,9 @@ bool jerry_is_feature_enabled (const jerry_feature_t feature) #ifdef JERRY_ENABLE_ERROR_MESSAGES || feature == JERRY_FEATURE_ERROR_MESSAGES #endif /* JERRY_ENABLE_ERROR_MESSAGES */ -#if JERRY_JS_PARSER +#ifndef JERRY_DISABLE_JS_PARSER || feature == JERRY_FEATURE_JS_PARSER -#endif /* JERRY_JS_PARSER */ +#endif /* !JERRY_DISABLE_JS_PARSER */ #ifdef JMEM_STATS || feature == JERRY_FEATURE_MEM_STATS #endif /* JMEM_STATS */ diff --git a/jerry-core/ecma/operations/ecma-eval.c b/jerry-core/ecma/operations/ecma-eval.c index 59e480f07..5376493e0 100644 --- a/jerry-core/ecma/operations/ecma-eval.c +++ b/jerry-core/ecma/operations/ecma-eval.c @@ -81,7 +81,7 @@ ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, /**< code characters b bool is_direct, /**< is eval called directly (ECMA-262 v5, 15.1.2.1.1) */ bool is_called_from_strict_mode_code) /**< is eval is called from strict mode code */ { -#if JERRY_JS_PARSER +#ifndef JERRY_DISABLE_JS_PARSER JERRY_ASSERT (code_p != NULL); ecma_compiled_code_t *bytecode_data_p; @@ -101,14 +101,14 @@ ecma_op_eval_chars_buffer (const lit_utf8_byte_t *code_p, /**< code characters b } return vm_run_eval (bytecode_data_p, is_direct); -#else /* !JERRY_JS_PARSER */ +#else /* JERRY_DISABLE_JS_PARSER */ JERRY_UNUSED (code_p); JERRY_UNUSED (code_buffer_size); JERRY_UNUSED (is_direct); JERRY_UNUSED (is_called_from_strict_mode_code); return ecma_raise_syntax_error (ECMA_ERR_MSG ("The parser has been disabled.")); -#endif /* JERRY_JS_PARSER */ +#endif /* !JERRY_DISABLE_JS_PARSER */ } /* ecma_op_eval_chars_buffer */ /** diff --git a/jerry-core/parser/js/byte-code.c b/jerry-core/parser/js/byte-code.c index 9ee17b7ad..43502c03d 100644 --- a/jerry-core/parser/js/byte-code.c +++ b/jerry-core/parser/js/byte-code.c @@ -21,7 +21,7 @@ JERRY_STATIC_ASSERT ((sizeof (cbc_uint8_arguments_t) % sizeof (jmem_cpointer_t)) JERRY_STATIC_ASSERT ((sizeof (cbc_uint16_arguments_t) % sizeof (jmem_cpointer_t)) == 0, sizeof_cbc_uint16_arguments_t_must_be_divisible_by_sizeof_jmem_cpointer_t); -#if JERRY_JS_PARSER +#ifndef JERRY_DISABLE_JS_PARSER /** \addtogroup parser Parser * @{ @@ -84,4 +84,4 @@ const char * const cbc_ext_names[] = * @} */ -#endif /* JERRY_JS_PARSER */ +#endif /* !JERRY_DISABLE_JS_PARSER */ diff --git a/jerry-core/parser/js/common.c b/jerry-core/parser/js/common.c index 9982e811e..9c31333f4 100644 --- a/jerry-core/parser/js/common.c +++ b/jerry-core/parser/js/common.c @@ -16,7 +16,7 @@ #include "common.h" #include "ecma-helpers.h" -#if JERRY_JS_PARSER +#ifndef JERRY_DISABLE_JS_PARSER /** \addtogroup parser Parser * @{ @@ -136,4 +136,4 @@ util_print_literal (lexer_literal_t *literal_p) /**< literal */ * @} */ -#endif /* JERRY_JS_PARSER */ +#endif /* !JERRY_DISABLE_JS_PARSER */ diff --git a/jerry-core/parser/js/js-lexer.c b/jerry-core/parser/js/js-lexer.c index dc96c4621..85ca96ded 100644 --- a/jerry-core/parser/js/js-lexer.c +++ b/jerry-core/parser/js/js-lexer.c @@ -20,7 +20,7 @@ #include "js-parser-internal.h" #include "lit-char-helpers.h" -#if JERRY_JS_PARSER +#ifndef JERRY_DISABLE_JS_PARSER /** \addtogroup parser Parser * @{ @@ -2355,4 +2355,4 @@ lexer_compare_identifier_to_current (parser_context_t *context_p, /**< co * @} */ -#endif /* JERRY_JS_PARSER */ +#endif /* !JERRY_DISABLE_JS_PARSER */ diff --git a/jerry-core/parser/js/js-parser-expr.c b/jerry-core/parser/js/js-parser-expr.c index 1132c4c12..5b1bbad92 100644 --- a/jerry-core/parser/js/js-parser-expr.c +++ b/jerry-core/parser/js/js-parser-expr.c @@ -19,7 +19,7 @@ #include "lit-char-helpers.h" #endif /* !CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS */ -#if JERRY_JS_PARSER +#ifndef JERRY_DISABLE_JS_PARSER /** \addtogroup parser Parser * @{ @@ -1774,4 +1774,4 @@ parser_parse_expression (parser_context_t *context_p, /**< context */ * @} */ -#endif /* JERRY_JS_PARSER */ +#endif /* !JERRY_DISABLE_JS_PARSER */ diff --git a/jerry-core/parser/js/js-parser-mem.c b/jerry-core/parser/js/js-parser-mem.c index 96e3ee44d..543df3d84 100644 --- a/jerry-core/parser/js/js-parser-mem.c +++ b/jerry-core/parser/js/js-parser-mem.c @@ -15,7 +15,7 @@ #include "js-parser-internal.h" -#if JERRY_JS_PARSER +#ifndef JERRY_DISABLE_JS_PARSER /** \addtogroup mem Memory allocation * @{ @@ -678,4 +678,4 @@ parser_stack_iterator_write (parser_stack_iterator_t *iterator, /**< iterator */ * @} */ -#endif /* JERRY_JS_PARSER */ +#endif /* !JERRY_DISABLE_JS_PARSER */ diff --git a/jerry-core/parser/js/js-parser-scanner.c b/jerry-core/parser/js/js-parser-scanner.c index 68a56c1c9..c3f0447e9 100644 --- a/jerry-core/parser/js/js-parser-scanner.c +++ b/jerry-core/parser/js/js-parser-scanner.c @@ -19,7 +19,7 @@ #include "lit-char-helpers.h" #endif /* !CONFIG_DISABLE_ES2015_TEMPLATE_STRINGS */ -#if JERRY_JS_PARSER +#ifndef JERRY_DISABLE_JS_PARSER /** \addtogroup parser Parser * @{ @@ -771,4 +771,4 @@ parser_scan_until (parser_context_t *context_p, /**< context */ * @} */ -#endif /* JERRY_JS_PARSER */ +#endif /* !JERRY_DISABLE_JS_PARSER */ diff --git a/jerry-core/parser/js/js-parser-statm.c b/jerry-core/parser/js/js-parser-statm.c index 2ea192490..e06810b38 100644 --- a/jerry-core/parser/js/js-parser-statm.c +++ b/jerry-core/parser/js/js-parser-statm.c @@ -15,7 +15,7 @@ #include "js-parser-internal.h" -#if JERRY_JS_PARSER +#ifndef JERRY_DISABLE_JS_PARSER #ifdef JERRY_DEBUGGER #include "jcontext.h" @@ -2245,4 +2245,4 @@ parser_free_jumps (parser_stack_iterator_t iterator) /**< iterator position */ * @} */ -#endif /* JERRY_JS_PARSER */ +#endif /* !JERRY_DISABLE_JS_PARSER */ diff --git a/jerry-core/parser/js/js-parser-util.c b/jerry-core/parser/js/js-parser-util.c index 3c81a94b5..4b2c55451 100644 --- a/jerry-core/parser/js/js-parser-util.c +++ b/jerry-core/parser/js/js-parser-util.c @@ -15,7 +15,7 @@ #include "js-parser-internal.h" -#if JERRY_JS_PARSER +#ifndef JERRY_DISABLE_JS_PARSER /** \addtogroup parser Parser * @{ @@ -953,4 +953,4 @@ parser_error_to_string (parser_error_t error) /**< error code */ * @} */ -#endif /* JERRY_JS_PARSER */ +#endif /* !JERRY_DISABLE_JS_PARSER */ diff --git a/jerry-core/parser/js/js-parser.c b/jerry-core/parser/js/js-parser.c index ab9042a21..740af1467 100644 --- a/jerry-core/parser/js/js-parser.c +++ b/jerry-core/parser/js/js-parser.c @@ -20,7 +20,7 @@ #include "jcontext.h" #include "js-parser-internal.h" -#if JERRY_JS_PARSER +#ifndef JERRY_DISABLE_JS_PARSER /** \addtogroup parser Parser * @{ @@ -2668,7 +2668,7 @@ parser_send_breakpoints (parser_context_t *context_p, /**< context */ #endif /* JERRY_DEBUGGER */ -#endif /* JERRY_JS_PARSER */ +#endif /* !JERRY_DISABLE_JS_PARSER */ /** * Parse EcamScript source code @@ -2688,7 +2688,7 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */ bool is_strict, /**< strict mode */ ecma_compiled_code_t **bytecode_data_p) /**< [out] JS bytecode */ { -#if JERRY_JS_PARSER +#ifndef JERRY_DISABLE_JS_PARSER parser_error_location_t parser_error; #ifdef JERRY_DEBUGGER @@ -2748,7 +2748,7 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */ #endif /* JERRY_ENABLE_ERROR_MESSAGES */ } return ecma_make_simple_value (ECMA_SIMPLE_VALUE_TRUE); -#else /* !JERRY_JS_PARSER */ +#else /* JERRY_DISABLE_JS_PARSER */ JERRY_UNUSED (arg_list_p); JERRY_UNUSED (arg_list_size); JERRY_UNUSED (source_p); @@ -2757,7 +2757,7 @@ parser_parse_script (const uint8_t *arg_list_p, /**< function argument list */ JERRY_UNUSED (bytecode_data_p); return ecma_raise_syntax_error (ECMA_ERR_MSG ("The parser has been disabled.")); -#endif /* JERRY_JS_PARSER */ +#endif /* !JERRY_DISABLE_JS_PARSER */ } /* parser_parse_script */ /** diff --git a/targets/curie_bsp/setup.py b/targets/curie_bsp/setup.py index 45e8dabb9..38a5a9b05 100755 --- a/targets/curie_bsp/setup.py +++ b/targets/curie_bsp/setup.py @@ -85,7 +85,6 @@ def build_jerry_data(jerry_path): jerry_cflags = [ '-DCONFIG_MEM_HEAP_AREA_SIZE=10*1024', '-DJERRY_NDEBUG', - '-DJERRY_JS_PARSER', '-DJERRY_DISABLE_HEAVY_DEBUG', '-DCONFIG_DISABLE_NUMBER_BUILTIN', '-DCONFIG_DISABLE_STRING_BUILTIN', diff --git a/targets/mbedos5/mbed_app.json b/targets/mbedos5/mbed_app.json index 9c956c620..67a1c8ccd 100644 --- a/targets/mbedos5/mbed_app.json +++ b/targets/mbedos5/mbed_app.json @@ -3,6 +3,5 @@ "NRF52_DK": { "target.uart_hwfc": 0 } - }, - "macros": ["JERRY_JS_PARSER 1"] + } } diff --git a/targets/nuttx-stm32f4/Makefile b/targets/nuttx-stm32f4/Makefile index 55ded68e2..1f63b0990 100644 --- a/targets/nuttx-stm32f4/Makefile +++ b/targets/nuttx-stm32f4/Makefile @@ -25,7 +25,7 @@ APPNAME = jerry ROOT_DIR = ../../.. PRIORITY = $(CONFIG_JERRYSCRIPT_PRIORITY) STACKSIZE = $(CONFIG_JERRYSCRIPT_STACKSIZE) -CFLAGS += -std=c99 -DJERRY_NDEBUG -DJERRY_JS_PARSER '-DCONFIG_MEM_HEAP_AREA_SIZE=$(CONFIG_JERRYSCRIPT_HEAPSIZE)' +CFLAGS += -std=c99 -DJERRY_NDEBUG '-DCONFIG_MEM_HEAP_AREA_SIZE=$(CONFIG_JERRYSCRIPT_HEAPSIZE)' CFLAGS += -I$(ROOT_DIR)/ $(shell find $(ROOT_DIR)/jerryscript/jerry-core -type d | sed -r -e 's/^/-I/g') CFLAGS += -I$(ROOT_DIR)/jerryscript/jerry-libm/include CFLAGS += -I$(ROOT_DIR)/jerryscript/jerry-ext/include diff --git a/targets/tizenrt-artik053/apps/jerryscript/Makefile b/targets/tizenrt-artik053/apps/jerryscript/Makefile index 0b166a895..b56817422 100644 --- a/targets/tizenrt-artik053/apps/jerryscript/Makefile +++ b/targets/tizenrt-artik053/apps/jerryscript/Makefile @@ -78,7 +78,7 @@ APPNAME = jerry ROOT_DIR = ../../../.. PRIORITY = $(CONFIG_JERRYSCRIPT_PRIORITY) STACKSIZE = $(CONFIG_JERRYSCRIPT_STACKSIZE) -CFLAGS += -std=c99 -DJERRY_NDEBUG -DJERRY_JS_PARSER '-DCONFIG_MEM_HEAP_AREA_SIZE=$(CONFIG_JERRYSCRIPT_HEAPSIZE)' +CFLAGS += -std=c99 -DJERRY_NDEBUG '-DCONFIG_MEM_HEAP_AREA_SIZE=$(CONFIG_JERRYSCRIPT_HEAPSIZE)' CFLAGS += -I$(ROOT_DIR)/ $(shell find $(ROOT_DIR)/jerryscript/jerry-core -type d | sed -r -e 's/^/-I/g') CFLAGS += -I$(ROOT_DIR)/jerryscript/jerry-ext/include diff --git a/tools/check-cppcheck.sh b/tools/check-cppcheck.sh index 6f7cb5426..cca8d6f17 100755 --- a/tools/check-cppcheck.sh +++ b/tools/check-cppcheck.sh @@ -38,7 +38,7 @@ done cppcheck -j$CPPCHECK_JOBS --force \ --language=c --std=c99 \ --enable=warning,style,performance,portability,information \ - --quiet --template="{file}:{line}: {severity}({id}): {message}" \ + --template="{file}:{line}: {severity}({id}): {message}" \ --error-exitcode=1 \ --exitcode-suppressions=tools/cppcheck/suppressions-list \ --suppressions-list=tools/cppcheck/suppressions-list \