From d1206830dd995f09d6f2666ceb39044b37043466 Mon Sep 17 00:00:00 2001 From: vpozdyayev Date: Wed, 31 Jul 2024 05:54:37 +0300 Subject: [PATCH 001/104] Bring macros back into C/C++ builders dafe804937a0edc8bc18e9de2e9818f886960352 --- build/conf/compilers/gnu_compiler.conf | 60 ++------------------ build/conf/compilers/msvc_compiler.conf | 3 - build/conf/settings.conf | 2 - build/ymake.core.conf | 73 ++++++++----------------- 4 files changed, 29 insertions(+), 109 deletions(-) diff --git a/build/conf/compilers/gnu_compiler.conf b/build/conf/compilers/gnu_compiler.conf index 9781f752f604..659c8936e901 100644 --- a/build/conf/compilers/gnu_compiler.conf +++ b/build/conf/compilers/gnu_compiler.conf @@ -204,31 +204,8 @@ _C_CPP_KV_STYLE_NEW=${hide;kv:_C_CPP_KV_STYLE_P} ${hide;kv:_C_CPP_KV_STYLE_PC} _C_CPP_KV_STYLE_P=p CC _C_CPP_KV_STYLE_PC=pc green -_CPP_ARGS=\ - $CLANG_STATIC_ANALYZER_OPTIONS && \ - $CLANG_TIDY_ARGS \ - $YNDEXER_ARGS \ - $RETRY_ARGS \ - $CXX_COMPILER_OLD \ - $C_FLAGS_PLATFORM \ - $GCC_COMPILE_FLAGS \ - $CXXFLAGS \ - $CL_MACRO_INFO \ - $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \ - $_COMPILER_TIME_TRACE_FLAGS \ - $EXTRA_OUTPUT \ - $SRCFLAGS \ - $_LANG_CFLAGS_VALUE \ - ${input:SRC} \ - $TOOLCHAIN_ENV \ - $YNDEXER_OUTPUT \ - && $_COMPILER_TIME_TRACE_POSTPROCESS \ - $_C_CPP_KV_STYLE - -_CPP_ARGS_NEW_CMD_0=\ - $CLANG_STATIC_ANALYZER_OPTIONS_NEW - -_CPP_ARGS_NEW_CMD_1_1=\ +_CPP_ARGS_NEW=\ + $CLANG_STATIC_ANALYZER_OPTIONS_NEW && \ $CLANG_TIDY_ARGS \ $YNDEXER_ARGS \ $RETRY_ARGS \ @@ -239,36 +216,14 @@ _CPP_ARGS_NEW_CMD_1_1=\ $CL_MACRO_INFO \ $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \ $_COMPILER_TIME_TRACE_FLAGS \ - $EXTRA_OUTPUT -_CPP_ARGS_NEW_CMD_1_2=\ - $SRCFLAGS \ - $_LANG_CFLAGS_VALUE_NEW \ - ${input:SRC} \ - $TOOLCHAIN_ENV \ - $YNDEXER_OUTPUT -_CPP_ARGS_NEW_CMD_2=\ - $_COMPILER_TIME_TRACE_POSTPROCESS \ - $_C_CPP_KV_STYLE_NEW \ - $SCU_NAME_KV_NEW - -_C_ARGS=\ - $CLANG_TIDY_ARGS \ - $YNDEXER_ARGS \ - $RETRY_ARGS \ - $C_COMPILER_OLD \ - $C_FLAGS_PLATFORM \ - $GCC_COMPILE_FLAGS \ - $CFLAGS \ - $CL_MACRO_INFO \ - $CL_MACRO_INFO_DISABLE_CACHE__NO_UID__ \ - $_COMPILER_TIME_TRACE_FLAGS \ - $CONLYFLAGS \ $EXTRA_OUTPUT \ $SRCFLAGS \ + $_LANG_CFLAGS_VALUE_NEW \ ${input:SRC} \ $TOOLCHAIN_ENV \ $YNDEXER_OUTPUT \ - $_C_CPP_KV_STYLE + && $_COMPILER_TIME_TRACE_POSTPROCESS \ + $_C_CPP_KV_STYLE_NEW _C_ARGS_NEW=\ $CLANG_TIDY_ARGS \ @@ -313,10 +268,7 @@ _SRC_C_NODEPS_CMD=\ _FORCE_CPP_FLAGS=-x c++ -_SRC_CPP_CMD=$_CPP_ARGS -_SRC_CPP_CMD_NEW= $_CPP_ARGS_NEW_CMD_0 && $_CPP_ARGS_NEW_CMD_1_1 $_CPP_ARGS_NEW_CMD_1_2 && $_CPP_ARGS_NEW_CMD_2 -_SRC_CPP_CMD_NEW_FORCED=$_CPP_ARGS_NEW_CMD_0 $CLANG_STATIC_ANALYZER_OPTIONS_NEW_FORCED && $_CPP_ARGS_NEW_CMD_1_1 $_FORCE_CPP_FLAGS $_CPP_ARGS_NEW_CMD_1_2 && $_CPP_ARGS_NEW_CMD_2 -_SRC_C_CMD=$_C_ARGS +_SRC_CPP_CMD_NEW=$_CPP_ARGS_NEW _SRC_C_CMD_NEW=$_C_ARGS_NEW _SRC_M_CMD=$SRC_c($SRC $SRCFLAGS) _SRC_MASM_CMD=$_EMPTY_CMD diff --git a/build/conf/compilers/msvc_compiler.conf b/build/conf/compilers/msvc_compiler.conf index 0f3f0484e0b3..9550b9effb54 100644 --- a/build/conf/compilers/msvc_compiler.conf +++ b/build/conf/compilers/msvc_compiler.conf @@ -92,10 +92,7 @@ _C_CPP_KV_STYLE_P=p CC _C_CPP_KV_STYLE_PC=pc yellow _SRC_C_NODEPS_CMD=${TOOLCHAIN_ENV} ${CL_WRAPPER} ${C_COMPILER} /c /Fo${OUTFILE} ${SRC} ${EXTRA_C_FLAGS} ${pre=/I :INC} ${CFLAGS} ${hide;kv:"soe"} ${hide;kv:"p CC"} ${hide;kv:"pc yellow"} -_SRC_CPP_CMD=${TOOLCHAIN_ENV} ${CL_WRAPPER} ${CXX_COMPILER_OLD} /c /Fo$_COMPILE_OUTPUTS ${input:SRC} ${EXTRA_C_FLAGS} ${pre=/I :_C__INCLUDE} ${CXXFLAGS} ${SRCFLAGS} ${_LANG_CFLAGS_VALUE} ${hide;kv:"soe"} ${hide;kv:"p CC"} ${hide;kv:"pc yellow"} _SRC_CPP_CMD_NEW=${TOOLCHAIN_ENV} ${CL_WRAPPER} ${CXX_COMPILER} /c /Fo$_COMPILE_OUTPUTS ${input:SRC} ${EXTRA_C_FLAGS} ${pre=/I :_C__INCLUDE} ${CXXFLAGS} ${SRCFLAGS} ${_LANG_CFLAGS_VALUE_NEW} ${hide;kv:"soe"} ${hide;kv:_C_CPP_KV_STYLE_P} ${hide;kv:_C_CPP_KV_STYLE_PC} -_SRC_CPP_CMD_NEW_FORCED=${TOOLCHAIN_ENV} ${CL_WRAPPER} ${CXX_COMPILER} /c /Fo$_COMPILE_OUTPUTS ${input:SRC} ${EXTRA_C_FLAGS} ${pre=/I :_C__INCLUDE} ${CXXFLAGS} $_FORCE_CPP_FLAGS ${SRCFLAGS} ${_LANG_CFLAGS_VALUE_NEW} ${hide;kv:"soe"} ${hide;kv:_C_CPP_KV_STYLE_P} ${hide;kv:_C_CPP_KV_STYLE_PC} -_SRC_C_CMD=${TOOLCHAIN_ENV} ${CL_WRAPPER} ${C_COMPILER_OLD} /c /Fo$_COMPILE_OUTPUTS ${input:SRC} ${EXTRA_C_FLAGS} ${pre=/I :_C__INCLUDE} ${CFLAGS} ${CONLYFLAGS} ${SRCFLAGS} ${hide;kv:"soe"} ${hide;kv:"p CC"} ${hide;kv:"pc yellow"} _SRC_C_CMD_NEW=${TOOLCHAIN_ENV} ${CL_WRAPPER} ${C_COMPILER} /c /Fo$_COMPILE_OUTPUTS ${input:SRC} ${EXTRA_C_FLAGS} ${pre=/I :_C__INCLUDE} ${CFLAGS} ${CONLYFLAGS} ${SRCFLAGS} ${hide;kv:"soe"} ${hide;kv:_C_CPP_KV_STYLE_P} ${hide;kv:_C_CPP_KV_STYLE_PC} _SRC_M_CMD=$_EMPTY_CMD _SRC_MASM_CMD=${cwd:ARCADIA_BUILD_ROOT} ${TOOLCHAIN_ENV} ${ML_WRAPPER} ${MASM_COMPILER_OLD} ${MASMFLAGS} ${SRCFLAGS} $_MASM_IO ${hide;kv:"p AS"} ${hide;kv:"pc yellow"} diff --git a/build/conf/settings.conf b/build/conf/settings.conf index 6b34cbdc44b3..a35a68a0cb0a 100644 --- a/build/conf/settings.conf +++ b/build/conf/settings.conf @@ -41,11 +41,9 @@ _FOLDABLE_VARS=\ _COMPILER_TIME_TRACE_FLAGS \ _COMPILER_TIME_TRACE_GRANULARITY \ _COMPILER_TIME_TRACE_POSTPROCESS \ - _CPP_ARGS \ _CROSS_SUFFIX \ _CXX_DEFINES \ _CXX_FLAGS \ - _C_ARGS \ _C_CPP_KV_STYLE \ _C_FLAGS \ _C_FOPTIONS \ diff --git a/build/ymake.core.conf b/build/ymake.core.conf index bdb2f6ec92e1..8b864929bfe2 100644 --- a/build/ymake.core.conf +++ b/build/ymake.core.conf @@ -47,6 +47,9 @@ FALSE=no MODULE_PREFIX= MODULE_SUFFIX= +# do not keep it undefined, since we directly subsitute it in LLVM_COMPILE_CXX etc. +WINDOWS=no + # tag:src-processing tag:internal ### @usage: _SRC(Ext Src Flags) # internal ### @@ -187,13 +190,6 @@ CLANG_CSA_ROOT=${CLANG_CSA16_RESOURCE_GLOBAL} CLANG_CSA_BIN=${CLANG_CSA16_RESOURCE_GLOBAL}/bin/clang when ($CLANG_SA_ENABLE == "yes" && $_CLANG_SA_CONFIG && $CLANG_CSA_ROOT) { PEERDIR+=build/platform/clang/clang-static-analyzer - CLANG_STATIC_ANALYZER_OPTIONS=$YMAKE_PYTHON3 ${input:"build/scripts/clang_static_analyzer.py"} \ - "--testing-src" ${input:SRC} \ - "--clang-bin" $CLANG_CSA_BIN \ - "--source-root" $(SOURCE_ROOT) \ - "--config-file" ${input:_CLANG_SA_CONFIG} \ - "--plugins-begin" "dummy_param" $_CLANG_SA_UNWRAP_PLUGINS($CLANG_SA_PLUGINS) "--plugins-end" \ - $GCC_COMPILE_FLAGS $CXXFLAGS $SRCFLAGS CLANG_STATIC_ANALYZER_OPTIONS_NEW=$YMAKE_PYTHON3 ${input:"build/scripts/clang_static_analyzer.py"} \ "--testing-src" ${input:SRC} \ "--clang-bin" $CLANG_CSA_BIN \ @@ -201,12 +197,9 @@ when ($CLANG_SA_ENABLE == "yes" && $_CLANG_SA_CONFIG && $CLANG_CSA_ROOT) { "--config-file" ${input:_CLANG_SA_CONFIG} \ "--plugins-begin" "dummy_param" $CLANG_SA_PLUGINS "--plugins-end" \ $GCC_COMPILE_FLAGS $CXXFLAGS $SRCFLAGS - CLANG_STATIC_ANALYZER_OPTIONS_NEW_FORCED=$_FORCE_CPP_FLAGS } otherwise { - CLANG_STATIC_ANALYZER_OPTIONS= CLANG_STATIC_ANALYZER_OPTIONS_NEW= - CLANG_STATIC_ANALYZER_OPTIONS_NEW_FORCED= } FAIL_MODULE_CMD=$YMAKE_PYTHON3 ${input:"build/scripts/fail_module_cmd.py"} $TARGET ${hide;kv:"p ER"} ${hide;kv:"pc red"} @@ -3207,7 +3200,7 @@ _SRC_CPP_TOOLCHAIN_INFO_PEER= # tag:src-processing macro _SRC("cpp", SRC, SRCFLAGS...) { - .CMD=$_SRC_CPP_CMD_NEW + .CMD=$_SRC_cpp_new($SRC $SRCFLAGS) .PEERDIR=$_SRC_CPP_TOOLCHAIN_INFO_PEER .SEM=target_sources PRIVATE ${input:SRC} ${hide;output;suf=${OBJ_SUF}.o:SRC} && target_options-privates-ITEM && target_options-privates-option target_sources && target_options-privates-args ${input:SRC} ${hide;output;suf=${OBJ_SUF}.o:SRC} $_ADD_EXTRA_FLAGS($SRCFLAGS) .STRUCT_CMD=yes @@ -3215,7 +3208,7 @@ macro _SRC("cpp", SRC, SRCFLAGS...) { # tag:src-processing macro _SRC("cxx", SRC, SRCFLAGS...) { - .CMD=$_SRC_CPP_CMD_NEW + .CMD=$_SRC_cpp_new($SRC $SRCFLAGS) .PEERDIR=$_SRC_CPP_TOOLCHAIN_INFO_PEER .SEM=target_sources PRIVATE ${input:SRC} ${hide;output;suf=${OBJ_SUF}.o:SRC} && target_options-privates-ITEM && target_options-privates-option target_sources && target_options-privates-args ${input:SRC} ${hide;output;suf=${OBJ_SUF}.o:SRC} $_ADD_EXTRA_FLAGS($SRCFLAGS) .STRUCT_CMD=yes @@ -3223,7 +3216,7 @@ macro _SRC("cxx", SRC, SRCFLAGS...) { # tag:src-processing macro _SRC("cc", SRC, SRCFLAGS...) { - .CMD=$_SRC_CPP_CMD_NEW + .CMD=$_SRC_cpp_new($SRC $SRCFLAGS) .PEERDIR=$_SRC_CPP_TOOLCHAIN_INFO_PEER .SEM=target_sources PRIVATE ${input:SRC} ${hide;output;suf=${OBJ_SUF}.o:SRC} && target_options-privates-ITEM && target_options-privates-option target_sources && target_options-privates-args ${input:SRC} ${hide;output;suf=${OBJ_SUF}.o:SRC} $_ADD_EXTRA_FLAGS($SRCFLAGS) .STRUCT_CMD=yes @@ -3231,7 +3224,7 @@ macro _SRC("cc", SRC, SRCFLAGS...) { # tag:src-processing macro _SRC("auxcpp", SRC, SRCFLAGS...) { - .CMD=$_SRC_CPP_CMD_NEW_FORCED + .CMD=$_SRC_cpp_new($SRC $_FORCE_CPP_FLAGS $SRCFLAGS) .PEERDIR=$_SRC_CPP_TOOLCHAIN_INFO_PEER .SEM=target_sources PRIVATE ${input:SRC} ${hide;output;suf=${OBJ_SUF}.o:SRC} && target_options-privates-ITEM && target_options-privates-option target_sources && target_options-privates-args ${input:SRC} ${hide;output;suf=${OBJ_SUF}.o:SRC} $_ADD_EXTRA_FLAGS($_FORCE_CPP_FLAGS $SRCFLAGS) .STRUCT_CMD=yes @@ -3239,7 +3232,7 @@ macro _SRC("auxcpp", SRC, SRCFLAGS...) { # tag:src-processing macro _SRC("C", SRC, SRCFLAGS...) { - .CMD=$_SRC_CPP_CMD_NEW + .CMD=$_SRC_cpp_new($SRC $SRCFLAGS) .PEERDIR=$_SRC_CPP_TOOLCHAIN_INFO_PEER .SEM=target_sources PRIVATE ${input:SRC} ${hide;output;suf=${OBJ_SUF}.o:SRC} && target_options-privates-ITEM && target_options-privates-option target_sources && target_options-privates-args ${input:SRC} ${hide;output;suf=${OBJ_SUF}.o:SRC} $_ADD_EXTRA_FLAGS($SRCFLAGS) .STRUCT_CMD=yes @@ -3247,7 +3240,7 @@ macro _SRC("C", SRC, SRCFLAGS...) { # tag:src-processing macro _SRC("c", SRC, SRCFLAGS...) { - .CMD=$_SRC_C_CMD_NEW + .CMD=$_SRC_c_new($SRC $SRCFLAGS) .PEERDIR=$_SRC_CPP_TOOLCHAIN_INFO_PEER .SEM=target_sources PRIVATE ${input:SRC} ${hide;output;suf=${OBJ_SUF}.o:SRC} && target_options-privates-ITEM && target_options-privates-option target_sources && target_options-privates-args ${input:SRC} ${hide;output;suf=${OBJ_SUF}.o:SRC} $_ADD_EXTRA_FLAGS($SRCFLAGS $USER_CONLYFLAGS $USER_CONLYFLAGS_GLOBAL) .STRUCT_CMD=yes @@ -3373,12 +3366,11 @@ macro _SRC_PYSRC(SRC, SRCFLAGS...) { # tag:src-processing macro _SRC_c_nodeps(SRC, OUTFILE, INC...) { + # this macro is used by link commands; TODO switch to the new engine after those .CMD=$_SRC_C_NODEPS_CMD } -# Custom flags for generated cpp-files. To support another generator: -# - insert additional file extension before .cpp into generated cpp-file name -# - update _LANG_CFLAGS_FILTER variable. Don't forget to add ' SKIP ' after flag list +# Custom flags for generated cpp-files # # ragel5 and ragel6 generated terrible code which makes use of goto's in switch statements. # This triggers -Werror-implicit-fallthrough due to `unannotated fall-through between switch labels`. @@ -3390,44 +3382,23 @@ macro _SRC_c_nodeps(SRC, OUTFILE, INC...) { # generated sources ## tag:src-processing when ($CLANG == "yes") { - _LANG_CFLAGS_FILTER=\ - ${pre=-Wno-implicit-fallthrough -fno-profile-instr-generate -fno-coverage-mapping SKIP ;ext=.rl5:SRC} \ - ${pre=-Wno-implicit-fallthrough -fno-profile-instr-generate -fno-coverage-mapping SKIP ;ext=.rl6:SRC} \ - ${pre=-Wno-implicit-fallthrough -fno-profile-instr-generate -fno-coverage-mapping SKIP ;ext=.pyx:SRC} _LANG_CFLAGS_RL=-Wno-implicit-fallthrough -fno-profile-instr-generate -fno-coverage-mapping _LANG_CFLAGS_SWG=-Wno-deprecated-declarations -fno-profile-instr-generate -fno-coverage-mapping _LANG_CFLAGS_LEX=-Wno-unused-variable -fno-profile-instr-generate -fno-coverage-mapping _LANG_CFLAGS_BISON=-Wno-unused-but-set-variable -Wno-deprecated-copy -fno-profile-instr-generate -fno-coverage-mapping } otherwise { - _LANG_CFLAGS_FILTER=\ - ${pre=-Wno-implicit-fallthrough SKIP ;ext=.rl5:SRC} \ - ${pre=-Wno-implicit-fallthrough SKIP ;ext=.rl6:SRC} \ - ${pre=-Wno-implicit-fallthrough SKIP ;ext=.pyx:SRC} _LANG_CFLAGS_RL=-Wno-implicit-fallthrough _LANG_CFLAGS_SWG=-Wno-deprecated-declarations _LANG_CFLAGS_LEX=-Wno-unused-variable _LANG_CFLAGS_BISON=-Wno-unused-but-set-variable -Wno-deprecated-copy } -# tag:src-processing -# Magic macro for removing file name from result (file name is passed as unused SKIP parameter) -macro _FILTER_EXTS(SKIP="", FLAGS...) { - .CMD=$FLAGS -} - -# tag:src-processing -macro _LANG_CFLAGS(SRC) { - .CMD=$_FILTER_EXTS($_LANG_CFLAGS_FILTER) -} - # tag:src-processing # ymake bug workaround: variables followed a macros call in .CMD are not substituted and are placed in result as is # Pack macro call into a variable and use it in _SRC_CPP_CMD instead of macro call -_LANG_CFLAGS_VALUE= _LANG_CFLAGS_VALUE_NEW= when ($CLANG == "yes" || $CLANG_CL == "yes" || $GCC == "yes") { - _LANG_CFLAGS_VALUE=$_LANG_CFLAGS(${noext:SRC}) _LANG_CFLAGS_VALUE_NEW=\ ${pre=$_LANG_CFLAGS_BISON;clear;ext=.y;noext;input:SRC} \ ${pre=$_LANG_CFLAGS_BISON;clear;ext=.ypp;noext;input:SRC} \ @@ -3441,26 +3412,24 @@ when ($CLANG == "yes" || $CLANG_CL == "yes" || $GCC == "yes") { # Allows to add single compilation unit name to the node's 'kv' section. # This is used by the coverage machinery to instrument only the necessary sources # when --coverage-prefix-filter is specified. For more info see DEVTOOLSSUPPORT-16891 -SCU_NAME_KV= SCU_NAME_KV_NEW= SCU_NAME_KV_NEW_BODY=scu_name ${input:SRC} when ($CLANG_COVERAGE && $CLANG_COVERAGE != "no" && $USE_SCU_VALUE == "yes") { - SCU_NAME_KV=${hide;kv:"scu_name $KV_VAL"} SCU_NAME_KV_NEW=${hide;kv:SCU_NAME_KV_NEW_BODY} } -macro _ADD_SCU_NAME(KV_VAL) { - .CMD=$SCU_NAME_KV +macro _ADD_SCU_NAME_NEW(KV_VAL) { + .CMD=$SCU_NAME_KV_NEW } # tag:src-processing -macro _SRC_cpp(SRC, COMPILE_OUT_SUFFIX="", SRCFLAGS...) { - .CMD=$_SRC_CPP_CMD $_ADD_SCU_NAME(${input:SRC}) +macro _SRC_cpp_new(SRC, COMPILE_OUT_SUFFIX="", SRCFLAGS...) { + .CMD=$_SRC_CPP_CMD_NEW && $_ADD_SCU_NAME_NEW(${input:SRC}) } # tag:src-processing -macro _SRC_c(SRC, COMPILE_OUT_SUFFIX="", SRCFLAGS...) { - .CMD=$_SRC_C_CMD $_ADD_SCU_NAME(${input:SRC}) +macro _SRC_c_new(SRC, COMPILE_OUT_SUFFIX="", SRCFLAGS...) { + .CMD=$_SRC_C_CMD_NEW $_ADD_SCU_NAME_NEW(${input:SRC}) } # tag:src-processing @@ -3607,13 +3576,15 @@ macro SRCS(FILES...) { # tag:c-specific macro _SRC_C_CUSTOM_FLAGS(SRC, COMPILE_OUT_SUFFIX, CUSTOM_FLAGS...) { - .CMD=$_SRC_c($SRC COMPILE_OUT_SUFFIX ${COMPILE_OUT_SUFFIX} ${CUSTOM_FLAGS}) + .CMD=$_SRC_c_new($SRC COMPILE_OUT_SUFFIX ${COMPILE_OUT_SUFFIX} ${CUSTOM_FLAGS}) .SEM=target_sources_custom $COMPILE_OUT_SUFFIX SRCS ${input:SRC} ${hide;output;suf=${COMPILE_OUT_SUFFIX}.o:SRC} CUSTOM_FLAGS $CUSTOM_FLAGS $USER_CONLYFLAGS $USER_CONLYFLAGS_GLOBAL && target_macroses-ITEM && target_macroses-macro target_sources_custom && target_macroses-args $COMPILE_OUT_SUFFIX SRCS ${input:SRC} ${hide;output;suf=${COMPILE_OUT_SUFFIX}.o:SRC} CUSTOM_FLAGS $CUSTOM_FLAGS $USER_CONLYFLAGS $USER_CONLYFLAGS_GLOBAL + .STRUCT_CMD=yes } macro _SRC_CPP_CUSTOM_FLAGS(SRC, COMPILE_OUT_SUFFIX, CUSTOM_FLAGS...) { - .CMD=$_SRC_cpp($SRC COMPILE_OUT_SUFFIX ${COMPILE_OUT_SUFFIX} ${CUSTOM_FLAGS}) + .CMD=$_SRC_cpp_new($SRC COMPILE_OUT_SUFFIX ${COMPILE_OUT_SUFFIX} ${CUSTOM_FLAGS}) .SEM=target_sources_custom $COMPILE_OUT_SUFFIX SRCS ${input:SRC} ${hide;output;suf=${COMPILE_OUT_SUFFIX}.o:SRC} CUSTOM_FLAGS $CUSTOM_FLAGS && target_macroses-ITEM && target_macroses-macro target_sources_custom && target_macroses-args $COMPILE_OUT_SUFFIX SRCS ${input:SRC} ${hide;output;suf=${COMPILE_OUT_SUFFIX}.o:SRC} CUSTOM_FLAGS $CUSTOM_FLAGS + .STRUCT_CMD=yes } @@ -4776,6 +4747,7 @@ macro CLANG_EMIT_AST_CXX(Input, Output, Opts...) { macro LLVM_COMPILE_CXX(Input, Output, Opts...) { .CMD=$YMAKE_PYTHON ${input:"build/scripts/clang_wrapper.py"} $WINDOWS ${CLANG_BC_ROOT}/bin/clang++ ${pre=-I:_C__INCLUDE} $BC_CXXFLAGS $C_FLAGS_PLATFORM -Wno-unknown-warning-option $LLVM_OPTS ${NO_LTO_CFLAGS} -emit-llvm -c ${input:Input} -o ${noauto;output:Output} $Opts ${hide;kv:"p BC"} ${hide;kv:"pc light-green"} .SEM=llvm_compile_cxx ${input:Input} ${noauto;output:Output} ${"${CLANGPLUSPLUS}"} -Wno-unknown-warning-option $LLVM_OPTS ${NO_LTO_CFLAGS} -emit-llvm ${Opts} && target_macroses-ITEM && target_macroses-macro llvm_compile_cxx && target_macroses-args ${input:Input} ${noauto;output:Output} ${"${CLANGPLUSPLUS}"} -Wno-unknown-warning-option $LLVM_OPTS ${NO_LTO_CFLAGS} -emit-llvm ${Opts} + .STRUCT_CMD=yes when ($CLANG_BC_ROOT == "") { _OK = no } @@ -4790,6 +4762,7 @@ macro LLVM_COMPILE_CXX(Input, Output, Opts...) { macro LLVM_COMPILE_C(Input, Output, Opts...) { .CMD=$YMAKE_PYTHON ${input:"build/scripts/clang_wrapper.py"} $WINDOWS ${CLANG_BC_ROOT}/bin/clang ${pre=-I:_C__INCLUDE} $BC_CFLAGS $C_FLAGS_PLATFORM $LLVM_OPTS ${NO_LTO_CFLAGS} -emit-llvm -c ${input:Input} -o ${noauto;output:Output} $Opts ${hide;kv:"p BC"} ${hide;kv:"pc light-green"} .SEM=llvm_compile_c ${input:Input} ${noauto;output:Output} ${"${CLANGC}"} -Wno-unknown-warning-option $LLVM_OPTS ${NO_LTO_CFLAGS} -emit-llvm ${Opts} && target_macroses-ITEM && target_macroses-macro llvm_compile_c && target_macroses-args ${input:Input} ${noauto;output:Output} ${"${CLANGC}"} -Wno-unknown-warning-option $LLVM_OPTS ${NO_LTO_CFLAGS} -emit-llvm ${Opts} + .STRUCT_CMD=yes when ($CLANG_BC_ROOT == "") { _OK = no } From 27b7ec6ec161019a7cb8f731166e892c60e863e1 Mon Sep 17 00:00:00 2001 From: robot-contrib Date: Wed, 31 Jul 2024 10:39:31 +0300 Subject: [PATCH 002/104] Update contrib/libs/backtrace to 2024-07-16 0ba06a4df3a5667d31b5de82f51cb0d3979f14ac --- contrib/libs/backtrace/dwarf.c | 63 +++++++++++++++++-------------- contrib/libs/backtrace/elf.c | 31 ++++++++++----- contrib/libs/backtrace/internal.h | 36 +++++++++++++++++- contrib/libs/backtrace/macho.c | 25 +++++++----- contrib/libs/backtrace/ya.make | 4 +- 5 files changed, 109 insertions(+), 50 deletions(-) diff --git a/contrib/libs/backtrace/dwarf.c b/contrib/libs/backtrace/dwarf.c index 54bff64b0d7f..9115836bf7d5 100644 --- a/contrib/libs/backtrace/dwarf.c +++ b/contrib/libs/backtrace/dwarf.c @@ -722,8 +722,8 @@ struct dwarf_data struct dwarf_data *next; /* The data for .gnu_debugaltlink. */ struct dwarf_data *altlink; - /* The base address for this file. */ - uintptr_t base_address; + /* The base address mapping for this file. */ + struct libbacktrace_base_address base_address; /* A sorted list of address ranges. */ struct unit_addrs *addrs; /* Number of address ranges in list. */ @@ -1944,8 +1944,9 @@ update_pcrange (const struct attr* attr, const struct attr_val* val, static int add_low_high_range (struct backtrace_state *state, const struct dwarf_sections *dwarf_sections, - uintptr_t base_address, int is_bigendian, - struct unit *u, const struct pcrange *pcrange, + struct libbacktrace_base_address base_address, + int is_bigendian, struct unit *u, + const struct pcrange *pcrange, int (*add_range) (struct backtrace_state *state, void *rdata, uintptr_t lowpc, uintptr_t highpc, @@ -1980,8 +1981,8 @@ add_low_high_range (struct backtrace_state *state, /* Add in the base address of the module when recording PC values, so that we can look up the PC directly. */ - lowpc += base_address; - highpc += base_address; + lowpc = libbacktrace_add_base (lowpc, base_address); + highpc = libbacktrace_add_base (highpc, base_address); return add_range (state, rdata, lowpc, highpc, error_callback, data, vec); } @@ -1993,7 +1994,7 @@ static int add_ranges_from_ranges ( struct backtrace_state *state, const struct dwarf_sections *dwarf_sections, - uintptr_t base_address, int is_bigendian, + struct libbacktrace_base_address base_address, int is_bigendian, struct unit *u, uintptr_t base, const struct pcrange *pcrange, int (*add_range) (struct backtrace_state *state, void *rdata, @@ -2039,10 +2040,11 @@ add_ranges_from_ranges ( base = (uintptr_t) high; else { - if (!add_range (state, rdata, - (uintptr_t) low + base + base_address, - (uintptr_t) high + base + base_address, - error_callback, data, vec)) + uintptr_t rl, rh; + + rl = libbacktrace_add_base ((uintptr_t) low + base, base_address); + rh = libbacktrace_add_base ((uintptr_t) high + base, base_address); + if (!add_range (state, rdata, rl, rh, error_callback, data, vec)) return 0; } } @@ -2060,7 +2062,7 @@ static int add_ranges_from_rnglists ( struct backtrace_state *state, const struct dwarf_sections *dwarf_sections, - uintptr_t base_address, int is_bigendian, + struct libbacktrace_base_address base_address, int is_bigendian, struct unit *u, uintptr_t base, const struct pcrange *pcrange, int (*add_range) (struct backtrace_state *state, void *rdata, @@ -2143,9 +2145,10 @@ add_ranges_from_rnglists ( u->addrsize, is_bigendian, index, error_callback, data, &high)) return 0; - if (!add_range (state, rdata, low + base_address, - high + base_address, error_callback, data, - vec)) + if (!add_range (state, rdata, + libbacktrace_add_base (low, base_address), + libbacktrace_add_base (high, base_address), + error_callback, data, vec)) return 0; } break; @@ -2162,7 +2165,7 @@ add_ranges_from_rnglists ( error_callback, data, &low)) return 0; length = read_uleb128 (&rnglists_buf); - low += base_address; + low = libbacktrace_add_base (low, base_address); if (!add_range (state, rdata, low, low + length, error_callback, data, vec)) return 0; @@ -2176,8 +2179,9 @@ add_ranges_from_rnglists ( low = read_uleb128 (&rnglists_buf); high = read_uleb128 (&rnglists_buf); - if (!add_range (state, rdata, low + base + base_address, - high + base + base_address, + if (!add_range (state, rdata, + libbacktrace_add_base (low + base, base_address), + libbacktrace_add_base (high + base, base_address), error_callback, data, vec)) return 0; } @@ -2194,9 +2198,10 @@ add_ranges_from_rnglists ( low = (uintptr_t) read_address (&rnglists_buf, u->addrsize); high = (uintptr_t) read_address (&rnglists_buf, u->addrsize); - if (!add_range (state, rdata, low + base_address, - high + base_address, error_callback, data, - vec)) + if (!add_range (state, rdata, + libbacktrace_add_base (low, base_address), + libbacktrace_add_base (high, base_address), + error_callback, data, vec)) return 0; } break; @@ -2208,7 +2213,7 @@ add_ranges_from_rnglists ( low = (uintptr_t) read_address (&rnglists_buf, u->addrsize); length = (uintptr_t) read_uleb128 (&rnglists_buf); - low += base_address; + low = libbacktrace_add_base (low, base_address); if (!add_range (state, rdata, low, low + length, error_callback, data, vec)) return 0; @@ -2236,7 +2241,7 @@ add_ranges_from_rnglists ( static int add_ranges (struct backtrace_state *state, const struct dwarf_sections *dwarf_sections, - uintptr_t base_address, int is_bigendian, + struct libbacktrace_base_address base_address, int is_bigendian, struct unit *u, uintptr_t base, const struct pcrange *pcrange, int (*add_range) (struct backtrace_state *state, void *rdata, uintptr_t lowpc, uintptr_t highpc, @@ -2272,7 +2277,8 @@ add_ranges (struct backtrace_state *state, read, 0 if there is some error. */ static int -find_address_ranges (struct backtrace_state *state, uintptr_t base_address, +find_address_ranges (struct backtrace_state *state, + struct libbacktrace_base_address base_address, struct dwarf_buf *unit_buf, const struct dwarf_sections *dwarf_sections, int is_bigendian, struct dwarf_data *altlink, @@ -2427,7 +2433,8 @@ find_address_ranges (struct backtrace_state *state, uintptr_t base_address, on success, 0 on failure. */ static int -build_address_map (struct backtrace_state *state, uintptr_t base_address, +build_address_map (struct backtrace_state *state, + struct libbacktrace_base_address base_address, const struct dwarf_sections *dwarf_sections, int is_bigendian, struct dwarf_data *altlink, backtrace_error_callback error_callback, void *data, @@ -2646,7 +2653,7 @@ add_line (struct backtrace_state *state, struct dwarf_data *ddata, /* Add in the base address here, so that we can look up the PC directly. */ - ln->pc = pc + ddata->base_address; + ln->pc = libbacktrace_add_base (pc, ddata->base_address); ln->filename = filename; ln->lineno = lineno; @@ -4285,7 +4292,7 @@ dwarf_fileline (struct backtrace_state *state, uintptr_t pc, static struct dwarf_data * build_dwarf_data (struct backtrace_state *state, - uintptr_t base_address, + struct libbacktrace_base_address base_address, const struct dwarf_sections *dwarf_sections, int is_bigendian, struct dwarf_data *altlink, @@ -4343,7 +4350,7 @@ build_dwarf_data (struct backtrace_state *state, int backtrace_dwarf_add (struct backtrace_state *state, - uintptr_t base_address, + struct libbacktrace_base_address base_address, const struct dwarf_sections *dwarf_sections, int is_bigendian, struct dwarf_data *fileline_altlink, diff --git a/contrib/libs/backtrace/elf.c b/contrib/libs/backtrace/elf.c index 81fcf4e00085..575e13daf500 100644 --- a/contrib/libs/backtrace/elf.c +++ b/contrib/libs/backtrace/elf.c @@ -633,7 +633,7 @@ elf_symbol_search (const void *vkey, const void *ventry) static int elf_initialize_syminfo (struct backtrace_state *state, - uintptr_t base_address, + struct libbacktrace_base_address base_address, const unsigned char *symtab_data, size_t symtab_size, const unsigned char *strtab, size_t strtab_size, backtrace_error_callback error_callback, @@ -699,7 +699,8 @@ elf_initialize_syminfo (struct backtrace_state *state, = *(const b_elf_addr *) (opd->data + (sym->st_value - opd->addr)); else elf_symbols[j].address = sym->st_value; - elf_symbols[j].address += base_address; + elf_symbols[j].address = + libbacktrace_add_base (elf_symbols[j].address, base_address); elf_symbols[j].size = sym->st_size; ++j; } @@ -6499,7 +6500,8 @@ backtrace_uncompress_lzma (struct backtrace_state *state, static int elf_add (struct backtrace_state *state, const char *filename, int descriptor, const unsigned char *memory, size_t memory_size, - uintptr_t base_address, struct elf_ppc64_opd_data *caller_opd, + struct libbacktrace_base_address base_address, + struct elf_ppc64_opd_data *caller_opd, backtrace_error_callback error_callback, void *data, fileline *fileline_fn, int *found_sym, int *found_dwarf, struct dwarf_data **fileline_entry, int exe, int debuginfo, @@ -7349,6 +7351,7 @@ phdr_callback (struct dl_phdr_info *info, size_t size ATTRIBUTE_UNUSED, const char *filename; int descriptor; int does_not_exist; + struct libbacktrace_base_address base_address; fileline elf_fileline_fn; int found_dwarf; @@ -7378,7 +7381,8 @@ phdr_callback (struct dl_phdr_info *info, size_t size ATTRIBUTE_UNUSED, return 0; } - if (elf_add (pd->state, filename, descriptor, NULL, 0, info->dlpi_addr, NULL, + base_address.m = info->dlpi_addr; + if (elf_add (pd->state, filename, descriptor, NULL, 0, base_address, NULL, pd->error_callback, pd->data, &elf_fileline_fn, pd->found_sym, &found_dwarf, NULL, 0, 0, NULL, 0)) { @@ -7407,11 +7411,20 @@ backtrace_initialize (struct backtrace_state *state, const char *filename, fileline elf_fileline_fn = elf_nodebug; struct phdr_data pd; - ret = elf_add (state, filename, descriptor, NULL, 0, 0, NULL, error_callback, - data, &elf_fileline_fn, &found_sym, &found_dwarf, NULL, 1, 0, - NULL, 0); - if (!ret) - return 0; + /* When using fdpic we must use dl_iterate_phdr for all modules, including + the main executable, so that we can get the right base address + mapping. */ + if (!libbacktrace_using_fdpic ()) + { + struct libbacktrace_base_address zero_base_address; + + memset (&zero_base_address, 0, sizeof zero_base_address); + ret = elf_add (state, filename, descriptor, NULL, 0, zero_base_address, + NULL, error_callback, data, &elf_fileline_fn, &found_sym, + &found_dwarf, NULL, 1, 0, NULL, 0); + if (!ret) + return 0; + } pd.state = state; pd.error_callback = error_callback; diff --git a/contrib/libs/backtrace/internal.h b/contrib/libs/backtrace/internal.h index 4fa0af8cb6c9..422115a2250a 100644 --- a/contrib/libs/backtrace/internal.h +++ b/contrib/libs/backtrace/internal.h @@ -323,10 +323,44 @@ struct dwarf_sections struct dwarf_data; +/* The load address mapping. */ + +#if defined(__FDPIC__) && defined(HAVE_DL_ITERATE_PHDR) && (defined(HAVE_LINK_H) || defined(HAVE_SYS_LINK_H)) + +#ifdef HAVE_LINK_H + #include +#endif +#ifdef HAVE_SYS_LINK_H + #error #include +#endif + +#define libbacktrace_using_fdpic() (1) + +struct libbacktrace_base_address +{ + struct elf32_fdpic_loadaddr m; +}; + +#define libbacktrace_add_base(pc, base) \ + ((uintptr_t) (__RELOC_POINTER ((pc), (base).m))) + +#else /* not _FDPIC__ */ + +#define libbacktrace_using_fdpic() (0) + +struct libbacktrace_base_address +{ + uintptr_t m; +}; + +#define libbacktrace_add_base(pc, base) ((pc) + (base).m) + +#endif /* not _FDPIC__ */ + /* Add file/line information for a DWARF module. */ extern int backtrace_dwarf_add (struct backtrace_state *state, - uintptr_t base_address, + struct libbacktrace_base_address base_address, const struct dwarf_sections *dwarf_sections, int is_bigendian, struct dwarf_data *fileline_altlink, diff --git a/contrib/libs/backtrace/macho.c b/contrib/libs/backtrace/macho.c index 8f768f14a579..fc4c9591dfa3 100644 --- a/contrib/libs/backtrace/macho.c +++ b/contrib/libs/backtrace/macho.c @@ -315,8 +315,9 @@ static const char * const dwarf_section_names[DEBUG_MAX] = /* Forward declaration. */ static int macho_add (struct backtrace_state *, const char *, int, off_t, - const unsigned char *, uintptr_t, int, - backtrace_error_callback, void *, fileline *, int *); + const unsigned char *, struct libbacktrace_base_address, + int, backtrace_error_callback, void *, fileline *, + int *); /* A dummy callback function used when we can't find any debug info. */ @@ -511,7 +512,7 @@ macho_defined_symbol (uint8_t type) static int macho_add_symtab (struct backtrace_state *state, int descriptor, - uintptr_t base_address, int is_64, + struct libbacktrace_base_address base_address, int is_64, off_t symoff, unsigned int nsyms, off_t stroff, unsigned int strsize, backtrace_error_callback error_callback, void *data) @@ -626,7 +627,7 @@ macho_add_symtab (struct backtrace_state *state, int descriptor, if (name[0] == '_') ++name; macho_symbols[j].name = name; - macho_symbols[j].address = value + base_address; + macho_symbols[j].address = libbacktrace_add_base (value, base_address); ++j; } @@ -758,7 +759,8 @@ macho_syminfo (struct backtrace_state *state, uintptr_t addr, static int macho_add_fat (struct backtrace_state *state, const char *filename, int descriptor, int swapped, off_t offset, - const unsigned char *match_uuid, uintptr_t base_address, + const unsigned char *match_uuid, + struct libbacktrace_base_address base_address, int skip_symtab, uint32_t nfat_arch, int is_64, backtrace_error_callback error_callback, void *data, fileline *fileline_fn, int *found_sym) @@ -860,7 +862,8 @@ macho_add_fat (struct backtrace_state *state, const char *filename, static int macho_add_dsym (struct backtrace_state *state, const char *filename, - uintptr_t base_address, const unsigned char *uuid, + struct libbacktrace_base_address base_address, + const unsigned char *uuid, backtrace_error_callback error_callback, void *data, fileline* fileline_fn) { @@ -978,7 +981,7 @@ macho_add_dsym (struct backtrace_state *state, const char *filename, static int macho_add (struct backtrace_state *state, const char *filename, int descriptor, off_t offset, const unsigned char *match_uuid, - uintptr_t base_address, int skip_symtab, + struct libbacktrace_base_address base_address, int skip_symtab, backtrace_error_callback error_callback, void *data, fileline *fileline_fn, int *found_sym) { @@ -1240,7 +1243,7 @@ backtrace_initialize (struct backtrace_state *state, const char *filename, c = _dyld_image_count (); for (i = 0; i < c; ++i) { - uintptr_t base_address; + struct libbacktrace_base_address base_address; const char *name; int d; fileline mff; @@ -1264,7 +1267,7 @@ backtrace_initialize (struct backtrace_state *state, const char *filename, continue; } - base_address = _dyld_get_image_vmaddr_slide (i); + base_address.m = _dyld_get_image_vmaddr_slide (i); mff = macho_nodebug; if (!macho_add (state, name, d, 0, NULL, base_address, 0, @@ -1319,10 +1322,12 @@ backtrace_initialize (struct backtrace_state *state, const char *filename, void *data, fileline *fileline_fn) { fileline macho_fileline_fn; + struct libbacktrace_base_address zero_base_address; int found_sym; macho_fileline_fn = macho_nodebug; - if (!macho_add (state, filename, descriptor, 0, NULL, 0, 0, + memset (&zero_base_address, 0, sizeof zero_base_address); + if (!macho_add (state, filename, descriptor, 0, NULL, zero_base_address, 0, error_callback, data, &macho_fileline_fn, &found_sym)) return 0; diff --git a/contrib/libs/backtrace/ya.make b/contrib/libs/backtrace/ya.make index 65e49d05d91a..202f54991f27 100644 --- a/contrib/libs/backtrace/ya.make +++ b/contrib/libs/backtrace/ya.make @@ -6,9 +6,9 @@ LICENSE(BSD-3-Clause) LICENSE_TEXTS(.yandex_meta/licenses.list.txt) -VERSION(2024-07-12) +VERSION(2024-07-16) -ORIGINAL_SOURCE(https://github.com/ianlancetaylor/libbacktrace/archive/febbb9bff98b39ee596aa15d1f58e4bba442cd6a.tar.gz) +ORIGINAL_SOURCE(https://github.com/ianlancetaylor/libbacktrace/archive/1dd5c408fe6f5d9bccf870ec4e0e4bcabeb0664e.tar.gz) ADDINCL( contrib/libs/backtrace From c4fb2cdf41179910a4e9632de119ab3c94b741bc Mon Sep 17 00:00:00 2001 From: pavook Date: Wed, 31 Jul 2024 12:03:17 +0300 Subject: [PATCH 003/104] Fix TEnumerator::TIterator 082782faf0e6e05d3aa1c56e096d33ea69282f57 --- library/cpp/iterator/enumerate.h | 22 +++++++++++++++------- library/cpp/iterator/ut/functools_ut.cpp | 14 +++++++++++++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/library/cpp/iterator/enumerate.h b/library/cpp/iterator/enumerate.h index 2c83fb41bfc1..6ebc12a0e7d9 100644 --- a/library/cpp/iterator/enumerate.h +++ b/library/cpp/iterator/enumerate.h @@ -27,23 +27,30 @@ namespace NPrivate { struct TIterator { using difference_type = std::ptrdiff_t; using value_type = TValue; - using pointer = TValue*; - using reference = TValue&; + using pointer = void; + using reference = value_type; using iterator_category = std::input_iterator_tag; - TValue operator*() { + reference operator*() const { return {Index_, *Iterator_}; } - TValue operator*() const { - return {Index_, *Iterator_}; - } - void operator++() { + + TIterator& operator++() { ++Index_; ++Iterator_; + return *this; + } + + TIterator operator++(int) { + TIterator result = *this; + ++(*this); + return result; } + bool operator!=(const TSentinel& other) const { return Iterator_ != other.Iterator_; } + bool operator==(const TSentinel& other) const { return Iterator_ == other.Iterator_; } @@ -51,6 +58,7 @@ namespace NPrivate { std::size_t Index_; TIteratorState Iterator_; }; + public: using iterator = TIterator; using const_iterator = TIterator; diff --git a/library/cpp/iterator/ut/functools_ut.cpp b/library/cpp/iterator/ut/functools_ut.cpp index 2dee9a55c858..b11a715e0c4c 100644 --- a/library/cpp/iterator/ut/functools_ut.cpp +++ b/library/cpp/iterator/ut/functools_ut.cpp @@ -99,7 +99,7 @@ using namespace NFuncTools; struct TTestSentinel {}; struct TTestIterator { - int operator*() { + int operator*() const { return X; } void operator++() { @@ -139,6 +139,18 @@ using namespace NFuncTools; EXPECT_EQ(j, v.size()); } + // Test correctness of iterator traits. + auto enumerated = Enumerate(a); + static_assert(std::ranges::input_range); + static_assert( + std::is_same_v::pointer>); + + // Post-increment test. + auto it = enumerated.begin(); + EXPECT_EQ(*(it++), (std::tuple{0, 1})); + EXPECT_EQ(*it, (std::tuple{1, 2})); + TVector d = {0, 0, 0}; FOR_DISPATCH_2(i, x, Enumerate(d)) { x = i; From 5872c8e0780708f1138757609dbf2b70abe28742 Mon Sep 17 00:00:00 2001 From: don-dron Date: Wed, 31 Jul 2024 12:32:54 +0300 Subject: [PATCH 004/104] Revert "YT-21931: Track memory for ahead blocks in write sessions" This reverts commit f34c547ac0041f6745654e8da71c886bc2ae5ebc, reversing changes made to 8c124ed0587173703d24131bf1565c0e85973b2a. 890663587fbe5faa158f70ac86dbd66fe028ab9e --- yt/yt/core/misc/memory_usage_tracker.cpp | 7 +------ yt/yt/core/misc/memory_usage_tracker.h | 3 +-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/yt/yt/core/misc/memory_usage_tracker.cpp b/yt/yt/core/misc/memory_usage_tracker.cpp index 269632e4fed4..3f24adc4a864 100644 --- a/yt/yt/core/misc/memory_usage_tracker.cpp +++ b/yt/yt/core/misc/memory_usage_tracker.cpp @@ -233,16 +233,11 @@ TError TMemoryUsageTrackerGuard::SetSizeImpl(i64 size, auto acquirer) return {}; } -void TMemoryUsageTrackerGuard::IncreaseSize(i64 sizeDelta) +void TMemoryUsageTrackerGuard::IncrementSize(i64 sizeDelta) { SetSize(Size_ + sizeDelta); } -void TMemoryUsageTrackerGuard::DecreaseSize(i64 sizeDelta) -{ - SetSize(Size_ - sizeDelta); -} - TMemoryUsageTrackerGuard TMemoryUsageTrackerGuard::TransferMemory(i64 size) { YT_VERIFY(Size_ >= size); diff --git a/yt/yt/core/misc/memory_usage_tracker.h b/yt/yt/core/misc/memory_usage_tracker.h index bcd132e8ed18..4b3887fa1748 100644 --- a/yt/yt/core/misc/memory_usage_tracker.h +++ b/yt/yt/core/misc/memory_usage_tracker.h @@ -93,8 +93,7 @@ class TMemoryUsageTrackerGuard i64 GetSize() const; void SetSize(i64 size); TError TrySetSize(i64 size); - void IncreaseSize(i64 sizeDelta); - void DecreaseSize(i64 sizeDelta); + void IncrementSize(i64 sizeDelta); TMemoryUsageTrackerGuard TransferMemory(i64 size); private: From 7b23cf9228055d185180136fdcf09b453a836a10 Mon Sep 17 00:00:00 2001 From: c0nsumer Date: Wed, 31 Jul 2024 15:27:38 +0300 Subject: [PATCH 005/104] language level supported 0b536fcac54655bfac44b1b3d83a57fe9113d264 --- build/export_generators/ide-gradle/build.gradle.kts.jinja | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build/export_generators/ide-gradle/build.gradle.kts.jinja b/build/export_generators/ide-gradle/build.gradle.kts.jinja index 44a6cb36f0fe..b0c2714a5b67 100644 --- a/build/export_generators/ide-gradle/build.gradle.kts.jinja +++ b/build/export_generators/ide-gradle/build.gradle.kts.jinja @@ -43,6 +43,12 @@ plugins { {% endif -%} {%- endif %} } +{# language level #} +java { + toolchain { + languageVersion = JavaLanguageVersion.of("{{ target.required_jdk }}") + } +} {%- if target.with_kotlinc_plugin_allopen %} allOpen { From b10c66202fbddb06bcfc4530a397b3ffaa602bc7 Mon Sep 17 00:00:00 2001 From: mpereskokova Date: Wed, 31 Jul 2024 15:55:38 +0300 Subject: [PATCH 006/104] Codestyle de2dd0433939b04a62a85e2c51428e3ac28f51d1 --- yt/yt/client/api/query_tracker_client.h | 6 +++--- yt/yt_proto/yt/client/api/rpc_proxy/proto/api_service.proto | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/yt/yt/client/api/query_tracker_client.h b/yt/yt/client/api/query_tracker_client.h index cc3f3966f4de..f4b8d48c4c0b 100644 --- a/yt/yt/client/api/query_tracker_client.h +++ b/yt/yt/client/api/query_tracker_client.h @@ -42,7 +42,7 @@ struct TStartQueryOptions bool Draft = false; NYTree::IMapNodePtr Annotations; std::vector Files; - std::optional AccessControlObject; // COMPAT + std::optional AccessControlObject; // COMPAT(mpereskokova) std::optional> AccessControlObjects; }; @@ -103,7 +103,7 @@ struct TQuery std::optional FinishTime; NYson::TYsonString Settings; std::optional User; - std::optional AccessControlObject; // COMPAT + std::optional AccessControlObject; // COMPAT(mpereskokova) std::optional AccessControlObjects; std::optional State; std::optional ResultCount; @@ -139,7 +139,7 @@ struct TAlterQueryOptions , public TQueryTrackerOptions { NYTree::IMapNodePtr Annotations; - std::optional AccessControlObject; // COMPAT + std::optional AccessControlObject; // COMPAT(mpereskokova) std::optional> AccessControlObjects; }; diff --git a/yt/yt_proto/yt/client/api/rpc_proxy/proto/api_service.proto b/yt/yt_proto/yt/client/api/rpc_proxy/proto/api_service.proto index beaa41a627a9..39ef2f681b18 100644 --- a/yt/yt_proto/yt/client/api/rpc_proxy/proto/api_service.proto +++ b/yt/yt_proto/yt/client/api/rpc_proxy/proto/api_service.proto @@ -3204,7 +3204,7 @@ message TReqStartQuery optional bool draft = 5; optional bytes annotations = 6; // YSON repeated TQueryFile files = 7; - optional string access_control_object = 8; // COMPAT + optional string access_control_object = 8; // COMPAT(mpereskokova) optional TAccessControlObjects access_control_objects = 9; } @@ -3279,7 +3279,7 @@ message TQuery optional uint64 finish_time = 6; // TInstant optional bytes settings = 7; // YSON optional string user = 8; - optional string access_control_object = 9; // COMPAT + optional string access_control_object = 9; // COMPAT(mpereskokova) optional EQueryState state = 10; optional int64 result_count = 11; optional bytes progress = 12; // YSON @@ -3340,7 +3340,7 @@ message TReqAlterQuery required string query_tracker_stage = 1; required NYT.NProto.TGuid query_id = 2; optional bytes annotations = 3; // YSON - optional string access_control_object = 4; // COMPAT + optional string access_control_object = 4; // COMPAT(mpereskokova) optional TAccessControlObjects access_control_objects = 5; } From f81030974a4660e301c110a5085c53dae44f7279 Mon Sep 17 00:00:00 2001 From: dgolear Date: Wed, 31 Jul 2024 16:00:23 +0300 Subject: [PATCH 007/104] Style Style a1b273d0e7946f2c3459730344e403b3191cc7ae --- yt/yt/client/ypath/rich.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yt/yt/client/ypath/rich.h b/yt/yt/client/ypath/rich.h index 1659532208be..60a63c3ce676 100644 --- a/yt/yt/client/ypath/rich.h +++ b/yt/yt/client/ypath/rich.h @@ -172,7 +172,7 @@ class TRichYPath NYTree::IAttributeDictionaryPtr Attributes_; }; -bool operator== (const TRichYPath& lhs, const TRichYPath& rhs); +bool operator==(const TRichYPath& lhs, const TRichYPath& rhs); //////////////////////////////////////////////////////////////////////////////// From d20a7253e7c98c39d8a0c23745bbe7ab0484fd14 Mon Sep 17 00:00:00 2001 From: osidorkin Date: Wed, 31 Jul 2024 19:17:10 +0300 Subject: [PATCH 008/104] YT-20327: More logging of ClockClusterTag in timestamp providers 7a6f61d1aa10edd839c19bc67e48c5f59cd44e32 --- .../transaction_client/timestamp_provider_base.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/yt/yt/client/transaction_client/timestamp_provider_base.cpp b/yt/yt/client/transaction_client/timestamp_provider_base.cpp index 3971b897a16a..c5e82465620f 100644 --- a/yt/yt/client/transaction_client/timestamp_provider_base.cpp +++ b/yt/yt/client/transaction_client/timestamp_provider_base.cpp @@ -25,7 +25,9 @@ TFuture TTimestampProviderBase::GenerateTimestamps(int count, TCellT { VERIFY_THREAD_AFFINITY_ANY(); - YT_LOG_DEBUG("Generating fresh timestamps (Count: %v)", count); + YT_LOG_DEBUG("Generating fresh timestamps (Count: %v, ClockClusterTag: %v)", + count, + clockClusterTag); return DoGenerateTimestamps(count, clockClusterTag).Apply(BIND( &TTimestampProviderBase::OnGenerateTimestamps, @@ -76,9 +78,10 @@ TFuture TTimestampProviderBase::OnGenerateTimestamps( auto firstTimestamp = timestampOrError.Value(); auto lastTimestamp = firstTimestamp + count - 1; - YT_LOG_DEBUG("Fresh timestamps generated (Timestamps: %v-%v)", + YT_LOG_DEBUG("Fresh timestamps generated (Timestamps: %v-%v, ClockClusterTag: %v)", firstTimestamp, - lastTimestamp); + lastTimestamp, + clockClusterTag); auto& latestTimestamp = GetLatestTimestampReferenceByTag(clockClusterTag); auto latestTimestampValue = latestTimestamp.load(std::memory_order::relaxed); From faec437d163d8015fd5e0da74381c190fa45c298 Mon Sep 17 00:00:00 2001 From: robot-piglet Date: Wed, 31 Jul 2024 19:34:56 +0300 Subject: [PATCH 009/104] Intermediate changes --- contrib/python/importlib-resources/ya.make | 3 +++ contrib/tools/m4/ya.make | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/contrib/python/importlib-resources/ya.make b/contrib/python/importlib-resources/ya.make index 21d607abef03..c7ba0d70fcbe 100644 --- a/contrib/python/importlib-resources/ya.make +++ b/contrib/python/importlib-resources/ya.make @@ -2,6 +2,9 @@ PY23_LIBRARY() LICENSE(Apache-2.0) +# The code is not taken from upstream. An analogue of version 1.0.2 has been implemented. See CONTRIB-1203 +VERSION(1.0.2) + PY_SRCS( TOP_LEVEL importlib_resources/__init__.py diff --git a/contrib/tools/m4/ya.make b/contrib/tools/m4/ya.make index 00546536a6d3..cf8d1d977e47 100644 --- a/contrib/tools/m4/ya.make +++ b/contrib/tools/m4/ya.make @@ -2,6 +2,10 @@ PROGRAM() LICENSE(GPL-3.0-or-later) +VERSION(1.4.17) + +ORIGINAL_SOURCE(https://github.com/tar-mirror/gnu-m4/archive/refs/tags/v1.4.17.tar.gz) + LICENSE_TEXTS(.yandex_meta/licenses.list.txt) NO_RUNTIME() From e1e639fc5c85ba4df83040ddb4ac8dc620ae208b Mon Sep 17 00:00:00 2001 From: akozhikhov Date: Wed, 31 Jul 2024 19:35:18 +0300 Subject: [PATCH 010/104] YT-22276: In fair throttler consider bucket guarantee in GetEstimatedOverdraftDuration 3d94c6e0a109be012841ea1ce18c627c14f574d8 --- yt/yt/core/concurrency/fair_throttler.cpp | 20 ++++++++++++++------ yt/yt/core/concurrency/fair_throttler.h | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/yt/yt/core/concurrency/fair_throttler.cpp b/yt/yt/core/concurrency/fair_throttler.cpp index 235784fa8ea7..12e78b5ad47b 100644 --- a/yt/yt/core/concurrency/fair_throttler.cpp +++ b/yt/yt/core/concurrency/fair_throttler.cpp @@ -471,7 +471,7 @@ class TBucketThrottler return TDuration::Zero(); } - auto limit = LastLimit_.load(); + auto limit = EstimatedLimit_.load(); auto distributionPeriod = DistributionPeriod_.load(); if (limit == 0) { return distributionPeriod; @@ -548,9 +548,12 @@ class TBucketThrottler return quota; } - i64 Refill(i64 quota) + i64 Refill(i64 quota, i64 guaranteedQuota) { - LastLimit_ = quota; + // This value is used to compute estimated overdraft duration. + // The limit is exceeded with |guaranteedQuota| because in case of an iteration with low demand + // the bucket gets low quota however it is eligible for greater quota that is at least |guaranteedQuota|. + EstimatedLimit_ = std::max(quota, guaranteedQuota); if (Quota_.Value->load() < 0) { auto remainingQuota = Quota_.Increment(quota); @@ -586,7 +589,7 @@ class TBucketThrottler NProfiling::TEventTimer WaitTime_; TLeakyCounter Quota_; - std::atomic LastLimit_ = 0; + std::atomic EstimatedLimit_ = 0; std::atomic QueueSize_ = 0; std::atomic Usage_ = 0; @@ -750,6 +753,8 @@ void TFairThrottler::DoUpdateLeader() auto tickLimit = i64(Config_->TotalLimit * Config_->DistributionPeriod.SecondsFloat()); auto tickIncome = ComputeFairDistribution(tickLimit, weights, demands, limits); + auto infiniteDemands = std::vector(weights.size(), tickLimit); + auto guaranteedQuotas = ComputeFairDistribution(tickLimit, weights, infiniteDemands, limits); // Distribute remaining quota according to weights and limits. auto freeQuota = tickLimit - std::accumulate(tickIncome.begin(), tickIncome.end(), i64(0)); @@ -768,6 +773,7 @@ void TFairThrottler::DoUpdateLeader() i64 leakedQuota = 0; int i = 0; + // TODO(akozhikhov): Shall we be concerned with the elements order on the second pass over buckets hash table? for (const auto& [name, bucket] : Buckets_) { auto state = states[i]; auto newLimit = tickIncome[i] + freeIncome[i]; @@ -776,7 +782,7 @@ void TFairThrottler::DoUpdateLeader() bucketQuota[name] = state.Quota; bucketIncome[name] = newLimit; - leakedQuota += bucket.Throttler->Refill(newLimit); + leakedQuota += bucket.Throttler->Refill(newLimit, guaranteedQuotas[i]); ++i; } @@ -786,6 +792,8 @@ void TFairThrottler::DoUpdateLeader() state->InFlow += tickIncome[i] + freeIncome[i]; + state->GuaranteedQuota = guaranteedQuotas[i]; + leakedQuota += state->OutFlow.exchange(0); ++i; @@ -845,7 +853,7 @@ void TFairThrottler::DoUpdateFollower() bucketDemands[name] = demand; auto in = ipc->InFlow.exchange(0); - auto out = bucket.Throttler->Refill(in); + auto out = bucket.Throttler->Refill(in, ipc->GuaranteedQuota); ipc->OutFlow += out; bucketIncome[name] = in; diff --git a/yt/yt/core/concurrency/fair_throttler.h b/yt/yt/core/concurrency/fair_throttler.h index 10e2ab23682a..ecf32ae14bcd 100644 --- a/yt/yt/core/concurrency/fair_throttler.h +++ b/yt/yt/core/concurrency/fair_throttler.h @@ -63,6 +63,7 @@ struct IIPCBucket std::atomic Demand; std::atomic InFlow; std::atomic OutFlow; + std::atomic GuaranteedQuota; }; virtual TBucket* State() = 0; From f3da1e8b8d13a3a52b3eab6f28ed798fa83b4215 Mon Sep 17 00:00:00 2001 From: robot-piglet Date: Wed, 31 Jul 2024 23:33:21 +0300 Subject: [PATCH 011/104] Intermediate changes --- library/python/fs/__init__.py | 67 +++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/library/python/fs/__init__.py b/library/python/fs/__init__.py index 6b6a011e7fe5..0beaf6665a63 100644 --- a/library/python/fs/__init__.py +++ b/library/python/fs/__init__.py @@ -196,32 +196,6 @@ def hardlink(src, lnk): os.link(src, lnk) -@errorfix_win -def hardlink_or_copy(src, lnk): - def should_fallback_to_copy(exc): - if WindowsError is not None and isinstance(exc, WindowsError) and exc.winerror == 1142: # too many hardlinks - return True - # cross-device hardlink or too many hardlinks, or some known WSL error - if isinstance(exc, OSError) and exc.errno in ( - errno.EXDEV, - errno.EMLINK, - errno.EINVAL, - errno.EACCES, - errno.EPERM, - ): - return True - return False - - try: - hardlink(src, lnk) - except Exception as e: - logger.debug('Failed to hardlink %s to %s with error %s, will copy it', src, lnk, repr(e)) - if should_fallback_to_copy(e): - copy2(src, lnk, follow_symlinks=False) - else: - raise - - # Atomic file/directory symlink (Unix only) # Dst must not exist # Throws OSError @@ -247,24 +221,57 @@ def copy2(src, lnk, follow_symlinks=True): symlink(os.readlink(src), lnk) +def copy2_safe(src, lnk, follow_symlinks=True): + try: + copy2(src, lnk, follow_symlinks) + except shutil.SameFileError: + pass + + +@errorfix_win +def hardlink_or_copy(src, lnk, copy_function=copy2): + def should_fallback_to_copy(exc): + if WindowsError is not None and isinstance(exc, WindowsError) and exc.winerror == 1142: # too many hardlinks + return True + # cross-device hardlink or too many hardlinks, or some known WSL error + if isinstance(exc, OSError) and exc.errno in ( + errno.EXDEV, + errno.EMLINK, + errno.EINVAL, + errno.EACCES, + errno.EPERM, + ): + return True + return False + + try: + hardlink(src, lnk) + except Exception as e: + logger.debug('Failed to hardlink %s to %s with error %s, will copy it', src, lnk, repr(e)) + if should_fallback_to_copy(e): + copy_function(src, lnk, follow_symlinks=False) + else: + raise + + # Recursively hardlink directory # Uses plain hardlink for files # Dst must not exist # Non-atomic # Throws OSError @errorfix_win -def hardlink_tree(src, dst): +def hardlink_tree(src, dst, hardlink_function=hardlink, mkdir_function=os.mkdir): if not os.path.exists(src): raise CustomFsError(errno.ENOENT, filename=src) if os.path.isfile(src): - hardlink(src, dst) + hardlink_function(src, dst) return for dirpath, _, filenames in walk_relative(src): src_dirpath = os.path.join(src, dirpath) if dirpath != '.' else src dst_dirpath = os.path.join(dst, dirpath) if dirpath != '.' else dst - os.mkdir(dst_dirpath) + mkdir_function(dst_dirpath) for filename in filenames: - hardlink(os.path.join(src_dirpath, filename), os.path.join(dst_dirpath, filename)) + hardlink_function(os.path.join(src_dirpath, filename), os.path.join(dst_dirpath, filename)) # File copy From df1d068c88515d34d4c2055643790c619e545352 Mon Sep 17 00:00:00 2001 From: orlovorlov Date: Wed, 31 Jul 2024 23:34:11 +0300 Subject: [PATCH 012/104] YT-22157 Interface part of HLL in columnar statistics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Выделил в отдельный PR, чтобы над кодом в YT и в YQL можно было работать независимо. 4fb122ecc4a54b38b09d854d93ae23fd3f76677e --- yt/cpp/mapreduce/interface/common.h | 3 +++ yt/cpp/mapreduce/interface/serialize.cpp | 1 + 2 files changed, 4 insertions(+) diff --git a/yt/cpp/mapreduce/interface/common.h b/yt/cpp/mapreduce/interface/common.h index 49e01bad5577..10988225dd34 100644 --- a/yt/cpp/mapreduce/interface/common.h +++ b/yt/cpp/mapreduce/interface/common.h @@ -1193,6 +1193,9 @@ struct TTableColumnarStatistics /// Total data weight for all chunks for each of requested columns. THashMap ColumnDataWeight; + /// Estimated number of unique elements for each column. + THashMap ColumnEstimatedUniqueCounts; + /// Total weight of all old chunks that don't keep columnar statistics. i64 LegacyChunksDataWeight = 0; diff --git a/yt/cpp/mapreduce/interface/serialize.cpp b/yt/cpp/mapreduce/interface/serialize.cpp index 9be114b45e6c..b195bf04d6e7 100644 --- a/yt/cpp/mapreduce/interface/serialize.cpp +++ b/yt/cpp/mapreduce/interface/serialize.cpp @@ -509,6 +509,7 @@ void Deserialize(TTableColumnarStatistics& statistics, const TNode& node) { const auto& nodeMap = node.AsMap(); DESERIALIZE_ITEM("column_data_weights", statistics.ColumnDataWeight); + DESERIALIZE_ITEM("column_estimated_unique_counts", statistics.ColumnEstimatedUniqueCounts); DESERIALIZE_ITEM("legacy_chunks_data_weight", statistics.LegacyChunksDataWeight); DESERIALIZE_ITEM("timestamp_total_weight", statistics.TimestampTotalWeight); } From 47f4373399712aeee5f71e1fe7363de5d56a631d Mon Sep 17 00:00:00 2001 From: swarmer Date: Thu, 1 Aug 2024 02:38:51 +0300 Subject: [PATCH 013/104] check lifetime of the TBlob no-copy-view 9d78e3f3c3b02b6a9467bda8b2af46826fa30868 --- util/memory/blob.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/memory/blob.h b/util/memory/blob.h index 20c02a68dfb1..008ac104fb8a 100644 --- a/util/memory/blob.h +++ b/util/memory/blob.h @@ -198,7 +198,7 @@ class TBlob { static TBlob Copy(const void* data, size_t length); /// Creates a blob which doesn't own data. No refcounter, no memory allocation, no data copy. - static TBlob NoCopy(const void* data, size_t length); + static TBlob NoCopy(const void* data Y_LIFETIME_BOUND, size_t length); /// Creates a blob with a single-threaded (non atomic) refcounter. It maps the file on the path as data. static TBlob FromFileSingleThreaded(const TString& path, EMappingMode); From fc4a5bce8457dd4aa05f857e0fc36183245a7fff Mon Sep 17 00:00:00 2001 From: robot-ratatosk Date: Thu, 1 Aug 2024 08:49:15 +0300 Subject: [PATCH 014/104] New version of the tld SKIP_CHECK SKIP_REVIEW 26412132206953d6c6817a1bd3b39409273c5e1b --- library/cpp/tld/tlds-alpha-by-domain.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/cpp/tld/tlds-alpha-by-domain.txt b/library/cpp/tld/tlds-alpha-by-domain.txt index b20e2da24db2..7da2d2b35b30 100644 --- a/library/cpp/tld/tlds-alpha-by-domain.txt +++ b/library/cpp/tld/tlds-alpha-by-domain.txt @@ -1,4 +1,4 @@ -# Version 2024072500, Last Updated Thu Jul 25 07:07:01 2024 UTC +# Version 2024073100, Last Updated Wed Jul 31 07:07:01 2024 UTC AAA AARP ABB From 226ad6e44ddaecc763a95f179974da04b9c9fa83 Mon Sep 17 00:00:00 2001 From: robot-piglet Date: Thu, 1 Aug 2024 09:58:13 +0300 Subject: [PATCH 015/104] Intermediate changes --- contrib/libs/backtrace/README.md | 12 +++++++++++- contrib/libs/backtrace/ya.make | 4 ++-- .../python/pytest-lazy-fixtures/.dist-info/METADATA | 10 +++------- contrib/python/pytest-lazy-fixtures/README.md | 8 ++------ .../pytest_lazy_fixtures/loader.py | 2 +- .../pytest_lazy_fixtures/plugin.py | 8 +------- contrib/python/pytest-lazy-fixtures/ya.make | 2 +- 7 files changed, 21 insertions(+), 25 deletions(-) diff --git a/contrib/libs/backtrace/README.md b/contrib/libs/backtrace/README.md index c82834d174d5..d1807842cce4 100644 --- a/contrib/libs/backtrace/README.md +++ b/contrib/libs/backtrace/README.md @@ -10,8 +10,18 @@ The libbacktrace library may be linked into a program or library and used to produce symbolic backtraces. Sample uses would be to print a detailed backtrace when an error occurs or to gather detailed profiling information. + In general the functions provided by this library are async-signal-safe, meaning that they may be safely called from a signal handler. +That said, on systems that use `dl_iterate_phdr`, such as GNU/Linux, +gitthe first call to a libbacktrace function will call `dl_iterate_phdr`, +which is not in general async-signal-safe. Therefore, programs +that call libbacktrace from a signal handler should ensure that they +make an initial call from outside of a signal handler. +Similar considerations apply when arranging to call libbacktrace +from within malloc; `dl_iterate_phdr` can also call malloc, +so make an initial call to a libbacktrace function outside of +malloc before trying to call libbacktrace functions within malloc. The libbacktrace library is provided under a BSD license. See the source files for the exact license text. @@ -25,7 +35,7 @@ will work. See the source file backtrace-supported.h.in for the macros that it defines. -As of October 2020, libbacktrace supports ELF, PE/COFF, Mach-O, and +As of July 2024, libbacktrace supports ELF, PE/COFF, Mach-O, and XCOFF executables with DWARF debugging information. In other words, it supports GNU/Linux, *BSD, macOS, Windows, and AIX. The library is written to make it straightforward to add support for diff --git a/contrib/libs/backtrace/ya.make b/contrib/libs/backtrace/ya.make index 202f54991f27..d8d066df2c78 100644 --- a/contrib/libs/backtrace/ya.make +++ b/contrib/libs/backtrace/ya.make @@ -6,9 +6,9 @@ LICENSE(BSD-3-Clause) LICENSE_TEXTS(.yandex_meta/licenses.list.txt) -VERSION(2024-07-16) +VERSION(2024-07-18) -ORIGINAL_SOURCE(https://github.com/ianlancetaylor/libbacktrace/archive/1dd5c408fe6f5d9bccf870ec4e0e4bcabeb0664e.tar.gz) +ORIGINAL_SOURCE(https://github.com/ianlancetaylor/libbacktrace/archive/8e32931a4fe98b9bc955cb97b4702123b204f139.tar.gz) ADDINCL( contrib/libs/backtrace diff --git a/contrib/python/pytest-lazy-fixtures/.dist-info/METADATA b/contrib/python/pytest-lazy-fixtures/.dist-info/METADATA index 260a9b18ccfa..e03b9014b7d4 100644 --- a/contrib/python/pytest-lazy-fixtures/.dist-info/METADATA +++ b/contrib/python/pytest-lazy-fixtures/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: pytest-lazy-fixtures -Version: 1.0.7 +Version: 1.1.0 Summary: Allows you to use fixtures in @pytest.mark.parametrize. Home-page: https://github.com/dev-petrov/pytest-lazy-fixtures License: MIT @@ -43,7 +43,7 @@ pip install pytest-lazy-fixtures ## Usage -To use your fixtures inside `@pytest.mark.parametrize` you can use `lf` (`lazy_fixture`) or `pytest.lazy_fixtures`. +To use your fixtures inside `@pytest.mark.parametrize` you can use `lf` (`lazy_fixture`). ```python import pytest @@ -54,10 +54,6 @@ def one(): return 1 @pytest.mark.parametrize('arg1,arg2', [('val1', lf('one'))]) -def test_func(arg1, arg2): - assert arg2 == 1 - -@pytest.mark.parametrize('arg1,arg2', [('val1', pytest.lazy_fixtures('one'))]) def test_func(arg1, arg2): assert arg2 == 1 ``` @@ -96,7 +92,7 @@ def test_func(arg1, arg2): assert arg2 == 1 ``` -And there is some useful wrapper called `lfc` (`lazy_fixture_callable`) or `pytest.lazy_fixtures_callable`. +And there is some useful wrapper called `lfc` (`lazy_fixture_callable`). It can work with any callable and your fixtures, e.g. ```python diff --git a/contrib/python/pytest-lazy-fixtures/README.md b/contrib/python/pytest-lazy-fixtures/README.md index 6c13ec033a7d..ba6ff870da3b 100644 --- a/contrib/python/pytest-lazy-fixtures/README.md +++ b/contrib/python/pytest-lazy-fixtures/README.md @@ -22,7 +22,7 @@ pip install pytest-lazy-fixtures ## Usage -To use your fixtures inside `@pytest.mark.parametrize` you can use `lf` (`lazy_fixture`) or `pytest.lazy_fixtures`. +To use your fixtures inside `@pytest.mark.parametrize` you can use `lf` (`lazy_fixture`). ```python import pytest @@ -33,10 +33,6 @@ def one(): return 1 @pytest.mark.parametrize('arg1,arg2', [('val1', lf('one'))]) -def test_func(arg1, arg2): - assert arg2 == 1 - -@pytest.mark.parametrize('arg1,arg2', [('val1', pytest.lazy_fixtures('one'))]) def test_func(arg1, arg2): assert arg2 == 1 ``` @@ -75,7 +71,7 @@ def test_func(arg1, arg2): assert arg2 == 1 ``` -And there is some useful wrapper called `lfc` (`lazy_fixture_callable`) or `pytest.lazy_fixtures_callable`. +And there is some useful wrapper called `lfc` (`lazy_fixture_callable`). It can work with any callable and your fixtures, e.g. ```python diff --git a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/loader.py b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/loader.py index 3c675c2aaf1e..d2d39ff4f802 100644 --- a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/loader.py +++ b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/loader.py @@ -14,7 +14,7 @@ def load_lazy_fixtures(value, request: pytest.FixtureRequest): return value.load_fixture(request) # we need to check exact type if type(value) is dict: # noqa: E721 - return {key: load_lazy_fixtures(value, request) for key, value in value.items()} + return {load_lazy_fixtures(key, request): load_lazy_fixtures(value, request) for key, value in value.items()} # we need to check exact type elif type(value) in {list, tuple, set}: return type(value)([load_lazy_fixtures(value, request) for value in value]) diff --git a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/plugin.py b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/plugin.py index de7d75a4f79b..f3475e199c83 100644 --- a/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/plugin.py +++ b/contrib/python/pytest-lazy-fixtures/pytest_lazy_fixtures/plugin.py @@ -1,16 +1,10 @@ import pytest -from .lazy_fixture import LazyFixtureWrapper, lf -from .lazy_fixture_callable import lfc +from .lazy_fixture import LazyFixtureWrapper from .loader import load_lazy_fixtures from .normalizer import normalize_metafunc_calls -def pytest_configure(): - pytest.lazy_fixtures = lf - pytest.lazy_fixtures_callable = lfc - - @pytest.hookimpl(tryfirst=True) def pytest_fixture_setup(fixturedef, request): val = getattr(request, "param", None) diff --git a/contrib/python/pytest-lazy-fixtures/ya.make b/contrib/python/pytest-lazy-fixtures/ya.make index b672f39330f6..47d86e8e0216 100644 --- a/contrib/python/pytest-lazy-fixtures/ya.make +++ b/contrib/python/pytest-lazy-fixtures/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(1.0.7) +VERSION(1.1.0) LICENSE(MIT) From 3ac0db172a3dd434aa6f776d71efd11de9f46bba Mon Sep 17 00:00:00 2001 From: barykinni Date: Thu, 1 Aug 2024 11:45:50 +0300 Subject: [PATCH 016/104] CHYT-1167: add request method to http client 746dc5319b081f1c1c324129e799a0f17605b084 --- yt/yt/core/http/client.cpp | 22 +++++++++++----------- yt/yt/core/http/client.h | 8 ++++++++ yt/yt/core/http/mock/client.cpp | 6 ++++++ yt/yt/core/http/mock/client.h | 3 +++ yt/yt/core/http/stream.cpp | 2 +- yt/yt/core/https/client.cpp | 9 +++++++++ 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/yt/yt/core/http/client.cpp b/yt/yt/core/http/client.cpp index 6214168bd15a..dc7bf3077df7 100644 --- a/yt/yt/core/http/client.cpp +++ b/yt/yt/core/http/client.cpp @@ -94,6 +94,17 @@ class TClient return StartRequest(EMethod::Put, url, headers); } + TFuture Request( + EMethod method, + const TString& url, + const std::optional& body, + const THeadersPtr& headers) override + { + return WrapError(url, BIND([=, this, this_ = MakeStrong(this)] { + return DoRequest(method, url, body, headers); + })); + } + private: const TClientConfigPtr Config_; const IDialerPtr Dialer_; @@ -294,17 +305,6 @@ class TClient return IResponsePtr(response); } - - TFuture Request( - EMethod method, - const TString& url, - const std::optional& body, - const THeadersPtr& headers) - { - return WrapError(url, BIND([=, this, this_ = MakeStrong(this)] { - return DoRequest(method, url, body, headers); - })); - } }; //////////////////////////////////////////////////////////////////////////////// diff --git a/yt/yt/core/http/client.h b/yt/yt/core/http/client.h index 0f6ba0239fc6..a75df31142e2 100644 --- a/yt/yt/core/http/client.h +++ b/yt/yt/core/http/client.h @@ -2,6 +2,8 @@ #include "public.h" +#include "yt/yt/core/http/http.h" + #include #include @@ -63,6 +65,12 @@ struct IClient virtual TFuture StartPut( const TString& url, const THeadersPtr& headers = nullptr) = 0; + + virtual TFuture Request( + EMethod method, + const TString& url, + const std::optional& body, + const THeadersPtr& headers) = 0; }; DEFINE_REFCOUNTED_TYPE(IClient) diff --git a/yt/yt/core/http/mock/client.cpp b/yt/yt/core/http/mock/client.cpp index bec6691be0a0..69f0b345c0c1 100644 --- a/yt/yt/core/http/mock/client.cpp +++ b/yt/yt/core/http/mock/client.cpp @@ -110,6 +110,12 @@ TFuture TMockClient::StartPut(const TString& /*url*/, const T YT_UNIMPLEMENTED(); } +TFuture TMockClient::Request(EMethod method, const TString& url, const std::optional& body, const THeadersPtr& headers) +{ + auto mockResponse = Request(method, url, ToString(body), DumpHeadersSafe(headers)); + return MakeFuture(New(mockResponse)); +} + //////////////////////////////////////////////////////////////////////////////// } // namespace NYT::NHttp diff --git a/yt/yt/core/http/mock/client.h b/yt/yt/core/http/mock/client.h index ea93320e2c5b..61a01e999966 100644 --- a/yt/yt/core/http/mock/client.h +++ b/yt/yt/core/http/mock/client.h @@ -32,11 +32,14 @@ class TMockClient TFuture StartPatch(const TString& url, const THeadersPtr& headers) override; TFuture StartPut(const TString& url, const THeadersPtr& headers) override; + TFuture Request(EMethod method, const TString& url, const std::optional& body, const THeadersPtr& headers) override; + MOCK_METHOD(TMockResponse, Get, (const TString& url, const TMockHeaders& headers)); MOCK_METHOD(TMockResponse, Post, (const TString& url, const TString& body, const TMockHeaders& headers)); MOCK_METHOD(TMockResponse, Patch, (const TString& url, const TString& body, const TMockHeaders& headers)); MOCK_METHOD(TMockResponse, Put, (const TString& url, const TString& body, const TMockHeaders& headers)); MOCK_METHOD(TMockResponse, Delete, (const TString& url, const TMockHeaders& headers)); + MOCK_METHOD(TMockResponse, Request, (EMethod method, const TString& url, const std::optional& body, const TMockHeaders& headers)); }; DECLARE_REFCOUNTED_CLASS(TMockClient) diff --git a/yt/yt/core/http/stream.cpp b/yt/yt/core/http/stream.cpp index 2811da6eae15..db16ffdf53aa 100644 --- a/yt/yt/core/http/stream.cpp +++ b/yt/yt/core/http/stream.cpp @@ -682,7 +682,7 @@ TSharedRef THttpOutput::GetHeadersPart(std::optional contentLength) if (contentLength) { if (MessageType_ == EMessageType::Response || - (MessageType_ == EMessageType::Request && methodNeedsContentLength)) { + (MessageType_ == EMessageType::Request && (*contentLength > 0 || methodNeedsContentLength))) { messageHeaders << "Content-Length: " << *contentLength << "\r\n"; } } else { diff --git a/yt/yt/core/https/client.cpp b/yt/yt/core/https/client.cpp index 95ac66b8561e..7d5fbc70e57d 100644 --- a/yt/yt/core/https/client.cpp +++ b/yt/yt/core/https/client.cpp @@ -89,6 +89,15 @@ class TClient return Underlying_->StartPut(url, headers); } + TFuture Request( + EMethod method, + const TString& url, + const std::optional& body, + const THeadersPtr& headers) override + { + return Underlying_->Request(method, url, body, headers); + } + private: const IClientPtr Underlying_; }; From ce1f1f126308cd11092ee1f8e855d9e97b22318e Mon Sep 17 00:00:00 2001 From: robot-piglet Date: Thu, 1 Aug 2024 12:35:19 +0300 Subject: [PATCH 017/104] Intermediate changes --- util/string/strip_ut.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/util/string/strip_ut.cpp b/util/string/strip_ut.cpp index 283ab66fdfa2..032bbe9b4fb2 100644 --- a/util/string/strip_ut.cpp +++ b/util/string/strip_ut.cpp @@ -22,8 +22,12 @@ Y_UNIT_TEST_SUITE(TStripStringTest) { {"\n \t\r", "", "", ""}, {"", "", "", ""}, {"abc", "abc", "abc", "abc"}, + {" abc ", "abc ", " abc", "abc"}, {"a c", "a c", "a c", "a c"}, {" long string to avoid SSO \n", "long string to avoid SSO \n", " long string to avoid SSO", "long string to avoid SSO"}, + {" набор не-ascii букв ", "набор не-ascii букв ", " набор не-ascii букв", "набор не-ascii букв"}, + // Russian "х" ends with \x85, whis is a space character in some encodings. + {"последней буквой идет х ", "последней буквой идет х ", "последней буквой идет х", "последней буквой идет х"}, }; Y_UNIT_TEST(TestStrip) { @@ -32,20 +36,23 @@ Y_UNIT_TEST_SUITE(TStripStringTest) { TString s; Strip(inputStr, s); - UNIT_ASSERT_EQUAL(s, test.StripRes); + UNIT_ASSERT_VALUES_EQUAL(s, test.StripRes); - UNIT_ASSERT_EQUAL(StripString(inputStr), test.StripRes); - UNIT_ASSERT_EQUAL(StripStringLeft(inputStr), test.StripLeftRes); - UNIT_ASSERT_EQUAL(StripStringRight(inputStr), test.StripRightRes); + UNIT_ASSERT_VALUES_EQUAL(StripString(inputStr), test.StripRes); + UNIT_ASSERT_VALUES_EQUAL(StripStringLeft(inputStr), test.StripLeftRes); + UNIT_ASSERT_VALUES_EQUAL(StripStringRight(inputStr), test.StripRightRes); TStringBuf inputStrBuf(test.Str); - UNIT_ASSERT_EQUAL(StripString(inputStrBuf), test.StripRes); - UNIT_ASSERT_EQUAL(StripStringLeft(inputStrBuf), test.StripLeftRes); - UNIT_ASSERT_EQUAL(StripStringRight(inputStrBuf), test.StripRightRes); + UNIT_ASSERT_VALUES_EQUAL(StripString(inputStrBuf), test.StripRes); + UNIT_ASSERT_VALUES_EQUAL(StripStringLeft(inputStrBuf), test.StripLeftRes); + UNIT_ASSERT_VALUES_EQUAL(StripStringRight(inputStrBuf), test.StripRightRes); }; } Y_UNIT_TEST(TestStripInPlace) { + // On Darwin default locale is set to a value which interprets certain cyrillic utf-8 sequences as spaces. + // Which we do not use ::isspace and only strip ASCII spaces, we want to ensure that this will not change in the future. + std::setlocale(LC_ALL, ""); for (const auto& test : StripTests) { TString str(test.Str); Y_ASSERT(str.IsDetached() || str.empty()); // prerequisite of the test; check that we don't try to modify shared COW-string in-place by accident From 90a087da62ad42fbbe97fdbcd8dd47fe96c37892 Mon Sep 17 00:00:00 2001 From: robot-brewer Date: Thu, 1 Aug 2024 12:43:28 +0300 Subject: [PATCH 018/104] Release java-grpc #1 https://github.com/yandex/toolchain-registry/releases/tag/java-grpc-v1 c1b07468a830993d69392aabc78201b2c1fe58e6 --- build/mapping.conf.json | 2 ++ build/platform/java/grpc/resources.json | 16 ++++++++-------- build/platform/java/grpc/ya.make.prebuilt | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/build/mapping.conf.json b/build/mapping.conf.json index e67b484a8d4e..c6e062b6be24 100644 --- a/build/mapping.conf.json +++ b/build/mapping.conf.json @@ -611,6 +611,7 @@ "6406437536": "https://devtools-registry.s3.yandex.net/6406437536", "6447316775": "https://devtools-registry.s3.yandex.net/6447316775", "6133419349": "https://devtools-registry.s3.yandex.net/6133419349", + "6785543406": "https://devtools-registry.s3.yandex.net/6785543406", "1277521710": "https://devtools-registry.s3.yandex.net/1277521710", "1812152858": "https://devtools-registry.s3.yandex.net/1812152858", "289381370": "https://devtools-registry.s3.yandex.net/289381370", @@ -1341,6 +1342,7 @@ "6406437536": "gdb-14-linux-x86_64-9d91f66a1caff272af94e2fc97e690a18d910204", "6447316775": "gdb-14-linux-x86_64-9db71d8b25a56ee316036c53fd941934a95831a3", "6133419349": "gdb-14-linux-x86_64-b1fa9be28bbf4ee845d6a39a049c7b60018a3695", + "6785543406": "grpc-java-linux-x86_64-231a5a5d0bf5248caf1a9539ef29dd2b20a9d05d", "1277521710": "infra/kernel/tools/atop/build/atop-static.tar.gz", "1812152858": "junk/zubchick/buf/buf for linux", "289381370": "none-none-none-jsr305-3.0.2-sources.jar", diff --git a/build/platform/java/grpc/resources.json b/build/platform/java/grpc/resources.json index ca60d5634d9c..e02259df4a49 100644 --- a/build/platform/java/grpc/resources.json +++ b/build/platform/java/grpc/resources.json @@ -1,19 +1,19 @@ { "by_platform": { "darwin-arm64": { - "uri": "sbr:6538659252" + "uri": "sbr:6785522906" }, "darwin-x86_64": { - "uri": "sbr:6538635125" - }, - "linux-x86_64": { - "uri": "sbr:6538599922" + "uri": "sbr:6785581427" }, "linux-aarch64": { - "uri": "sbr:6538555418" + "uri": "sbr:6785818439" + }, + "linux-x86_64": { + "uri": "sbr:6785543406" }, "win32-x86_64": { - "uri": "sbr:6538717281" + "uri": "sbr:6785822552" } } -} \ No newline at end of file +} diff --git a/build/platform/java/grpc/ya.make.prebuilt b/build/platform/java/grpc/ya.make.prebuilt index 27a05320f993..7de87dd46cc8 100644 --- a/build/platform/java/grpc/ya.make.prebuilt +++ b/build/platform/java/grpc/ya.make.prebuilt @@ -4,6 +4,6 @@ ENABLE(PREBUILT) PREBUILT_PROGRAM() IF (SANDBOX_RESOURCE_URI != "") DECLARE_EXTERNAL_RESOURCE(GRPC_JAVA ${SANDBOX_RESOURCE_URI}) - PRIMARY_OUTPUT(${GRPC_JAVA_RESOURCE_GLOBAL}/grpc_java${MODULE_SUFFIX}) + PRIMARY_OUTPUT(${GRPC_JAVA_RESOURCE_GLOBAL}/bin/grpc_java${MODULE_SUFFIX}) ENDIF() END() From e43e1b272d0b7bc3a0eeb2ec4d487188f839ff10 Mon Sep 17 00:00:00 2001 From: robot-piglet Date: Thu, 1 Aug 2024 16:52:56 +0300 Subject: [PATCH 019/104] Intermediate changes --- .../future/ut_gtest/coroutine_traits_ut.cpp | 189 ++++++++++++++++++ library/cpp/threading/future/ut_gtest/ya.make | 11 + library/cpp/threading/future/ya.make | 1 + 3 files changed, 201 insertions(+) create mode 100644 library/cpp/threading/future/ut_gtest/coroutine_traits_ut.cpp create mode 100644 library/cpp/threading/future/ut_gtest/ya.make diff --git a/library/cpp/threading/future/ut_gtest/coroutine_traits_ut.cpp b/library/cpp/threading/future/ut_gtest/coroutine_traits_ut.cpp new file mode 100644 index 000000000000..a98e455c583e --- /dev/null +++ b/library/cpp/threading/future/ut_gtest/coroutine_traits_ut.cpp @@ -0,0 +1,189 @@ +#include +#include +#include +#include + +#include +#include +#include + + +TEST(TestFutureTraits, Simple) { + TVector result; + + auto coroutine1 = [&result]() -> NThreading::TFuture { + result.push_back("coroutine1"); + co_return 1; + }; + + NThreading::TPromise coroutine2SuspendPromise = NThreading::NewPromise(); + auto coroutine2 = [&result, coroutine2SuspendFuture = coroutine2SuspendPromise.GetFuture()]() -> NThreading::TFuture { + result.push_back("coroutine2"); + + result.push_back("pre_coroutine2_suspend_future"); + size_t futureResult = co_await coroutine2SuspendFuture; + result.push_back("post_coroutine2_suspend_future"); + + co_return 2 + futureResult; + }; + + auto coroutineAll = [&]() -> NThreading::TFuture { + Y_DEFER { + result.push_back("coroutine_all_destroy"); + }; + + result.push_back("pre_coroutine1"); + size_t coroutine1Res = co_await coroutine1(); + result.push_back("post_coroutine1"); + + result.push_back("pre_coroutine2"); + size_t coroutine2Res = co_await coroutine2(); + result.push_back("post_coroutine2"); + + co_return coroutine1Res + coroutine2Res; + }; + + NThreading::TFuture coroutineAllFuture = coroutineAll(); + EXPECT_FALSE(coroutineAllFuture.HasValue()); + EXPECT_FALSE(coroutineAllFuture.HasException()); + EXPECT_THAT( + result, + ::testing::ContainerEq( + TVector({ + "pre_coroutine1", + "coroutine1", + "post_coroutine1", + + "pre_coroutine2", + "coroutine2", + "pre_coroutine2_suspend_future" + }) + ) + ); + + coroutine2SuspendPromise.SetValue(3u); + EXPECT_TRUE(coroutineAllFuture.HasValue()); + EXPECT_EQ(coroutineAllFuture.GetValue(), 6u); + EXPECT_THAT( + result, + ::testing::ContainerEq( + TVector({ + "pre_coroutine1", + "coroutine1", + "post_coroutine1", + + "pre_coroutine2", + "coroutine2", + "pre_coroutine2_suspend_future", + "post_coroutine2_suspend_future", + "post_coroutine2", + + "coroutine_all_destroy" + }) + ) + ); +} + +TEST(TestFutureTraits, Exception) { + TVector result; + + auto coroutine1 = [&result]() -> NThreading::TFuture { + result.push_back("coroutine1"); + co_return 1; + }; + + auto coroutine2 = [&result]() -> NThreading::TFuture { + result.push_back("coroutine2"); + ythrow yexception() << "coroutine2 exception"; + }; + + auto coroutineAll = [&]() -> NThreading::TFuture { + Y_DEFER { + result.push_back("coroutine_all_destroy"); + }; + + result.push_back("pre_coroutine1"); + size_t coroutine1Res = co_await coroutine1(); + result.push_back("post_coroutine1"); + + result.push_back("pre_coroutine2"); + size_t coroutine2Res = co_await coroutine2(); + result.push_back("post_coroutine2"); + + co_return coroutine1Res + coroutine2Res; + }; + + EXPECT_THROW_MESSAGE_HAS_SUBSTR( + coroutineAll().GetValueSync(), + yexception, + "coroutine2 exception" + ); + EXPECT_THAT( + result, + ::testing::ContainerEq( + TVector({ + "pre_coroutine1", + "coroutine1", + "post_coroutine1", + + "pre_coroutine2", + "coroutine2", + + "coroutine_all_destroy" + }) + ) + ); +} + +TEST(TestFutureTraits, CrashOnExceptionInCoroutineHandlerResume) { + EXPECT_DEATH( + { + struct TBadPromise; + struct TBadCoroutine : std::coroutine_handle { + using promise_type = TBadPromise; + }; + + struct TBadPromise { + TBadCoroutine get_return_object() { + return {TBadCoroutine::from_promise(*this)}; + } + + std::suspend_never initial_suspend() noexcept { + return {}; + } + std::suspend_never final_suspend() noexcept { + return {}; + } + void return_void() { + } + void unhandled_exception() { + throw; + } + }; + + auto badCoroutine = []() -> TBadCoroutine { + ythrow yexception() << "bad coroutine exception"; + }; + // Sanity check + EXPECT_THROW_MESSAGE_HAS_SUBSTR( + badCoroutine(), + yexception, + "bad coroutine exception" + ); + + NThreading::TPromise promise = NThreading::NewPromise(); + auto badCoroutineWithFutureAwait = [future = promise.GetFuture()]() -> TBadCoroutine { + co_await future; + ythrow yexception() << "bad coroutine with future await exception"; + }; + + badCoroutineWithFutureAwait(); + promise.SetValue(); + }, +#if defined(_win_) + ".*" +#else + "bad coroutine with future await exception" +#endif + ); +} diff --git a/library/cpp/threading/future/ut_gtest/ya.make b/library/cpp/threading/future/ut_gtest/ya.make new file mode 100644 index 000000000000..84f7ebe2e0e1 --- /dev/null +++ b/library/cpp/threading/future/ut_gtest/ya.make @@ -0,0 +1,11 @@ +GTEST() + +PEERDIR( + library/cpp/threading/future +) + +SRCS( + coroutine_traits_ut.cpp +) + +END() diff --git a/library/cpp/threading/future/ya.make b/library/cpp/threading/future/ya.make index 1d98569906c9..77ee8b3c5391 100644 --- a/library/cpp/threading/future/ya.make +++ b/library/cpp/threading/future/ya.make @@ -19,4 +19,5 @@ RECURSE( mt_ut perf ut + ut_gtest ) From cae5d68c4cae12cdcdba67084970d51e72b4fb89 Mon Sep 17 00:00:00 2001 From: sabdenovch Date: Thu, 1 Aug 2024 16:52:57 +0300 Subject: [PATCH 020/104] YT-21050: Unique secondary index ba40304e0daf8a897f051cb7bef04e8358a7fc72 --- yt/yt/client/tablet_client/public.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/yt/yt/client/tablet_client/public.h b/yt/yt/client/tablet_client/public.h index 332a877a6de1..c0fe8449a505 100644 --- a/yt/yt/client/tablet_client/public.h +++ b/yt/yt/client/tablet_client/public.h @@ -92,6 +92,7 @@ YT_DEFINE_ERROR_ENUM( ((TableSchemaIncompatible) (1738)) ((BundleIsBanned) (1739)) ((TabletServantIsNotActive) (1740)) + ((UniqueIndexConflict) (1741)) ); DEFINE_ENUM(EInMemoryMode, @@ -222,6 +223,7 @@ DEFINE_ENUM(ETabletServiceFeatures, DEFINE_ENUM(ESecondaryIndexKind, ((FullSync) (0)) ((Unfolding) (1)) + ((Unique) (2)) ); DEFINE_ENUM(ERowMergerType, From 6a72de53917646d5eb6bb156ab672ec2de853947 Mon Sep 17 00:00:00 2001 From: artemagafonov Date: Thu, 1 Aug 2024 17:59:03 +0300 Subject: [PATCH 021/104] YT-22323: Improve logging of tcp connections a95f8b7bcb0c36cba182953b7244b4ec4c723dd1 --- yt/yt/core/bus/tcp/connection.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/yt/yt/core/bus/tcp/connection.cpp b/yt/yt/core/bus/tcp/connection.cpp index 5a26424aad33..e6241815b4f0 100644 --- a/yt/yt/core/bus/tcp/connection.cpp +++ b/yt/yt/core/bus/tcp/connection.cpp @@ -214,7 +214,9 @@ void TTcpConnection::Start() } if (!Poller_->TryRegister(this)) { - Abort(TError(NBus::EErrorCode::TransportError, "Cannot register connection pollable")); + auto error = TError(NBus::EErrorCode::TransportError, "Cannot register connection pollable"); + Abort(error); + YT_LOG_WARNING(error << *EndpointAttributes_, "Connection aborted"); return; } @@ -223,8 +225,9 @@ void TTcpConnection::Start() try { InitBuffers(); } catch (const std::exception& ex) { - Abort(TError(NBus::EErrorCode::TransportError, "I/O buffers allocation error") - << ex); + auto error = TError(NBus::EErrorCode::TransportError, "I/O buffers allocation error") << ex; + Abort(error); + YT_LOG_WARNING(error << *EndpointAttributes_, "Connection aborted"); return; } From 5b40c9f2b99b0d27c33d6dba1a064821e0134b5d Mon Sep 17 00:00:00 2001 From: melkov Date: Thu, 1 Aug 2024 21:25:27 +0300 Subject: [PATCH 022/104] YT-22414: Prepare to use TRange constructor directly instead of MakeRange * Also the same for TMutableRange. * Add TRange, TMutableRange constructor from std::span. 46da1787e68a922bb65181c63a226a3797edae0b --- library/cpp/yt/memory/range.h | 48 ++++++++++++++++++++++++++-- library/cpp/yt/memory/ref-inl.h | 2 +- library/cpp/yt/memory/shared_range.h | 2 +- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/library/cpp/yt/memory/range.h b/library/cpp/yt/memory/range.h index 7a9c0bcd7902..232de3baa1e1 100644 --- a/library/cpp/yt/memory/range.h +++ b/library/cpp/yt/memory/range.h @@ -4,10 +4,11 @@ #include -#include #include -#include #include +#include +#include +#include // For size_t. #include @@ -91,6 +92,12 @@ class TRange , Length_(elements.size()) { } + //! Constructs a TRange from an std::span. + TRange(const std::span& elements) + : Data_(elements.data()) + , Length_(elements.size()) + { } + //! Constructs a TRange from a C array. template TRange(const T (&elements)[N]) @@ -118,6 +125,19 @@ class TRange , Length_(element ? 1 : 0) { } + //! Constructs a TRange from RepeatedField. + TRange(const google::protobuf::RepeatedField& elements) + : Data_(elements.data()) + , Length_(elements.size()) + { } + + //! Constructs a TRange from RepeatedPtrField. + template + TRange(const google::protobuf::RepeatedPtrField& elements) + : Data_(elements.data()) + , Length_(elements.size()) + { } + const_iterator Begin() const { return Data_; @@ -228,6 +248,10 @@ typename TRange::const_iterator end(TRange ref) return ref.End(); } +// Deduction guide for the constructor from RepeatedPtrField. +template +TRange(const google::protobuf::RepeatedPtrField& elements) -> TRange; + //////////////////////////////////////////////////////////////////////////////// //! Constructs a TRange from a pointer and length. @@ -348,6 +372,11 @@ class TMutableRange : TRange(elements) { } + //! Constructs a TMutableRange from an std::span. + TMutableRange(std::span& elements) + : TRange(elements) + { } + //! Constructs a TMutableRange from std::array. template TMutableRange(std::array& elements) @@ -366,6 +395,17 @@ class TMutableRange : TRange(elements) { } + //! Constructs a TMutableRange from RepeatedField. + TMutableRange(google::protobuf::RepeatedField& elements) + : TRange(elements) + { } + + //! Constructs a TMutableRange from RepeatedPtrField. + template + TMutableRange(google::protobuf::RepeatedPtrField& elements) + : TRange(elements) + { } + using TRange::Begin; using TRange::End; using TRange::Front; @@ -439,6 +479,10 @@ typename TMutableRange::iterator end(TMutableRange ref) return ref.End(); } +// Deduction guide for the constructor from RepeatedPtrField. +template +TMutableRange(google::protobuf::RepeatedPtrField& elements) -> TMutableRange; + //////////////////////////////////////////////////////////////////////////////// //! Constructs a TMutableRange from a pointer and length. diff --git a/library/cpp/yt/memory/ref-inl.h b/library/cpp/yt/memory/ref-inl.h index 14b21903c057..c5756963823d 100644 --- a/library/cpp/yt/memory/ref-inl.h +++ b/library/cpp/yt/memory/ref-inl.h @@ -256,7 +256,7 @@ size_t GetByteSize(TRange parts) template size_t GetByteSize(const std::vector& parts) { - return GetByteSize(MakeRange(parts)); + return GetByteSize(TRange(parts)); } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/cpp/yt/memory/shared_range.h b/library/cpp/yt/memory/shared_range.h index de5fc354eaa4..113378670a17 100644 --- a/library/cpp/yt/memory/shared_range.h +++ b/library/cpp/yt/memory/shared_range.h @@ -191,7 +191,7 @@ TSharedRange DoMakeSharedRange(TContainer&& elements, THolders&&... holders) holder->Holders = std::tuple(std::forward(holders)...); holder->Elements = std::forward(elements); - auto range = MakeRange(holder->Elements); + auto range = TRange(holder->Elements); return TSharedRange(range, std::move(holder)); } From 89dc8db979bd4749dfbd3220ce69d0fbbcbf708d Mon Sep 17 00:00:00 2001 From: robot-piglet Date: Fri, 2 Aug 2024 00:00:50 +0300 Subject: [PATCH 023/104] Intermediate changes --- yt/python/yt/yson/__init__.py | 2 +- yt/yt/library/program/config.cpp | 2 +- yt/yt/library/program/config.h | 8 ++++---- yt/yt/library/program/public.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/yt/python/yt/yson/__init__.py b/yt/python/yt/yson/__init__.py index e9a303b4f89e..d3eb9d5dca50 100644 --- a/yt/python/yt/yson/__init__.py +++ b/yt/python/yt/yson/__init__.py @@ -54,7 +54,7 @@ print("Warning! Failed to import YSON bindings: " + message, file=_sys.stderr) try: - from yt_yson_bindings import upload_parquet, dump_parquet # noqa + from yt_yson_bindings import upload_parquet, dump_parquet, dump_orc, upload_orc # noqa HAS_PARQUET = True except ImportError as error: message = str(error) diff --git a/yt/yt/library/program/config.cpp b/yt/yt/library/program/config.cpp index b44abdd6e9ac..0544c7f8af19 100644 --- a/yt/yt/library/program/config.cpp +++ b/yt/yt/library/program/config.cpp @@ -8,7 +8,7 @@ using namespace NYTree; //////////////////////////////////////////////////////////////////////////////// -void THeapSizeLimit::Register(TRegistrar registrar) +void THeapSizeLimitConfig::Register(TRegistrar registrar) { registrar.Parameter("container_memory_ratio", &TThis::ContainerMemoryRatio) .Optional(); diff --git a/yt/yt/library/program/config.h b/yt/yt/library/program/config.h index 96f70cc33993..c91f6bac1e7c 100644 --- a/yt/yt/library/program/config.h +++ b/yt/yt/library/program/config.h @@ -35,7 +35,7 @@ namespace NYT { //////////////////////////////////////////////////////////////////////////////// -class THeapSizeLimit +class THeapSizeLimitConfig : public virtual NYTree::TYsonStruct { public: @@ -50,12 +50,12 @@ class THeapSizeLimit TDuration DumpMemoryProfileTimeout; TString DumpMemoryProfilePath; - REGISTER_YSON_STRUCT(THeapSizeLimit); + REGISTER_YSON_STRUCT(THeapSizeLimitConfig); static void Register(TRegistrar registrar); }; -DEFINE_REFCOUNTED_TYPE(THeapSizeLimit) +DEFINE_REFCOUNTED_TYPE(THeapSizeLimitConfig) //////////////////////////////////////////////////////////////////////////////// @@ -79,7 +79,7 @@ class TTCMallocConfig //! size <= 256 KiB will be under GWP-ASAN. std::optional GuardedSamplingRate; - THeapSizeLimitPtr HeapSizeLimit; + THeapSizeLimitConfigPtr HeapSizeLimit; REGISTER_YSON_STRUCT(TTCMallocConfig); diff --git a/yt/yt/library/program/public.h b/yt/yt/library/program/public.h index b10575778e48..8b2a2321d786 100644 --- a/yt/yt/library/program/public.h +++ b/yt/yt/library/program/public.h @@ -13,7 +13,7 @@ DECLARE_REFCOUNTED_CLASS(TStockpileConfig) DECLARE_REFCOUNTED_CLASS(TSingletonsConfig) DECLARE_REFCOUNTED_CLASS(TSingletonsDynamicConfig) DECLARE_REFCOUNTED_CLASS(TDiagnosticDumpConfig) -DECLARE_REFCOUNTED_CLASS(THeapSizeLimit) +DECLARE_REFCOUNTED_CLASS(THeapSizeLimitConfig) DECLARE_REFCOUNTED_CLASS(THeapProfilerConfig) //////////////////////////////////////////////////////////////////////////////// From a4aec9c1ab95d9444fd86497ba56f3c8c61454d6 Mon Sep 17 00:00:00 2001 From: robot-ratatosk Date: Fri, 2 Aug 2024 07:11:15 +0300 Subject: [PATCH 024/104] New version of the tld SKIP_CHECK SKIP_REVIEW d16503c5573e00368ec69f5e18842f6ee36ad057 --- library/cpp/tld/tlds-alpha-by-domain.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/cpp/tld/tlds-alpha-by-domain.txt b/library/cpp/tld/tlds-alpha-by-domain.txt index 7da2d2b35b30..267f7f13c18d 100644 --- a/library/cpp/tld/tlds-alpha-by-domain.txt +++ b/library/cpp/tld/tlds-alpha-by-domain.txt @@ -1,4 +1,4 @@ -# Version 2024073100, Last Updated Wed Jul 31 07:07:01 2024 UTC +# Version 2024080100, Last Updated Thu Aug 1 07:07:01 2024 UTC AAA AARP ABB From 361db6f916e56c2f127232d0260fcc910f2527b9 Mon Sep 17 00:00:00 2001 From: snermolaev Date: Fri, 2 Aug 2024 08:32:19 +0300 Subject: [PATCH 025/104] Skip GLOBAL keyword in SRCS for DESC_PROTO dad88cdc3a4e9354a746ba0649987e9e2fcb038b --- build/conf/proto.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/build/conf/proto.conf b/build/conf/proto.conf index d68ec651d390..89870fbe19b6 100644 --- a/build/conf/proto.conf +++ b/build/conf/proto.conf @@ -810,6 +810,7 @@ multimodule PROTO_LIBRARY { .EXTS=.desc .NODE_TYPE=Library .IGNORED=GENERATE_ENUM_SERIALIZATION GENERATE_ENUM_SERIALIZATION_WITH_HEADER YMAPS_SPROTO RESOURCE GO_PROTO_PLUGIN GRPC + .ALIASES=SRCS=_SRCS_NO_GLOBAL SET(PEERDIR_TAGS DESC_PROTO) ENABLE(DESC_PROTO) From 7d4535be64fde4963aa2ddd389134facac293e87 Mon Sep 17 00:00:00 2001 From: thegeorg Date: Fri, 2 Aug 2024 09:47:14 +0300 Subject: [PATCH 026/104] contrib/tools/bison: Replace patch with environment variable 59fef9fd4f33196d66de3ac1fba18aba86a7f327 --- build/conf/bison_lex.conf | 4 +++- contrib/tools/bison/lib/config-win.h | 1 + contrib/tools/bison/src/getargs.c | 8 -------- contrib/tools/bison/src/getargs.h | 2 -- contrib/tools/bison/src/output.c | 3 --- 5 files changed, 4 insertions(+), 14 deletions(-) diff --git a/build/conf/bison_lex.conf b/build/conf/bison_lex.conf index 5e3a5418f67d..f8bee6b89abe 100644 --- a/build/conf/bison_lex.conf +++ b/build/conf/bison_lex.conf @@ -3,6 +3,8 @@ # This specilizes _SRC() macro, so should be imported after generic version definition # Thus uses _ADD_HIDDEN_INPUTS() macro from ymake.core.conf +M4_PATH=contrib/tools/m4 + LEX_FLAGS= BISON_FLAGS=-v @@ -133,7 +135,7 @@ macro USE_OLD_FLEX() { macro _SRC("y", SRC, SRCFLAGS...) { .PEERDIR=build/induced/by_bison - .CMD=${tool:"contrib/tools/bison"} $BISON_FLAGS --m4=${tool:"contrib/tools/m4"} $_BISON_HEADER ${hide:_BISON_GEN_EXT} -o ${nopath;output;suf=$_BISON_GEN_EXT:SRC} ${input:SRC} ${SRCFLAGS} ${kv;hide:"p YC"} ${kv;hide:"pc light-green"} && $_BISON_PP + .CMD=${tool:"contrib/tools/bison"} $BISON_FLAGS ${env:"M4=${tool:M4_PATH}"} $_BISON_HEADER ${hide:_BISON_GEN_EXT} -o ${nopath;output;suf=$_BISON_GEN_EXT:SRC} ${input:SRC} ${SRCFLAGS} ${kv;hide:"p YC"} ${kv;hide:"pc light-green"} && $_BISON_PP .SEM=target_bison_parser PRIVATE ${input:SRC} ${output;nopath;noext;hide;suf=${OBJ_SUF}.o:SRC} ${nopath;noext;output;hide:SRC.h} ${nopath;noext;output;addincl;hide:SRC.h} && set_global_flags BISON_FLAGS $BISON_FLAGS && conan_require_tool m4/1.4.19 && conan_import '"bin, m4* -> ./bin/m4/bin"' && conan_require_tool bison/3.8.2 && conan_import '"bin, bison* -> ./bin/bison/bin"' && conan_import '"res, * -> ./bin/bison/res"' && target_macroses-ITEM && target_macroses-macro target_bison_parser && target_macroses-args PRIVATE ${input:SRC} ${output;nopath;noext;hide;suf=${OBJ_SUF}.o:SRC} ${nopath;noext;output;hide:SRC.h} ${nopath;noext;output;addincl;hide:SRC.h} && platform_vars-BISON_FLAGS ${quo:BISON_FLAGS} && conan-tool_requires m4/1.4.19 && conan-imports 'bin, m4* -> ./bin/m4/bin' && conan-tool_requires bison/3.8.2 && conan-imports 'bin, bison* -> ./bin/bison/bin' && conan-imports 'res, * -> ./bin/bison/res' } diff --git a/contrib/tools/bison/lib/config-win.h b/contrib/tools/bison/lib/config-win.h index 4e3fc4ebfa95..a3a4ad1adec4 100644 --- a/contrib/tools/bison/lib/config-win.h +++ b/contrib/tools/bison/lib/config-win.h @@ -1701,6 +1701,7 @@ char *strsignal (int signum); /* Define as a macro for copying va_list variables. */ #define va_copy gl_va_copy +#define M4 "/var/empty/gnum4-1.4.19/bin/m4" #define M4_GNU_OPTION "--gnu" #define PACKAGE_COPYRIGHT_YEAR 2013 #define _GL_ATTRIBUTE_MALLOC diff --git a/contrib/tools/bison/src/getargs.c b/contrib/tools/bison/src/getargs.c index 51d66be3f531..417e163c2aaf 100644 --- a/contrib/tools/bison/src/getargs.c +++ b/contrib/tools/bison/src/getargs.c @@ -65,8 +65,6 @@ const char *skeleton = NULL; int language_prio = default_prio; struct bison_language const *language = &valid_languages[0]; -const char* m4_path = NULL; - /** Decode an option's key. * * \param opt option being decoded. @@ -496,7 +494,6 @@ enum LOCATIONS_OPTION = CHAR_MAX + 1, PRINT_LOCALEDIR_OPTION, PRINT_DATADIR_OPTION, - M4_PATH, REPORT_FILE_OPTION }; @@ -525,7 +522,6 @@ static struct option const long_options[] = /* Hidden. */ { "trace", optional_argument, 0, 'T' }, - { "m4", required_argument, 0, M4_PATH }, /* Output. */ { "defines", optional_argument, 0, 'd' }, @@ -734,10 +730,6 @@ getargs (int argc, char *argv[]) spec_verbose_file = xstrdup (AS_FILE_NAME (optarg)); break; - case M4_PATH: - m4_path = xstrdup (AS_FILE_NAME (optarg)); - break; - default: usage (EXIT_FAILURE); } diff --git a/contrib/tools/bison/src/getargs.h b/contrib/tools/bison/src/getargs.h index b488091393a8..c5adb8487ab5 100644 --- a/contrib/tools/bison/src/getargs.h +++ b/contrib/tools/bison/src/getargs.h @@ -42,8 +42,6 @@ extern bool token_table_flag; /* for -k */ extern location yacc_loc; /* for -y */ extern bool update_flag; /* for -u */ -extern const char* m4_path; - /* GLR_PARSER is true if the input file says to use the GLR (Generalized LR) parser, and to output some additional information used by the GLR algorithm. */ diff --git a/contrib/tools/bison/src/output.c b/contrib/tools/bison/src/output.c index ae0dc5834f9e..10a6d38a7ad5 100644 --- a/contrib/tools/bison/src/output.c +++ b/contrib/tools/bison/src/output.c @@ -48,9 +48,6 @@ #include -#undef M4 -#define M4 (m4_path) - #define STR(a) XSTR(a) #define XSTR(a) #a From 5a45964796c9ec3473a077d84d58554fa74d6582 Mon Sep 17 00:00:00 2001 From: robot-contrib Date: Fri, 2 Aug 2024 10:25:55 +0300 Subject: [PATCH 027/104] Update contrib/libs/backtrace to 2024-07-18 6556f8d7260c8d1b632c0bb680c61c73c9616cb9 --- contrib/libs/backtrace/elf.c | 14 ++++---- contrib/libs/backtrace/internal.h | 5 +++ contrib/libs/backtrace/print.c | 55 ++++++++++++++++++++++--------- contrib/libs/backtrace/ya.make | 2 +- 4 files changed, 53 insertions(+), 23 deletions(-) diff --git a/contrib/libs/backtrace/elf.c b/contrib/libs/backtrace/elf.c index 575e13daf500..380cafe91a86 100644 --- a/contrib/libs/backtrace/elf.c +++ b/contrib/libs/backtrace/elf.c @@ -4848,25 +4848,25 @@ elf_zstd_decompress (const unsigned char *pin, size_t sin, { case 8: *pout++ = *plit++; - /* FALLTHROUGH */ + ATTRIBUTE_FALLTHROUGH; case 7: *pout++ = *plit++; - /* FALLTHROUGH */ + ATTRIBUTE_FALLTHROUGH; case 6: *pout++ = *plit++; - /* FALLTHROUGH */ + ATTRIBUTE_FALLTHROUGH; case 5: *pout++ = *plit++; - /* FALLTHROUGH */ + ATTRIBUTE_FALLTHROUGH; case 4: *pout++ = *plit++; - /* FALLTHROUGH */ + ATTRIBUTE_FALLTHROUGH; case 3: *pout++ = *plit++; - /* FALLTHROUGH */ + ATTRIBUTE_FALLTHROUGH; case 2: *pout++ = *plit++; - /* FALLTHROUGH */ + ATTRIBUTE_FALLTHROUGH; case 1: *pout++ = *plit++; break; diff --git a/contrib/libs/backtrace/internal.h b/contrib/libs/backtrace/internal.h index 422115a2250a..6164c01a5802 100644 --- a/contrib/libs/backtrace/internal.h +++ b/contrib/libs/backtrace/internal.h @@ -56,6 +56,11 @@ POSSIBILITY OF SUCH DAMAGE. */ # endif #endif +#ifdef __has_attribute +# if __has_attribute(fallthrough) +# define ATTRIBUTE_FALLTHROUGH __attribute__ ((fallthrough)) +# endif +#endif #ifndef ATTRIBUTE_FALLTHROUGH # if (GCC_VERSION >= 7000) # define ATTRIBUTE_FALLTHROUGH __attribute__ ((__fallthrough__)) diff --git a/contrib/libs/backtrace/print.c b/contrib/libs/backtrace/print.c index 3e61f02ebbc2..d4637af9a4fd 100644 --- a/contrib/libs/backtrace/print.c +++ b/contrib/libs/backtrace/print.c @@ -47,6 +47,39 @@ struct print_data FILE *f; }; +/* Print errors to stderr. */ + +static void +error_callback (void *data, const char *msg, int errnum) +{ + struct print_data *pdata = (struct print_data *) data; + + if (pdata->state->filename != NULL) + fprintf (stderr, "%s: ", pdata->state->filename); + fprintf (stderr, "libbacktrace: %s", msg); + if (errnum > 0) + fprintf (stderr, ": %s", strerror (errnum)); + fputc ('\n', stderr); +} + +/* Print one level of a backtrace if we couldn't get a file or function name. + Use syminfo to try to get a symbol name. */ + +static void print_syminfo_callback (void *data, uintptr_t pc, + const char *symname, uintptr_t symval, + uintptr_t symsize ATTRIBUTE_UNUSED) +{ + struct print_data *pdata = (struct print_data *) data; + + if (symname == NULL) + fprintf (pdata->f, "0x%lx ???\n\t???:0\n", (unsigned long) pc); + else + fprintf (pdata->f, "0x%lx ???\n\t%s+0x%lx:0\n", + (unsigned long) pc, + symname, + (unsigned long) (pc - symval)); +} + /* Print one level of a backtrace. */ static int @@ -55,6 +88,13 @@ print_callback (void *data, uintptr_t pc, const char *filename, int lineno, { struct print_data *pdata = (struct print_data *) data; + if (function == NULL && filename == NULL) + { + backtrace_syminfo (pdata->state, pc, print_syminfo_callback, + error_callback, data); + return 0; + } + fprintf (pdata->f, "0x%lx %s\n\t%s:%d\n", (unsigned long) pc, function == NULL ? "???" : function, @@ -63,21 +103,6 @@ print_callback (void *data, uintptr_t pc, const char *filename, int lineno, return 0; } -/* Print errors to stderr. */ - -static void -error_callback (void *data, const char *msg, int errnum) -{ - struct print_data *pdata = (struct print_data *) data; - - if (pdata->state->filename != NULL) - fprintf (stderr, "%s: ", pdata->state->filename); - fprintf (stderr, "libbacktrace: %s", msg); - if (errnum > 0) - fprintf (stderr, ": %s", strerror (errnum)); - fputc ('\n', stderr); -} - /* Print a backtrace. */ void __attribute__((noinline)) diff --git a/contrib/libs/backtrace/ya.make b/contrib/libs/backtrace/ya.make index d8d066df2c78..10bc0fe17be0 100644 --- a/contrib/libs/backtrace/ya.make +++ b/contrib/libs/backtrace/ya.make @@ -8,7 +8,7 @@ LICENSE_TEXTS(.yandex_meta/licenses.list.txt) VERSION(2024-07-18) -ORIGINAL_SOURCE(https://github.com/ianlancetaylor/libbacktrace/archive/8e32931a4fe98b9bc955cb97b4702123b204f139.tar.gz) +ORIGINAL_SOURCE(https://github.com/ianlancetaylor/libbacktrace/archive/7e2b7da3d6568d2e4e78658f22e701746a48d7e1.tar.gz) ADDINCL( contrib/libs/backtrace From 92b85f69f24f17bdfe07ce6b79a1c89a6be6570b Mon Sep 17 00:00:00 2001 From: robot-piglet Date: Fri, 2 Aug 2024 11:46:37 +0300 Subject: [PATCH 028/104] Intermediate changes --- .../threading/future/core/coroutine_traits.h | 62 ++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/library/cpp/threading/future/core/coroutine_traits.h b/library/cpp/threading/future/core/coroutine_traits.h index 5871e22a35da..f032190fb1ba 100644 --- a/library/cpp/threading/future/core/coroutine_traits.h +++ b/library/cpp/threading/future/core/coroutine_traits.h @@ -51,42 +51,46 @@ struct std::coroutine_traits, Args...> { }; }; -template -struct TFutureAwaitable { - NThreading::TFuture Future; +namespace NThreading { - TFutureAwaitable(NThreading::TFuture future) - : Future{future} - { - } + template + struct TFutureAwaitable { + NThreading::TFuture Future; - bool await_ready() const noexcept { - return Future.HasValue() || Future.HasException(); - } + TFutureAwaitable(NThreading::TFuture future) noexcept + : Future{std::move(future)} + { + } - void await_suspend(auto h) noexcept { - /* - * This library assumes that resume never throws an exception. - * This assumption is made due to the fact that the users of these library in most cases do not need to write their own coroutine handlers, - * and all coroutine handlers provided by the library do not throw exception from resume. - * - * WARNING: do not change subscribe to apply or something other here, creating an extra future state degrades performance. - */ - Future.NoexceptSubscribe( - [h](auto) mutable noexcept { - h(); - } - ); - } + bool await_ready() const noexcept { + return Future.IsReady(); + } - decltype(auto) await_resume() { - return Future.GetValue(); - } -}; + void await_suspend(auto h) noexcept { + /* + * This library assumes that resume never throws an exception. + * This assumption is made due to the fact that the users of these library in most cases do not need to write their own coroutine handlers, + * and all coroutine handlers provided by the library do not throw exception from resume. + * + * WARNING: do not change subscribe to apply or something other here, creating an extra future state degrades performance. + */ + Future.NoexceptSubscribe( + [h](auto) mutable noexcept { + h(); + } + ); + } + + decltype(auto) await_resume() { + return Future.GetValue(); + } + }; + +} // namespace NThreading template auto operator co_await(const NThreading::TFuture& future) { - return TFutureAwaitable{future}; + return NThreading::TFutureAwaitable{future}; } namespace NThreading { From 99d0a5c88a19f2a5310c8bfe5ed63ef53e8ce00b Mon Sep 17 00:00:00 2001 From: pavook Date: Fri, 2 Aug 2024 11:46:39 +0300 Subject: [PATCH 029/104] Fix TStringBuilderStream e88898a7dd45bf17aa4fc54bf91639a0fdabbca7 --- yt/yt/core/yson/string_builder_stream.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yt/yt/core/yson/string_builder_stream.h b/yt/yt/core/yson/string_builder_stream.h index b1e0aa4b1449..ae87bdd2b31d 100644 --- a/yt/yt/core/yson/string_builder_stream.h +++ b/yt/yt/core/yson/string_builder_stream.h @@ -12,10 +12,10 @@ class TStringBuilderStream final : public IOutputStream { public: - TStringBuilderStream(TStringBuilderBase* builder) noexcept; + explicit TStringBuilderStream(TStringBuilderBase* builder) noexcept; private: - TStringBuilderBase* Builder_; + TStringBuilderBase* const Builder_; void DoWrite(const void* data, size_t size) final; }; From 23b7c61b3876a421a9f239646c2f67c70877d21e Mon Sep 17 00:00:00 2001 From: babenko Date: Fri, 2 Aug 2024 12:04:49 +0300 Subject: [PATCH 030/104] Refactor and unify exit codes ec1d0c473e709e8aad76b4e190a75ad4125a9ce2 --- .../cpp/yt/memory/chunked_memory_pool-inl.h | 6 +++++ library/cpp/yt/memory/ya.make | 1 + library/cpp/yt/system/exit.cpp | 14 +++++++++++ library/cpp/yt/system/exit.h | 22 ++++++++++++++++ library/cpp/yt/system/ya.make | 1 + yt/yt/core/compression/zstd.cpp | 14 +++++++++-- yt/yt/core/concurrency/execution_stack.cpp | 4 ++- yt/yt/core/logging/log_writer_detail.cpp | 4 +-- yt/yt/core/misc/crash_handler.cpp | 4 ++- yt/yt/core/misc/fs.cpp | 3 ++- yt/yt/core/misc/shutdown.cpp | 4 ++- .../oom/tcmalloc_memory_limit_handler.cpp | 10 +++++--- yt/yt/library/process/process.cpp | 4 +-- yt/yt/library/program/program.cpp | 25 ++++++------------- yt/yt/library/program/program.h | 11 -------- 15 files changed, 85 insertions(+), 42 deletions(-) create mode 100644 library/cpp/yt/system/exit.cpp create mode 100644 library/cpp/yt/system/exit.h diff --git a/library/cpp/yt/memory/chunked_memory_pool-inl.h b/library/cpp/yt/memory/chunked_memory_pool-inl.h index 58a0cefcc2ff..25022041607a 100644 --- a/library/cpp/yt/memory/chunked_memory_pool-inl.h +++ b/library/cpp/yt/memory/chunked_memory_pool-inl.h @@ -6,6 +6,8 @@ #include "serialize.h" +#include + #include #include @@ -30,6 +32,10 @@ TDerived* TAllocationHolder::Allocate(size_t size, TRefCountedTypeCookie cookie) auto requestedSize = sizeof(TDerived) + size; auto* ptr = ::malloc(requestedSize); + if (!ptr) { + AbortProcess(ToUnderlying(EProcessExitCode::OutOfMemory)); + } + #ifndef _win_ auto allocatedSize = ::malloc_usable_size(ptr); if (allocatedSize) { diff --git a/library/cpp/yt/memory/ya.make b/library/cpp/yt/memory/ya.make index 7a5a2f88eae8..9dc437272915 100644 --- a/library/cpp/yt/memory/ya.make +++ b/library/cpp/yt/memory/ya.make @@ -21,6 +21,7 @@ PEERDIR( library/cpp/yt/assert library/cpp/yt/misc library/cpp/yt/malloc + library/cpp/yt/system ) CHECK_DEPENDENT_DIRS( diff --git a/library/cpp/yt/system/exit.cpp b/library/cpp/yt/system/exit.cpp new file mode 100644 index 000000000000..b17f6c5ad73b --- /dev/null +++ b/library/cpp/yt/system/exit.cpp @@ -0,0 +1,14 @@ +#include "exit.h" + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + +void AbortProcess(int exitCode) +{ + _exit(exitCode); +} + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT diff --git a/library/cpp/yt/system/exit.h b/library/cpp/yt/system/exit.h new file mode 100644 index 000000000000..6c009fff901b --- /dev/null +++ b/library/cpp/yt/system/exit.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + +DEFINE_ENUM(EProcessExitCode, + ((OK) (0)) + ((ArgumentsError) (1)) + ((GenericError) (2)) + ((IOError) (3)) + ((OutOfMemory) (9)) +); + +//! Invokes _exit to abort the process immediately without calling any cleanup code. +[[noreturn]] void AbortProcess(int exitCode); + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT diff --git a/library/cpp/yt/system/ya.make b/library/cpp/yt/system/ya.make index 22aab5151e7b..de4516d928e1 100644 --- a/library/cpp/yt/system/ya.make +++ b/library/cpp/yt/system/ya.make @@ -3,6 +3,7 @@ LIBRARY() INCLUDE(${ARCADIA_ROOT}/library/cpp/yt/ya_cpp.make.inc) SRCS( + exit.cpp thread_id.cpp ) diff --git a/yt/yt/core/compression/zstd.cpp b/yt/yt/core/compression/zstd.cpp index c8c067e76382..2054e0306b13 100644 --- a/yt/yt/core/compression/zstd.cpp +++ b/yt/yt/core/compression/zstd.cpp @@ -6,6 +6,8 @@ #include #include +#include + #include #include @@ -29,8 +31,16 @@ struct TZstdCompressBufferTag void VerifyError(size_t result) { - YT_LOG_FATAL_IF(ZSTD_isError(result), - "Zstd compression failed (Error: %v)", + if (!ZSTD_isError(result)) { + return; + } + + if (result == ZSTD_error_memory_allocation) { + YT_LOG_ERROR("Zstd compression failed with memory allocation error; terminating"); + AbortProcess(ToUnderlying(EProcessExitCode::OutOfMemory)); + } + + YT_LOG_FATAL("Zstd compression failed (Error: %v)", ZSTD_getErrorName(result)); } diff --git a/yt/yt/core/concurrency/execution_stack.cpp b/yt/yt/core/concurrency/execution_stack.cpp index f2a66f04764f..4fd488de08d5 100644 --- a/yt/yt/core/concurrency/execution_stack.cpp +++ b/yt/yt/core/concurrency/execution_stack.cpp @@ -18,6 +18,8 @@ #include +#include + #include namespace NYT::NConcurrency { @@ -88,7 +90,7 @@ TExecutionStack::TExecutionStack(size_t size) auto checkOom = [] { if (LastSystemError() == ENOMEM) { fprintf(stderr, "Out-of-memory condition detected while allocating execution stack; terminating\n"); - _exit(9); + AbortProcess(ToUnderlying(EProcessExitCode::OutOfMemory)); } }; diff --git a/yt/yt/core/logging/log_writer_detail.cpp b/yt/yt/core/logging/log_writer_detail.cpp index aff1c6fc1dcc..2247d15936f8 100644 --- a/yt/yt/core/logging/log_writer_detail.cpp +++ b/yt/yt/core/logging/log_writer_detail.cpp @@ -3,6 +3,7 @@ #include "log.h" #include "formatter.h" +#include #include namespace NYT::NLogging { @@ -153,8 +154,7 @@ void TStreamLogWriterBase::OnException(const std::exception& ex) /*lpNumberOfBytesWritten*/ nullptr, /*lpOverlapped*/ nullptr); #endif - _exit(100); - YT_ABORT(); + AbortProcess(ToUnderlying(EProcessExitCode::IOError)); } void TStreamLogWriterBase::ResetCurrentSegment(i64 size) diff --git a/yt/yt/core/misc/crash_handler.cpp b/yt/yt/core/misc/crash_handler.cpp index 90c1e11ec92b..0dcfd4375466 100644 --- a/yt/yt/core/misc/crash_handler.cpp +++ b/yt/yt/core/misc/crash_handler.cpp @@ -10,6 +10,8 @@ #include +#include + #include #include @@ -463,7 +465,7 @@ void DumpSigcontext(void* uc) void CrashTimeoutHandler(int /*signal*/) { WriteToStderr("*** Process hung during crash ***\n"); - _exit(1); + AbortProcess(ToUnderlying(EProcessExitCode::GenericError)); } void DumpUndumpableBlocksInfo() diff --git a/yt/yt/core/misc/fs.cpp b/yt/yt/core/misc/fs.cpp index 8092aaa85097..d0e925032a05 100644 --- a/yt/yt/core/misc/fs.cpp +++ b/yt/yt/core/misc/fs.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -826,7 +827,7 @@ void WrapIOErrors(std::function func) switch (status) { case ENOMEM: fprintf(stderr, "Out-of-memory condition detected during I/O operation; terminating\n"); - _exit(9); + AbortProcess(ToUnderlying(EProcessExitCode::OutOfMemory)); break; case EIO: diff --git a/yt/yt/core/misc/shutdown.cpp b/yt/yt/core/misc/shutdown.cpp index 412db68119e2..bb8f2adcc6de 100644 --- a/yt/yt/core/misc/shutdown.cpp +++ b/yt/yt/core/misc/shutdown.cpp @@ -13,6 +13,8 @@ #include +#include + #include #include @@ -106,7 +108,7 @@ class TShutdownManager YT_ABORT(); } else { ::fprintf(stderr, "*** Shutdown hung, exiting\n"); - ::_exit(options.HungExitCode); + AbortProcess(options.HungExitCode); } } }); diff --git a/yt/yt/library/oom/tcmalloc_memory_limit_handler.cpp b/yt/yt/library/oom/tcmalloc_memory_limit_handler.cpp index ef63f60b83b7..b135c2b43831 100644 --- a/yt/yt/library/oom/tcmalloc_memory_limit_handler.cpp +++ b/yt/yt/library/oom/tcmalloc_memory_limit_handler.cpp @@ -13,6 +13,8 @@ #include +#include + #include #include #include @@ -49,7 +51,7 @@ void CollectAndDumpMemoryProfile(const TString& memoryProfilePath) void MemoryProfileTimeoutHandler(int /*signal*/) { WriteToStderr("*** Process hung during dumping heap profile ***\n"); - ::_exit(1); + AbortProcess(ToUnderlying(EProcessExitCode::GenericError)); } void SetupMemoryProfileTimeout(int timeout) @@ -125,16 +127,16 @@ class TTCMallocLimitHandler CollectAndDumpMemoryProfile(heapDumpPath); Cerr << "TTCMallocLimitHandler: Heap profile written" << Endl; - ::_exit(0); + AbortProcess(ToUnderlying(EProcessExitCode::OK)); } if (childPid < 0) { Cerr << "TTCMallocLimitHandler: Fork failed: " << LastSystemErrorText() << Endl; - ::_exit(1); + AbortProcess(ToUnderlying(EProcessExitCode::GenericError)); } ExecWaitForChild(childPid); - ::_exit(0); + AbortProcess(ToUnderlying(EProcessExitCode::OK)); } TString GetHeapDumpPath() const diff --git a/yt/yt/library/process/process.cpp b/yt/yt/library/process/process.cpp index 5dbd21d5beb5..e786ae626560 100644 --- a/yt/yt/library/process/process.cpp +++ b/yt/yt/library/process/process.cpp @@ -15,13 +15,13 @@ #include #include +#include #include #include #include - #include #include @@ -657,7 +657,7 @@ class TSimpleProcess::TProcessSpawnState YT_VERIFY(Pipe_); ssize_t size = HandleEintr(::write, Pipe_->GetWriteFD(), &data, sizeof(data)); YT_VERIFY(size == sizeof(data)); - _exit(1); + AbortProcess(ToUnderlying(EProcessExitCode::GenericError)); } } YT_ABORT(); diff --git a/yt/yt/library/program/program.cpp b/yt/yt/library/program/program.cpp index 318d998b3a96..78a3b95c4552 100644 --- a/yt/yt/library/program/program.cpp +++ b/yt/yt/library/program/program.cpp @@ -25,6 +25,8 @@ #include #include +#include + #include #include @@ -74,7 +76,7 @@ class TProgram::TOptsParseResult { Owner_->OnError(CurrentExceptionMessage()); Cerr << Endl << "Try running '" << Owner_->Argv0_ << " --help' for more information." << Endl; - Owner_->Exit(EProgramExitCode::OptionsError); + Owner_->Exit(ToUnderlying(EProcessExitCode::ArgumentsError)); } private: @@ -137,35 +139,24 @@ int TProgram::Run(int argc, const char** argv) if (!CrashOnError_) { try { run(); - Exit(EProgramExitCode::OK); + Exit(ToUnderlying(EProcessExitCode::OK)); } catch (...) { OnError(CurrentExceptionMessage()); - Exit(EProgramExitCode::ProgramError); + Exit(ToUnderlying(EProcessExitCode::GenericError)); } } else { run(); - Exit(EProgramExitCode::OK); + Exit(ToUnderlying(EProcessExitCode::OK)); } // Cannot reach this due to #Exit calls above. YT_ABORT(); } -void TProgram::Abort(EProgramExitCode code) noexcept -{ - Abort(static_cast(code)); -} - void TProgram::Abort(int code) noexcept { NLogging::TLogManager::Get()->Shutdown(); - - ::_exit(code); -} - -void TProgram::Exit(EProgramExitCode code) noexcept -{ - Exit(static_cast(code)); + AbortProcess(code); } void TProgram::Exit(int code) noexcept @@ -329,7 +320,7 @@ void ExitZero(int /*unused*/) // TODO(babenko): replace with pure "exit" some day. // Currently this causes some RPC requests to master to be replied with "Promise abandoned" error, // which is not retriable. - _exit(0); + AbortProcess(ToUnderlying(EProcessExitCode::OK)); } } // namespace diff --git a/yt/yt/library/program/program.h b/yt/yt/library/program/program.h index f1f236cfabc4..bb27c0d99463 100644 --- a/yt/yt/library/program/program.h +++ b/yt/yt/library/program/program.h @@ -12,12 +12,6 @@ namespace NYT { //////////////////////////////////////////////////////////////////////////////// -DEFINE_ENUM(EProgramExitCode, - ((OK)(0)) - ((OptionsError)(1)) - ((ProgramError)(2)) -); - class TProgram { public: @@ -41,8 +35,6 @@ class TProgram * Aborts via |_exit| call. */ [[noreturn]] - static void Abort(EProgramExitCode code) noexcept; - [[noreturn]] static void Abort(int code) noexcept; protected: @@ -75,9 +67,6 @@ class TProgram [[noreturn]] virtual void PrintVersionAndExit(); - [[noreturn]] - void Exit(EProgramExitCode code) noexcept; - [[noreturn]] void Exit(int code) noexcept; From 2610922a0ebe85795934f2695e09392bc900260a Mon Sep 17 00:00:00 2001 From: pavook Date: Fri, 2 Aug 2024 17:25:27 +0300 Subject: [PATCH 031/104] Naming in statistics 8aee091f23875842b0e87bd9f39aa5032397f6fb --- yt/yt/core/misc/statistics-inl.h | 28 ++++++++++++++-------------- yt/yt/core/misc/statistics.cpp | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/yt/yt/core/misc/statistics-inl.h b/yt/yt/core/misc/statistics-inl.h index 2ca1778addc6..f8f3a1af90bf 100644 --- a/yt/yt/core/misc/statistics-inl.h +++ b/yt/yt/core/misc/statistics-inl.h @@ -38,22 +38,22 @@ std::pair IsCompatib TSummaryMap& existingStatistics, const NYPath::TYPath& path) { - auto hint = existingStatistics.lower_bound(path); - if (hint != existingStatistics.end()) { - if (hint->first == path) { - return {EStatisticPathConflictType::Exists, hint}; + auto it = existingStatistics.lower_bound(path); + if (it != existingStatistics.end()) { + if (it->first == path) { + return {EStatisticPathConflictType::Exists, it}; } - if (NYPath::HasPrefix(hint->first, path)) { - return {EStatisticPathConflictType::IsPrefix, hint}; + if (NYPath::HasPrefix(it->first, path)) { + return {EStatisticPathConflictType::IsPrefix, it}; } } - if (hint != existingStatistics.begin()) { - auto prev = std::prev(hint); + if (it != existingStatistics.begin()) { + auto prev = std::prev(it); if (NYPath::HasPrefix(path, prev->first)) { return {EStatisticPathConflictType::HasPrefix, prev}; } } - return {EStatisticPathConflictType::None, hint}; + return {EStatisticPathConflictType::None, it}; } //////////////////////////////////////////////////////////////////////////////// @@ -65,12 +65,12 @@ std::pair CheckedEmplaceStatistic( const NYPath::TYPath& path, Ts&&... args) { - auto [conflictType, hint] = IsCompatibleStatistic(existingStatistics, path); + auto [conflictType, hintIt] = IsCompatibleStatistic(existingStatistics, path); if (conflictType == EStatisticPathConflictType::Exists) { - return {hint, false}; + return {hintIt, false}; } if (conflictType != EStatisticPathConflictType::None) { - auto prefixPath = hint->first; + auto prefixPath = hintIt->first; auto conflictPath = path; if (conflictType == EStatisticPathConflictType::IsPrefix) { @@ -81,8 +81,8 @@ std::pair CheckedEmplaceStatistic( << TErrorAttribute("prefix_path", prefixPath) << TErrorAttribute("contained_in_path", conflictPath); } - auto emplacedIterator = existingStatistics.emplace_hint(hint, path, std::forward(args)...); - return {emplacedIterator, true}; + auto emplacedIt = existingStatistics.emplace_hint(hintIt, path, std::forward(args)...); + return {emplacedIt, true}; } //////////////////////////////////////////////////////////////////////////////// diff --git a/yt/yt/core/misc/statistics.cpp b/yt/yt/core/misc/statistics.cpp index 29e078513470..476433b57b59 100644 --- a/yt/yt/core/misc/statistics.cpp +++ b/yt/yt/core/misc/statistics.cpp @@ -93,8 +93,8 @@ bool TSummary::operator ==(const TSummary& other) const TSummary& TStatistics::GetSummary(const NYPath::TYPath& path) { - auto [iterator, _] = CheckedEmplaceStatistic(Data_, path, TSummary()); - return iterator->second; + auto [it, _] = CheckedEmplaceStatistic(Data_, path, TSummary()); + return it->second; } void TStatistics::AddSample(const NYPath::TYPath& path, i64 sample) From 9fc72f6c2ac91a3cc867ee7b76e6222b0fda72f0 Mon Sep 17 00:00:00 2001 From: melkov Date: Fri, 2 Aug 2024 23:39:10 +0300 Subject: [PATCH 032/104] YT-22414: Use TRange constructor directly instead of MakeRange * Use TMutableRange instead of MakeMutableRange. No functionality changes expected; [nodiff:caesar] 21be7d7457955cef67f2d8ca9aa00abd30dd58f1 --- yt/yt/client/api/rpc_proxy/client_impl.cpp | 2 +- .../client/api/rpc_proxy/transaction_impl.cpp | 4 +- .../client/arrow/arrow_row_stream_encoder.cpp | 4 +- yt/yt/client/table_client/key.cpp | 2 +- yt/yt/client/table_client/key_bound.cpp | 4 +- .../table_client/unittests/columnar_ut.cpp | 70 +++++++++---------- .../table_client/unittests/helpers/helpers.h | 4 +- yt/yt/client/table_client/unversioned_row.cpp | 2 +- yt/yt/client/table_client/value_consumer.cpp | 2 +- yt/yt/client/table_client/wire_protocol.cpp | 2 +- .../farm_fingerprint_stability_ut.cpp | 2 +- .../new_fair_share_thread_pool.cpp | 2 +- yt/yt/core/logging/unittests/logging_ut.cpp | 4 +- .../misc/bit_packed_unsigned_vector-inl.h | 2 +- yt/yt/core/misc/crash_handler.cpp | 4 +- .../bit_packed_integer_vector_ut.cpp | 2 +- yt/yt/core/rpc/client.cpp | 2 +- .../backtrace_introspector/introspect.cpp | 2 +- yt/yt/library/formats/arrow_writer.cpp | 4 +- yt/yt/library/oom/oom.cpp | 2 +- 20 files changed, 61 insertions(+), 61 deletions(-) diff --git a/yt/yt/client/api/rpc_proxy/client_impl.cpp b/yt/yt/client/api/rpc_proxy/client_impl.cpp index f40496f065cf..a854a959fcc6 100644 --- a/yt/yt/client/api/rpc_proxy/client_impl.cpp +++ b/yt/yt/client/api/rpc_proxy/client_impl.cpp @@ -343,7 +343,7 @@ TFuture TClient::ReshardTable( for (const auto& pivotKey : pivotKeys) { keys.push_back(pivotKey); } - writer->WriteRowset(MakeRange(keys)); + writer->WriteRowset(TRange(keys)); req->Attachments() = writer->Finish(); ToProto(req->mutable_mutating_options(), options); diff --git a/yt/yt/client/api/rpc_proxy/transaction_impl.cpp b/yt/yt/client/api/rpc_proxy/transaction_impl.cpp index 3aef87b49cc5..a5ed64fa5ce4 100644 --- a/yt/yt/client/api/rpc_proxy/transaction_impl.cpp +++ b/yt/yt/client/api/rpc_proxy/transaction_impl.cpp @@ -441,7 +441,7 @@ void TTransaction::ModifyRows( req->Attachments() = SerializeRowset( nameTable, - MakeRange(rows), + TRange(rows), req->mutable_rowset_descriptor()); TFuture future; @@ -571,7 +571,7 @@ TFuture TTransaction::PushQueueProducer( req->Attachments() = SerializeRowset( nameTable, - MakeRange(rows), + TRange(rows), req->mutable_rowset_descriptor()); return req->Invoke().Apply(BIND([] (const TApiServiceProxy::TRspPushQueueProducerPtr& rsp) { diff --git a/yt/yt/client/arrow/arrow_row_stream_encoder.cpp b/yt/yt/client/arrow/arrow_row_stream_encoder.cpp index 5413729fdc16..23a06a45b71d 100644 --- a/yt/yt/client/arrow/arrow_row_stream_encoder.cpp +++ b/yt/yt/client/arrow/arrow_row_stream_encoder.cpp @@ -189,7 +189,7 @@ struct TRecordBatchSerializationContext final template TMutableRange GetTypedValues(TMutableRef ref) { - return MakeMutableRange( + return TMutableRange( reinterpret_cast(ref.Begin()), reinterpret_cast(ref.End())); } @@ -1089,7 +1089,7 @@ class TArrowRowStreamBlockEncoder auto [recordBatchOffset, bodySize, bodyWriter] = SerializeRecordBatch( &flatbufBuilder, typedColumn.Column->ValueCount, - MakeRange({typedColumn})); + TRange({typedColumn})); auto dictionaryBatchOffset = org::apache::arrow::flatbuf::CreateDictionaryBatch( flatbufBuilder, diff --git a/yt/yt/client/table_client/key.cpp b/yt/yt/client/table_client/key.cpp index 984dc7d5921f..7ba78aa88ed0 100644 --- a/yt/yt/client/table_client/key.cpp +++ b/yt/yt/client/table_client/key.cpp @@ -138,7 +138,7 @@ void Serialize(const TKey& key, IYsonConsumer* consumer) { if (key) { BuildYsonFluently(consumer) - .DoListFor(MakeRange(key.Begin(), key.End()), [&] (TFluentList fluent, const TUnversionedValue& value) { + .DoListFor(TRange(key.Begin(), key.End()), [&] (TFluentList fluent, const TUnversionedValue& value) { fluent .Item() .Value(value); diff --git a/yt/yt/client/table_client/key_bound.cpp b/yt/yt/client/table_client/key_bound.cpp index 3274df5ce2f3..e02b894afd97 100644 --- a/yt/yt/client/table_client/key_bound.cpp +++ b/yt/yt/client/table_client/key_bound.cpp @@ -421,7 +421,7 @@ TKeyBound KeyBoundFromLegacyRow(TUnversionedRow row, bool isUpper, int keyLength auto [prefixLength, isInclusive] = GetBoundPrefixAndInclusiveness(row, isUpper, keyLength); YT_VERIFY(prefixLength <= static_cast(row.GetCount())); - row = rowBuffer->CaptureRow(MakeRange(row.Begin(), prefixLength)); + row = rowBuffer->CaptureRow(TRange(row.Begin(), prefixLength)); return TKeyBound::FromRow( row, @@ -480,7 +480,7 @@ TKeyBound ShortenKeyBound(TKeyBound keyBound, int length, const TRowBufferPtr& r // If we do perform shortening, resulting key bound is going to be inclusive despite the original inclusiveness. auto result = TKeyBound::FromRowUnchecked( - rowBuffer->CaptureRow(MakeRange(keyBound.Prefix.Begin(), length)), + rowBuffer->CaptureRow(TRange(keyBound.Prefix.Begin(), length)), /* isInclusive */ true, keyBound.IsUpper); diff --git a/yt/yt/client/table_client/unittests/columnar_ut.cpp b/yt/yt/client/table_client/unittests/columnar_ut.cpp index 35e25ecd99e0..e095d4f63fc8 100644 --- a/yt/yt/client/table_client/unittests/columnar_ut.cpp +++ b/yt/yt/client/table_client/unittests/columnar_ut.cpp @@ -24,7 +24,7 @@ TEST(TBuildValidityBitmapFromDictionaryIndexesWithZeroNullTest, LessThanByte) std::array indexes{0, 0, 1, 3, 4, 0}; ui8 result; BuildValidityBitmapFromDictionaryIndexesWithZeroNull( - MakeRange(indexes), + TRange(indexes), TMutableRef(&result, 1)); EXPECT_EQ(0x1c, result); } @@ -37,7 +37,7 @@ TEST(TBuildValidityBitmapFromDictionaryIndexesWithZeroNullTest, TenBytes) } std::array result; BuildValidityBitmapFromDictionaryIndexesWithZeroNull( - MakeRange(indexes), + TRange(indexes), TMutableRef(&result, result.size())); for (int i = 0; i < std::ssize(result); ++i) { EXPECT_EQ(0xaa, result[i]); @@ -52,7 +52,7 @@ TEST(TBuildValidityBitmapFromDictionaryIndexesWithZeroNullTest, ManyBits) } std::array result; BuildValidityBitmapFromDictionaryIndexesWithZeroNull( - MakeRange(indexes), + TRange(indexes), TMutableRef(&result, result.size())); for (int i = 0; i < std::ssize(result) - 1; ++i) { EXPECT_EQ(0xaa, result[i]); @@ -74,8 +74,8 @@ TEST(TBuildDictionaryIndexesFromDictionaryIndexesWithZeroNullTest, NonEmpty) std::array indexes{0, 1, 2, 3, 4, 5}; std::array result; BuildDictionaryIndexesFromDictionaryIndexesWithZeroNull( - MakeRange(indexes), - MakeMutableRange(result)); + TRange(indexes), + TMutableRange(result)); for (int i = 1; i < std::ssize(result); ++i) { EXPECT_EQ(indexes[i] - 1, result[i]); } @@ -91,7 +91,7 @@ TEST(TCountNullsInDictionaryIndexesWithZeroNullTest, Empty) TEST(TCountNullsInDictionaryIndexesWithZeroNullTest, NonEmpty) { std::array indexes{0, 1, 2, 0, 4, 5}; - EXPECT_EQ(2, CountNullsInDictionaryIndexesWithZeroNull(MakeRange(indexes))); + EXPECT_EQ(2, CountNullsInDictionaryIndexesWithZeroNull(TRange(indexes))); } //////////////////////////////////////////////////////////////////////////////// @@ -217,7 +217,7 @@ TEST(TTranslateRleIndexTest, CheckAll) { std::array rleIndexes{0, 1, 3, 10, 11, 15, 20, 21}; for (ui64 i = 0; i < rleIndexes[rleIndexes.size() - 1] + 10; ++i) { - auto j = TranslateRleIndex(MakeRange(rleIndexes), i); + auto j = TranslateRleIndex(TRange(rleIndexes), i); EXPECT_LE(rleIndexes[j], i); if (j < std::ssize(rleIndexes) - 1) { EXPECT_LT(i, rleIndexes[j + 1]); @@ -291,7 +291,7 @@ TEST_F(TDecodeStringsTest, Single) { std::vector result; for (int index = 0; index <= std::ssize(Offsets); ++index) { - result.push_back(DecodeStringOffset(MakeRange(Offsets), AvgLength, index)); + result.push_back(DecodeStringOffset(TRange(Offsets), AvgLength, index)); } EXPECT_EQ(Expected, result); } @@ -301,10 +301,10 @@ TEST_F(TDecodeStringsTest, Multiple) for (int i = 0; i <= std::ssize(Offsets); ++i) { for (int j = i; j <= std::ssize(Offsets); ++j) { std::vector result(j - i + 1); - DecodeStringOffsets(MakeRange(Offsets), AvgLength, i, j, MakeMutableRange(result)); + DecodeStringOffsets(TRange(Offsets), AvgLength, i, j, TMutableRange(result)); std::vector expected; for (int k = i; k <= j; ++k) { - expected.push_back(Expected[k] - DecodeStringOffset(MakeRange(Offsets), AvgLength, i)); + expected.push_back(Expected[k] - DecodeStringOffset(TRange(Offsets), AvgLength, i)); } EXPECT_EQ(expected, result); } @@ -317,11 +317,11 @@ TEST_F(TDecodeStringsTest, PointersAndLengths) std::vector strings(Offsets.size()); std::vector lengths(Offsets.size()); DecodeStringPointersAndLengths( - MakeRange(Offsets), + TRange(Offsets), AvgLength, TRef(chars.data(), chars.size()), - MakeMutableRange(strings), - MakeMutableRange(lengths)); + TMutableRange(strings), + TMutableRange(lengths)); for (int i = 0; i < std::ssize(Offsets); ++i) { EXPECT_EQ(Expected[i], strings[i] - chars.data()); EXPECT_EQ(static_cast(Expected[i + 1] - Expected[i]), lengths[i]); @@ -354,8 +354,8 @@ TEST_P(TDecodeNullsFromRleDictionaryIndexesWithZeroNullTest, ValidityBitmap) auto [startIndex, endIndex] = GetParam(); std::vector bitmap(GetBitmapByteSize(endIndex - startIndex)); BuildValidityBitmapFromRleDictionaryIndexesWithZeroNull( - MakeRange(DictionaryIndexes), - MakeRange(RleIndexes), + TRange(DictionaryIndexes), + TRange(RleIndexes), startIndex, endIndex, TMutableRef(bitmap.data(), bitmap.size())); @@ -370,11 +370,11 @@ TEST_P(TDecodeNullsFromRleDictionaryIndexesWithZeroNullTest, NullBytemap) auto [startIndex, endIndex] = GetParam(); std::vector bytemap(endIndex - startIndex); BuildNullBytemapFromRleDictionaryIndexesWithZeroNull( - MakeRange(DictionaryIndexes), - MakeRange(RleIndexes), + TRange(DictionaryIndexes), + TRange(RleIndexes), startIndex, endIndex, - MakeMutableRange(bytemap)); + TMutableRange(bytemap)); for (int i = startIndex; i < endIndex; ++i) { EXPECT_TRUE(bytemap[i - startIndex] == 0 || bytemap[i - startIndex] == 1); EXPECT_EQ(Expected[i], bytemap[i - startIndex] == 0) @@ -413,11 +413,11 @@ TEST_P(TBuildDictionaryIndexesFromRleDictionaryIndexesWithZeroNullTest, CheckAll auto [startIndex, endIndex] = GetParam(); std::vector result(endIndex - startIndex); BuildDictionaryIndexesFromRleDictionaryIndexesWithZeroNull( - MakeRange(DictionaryIndexes), - MakeRange(RleIndexes), + TRange(DictionaryIndexes), + TRange(RleIndexes), startIndex, endIndex, - MakeMutableRange(result)); + TMutableRange(result)); for (int i = startIndex; i < endIndex; ++i) { EXPECT_EQ(Expected[i], result[i - startIndex]) << "i = " << i; @@ -449,10 +449,10 @@ TEST_P(TBuildIotaDictionaryIndexesFromRleIndexesTest, CheckAll) auto [startIndex, endIndex, expected] = GetParam(); std::vector result(endIndex - startIndex); BuildIotaDictionaryIndexesFromRleIndexes( - MakeRange(RleIndexes), + TRange(RleIndexes), startIndex, endIndex, - MakeMutableRange(result)); + TMutableRange(result)); EXPECT_EQ(expected, result); } @@ -476,7 +476,7 @@ class TCountNullsInDictionaryIndexesWithZeroNullTest TEST_P(TCountNullsInDictionaryIndexesWithZeroNullTest, CheckAll) { const auto& [indexes, expected] = GetParam(); - EXPECT_EQ(expected, CountNullsInDictionaryIndexesWithZeroNull(MakeRange(indexes))); + EXPECT_EQ(expected, CountNullsInDictionaryIndexesWithZeroNull(TRange(indexes))); } INSTANTIATE_TEST_SUITE_P( @@ -502,7 +502,7 @@ class TCountOnesInRleBitmapTest TEST_P(TCountOnesInRleBitmapTest, CheckAll) { auto [startIndex, endIndex, expected] = GetParam(); - EXPECT_EQ(expected, CountOnesInRleBitmap(TRef(&Bitmap, 1), MakeRange(RleIndexes), startIndex, endIndex)); + EXPECT_EQ(expected, CountOnesInRleBitmap(TRef(&Bitmap, 1), TRange(RleIndexes), startIndex, endIndex)); } INSTANTIATE_TEST_SUITE_P( @@ -543,7 +543,7 @@ TEST_P(TDecodeNullsFromRleNullBitmapTest, ValidityBitmap) std::vector bitmap(GetBitmapByteSize(endIndex - startIndex)); BuildValidityBitmapFromRleNullBitmap( TRef(&Bitmap, 1), - MakeRange(RleIndexes), + TRange(RleIndexes), startIndex, endIndex, TMutableRef(bitmap.data(), bitmap.size())); @@ -559,10 +559,10 @@ TEST_P(TDecodeNullsFromRleNullBitmapTest, NullBytemap) std::vector bytemap(endIndex - startIndex); BuildNullBytemapFromRleNullBitmap( TRef(&Bitmap, 1), - MakeRange(RleIndexes), + TRange(RleIndexes), startIndex, endIndex, - MakeMutableRange(bytemap)); + TMutableRange(bytemap)); for (int i = startIndex; i < endIndex; ++i) { EXPECT_TRUE(bytemap[i - startIndex] == 0 || bytemap[i - startIndex] == 1); EXPECT_EQ(Expected[i], bytemap[i - startIndex] == 0) @@ -614,7 +614,7 @@ TEST_P(TDecodeBytemapFromBitmapTest, CheckAll) TRef(Bitmap.data(), Bitmap.size()), startIndex, endIndex, - MakeMutableRange(bytemap)); + TMutableRange(bytemap)); for (int i = startIndex; i < endIndex; ++i) { EXPECT_TRUE(bytemap[i - startIndex] == 0 || bytemap[i - startIndex] == 1); EXPECT_EQ(Expected[i], bytemap[i - startIndex]) @@ -661,7 +661,7 @@ class TCountTotalStringLengthInRleDictionaryIndexesWithZeroNullTest for (int i = 0; i < std::ssize(Offsets); ++i) { auto [startOffset, endOffset] = DecodeStringRange( - MakeRange(Offsets), + TRange(Offsets), AvgLength, i); Lengths.push_back(endOffset - startOffset); @@ -681,18 +681,18 @@ TEST_P(TCountTotalStringLengthInRleDictionaryIndexesWithZeroNullTest, CheckAll) auto [startIndex, endIndex] = GetParam(); auto actual = CountTotalStringLengthInRleDictionaryIndexesWithZeroNull( - MakeRange(DictionaryIndexes), - MakeRange(RleIndexes), - MakeRange(Lengths), + TRange(DictionaryIndexes), + TRange(RleIndexes), + TRange(Lengths), startIndex, endIndex); i64 expected = 0; for (int i = startIndex; i < endIndex; ++i) { - int j = TranslateRleIndex(MakeRange(RleIndexes), i); + int j = TranslateRleIndex(TRange(RleIndexes), i); auto k = DictionaryIndexes[j]; if (k != 0) { - auto [startOffset, endOffset] = DecodeStringRange(MakeRange(Offsets), AvgLength, k - 1); + auto [startOffset, endOffset] = DecodeStringRange(TRange(Offsets), AvgLength, k - 1); expected += (endOffset - startOffset); } } diff --git a/yt/yt/client/table_client/unittests/helpers/helpers.h b/yt/yt/client/table_client/unittests/helpers/helpers.h index ef17b4cae35d..8b917a16e624 100644 --- a/yt/yt/client/table_client/unittests/helpers/helpers.h +++ b/yt/yt/client/table_client/unittests/helpers/helpers.h @@ -69,7 +69,7 @@ void CheckSchemalessResult( ASSERT_LE(std::ssize(actual), options.MaxRowsPerRead); CheckSchemalessResult( - MakeRange(expected).Slice(offset, std::min(expected.size(), offset + actual.size())), + TRange(expected).Slice(offset, std::min(expected.size(), offset + actual.size())), actual, keyColumnCount); offset += actual.size(); @@ -91,7 +91,7 @@ void AppendVector(std::vector* data, const std::vector toAppend) template TRange GetTypedData(const NTableClient::IUnversionedColumnarRowBatch::TValueBuffer& buffer) { - return MakeRange( + return TRange( reinterpret_cast(buffer.Data.Begin()), reinterpret_cast(buffer.Data.End())); } diff --git a/yt/yt/client/table_client/unversioned_row.cpp b/yt/yt/client/table_client/unversioned_row.cpp index 24603024a999..e3303daaf4a8 100644 --- a/yt/yt/client/table_client/unversioned_row.cpp +++ b/yt/yt/client/table_client/unversioned_row.cpp @@ -1633,7 +1633,7 @@ std::pair, i64> CaptureRowsImpl( return { MakeSharedRange( - MakeRange(capturedRows, rows.Size()), + TRange(capturedRows, rows.Size()), std::move(buffer.ReleaseHolder())), bufferSize }; diff --git a/yt/yt/client/table_client/value_consumer.cpp b/yt/yt/client/table_client/value_consumer.cpp index 630f849f97c2..b6865a4c68c0 100644 --- a/yt/yt/client/table_client/value_consumer.cpp +++ b/yt/yt/client/table_client/value_consumer.cpp @@ -373,7 +373,7 @@ void TWritingValueConsumer::OnMyValue(const TUnversionedValue& value) void TWritingValueConsumer::OnEndRow() { - auto row = RowBuffer_->CaptureRow(MakeRange(Values_), false); + auto row = RowBuffer_->CaptureRow(TRange(Values_), false); Values_.clear(); Rows_.push_back(row); diff --git a/yt/yt/client/table_client/wire_protocol.cpp b/yt/yt/client/table_client/wire_protocol.cpp index 1fab79620ad2..6bb5446eca2c 100644 --- a/yt/yt/client/table_client/wire_protocol.cpp +++ b/yt/yt/client/table_client/wire_protocol.cpp @@ -392,7 +392,7 @@ class TWireProtocolWriter return lhs.Id < rhs.Id; }); - return MakeRange(PooledValues_); + return TRange(PooledValues_); } void UnsafeWriteNullBitmap(TUnversionedValueRange values) diff --git a/yt/yt/client/unittests/farm_fingerprint_stability_ut.cpp b/yt/yt/client/unittests/farm_fingerprint_stability_ut.cpp index 37f42a529ccd..421e8985ff40 100644 --- a/yt/yt/client/unittests/farm_fingerprint_stability_ut.cpp +++ b/yt/yt/client/unittests/farm_fingerprint_stability_ut.cpp @@ -21,7 +21,7 @@ TEST_P(TFarmHashTest, TFarmHashUnversionedValueTest) const auto& params = GetParam(); std::array values{std::get<0>(params), std::get<1>(params)}; - auto valueRange = MakeRange(values); + auto valueRange = TRange(values); auto expected1 = std::get<2>(params); auto expected2 = std::get<3>(params); diff --git a/yt/yt/core/concurrency/new_fair_share_thread_pool.cpp b/yt/yt/core/concurrency/new_fair_share_thread_pool.cpp index 3f97d7252542..d27a14605994 100644 --- a/yt/yt/core/concurrency/new_fair_share_thread_pool.cpp +++ b/yt/yt/core/concurrency/new_fair_share_thread_pool.cpp @@ -1117,7 +1117,7 @@ class TTwoLevelFairShareQueue } // Schedule other actions. - for (int threadIndex : MakeRange(threadIds.data(), requestCount)) { + for (int threadIndex : TRange(threadIds.data(), requestCount)) { if (threadRequests[threadIndex]) { if (otherActionCount > 0) { ServeBeginExecute(&ThreadStates_[threadIndex], currentInstant, std::move(OtherActions_[--otherActionCount])); diff --git a/yt/yt/core/logging/unittests/logging_ut.cpp b/yt/yt/core/logging/unittests/logging_ut.cpp index 2d14f8235d0d..5461c865b7cc 100644 --- a/yt/yt/core/logging/unittests/logging_ut.cpp +++ b/yt/yt/core/logging/unittests/logging_ut.cpp @@ -1204,7 +1204,7 @@ class TLongMessagesTest void LogLongMessages() { for (int i = 0; i < N; ++i) { - YT_LOG_INFO("%v", MakeRange(Chunks_.data(), Chunks_.data() + i)); + YT_LOG_INFO("%v", TRange(Chunks_.data(), Chunks_.data() + i)); } } @@ -1215,7 +1215,7 @@ class TLongMessagesTest auto lines = ReadPlainTextEvents(fileName); EXPECT_EQ(N, std::ssize(lines)); for (int i = 0; i < N; ++i) { - auto expected = Format("%v", MakeRange(Chunks_.data(), Chunks_.data() + i)); + auto expected = Format("%v", TRange(Chunks_.data(), Chunks_.data() + i)); auto actual = lines[i]; EXPECT_NE(TString::npos, actual.find(expected)); } diff --git a/yt/yt/core/misc/bit_packed_unsigned_vector-inl.h b/yt/yt/core/misc/bit_packed_unsigned_vector-inl.h index 83df7d6708a2..d1abbbbd0a2a 100644 --- a/yt/yt/core/misc/bit_packed_unsigned_vector-inl.h +++ b/yt/yt/core/misc/bit_packed_unsigned_vector-inl.h @@ -154,7 +154,7 @@ inline size_t TBitPackedUnsignedVectorReader::GetByteSize() const template TRange TBitPackedUnsignedVectorReader::GetData() const { - return MakeRange(Values_, Values_ + Size_); + return TRange(Values_, Values_ + Size_); } template diff --git a/yt/yt/core/misc/crash_handler.cpp b/yt/yt/core/misc/crash_handler.cpp index 0dcfd4375466..af00c5122778 100644 --- a/yt/yt/core/misc/crash_handler.cpp +++ b/yt/yt/core/misc/crash_handler.cpp @@ -85,7 +85,7 @@ Y_NO_INLINE TStackTrace GetStackTrace(TStackTraceBuffer* buffer) #endif return NBacktrace::GetBacktrace( &cursor, - MakeMutableRange(*buffer), + TMutableRange(*buffer), /*framesToSkip*/ 2); } @@ -518,7 +518,7 @@ void CrashSignalHandler(int /*signal*/, siginfo_t* si, void* uc) { std::array frames{NDetail::GetPC(uc)}; NBacktrace::SymbolizeBacktrace( - MakeRange(frames), + TRange(frames), [] (TStringBuf info) { info.SkipPrefix(" 1. "); WriteToStderr(info); diff --git a/yt/yt/core/misc/unittests/bit_packed_integer_vector_ut.cpp b/yt/yt/core/misc/unittests/bit_packed_integer_vector_ut.cpp index eaa209a13baf..ba53a942b41c 100644 --- a/yt/yt/core/misc/unittests/bit_packed_integer_vector_ut.cpp +++ b/yt/yt/core/misc/unittests/bit_packed_integer_vector_ut.cpp @@ -21,7 +21,7 @@ size_t Compress(const std::vector &data, std::vector *buffer) // NB: initialize with zeros! buffer->resize(size, 0); - return BitPackUnsignedVector(MakeRange(data), maxValue, buffer->data()); + return BitPackUnsignedVector(TRange(data), maxValue, buffer->data()); } template diff --git a/yt/yt/core/rpc/client.cpp b/yt/yt/core/rpc/client.cpp index acd67934f352..2dbc67f888a1 100644 --- a/yt/yt/core/rpc/client.cpp +++ b/yt/yt/core/rpc/client.cpp @@ -619,7 +619,7 @@ void TClientResponse::Deserialize(TSharedRefArray responseMessage) THROW_ERROR_EXCEPTION(NRpc::EErrorCode::ProtocolError, "Error deserializing response body"); } - auto compressedAttachments = MakeRange(ResponseMessage_.Begin() + 2, ResponseMessage_.End()); + auto compressedAttachments = TRange(ResponseMessage_.Begin() + 2, ResponseMessage_.End()); auto memoryUsageTracker = ClientContext_->GetMemoryUsageTracker(); if (attachmentCodecId == NCompression::ECodec::None) { diff --git a/yt/yt/library/backtrace_introspector/introspect.cpp b/yt/yt/library/backtrace_introspector/introspect.cpp index 1f6084549ee0..cfbd24a24617 100644 --- a/yt/yt/library/backtrace_introspector/introspect.cpp +++ b/yt/yt/library/backtrace_introspector/introspect.cpp @@ -162,7 +162,7 @@ void FormatBacktrace(TStringBuilder* builder, const std::vector& ba if (!backtrace.empty()) { builder->AppendString("Backtrace:\n"); SymbolizeBacktrace( - MakeRange(backtrace), + TRange(backtrace), [&] (TStringBuf str) { builder->AppendFormat(" %v", str); }); diff --git a/yt/yt/library/formats/arrow_writer.cpp b/yt/yt/library/formats/arrow_writer.cpp index 511964738f35..e540c155335d 100644 --- a/yt/yt/library/formats/arrow_writer.cpp +++ b/yt/yt/library/formats/arrow_writer.cpp @@ -275,7 +275,7 @@ struct TRecordBatchSerializationContext final template TMutableRange GetTypedValues(TMutableRef ref) { - return MakeMutableRange( + return TMutableRange( reinterpret_cast(ref.Begin()), reinterpret_cast(ref.End())); } @@ -1355,7 +1355,7 @@ class TArrowWriter auto [recordBatchOffset, bodySize, bodyWriter] = SerializeRecordBatch( &flatbufBuilder, typedColumn.Column->ValueCount, - MakeRange({typedColumn})); + TRange({typedColumn})); auto dictionaryBatchOffset = org::apache::arrow::flatbuf::CreateDictionaryBatch( flatbufBuilder, diff --git a/yt/yt/library/oom/oom.cpp b/yt/yt/library/oom/oom.cpp index 10b3e64e7b4f..cea6b6a2c2b4 100644 --- a/yt/yt/library/oom/oom.cpp +++ b/yt/yt/library/oom/oom.cpp @@ -109,7 +109,7 @@ void OomWatchdog(TOomWatchdogOptions options) rssFile, rssShmem, MakeFormattableView( - MakeRange(TCMallocStats), + TRange(TCMallocStats), [&] (auto* builder, auto metric) { auto value = tcmalloc::MallocExtension::GetNumericProperty(metric); builder->AppendFormat("%v: %v", metric, value); From 8744db6c4910e07c48a536a49886d2601c4fe6c6 Mon Sep 17 00:00:00 2001 From: ignat Date: Sat, 3 Aug 2024 07:55:33 +0300 Subject: [PATCH 033/104] YT-22431: better support for protobuf string interop in apache orc 97f3f0e3c10d73bf0dba054c53176afd21749eb7 --- contrib/libs/apache/orc/c++/include/orc/Common.hh | 4 ++++ contrib/libs/apache/orc/c++/src/Statistics.hh | 2 -- contrib/libs/apache/orc/c++/src/sargs/PredicateLeaf.cc | 2 -- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/libs/apache/orc/c++/include/orc/Common.hh b/contrib/libs/apache/orc/c++/include/orc/Common.hh index 9da67a3f1990..b3db848b5240 100644 --- a/contrib/libs/apache/orc/c++/include/orc/Common.hh +++ b/contrib/libs/apache/orc/c++/include/orc/Common.hh @@ -23,8 +23,12 @@ #include "orc/Type.hh" #include "orc/Vector.hh" +#include + #include +using TProtoStringType = decltype(std::declval<::google::protobuf::MessageLite>().GetTypeName()); + namespace orc { class FileVersion { diff --git a/contrib/libs/apache/orc/c++/src/Statistics.hh b/contrib/libs/apache/orc/c++/src/Statistics.hh index 053b6c7fd857..eb14011c410b 100644 --- a/contrib/libs/apache/orc/c++/src/Statistics.hh +++ b/contrib/libs/apache/orc/c++/src/Statistics.hh @@ -27,8 +27,6 @@ #include "Timezone.hh" #include "TypeImpl.hh" -#include - namespace orc { /** diff --git a/contrib/libs/apache/orc/c++/src/sargs/PredicateLeaf.cc b/contrib/libs/apache/orc/c++/src/sargs/PredicateLeaf.cc index 54968545b9ef..78b699f3f2e3 100644 --- a/contrib/libs/apache/orc/c++/src/sargs/PredicateLeaf.cc +++ b/contrib/libs/apache/orc/c++/src/sargs/PredicateLeaf.cc @@ -26,8 +26,6 @@ #include #include -#include - namespace orc { PredicateLeaf::PredicateLeaf(Operator op, PredicateDataType type, const std::string& colName, From ad701999eb5b93914c402b833230cf5f25958d46 Mon Sep 17 00:00:00 2001 From: thegeorg Date: Sun, 4 Aug 2024 11:38:26 +0300 Subject: [PATCH 034/104] Update contrib/tools/bison to 3.5.4 3.4.2 build is broken in NixOS, hence 3.3.x is updated to 3.5.y. 61a027adbe6cc0b27392bf3980c328640fd0ba69 --- build/sysincl/misc-win.yml | 2 + contrib/tools/bison/AUTHORS | 2 +- contrib/tools/bison/NEWS | 429 +++- contrib/tools/bison/README | 117 +- contrib/tools/bison/README-alpha | 2 +- .../tools/bison/data/{README => README.md} | 5 +- contrib/tools/bison/data/skeletons/bison.m4 | 69 +- .../tools/bison/data/skeletons/c++-skel.m4 | 2 +- contrib/tools/bison/data/skeletons/c++.m4 | 44 +- contrib/tools/bison/data/skeletons/c-like.m4 | 2 +- contrib/tools/bison/data/skeletons/c-skel.m4 | 2 +- contrib/tools/bison/data/skeletons/c.m4 | 204 +- contrib/tools/bison/data/skeletons/glr.cc | 35 +- contrib/tools/bison/data/skeletons/lalr1.cc | 341 ++- .../tools/bison/data/skeletons/location.cc | 78 +- contrib/tools/bison/data/skeletons/stack.hh | 51 +- contrib/tools/bison/data/skeletons/variant.hh | 42 +- contrib/tools/bison/data/skeletons/yacc.c | 457 ++-- contrib/tools/bison/lib/allocator.h | 2 +- contrib/tools/bison/lib/areadlink.c | 2 +- contrib/tools/bison/lib/areadlink.h | 2 +- contrib/tools/bison/lib/arg-nonnull.h | 2 +- contrib/tools/bison/lib/argmatch.c | 24 +- contrib/tools/bison/lib/argmatch.h | 250 +- contrib/tools/bison/lib/asnprintf.c | 2 +- contrib/tools/bison/lib/asprintf.c | 39 + contrib/tools/bison/lib/assure.h | 37 + contrib/tools/bison/lib/basename-lgpl.c | 2 +- contrib/tools/bison/lib/basename.c | 2 +- contrib/tools/bison/lib/binary-io.c | 18 +- contrib/tools/bison/lib/binary-io.h | 16 +- contrib/tools/bison/lib/bitrotate.h | 12 +- contrib/tools/bison/lib/bitset.c | 16 +- contrib/tools/bison/lib/bitset.h | 13 +- contrib/tools/bison/lib/bitset/array.c | 4 +- contrib/tools/bison/lib/bitset/array.h | 4 +- contrib/tools/bison/lib/bitset/base.h | 6 +- contrib/tools/bison/lib/bitset/list.c | 7 +- contrib/tools/bison/lib/bitset/list.h | 4 +- contrib/tools/bison/lib/bitset/stats.c | 12 +- contrib/tools/bison/lib/bitset/stats.h | 4 +- contrib/tools/bison/lib/bitset/table.c | 81 +- contrib/tools/bison/lib/bitset/table.h | 4 +- contrib/tools/bison/lib/bitset/vector.c | 40 +- contrib/tools/bison/lib/bitset/vector.h | 4 +- contrib/tools/bison/lib/bitsetv.c | 15 +- contrib/tools/bison/lib/bitsetv.h | 6 +- contrib/tools/bison/lib/c-ctype.h | 2 +- contrib/tools/bison/lib/c-strcase.h | 2 +- contrib/tools/bison/lib/c-strcasecmp.c | 2 +- contrib/tools/bison/lib/c-strcaseeq.h | 2 +- contrib/tools/bison/lib/c-strncasecmp.c | 2 +- contrib/tools/bison/lib/careadlinkat.c | 4 +- contrib/tools/bison/lib/careadlinkat.h | 6 +- contrib/tools/bison/lib/cloexec.c | 2 +- contrib/tools/bison/lib/cloexec.h | 2 +- contrib/tools/bison/lib/close-stream.c | 2 +- contrib/tools/bison/lib/close.c | 2 +- contrib/tools/bison/lib/closeout.c | 2 +- contrib/tools/bison/lib/closeout.h | 2 +- contrib/tools/bison/lib/concat-filename.c | 2 +- contrib/tools/bison/lib/concat-filename.h | 2 +- contrib/tools/bison/lib/config-linux.h | 213 +- contrib/tools/bison/lib/config-win.h | 7 +- contrib/tools/bison/lib/configmake-linux.h | 55 +- contrib/tools/bison/lib/configmake-win.h | 3 +- contrib/tools/bison/lib/diffseq.h | 529 ++++ contrib/tools/bison/lib/dirname-lgpl.c | 2 +- contrib/tools/bison/lib/dirname.c | 2 +- contrib/tools/bison/lib/dirname.h | 2 +- contrib/tools/bison/lib/dosname.h | 2 +- contrib/tools/bison/lib/dup-safer-flag.c | 2 +- contrib/tools/bison/lib/dup-safer.c | 2 +- contrib/tools/bison/lib/dup2.c | 2 +- contrib/tools/bison/lib/error.c | 4 +- contrib/tools/bison/lib/error.h | 2 +- contrib/tools/bison/lib/exitfail.c | 2 +- contrib/tools/bison/lib/exitfail.h | 2 +- contrib/tools/bison/lib/fatal-signal.c | 27 +- contrib/tools/bison/lib/fatal-signal.h | 13 +- contrib/tools/bison/lib/fcntl.c | 3 +- contrib/tools/bison/lib/fd-hook.c | 2 +- contrib/tools/bison/lib/fd-hook.h | 2 +- contrib/tools/bison/lib/fd-safer-flag.c | 2 +- contrib/tools/bison/lib/fd-safer.c | 2 +- contrib/tools/bison/lib/filename.h | 2 +- contrib/tools/bison/lib/float+.h | 2 +- contrib/tools/bison/lib/fopen-safer.c | 2 +- contrib/tools/bison/lib/fpending.c | 2 +- contrib/tools/bison/lib/fpending.h | 2 +- contrib/tools/bison/lib/fpucw.h | 8 +- contrib/tools/bison/lib/fseterr.c | 2 +- contrib/tools/bison/lib/fseterr.h | 2 +- contrib/tools/bison/lib/fstrcmp.c | 263 ++ contrib/tools/bison/lib/fstrcmp.h | 54 + contrib/tools/bison/lib/get-errno.c | 2 +- contrib/tools/bison/lib/get-errno.h | 2 +- contrib/tools/bison/lib/getdtablesize.c | 2 +- contrib/tools/bison/lib/gethrxtime.c | 2 +- contrib/tools/bison/lib/gethrxtime.h | 2 +- contrib/tools/bison/lib/getopt.c | 2 +- contrib/tools/bison/lib/getopt1.c | 2 +- contrib/tools/bison/lib/getopt_int.h | 2 +- contrib/tools/bison/lib/getprogname.c | 13 +- contrib/tools/bison/lib/getprogname.h | 2 +- contrib/tools/bison/lib/gettext.h | 2 +- contrib/tools/bison/lib/gl_array_list.c | 7 +- contrib/tools/bison/lib/gl_array_list.h | 2 +- contrib/tools/bison/lib/gl_list.h | 134 +- contrib/tools/bison/lib/gl_xlist.h | 2 +- contrib/tools/bison/lib/glthread/lock.c | 749 ++++++ contrib/tools/bison/lib/glthread/lock.h | 789 ++++++ contrib/tools/bison/lib/glthread/threadlib.c | 73 + contrib/tools/bison/lib/glthread/tls.c | 41 + contrib/tools/bison/lib/glthread/tls.h | 228 ++ contrib/tools/bison/lib/hard-locale.c | 48 +- contrib/tools/bison/lib/hard-locale.h | 7 +- contrib/tools/bison/lib/hash.c | 2 +- contrib/tools/bison/lib/hash.h | 5 +- contrib/tools/bison/lib/intprops.h | 584 +++++ contrib/tools/bison/lib/isnand-nolibm.h | 2 +- contrib/tools/bison/lib/isnanl-nolibm.h | 2 +- contrib/tools/bison/lib/localcharset.c | 273 ++- contrib/tools/bison/lib/localcharset.h | 31 +- contrib/tools/bison/lib/mbchar.c | 37 + contrib/tools/bison/lib/mbchar.h | 360 +++ contrib/tools/bison/lib/mbfile.c | 3 + contrib/tools/bison/lib/mbfile.h | 252 ++ contrib/tools/bison/lib/mbrtowc.c | 377 +-- contrib/tools/bison/lib/mbswidth.c | 2 +- contrib/tools/bison/lib/mbswidth.h | 2 +- contrib/tools/bison/lib/minmax.h | 2 +- contrib/tools/bison/lib/msvc-inval.c | 2 +- contrib/tools/bison/lib/msvc-inval.h | 6 +- contrib/tools/bison/lib/msvc-nothrow.c | 2 +- contrib/tools/bison/lib/msvc-nothrow.h | 2 +- contrib/tools/bison/lib/obstack.c | 2 +- contrib/tools/bison/lib/obstack.h | 2 +- contrib/tools/bison/lib/obstack_printf.c | 2 +- contrib/tools/bison/lib/open.c | 37 +- contrib/tools/bison/lib/path-join.c | 2 +- contrib/tools/bison/lib/path-join.h | 2 +- contrib/tools/bison/lib/pipe-safer.c | 2 +- contrib/tools/bison/lib/pipe2-safer.c | 2 +- contrib/tools/bison/lib/pipe2.c | 4 +- .../bison/lib/platform/win64/sys/ioctl.h | 0 .../tools/bison/lib/platform/win64/sys/stat.h | 6 +- .../tools/bison/lib/platform/win64/termios.h | 0 contrib/tools/bison/lib/printf-args.c | 6 +- contrib/tools/bison/lib/printf-args.h | 14 +- contrib/tools/bison/lib/printf-frexp.c | 2 +- contrib/tools/bison/lib/printf-frexp.h | 2 +- contrib/tools/bison/lib/printf-frexpl.c | 2 +- contrib/tools/bison/lib/printf-frexpl.h | 2 +- contrib/tools/bison/lib/printf-parse.c | 26 +- contrib/tools/bison/lib/printf-parse.h | 2 +- contrib/tools/bison/lib/progname.c | 2 +- contrib/tools/bison/lib/progname.h | 2 +- contrib/tools/bison/lib/quote.h | 2 +- contrib/tools/bison/lib/quotearg.c | 2 +- contrib/tools/bison/lib/quotearg.h | 4 +- contrib/tools/bison/lib/raise.c | 2 +- contrib/tools/bison/lib/relocatable.h | 2 +- contrib/tools/bison/lib/setlocale_null.c | 413 ++++ contrib/tools/bison/lib/setlocale_null.h | 82 + contrib/tools/bison/lib/sig-handler.h | 2 +- contrib/tools/bison/lib/sigaction.c | 2 +- contrib/tools/bison/lib/sigprocmask.c | 2 +- contrib/tools/bison/lib/spawn-pipe.c | 2 +- contrib/tools/bison/lib/spawn-pipe.h | 2 +- contrib/tools/bison/lib/stdio-impl.h | 15 +- contrib/tools/bison/lib/stdio-safer.h | 2 +- contrib/tools/bison/lib/stpcpy.c | 2 +- contrib/tools/bison/lib/streq.h | 2 +- contrib/tools/bison/lib/stripslash.c | 2 +- contrib/tools/bison/lib/strndup.c | 2 +- contrib/tools/bison/lib/strverscmp.c | 37 +- contrib/tools/bison/lib/textstyle.h | 466 ++++ contrib/tools/bison/lib/timespec.h | 2 +- contrib/tools/bison/lib/timevar.c | 4 +- contrib/tools/bison/lib/timevar.def | 2 +- contrib/tools/bison/lib/timevar.h | 4 +- contrib/tools/bison/lib/unistd-safer.h | 2 +- contrib/tools/bison/lib/unitypes.h | 15 +- contrib/tools/bison/lib/uniwidth.h | 2 +- contrib/tools/bison/lib/uniwidth/cjk.h | 2 +- contrib/tools/bison/lib/uniwidth/width.c | 2 +- contrib/tools/bison/lib/unlocked-io.h | 2 +- contrib/tools/bison/lib/vasnprintf.c | 29 +- contrib/tools/bison/lib/vasnprintf.h | 8 +- contrib/tools/bison/lib/vasprintf.c | 50 + contrib/tools/bison/lib/verify.h | 122 +- contrib/tools/bison/lib/w32spawn.h | 2 +- contrib/tools/bison/lib/wait-process.c | 14 +- contrib/tools/bison/lib/wait-process.h | 2 +- contrib/tools/bison/lib/waitpid.c | 2 +- contrib/tools/bison/lib/wcwidth.c | 2 +- contrib/tools/bison/lib/windows-initguard.h | 35 + contrib/tools/bison/lib/windows-mutex.c | 95 + contrib/tools/bison/lib/windows-mutex.h | 51 + contrib/tools/bison/lib/windows-once.c | 62 + contrib/tools/bison/lib/windows-once.h | 47 + contrib/tools/bison/lib/windows-recmutex.c | 127 + contrib/tools/bison/lib/windows-recmutex.h | 57 + contrib/tools/bison/lib/windows-rwlock.c | 373 +++ contrib/tools/bison/lib/windows-rwlock.h | 68 + contrib/tools/bison/lib/windows-tls.c | 339 +++ contrib/tools/bison/lib/windows-tls.h | 42 + contrib/tools/bison/lib/xalloc-die.c | 2 +- contrib/tools/bison/lib/xalloc-oversized.h | 2 +- contrib/tools/bison/lib/xalloc.h | 4 +- contrib/tools/bison/lib/xconcat-filename.c | 2 +- contrib/tools/bison/lib/xhash.c | 38 + contrib/tools/bison/lib/xmalloc.c | 8 +- contrib/tools/bison/lib/xmemdup0.c | 5 +- contrib/tools/bison/lib/xmemdup0.h | 2 +- contrib/tools/bison/lib/xreadlink.c | 2 +- contrib/tools/bison/lib/xreadlink.h | 2 +- contrib/tools/bison/lib/xsize.h | 2 +- contrib/tools/bison/lib/xstrndup.c | 2 +- contrib/tools/bison/lib/xstrndup.h | 2 +- contrib/tools/bison/lib/xtime.h | 39 +- contrib/tools/bison/lib/ya.make | 16 + contrib/tools/bison/src/AnnotationList.c | 4 +- contrib/tools/bison/src/AnnotationList.h | 4 +- contrib/tools/bison/src/InadequacyList.c | 11 +- contrib/tools/bison/src/InadequacyList.h | 7 +- contrib/tools/bison/src/Sbitset.c | 2 +- contrib/tools/bison/src/Sbitset.h | 2 +- contrib/tools/bison/src/assoc.c | 6 +- contrib/tools/bison/src/assoc.h | 2 +- contrib/tools/bison/src/closure.c | 25 +- contrib/tools/bison/src/closure.h | 23 +- contrib/tools/bison/src/complain.c | 346 ++- contrib/tools/bison/src/complain.h | 61 +- contrib/tools/bison/src/conflicts.c | 73 +- contrib/tools/bison/src/conflicts.h | 2 +- contrib/tools/bison/src/derives.c | 27 +- contrib/tools/bison/src/derives.h | 2 +- contrib/tools/bison/src/files.c | 41 +- contrib/tools/bison/src/files.h | 10 +- contrib/tools/bison/src/fixits.c | 34 +- contrib/tools/bison/src/fixits.h | 2 +- contrib/tools/bison/src/flex-scanner.h | 2 +- contrib/tools/bison/src/getargs.c | 524 ++-- contrib/tools/bison/src/getargs.h | 15 +- contrib/tools/bison/src/gram.c | 133 +- contrib/tools/bison/src/gram.h | 53 +- contrib/tools/bison/src/graphviz.c | 10 +- contrib/tools/bison/src/graphviz.h | 2 +- contrib/tools/bison/src/ielr.c | 104 +- contrib/tools/bison/src/ielr.h | 2 +- contrib/tools/bison/src/lalr.c | 371 ++- contrib/tools/bison/src/lalr.h | 11 +- contrib/tools/bison/src/location.c | 535 +++- contrib/tools/bison/src/location.h | 60 +- contrib/tools/bison/src/{LR0.c => lr0.c} | 179 +- contrib/tools/bison/src/{LR0.h => lr0.h} | 4 +- contrib/tools/bison/src/main.c | 33 +- contrib/tools/bison/src/muscle-tab.c | 39 +- contrib/tools/bison/src/muscle-tab.h | 7 +- contrib/tools/bison/src/named-ref.c | 2 +- contrib/tools/bison/src/named-ref.h | 2 +- contrib/tools/bison/src/nullable.c | 2 +- contrib/tools/bison/src/nullable.h | 2 +- contrib/tools/bison/src/output.c | 104 +- contrib/tools/bison/src/output.h | 5 +- contrib/tools/bison/src/parse-gram.c | 2170 ++++++++--------- contrib/tools/bison/src/parse-gram.h | 149 +- .../src/{print_graph.c => print-graph.c} | 20 +- .../src/{print_graph.h => print-graph.h} | 2 +- contrib/tools/bison/src/print-xml.c | 59 +- contrib/tools/bison/src/print-xml.h | 6 +- contrib/tools/bison/src/print.c | 137 +- contrib/tools/bison/src/print.h | 2 +- contrib/tools/bison/src/reader.c | 173 +- contrib/tools/bison/src/reader.h | 12 +- contrib/tools/bison/src/reduce.c | 67 +- contrib/tools/bison/src/reduce.h | 6 +- contrib/tools/bison/src/relation.c | 121 +- contrib/tools/bison/src/relation.h | 19 +- contrib/tools/bison/src/scan-code.c | 303 ++- contrib/tools/bison/src/scan-code.h | 2 +- contrib/tools/bison/src/scan-gram.c | 1759 ++++++------- contrib/tools/bison/src/scan-gram.h | 17 +- contrib/tools/bison/src/scan-skel.h | 2 +- contrib/tools/bison/src/state.c | 144 +- contrib/tools/bison/src/state.h | 35 +- contrib/tools/bison/src/symlist.c | 33 +- contrib/tools/bison/src/symlist.h | 23 +- contrib/tools/bison/src/symtab.c | 349 ++- contrib/tools/bison/src/symtab.h | 34 +- contrib/tools/bison/src/system.h | 36 +- contrib/tools/bison/src/tables.c | 88 +- contrib/tools/bison/src/tables.h | 6 +- contrib/tools/bison/src/uniqstr.c | 12 +- contrib/tools/bison/src/uniqstr.h | 2 +- contrib/tools/bison/ya.make | 11 +- 298 files changed, 13873 insertions(+), 5499 deletions(-) rename contrib/tools/bison/data/{README => README.md} (98%) create mode 100644 contrib/tools/bison/lib/asprintf.c create mode 100644 contrib/tools/bison/lib/assure.h create mode 100644 contrib/tools/bison/lib/diffseq.h create mode 100644 contrib/tools/bison/lib/fstrcmp.c create mode 100644 contrib/tools/bison/lib/fstrcmp.h create mode 100644 contrib/tools/bison/lib/glthread/lock.c create mode 100644 contrib/tools/bison/lib/glthread/lock.h create mode 100644 contrib/tools/bison/lib/glthread/threadlib.c create mode 100644 contrib/tools/bison/lib/glthread/tls.c create mode 100644 contrib/tools/bison/lib/glthread/tls.h create mode 100644 contrib/tools/bison/lib/intprops.h create mode 100644 contrib/tools/bison/lib/mbchar.c create mode 100644 contrib/tools/bison/lib/mbchar.h create mode 100644 contrib/tools/bison/lib/mbfile.c create mode 100644 contrib/tools/bison/lib/mbfile.h create mode 100644 contrib/tools/bison/lib/platform/win64/sys/ioctl.h create mode 100644 contrib/tools/bison/lib/platform/win64/termios.h create mode 100644 contrib/tools/bison/lib/setlocale_null.c create mode 100644 contrib/tools/bison/lib/setlocale_null.h create mode 100644 contrib/tools/bison/lib/textstyle.h create mode 100644 contrib/tools/bison/lib/vasprintf.c create mode 100644 contrib/tools/bison/lib/windows-initguard.h create mode 100644 contrib/tools/bison/lib/windows-mutex.c create mode 100644 contrib/tools/bison/lib/windows-mutex.h create mode 100644 contrib/tools/bison/lib/windows-once.c create mode 100644 contrib/tools/bison/lib/windows-once.h create mode 100644 contrib/tools/bison/lib/windows-recmutex.c create mode 100644 contrib/tools/bison/lib/windows-recmutex.h create mode 100644 contrib/tools/bison/lib/windows-rwlock.c create mode 100644 contrib/tools/bison/lib/windows-rwlock.h create mode 100644 contrib/tools/bison/lib/windows-tls.c create mode 100644 contrib/tools/bison/lib/windows-tls.h create mode 100644 contrib/tools/bison/lib/xhash.c rename contrib/tools/bison/src/{LR0.c => lr0.c} (70%) rename contrib/tools/bison/src/{LR0.h => lr0.h} (96%) rename contrib/tools/bison/src/{print_graph.c => print-graph.c} (93%) rename contrib/tools/bison/src/{print_graph.h => print-graph.h} (93%) diff --git a/build/sysincl/misc-win.yml b/build/sysincl/misc-win.yml index cef2a54d5037..4410b37521f4 100644 --- a/build/sysincl/misc-win.yml +++ b/build/sysincl/misc-win.yml @@ -86,8 +86,10 @@ - sched.h: contrib/tools/bison/lib/platform/win64/sched.h - signal.h: contrib/tools/bison/lib/platform/win64/signal.h - spawn.h: contrib/tools/bison/lib/platform/win64/spawn.h + - sys/ioctl.h: contrib/tools/bison/lib/platform/win64/sys/ioctl.h - sys/stat.h: contrib/tools/bison/lib/platform/win64/sys/stat.h - sys/wait.h: contrib/tools/bison/lib/platform/win64/sys/wait.h + - termios.h: contrib/tools/bison/lib/platform/win64/termios.h - unistd.h: contrib/tools/bison/lib/platform/win64/unistd.h - source_filter: "^contrib/tools/m4/" diff --git a/contrib/tools/bison/AUTHORS b/contrib/tools/bison/AUTHORS index 63946aa31758..e624c51bc716 100644 --- a/contrib/tools/bison/AUTHORS +++ b/contrib/tools/bison/AUTHORS @@ -24,7 +24,7 @@ and nasty bugs. ----- -Copyright (C) 1998-2015, 2018-2019 Free Software Foundation, Inc. +Copyright (C) 1998-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/NEWS b/contrib/tools/bison/NEWS index 30e31ff58455..75c8abdcb7cc 100644 --- a/contrib/tools/bison/NEWS +++ b/contrib/tools/bison/NEWS @@ -1,5 +1,422 @@ GNU Bison NEWS +* Noteworthy changes in release 3.5.4 (2020-04-05) [stable] + +** WARNING: Future backward-incompatibilities! + + TL;DR: replace "#define YYERROR_VERBOSE 1" by "%define parse.error verbose". + + Bison 3.6 will no longer support the YYERROR_VERBOSE macro; the parsers + that still depend on it will produce Yacc-like error messages (just + "syntax error"). It was superseded by the "%error-verbose" directive in + Bison 1.875 (2003-01-01). Bison 2.6 (2012-07-19) clearly announced that + support for YYERROR_VERBOSE would be removed. Note that since Bison 3.0 + (2013-07-25), "%error-verbose" is deprecated in favor of "%define + parse.error verbose". + +** Bug fixes + + Fix portability issues of the package itself on old compilers. + + Fix api.token.raw support in Java. + +* Noteworthy changes in release 3.5.3 (2020-03-08) [stable] + +** Bug fixes + + Error messages could quote lines containing zero-width characters (such as + \005) with incorrect styling. Fixes for similar issues with unexpectedly + short lines (e.g., the file was changed between parsing and diagnosing). + + Several unlikely crashes found by fuzzing have been fixed. + +* Noteworthy changes in release 3.5.2 (2020-02-13) [stable] + +** Bug fixes + + Portability issues and minor cosmetic issues. + + The lalr1.cc skeleton properly rejects unsupported values for parse.lac + (as yacc.c does). + +* Noteworthy changes in release 3.5.1 (2020-01-19) [stable] + +** Bug fixes + + Portability fixes. + + Fix compiler warnings. + +* Noteworthy changes in release 3.5 (2019-12-11) [stable] + +** Backward incompatible changes + + Lone carriage-return characters (aka \r or ^M) in the grammar files are no + longer treated as end-of-lines. This changes the diagnostics, and in + particular their locations. + + In C++, line numbers and columns are now represented as 'int' not + 'unsigned', so that integer overflow on positions is easily checkable via + 'gcc -fsanitize=undefined' and the like. This affects the API for + positions. The default position and location classes now expose + 'counter_type' (int), used to define line and column numbers. + +** Deprecated features + + The YYPRINT macro, which works only with yacc.c and only for tokens, was + obsoleted long ago by %printer, introduced in Bison 1.50 (November 2002). + It is deprecated and its support will be removed eventually. + +** New features + +*** Lookahead correction in C++ + + Contributed by Adrian Vogelsgesang. + + The C++ deterministic skeleton (lalr1.cc) now supports LAC, via the + %define variable parse.lac. + +*** Variable api.token.raw: Optimized token numbers (all skeletons) + + In the generated parsers, tokens have two numbers: the "external" token + number as returned by yylex (which starts at 257), and the "internal" + symbol number (which starts at 3). Each time yylex is called, a table + lookup maps the external token number to the internal symbol number. + + When the %define variable api.token.raw is set, tokens are assigned their + internal number, which saves one table lookup per token, and also saves + the generation of the mapping table. + + The gain is typically moderate, but in extreme cases (very simple user + actions), a 10% improvement can be observed. + +*** Generated parsers use better types for states + + Stacks now use the best integral type for state numbers, instead of always + using 15 bits. As a result "small" parsers now have a smaller memory + footprint (they use 8 bits), and there is support for large automata (16 + bits), and extra large (using int, i.e., typically 31 bits). + +*** Generated parsers prefer signed integer types + + Bison skeletons now prefer signed to unsigned integer types when either + will do, as the signed types are less error-prone and allow for better + checking with 'gcc -fsanitize=undefined'. Also, the types chosen are now + portable to unusual machines where char, short and int are all the same + width. On non-GNU platforms this may entail including and (if + available) to define integer types and constants. + +*** A skeleton for the D programming language + + For the last few releases, Bison has shipped a stealth experimental + skeleton: lalr1.d. It was first contributed by Oliver Mangold, based on + Paolo Bonzini's lalr1.java, and was cleaned and improved thanks to + H. S. Teoh. + + However, because nobody has committed to improving, testing, and + documenting this skeleton, it is not clear that it will be supported in + the future. + + The lalr1.d skeleton *is functional*, and works well, as demonstrated in + examples/d/calc.d. Please try it, enjoy it, and... commit to support it. + +*** Debug traces in Java + + The Java backend no longer emits code and data for parser tracing if the + %define variable parse.trace is not defined. + +** Diagnostics + +*** New diagnostic: -Wdangling-alias + + String literals, which allow for better error messages, are (too) + liberally accepted by Bison, which might result in silent errors. For + instance + + %type cond "condition" + + does not define "condition" as a string alias to 'cond' (nonterminal + symbols do not have string aliases). It is rather equivalent to + + %nterm cond + %token "condition" + + i.e., it gives the type 'exVal' to the "condition" token, which was + clearly not the intention. + + Also, because string aliases need not be defined, typos such as "baz" + instead of "bar" will be not reported. + + The option -Wdangling-alias catches these situations. On + + %token BAR "bar" + %type foo "foo" + %% + foo: "baz" {} + + bison -Wdangling-alias reports + + warning: string literal not attached to a symbol + | %type foo "foo" + | ^~~~~ + warning: string literal not attached to a symbol + | foo: "baz" {} + | ^~~~~ + + The -Wall option does not (yet?) include -Wdangling-alias. + +*** Better POSIX Yacc compatibility diagnostics + + POSIX Yacc restricts %type to nonterminals. This is now diagnosed by + -Wyacc. + + %token TOKEN1 + %type TOKEN1 TOKEN2 't' + %token TOKEN2 + %% + expr: + + gives with -Wyacc + + input.y:2.15-20: warning: POSIX yacc reserves %type to nonterminals [-Wyacc] + 2 | %type TOKEN1 TOKEN2 't' + | ^~~~~~ + input.y:2.29-31: warning: POSIX yacc reserves %type to nonterminals [-Wyacc] + 2 | %type TOKEN1 TOKEN2 't' + | ^~~ + input.y:2.22-27: warning: POSIX yacc reserves %type to nonterminals [-Wyacc] + 2 | %type TOKEN1 TOKEN2 't' + | ^~~~~~ + +*** Diagnostics with insertion + + The diagnostics now display the suggestion below the underlined source. + Replacement for undeclared symbols are now also suggested. + + $ cat /tmp/foo.y + %% + list: lis '.' | + + $ bison -Wall foo.y + foo.y:2.7-9: error: symbol 'lis' is used, but is not defined as a token and has no rules; did you mean 'list'? + 2 | list: lis '.' | + | ^~~ + | list + foo.y:2.16: warning: empty rule without %empty [-Wempty-rule] + 2 | list: lis '.' | + | ^ + | %empty + foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother] + +*** Diagnostics about long lines + + Quoted sources may now be truncated to fit the screen. For instance, on a + 30-column wide terminal: + + $ cat foo.y + %token FOO FOO FOO + %% + exp: FOO + $ bison foo.y + foo.y:1.34-36: warning: symbol FOO redeclared [-Wother] + 1 | … FOO … + | ^~~ + foo.y:1.8-10: previous declaration + 1 | %token FOO … + | ^~~ + foo.y:1.62-64: warning: symbol FOO redeclared [-Wother] + 1 | … FOO + | ^~~ + foo.y:1.8-10: previous declaration + 1 | %token FOO … + | ^~~ + +** Changes + +*** Debugging glr.c and glr.cc + + The glr.c skeleton always had asserts to check its own behavior (not the + user's). These assertions are now under the control of the parse.assert + %define variable (disabled by default). + +*** Clean up + + Several new compiler warnings in the generated output have been avoided. + Some unused features are no longer emitted. Cleaner generated code in + general. + +** Bug Fixes + + Portability issues in the test suite. + + In theory, parsers using %nonassoc could crash when reporting verbose + error messages. This unlikely bug has been fixed. + + In Java, %define api.prefix was ignored. It now behaves as expected. + +* Noteworthy changes in release 3.4.2 (2019-09-12) [stable] + +** Bug fixes + + In some cases, when warnings are disabled, bison could emit tons of white + spaces as diagnostics. + + When running out of memory, bison could crash (found by fuzzing). + + When defining twice the EOF token, bison would crash. + + New warnings from recent compilers have been addressed in the generated + parsers (yacc.c, glr.c, glr.cc). + + When lone carriage-return characters appeared in the input file, + diagnostics could hang forever. + +* Noteworthy changes in release 3.4.1 (2019-05-22) [stable] + +** Bug fixes + + Portability fixes. + +* Noteworthy changes in release 3.4 (2019-05-19) [stable] + +** Deprecated features + + The %pure-parser directive is deprecated in favor of '%define api.pure' + since Bison 2.3b (2008-05-27), but no warning was issued; there is one + now. Note that since Bison 2.7 you are strongly encouraged to use + '%define api.pure full' instead of '%define api.pure'. + +** New features + +*** Colored diagnostics + + As an experimental feature, diagnostics are now colored, controlled by the + new options --color and --style. + + To use them, install the libtextstyle library before configuring Bison. + It is available from + + https://alpha.gnu.org/gnu/gettext/ + + for instance + + https://alpha.gnu.org/gnu/gettext/libtextstyle-0.8.tar.gz + + The option --color supports the following arguments: + - always, yes: Enable colors. + - never, no: Disable colors. + - auto, tty (default): Enable colors if the output device is a tty. + + To customize the styles, create a CSS file similar to + + /* bison-bw.css */ + .warning { } + .error { font-weight: 800; text-decoration: underline; } + .note { } + + then invoke bison with --style=bison-bw.css, or set the BISON_STYLE + environment variable to "bison-bw.css". + +*** Disabling output + + When given -fsyntax-only, the diagnostics are reported, but no output is + generated. + + The name of this option is somewhat misleading as bison does more than + just checking the syntax: every stage is run (including checking for + conflicts for instance), except the generation of the output files. + +*** Include the generated header (yacc.c) + + Before, when --defines is used, bison generated a header, and pasted an + exact copy of it into the generated parser implementation file. If the + header name is not "y.tab.h", it is now #included instead of being + duplicated. + + To use an '#include' even if the header name is "y.tab.h" (which is what + happens with --yacc, or when using the Autotools' ylwrap), define + api.header.include to the exact argument to pass to #include. For + instance: + + %define api.header.include {"parse.h"} + + or + + %define api.header.include {} + +*** api.location.type is now supported in C (yacc.c, glr.c) + + The %define variable api.location.type defines the name of the type to use + for locations. When defined, Bison no longer defines YYLTYPE. + + This can be used in programs with several parsers to factor their + definition of locations: let one of them generate them, and the others + just use them. + +** Changes + +*** Graphviz output + + In conformance with the recommendations of the Graphviz team, if %require + "3.4" (or better) is specified, the option --graph generates a *.gv file + by default, instead of *.dot. + +*** Diagnostics overhaul + + Column numbers were wrong with multibyte characters, which would also + result in skewed diagnostics with carets. Beside, because we were + indenting the quoted source with a single space, lines with tab characters + were incorrectly underlined. + + To address these issues, and to be clearer, Bison now issues diagnostics + as GCC9 does. For instance it used to display (there's a tab before the + opening brace): + + foo.y:3.37-38: error: $2 of ‘expr’ has no declared type + expr: expr '+' "number" { $$ = $1 + $2; } + ^~ + It now reports + + foo.y:3.37-38: error: $2 of ‘expr’ has no declared type + 3 | expr: expr '+' "number" { $$ = $1 + $2; } + | ^~ + + Other constructs now also have better locations, resulting in more precise + diagnostics. + +*** Fix-it hints for %empty + + Running Bison with -Wempty-rules and --update will remove incorrect %empty + annotations, and add the missing ones. + +*** Generated reports + + The format of the reports (parse.output) was improved for readability. + +*** Better support for --no-line. + + When --no-line is used, the generated files are now cleaner: no lines are + generated instead of empty lines. Together with using api.header.include, + that should help people saving the generated files into version control + systems get smaller diffs. + +** Documentation + + A new example in C shows an simple infix calculator with a hand-written + scanner (examples/c/calc). + + A new example in C shows a reentrant parser (capable of recursive calls) + built with Flex and Bison (examples/c/reccalc). + + There is a new section about the history of Yaccs and Bison. + +** Bug fixes + + A few obscure bugs were fixed, including the second oldest (known) bug in + Bison: it was there when Bison was entered in the RCS version control + system, in December 1987. See the NEWS of Bison 3.3 for the previous + oldest bug. + * Noteworthy changes in release 3.3.2 (2019-02-03) [stable] ** Bug fixes @@ -737,10 +1154,10 @@ GNU Bison NEWS bison used to report: - /tmp/foo.yy:2.10-11: error: %printer redeclaration for FOO + foo.yy:2.10-11: error: %printer redeclaration for FOO %printer {} "foo" ^^ - /tmp/foo.yy:3.10-11: previous declaration + foo.yy:3.10-11: previous declaration %printer {} FOO ^^ @@ -3441,7 +3858,7 @@ Output file does not redefine const for C++. ----- -Copyright (C) 1995-2015, 2018-2019 Free Software Foundation, Inc. +Copyright (C) 1995-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Parser Generator. @@ -3482,12 +3899,14 @@ along with this program. If not, see . LocalWords: redeclaration sval fcaret reentrant XSLT xsl Wmaybe yyvsp Tedi LocalWords: pragmas noreturn untyped Rozenman unexpanded Wojciech Polak LocalWords: Alexandre MERCHANTABILITY yytype emplace ptr automove lvalues - LocalWords: nonterminal yy args Pragma dereference yyformat rhs docdir + LocalWords: nonterminal yy args Pragma dereference yyformat rhs docdir bw LocalWords: Redeclarations rpcalc Autoconf YFLAGS Makefiles PROG DECL num LocalWords: Heimbigner AST src ast Makefile srcdir MinGW xxlex XXSTYPE LocalWords: XXLTYPE strictfp IDEs ffixit fdiagnostics parseable fixits LocalWords: Wdeprecated yytext Variadic variadic yyrhs yyphrs RCS README - LocalWords: noexcept constexpr ispell american deprecations + LocalWords: noexcept constexpr ispell american deprecations backend Teoh + LocalWords: YYPRINT Mangold Bonzini's Wdangling exVal baz checkable gcc + LocalWords: fsanitize Vogelsgesang lis redeclared stdint automata Local Variables: ispell-dictionary: "american" diff --git a/contrib/tools/bison/README b/contrib/tools/bison/README index 7fa1bfe949a6..f5748c3c2568 100644 --- a/contrib/tools/bison/README +++ b/contrib/tools/bison/README @@ -1,15 +1,67 @@ -This package contains the GNU Bison parser generator. +GNU Bison is a general-purpose parser generator that converts an annotated +context-free grammar into a deterministic LR or generalized LR (GLR) parser +employing LALR(1) parser tables. Bison can also generate IELR(1) or +canonical LR(1) parser tables. Once you are proficient with Bison, you can +use it to develop a wide range of language parsers, from those used in +simple desk calculators to complex programming languages. -* Installation -** Build +Bison is upward compatible with Yacc: all properly-written Yacc grammars +work with Bison with no change. Anyone familiar with Yacc should be able to +use Bison with little trouble. You need to be fluent in C, C++ or Java +programming in order to use Bison. + +Bison and the parsers it generates are portable, they do not require any +specific compilers. + +GNU Bison's home page is https://gnu.org/software/bison/. + +# Installation +## Build from git +Here are basic installation instructions for a repository checkout: + + $ git submodule update --init + $ ./bootstrap + +then proceed with the usual `configure && make` steps. + +The file README-hacking.md is about building, modifying and checking Bison. + +## Build from tarball See the file INSTALL for generic compilation and installation instructions. -Bison requires GNU m4 1.4.6 or later. See: +Bison requires GNU m4 1.4.6 or later. See +https://ftp.gnu.org/gnu/m4/m4-1.4.6.tar.gz. + +## Running a non installed bison +Once you ran `make`, you might want to toy with this fresh bison before +installing it. In that case, do not use `src/bison`: it would use the +*installed* files (skeletons, etc.), not the local ones. Use `tests/bison`. + +## Colored diagnostics +As an experimental feature, diagnostics are now colored, controlled by the +`--color` and `--style` options. + +To use them, install the libtextstyle library before configuring Bison. It +is available from https://alpha.gnu.org/gnu/gettext/, for instance +https://alpha.gnu.org/pub/gnu/gettext/libtextstyle-0.20.5.tar.gz. + +The option --color supports the following arguments: +- always, yes: Enable colors. +- never, no: Disable colors. +- auto, tty (default): Enable colors if the output device is a tty. - https://ftp.gnu.org/gnu/m4/m4-1.4.6.tar.gz +To customize the styles, create a CSS file, say `bison-bw.css`, similar to -** Relocatability -If you pass '--enable-relocatable' to 'configure', Bison is relocatable. + /* bison-bw.css */ + .warning { } + .error { font-weight: 800; text-decoration: underline; } + .note { } + +then invoke bison with `--style=bison-bw.css`, or set the `BISON_STYLE` +environment variable to `bison-bw.css`. + +## Relocatability +If you pass `--enable-relocatable` to `configure`, Bison is relocatable. A relocatable program can be moved or copied to a different location on the file system. It can also be used through mount points for network sharing. @@ -18,7 +70,7 @@ invoke them through the symlink. See "Enabling Relocatability" in the documentation. -** Internationalization +## Internationalization Bison supports two catalogs: one for Bison itself (i.e., for the maintainer-side parser generation), and one for the generated parsers (i.e., for the user-side parser execution). The requirements between both differ: @@ -28,49 +80,46 @@ generated parsers could have been localized. See http://lists.gnu.org/archive/html/bug-bison/2009-08/msg00006.html for more details. -* Questions +# Questions See the section FAQ in the documentation (doc/bison.info) for frequently asked questions. The documentation is also available in PDF and HTML, -provided you have a recent version of Texinfo installed: run "make pdf" or -"make html". +provided you have a recent version of Texinfo installed: run `make pdf` or +`make html`. If you have questions about using Bison and the documentation does not answer them, please send mail to . -* Bug reports +# Bug reports Please send bug reports to . Be sure to include the -version number from 'bison --version', and a complete, self-contained test +version number from `bison --version`, and a complete, self-contained test case in each bug report. -* Copyright statements +# Copyright statements For any copyright year range specified as YYYY-ZZZZ in this package, note that the range specifies every single year in that closed interval. ------ + diff --git a/contrib/tools/bison/README-alpha b/contrib/tools/bison/README-alpha index c4effc49328d..dbd0e88e2059 100644 --- a/contrib/tools/bison/README-alpha +++ b/contrib/tools/bison/README-alpha @@ -12,7 +12,7 @@ the problems you encounter. ----- -Copyright (C) 2002, 2004, 2009-2015, 2018-2019 Free Software Foundation, +Copyright (C) 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of GNU Bison. diff --git a/contrib/tools/bison/data/README b/contrib/tools/bison/data/README.md similarity index 98% rename from contrib/tools/bison/data/README rename to contrib/tools/bison/data/README.md index ed217365b475..c91fe1c54599 100644 --- a/contrib/tools/bison/data/README +++ b/contrib/tools/bison/data/README.md @@ -138,9 +138,10 @@ The macro `b4_symbol(NUM, FIELD)` gives access to the following FIELDS: - `printer`: string - `printer_file`: string - `printer_line`: integer +- `printer_loc`: location If the symbol has a printer, everything about it. -- `has_destructor`, `destructor`, `destructor_file`, `destructor_line` +- `has_destructor`, `destructor`, `destructor_file`, `destructor_line`, `destructor_loc` Likewise. ### `b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG])` @@ -173,7 +174,7 @@ fill-column: 76 ispell-dictionary: "american" End: -Copyright (C) 2002, 2008-2015, 2018-2019 Free Software Foundation, Inc. +Copyright (C) 2002, 2008-2015, 2018-2020 Free Software Foundation, Inc. This file is part of GNU Bison. diff --git a/contrib/tools/bison/data/skeletons/bison.m4 b/contrib/tools/bison/data/skeletons/bison.m4 index e3591875c0f6..8e01bd6a6d7a 100644 --- a/contrib/tools/bison/data/skeletons/bison.m4 +++ b/contrib/tools/bison/data/skeletons/bison.m4 @@ -2,7 +2,7 @@ # Language-independent M4 Macros for Bison. -# Copyright (C) 2002, 2004-2015, 2018-2019 Free Software Foundation, +# Copyright (C) 2002, 2004-2015, 2018-2020 Free Software Foundation, # Inc. # This program is free software: you can redistribute it and/or modify @@ -192,7 +192,7 @@ m4_define([b4_error], # @warn(1@) # @warn(1@,2@) m4_define([b4_warn], -[b4_error([[warn]], [], [], $@)]) +[b4_warn_at([], [], $@)]) # b4_warn_at(START, END, FORMAT, [ARG1], [ARG2], ...) # --------------------------------------------------- @@ -210,7 +210,7 @@ m4_define([b4_warn_at], # # See b4_warn example. m4_define([b4_complain], -[b4_error([[complain]], [], [], $@)]) +[b4_complain_at([], [], $@)]) # b4_complain_at(START, END, FORMAT, [ARG1], [ARG2], ...) # ------------------------------------------------------- @@ -226,8 +226,7 @@ m4_define([b4_complain_at], # # See b4_warn example. m4_define([b4_fatal], -[b4_error([[fatal]], [], [], $@)dnl -m4_exit(1)]) +[b4_fatal_at([], [], $@)]) # b4_fatal_at(START, END, FORMAT, [ARG1], [ARG2], ...) # ---------------------------------------------------- @@ -438,13 +437,6 @@ m4_define([b4_symbol_tag_comment], ]) -# b4_symbol_action_location(SYMBOL-NUM, KIND) -# ------------------------------------------- -# Report the location of the KIND action as FILE:LINE. -m4_define([b4_symbol_action_location], -[b4_symbol([$1], [$2_file]):b4_syncline([b4_symbol([$1], [$2_line])])]) - - # b4_symbol_action(SYMBOL-NUM, KIND) # ---------------------------------- # Run the action KIND (destructor or printer) for SYMBOL-NUM. @@ -455,9 +447,9 @@ m4_define([b4_symbol_action], [], [(*yylocationp)])dnl _b4_symbol_case([$1])[]dnl -b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])]) - b4_symbol([$1], [$2]) -b4_syncline([@oline@], [@ofile@]) +b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl +b4_symbol([$1], [$2]) +b4_syncline([@oline@], [@ofile@])dnl break; b4_dollar_popdef[]dnl @@ -540,9 +532,9 @@ m4_define([b4_any_token_visible_if], # ---------------------------- m4_define([b4_token_format], [b4_token_visible_if([$2], -[m4_quote(m4_format([$1], - [b4_symbol([$2], [id])], - [b4_symbol([$2], [user_number])]))])]) +[m4_format([[$1]], + m4_quote(b4_symbol([$2], [id])), + m4_quote(b4_symbol([$2], b4_api_token_raw_if([[number]], [[user_number]]))))])]) ## ------- ## @@ -586,12 +578,15 @@ m4_define([b4_basename], [m4_bpatsubst([$1], [^.*/\([^/]+\)/*$], [\1])]) -# b4_syncline(LINE, FILE) -# ----------------------- +# b4_syncline(LINE, FILE)dnl +# -------------------------- +# Should always be following by a dnl. +# +# Emit "#line LINE FILE /* __LINE__ __FILE__ */". m4_define([b4_syncline], [b4_flag_if([synclines], -[b4_sync_start([$1], [$2]) b4_sync_end([__line__], - [b4_basename(m4_quote(__file__))])[]dnl +[b4_sync_start([$1], [$2])[]dnl +b4_sync_end([__line__], [b4_basename(m4_quote(__file__))]) ])]) # b4_sync_start(LINE, FILE) @@ -603,7 +598,17 @@ m4_define([b4_sync_start], [b4_comment([$2:$1])]) # ----------------------- # Syncline for the current place, which ends. Typically a comment # left for the reader. -m4_define([b4_sync_end], [b4_comment([$2:$1])]) +m4_define([b4_sync_end], [ b4_comment([$2:$1])] +) +# This generates dependencies on the Bison skeletons hence lots of +# useless 'git diff'. This location is useless for the regular +# user (who does not care about the skeletons) and is actually not +# useful for Bison developpers too (I, Akim, never used this to locate +# the code in skeletons that generated output). So disable it +# completely. If someone thinks this was actually useful, a %define +# variable should be provided to control the level of verbosity of +# '#line', in replacement of --no-lines. +m4_define([b4_sync_end]) # b4_user_code(USER-CODE) @@ -753,8 +758,10 @@ m4_define([b4_percent_define_get_kind], [m4_indir([b4_percent_define_kind(]$1[)])], [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])]) -# b4_percent_define_get_syncline(VARIABLE) -# ---------------------------------------- +# b4_percent_define_get_syncline(VARIABLE)dnl +# ------------------------------------------- +# Should always be following by a dnl. +# # Mimic muscle_percent_define_get_syncline in ../src/muscle-tab.h exactly. # That is, if the %define variable VARIABLE is undefined, complain fatally # since that's a Bison or skeleton error. Otherwise, return its definition @@ -968,10 +975,9 @@ m4_define([b4_percent_code_get], [m4_pushdef([b4_macro_name], [[b4_percent_code(]$1[)]])dnl m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])dnl m4_ifdef(b4_macro_name, -[b4_comment([m4_if([$#], [0], [[Unqualified %code]], - [["%code ]$1["]])[ blocks.]]) -b4_user_code([m4_indir(b4_macro_name)]) -])dnl +[b4_comment(m4_if([$#], [0], [[[Unqualified %code blocks.]]], + [[["%code ]$1[" blocks.]]])) +b4_user_code([m4_indir(b4_macro_name)])])dnl m4_popdef([b4_macro_name])]) # b4_percent_code_ifdef(QUALIFIER, IF-TRUE, [IF-FALSE]) @@ -995,6 +1001,7 @@ m4_define([b4_percent_code_ifdef], # b4_parse_trace_if([IF-DEBUG-TRACES-ARE-ENABLED], [IF-NOT]) # b4_token_ctor_if([IF-YYLEX-RETURNS-A-TOKEN], [IF-NOT]) # ---------------------------------------------------------- +b4_percent_define_if_define([api.token.raw]) b4_percent_define_if_define([token_ctor], [api.token.constructor]) b4_percent_define_if_define([locations]) # Whether locations are tracked. b4_percent_define_if_define([parse.assert]) @@ -1071,10 +1078,10 @@ m4_define_default([b4_location_initial_line], [1]) ## Sanity checks. ## ## --------------- ## -# api.location.prefix={...} (Java and C++). +# api.location.type={...} (C, C++ and Java). b4_percent_define_check_kind([api.location.type], [code], [deprecated]) -# api.position.prefix={...} (Java). +# api.position.type={...} (Java). b4_percent_define_check_kind([api.position.type], [code], [deprecated]) # api.prefix >< %name-prefix. diff --git a/contrib/tools/bison/data/skeletons/c++-skel.m4 b/contrib/tools/bison/data/skeletons/c++-skel.m4 index 1c3721cdbbb9..6d3becf5e6e7 100644 --- a/contrib/tools/bison/data/skeletons/c++-skel.m4 +++ b/contrib/tools/bison/data/skeletons/c++-skel.m4 @@ -2,7 +2,7 @@ # C++ skeleton dispatching for Bison. -# Copyright (C) 2006-2007, 2009-2015, 2018-2019 Free Software +# Copyright (C) 2006-2007, 2009-2015, 2018-2020 Free Software # Foundation, Inc. # This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/data/skeletons/c++.m4 b/contrib/tools/bison/data/skeletons/c++.m4 index 35008f374515..c52f034c5682 100644 --- a/contrib/tools/bison/data/skeletons/c++.m4 +++ b/contrib/tools/bison/data/skeletons/c++.m4 @@ -2,7 +2,7 @@ # C++ skeleton for Bison -# Copyright (C) 2002-2019 Free Software Foundation, Inc. +# Copyright (C) 2002-2020 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -147,13 +147,13 @@ m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*$]), [-1], [], [[namespace reference has a trailing "::"]])]) m4_define([b4_namespace_open], -[b4_user_code([b4_percent_define_get_syncline([[api.namespace]]) +[b4_user_code([b4_percent_define_get_syncline([[api.namespace]])dnl [namespace ]m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref), [^\(.\)[ ]*::], [\1])), [::], [ { namespace ])[ {]])]) m4_define([b4_namespace_close], -[b4_user_code([b4_percent_define_get_syncline([[api.namespace]]) +[b4_user_code([b4_percent_define_get_syncline([[api.namespace]])dnl m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref[ ]), [^\(.\)[ ]*\(::\)?\([^][:]\|:[^:]\)*], [\1])), @@ -194,7 +194,7 @@ m4_define([b4_value_type_declare], [union\|union-directive], [[ union semantic_type { - ]b4_user_union_members[ +]b4_user_union_members[ };]])])dnl ]) @@ -367,9 +367,6 @@ m4_define([b4_symbol_type_define], /// \a empty when empty. symbol_number_type type_get () const YY_NOEXCEPT; - /// The token. - token_type token () const YY_NOEXCEPT; - /// The symbol type. /// \a empty_symbol when empty. /// An int, not token_number_type, to be able to store empty_symbol. @@ -498,22 +495,7 @@ m4_define([b4_public_types_define], { return type; } -]b4_token_ctor_if([[ - ]b4_inline([$1])b4_parser_class[::token_type - ]b4_parser_class[::by_type::token () const YY_NOEXCEPT - { - // YYTOKNUM[NUM] -- (External) token number corresponding to the - // (internal) symbol number NUM (which must be that of a token). */ - static - const ]b4_int_type_for([b4_toknum])[ - yytoken_number_[] = - { - ]b4_toknum[ - }; - return token_type (yytoken_number_[type]); - } -]])[]dnl -]) +]]) # b4_token_constructor_define @@ -529,10 +511,11 @@ m4_define([b4_token_constructor_define], []) # sometimes in the cc file. m4_define([b4_yytranslate_define], [ b4_inline([$1])b4_parser_class[::token_number_type - ]b4_parser_class[::yytranslate_ (]b4_token_ctor_if([token_type], - [int])[ t) + ]b4_parser_class[::yytranslate_ (int t) { - // YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to +]b4_api_token_raw_if( +[[ return static_cast (t);]], +[[ // YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to // TOKEN-NUM as returned by yylex. static const token_number_type @@ -540,15 +523,14 @@ m4_define([b4_yytranslate_define], { ]b4_translate[ }; - const unsigned user_token_number_max_ = ]b4_user_token_number_max[; - const token_number_type undef_token_ = ]b4_undef_token_number[; + const int user_token_number_max_ = ]b4_user_token_number_max[; - if (static_cast (t) <= yyeof_) + if (t <= 0) return yyeof_; - else if (static_cast (t) <= user_token_number_max_) + else if (t <= user_token_number_max_) return translate_table[t]; else - return undef_token_; + return yy_undef_token_;]])[ } ]]) diff --git a/contrib/tools/bison/data/skeletons/c-like.m4 b/contrib/tools/bison/data/skeletons/c-like.m4 index 8d891b67ef97..e0460d4834a9 100644 --- a/contrib/tools/bison/data/skeletons/c-like.m4 +++ b/contrib/tools/bison/data/skeletons/c-like.m4 @@ -2,7 +2,7 @@ # Common code for C-like languages (C, C++, Java, etc.) -# Copyright (C) 2012-2015, 2018-2019 Free Software Foundation, Inc. +# Copyright (C) 2012-2015, 2018-2020 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/data/skeletons/c-skel.m4 b/contrib/tools/bison/data/skeletons/c-skel.m4 index 2a21cfc7d0d5..68d057cb7422 100644 --- a/contrib/tools/bison/data/skeletons/c-skel.m4 +++ b/contrib/tools/bison/data/skeletons/c-skel.m4 @@ -2,7 +2,7 @@ # C skeleton dispatching for Bison. -# Copyright (C) 2006-2007, 2009-2015, 2018-2019 Free Software +# Copyright (C) 2006-2007, 2009-2015, 2018-2020 Free Software # Foundation, Inc. # This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/data/skeletons/c.m4 b/contrib/tools/bison/data/skeletons/c.m4 index 3cde04a9571b..0987ef777a66 100644 --- a/contrib/tools/bison/data/skeletons/c.m4 +++ b/contrib/tools/bison/data/skeletons/c.m4 @@ -2,7 +2,7 @@ # C M4 Macros for Bison. -# Copyright (C) 2002, 2004-2015, 2018-2019 Free Software Foundation, +# Copyright (C) 2002, 2004-2015, 2018-2020 Free Software Foundation, # Inc. # This program is free software: you can redistribute it and/or modify @@ -167,38 +167,110 @@ b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal); # b4_int_type(MIN, MAX) # --------------------- -# Return the smallest int type able to handle numbers ranging from -# MIN to MAX (included). +# Return a narrow int type able to handle integers ranging from MIN +# to MAX (included) in portable C code. Assume MIN and MAX fall in +# 'int' range. m4_define([b4_int_type], -[m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char], - b4_ints_in($@, [-128], [127]), [1], [signed char], +[m4_if(b4_ints_in($@, [-127], [127]), [1], [signed char], + b4_ints_in($@, [0], [255]), [1], [unsigned char], + b4_ints_in($@, [-32767], [32767]), [1], [short], b4_ints_in($@, [0], [65535]), [1], [unsigned short], - b4_ints_in($@, [-32768], [32767]), [1], [short], - m4_eval([0 <= $1]), [1], [unsigned], + [int])]) + +# b4_c99_int_type(MIN, MAX) +# ------------------------- +# Like b4_int_type, but for C99. +# b4_c99_int_type_define replaces b4_int_type with this. +m4_define([b4_c99_int_type], +[m4_if(b4_ints_in($@, [-127], [127]), [1], [yytype_int8], + b4_ints_in($@, [0], [255]), [1], [yytype_uint8], + + b4_ints_in($@, [-32767], [32767]), [1], [yytype_int16], + b4_ints_in($@, [0], [65535]), [1], [yytype_uint16], [int])]) +# b4_c99_int_type_define +# ---------------------- +# Define private types suitable for holding small integers in C99 or later. +m4_define([b4_c99_int_type_define], +[m4_copy_force([b4_c99_int_type], [b4_int_type])dnl +[/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure + and (if available) are included + so that the code can choose integer types of a good width. */ + +#ifndef __PTRDIFF_MAX__ +# include /* INFRINGES ON USER NAME SPACE */ +# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_STDINT_H +# endif +#endif + +/* Narrow types that promote to a signed type and that can represent a + signed or unsigned integer of at least N bits. In tables they can + save space and decrease cache pressure. Promoting to a signed type + helps avoid bugs in integer arithmetic. */ + +#ifdef __INT_LEAST8_MAX__ +typedef __INT_LEAST8_TYPE__ yytype_int8; +#elif defined YY_STDINT_H +typedef int_least8_t yytype_int8; +#else +typedef signed char yytype_int8; +#endif + +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; +#else +typedef short yytype_int16; +#endif + +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; +#else +typedef short yytype_uint8; +#endif + +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; +#else +typedef int yytype_uint16; +#endif]]) + # b4_int_type_for(NAME) # --------------------- -# Return the smallest int type able to handle numbers ranging from +# Return a narrow int type able to handle numbers ranging from # 'NAME_min' to 'NAME_max' (included). m4_define([b4_int_type_for], [b4_int_type($1_min, $1_max)]) -# b4_table_value_equals(TABLE, VALUE, LITERAL) -# -------------------------------------------- +# b4_table_value_equals(TABLE, VALUE, LITERAL, SYMBOL) +# ---------------------------------------------------- # Without inducing a comparison warning from the compiler, check if the # literal value LITERAL equals VALUE from table TABLE, which must have -# TABLE_min and TABLE_max defined. +# TABLE_min and TABLE_max defined. SYMBOL denotes m4_define([b4_table_value_equals], [m4_if(m4_eval($3 < m4_indir([b4_]$1[_min]) || m4_indir([b4_]$1[_max]) < $3), [1], [[0]], - [(!!(($2) == ($3)))])]) + [(($2) == $4)])]) ## ----------------- ## @@ -210,37 +282,39 @@ m4_define([b4_table_value_equals], # Provide portable compiler "attributes". If "noreturn" is passed, define # _Noreturn. m4_define([b4_attribute_define], -[[#ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) +[[#ifndef YY_ATTRIBUTE_PURE +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) # else -# define YY_ATTRIBUTE(Spec) /* empty */ +# define YY_ATTRIBUTE_PURE # endif #endif -#ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) -#endif - #ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +# else +# define YY_ATTRIBUTE_UNUSED +# endif #endif ]m4_bmatch([$1], [\bnoreturn\b], [[/* The _Noreturn keyword of C11. */ -#if ! defined _Noreturn -# if defined __cplusplus && 201103L <= __cplusplus +]dnl This is an exact copy of lib/_Noreturn.h. +[#ifndef _Noreturn +# if (defined __cplusplus \ + && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \ + || (defined _MSC_VER && 1900 <= _MSC_VER))) # define _Noreturn [[noreturn]] -# elif !(defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__) -# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \ - || 0x5110 <= __SUNPRO_C) -# define _Noreturn __attribute__ ((__noreturn__)) -# elif defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) -# else -# define _Noreturn -# endif +# elif ((!defined __cplusplus || defined __clang__) \ + && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \ + || 4 < __GNUC__ + (7 <= __GNUC_MINOR__))) + /* _Noreturn works as-is. */ +# elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C +# define _Noreturn __attribute__ ((__noreturn__)) +# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0) +# define _Noreturn __declspec (noreturn) +# else +# define _Noreturn # endif #endif @@ -253,11 +327,11 @@ m4_define([b4_attribute_define], #if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ _Pragma ("GCC diagnostic pop") #else # define YY_INITIAL_VALUE(Value) Value @@ -269,9 +343,36 @@ m4_define([b4_attribute_define], #ifndef YY_INITIAL_VALUE # define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif + +#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END \ + _Pragma ("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END +#endif ]]) +# b4_cast_define +# -------------- +m4_define([b4_cast_define], +[# ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast (Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) +# else +# define YY_CAST(Type, Val) ((Type) (Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) +# endif +# endif[]dnl +]) + + # b4_null_define # -------------- # Portability issues: define a YY_NULLPTR appropriate for the current @@ -470,7 +571,7 @@ m4_define([b4_sync_start], [[#]line $1 $2]) m4_define([b4_case], [ case $1: $2 -b4_syncline([@oline@], [@ofile@]) +b4_syncline([@oline@], [@ofile@])dnl break;]) @@ -480,7 +581,7 @@ m4_define([b4_predicate_case], [ case $1: if (! ( $2)) YYERROR; -b4_syncline([@oline@], [@ofile@]) +b4_syncline([@oline@], [@ofile@])dnl break;]) @@ -540,8 +641,12 @@ m4_if(b4_skeleton, ["yacc.c"], YYPRINT (yyo, yytoknum[yytype], *yyvaluep); # endif ]])dnl - b4_symbol_actions([printer])[ -} +b4_percent_code_get([[pre-printer]])dnl + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + b4_symbol_actions([printer]) + YY_IGNORE_MAYBE_UNINITIALIZED_END +b4_percent_code_get([[post-printer]])dnl +[} /*---------------------------. @@ -709,13 +814,13 @@ typedef ]b4_percent_define_get([[api.value.type]])[ ]b4_api_PREFIX[STYPE; [m4_bmatch(b4_percent_define_get([[api.value.type]]), [union\|union-directive], [[#if ! defined ]b4_api_PREFIX[STYPE && ! defined ]b4_api_PREFIX[STYPE_IS_DECLARED -]b4_percent_define_get_syncline([[api.value.union.name]])[ -union ]b4_percent_define_get([[api.value.union.name]])[ +]b4_percent_define_get_syncline([[api.value.union.name]])dnl +[union ]b4_percent_define_get([[api.value.union.name]])[ { ]b4_user_union_members[ }; -]b4_percent_define_get_syncline([[api.value.union.name]])[ -typedef union ]b4_percent_define_get([[api.value.union.name]])[ ]b4_api_PREFIX[STYPE; +]b4_percent_define_get_syncline([[api.value.union.name]])dnl +[typedef union ]b4_percent_define_get([[api.value.union.name]])[ ]b4_api_PREFIX[STYPE; # define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1 # define ]b4_api_PREFIX[STYPE_IS_DECLARED 1 #endif @@ -726,7 +831,10 @@ typedef union ]b4_percent_define_get([[api.value.union.name]])[ ]b4_api_PREFIX[S # ----------------------- m4_define([b4_location_type_define], [[/* Location type. */ -#if ! defined ]b4_api_PREFIX[LTYPE && ! defined ]b4_api_PREFIX[LTYPE_IS_DECLARED +]b4_percent_define_ifdef([[api.location.type]], +[[typedef ]b4_percent_define_get([[api.location.type]])[ ]b4_api_PREFIX[LTYPE; +]], +[[#if ! defined ]b4_api_PREFIX[LTYPE && ! defined ]b4_api_PREFIX[LTYPE_IS_DECLARED typedef struct ]b4_api_PREFIX[LTYPE ]b4_api_PREFIX[LTYPE; struct ]b4_api_PREFIX[LTYPE { @@ -738,7 +846,7 @@ struct ]b4_api_PREFIX[LTYPE # define ]b4_api_PREFIX[LTYPE_IS_DECLARED 1 # define ]b4_api_PREFIX[LTYPE_IS_TRIVIAL 1 #endif -]]) +]])]) # b4_declare_yylstype diff --git a/contrib/tools/bison/data/skeletons/glr.cc b/contrib/tools/bison/data/skeletons/glr.cc index 562173416307..887b6146b4cf 100644 --- a/contrib/tools/bison/data/skeletons/glr.cc +++ b/contrib/tools/bison/data/skeletons/glr.cc @@ -1,6 +1,6 @@ # C++ GLR skeleton for Bison -# Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc. +# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -100,8 +100,8 @@ m4_defn([b4_initial_action])]))])[ # Hijack the post prologue to declare yyerror. ]m4_append([b4_post_prologue], -[b4_syncline([@oline@], [@ofile@])[ -]b4_function_declare([yyerror], +[b4_syncline([@oline@], [@ofile@])dnl +b4_function_declare([yyerror], [static void],b4_locations_if([ [[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp], [yylocationp]],]) @@ -128,8 +128,8 @@ m4_if(b4_prefix, [yy], [], # Hijack the epilogue to define implementations (yyerror, parser member # functions etc.). m4_append([b4_epilogue], -[b4_syncline([@oline@], [@ofile@])[ - +[b4_syncline([@oline@], [@ofile@])dnl +[ /*------------------. | Report an error. | `------------------*/ @@ -234,7 +234,7 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl #endif ]m4_popdef([b4_parse_param])dnl -b4_namespace_close +b4_namespace_close[]dnl ]) @@ -257,6 +257,21 @@ b4_percent_code_get([[requires]])[ ]b4_attribute_define[ ]b4_null_define[ +// This skeleton is based on C, yet compiles it as C++. +// So expect warnings about C style casts. +#if defined __clang__ && 306 <= __clang_major__ * 100 + __clang_minor__ +# pragma clang diagnostic ignored "-Wold-style-cast" +#elif defined __GNUC__ && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ +# pragma GCC diagnostic ignored "-Wold-style-cast" +#endif + +// On MacOS, PTRDIFF_MAX is defined as long long, which Clang's +// -pedantic reports as being a C++11 extension. +#if defined __APPLE__ && YY_CPLUSPLUS < 201103L \ + && defined __clang__ && 4 <= __clang_major__ +# pragma clang diagnostic ignored "-Wc++11-long-long" +#endif + // Whether we are compiled with exception support. #ifndef YY_EXCEPTIONS # if defined __GNUC__ && !defined __EXCEPTIONS @@ -351,15 +366,15 @@ b4_percent_define_flag_if([[global_tokens_and_yystype]], ]) b4_defines_if( -[b4_output_begin([b4_spec_defines_file]) +[b4_output_begin([b4_spec_header_file]) b4_copyright([Skeleton interface for Bison GLR parsers in C++], - [2002-2015, 2018-2019])[ + [2002-2015, 2018-2020])[ // C++ GLR parser skeleton written by Akim Demaille. ]b4_disclaimer[ -]b4_cpp_guard_open([b4_spec_defines_file])[ +]b4_cpp_guard_open([b4_spec_header_file])[ ]b4_shared_declarations[ -]b4_cpp_guard_close([b4_spec_defines_file])[ +]b4_cpp_guard_close([b4_spec_header_file])[ ]b4_output_end]) # Let glr.c (and b4_shared_declarations) believe that the user diff --git a/contrib/tools/bison/data/skeletons/lalr1.cc b/contrib/tools/bison/data/skeletons/lalr1.cc index 09f4259f2868..dc674a2d60eb 100644 --- a/contrib/tools/bison/data/skeletons/lalr1.cc +++ b/contrib/tools/bison/data/skeletons/lalr1.cc @@ -1,6 +1,6 @@ # C++ skeleton for Bison -# Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc. +# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,14 +20,23 @@ m4_include(b4_skeletonsdir/[c++.m4]) # api.value.type=variant is valid. m4_define([b4_value_type_setup_variant]) +# Check the value of %define parse.lac, where LAC stands for lookahead +# correction. +b4_percent_define_default([[parse.lac]], [[none]]) +b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]]) +b4_define_flag_if([lac]) +m4_define([b4_lac_flag], + [m4_if(b4_percent_define_get([[parse.lac]]), + [none], [[0]], [[1]])]) + # b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT) # -------------------------------------------------------------- # Declare "parser::yy_" whose contents is CONTENT. m4_define([b4_integral_parser_table_declare], -[m4_ifval([$3], [b4_comment([$3], [ ]) +[m4_ifval([$3], [b4_comment([$3], [ ]) ])dnl - static const b4_int_type_for([$2]) yy$1_[[]];dnl + static const b4_int_type_for([$2]) yy$1_[[]];dnl ]) # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT) @@ -111,9 +120,9 @@ b4_dollar_pushdef([yysym.value], [], [yysym.location])dnl _b4_symbol_case([$1])[]dnl -b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])]) +b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl b4_symbol([$1], [$2]) -b4_syncline([@oline@], [@ofile@]) +b4_syncline([@oline@], [@ofile@])dnl break; m4_popdef([b4_symbol_value])[]dnl @@ -135,7 +144,7 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))])]) m4_pushdef([b4_copyright_years], - [2002-2015, 2018-2019]) + [2002-2015, 2018-2020]) m4_define([b4_parser_class], [b4_percent_define_get([[api.parser.class]])]) @@ -166,6 +175,7 @@ m4_define([b4_shared_declarations], ]b4_variant_if([b4_variant_includes])[ ]b4_attribute_define[ +]b4_cast_define[ ]b4_null_define[ ]b4_YYDEBUG_define[ @@ -220,10 +230,21 @@ m4_define([b4_shared_declarations], private: /// This class is not copyable. ]b4_parser_class[ (const ]b4_parser_class[&); - ]b4_parser_class[& operator= (const ]b4_parser_class[&); - - /// State numbers. - typedef int state_type; + ]b4_parser_class[& operator= (const ]b4_parser_class[&);]b4_lac_if([[ + + /// Check the lookahead yytoken. + /// \returns true iff the token will be eventually shifted. + bool yy_lac_check_ (int yytoken) const; + /// Establish the initial context if no initial context currently exists. + /// \returns true iff the token will be eventually shifted. + bool yy_lac_establish_ (int yytoken); + /// Discard any previous initial lookahead context because of event. + /// \param event the event which caused the lookahead to be discarded. + /// Only used for debbuging output. + void yy_lac_discard_ (const char* event);]])[ + + /// Stored state numbers (used for stacks). + typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ state_type; /// Generate an error message. /// \param yystate the state where the error occurred. @@ -234,7 +255,7 @@ m4_define([b4_shared_declarations], /// Compute post-reduction state. /// \param yystate the current state /// \param yysym the nonterminal to push on the stack - state_type yy_lr_goto_state_ (state_type yystate, int yysym); + static state_type yy_lr_goto_state_ (state_type yystate, int yysym); /// Whether the given \c yypact_ value indicates a defaulted state. /// \param yyvalue the value to check @@ -248,7 +269,9 @@ m4_define([b4_shared_declarations], static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_; /// Convert a scanner token number \a t to a symbol number. - static token_number_type yytranslate_ (]b4_token_ctor_if([token_type], [int])[ t); + /// In theory \a t should be a token_type, but character literals + /// are valid, yet not members of the token_type enum. + static token_number_type yytranslate_ (int t); // Tables. ]b4_parser_tables_declare[]b4_error_verbose_if([ @@ -313,7 +336,8 @@ m4_define([b4_shared_declarations], symbol_number_type type_get () const YY_NOEXCEPT; /// The state number used to denote an empty symbol. - enum { empty_state = -1 }; + /// We use the initial state, as it does not have a value. + enum { empty_state = 0 }; /// The state. /// \a empty when empty. @@ -335,6 +359,10 @@ m4_define([b4_shared_declarations], /// Assignment, needed by push_back by some old implementations. /// Moves the contents of that. stack_symbol_type& operator= (stack_symbol_type& that); + + /// Assignment, needed by push_back by other implementations. + /// Needed by some other old implementations. + stack_symbol_type& operator= (const stack_symbol_type& that); #endif }; @@ -344,7 +372,16 @@ m4_define([b4_shared_declarations], typedef stack stack_type; /// The stack. - stack_type yystack_; + stack_type yystack_;]b4_lac_if([[ + /// The stack for LAC. + /// Logically, the yy_lac_stack's lifetime is confined to the function + /// yy_lac_check_. We just store it as a member of this class to hold + /// on to the memory and to avoid frequent reallocations. + /// Since yy_lac_check_ is const, this member must be mutable. + mutable std::vector yylac_stack_; + /// Whether an initial LAC context was established. + bool yy_lac_established_; +]])[ /// Push a new state on the stack. /// \param m a debug message to display @@ -364,6 +401,10 @@ m4_define([b4_shared_declarations], /// Pop \a n symbols from the stack. void yypop_ (int n = 1); + /// Some specific tokens. + static const token_number_type yy_error_token_ = 1; + static const token_number_type yy_undef_token_ = ]b4_undef_token_number[; + /// Constants. enum { @@ -371,8 +412,6 @@ m4_define([b4_shared_declarations], yylast_ = ]b4_last[, ///< Last index in yytable_. yynnts_ = ]b4_nterms_number[, ///< Number of nonterminal symbols. yyfinal_ = ]b4_final_state_number[, ///< Termination state number. - yyterror_ = 1, - yyerrcode_ = 256, yyntokens_ = ]b4_tokens_number[ ///< Number of tokens. }; @@ -399,22 +438,22 @@ m4_define([b4_shared_declarations], ## -------------- ## b4_defines_if( -[b4_output_begin([b4_spec_defines_file]) +[b4_output_begin([b4_spec_header_file]) b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++]) [ /** - ** \file ]b4_spec_defines_file[ + ** \file ]b4_spec_header_file[ ** Define the ]b4_namespace_ref[::parser class. */ // C++ LALR(1) parser skeleton written by Akim Demaille. ]b4_disclaimer[ -]b4_cpp_guard_open([b4_spec_defines_file])[ +]b4_cpp_guard_open([b4_spec_header_file])[ ]b4_shared_declarations(hh)[ -]b4_cpp_guard_close([b4_spec_defines_file]) -b4_output_end -]) +]b4_cpp_guard_close([b4_spec_header_file])[ +]b4_output_end[ +]]) b4_output_begin([b4_parser_file_name])[ @@ -428,7 +467,7 @@ m4_if(b4_prefix, [yy], [], ]b4_user_pre_prologue[ -]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]], +]b4_defines_if([[#include "@basename(]b4_spec_header_file[@)"]], [b4_shared_declarations([cc])])[ ]b4_user_post_prologue[ @@ -459,9 +498,6 @@ m4_if(b4_prefix, [yy], [], [#define YYRHSLOC(Rhs, K) ((Rhs)[K].location) ]b4_yylloc_default_define])[ -// Suppress unused-variable warnings by "using" E. -#define YYUSE(E) ((void) (E)) - // Enable debugging if requested. #if ]b4_api_PREFIX[DEBUG @@ -551,12 +587,14 @@ m4_if(b4_prefix, [yy], [], ]])[ /// Build a parser object. - ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [ - :])[ + ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[) #if ]b4_api_PREFIX[DEBUG - ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false), - yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[ -#endif]b4_parse_param_cons[ + : yydebug_ (false), + yycdebug_ (&std::cerr)]b4_lac_if([,], [m4_ifset([b4_parse_param], [,])])[ +#else +]b4_lac_if([ :], [m4_ifset([b4_parse_param], [ :])])[ +#endif]b4_lac_if([[ + yy_lac_established_ (false)]m4_ifset([b4_parse_param], [,])])[]b4_parse_param_cons[ {} ]b4_parser_class::~b4_parser_class[ () @@ -603,7 +641,7 @@ m4_if(b4_prefix, [yy], [], if (state == empty_state) return empty_symbol; else - return yystos_[state]; + return yystos_[+state]; } ]b4_parser_class[::stack_symbol_type::stack_symbol_type () @@ -630,6 +668,17 @@ m4_if(b4_prefix, [yy], [], } #if YY_CPLUSPLUS < 201103L + ]b4_parser_class[::stack_symbol_type& + ]b4_parser_class[::stack_symbol_type::operator= (const stack_symbol_type& that) + { + state = that.state; + ]b4_variant_if([b4_symbol_variant([that.type_get ()], + [value], [copy], [that.value])], + [[value = that.value;]])[]b4_locations_if([ + location = that.location;])[ + return *this; + } + ]b4_parser_class[::stack_symbol_type& ]b4_parser_class[::stack_symbol_type::operator= (stack_symbol_type& that) { @@ -761,7 +810,6 @@ m4_if(b4_prefix, [yy], [], int ]b4_parser_class[::parse () { - // State. int yyn; /// Length of the RHS of the rule being reduced. int yylen = 0; @@ -777,7 +825,11 @@ m4_if(b4_prefix, [yy], [], stack_symbol_type yyerror_range[3];]])[ /// The return value of parse (). - int yyresult; + int yyresult;]b4_lac_if([[ + + /// Discard the LAC context in case there still is one left from a + /// previous invocation. + yy_lac_discard_ ("init");]])[ #if YY_EXCEPTIONS try @@ -801,7 +853,7 @@ b4_dollar_popdef])[]dnl | yynewstate -- push a new symbol on the stack. | `-----------------------------------------------*/ yynewstate: - YYCDEBUG << "Entering state " << yystack_[0].state << '\n'; + YYCDEBUG << "Entering state " << int (yystack_[0].state) << '\n'; // Accept? if (yystack_[0].state == yyfinal_) @@ -815,7 +867,7 @@ b4_dollar_popdef])[]dnl `-----------*/ yybackup: // Try to take a decision without lookahead. - yyn = yypact_[yystack_[0].state]; + yyn = yypact_[+yystack_[0].state]; if (yy_pact_value_is_default_ (yyn)) goto yydefault; @@ -846,14 +898,21 @@ b4_dollar_popdef])[]dnl to detect an error, take that action. */ yyn += yyla.type_get (); if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type_get ()) - goto yydefault; + {]b4_lac_if([[ + if (!yy_lac_establish_ (yyla.type_get ())) + goto yyerrlab;]])[ + goto yydefault; + } // Reduce or error. yyn = yytable_[yyn]; if (yyn <= 0) { if (yy_table_value_is_error_ (yyn)) - goto yyerrlab; + goto yyerrlab;]b4_lac_if([[ + if (!yy_lac_establish_ (yyla.type_get ())) + goto yyerrlab; +]])[ yyn = -yyn; goto yyreduce; } @@ -863,7 +922,8 @@ b4_dollar_popdef])[]dnl --yyerrstatus_; // Shift the lookahead token. - yypush_ ("Shifting", yyn, YY_MOVE (yyla)); + yypush_ ("Shifting", state_type (yyn), YY_MOVE (yyla));]b4_lac_if([[ + yy_lac_discard_ ("shift");]])[ goto yynewstate; @@ -871,7 +931,7 @@ b4_dollar_popdef])[]dnl | yydefault -- do the default action for the current state. | `-----------------------------------------------------------*/ yydefault: - yyn = yydefact_[yystack_[0].state]; + yyn = yydefact_[+yystack_[0].state]; if (yyn == 0) goto yyerrlab; goto yyreduce; @@ -998,11 +1058,11 @@ b4_dollar_popdef])[]dnl stack_symbol_type error_token; for (;;) { - yyn = yypact_[yystack_[0].state]; + yyn = yypact_[+yystack_[0].state]; if (!yy_pact_value_is_default_ (yyn)) { - yyn += yyterror_; - if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_) + yyn += yy_error_token_; + if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yy_error_token_) { yyn = yytable_[yyn]; if (0 < yyn) @@ -1023,8 +1083,9 @@ b4_dollar_popdef])[]dnl yyerror_range[2].location = yyla.location; YYLLOC_DEFAULT (error_token.location, yyerror_range, 2);]])[ - // Shift the error token. - error_token.state = yyn; + // Shift the error token.]b4_lac_if([[ + yy_lac_discard_ ("error recovery");]])[ + error_token.state = state_type (yyn); yypush_ ("Shifting", YY_MOVE (error_token)); } goto yynewstate; @@ -1088,8 +1149,147 @@ b4_dollar_popdef])[]dnl { error (]b4_join(b4_locations_if([yyexc.location]), [[yyexc.what ()]])[); + }]b4_lac_if([[ + + bool + ]b4_parser_class[::yy_lac_check_ (int yytoken) const + { + // Logically, the yylac_stack's lifetime is confined to this function. + // Clear it, to get rid of potential left-overs from previous call. + yylac_stack_.clear (); + // Reduce until we encounter a shift and thereby accept the token. +#if ]b4_api_PREFIX[DEBUG + YYCDEBUG << "LAC: checking lookahead " << yytname_[yytoken] << ':'; +#endif + std::ptrdiff_t lac_top = 0; + while (true) + { + state_type top_state = (yylac_stack_.empty () + ? yystack_[lac_top].state + : yylac_stack_.back ()); + int yyrule = yypact_[+top_state]; + if (yy_pact_value_is_default_ (yyrule) + || (yyrule += yytoken) < 0 || yylast_ < yyrule + || yycheck_[yyrule] != yytoken) + { + // Use the default action. + yyrule = yydefact_[+top_state]; + if (yyrule == 0) + { + YYCDEBUG << " Err\n"; + return false; + } + } + else + { + // Use the action from yytable. + yyrule = yytable_[yyrule]; + if (yy_table_value_is_error_ (yyrule)) + { + YYCDEBUG << " Err\n"; + return false; + } + if (0 < yyrule) + { + YYCDEBUG << " S" << yyrule << '\n'; + return true; + } + yyrule = -yyrule; + } + // By now we know we have to simulate a reduce. + YYCDEBUG << " R" << yyrule - 1; + // Pop the corresponding number of values from the stack. + { + std::ptrdiff_t yylen = yyr2_[yyrule]; + // First pop from the LAC stack as many tokens as possible. + std::ptrdiff_t lac_size = std::ptrdiff_t (yylac_stack_.size ()); + if (yylen < lac_size) + { + yylac_stack_.resize (std::size_t (lac_size - yylen)); + yylen = 0; + } + else if (lac_size) + { + yylac_stack_.clear (); + yylen -= lac_size; + } + // Only afterwards look at the main stack. + // We simulate popping elements by incrementing lac_top. + lac_top += yylen; + } + // Keep top_state in sync with the updated stack. + top_state = (yylac_stack_.empty () + ? yystack_[lac_top].state + : yylac_stack_.back ()); + // Push the resulting state of the reduction. + state_type state = yy_lr_goto_state_ (top_state, yyr1_[yyrule]); + YYCDEBUG << " G" << state; + yylac_stack_.push_back (state); + } } + // Establish the initial context if no initial context currently exists. + bool + ]b4_parser_class[::yy_lac_establish_ (int yytoken) + { + /* Establish the initial context for the current lookahead if no initial + context is currently established. + + We define a context as a snapshot of the parser stacks. We define + the initial context for a lookahead as the context in which the + parser initially examines that lookahead in order to select a + syntactic action. Thus, if the lookahead eventually proves + syntactically unacceptable (possibly in a later context reached via a + series of reductions), the initial context can be used to determine + the exact set of tokens that would be syntactically acceptable in the + lookahead's place. Moreover, it is the context after which any + further semantic actions would be erroneous because they would be + determined by a syntactically unacceptable token. + + yy_lac_establish_ should be invoked when a reduction is about to be + performed in an inconsistent state (which, for the purposes of LAC, + includes consistent states that don't know they're consistent because + their default reductions have been disabled). + + For parse.lac=full, the implementation of yy_lac_establish_ is as + follows. If no initial context is currently established for the + current lookahead, then check if that lookahead can eventually be + shifted if syntactic actions continue from the current context. */ + if (!yy_lac_established_) + { +#if ]b4_api_PREFIX[DEBUG + YYCDEBUG << "LAC: initial context established for " + << yytname_[yytoken] << '\n'; +#endif + yy_lac_established_ = true; + return yy_lac_check_ (yytoken); + } + return true; + } + + // Discard any previous initial lookahead context. + void + ]b4_parser_class[::yy_lac_discard_ (const char* evt) + { + /* Discard any previous initial lookahead context because of Event, + which may be a lookahead change or an invalidation of the currently + established initial context for the current lookahead. + + The most common example of a lookahead change is a shift. An example + of both cases is syntax error recovery. That is, a syntax error + occurs when the lookahead is syntactically erroneous for the + currently established initial context, so error recovery manipulates + the parser stacks to try to find a new initial context in which the + current lookahead is syntactically acceptable. If it fails to find + such a context, it discards the lookahead. */ + if (yy_lac_established_) + { + YYCDEBUG << "LAC: initial context discarded due to " + << evt << '\n'; + yy_lac_established_ = false; + } + }]])[ + // Generate an error message. std::string ]b4_parser_class[::yysyntax_error_ (]dnl @@ -1098,7 +1298,7 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla], {]b4_error_verbose_if([[ // Number of reported tokens (one for the "unexpected", one per // "expected"). - size_t yycount = 0; + std::ptrdiff_t yycount = 0; // Its maximum. enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; // Arguments of yyformat. @@ -1118,24 +1318,41 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla], a consistent state with a default action. There might have been a previous inconsistent state, consistent state with a non-default action, or user semantic action that manipulated - yyla. (However, yyla is currently not documented for users.) + yyla. (However, yyla is currently not documented for users.)]b4_lac_if([[ + In the first two cases, it might appear that the current syntax + error should have been detected in the previous state when + yy_lac_check was invoked. However, at that time, there might + have been a different syntax error that discarded a different + initial context during error recovery, leaving behind the + current lookahead.]], [[ - Of course, the expected token list depends on states to have correct lookahead information, and it depends on the parser not to perform extra reductions after fetching a lookahead from the - scanner and before detecting a syntax error. Thus, state - merging (from LALR or IELR) and default reductions corrupt the - expected token list. However, the list is correct for - canonical LR with one exception: it will still contain any - token that will not be accepted due to an error action in a - later state. + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state.]])[ */ if (!yyla.empty ()) { - int yytoken = yyla.type_get (); - yyarg[yycount++] = yytname_[yytoken]; - int yyn = yypact_[yystate]; + symbol_number_type yytoken = yyla.type_get (); + yyarg[yycount++] = yytname_[yytoken];]b4_lac_if([[ + +#if ]b4_api_PREFIX[DEBUG + // Execute LAC once. We don't care if it is successful, we + // only do it for the sake of debugging output. + if (!yy_lac_established_) + yy_lac_check_ (yytoken); +#endif]])[ + + int yyn = yypact_[+yystate]; if (!yy_pact_value_is_default_ (yyn)) - { + {]b4_lac_if([[ + for (int yyx = 0; yyx < yyntokens_; ++yyx) + if (yyx != yy_error_token_ && yyx != yy_undef_token_ + && yy_lac_check_ (yyx)) + {]], [[ /* Start YYX at -YYN if negative to avoid negative indexes in YYCHECK. In other words, skip the first -YYN actions for this state because they are default actions. */ @@ -1144,9 +1361,9 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla], int yychecklim = yylast_ - yyn + 1; int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; for (int yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_ + if (yycheck_[yyx + yyn] == yyx && yyx != yy_error_token_ && !yy_table_value_is_error_ (yytable_[yyx + yyn])) - { + {]])[ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) { yycount = 1; @@ -1177,7 +1394,7 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla], std::string yyres; // Argument number. - size_t yyi = 0; + std::ptrdiff_t yyi = 0; for (char const* yyp = yyformat; *yyp; ++yyp) if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) { @@ -1218,7 +1435,7 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla], i = yystack_.begin (), i_end = yystack_.end (); i != i_end; ++i) - *yycdebug_ << ' ' << i->state; + *yycdebug_ << ' ' << int (i->state); *yycdebug_ << '\n'; } @@ -1226,7 +1443,7 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla], void ]b4_parser_class[::yy_reduce_print_ (int yyrule) { - unsigned yylno = yyrline_[yyrule]; + int yylno = yyrline_[yyrule]; int yynrhs = yyr2_[yyrule]; // Print the symbols being reduced, and their result. *yycdebug_ << "Reducing stack by rule " << yyrule - 1 diff --git a/contrib/tools/bison/data/skeletons/location.cc b/contrib/tools/bison/data/skeletons/location.cc index a57c0fb67ad3..34db41881cbc 100644 --- a/contrib/tools/bison/data/skeletons/location.cc +++ b/contrib/tools/bison/data/skeletons/location.cc @@ -1,6 +1,6 @@ # C++ skeleton for Bison -# Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc. +# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,7 +16,7 @@ # along with this program. If not, see . m4_pushdef([b4_copyright_years], - [2002-2015, 2018-2019]) + [2002-2015, 2018-2020]) # b4_position_file @@ -62,11 +62,14 @@ m4_define([b4_location_define], [[ /// A point in a source file. class position { - public:]m4_ifdef([b4_location_constructors], [[ + public: + /// Type for line and column numbers. + typedef int counter_type; +]m4_ifdef([b4_location_constructors], [[ /// Construct a position. explicit position (]b4_percent_define_get([[filename_type]])[* f = YY_NULLPTR, - unsigned l = ]b4_location_initial_line[u, - unsigned c = ]b4_location_initial_column[u) + counter_type l = ]b4_location_initial_line[, + counter_type c = ]b4_location_initial_column[) : filename (f) , line (l) , column (c) @@ -75,8 +78,8 @@ m4_define([b4_location_define], ]])[ /// Initialization. void initialize (]b4_percent_define_get([[filename_type]])[* fn = YY_NULLPTR, - unsigned l = ]b4_location_initial_line[u, - unsigned c = ]b4_location_initial_column[u) + counter_type l = ]b4_location_initial_line[, + counter_type c = ]b4_location_initial_column[) { filename = fn; line = l; @@ -86,17 +89,17 @@ m4_define([b4_location_define], /** \name Line and Column related manipulators ** \{ */ /// (line related) Advance to the COUNT next lines. - void lines (int count = 1) + void lines (counter_type count = 1) { if (count) { - column = ]b4_location_initial_column[u; + column = ]b4_location_initial_column[; line = add_ (line, count, ]b4_location_initial_line[); } } /// (column related) Advance to the COUNT next columns. - void columns (int count = 1) + void columns (counter_type count = 1) { column = add_ (column, count, ]b4_location_initial_column[); } @@ -105,22 +108,21 @@ m4_define([b4_location_define], /// File name to which this position refers. ]b4_percent_define_get([[filename_type]])[* filename; /// Current line number. - unsigned line; + counter_type line; /// Current column number. - unsigned column; + counter_type column; private: /// Compute max (min, lhs+rhs). - static unsigned add_ (unsigned lhs, int rhs, int min) + static counter_type add_ (counter_type lhs, counter_type rhs, counter_type min) { - return static_cast (std::max (min, - static_cast (lhs) + rhs)); + return lhs + rhs < min ? min : lhs + rhs; } }; /// Add \a width columns, in place. inline position& - operator+= (position& res, int width) + operator+= (position& res, position::counter_type width) { res.columns (width); return res; @@ -128,21 +130,21 @@ m4_define([b4_location_define], /// Add \a width columns. inline position - operator+ (position res, int width) + operator+ (position res, position::counter_type width) { return res += width; } /// Subtract \a width columns, in place. inline position& - operator-= (position& res, int width) + operator-= (position& res, position::counter_type width) { return res += -width; } /// Subtract \a width columns. inline position - operator- (position res, int width) + operator- (position res, position::counter_type width) { return res -= width; } @@ -182,6 +184,8 @@ m4_define([b4_location_define], class location { public: + /// Type for line and column numbers. + typedef position::counter_type counter_type; ]m4_ifdef([b4_location_constructors], [ /// Construct a location from \a b to \a e. location (const position& b, const position& e) @@ -197,8 +201,8 @@ m4_define([b4_location_define], /// Construct a 0-width location in \a f, \a l, \a c. explicit location (]b4_percent_define_get([[filename_type]])[* f, - unsigned l = ]b4_location_initial_line[u, - unsigned c = ]b4_location_initial_column[u) + counter_type l = ]b4_location_initial_line[, + counter_type c = ]b4_location_initial_column[) : begin (f, l, c) , end (f, l, c) {} @@ -206,8 +210,8 @@ m4_define([b4_location_define], ])[ /// Initialization. void initialize (]b4_percent_define_get([[filename_type]])[* f = YY_NULLPTR, - unsigned l = ]b4_location_initial_line[u, - unsigned c = ]b4_location_initial_column[u) + counter_type l = ]b4_location_initial_line[, + counter_type c = ]b4_location_initial_column[) { begin.initialize (f, l, c); end = begin; @@ -223,13 +227,13 @@ m4_define([b4_location_define], } /// Extend the current location to the COUNT next columns. - void columns (int count = 1) + void columns (counter_type count = 1) { end += count; } /// Extend the current location to the COUNT next lines. - void lines (int count = 1) + void lines (counter_type count = 1) { end.lines (count); } @@ -244,39 +248,45 @@ m4_define([b4_location_define], }; /// Join two locations, in place. - inline location& operator+= (location& res, const location& end) + inline location& + operator+= (location& res, const location& end) { res.end = end.end; return res; } /// Join two locations. - inline location operator+ (location res, const location& end) + inline location + operator+ (location res, const location& end) { return res += end; } /// Add \a width columns to the end position, in place. - inline location& operator+= (location& res, int width) + inline location& + operator+= (location& res, location::counter_type width) { res.columns (width); return res; } /// Add \a width columns to the end position. - inline location operator+ (location res, int width) + inline location + operator+ (location res, location::counter_type width) { return res += width; } /// Subtract \a width columns to the end position, in place. - inline location& operator-= (location& res, int width) + inline location& + operator-= (location& res, location::counter_type width) { return res += -width; } /// Subtract \a width columns to the end position. - inline location operator- (location res, int width) + inline location + operator- (location res, location::counter_type width) { return res -= width; } @@ -305,7 +315,8 @@ m4_define([b4_location_define], std::basic_ostream& operator<< (std::basic_ostream& ostr, const location& loc) { - unsigned end_col = 0 < loc.end.column ? loc.end.column - 1 : 0; + location::counter_type end_col + = 0 < loc.end.column ? loc.end.column - 1 : 0; ostr << loc.begin; if (loc.end.filename && (!loc.begin.filename @@ -327,7 +338,7 @@ m4_ifdef([b4_position_file], [[ // used to define is now defined in "]b4_location_file[". // // To get rid of this file: -// 1. add 'require "3.2"' (or newer) to your grammar file +// 1. add '%require "3.2"' (or newer) to your grammar file // 2. remove references to this file from your build system // 3. if you used to include it, include "]b4_location_file[" instead. @@ -346,7 +357,6 @@ m4_ifdef([b4_location_file], [[ ]b4_cpp_guard_open([b4_location_path])[ -# include // std::max # include # include diff --git a/contrib/tools/bison/data/skeletons/stack.hh b/contrib/tools/bison/data/skeletons/stack.hh index 926a6f8cac24..5eb485696af1 100644 --- a/contrib/tools/bison/data/skeletons/stack.hh +++ b/contrib/tools/bison/data/skeletons/stack.hh @@ -1,6 +1,6 @@ # C++ skeleton for Bison -# Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc. +# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -35,45 +35,28 @@ m4_define([b4_stack_define], typedef typename S::reverse_iterator iterator; typedef typename S::const_reverse_iterator const_iterator; typedef typename S::size_type size_type; + typedef typename std::ptrdiff_t index_type; stack (size_type n = 200) : seq_ (n) {} - /// Random access. - /// - /// Index 0 returns the topmost element. - T& - operator[] (size_type i) - { - return seq_[size () - 1 - i]; - } - - /// Random access. - /// - /// Index 0 returns the topmost element. - T& - operator[] (int i) - { - return operator[] (size_type (i)); - } - /// Random access. /// /// Index 0 returns the topmost element. const T& - operator[] (size_type i) const + operator[] (index_type i) const { - return seq_[size () - 1 - i]; + return seq_[size_type (size () - 1 - i)]; } /// Random access. /// /// Index 0 returns the topmost element. - const T& - operator[] (int i) const + T& + operator[] (index_type i) { - return operator[] (size_type (i)); + return seq_[size_type (size () - 1 - i)]; } /// Steal the contents of \a t. @@ -88,7 +71,7 @@ m4_define([b4_stack_define], /// Pop elements from the stack. void - pop (int n = 1) YY_NOEXCEPT + pop (std::ptrdiff_t n = 1) YY_NOEXCEPT { for (; 0 < n; --n) seq_.pop_back (); @@ -102,10 +85,16 @@ m4_define([b4_stack_define], } /// Number of elements on the stack. - size_type + index_type size () const YY_NOEXCEPT { - return seq_.size (); + return index_type (seq_.size ()); + } + + std::ptrdiff_t + ssize () const YY_NOEXCEPT + { + return std::ptrdiff_t (size ()); } /// Iterator on top of the stack (going downwards). @@ -126,20 +115,20 @@ m4_define([b4_stack_define], class slice { public: - slice (const stack& stack, int range) + slice (const stack& stack, index_type range) : stack_ (stack) , range_ (range) {} const T& - operator[] (int i) const + operator[] (index_type i) const { return stack_[range_ - i]; } private: const stack& stack_; - int range_; + index_type range_; }; private: @@ -157,7 +146,7 @@ m4_ifdef([b4_stack_file], // used to define is now defined with the parser itself. // // To get rid of this file: -// 1. add 'require "3.2"' (or newer) to your grammar file +// 1. add '%require "3.2"' (or newer) to your grammar file // 2. remove references to this file from your build system. ]b4_output_end[ ]]) diff --git a/contrib/tools/bison/data/skeletons/variant.hh b/contrib/tools/bison/data/skeletons/variant.hh index 8b9d4802df9a..13a35c6dd5c3 100644 --- a/contrib/tools/bison/data/skeletons/variant.hh +++ b/contrib/tools/bison/data/skeletons/variant.hh @@ -1,6 +1,6 @@ # C++ skeleton for Bison -# Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc. +# Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -72,9 +72,9 @@ m4_map([ b4_symbol_tag_comment], [$@])dnl # The needed includes for variants support. m4_define([b4_variant_includes], [b4_parse_assert_if([[#include ]])[ -#ifndef YYASSERT +#ifndef YY_ASSERT # include -# define YYASSERT assert +# define YY_ASSERT assert #endif ]]) @@ -111,14 +111,14 @@ m4_define([b4_value_type_declare], semantic_type (YY_RVREF (T) t)]b4_parse_assert_if([ : yytypeid_ (&typeid (T))])[ { - YYASSERT (sizeof (T) <= size); + YY_ASSERT (sizeof (T) <= size); new (yyas_ ()) T (YY_MOVE (t)); } /// Destruction, allowed only if empty. ~semantic_type () YY_NOEXCEPT {]b4_parse_assert_if([ - YYASSERT (!yytypeid_); + YY_ASSERT (!yytypeid_); ])[} # if 201103L <= YY_CPLUSPLUS @@ -127,8 +127,8 @@ m4_define([b4_value_type_declare], T& emplace (U&&... u) {]b4_parse_assert_if([ - YYASSERT (!yytypeid_); - YYASSERT (sizeof (T) <= size); + YY_ASSERT (!yytypeid_); + YY_ASSERT (sizeof (T) <= size); yytypeid_ = & typeid (T);])[ return *new (yyas_ ()) T (std::forward (u)...); } @@ -138,8 +138,8 @@ m4_define([b4_value_type_declare], T& emplace () {]b4_parse_assert_if([ - YYASSERT (!yytypeid_); - YYASSERT (sizeof (T) <= size); + YY_ASSERT (!yytypeid_); + YY_ASSERT (sizeof (T) <= size); yytypeid_ = & typeid (T);])[ return *new (yyas_ ()) T (); } @@ -149,8 +149,8 @@ m4_define([b4_value_type_declare], T& emplace (const T& t) {]b4_parse_assert_if([ - YYASSERT (!yytypeid_); - YYASSERT (sizeof (T) <= size); + YY_ASSERT (!yytypeid_); + YY_ASSERT (sizeof (T) <= size); yytypeid_ = & typeid (T);])[ return *new (yyas_ ()) T (t); } @@ -179,9 +179,9 @@ m4_define([b4_value_type_declare], T& as () YY_NOEXCEPT {]b4_parse_assert_if([ - YYASSERT (yytypeid_); - YYASSERT (*yytypeid_ == typeid (T)); - YYASSERT (sizeof (T) <= size);])[ + YY_ASSERT (yytypeid_); + YY_ASSERT (*yytypeid_ == typeid (T)); + YY_ASSERT (sizeof (T) <= size);])[ return *yyas_ (); } @@ -190,9 +190,9 @@ m4_define([b4_value_type_declare], const T& as () const YY_NOEXCEPT {]b4_parse_assert_if([ - YYASSERT (yytypeid_); - YYASSERT (*yytypeid_ == typeid (T)); - YYASSERT (sizeof (T) <= size);])[ + YY_ASSERT (yytypeid_); + YY_ASSERT (*yytypeid_ == typeid (T)); + YY_ASSERT (sizeof (T) <= size);])[ return *yyas_ (); } @@ -208,8 +208,8 @@ m4_define([b4_value_type_declare], void swap (self_type& that) YY_NOEXCEPT {]b4_parse_assert_if([ - YYASSERT (yytypeid_); - YYASSERT (*yytypeid_ == *that.yytypeid_);])[ + YY_ASSERT (yytypeid_); + YY_ASSERT (*yytypeid_ == *that.yytypeid_);])[ std::swap (as (), that.as ()); } @@ -401,7 +401,7 @@ m4_define([_b4_token_constructor_define], b4_symbol_if([$1], [has_type], [std::move (v)]), b4_locations_if([std::move (l)]))[) { - YYASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[); + YY_ASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[); } #else symbol_type (]b4_join( @@ -413,7 +413,7 @@ m4_define([_b4_token_constructor_define], b4_symbol_if([$1], [has_type], [v]), b4_locations_if([l]))[) { - YYASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[); + YY_ASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[); } #endif ]])]) diff --git a/contrib/tools/bison/data/skeletons/yacc.c b/contrib/tools/bison/data/skeletons/yacc.c index 54e40e67412e..add943519257 100644 --- a/contrib/tools/bison/data/skeletons/yacc.c +++ b/contrib/tools/bison/data/skeletons/yacc.c @@ -1,11 +1,11 @@ - -*- C -*- +# -*- C -*- # Yacc compatible skeleton for Bison -# Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software +# Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software # Foundation, Inc. m4_pushdef([b4_copyright_years], - [1984, 1989-1990, 2000-2015, 2018-2019]) + [1984, 1989-1990, 2000-2015, 2018-2020]) # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,7 +20,34 @@ m4_pushdef([b4_copyright_years], # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# Check the value of %define api.push-pull. +m4_include(b4_skeletonsdir/[c.m4]) + +## ---------- ## +## api.pure. ## +## ---------- ## + +b4_percent_define_default([[api.pure]], [[false]]) +b4_percent_define_check_values([[[[api.pure]], + [[false]], [[true]], [[]], [[full]]]]) + +m4_define([b4_pure_flag], [[0]]) +m4_case(b4_percent_define_get([[api.pure]]), + [false], [m4_define([b4_pure_flag], [[0]])], + [true], [m4_define([b4_pure_flag], [[1]])], + [], [m4_define([b4_pure_flag], [[1]])], + [full], [m4_define([b4_pure_flag], [[2]])]) + +m4_define([b4_pure_if], +[m4_case(b4_pure_flag, + [0], [$2], + [1], [$1], + [2], [$1])]) + [m4_fatal([invalid api.pure value: ]$1)])]) + +## --------------- ## +## api.push-pull. ## +## --------------- ## + b4_percent_define_default([[api.push-pull]], [[pull]]) b4_percent_define_check_values([[[[api.push-pull]], [[pull]], [[push]], [[both]]]]) @@ -38,8 +65,10 @@ b4_use_push_for_pull_if([ b4_push_if([m4_define([b4_use_push_for_pull_flag], [[0]])], [m4_define([b4_push_flag], [[1]])])]) -# Check the value of %define parse.lac and friends, where LAC stands for -# lookahead correction. +## ----------- ## +## parse.lac. ## +## ----------- ## + b4_percent_define_default([[parse.lac]], [[none]]) b4_percent_define_default([[parse.lac.es-capacity-initial]], [[20]]) b4_percent_define_default([[parse.lac.memory-trace]], [[failures]]) @@ -51,8 +80,6 @@ m4_define([b4_lac_flag], [m4_if(b4_percent_define_get([[parse.lac]]), [none], [[0]], [[1]])]) -m4_include(b4_skeletonsdir/[c.m4]) - ## ---------------- ## ## Default values. ## ## ---------------- ## @@ -62,28 +89,6 @@ m4_define_default([b4_stack_depth_max], [10000]) m4_define_default([b4_stack_depth_init], [200]) -## ------------------------ ## -## Pure/impure interfaces. ## -## ------------------------ ## - -b4_percent_define_default([[api.pure]], [[false]]) -b4_percent_define_check_values([[[[api.pure]], - [[false]], [[true]], [[]], [[full]]]]) - -m4_define([b4_pure_flag], [[0]]) -m4_case(b4_percent_define_get([[api.pure]]), - [false], [m4_define([b4_pure_flag], [[0]])], - [true], [m4_define([b4_pure_flag], [[1]])], - [], [m4_define([b4_pure_flag], [[1]])], - [full], [m4_define([b4_pure_flag], [[2]])]) - -m4_define([b4_pure_if], -[m4_case(b4_pure_flag, - [0], [$2], - [1], [$1], - [2], [$1])]) - [m4_fatal([invalid api.pure value: ]$1)])]) - # b4_yyerror_arg_loc_if(ARG) # -------------------------- # Expand ARG iff yyerror is to be given a location as argument. @@ -101,28 +106,6 @@ m4_ifset([b4_parse_param], [b4_args(b4_parse_param), ])]) -## ------------ ## -## Data Types. ## -## ------------ ## - -# b4_int_type(MIN, MAX) -# --------------------- -# Return the smallest int type able to handle numbers ranging from -# MIN to MAX (included). Overwrite the version from c.m4, which -# uses only C89 types, so that the user can override the shorter -# types, and so that pre-C89 compilers are handled correctly. -m4_define([b4_int_type], -[m4_if(b4_ints_in($@, [0], [255]), [1], [yytype_uint8], - b4_ints_in($@, [-128], [127]), [1], [yytype_int8], - - b4_ints_in($@, [0], [65535]), [1], [yytype_uint16], - b4_ints_in($@, [-32768], [32767]), [1], [yytype_int16], - - m4_eval([0 <= $1]), [1], [unsigned], - - [int])]) - - ## ----------------- ## ## Semantic Values. ## ## ----------------- ## @@ -199,7 +182,7 @@ m4_define([b4_declare_parser_state_variables], [b4_pure_if([[ /* Number of syntax errors so far. */ int yynerrs; ]])[ - int yystate; + yy_state_fast_t yystate; /* Number of tokens to shift before error messages enabled. */ int yyerrstatus; @@ -212,9 +195,9 @@ m4_define([b4_declare_parser_state_variables], [b4_pure_if([[ to reallocate them elsewhere. */ /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss; - yytype_int16 *yyssp; + yy_state_t yyssa[YYINITDEPTH]; + yy_state_t *yyss; + yy_state_t *yyssp; /* The semantic value stack. */ YYSTYPE yyvsa[YYINITDEPTH]; @@ -229,11 +212,11 @@ m4_define([b4_declare_parser_state_variables], [b4_pure_if([[ /* The locations where the error started and ended. */ YYLTYPE yyerror_range[3];]])[ - YYSIZE_T yystacksize;]b4_lac_if([[ + YYPTRDIFF_T yystacksize;]b4_lac_if([[ - yytype_int16 yyesa@{]b4_percent_define_get([[parse.lac.es-capacity-initial]])[@}; - yytype_int16 *yyes; - YYSIZE_T yyes_capacity;]])]) + yy_state_t yyesa@{]b4_percent_define_get([[parse.lac.es-capacity-initial]])[@}; + yy_state_t *yyes; + YYPTRDIFF_T yyes_capacity;]])]) # _b4_declare_yyparse_push @@ -284,20 +267,48 @@ m4_define([b4_declare_yyparse], # Declaration that might either go into the header (if --defines) # or open coded in the parser body. m4_define([b4_shared_declarations], -[b4_cpp_guard_open([b4_spec_defines_file])[ +[b4_cpp_guard_open([b4_spec_header_file])[ ]b4_declare_yydebug[ ]b4_percent_code_get([[requires]])[ ]b4_token_enums_defines[ ]b4_declare_yylstype[ ]b4_declare_yyparse[ ]b4_percent_code_get([[provides]])[ -]b4_cpp_guard_close([b4_spec_defines_file])[]dnl +]b4_cpp_guard_close([b4_spec_header_file])[]dnl ]) + +# b4_header_include_if(IF-TRUE, IF-FALSE) +# --------------------------------------- +# Run IF-TRUE if we generate an output file and api.header.include +# is defined. +m4_define([b4_header_include_if], +[m4_ifval(m4_quote(b4_spec_header_file), + [b4_percent_define_ifdef([[api.header.include]], + [$1], + [$2])], + [$2])]) + +m4_if(b4_spec_header_file, [[y.tab.h]], + [b4_percent_define_default([[api.header.include]], + [["@basename(]b4_spec_header_file[@)"]])]) + + + + ## -------------- ## ## Output files. ## ## -------------- ## + +b4_defines_if([[ +]b4_output_begin([b4_spec_header_file])[ +]b4_copyright([Bison interface for Yacc-like parsers in C])[ +]b4_disclaimer[ +]b4_shared_declarations[ +]b4_output_end[ +]])# b4_defines_if + b4_output_begin([b4_parser_file_name])[ ]b4_copyright([Bison implementation for Yacc-like parsers in C])[ /* C LALR(1) parser skeleton written by Richard Stallman, by @@ -328,13 +339,13 @@ m4_if(b4_api_prefix, [yy], [], #define yylex ]b4_prefix[lex #define yyerror ]b4_prefix[error #define yydebug ]b4_prefix[debug -#define yynerrs ]b4_prefix[nerrs -]]b4_pure_if([], [[ +#define yynerrs ]b4_prefix[nerrs]]b4_pure_if([], [[ #define yylval ]b4_prefix[lval #define yychar ]b4_prefix[char]b4_locations_if([[ #define yylloc ]b4_prefix[lloc]])]))[ ]b4_user_pre_prologue[ +]b4_cast_define[ ]b4_null_define[ /* Enabling verbose error messages. */ @@ -345,11 +356,11 @@ m4_if(b4_api_prefix, [yy], [], # define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[ #endif -]m4_ifval(m4_quote(b4_spec_defines_file), -[[/* In a future release of Bison, this section will be replaced - by #include "@basename(]b4_spec_defines_file[@)". */ -]])dnl -b4_shared_declarations[ +]b4_header_include_if([[#include ]b4_percent_define_get([[api.header.include]])], + [m4_ifval(m4_quote(b4_spec_header_file), + [/* Use api.header.include to #include this header + instead of duplicating it here. */ +])b4_shared_declarations])[ ]b4_user_post_prologue[ ]b4_percent_code_get[]dnl @@ -358,28 +369,22 @@ b4_shared_declarations[ # undef short #endif -#ifdef YYTYPE_UINT8 -typedef YYTYPE_UINT8 yytype_uint8; -#else -typedef unsigned char yytype_uint8; -#endif - -#ifdef YYTYPE_INT8 -typedef YYTYPE_INT8 yytype_int8; -#else -typedef signed char yytype_int8; -#endif - -#ifdef YYTYPE_UINT16 -typedef YYTYPE_UINT16 yytype_uint16; -#else -typedef unsigned short yytype_uint16; -#endif +]b4_c99_int_type_define[ -#ifdef YYTYPE_INT16 -typedef YYTYPE_INT16 yytype_int16; -#else -typedef short yytype_int16; +#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif #endif #ifndef YYSIZE_T @@ -387,7 +392,7 @@ typedef short yytype_int16; # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t -# elif ! defined YYSIZE_T +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else @@ -395,7 +400,19 @@ typedef short yytype_int16; # endif #endif -#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) +#define YYSIZE_MAXIMUM \ + YY_CAST (YYPTRDIFF_T, \ + (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ + ? YYPTRDIFF_MAXIMUM \ + : YY_CAST (YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) + +/* Stored state numbers (used for stacks). */ +typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ yy_state_t; + +/* State numbers in computations. */ +typedef int yy_state_fast_t; #ifndef YY_ # if defined YYENABLE_NLS && YYENABLE_NLS @@ -411,6 +428,15 @@ typedef short yytype_int16; ]b4_attribute_define[ +]b4_parse_assert_if([[#ifdef NDEBUG +# define YY_ASSERT(E) ((void) (0 && (E))) +#else +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_ASSERT(E) assert (E) +#endif +]], +[[#define YY_ASSERT(E) ((void) (0 && (E)))]])[ + #if ]b4_lac_if([[1]], [[! defined yyoverflow || YYERROR_VERBOSE]])[ /* The parser invokes alloca or malloc; define the necessary symbols. */]dnl @@ -489,22 +515,23 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ /* A type that is properly aligned for any stack member. */ union yyalloc { - yytype_int16 yyss_alloc; + yy_state_t yyss_alloc; YYSTYPE yyvs_alloc;]b4_locations_if([ YYLTYPE yyls_alloc;])[ }; /* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) +# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ ]b4_locations_if( [# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE) \ + + YYSIZEOF (YYLTYPE)) \ + 2 * YYSTACK_GAP_MAXIMUM)], [# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM)])[ # define YYCOPY_NEEDED 1 @@ -517,11 +544,11 @@ union yyalloc # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ do \ { \ - YYSIZE_T yynewbytes; \ + YYPTRDIFF_T yynewbytes; \ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ + yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / YYSIZEOF (*yyptr); \ } \ while (0) @@ -533,12 +560,12 @@ union yyalloc # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ # define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) + __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) # else # define YYCOPY(Dst, Src, Count) \ do \ { \ - YYSIZE_T yyi; \ + YYPTRDIFF_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (Dst)[yyi] = (Src)[yyi]; \ } \ @@ -564,17 +591,20 @@ union yyalloc #define YYUNDEFTOK ]b4_undef_token_number[ #define YYMAXUTOK ]b4_user_token_number_max[ + /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM as returned by yylex, with out-of-bounds checking. */ -#define YYTRANSLATE(YYX) \ - ((unsigned) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) +]b4_api_token_raw_if(dnl +[[#define YYTRANSLATE(YYX) (YYX)]], +[[#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM as returned by yylex. */ static const ]b4_int_type_for([b4_translate])[ yytranslate[] = { ]b4_translate[ -}; +};]])[ #if ]b4_api_PREFIX[DEBUG ]b4_integral_parser_table_define([rline], [b4_rline], @@ -599,15 +629,15 @@ static const ]b4_int_type_for([b4_toknum])[ yytoknum[] = }; # endif -#define YYPACT_NINF ]b4_pact_ninf[ +#define YYPACT_NINF (]b4_pact_ninf[) -#define yypact_value_is_default(Yystate) \ - ]b4_table_value_equals([[pact]], [[Yystate]], [b4_pact_ninf])[ +#define yypact_value_is_default(Yyn) \ + ]b4_table_value_equals([[pact]], [[Yyn]], [b4_pact_ninf], [YYPACT_NINF])[ -#define YYTABLE_NINF ]b4_table_ninf[ +#define YYTABLE_NINF (]b4_table_ninf[) -#define yytable_value_is_error(Yytable_value) \ - ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[ +#define yytable_value_is_error(Yyn) \ + ]b4_table_value_equals([[table]], [[Yyn]], [b4_table_ninf], [YYTABLE_NINF])[ ]b4_parser_tables_define[ @@ -643,7 +673,7 @@ static const ]b4_int_type_for([b4_toknum])[ yytoknum[] = /* Error token number */ #define YYTERROR 1 -#define YYERRCODE 256 +#define YYERRCODE ]b4_symbol(1, user_number)[ ]b4_locations_if([[ ]b4_yylloc_default_define[ @@ -685,8 +715,8 @@ do { \ `------------------------------------------------------------------*/ ]b4_function_define([yy_stack_print], [static void], - [[yytype_int16 *yybottom], [yybottom]], - [[yytype_int16 *yytop], [yytop]])[ + [[yy_state_t *yybottom], [yybottom]], + [[yy_state_t *yytop], [yytop]])[ { YYFPRINTF (stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) @@ -709,23 +739,23 @@ do { \ `------------------------------------------------*/ ]b4_function_define([yy_reduce_print], [static void], - [[yytype_int16 *yyssp], [yyssp]], + [[yy_state_t *yyssp], [yyssp]], [[YYSTYPE *yyvsp], [yyvsp]], b4_locations_if([[[YYLTYPE *yylsp], [yylsp]], ])[[int yyrule], [yyrule]]m4_ifset([b4_parse_param], [, b4_parse_param]))[ { - unsigned long yylno = yyrline[yyrule]; + int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, - yystos[yyssp[yyi + 1 - yynrhs]], + yystos[+yyssp[yyi + 1 - yynrhs]], &]b4_rhs_value(yynrhs, yyi + 1)[ ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl b4_user_args[); @@ -777,22 +807,22 @@ int yydebug; using YYSTACK_FREE. Return 0 if successful or if no reallocation is required. Return 1 if memory is exhausted. */ static int -yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd, +yy_lac_stack_realloc (YYPTRDIFF_T *yycapacity, YYPTRDIFF_T yyadd, #if ]b4_api_PREFIX[DEBUG char const *yydebug_prefix, char const *yydebug_suffix, #endif - yytype_int16 **yybottom, - yytype_int16 *yybottom_no_free, - yytype_int16 **yytop, yytype_int16 *yytop_empty) + yy_state_t **yybottom, + yy_state_t *yybottom_no_free, + yy_state_t **yytop, yy_state_t *yytop_empty) { - YYSIZE_T yysize_old = - (YYSIZE_T) (*yytop == yytop_empty ? 0 : *yytop - *yybottom + 1); - YYSIZE_T yysize_new = yysize_old + yyadd; + YYPTRDIFF_T yysize_old = + *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1; + YYPTRDIFF_T yysize_new = yysize_old + yyadd; if (*yycapacity < yysize_new) { - YYSIZE_T yyalloc = 2 * yysize_new; - yytype_int16 *yybottom_new; + YYPTRDIFF_T yyalloc = 2 * yysize_new; + yy_state_t *yybottom_new; /* Use YYMAXDEPTH for maximum stack size given that the stack should never need to grow larger than the main state stack needs to grow without LAC. */ @@ -805,7 +835,9 @@ yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd, if (YYMAXDEPTH < yyalloc) yyalloc = YYMAXDEPTH; yybottom_new = - (yytype_int16*) YYSTACK_ALLOC (yyalloc * sizeof *yybottom_new); + YY_CAST (yy_state_t *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, + yyalloc * YYSIZEOF (*yybottom_new)))); if (!yybottom_new) { YYDPRINTF ((stderr, "%srealloc failed%s", yydebug_prefix, @@ -822,8 +854,10 @@ yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd, *yybottom = yybottom_new; *yycapacity = yyalloc;]m4_if(b4_percent_define_get([[parse.lac.memory-trace]]), [full], [[ - YYDPRINTF ((stderr, "%srealloc to %lu%s", yydebug_prefix, - (unsigned long) yyalloc, yydebug_suffix));]])[ + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "%srealloc to %ld%s", yydebug_prefix, + YY_CAST (long, yyalloc), yydebug_suffix)); + YY_IGNORE_USELESS_CAST_END]])[ } return 0; } @@ -908,11 +942,11 @@ do { \ contents of either array, alter *YYES and *YYES_CAPACITY, and free any old *YYES other than YYESA. */ static int -yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, - YYSIZE_T *yyes_capacity, yytype_int16 *yyssp, int yytoken) +yy_lac (yy_state_t *yyesa, yy_state_t **yyes, + YYPTRDIFF_T *yyes_capacity, yy_state_t *yyssp, int yytoken) { - yytype_int16 *yyes_prev = yyssp; - yytype_int16 *yyesp = yyes_prev; + yy_state_t *yyes_prev = yyssp; + yy_state_t *yyesp = yyes_prev; YYDPRINTF ((stderr, "LAC: checking lookahead %s:", yytname[yytoken])); if (yytoken == YYUNDEFTOK) { @@ -921,12 +955,12 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, } while (1) { - int yyrule = yypact[*yyesp]; + int yyrule = yypact[+*yyesp]; if (yypact_value_is_default (yyrule) || (yyrule += yytoken) < 0 || YYLAST < yyrule || yycheck[yyrule] != yytoken) { - yyrule = yydefact[*yyesp]; + yyrule = yydefact[+*yyesp]; if (yyrule == 0) { YYDPRINTF ((stderr, " Err\n")); @@ -949,11 +983,11 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, yyrule = -yyrule; } { - YYSIZE_T yylen = yyr2[yyrule]; + YYPTRDIFF_T yylen = yyr2[yyrule]; YYDPRINTF ((stderr, " R%d", yyrule - 1)); if (yyesp != yyes_prev) { - YYSIZE_T yysize = (YYSIZE_T) (yyesp - *yyes + 1); + YYPTRDIFF_T yysize = yyesp - *yyes + 1; if (yylen < yysize) { yyesp -= yylen; @@ -969,19 +1003,20 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, yyesp = yyes_prev -= yylen; } { - yytype_int16 yystate; + yy_state_fast_t yystate; { const int yylhs = yyr1[yyrule] - YYNTOKENS; const int yyi = yypgoto[yylhs] + *yyesp; - yystate = ((yytype_int16) - (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyesp - ? yytable[yyi] - : yydefgoto[yylhs])); + yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyesp + ? yytable[yyi] + : yydefgoto[yylhs]); } if (yyesp == yyes_prev) { yyesp = *yyes; - *yyesp = yystate; + YY_IGNORE_USELESS_CAST_BEGIN + *yyesp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END } else { @@ -994,9 +1029,11 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, YYDPRINTF ((stderr, "\n")); return 2; } - *++yyesp = yystate; + YY_IGNORE_USELESS_CAST_BEGIN + *++yyesp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END } - YYDPRINTF ((stderr, " G%d", (int) yystate)); + YYDPRINTF ((stderr, " G%d", yystate)); } } }]])[ @@ -1006,13 +1043,13 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, # ifndef yystrlen # if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen +# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) # else /* Return the length of YYSTR. */ -]b4_function_define([yystrlen], [static YYSIZE_T], +]b4_function_define([yystrlen], [static YYPTRDIFF_T], [[const char *yystr], [yystr]])[ { - YYSIZE_T yylen; + YYPTRDIFF_T yylen; for (yylen = 0; yystr[yylen]; yylen++) continue; return yylen; @@ -1048,12 +1085,12 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, backslash-backslash). YYSTR is taken from yytname. If YYRES is null, do not copy; instead, return the length of what the result would have been. */ -static YYSIZE_T +static YYPTRDIFF_T yytnamerr (char *yyres, const char *yystr) { if (*yystr == '"') { - YYSIZE_T yyn = 0; + YYPTRDIFF_T yyn = 0; char const *yyp = yystr; for (;;) @@ -1084,10 +1121,10 @@ yytnamerr (char *yyres, const char *yystr) do_not_strip_quotes: ; } - if (! yyres) + if (yyres) + return yystpcpy (yyres, yystr) - yyres; + else return yystrlen (yystr); - - return (YYSIZE_T) (yystpcpy (yyres, yystr) - yyres); } # endif @@ -1102,20 +1139,20 @@ yytnamerr (char *yyres, const char *yystr) required number of bytes is too large to store]b4_lac_if([[ or if yy_lac returned 2]])[. */ static int -yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - ]b4_lac_if([[yytype_int16 *yyesa, yytype_int16 **yyes, - YYSIZE_T *yyes_capacity, ]])[yytype_int16 *yyssp, int yytoken) +yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, + ]b4_lac_if([[yy_state_t *yyesa, yy_state_t **yyes, + YYPTRDIFF_T *yyes_capacity, ]])[yy_state_t *yyssp, int yytoken) { - YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); - YYSIZE_T yysize = yysize0; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; /* Internationalized format string. */ const char *yyformat = YY_NULLPTR; - /* Arguments of yyformat. */ + /* Arguments of yyformat: reported tokens (one for the "unexpected", + one per "expected"). */ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - /* Number of reported tokens (one for the "unexpected", one per - "expected"). */ + /* Actual size of YYARG. */ int yycount = 0; + /* Cumulated lengths of YYARG. */ + YYPTRDIFF_T yysize = 0; /* There are many possibilities here to consider: - If this state is a consistent state with a default action, then @@ -1147,19 +1184,14 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, */ if (yytoken != YYEMPTY) { - int yyn = yypact[*yyssp];]b4_lac_if([[ + int yyn = yypact[+*yyssp]; + YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); + yysize = yysize0;]b4_lac_if([[ YYDPRINTF ((stderr, "Constructing syntax error message\n"));]])[ yyarg[yycount++] = yytname[yytoken]; if (!yypact_value_is_default (yyn)) - {]b4_lac_if([], [[ - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;]])[ - int yyx;]b4_lac_if([[ + {]b4_lac_if([[ + int yyx; for (yyx = 0; yyx < YYNTOKENS; ++yyx) if (yyx != YYTERROR && yyx != YYUNDEFTOK) @@ -1172,6 +1204,14 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, if (yy_lac_status == 1) continue; }]], [[ + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; for (yyx = yyxbegin; yyx < yyxend; ++yyx) if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR @@ -1185,7 +1225,8 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, } yyarg[yycount++] = yytname[yyx]; { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); + YYPTRDIFF_T yysize1 + = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) yysize = yysize1; else @@ -1216,7 +1257,9 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, } { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); + /* Don't count the "%s"s in the final size, but reserve room for + the terminator. */ + YYPTRDIFF_T yysize1 = yysize + (yystrlen (yyformat) - 2 * yycount) + 1; if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) yysize = yysize1; else @@ -1246,8 +1289,8 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, } else { - yyp++; - yyformat++; + ++yyp; + ++yyformat; } } return 0; @@ -1313,7 +1356,7 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[ yypstate *yyps;]b4_pure_if([], [[ if (yypstate_allocated) return YY_NULLPTR;]])[ - yyps = (yypstate *) malloc (sizeof *yyps); + yyps = YY_CAST (yypstate *, malloc (sizeof *yyps)); if (!yyps) return YY_NULLPTR; yyps->yynew = 1;]b4_pure_if([], [[ @@ -1397,7 +1440,7 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[ /* Buffer for error messages, and its allocated size. */ char yymsgbuf[128]; char *yymsg = yymsgbuf; - YYSIZE_T yymsg_alloc = sizeof yymsgbuf; + YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf; #endif #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)]b4_locations_if([, yylsp -= (N)])[) @@ -1418,7 +1461,7 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[ yystacksize = YYINITDEPTH;]b4_lac_if([[ yyes = yyesa; - yyes_capacity = sizeof yyesa / sizeof *yyes; + yyes_capacity = ]b4_percent_define_get([[parse.lac.es-capacity-initial]])[; if (YYMAXDEPTH < yyes_capacity) yyes_capacity = YYMAXDEPTH;]])[ @@ -1450,10 +1493,14 @@ b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yyllo /*--------------------------------------------------------------------. -| yynewstate -- set current state (the top of the stack) to yystate. | +| yysetstate -- set current state (the top of the stack) to yystate. | `--------------------------------------------------------------------*/ yysetstate: - *yyssp = (yytype_int16) yystate; + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YY_ASSERT (0 <= yystate && yystate < YYNSTATES); + YY_IGNORE_USELESS_CAST_BEGIN + *yyssp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END if (yyss + yystacksize - 1 <= yyssp) #if !defined yyoverflow && !defined YYSTACK_RELOCATE @@ -1461,15 +1508,15 @@ b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yyllo #else { /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = (YYSIZE_T) (yyssp - yyss + 1); + YYPTRDIFF_T yysize = yyssp - yyss + 1; # if defined yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss;]b4_locations_if([ + yy_state_t *yyss1 = yyss; + YYSTYPE *yyvs1 = yyvs;]b4_locations_if([ YYLTYPE *yyls1 = yyls;])[ /* Each stack pointer address is followed by the size of the @@ -1477,9 +1524,9 @@ b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yyllo conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp),]b4_locations_if([ - &yyls1, yysize * sizeof (*yylsp),])[ + &yyss1, yysize * YYSIZEOF (*yyssp), + &yyvs1, yysize * YYSIZEOF (*yyvsp),]b4_locations_if([ + &yyls1, yysize * YYSIZEOF (*yylsp),])[ &yystacksize); yyss = yyss1; yyvs = yyvs1;]b4_locations_if([ @@ -1494,9 +1541,10 @@ b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yyllo yystacksize = YYMAXDEPTH; { - yytype_int16 *yyss1 = yyss; + yy_state_t *yyss1 = yyss; union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + YY_CAST (union yyalloc *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); if (! yyptr) goto yyexhaustedlab; YYSTACK_RELOCATE (yyss_alloc, yyss); @@ -1512,16 +1560,16 @@ b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yyllo yyvsp = yyvs + yysize - 1;]b4_locations_if([ yylsp = yyls + yysize - 1;])[ - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long) yystacksize)); + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "Stack size increased to %ld\n", + YY_CAST (long, yystacksize))); + YY_IGNORE_USELESS_CAST_END if (yyss + yystacksize - 1 <= yyssp) YYABORT; } #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); - if (yystate == YYFINAL) YYACCEPT; @@ -1605,16 +1653,15 @@ yyread_pushed_token:]])[ /* Shift the lookahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END]b4_locations_if([ + *++yylsp = yylloc;])[ /* Discard the shifted token. */ yychar = YYEMPTY;]b4_lac_if([[ YY_LAC_DISCARD ("shift");]])[ - - yystate = yyn; - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - *++yyvsp = yylval; - YY_IGNORE_MAYBE_UNINITIALIZED_END -]b4_locations_if([ *++yylsp = yylloc;])[ goto yynewstate; @@ -1662,7 +1709,7 @@ yyread_pushed_token:]])[ }]], [[ switch (yyn) { - ]b4_user_actions[ +]b4_user_actions[ default: break; }]])[ /* User semantic actions sometimes alter yychar, and that requires @@ -1729,7 +1776,7 @@ yyread_pushed_token:]])[ { if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + yymsg = YY_CAST (char *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc))); if (!yymsg) { yymsg = yymsgbuf; @@ -1893,7 +1940,7 @@ yyread_pushed_token:]])[ while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp]b4_locations_if([, yylsp])[]b4_user_args[); + yystos[+*yyssp], yyvsp]b4_locations_if([, yylsp])[]b4_user_args[); YYPOPSTACK (1); } #ifndef yyoverflow @@ -1917,11 +1964,3 @@ yypushreturn:]])[ } ]b4_epilogue[]dnl b4_output_end - -b4_defines_if([[ -]b4_output_begin([b4_spec_defines_file])[ -]b4_copyright([Bison interface for Yacc-like parsers in C])[ -]b4_disclaimer[ -]b4_shared_declarations[ -]b4_output_end[ -]])# b4_defines_if diff --git a/contrib/tools/bison/lib/allocator.h b/contrib/tools/bison/lib/allocator.h index 5a632ba6ff35..2b032383de25 100644 --- a/contrib/tools/bison/lib/allocator.h +++ b/contrib/tools/bison/lib/allocator.h @@ -1,6 +1,6 @@ /* Memory allocators such as malloc+free. - Copyright (C) 2011-2019 Free Software Foundation, Inc. + Copyright (C) 2011-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/areadlink.c b/contrib/tools/bison/lib/areadlink.c index 059435624db5..a72ddf8d650e 100644 --- a/contrib/tools/bison/lib/areadlink.c +++ b/contrib/tools/bison/lib/areadlink.c @@ -1,7 +1,7 @@ /* areadlink.c -- readlink wrapper to return the link name in malloc'd storage Unlike xreadlink and xreadlink_with_size, don't ever call exit. - Copyright (C) 2001, 2003-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2003-2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/areadlink.h b/contrib/tools/bison/lib/areadlink.h index ddcd06d7d7af..f68efe5e3b3d 100644 --- a/contrib/tools/bison/lib/areadlink.h +++ b/contrib/tools/bison/lib/areadlink.h @@ -1,6 +1,6 @@ /* Read symbolic links without size limitation. - Copyright (C) 2001, 2003-2004, 2007, 2009-2019 Free Software Foundation, + Copyright (C) 2001, 2003-2004, 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/arg-nonnull.h b/contrib/tools/bison/lib/arg-nonnull.h index ad8c26c225e7..ac26ca8cfedd 100644 --- a/contrib/tools/bison/lib/arg-nonnull.h +++ b/contrib/tools/bison/lib/arg-nonnull.h @@ -1,5 +1,5 @@ /* A C macro for declaring that specific arguments must not be NULL. - Copyright (C) 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published diff --git a/contrib/tools/bison/lib/argmatch.c b/contrib/tools/bison/lib/argmatch.c index b9a3e400c41d..195f90252bce 100644 --- a/contrib/tools/bison/lib/argmatch.c +++ b/contrib/tools/bison/lib/argmatch.c @@ -1,6 +1,6 @@ /* argmatch.c -- find a match for a string in an array - Copyright (C) 1990, 1998-1999, 2001-2007, 2009-2019 Free Software + Copyright (C) 1990, 1998-1999, 2001-2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -29,12 +29,10 @@ #include #include -#include "gettext.h" #define _(msgid) gettext (msgid) #include "error.h" #include "quotearg.h" -#include "quote.h" #include "getprogname.h" #if USE_UNLOCKED_IO @@ -82,7 +80,7 @@ argmatch_exit_fn argmatch_die = __argmatch_die; ptrdiff_t argmatch (const char *arg, const char *const *arglist, - const char *vallist, size_t valsize) + const void *vallist, size_t valsize) { size_t i; /* Temporary index in ARGLIST. */ size_t arglen; /* Length of ARG. */ @@ -106,8 +104,8 @@ argmatch (const char *arg, const char *const *arglist, { /* Second nonexact match found. */ if (vallist == NULL - || memcmp (vallist + valsize * matchind, - vallist + valsize * i, valsize)) + || memcmp ((char const *) vallist + valsize * matchind, + (char const *) vallist + valsize * i, valsize)) { /* There is a real ambiguity, or we could not disambiguate. */ @@ -144,7 +142,7 @@ argmatch_invalid (const char *context, const char *value, ptrdiff_t problem) VALSIZE is the size of the elements of VALLIST */ void argmatch_valid (const char *const *arglist, - const char *vallist, size_t valsize) + const void *vallist, size_t valsize) { size_t i; const char *last_val = NULL; @@ -154,10 +152,10 @@ argmatch_valid (const char *const *arglist, fputs (_("Valid arguments are:"), stderr); for (i = 0; arglist[i]; i++) if ((i == 0) - || memcmp (last_val, vallist + valsize * i, valsize)) + || memcmp (last_val, (char const *) vallist + valsize * i, valsize)) { fprintf (stderr, "\n - %s", quote (arglist[i])); - last_val = vallist + valsize * i; + last_val = (char const *) vallist + valsize * i; } else { @@ -175,7 +173,7 @@ argmatch_valid (const char *const *arglist, ptrdiff_t __xargmatch_internal (const char *context, const char *arg, const char *const *arglist, - const char *vallist, size_t valsize, + const void *vallist, size_t valsize, argmatch_exit_fn exit_fn) { ptrdiff_t res = argmatch (arg, arglist, vallist, valsize); @@ -194,14 +192,14 @@ __xargmatch_internal (const char *context, /* Look for VALUE in VALLIST, an array of objects of size VALSIZE and return the first corresponding argument in ARGLIST */ const char * -argmatch_to_argument (const char *value, +argmatch_to_argument (const void *value, const char *const *arglist, - const char *vallist, size_t valsize) + const void *vallist, size_t valsize) { size_t i; for (i = 0; arglist[i]; i++) - if (!memcmp (value, vallist + valsize * i, valsize)) + if (!memcmp (value, (char const *) vallist + valsize * i, valsize)) return arglist[i]; return NULL; } diff --git a/contrib/tools/bison/lib/argmatch.h b/contrib/tools/bison/lib/argmatch.h index 51d2885879d8..daa0fdbf3ab0 100644 --- a/contrib/tools/bison/lib/argmatch.h +++ b/contrib/tools/bison/lib/argmatch.h @@ -1,6 +1,6 @@ /* argmatch.h -- definitions and prototypes for argmatch.c - Copyright (C) 1990, 1998-1999, 2001-2002, 2004-2005, 2009-2019 Free Software + Copyright (C) 1990, 1998-1999, 2001-2002, 2004-2005, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -22,13 +22,19 @@ #ifndef ARGMATCH_H_ # define ARGMATCH_H_ 1 +# include +# include # include +# include +# include /* memcmp */ +# include "gettext.h" +# include "quote.h" # include "verify.h" -#ifdef __cplusplus +# ifdef __cplusplus extern "C" { -#endif +# endif # define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array)) @@ -44,10 +50,10 @@ extern "C" { to the same values in VALLIST). */ ptrdiff_t argmatch (char const *arg, char const *const *arglist, - char const *vallist, size_t valsize) _GL_ATTRIBUTE_PURE; + void const *vallist, size_t valsize) _GL_ATTRIBUTE_PURE; # define ARGMATCH(Arg, Arglist, Vallist) \ - argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist)) + argmatch (Arg, Arglist, (void const *) (Vallist), sizeof *(Vallist)) /* xargmatch calls this function when it fails. This function should not return. By default, this is a function that calls ARGMATCH_DIE which @@ -70,10 +76,10 @@ void argmatch_invalid (char const *context, char const *value, /* Report on stderr the list of possible arguments. */ void argmatch_valid (char const *const *arglist, - char const *vallist, size_t valsize); + void const *vallist, size_t valsize); # define ARGMATCH_VALID(Arglist, Vallist) \ - argmatch_valid (Arglist, (char const *) (Vallist), sizeof *(Vallist)) + argmatch_valid (Arglist, (void const *) (Vallist), sizeof *(Vallist)) @@ -82,30 +88,244 @@ void argmatch_valid (char const *const *arglist, ptrdiff_t __xargmatch_internal (char const *context, char const *arg, char const *const *arglist, - char const *vallist, size_t valsize, + void const *vallist, size_t valsize, argmatch_exit_fn exit_fn); /* Programmer friendly interface to __xargmatch_internal. */ # define XARGMATCH(Context, Arg, Arglist, Vallist) \ ((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \ - (char const *) (Vallist), \ + (void const *) (Vallist), \ sizeof *(Vallist), \ argmatch_die)]) /* Convert a value into a corresponding argument. */ -char const *argmatch_to_argument (char const *value, +char const *argmatch_to_argument (void const *value, char const *const *arglist, - char const *vallist, size_t valsize) + void const *vallist, size_t valsize) _GL_ATTRIBUTE_PURE; # define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \ argmatch_to_argument (Value, Arglist, \ - (char const *) (Vallist), sizeof *(Vallist)) - -#ifdef __cplusplus + (void const *) (Vallist), sizeof *(Vallist)) + +# define ARGMATCH_DEFINE_GROUP(Name, Type) \ + /* The type of the values of this group. */ \ + typedef Type argmatch_##Name##_type; \ + \ + /* The size of the type of the values of this group. */ \ + enum argmatch_##Name##_size_enum \ + { \ + argmatch_##Name##_size = sizeof (argmatch_##Name##_type) \ + }; \ + \ + /* Argument mapping of this group. */ \ + typedef struct \ + { \ + /* Argument (e.g., "simple"). */ \ + const char *arg; \ + /* Value (e.g., simple_backups). */ \ + const argmatch_##Name##_type val; \ + } argmatch_##Name##_arg; \ + \ + /* Documentation of this group. */ \ + typedef struct \ + { \ + /* Argument (e.g., "simple"). */ \ + const char *arg; \ + /* Documentation (e.g., N_("always make simple backups")). */ \ + const char *doc; \ + } argmatch_##Name##_doc; \ + \ + /* All the features of an argmatch group. */ \ + typedef struct \ + { \ + const argmatch_##Name##_arg* args; \ + const argmatch_##Name##_doc* docs; \ + \ + /* Printed before the usage message. */ \ + const char *doc_pre; \ + /* Printed after the usage message. */ \ + const char *doc_post; \ + } argmatch_##Name##_group_type; \ + \ + /* The structure the user must build. */ \ + extern const argmatch_##Name##_group_type argmatch_##Name##_group; \ + \ + /* Print the documentation of this group. */ \ + void argmatch_##Name##_usage (FILE *out); \ + \ + /* If nonnegative, the index I of ARG in ARGS, i.e, \ + ARGS[I] == ARG. \ + Return -1 for invalid argument, -2 for ambiguous argument. */ \ + ptrdiff_t argmatch_##Name##_choice (const char *arg); \ + \ + /* A pointer to the corresponding value if it exists, or \ + report an error and exit with failure if the argument was \ + not recognized. */ \ + const argmatch_##Name##_type* \ + argmatch_##Name##_value (const char *context, const char *arg); \ + \ + /* The first argument in ARGS that matches this value, or NULL. */ \ + const char * \ + argmatch_##Name##_argument (const argmatch_##Name##_type *val); \ + \ + ptrdiff_t \ + argmatch_##Name##_choice (const char *arg) \ + { \ + const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \ + size_t size = argmatch_##Name##_size; \ + ptrdiff_t res = -1; /* Index of first nonexact match. */ \ + bool ambiguous = false; /* Whether multiple nonexact match(es). */ \ + size_t arglen = strlen (arg); \ + \ + /* Test all elements for either exact match or abbreviated \ + matches. */ \ + for (size_t i = 0; g->args[i].arg; i++) \ + if (!strncmp (g->args[i].arg, arg, arglen)) \ + { \ + if (strlen (g->args[i].arg) == arglen) \ + /* Exact match found. */ \ + return i; \ + else if (res == -1) \ + /* First nonexact match found. */ \ + res = i; \ + else if (memcmp (&g->args[res].val, &g->args[i].val, size)) \ + /* Second nonexact match found. */ \ + /* There is a real ambiguity, or we could not \ + disambiguate. */ \ + ambiguous = true; \ + } \ + return ambiguous ? -2 : res; \ + } \ + \ + const char * \ + argmatch_##Name##_argument (const argmatch_##Name##_type *val) \ + { \ + const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \ + size_t size = argmatch_##Name##_size; \ + for (size_t i = 0; g->args[i].arg; i++) \ + if (!memcmp (val, &g->args[i].val, size)) \ + return g->args[i].arg; \ + return NULL; \ + } \ + \ + /* List the valid values of this group. */ \ + static void \ + argmatch_##Name##_valid (FILE *out) \ + { \ + const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \ + size_t size = argmatch_##Name##_size; \ + \ + /* Try to put synonyms on the same line. Synonyms are expected \ + to follow each other. */ \ + fputs (gettext ("Valid arguments are:"), out); \ + for (int i = 0; g->args[i].arg; i++) \ + if (i == 0 \ + || memcmp (&g->args[i-1].val, &g->args[i].val, size)) \ + fprintf (out, "\n - %s", quote (g->args[i].arg)); \ + else \ + fprintf (out, ", %s", quote (g->args[i].arg)); \ + putc ('\n', out); \ + } \ + \ + const argmatch_##Name##_type* \ + argmatch_##Name##_value (const char *context, const char *arg) \ + { \ + const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \ + ptrdiff_t res = argmatch_##Name##_choice (arg); \ + if (res < 0) \ + { \ + argmatch_invalid (context, arg, res); \ + argmatch_##Name##_valid (stderr); \ + argmatch_die (); \ + } \ + return &g->args[res].val; \ + } \ + \ + /* The column in which the documentation is displayed. \ + The leftmost possible, but no more than 20. */ \ + static int \ + argmatch_##Name##_doc_col (void) \ + { \ + const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \ + size_t size = argmatch_##Name##_size; \ + int res = 0; \ + for (int i = 0; g->docs[i].arg; ++i) \ + { \ + int col = 4; \ + int ival = argmatch_##Name##_choice (g->docs[i].arg); \ + if (ival < 0) \ + /* Pseudo argument, display it. */ \ + col += strlen (g->docs[i].arg); \ + else \ + /* Genuine argument, display it with its synonyms. */ \ + for (int j = 0; g->args[j].arg; ++j) \ + if (! memcmp (&g->args[ival].val, &g->args[j].val, size)) \ + col += (col == 4 ? 0 : 2) + strlen (g->args[j].arg); \ + if (res <= col) \ + res = col <= 20 ? col : 20; \ + } \ + return res ? res : 20; \ + } \ + \ + void \ + argmatch_##Name##_usage (FILE *out) \ + { \ + const argmatch_##Name##_group_type *g = &argmatch_##Name##_group; \ + size_t size = argmatch_##Name##_size; \ + /* Width of the screen. Help2man does not seem to support \ + arguments on several lines, so in that case pretend a very \ + large width. */ \ + const int screen_width = getenv ("HELP2MAN") ? INT_MAX : 80; \ + if (g->doc_pre) \ + fprintf (out, "%s\n", gettext (g->doc_pre)); \ + int doc_col = argmatch_##Name##_doc_col (); \ + for (int i = 0; g->docs[i].arg; ++i) \ + { \ + int col = 0; \ + bool first = true; \ + int ival = argmatch_##Name##_choice (g->docs[i].arg); \ + if (ival < 0) \ + /* Pseudo argument, display it. */ \ + col += fprintf (out, " %s", g->docs[i].arg); \ + else \ + /* Genuine argument, display it with its synonyms. */ \ + for (int j = 0; g->args[j].arg; ++j) \ + if (! memcmp (&g->args[ival].val, &g->args[j].val, size)) \ + { \ + if (!first \ + && screen_width < col + 2 + strlen (g->args[j].arg)) \ + { \ + fprintf (out, ",\n"); \ + col = 0; \ + first = true; \ + } \ + if (first) \ + { \ + col += fprintf (out, " "); \ + first = false; \ + } \ + else \ + col += fprintf (out, ","); \ + col += fprintf (out, " %s", g->args[j].arg); \ + } \ + /* The doc. Separated by at least two spaces. */ \ + if (doc_col < col + 2) \ + { \ + fprintf (out, "\n"); \ + col = 0; \ + } \ + fprintf (out, "%*s%s\n", \ + doc_col - col, "", gettext (g->docs[i].doc)); \ + } \ + if (g->doc_post) \ + fprintf (out, "%s\n", gettext (g->doc_post)); \ + } + +# ifdef __cplusplus } -#endif +# endif #endif /* ARGMATCH_H_ */ diff --git a/contrib/tools/bison/lib/asnprintf.c b/contrib/tools/bison/lib/asnprintf.c index d2a8c0972052..37dcf925eccf 100644 --- a/contrib/tools/bison/lib/asnprintf.c +++ b/contrib/tools/bison/lib/asnprintf.c @@ -1,5 +1,5 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/asprintf.c b/contrib/tools/bison/lib/asprintf.c new file mode 100644 index 000000000000..f97580f74543 --- /dev/null +++ b/contrib/tools/bison/lib/asprintf.c @@ -0,0 +1,39 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2007, 2009-2020 Free Software Foundation, + Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +#include + +/* Specification. */ +#ifdef IN_LIBASPRINTF +# include "vasprintf.h" +#else +# include +#endif + +#include + +int +asprintf (char **resultp, const char *format, ...) +{ + va_list args; + int result; + + va_start (args, format); + result = vasprintf (resultp, format, args); + va_end (args); + return result; +} diff --git a/contrib/tools/bison/lib/assure.h b/contrib/tools/bison/lib/assure.h new file mode 100644 index 000000000000..8ea2f6e480b6 --- /dev/null +++ b/contrib/tools/bison/lib/assure.h @@ -0,0 +1,37 @@ +/* Run-time assert-like macros. + + Copyright (C) 2014-2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Paul Eggert. */ + +#ifndef _GL_ASSURE_H +#define _GL_ASSURE_H + +#include + +/* Check E's value at runtime, and report an error and abort if not. + However, do nothing if NDEBUG is defined. + + Unlike standard 'assert', this macro always compiles E even when NDEBUG + is defined, so as to catch typos and avoid some GCC warnings. */ + +#ifdef NDEBUG +# define assure(E) ((void) (0 && (E))) +#else +# define assure(E) assert (E) +#endif + +#endif diff --git a/contrib/tools/bison/lib/basename-lgpl.c b/contrib/tools/bison/lib/basename-lgpl.c index 0ae04ee5722b..565469ea3d10 100644 --- a/contrib/tools/bison/lib/basename-lgpl.c +++ b/contrib/tools/bison/lib/basename-lgpl.c @@ -1,6 +1,6 @@ /* basename.c -- return the last element in a file name - Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2019 Free Software + Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/basename.c b/contrib/tools/bison/lib/basename.c index 1b6e0ea59bd7..b14417f48d70 100644 --- a/contrib/tools/bison/lib/basename.c +++ b/contrib/tools/bison/lib/basename.c @@ -1,6 +1,6 @@ /* basename.c -- return the last element in a file name - Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2019 Free Software + Copyright (C) 1990, 1998-2001, 2003-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/binary-io.c b/contrib/tools/bison/lib/binary-io.c index 01e0bf64765d..e84e223fc88e 100644 --- a/contrib/tools/bison/lib/binary-io.c +++ b/contrib/tools/bison/lib/binary-io.c @@ -1,5 +1,5 @@ /* Binary mode I/O. - Copyright 2017-2019 Free Software Foundation, Inc. + Copyright 2017-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,18 +20,20 @@ #include "binary-io.h" #if defined __DJGPP__ || defined __EMX__ -# include # include int -__gl_setmode_check (int fd) +set_binary_mode (int fd, int mode) { if (isatty (fd)) - { - errno = EINVAL; - return -1; - } + /* If FD refers to a console (not a pipe, not a regular file), + O_TEXT is the only reasonable mode, both on input and on output. + Silently ignore the request. If we were to return -1 here, + all programs that use xset_binary_mode would fail when run + with console input or console output. */ + return O_TEXT; else - return 0; + return __gl_setmode (fd, mode); } + #endif diff --git a/contrib/tools/bison/lib/binary-io.h b/contrib/tools/bison/lib/binary-io.h index 100ac3011c19..05f7986b5f9c 100644 --- a/contrib/tools/bison/lib/binary-io.h +++ b/contrib/tools/bison/lib/binary-io.h @@ -1,5 +1,5 @@ /* Binary mode I/O. - Copyright (C) 2001, 2003, 2005, 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2003, 2005, 2008-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -61,25 +61,21 @@ __gl_setmode (int fd _GL_UNUSED, int mode _GL_UNUSED) } #endif -#if defined __DJGPP__ || defined __EMX__ -extern int __gl_setmode_check (int); -#else -BINARY_IO_INLINE int -__gl_setmode_check (int fd _GL_UNUSED) { return 0; } -#endif - /* Set FD's mode to MODE, which should be either O_TEXT or O_BINARY. Return the old mode if successful, -1 (setting errno) on failure. Ordinarily this function would be called 'setmode', since that is its name on MS-Windows, but it is called 'set_binary_mode' here to avoid colliding with a BSD function of another name. */ +#if defined __DJGPP__ || defined __EMX__ +extern int set_binary_mode (int fd, int mode); +#else BINARY_IO_INLINE int set_binary_mode (int fd, int mode) { - int r = __gl_setmode_check (fd); - return r != 0 ? r : __gl_setmode (fd, mode); + return __gl_setmode (fd, mode); } +#endif /* This macro is obsolescent. */ #define SET_BINARY(fd) ((void) set_binary_mode (fd, O_BINARY)) diff --git a/contrib/tools/bison/lib/bitrotate.h b/contrib/tools/bison/lib/bitrotate.h index 862331e204b2..59827e2742b0 100644 --- a/contrib/tools/bison/lib/bitrotate.h +++ b/contrib/tools/bison/lib/bitrotate.h @@ -1,5 +1,5 @@ /* bitrotate.h - Rotate bits in integers - Copyright (C) 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2008-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -95,7 +95,8 @@ rotr_sz (size_t x, int n) BITROTATE_INLINE uint16_t rotl16 (uint16_t x, int n) { - return ((x << n) | (x >> (16 - n))) & UINT16_MAX; + return (((unsigned int) x << n) | ((unsigned int) x >> (16 - n))) + & UINT16_MAX; } /* Given an unsigned 16-bit argument X, return the value corresponding @@ -106,7 +107,8 @@ rotl16 (uint16_t x, int n) BITROTATE_INLINE uint16_t rotr16 (uint16_t x, int n) { - return ((x >> n) | (x << (16 - n))) & UINT16_MAX; + return (((unsigned int) x >> n) | ((unsigned int) x << (16 - n))) + & UINT16_MAX; } /* Given an unsigned 8-bit argument X, return the value corresponding @@ -117,7 +119,7 @@ rotr16 (uint16_t x, int n) BITROTATE_INLINE uint8_t rotl8 (uint8_t x, int n) { - return ((x << n) | (x >> (8 - n))) & UINT8_MAX; + return (((unsigned int) x << n) | ((unsigned int) x >> (8 - n))) & UINT8_MAX; } /* Given an unsigned 8-bit argument X, return the value corresponding @@ -128,7 +130,7 @@ rotl8 (uint8_t x, int n) BITROTATE_INLINE uint8_t rotr8 (uint8_t x, int n) { - return ((x >> n) | (x << (8 - n))) & UINT8_MAX; + return (((unsigned int) x >> n) | ((unsigned int) x << (8 - n))) & UINT8_MAX; } _GL_INLINE_HEADER_END diff --git a/contrib/tools/bison/lib/bitset.c b/contrib/tools/bison/lib/bitset.c index cccb1e83476a..c0fc13fd521f 100644 --- a/contrib/tools/bison/lib/bitset.c +++ b/contrib/tools/bison/lib/bitset.c @@ -1,6 +1,6 @@ /* General bitsets. - Copyright (C) 2002-2006, 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -15,7 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #include @@ -129,7 +129,7 @@ bitset_alloc (bitset_bindex n_bits, enum bitset_type type) { size_t bytes = bitset_bytes (type, n_bits); - bitset bset = xcalloc (1, bytes); + bitset bset = xzalloc (bytes); /* The cache is disabled until some elements are allocated. If we have variable length arrays, then we may need to allocate a dummy @@ -168,8 +168,11 @@ bitset_create (bitset_bindex n_bits, unsigned attr) void bitset_free (bitset bset) { - BITSET_FREE_ (bset); - free (bset); + if (bset) + { + BITSET_FREE_ (bset); + free (bset); + } } @@ -177,7 +180,8 @@ bitset_free (bitset bset) void bitset_obstack_free (bitset bset) { - BITSET_FREE_ (bset); + if (bset) + BITSET_FREE_ (bset); } diff --git a/contrib/tools/bison/lib/bitset.h b/contrib/tools/bison/lib/bitset.h index 32d08e7aa97a..a13b8d4d1687 100644 --- a/contrib/tools/bison/lib/bitset.h +++ b/contrib/tools/bison/lib/bitset.h @@ -1,6 +1,6 @@ /* Generic bitsets. - Copyright (C) 2002-2004, 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -15,7 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #ifndef _GL_BITSET_H #define _GL_BITSET_H @@ -109,7 +109,7 @@ enum bitset_type bitset_type_choose (bitset_bindex, bitset_attrs); /* Create a bitset of desired type and size. The bitset is zeroed. */ bitset bitset_alloc (bitset_bindex, enum bitset_type); -/* Free bitset. */ +/* Free bitset. Do nothing if NULL. */ void bitset_free (bitset); /* Create a bitset of desired type and size using an obstack. The @@ -117,7 +117,7 @@ void bitset_free (bitset); bitset bitset_obstack_alloc (struct obstack *bobstack, bitset_bindex, enum bitset_type); -/* Free bitset allocated on obstack. */ +/* Free bitset allocated on obstack. Do nothing if NULL. */ void bitset_obstack_free (bitset); /* Create a bitset of desired size and attributes. The bitset is zeroed. */ @@ -178,8 +178,9 @@ bitset_test (bitset bset, bitset_bindex bitno) /* Return size in bits of bitset SRC. */ #define bitset_size(SRC) BITSET_SIZE_ (SRC) -/* Change size of bitset. */ -void bitset_resize (bitset, bitset_bindex); +/* Change size in bits of bitset. New bits are zeroed. Return + SIZE. */ +#define bitset_resize(DST, SIZE) BITSET_RESIZE_ (DST, SIZE) /* Return number of bits set in bitset SRC. */ #define bitset_count(SRC) BITSET_COUNT_ (SRC) diff --git a/contrib/tools/bison/lib/bitset/array.c b/contrib/tools/bison/lib/bitset/array.c index fde9fa24f562..e611f38bcfe8 100644 --- a/contrib/tools/bison/lib/bitset/array.c +++ b/contrib/tools/bison/lib/bitset/array.c @@ -1,6 +1,6 @@ /* Array bitsets. - Copyright (C) 2002-2003, 2006, 2009-2015, 2018-2019 Free Software + Copyright (C) 2002-2003, 2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #include diff --git a/contrib/tools/bison/lib/bitset/array.h b/contrib/tools/bison/lib/bitset/array.h index 6f49a2e04741..0ec6a46129af 100644 --- a/contrib/tools/bison/lib/bitset/array.h +++ b/contrib/tools/bison/lib/bitset/array.h @@ -1,6 +1,6 @@ /* Functions to support abitsets. - Copyright (C) 2002, 2004, 2009-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #ifndef _BITSET_ARRAY_H #define _BITSET_ARRAY_H diff --git a/contrib/tools/bison/lib/bitset/base.h b/contrib/tools/bison/lib/bitset/base.h index 4fcafac8b67d..46ec894eceb1 100644 --- a/contrib/tools/bison/lib/bitset/base.h +++ b/contrib/tools/bison/lib/bitset/base.h @@ -1,6 +1,6 @@ /* Base bitset stuff. - Copyright (C) 2002-2004, 2006, 2009-2015, 2018-2019 Free Software + Copyright (C) 2002-2004, 2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #ifndef _BITSET_BASE_H #define _BITSET_BASE_H @@ -55,8 +55,6 @@ enum bitset_type {BITSET_ARRAY, BITSET_LIST, BITSET_TABLE, BITSET_VECTOR, extern const char * const bitset_type_names[]; -enum bitset_alloc_type {BITSET_MALLOC, BITSET_OBALLOC}; - /* Data type used to store a word of bits. */ typedef unsigned long bitset_word; #define BITSET_WORD_BITS ((unsigned) (CHAR_BIT * sizeof (bitset_word))) diff --git a/contrib/tools/bison/lib/bitset/list.c b/contrib/tools/bison/lib/bitset/list.c index f42edb8ea3ec..f45367182714 100644 --- a/contrib/tools/bison/lib/bitset/list.c +++ b/contrib/tools/bison/lib/bitset/list.c @@ -1,6 +1,6 @@ /* Functions to support link list bitsets. - Copyright (C) 2002-2004, 2006, 2009-2015, 2018-2019 Free Software + Copyright (C) 2002-2004, 2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #include @@ -859,7 +859,8 @@ lbitset_unused_clear (bitset dst) bitset_word *srcp = elt->words; bitset_windex windex = n_bits / BITSET_WORD_BITS; - srcp[windex - elt->index] &= ((bitset_word) 1 << last_bit) - 1; + srcp[windex - elt->index] + &= ((bitset_word) 1 << (last_bit % BITSET_WORD_BITS)) - 1; windex++; for (; (windex - elt->index) < LBITSET_ELT_WORDS; windex++) diff --git a/contrib/tools/bison/lib/bitset/list.h b/contrib/tools/bison/lib/bitset/list.h index a0fc09f8c6de..8b24f2593f15 100644 --- a/contrib/tools/bison/lib/bitset/list.h +++ b/contrib/tools/bison/lib/bitset/list.h @@ -1,6 +1,6 @@ /* Functions to support lbitsets. - Copyright (C) 2002, 2004, 2009-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #ifndef _BITSET_LIST_H #define _BITSET_LIST_H diff --git a/contrib/tools/bison/lib/bitset/stats.c b/contrib/tools/bison/lib/bitset/stats.c index da73cdcac522..222cde09051b 100644 --- a/contrib/tools/bison/lib/bitset/stats.c +++ b/contrib/tools/bison/lib/bitset/stats.c @@ -1,6 +1,6 @@ /* Bitset statistics. - Copyright (C) 2002-2006, 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -15,7 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ /* This file is a wrapper bitset implementation for the other bitset implementations. It provides bitset compatibility checking and @@ -694,7 +694,7 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) case BITSET_ARRAY: { size_t bytes = abitset_bytes (n_bits); - bset->s.bset = xcalloc (1, bytes); + bset->s.bset = xzalloc (bytes); abitset_init (bset->s.bset, n_bits); } break; @@ -702,7 +702,7 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) case BITSET_LIST: { size_t bytes = lbitset_bytes (n_bits); - bset->s.bset = xcalloc (1, bytes); + bset->s.bset = xzalloc (bytes); lbitset_init (bset->s.bset, n_bits); } break; @@ -710,7 +710,7 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) case BITSET_TABLE: { size_t bytes = tbitset_bytes (n_bits); - bset->s.bset = xcalloc (1, bytes); + bset->s.bset = xzalloc (bytes); tbitset_init (bset->s.bset, n_bits); } break; @@ -718,7 +718,7 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type) case BITSET_VECTOR: { size_t bytes = vbitset_bytes (n_bits); - bset->s.bset = xcalloc (1, bytes); + bset->s.bset = xzalloc (bytes); vbitset_init (bset->s.bset, n_bits); } break; diff --git a/contrib/tools/bison/lib/bitset/stats.h b/contrib/tools/bison/lib/bitset/stats.h index 95e64dc4e51b..0bfed3e21b80 100644 --- a/contrib/tools/bison/lib/bitset/stats.h +++ b/contrib/tools/bison/lib/bitset/stats.h @@ -1,6 +1,6 @@ /* Functions to support bitset statistics. - Copyright (C) 2002-2004, 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -15,7 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #ifndef _BITSET_STATS_H #define _BITSET_STATS_H diff --git a/contrib/tools/bison/lib/bitset/table.c b/contrib/tools/bison/lib/bitset/table.c index 8351cf784825..ab68e518d040 100644 --- a/contrib/tools/bison/lib/bitset/table.c +++ b/contrib/tools/bison/lib/bitset/table.c @@ -1,6 +1,6 @@ /* Functions to support expandable bitsets. - Copyright (C) 2002-2006, 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -15,7 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #include @@ -25,6 +25,7 @@ #include #include "obstack.h" +#include "xalloc.h" /* This file implements expandable bitsets. These bitsets can be of arbitrary length and are more efficient than arrays of bits for @@ -142,7 +143,7 @@ tbitset_resize (bitset src, bitset_bindex n_bits) bitset_windex size = oldsize == 0 ? newsize : newsize + newsize / 4; EBITSET_ELTS (src) - = realloc (EBITSET_ELTS (src), size * sizeof (tbitset_elt *)); + = xrealloc (EBITSET_ELTS (src), size * sizeof (tbitset_elt *)); EBITSET_ASIZE (src) = size; } @@ -155,9 +156,13 @@ tbitset_resize (bitset src, bitset_bindex n_bits) the memory unless it is shrinking by a reasonable amount. */ if ((oldsize - newsize) >= oldsize / 2) { - EBITSET_ELTS (src) + void *p = realloc (EBITSET_ELTS (src), newsize * sizeof (tbitset_elt *)); - EBITSET_ASIZE (src) = newsize; + if (p) + { + EBITSET_ELTS (src) = p; + EBITSET_ASIZE (src) = newsize; + } } /* Need to prune any excess bits. FIXME. */ @@ -188,21 +193,21 @@ tbitset_elt_alloc (void) /* Let particular systems override the size of a chunk. */ #ifndef OBSTACK_CHUNK_SIZE -#define OBSTACK_CHUNK_SIZE 0 +# define OBSTACK_CHUNK_SIZE 0 #endif /* Let them override the alloc and free routines too. */ #ifndef OBSTACK_CHUNK_ALLOC -#define OBSTACK_CHUNK_ALLOC xmalloc +# define OBSTACK_CHUNK_ALLOC xmalloc #endif #ifndef OBSTACK_CHUNK_FREE -#define OBSTACK_CHUNK_FREE free +# define OBSTACK_CHUNK_FREE free #endif #if ! defined __GNUC__ || __GNUC__ < 2 -#define __alignof__(type) 0 +# define __alignof__(type) 0 #endif obstack_specify_allocation (&tbitset_obstack, OBSTACK_CHUNK_SIZE, @@ -300,7 +305,7 @@ tbitset_elt_find (bitset bset, bitset_bindex bindex, abort (); case EBITSET_FIND: - return 0; + return NULL; case EBITSET_CREATE: if (eindex >= size) @@ -588,8 +593,8 @@ tbitset_list_reverse (bitset bset, bitset_bindex *list, /* Find list of up to NUM bits set in BSET starting from and including - *NEXT and store in array LIST. Return with actual number of bits - found and with *NEXT indicating where search stopped. */ + *NEXT and store in array LIST. Return with actual number of bits + found and with *NEXT indicating where search stopped. */ static bitset_bindex tbitset_list (bitset bset, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) @@ -607,17 +612,14 @@ tbitset_list (bitset bset, bitset_bindex *list, if (bitno % EBITSET_ELT_BITS) { /* We need to start within an element. This is not very common. */ - tbitset_elt *elt = elts[eindex]; if (elt) { - bitset_windex woffset; bitset_word *srcp = EBITSET_WORDS (elt); + bitset_windex woffset = eindex * EBITSET_ELT_WORDS; - bitset_windex windex = bitno / BITSET_WORD_BITS; - woffset = eindex * EBITSET_ELT_WORDS; - - for (; (windex - woffset) < EBITSET_ELT_WORDS; windex++) + for (bitset_windex windex = bitno / BITSET_WORD_BITS; + (windex - woffset) < EBITSET_ELT_WORDS; windex++) { bitset_word word = srcp[windex - woffset] >> (bitno % BITSET_WORD_BITS); @@ -781,7 +783,8 @@ tbitset_unused_clear (bitset dst) bitset_windex windex = n_bits / BITSET_WORD_BITS; bitset_windex woffset = eindex * EBITSET_ELT_WORDS; - srcp[windex - woffset] &= ((bitset_word) 1 << last_bit) - 1; + srcp[windex - woffset] + &= ((bitset_word) 1 << (last_bit % BITSET_WORD_BITS)) - 1; windex++; for (; (windex - woffset) < EBITSET_ELT_WORDS; windex++) srcp[windex - woffset] = 0; @@ -1020,13 +1023,9 @@ tbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op) } if (!tbitset_elt_zero_p (delt)) - { - tbitset_elt_add (dst, delt, j); - } + tbitset_elt_add (dst, delt, j); else - { - tbitset_elt_free (delt); - } + tbitset_elt_free (delt); } /* If we have elements of DST left over, free them all. */ @@ -1061,7 +1060,8 @@ tbitset_and_cmp (bitset dst, bitset src1, bitset src2) tbitset_zero (dst); return changed; } - return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_AND); + else + return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_AND); } @@ -1076,9 +1076,7 @@ static bool tbitset_andn_cmp (bitset dst, bitset src1, bitset src2) { if (EBITSET_ZERO_P (src2)) - { - return tbitset_copy_cmp (dst, src1); - } + return tbitset_copy_cmp (dst, src1); else if (EBITSET_ZERO_P (src1)) { tbitset_weed (dst); @@ -1086,7 +1084,8 @@ tbitset_andn_cmp (bitset dst, bitset src1, bitset src2) tbitset_zero (dst); return changed; } - return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN); + else + return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN); } @@ -1101,14 +1100,11 @@ static bool tbitset_or_cmp (bitset dst, bitset src1, bitset src2) { if (EBITSET_ZERO_P (src2)) - { - return tbitset_copy_cmp (dst, src1); - } + return tbitset_copy_cmp (dst, src1); else if (EBITSET_ZERO_P (src1)) - { - return tbitset_copy_cmp (dst, src2); - } - return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_OR); + return tbitset_copy_cmp (dst, src2); + else + return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_OR); } @@ -1123,14 +1119,11 @@ static bool tbitset_xor_cmp (bitset dst, bitset src1, bitset src2) { if (EBITSET_ZERO_P (src2)) - { - return tbitset_copy_cmp (dst, src1); - } + return tbitset_copy_cmp (dst, src1); else if (EBITSET_ZERO_P (src1)) - { - return tbitset_copy_cmp (dst, src2); - } - return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR); + return tbitset_copy_cmp (dst, src2); + else + return tbitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR); } diff --git a/contrib/tools/bison/lib/bitset/table.h b/contrib/tools/bison/lib/bitset/table.h index 6c781adde357..cf8555b9ce99 100644 --- a/contrib/tools/bison/lib/bitset/table.h +++ b/contrib/tools/bison/lib/bitset/table.h @@ -1,6 +1,6 @@ /* Functions to support tbitsets. - Copyright (C) 2002, 2004, 2009-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #ifndef _BITSET_TABLE_H #define _BITSET_TABLE_H diff --git a/contrib/tools/bison/lib/bitset/vector.c b/contrib/tools/bison/lib/bitset/vector.c index 15d3e9956775..cb60ba4a3a85 100644 --- a/contrib/tools/bison/lib/bitset/vector.c +++ b/contrib/tools/bison/lib/bitset/vector.c @@ -1,6 +1,6 @@ /* Variable array bitsets. - Copyright (C) 2002-2006, 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -15,7 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #include @@ -24,6 +24,8 @@ #include #include +#include "xalloc.h" + /* This file implements variable size bitsets stored as a variable length array of words. Any unused bits in the last word must be zero. @@ -74,13 +76,12 @@ vbitset_resize (bitset src, bitset_bindex n_bits) bitset_windex size = oldsize == 0 ? newsize : newsize + newsize / 4; VBITSET_WORDS (src) - = realloc (VBITSET_WORDS (src), size * sizeof (bitset_word)); + = xrealloc (VBITSET_WORDS (src), size * sizeof (bitset_word)); VBITSET_ASIZE (src) = size; } memset (VBITSET_WORDS (src) + oldsize, 0, (newsize - oldsize) * sizeof (bitset_word)); - VBITSET_SIZE (src) = newsize; } else { @@ -88,16 +89,19 @@ vbitset_resize (bitset src, bitset_bindex n_bits) the memory unless it is shrinking by a reasonable amount. */ if ((oldsize - newsize) >= oldsize / 2) { - VBITSET_WORDS (src) + void *p = realloc (VBITSET_WORDS (src), newsize * sizeof (bitset_word)); - VBITSET_ASIZE (src) = newsize; + if (p) + { + VBITSET_WORDS (src) = p; + VBITSET_ASIZE (src) = newsize; + } } /* Need to prune any excess bits. FIXME. */ - - VBITSET_SIZE (src) = newsize; } + VBITSET_SIZE (src) = newsize; BITSET_NBITS_ (src) = n_bits; return n_bits; } @@ -467,7 +471,6 @@ vbitset_and (bitset dst, bitset src1, bitset src2) static bool vbitset_and_cmp (bitset dst, bitset src1, bitset src2) { - bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); bitset_windex dsize = VBITSET_SIZE (dst); @@ -477,6 +480,7 @@ vbitset_and_cmp (bitset dst, bitset src1, bitset src2) bitset_word *src1p = VBITSET_WORDS (src1); bitset_word *src2p = VBITSET_WORDS (src2); + bool changed = false; unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { @@ -546,7 +550,6 @@ vbitset_andn (bitset dst, bitset src1, bitset src2) static bool vbitset_andn_cmp (bitset dst, bitset src1, bitset src2) { - bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); bitset_windex dsize = VBITSET_SIZE (dst); @@ -556,6 +559,7 @@ vbitset_andn_cmp (bitset dst, bitset src1, bitset src2) bitset_word *src1p = VBITSET_WORDS (src1); bitset_word *src2p = VBITSET_WORDS (src2); + bool changed = false; unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { @@ -633,8 +637,6 @@ vbitset_or (bitset dst, bitset src1, bitset src2) static bool vbitset_or_cmp (bitset dst, bitset src1, bitset src2) { - bool changed = false; - vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); bitset_windex dsize = VBITSET_SIZE (dst); @@ -644,6 +646,7 @@ vbitset_or_cmp (bitset dst, bitset src1, bitset src2) bitset_word *src1p = VBITSET_WORDS (src1); bitset_word *src2p = VBITSET_WORDS (src2); + bool changed = false; unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { @@ -711,7 +714,6 @@ vbitset_xor (bitset dst, bitset src1, bitset src2) static bool vbitset_xor_cmp (bitset dst, bitset src1, bitset src2) { - bool changed = false; vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2))); bitset_windex dsize = VBITSET_SIZE (dst); @@ -721,6 +723,7 @@ vbitset_xor_cmp (bitset dst, bitset src1, bitset src2) bitset_word *src1p = VBITSET_WORDS (src1); bitset_word *src2p = VBITSET_WORDS (src2); + bool changed = false; unsigned i; for (i = 0; i < min (ssize1, ssize2); i++, dstp++) { @@ -903,8 +906,8 @@ vbitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3) bitset_word *dstp = VBITSET_WORDS (dst); bitset_windex size = VBITSET_SIZE (dst); - unsigned i; bool changed = false; + unsigned i; for (i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ | *src2p++) & *src3p++; @@ -929,6 +932,13 @@ vbitset_copy (bitset dst, bitset src) } +static void +vbitset_free (bitset bset) +{ + free (VBITSET_WORDS (bset)); +} + + /* Vector of operations for multiple word bitsets. */ struct bitset_vtable vbitset_vtable = { vbitset_set, @@ -962,7 +972,7 @@ struct bitset_vtable vbitset_vtable = { vbitset_or_and_cmp, vbitset_list, vbitset_list_reverse, - NULL, + vbitset_free, BITSET_VECTOR }; diff --git a/contrib/tools/bison/lib/bitset/vector.h b/contrib/tools/bison/lib/bitset/vector.h index 1f5b94dea092..aeea89a6c723 100644 --- a/contrib/tools/bison/lib/bitset/vector.h +++ b/contrib/tools/bison/lib/bitset/vector.h @@ -1,6 +1,6 @@ /* Functions to support vbitsets. - Copyright (C) 2002, 2004, 2009-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #ifndef _BITSET_VECTOR_H #define _BITSET_VECTOR_H diff --git a/contrib/tools/bison/lib/bitsetv.c b/contrib/tools/bison/lib/bitsetv.c index e3cc5845a766..0ec9ac38c232 100644 --- a/contrib/tools/bison/lib/bitsetv.c +++ b/contrib/tools/bison/lib/bitsetv.c @@ -1,6 +1,6 @@ /* Bitset vectors. - Copyright (C) 2001-2002, 2004-2006, 2009-2015, 2018-2019 Free Software + Copyright (C) 2001-2002, 2004-2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -14,7 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #include @@ -41,7 +41,7 @@ bitsetv_alloc (bitset_bindex n_vecs, bitset_bindex n_bits, /* Allocate vector table at head of bitset array. */ size_t vector_bytes = (n_vecs + 1) * sizeof (bitset) + bytes - 1; vector_bytes -= vector_bytes % bytes; - bitset *bsetv = xcalloc (1, vector_bytes + bytes * n_vecs); + bitset *bsetv = xzalloc (vector_bytes + bytes * n_vecs); bitset_bindex i = 0; for (i = 0; i < n_vecs; i++) @@ -71,9 +71,12 @@ bitsetv_create (bitset_bindex n_vecs, bitset_bindex n_bits, unsigned attr) void bitsetv_free (bitsetv bsetv) { - for (bitset_bindex i = 0; bsetv[i]; i++) - BITSET_FREE_ (bsetv[i]); - free (bsetv); + if (bsetv) + { + for (bitset_bindex i = 0; bsetv[i]; i++) + BITSET_FREE_ (bsetv[i]); + free (bsetv); + } } diff --git a/contrib/tools/bison/lib/bitsetv.h b/contrib/tools/bison/lib/bitsetv.h index 798b70d9b42d..13e9ba4cd6b5 100644 --- a/contrib/tools/bison/lib/bitsetv.h +++ b/contrib/tools/bison/lib/bitsetv.h @@ -1,6 +1,6 @@ /* Bitset vectors. - Copyright (C) 2002, 2004, 2009-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #ifndef _BITSETV_H #define _BITSETV_H @@ -33,7 +33,7 @@ bitsetv bitsetv_alloc (bitset_bindex, bitset_bindex, enum bitset_type); attribute hints specified by ATTR. */ bitsetv bitsetv_create (bitset_bindex, bitset_bindex, unsigned); -/* Free vector of bitsets. */ +/* Free vector of bitsets. Do nothing if NULL. */ void bitsetv_free (bitsetv); /* Zero vector of bitsets. */ diff --git a/contrib/tools/bison/lib/c-ctype.h b/contrib/tools/bison/lib/c-ctype.h index 4d521763843f..fbd11b34508f 100644 --- a/contrib/tools/bison/lib/c-ctype.h +++ b/contrib/tools/bison/lib/c-ctype.h @@ -5,7 +5,7 @@ functions' behaviour depends on the current locale set via setlocale. - Copyright (C) 2000-2003, 2006, 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2000-2003, 2006, 2008-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/c-strcase.h b/contrib/tools/bison/lib/c-strcase.h index b67c9b5da0e3..3b711f5aa57f 100644 --- a/contrib/tools/bison/lib/c-strcase.h +++ b/contrib/tools/bison/lib/c-strcase.h @@ -1,5 +1,5 @@ /* Case-insensitive string comparison functions in C locale. - Copyright (C) 1995-1996, 2001, 2003, 2005, 2009-2019 Free Software + Copyright (C) 1995-1996, 2001, 2003, 2005, 2009-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/c-strcasecmp.c b/contrib/tools/bison/lib/c-strcasecmp.c index ec50f1abe763..951220f3e29e 100644 --- a/contrib/tools/bison/lib/c-strcasecmp.c +++ b/contrib/tools/bison/lib/c-strcasecmp.c @@ -1,5 +1,5 @@ /* c-strcasecmp.c -- case insensitive string comparator in C locale - Copyright (C) 1998-1999, 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1998-1999, 2005-2006, 2009-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/c-strcaseeq.h b/contrib/tools/bison/lib/c-strcaseeq.h index bcc81fc388db..304c72ea49d1 100644 --- a/contrib/tools/bison/lib/c-strcaseeq.h +++ b/contrib/tools/bison/lib/c-strcaseeq.h @@ -1,5 +1,5 @@ /* Optimized case-insensitive string comparison in C locale. - Copyright (C) 2001-2002, 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published diff --git a/contrib/tools/bison/lib/c-strncasecmp.c b/contrib/tools/bison/lib/c-strncasecmp.c index 513c353f6c28..9ad49191b7fd 100644 --- a/contrib/tools/bison/lib/c-strncasecmp.c +++ b/contrib/tools/bison/lib/c-strncasecmp.c @@ -1,5 +1,5 @@ /* c-strncasecmp.c -- case insensitive string comparator in C locale - Copyright (C) 1998-1999, 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1998-1999, 2005-2006, 2009-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/careadlinkat.c b/contrib/tools/bison/lib/careadlinkat.c index e56d5030856e..1effdb78451f 100644 --- a/contrib/tools/bison/lib/careadlinkat.c +++ b/contrib/tools/bison/lib/careadlinkat.c @@ -1,6 +1,6 @@ /* Read symbolic links into a buffer without size limitation, relative to fd. - Copyright (C) 2001, 2003-2004, 2007, 2009-2019 Free Software Foundation, + Copyright (C) 2001, 2003-2004, 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -54,7 +54,7 @@ The PREADLINKAT function specifies how to read links. It operates like POSIX readlinkat() - + but can assume that its first argument is the same as FD. If successful, return the buffer address; otherwise return NULL and diff --git a/contrib/tools/bison/lib/careadlinkat.h b/contrib/tools/bison/lib/careadlinkat.h index 68b69aa88939..a4a37b274d0a 100644 --- a/contrib/tools/bison/lib/careadlinkat.h +++ b/contrib/tools/bison/lib/careadlinkat.h @@ -1,6 +1,6 @@ /* Read symbolic links into a buffer without size limitation, relative to fd. - Copyright (C) 2011-2019 Free Software Foundation, Inc. + Copyright (C) 2011-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -40,14 +40,14 @@ struct allocator; The PREADLINKAT function specifies how to read links. It operates like POSIX readlinkat() - + but can assume that its first argument is the same as FD. If successful, return the buffer address; otherwise return NULL and set errno. */ char *careadlinkat (int fd, char const *filename, - char *buffer, size_t buffer_size, + char *restrict buffer, size_t buffer_size, struct allocator const *alloc, ssize_t (*preadlinkat) (int, char const *, char *, size_t)); diff --git a/contrib/tools/bison/lib/cloexec.c b/contrib/tools/bison/lib/cloexec.c index db425766a0e1..510be3d57ec0 100644 --- a/contrib/tools/bison/lib/cloexec.c +++ b/contrib/tools/bison/lib/cloexec.c @@ -1,6 +1,6 @@ /* cloexec.c - set or clear the close-on-exec descriptor flag - Copyright (C) 1991, 2004-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1991, 2004-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/cloexec.h b/contrib/tools/bison/lib/cloexec.h index 06ad945d8e2a..f14a99736d50 100644 --- a/contrib/tools/bison/lib/cloexec.h +++ b/contrib/tools/bison/lib/cloexec.h @@ -1,6 +1,6 @@ /* cloexec.c - set or clear the close-on-exec descriptor flag - Copyright (C) 2004, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2004, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/close-stream.c b/contrib/tools/bison/lib/close-stream.c index 5458c4f29f36..04bc8009a573 100644 --- a/contrib/tools/bison/lib/close-stream.c +++ b/contrib/tools/bison/lib/close-stream.c @@ -1,6 +1,6 @@ /* Close a stream, with nicer error checking than fclose's. - Copyright (C) 1998-2002, 2004, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 1998-2002, 2004, 2006-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/close.c b/contrib/tools/bison/lib/close.c index 40ce845bc333..0c8780dc24ab 100644 --- a/contrib/tools/bison/lib/close.c +++ b/contrib/tools/bison/lib/close.c @@ -1,5 +1,5 @@ /* close replacement. - Copyright (C) 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2008-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/closeout.c b/contrib/tools/bison/lib/closeout.c index 4a604ec35d4b..8b92ce9476b4 100644 --- a/contrib/tools/bison/lib/closeout.c +++ b/contrib/tools/bison/lib/closeout.c @@ -1,6 +1,6 @@ /* Close standard output and standard error, exiting with a diagnostic on error. - Copyright (C) 1998-2002, 2004, 2006, 2008-2019 Free Software Foundation, + Copyright (C) 1998-2002, 2004, 2006, 2008-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/closeout.h b/contrib/tools/bison/lib/closeout.h index ac89f760a952..8294c6268c9b 100644 --- a/contrib/tools/bison/lib/closeout.h +++ b/contrib/tools/bison/lib/closeout.h @@ -1,6 +1,6 @@ /* Close standard output and standard error. - Copyright (C) 1998, 2000, 2003-2004, 2006, 2008-2019 Free Software + Copyright (C) 1998, 2000, 2003-2004, 2006, 2008-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/concat-filename.c b/contrib/tools/bison/lib/concat-filename.c index df0e170a89cf..367e41d22c95 100644 --- a/contrib/tools/bison/lib/concat-filename.c +++ b/contrib/tools/bison/lib/concat-filename.c @@ -1,5 +1,5 @@ /* Construct a full filename from a directory and a relative filename. - Copyright (C) 2001-2004, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the diff --git a/contrib/tools/bison/lib/concat-filename.h b/contrib/tools/bison/lib/concat-filename.h index 4448b783fce8..64b461e39d4c 100644 --- a/contrib/tools/bison/lib/concat-filename.h +++ b/contrib/tools/bison/lib/concat-filename.h @@ -1,5 +1,5 @@ /* Construct a full filename from a directory and a relative filename. - Copyright (C) 2001-2004, 2007-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2007-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/config-linux.h b/contrib/tools/bison/lib/config-linux.h index 9c4e201410b4..5d1714a49f11 100644 --- a/contrib/tools/bison/lib/config-linux.h +++ b/contrib/tools/bison/lib/config-linux.h @@ -31,9 +31,6 @@ /* Define to 1 if using `alloca.c'. */ /* #undef C_ALLOCA */ -/* Define to 1 if the C locale may have encoding errors. */ -#define C_LOCALE_MAYBE_EILSEQ 1 - /* Define as the bit index in the word where to find bit 0 of the exponent of 'double'. */ #define DBL_EXPBIT0_BIT 20 @@ -113,7 +110,7 @@ /* Define to a C preprocessor expression that evaluates to 1 or 0, depending whether the gnulib module lock shall be considered present. */ -/* #undef GNULIB_LOCK */ +#define GNULIB_LOCK 1 /* Define to a C preprocessor expression that evaluates to 1 or 0, depending whether the gnulib module malloc-gnu shall be considered present. */ @@ -187,9 +184,15 @@ /* Define to 1 when the gnulib module fstat should be tested. */ /* #undef GNULIB_TEST_FSTAT */ +/* Define to 1 when the gnulib module fsync should be tested. */ +#define GNULIB_TEST_FSYNC 1 + /* Define to 1 when the gnulib module getdtablesize should be tested. */ #define GNULIB_TEST_GETDTABLESIZE 1 +/* Define to 1 when the gnulib module getopt-posix should be tested. */ +#define GNULIB_TEST_GETOPT_POSIX 1 + /* Define to 1 when the gnulib module getrusage should be tested. */ #define GNULIB_TEST_GETRUSAGE 1 @@ -208,6 +211,15 @@ /* Define to 1 when the gnulib module isnanl should be tested. */ #define GNULIB_TEST_ISNANL 1 +/* Define to 1 when the gnulib module iswblank should be tested. */ +#define GNULIB_TEST_ISWBLANK 1 + +/* Define to 1 when the gnulib module iswdigit should be tested. */ +#define GNULIB_TEST_ISWDIGIT 1 + +/* Define to 1 when the gnulib module iswxdigit should be tested. */ +#define GNULIB_TEST_ISWXDIGIT 1 + /* Define to 1 when the gnulib module ldexpl should be tested. */ #define GNULIB_TEST_LDEXPL 1 @@ -301,6 +313,9 @@ /* Define to 1 when the gnulib module rmdir should be tested. */ /* #undef GNULIB_TEST_RMDIR */ +/* Define to 1 when the gnulib module setlocale_null should be tested. */ +#define GNULIB_TEST_SETLOCALE_NULL 1 + /* Define to 1 when the gnulib module sigaction should be tested. */ #define GNULIB_TEST_SIGACTION 1 @@ -349,6 +364,9 @@ /* Define to 1 when the gnulib module unsetenv should be tested. */ #define GNULIB_TEST_UNSETENV 1 +/* Define to 1 when the gnulib module vasprintf should be tested. */ +#define GNULIB_TEST_VASPRINTF 1 + /* Define to 1 when the gnulib module vfprintf-posix should be tested. */ #define GNULIB_TEST_VFPRINTF_POSIX 1 @@ -364,6 +382,9 @@ /* Define to 1 when the gnulib module wcwidth should be tested. */ #define GNULIB_TEST_WCWIDTH 1 +/* Define if your system defines TIOCGWINSZ in sys/ioctl.h. */ +#define GWINSZ_IN_SYS_IOCTL 1 + /* Define to 1 if you have 'alloca' after including , a header that may be supplied by this distribution. */ #define HAVE_ALLOCA 1 @@ -391,10 +412,6 @@ CoreFoundation framework. */ /* #undef HAVE_CFLOCALECOPYCURRENT */ -/* Define to 1 if you have the Mac OS X function - CFLocaleCopyPreferredLanguages in the CoreFoundation framework. */ -/* #undef HAVE_CFLOCALECOPYPREFERREDLANGUAGES */ - /* Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in the CoreFoundation framework. */ /* #undef HAVE_CFPREFERENCESCOPYAPPVALUE */ @@ -420,6 +437,9 @@ libc. */ /* #undef HAVE_COPYSIGN_IN_LIBC */ +/* Define to 1 if you have the `copy_file_range' function. */ +/* #undef HAVE_COPY_FILE_RANGE */ + /* Define to 1 if you have the header file. */ /* #undef HAVE_CRTDEFS_H */ @@ -495,6 +515,10 @@ don't. */ #define HAVE_DECL_GETHRTIME 0 +/* Define to 1 if you have the declaration of `iswblank', and to 0 if you + don't. */ +#define HAVE_DECL_ISWBLANK 1 + /* Define to 1 if you have the declaration of `mbrtowc', and to 0 if you don't. */ /* #undef HAVE_DECL_MBRTOWC */ @@ -597,6 +621,9 @@ /* Define if the frexp function is available in libc. */ #define HAVE_FREXP_IN_LIBC 1 +/* Define to 1 if you have the `fsync' function. */ +#define HAVE_FSYNC 1 + /* Define to 1 if you have the `getcwd' function. */ #define HAVE_GETCWD 1 @@ -649,6 +676,9 @@ /* Define if the isnan(long double) function is available in libc. */ #define HAVE_ISNANL_IN_LIBC 1 +/* Define to 1 if you have the `iswblank' function. */ +#define HAVE_ISWBLANK 1 + /* Define to 1 if you have the `iswcntrl' function. */ #define HAVE_ISWCNTRL 1 @@ -664,6 +694,9 @@ /* Define if the ldexp function is available in libc. */ #define HAVE_LDEXP_IN_LIBC 1 +/* Define if you have the libtextstyle library. */ +/* #undef HAVE_LIBTEXTSTYLE */ + /* Define to 1 if you have the header file. */ #define HAVE_LIMITS_H 1 @@ -754,11 +787,14 @@ /* Define to 1 if the system has the type `posix_spawn_file_actions_t'. */ #define HAVE_POSIX_SPAWN_FILE_ACTIONS_T 1 +/* Define if you have the header and the POSIX threads API. */ +#define HAVE_PTHREAD_API 1 + /* Define if the defines PTHREAD_MUTEX_RECURSIVE. */ -/* #undef HAVE_PTHREAD_MUTEX_RECURSIVE */ +#define HAVE_PTHREAD_MUTEX_RECURSIVE 1 /* Define if the POSIX multithreading library has read/write locks. */ -/* #undef HAVE_PTHREAD_RWLOCK */ +#define HAVE_PTHREAD_RWLOCK 1 /* Define if the 'pthread_rwlock_rdlock' function prefers a writer to a reader. */ @@ -786,7 +822,7 @@ /* #undef HAVE_SAME_LONG_DOUBLE_AS_DOUBLE */ /* Define to 1 if you have the header file. */ -/* #undef HAVE_SCHED_H */ +#define HAVE_SCHED_H 1 /* Define to 1 if you have the `sched_setparam' function. */ /* #undef HAVE_SCHED_SETPARAM */ @@ -956,6 +992,15 @@ /* Define to 1 if you have the header file. */ #define HAVE_SYS_WAIT_H 1 +/* Define to 1 if you have the `tcdrain' function. */ +#define HAVE_TCDRAIN 1 + +/* Define to 1 if you have the `thrd_create' function. */ +/* #undef HAVE_THRD_CREATE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_THREADS_H 1 + /* Define to 1 if you have the `towlower' function. */ #define HAVE_TOWLOWER 1 @@ -977,9 +1022,16 @@ /* Define to 1 if you have the `vasnprintf' function. */ /* #undef HAVE_VASNPRINTF */ +/* Define to 1 if you have the `vasprintf' function. */ +#define HAVE_VASPRINTF 1 + /* Define to 1 if you have the `vfork' function. */ /* #undef HAVE_VFORK */ +/* Define to 1 or 0, depending whether the compiler supports simple visibility + declarations. */ +/* #undef HAVE_VISIBILITY */ + /* Define to 1 if you have the `vsnprintf' function. */ #define HAVE_VSNPRINTF 1 @@ -1007,6 +1059,10 @@ /* Define to 1 if you have the `wcwidth' function. */ #define HAVE_WCWIDTH 1 +/* Define to 1 if the compiler and linker support weak declarations of + symbols. */ +#define HAVE_WEAK_SYMBOLS 1 + /* Define to 1 if you have the header file. */ /* #undef HAVE_WINSOCK2_H */ @@ -1019,6 +1075,9 @@ /* Define to 1 if O_NOFOLLOW works. */ #define HAVE_WORKING_O_NOFOLLOW 1 +/* Define to 1 if you have the header file. */ +/* #undef HAVE_XLOCALE_H */ + /* Define to 1 if the system has the type `_Bool'. */ #define HAVE__BOOL 1 @@ -1031,11 +1090,14 @@ /* Define to 1 if you have the `__fseterr' function. */ /* #undef HAVE___FSETERR */ +/* Define to 1 if the compiler supports the keyword '__inline'. */ +/* #undef HAVE___INLINE */ + /* Define to 1 if you have the `__xpg_strerror_r' function. */ #define HAVE___XPG_STRERROR_R 1 /* Define to the value of ${prefix}, as a string. */ -#define INSTALLPREFIX "/var/empty/bison-3.3.2" +#define INSTALLPREFIX "/var/empty/bison-3.5.4" /* Define as the bit index in the word where to find bit 0 of the exponent of 'long double'. */ @@ -1071,6 +1133,10 @@ */ /* #undef MBRTOWC_EMPTY_INPUT_BUG */ +/* Define if the mbrtowc function may signal encoding errors in the C locale. + */ +#define MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ 1 + /* Define if the mbrtowc function has the NULL pwc argument bug. */ /* #undef MBRTOWC_NULL_ARG1_BUG */ @@ -1083,6 +1149,10 @@ /* Define if the mbrtowc function returns a wrong return value. */ /* #undef MBRTOWC_RETVAL_BUG */ +/* Define if the mbrtowc function stores a wide character when reporting + incomplete input. */ +/* #undef MBRTOWC_STORES_INCOMPLETE_BUG */ + /* Use GNU style printf and scanf. */ #ifndef __USE_MINGW_ANSI_STDIO # define __USE_MINGW_ANSI_STDIO 1 @@ -1150,22 +1220,22 @@ #define PACKAGE_BUGREPORT "bug-bison@gnu.org" /* The copyright year for this package */ -#define PACKAGE_COPYRIGHT_YEAR 2019 +#define PACKAGE_COPYRIGHT_YEAR 2020 /* Define to the full name of this package. */ #define PACKAGE_NAME "GNU Bison" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "GNU Bison 3.3.2" +#define PACKAGE_STRING "GNU Bison 3.5.4" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "bison" /* Define to the home page for this package. */ -#define PACKAGE_URL "http://www.gnu.org/software/bison/" +#define PACKAGE_URL "https://www.gnu.org/software/bison/" /* Define to the version of this package. */ -#define PACKAGE_VERSION "3.3.2" +#define PACKAGE_VERSION "3.5.4" /* Define if exists and defines unusable PRI* macros. */ /* #undef PRI_MACROS_BROKEN */ @@ -1225,10 +1295,18 @@ implementation. */ #define REPLACE_VFPRINTF_POSIX 1 +/* Define to 1 if setlocale (LC_ALL, NULL) is multithread-safe. */ +#define SETLOCALE_NULL_ALL_MTSAFE 1 + +/* Define to 1 if setlocale (category, NULL) is multithread-safe. */ +#define SETLOCALE_NULL_ONE_MTSAFE 1 + /* File name of the Bourne shell. */ -#if defined __CYGWIN__ -/* Omit the directory part because for 32-bit Cygwin programs in a - 64-bit Cygwin environment, the Cygwin mounts are not visible. */ +#if defined __CYGWIN__ || defined __ANDROID__ +/* Omit the directory part because + - For 32-bit Cygwin programs in a 64-bit Cygwin environment, the Cygwin + mounts are not visible. + - On Android, /bin/sh does not exist. It's /system/bin/sh instead. */ # define BOURNE_SHELL "sh" #else # define BOURNE_SHELL "/bin/sh" @@ -1276,6 +1354,13 @@ an underscore or empty. */ #define USER_LABEL_PREFIX +/* Define if the combination of the ISO C and POSIX multithreading APIs can be + used. */ +/* #undef USE_ISOC_AND_POSIX_THREADS */ + +/* Define if the ISO C multithreading library can be used. */ +/* #undef USE_ISOC_THREADS */ + /* Define if the POSIX multithreading library can be used. */ #define USE_POSIX_THREADS 1 @@ -1283,20 +1368,6 @@ weak. */ #define USE_POSIX_THREADS_WEAK 1 -/* Define if the GNU Pth multithreading library can be used. */ -/* #undef USE_PTH_THREADS */ - -/* Define if references to the GNU Pth multithreading library should be made - weak. */ -/* #undef USE_PTH_THREADS_WEAK */ - -/* Define if the old Solaris multithreading library can be used. */ -/* #undef USE_SOLARIS_THREADS */ - -/* Define if references to the old Solaris multithreading library should be - made weak. */ -/* #undef USE_SOLARIS_THREADS_WEAK */ - /* Enable extensions on AIX 3, Interix. */ #ifndef _ALL_SOURCE # define _ALL_SOURCE 1 @@ -1379,7 +1450,7 @@ /* #undef USE_WINDOWS_THREADS */ /* Version number of package */ -#define VERSION "3.3.2" +#define VERSION "3.5.4" /* Define to 1 if unsetenv returns void instead of int. */ /* #undef VOID_UNSETENV */ @@ -1388,13 +1459,13 @@ 'wchar_t'. */ /* #undef WCHAR_T_SUFFIX */ +/* Define if sys/ptem.h is required for struct winsize. */ +/* #undef WINSIZE_IN_PTEM */ + /* Define to l, ll, u, ul, ull, etc., as suitable for constants of type 'wint_t'. */ /* #undef WINT_T_SUFFIX */ -/* Define if using the dmalloc debugging malloc package */ -/* #undef WITH_DMALLOC */ - /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ #if defined AC_APPLE_UNIVERSAL_BUILD @@ -1414,15 +1485,15 @@ `char[]'. */ /* #undef YYTEXT_POINTER */ -/* Enable large inode numbers on Mac OS X 10.5. */ -#define _DARWIN_USE_64_BIT_INODE 1 - /* Number of bits in a file offset, on hosts where this is settable. */ /* #undef _FILE_OFFSET_BITS */ /* Define for large files, on AIX-style hosts. */ /* #undef _LARGE_FILES */ +/* Define to 1 on Solaris. */ +/* #undef _LCONV_C99 */ + /* Define to 1 if on MINIX. */ /* #undef _MINIX */ @@ -1431,10 +1502,23 @@ /* The _Noreturn keyword of C11. */ #ifndef _Noreturn -# if 201103 <= (defined __cplusplus ? __cplusplus : 0) +# if (defined __cplusplus \ + && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \ + || (defined _MSC_VER && 1900 <= _MSC_VER)) \ + && 0) + /* [[noreturn]] is not practically usable, because with it the syntax + extern _Noreturn void func (...); + would not be valid; such a declaration would only be valid with 'extern' + and '_Noreturn' swapped, or without the 'extern' keyword. However, some + AIX system header files and several gnulib header files use precisely + this syntax with 'extern'. */ # define _Noreturn [[noreturn]] -# elif (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \ - || 4 < __GNUC__ + (7 <= __GNUC_MINOR__)) +# elif ((!defined __cplusplus || defined __clang__) \ + && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \ + || 4 < __GNUC__ + (7 <= __GNUC_MINOR__) \ + || (defined __apple_build_version__ \ + ? 6000000 <= __apple_build_version__ \ + : 3 < __clang_major__ + (5 <= __clang_minor__)))) /* _Noreturn works as-is. */ # elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C # define _Noreturn __attribute__ ((__noreturn__)) @@ -1466,6 +1550,33 @@ /* Define to 1 if the system predates C++11. */ /* #undef __STDC_LIMIT_MACROS */ +/* The _GL_ASYNC_SAFE marker should be attached to functions that are + signal handlers (for signals other than SIGABRT, SIGPIPE) or can be + invoked from such signal handlers. Such functions have some restrictions: + * All functions that it calls should be marked _GL_ASYNC_SAFE as well, + or should be listed as async-signal-safe in POSIX + + section 2.4.3. Note that malloc(), sprintf(), and fwrite(), in + particular, are NOT async-signal-safe. + * All memory locations (variables and struct fields) that these functions + access must be marked 'volatile'. This holds for both read and write + accesses. Otherwise the compiler might optimize away stores to and + reads from such locations that occur in the program, depending on its + data flow analysis. For example, when the program contains a loop + that is intended to inspect a variable set from within a signal handler + while (!signal_occurred) + ; + the compiler is allowed to transform this into an endless loop if the + variable 'signal_occurred' is not declared 'volatile'. + Additionally, recall that: + * A signal handler should not modify errno (except if it is a handler + for a fatal signal and ends by raising the same signal again, thus + provoking the termination of the process). If it invokes a function + that may clobber errno, it needs to save and restore the value of + errno. */ +#define _GL_ASYNC_SAFE + + /* Please see the Gnulib manual for how to use these macros. Suppress extern inline with HP-UX cc, as it appears to be broken; see @@ -1490,7 +1601,7 @@ https://lists.gnu.org/r/bug-gnulib/2012-12/msg00023.html DragonFly; see - http://muscles.dragonflybsd.org/bulk/bleeding-edge-potential/latest-per-pkg/ah-tty-0.3.12.log + http://muscles.dragonflybsd.org/bulk/clang-master-potential/20141111_102002/logs/ah-tty-0.3.12.log FreeBSD; see: https://lists.gnu.org/r/bug-gnulib/2014-07/msg00104.html @@ -1612,12 +1723,13 @@ nothing if this is not supported. Do not define if restrict is supported directly. */ #define restrict __restrict -/* Work around a bug in Sun C++: it does not support _Restrict or - __restrict__, even though the corresponding Sun C compiler ends up with - "#define restrict _Restrict" or "#define restrict __restrict__" in the - previous line. Perhaps some future version of Sun C++ will work with - restrict; if so, hopefully it defines __RESTRICT like Sun C does. */ -#if defined __SUNPRO_CC && !defined __RESTRICT +/* Work around a bug in older versions of Sun C++, which did not + #define __restrict__ or support _Restrict or __restrict__ + even though the corresponding Sun C compiler ended up with + "#define restrict _Restrict" or "#define restrict __restrict__" + in the previous line. This workaround can be removed once + we assume Oracle Developer Studio 12.5 (2016) or later. */ +#if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__ # define _Restrict # define __restrict__ #endif @@ -1678,4 +1790,5 @@ # define _GL_ATTRIBUTE_MALLOC /* empty */ #endif +#undef HAVE_THREADS_H #define _GL_ATTRIBUTE_FORMAT_PRINTF(...) diff --git a/contrib/tools/bison/lib/config-win.h b/contrib/tools/bison/lib/config-win.h index a3a4ad1adec4..ef3a3edc5b01 100644 --- a/contrib/tools/bison/lib/config-win.h +++ b/contrib/tools/bison/lib/config-win.h @@ -1226,7 +1226,7 @@ char *strsignal (int signum); /* #undef PACKAGE_PACKAGER_VERSION */ /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "GNU Bison 3.3.2" +#define PACKAGE_STRING "GNU Bison 3.5.4" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "m4" @@ -1235,7 +1235,7 @@ char *strsignal (int signum); #define PACKAGE_URL "http://www.gnu.org/software/m4/" /* Define to the version of this package. */ -#define PACKAGE_VERSION "3.3.2" +#define PACKAGE_VERSION "3.5.4" /* Define if exists and defines unusable PRI* macros. */ /* #undef PRI_MACROS_BROKEN */ @@ -1398,7 +1398,7 @@ char *strsignal (int signum); /* #undef USE_WINDOWS_THREADS */ /* Version number of package */ -#define VERSION "3.3.2" +#define VERSION "3.5.4" /* Define to 1 if unsetenv returns void instead of int. */ /* #undef VOID_UNSETENV */ @@ -1709,3 +1709,4 @@ char *strsignal (int signum); #define _GL_ATTRIBUTE_FORMAT_PRINTF(...) #define HAVE_ISNANL_IN_LIBC 1 #define HAVE_ISNAND_IN_LIBC 1 +#define _GL_ASYNC_SAFE diff --git a/contrib/tools/bison/lib/configmake-linux.h b/contrib/tools/bison/lib/configmake-linux.h index 14fe253583c5..7dc40e17b9ad 100644 --- a/contrib/tools/bison/lib/configmake-linux.h +++ b/contrib/tools/bison/lib/configmake-linux.h @@ -1,28 +1,31 @@ /* DO NOT EDIT! GENERATED AUTOMATICALLY! */ -#define PREFIX "/var/empty/bison-3.3.2" -#define EXEC_PREFIX "/var/empty/bison-3.3.2" -#define BINDIR "/var/empty/bison-3.3.2/bin" -#define SBINDIR "/var/empty/bison-3.3.2/sbin" -#define LIBEXECDIR "/var/empty/bison-3.3.2/libexec" -#define DATAROOTDIR "/var/empty/bison-3.3.2/share" -#define DATADIR "/var/empty/bison-3.3.2/share" -#define SYSCONFDIR "/var/empty/bison-3.3.2/etc" -#define SHAREDSTATEDIR "/var/empty/bison-3.3.2/com" -#define LOCALSTATEDIR "/var/empty/bison-3.3.2/var" -#define RUNSTATEDIR "/var/empty/bison-3.3.2/var/run" -#define INCLUDEDIR "/var/empty/bison-3.3.2/include" +#if HAVE_WINSOCK2_H +# include /* avoid mingw pollution on DATADIR */ +#endif +#define PREFIX "/var/empty/bison-3.5.4" +#define EXEC_PREFIX "/var/empty/bison-3.5.4" +#define BINDIR "/var/empty/bison-3.5.4/bin" +#define SBINDIR "/var/empty/bison-3.5.4/sbin" +#define LIBEXECDIR "/var/empty/bison-3.5.4/libexec" +#define DATAROOTDIR "/var/empty/bison-3.5.4/share" +#define DATADIR "/var/empty/bison-3.5.4/share" +#define SYSCONFDIR "/var/empty/bison-3.5.4/etc" +#define SHAREDSTATEDIR "/var/empty/bison-3.5.4/com" +#define LOCALSTATEDIR "/var/empty/bison-3.5.4/var" +#define RUNSTATEDIR "/var/empty/bison-3.5.4/var/run" +#define INCLUDEDIR "/var/empty/bison-3.5.4/include" #define OLDINCLUDEDIR "/usr/include" -#define DOCDIR "/var/empty/bison-3.3.2/share/doc/bison" -#define INFODIR "/var/empty/bison-3.3.2/share/info" -#define HTMLDIR "/var/empty/bison-3.3.2/share/doc/bison" -#define DVIDIR "/var/empty/bison-3.3.2/share/doc/bison" -#define PDFDIR "/var/empty/bison-3.3.2/share/doc/bison" -#define PSDIR "/var/empty/bison-3.3.2/share/doc/bison" -#define LIBDIR "/var/empty/bison-3.3.2/lib" -#define LISPDIR "/var/empty/bison-3.3.2/share/emacs/site-lisp" -#define LOCALEDIR "/var/empty/bison-3.3.2/share/locale" -#define MANDIR "/var/empty/bison-3.3.2/share/man" -#define PKGDATADIR "/var/empty/bison-3.3.2/share/bison" -#define PKGINCLUDEDIR "/var/empty/bison-3.3.2/include/bison" -#define PKGLIBDIR "/var/empty/bison-3.3.2/lib/bison" -#define PKGLIBEXECDIR "/var/empty/bison-3.3.2/libexec/bison" +#define DOCDIR "/var/empty/bison-3.5.4/share/doc/bison" +#define INFODIR "/var/empty/bison-3.5.4/share/info" +#define HTMLDIR "/var/empty/bison-3.5.4/share/doc/bison" +#define DVIDIR "/var/empty/bison-3.5.4/share/doc/bison" +#define PDFDIR "/var/empty/bison-3.5.4/share/doc/bison" +#define PSDIR "/var/empty/bison-3.5.4/share/doc/bison" +#define LIBDIR "/var/empty/bison-3.5.4/lib" +#define LISPDIR "/var/empty/bison-3.5.4/share/emacs/site-lisp" +#define LOCALEDIR "/var/empty/bison-3.5.4/share/locale" +#define MANDIR "/var/empty/bison-3.5.4/share/man" +#define PKGDATADIR "/var/empty/bison-3.5.4/share/bison" +#define PKGINCLUDEDIR "/var/empty/bison-3.5.4/include/bison" +#define PKGLIBDIR "/var/empty/bison-3.5.4/lib/bison" +#define PKGLIBEXECDIR "/var/empty/bison-3.5.4/libexec/bison" diff --git a/contrib/tools/bison/lib/configmake-win.h b/contrib/tools/bison/lib/configmake-win.h index 3efbed28dfd3..5c53dc59ec38 100644 --- a/contrib/tools/bison/lib/configmake-win.h +++ b/contrib/tools/bison/lib/configmake-win.h @@ -1,3 +1,2 @@ -/* DO NOT EDIT! GENERATED AUTOMATICALLY! */ - #define LOCALEDIR "C:\\Windows" +#define PKGDATADIR "C:\\Windows" diff --git a/contrib/tools/bison/lib/diffseq.h b/contrib/tools/bison/lib/diffseq.h new file mode 100644 index 000000000000..c89363ac9eef --- /dev/null +++ b/contrib/tools/bison/lib/diffseq.h @@ -0,0 +1,529 @@ +/* Analyze differences between two vectors. + + Copyright (C) 1988-1989, 1992-1995, 2001-2004, 2006-2020 Free Software + Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + + +/* The basic idea is to consider two vectors as similar if, when + transforming the first vector into the second vector through a + sequence of edits (inserts and deletes of one element each), + this sequence is short - or equivalently, if the ordered list + of elements that are untouched by these edits is long. For a + good introduction to the subject, read about the "Levenshtein + distance" in Wikipedia. + + The basic algorithm is described in: + "An O(ND) Difference Algorithm and its Variations", Eugene W. Myers, + Algorithmica Vol. 1, 1986, pp. 251-266, + . + See especially section 4.2, which describes the variation used below. + + The basic algorithm was independently discovered as described in: + "Algorithms for Approximate String Matching", Esko Ukkonen, + Information and Control Vol. 64, 1985, pp. 100-118, + . + + Unless the 'find_minimal' flag is set, this code uses the TOO_EXPENSIVE + heuristic, by Paul Eggert, to limit the cost to O(N**1.5 log N) + at the price of producing suboptimal output for large inputs with + many differences. */ + +/* Before including this file, you need to define: + ELEMENT The element type of the vectors being compared. + EQUAL A two-argument macro that tests two elements for + equality. + OFFSET A signed integer type sufficient to hold the + difference between two indices. Usually + something like ptrdiff_t. + EXTRA_CONTEXT_FIELDS Declarations of fields for 'struct context'. + NOTE_DELETE(ctxt, xoff) Record the removal of the object xvec[xoff]. + NOTE_INSERT(ctxt, yoff) Record the insertion of the object yvec[yoff]. + EARLY_ABORT(ctxt) (Optional) A boolean expression that triggers an + early abort of the computation. + USE_HEURISTIC (Optional) Define if you want to support the + heuristic for large vectors. + It is also possible to use this file with abstract arrays. In this case, + xvec and yvec are not represented in memory. They only exist conceptually. + In this case, the list of defines above is amended as follows: + ELEMENT Undefined. + EQUAL Undefined. + XVECREF_YVECREF_EQUAL(ctxt, xoff, yoff) + A three-argument macro: References xvec[xoff] and + yvec[yoff] and tests these elements for equality. + Before including this file, you also need to include: + #include + #include + #include "minmax.h" + */ + +/* Maximum value of type OFFSET. */ +#define OFFSET_MAX \ + ((((OFFSET)1 << (sizeof (OFFSET) * CHAR_BIT - 2)) - 1) * 2 + 1) + +/* Default to no early abort. */ +#ifndef EARLY_ABORT +# define EARLY_ABORT(ctxt) false +#endif + +/* Use this to suppress gcc's "...may be used before initialized" warnings. + Beware: The Code argument must not contain commas. */ +#ifndef IF_LINT +# if defined GCC_LINT || defined lint +# define IF_LINT(Code) Code +# else +# define IF_LINT(Code) /* empty */ +# endif +#endif + +/* As above, but when Code must contain one comma. */ +#ifndef IF_LINT2 +# if defined GCC_LINT || defined lint +# define IF_LINT2(Code1, Code2) Code1, Code2 +# else +# define IF_LINT2(Code1, Code2) /* empty */ +# endif +#endif + +/* + * Context of comparison operation. + */ +struct context +{ + #ifdef ELEMENT + /* Vectors being compared. */ + ELEMENT const *xvec; + ELEMENT const *yvec; + #endif + + /* Extra fields. */ + EXTRA_CONTEXT_FIELDS + + /* Vector, indexed by diagonal, containing 1 + the X coordinate of the point + furthest along the given diagonal in the forward search of the edit + matrix. */ + OFFSET *fdiag; + + /* Vector, indexed by diagonal, containing the X coordinate of the point + furthest along the given diagonal in the backward search of the edit + matrix. */ + OFFSET *bdiag; + + #ifdef USE_HEURISTIC + /* This corresponds to the diff --speed-large-files flag. With this + heuristic, for vectors with a constant small density of changes, + the algorithm is linear in the vector size. */ + bool heuristic; + #endif + + /* Edit scripts longer than this are too expensive to compute. */ + OFFSET too_expensive; + + /* Snakes bigger than this are considered "big". */ + #define SNAKE_LIMIT 20 +}; + +struct partition +{ + /* Midpoints of this partition. */ + OFFSET xmid; + OFFSET ymid; + + /* True if low half will be analyzed minimally. */ + bool lo_minimal; + + /* Likewise for high half. */ + bool hi_minimal; +}; + + +/* Find the midpoint of the shortest edit script for a specified portion + of the two vectors. + + Scan from the beginnings of the vectors, and simultaneously from the ends, + doing a breadth-first search through the space of edit-sequence. + When the two searches meet, we have found the midpoint of the shortest + edit sequence. + + If FIND_MINIMAL is true, find the minimal edit script regardless of + expense. Otherwise, if the search is too expensive, use heuristics to + stop the search and report a suboptimal answer. + + Set PART->(xmid,ymid) to the midpoint (XMID,YMID). The diagonal number + XMID - YMID equals the number of inserted elements minus the number + of deleted elements (counting only elements before the midpoint). + + Set PART->lo_minimal to true iff the minimal edit script for the + left half of the partition is known; similarly for PART->hi_minimal. + + This function assumes that the first elements of the specified portions + of the two vectors do not match, and likewise that the last elements do not + match. The caller must trim matching elements from the beginning and end + of the portions it is going to specify. + + If we return the "wrong" partitions, the worst this can do is cause + suboptimal diff output. It cannot cause incorrect diff output. */ + +static void +diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, bool find_minimal, + struct partition *part, struct context *ctxt) +{ + OFFSET *const fd = ctxt->fdiag; /* Give the compiler a chance. */ + OFFSET *const bd = ctxt->bdiag; /* Additional help for the compiler. */ +#ifdef ELEMENT + ELEMENT const *const xv = ctxt->xvec; /* Still more help for the compiler. */ + ELEMENT const *const yv = ctxt->yvec; /* And more and more . . . */ + #define XREF_YREF_EQUAL(x,y) EQUAL (xv[x], yv[y]) +#else + #define XREF_YREF_EQUAL(x,y) XVECREF_YVECREF_EQUAL (ctxt, x, y) +#endif + const OFFSET dmin = xoff - ylim; /* Minimum valid diagonal. */ + const OFFSET dmax = xlim - yoff; /* Maximum valid diagonal. */ + const OFFSET fmid = xoff - yoff; /* Center diagonal of top-down search. */ + const OFFSET bmid = xlim - ylim; /* Center diagonal of bottom-up search. */ + OFFSET fmin = fmid; + OFFSET fmax = fmid; /* Limits of top-down search. */ + OFFSET bmin = bmid; + OFFSET bmax = bmid; /* Limits of bottom-up search. */ + OFFSET c; /* Cost. */ + bool odd = (fmid - bmid) & 1; /* True if southeast corner is on an odd + diagonal with respect to the northwest. */ + + fd[fmid] = xoff; + bd[bmid] = xlim; + + for (c = 1;; ++c) + { + OFFSET d; /* Active diagonal. */ + bool big_snake = false; + + /* Extend the top-down search by an edit step in each diagonal. */ + if (fmin > dmin) + fd[--fmin - 1] = -1; + else + ++fmin; + if (fmax < dmax) + fd[++fmax + 1] = -1; + else + --fmax; + for (d = fmax; d >= fmin; d -= 2) + { + OFFSET x; + OFFSET y; + OFFSET tlo = fd[d - 1]; + OFFSET thi = fd[d + 1]; + OFFSET x0 = tlo < thi ? thi : tlo + 1; + + for (x = x0, y = x0 - d; + x < xlim && y < ylim && XREF_YREF_EQUAL (x, y); + x++, y++) + continue; + if (x - x0 > SNAKE_LIMIT) + big_snake = true; + fd[d] = x; + if (odd && bmin <= d && d <= bmax && bd[d] <= x) + { + part->xmid = x; + part->ymid = y; + part->lo_minimal = part->hi_minimal = true; + return; + } + } + + /* Similarly extend the bottom-up search. */ + if (bmin > dmin) + bd[--bmin - 1] = OFFSET_MAX; + else + ++bmin; + if (bmax < dmax) + bd[++bmax + 1] = OFFSET_MAX; + else + --bmax; + for (d = bmax; d >= bmin; d -= 2) + { + OFFSET x; + OFFSET y; + OFFSET tlo = bd[d - 1]; + OFFSET thi = bd[d + 1]; + OFFSET x0 = tlo < thi ? tlo : thi - 1; + + for (x = x0, y = x0 - d; + xoff < x && yoff < y && XREF_YREF_EQUAL (x - 1, y - 1); + x--, y--) + continue; + if (x0 - x > SNAKE_LIMIT) + big_snake = true; + bd[d] = x; + if (!odd && fmin <= d && d <= fmax && x <= fd[d]) + { + part->xmid = x; + part->ymid = y; + part->lo_minimal = part->hi_minimal = true; + return; + } + } + + if (find_minimal) + continue; + +#ifdef USE_HEURISTIC + bool heuristic = ctxt->heuristic; +#else + bool heuristic = false; +#endif + + /* Heuristic: check occasionally for a diagonal that has made lots + of progress compared with the edit distance. If we have any + such, find the one that has made the most progress and return it + as if it had succeeded. + + With this heuristic, for vectors with a constant small density + of changes, the algorithm is linear in the vector size. */ + + if (200 < c && big_snake && heuristic) + { + { + OFFSET best = 0; + + for (d = fmax; d >= fmin; d -= 2) + { + OFFSET dd = d - fmid; + OFFSET x = fd[d]; + OFFSET y = x - d; + OFFSET v = (x - xoff) * 2 - dd; + + if (v > 12 * (c + (dd < 0 ? -dd : dd))) + { + if (v > best + && xoff + SNAKE_LIMIT <= x && x < xlim + && yoff + SNAKE_LIMIT <= y && y < ylim) + { + /* We have a good enough best diagonal; now insist + that it end with a significant snake. */ + int k; + + for (k = 1; XREF_YREF_EQUAL (x - k, y - k); k++) + if (k == SNAKE_LIMIT) + { + best = v; + part->xmid = x; + part->ymid = y; + break; + } + } + } + } + if (best > 0) + { + part->lo_minimal = true; + part->hi_minimal = false; + return; + } + } + + { + OFFSET best = 0; + + for (d = bmax; d >= bmin; d -= 2) + { + OFFSET dd = d - bmid; + OFFSET x = bd[d]; + OFFSET y = x - d; + OFFSET v = (xlim - x) * 2 + dd; + + if (v > 12 * (c + (dd < 0 ? -dd : dd))) + { + if (v > best + && xoff < x && x <= xlim - SNAKE_LIMIT + && yoff < y && y <= ylim - SNAKE_LIMIT) + { + /* We have a good enough best diagonal; now insist + that it end with a significant snake. */ + int k; + + for (k = 0; XREF_YREF_EQUAL (x + k, y + k); k++) + if (k == SNAKE_LIMIT - 1) + { + best = v; + part->xmid = x; + part->ymid = y; + break; + } + } + } + } + if (best > 0) + { + part->lo_minimal = false; + part->hi_minimal = true; + return; + } + } + } + + /* Heuristic: if we've gone well beyond the call of duty, give up + and report halfway between our best results so far. */ + if (c >= ctxt->too_expensive) + { + OFFSET fxybest; + OFFSET fxbest IF_LINT (= 0); + OFFSET bxybest; + OFFSET bxbest IF_LINT (= 0); + + /* Find forward diagonal that maximizes X + Y. */ + fxybest = -1; + for (d = fmax; d >= fmin; d -= 2) + { + OFFSET x = MIN (fd[d], xlim); + OFFSET y = x - d; + if (ylim < y) + { + x = ylim + d; + y = ylim; + } + if (fxybest < x + y) + { + fxybest = x + y; + fxbest = x; + } + } + + /* Find backward diagonal that minimizes X + Y. */ + bxybest = OFFSET_MAX; + for (d = bmax; d >= bmin; d -= 2) + { + OFFSET x = MAX (xoff, bd[d]); + OFFSET y = x - d; + if (y < yoff) + { + x = yoff + d; + y = yoff; + } + if (x + y < bxybest) + { + bxybest = x + y; + bxbest = x; + } + } + + /* Use the better of the two diagonals. */ + if ((xlim + ylim) - bxybest < fxybest - (xoff + yoff)) + { + part->xmid = fxbest; + part->ymid = fxybest - fxbest; + part->lo_minimal = true; + part->hi_minimal = false; + } + else + { + part->xmid = bxbest; + part->ymid = bxybest - bxbest; + part->lo_minimal = false; + part->hi_minimal = true; + } + return; + } + } + #undef XREF_YREF_EQUAL +} + + +/* Compare in detail contiguous subsequences of the two vectors + which are known, as a whole, to match each other. + + The subsequence of vector 0 is [XOFF, XLIM) and likewise for vector 1. + + Note that XLIM, YLIM are exclusive bounds. All indices into the vectors + are origin-0. + + If FIND_MINIMAL, find a minimal difference no matter how + expensive it is. + + The results are recorded by invoking NOTE_DELETE and NOTE_INSERT. + + Return false if terminated normally, or true if terminated through early + abort. */ + +static bool +compareseq (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, + bool find_minimal, struct context *ctxt) +{ +#ifdef ELEMENT + ELEMENT const *xv = ctxt->xvec; /* Help the compiler. */ + ELEMENT const *yv = ctxt->yvec; + #define XREF_YREF_EQUAL(x,y) EQUAL (xv[x], yv[y]) +#else + #define XREF_YREF_EQUAL(x,y) XVECREF_YVECREF_EQUAL (ctxt, x, y) +#endif + + /* Slide down the bottom initial diagonal. */ + while (xoff < xlim && yoff < ylim && XREF_YREF_EQUAL (xoff, yoff)) + { + xoff++; + yoff++; + } + + /* Slide up the top initial diagonal. */ + while (xoff < xlim && yoff < ylim && XREF_YREF_EQUAL (xlim - 1, ylim - 1)) + { + xlim--; + ylim--; + } + + /* Handle simple cases. */ + if (xoff == xlim) + while (yoff < ylim) + { + NOTE_INSERT (ctxt, yoff); + if (EARLY_ABORT (ctxt)) + return true; + yoff++; + } + else if (yoff == ylim) + while (xoff < xlim) + { + NOTE_DELETE (ctxt, xoff); + if (EARLY_ABORT (ctxt)) + return true; + xoff++; + } + else + { + struct partition part IF_LINT2 (= { .xmid = 0, .ymid = 0 }); + + /* Find a point of correspondence in the middle of the vectors. */ + diag (xoff, xlim, yoff, ylim, find_minimal, &part, ctxt); + + /* Use the partitions to split this problem into subproblems. */ + if (compareseq (xoff, part.xmid, yoff, part.ymid, part.lo_minimal, ctxt)) + return true; + if (compareseq (part.xmid, xlim, part.ymid, ylim, part.hi_minimal, ctxt)) + return true; + } + + return false; + #undef XREF_YREF_EQUAL +} + +#undef ELEMENT +#undef EQUAL +#undef OFFSET +#undef EXTRA_CONTEXT_FIELDS +#undef NOTE_DELETE +#undef NOTE_INSERT +#undef EARLY_ABORT +#undef USE_HEURISTIC +#undef XVECREF_YVECREF_EQUAL +#undef OFFSET_MAX diff --git a/contrib/tools/bison/lib/dirname-lgpl.c b/contrib/tools/bison/lib/dirname-lgpl.c index 7cf89d8cf80e..27d4374c2e71 100644 --- a/contrib/tools/bison/lib/dirname-lgpl.c +++ b/contrib/tools/bison/lib/dirname-lgpl.c @@ -1,6 +1,6 @@ /* dirname.c -- return all but the last element in a file name - Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2019 Free Software + Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/dirname.c b/contrib/tools/bison/lib/dirname.c index 1e042a5cdc96..dc1997c810dd 100644 --- a/contrib/tools/bison/lib/dirname.c +++ b/contrib/tools/bison/lib/dirname.c @@ -1,6 +1,6 @@ /* dirname.c -- return all but the last element in a file name - Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2019 Free Software + Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/dirname.h b/contrib/tools/bison/lib/dirname.h index 579165947f74..8c12d93b510d 100644 --- a/contrib/tools/bison/lib/dirname.h +++ b/contrib/tools/bison/lib/dirname.h @@ -1,6 +1,6 @@ /* Take file names apart into directory and base names. - Copyright (C) 1998, 2001, 2003-2006, 2009-2019 Free Software Foundation, + Copyright (C) 1998, 2001, 2003-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/dosname.h b/contrib/tools/bison/lib/dosname.h index c0ab6848a58a..57829600948c 100644 --- a/contrib/tools/bison/lib/dosname.h +++ b/contrib/tools/bison/lib/dosname.h @@ -1,6 +1,6 @@ /* File names on MS-DOS/Windows systems. - Copyright (C) 2000-2001, 2004-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2000-2001, 2004-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/dup-safer-flag.c b/contrib/tools/bison/lib/dup-safer-flag.c index 485f7411bdb0..b2c345e0ed65 100644 --- a/contrib/tools/bison/lib/dup-safer-flag.c +++ b/contrib/tools/bison/lib/dup-safer-flag.c @@ -1,7 +1,7 @@ /* Duplicate a file descriptor result, avoiding clobbering STD{IN,OUT,ERR}_FILENO, with specific flags. - Copyright (C) 2001, 2004-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2004-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/dup-safer.c b/contrib/tools/bison/lib/dup-safer.c index c0c5f2a914b8..4ada3fe8d231 100644 --- a/contrib/tools/bison/lib/dup-safer.c +++ b/contrib/tools/bison/lib/dup-safer.c @@ -1,6 +1,6 @@ /* Invoke dup, but avoid some glitches. - Copyright (C) 2001, 2004-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2004-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/dup2.c b/contrib/tools/bison/lib/dup2.c index 56a27944789b..410064a93529 100644 --- a/contrib/tools/bison/lib/dup2.c +++ b/contrib/tools/bison/lib/dup2.c @@ -1,6 +1,6 @@ /* Duplicate an open file descriptor to a specified file descriptor. - Copyright (C) 1999, 2004-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1999, 2004-2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/error.c b/contrib/tools/bison/lib/error.c index 7e532f0e486c..3657b51cdfeb 100644 --- a/contrib/tools/bison/lib/error.c +++ b/contrib/tools/bison/lib/error.c @@ -1,5 +1,5 @@ /* Error handler for noninteractive utilities - Copyright (C) 1990-1998, 2000-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1990-1998, 2000-2007, 2009-2020 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software: you can redistribute it and/or modify @@ -119,7 +119,7 @@ int strerror_r (int errnum, char *buf, size_t buflen); # endif # endif -#define program_name getprogname () +# define program_name getprogname () # if GNULIB_STRERROR_R_POSIX || HAVE_STRERROR_R || defined strerror_r # define __strerror_r strerror_r diff --git a/contrib/tools/bison/lib/error.h b/contrib/tools/bison/lib/error.h index 3759f8ad44e9..bad47a16dd28 100644 --- a/contrib/tools/bison/lib/error.h +++ b/contrib/tools/bison/lib/error.h @@ -1,5 +1,5 @@ /* Declaration for error-reporting function - Copyright (C) 1995-1997, 2003, 2006, 2008-2019 Free Software Foundation, + Copyright (C) 1995-1997, 2003, 2006, 2008-2020 Free Software Foundation, Inc. This file is part of the GNU C Library. diff --git a/contrib/tools/bison/lib/exitfail.c b/contrib/tools/bison/lib/exitfail.c index 69b351372e5b..189fa16f46a8 100644 --- a/contrib/tools/bison/lib/exitfail.c +++ b/contrib/tools/bison/lib/exitfail.c @@ -1,6 +1,6 @@ /* Failure exit status - Copyright (C) 2002-2003, 2005-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2003, 2005-2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/exitfail.h b/contrib/tools/bison/lib/exitfail.h index 480ad1a1663d..a69a03bbd5b7 100644 --- a/contrib/tools/bison/lib/exitfail.h +++ b/contrib/tools/bison/lib/exitfail.h @@ -1,6 +1,6 @@ /* Failure exit status - Copyright (C) 2002, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2002, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/fatal-signal.c b/contrib/tools/bison/lib/fatal-signal.c index 1fe31d10f59b..c8ff33804103 100644 --- a/contrib/tools/bison/lib/fatal-signal.c +++ b/contrib/tools/bison/lib/fatal-signal.c @@ -1,5 +1,5 @@ /* Emergency actions in case of a fatal signal. - Copyright (C) 2003-2004, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 2003-2004, 2006-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software: you can redistribute it and/or modify @@ -107,7 +107,7 @@ init_fatal_signals (void) /* ========================================================================= */ -typedef void (*action_t) (void); +typedef _GL_ASYNC_SAFE void (*action_t) (int sig); /* Type of an entry in the actions array. The 'action' field is accessed from within the fatal_signal_handler(), @@ -131,7 +131,7 @@ static struct sigaction saved_sigactions[64]; /* Uninstall the handlers. */ -static void +static _GL_ASYNC_SAFE void uninstall_handlers (void) { size_t i; @@ -148,7 +148,7 @@ uninstall_handlers (void) /* The signal handler. It gets called asynchronously. */ -static void +static _GL_ASYNC_SAFE void fatal_signal_handler (int sig) { for (;;) @@ -162,7 +162,7 @@ fatal_signal_handler (int sig) actions_count = n; action = actions[n].action; /* Execute the action. */ - action (); + action (sig); } /* Now execute the signal's default action. @@ -284,3 +284,20 @@ unblock_fatal_signals (void) init_fatal_signal_set (); sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL); } + + +unsigned int +get_fatal_signals (int signals[64]) +{ + init_fatal_signal_set (); + + { + int *p = signals; + size_t i; + + for (i = 0; i < num_fatal_signals; i++) + if (fatal_signals[i] >= 0) + *p++ = fatal_signals[i]; + return p - signals; + } +} diff --git a/contrib/tools/bison/lib/fatal-signal.h b/contrib/tools/bison/lib/fatal-signal.h index a2e60d3a629a..2c0154ffc3e0 100644 --- a/contrib/tools/bison/lib/fatal-signal.h +++ b/contrib/tools/bison/lib/fatal-signal.h @@ -1,5 +1,5 @@ /* Emergency actions in case of a fatal signal. - Copyright (C) 2003-2004, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2003-2004, 2009-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software: you can redistribute it and/or modify @@ -36,7 +36,8 @@ extern "C" { occurs. Restrictions for the cleanup function: - - The cleanup function can do all kinds of system calls. + - The cleanup function can do all kinds of system calls. It may also + modify (clobber) errno. - It can also access application dependent memory locations and data structures provided they are in a consistent state. One way to ensure this is through block_fatal_signals()/unblock_fatal_signals(), see @@ -51,7 +52,7 @@ extern "C" { The cleanup function is executed asynchronously. It is unspecified whether during its execution the catchable fatal signals are blocked or not. */ -extern void at_fatal_signal (void (*function) (void)); +extern void at_fatal_signal (_GL_ASYNC_SAFE void (*function) (int sig)); /* Sometimes it is necessary to block the usually fatal signals while the @@ -71,6 +72,12 @@ extern void block_fatal_signals (void); extern void unblock_fatal_signals (void); +/* Return the list of signals that block_fatal_signals/unblock_fatal_signals + would block or unblock. + Fills signals[0..count-1] and returns count. */ +extern unsigned int get_fatal_signals (int signals[64]); + + #ifdef __cplusplus } #endif diff --git a/contrib/tools/bison/lib/fcntl.c b/contrib/tools/bison/lib/fcntl.c index e65f1b21c7d7..cc54f62ed7c4 100644 --- a/contrib/tools/bison/lib/fcntl.c +++ b/contrib/tools/bison/lib/fcntl.c @@ -1,6 +1,6 @@ /* Provide file descriptor control. - Copyright (C) 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,6 +25,7 @@ #include #include #include +#include #include #ifdef __KLIBC__ diff --git a/contrib/tools/bison/lib/fd-hook.c b/contrib/tools/bison/lib/fd-hook.c index 78791198fa07..8840f634880a 100644 --- a/contrib/tools/bison/lib/fd-hook.c +++ b/contrib/tools/bison/lib/fd-hook.c @@ -1,5 +1,5 @@ /* Hook for making file descriptor functions close(), ioctl() extensible. - Copyright (C) 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/contrib/tools/bison/lib/fd-hook.h b/contrib/tools/bison/lib/fd-hook.h index bf07f0068b7e..ed1a15a230c5 100644 --- a/contrib/tools/bison/lib/fd-hook.h +++ b/contrib/tools/bison/lib/fd-hook.h @@ -1,5 +1,5 @@ /* Hook for making file descriptor functions close(), ioctl() extensible. - Copyright (C) 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published diff --git a/contrib/tools/bison/lib/fd-safer-flag.c b/contrib/tools/bison/lib/fd-safer-flag.c index 7c026ef54152..8fdf8dbc16ac 100644 --- a/contrib/tools/bison/lib/fd-safer-flag.c +++ b/contrib/tools/bison/lib/fd-safer-flag.c @@ -1,7 +1,7 @@ /* Adjust a file descriptor result so that it avoids clobbering STD{IN,OUT,ERR}_FILENO, with specific flags. - Copyright (C) 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/fd-safer.c b/contrib/tools/bison/lib/fd-safer.c index b5113e13673f..e011c00308aa 100644 --- a/contrib/tools/bison/lib/fd-safer.c +++ b/contrib/tools/bison/lib/fd-safer.c @@ -1,6 +1,6 @@ /* Return a safer copy of a file descriptor. - Copyright (C) 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/filename.h b/contrib/tools/bison/lib/filename.h index 3ba31059f696..d4c70203e663 100644 --- a/contrib/tools/bison/lib/filename.h +++ b/contrib/tools/bison/lib/filename.h @@ -1,5 +1,5 @@ /* Basic filename support macros. - Copyright (C) 2001-2004, 2007-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2007-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/float+.h b/contrib/tools/bison/lib/float+.h index 5af861f7aeb6..1e19a7185a9c 100644 --- a/contrib/tools/bison/lib/float+.h +++ b/contrib/tools/bison/lib/float+.h @@ -1,5 +1,5 @@ /* Supplemental information about the floating-point formats. - Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software; you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/fopen-safer.c b/contrib/tools/bison/lib/fopen-safer.c index 5d4a4a9e7530..bd363177659d 100644 --- a/contrib/tools/bison/lib/fopen-safer.c +++ b/contrib/tools/bison/lib/fopen-safer.c @@ -1,6 +1,6 @@ /* Invoke fopen, but avoid some glitches. - Copyright (C) 2001, 2004-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2004-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/fpending.c b/contrib/tools/bison/lib/fpending.c index 3c01285bb837..802ebcba6544 100644 --- a/contrib/tools/bison/lib/fpending.c +++ b/contrib/tools/bison/lib/fpending.c @@ -1,5 +1,5 @@ /* fpending.c -- return the number of pending output bytes on a stream - Copyright (C) 2000, 2004, 2006-2007, 2009-2019 Free Software Foundation, + Copyright (C) 2000, 2004, 2006-2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/fpending.h b/contrib/tools/bison/lib/fpending.h index 097a3ef0717f..a8b8859726d3 100644 --- a/contrib/tools/bison/lib/fpending.h +++ b/contrib/tools/bison/lib/fpending.h @@ -1,6 +1,6 @@ /* Declare __fpending. - Copyright (C) 2000, 2003, 2005-2006, 2009-2019 Free Software Foundation, + Copyright (C) 2000, 2003, 2005-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/fpucw.h b/contrib/tools/bison/lib/fpucw.h index caa51fe3bbbb..1c6edf6b7641 100644 --- a/contrib/tools/bison/lib/fpucw.h +++ b/contrib/tools/bison/lib/fpucw.h @@ -1,5 +1,5 @@ /* Manipulating the FPU control word. -*- coding: utf-8 -*- - Copyright (C) 2007-2019 Free Software Foundation, Inc. + Copyright (C) 2007-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify @@ -43,7 +43,7 @@ See Vincent Lefèvre's page https://www.vinc17.net/research/extended.en.html for a good explanation. - See http://www.uwsg.iu.edu/hypermail/linux/kernel/0103.0/0453.html for + See https://web.archive.org/web/20060905133417/http://www.uwsg.iu.edu/hypermail/linux/kernel/0103.0/0453.html some argumentation which setting should be the default. */ /* This header file provides the following facilities: @@ -70,12 +70,12 @@ typedef unsigned short fpucw_t; /* glibc calls this fpu_control_t */ # define FPU_PC_DOUBLE 0x200 /* glibc calls this _FPU_DOUBLE */ # define FPU_PC_EXTENDED 0x300 /* glibc calls this _FPU_EXTENDED */ -# define GET_FPUCW() \ +# define GET_FPUCW() __extension__ \ ({ fpucw_t _cw; \ __asm__ __volatile__ ("fnstcw %0" : "=m" (*&_cw)); \ _cw; \ }) -# define SET_FPUCW(word) \ +# define SET_FPUCW(word) __extension__ \ (void)({ fpucw_t _ncw = (word); \ __asm__ __volatile__ ("fldcw %0" : : "m" (*&_ncw)); \ }) diff --git a/contrib/tools/bison/lib/fseterr.c b/contrib/tools/bison/lib/fseterr.c index 8cd68e8ce7ff..8f32b7e5af2d 100644 --- a/contrib/tools/bison/lib/fseterr.c +++ b/contrib/tools/bison/lib/fseterr.c @@ -1,5 +1,5 @@ /* Set the error indicator of a stream. - Copyright (C) 2007-2019 Free Software Foundation, Inc. + Copyright (C) 2007-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/fseterr.h b/contrib/tools/bison/lib/fseterr.h index 7b57faa3d2e4..bbeb6619f97e 100644 --- a/contrib/tools/bison/lib/fseterr.h +++ b/contrib/tools/bison/lib/fseterr.h @@ -1,5 +1,5 @@ /* Set the error indicator of a stream. - Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/fstrcmp.c b/contrib/tools/bison/lib/fstrcmp.c new file mode 100644 index 000000000000..1a4fbfdf8de6 --- /dev/null +++ b/contrib/tools/bison/lib/fstrcmp.c @@ -0,0 +1,263 @@ +/* Functions to make fuzzy comparisons between strings + Copyright (C) 1988-1989, 1992-1993, 1995, 2001-2003, 2006, 2008-2020 Free + Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + + +#include + +/* Specification. */ +#include "fstrcmp.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "glthread/lock.h" +#include "glthread/tls.h" +#include "minmax.h" +#include "xalloc.h" + + +#define ELEMENT char +#define EQUAL(x,y) ((x) == (y)) +#define OFFSET ptrdiff_t +#define EXTRA_CONTEXT_FIELDS \ + /* The number of edits beyond which the computation can be aborted. */ \ + ptrdiff_t edit_count_limit; \ + /* The number of edits (= number of elements inserted, plus the number of \ + elements deleted), temporarily minus edit_count_limit. */ \ + ptrdiff_t edit_count; +#define NOTE_DELETE(ctxt, xoff) ctxt->edit_count++ +#define NOTE_INSERT(ctxt, yoff) ctxt->edit_count++ +#define EARLY_ABORT(ctxt) ctxt->edit_count > 0 +/* We don't need USE_HEURISTIC, since it is unlikely in typical uses of + fstrcmp(). */ +#include "diffseq.h" + + +/* Because fstrcmp is typically called multiple times, attempt to minimize + the number of memory allocations performed. Thus, let a call reuse the + memory already allocated by the previous call, if it is sufficient. + To make it multithread-safe, without need for a lock that protects the + already allocated memory, store the allocated memory per thread. Free + it only when the thread exits. */ + +static gl_tls_key_t buffer_key; /* TLS key for a 'ptrdiff_t *' */ +static gl_tls_key_t bufmax_key; /* TLS key for a 'uintptr_t' */ + +static void +keys_init (void) +{ + gl_tls_key_init (buffer_key, free); + gl_tls_key_init (bufmax_key, NULL); + /* The per-thread initial values are NULL and 0, respectively. */ +} + +/* Ensure that keys_init is called once only. */ +gl_once_define(static, keys_init_once) + +void +fstrcmp_free_resources (void) +{ + ptrdiff_t *buffer; + + gl_once (keys_init_once, keys_init); + buffer = gl_tls_get (buffer_key); + if (buffer != NULL) + { + gl_tls_set (buffer_key, NULL); + gl_tls_set (bufmax_key, (void *) (uintptr_t) 0); + free (buffer); + } +} + + +/* In the code below, branch probabilities were measured by Ralf Wildenhues, + by running "msgmerge LL.po coreutils.pot" with msgmerge 0.18 for many + values of LL. The probability indicates that the condition evaluates + to true; whether that leads to a branch or a non-branch in the code, + depends on the compiler's reordering of basic blocks. */ + + +double +fstrcmp_bounded (const char *string1, const char *string2, double lower_bound) +{ + struct context ctxt; + size_t xvec_length = strlen (string1); + size_t yvec_length = strlen (string2); + size_t length_sum = xvec_length + yvec_length; + ptrdiff_t i; + + ptrdiff_t fdiag_len; + ptrdiff_t *buffer; + uintptr_t bufmax; + + /* short-circuit obvious comparisons */ + if (xvec_length == 0 || yvec_length == 0) /* Prob: 1% */ + return length_sum == 0; + + if (! (xvec_length <= length_sum + && length_sum <= MIN (UINTPTR_MAX, PTRDIFF_MAX) - 3)) + xalloc_die (); + + if (lower_bound > 0) + { + /* Compute a quick upper bound. + Each edit is an insertion or deletion of an element, hence modifies + the length of the sequence by at most 1. + Therefore, when starting from a sequence X and ending at a sequence Y, + with N edits, | yvec_length - xvec_length | <= N. (Proof by + induction over N.) + So, at the end, we will have + edit_count >= | xvec_length - yvec_length |. + and hence + result + = (xvec_length + yvec_length - edit_count) + / (xvec_length + yvec_length) + <= (xvec_length + yvec_length - | yvec_length - xvec_length |) + / (xvec_length + yvec_length) + = 2 * min (xvec_length, yvec_length) / (xvec_length + yvec_length). + */ + ptrdiff_t length_min = MIN (xvec_length, yvec_length); + volatile double upper_bound = 2.0 * length_min / length_sum; + + if (upper_bound < lower_bound) /* Prob: 74% */ + /* Return an arbitrary value < LOWER_BOUND. */ + return 0.0; + +#if CHAR_BIT <= 8 + /* When X and Y are both small, avoid the overhead of setting up an + array of size 256. */ + if (length_sum >= 20) /* Prob: 99% */ + { + /* Compute a less quick upper bound. + Each edit is an insertion or deletion of a character, hence + modifies the occurrence count of a character by 1 and leaves the + other occurrence counts unchanged. + Therefore, when starting from a sequence X and ending at a + sequence Y, and denoting the occurrence count of C in X with + OCC (X, C), with N edits, + sum_C | OCC (X, C) - OCC (Y, C) | <= N. + (Proof by induction over N.) + So, at the end, we will have + edit_count >= sum_C | OCC (X, C) - OCC (Y, C) |, + and hence + result + = (xvec_length + yvec_length - edit_count) + / (xvec_length + yvec_length) + <= (xvec_length + yvec_length - sum_C | OCC(X,C) - OCC(Y,C) |) + / (xvec_length + yvec_length). + */ + ptrdiff_t occ_diff[UCHAR_MAX + 1]; /* array C -> OCC(X,C) - OCC(Y,C) */ + ptrdiff_t sum; + double dsum; + + /* Determine the occurrence counts in X. */ + memset (occ_diff, 0, sizeof (occ_diff)); + for (i = xvec_length - 1; i >= 0; i--) + occ_diff[(unsigned char) string1[i]]++; + /* Subtract the occurrence counts in Y. */ + for (i = yvec_length - 1; i >= 0; i--) + occ_diff[(unsigned char) string2[i]]--; + /* Sum up the absolute values. */ + sum = 0; + for (i = 0; i <= UCHAR_MAX; i++) + { + ptrdiff_t d = occ_diff[i]; + sum += (d >= 0 ? d : -d); + } + + dsum = sum; + upper_bound = 1.0 - dsum / length_sum; + + if (upper_bound < lower_bound) /* Prob: 66% */ + /* Return an arbitrary value < LOWER_BOUND. */ + return 0.0; + } +#endif + } + + /* set the info for each string. */ + ctxt.xvec = string1; + ctxt.yvec = string2; + + /* Set TOO_EXPENSIVE to be approximate square root of input size, + bounded below by 4096. */ + ctxt.too_expensive = 1; + for (i = xvec_length + yvec_length; i != 0; i >>= 2) + ctxt.too_expensive <<= 1; + if (ctxt.too_expensive < 4096) + ctxt.too_expensive = 4096; + + /* Allocate memory for fdiag and bdiag from a thread-local pool. */ + fdiag_len = length_sum + 3; + gl_once (keys_init_once, keys_init); + buffer = gl_tls_get (buffer_key); + bufmax = (uintptr_t) gl_tls_get (bufmax_key); + if (fdiag_len > bufmax) + { + /* Need more memory. */ + bufmax = 2 * bufmax; + if (fdiag_len > bufmax) + bufmax = fdiag_len; + /* Calling xrealloc would be a waste: buffer's contents does not need + to be preserved. */ + free (buffer); + buffer = xnmalloc (bufmax, 2 * sizeof *buffer); + gl_tls_set (buffer_key, buffer); + gl_tls_set (bufmax_key, (void *) (uintptr_t) bufmax); + } + ctxt.fdiag = buffer + yvec_length + 1; + ctxt.bdiag = ctxt.fdiag + fdiag_len; + + /* The edit_count is only ever increased. The computation can be aborted + when + (xvec_length + yvec_length - edit_count) / (xvec_length + yvec_length) + < lower_bound, + or equivalently + edit_count > (xvec_length + yvec_length) * (1 - lower_bound) + or equivalently + edit_count > floor((xvec_length + yvec_length) * (1 - lower_bound)). + We need to add an epsilon inside the floor(...) argument, to neutralize + rounding errors. */ + ctxt.edit_count_limit = + (lower_bound < 1.0 + ? (ptrdiff_t) (length_sum * (1.0 - lower_bound + 0.000001)) + : 0); + + /* Now do the main comparison algorithm */ + ctxt.edit_count = - ctxt.edit_count_limit; + if (compareseq (0, xvec_length, 0, yvec_length, 0, &ctxt)) /* Prob: 98% */ + /* The edit_count passed the limit. Hence the result would be + < lower_bound. We can return any value < lower_bound instead. */ + return 0.0; + ctxt.edit_count += ctxt.edit_count_limit; + + /* The result is + ((number of chars in common) / (average length of the strings)). + The numerator is + = xvec_length - (number of calls to NOTE_DELETE) + = yvec_length - (number of calls to NOTE_INSERT) + = 1/2 * (xvec_length + yvec_length - (number of edits)). + This is admittedly biased towards finding that the strings are + similar, however it does produce meaningful results. */ + return ((double) (xvec_length + yvec_length - ctxt.edit_count) + / (xvec_length + yvec_length)); +} diff --git a/contrib/tools/bison/lib/fstrcmp.h b/contrib/tools/bison/lib/fstrcmp.h new file mode 100644 index 000000000000..37df588a3edc --- /dev/null +++ b/contrib/tools/bison/lib/fstrcmp.h @@ -0,0 +1,54 @@ +/* Fuzzy string comparison. + Copyright (C) 1995, 2000, 2002-2003, 2006, 2008-2020 Free Software + Foundation, Inc. + + This file was written by Peter Miller + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . */ + +#ifndef _FSTRCMP_H +#define _FSTRCMP_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Fuzzy compare of S1 and S2. Return a measure for the similarity of S1 + and S1. The higher the result, the more similar the strings are. + The result is bounded between 0 (meaning very dissimilar strings) and + 1 (meaning identical strings). */ +extern double fstrcmp (const char *s1, const char *s2); + +/* Like fstrcmp (S1, S2), except that if the result is < LOWER_BOUND, an + arbitrary other value < LOWER_BOUND can be returned. */ +extern double fstrcmp_bounded (const char *s1, const char *s2, + double lower_bound); + +/* A shortcut for fstrcmp. Avoids a function call. */ +#define fstrcmp(s1,s2) fstrcmp_bounded (s1, s2, 0.0) + +/* Frees the per-thread resources allocated by this module for the current + thread. + You don't need to call this function in threads other than the main thread, + because per-thread resources are reclaimed automatically when the thread + exits. However, per-thread resources allocated by the main thread are + comparable to static allocations; calling this function can be useful to + avoid an error report from valgrind. */ +extern void fstrcmp_free_resources (void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/contrib/tools/bison/lib/get-errno.c b/contrib/tools/bison/lib/get-errno.c index 36e07adaff77..ef3b71b4fb4f 100644 --- a/contrib/tools/bison/lib/get-errno.c +++ b/contrib/tools/bison/lib/get-errno.c @@ -1,6 +1,6 @@ /* get-errno.c - get and set errno. - Copyright (C) 2002, 2006, 2009-2015, 2018-2019 Free Software + Copyright (C) 2002, 2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/get-errno.h b/contrib/tools/bison/lib/get-errno.h index c13ac6b319c2..b6550852f561 100644 --- a/contrib/tools/bison/lib/get-errno.h +++ b/contrib/tools/bison/lib/get-errno.h @@ -1,6 +1,6 @@ /* get-errno.h - get and set errno. - Copyright (C) 2002, 2009-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2002, 2009-2015, 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/getdtablesize.c b/contrib/tools/bison/lib/getdtablesize.c index 03a92435f0b3..0fe70921f9d7 100644 --- a/contrib/tools/bison/lib/getdtablesize.c +++ b/contrib/tools/bison/lib/getdtablesize.c @@ -1,5 +1,5 @@ /* getdtablesize() function: Return maximum possible file descriptor value + 1. - Copyright (C) 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2008-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2008. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/gethrxtime.c b/contrib/tools/bison/lib/gethrxtime.c index 877596257a07..88342cb1026e 100644 --- a/contrib/tools/bison/lib/gethrxtime.c +++ b/contrib/tools/bison/lib/gethrxtime.c @@ -1,6 +1,6 @@ /* gethrxtime -- get high resolution real time - Copyright (C) 2005-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2005-2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/gethrxtime.h b/contrib/tools/bison/lib/gethrxtime.h index 6491794554d0..44973397b543 100644 --- a/contrib/tools/bison/lib/gethrxtime.h +++ b/contrib/tools/bison/lib/gethrxtime.h @@ -1,6 +1,6 @@ /* gethrxtime -- get high resolution real time - Copyright (C) 2005, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2005, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/getopt.c b/contrib/tools/bison/lib/getopt.c index 8ee075a8091c..a6389d8ea9bb 100644 --- a/contrib/tools/bison/lib/getopt.c +++ b/contrib/tools/bison/lib/getopt.c @@ -1,5 +1,5 @@ /* Getopt for GNU. - Copyright (C) 1987-2019 Free Software Foundation, Inc. + Copyright (C) 1987-2020 Free Software Foundation, Inc. This file is part of the GNU C Library and is also part of gnulib. Patches to this file should be submitted to both projects. diff --git a/contrib/tools/bison/lib/getopt1.c b/contrib/tools/bison/lib/getopt1.c index 883aa6bbc916..0902efe68e38 100644 --- a/contrib/tools/bison/lib/getopt1.c +++ b/contrib/tools/bison/lib/getopt1.c @@ -1,5 +1,5 @@ /* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987-2019 Free Software Foundation, Inc. + Copyright (C) 1987-2020 Free Software Foundation, Inc. This file is part of the GNU C Library and is also part of gnulib. Patches to this file should be submitted to both projects. diff --git a/contrib/tools/bison/lib/getopt_int.h b/contrib/tools/bison/lib/getopt_int.h index e63706f60ea3..afcd8a67fb2a 100644 --- a/contrib/tools/bison/lib/getopt_int.h +++ b/contrib/tools/bison/lib/getopt_int.h @@ -1,5 +1,5 @@ /* Internal declarations for getopt. - Copyright (C) 1989-2019 Free Software Foundation, Inc. + Copyright (C) 1989-2020 Free Software Foundation, Inc. This file is part of the GNU C Library and is also part of gnulib. Patches to this file should be submitted to both projects. diff --git a/contrib/tools/bison/lib/getprogname.c b/contrib/tools/bison/lib/getprogname.c index 50fe23cb890e..7507e0d7579c 100644 --- a/contrib/tools/bison/lib/getprogname.c +++ b/contrib/tools/bison/lib/getprogname.c @@ -1,5 +1,5 @@ /* Program name management. - Copyright (C) 2016-2019 Free Software Foundation, Inc. + Copyright (C) 2016-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -70,10 +70,10 @@ getprogname (void) p = "?"; return last_component (p); # elif HAVE_DECL___ARGV /* mingw, MSVC */ - /* https://msdn.microsoft.com/en-us/library/dn727674.aspx */ + /* https://docs.microsoft.com/en-us/cpp/c-runtime-library/argc-argv-wargv */ const char *p = __argv && __argv[0] ? __argv[0] : "?"; return last_component (p); -# elif HAVE_VAR___PROGNAME /* OpenBSD, QNX */ +# elif HAVE_VAR___PROGNAME /* OpenBSD, Android, QNX */ /* https://man.openbsd.org/style.9 */ /* http://www.qnx.de/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.neutrino_lib_ref%2Fp%2F__progname.html */ /* Be careful to declare this only when we absolutely need it @@ -82,7 +82,11 @@ getprogname (void) malfunction (have zero length) with Fedora 25's glibc. */ extern char *__progname; const char *p = __progname; +# if defined __ANDROID__ + return last_component (p); +# else return p && p[0] ? p : "?"; +# endif # elif _AIX /* AIX */ /* Idea by Bastien ROUCARIÈS, https://lists.gnu.org/r/bug-gnulib/2010-12/msg00095.html @@ -229,12 +233,13 @@ getprogname (void) { char *name = buf.pr_fname; size_t namesize = sizeof buf.pr_fname; + /* It may not be NUL-terminated. */ char *namenul = memchr (name, '\0', namesize); size_t namelen = namenul ? namenul - name : namesize; char *namecopy = malloc (namelen + 1); if (namecopy) { - namecopy[namelen] = 0; + namecopy[namelen] = '\0'; return memcpy (namecopy, name, namelen); } } diff --git a/contrib/tools/bison/lib/getprogname.h b/contrib/tools/bison/lib/getprogname.h index 1590b38d3f14..676912b4b84c 100644 --- a/contrib/tools/bison/lib/getprogname.h +++ b/contrib/tools/bison/lib/getprogname.h @@ -1,5 +1,5 @@ /* Program name management. - Copyright (C) 2016-2019 Free Software Foundation, Inc. + Copyright (C) 2016-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/gettext.h b/contrib/tools/bison/lib/gettext.h index c7c0fdb53116..0bd1e13348a7 100644 --- a/contrib/tools/bison/lib/gettext.h +++ b/contrib/tools/bison/lib/gettext.h @@ -1,5 +1,5 @@ /* Convenience header for conditional use of GNU . - Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2019 Free Software + Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/gl_array_list.c b/contrib/tools/bison/lib/gl_array_list.c index 4ac743fde4fa..49509620f735 100644 --- a/contrib/tools/bison/lib/gl_array_list.c +++ b/contrib/tools/bison/lib/gl_array_list.c @@ -1,5 +1,5 @@ /* Sequential list data type implemented by an array. - Copyright (C) 2006-2019 Free Software Foundation, Inc. + Copyright (C) 2006-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2006. This program is free software: you can redistribute it and/or modify @@ -20,6 +20,7 @@ /* Specification. */ #include "gl_array_list.h" +#include #include /* Get memcpy. */ #include @@ -27,10 +28,6 @@ /* Checked size_t computations. */ #include "xsize.h" -#ifndef uintptr_t -# define uintptr_t unsigned long -#endif - /* -------------------------- gl_list_t Data Type -------------------------- */ /* Concrete gl_list_impl type, valid for this file only. */ diff --git a/contrib/tools/bison/lib/gl_array_list.h b/contrib/tools/bison/lib/gl_array_list.h index 98158feb1b1c..8dd48bd36509 100644 --- a/contrib/tools/bison/lib/gl_array_list.h +++ b/contrib/tools/bison/lib/gl_array_list.h @@ -1,5 +1,5 @@ /* Sequential list data type implemented by an array. - Copyright (C) 2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2006, 2009-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2006. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/gl_list.h b/contrib/tools/bison/lib/gl_list.h index 5f2cade22cce..39d14401f96d 100644 --- a/contrib/tools/bison/lib/gl_list.h +++ b/contrib/tools/bison/lib/gl_list.h @@ -1,5 +1,5 @@ /* Abstract sequential list data type. -*- coding: utf-8 -*- - Copyright (C) 2006-2019 Free Software Foundation, Inc. + Copyright (C) 2006-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2006. This program is free software: you can redistribute it and/or modify @@ -130,7 +130,7 @@ typedef const struct gl_list_implementation * gl_list_implementation_t; #if 0 /* Unless otherwise specified, these are defined inline below. */ -/* Create an empty list. +/* Creates an empty list. IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST, GL_AVLTREE_LIST, GL_RBTREE_LIST, GL_LINKEDHASH_LIST, GL_AVLTREEHASH_LIST, GL_RBTREEHASH_LIST. @@ -145,14 +145,14 @@ extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation, gl_listelement_hashcode_fn hashcode_fn, gl_listelement_dispose_fn dispose_fn, bool allow_duplicates); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_t gl_list_nx_create_empty (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, gl_listelement_dispose_fn dispose_fn, bool allow_duplicates); -/* Create a list with given contents. +/* Creates a list with given contents. IMPLEMENTATION is one of GL_ARRAY_LIST, GL_CARRAY_LIST, GL_LINKED_LIST, GL_AVLTREE_LIST, GL_RBTREE_LIST, GL_LINKEDHASH_LIST, GL_AVLTREEHASH_LIST, GL_RBTREEHASH_LIST. @@ -170,7 +170,7 @@ extern gl_list_t gl_list_create (gl_list_implementation_t implementation, gl_listelement_dispose_fn dispose_fn, bool allow_duplicates, size_t count, const void **contents); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_t gl_list_nx_create (gl_list_implementation_t implementation, gl_listelement_equals_fn equals_fn, gl_listelement_hashcode_fn hashcode_fn, @@ -178,17 +178,17 @@ extern gl_list_t gl_list_nx_create (gl_list_implementation_t implementation, bool allow_duplicates, size_t count, const void **contents); -/* Return the current number of elements in a list. */ +/* Returns the current number of elements in a list. */ extern size_t gl_list_size (gl_list_t list); -/* Return the element value represented by a list node. */ +/* Returns the element value represented by a list node. */ extern const void * gl_list_node_value (gl_list_t list, gl_list_node_t node); -/* Replace the element value represented by a list node. */ +/* Replaces the element value represented by a list node. */ /* declared in gl_xlist.h */ extern void gl_list_node_set_value (gl_list_t list, gl_list_node_t node, const void *elt); -/* Likewise. Return 0 upon success, -1 upon out-of-memory. */ +/* Likewise. Returns 0 upon success, -1 upon out-of-memory. */ extern int gl_list_node_nx_set_value (gl_list_t list, gl_list_node_t node, const void *elt) #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) @@ -196,25 +196,25 @@ extern int gl_list_node_nx_set_value (gl_list_t list, gl_list_node_t node, #endif ; -/* Return the node immediately after the given node in the list, or NULL +/* Returns the node immediately after the given node in the list, or NULL if the given node is the last (rightmost) one in the list. */ extern gl_list_node_t gl_list_next_node (gl_list_t list, gl_list_node_t node); -/* Return the node immediately before the given node in the list, or NULL +/* Returns the node immediately before the given node in the list, or NULL if the given node is the first (leftmost) one in the list. */ extern gl_list_node_t gl_list_previous_node (gl_list_t list, gl_list_node_t node); -/* Return the element at a given position in the list. +/* Returns the element at a given position in the list. POSITION must be >= 0 and < gl_list_size (list). */ extern const void * gl_list_get_at (gl_list_t list, size_t position); -/* Replace the element at a given position in the list. +/* Replaces the element at a given position in the list. POSITION must be >= 0 and < gl_list_size (list). - Return its node. */ + Returns its node. */ /* declared in gl_xlist.h */ extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position, const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_node_t gl_list_nx_set_at (gl_list_t list, size_t position, const void *elt) #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) @@ -222,69 +222,69 @@ extern gl_list_node_t gl_list_nx_set_at (gl_list_t list, size_t position, #endif ; -/* Search whether an element is already in the list. - Return its node if found, or NULL if not present in the list. */ +/* Searches whether an element is already in the list. + Returns its node if found, or NULL if not present in the list. */ extern gl_list_node_t gl_list_search (gl_list_t list, const void *elt); -/* Search whether an element is already in the list, +/* Searches whether an element is already in the list, at a position >= START_INDEX. - Return its node if found, or NULL if not present in the list. */ + Returns its node if found, or NULL if not present in the list. */ extern gl_list_node_t gl_list_search_from (gl_list_t list, size_t start_index, const void *elt); -/* Search whether an element is already in the list, +/* Searches whether an element is already in the list, at a position >= START_INDEX and < END_INDEX. - Return its node if found, or NULL if not present in the list. */ + Returns its node if found, or NULL if not present in the list. */ extern gl_list_node_t gl_list_search_from_to (gl_list_t list, size_t start_index, size_t end_index, const void *elt); -/* Search whether an element is already in the list. - Return its position if found, or (size_t)(-1) if not present in the list. */ +/* Searches whether an element is already in the list. + Returns its position if found, or (size_t)(-1) if not present in the list. */ extern size_t gl_list_indexof (gl_list_t list, const void *elt); -/* Search whether an element is already in the list, +/* Searches whether an element is already in the list, at a position >= START_INDEX. - Return its position if found, or (size_t)(-1) if not present in the list. */ + Returns its position if found, or (size_t)(-1) if not present in the list. */ extern size_t gl_list_indexof_from (gl_list_t list, size_t start_index, const void *elt); -/* Search whether an element is already in the list, +/* Searches whether an element is already in the list, at a position >= START_INDEX and < END_INDEX. - Return its position if found, or (size_t)(-1) if not present in the list. */ + Returns its position if found, or (size_t)(-1) if not present in the list. */ extern size_t gl_list_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, const void *elt); -/* Add an element as the first element of the list. - Return its node. */ +/* Adds an element as the first element of the list. + Returns its node. */ /* declared in gl_xlist.h */ extern gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_node_t gl_list_nx_add_first (gl_list_t list, const void *elt) #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) __attribute__ ((__warn_unused_result__)) #endif ; -/* Add an element as the last element of the list. - Return its node. */ +/* Adds an element as the last element of the list. + Returns its node. */ /* declared in gl_xlist.h */ extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_node_t gl_list_nx_add_last (gl_list_t list, const void *elt) #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) __attribute__ ((__warn_unused_result__)) #endif ; -/* Add an element before a given element node of the list. - Return its node. */ +/* Adds an element before a given element node of the list. + Returns its node. */ /* declared in gl_xlist.h */ extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_node_t gl_list_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt) @@ -293,12 +293,12 @@ extern gl_list_node_t gl_list_nx_add_before (gl_list_t list, #endif ; -/* Add an element after a given element node of the list. - Return its node. */ +/* Adds an element after a given element node of the list. + Returns its node. */ /* declared in gl_xlist.h */ extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_node_t gl_list_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt) #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) @@ -306,12 +306,12 @@ extern gl_list_node_t gl_list_nx_add_after (gl_list_t list, gl_list_node_t node, #endif ; -/* Add an element at a given position in the list. +/* Adds an element at a given position in the list. POSITION must be >= 0 and <= gl_list_size (list). */ /* declared in gl_xlist.h */ extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position, const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_node_t gl_list_nx_add_at (gl_list_t list, size_t position, const void *elt) #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) @@ -319,20 +319,20 @@ extern gl_list_node_t gl_list_nx_add_at (gl_list_t list, size_t position, #endif ; -/* Remove an element from the list. - Return true. */ +/* Removes an element from the list. + Returns true. */ extern bool gl_list_remove_node (gl_list_t list, gl_list_node_t node); -/* Remove an element at a given position from the list. +/* Removes an element at a given position from the list. POSITION must be >= 0 and < gl_list_size (list). - Return true. */ + Returns true. */ extern bool gl_list_remove_at (gl_list_t list, size_t position); -/* Search and remove an element from the list. - Return true if it was found and removed. */ +/* Searches and removes an element from the list. + Returns true if it was found and removed. */ extern bool gl_list_remove (gl_list_t list, const void *elt); -/* Free an entire list. +/* Frees an entire list. (But this call does not free the elements of the list. It only invokes the DISPOSE_FN on each of the elements of the list, and only if the list is not a sublist.) */ @@ -361,12 +361,12 @@ typedef struct #if 0 /* These are defined inline below. */ -/* Create an iterator traversing a list. +/* Creates an iterator traversing a list. The list contents must not be modified while the iterator is in use, except for replacing or removing the last returned element. */ extern gl_list_iterator_t gl_list_iterator (gl_list_t list); -/* Create an iterator traversing the element with indices i, +/* Creates an iterator traversing the element with indices i, start_index <= i < end_index, of a list. The list contents must not be modified while the iterator is in use, except for replacing or removing the last returned element. */ @@ -374,13 +374,13 @@ extern gl_list_iterator_t gl_list_iterator_from_to (gl_list_t list, size_t start_index, size_t end_index); -/* If there is a next element, store the next element in *ELTP, store its - node in *NODEP if NODEP is non-NULL, advance the iterator and return true. - Otherwise, return false. */ +/* If there is a next element, stores the next element in *ELTP, stores its + node in *NODEP if NODEP is non-NULL, advances the iterator and returns true. + Otherwise, returns false. */ extern bool gl_list_iterator_next (gl_list_iterator_t *iterator, const void **eltp, gl_list_node_t *nodep); -/* Free an iterator. */ +/* Frees an iterator. */ extern void gl_list_iterator_free (gl_list_iterator_t *iterator); #endif /* End of inline functions. */ @@ -396,21 +396,21 @@ typedef int (*gl_listelement_compar_fn) (const void *elt1, const void *elt2); #if 0 /* Unless otherwise specified, these are defined inline below. */ -/* Search whether an element is already in the list. +/* Searches whether an element is already in the list. The list is assumed to be sorted with COMPAR. - Return its node if found, or NULL if not present in the list. + Returns its node if found, or NULL if not present in the list. If the list contains several copies of ELT, the node of the leftmost one is returned. */ extern gl_list_node_t gl_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, const void *elt); -/* Search whether an element is already in the list. +/* Searches whether an element is already in the list. The list is assumed to be sorted with COMPAR. Only list elements with indices >= START_INDEX and < END_INDEX are considered; the implementation uses these bounds to minimize the number of COMPAR invocations. - Return its node if found, or NULL if not present in the list. + Returns its node if found, or NULL if not present in the list. If the list contains several copies of ELT, the node of the leftmost one is returned. */ extern gl_list_node_t gl_sortedlist_search_from_to (gl_list_t list, @@ -419,21 +419,21 @@ extern gl_list_node_t gl_sortedlist_search_from_to (gl_list_t list, size_t end_index, const void *elt); -/* Search whether an element is already in the list. +/* Searches whether an element is already in the list. The list is assumed to be sorted with COMPAR. - Return its position if found, or (size_t)(-1) if not present in the list. + Returns its position if found, or (size_t)(-1) if not present in the list. If the list contains several copies of ELT, the position of the leftmost one is returned. */ extern size_t gl_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, const void *elt); -/* Search whether an element is already in the list. +/* Searches whether an element is already in the list. The list is assumed to be sorted with COMPAR. Only list elements with indices >= START_INDEX and < END_INDEX are considered; the implementation uses these bounds to minimize the number of COMPAR invocations. - Return its position if found, or (size_t)(-1) if not present in the list. + Returns its position if found, or (size_t)(-1) if not present in the list. If the list contains several copies of ELT, the position of the leftmost one is returned. */ extern size_t gl_sortedlist_indexof_from_to (gl_list_t list, @@ -442,14 +442,14 @@ extern size_t gl_sortedlist_indexof_from_to (gl_list_t list, size_t end_index, const void *elt); -/* Add an element at the appropriate position in the list. +/* Adds an element at the appropriate position in the list. The list is assumed to be sorted with COMPAR. - Return its node. */ + Returns its node. */ /* declared in gl_xlist.h */ extern gl_list_node_t gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, const void *elt); -/* Likewise. Return NULL upon out-of-memory. */ +/* Likewise. Returns NULL upon out-of-memory. */ extern gl_list_node_t gl_sortedlist_nx_add (gl_list_t list, gl_listelement_compar_fn compar, const void *elt) @@ -458,9 +458,9 @@ extern gl_list_node_t gl_sortedlist_nx_add (gl_list_t list, #endif ; -/* Search and remove an element from the list. +/* Searches and removes an element from the list. The list is assumed to be sorted with COMPAR. - Return true if it was found and removed. + Returns true if it was found and removed. If the list contains several copies of ELT, only the leftmost one is removed. */ extern bool gl_sortedlist_remove (gl_list_t list, diff --git a/contrib/tools/bison/lib/gl_xlist.h b/contrib/tools/bison/lib/gl_xlist.h index 87885c33c81e..ef6b93f6a50d 100644 --- a/contrib/tools/bison/lib/gl_xlist.h +++ b/contrib/tools/bison/lib/gl_xlist.h @@ -1,5 +1,5 @@ /* Abstract sequential list data type, with out-of-memory checking. - Copyright (C) 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/glthread/lock.c b/contrib/tools/bison/lib/glthread/lock.c new file mode 100644 index 000000000000..10af6f2e1f07 --- /dev/null +++ b/contrib/tools/bison/lib/glthread/lock.c @@ -0,0 +1,749 @@ +/* Locking in multithreaded situations. + Copyright (C) 2005-2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Bruno Haible , 2005. + Based on GCC's gthr-posix.h, gthr-posix95.h. */ + +#include + +#include "glthread/lock.h" + +/* ========================================================================= */ + +#if USE_ISOC_THREADS || USE_ISOC_AND_POSIX_THREADS + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +int +glthread_lock_init (gl_lock_t *lock) +{ + if (mtx_init (&lock->mutex, mtx_plain) != thrd_success) + return ENOMEM; + lock->init_needed = 0; + return 0; +} + +int +glthread_lock_lock (gl_lock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + if (mtx_lock (&lock->mutex) != thrd_success) + return EAGAIN; + return 0; +} + +int +glthread_lock_unlock (gl_lock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + if (mtx_unlock (&lock->mutex) != thrd_success) + return EINVAL; + return 0; +} + +int +glthread_lock_destroy (gl_lock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + mtx_destroy (&lock->mutex); + return 0; +} + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +int +glthread_rwlock_init (gl_rwlock_t *lock) +{ + if (mtx_init (&lock->lock, mtx_plain) != thrd_success + || cnd_init (&lock->waiting_readers) != thrd_success + || cnd_init (&lock->waiting_writers) != thrd_success) + return ENOMEM; + lock->waiting_writers_count = 0; + lock->runcount = 0; + lock->init_needed = 0; + return 0; +} + +int +glthread_rwlock_rdlock (gl_rwlock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + if (mtx_lock (&lock->lock) != thrd_success) + return EAGAIN; + /* Test whether only readers are currently running, and whether the runcount + field will not overflow, and whether no writer is waiting. The latter + condition is because POSIX recommends that "write locks shall take + precedence over read locks", to avoid "writer starvation". */ + while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_readers. */ + if (cnd_wait (&lock->waiting_readers, &lock->lock) != thrd_success) + { + mtx_unlock (&lock->lock); + return EINVAL; + } + } + lock->runcount++; + if (mtx_unlock (&lock->lock) != thrd_success) + return EINVAL; + return 0; +} + +int +glthread_rwlock_wrlock (gl_rwlock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + if (mtx_lock (&lock->lock) != thrd_success) + return EAGAIN; + /* Test whether no readers or writers are currently running. */ + while (!(lock->runcount == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_writers. */ + lock->waiting_writers_count++; + if (cnd_wait (&lock->waiting_writers, &lock->lock) != thrd_success) + { + lock->waiting_writers_count--; + mtx_unlock (&lock->lock); + return EINVAL; + } + lock->waiting_writers_count--; + } + lock->runcount--; /* runcount becomes -1 */ + if (mtx_unlock (&lock->lock) != thrd_success) + return EINVAL; + return 0; +} + +int +glthread_rwlock_unlock (gl_rwlock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + if (mtx_lock (&lock->lock) != thrd_success) + return EAGAIN; + if (lock->runcount < 0) + { + /* Drop a writer lock. */ + if (!(lock->runcount == -1)) + { + mtx_unlock (&lock->lock); + return EINVAL; + } + lock->runcount = 0; + } + else + { + /* Drop a reader lock. */ + if (!(lock->runcount > 0)) + { + mtx_unlock (&lock->lock); + return EINVAL; + } + lock->runcount--; + } + if (lock->runcount == 0) + { + /* POSIX recommends that "write locks shall take precedence over read + locks", to avoid "writer starvation". */ + if (lock->waiting_writers_count > 0) + { + /* Wake up one of the waiting writers. */ + if (cnd_signal (&lock->waiting_writers) != thrd_success) + { + mtx_unlock (&lock->lock); + return EINVAL; + } + } + else + { + /* Wake up all waiting readers. */ + if (cnd_broadcast (&lock->waiting_readers) != thrd_success) + { + mtx_unlock (&lock->lock); + return EINVAL; + } + } + } + if (mtx_unlock (&lock->lock) != thrd_success) + return EINVAL; + return 0; +} + +int +glthread_rwlock_destroy (gl_rwlock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + mtx_destroy (&lock->lock); + cnd_destroy (&lock->waiting_readers); + cnd_destroy (&lock->waiting_writers); + return 0; +} + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +int +glthread_recursive_lock_init (gl_recursive_lock_t *lock) +{ + if (mtx_init (&lock->mutex, mtx_plain | mtx_recursive) != thrd_success) + return ENOMEM; + lock->init_needed = 0; + return 0; +} + +int +glthread_recursive_lock_lock (gl_recursive_lock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + if (mtx_lock (&lock->mutex) != thrd_success) + return EAGAIN; + return 0; +} + +int +glthread_recursive_lock_unlock (gl_recursive_lock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + if (mtx_unlock (&lock->mutex) != thrd_success) + return EINVAL; + return 0; +} + +int +glthread_recursive_lock_destroy (gl_recursive_lock_t *lock) +{ + if (lock->init_needed) + call_once (&lock->init_once, lock->init_func); + mtx_destroy (&lock->mutex); + return 0; +} + +/* -------------------------- gl_once_t datatype -------------------------- */ + +#endif + +/* ========================================================================= */ + +#if USE_POSIX_THREADS + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +# if HAVE_PTHREAD_RWLOCK && (HAVE_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER || (defined PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP && (__GNU_LIBRARY__ > 1))) + +# if defined PTHREAD_RWLOCK_INITIALIZER || defined PTHREAD_RWLOCK_INITIALIZER_NP + +# if !HAVE_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER + /* glibc with bug https://sourceware.org/bugzilla/show_bug.cgi?id=13701 */ + +int +glthread_rwlock_init_for_glibc (pthread_rwlock_t *lock) +{ + pthread_rwlockattr_t attributes; + int err; + + err = pthread_rwlockattr_init (&attributes); + if (err != 0) + return err; + /* Note: PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP is the only value that + causes the writer to be preferred. PTHREAD_RWLOCK_PREFER_WRITER_NP does not + do this; see + http://man7.org/linux/man-pages/man3/pthread_rwlockattr_setkind_np.3.html */ + err = pthread_rwlockattr_setkind_np (&attributes, + PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP); + if (err == 0) + err = pthread_rwlock_init(lock, &attributes); + /* pthread_rwlockattr_destroy always returns 0. It cannot influence the + return value. */ + pthread_rwlockattr_destroy (&attributes); + return err; +} + +# endif +# else + +int +glthread_rwlock_init_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_rwlock_init (&lock->rwlock, NULL); + if (err != 0) + return err; + lock->initialized = 1; + return 0; +} + +int +glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) +{ + if (!lock->initialized) + { + int err; + + err = pthread_mutex_lock (&lock->guard); + if (err != 0) + return err; + if (!lock->initialized) + { + err = glthread_rwlock_init_multithreaded (lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->guard); + return err; + } + } + err = pthread_mutex_unlock (&lock->guard); + if (err != 0) + return err; + } + return pthread_rwlock_rdlock (&lock->rwlock); +} + +int +glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) +{ + if (!lock->initialized) + { + int err; + + err = pthread_mutex_lock (&lock->guard); + if (err != 0) + return err; + if (!lock->initialized) + { + err = glthread_rwlock_init_multithreaded (lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->guard); + return err; + } + } + err = pthread_mutex_unlock (&lock->guard); + if (err != 0) + return err; + } + return pthread_rwlock_wrlock (&lock->rwlock); +} + +int +glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) +{ + if (!lock->initialized) + return EINVAL; + return pthread_rwlock_unlock (&lock->rwlock); +} + +int +glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock) +{ + int err; + + if (!lock->initialized) + return EINVAL; + err = pthread_rwlock_destroy (&lock->rwlock); + if (err != 0) + return err; + lock->initialized = 0; + return 0; +} + +# endif + +# else + +int +glthread_rwlock_init_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_init (&lock->lock, NULL); + if (err != 0) + return err; + err = pthread_cond_init (&lock->waiting_readers, NULL); + if (err != 0) + return err; + err = pthread_cond_init (&lock->waiting_writers, NULL); + if (err != 0) + return err; + lock->waiting_writers_count = 0; + lock->runcount = 0; + return 0; +} + +int +glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_lock (&lock->lock); + if (err != 0) + return err; + /* Test whether only readers are currently running, and whether the runcount + field will not overflow, and whether no writer is waiting. The latter + condition is because POSIX recommends that "write locks shall take + precedence over read locks", to avoid "writer starvation". */ + while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_readers. */ + err = pthread_cond_wait (&lock->waiting_readers, &lock->lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->lock); + return err; + } + } + lock->runcount++; + return pthread_mutex_unlock (&lock->lock); +} + +int +glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_lock (&lock->lock); + if (err != 0) + return err; + /* Test whether no readers or writers are currently running. */ + while (!(lock->runcount == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_writers. */ + lock->waiting_writers_count++; + err = pthread_cond_wait (&lock->waiting_writers, &lock->lock); + if (err != 0) + { + lock->waiting_writers_count--; + pthread_mutex_unlock (&lock->lock); + return err; + } + lock->waiting_writers_count--; + } + lock->runcount--; /* runcount becomes -1 */ + return pthread_mutex_unlock (&lock->lock); +} + +int +glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_lock (&lock->lock); + if (err != 0) + return err; + if (lock->runcount < 0) + { + /* Drop a writer lock. */ + if (!(lock->runcount == -1)) + { + pthread_mutex_unlock (&lock->lock); + return EINVAL; + } + lock->runcount = 0; + } + else + { + /* Drop a reader lock. */ + if (!(lock->runcount > 0)) + { + pthread_mutex_unlock (&lock->lock); + return EINVAL; + } + lock->runcount--; + } + if (lock->runcount == 0) + { + /* POSIX recommends that "write locks shall take precedence over read + locks", to avoid "writer starvation". */ + if (lock->waiting_writers_count > 0) + { + /* Wake up one of the waiting writers. */ + err = pthread_cond_signal (&lock->waiting_writers); + if (err != 0) + { + pthread_mutex_unlock (&lock->lock); + return err; + } + } + else + { + /* Wake up all waiting readers. */ + err = pthread_cond_broadcast (&lock->waiting_readers); + if (err != 0) + { + pthread_mutex_unlock (&lock->lock); + return err; + } + } + } + return pthread_mutex_unlock (&lock->lock); +} + +int +glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_destroy (&lock->lock); + if (err != 0) + return err; + err = pthread_cond_destroy (&lock->waiting_readers); + if (err != 0) + return err; + err = pthread_cond_destroy (&lock->waiting_writers); + if (err != 0) + return err; + return 0; +} + +# endif + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +# if HAVE_PTHREAD_MUTEX_RECURSIVE + +# if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP + +int +glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) +{ + pthread_mutexattr_t attributes; + int err; + + err = pthread_mutexattr_init (&attributes); + if (err != 0) + return err; + err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE); + if (err != 0) + { + pthread_mutexattr_destroy (&attributes); + return err; + } + err = pthread_mutex_init (lock, &attributes); + if (err != 0) + { + pthread_mutexattr_destroy (&attributes); + return err; + } + err = pthread_mutexattr_destroy (&attributes); + if (err != 0) + return err; + return 0; +} + +# else + +int +glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) +{ + pthread_mutexattr_t attributes; + int err; + + err = pthread_mutexattr_init (&attributes); + if (err != 0) + return err; + err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE); + if (err != 0) + { + pthread_mutexattr_destroy (&attributes); + return err; + } + err = pthread_mutex_init (&lock->recmutex, &attributes); + if (err != 0) + { + pthread_mutexattr_destroy (&attributes); + return err; + } + err = pthread_mutexattr_destroy (&attributes); + if (err != 0) + return err; + lock->initialized = 1; + return 0; +} + +int +glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) +{ + if (!lock->initialized) + { + int err; + + err = pthread_mutex_lock (&lock->guard); + if (err != 0) + return err; + if (!lock->initialized) + { + err = glthread_recursive_lock_init_multithreaded (lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->guard); + return err; + } + } + err = pthread_mutex_unlock (&lock->guard); + if (err != 0) + return err; + } + return pthread_mutex_lock (&lock->recmutex); +} + +int +glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) +{ + if (!lock->initialized) + return EINVAL; + return pthread_mutex_unlock (&lock->recmutex); +} + +int +glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) +{ + int err; + + if (!lock->initialized) + return EINVAL; + err = pthread_mutex_destroy (&lock->recmutex); + if (err != 0) + return err; + lock->initialized = 0; + return 0; +} + +# endif + +# else + +int +glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) +{ + int err; + + err = pthread_mutex_init (&lock->mutex, NULL); + if (err != 0) + return err; + lock->owner = (pthread_t) 0; + lock->depth = 0; + return 0; +} + +int +glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) +{ + pthread_t self = pthread_self (); + if (lock->owner != self) + { + int err; + + err = pthread_mutex_lock (&lock->mutex); + if (err != 0) + return err; + lock->owner = self; + } + if (++(lock->depth) == 0) /* wraparound? */ + { + lock->depth--; + return EAGAIN; + } + return 0; +} + +int +glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) +{ + if (lock->owner != pthread_self ()) + return EPERM; + if (lock->depth == 0) + return EINVAL; + if (--(lock->depth) == 0) + { + lock->owner = (pthread_t) 0; + return pthread_mutex_unlock (&lock->mutex); + } + else + return 0; +} + +int +glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) +{ + if (lock->owner != (pthread_t) 0) + return EBUSY; + return pthread_mutex_destroy (&lock->mutex); +} + +# endif + +/* -------------------------- gl_once_t datatype -------------------------- */ + +static const pthread_once_t fresh_once = PTHREAD_ONCE_INIT; + +int +glthread_once_singlethreaded (pthread_once_t *once_control) +{ + /* We don't know whether pthread_once_t is an integer type, a floating-point + type, a pointer type, or a structure type. */ + char *firstbyte = (char *)once_control; + if (*firstbyte == *(const char *)&fresh_once) + { + /* First time use of once_control. Invert the first byte. */ + *firstbyte = ~ *(const char *)&fresh_once; + return 1; + } + else + return 0; +} + +# if !(PTHREAD_IN_USE_DETECTION_HARD || USE_POSIX_THREADS_WEAK) + +int +glthread_once_multithreaded (pthread_once_t *once_control, + void (*init_function) (void)) +{ + int err = pthread_once (once_control, init_function); + if (err == ENOSYS) + { + /* This happens on FreeBSD 11: The pthread_once function in libc returns + ENOSYS. */ + if (glthread_once_singlethreaded (once_control)) + init_function (); + return 0; + } + return err; +} + +# endif + +#endif + +/* ========================================================================= */ + +#if USE_WINDOWS_THREADS + +#endif + +/* ========================================================================= */ diff --git a/contrib/tools/bison/lib/glthread/lock.h b/contrib/tools/bison/lib/glthread/lock.h new file mode 100644 index 000000000000..59485f260140 --- /dev/null +++ b/contrib/tools/bison/lib/glthread/lock.h @@ -0,0 +1,789 @@ +/* Locking in multithreaded situations. + Copyright (C) 2005-2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Bruno Haible , 2005. + Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-win32.h. */ + +/* This file contains locking primitives for use with a given thread library. + It does not contain primitives for creating threads or for other + synchronization primitives. + + Normal (non-recursive) locks: + Type: gl_lock_t + Declaration: gl_lock_define(extern, name) + Initializer: gl_lock_define_initialized(, name) + Initialization: gl_lock_init (name); + Taking the lock: gl_lock_lock (name); + Releasing the lock: gl_lock_unlock (name); + De-initialization: gl_lock_destroy (name); + Equivalent functions with control of error handling: + Initialization: err = glthread_lock_init (&name); + Taking the lock: err = glthread_lock_lock (&name); + Releasing the lock: err = glthread_lock_unlock (&name); + De-initialization: err = glthread_lock_destroy (&name); + + Read-Write (non-recursive) locks: + Type: gl_rwlock_t + Declaration: gl_rwlock_define(extern, name) + Initializer: gl_rwlock_define_initialized(, name) + Initialization: gl_rwlock_init (name); + Taking the lock: gl_rwlock_rdlock (name); + gl_rwlock_wrlock (name); + Releasing the lock: gl_rwlock_unlock (name); + De-initialization: gl_rwlock_destroy (name); + Equivalent functions with control of error handling: + Initialization: err = glthread_rwlock_init (&name); + Taking the lock: err = glthread_rwlock_rdlock (&name); + err = glthread_rwlock_wrlock (&name); + Releasing the lock: err = glthread_rwlock_unlock (&name); + De-initialization: err = glthread_rwlock_destroy (&name); + + Recursive locks: + Type: gl_recursive_lock_t + Declaration: gl_recursive_lock_define(extern, name) + Initializer: gl_recursive_lock_define_initialized(, name) + Initialization: gl_recursive_lock_init (name); + Taking the lock: gl_recursive_lock_lock (name); + Releasing the lock: gl_recursive_lock_unlock (name); + De-initialization: gl_recursive_lock_destroy (name); + Equivalent functions with control of error handling: + Initialization: err = glthread_recursive_lock_init (&name); + Taking the lock: err = glthread_recursive_lock_lock (&name); + Releasing the lock: err = glthread_recursive_lock_unlock (&name); + De-initialization: err = glthread_recursive_lock_destroy (&name); + + Once-only execution: + Type: gl_once_t + Initializer: gl_once_define(extern, name) + Execution: gl_once (name, initfunction); + Equivalent functions with control of error handling: + Execution: err = glthread_once (&name, initfunction); +*/ + + +#ifndef _LOCK_H +#define _LOCK_H + +#include +#include + +#if !defined c11_threads_in_use +# if HAVE_THREADS_H && USE_POSIX_THREADS_WEAK +# include +# pragma weak thrd_exit +# define c11_threads_in_use() (thrd_exit != NULL) +# else +# define c11_threads_in_use() 0 +# endif +#endif + +/* ========================================================================= */ + +#if USE_ISOC_THREADS || USE_ISOC_AND_POSIX_THREADS + +/* Use the ISO C threads library. */ + +# include + +# ifdef __cplusplus +extern "C" { +# endif + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +typedef struct + { + int volatile init_needed; + once_flag init_once; + void (*init_func) (void); + mtx_t mutex; + } + gl_lock_t; +# define gl_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_lock_t NAME; +# define gl_lock_define_initialized(STORAGECLASS, NAME) \ + static void _atomic_init_##NAME (void); \ + STORAGECLASS gl_lock_t NAME = \ + { 1, ONCE_FLAG_INIT, _atomic_init_##NAME }; \ + static void _atomic_init_##NAME (void) \ + { \ + if (glthread_lock_init (&(NAME))) \ + abort (); \ + } +extern int glthread_lock_init (gl_lock_t *lock); +extern int glthread_lock_lock (gl_lock_t *lock); +extern int glthread_lock_unlock (gl_lock_t *lock); +extern int glthread_lock_destroy (gl_lock_t *lock); + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +typedef struct + { + int volatile init_needed; + once_flag init_once; + void (*init_func) (void); + mtx_t lock; /* protects the remaining fields */ + cnd_t waiting_readers; /* waiting readers */ + cnd_t waiting_writers; /* waiting writers */ + unsigned int waiting_writers_count; /* number of waiting writers */ + int runcount; /* number of readers running, or -1 when a writer runs */ + } + gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME; +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ + static void _atomic_init_##NAME (void); \ + STORAGECLASS gl_rwlock_t NAME = \ + { 1, ONCE_FLAG_INIT, _atomic_init_##NAME }; \ + static void _atomic_init_##NAME (void) \ + { \ + if (glthread_rwlock_init (&(NAME))) \ + abort (); \ + } +extern int glthread_rwlock_init (gl_rwlock_t *lock); +extern int glthread_rwlock_rdlock (gl_rwlock_t *lock); +extern int glthread_rwlock_wrlock (gl_rwlock_t *lock); +extern int glthread_rwlock_unlock (gl_rwlock_t *lock); +extern int glthread_rwlock_destroy (gl_rwlock_t *lock); + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +typedef struct + { + int volatile init_needed; + once_flag init_once; + void (*init_func) (void); + mtx_t mutex; + } + gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME; +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ + static void _atomic_init_##NAME (void); \ + STORAGECLASS gl_recursive_lock_t NAME = \ + { 1, ONCE_FLAG_INIT, _atomic_init_##NAME }; \ + static void _atomic_init_##NAME (void) \ + { \ + if (glthread_recursive_lock_init (&(NAME))) \ + abort (); \ + } +extern int glthread_recursive_lock_init (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_lock (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_unlock (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_destroy (gl_recursive_lock_t *lock); + +/* -------------------------- gl_once_t datatype -------------------------- */ + +typedef once_flag gl_once_t; +# define gl_once_define(STORAGECLASS, NAME) \ + STORAGECLASS once_flag NAME = ONCE_FLAG_INIT; +# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ + (call_once (ONCE_CONTROL, INITFUNCTION), 0) + +# ifdef __cplusplus +} +# endif + +#endif + +/* ========================================================================= */ + +#if USE_POSIX_THREADS + +/* Use the POSIX threads library. */ + +# include + +# ifdef __cplusplus +extern "C" { +# endif + +# if PTHREAD_IN_USE_DETECTION_HARD + +/* The pthread_in_use() detection needs to be done at runtime. */ +# define pthread_in_use() \ + glthread_in_use () +extern int glthread_in_use (void); + +# endif + +# if USE_POSIX_THREADS_WEAK + +/* Use weak references to the POSIX threads library. */ + +/* Weak references avoid dragging in external libraries if the other parts + of the program don't use them. Here we use them, because we don't want + every program that uses libintl to depend on libpthread. This assumes + that libpthread would not be loaded after libintl; i.e. if libintl is + loaded first, by an executable that does not depend on libpthread, and + then a module is dynamically loaded that depends on libpthread, libintl + will not be multithread-safe. */ + +/* The way to test at runtime whether libpthread is present is to test + whether a function pointer's value, such as &pthread_mutex_init, is + non-NULL. However, some versions of GCC have a bug through which, in + PIC mode, &foo != NULL always evaluates to true if there is a direct + call to foo(...) in the same function. To avoid this, we test the + address of a function in libpthread that we don't use. */ + +# pragma weak pthread_mutex_init +# pragma weak pthread_mutex_lock +# pragma weak pthread_mutex_unlock +# pragma weak pthread_mutex_destroy +# pragma weak pthread_rwlock_init +# pragma weak pthread_rwlock_rdlock +# pragma weak pthread_rwlock_wrlock +# pragma weak pthread_rwlock_unlock +# pragma weak pthread_rwlock_destroy +# pragma weak pthread_once +# pragma weak pthread_cond_init +# pragma weak pthread_cond_wait +# pragma weak pthread_cond_signal +# pragma weak pthread_cond_broadcast +# pragma weak pthread_cond_destroy +# pragma weak pthread_mutexattr_init +# pragma weak pthread_mutexattr_settype +# pragma weak pthread_mutexattr_destroy +# pragma weak pthread_rwlockattr_init +# if __GNU_LIBRARY__ > 1 +# pragma weak pthread_rwlockattr_setkind_np +# endif +# pragma weak pthread_rwlockattr_destroy +# ifndef pthread_self +# pragma weak pthread_self +# endif + +# if !PTHREAD_IN_USE_DETECTION_HARD + /* Considering all platforms with USE_POSIX_THREADS_WEAK, only few symbols + can be used to determine whether libpthread is in use. These are: + pthread_mutexattr_gettype + pthread_rwlockattr_destroy + pthread_rwlockattr_init + */ +# pragma weak pthread_mutexattr_gettype +# define pthread_in_use() \ + (pthread_mutexattr_gettype != NULL || c11_threads_in_use ()) +# endif + +# else + +# if !PTHREAD_IN_USE_DETECTION_HARD +# define pthread_in_use() 1 +# endif + +# endif + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +typedef pthread_mutex_t gl_lock_t; +# define gl_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS pthread_mutex_t NAME; +# define gl_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS pthread_mutex_t NAME = gl_lock_initializer; +# define gl_lock_initializer \ + PTHREAD_MUTEX_INITIALIZER +# define glthread_lock_init(LOCK) \ + (pthread_in_use () ? pthread_mutex_init (LOCK, NULL) : 0) +# define glthread_lock_lock(LOCK) \ + (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0) +# define glthread_lock_unlock(LOCK) \ + (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0) +# define glthread_lock_destroy(LOCK) \ + (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0) + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +# if HAVE_PTHREAD_RWLOCK && (HAVE_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER || (defined PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP && (__GNU_LIBRARY__ > 1))) + +# if defined PTHREAD_RWLOCK_INITIALIZER || defined PTHREAD_RWLOCK_INITIALIZER_NP + +typedef pthread_rwlock_t gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) \ + STORAGECLASS pthread_rwlock_t NAME; +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS pthread_rwlock_t NAME = gl_rwlock_initializer; +# if HAVE_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER +# if defined PTHREAD_RWLOCK_INITIALIZER +# define gl_rwlock_initializer \ + PTHREAD_RWLOCK_INITIALIZER +# else +# define gl_rwlock_initializer \ + PTHREAD_RWLOCK_INITIALIZER_NP +# endif +# define glthread_rwlock_init(LOCK) \ + (pthread_in_use () ? pthread_rwlock_init (LOCK, NULL) : 0) +# else /* glibc with bug https://sourceware.org/bugzilla/show_bug.cgi?id=13701 */ +# define gl_rwlock_initializer \ + PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP +# define glthread_rwlock_init(LOCK) \ + (pthread_in_use () ? glthread_rwlock_init_for_glibc (LOCK) : 0) +extern int glthread_rwlock_init_for_glibc (pthread_rwlock_t *lock); +# endif +# define glthread_rwlock_rdlock(LOCK) \ + (pthread_in_use () ? pthread_rwlock_rdlock (LOCK) : 0) +# define glthread_rwlock_wrlock(LOCK) \ + (pthread_in_use () ? pthread_rwlock_wrlock (LOCK) : 0) +# define glthread_rwlock_unlock(LOCK) \ + (pthread_in_use () ? pthread_rwlock_unlock (LOCK) : 0) +# define glthread_rwlock_destroy(LOCK) \ + (pthread_in_use () ? pthread_rwlock_destroy (LOCK) : 0) + +# else + +typedef struct + { + int initialized; + pthread_mutex_t guard; /* protects the initialization */ + pthread_rwlock_t rwlock; /* read-write lock */ + } + gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME; +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer; +# define gl_rwlock_initializer \ + { 0, PTHREAD_MUTEX_INITIALIZER } +# define glthread_rwlock_init(LOCK) \ + (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0) +# define glthread_rwlock_rdlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_wrlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_unlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_destroy(LOCK) \ + (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0) +extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock); + +# endif + +# else + +typedef struct + { + pthread_mutex_t lock; /* protects the remaining fields */ + pthread_cond_t waiting_readers; /* waiting readers */ + pthread_cond_t waiting_writers; /* waiting writers */ + unsigned int waiting_writers_count; /* number of waiting writers */ + int runcount; /* number of readers running, or -1 when a writer runs */ + } + gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME; +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer; +# define gl_rwlock_initializer \ + { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0 } +# define glthread_rwlock_init(LOCK) \ + (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0) +# define glthread_rwlock_rdlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_wrlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_unlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_destroy(LOCK) \ + (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0) +extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock); + +# endif + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +# if HAVE_PTHREAD_MUTEX_RECURSIVE + +# if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP + +typedef pthread_mutex_t gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS pthread_mutex_t NAME; +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS pthread_mutex_t NAME = gl_recursive_lock_initializer; +# ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER +# define gl_recursive_lock_initializer \ + PTHREAD_RECURSIVE_MUTEX_INITIALIZER +# else +# define gl_recursive_lock_initializer \ + PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP +# endif +# define glthread_recursive_lock_init(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_lock(LOCK) \ + (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0) +# define glthread_recursive_lock_unlock(LOCK) \ + (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0) +# define glthread_recursive_lock_destroy(LOCK) \ + (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0) +extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock); + +# else + +typedef struct + { + pthread_mutex_t recmutex; /* recursive mutex */ + pthread_mutex_t guard; /* protects the initialization */ + int initialized; + } + gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME; +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; +# define gl_recursive_lock_initializer \ + { PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, 0 } +# define glthread_recursive_lock_init(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_lock(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_unlock(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_destroy(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0) +extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock); + +# endif + +# else + +/* Old versions of POSIX threads on Solaris did not have recursive locks. + We have to implement them ourselves. */ + +typedef struct + { + pthread_mutex_t mutex; + pthread_t owner; + unsigned long depth; + } + gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME; +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; +# define gl_recursive_lock_initializer \ + { PTHREAD_MUTEX_INITIALIZER, (pthread_t) 0, 0 } +# define glthread_recursive_lock_init(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_lock(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_unlock(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_destroy(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0) +extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock); + +# endif + +/* -------------------------- gl_once_t datatype -------------------------- */ + +typedef pthread_once_t gl_once_t; +# define gl_once_define(STORAGECLASS, NAME) \ + STORAGECLASS pthread_once_t NAME = PTHREAD_ONCE_INIT; +# if PTHREAD_IN_USE_DETECTION_HARD || USE_POSIX_THREADS_WEAK +# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ + (pthread_in_use () \ + ? pthread_once (ONCE_CONTROL, INITFUNCTION) \ + : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0)) +# else +# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ + (pthread_in_use () \ + ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION) \ + : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0)) +extern int glthread_once_multithreaded (pthread_once_t *once_control, + void (*init_function) (void)); +# endif +extern int glthread_once_singlethreaded (pthread_once_t *once_control); + +# ifdef __cplusplus +} +# endif + +#endif + +/* ========================================================================= */ + +#if USE_WINDOWS_THREADS + +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include + +# include "windows-mutex.h" +# include "windows-rwlock.h" +# include "windows-recmutex.h" +# include "windows-once.h" + +# ifdef __cplusplus +extern "C" { +# endif + +/* We can use CRITICAL_SECTION directly, rather than the native Windows Event, + Mutex, Semaphore types, because + - we need only to synchronize inside a single process (address space), + not inter-process locking, + - we don't need to support trylock operations. (TryEnterCriticalSection + does not work on Windows 95/98/ME. Packages that need trylock usually + define their own mutex type.) */ + +/* There is no way to statically initialize a CRITICAL_SECTION. It needs + to be done lazily, once only. For this we need spinlocks. */ + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +typedef glwthread_mutex_t gl_lock_t; +# define gl_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_lock_t NAME; +# define gl_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_lock_t NAME = gl_lock_initializer; +# define gl_lock_initializer \ + GLWTHREAD_MUTEX_INIT +# define glthread_lock_init(LOCK) \ + (glwthread_mutex_init (LOCK), 0) +# define glthread_lock_lock(LOCK) \ + glwthread_mutex_lock (LOCK) +# define glthread_lock_unlock(LOCK) \ + glwthread_mutex_unlock (LOCK) +# define glthread_lock_destroy(LOCK) \ + glwthread_mutex_destroy (LOCK) + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +typedef glwthread_rwlock_t gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME; +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer; +# define gl_rwlock_initializer \ + GLWTHREAD_RWLOCK_INIT +# define glthread_rwlock_init(LOCK) \ + (glwthread_rwlock_init (LOCK), 0) +# define glthread_rwlock_rdlock(LOCK) \ + glwthread_rwlock_rdlock (LOCK) +# define glthread_rwlock_wrlock(LOCK) \ + glwthread_rwlock_wrlock (LOCK) +# define glthread_rwlock_unlock(LOCK) \ + glwthread_rwlock_unlock (LOCK) +# define glthread_rwlock_destroy(LOCK) \ + glwthread_rwlock_destroy (LOCK) + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +typedef glwthread_recmutex_t gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME; +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; +# define gl_recursive_lock_initializer \ + GLWTHREAD_RECMUTEX_INIT +# define glthread_recursive_lock_init(LOCK) \ + (glwthread_recmutex_init (LOCK), 0) +# define glthread_recursive_lock_lock(LOCK) \ + glwthread_recmutex_lock (LOCK) +# define glthread_recursive_lock_unlock(LOCK) \ + glwthread_recmutex_unlock (LOCK) +# define glthread_recursive_lock_destroy(LOCK) \ + glwthread_recmutex_destroy (LOCK) + +/* -------------------------- gl_once_t datatype -------------------------- */ + +typedef glwthread_once_t gl_once_t; +# define gl_once_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_once_t NAME = GLWTHREAD_ONCE_INIT; +# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ + (glwthread_once (ONCE_CONTROL, INITFUNCTION), 0) + +# ifdef __cplusplus +} +# endif + +#endif + +/* ========================================================================= */ + +#if !(USE_ISOC_THREADS || USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS || USE_WINDOWS_THREADS) + +/* Provide dummy implementation if threads are not supported. */ + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +typedef int gl_lock_t; +# define gl_lock_define(STORAGECLASS, NAME) +# define gl_lock_define_initialized(STORAGECLASS, NAME) +# define glthread_lock_init(NAME) 0 +# define glthread_lock_lock(NAME) 0 +# define glthread_lock_unlock(NAME) 0 +# define glthread_lock_destroy(NAME) 0 + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +typedef int gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) +# define glthread_rwlock_init(NAME) 0 +# define glthread_rwlock_rdlock(NAME) 0 +# define glthread_rwlock_wrlock(NAME) 0 +# define glthread_rwlock_unlock(NAME) 0 +# define glthread_rwlock_destroy(NAME) 0 + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +typedef int gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) +# define glthread_recursive_lock_init(NAME) 0 +# define glthread_recursive_lock_lock(NAME) 0 +# define glthread_recursive_lock_unlock(NAME) 0 +# define glthread_recursive_lock_destroy(NAME) 0 + +/* -------------------------- gl_once_t datatype -------------------------- */ + +typedef int gl_once_t; +# define gl_once_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_once_t NAME = 0; +# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ + (*(ONCE_CONTROL) == 0 ? (*(ONCE_CONTROL) = ~ 0, INITFUNCTION (), 0) : 0) + +#endif + +/* ========================================================================= */ + +/* Macros with built-in error handling. */ + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +#define gl_lock_init(NAME) \ + do \ + { \ + if (glthread_lock_init (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_lock_lock(NAME) \ + do \ + { \ + if (glthread_lock_lock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_lock_unlock(NAME) \ + do \ + { \ + if (glthread_lock_unlock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_lock_destroy(NAME) \ + do \ + { \ + if (glthread_lock_destroy (&NAME)) \ + abort (); \ + } \ + while (0) + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +#define gl_rwlock_init(NAME) \ + do \ + { \ + if (glthread_rwlock_init (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_rwlock_rdlock(NAME) \ + do \ + { \ + if (glthread_rwlock_rdlock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_rwlock_wrlock(NAME) \ + do \ + { \ + if (glthread_rwlock_wrlock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_rwlock_unlock(NAME) \ + do \ + { \ + if (glthread_rwlock_unlock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_rwlock_destroy(NAME) \ + do \ + { \ + if (glthread_rwlock_destroy (&NAME)) \ + abort (); \ + } \ + while (0) + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +#define gl_recursive_lock_init(NAME) \ + do \ + { \ + if (glthread_recursive_lock_init (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_recursive_lock_lock(NAME) \ + do \ + { \ + if (glthread_recursive_lock_lock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_recursive_lock_unlock(NAME) \ + do \ + { \ + if (glthread_recursive_lock_unlock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_recursive_lock_destroy(NAME) \ + do \ + { \ + if (glthread_recursive_lock_destroy (&NAME)) \ + abort (); \ + } \ + while (0) + +/* -------------------------- gl_once_t datatype -------------------------- */ + +#define gl_once(NAME, INITFUNCTION) \ + do \ + { \ + if (glthread_once (&NAME, INITFUNCTION)) \ + abort (); \ + } \ + while (0) + +/* ========================================================================= */ + +#endif /* _LOCK_H */ diff --git a/contrib/tools/bison/lib/glthread/threadlib.c b/contrib/tools/bison/lib/glthread/threadlib.c new file mode 100644 index 000000000000..28bf3c6f76dc --- /dev/null +++ b/contrib/tools/bison/lib/glthread/threadlib.c @@ -0,0 +1,73 @@ +/* Multithreading primitives. + Copyright (C) 2005-2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Bruno Haible , 2005. */ + +#include + +/* ========================================================================= */ + +#if USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS + +/* Use the POSIX threads library. */ + +# include +# include + +# if PTHREAD_IN_USE_DETECTION_HARD + +/* The function to be executed by a dummy thread. */ +static void * +dummy_thread_func (void *arg) +{ + return arg; +} + +int +glthread_in_use (void) +{ + static int tested; + static int result; /* 1: linked with -lpthread, 0: only with libc */ + + if (!tested) + { + pthread_t thread; + + if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0) + /* Thread creation failed. */ + result = 0; + else + { + /* Thread creation works. */ + void *retval; + if (pthread_join (thread, &retval) != 0) + abort (); + result = 1; + } + tested = 1; + } + return result; +} + +# endif + +#endif + +/* ========================================================================= */ + +/* This declaration is solely to ensure that after preprocessing + this file is never empty. */ +typedef int dummy; diff --git a/contrib/tools/bison/lib/glthread/tls.c b/contrib/tools/bison/lib/glthread/tls.c new file mode 100644 index 000000000000..2492b00c0e57 --- /dev/null +++ b/contrib/tools/bison/lib/glthread/tls.c @@ -0,0 +1,41 @@ +/* Thread-local storage in multithreaded situations. + Copyright (C) 2005-2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2005. */ + +#include + +#include "glthread/tls.h" + +/* ========================================================================= */ + +#if USE_ISOC_THREADS || USE_ISOC_AND_POSIX_THREADS + +#endif + +/* ========================================================================= */ + +#if USE_POSIX_THREADS + +#endif + +/* ========================================================================= */ + +#if USE_WINDOWS_THREADS + +#endif + +/* ========================================================================= */ diff --git a/contrib/tools/bison/lib/glthread/tls.h b/contrib/tools/bison/lib/glthread/tls.h new file mode 100644 index 000000000000..d11e89bac824 --- /dev/null +++ b/contrib/tools/bison/lib/glthread/tls.h @@ -0,0 +1,228 @@ +/* Thread-local storage in multithreaded situations. + Copyright (C) 2005, 2007-2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2005. */ + +/* This file contains thread-local storage primitives for use with a given + thread library. It does not contain primitives for creating threads or + for other multithreading primitives. + + Type: gl_tls_key_t + Initialization: gl_tls_key_init (name, destructor); + Getting per-thread value: gl_tls_get (name) + Setting per-thread value: gl_tls_set (name, pointer); + De-initialization: gl_tls_key_destroy (name); + Equivalent functions with control of error handling: + Initialization: err = glthread_tls_key_init (&name, destructor); + Setting per-thread value: err = glthread_tls_set (&name, pointer); + De-initialization: err = glthread_tls_key_destroy (&name); + + A per-thread value is of type 'void *'. + + A destructor is a function pointer of type 'void (*) (void *)', called + when a thread exits, and taking the last per-thread value as argument. It + is unspecified whether the destructor function is called when the last + per-thread value is NULL. On some platforms, the destructor function is + not called at all. +*/ + + +#ifndef _TLS_H +#define _TLS_H + +#include +#include + +#if !defined c11_threads_in_use +# if HAVE_THREADS_H && USE_POSIX_THREADS_WEAK +# include +# pragma weak thrd_exit +# define c11_threads_in_use() (thrd_exit != NULL) +# else +# define c11_threads_in_use() 0 +# endif +#endif + +/* ========================================================================= */ + +#if USE_ISOC_THREADS || USE_ISOC_AND_POSIX_THREADS + +/* Use the ISO C threads library. */ + +# include + +/* ------------------------- gl_tls_key_t datatype ------------------------- */ + +typedef tss_t gl_tls_key_t; +# define glthread_tls_key_init(KEY, DESTRUCTOR) \ + (tss_create (KEY, DESTRUCTOR) != thrd_success ? EAGAIN : 0) +# define gl_tls_get(NAME) \ + tss_get (NAME) +# define glthread_tls_set(KEY, POINTER) \ + (tss_set (*(KEY), (POINTER)) != thrd_success ? ENOMEM : 0) +# define glthread_tls_key_destroy(KEY) \ + (tss_delete (*(KEY)), 0) + +#endif + +/* ========================================================================= */ + +#if USE_POSIX_THREADS + +/* Use the POSIX threads library. */ + +# include + +# if PTHREAD_IN_USE_DETECTION_HARD + +/* The pthread_in_use() detection needs to be done at runtime. */ +# define pthread_in_use() \ + glthread_in_use () +extern int glthread_in_use (void); + +# endif + +# if USE_POSIX_THREADS_WEAK + +/* Use weak references to the POSIX threads library. */ + +# pragma weak pthread_key_create +# pragma weak pthread_getspecific +# pragma weak pthread_setspecific +# pragma weak pthread_key_delete +# ifndef pthread_self +# pragma weak pthread_self +# endif + +# if !PTHREAD_IN_USE_DETECTION_HARD +# pragma weak pthread_mutexattr_gettype +# define pthread_in_use() \ + (pthread_mutexattr_gettype != NULL || c11_threads_in_use ()) +# endif + +# else + +# if !PTHREAD_IN_USE_DETECTION_HARD +# define pthread_in_use() 1 +# endif + +# endif + +/* ------------------------- gl_tls_key_t datatype ------------------------- */ + +typedef union + { + void *singlethread_value; + pthread_key_t key; + } + gl_tls_key_t; +# define glthread_tls_key_init(KEY, DESTRUCTOR) \ + (pthread_in_use () \ + ? pthread_key_create (&(KEY)->key, DESTRUCTOR) \ + : ((KEY)->singlethread_value = NULL, 0)) +# define gl_tls_get(NAME) \ + (pthread_in_use () \ + ? pthread_getspecific ((NAME).key) \ + : (NAME).singlethread_value) +# define glthread_tls_set(KEY, POINTER) \ + (pthread_in_use () \ + ? pthread_setspecific ((KEY)->key, (POINTER)) \ + : ((KEY)->singlethread_value = (POINTER), 0)) +# define glthread_tls_key_destroy(KEY) \ + (pthread_in_use () ? pthread_key_delete ((KEY)->key) : 0) + +#endif + +/* ========================================================================= */ + +#if USE_WINDOWS_THREADS + +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include + +# include "windows-tls.h" + +/* ------------------------- gl_tls_key_t datatype ------------------------- */ + +typedef glwthread_tls_key_t gl_tls_key_t; +# define glthread_tls_key_init(KEY, DESTRUCTOR) \ + glwthread_tls_key_create (KEY, DESTRUCTOR) +# define gl_tls_get(NAME) \ + TlsGetValue (NAME) +# define glthread_tls_set(KEY, POINTER) \ + (!TlsSetValue (*(KEY), POINTER) ? EINVAL : 0) +# define glthread_tls_key_destroy(KEY) \ + glwthread_tls_key_delete (*(KEY)) + +#endif + +/* ========================================================================= */ + +#if !(USE_ISOC_THREADS || USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS || USE_WINDOWS_THREADS) + +/* Provide dummy implementation if threads are not supported. */ + +/* ------------------------- gl_tls_key_t datatype ------------------------- */ + +typedef struct + { + void *singlethread_value; + } + gl_tls_key_t; +# define glthread_tls_key_init(KEY, DESTRUCTOR) \ + ((KEY)->singlethread_value = NULL, \ + (void) (DESTRUCTOR), \ + 0) +# define gl_tls_get(NAME) \ + (NAME).singlethread_value +# define glthread_tls_set(KEY, POINTER) \ + ((KEY)->singlethread_value = (POINTER), 0) +# define glthread_tls_key_destroy(KEY) \ + 0 + +#endif + +/* ========================================================================= */ + +/* Macros with built-in error handling. */ + +/* ------------------------- gl_tls_key_t datatype ------------------------- */ + +#define gl_tls_key_init(NAME, DESTRUCTOR) \ + do \ + { \ + if (glthread_tls_key_init (&NAME, DESTRUCTOR)) \ + abort (); \ + } \ + while (0) +#define gl_tls_set(NAME, POINTER) \ + do \ + { \ + if (glthread_tls_set (&NAME, POINTER)) \ + abort (); \ + } \ + while (0) +#define gl_tls_key_destroy(NAME) \ + do \ + { \ + if (glthread_tls_key_destroy (&NAME)) \ + abort (); \ + } \ + while (0) + +/* ========================================================================= */ + +#endif /* _TLS_H */ diff --git a/contrib/tools/bison/lib/hard-locale.c b/contrib/tools/bison/lib/hard-locale.c index dcfcad62ee7c..237f875b3a40 100644 --- a/contrib/tools/bison/lib/hard-locale.c +++ b/contrib/tools/bison/lib/hard-locale.c @@ -1,6 +1,6 @@ /* hard-locale.c -- Determine whether a locale is hard. - Copyright (C) 1997-1999, 2002-2004, 2006-2007, 2009-2019 Free Software + Copyright (C) 1997-1999, 2002-2004, 2006-2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -19,54 +19,18 @@ #include #include "hard-locale.h" +#include "setlocale_null.h" #include -#include #include -#ifdef __GLIBC__ -# define GLIBC_VERSION __GLIBC__ -#elif defined __UCLIBC__ -# define GLIBC_VERSION 2 -#else -# define GLIBC_VERSION 0 -#endif - -/* Return true if the current CATEGORY locale is hard, i.e. if you - can't get away with assuming traditional C or POSIX behavior. */ bool hard_locale (int category) { - bool hard = true; - char const *p = setlocale (category, NULL); - - if (p) - { - if (2 <= GLIBC_VERSION) - { - if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0) - hard = false; - } - else - { - char *locale = strdup (p); - if (locale) - { - /* Temporarily set the locale to the "C" and "POSIX" locales - to find their names, so that we can determine whether one - or the other is the caller's locale. */ - if (((p = setlocale (category, "C")) - && strcmp (p, locale) == 0) - || ((p = setlocale (category, "POSIX")) - && strcmp (p, locale) == 0)) - hard = false; + char locale[SETLOCALE_NULL_MAX]; - /* Restore the caller's locale. */ - setlocale (category, locale); - free (locale); - } - } - } + if (setlocale_null_r (category, locale, sizeof (locale))) + return false; - return hard; + return !(strcmp (locale, "C") == 0 || strcmp (locale, "POSIX") == 0); } diff --git a/contrib/tools/bison/lib/hard-locale.h b/contrib/tools/bison/lib/hard-locale.h index 8f1da96e2f25..1886eaae9226 100644 --- a/contrib/tools/bison/lib/hard-locale.h +++ b/contrib/tools/bison/lib/hard-locale.h @@ -1,6 +1,6 @@ /* Determine whether a locale is hard. - Copyright (C) 1999, 2003-2004, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1999, 2003-2004, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,6 +20,9 @@ # include -bool hard_locale (int); +/* Return true if the specified CATEGORY of the current locale is hard, i.e. + different from the C or POSIX locale that has a fixed behavior. + CATEGORY must be one of the LC_* values, but not LC_ALL. */ +extern bool hard_locale (int category); #endif /* HARD_LOCALE_H_ */ diff --git a/contrib/tools/bison/lib/hash.c b/contrib/tools/bison/lib/hash.c index 9e1f8e8417eb..7aaf10626718 100644 --- a/contrib/tools/bison/lib/hash.c +++ b/contrib/tools/bison/lib/hash.c @@ -1,6 +1,6 @@ /* hash - hashing table processing. - Copyright (C) 1998-2004, 2006-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1998-2004, 2006-2007, 2009-2020 Free Software Foundation, Inc. Written by Jim Meyering, 1992. diff --git a/contrib/tools/bison/lib/hash.h b/contrib/tools/bison/lib/hash.h index a1a483a35941..2ff4266a4fd9 100644 --- a/contrib/tools/bison/lib/hash.h +++ b/contrib/tools/bison/lib/hash.h @@ -1,5 +1,5 @@ /* hash - hashing table processing. - Copyright (C) 1998-1999, 2001, 2003, 2009-2019 Free Software Foundation, + Copyright (C) 1998-1999, 2001, 2003, 2009-2020 Free Software Foundation, Inc. Written by Jim Meyering , 1998. @@ -89,6 +89,9 @@ void hash_reset_tuning (Hash_tuning *); Hash_table *hash_initialize (size_t, const Hash_tuning *, Hash_hasher, Hash_comparator, Hash_data_freer) _GL_ATTRIBUTE_WUR; +Hash_table *hash_xinitialize (size_t, const Hash_tuning *, + Hash_hasher, Hash_comparator, + Hash_data_freer) _GL_ATTRIBUTE_WUR; void hash_clear (Hash_table *); void hash_free (Hash_table *); diff --git a/contrib/tools/bison/lib/intprops.h b/contrib/tools/bison/lib/intprops.h new file mode 100644 index 000000000000..dfbcaae73e37 --- /dev/null +++ b/contrib/tools/bison/lib/intprops.h @@ -0,0 +1,584 @@ +/* intprops.h -- properties of integer types + + Copyright (C) 2001-2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Paul Eggert. */ + +#ifndef _GL_INTPROPS_H +#define _GL_INTPROPS_H + +#include + +/* Return a value with the common real type of E and V and the value of V. + Do not evaluate E. */ +#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v)) + +/* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see + . */ +#define _GL_INT_NEGATE_CONVERT(e, v) ((1 ? 0 : (e)) - (v)) + +/* The extra casts in the following macros work around compiler bugs, + e.g., in Cray C 5.0.3.0. */ + +/* True if the arithmetic type T is an integer type. bool counts as + an integer. */ +#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1) + +/* True if the real type T is signed. */ +#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) + +/* Return 1 if the real expression E, after promotion, has a + signed or floating type. Do not evaluate E. */ +#define EXPR_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0) + + +/* Minimum and maximum values for integer types and expressions. */ + +/* The width in bits of the integer type or expression T. + Do not evaluate T. + Padding bits are not supported; this is checked at compile-time below. */ +#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT) + +/* The maximum and minimum values for the integer type T. */ +#define TYPE_MINIMUM(t) ((t) ~ TYPE_MAXIMUM (t)) +#define TYPE_MAXIMUM(t) \ + ((t) (! TYPE_SIGNED (t) \ + ? (t) -1 \ + : ((((t) 1 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1))) + +/* The maximum and minimum values for the type of the expression E, + after integer promotion. E is not evaluated. */ +#define _GL_INT_MINIMUM(e) \ + (EXPR_SIGNED (e) \ + ? ~ _GL_SIGNED_INT_MAXIMUM (e) \ + : _GL_INT_CONVERT (e, 0)) +#define _GL_INT_MAXIMUM(e) \ + (EXPR_SIGNED (e) \ + ? _GL_SIGNED_INT_MAXIMUM (e) \ + : _GL_INT_NEGATE_CONVERT (e, 1)) +#define _GL_SIGNED_INT_MAXIMUM(e) \ + (((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH ((e) + 0) - 2)) - 1) * 2 + 1) + +/* Work around OpenVMS incompatibility with C99. */ +#if !defined LLONG_MAX && defined __INT64_MAX +# define LLONG_MAX __INT64_MAX +# define LLONG_MIN __INT64_MIN +#endif + +/* This include file assumes that signed types are two's complement without + padding bits; the above macros have undefined behavior otherwise. + If this is a problem for you, please let us know how to fix it for your host. + This assumption is tested by the intprops-tests module. */ + +/* Does the __typeof__ keyword work? This could be done by + 'configure', but for now it's easier to do it by hand. */ +#if (2 <= __GNUC__ \ + || (1210 <= __IBMC__ && defined __IBM__TYPEOF__) \ + || (0x5110 <= __SUNPRO_C && !__STDC__)) +# define _GL_HAVE___TYPEOF__ 1 +#else +# define _GL_HAVE___TYPEOF__ 0 +#endif + +/* Return 1 if the integer type or expression T might be signed. Return 0 + if it is definitely unsigned. This macro does not evaluate its argument, + and expands to an integer constant expression. */ +#if _GL_HAVE___TYPEOF__ +# define _GL_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED (__typeof__ (t)) +#else +# define _GL_SIGNED_TYPE_OR_EXPR(t) 1 +#endif + +/* Bound on length of the string representing an unsigned integer + value representable in B bits. log10 (2.0) < 146/485. The + smallest value of B where this bound is not tight is 2621. */ +#define INT_BITS_STRLEN_BOUND(b) (((b) * 146 + 484) / 485) + +/* Bound on length of the string representing an integer type or expression T. + Subtract 1 for the sign bit if T is signed, and then add 1 more for + a minus sign if needed. + + Because _GL_SIGNED_TYPE_OR_EXPR sometimes returns 1 when its argument is + unsigned, this macro may overestimate the true bound by one byte when + applied to unsigned types of size 2, 4, 16, ... bytes. */ +#define INT_STRLEN_BOUND(t) \ + (INT_BITS_STRLEN_BOUND (TYPE_WIDTH (t) - _GL_SIGNED_TYPE_OR_EXPR (t)) \ + + _GL_SIGNED_TYPE_OR_EXPR (t)) + +/* Bound on buffer size needed to represent an integer type or expression T, + including the terminating null. */ +#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1) + + +/* Range overflow checks. + + The INT__RANGE_OVERFLOW macros return 1 if the corresponding C + operators might not yield numerically correct answers due to + arithmetic overflow. They do not rely on undefined or + implementation-defined behavior. Their implementations are simple + and straightforward, but they are a bit harder to use than the + INT__OVERFLOW macros described below. + + Example usage: + + long int i = ...; + long int j = ...; + if (INT_MULTIPLY_RANGE_OVERFLOW (i, j, LONG_MIN, LONG_MAX)) + printf ("multiply would overflow"); + else + printf ("product is %ld", i * j); + + Restrictions on *_RANGE_OVERFLOW macros: + + These macros do not check for all possible numerical problems or + undefined or unspecified behavior: they do not check for division + by zero, for bad shift counts, or for shifting negative numbers. + + These macros may evaluate their arguments zero or multiple times, + so the arguments should not have side effects. The arithmetic + arguments (including the MIN and MAX arguments) must be of the same + integer type after the usual arithmetic conversions, and the type + must have minimum value MIN and maximum MAX. Unsigned types should + use a zero MIN of the proper type. + + These macros are tuned for constant MIN and MAX. For commutative + operations such as A + B, they are also tuned for constant B. */ + +/* Return 1 if A + B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. */ +#define INT_ADD_RANGE_OVERFLOW(a, b, min, max) \ + ((b) < 0 \ + ? (a) < (min) - (b) \ + : (max) - (b) < (a)) + +/* Return 1 if A - B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. */ +#define INT_SUBTRACT_RANGE_OVERFLOW(a, b, min, max) \ + ((b) < 0 \ + ? (max) + (b) < (a) \ + : (a) < (min) + (b)) + +/* Return 1 if - A would overflow in [MIN,MAX] arithmetic. + See above for restrictions. */ +#define INT_NEGATE_RANGE_OVERFLOW(a, min, max) \ + ((min) < 0 \ + ? (a) < - (max) \ + : 0 < (a)) + +/* Return 1 if A * B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Avoid && and || as they tickle + bugs in Sun C 5.11 2010/08/13 and other compilers; see + . */ +#define INT_MULTIPLY_RANGE_OVERFLOW(a, b, min, max) \ + ((b) < 0 \ + ? ((a) < 0 \ + ? (a) < (max) / (b) \ + : (b) == -1 \ + ? 0 \ + : (min) / (b) < (a)) \ + : (b) == 0 \ + ? 0 \ + : ((a) < 0 \ + ? (a) < (min) / (b) \ + : (max) / (b) < (a))) + +/* Return 1 if A / B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Do not check for division by zero. */ +#define INT_DIVIDE_RANGE_OVERFLOW(a, b, min, max) \ + ((min) < 0 && (b) == -1 && (a) < - (max)) + +/* Return 1 if A % B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Do not check for division by zero. + Mathematically, % should never overflow, but on x86-like hosts + INT_MIN % -1 traps, and the C standard permits this, so treat this + as an overflow too. */ +#define INT_REMAINDER_RANGE_OVERFLOW(a, b, min, max) \ + INT_DIVIDE_RANGE_OVERFLOW (a, b, min, max) + +/* Return 1 if A << B would overflow in [MIN,MAX] arithmetic. + See above for restrictions. Here, MIN and MAX are for A only, and B need + not be of the same type as the other arguments. The C standard says that + behavior is undefined for shifts unless 0 <= B < wordwidth, and that when + A is negative then A << B has undefined behavior and A >> B has + implementation-defined behavior, but do not check these other + restrictions. */ +#define INT_LEFT_SHIFT_RANGE_OVERFLOW(a, b, min, max) \ + ((a) < 0 \ + ? (a) < (min) >> (b) \ + : (max) >> (b) < (a)) + +/* True if __builtin_add_overflow (A, B, P) and __builtin_sub_overflow + (A, B, P) work when P is non-null. */ +#if 5 <= __GNUC__ && !defined __ICC +# define _GL_HAS_BUILTIN_ADD_OVERFLOW 1 +#elif defined __has_builtin +# define _GL_HAS_BUILTIN_ADD_OVERFLOW __has_builtin (__builtin_add_overflow) +#else +# define _GL_HAS_BUILTIN_ADD_OVERFLOW 0 +#endif + +/* True if __builtin_mul_overflow (A, B, P) works when P is non-null. */ +#ifdef __clang__ +/* Work around Clang bug . */ +# define _GL_HAS_BUILTIN_MUL_OVERFLOW 0 +#else +# define _GL_HAS_BUILTIN_MUL_OVERFLOW _GL_HAS_BUILTIN_ADD_OVERFLOW +#endif + +/* True if __builtin_add_overflow_p (A, B, C) works, and similarly for + __builtin_mul_overflow_p and __builtin_mul_overflow_p. */ +#define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__) + +/* The _GL*_OVERFLOW macros have the same restrictions as the + *_RANGE_OVERFLOW macros, except that they do not assume that operands + (e.g., A and B) have the same type as MIN and MAX. Instead, they assume + that the result (e.g., A + B) has that type. */ +#if _GL_HAS_BUILTIN_OVERFLOW_P +# define _GL_ADD_OVERFLOW(a, b, min, max) \ + __builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0) +# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \ + __builtin_sub_overflow_p (a, b, (__typeof__ ((a) - (b))) 0) +# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \ + __builtin_mul_overflow_p (a, b, (__typeof__ ((a) * (b))) 0) +#else +# define _GL_ADD_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \ + : (a) < 0 ? (b) <= (a) + (b) \ + : (b) < 0 ? (a) <= (a) + (b) \ + : (a) + (b) < (b)) +# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max) \ + : (a) < 0 ? 1 \ + : (b) < 0 ? (a) - (b) <= (a) \ + : (a) < (b)) +# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \ + (((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \ + || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max)) +#endif +#define _GL_DIVIDE_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \ + : (a) < 0 ? (b) <= (a) + (b) - 1 \ + : (b) < 0 && (a) + (b) <= (a)) +#define _GL_REMAINDER_OVERFLOW(a, b, min, max) \ + ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \ + : (a) < 0 ? (a) % (b) != ((max) - (b) + 1) % (b) \ + : (b) < 0 && ! _GL_UNSIGNED_NEG_MULTIPLE (a, b, max)) + +/* Return a nonzero value if A is a mathematical multiple of B, where + A is unsigned, B is negative, and MAX is the maximum value of A's + type. A's type must be the same as (A % B)'s type. Normally (A % + -B == 0) suffices, but things get tricky if -B would overflow. */ +#define _GL_UNSIGNED_NEG_MULTIPLE(a, b, max) \ + (((b) < -_GL_SIGNED_INT_MAXIMUM (b) \ + ? (_GL_SIGNED_INT_MAXIMUM (b) == (max) \ + ? (a) \ + : (a) % (_GL_INT_CONVERT (a, _GL_SIGNED_INT_MAXIMUM (b)) + 1)) \ + : (a) % - (b)) \ + == 0) + +/* Check for integer overflow, and report low order bits of answer. + + The INT__OVERFLOW macros return 1 if the corresponding C operators + might not yield numerically correct answers due to arithmetic overflow. + The INT__WRAPV macros compute the low-order bits of the sum, + difference, and product of two C integers, and return 1 if these + low-order bits are not numerically correct. + These macros work correctly on all known practical hosts, and do not rely + on undefined behavior due to signed arithmetic overflow. + + Example usage, assuming A and B are long int: + + if (INT_MULTIPLY_OVERFLOW (a, b)) + printf ("result would overflow\n"); + else + printf ("result is %ld (no overflow)\n", a * b); + + Example usage with WRAPV flavor: + + long int result; + bool overflow = INT_MULTIPLY_WRAPV (a, b, &result); + printf ("result is %ld (%s)\n", result, + overflow ? "after overflow" : "no overflow"); + + Restrictions on these macros: + + These macros do not check for all possible numerical problems or + undefined or unspecified behavior: they do not check for division + by zero, for bad shift counts, or for shifting negative numbers. + + These macros may evaluate their arguments zero or multiple times, so the + arguments should not have side effects. + + The WRAPV macros are not constant expressions. They support only + +, binary -, and *. Because the WRAPV macros convert the result, + they report overflow in different circumstances than the OVERFLOW + macros do. + + These macros are tuned for their last input argument being a constant. + + Return 1 if the integer expressions A * B, A - B, -A, A * B, A / B, + A % B, and A << B would overflow, respectively. */ + +#define INT_ADD_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW) +#define INT_SUBTRACT_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW) +#if _GL_HAS_BUILTIN_OVERFLOW_P +# define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a) +#else +# define INT_NEGATE_OVERFLOW(a) \ + INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a)) +#endif +#define INT_MULTIPLY_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW) +#define INT_DIVIDE_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_DIVIDE_OVERFLOW) +#define INT_REMAINDER_OVERFLOW(a, b) \ + _GL_BINARY_OP_OVERFLOW (a, b, _GL_REMAINDER_OVERFLOW) +#define INT_LEFT_SHIFT_OVERFLOW(a, b) \ + INT_LEFT_SHIFT_RANGE_OVERFLOW (a, b, \ + _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a)) + +/* Return 1 if the expression A B would overflow, + where OP_RESULT_OVERFLOW (A, B, MIN, MAX) does the actual test, + assuming MIN and MAX are the minimum and maximum for the result type. + Arguments should be free of side effects. */ +#define _GL_BINARY_OP_OVERFLOW(a, b, op_result_overflow) \ + op_result_overflow (a, b, \ + _GL_INT_MINIMUM (_GL_INT_CONVERT (a, b)), \ + _GL_INT_MAXIMUM (_GL_INT_CONVERT (a, b))) + +/* Store the low-order bits of A + B, A - B, A * B, respectively, into *R. + Return 1 if the result overflows. See above for restrictions. */ +#if _GL_HAS_BUILTIN_ADD_OVERFLOW +# define INT_ADD_WRAPV(a, b, r) __builtin_add_overflow (a, b, r) +# define INT_SUBTRACT_WRAPV(a, b, r) __builtin_sub_overflow (a, b, r) +#else +# define INT_ADD_WRAPV(a, b, r) \ + _GL_INT_OP_WRAPV (a, b, r, +, _GL_INT_ADD_RANGE_OVERFLOW) +# define INT_SUBTRACT_WRAPV(a, b, r) \ + _GL_INT_OP_WRAPV (a, b, r, -, _GL_INT_SUBTRACT_RANGE_OVERFLOW) +#endif +#if _GL_HAS_BUILTIN_MUL_OVERFLOW +# if (9 < __GNUC__ + (3 <= __GNUC_MINOR__) \ + || (__GNUC__ == 8 && 4 <= __GNUC_MINOR__)) +# define INT_MULTIPLY_WRAPV(a, b, r) __builtin_mul_overflow (a, b, r) +# else + /* Work around GCC bug 91450. */ +# define INT_MULTIPLY_WRAPV(a, b, r) \ + ((!_GL_SIGNED_TYPE_OR_EXPR (*(r)) && EXPR_SIGNED (a) && EXPR_SIGNED (b) \ + && _GL_INT_MULTIPLY_RANGE_OVERFLOW (a, b, 0, (__typeof__ (*(r))) -1)) \ + ? ((void) __builtin_mul_overflow (a, b, r), 1) \ + : __builtin_mul_overflow (a, b, r)) +# endif +#else +# define INT_MULTIPLY_WRAPV(a, b, r) \ + _GL_INT_OP_WRAPV (a, b, r, *, _GL_INT_MULTIPLY_RANGE_OVERFLOW) +#endif + +/* Nonzero if this compiler has GCC bug 68193 or Clang bug 25390. See: + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68193 + https://llvm.org/bugs/show_bug.cgi?id=25390 + For now, assume all versions of GCC-like compilers generate bogus + warnings for _Generic. This matters only for compilers that + lack relevant builtins. */ +#if __GNUC__ +# define _GL__GENERIC_BOGUS 1 +#else +# define _GL__GENERIC_BOGUS 0 +#endif + +/* Store the low-order bits of A B into *R, where OP specifies + the operation and OVERFLOW the overflow predicate. Return 1 if the + result overflows. See above for restrictions. */ +#if 201112 <= __STDC_VERSION__ && !_GL__GENERIC_BOGUS +# define _GL_INT_OP_WRAPV(a, b, r, op, overflow) \ + (_Generic \ + (*(r), \ + signed char: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + signed char, SCHAR_MIN, SCHAR_MAX), \ + unsigned char: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + unsigned char, 0, UCHAR_MAX), \ + short int: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + short int, SHRT_MIN, SHRT_MAX), \ + unsigned short int: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + unsigned short int, 0, USHRT_MAX), \ + int: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + int, INT_MIN, INT_MAX), \ + unsigned int: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + unsigned int, 0, UINT_MAX), \ + long int: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ + long int, LONG_MIN, LONG_MAX), \ + unsigned long int: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ + unsigned long int, 0, ULONG_MAX), \ + long long int: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \ + long long int, LLONG_MIN, LLONG_MAX), \ + unsigned long long int: \ + _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \ + unsigned long long int, 0, ULLONG_MAX))) +#else +/* Store the low-order bits of A B into *R, where OP specifies + the operation and OVERFLOW the overflow predicate. If *R is + signed, its type is ST with bounds SMIN..SMAX; otherwise its type + is UT with bounds U..UMAX. ST and UT are narrower than int. + Return 1 if the result overflows. See above for restrictions. */ +# if _GL_HAVE___TYPEOF__ +# define _GL_INT_OP_WRAPV_SMALLISH(a,b,r,op,overflow,st,smin,smax,ut,umax) \ + (TYPE_SIGNED (__typeof__ (*(r))) \ + ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, st, smin, smax) \ + : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, ut, 0, umax)) +# else +# define _GL_INT_OP_WRAPV_SMALLISH(a,b,r,op,overflow,st,smin,smax,ut,umax) \ + (overflow (a, b, smin, smax) \ + ? (overflow (a, b, 0, umax) \ + ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st), 1) \ + : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st)) < 0) \ + : (overflow (a, b, 0, umax) \ + ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st)) >= 0 \ + : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a,b,op,unsigned,st), 0))) +# endif + +# define _GL_INT_OP_WRAPV(a, b, r, op, overflow) \ + (sizeof *(r) == sizeof (signed char) \ + ? _GL_INT_OP_WRAPV_SMALLISH (a, b, r, op, overflow, \ + signed char, SCHAR_MIN, SCHAR_MAX, \ + unsigned char, UCHAR_MAX) \ + : sizeof *(r) == sizeof (short int) \ + ? _GL_INT_OP_WRAPV_SMALLISH (a, b, r, op, overflow, \ + short int, SHRT_MIN, SHRT_MAX, \ + unsigned short int, USHRT_MAX) \ + : sizeof *(r) == sizeof (int) \ + ? (EXPR_SIGNED (*(r)) \ + ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + int, INT_MIN, INT_MAX) \ + : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned int, \ + unsigned int, 0, UINT_MAX)) \ + : _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow)) +# ifdef LLONG_MAX +# define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \ + (sizeof *(r) == sizeof (long int) \ + ? (EXPR_SIGNED (*(r)) \ + ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ + long int, LONG_MIN, LONG_MAX) \ + : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ + unsigned long int, 0, ULONG_MAX)) \ + : (EXPR_SIGNED (*(r)) \ + ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \ + long long int, LLONG_MIN, LLONG_MAX) \ + : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long long int, \ + unsigned long long int, 0, ULLONG_MAX))) +# else +# define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \ + (EXPR_SIGNED (*(r)) \ + ? _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ + long int, LONG_MIN, LONG_MAX) \ + : _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \ + unsigned long int, 0, ULONG_MAX)) +# endif +#endif + +/* Store the low-order bits of A B into *R, where the operation + is given by OP. Use the unsigned type UT for calculation to avoid + overflow problems. *R's type is T, with extrema TMIN and TMAX. + T must be a signed integer type. Return 1 if the result overflows. */ +#define _GL_INT_OP_CALC(a, b, r, op, overflow, ut, t, tmin, tmax) \ + (overflow (a, b, tmin, tmax) \ + ? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 1) \ + : (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t), 0)) + +/* Return the low-order bits of A B, where the operation is given + by OP. Use the unsigned type UT for calculation to avoid undefined + behavior on signed integer overflow, and convert the result to type T. + UT is at least as wide as T and is no narrower than unsigned int, + T is two's complement, and there is no padding or trap representations. + Assume that converting UT to T yields the low-order bits, as is + done in all known two's-complement C compilers. E.g., see: + https://gcc.gnu.org/onlinedocs/gcc/Integers-implementation.html + + According to the C standard, converting UT to T yields an + implementation-defined result or signal for values outside T's + range. However, code that works around this theoretical problem + runs afoul of a compiler bug in Oracle Studio 12.3 x86. See: + https://lists.gnu.org/r/bug-gnulib/2017-04/msg00049.html + As the compiler bug is real, don't try to work around the + theoretical problem. */ + +#define _GL_INT_OP_WRAPV_VIA_UNSIGNED(a, b, op, ut, t) \ + ((t) ((ut) (a) op (ut) (b))) + +/* Return true if the numeric values A + B, A - B, A * B fall outside + the range TMIN..TMAX. Arguments should be integer expressions + without side effects. TMIN should be signed and nonpositive. + TMAX should be positive, and should be signed unless TMIN is zero. */ +#define _GL_INT_ADD_RANGE_OVERFLOW(a, b, tmin, tmax) \ + ((b) < 0 \ + ? (((tmin) \ + ? ((EXPR_SIGNED (_GL_INT_CONVERT (a, (tmin) - (b))) || (b) < (tmin)) \ + && (a) < (tmin) - (b)) \ + : (a) <= -1 - (b)) \ + || ((EXPR_SIGNED (a) ? 0 <= (a) : (tmax) < (a)) && (tmax) < (a) + (b))) \ + : (a) < 0 \ + ? (((tmin) \ + ? ((EXPR_SIGNED (_GL_INT_CONVERT (b, (tmin) - (a))) || (a) < (tmin)) \ + && (b) < (tmin) - (a)) \ + : (b) <= -1 - (a)) \ + || ((EXPR_SIGNED (_GL_INT_CONVERT (a, b)) || (tmax) < (b)) \ + && (tmax) < (a) + (b))) \ + : (tmax) < (b) || (tmax) - (b) < (a)) +#define _GL_INT_SUBTRACT_RANGE_OVERFLOW(a, b, tmin, tmax) \ + (((a) < 0) == ((b) < 0) \ + ? ((a) < (b) \ + ? !(tmin) || -1 - (tmin) < (b) - (a) - 1 \ + : (tmax) < (a) - (b)) \ + : (a) < 0 \ + ? ((!EXPR_SIGNED (_GL_INT_CONVERT ((a) - (tmin), b)) && (a) - (tmin) < 0) \ + || (a) - (tmin) < (b)) \ + : ((! (EXPR_SIGNED (_GL_INT_CONVERT (tmax, b)) \ + && EXPR_SIGNED (_GL_INT_CONVERT ((tmax) + (b), a))) \ + && (tmax) <= -1 - (b)) \ + || (tmax) + (b) < (a))) +#define _GL_INT_MULTIPLY_RANGE_OVERFLOW(a, b, tmin, tmax) \ + ((b) < 0 \ + ? ((a) < 0 \ + ? (EXPR_SIGNED (_GL_INT_CONVERT (tmax, b)) \ + ? (a) < (tmax) / (b) \ + : ((INT_NEGATE_OVERFLOW (b) \ + ? _GL_INT_CONVERT (b, tmax) >> (TYPE_WIDTH (b) - 1) \ + : (tmax) / -(b)) \ + <= -1 - (a))) \ + : INT_NEGATE_OVERFLOW (_GL_INT_CONVERT (b, tmin)) && (b) == -1 \ + ? (EXPR_SIGNED (a) \ + ? 0 < (a) + (tmin) \ + : 0 < (a) && -1 - (tmin) < (a) - 1) \ + : (tmin) / (b) < (a)) \ + : (b) == 0 \ + ? 0 \ + : ((a) < 0 \ + ? (INT_NEGATE_OVERFLOW (_GL_INT_CONVERT (a, tmin)) && (a) == -1 \ + ? (EXPR_SIGNED (b) ? 0 < (b) + (tmin) : -1 - (tmin) < (b) - 1) \ + : (tmin) / (a) < (b)) \ + : (tmax) / (b) < (a))) + +#endif /* _GL_INTPROPS_H */ diff --git a/contrib/tools/bison/lib/isnand-nolibm.h b/contrib/tools/bison/lib/isnand-nolibm.h index 174c61ebd23e..cbabed4c10ca 100644 --- a/contrib/tools/bison/lib/isnand-nolibm.h +++ b/contrib/tools/bison/lib/isnand-nolibm.h @@ -1,5 +1,5 @@ /* Test for NaN that does not need libm. - Copyright (C) 2007-2019 Free Software Foundation, Inc. + Copyright (C) 2007-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/isnanl-nolibm.h b/contrib/tools/bison/lib/isnanl-nolibm.h index fdedf56b6261..c45e3ab2c7b1 100644 --- a/contrib/tools/bison/lib/isnanl-nolibm.h +++ b/contrib/tools/bison/lib/isnanl-nolibm.h @@ -1,5 +1,5 @@ /* Test for NaN that does not need libm. - Copyright (C) 2007-2019 Free Software Foundation, Inc. + Copyright (C) 2007-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/localcharset.c b/contrib/tools/bison/lib/localcharset.c index 579972bc2f90..38026dffed5c 100644 --- a/contrib/tools/bison/lib/localcharset.c +++ b/contrib/tools/bison/lib/localcharset.c @@ -1,6 +1,6 @@ /* Determine a canonical name for the current locale's character encoding. - Copyright (C) 2000-2006, 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2000-2006, 2008-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -58,6 +58,9 @@ #elif defined WINDOWS_NATIVE # define WIN32_LEAN_AND_MEAN # include + /* For the use of setlocale() below, the Gnulib override in setlocale.c is + not needed; see the platform lists in setlocale_null.m4. */ +# undef setlocale #endif #if defined OS2 # define INCL_DOS @@ -150,7 +153,8 @@ static const struct table_entry alias_table[] = { "ISO8859-2", "ISO-8859-2" }, { "ISO8859-4", "ISO-8859-4" }, { "ISO8859-5", "ISO-8859-5" }, - { "ISO8859-7", "ISO-8859-7" } + { "ISO8859-7", "ISO-8859-7" }, + { "US-ASCII", "ASCII" } # define alias_table_defined # endif # if defined __APPLE__ && defined __MACH__ /* Mac OS X */ @@ -377,27 +381,164 @@ static const struct table_entry alias_table[] = /* The list of encodings is taken from "List of OS/2 Codepages" by Alex Taylor: . - See also "IBM Globalization - Code page identifiers": - . */ - { "CP1089", "ISO-8859-6" }, - { "CP1208", "UTF-8" }, - { "CP1381", "GB2312" }, - { "CP1386", "GBK" }, - { "CP3372", "EUC-JP" }, - { "CP813", "ISO-8859-7" }, - { "CP819", "ISO-8859-1" }, - { "CP878", "KOI8-R" }, - { "CP912", "ISO-8859-2" }, - { "CP913", "ISO-8859-3" }, - { "CP914", "ISO-8859-4" }, - { "CP915", "ISO-8859-5" }, - { "CP916", "ISO-8859-8" }, - { "CP920", "ISO-8859-9" }, - { "CP921", "ISO-8859-13" }, - { "CP923", "ISO-8859-15" }, - { "CP954", "EUC-JP" }, - { "CP964", "EUC-TW" }, - { "CP970", "EUC-KR" } + See also "__convcp() of kLIBC": + . */ + { "CP1004", "CP1252" }, + /*{ "CP1041", "CP943" },*/ + /*{ "CP1088", "CP949" },*/ + { "CP1089", "ISO-8859-6" }, + /*{ "CP1114", "CP950" },*/ + /*{ "CP1115", "GB2312" },*/ + { "CP1208", "UTF-8" }, + /*{ "CP1380", "GB2312" },*/ + { "CP1381", "GB2312" }, + { "CP1383", "GB2312" }, + { "CP1386", "GBK" }, + /*{ "CP301", "CP943" },*/ + { "CP3372", "EUC-JP" }, + { "CP4946", "CP850" }, + /*{ "CP5048", "JIS_X0208-1990" },*/ + /*{ "CP5049", "JIS_X0212-1990" },*/ + /*{ "CP5067", "KS_C_5601-1987" },*/ + { "CP813", "ISO-8859-7" }, + { "CP819", "ISO-8859-1" }, + { "CP878", "KOI8-R" }, + /*{ "CP897", "CP943" },*/ + { "CP912", "ISO-8859-2" }, + { "CP913", "ISO-8859-3" }, + { "CP914", "ISO-8859-4" }, + { "CP915", "ISO-8859-5" }, + { "CP916", "ISO-8859-8" }, + { "CP920", "ISO-8859-9" }, + { "CP921", "ISO-8859-13" }, + { "CP923", "ISO-8859-15" }, + /*{ "CP941", "CP943" },*/ + /*{ "CP947", "CP950" },*/ + /*{ "CP951", "CP949" },*/ + /*{ "CP952", "JIS_X0208-1990" },*/ + /*{ "CP953", "JIS_X0212-1990" },*/ + { "CP954", "EUC-JP" }, + { "CP964", "EUC-TW" }, + { "CP970", "EUC-KR" }, + /*{ "CP971", "KS_C_5601-1987" },*/ + { "IBM-1004", "CP1252" }, + /*{ "IBM-1006", "?" },*/ + /*{ "IBM-1008", "?" },*/ + /*{ "IBM-1041", "CP943" },*/ + /*{ "IBM-1051", "?" },*/ + /*{ "IBM-1088", "CP949" },*/ + { "IBM-1089", "ISO-8859-6" }, + /*{ "IBM-1098", "?" },*/ + /*{ "IBM-1114", "CP950" },*/ + /*{ "IBM-1115", "GB2312" },*/ + /*{ "IBM-1116", "?" },*/ + /*{ "IBM-1117", "?" },*/ + /*{ "IBM-1118", "?" },*/ + /*{ "IBM-1119", "?" },*/ + { "IBM-1124", "CP1124" }, + { "IBM-1125", "CP1125" }, + { "IBM-1131", "CP1131" }, + { "IBM-1208", "UTF-8" }, + { "IBM-1250", "CP1250" }, + { "IBM-1251", "CP1251" }, + { "IBM-1252", "CP1252" }, + { "IBM-1253", "CP1253" }, + { "IBM-1254", "CP1254" }, + { "IBM-1255", "CP1255" }, + { "IBM-1256", "CP1256" }, + { "IBM-1257", "CP1257" }, + /*{ "IBM-1275", "?" },*/ + /*{ "IBM-1276", "?" },*/ + /*{ "IBM-1277", "?" },*/ + /*{ "IBM-1280", "?" },*/ + /*{ "IBM-1281", "?" },*/ + /*{ "IBM-1282", "?" },*/ + /*{ "IBM-1283", "?" },*/ + /*{ "IBM-1380", "GB2312" },*/ + { "IBM-1381", "GB2312" }, + { "IBM-1383", "GB2312" }, + { "IBM-1386", "GBK" }, + /*{ "IBM-301", "CP943" },*/ + { "IBM-3372", "EUC-JP" }, + { "IBM-367", "ASCII" }, + { "IBM-437", "CP437" }, + { "IBM-4946", "CP850" }, + /*{ "IBM-5048", "JIS_X0208-1990" },*/ + /*{ "IBM-5049", "JIS_X0212-1990" },*/ + /*{ "IBM-5067", "KS_C_5601-1987" },*/ + { "IBM-813", "ISO-8859-7" }, + { "IBM-819", "ISO-8859-1" }, + { "IBM-850", "CP850" }, + /*{ "IBM-851", "?" },*/ + { "IBM-852", "CP852" }, + { "IBM-855", "CP855" }, + { "IBM-856", "CP856" }, + { "IBM-857", "CP857" }, + /*{ "IBM-859", "?" },*/ + { "IBM-860", "CP860" }, + { "IBM-861", "CP861" }, + { "IBM-862", "CP862" }, + { "IBM-863", "CP863" }, + { "IBM-864", "CP864" }, + { "IBM-865", "CP865" }, + { "IBM-866", "CP866" }, + /*{ "IBM-868", "?" },*/ + { "IBM-869", "CP869" }, + { "IBM-874", "CP874" }, + { "IBM-878", "KOI8-R" }, + /*{ "IBM-895", "?" },*/ + /*{ "IBM-897", "CP943" },*/ + /*{ "IBM-907", "?" },*/ + /*{ "IBM-909", "?" },*/ + { "IBM-912", "ISO-8859-2" }, + { "IBM-913", "ISO-8859-3" }, + { "IBM-914", "ISO-8859-4" }, + { "IBM-915", "ISO-8859-5" }, + { "IBM-916", "ISO-8859-8" }, + { "IBM-920", "ISO-8859-9" }, + { "IBM-921", "ISO-8859-13" }, + { "IBM-922", "CP922" }, + { "IBM-923", "ISO-8859-15" }, + { "IBM-932", "CP932" }, + /*{ "IBM-941", "CP943" },*/ + /*{ "IBM-942", "?" },*/ + { "IBM-943", "CP943" }, + /*{ "IBM-947", "CP950" },*/ + { "IBM-949", "CP949" }, + { "IBM-950", "CP950" }, + /*{ "IBM-951", "CP949" },*/ + /*{ "IBM-952", "JIS_X0208-1990" },*/ + /*{ "IBM-953", "JIS_X0212-1990" },*/ + { "IBM-954", "EUC-JP" }, + /*{ "IBM-955", "?" },*/ + { "IBM-964", "EUC-TW" }, + { "IBM-970", "EUC-KR" }, + /*{ "IBM-971", "KS_C_5601-1987" },*/ + { "IBM-eucCN", "GB2312" }, + { "IBM-eucJP", "EUC-JP" }, + { "IBM-eucKR", "EUC-KR" }, + { "IBM-eucTW", "EUC-TW" }, + { "IBM33722", "EUC-JP" }, + { "ISO8859-1", "ISO-8859-1" }, + { "ISO8859-2", "ISO-8859-2" }, + { "ISO8859-3", "ISO-8859-3" }, + { "ISO8859-4", "ISO-8859-4" }, + { "ISO8859-5", "ISO-8859-5" }, + { "ISO8859-6", "ISO-8859-6" }, + { "ISO8859-7", "ISO-8859-7" }, + { "ISO8859-8", "ISO-8859-8" }, + { "ISO8859-9", "ISO-8859-9" }, + /*{ "JISX0201-1976", "JISX0201-1976" },*/ + /*{ "JISX0208-1978", "?" },*/ + /*{ "JISX0208-1983", "JIS_X0208-1983" },*/ + /*{ "JISX0208-1990", "JIS_X0208-1990" },*/ + /*{ "JISX0212-1990", "JIS_X0212-1990" },*/ + /*{ "KSC5601-1987", "KS_C_5601-1987" },*/ + { "SJIS-1", "CP943" }, + { "SJIS-2", "CP943" }, + { "eucJP", "EUC-JP" }, + { "eucKR", "EUC-KR" }, + { "eucTW-1993", "EUC-TW" } # define alias_table_defined # endif # if defined VMS /* OpenVMS */ @@ -675,8 +816,11 @@ static const struct table_entry locale_table[] = /* Determine the current locale's character encoding, and canonicalize it - into one of the canonical names listed in localcharset.h. - The result must not be freed; it is statically allocated. + into one of the canonical names listed below. + The result must not be freed; it is statically allocated. The result + becomes invalid when setlocale() is used to change the global locale, or + when the value of one of the environment variables LC_ALL, LC_CTYPE, LANG + is changed; threads in multithreaded programs should not do this. If the canonical name cannot be determined, the result is a non-canonical name. */ @@ -688,6 +832,13 @@ locale_charset (void) { const char *codeset; + /* This function must be multithread-safe. To achieve this without using + thread-local storage, we use a simple strcpy or memcpy to fill this static + buffer. Filling it through, for example, strcpy + strcat would not be + guaranteed to leave the buffer's contents intact if another thread is + currently accessing it. If necessary, the contents is first assembled in + a stack-allocated buffer. */ + #if HAVE_LANGINFO_CODESET || defined WINDOWS_NATIVE || defined OS2 # if HAVE_LANGINFO_CODESET @@ -702,7 +853,7 @@ locale_charset (void) if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0) { const char *locale; - static char buf[2 + 10 + 1]; + static char resultbuf[2 + 10 + 1]; locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') @@ -726,11 +877,12 @@ locale_charset (void) modifier = strchr (dot, '@'); if (modifier == NULL) return dot; - if (modifier - dot < sizeof (buf)) + if (modifier - dot < sizeof (resultbuf)) { - memcpy (buf, dot, modifier - dot); - buf [modifier - dot] = '\0'; - return buf; + /* This way of filling resultbuf is multithread-safe. */ + memcpy (resultbuf, dot, modifier - dot); + resultbuf [modifier - dot] = '\0'; + return resultbuf; } } } @@ -746,8 +898,13 @@ locale_charset (void) converting to GetConsoleOutputCP(). This leads to correct results, except when SetConsoleOutputCP has been called and a raster font is in use. */ - sprintf (buf, "CP%u", GetACP ()); - codeset = buf; + { + char buf[2 + 10 + 1]; + + sprintf (buf, "CP%u", GetACP ()); + strcpy (resultbuf, buf); + codeset = resultbuf; + } } # endif @@ -757,42 +914,44 @@ locale_charset (void) # elif defined WINDOWS_NATIVE - static char buf[2 + 10 + 1]; + char buf[2 + 10 + 1]; + static char resultbuf[2 + 10 + 1]; /* The Windows API has a function returning the locale's codepage as a number, but the value doesn't change according to what the 'setlocale' call specified. So we use it as a last resort, in case the string returned by 'setlocale' doesn't specify the codepage. */ - char *current_locale = setlocale (LC_ALL, NULL); - char *pdot; + char *current_locale = setlocale (LC_CTYPE, NULL); + char *pdot = strrchr (current_locale, '.'); - /* If they set different locales for different categories, - 'setlocale' will return a semi-colon separated list of locale - values. To make sure we use the correct one, we choose LC_CTYPE. */ - if (strchr (current_locale, ';')) - current_locale = setlocale (LC_CTYPE, NULL); - - pdot = strrchr (current_locale, '.'); if (pdot && 2 + strlen (pdot + 1) + 1 <= sizeof (buf)) sprintf (buf, "CP%s", pdot + 1); else { /* The Windows API has a function returning the locale's codepage as a - number: GetACP(). - When the output goes to a console window, it needs to be provided in - GetOEMCP() encoding if the console is using a raster font, or in - GetConsoleOutputCP() encoding if it is using a TrueType font. - But in GUI programs and for output sent to files and pipes, GetACP() - encoding is the best bet. */ + number: GetACP(). + When the output goes to a console window, it needs to be provided in + GetOEMCP() encoding if the console is using a raster font, or in + GetConsoleOutputCP() encoding if it is using a TrueType font. + But in GUI programs and for output sent to files and pipes, GetACP() + encoding is the best bet. */ sprintf (buf, "CP%u", GetACP ()); } - codeset = buf; + /* For a locale name such as "French_France.65001", in Windows 10, + setlocale now returns "French_France.utf8" instead. */ + if (strcmp (buf + 2, "65001") == 0 || strcmp (buf + 2, "utf8") == 0) + codeset = "UTF-8"; + else + { + strcpy (resultbuf, buf); + codeset = resultbuf; + } # elif defined OS2 const char *locale; - static char buf[2 + 10 + 1]; + static char resultbuf[2 + 10 + 1]; ULONG cp[3]; ULONG cplen; @@ -821,11 +980,12 @@ locale_charset (void) modifier = strchr (dot, '@'); if (modifier == NULL) return dot; - if (modifier - dot < sizeof (buf)) + if (modifier - dot < sizeof (resultbuf)) { - memcpy (buf, dot, modifier - dot); - buf [modifier - dot] = '\0'; - return buf; + /* This way of filling resultbuf is multithread-safe. */ + memcpy (resultbuf, dot, modifier - dot); + resultbuf [modifier - dot] = '\0'; + return resultbuf; } } @@ -841,8 +1001,11 @@ locale_charset (void) codeset = ""; else { + char buf[2 + 10 + 1]; + sprintf (buf, "CP%u", cp[0]); - codeset = buf; + strcpy (resultbuf, buf); + codeset = resultbuf; } } diff --git a/contrib/tools/bison/lib/localcharset.h b/contrib/tools/bison/lib/localcharset.h index 7d0d7711dbe4..aa623be07a12 100644 --- a/contrib/tools/bison/lib/localcharset.h +++ b/contrib/tools/bison/lib/localcharset.h @@ -1,5 +1,5 @@ /* Determine a canonical name for the current locale's character encoding. - Copyright (C) 2000-2003, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2000-2003, 2009-2020 Free Software Foundation, Inc. This file is part of the GNU CHARSET Library. This program is free software; you can redistribute it and/or modify @@ -26,7 +26,10 @@ extern "C" { /* Determine the current locale's character encoding, and canonicalize it into one of the canonical names listed below. - The result must not be freed; it is statically allocated. + The result must not be freed; it is statically allocated. The result + becomes invalid when setlocale() is used to change the global locale, or + when the value of one of the environment variables LC_ALL, LC_CTYPE, LANG + is changed; threads in multithreaded programs should not do this. If the canonical name cannot be determined, the result is a non-canonical name. */ extern const char * locale_charset (void); @@ -45,15 +48,15 @@ extern const char * locale_charset (void); (darwin = Mac OS X, windows = native Windows) ASCII, ANSI_X3.4-1968 glibc solaris freebsd netbsd darwin minix cygwin - ISO-8859-1 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin - ISO-8859-2 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin + ISO-8859-1 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin zos + ISO-8859-2 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin zos ISO-8859-3 Y glibc solaris cygwin ISO-8859-4 Y hpux osf solaris freebsd netbsd openbsd darwin - ISO-8859-5 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin + ISO-8859-5 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin zos ISO-8859-6 Y glibc aix hpux solaris cygwin - ISO-8859-7 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin - ISO-8859-8 Y glibc aix hpux osf solaris cygwin - ISO-8859-9 Y glibc aix hpux irix osf solaris freebsd darwin cygwin + ISO-8859-7 Y glibc aix hpux irix osf solaris freebsd netbsd openbsd darwin cygwin zos + ISO-8859-8 Y glibc aix hpux osf solaris cygwin zos + ISO-8859-9 Y glibc aix hpux irix osf solaris freebsd darwin cygwin zos ISO-8859-13 glibc hpux solaris freebsd netbsd openbsd darwin cygwin ISO-8859-14 glibc cygwin ISO-8859-15 glibc aix irix osf solaris freebsd netbsd openbsd darwin cygwin @@ -76,7 +79,7 @@ extern const char * locale_charset (void); CP874 windows dos CP922 aix CP932 aix cygwin windows dos - CP943 aix + CP943 aix zos CP949 osf darwin windows dos CP950 windows dos CP1046 aix @@ -92,17 +95,17 @@ extern const char * locale_charset (void); CP1255 glibc windows CP1256 windows CP1257 windows - GB2312 Y glibc aix hpux irix solaris freebsd netbsd darwin cygwin + GB2312 Y glibc aix hpux irix solaris freebsd netbsd darwin cygwin zos EUC-JP Y glibc aix hpux irix osf solaris freebsd netbsd darwin cygwin - EUC-KR Y glibc aix hpux irix osf solaris freebsd netbsd darwin cygwin + EUC-KR Y glibc aix hpux irix osf solaris freebsd netbsd darwin cygwin zos EUC-TW glibc aix hpux irix osf solaris netbsd - BIG5 Y glibc aix hpux osf solaris freebsd netbsd darwin cygwin + BIG5 Y glibc aix hpux osf solaris freebsd netbsd darwin cygwin zos BIG5-HKSCS glibc hpux solaris netbsd darwin GBK glibc aix osf solaris freebsd darwin cygwin windows dos GB18030 glibc hpux solaris freebsd netbsd darwin SHIFT_JIS Y hpux osf solaris freebsd netbsd darwin JOHAB glibc solaris windows - TIS-620 glibc aix hpux osf solaris cygwin + TIS-620 glibc aix hpux osf solaris cygwin zos VISCII Y glibc TCVN5712-1 glibc ARMSCII-8 glibc freebsd netbsd darwin @@ -116,7 +119,7 @@ extern const char * locale_charset (void); HP-KANA8 hpux DEC-KANJI osf DEC-HANYU osf - UTF-8 Y glibc aix hpux osf solaris netbsd darwin cygwin + UTF-8 Y glibc aix hpux osf solaris netbsd darwin cygwin zos Note: Names which are not marked as being a MIME name should not be used in Internet protocols for information interchange (mail, news, etc.). diff --git a/contrib/tools/bison/lib/mbchar.c b/contrib/tools/bison/lib/mbchar.c new file mode 100644 index 000000000000..bd5c93215d55 --- /dev/null +++ b/contrib/tools/bison/lib/mbchar.c @@ -0,0 +1,37 @@ +/* Copyright (C) 2001, 2006, 2009-2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + + +#include + +#define MBCHAR_INLINE _GL_EXTERN_INLINE + +#include + +#include "mbchar.h" + +#if IS_BASIC_ASCII + +/* Bit table of characters in the ISO C "basic character set". */ +const unsigned int is_basic_table [UCHAR_MAX / 32 + 1] = +{ + 0x00001a00, /* '\t' '\v' '\f' */ + 0xffffffef, /* ' '...'#' '%'...'?' */ + 0xfffffffe, /* 'A'...'Z' '[' '\\' ']' '^' '_' */ + 0x7ffffffe /* 'a'...'z' '{' '|' '}' '~' */ + /* The remaining bits are 0. */ +}; + +#endif /* IS_BASIC_ASCII */ diff --git a/contrib/tools/bison/lib/mbchar.h b/contrib/tools/bison/lib/mbchar.h new file mode 100644 index 000000000000..8ff58bf519ad --- /dev/null +++ b/contrib/tools/bison/lib/mbchar.h @@ -0,0 +1,360 @@ +/* Multibyte character data type. + Copyright (C) 2001, 2005-2007, 2009-2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible . */ + +/* A multibyte character is a short subsequence of a char* string, + representing a single wide character. + + We use multibyte characters instead of wide characters because of + the following goals: + 1) correct multibyte handling, i.e. operate according to the LC_CTYPE + locale, + 2) ease of maintenance, i.e. the maintainer needs not know all details + of the ISO C 99 standard, + 3) don't fail grossly if the input is not in the encoding set by the + locale, because often different encodings are in use in the same + countries (ISO-8859-1/UTF-8, EUC-JP/Shift_JIS, ...), + 4) fast in the case of ASCII characters, + 5) portability, i.e. don't make unportable assumptions about wchar_t. + + Multibyte characters are only accessed through the mb* macros. + + mb_ptr (mbc) + return a pointer to the beginning of the multibyte sequence. + + mb_len (mbc) + returns the number of bytes occupied by the multibyte sequence. + Always > 0. + + mb_iseq (mbc, sc) + returns true if mbc is the standard ASCII character sc. + + mb_isnul (mbc) + returns true if mbc is the nul character. + + mb_cmp (mbc1, mbc2) + returns a positive, zero, or negative value depending on whether mbc1 + sorts after, same or before mbc2. + + mb_casecmp (mbc1, mbc2) + returns a positive, zero, or negative value depending on whether mbc1 + sorts after, same or before mbc2, modulo upper/lowercase conversion. + + mb_equal (mbc1, mbc2) + returns true if mbc1 and mbc2 are equal. + + mb_caseequal (mbc1, mbc2) + returns true if mbc1 and mbc2 are equal modulo upper/lowercase conversion. + + mb_isalnum (mbc) + returns true if mbc is alphanumeric. + + mb_isalpha (mbc) + returns true if mbc is alphabetic. + + mb_isascii(mbc) + returns true if mbc is plain ASCII. + + mb_isblank (mbc) + returns true if mbc is a blank. + + mb_iscntrl (mbc) + returns true if mbc is a control character. + + mb_isdigit (mbc) + returns true if mbc is a decimal digit. + + mb_isgraph (mbc) + returns true if mbc is a graphic character. + + mb_islower (mbc) + returns true if mbc is lowercase. + + mb_isprint (mbc) + returns true if mbc is a printable character. + + mb_ispunct (mbc) + returns true if mbc is a punctuation character. + + mb_isspace (mbc) + returns true if mbc is a space character. + + mb_isupper (mbc) + returns true if mbc is uppercase. + + mb_isxdigit (mbc) + returns true if mbc is a hexadecimal digit. + + mb_width (mbc) + returns the number of columns on the output device occupied by mbc. + Always >= 0. + + mb_putc (mbc, stream) + outputs mbc on stream, a byte oriented FILE stream opened for output. + + mb_setascii (&mbc, sc) + assigns the standard ASCII character sc to mbc. + + mb_copy (&destmbc, &srcmbc) + copies srcmbc to destmbc. + + Here are the function prototypes of the macros. + + extern const char * mb_ptr (const mbchar_t mbc); + extern size_t mb_len (const mbchar_t mbc); + extern bool mb_iseq (const mbchar_t mbc, char sc); + extern bool mb_isnul (const mbchar_t mbc); + extern int mb_cmp (const mbchar_t mbc1, const mbchar_t mbc2); + extern int mb_casecmp (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_equal (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_caseequal (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_isalnum (const mbchar_t mbc); + extern bool mb_isalpha (const mbchar_t mbc); + extern bool mb_isascii (const mbchar_t mbc); + extern bool mb_isblank (const mbchar_t mbc); + extern bool mb_iscntrl (const mbchar_t mbc); + extern bool mb_isdigit (const mbchar_t mbc); + extern bool mb_isgraph (const mbchar_t mbc); + extern bool mb_islower (const mbchar_t mbc); + extern bool mb_isprint (const mbchar_t mbc); + extern bool mb_ispunct (const mbchar_t mbc); + extern bool mb_isspace (const mbchar_t mbc); + extern bool mb_isupper (const mbchar_t mbc); + extern bool mb_isxdigit (const mbchar_t mbc); + extern int mb_width (const mbchar_t mbc); + extern void mb_putc (const mbchar_t mbc, FILE *stream); + extern void mb_setascii (mbchar_t *new, char sc); + extern void mb_copy (mbchar_t *new, const mbchar_t *old); + */ + +#ifndef _MBCHAR_H +#define _MBCHAR_H 1 + +#include +#include + +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.1 has a bug: and must be included before + . */ +#include +#include +#include +#include + +#ifndef _GL_INLINE_HEADER_BEGIN + #error "Please include config.h first." +#endif +_GL_INLINE_HEADER_BEGIN +#ifndef MBCHAR_INLINE +# define MBCHAR_INLINE _GL_INLINE +#endif + +#define MBCHAR_BUF_SIZE 24 + +struct mbchar +{ + const char *ptr; /* pointer to current character */ + size_t bytes; /* number of bytes of current character, > 0 */ + bool wc_valid; /* true if wc is a valid wide character */ + wchar_t wc; /* if wc_valid: the current character */ + char buf[MBCHAR_BUF_SIZE]; /* room for the bytes, used for file input only */ +}; + +/* EOF (not a real character) is represented with bytes = 0 and + wc_valid = false. */ + +typedef struct mbchar mbchar_t; + +/* Access the current character. */ +#define mb_ptr(mbc) ((mbc).ptr) +#define mb_len(mbc) ((mbc).bytes) + +/* Comparison of characters. */ +#define mb_iseq(mbc, sc) ((mbc).wc_valid && (mbc).wc == (sc)) +#define mb_isnul(mbc) ((mbc).wc_valid && (mbc).wc == 0) +#define mb_cmp(mbc1, mbc2) \ + ((mbc1).wc_valid \ + ? ((mbc2).wc_valid \ + ? (int) (mbc1).wc - (int) (mbc2).wc \ + : -1) \ + : ((mbc2).wc_valid \ + ? 1 \ + : (mbc1).bytes == (mbc2).bytes \ + ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ + : (mbc1).bytes < (mbc2).bytes \ + ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \ + : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1))) +#define mb_casecmp(mbc1, mbc2) \ + ((mbc1).wc_valid \ + ? ((mbc2).wc_valid \ + ? (int) towlower ((mbc1).wc) - (int) towlower ((mbc2).wc) \ + : -1) \ + : ((mbc2).wc_valid \ + ? 1 \ + : (mbc1).bytes == (mbc2).bytes \ + ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ + : (mbc1).bytes < (mbc2).bytes \ + ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \ + : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1))) +#define mb_equal(mbc1, mbc2) \ + ((mbc1).wc_valid && (mbc2).wc_valid \ + ? (mbc1).wc == (mbc2).wc \ + : (mbc1).bytes == (mbc2).bytes \ + && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0) +#define mb_caseequal(mbc1, mbc2) \ + ((mbc1).wc_valid && (mbc2).wc_valid \ + ? towlower ((mbc1).wc) == towlower ((mbc2).wc) \ + : (mbc1).bytes == (mbc2).bytes \ + && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0) + +/* , classification. */ +#define mb_isascii(mbc) \ + ((mbc).wc_valid && (mbc).wc >= 0 && (mbc).wc <= 127) +#define mb_isalnum(mbc) ((mbc).wc_valid && iswalnum ((mbc).wc)) +#define mb_isalpha(mbc) ((mbc).wc_valid && iswalpha ((mbc).wc)) +#define mb_isblank(mbc) ((mbc).wc_valid && iswblank ((mbc).wc)) +#define mb_iscntrl(mbc) ((mbc).wc_valid && iswcntrl ((mbc).wc)) +#define mb_isdigit(mbc) ((mbc).wc_valid && iswdigit ((mbc).wc)) +#define mb_isgraph(mbc) ((mbc).wc_valid && iswgraph ((mbc).wc)) +#define mb_islower(mbc) ((mbc).wc_valid && iswlower ((mbc).wc)) +#define mb_isprint(mbc) ((mbc).wc_valid && iswprint ((mbc).wc)) +#define mb_ispunct(mbc) ((mbc).wc_valid && iswpunct ((mbc).wc)) +#define mb_isspace(mbc) ((mbc).wc_valid && iswspace ((mbc).wc)) +#define mb_isupper(mbc) ((mbc).wc_valid && iswupper ((mbc).wc)) +#define mb_isxdigit(mbc) ((mbc).wc_valid && iswxdigit ((mbc).wc)) + +/* Extra function. */ + +/* Unprintable characters appear as a small box of width 1. */ +#define MB_UNPRINTABLE_WIDTH 1 + +MBCHAR_INLINE int +mb_width_aux (wint_t wc) +{ + int w = wcwidth (wc); + /* For unprintable characters, arbitrarily return 0 for control characters + and MB_UNPRINTABLE_WIDTH otherwise. */ + return (w >= 0 ? w : iswcntrl (wc) ? 0 : MB_UNPRINTABLE_WIDTH); +} + +#define mb_width(mbc) \ + ((mbc).wc_valid ? mb_width_aux ((mbc).wc) : MB_UNPRINTABLE_WIDTH) + +/* Output. */ +#define mb_putc(mbc, stream) fwrite ((mbc).ptr, 1, (mbc).bytes, (stream)) + +/* Assignment. */ +#define mb_setascii(mbc, sc) \ + ((mbc)->ptr = (mbc)->buf, (mbc)->bytes = 1, (mbc)->wc_valid = 1, \ + (mbc)->wc = (mbc)->buf[0] = (sc)) + +/* Copying a character. */ +MBCHAR_INLINE void +mb_copy (mbchar_t *new_mbc, const mbchar_t *old_mbc) +{ + if (old_mbc->ptr == &old_mbc->buf[0]) + { + memcpy (&new_mbc->buf[0], &old_mbc->buf[0], old_mbc->bytes); + new_mbc->ptr = &new_mbc->buf[0]; + } + else + new_mbc->ptr = old_mbc->ptr; + new_mbc->bytes = old_mbc->bytes; + if ((new_mbc->wc_valid = old_mbc->wc_valid)) + new_mbc->wc = old_mbc->wc; +} + + +/* is_basic(c) tests whether the single-byte character c is in the + ISO C "basic character set". + This is a convenience function, and is in this file only to share code + between mbiter_multi.h and mbfile_multi.h. */ +#if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ + && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ + && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \ + && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \ + && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \ + && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \ + && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \ + && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \ + && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \ + && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \ + && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \ + && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \ + && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \ + && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \ + && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \ + && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \ + && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \ + && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \ + && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \ + && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \ + && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \ + && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ + && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126) +/* The character set is ISO-646, not EBCDIC. */ +# define IS_BASIC_ASCII 1 + +extern const unsigned int is_basic_table[]; + +MBCHAR_INLINE bool +is_basic (char c) +{ + return (is_basic_table [(unsigned char) c >> 5] >> ((unsigned char) c & 31)) + & 1; +} + +#else + +MBCHAR_INLINE bool +is_basic (char c) +{ + switch (c) + { + case '\t': case '\v': case '\f': + case ' ': case '!': case '"': case '#': case '%': + case '&': case '\'': case '(': case ')': case '*': + case '+': case ',': case '-': case '.': case '/': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case ':': case ';': case '<': case '=': case '>': + case '?': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '[': case '\\': case ']': case '^': case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': case '{': case '|': case '}': case '~': + return 1; + default: + return 0; + } +} + +#endif + +_GL_INLINE_HEADER_END + +#endif /* _MBCHAR_H */ diff --git a/contrib/tools/bison/lib/mbfile.c b/contrib/tools/bison/lib/mbfile.c new file mode 100644 index 000000000000..b0a468efa6b7 --- /dev/null +++ b/contrib/tools/bison/lib/mbfile.c @@ -0,0 +1,3 @@ +#include +#define MBFILE_INLINE _GL_EXTERN_INLINE +#include "mbfile.h" diff --git a/contrib/tools/bison/lib/mbfile.h b/contrib/tools/bison/lib/mbfile.h new file mode 100644 index 000000000000..6c86116f1c9b --- /dev/null +++ b/contrib/tools/bison/lib/mbfile.h @@ -0,0 +1,252 @@ +/* Multibyte character I/O: macros for multi-byte encodings. + Copyright (C) 2001, 2005, 2009-2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Mitsuru Chinen + and Bruno Haible . */ + +/* The macros in this file implement multi-byte character input from a + stream. + + mb_file_t + is the type for multibyte character input stream, usable for variable + declarations. + + mbf_char_t + is the type for multibyte character or EOF, usable for variable + declarations. + + mbf_init (mbf, stream) + initializes the MB_FILE for reading from stream. + + mbf_getc (mbc, mbf) + reads the next multibyte character from mbf and stores it in mbc. + + mb_iseof (mbc) + returns true if mbc represents the EOF value. + + Here are the function prototypes of the macros. + + extern void mbf_init (mb_file_t mbf, FILE *stream); + extern void mbf_getc (mbf_char_t mbc, mb_file_t mbf); + extern bool mb_iseof (const mbf_char_t mbc); + */ + +#ifndef _MBFILE_H +#define _MBFILE_H 1 + +#include +#include +#include +#include + +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.1 has a bug: and must be included before + . */ +#include +#include +#include + +#include "mbchar.h" + +#ifndef _GL_INLINE_HEADER_BEGIN + #error "Please include config.h first." +#endif +_GL_INLINE_HEADER_BEGIN +#ifndef MBFILE_INLINE +# define MBFILE_INLINE _GL_INLINE +#endif + +struct mbfile_multi { + FILE *fp; + bool eof_seen; + bool have_pushback; + mbstate_t state; + unsigned int bufcount; + char buf[MBCHAR_BUF_SIZE]; + struct mbchar pushback; +}; + +MBFILE_INLINE void +mbfile_multi_getc (struct mbchar *mbc, struct mbfile_multi *mbf) +{ + size_t bytes; + + /* If EOF has already been seen, don't use getc. This matters if + mbf->fp is connected to an interactive tty. */ + if (mbf->eof_seen) + goto eof; + + /* Return character pushed back, if there is one. */ + if (mbf->have_pushback) + { + mb_copy (mbc, &mbf->pushback); + mbf->have_pushback = false; + return; + } + + /* Before using mbrtowc, we need at least one byte. */ + if (mbf->bufcount == 0) + { + int c = getc (mbf->fp); + if (c == EOF) + { + mbf->eof_seen = true; + goto eof; + } + mbf->buf[0] = (unsigned char) c; + mbf->bufcount++; + } + + /* Handle most ASCII characters quickly, without calling mbrtowc(). */ + if (mbf->bufcount == 1 && mbsinit (&mbf->state) && is_basic (mbf->buf[0])) + { + /* These characters are part of the basic character set. ISO C 99 + guarantees that their wide character code is identical to their + char code. */ + mbc->wc = mbc->buf[0] = mbf->buf[0]; + mbc->wc_valid = true; + mbc->ptr = &mbc->buf[0]; + mbc->bytes = 1; + mbf->bufcount = 0; + return; + } + + /* Use mbrtowc on an increasing number of bytes. Read only as many bytes + from mbf->fp as needed. This is needed to give reasonable interactive + behaviour when mbf->fp is connected to an interactive tty. */ + for (;;) + { + /* We don't know whether the 'mbrtowc' function updates the state when + it returns -2, - this is the ISO C 99 and glibc-2.2 behaviour - or + not - amended ANSI C, glibc-2.1 and Solaris 2.7 behaviour. We + don't have an autoconf test for this, yet. + The new behaviour would allow us to feed the bytes one by one into + mbrtowc. But the old behaviour forces us to feed all bytes since + the end of the last character into mbrtowc. Since we want to retry + with more bytes when mbrtowc returns -2, we must backup the state + before calling mbrtowc, because implementations with the new + behaviour will clobber it. */ + mbstate_t backup_state = mbf->state; + + bytes = mbrtowc (&mbc->wc, &mbf->buf[0], mbf->bufcount, &mbf->state); + + if (bytes == (size_t) -1) + { + /* An invalid multibyte sequence was encountered. */ + /* Return a single byte. */ + bytes = 1; + mbc->wc_valid = false; + break; + } + else if (bytes == (size_t) -2) + { + /* An incomplete multibyte character. */ + mbf->state = backup_state; + if (mbf->bufcount == MBCHAR_BUF_SIZE) + { + /* An overlong incomplete multibyte sequence was encountered. */ + /* Return a single byte. */ + bytes = 1; + mbc->wc_valid = false; + break; + } + else + { + /* Read one more byte and retry mbrtowc. */ + int c = getc (mbf->fp); + if (c == EOF) + { + /* An incomplete multibyte character at the end. */ + mbf->eof_seen = true; + bytes = mbf->bufcount; + mbc->wc_valid = false; + break; + } + mbf->buf[mbf->bufcount] = (unsigned char) c; + mbf->bufcount++; + } + } + else + { + if (bytes == 0) + { + /* A null wide character was encountered. */ + bytes = 1; + assert (mbf->buf[0] == '\0'); + assert (mbc->wc == 0); + } + mbc->wc_valid = true; + break; + } + } + + /* Return the multibyte sequence mbf->buf[0..bytes-1]. */ + mbc->ptr = &mbc->buf[0]; + memcpy (&mbc->buf[0], &mbf->buf[0], bytes); + mbc->bytes = bytes; + + mbf->bufcount -= bytes; + if (mbf->bufcount > 0) + { + /* It's not worth calling memmove() for so few bytes. */ + unsigned int count = mbf->bufcount; + char *p = &mbf->buf[0]; + + do + { + *p = *(p + bytes); + p++; + } + while (--count > 0); + } + return; + +eof: + /* An mbchar_t with bytes == 0 is used to indicate EOF. */ + mbc->ptr = NULL; + mbc->bytes = 0; + mbc->wc_valid = false; + return; +} + +MBFILE_INLINE void +mbfile_multi_ungetc (const struct mbchar *mbc, struct mbfile_multi *mbf) +{ + mb_copy (&mbf->pushback, mbc); + mbf->have_pushback = true; +} + +typedef struct mbfile_multi mb_file_t; + +typedef mbchar_t mbf_char_t; + +#define mbf_init(mbf, stream) \ + ((mbf).fp = (stream), \ + (mbf).eof_seen = false, \ + (mbf).have_pushback = false, \ + memset (&(mbf).state, '\0', sizeof (mbstate_t)), \ + (mbf).bufcount = 0) + +#define mbf_getc(mbc, mbf) mbfile_multi_getc (&(mbc), &(mbf)) + +#define mbf_ungetc(mbc, mbf) mbfile_multi_ungetc (&(mbc), &(mbf)) + +#define mb_iseof(mbc) ((mbc).bytes == 0) + +_GL_INLINE_HEADER_END + +#endif /* _MBFILE_H */ diff --git a/contrib/tools/bison/lib/mbrtowc.c b/contrib/tools/bison/lib/mbrtowc.c index bbe3f7a3b91e..08e181bc3bcb 100644 --- a/contrib/tools/bison/lib/mbrtowc.c +++ b/contrib/tools/bison/lib/mbrtowc.c @@ -1,5 +1,5 @@ /* Convert multibyte character to wide character. - Copyright (C) 1999-2002, 2005-2019 Free Software Foundation, Inc. + Copyright (C) 1999-2002, 2005-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2008. This program is free software: you can redistribute it and/or modify @@ -20,20 +20,39 @@ /* Specification. */ #include -#if C_LOCALE_MAYBE_EILSEQ -# include "hard-locale.h" -# include -#endif - #if GNULIB_defined_mbstate_t -/* Implement mbrtowc() on top of mbtowc(). */ +/* Implement mbrtowc() on top of mbtowc() for the non-UTF-8 locales + and directly for the UTF-8 locales. */ # include +# include # include -# include "localcharset.h" -# include "streq.h" +# if defined _WIN32 && !defined __CYGWIN__ + +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include + +# elif HAVE_PTHREAD_API + +# include +# if HAVE_THREADS_H && HAVE_WEAK_SYMBOLS +# include +# pragma weak thrd_exit +# define c11_threads_in_use() (thrd_exit != NULL) +# else +# define c11_threads_in_use() 0 +# endif + +# elif HAVE_THREADS_H + +# include + +# endif + # include "verify.h" +# error #include "lc-charset-dispatch.h" +# error #include "mbtowc-lock.h" # ifndef FALLTHROUGH # if __GNUC__ < 7 @@ -43,342 +62,24 @@ # endif # endif -/* Returns a classification of special values of the encoding of the current - locale. */ -typedef enum { - enc_other, /* other */ - enc_utf8, /* UTF-8 */ - enc_eucjp, /* EUC-JP */ - enc_94, /* EUC-KR, GB2312, BIG5 */ - enc_euctw, /* EUC-TW */ - enc_gb18030, /* GB18030 */ - enc_sjis /* SJIS */ -} enc_t; -static inline enc_t -locale_enc (void) -{ - const char *encoding = locale_charset (); - if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0)) - return enc_utf8; - if (STREQ_OPT (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0)) - return enc_eucjp; - if (STREQ_OPT (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0) - || STREQ_OPT (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0) - || STREQ_OPT (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0)) - return enc_94; - if (STREQ_OPT (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0)) - return enc_euctw; - if (STREQ_OPT (encoding, "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0)) - return enc_gb18030; - if (STREQ_OPT (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0)) - return enc_sjis; - return enc_other; -} - -#if GNULIB_WCHAR_SINGLE -/* When we know that the locale does not change, provide a speedup by - caching the value of locale_enc. */ -static int cached_locale_enc = -1; -static inline enc_t -locale_enc_cached (void) -{ - if (cached_locale_enc < 0) - cached_locale_enc = locale_enc (); - return cached_locale_enc; -} -#else -/* By default, don't make assumptions, hence no caching. */ -# define locale_enc_cached locale_enc -#endif - verify (sizeof (mbstate_t) >= 4); - static char internal_state[4]; size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) { - char *pstate = (char *)ps; - - if (s == NULL) - { - pwc = NULL; - s = ""; - n = 1; - } - - if (n == 0) - return (size_t)(-2); - - /* Here n > 0. */ - - if (pstate == NULL) - pstate = internal_state; - - { - size_t nstate = pstate[0]; - char buf[4]; - const char *p; - size_t m; - - switch (nstate) - { - case 0: - p = s; - m = n; - break; - case 3: - buf[2] = pstate[3]; - FALLTHROUGH; - case 2: - buf[1] = pstate[2]; - FALLTHROUGH; - case 1: - buf[0] = pstate[1]; - p = buf; - m = nstate; - buf[m++] = s[0]; - if (n >= 2 && m < 4) - { - buf[m++] = s[1]; - if (n >= 3 && m < 4) - buf[m++] = s[2]; - } - break; - default: - errno = EINVAL; - return (size_t)(-1); - } - - /* Here m > 0. */ - -# if __GLIBC__ || defined __UCLIBC__ - /* Work around bug */ - mbtowc (NULL, NULL, 0); -# endif - { - int res = mbtowc (pwc, p, m); - - if (res >= 0) - { - if (pwc != NULL && ((*pwc == 0) != (res == 0))) - abort (); - if (nstate >= (res > 0 ? res : 1)) - abort (); - res -= nstate; - pstate[0] = 0; - return res; - } - - /* mbtowc does not distinguish between invalid and incomplete multibyte - sequences. But mbrtowc needs to make this distinction. - There are two possible approaches: - - Use iconv() and its return value. - - Use built-in knowledge about the possible encodings. - Given the low quality of implementation of iconv() on the systems that - lack mbrtowc(), we use the second approach. - The possible encodings are: - - 8-bit encodings, - - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, GB18030, SJIS, - - UTF-8. - Use specialized code for each. */ - if (m >= 4 || m >= MB_CUR_MAX) - goto invalid; - /* Here MB_CUR_MAX > 1 and 0 < m < 4. */ - switch (locale_enc_cached ()) - { - case enc_utf8: /* UTF-8 */ - { - /* Cf. unistr/u8-mblen.c. */ - unsigned char c = (unsigned char) p[0]; - - if (c >= 0xc2) - { - if (c < 0xe0) - { - if (m == 1) - goto incomplete; - } - else if (c < 0xf0) - { - if (m == 1) - goto incomplete; - if (m == 2) - { - unsigned char c2 = (unsigned char) p[1]; - - if ((c2 ^ 0x80) < 0x40 - && (c >= 0xe1 || c2 >= 0xa0) - && (c != 0xed || c2 < 0xa0)) - goto incomplete; - } - } - else if (c <= 0xf4) - { - if (m == 1) - goto incomplete; - else /* m == 2 || m == 3 */ - { - unsigned char c2 = (unsigned char) p[1]; - - if ((c2 ^ 0x80) < 0x40 - && (c >= 0xf1 || c2 >= 0x90) - && (c < 0xf4 || (c == 0xf4 && c2 < 0x90))) - { - if (m == 2) - goto incomplete; - else /* m == 3 */ - { - unsigned char c3 = (unsigned char) p[2]; - - if ((c3 ^ 0x80) < 0x40) - goto incomplete; - } - } - } - } - } - goto invalid; - } - - /* As a reference for this code, you can use the GNU libiconv - implementation. Look for uses of the RET_TOOFEW macro. */ - - case enc_eucjp: /* EUC-JP */ - { - if (m == 1) - { - unsigned char c = (unsigned char) p[0]; - - if ((c >= 0xa1 && c < 0xff) || c == 0x8e || c == 0x8f) - goto incomplete; - } - if (m == 2) - { - unsigned char c = (unsigned char) p[0]; - - if (c == 0x8f) - { - unsigned char c2 = (unsigned char) p[1]; - - if (c2 >= 0xa1 && c2 < 0xff) - goto incomplete; - } - } - goto invalid; - } - - case enc_94: /* EUC-KR, GB2312, BIG5 */ - { - if (m == 1) - { - unsigned char c = (unsigned char) p[0]; - - if (c >= 0xa1 && c < 0xff) - goto incomplete; - } - goto invalid; - } - - case enc_euctw: /* EUC-TW */ - { - if (m == 1) - { - unsigned char c = (unsigned char) p[0]; - - if ((c >= 0xa1 && c < 0xff) || c == 0x8e) - goto incomplete; - } - else /* m == 2 || m == 3 */ - { - unsigned char c = (unsigned char) p[0]; - - if (c == 0x8e) - goto incomplete; - } - goto invalid; - } - - case enc_gb18030: /* GB18030 */ - { - if (m == 1) - { - unsigned char c = (unsigned char) p[0]; - - if ((c >= 0x90 && c <= 0xe3) || (c >= 0xf8 && c <= 0xfe)) - goto incomplete; - } - else /* m == 2 || m == 3 */ - { - unsigned char c = (unsigned char) p[0]; - - if (c >= 0x90 && c <= 0xe3) - { - unsigned char c2 = (unsigned char) p[1]; - - if (c2 >= 0x30 && c2 <= 0x39) - { - if (m == 2) - goto incomplete; - else /* m == 3 */ - { - unsigned char c3 = (unsigned char) p[2]; - - if (c3 >= 0x81 && c3 <= 0xfe) - goto incomplete; - } - } - } - } - goto invalid; - } - - case enc_sjis: /* SJIS */ - { - if (m == 1) - { - unsigned char c = (unsigned char) p[0]; - - if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea) - || (c >= 0xf0 && c <= 0xf9)) - goto incomplete; - } - goto invalid; - } - - default: - /* An unknown multibyte encoding. */ - goto incomplete; - } - - incomplete: - { - size_t k = nstate; - /* Here 0 <= k < m < 4. */ - pstate[++k] = s[0]; - if (k < m) - { - pstate[++k] = s[1]; - if (k < m) - pstate[++k] = s[2]; - } - if (k != m) - abort (); - } - pstate[0] = m; - return (size_t)(-2); - - invalid: - errno = EILSEQ; - /* The conversion state is undefined, says POSIX. */ - return (size_t)(-1); - } - } +# define FITS_IN_CHAR_TYPE(wc) ((wc) <= WCHAR_MAX) +# error #include "mbrtowc-impl.h" } #else /* Override the system's mbrtowc() function. */ +# if MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ +# include "hard-locale.h" +# include +# endif + # undef mbrtowc size_t @@ -436,14 +137,20 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) } # endif +# if MBRTOWC_STORES_INCOMPLETE_BUG + ret = mbrtowc (&wc, s, n, ps); + if (ret < (size_t) -2 && pwc != NULL) + *pwc = wc; +# else ret = mbrtowc (pwc, s, n, ps); +# endif # if MBRTOWC_NUL_RETVAL_BUG if (ret < (size_t) -2 && !*pwc) return 0; # endif -# if C_LOCALE_MAYBE_EILSEQ +# if MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ if ((size_t) -2 <= ret && n != 0 && ! hard_locale (LC_CTYPE)) { unsigned char uc = *s; diff --git a/contrib/tools/bison/lib/mbswidth.c b/contrib/tools/bison/lib/mbswidth.c index 408a15e34480..a3f2099beef4 100644 --- a/contrib/tools/bison/lib/mbswidth.c +++ b/contrib/tools/bison/lib/mbswidth.c @@ -1,5 +1,5 @@ /* Determine the number of screen columns needed for a string. - Copyright (C) 2000-2019 Free Software Foundation, Inc. + Copyright (C) 2000-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/mbswidth.h b/contrib/tools/bison/lib/mbswidth.h index 2b5c53c3728a..50ef747da85a 100644 --- a/contrib/tools/bison/lib/mbswidth.h +++ b/contrib/tools/bison/lib/mbswidth.h @@ -1,5 +1,5 @@ /* Determine the number of screen columns needed for a string. - Copyright (C) 2000-2004, 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2000-2004, 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/minmax.h b/contrib/tools/bison/lib/minmax.h index d7f6bea0619c..b9477767b0df 100644 --- a/contrib/tools/bison/lib/minmax.h +++ b/contrib/tools/bison/lib/minmax.h @@ -1,5 +1,5 @@ /* MIN, MAX macros. - Copyright (C) 1995, 1998, 2001, 2003, 2005, 2009-2019 Free Software + Copyright (C) 1995, 1998, 2001, 2003, 2005, 2009-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/msvc-inval.c b/contrib/tools/bison/lib/msvc-inval.c index 75b5a070ab59..863668889c6a 100644 --- a/contrib/tools/bison/lib/msvc-inval.c +++ b/contrib/tools/bison/lib/msvc-inval.c @@ -1,5 +1,5 @@ /* Invalid parameter handler for MSVC runtime libraries. - Copyright (C) 2011-2019 Free Software Foundation, Inc. + Copyright (C) 2011-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/msvc-inval.h b/contrib/tools/bison/lib/msvc-inval.h index e31cf650919a..93ee7859ca9e 100644 --- a/contrib/tools/bison/lib/msvc-inval.h +++ b/contrib/tools/bison/lib/msvc-inval.h @@ -1,5 +1,5 @@ /* Invalid parameter handler for MSVC runtime libraries. - Copyright (C) 2011-2019 Free Software Foundation, Inc. + Copyright (C) 2011-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -95,7 +95,7 @@ extern void gl_msvc_inval_ensure_handler (void); /* Gnulib can define its own status codes, as described in the page "Raising Software Exceptions" on microsoft.com - . + . Our status codes are composed of - 0xE0000000, mandatory for all user-defined status codes, - 0x474E550, a API identifier ("GNU"), @@ -106,7 +106,7 @@ extern void gl_msvc_inval_ensure_handler (void); # if defined _MSC_VER /* A compiler that supports __try/__except, as described in the page "try-except statement" on microsoft.com - . + . With __try/__except, we can use the multithread-safe exception handling. */ # ifdef __cplusplus diff --git a/contrib/tools/bison/lib/msvc-nothrow.c b/contrib/tools/bison/lib/msvc-nothrow.c index 49b709ca4aa0..bf93b8824121 100644 --- a/contrib/tools/bison/lib/msvc-nothrow.c +++ b/contrib/tools/bison/lib/msvc-nothrow.c @@ -1,6 +1,6 @@ /* Wrappers that don't throw invalid parameter notifications with MSVC runtime libraries. - Copyright (C) 2011-2019 Free Software Foundation, Inc. + Copyright (C) 2011-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/msvc-nothrow.h b/contrib/tools/bison/lib/msvc-nothrow.h index 8d3ca7892e89..fca541573fc3 100644 --- a/contrib/tools/bison/lib/msvc-nothrow.h +++ b/contrib/tools/bison/lib/msvc-nothrow.h @@ -1,6 +1,6 @@ /* Wrappers that don't throw invalid parameter notifications with MSVC runtime libraries. - Copyright (C) 2011-2019 Free Software Foundation, Inc. + Copyright (C) 2011-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/obstack.c b/contrib/tools/bison/lib/obstack.c index 411de4742907..780cda7b529c 100644 --- a/contrib/tools/bison/lib/obstack.c +++ b/contrib/tools/bison/lib/obstack.c @@ -1,5 +1,5 @@ /* obstack.c - subroutines used implicitly by object stack macros - Copyright (C) 1988-2019 Free Software Foundation, Inc. + Copyright (C) 1988-2020 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or diff --git a/contrib/tools/bison/lib/obstack.h b/contrib/tools/bison/lib/obstack.h index 90ba66004b0f..3a7beb0ca3fd 100644 --- a/contrib/tools/bison/lib/obstack.h +++ b/contrib/tools/bison/lib/obstack.h @@ -1,5 +1,5 @@ /* obstack.h - object stack macros - Copyright (C) 1988-2019 Free Software Foundation, Inc. + Copyright (C) 1988-2020 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or diff --git a/contrib/tools/bison/lib/obstack_printf.c b/contrib/tools/bison/lib/obstack_printf.c index 0d59a8bcfff6..cdb9ecdabe48 100644 --- a/contrib/tools/bison/lib/obstack_printf.c +++ b/contrib/tools/bison/lib/obstack_printf.c @@ -1,5 +1,5 @@ /* Formatted output to obstacks. - Copyright (C) 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2008-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/open.c b/contrib/tools/bison/lib/open.c index 655260572d42..487194f6652b 100644 --- a/contrib/tools/bison/lib/open.c +++ b/contrib/tools/bison/lib/open.c @@ -1,5 +1,5 @@ /* Open a descriptor to a file. - Copyright (C) 2007-2019 Free Software Foundation, Inc. + Copyright (C) 2007-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -92,22 +92,19 @@ open (const char *filename, int flags, ...) #endif #if OPEN_TRAILING_SLASH_BUG - /* If the filename ends in a slash and one of O_CREAT, O_WRONLY, O_RDWR - is specified, then fail. - Rationale: POSIX - says that - "A pathname that contains at least one non-slash character and that - ends with one or more trailing slashes shall be resolved as if a - single dot character ( '.' ) were appended to the pathname." - and - "The special filename dot shall refer to the directory specified by - its predecessor." + /* Fail if one of O_CREAT, O_WRONLY, O_RDWR is specified and the filename + ends in a slash, as POSIX says such a filename must name a directory + : + "A pathname that contains at least one non- character and that + ends with one or more trailing characters shall not be resolved + successfully unless the last pathname component before the trailing + characters names an existing directory" If the named file already exists as a directory, then - if O_CREAT is specified, open() must fail because of the semantics of O_CREAT, - if O_WRONLY or O_RDWR is specified, open() must fail because POSIX - says that it - fails with errno = EISDIR in this case. + + says that it fails with errno = EISDIR in this case. If the named file does not exist or does not name a directory, then - if O_CREAT is specified, open() must fail since open() cannot create directories, @@ -171,14 +168,12 @@ open (const char *filename, int flags, ...) #if OPEN_TRAILING_SLASH_BUG /* If the filename ends in a slash and fd does not refer to a directory, then fail. - Rationale: POSIX - says that - "A pathname that contains at least one non-slash character and that - ends with one or more trailing slashes shall be resolved as if a - single dot character ( '.' ) were appended to the pathname." - and - "The special filename dot shall refer to the directory specified by - its predecessor." + Rationale: POSIX says such a filename must name a directory + : + "A pathname that contains at least one non- character and that + ends with one or more trailing characters shall not be resolved + successfully unless the last pathname component before the trailing + characters names an existing directory" If the named file without the slash is not a directory, open() must fail with ENOTDIR. */ if (fd >= 0) diff --git a/contrib/tools/bison/lib/path-join.c b/contrib/tools/bison/lib/path-join.c index 727874222a7c..411f33160394 100644 --- a/contrib/tools/bison/lib/path-join.c +++ b/contrib/tools/bison/lib/path-join.c @@ -1,5 +1,5 @@ /* Concatenate path components. - Copyright (C) 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the diff --git a/contrib/tools/bison/lib/path-join.h b/contrib/tools/bison/lib/path-join.h index 0ac7055ff0a2..c4444a472ccd 100644 --- a/contrib/tools/bison/lib/path-join.h +++ b/contrib/tools/bison/lib/path-join.h @@ -1,5 +1,5 @@ /* Concatenate path components. - Copyright (C) 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the diff --git a/contrib/tools/bison/lib/pipe-safer.c b/contrib/tools/bison/lib/pipe-safer.c index 62017397c60e..5a597c527015 100644 --- a/contrib/tools/bison/lib/pipe-safer.c +++ b/contrib/tools/bison/lib/pipe-safer.c @@ -1,5 +1,5 @@ /* Invoke pipe, but avoid some glitches. - Copyright (C) 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/pipe2-safer.c b/contrib/tools/bison/lib/pipe2-safer.c index 390d96b51c37..b644daa38c81 100644 --- a/contrib/tools/bison/lib/pipe2-safer.c +++ b/contrib/tools/bison/lib/pipe2-safer.c @@ -1,5 +1,5 @@ /* Invoke pipe2, but avoid some glitches. - Copyright (C) 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/pipe2.c b/contrib/tools/bison/lib/pipe2.c index 15a5dec98527..591e94db4ce1 100644 --- a/contrib/tools/bison/lib/pipe2.c +++ b/contrib/tools/bison/lib/pipe2.c @@ -1,5 +1,5 @@ /* Create a pipe, with specific opening flags. - Copyright (C) 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -107,7 +107,7 @@ pipe2 (int fd[2], int flags) if (pipe (fd) < 0) return -1; - /* POSIX + /* POSIX says that initially, the O_NONBLOCK and FD_CLOEXEC flags are cleared on both fd[0] and fd[1]. */ diff --git a/contrib/tools/bison/lib/platform/win64/sys/ioctl.h b/contrib/tools/bison/lib/platform/win64/sys/ioctl.h new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/contrib/tools/bison/lib/platform/win64/sys/stat.h b/contrib/tools/bison/lib/platform/win64/sys/stat.h index bf7dc29f6e56..7a9004a80d21 100644 --- a/contrib/tools/bison/lib/platform/win64/sys/stat.h +++ b/contrib/tools/bison/lib/platform/win64/sys/stat.h @@ -653,8 +653,8 @@ _GL_WARN_ON_USE (fchmodat, "fchmodat is not portable - " #endif -#if 1 -# if 1 +#if 0 +# if 0 # if !(defined __cplusplus && defined GNULIB_NAMESPACE) # undef fstat # define fstat rpl_fstat @@ -665,7 +665,7 @@ _GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf)); _GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf)); # endif _GL_CXXALIASWARN (fstat); -#elif 1 +#elif 0 /* Above, we define stat to _stati64. */ # define fstat _fstati64 #elif defined GNULIB_POSIXCHECK diff --git a/contrib/tools/bison/lib/platform/win64/termios.h b/contrib/tools/bison/lib/platform/win64/termios.h new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/contrib/tools/bison/lib/printf-args.c b/contrib/tools/bison/lib/printf-args.c index e45cfbede10e..943b77c23ce2 100644 --- a/contrib/tools/bison/lib/printf-args.c +++ b/contrib/tools/bison/lib/printf-args.c @@ -1,5 +1,5 @@ /* Decomposed printf argument list. - Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2019 Free Software + Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -65,14 +65,12 @@ PRINTF_FETCHARGS (va_list args, arguments *a) case TYPE_ULONGINT: ap->a.a_ulongint = va_arg (args, unsigned long int); break; -#if HAVE_LONG_LONG_INT case TYPE_LONGLONGINT: ap->a.a_longlongint = va_arg (args, long long int); break; case TYPE_ULONGLONGINT: ap->a.a_ulonglongint = va_arg (args, unsigned long long int); break; -#endif case TYPE_DOUBLE: ap->a.a_double = va_arg (args, double); break; @@ -135,11 +133,9 @@ PRINTF_FETCHARGS (va_list args, arguments *a) case TYPE_COUNT_LONGINT_POINTER: ap->a.a_count_longint_pointer = va_arg (args, long int *); break; -#if HAVE_LONG_LONG_INT case TYPE_COUNT_LONGLONGINT_POINTER: ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); break; -#endif #if ENABLE_UNISTDIO /* The unistdio extensions. */ case TYPE_U8_STRING: diff --git a/contrib/tools/bison/lib/printf-args.h b/contrib/tools/bison/lib/printf-args.h index 866cba04d8ca..781f5723828b 100644 --- a/contrib/tools/bison/lib/printf-args.h +++ b/contrib/tools/bison/lib/printf-args.h @@ -1,5 +1,5 @@ /* Decomposed printf argument list. - Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2019 Free Software + Copyright (C) 1999, 2002-2003, 2006-2007, 2011-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -57,10 +57,8 @@ typedef enum TYPE_UINT, TYPE_LONGINT, TYPE_ULONGINT, -#if HAVE_LONG_LONG_INT TYPE_LONGLONGINT, TYPE_ULONGLONGINT, -#endif TYPE_DOUBLE, TYPE_LONGDOUBLE, TYPE_CHAR, @@ -75,10 +73,8 @@ typedef enum TYPE_COUNT_SCHAR_POINTER, TYPE_COUNT_SHORT_POINTER, TYPE_COUNT_INT_POINTER, - TYPE_COUNT_LONGINT_POINTER -#if HAVE_LONG_LONG_INT -, TYPE_COUNT_LONGLONGINT_POINTER -#endif + TYPE_COUNT_LONGINT_POINTER, + TYPE_COUNT_LONGLONGINT_POINTER #if ENABLE_UNISTDIO /* The unistdio extensions. */ , TYPE_U8_STRING @@ -101,10 +97,8 @@ typedef struct unsigned int a_uint; long int a_longint; unsigned long int a_ulongint; -#if HAVE_LONG_LONG_INT long long int a_longlongint; unsigned long long int a_ulonglongint; -#endif float a_float; double a_double; long double a_longdouble; @@ -121,9 +115,7 @@ typedef struct short * a_count_short_pointer; int * a_count_int_pointer; long int * a_count_longint_pointer; -#if HAVE_LONG_LONG_INT long long int * a_count_longlongint_pointer; -#endif #if ENABLE_UNISTDIO /* The unistdio extensions. */ const uint8_t * a_u8_string; diff --git a/contrib/tools/bison/lib/printf-frexp.c b/contrib/tools/bison/lib/printf-frexp.c index 77eafab54453..6e1e647b44bb 100644 --- a/contrib/tools/bison/lib/printf-frexp.c +++ b/contrib/tools/bison/lib/printf-frexp.c @@ -1,5 +1,5 @@ /* Split a double into fraction and mantissa, for hexadecimal printf. - Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/printf-frexp.h b/contrib/tools/bison/lib/printf-frexp.h index 93107343adcb..321ea602dcfa 100644 --- a/contrib/tools/bison/lib/printf-frexp.h +++ b/contrib/tools/bison/lib/printf-frexp.h @@ -1,5 +1,5 @@ /* Split a double into fraction and mantissa, for hexadecimal printf. - Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/printf-frexpl.c b/contrib/tools/bison/lib/printf-frexpl.c index 693b88976d4a..7992cbb4b6d9 100644 --- a/contrib/tools/bison/lib/printf-frexpl.c +++ b/contrib/tools/bison/lib/printf-frexpl.c @@ -1,5 +1,5 @@ /* Split a 'long double' into fraction and mantissa, for hexadecimal printf. - Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/printf-frexpl.h b/contrib/tools/bison/lib/printf-frexpl.h index 276076944276..be729dd45e8d 100644 --- a/contrib/tools/bison/lib/printf-frexpl.h +++ b/contrib/tools/bison/lib/printf-frexpl.h @@ -1,5 +1,5 @@ /* Split a 'long double' into fraction and mantissa, for hexadecimal printf. - Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/printf-parse.c b/contrib/tools/bison/lib/printf-parse.c index 8596fd5f305c..99ddbc37a8a4 100644 --- a/contrib/tools/bison/lib/printf-parse.c +++ b/contrib/tools/bison/lib/printf-parse.c @@ -1,5 +1,5 @@ /* Formatted output to strings. - Copyright (C) 1999-2000, 2002-2003, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 1999-2000, 2002-2003, 2006-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -447,14 +447,12 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) switch (c) { case 'd': case 'i': -#if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ + /* If 'long long' is larger than 'long': */ if (flags >= 16 || (flags & 4)) type = TYPE_LONGLONGINT; else -#endif - /* If 'long long' exists and is the same as 'long', we parse - "lld" into TYPE_LONGINT. */ + /* If 'long long' is the same as 'long', we parse "lld" into + TYPE_LONGINT. */ if (flags >= 8) type = TYPE_LONGINT; else if (flags & 2) @@ -465,14 +463,12 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) type = TYPE_INT; break; case 'o': case 'u': case 'x': case 'X': -#if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ + /* If 'unsigned long long' is larger than 'unsigned long': */ if (flags >= 16 || (flags & 4)) type = TYPE_ULONGLONGINT; else -#endif - /* If 'unsigned long long' exists and is the same as - 'unsigned long', we parse "llu" into TYPE_ULONGINT. */ + /* If 'unsigned long long' is the same as 'unsigned long', we + parse "llu" into TYPE_ULONGINT. */ if (flags >= 8) type = TYPE_ULONGINT; else if (flags & 2) @@ -525,14 +521,12 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) type = TYPE_POINTER; break; case 'n': -#if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ + /* If 'long long' is larger than 'long': */ if (flags >= 16 || (flags & 4)) type = TYPE_COUNT_LONGLONGINT_POINTER; else -#endif - /* If 'long long' exists and is the same as 'long', we parse - "lln" into TYPE_COUNT_LONGINT_POINTER. */ + /* If 'long long' is the same as 'long', we parse "lln" into + TYPE_COUNT_LONGINT_POINTER. */ if (flags >= 8) type = TYPE_COUNT_LONGINT_POINTER; else if (flags & 2) diff --git a/contrib/tools/bison/lib/printf-parse.h b/contrib/tools/bison/lib/printf-parse.h index 746bb3fe0fa9..34b91f4f7694 100644 --- a/contrib/tools/bison/lib/printf-parse.h +++ b/contrib/tools/bison/lib/printf-parse.h @@ -1,5 +1,5 @@ /* Parse printf format string. - Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2019 Free Software + Copyright (C) 1999, 2002-2003, 2005, 2007, 2010-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/progname.c b/contrib/tools/bison/lib/progname.c index a42b7fa2f700..d59d969ba659 100644 --- a/contrib/tools/bison/lib/progname.c +++ b/contrib/tools/bison/lib/progname.c @@ -1,5 +1,5 @@ /* Program name management. - Copyright (C) 2001-2003, 2005-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2005-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/progname.h b/contrib/tools/bison/lib/progname.h index c726e97e905e..bc276cc8e781 100644 --- a/contrib/tools/bison/lib/progname.h +++ b/contrib/tools/bison/lib/progname.h @@ -1,5 +1,5 @@ /* Program name management. - Copyright (C) 2001-2004, 2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006, 2009-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/quote.h b/contrib/tools/bison/lib/quote.h index 5cef8ff1e093..391ff1a35390 100644 --- a/contrib/tools/bison/lib/quote.h +++ b/contrib/tools/bison/lib/quote.h @@ -1,6 +1,6 @@ /* quote.h - prototypes for quote.c - Copyright (C) 1998-2001, 2003, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 1998-2001, 2003, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/quotearg.c b/contrib/tools/bison/lib/quotearg.c index 773d53f11549..c78fc1670f44 100644 --- a/contrib/tools/bison/lib/quotearg.c +++ b/contrib/tools/bison/lib/quotearg.c @@ -1,6 +1,6 @@ /* quotearg.c - quote arguments for output - Copyright (C) 1998-2002, 2004-2019 Free Software Foundation, Inc. + Copyright (C) 1998-2002, 2004-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/quotearg.h b/contrib/tools/bison/lib/quotearg.h index 0f07e0211e29..3bf149b39757 100644 --- a/contrib/tools/bison/lib/quotearg.h +++ b/contrib/tools/bison/lib/quotearg.h @@ -1,6 +1,6 @@ /* quotearg.h - quote arguments for output - Copyright (C) 1998-2002, 2004, 2006, 2008-2019 Free Software Foundation, + Copyright (C) 1998-2002, 2004, 2006, 2008-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -323,7 +323,7 @@ void set_custom_quoting (struct quoting_options *o, On output, BUFFER might contain embedded null bytes if ARGSIZE was not -1, the style of O does not use backslash escapes, and the flags of O do not request elision of null bytes.*/ -size_t quotearg_buffer (char *buffer, size_t buffersize, +size_t quotearg_buffer (char *restrict buffer, size_t buffersize, char const *arg, size_t argsize, struct quoting_options const *o); diff --git a/contrib/tools/bison/lib/raise.c b/contrib/tools/bison/lib/raise.c index e750b7a4c649..1b93e529a78d 100644 --- a/contrib/tools/bison/lib/raise.c +++ b/contrib/tools/bison/lib/raise.c @@ -1,6 +1,6 @@ /* Provide a non-threads replacement for the POSIX raise function. - Copyright (C) 2002-2003, 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2003, 2005-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/relocatable.h b/contrib/tools/bison/lib/relocatable.h index 896a7e59c02a..ffb8cdb2ec96 100644 --- a/contrib/tools/bison/lib/relocatable.h +++ b/contrib/tools/bison/lib/relocatable.h @@ -1,5 +1,5 @@ /* Provide relocatable packages. - Copyright (C) 2003, 2005, 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2003, 2005, 2008-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/setlocale_null.c b/contrib/tools/bison/lib/setlocale_null.c new file mode 100644 index 000000000000..64b1cef79490 --- /dev/null +++ b/contrib/tools/bison/lib/setlocale_null.c @@ -0,0 +1,413 @@ +/* Query the name of the current global locale. + Copyright (C) 2019-2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2019. */ + +#include + +/* Specification. */ +#include "setlocale_null.h" + +#include +#include +#include +#include +#if defined _WIN32 && !defined __CYGWIN__ +# include +#endif + +#if !(SETLOCALE_NULL_ALL_MTSAFE && SETLOCALE_NULL_ONE_MTSAFE) +# if defined _WIN32 && !defined __CYGWIN__ + +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include + +# elif HAVE_PTHREAD_API + +# include +# if HAVE_THREADS_H && HAVE_WEAK_SYMBOLS +# include +# pragma weak thrd_exit +# define c11_threads_in_use() (thrd_exit != NULL) +# else +# define c11_threads_in_use() 0 +# endif + +# elif HAVE_THREADS_H + +# include + +# endif +#endif + +/* Use the system's setlocale() function, not the gnulib override, here. */ +#undef setlocale + +static const char * +setlocale_null_androidfix (int category) +{ + const char *result = setlocale (category, NULL); + +#ifdef __ANDROID__ + if (result == NULL) + switch (category) + { + case LC_CTYPE: + case LC_NUMERIC: + case LC_TIME: + case LC_COLLATE: + case LC_MONETARY: + case LC_MESSAGES: + case LC_ALL: + case LC_PAPER: + case LC_NAME: + case LC_ADDRESS: + case LC_TELEPHONE: + case LC_MEASUREMENT: + result = "C"; + break; + default: + break; + } +#endif + + return result; +} + +static int +setlocale_null_unlocked (int category, char *buf, size_t bufsize) +{ +#if defined _WIN32 && !defined __CYGWIN__ && defined _MSC_VER + /* On native Windows, nowadays, the setlocale() implementation is based + on _wsetlocale() and uses malloc() for the result. We are better off + using _wsetlocale() directly. */ + const wchar_t *result = _wsetlocale (category, NULL); + + if (result == NULL) + { + /* CATEGORY is invalid. */ + if (bufsize > 0) + /* Return an empty string in BUF. + This is a convenience for callers that don't want to write explicit + code for handling EINVAL. */ + buf[0] = '\0'; + return EINVAL; + } + else + { + size_t length = wcslen (result); + if (length < bufsize) + { + size_t i; + + /* Convert wchar_t[] -> char[], assuming plain ASCII. */ + for (i = 0; i <= length; i++) + buf[i] = result[i]; + + return 0; + } + else + { + if (bufsize > 0) + { + /* Return a truncated result in BUF. + This is a convenience for callers that don't want to write + explicit code for handling ERANGE. */ + size_t i; + + /* Convert wchar_t[] -> char[], assuming plain ASCII. */ + for (i = 0; i < bufsize; i++) + buf[i] = result[i]; + buf[bufsize - 1] = '\0'; + } + return ERANGE; + } + } +#else + const char *result = setlocale_null_androidfix (category); + + if (result == NULL) + { + /* CATEGORY is invalid. */ + if (bufsize > 0) + /* Return an empty string in BUF. + This is a convenience for callers that don't want to write explicit + code for handling EINVAL. */ + buf[0] = '\0'; + return EINVAL; + } + else + { + size_t length = strlen (result); + if (length < bufsize) + { + memcpy (buf, result, length + 1); + return 0; + } + else + { + if (bufsize > 0) + { + /* Return a truncated result in BUF. + This is a convenience for callers that don't want to write + explicit code for handling ERANGE. */ + memcpy (buf, result, bufsize - 1); + buf[bufsize - 1] = '\0'; + } + return ERANGE; + } + } +#endif +} + +#if !(SETLOCALE_NULL_ALL_MTSAFE && SETLOCALE_NULL_ONE_MTSAFE) /* musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku, Cygwin */ + +/* Use a lock, so that no two threads can invoke setlocale_null_unlocked + at the same time. */ + +/* Prohibit renaming this symbol. */ +# undef gl_get_setlocale_null_lock + +# if defined _WIN32 && !defined __CYGWIN__ + +extern __declspec(dllimport) CRITICAL_SECTION *gl_get_setlocale_null_lock (void); + +static int +setlocale_null_with_lock (int category, char *buf, size_t bufsize) +{ + CRITICAL_SECTION *lock = gl_get_setlocale_null_lock (); + int ret; + + EnterCriticalSection (lock); + ret = setlocale_null_unlocked (category, buf, bufsize); + LeaveCriticalSection (lock); + + return ret; +} + +# elif HAVE_PTHREAD_API /* musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku, Cygwin */ + +extern +# if defined _WIN32 || defined __CYGWIN__ + __declspec(dllimport) +# endif + pthread_mutex_t *gl_get_setlocale_null_lock (void); + +# if HAVE_WEAK_SYMBOLS /* musl libc, FreeBSD, NetBSD, OpenBSD, Haiku */ + + /* Avoid the need to link with '-lpthread'. */ +# pragma weak pthread_mutex_lock +# pragma weak pthread_mutex_unlock + + /* Determine whether libpthread is in use. */ +# pragma weak pthread_mutexattr_gettype + /* See the comments in lock.h. */ +# define pthread_in_use() \ + (pthread_mutexattr_gettype != NULL || c11_threads_in_use ()) + +# else +# define pthread_in_use() 1 +# endif + +static int +setlocale_null_with_lock (int category, char *buf, size_t bufsize) +{ + if (pthread_in_use()) + { + pthread_mutex_t *lock = gl_get_setlocale_null_lock (); + int ret; + + if (pthread_mutex_lock (lock)) + abort (); + ret = setlocale_null_unlocked (category, buf, bufsize); + if (pthread_mutex_unlock (lock)) + abort (); + + return ret; + } + else + return setlocale_null_unlocked (category, buf, bufsize); +} + +# elif HAVE_THREADS_H + +extern mtx_t *gl_get_setlocale_null_lock (void); + +static int +setlocale_null_with_lock (int category, char *buf, size_t bufsize) +{ + mtx_t *lock = gl_get_setlocale_null_lock (); + int ret; + + if (mtx_lock (lock) != thrd_success) + abort (); + ret = setlocale_null_unlocked (category, buf, bufsize); + if (mtx_unlock (lock) != thrd_success) + abort (); + + return ret; +} + +# endif + +#endif + +int +setlocale_null_r (int category, char *buf, size_t bufsize) +{ +#if SETLOCALE_NULL_ALL_MTSAFE +# if SETLOCALE_NULL_ONE_MTSAFE + + return setlocale_null_unlocked (category, buf, bufsize); + +# else + + if (category == LC_ALL) + return setlocale_null_unlocked (category, buf, bufsize); + else + return setlocale_null_with_lock (category, buf, bufsize); + +# endif +#else +# if SETLOCALE_NULL_ONE_MTSAFE + + if (category == LC_ALL) + return setlocale_null_with_lock (category, buf, bufsize); + else + return setlocale_null_unlocked (category, buf, bufsize); + +# else + + return setlocale_null_with_lock (category, buf, bufsize); + +# endif +#endif +} + +const char * +setlocale_null (int category) +{ +#if SETLOCALE_NULL_ALL_MTSAFE && SETLOCALE_NULL_ONE_MTSAFE + return setlocale_null_androidfix (category); +#else + + /* This call must be multithread-safe. To achieve this without using + thread-local storage: + 1. We use a specific static buffer for each possible CATEGORY + argument. So that different threads can call setlocale_mtsafe + with different CATEGORY arguments, without interfering. + 2. We use a simple strcpy or memcpy to fill this static buffer. + Filling it through, for example, strcpy + strcat would not be + guaranteed to leave the buffer's contents intact if another thread + is currently accessing it. If necessary, the contents is first + assembled in a stack-allocated buffer. */ + if (category == LC_ALL) + { +# if SETLOCALE_NULL_ALL_MTSAFE + return setlocale_null_androidfix (LC_ALL); +# else + char buf[SETLOCALE_NULL_ALL_MAX]; + static char resultbuf[SETLOCALE_NULL_ALL_MAX]; + + if (setlocale_null_r (LC_ALL, buf, sizeof (buf))) + return "C"; + strcpy (resultbuf, buf); + return resultbuf; +# endif + } + else + { +# if SETLOCALE_NULL_ONE_MTSAFE + return setlocale_null_androidfix (category); +# else + enum + { + LC_CTYPE_INDEX, + LC_NUMERIC_INDEX, + LC_TIME_INDEX, + LC_COLLATE_INDEX, + LC_MONETARY_INDEX, + LC_MESSAGES_INDEX, +# ifdef LC_PAPER + LC_PAPER_INDEX, +# endif +# ifdef LC_NAME + LC_NAME_INDEX, +# endif +# ifdef LC_ADDRESS + LC_ADDRESS_INDEX, +# endif +# ifdef LC_TELEPHONE + LC_TELEPHONE_INDEX, +# endif +# ifdef LC_MEASUREMENT + LC_MEASUREMENT_INDEX, +# endif +# ifdef LC_IDENTIFICATION + LC_IDENTIFICATION_INDEX, +# endif + LC_INDICES_COUNT + } + i; + char buf[SETLOCALE_NULL_MAX]; + static char resultbuf[LC_INDICES_COUNT][SETLOCALE_NULL_MAX]; + int err; + + err = setlocale_null_r (category, buf, sizeof (buf)); + if (err == EINVAL) + return NULL; + if (err) + return "C"; + + switch (category) + { + case LC_CTYPE: i = LC_CTYPE_INDEX; break; + case LC_NUMERIC: i = LC_NUMERIC_INDEX; break; + case LC_TIME: i = LC_TIME_INDEX; break; + case LC_COLLATE: i = LC_COLLATE_INDEX; break; + case LC_MONETARY: i = LC_MONETARY_INDEX; break; +# ifdef LC_MESSAGES + case LC_MESSAGES: i = LC_MESSAGES_INDEX; break; +# endif +# ifdef LC_PAPER + case LC_PAPER: i = LC_PAPER_INDEX; break; +# endif +# ifdef LC_NAME + case LC_NAME: i = LC_NAME_INDEX; break; +# endif +# ifdef LC_ADDRESS + case LC_ADDRESS: i = LC_ADDRESS_INDEX; break; +# endif +# ifdef LC_TELEPHONE + case LC_TELEPHONE: i = LC_TELEPHONE_INDEX; break; +# endif +# ifdef LC_MEASUREMENT + case LC_MEASUREMENT: i = LC_MEASUREMENT_INDEX; break; +# endif +# ifdef LC_IDENTIFICATION + case LC_IDENTIFICATION: i = LC_IDENTIFICATION_INDEX; break; +# endif + default: + /* If you get here, a #ifdef LC_xxx is missing. */ + abort (); + } + + strcpy (resultbuf[i], buf); + return resultbuf[i]; +# endif + } +#endif +} diff --git a/contrib/tools/bison/lib/setlocale_null.h b/contrib/tools/bison/lib/setlocale_null.h new file mode 100644 index 000000000000..6844be5fac65 --- /dev/null +++ b/contrib/tools/bison/lib/setlocale_null.h @@ -0,0 +1,82 @@ +/* Query the name of the current global locale. + Copyright (C) 2019-2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2019. */ + +#ifndef _SETLOCALE_NULL_H +#define _SETLOCALE_NULL_H + +#include + +#include "arg-nonnull.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Recommended size of a buffer for a locale name for a single category. + On glibc systems, you can have locale names that are relative file names; + assume a maximum length 256. + In native Windows, in 2018 the longest locale name was of length 58 + ("FYRO Macedonian_Former Yugoslav Republic of Macedonia.1251"). */ +#define SETLOCALE_NULL_MAX (256+1) + +/* Recommended size of a buffer for a locale name with all categories. + On glibc systems, you can have locale names that are relative file names; + assume maximum length 256 for each. There are 12 categories; so, the + maximum total length is 148+12*256. + In native Windows, there are 5 categories, and the maximum total length is + 55+5*58. */ +#define SETLOCALE_NULL_ALL_MAX (148+12*256+1) + +/* setlocale_null_r (CATEGORY, BUF, BUFSIZE) is like setlocale (CATEGORY, NULL), + except that + - it is guaranteed to be multithread-safe, + - it returns the resulting locale category name or locale name in the + user-supplied buffer BUF, which must be BUFSIZE bytes long. + The recommended minimum buffer size is + - SETLOCALE_NULL_MAX for CATEGORY != LC_ALL, and + - SETLOCALE_NULL_ALL_MAX for CATEGORY == LC_ALL. + The return value is an error code: 0 if the call is successful, EINVAL if + CATEGORY is invalid, or ERANGE if BUFSIZE is smaller than the length needed + size (including the trailing NUL byte). In the latter case, a truncated + result is returned in BUF, but still NUL-terminated if BUFSIZE > 0. + For this call to be multithread-safe, *all* calls to + setlocale (CATEGORY, NULL) in all other threads must have been converted + to use setlocale_null_r or setlocale_null as well, and the other threads + must not make other setlocale invocations (since changing the global locale + has side effects on all threads). */ +extern int setlocale_null_r (int category, char *buf, size_t bufsize) + _GL_ARG_NONNULL ((2)); + +/* setlocale_null (CATEGORY) is like setlocale (CATEGORY, NULL), except that + it is guaranteed to be multithread-safe. + The return value is NULL if CATEGORY is invalid. + For this call to be multithread-safe, *all* calls to + setlocale (CATEGORY, NULL) in all other threads must have been converted + to use setlocale_null_r or setlocale_null as well, and the other threads + must not make other setlocale invocations (since changing the global locale + has side effects on all threads). */ +extern const char *setlocale_null (int category); + + +#ifdef __cplusplus +} +#endif + +#endif /* _SETLOCALE_NULL_H */ diff --git a/contrib/tools/bison/lib/sig-handler.h b/contrib/tools/bison/lib/sig-handler.h index b289473dbde3..17604eada383 100644 --- a/contrib/tools/bison/lib/sig-handler.h +++ b/contrib/tools/bison/lib/sig-handler.h @@ -1,6 +1,6 @@ /* Convenience declarations when working with . - Copyright (C) 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2008-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/sigaction.c b/contrib/tools/bison/lib/sigaction.c index abedfdcdc478..792b3e8dac70 100644 --- a/contrib/tools/bison/lib/sigaction.c +++ b/contrib/tools/bison/lib/sigaction.c @@ -1,5 +1,5 @@ /* POSIX compatible signal blocking. - Copyright (C) 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2008-2020 Free Software Foundation, Inc. Written by Eric Blake , 2008. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/sigprocmask.c b/contrib/tools/bison/lib/sigprocmask.c index d6cd3f82e503..d18610691ea7 100644 --- a/contrib/tools/bison/lib/sigprocmask.c +++ b/contrib/tools/bison/lib/sigprocmask.c @@ -1,5 +1,5 @@ /* POSIX compatible signal blocking. - Copyright (C) 2006-2019 Free Software Foundation, Inc. + Copyright (C) 2006-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2006. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/spawn-pipe.c b/contrib/tools/bison/lib/spawn-pipe.c index 5fe50fc6403f..3e5afbef947d 100644 --- a/contrib/tools/bison/lib/spawn-pipe.c +++ b/contrib/tools/bison/lib/spawn-pipe.c @@ -1,5 +1,5 @@ /* Creation of subprocesses, communicating via pipes. - Copyright (C) 2001-2004, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/spawn-pipe.h b/contrib/tools/bison/lib/spawn-pipe.h index 0d709686665a..6a95650ee0fa 100644 --- a/contrib/tools/bison/lib/spawn-pipe.h +++ b/contrib/tools/bison/lib/spawn-pipe.h @@ -1,5 +1,5 @@ /* Creation of subprocesses, communicating via pipes. - Copyright (C) 2001-2003, 2006, 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006, 2008-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/stdio-impl.h b/contrib/tools/bison/lib/stdio-impl.h index 4260468b612e..067b95ebd64a 100644 --- a/contrib/tools/bison/lib/stdio-impl.h +++ b/contrib/tools/bison/lib/stdio-impl.h @@ -1,5 +1,5 @@ /* Implementation details of FILE streams. - Copyright (C) 2007-2008, 2010-2019 Free Software Foundation, Inc. + Copyright (C) 2007-2008, 2010-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,11 +18,16 @@ the same implementation of stdio extension API, except that some fields have different naming conventions, or their access requires some casts. */ -/* Glibc 2.28 made _IO_IN_BACKUP private. For now, work around this - problem by defining it ourselves. FIXME: Do not rely on glibc +/* Glibc 2.28 made _IO_UNBUFFERED and _IO_IN_BACKUP private. For now, work + around this problem by defining them ourselves. FIXME: Do not rely on glibc internals. */ -#if !defined _IO_IN_BACKUP && defined _IO_EOF_SEEN -# define _IO_IN_BACKUP 0x100 +#if defined _IO_EOF_SEEN +# if !defined _IO_UNBUFFERED +# define _IO_UNBUFFERED 0x2 +# endif +# if !defined _IO_IN_BACKUP +# define _IO_IN_BACKUP 0x100 +# endif #endif /* BSD stdio derived implementations. */ diff --git a/contrib/tools/bison/lib/stdio-safer.h b/contrib/tools/bison/lib/stdio-safer.h index 790846c2e7e4..ce74a93ea3d3 100644 --- a/contrib/tools/bison/lib/stdio-safer.h +++ b/contrib/tools/bison/lib/stdio-safer.h @@ -1,6 +1,6 @@ /* Invoke stdio functions, but avoid some glitches. - Copyright (C) 2001, 2003, 2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2003, 2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/stpcpy.c b/contrib/tools/bison/lib/stpcpy.c index a1d32fdaf81c..58265f0b797b 100644 --- a/contrib/tools/bison/lib/stpcpy.c +++ b/contrib/tools/bison/lib/stpcpy.c @@ -1,5 +1,5 @@ /* stpcpy.c -- copy a string and return pointer to end of new string - Copyright (C) 1992, 1995, 1997-1998, 2006, 2009-2019 Free Software + Copyright (C) 1992, 1995, 1997-1998, 2006, 2009-2020 Free Software Foundation, Inc. NOTE: The canonical source of this file is maintained with the GNU C Library. diff --git a/contrib/tools/bison/lib/streq.h b/contrib/tools/bison/lib/streq.h index 326537b6d020..d06c27200cd4 100644 --- a/contrib/tools/bison/lib/streq.h +++ b/contrib/tools/bison/lib/streq.h @@ -1,5 +1,5 @@ /* Optimized string comparison. - Copyright (C) 2001-2002, 2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published diff --git a/contrib/tools/bison/lib/stripslash.c b/contrib/tools/bison/lib/stripslash.c index dfc15b43cc97..6818b3061416 100644 --- a/contrib/tools/bison/lib/stripslash.c +++ b/contrib/tools/bison/lib/stripslash.c @@ -1,6 +1,6 @@ /* stripslash.c -- remove redundant trailing slashes from a file name - Copyright (C) 1990, 2001, 2003-2006, 2009-2019 Free Software Foundation, + Copyright (C) 1990, 2001, 2003-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/strndup.c b/contrib/tools/bison/lib/strndup.c index 5b74828469a8..d5294b88525b 100644 --- a/contrib/tools/bison/lib/strndup.c +++ b/contrib/tools/bison/lib/strndup.c @@ -1,6 +1,6 @@ /* A replacement function, for systems that lack strndup. - Copyright (C) 1996-1998, 2001-2003, 2005-2007, 2009-2019 Free Software + Copyright (C) 1996-1998, 2001-2003, 2005-2007, 2009-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it diff --git a/contrib/tools/bison/lib/strverscmp.c b/contrib/tools/bison/lib/strverscmp.c index bf5ce5086f11..2e9284486da6 100644 --- a/contrib/tools/bison/lib/strverscmp.c +++ b/contrib/tools/bison/lib/strverscmp.c @@ -1,5 +1,5 @@ /* Compare strings while treating digits characters numerically. - Copyright (C) 1997-2019 Free Software Foundation, Inc. + Copyright (C) 1997-2020 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jean-François Bignolles , 1997. @@ -17,10 +17,8 @@ License along with the GNU C Library; if not, see . */ -#if !_LIBC -# include -#endif +#include #include #include @@ -35,27 +33,25 @@ #define CMP 2 #define LEN 3 -#ifndef weak_alias -# define __strverscmp strverscmp -#endif /* Compare S1 and S2 as strings holding indices/version numbers, returning less than, equal to or greater than zero if S1 is less than, equal to or greater than S2 (for more info, see the texinfo doc). */ +#ifndef weak_alias +#define __strverscmp strverscmp +#endif + int __strverscmp (const char *s1, const char *s2) { const unsigned char *p1 = (const unsigned char *) s1; const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; - int state; - int diff; /* Symbol(s) 0 [1-9] others Transition (10) 0 (01) d (00) x */ - static const unsigned char next_state[] = + static const uint_least8_t next_state[] = { /* state x d 0 */ /* S_N */ S_N, S_I, S_Z, @@ -64,7 +60,7 @@ __strverscmp (const char *s1, const char *s2) /* S_Z */ S_N, S_F, S_Z }; - static const signed char result_type[] = + static const int_least8_t result_type[] = { /* state x/x x/d x/0 d/x d/d d/0 0/x 0/d 0/0 */ @@ -77,15 +73,16 @@ __strverscmp (const char *s1, const char *s2) if (p1 == p2) return 0; - c1 = *p1++; - c2 = *p2++; + unsigned char c1 = *p1++; + unsigned char c2 = *p2++; /* Hint: '0' is a digit too. */ - state = S_N + ((c1 == '0') + (isdigit (c1) != 0)); + int state = S_N + ((c1 == '0') + (isdigit (c1) != 0)); + int diff; while ((diff = c1 - c2) == 0) { if (c1 == '\0') - return diff; + return diff; state = next_state[state]; c1 = *p1++; @@ -96,20 +93,20 @@ __strverscmp (const char *s1, const char *s2) state = result_type[state * 3 + (((c2 == '0') + (isdigit (c2) != 0)))]; switch (state) - { + { case CMP: return diff; case LEN: while (isdigit (*p1++)) - if (!isdigit (*p2++)) - return 1; + if (!isdigit (*p2++)) + return 1; return isdigit (*p2) ? -1 : diff; default: return state; - } + } } #ifdef weak_alias libc_hidden_def (__strverscmp) diff --git a/contrib/tools/bison/lib/textstyle.h b/contrib/tools/bison/lib/textstyle.h new file mode 100644 index 000000000000..8cf63c7979bb --- /dev/null +++ b/contrib/tools/bison/lib/textstyle.h @@ -0,0 +1,466 @@ +/* DO NOT EDIT! GENERATED AUTOMATICALLY! */ +/* Dummy replacement for part of the public API of the libtextstyle library. + Copyright (C) 2006-2007, 2019-2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2019. */ + +/* This file is used as replacement when libtextstyle with its include file + is not found. + It supports the essential API and implements it in a way that does not + provide text styling. That is, it produces plain text output via + FILE objects. + Thus, it allows a package to be build with or without a dependency to + libtextstyle, with very few occurrences of '#if HAVE_LIBTEXTSTYLE'. + + Restriction: + It assumes that freopen() is not being called on stdout and stderr. */ + +#ifndef _TEXTSTYLE_H +#define _TEXTSTYLE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#if HAVE_TCDRAIN +# include +#endif + +/* ----------------------------- From ostream.h ----------------------------- */ + +/* Describes the scope of a flush operation. */ +typedef enum +{ + /* Flushes buffers in this ostream_t. + Use this value if you want to write to the underlying ostream_t. */ + FLUSH_THIS_STREAM = 0, + /* Flushes all buffers in the current process. + Use this value if you want to write to the same target through a + different file descriptor or a FILE stream. */ + FLUSH_THIS_PROCESS = 1, + /* Flushes buffers in the current process and attempts to flush the buffers + in the kernel. + Use this value so that some other process (or the kernel itself) + may write to the same target. */ + FLUSH_ALL = 2 +} ostream_flush_scope_t; + + +/* An output stream is an object to which one can feed a sequence of bytes. */ + +typedef FILE * ostream_t; + +static inline void +ostream_write_mem (ostream_t stream, const void *data, size_t len) +{ + if (len > 0) + fwrite (data, 1, len, stream); +} + +static inline void +ostream_flush (ostream_t stream, ostream_flush_scope_t scope) +{ + fflush (stream); + if (scope == FLUSH_ALL) + { + int fd = fileno (stream); + if (fd >= 0) + { + /* For streams connected to a disk file: */ + fsync (fd); + #if HAVE_TCDRAIN + /* For streams connected to a terminal: */ + { + int retval; + + do + retval = tcdrain (fd); + while (retval < 0 && errno == EINTR); + } + #endif + } + } +} + +static inline void +ostream_free (ostream_t stream) +{ + if (stream == stdin || stream == stderr) + fflush (stream); + else + fclose (stream); +} + +static inline void +ostream_write_str (ostream_t stream, const char *string) +{ + ostream_write_mem (stream, string, strlen (string)); +} + +static inline ptrdiff_t ostream_printf (ostream_t stream, + const char *format, ...) +#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3 + __attribute__ ((__format__ (__printf__, 2, 3))) +#endif + ; +static inline ptrdiff_t +ostream_printf (ostream_t stream, const char *format, ...) +{ + va_list args; + char *temp_string; + ptrdiff_t ret; + + va_start (args, format); + ret = vasprintf (&temp_string, format, args); + va_end (args); + if (ret >= 0) + { + if (ret > 0) + ostream_write_str (stream, temp_string); + free (temp_string); + } + return ret; +} + +static inline ptrdiff_t ostream_vprintf (ostream_t stream, + const char *format, va_list args) +#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ > 3 + __attribute__ ((__format__ (__printf__, 2, 0))) +#endif + ; +static inline ptrdiff_t +ostream_vprintf (ostream_t stream, const char *format, va_list args) +{ + char *temp_string; + ptrdiff_t ret = vasprintf (&temp_string, format, args); + if (ret >= 0) + { + if (ret > 0) + ostream_write_str (stream, temp_string); + free (temp_string); + } + return ret; +} + +/* ------------------------- From styled-ostream.h ------------------------- */ + +typedef ostream_t styled_ostream_t; + +#define styled_ostream_write_mem ostream_write_mem +#define styled_ostream_flush ostream_flush +#define styled_ostream_free ostream_free + +static inline void +styled_ostream_begin_use_class (styled_ostream_t stream _GL_UNUSED, + const char *classname _GL_UNUSED) +{ +} + +static inline void +styled_ostream_end_use_class (styled_ostream_t stream _GL_UNUSED, + const char *classname _GL_UNUSED) +{ +} + +static inline const char * +styled_ostream_get_hyperlink_ref (styled_ostream_t stream _GL_UNUSED) +{ + return NULL; +} + +static inline const char * +styled_ostream_get_hyperlink_id (styled_ostream_t stream _GL_UNUSED) +{ + return NULL; +} + +static inline void +styled_ostream_set_hyperlink (styled_ostream_t stream _GL_UNUSED, + const char *ref _GL_UNUSED, + const char *id _GL_UNUSED) +{ +} + +static inline void +styled_ostream_flush_to_current_style (styled_ostream_t stream _GL_UNUSED) +{ +} + +/* -------------------------- From file-ostream.h -------------------------- */ + +typedef ostream_t file_ostream_t; + +#define file_ostream_write_mem ostream_write_mem +#define file_ostream_flush ostream_flush +#define file_ostream_free ostream_free + +static inline file_ostream_t +file_ostream_create (FILE *fp) +{ + return fp; +} + +/* --------------------------- From fd-ostream.h --------------------------- */ + +typedef ostream_t fd_ostream_t; + +#define fd_ostream_write_mem ostream_write_mem +#define fd_ostream_flush ostream_flush +#define fd_ostream_free ostream_free + +static inline fd_ostream_t +fd_ostream_create (int fd, const char *filename _GL_UNUSED, + bool buffered _GL_UNUSED) +{ + if (fd == 1) + return stdout; + else if (fd == 2) + return stderr; + else + return fdopen (fd, "w"); +} + +/* -------------------------- From term-ostream.h -------------------------- */ + +typedef int term_color_t; +enum +{ + COLOR_DEFAULT = -1 /* unknown */ +}; + +typedef enum +{ + WEIGHT_NORMAL = 0, + WEIGHT_BOLD, + WEIGHT_DEFAULT = WEIGHT_NORMAL +} term_weight_t; + +typedef enum +{ + POSTURE_NORMAL = 0, + POSTURE_ITALIC, /* same as oblique */ + POSTURE_DEFAULT = POSTURE_NORMAL +} term_posture_t; + +typedef enum +{ + UNDERLINE_OFF = 0, + UNDERLINE_ON, + UNDERLINE_DEFAULT = UNDERLINE_OFF +} term_underline_t; + +typedef ostream_t term_ostream_t; + +#define term_ostream_write_mem ostream_write_mem +#define term_ostream_flush ostream_flush +#define term_ostream_free ostream_free + +static inline term_color_t +term_ostream_get_color (term_ostream_t stream _GL_UNUSED) +{ + return COLOR_DEFAULT; +} + +static inline void +term_ostream_set_color (term_ostream_t stream _GL_UNUSED, + term_color_t color _GL_UNUSED) +{ +} + +static inline term_color_t +term_ostream_get_bgcolor (term_ostream_t stream _GL_UNUSED) +{ + return COLOR_DEFAULT; +} + +static inline void +term_ostream_set_bgcolor (term_ostream_t stream _GL_UNUSED, + term_color_t color _GL_UNUSED) +{ +} + +static inline term_weight_t +term_ostream_get_weight (term_ostream_t stream _GL_UNUSED) +{ + return WEIGHT_DEFAULT; +} + +static inline void +term_ostream_set_weight (term_ostream_t stream _GL_UNUSED, + term_weight_t weight _GL_UNUSED) +{ +} + +static inline term_posture_t +term_ostream_get_posture (term_ostream_t stream _GL_UNUSED) +{ + return POSTURE_DEFAULT; +} + +static inline void +term_ostream_set_posture (term_ostream_t stream _GL_UNUSED, + term_posture_t posture _GL_UNUSED) +{ +} + +static inline term_underline_t +term_ostream_get_underline (term_ostream_t stream _GL_UNUSED) +{ + return UNDERLINE_DEFAULT; +} + +static inline void +term_ostream_set_underline (term_ostream_t stream _GL_UNUSED, + term_underline_t underline _GL_UNUSED) +{ +} + +static inline const char * +term_ostream_get_hyperlink_ref (term_ostream_t stream _GL_UNUSED) +{ + return NULL; +} + +static inline const char * +term_ostream_get_hyperlink_id (term_ostream_t stream _GL_UNUSED) +{ + return NULL; +} + +static inline void +term_ostream_set_hyperlink (term_ostream_t stream _GL_UNUSED, + const char *ref _GL_UNUSED, + const char *id _GL_UNUSED) +{ +} + +static inline void +term_ostream_flush_to_current_style (term_ostream_t stream) +{ + fflush (stream); +} + +typedef enum +{ + TTYCTL_AUTO = 0, /* Automatic best-possible choice. */ + TTYCTL_NONE, /* No control. + Result: Garbled output can occur, and the terminal can + be left in any state when the program is interrupted. */ + TTYCTL_PARTIAL, /* Signal handling. + Result: Garbled output can occur, but the terminal will + be left in the default state when the program is + interrupted. */ + TTYCTL_FULL /* Signal handling and disabling echo and flush-upon-signal. + Result: No garbled output, and the the terminal will + be left in the default state when the program is + interrupted. */ +} ttyctl_t; + +static inline term_ostream_t +term_ostream_create (int fd, const char *filename, + ttyctl_t tty_control _GL_UNUSED) +{ + return fd_ostream_create (fd, filename, true); +} + +/* ----------------------- From term-styled-ostream.h ----------------------- */ + +typedef styled_ostream_t term_styled_ostream_t; + +#define term_styled_ostream_write_mem ostream_write_mem +#define term_styled_ostream_flush ostream_flush +#define term_styled_ostream_free ostream_free +#define term_styled_ostream_begin_use_class styled_ostream_begin_use_class +#define term_styled_ostream_end_use_class styled_ostream_end_use_class +#define term_styled_ostream_get_hyperlink_ref styled_ostream_get_hyperlink_ref +#define term_styled_ostream_get_hyperlink_id styled_ostream_get_hyperlink_id +#define term_styled_ostream_set_hyperlink styled_ostream_set_hyperlink +#define term_styled_ostream_flush_to_current_style styled_ostream_flush_to_current_style + +static inline term_styled_ostream_t +term_styled_ostream_create (int fd, const char *filename, + ttyctl_t tty_control _GL_UNUSED, + const char *css_filename _GL_UNUSED) +{ + return fd_ostream_create (fd, filename, true); +} + +/* ----------------------- From html-styled-ostream.h ----------------------- */ + +typedef styled_ostream_t html_styled_ostream_t; + +static inline html_styled_ostream_t +html_styled_ostream_create (ostream_t destination _GL_UNUSED, + const char *css_filename _GL_UNUSED) +{ + abort (); + return NULL; +} + +/* ------------------------------ From color.h ------------------------------ */ + +#define color_test_mode false + +enum color_option { color_no, color_tty, color_yes, color_html }; +#define color_mode color_no + +#define style_file_name NULL + +static inline bool +handle_color_option (const char *option _GL_UNUSED) +{ + return false; +} + +static inline void +handle_style_option (const char *option _GL_UNUSED) +{ +} + +static inline void +print_color_test (void) +{ + abort (); +} + +static inline void +style_file_prepare (const char *style_file_envvar _GL_UNUSED, + const char *stylesdir_envvar _GL_UNUSED, + const char *stylesdir_after_install _GL_UNUSED, + const char *default_style_file _GL_UNUSED) +{ +} + +/* ------------------------------ From misc.h ------------------------------ */ + +static inline styled_ostream_t +styled_ostream_create (int fd, const char *filename, + ttyctl_t tty_control _GL_UNUSED, + const char *css_filename _GL_UNUSED) +{ + return fd_ostream_create (fd, filename, true); +} + +static inline void +libtextstyle_set_failure_exit_code (int exit_code _GL_UNUSED) +{ +} + +#endif /* _TEXTSTYLE_H */ diff --git a/contrib/tools/bison/lib/timespec.h b/contrib/tools/bison/lib/timespec.h index 26f1bc1a4c78..02684ce6eace 100644 --- a/contrib/tools/bison/lib/timespec.h +++ b/contrib/tools/bison/lib/timespec.h @@ -1,6 +1,6 @@ /* timespec -- System time interface - Copyright (C) 2000, 2002, 2004-2005, 2007, 2009-2019 Free Software + Copyright (C) 2000, 2002, 2004-2005, 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/timevar.c b/contrib/tools/bison/lib/timevar.c index 0f6fb402e46f..6657e97c251d 100644 --- a/contrib/tools/bison/lib/timevar.c +++ b/contrib/tools/bison/lib/timevar.c @@ -1,6 +1,6 @@ /* Timing variables for measuring compiler performance. - Copyright (C) 2000, 2002, 2004, 2006, 2009-2015, 2018-2019 Free Software + Copyright (C) 2000, 2002, 2004, 2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Alex Samuel @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #include diff --git a/contrib/tools/bison/lib/timevar.def b/contrib/tools/bison/lib/timevar.def index 9de9b815a797..6e0d6ff0545b 100644 --- a/contrib/tools/bison/lib/timevar.def +++ b/contrib/tools/bison/lib/timevar.def @@ -1,7 +1,7 @@ /* This file contains the definitions for timing variables used to -*- C -*- measure run-time performance of the compiler. - Copyright (C) 2002, 2007, 2009-2015, 2018-2019 Free Software + Copyright (C) 2002, 2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Akim Demaille . diff --git a/contrib/tools/bison/lib/timevar.h b/contrib/tools/bison/lib/timevar.h index 5d5a279cc5d9..036be80893b8 100644 --- a/contrib/tools/bison/lib/timevar.h +++ b/contrib/tools/bison/lib/timevar.h @@ -1,6 +1,6 @@ /* Timing variables for measuring application performance. - Copyright (C) 2000, 2002, 2004, 2009-2015, 2018-2019 Free Software + Copyright (C) 2000, 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. Contributed by Alex Samuel @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #ifndef _TIMEVAR_H # define _TIMEVAR_H 1 diff --git a/contrib/tools/bison/lib/unistd-safer.h b/contrib/tools/bison/lib/unistd-safer.h index 8eebffcae224..3e8350967832 100644 --- a/contrib/tools/bison/lib/unistd-safer.h +++ b/contrib/tools/bison/lib/unistd-safer.h @@ -1,6 +1,6 @@ /* Invoke unistd-like functions, but avoid some glitches. - Copyright (C) 2001, 2003, 2005, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2003, 2005, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/unitypes.h b/contrib/tools/bison/lib/unitypes.h index 8ce466142b2a..b277a0858abc 100644 --- a/contrib/tools/bison/lib/unitypes.h +++ b/contrib/tools/bison/lib/unitypes.h @@ -1,6 +1,6 @@ /* DO NOT EDIT! GENERATED AUTOMATICALLY! */ /* Elementary types and macros for the GNU UniString library. - Copyright (C) 2002, 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2002, 2005-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -44,4 +44,17 @@ typedef uint32_t ucs4_t; # endif #endif +/* Qualifier in a function declaration, that asserts that the caller must + pass a pointer to a different object in the specified pointer argument + than in the other pointer arguments. */ +#ifndef _UC_RESTRICT +# if defined __restrict || 2 < __GNUC__ + (95 <= __GNUC_MINOR__) +# define _UC_RESTRICT __restrict +# elif 199901L <= __STDC_VERSION__ || defined restrict +# define _UC_RESTRICT restrict +# else +# define _UC_RESTRICT +# endif +#endif + #endif /* _UNITYPES_H */ diff --git a/contrib/tools/bison/lib/uniwidth.h b/contrib/tools/bison/lib/uniwidth.h index cb79a7048157..b28898b54fed 100644 --- a/contrib/tools/bison/lib/uniwidth.h +++ b/contrib/tools/bison/lib/uniwidth.h @@ -1,6 +1,6 @@ /* DO NOT EDIT! GENERATED AUTOMATICALLY! */ /* Display width functions. - Copyright (C) 2001-2002, 2005, 2007, 2009-2019 Free Software Foundation, + Copyright (C) 2001-2002, 2005, 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it diff --git a/contrib/tools/bison/lib/uniwidth/cjk.h b/contrib/tools/bison/lib/uniwidth/cjk.h index 9870422ca6c7..3dcc7cb856dc 100644 --- a/contrib/tools/bison/lib/uniwidth/cjk.h +++ b/contrib/tools/bison/lib/uniwidth/cjk.h @@ -1,5 +1,5 @@ /* Test for CJK encoding. - Copyright (C) 2001-2002, 2005-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2005-2007, 2009-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/contrib/tools/bison/lib/uniwidth/width.c b/contrib/tools/bison/lib/uniwidth/width.c index a7f59b18eba0..ad92323cce52 100644 --- a/contrib/tools/bison/lib/uniwidth/width.c +++ b/contrib/tools/bison/lib/uniwidth/width.c @@ -1,5 +1,5 @@ /* Determine display width of Unicode character. - Copyright (C) 2001-2002, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/contrib/tools/bison/lib/unlocked-io.h b/contrib/tools/bison/lib/unlocked-io.h index ee1c06268fe4..e7f7199edae8 100644 --- a/contrib/tools/bison/lib/unlocked-io.h +++ b/contrib/tools/bison/lib/unlocked-io.h @@ -1,6 +1,6 @@ /* Prefer faster, non-thread-safe stdio functions if available. - Copyright (C) 2001-2004, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/vasnprintf.c b/contrib/tools/bison/lib/vasnprintf.c index f1f47f0d2170..e3a1e9fa75a7 100644 --- a/contrib/tools/bison/lib/vasnprintf.c +++ b/contrib/tools/bison/lib/vasnprintf.c @@ -1,5 +1,5 @@ /* vsprintf with automatic memory allocation. - Copyright (C) 1999, 2002-2019 Free Software Foundation, Inc. + Copyright (C) 1999, 2002-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -1553,16 +1553,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion, switch (conversion) { case 'd': case 'i': case 'u': -# if HAVE_LONG_LONG_INT if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) tmp_length = (unsigned int) (sizeof (unsigned long long) * CHAR_BIT * 0.30103 /* binary -> decimal */ ) + 1; /* turn floor into ceil */ - else -# endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + else if (type == TYPE_LONGINT || type == TYPE_ULONGINT) tmp_length = (unsigned int) (sizeof (unsigned long) * CHAR_BIT * 0.30103 /* binary -> decimal */ @@ -1583,16 +1580,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion, break; case 'o': -# if HAVE_LONG_LONG_INT if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) tmp_length = (unsigned int) (sizeof (unsigned long long) * CHAR_BIT * 0.333334 /* binary -> octal */ ) + 1; /* turn floor into ceil */ - else -# endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + else if (type == TYPE_LONGINT || type == TYPE_ULONGINT) tmp_length = (unsigned int) (sizeof (unsigned long) * CHAR_BIT * 0.333334 /* binary -> octal */ @@ -1611,16 +1605,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion, break; case 'x': case 'X': -# if HAVE_LONG_LONG_INT if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) tmp_length = (unsigned int) (sizeof (unsigned long long) * CHAR_BIT * 0.25 /* binary -> hexadecimal */ ) + 1; /* turn floor into ceil */ - else -# endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + else if (type == TYPE_LONGINT || type == TYPE_ULONGINT) tmp_length = (unsigned int) (sizeof (unsigned long) * CHAR_BIT * 0.25 /* binary -> hexadecimal */ @@ -1939,11 +1930,9 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, case TYPE_COUNT_LONGINT_POINTER: *a.arg[dp->arg_index].a.a_count_longint_pointer = length; break; -#if HAVE_LONG_LONG_INT case TYPE_COUNT_LONGLONGINT_POINTER: *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; break; -#endif default: abort (); } @@ -4835,17 +4824,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, switch (type) { -#if HAVE_LONG_LONG_INT case TYPE_LONGLONGINT: case TYPE_ULONGLONGINT: -# if defined _WIN32 && ! defined __CYGWIN__ +#if defined _WIN32 && ! defined __CYGWIN__ *fbp++ = 'I'; *fbp++ = '6'; *fbp++ = '4'; break; -# else +#else *fbp++ = 'l'; -# endif #endif FALLTHROUGH; case TYPE_LONGINT: @@ -4917,7 +4904,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, Windows Vista, the use of %n in format strings by default crashes the program. See and - + So we should avoid %n in this situation. */ fbp[1] = '\0'; # endif @@ -5063,7 +5050,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, SNPRINTF_BUF (arg); } break; -#if HAVE_LONG_LONG_INT case TYPE_LONGLONGINT: { long long int arg = a.arg[dp->arg_index].a.a_longlongint; @@ -5076,7 +5062,6 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, SNPRINTF_BUF (arg); } break; -#endif case TYPE_DOUBLE: { double arg = a.arg[dp->arg_index].a.a_double; diff --git a/contrib/tools/bison/lib/vasnprintf.h b/contrib/tools/bison/lib/vasnprintf.h index 5b192b21e9bc..f63399a5e6c3 100644 --- a/contrib/tools/bison/lib/vasnprintf.h +++ b/contrib/tools/bison/lib/vasnprintf.h @@ -1,5 +1,5 @@ /* vsprintf with automatic memory allocation. - Copyright (C) 2002-2004, 2007-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2004, 2007-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -67,9 +67,11 @@ extern "C" { # define asnprintf rpl_asnprintf # define vasnprintf rpl_vasnprintf #endif -extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...) +extern char * asnprintf (char *restrict resultbuf, size_t *lengthp, + const char *format, ...) _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4)); -extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) +extern char * vasnprintf (char *restrict resultbuf, size_t *lengthp, + const char *format, va_list args) _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0)); #ifdef __cplusplus diff --git a/contrib/tools/bison/lib/vasprintf.c b/contrib/tools/bison/lib/vasprintf.c new file mode 100644 index 000000000000..7bb21dde3b00 --- /dev/null +++ b/contrib/tools/bison/lib/vasprintf.c @@ -0,0 +1,50 @@ +/* Formatted output to strings. + Copyright (C) 1999, 2002, 2006-2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . */ + +#include + +/* Specification. */ +#ifdef IN_LIBASPRINTF +# include "vasprintf.h" +#else +# include +#endif + +#include +#include +#include + +#include "vasnprintf.h" + +int +vasprintf (char **resultp, const char *format, va_list args) +{ + size_t length; + char *result = vasnprintf (NULL, &length, format, args); + if (result == NULL) + return -1; + + if (length > INT_MAX) + { + free (result); + errno = EOVERFLOW; + return -1; + } + + *resultp = result; + /* Return the number of resulting bytes, excluding the trailing NUL. */ + return length; +} diff --git a/contrib/tools/bison/lib/verify.h b/contrib/tools/bison/lib/verify.h index 6930645a3501..d9ab89a570c9 100644 --- a/contrib/tools/bison/lib/verify.h +++ b/contrib/tools/bison/lib/verify.h @@ -1,6 +1,6 @@ /* Compile-time assert-like macros. - Copyright (C) 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,29 +21,37 @@ #define _GL_VERIFY_H -/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert works as per C11. - This is supported by GCC 4.6.0 and later, in C mode, and its use - here generates easier-to-read diagnostics when verify (R) fails. +/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert (R, DIAGNOSTIC) + works as per C11. This is supported by GCC 4.6.0 and later, in C + mode. - Define _GL_HAVE_STATIC_ASSERT to 1 if static_assert works as per C++11. - This is supported by GCC 6.1.0 and later, in C++ mode. + Define _GL_HAVE__STATIC_ASSERT1 to 1 if _Static_assert (R) works as + per C2X, and define _GL_HAVE_STATIC_ASSERT1 if static_assert (R) + works as per C++17. This is supported by GCC 9.1 and later. - Use this only with GCC. If we were willing to slow 'configure' - down we could also use it with other compilers, but since this - affects only the quality of diagnostics, why bother? */ -#if (4 < __GNUC__ + (6 <= __GNUC_MINOR__) \ - && (201112L <= __STDC_VERSION__ || !defined __STRICT_ANSI__) \ - && !defined __cplusplus) -# define _GL_HAVE__STATIC_ASSERT 1 -#endif -#if (6 <= __GNUC__) && defined __cplusplus -# define _GL_HAVE_STATIC_ASSERT 1 + Support compilers claiming conformance to the relevant standard, + and also support GCC when not pedantic. If we were willing to slow + 'configure' down we could also use it with other compilers, but + since this affects only the quality of diagnostics, why bother? */ +#ifndef __cplusplus +# if (201112L <= __STDC_VERSION__ \ + || (!defined __STRICT_ANSI__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__))) +# define _GL_HAVE__STATIC_ASSERT 1 +# endif +# if (202000L <= __STDC_VERSION__ \ + || (!defined __STRICT_ANSI__ && 9 <= __GNUC__)) +# define _GL_HAVE__STATIC_ASSERT1 1 +# endif +#else +# if 201703L <= __cplusplus || 9 <= __GNUC__ +# define _GL_HAVE_STATIC_ASSERT1 1 +# endif #endif /* FreeBSD 9.1 , included by and lots of other system headers, defines a conflicting _Static_assert that is no better than ours; override it. */ -#ifndef _GL_HAVE_STATIC_ASSERT +#ifndef _GL_HAVE__STATIC_ASSERT # include # undef _Static_assert #endif @@ -141,9 +149,9 @@ which do not support _Static_assert, also do not warn about the last declaration mentioned above. - * GCC warns if -Wnested-externs is enabled and verify() is used + * GCC warns if -Wnested-externs is enabled and 'verify' is used within a function body; but inside a function, you can always - arrange to use verify_expr() instead. + arrange to use verify_expr instead. * In C++, any struct definition inside sizeof is invalid. Use a template type to work around the problem. */ @@ -195,48 +203,61 @@ template #endif /* Verify requirement R at compile-time, as a declaration without a - trailing ';'. If R is false, fail at compile-time, preferably - with a diagnostic that includes the string-literal DIAGNOSTIC. + trailing ';'. If R is false, fail at compile-time. + + This macro requires three or more arguments but uses at most the first + two, so that the _Static_assert macro optionally defined below supports + both the C11 two-argument syntax and the C2X one-argument syntax. Unfortunately, unlike C11, this implementation must appear as an ordinary declaration, and cannot appear inside struct { ... }. */ -#ifdef _GL_HAVE__STATIC_ASSERT -# define _GL_VERIFY _Static_assert +#if defined _GL_HAVE__STATIC_ASSERT +# define _GL_VERIFY(R, DIAGNOSTIC, ...) _Static_assert (R, DIAGNOSTIC) #else -# define _GL_VERIFY(R, DIAGNOSTIC) \ +# define _GL_VERIFY(R, DIAGNOSTIC, ...) \ extern int (*_GL_GENSYM (_gl_verify_function) (void)) \ [_GL_VERIFY_TRUE (R, DIAGNOSTIC)] #endif /* _GL_STATIC_ASSERT_H is defined if this code is copied into assert.h. */ #ifdef _GL_STATIC_ASSERT_H -# if !defined _GL_HAVE__STATIC_ASSERT && !defined _Static_assert -# define _Static_assert(R, DIAGNOSTIC) _GL_VERIFY (R, DIAGNOSTIC) +# if !defined _GL_HAVE__STATIC_ASSERT1 && !defined _Static_assert +# define _Static_assert(...) \ + _GL_VERIFY (__VA_ARGS__, "static assertion failed", -) # endif -# if !defined _GL_HAVE_STATIC_ASSERT && !defined static_assert +# if !defined _GL_HAVE_STATIC_ASSERT1 && !defined static_assert # define static_assert _Static_assert /* C11 requires this #define. */ # endif #endif /* @assert.h omit start@ */ +#if 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__)) +# define _GL_HAS_BUILTIN_TRAP 1 +#elif defined __has_builtin +# define _GL_HAS_BUILTIN_TRAP __has_builtin (__builtin_trap) +#else +# define _GL_HAS_BUILTIN_TRAP 0 +#endif + +#if 4 < __GNUC__ + (5 <= __GNUC_MINOR__) +# define _GL_HAS_BUILTIN_UNREACHABLE 1 +#elif defined __has_builtin +# define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable) +#else +# define _GL_HAS_BUILTIN_UNREACHABLE 0 +#endif + /* Each of these macros verifies that its argument R is nonzero. To be portable, R should be an integer constant expression. Unlike assert (R), there is no run-time overhead. There are two macros, since no single macro can be used in all - contexts in C. verify_true (R) is for scalar contexts, including + contexts in C. verify_expr (R, E) is for scalar contexts, including integer constant expression contexts. verify (R) is for declaration contexts, e.g., the top level. */ -/* Verify requirement R at compile-time, as an integer constant expression. - Return 1. This is equivalent to verify_expr (R, 1). - - verify_true is obsolescent; please use verify_expr instead. */ - -#define verify_true(R) _GL_VERIFY_TRUE (R, "verify_true (" #R ")") - /* Verify requirement R at compile-time. Return the value of the expression E. */ @@ -244,31 +265,28 @@ template (_GL_VERIFY_TRUE (R, "verify_expr (" #R ", " #E ")") ? (E) : (E)) /* Verify requirement R at compile-time, as a declaration without a - trailing ';'. */ + trailing ';'. verify (R) acts like static_assert (R) except that + it is portable to C11/C++14 and earlier, it can issue better + diagnostics, and its name is shorter and may be more convenient. */ -#ifdef __GNUC__ -# define verify(R) _GL_VERIFY (R, "verify (" #R ")") +#ifdef __PGI +/* PGI barfs if R is long. */ +# define verify(R) _GL_VERIFY (R, "verify (...)", -) #else -/* PGI barfs if R is long. Play it safe. */ -# define verify(R) _GL_VERIFY (R, "verify (...)") -#endif - -#ifndef __has_builtin -# define __has_builtin(x) 0 +# define verify(R) _GL_VERIFY (R, "verify (" #R ")", -) #endif -/* Assume that R always holds. This lets the compiler optimize - accordingly. R should not have side-effects; it may or may not be - evaluated. Behavior is undefined if R is false. */ +/* Assume that R always holds. Behavior is undefined if R is false, + fails to evaluate, or has side effects. Although assuming R can + help a compiler generate better code or diagnostics, performance + can suffer if R uses hard-to-optimize features such as function + calls not inlined by the compiler. */ -#if (__has_builtin (__builtin_unreachable) \ - || 4 < __GNUC__ + (5 <= __GNUC_MINOR__)) +#if _GL_HAS_BUILTIN_UNREACHABLE # define assume(R) ((R) ? (void) 0 : __builtin_unreachable ()) #elif 1200 <= _MSC_VER # define assume(R) __assume (R) -#elif ((defined GCC_LINT || defined lint) \ - && (__has_builtin (__builtin_trap) \ - || 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__)))) +#elif (defined GCC_LINT || defined lint) && _GL_HAS_BUILTIN_TRAP /* Doing it this way helps various packages when configured with --enable-gcc-warnings, which compiles with -Dlint. It's nicer when 'assume' silences warnings even with older GCCs. */ diff --git a/contrib/tools/bison/lib/w32spawn.h b/contrib/tools/bison/lib/w32spawn.h index 941ff1ab2d4e..a4b3b1e500b9 100644 --- a/contrib/tools/bison/lib/w32spawn.h +++ b/contrib/tools/bison/lib/w32spawn.h @@ -1,5 +1,5 @@ /* Auxiliary functions for the creation of subprocesses. Native Windows API. - Copyright (C) 2001, 2003-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2003-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/wait-process.c b/contrib/tools/bison/lib/wait-process.c index 84c0e86b1f50..58a1e1121d4e 100644 --- a/contrib/tools/bison/lib/wait-process.c +++ b/contrib/tools/bison/lib/wait-process.c @@ -1,5 +1,5 @@ /* Waiting for a subprocess to finish. - Copyright (C) 2001-2003, 2005-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2005-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -80,7 +80,7 @@ static size_t slaves_allocated = SIZEOF (static_slaves); #endif /* The cleanup action. It gets called asynchronously. */ -static void +static _GL_ASYNC_SAFE void cleanup_slaves (void) { for (;;) @@ -102,6 +102,14 @@ cleanup_slaves (void) } } +/* The cleanup action, taking a signal argument. + It gets called asynchronously. */ +static _GL_ASYNC_SAFE void +cleanup_slaves_action (int sig _GL_UNUSED) +{ + cleanup_slaves (); +} + /* Register a subprocess as being a slave process. This means that the subprocess will be terminated when its creator receives a catchable fatal signal or exits normally. Registration ends when wait_subprocess() @@ -113,7 +121,7 @@ register_slave_subprocess (pid_t child) if (!cleanup_slaves_registered) { atexit (cleanup_slaves); - at_fatal_signal (cleanup_slaves); + at_fatal_signal (cleanup_slaves_action); cleanup_slaves_registered = true; } diff --git a/contrib/tools/bison/lib/wait-process.h b/contrib/tools/bison/lib/wait-process.h index 08470fb850c4..849d5156f956 100644 --- a/contrib/tools/bison/lib/wait-process.h +++ b/contrib/tools/bison/lib/wait-process.h @@ -1,5 +1,5 @@ /* Waiting for a subprocess to finish. - Copyright (C) 2001-2003, 2006, 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006, 2008-2020 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/waitpid.c b/contrib/tools/bison/lib/waitpid.c index a9dace628c49..2ef76615aa92 100644 --- a/contrib/tools/bison/lib/waitpid.c +++ b/contrib/tools/bison/lib/waitpid.c @@ -1,5 +1,5 @@ /* Wait for process state change. - Copyright (C) 2001-2003, 2005-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2005-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/wcwidth.c b/contrib/tools/bison/lib/wcwidth.c index 1f081ccaa120..6af212b2c259 100644 --- a/contrib/tools/bison/lib/wcwidth.c +++ b/contrib/tools/bison/lib/wcwidth.c @@ -1,5 +1,5 @@ /* Determine the number of screen columns needed for a character. - Copyright (C) 2006-2007, 2010-2019 Free Software Foundation, Inc. + Copyright (C) 2006-2007, 2010-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/windows-initguard.h b/contrib/tools/bison/lib/windows-initguard.h new file mode 100644 index 000000000000..c4be45a5f8bb --- /dev/null +++ b/contrib/tools/bison/lib/windows-initguard.h @@ -0,0 +1,35 @@ +/* Init guards, somewhat like spinlocks (native Windows implementation). + Copyright (C) 2005-2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Bruno Haible , 2005. + Based on GCC's gthr-win32.h. */ + +#ifndef _WINDOWS_INITGUARD_H +#define _WINDOWS_INITGUARD_H + +#define WIN32_LEAN_AND_MEAN /* avoid including junk */ +#include + +typedef struct + { + volatile int done; + volatile LONG started; + } + glwthread_initguard_t; + +#define GLWTHREAD_INITGUARD_INIT { 0, -1 } + +#endif /* _WINDOWS_INITGUARD_H */ diff --git a/contrib/tools/bison/lib/windows-mutex.c b/contrib/tools/bison/lib/windows-mutex.c new file mode 100644 index 000000000000..7eb38a2b1e92 --- /dev/null +++ b/contrib/tools/bison/lib/windows-mutex.c @@ -0,0 +1,95 @@ +/* Plain mutexes (native Windows implementation). + Copyright (C) 2005-2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Bruno Haible , 2005. + Based on GCC's gthr-win32.h. */ + +#include + +/* Specification. */ +#include "windows-mutex.h" + +#include + +void +glwthread_mutex_init (glwthread_mutex_t *mutex) +{ + InitializeCriticalSection (&mutex->lock); + mutex->guard.done = 1; +} + +int +glwthread_mutex_lock (glwthread_mutex_t *mutex) +{ + if (!mutex->guard.done) + { + if (InterlockedIncrement (&mutex->guard.started) == 0) + /* This thread is the first one to need this mutex. Initialize it. */ + glwthread_mutex_init (mutex); + else + { + /* Don't let mutex->guard.started grow and wrap around. */ + InterlockedDecrement (&mutex->guard.started); + /* Yield the CPU while waiting for another thread to finish + initializing this mutex. */ + while (!mutex->guard.done) + Sleep (0); + } + } + EnterCriticalSection (&mutex->lock); + return 0; +} + +int +glwthread_mutex_trylock (glwthread_mutex_t *mutex) +{ + if (!mutex->guard.done) + { + if (InterlockedIncrement (&mutex->guard.started) == 0) + /* This thread is the first one to need this mutex. Initialize it. */ + glwthread_mutex_init (mutex); + else + { + /* Don't let mutex->guard.started grow and wrap around. */ + InterlockedDecrement (&mutex->guard.started); + /* Let another thread finish initializing this mutex, and let it also + lock this mutex. */ + return EBUSY; + } + } + if (!TryEnterCriticalSection (&mutex->lock)) + return EBUSY; + return 0; +} + +int +glwthread_mutex_unlock (glwthread_mutex_t *mutex) +{ + if (!mutex->guard.done) + return EINVAL; + LeaveCriticalSection (&mutex->lock); + return 0; +} + +int +glwthread_mutex_destroy (glwthread_mutex_t *mutex) +{ + if (!mutex->guard.done) + return EINVAL; + DeleteCriticalSection (&mutex->lock); + mutex->guard.done = 0; + return 0; +} diff --git a/contrib/tools/bison/lib/windows-mutex.h b/contrib/tools/bison/lib/windows-mutex.h new file mode 100644 index 000000000000..748b9883db60 --- /dev/null +++ b/contrib/tools/bison/lib/windows-mutex.h @@ -0,0 +1,51 @@ +/* Plain mutexes (native Windows implementation). + Copyright (C) 2005-2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Bruno Haible , 2005. + Based on GCC's gthr-win32.h. */ + +#ifndef _WINDOWS_MUTEX_H +#define _WINDOWS_MUTEX_H + +#define WIN32_LEAN_AND_MEAN /* avoid including junk */ +#include + +#include "windows-initguard.h" + +typedef struct + { + glwthread_initguard_t guard; /* protects the initialization */ + CRITICAL_SECTION lock; + } + glwthread_mutex_t; + +#define GLWTHREAD_MUTEX_INIT { GLWTHREAD_INITGUARD_INIT } + +#ifdef __cplusplus +extern "C" { +#endif + +extern void glwthread_mutex_init (glwthread_mutex_t *mutex); +extern int glwthread_mutex_lock (glwthread_mutex_t *mutex); +extern int glwthread_mutex_trylock (glwthread_mutex_t *mutex); +extern int glwthread_mutex_unlock (glwthread_mutex_t *mutex); +extern int glwthread_mutex_destroy (glwthread_mutex_t *mutex); + +#ifdef __cplusplus +} +#endif + +#endif /* _WINDOWS_MUTEX_H */ diff --git a/contrib/tools/bison/lib/windows-once.c b/contrib/tools/bison/lib/windows-once.c new file mode 100644 index 000000000000..c431bd67073b --- /dev/null +++ b/contrib/tools/bison/lib/windows-once.c @@ -0,0 +1,62 @@ +/* Once-only control (native Windows implementation). + Copyright (C) 2005-2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Bruno Haible , 2005. + Based on GCC's gthr-win32.h. */ + +#include + +/* Specification. */ +#include "windows-once.h" + +#include + +void +glwthread_once (glwthread_once_t *once_control, void (*initfunction) (void)) +{ + if (once_control->inited <= 0) + { + if (InterlockedIncrement (&once_control->started) == 0) + { + /* This thread is the first one to come to this once_control. */ + InitializeCriticalSection (&once_control->lock); + EnterCriticalSection (&once_control->lock); + once_control->inited = 0; + initfunction (); + once_control->inited = 1; + LeaveCriticalSection (&once_control->lock); + } + else + { + /* Don't let once_control->started grow and wrap around. */ + InterlockedDecrement (&once_control->started); + /* Some other thread has already started the initialization. + Yield the CPU while waiting for the other thread to finish + initializing and taking the lock. */ + while (once_control->inited < 0) + Sleep (0); + if (once_control->inited <= 0) + { + /* Take the lock. This blocks until the other thread has + finished calling the initfunction. */ + EnterCriticalSection (&once_control->lock); + LeaveCriticalSection (&once_control->lock); + if (!(once_control->inited > 0)) + abort (); + } + } + } +} diff --git a/contrib/tools/bison/lib/windows-once.h b/contrib/tools/bison/lib/windows-once.h new file mode 100644 index 000000000000..d31717e861ee --- /dev/null +++ b/contrib/tools/bison/lib/windows-once.h @@ -0,0 +1,47 @@ +/* Once-only control (native Windows implementation). + Copyright (C) 2005-2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Bruno Haible , 2005. + Based on GCC's gthr-win32.h. */ + +#ifndef _WINDOWS_ONCE_H +#define _WINDOWS_ONCE_H + +#define WIN32_LEAN_AND_MEAN /* avoid including junk */ +#include + +typedef struct + { + volatile int inited; + volatile LONG started; + CRITICAL_SECTION lock; + } + glwthread_once_t; + +#define GLWTHREAD_ONCE_INIT { -1, -1 } + +#ifdef __cplusplus +extern "C" { +#endif + +extern void glwthread_once (glwthread_once_t *once_control, + void (*initfunction) (void)); + +#ifdef __cplusplus +} +#endif + +#endif /* _WINDOWS_ONCE_H */ diff --git a/contrib/tools/bison/lib/windows-recmutex.c b/contrib/tools/bison/lib/windows-recmutex.c new file mode 100644 index 000000000000..db3c40c442fd --- /dev/null +++ b/contrib/tools/bison/lib/windows-recmutex.c @@ -0,0 +1,127 @@ +/* Plain recursive mutexes (native Windows implementation). + Copyright (C) 2005-2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Bruno Haible , 2005. + Based on GCC's gthr-win32.h. */ + +#include + +/* Specification. */ +#include "windows-recmutex.h" + +#include + +void +glwthread_recmutex_init (glwthread_recmutex_t *mutex) +{ + mutex->owner = 0; + mutex->depth = 0; + InitializeCriticalSection (&mutex->lock); + mutex->guard.done = 1; +} + +int +glwthread_recmutex_lock (glwthread_recmutex_t *mutex) +{ + if (!mutex->guard.done) + { + if (InterlockedIncrement (&mutex->guard.started) == 0) + /* This thread is the first one to need this mutex. Initialize it. */ + glwthread_recmutex_init (mutex); + else + { + /* Don't let mutex->guard.started grow and wrap around. */ + InterlockedDecrement (&mutex->guard.started); + /* Yield the CPU while waiting for another thread to finish + initializing this mutex. */ + while (!mutex->guard.done) + Sleep (0); + } + } + { + DWORD self = GetCurrentThreadId (); + if (mutex->owner != self) + { + EnterCriticalSection (&mutex->lock); + mutex->owner = self; + } + if (++(mutex->depth) == 0) /* wraparound? */ + { + mutex->depth--; + return EAGAIN; + } + } + return 0; +} + +int +glwthread_recmutex_trylock (glwthread_recmutex_t *mutex) +{ + if (!mutex->guard.done) + { + if (InterlockedIncrement (&mutex->guard.started) == 0) + /* This thread is the first one to need this mutex. Initialize it. */ + glwthread_recmutex_init (mutex); + else + { + /* Don't let mutex->guard.started grow and wrap around. */ + InterlockedDecrement (&mutex->guard.started); + /* Let another thread finish initializing this mutex, and let it also + lock this mutex. */ + return EBUSY; + } + } + { + DWORD self = GetCurrentThreadId (); + if (mutex->owner != self) + { + if (!TryEnterCriticalSection (&mutex->lock)) + return EBUSY; + mutex->owner = self; + } + if (++(mutex->depth) == 0) /* wraparound? */ + { + mutex->depth--; + return EAGAIN; + } + } + return 0; +} + +int +glwthread_recmutex_unlock (glwthread_recmutex_t *mutex) +{ + if (mutex->owner != GetCurrentThreadId ()) + return EPERM; + if (mutex->depth == 0) + return EINVAL; + if (--(mutex->depth) == 0) + { + mutex->owner = 0; + LeaveCriticalSection (&mutex->lock); + } + return 0; +} + +int +glwthread_recmutex_destroy (glwthread_recmutex_t *mutex) +{ + if (mutex->owner != 0) + return EBUSY; + DeleteCriticalSection (&mutex->lock); + mutex->guard.done = 0; + return 0; +} diff --git a/contrib/tools/bison/lib/windows-recmutex.h b/contrib/tools/bison/lib/windows-recmutex.h new file mode 100644 index 000000000000..3b315e5ce9f2 --- /dev/null +++ b/contrib/tools/bison/lib/windows-recmutex.h @@ -0,0 +1,57 @@ +/* Plain recursive mutexes (native Windows implementation). + Copyright (C) 2005-2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Bruno Haible , 2005. + Based on GCC's gthr-win32.h. */ + +#ifndef _WINDOWS_RECMUTEX_H +#define _WINDOWS_RECMUTEX_H + +#define WIN32_LEAN_AND_MEAN /* avoid including junk */ +#include + +#include "windows-initguard.h" + +/* The native Windows documentation says that CRITICAL_SECTION already + implements a recursive lock. But we need not rely on it: It's easy to + implement a recursive lock without this assumption. */ + +typedef struct + { + glwthread_initguard_t guard; /* protects the initialization */ + DWORD owner; + unsigned long depth; + CRITICAL_SECTION lock; + } + glwthread_recmutex_t; + +#define GLWTHREAD_RECMUTEX_INIT { GLWTHREAD_INITGUARD_INIT, 0, 0 } + +#ifdef __cplusplus +extern "C" { +#endif + +extern void glwthread_recmutex_init (glwthread_recmutex_t *mutex); +extern int glwthread_recmutex_lock (glwthread_recmutex_t *mutex); +extern int glwthread_recmutex_trylock (glwthread_recmutex_t *mutex); +extern int glwthread_recmutex_unlock (glwthread_recmutex_t *mutex); +extern int glwthread_recmutex_destroy (glwthread_recmutex_t *mutex); + +#ifdef __cplusplus +} +#endif + +#endif /* _WINDOWS_RECMUTEX_H */ diff --git a/contrib/tools/bison/lib/windows-rwlock.c b/contrib/tools/bison/lib/windows-rwlock.c new file mode 100644 index 000000000000..aafc5ddda3bd --- /dev/null +++ b/contrib/tools/bison/lib/windows-rwlock.c @@ -0,0 +1,373 @@ +/* Read-write locks (native Windows implementation). + Copyright (C) 2005-2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Bruno Haible , 2005. + Based on GCC's gthr-win32.h. */ + +#include + +/* Specification. */ +#include "windows-rwlock.h" + +#include +#include + +/* In this file, the waitqueues are implemented as circular arrays. */ +#define glwthread_waitqueue_t glwthread_carray_waitqueue_t + +static void +glwthread_waitqueue_init (glwthread_waitqueue_t *wq) +{ + wq->array = NULL; + wq->count = 0; + wq->alloc = 0; + wq->offset = 0; +} + +/* Enqueues the current thread, represented by an event, in a wait queue. + Returns INVALID_HANDLE_VALUE if an allocation failure occurs. */ +static HANDLE +glwthread_waitqueue_add (glwthread_waitqueue_t *wq) +{ + HANDLE event; + unsigned int index; + + if (wq->count == wq->alloc) + { + unsigned int new_alloc = 2 * wq->alloc + 1; + HANDLE *new_array = + (HANDLE *) realloc (wq->array, new_alloc * sizeof (HANDLE)); + if (new_array == NULL) + /* No more memory. */ + return INVALID_HANDLE_VALUE; + /* Now is a good opportunity to rotate the array so that its contents + starts at offset 0. */ + if (wq->offset > 0) + { + unsigned int old_count = wq->count; + unsigned int old_alloc = wq->alloc; + unsigned int old_offset = wq->offset; + unsigned int i; + if (old_offset + old_count > old_alloc) + { + unsigned int limit = old_offset + old_count - old_alloc; + for (i = 0; i < limit; i++) + new_array[old_alloc + i] = new_array[i]; + } + for (i = 0; i < old_count; i++) + new_array[i] = new_array[old_offset + i]; + wq->offset = 0; + } + wq->array = new_array; + wq->alloc = new_alloc; + } + /* Whether the created event is a manual-reset one or an auto-reset one, + does not matter, since we will wait on it only once. */ + event = CreateEvent (NULL, TRUE, FALSE, NULL); + if (event == INVALID_HANDLE_VALUE) + /* No way to allocate an event. */ + return INVALID_HANDLE_VALUE; + index = wq->offset + wq->count; + if (index >= wq->alloc) + index -= wq->alloc; + wq->array[index] = event; + wq->count++; + return event; +} + +/* Notifies the first thread from a wait queue and dequeues it. */ +static void +glwthread_waitqueue_notify_first (glwthread_waitqueue_t *wq) +{ + SetEvent (wq->array[wq->offset + 0]); + wq->offset++; + wq->count--; + if (wq->count == 0 || wq->offset == wq->alloc) + wq->offset = 0; +} + +/* Notifies all threads from a wait queue and dequeues them all. */ +static void +glwthread_waitqueue_notify_all (glwthread_waitqueue_t *wq) +{ + unsigned int i; + + for (i = 0; i < wq->count; i++) + { + unsigned int index = wq->offset + i; + if (index >= wq->alloc) + index -= wq->alloc; + SetEvent (wq->array[index]); + } + wq->count = 0; + wq->offset = 0; +} + +void +glwthread_rwlock_init (glwthread_rwlock_t *lock) +{ + InitializeCriticalSection (&lock->lock); + glwthread_waitqueue_init (&lock->waiting_readers); + glwthread_waitqueue_init (&lock->waiting_writers); + lock->runcount = 0; + lock->guard.done = 1; +} + +int +glwthread_rwlock_rdlock (glwthread_rwlock_t *lock) +{ + if (!lock->guard.done) + { + if (InterlockedIncrement (&lock->guard.started) == 0) + /* This thread is the first one to need this lock. Initialize it. */ + glwthread_rwlock_init (lock); + else + { + /* Don't let lock->guard.started grow and wrap around. */ + InterlockedDecrement (&lock->guard.started); + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); + } + } + EnterCriticalSection (&lock->lock); + /* Test whether only readers are currently running, and whether the runcount + field will not overflow, and whether no writer is waiting. The latter + condition is because POSIX recommends that "write locks shall take + precedence over read locks", to avoid "writer starvation". */ + if (!(lock->runcount + 1 > 0 && lock->waiting_writers.count == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_readers. */ + HANDLE event = glwthread_waitqueue_add (&lock->waiting_readers); + if (event != INVALID_HANDLE_VALUE) + { + DWORD result; + LeaveCriticalSection (&lock->lock); + /* Wait until another thread signals this event. */ + result = WaitForSingleObject (event, INFINITE); + if (result == WAIT_FAILED || result == WAIT_TIMEOUT) + abort (); + CloseHandle (event); + /* The thread which signalled the event already did the bookkeeping: + removed us from the waiting_readers, incremented lock->runcount. */ + if (!(lock->runcount > 0)) + abort (); + return 0; + } + else + { + /* Allocation failure. Weird. */ + do + { + LeaveCriticalSection (&lock->lock); + Sleep (1); + EnterCriticalSection (&lock->lock); + } + while (!(lock->runcount + 1 > 0)); + } + } + lock->runcount++; + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glwthread_rwlock_wrlock (glwthread_rwlock_t *lock) +{ + if (!lock->guard.done) + { + if (InterlockedIncrement (&lock->guard.started) == 0) + /* This thread is the first one to need this lock. Initialize it. */ + glwthread_rwlock_init (lock); + else + { + /* Don't let lock->guard.started grow and wrap around. */ + InterlockedDecrement (&lock->guard.started); + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); + } + } + EnterCriticalSection (&lock->lock); + /* Test whether no readers or writers are currently running. */ + if (!(lock->runcount == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_writers. */ + HANDLE event = glwthread_waitqueue_add (&lock->waiting_writers); + if (event != INVALID_HANDLE_VALUE) + { + DWORD result; + LeaveCriticalSection (&lock->lock); + /* Wait until another thread signals this event. */ + result = WaitForSingleObject (event, INFINITE); + if (result == WAIT_FAILED || result == WAIT_TIMEOUT) + abort (); + CloseHandle (event); + /* The thread which signalled the event already did the bookkeeping: + removed us from the waiting_writers, set lock->runcount = -1. */ + if (!(lock->runcount == -1)) + abort (); + return 0; + } + else + { + /* Allocation failure. Weird. */ + do + { + LeaveCriticalSection (&lock->lock); + Sleep (1); + EnterCriticalSection (&lock->lock); + } + while (!(lock->runcount == 0)); + } + } + lock->runcount--; /* runcount becomes -1 */ + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glwthread_rwlock_tryrdlock (glwthread_rwlock_t *lock) +{ + if (!lock->guard.done) + { + if (InterlockedIncrement (&lock->guard.started) == 0) + /* This thread is the first one to need this lock. Initialize it. */ + glwthread_rwlock_init (lock); + else + { + /* Don't let lock->guard.started grow and wrap around. */ + InterlockedDecrement (&lock->guard.started); + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); + } + } + /* It's OK to wait for this critical section, because it is never taken for a + long time. */ + EnterCriticalSection (&lock->lock); + /* Test whether only readers are currently running, and whether the runcount + field will not overflow, and whether no writer is waiting. The latter + condition is because POSIX recommends that "write locks shall take + precedence over read locks", to avoid "writer starvation". */ + if (!(lock->runcount + 1 > 0 && lock->waiting_writers.count == 0)) + { + /* This thread would have to wait for a while. Return instead. */ + LeaveCriticalSection (&lock->lock); + return EBUSY; + } + lock->runcount++; + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glwthread_rwlock_trywrlock (glwthread_rwlock_t *lock) +{ + if (!lock->guard.done) + { + if (InterlockedIncrement (&lock->guard.started) == 0) + /* This thread is the first one to need this lock. Initialize it. */ + glwthread_rwlock_init (lock); + else + { + /* Don't let lock->guard.started grow and wrap around. */ + InterlockedDecrement (&lock->guard.started); + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); + } + } + /* It's OK to wait for this critical section, because it is never taken for a + long time. */ + EnterCriticalSection (&lock->lock); + /* Test whether no readers or writers are currently running. */ + if (!(lock->runcount == 0)) + { + /* This thread would have to wait for a while. Return instead. */ + LeaveCriticalSection (&lock->lock); + return EBUSY; + } + lock->runcount--; /* runcount becomes -1 */ + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glwthread_rwlock_unlock (glwthread_rwlock_t *lock) +{ + if (!lock->guard.done) + return EINVAL; + EnterCriticalSection (&lock->lock); + if (lock->runcount < 0) + { + /* Drop a writer lock. */ + if (!(lock->runcount == -1)) + abort (); + lock->runcount = 0; + } + else + { + /* Drop a reader lock. */ + if (!(lock->runcount > 0)) + { + LeaveCriticalSection (&lock->lock); + return EPERM; + } + lock->runcount--; + } + if (lock->runcount == 0) + { + /* POSIX recommends that "write locks shall take precedence over read + locks", to avoid "writer starvation". */ + if (lock->waiting_writers.count > 0) + { + /* Wake up one of the waiting writers. */ + lock->runcount--; + glwthread_waitqueue_notify_first (&lock->waiting_writers); + } + else + { + /* Wake up all waiting readers. */ + lock->runcount += lock->waiting_readers.count; + glwthread_waitqueue_notify_all (&lock->waiting_readers); + } + } + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glwthread_rwlock_destroy (glwthread_rwlock_t *lock) +{ + if (!lock->guard.done) + return EINVAL; + if (lock->runcount != 0) + return EBUSY; + DeleteCriticalSection (&lock->lock); + if (lock->waiting_readers.array != NULL) + free (lock->waiting_readers.array); + if (lock->waiting_writers.array != NULL) + free (lock->waiting_writers.array); + lock->guard.done = 0; + return 0; +} diff --git a/contrib/tools/bison/lib/windows-rwlock.h b/contrib/tools/bison/lib/windows-rwlock.h new file mode 100644 index 000000000000..ae5b82f52755 --- /dev/null +++ b/contrib/tools/bison/lib/windows-rwlock.h @@ -0,0 +1,68 @@ +/* Read-write locks (native Windows implementation). + Copyright (C) 2005-2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . */ + +/* Written by Bruno Haible , 2005. + Based on GCC's gthr-win32.h. */ + +#ifndef _WINDOWS_RWLOCK_H +#define _WINDOWS_RWLOCK_H + +#define WIN32_LEAN_AND_MEAN /* avoid including junk */ +#include + +#include "windows-initguard.h" + +/* It is impossible to implement read-write locks using plain locks, without + introducing an extra thread dedicated to managing read-write locks. + Therefore here we need to use the low-level Event type. */ + +typedef struct + { + HANDLE *array; /* array of waiting threads, each represented by an event */ + unsigned int count; /* number of waiting threads */ + unsigned int alloc; /* length of allocated array */ + unsigned int offset; /* index of first waiting thread in array */ + } + glwthread_carray_waitqueue_t; +typedef struct + { + glwthread_initguard_t guard; /* protects the initialization */ + CRITICAL_SECTION lock; /* protects the remaining fields */ + glwthread_carray_waitqueue_t waiting_readers; /* waiting readers */ + glwthread_carray_waitqueue_t waiting_writers; /* waiting writers */ + int runcount; /* number of readers running, or -1 when a writer runs */ + } + glwthread_rwlock_t; + +#define GLWTHREAD_RWLOCK_INIT { GLWTHREAD_INITGUARD_INIT } + +#ifdef __cplusplus +extern "C" { +#endif + +extern void glwthread_rwlock_init (glwthread_rwlock_t *lock); +extern int glwthread_rwlock_rdlock (glwthread_rwlock_t *lock); +extern int glwthread_rwlock_wrlock (glwthread_rwlock_t *lock); +extern int glwthread_rwlock_tryrdlock (glwthread_rwlock_t *lock); +extern int glwthread_rwlock_trywrlock (glwthread_rwlock_t *lock); +extern int glwthread_rwlock_unlock (glwthread_rwlock_t *lock); +extern int glwthread_rwlock_destroy (glwthread_rwlock_t *lock); + +#ifdef __cplusplus +} +#endif + +#endif /* _WINDOWS_RWLOCK_H */ diff --git a/contrib/tools/bison/lib/windows-tls.c b/contrib/tools/bison/lib/windows-tls.c new file mode 100644 index 000000000000..d52515c95811 --- /dev/null +++ b/contrib/tools/bison/lib/windows-tls.c @@ -0,0 +1,339 @@ +/* Thread-local storage (native Windows implementation). + Copyright (C) 2005-2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2005. */ + +#include + +/* Specification. */ +#include "windows-tls.h" + +#include +#include +#include + +#include "windows-once.h" + +void * +glwthread_tls_get (glwthread_tls_key_t key) +{ + return TlsGetValue (key); +} + +int +glwthread_tls_set (glwthread_tls_key_t key, void *value) +{ + if (!TlsSetValue (key, value)) + return EINVAL; + return 0; +} + +/* The following variables keep track of TLS keys with non-NULL destructor. */ + +static glwthread_once_t dtor_table_init_once = GLWTHREAD_ONCE_INIT; + +static CRITICAL_SECTION dtor_table_lock; + +struct dtor { glwthread_tls_key_t key; void (*destructor) (void *); }; + +/* The table of dtors. */ +static struct dtor *dtor_table; +/* Number of active entries in the dtor_table. */ +static unsigned int dtors_count; +/* Valid indices into dtor_table are 0..dtors_used-1. */ +static unsigned int dtors_used; +/* Allocation size of dtor_table. */ +static unsigned int dtors_allocated; +/* Invariant: 0 <= dtors_count <= dtors_used <= dtors_allocated. */ + +/* Number of threads that are currently processing destructors. */ +static unsigned int dtor_processing_threads; + +static void +dtor_table_initialize (void) +{ + InitializeCriticalSection (&dtor_table_lock); + /* The other variables are already initialized to NULL or 0, respectively. */ +} + +static void +dtor_table_ensure_initialized (void) +{ + glwthread_once (&dtor_table_init_once, dtor_table_initialize); +} + +/* Shrinks dtors_used down to dtors_count, by replacing inactive entries + with active ones. */ +static void +dtor_table_shrink_used (void) +{ + unsigned int i = 0; + unsigned int j = dtors_used; + + for (;;) + { + BOOL i_found = FALSE; + BOOL j_found = FALSE; + /* Find the next inactive entry, from the left. */ + for (; i < dtors_count;) + { + if (dtor_table[i].destructor == NULL) + { + i_found = TRUE; + break; + } + i++; + } + + /* Find the next active entry, from the right. */ + for (; j > dtors_count;) + { + j--; + if (dtor_table[j].destructor != NULL) + { + j_found = TRUE; + break; + } + } + + if (i_found != j_found) + /* dtors_count was apparently wrong. */ + abort (); + + if (!i_found) + break; + + /* i_found and j_found are TRUE. Swap the two entries. */ + dtor_table[i] = dtor_table[j]; + + i++; + } + + dtors_used = dtors_count; +} + +void +glwthread_tls_process_destructors (void) +{ + unsigned int repeat; + + dtor_table_ensure_initialized (); + + EnterCriticalSection (&dtor_table_lock); + if (dtor_processing_threads == 0) + { + /* Now it's the appropriate time for shrinking dtors_used. */ + if (dtors_used > dtors_count) + dtor_table_shrink_used (); + } + dtor_processing_threads++; + + for (repeat = GLWTHREAD_DESTRUCTOR_ITERATIONS; repeat > 0; repeat--) + { + unsigned int destructors_run = 0; + + /* Iterate across dtor_table. We don't need to make a copy of dtor_table, + because + * When another thread calls glwthread_tls_key_create with a non-NULL + destructor argument, this will possibly reallocate the dtor_table + array and increase dtors_allocated as well as dtors_used and + dtors_count, but it will not change dtors_used nor the contents of + the first dtors_used entries of dtor_table. + * When another thread calls glwthread_tls_key_delete, this will + possibly set some 'destructor' member to NULL, thus marking an + entry as inactive, but it will not otherwise change dtors_used nor + the contents of the first dtors_used entries of dtor_table. */ + unsigned int i_limit = dtors_used; + unsigned int i; + + for (i = 0; i < i_limit; i++) + { + struct dtor current = dtor_table[i]; + if (current.destructor != NULL) + { + /* The current dtor has not been deleted yet. */ + void *current_value = glwthread_tls_get (current.key); + if (current_value != NULL) + { + /* The current value is non-NULL. Run the destructor. */ + glwthread_tls_set (current.key, NULL); + LeaveCriticalSection (&dtor_table_lock); + current.destructor (current_value); + EnterCriticalSection (&dtor_table_lock); + destructors_run++; + } + } + } + + /* When all TLS values were already NULL, no further iterations are + needed. */ + if (destructors_run == 0) + break; + } + + dtor_processing_threads--; + LeaveCriticalSection (&dtor_table_lock); +} + +int +glwthread_tls_key_create (glwthread_tls_key_t *keyp, void (*destructor) (void *)) +{ + if (destructor != NULL) + { + dtor_table_ensure_initialized (); + + EnterCriticalSection (&dtor_table_lock); + if (dtor_processing_threads == 0) + { + /* Now it's the appropriate time for shrinking dtors_used. */ + if (dtors_used > dtors_count) + dtor_table_shrink_used (); + } + + while (dtors_used == dtors_allocated) + { + /* Need to grow the dtor_table. */ + unsigned int new_allocated = 2 * dtors_allocated + 1; + if (new_allocated < 7) + new_allocated = 7; + if (new_allocated <= dtors_allocated) /* overflow? */ + new_allocated = UINT_MAX; + + LeaveCriticalSection (&dtor_table_lock); + { + struct dtor *new_table = + (struct dtor *) malloc (new_allocated * sizeof (struct dtor)); + if (new_table == NULL) + return ENOMEM; + EnterCriticalSection (&dtor_table_lock); + /* Attention! dtors_used, dtors_allocated may have changed! */ + if (dtors_used < new_allocated) + { + if (dtors_allocated < new_allocated) + { + /* The new_table is useful. */ + memcpy (new_table, dtor_table, + dtors_used * sizeof (struct dtor)); + dtor_table = new_table; + dtors_allocated = new_allocated; + } + else + { + /* The new_table is not useful, since another thread + meanwhile allocated a drop_table that is at least + as large. */ + free (new_table); + } + break; + } + /* The new_table is not useful, since other threads increased + dtors_used. Free it any retry. */ + free (new_table); + } + } + /* Here dtors_used < dtors_allocated. */ + { + /* Allocate a new key. */ + glwthread_tls_key_t key = TlsAlloc (); + if (key == (DWORD)-1) + { + LeaveCriticalSection (&dtor_table_lock); + return EAGAIN; + } + /* Store the new dtor in the dtor_table, after all used entries. + Do not overwrite inactive entries with indices < dtors_used, in order + not to disturb glwthread_tls_process_destructors invocations that may + be executing in other threads. */ + dtor_table[dtors_used].key = key; + dtor_table[dtors_used].destructor = destructor; + dtors_used++; + dtors_count++; + LeaveCriticalSection (&dtor_table_lock); + *keyp = key; + } + } + else + { + /* Allocate a new key. */ + glwthread_tls_key_t key = TlsAlloc (); + if (key == (DWORD)-1) + return EAGAIN; + *keyp = key; + } + return 0; +} + +int +glwthread_tls_key_delete (glwthread_tls_key_t key) +{ + /* Should the destructor be called for all threads that are currently running? + Probably not, because + - ISO C does not specify when the destructor is to be invoked at all. + - In POSIX, the destructor functions specified with pthread_key_create() + are invoked at thread exit. + - It would be hard to implement, because there are no primitives for + accessing thread-specific values from a different thread. */ + dtor_table_ensure_initialized (); + + EnterCriticalSection (&dtor_table_lock); + if (dtor_processing_threads == 0) + { + /* Now it's the appropriate time for shrinking dtors_used. */ + if (dtors_used > dtors_count) + dtor_table_shrink_used (); + /* Here dtors_used == dtors_count. */ + + /* Find the key in dtor_table. */ + { + unsigned int i_limit = dtors_used; + unsigned int i; + + for (i = 0; i < i_limit; i++) + if (dtor_table[i].key == key) + { + if (i < dtors_used - 1) + /* Swap the entries i and dtors_used - 1. */ + dtor_table[i] = dtor_table[dtors_used - 1]; + dtors_count = dtors_used = dtors_used - 1; + break; + } + } + } + else + { + /* Be careful not to disturb the glwthread_tls_process_destructors + invocations that are executing in other threads. */ + unsigned int i_limit = dtors_used; + unsigned int i; + + for (i = 0; i < i_limit; i++) + if (dtor_table[i].destructor != NULL /* skip inactive entries */ + && dtor_table[i].key == key) + { + /* Mark this entry as inactive. */ + dtor_table[i].destructor = NULL; + dtors_count = dtors_count - 1; + break; + } + } + LeaveCriticalSection (&dtor_table_lock); + /* Now we have ensured that glwthread_tls_process_destructors will no longer + use this key. */ + + if (!TlsFree (key)) + return EINVAL; + return 0; +} diff --git a/contrib/tools/bison/lib/windows-tls.h b/contrib/tools/bison/lib/windows-tls.h new file mode 100644 index 000000000000..2b39fabd5a5a --- /dev/null +++ b/contrib/tools/bison/lib/windows-tls.h @@ -0,0 +1,42 @@ +/* Thread-local storage (native Windows implementation). + Copyright (C) 2005-2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2005. */ + +#ifndef _WINDOWS_TLS_H +#define _WINDOWS_TLS_H + +#define WIN32_LEAN_AND_MEAN /* avoid including junk */ +#include + +typedef DWORD glwthread_tls_key_t; + +#ifdef __cplusplus +extern "C" { +#endif + +extern int glwthread_tls_key_create (glwthread_tls_key_t *keyp, void (*destructor) (void *)); +extern void *glwthread_tls_get (glwthread_tls_key_t key); +extern int glwthread_tls_set (glwthread_tls_key_t key, void *value); +extern int glwthread_tls_key_delete (glwthread_tls_key_t key); +extern void glwthread_tls_process_destructors (void); +#define GLWTHREAD_DESTRUCTOR_ITERATIONS 4 + +#ifdef __cplusplus +} +#endif + +#endif /* _WINDOWS_TLS_H */ diff --git a/contrib/tools/bison/lib/xalloc-die.c b/contrib/tools/bison/lib/xalloc-die.c index 295f8d8e758d..68559deebb31 100644 --- a/contrib/tools/bison/lib/xalloc-die.c +++ b/contrib/tools/bison/lib/xalloc-die.c @@ -1,6 +1,6 @@ /* Report a memory allocation failure and exit. - Copyright (C) 1997-2000, 2002-2004, 2006, 2009-2019 Free Software + Copyright (C) 1997-2000, 2002-2004, 2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/xalloc-oversized.h b/contrib/tools/bison/lib/xalloc-oversized.h index e3068c83c48f..13ee23031a05 100644 --- a/contrib/tools/bison/lib/xalloc-oversized.h +++ b/contrib/tools/bison/lib/xalloc-oversized.h @@ -1,6 +1,6 @@ /* xalloc-oversized.h -- memory allocation size checking - Copyright (C) 1990-2000, 2003-2004, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 1990-2000, 2003-2004, 2006-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/xalloc.h b/contrib/tools/bison/lib/xalloc.h index fc7e86bd89b3..19c64acb4168 100644 --- a/contrib/tools/bison/lib/xalloc.h +++ b/contrib/tools/bison/lib/xalloc.h @@ -1,6 +1,6 @@ /* xalloc.h -- malloc with out-of-memory checking - Copyright (C) 1990-2000, 2003-2004, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 1990-2000, 2003-2004, 2006-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -48,7 +48,7 @@ extern "C" { or by using gnulib's xalloc-die module. This is the function to call when one wants the program to die because of a memory allocation failure. */ -extern _Noreturn void xalloc_die (void); +/*extern*/ _Noreturn void xalloc_die (void); void *xmalloc (size_t s) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1)); diff --git a/contrib/tools/bison/lib/xconcat-filename.c b/contrib/tools/bison/lib/xconcat-filename.c index ad2d5f66b47a..e04d4337eb69 100644 --- a/contrib/tools/bison/lib/xconcat-filename.c +++ b/contrib/tools/bison/lib/xconcat-filename.c @@ -1,5 +1,5 @@ /* Construct a full filename from a directory and a relative filename. - Copyright (C) 2001-2004, 2006-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the diff --git a/contrib/tools/bison/lib/xhash.c b/contrib/tools/bison/lib/xhash.c new file mode 100644 index 000000000000..1e998d2d15e4 --- /dev/null +++ b/contrib/tools/bison/lib/xhash.c @@ -0,0 +1,38 @@ +/* hash - hashing table processing. + + Copyright (C) 2019-2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include "hash.h" + +#include "xalloc.h" + +/* Same as hash_initialize, but invokes xalloc_die on memory + exhaustion. */ + +Hash_table * +hash_xinitialize (size_t candidate, const Hash_tuning *tuning, + Hash_hasher hasher, Hash_comparator comparator, + Hash_data_freer data_freer) +{ + Hash_table *res = + hash_initialize (candidate, tuning, hasher, comparator, data_freer); + if (!res) + xalloc_die (); + return res; +} diff --git a/contrib/tools/bison/lib/xmalloc.c b/contrib/tools/bison/lib/xmalloc.c index cbe9a4f5671e..486873602e4e 100644 --- a/contrib/tools/bison/lib/xmalloc.c +++ b/contrib/tools/bison/lib/xmalloc.c @@ -1,6 +1,6 @@ /* xmalloc.c -- malloc with out of memory checking - Copyright (C) 1990-2000, 2002-2006, 2008-2019 Free Software Foundation, Inc. + Copyright (C) 1990-2000, 2002-2006, 2008-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -76,14 +76,14 @@ x2realloc (void *p, size_t *pn) return x2nrealloc (p, pn, 1); } -/* Allocate S bytes of zeroed memory dynamically, with error checking. +/* Allocate N bytes of zeroed memory dynamically, with error checking. There's no need for xnzalloc (N, S), since it would be equivalent to xcalloc (N, S). */ void * -xzalloc (size_t s) +xzalloc (size_t n) { - return memset (xmalloc (s), 0, s); + return xcalloc (n, 1); } /* Allocate zeroed memory for N elements of S bytes, with error diff --git a/contrib/tools/bison/lib/xmemdup0.c b/contrib/tools/bison/lib/xmemdup0.c index 4f491be1b8d0..c076b9affba9 100644 --- a/contrib/tools/bison/lib/xmemdup0.c +++ b/contrib/tools/bison/lib/xmemdup0.c @@ -1,6 +1,6 @@ /* xmemdup0.c -- copy a block of arbitrary bytes, plus a trailing NUL - Copyright (C) 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2008-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -38,7 +38,8 @@ char * xmemdup0 (void const *p, size_t s) { char *result = xcharalloc (s + 1); - memcpy (result, p, s); + if (s > 0) + memcpy (result, p, s); result[s] = 0; return result; } diff --git a/contrib/tools/bison/lib/xmemdup0.h b/contrib/tools/bison/lib/xmemdup0.h index 768f0b274b66..9a61ade9c0e6 100644 --- a/contrib/tools/bison/lib/xmemdup0.h +++ b/contrib/tools/bison/lib/xmemdup0.h @@ -1,6 +1,6 @@ /* xmemdup0.h -- copy a block of arbitrary bytes, plus a trailing NUL - Copyright (C) 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2008-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/xreadlink.c b/contrib/tools/bison/lib/xreadlink.c index 59cfde91b943..31521b989527 100644 --- a/contrib/tools/bison/lib/xreadlink.c +++ b/contrib/tools/bison/lib/xreadlink.c @@ -1,6 +1,6 @@ /* xreadlink.c -- readlink wrapper to return the link name in malloc'd storage - Copyright (C) 2001, 2003-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2001, 2003-2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/xreadlink.h b/contrib/tools/bison/lib/xreadlink.h index 583205be54f3..be82e78d63f2 100644 --- a/contrib/tools/bison/lib/xreadlink.h +++ b/contrib/tools/bison/lib/xreadlink.h @@ -1,6 +1,6 @@ /* Reading symbolic links without size limitation. - Copyright (C) 2001, 2003-2004, 2007, 2009-2019 Free Software Foundation, + Copyright (C) 2001, 2003-2004, 2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify diff --git a/contrib/tools/bison/lib/xsize.h b/contrib/tools/bison/lib/xsize.h index ecfd478dcd56..45d41661794b 100644 --- a/contrib/tools/bison/lib/xsize.h +++ b/contrib/tools/bison/lib/xsize.h @@ -1,6 +1,6 @@ /* xsize.h -- Checked size_t computations. - Copyright (C) 2003, 2008-2019 Free Software Foundation, Inc. + Copyright (C) 2003, 2008-2020 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/xstrndup.c b/contrib/tools/bison/lib/xstrndup.c index a9738291130d..93dcfe50fdd7 100644 --- a/contrib/tools/bison/lib/xstrndup.c +++ b/contrib/tools/bison/lib/xstrndup.c @@ -1,6 +1,6 @@ /* Duplicate a bounded initial segment of a string, with out-of-memory checking. - Copyright (C) 2003, 2006-2007, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2003, 2006-2007, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/xstrndup.h b/contrib/tools/bison/lib/xstrndup.h index 360ccfdbb1f2..4f1da97c3ffc 100644 --- a/contrib/tools/bison/lib/xstrndup.h +++ b/contrib/tools/bison/lib/xstrndup.h @@ -1,6 +1,6 @@ /* Duplicate a bounded initial segment of a string, with out-of-memory checking. - Copyright (C) 2003, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2003, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/lib/xtime.h b/contrib/tools/bison/lib/xtime.h index 9edd12392db9..7f2992c335f4 100644 --- a/contrib/tools/bison/lib/xtime.h +++ b/contrib/tools/bison/lib/xtime.h @@ -1,6 +1,6 @@ /* xtime -- extended-resolution integer timestamps - Copyright (C) 2005-2006, 2009-2019 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2009-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,40 +29,27 @@ _GL_INLINE_HEADER_BEGIN #endif /* xtime_t is a signed type used for timestamps. It is an integer - type that is a count of nanoseconds -- except for obsolescent hosts - without sufficiently-wide integers, where it is a count of - seconds. */ -#if HAVE_LONG_LONG_INT + type that is a count of nanoseconds. */ typedef long long int xtime_t; -# define XTIME_PRECISION 1000000000 -#else -# include -typedef long int xtime_t; -# if LONG_MAX >> 31 >> 31 == 0 -# define XTIME_PRECISION 1 -# else -# define XTIME_PRECISION 1000000000 -# endif -#endif +#define XTIME_PRECISION 1000000000 #ifdef __cplusplus extern "C" { #endif /* Return an extended time value that contains S seconds and NS - nanoseconds. */ + nanoseconds. S and NS should be nonnegative; otherwise, integer + overflow can occur even if the result is in range. */ XTIME_INLINE xtime_t xtime_make (xtime_t s, long int ns) { - const long int giga = 1000 * 1000 * 1000; - s += ns / giga; - ns %= giga; - if (XTIME_PRECISION == 1) - return s; - else - return XTIME_PRECISION * s + ns; + return XTIME_PRECISION * s + ns; } +/* The following functions split an extended time value: + T = XTIME_PRECISION * xtime_sec (T) + xtime_nsec (T) + with 0 <= xtime_nsec (T) < XTIME_PRECISION. */ + /* Return the number of seconds in T, which must be nonnegative. */ XTIME_INLINE xtime_t xtime_nonnegative_sec (xtime_t t) @@ -74,11 +61,7 @@ xtime_nonnegative_sec (xtime_t t) XTIME_INLINE xtime_t xtime_sec (xtime_t t) { - return (XTIME_PRECISION == 1 - ? t - : t < 0 - ? (t + XTIME_PRECISION - 1) / XTIME_PRECISION - 1 - : xtime_nonnegative_sec (t)); + return (t + (t < 0)) / XTIME_PRECISION - (t < 0); } /* Return the number of nanoseconds in T, which must be nonnegative. */ diff --git a/contrib/tools/bison/lib/ya.make b/contrib/tools/bison/lib/ya.make index 4d6afb692a26..41aec50a8718 100644 --- a/contrib/tools/bison/lib/ya.make +++ b/contrib/tools/bison/lib/ya.make @@ -16,6 +16,7 @@ NO_COMPILER_WARNINGS() NO_RUNTIME() CFLAGS( + -DDEFAULT_TEXT_DOMAIN=\"bison-gnulib\" -DEXEEXT=\"\" ) @@ -24,6 +25,7 @@ SRCS( areadlink.c argmatch.c asnprintf.c + asprintf.c basename-lgpl.c basename.c binary-io.c @@ -53,16 +55,22 @@ SRCS( fd-safer.c fopen-safer.c fseterr.c + fstrcmp.c get-errno.c gethrxtime.c getprogname.c gl_array_list.c gl_list.c gl_xlist.c + glthread/lock.c + glthread/threadlib.c + glthread/tls.c hard-locale.c hash.c localcharset.c math.c + mbchar.c + mbfile.c mbrtowc.c mbswidth.c path-join.c @@ -75,6 +83,7 @@ SRCS( printf-parse.c progname.c quotearg.c + setlocale_null.c sig-handler.c spawn-pipe.c stripslash.c @@ -83,10 +92,12 @@ SRCS( unistd.c uniwidth/width.c vasnprintf.c + vasprintf.c wait-process.c wctype-h.c xalloc-die.c xconcat-filename.c + xhash.c xmalloc.c xmemdup0.c xreadlink.c @@ -130,6 +141,11 @@ ELSEIF (OS_WINDOWS) strverscmp.c waitpid.c wcwidth.c + windows-mutex.c + windows-once.c + windows-recmutex.c + windows-rwlock.c + windows-tls.c ) ENDIF() diff --git a/contrib/tools/bison/src/AnnotationList.c b/contrib/tools/bison/src/AnnotationList.c index 4e29127c5760..f7ef09297178 100644 --- a/contrib/tools/bison/src/AnnotationList.c +++ b/contrib/tools/bison/src/AnnotationList.c @@ -1,6 +1,6 @@ /* IELR's inadequacy annotation list. - Copyright (C) 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -269,7 +269,7 @@ AnnotationList__computePredecessorAnnotations ( if (item_number_is_rule_number (ritem[s->items[self_item] - 2])) { - unsigned rulei; + int rulei; for (rulei = s->items[self_item]; !item_number_is_rule_number (ritem[rulei]); ++rulei) diff --git a/contrib/tools/bison/src/AnnotationList.h b/contrib/tools/bison/src/AnnotationList.h index ef3eeb6b0fa0..d5258a57d368 100644 --- a/contrib/tools/bison/src/AnnotationList.h +++ b/contrib/tools/bison/src/AnnotationList.h @@ -1,6 +1,6 @@ /* IELR's inadequacy annotation list. - Copyright (C) 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -25,7 +25,7 @@ # include "InadequacyList.h" # include "state.h" -typedef unsigned AnnotationIndex; +typedef int AnnotationIndex; /** * A node in a list of annotations on a particular LR(0) state. Each diff --git a/contrib/tools/bison/src/InadequacyList.c b/contrib/tools/bison/src/InadequacyList.c index 6caa14ea2f5e..6d7f19224eb0 100644 --- a/contrib/tools/bison/src/InadequacyList.c +++ b/contrib/tools/bison/src/InadequacyList.c @@ -1,6 +1,6 @@ /* IELR's inadequacy list. - Copyright (C) 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -22,6 +22,8 @@ #include "InadequacyList.h" +#include + ContributionIndex const ContributionIndex__none = -1; ContributionIndex const ContributionIndex__error_action = -2; @@ -31,8 +33,11 @@ InadequacyList__new_conflict (state *manifesting_state, symbol *token, InadequacyListNodeCount *node_count) { InadequacyList *result = xmalloc (sizeof *result); - result->id = (*node_count)++; - aver (*node_count != 0); + result->id = *node_count; + IGNORE_TYPE_LIMITS_BEGIN + if (INT_ADD_WRAPV (*node_count, 1, node_count)) + aver (false); + IGNORE_TYPE_LIMITS_END result->next = NULL; result->manifestingState = manifesting_state; result->contributionCount = bitset_count (actions); diff --git a/contrib/tools/bison/src/InadequacyList.h b/contrib/tools/bison/src/InadequacyList.h index bb52f7ae8498..317d9d5a5201 100644 --- a/contrib/tools/bison/src/InadequacyList.h +++ b/contrib/tools/bison/src/InadequacyList.h @@ -1,6 +1,6 @@ /* IELR's inadequacy list. - Copyright (C) 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -27,11 +27,8 @@ /** * A unique ID assigned to every \c InadequacyList node. - * - * This must remain unsigned so that the overflow check in - * \c InadequacyList__new_conflict works properly. */ -typedef unsigned long long InadequacyListNodeCount; +typedef long long InadequacyListNodeCount; /** * For a conflict, each rule in the grammar can have at most one contributing diff --git a/contrib/tools/bison/src/Sbitset.c b/contrib/tools/bison/src/Sbitset.c index aaa6819be06b..3b1651032286 100644 --- a/contrib/tools/bison/src/Sbitset.c +++ b/contrib/tools/bison/src/Sbitset.c @@ -1,6 +1,6 @@ /* A simple, memory-efficient bitset implementation. - Copyright (C) 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/src/Sbitset.h b/contrib/tools/bison/src/Sbitset.h index fc6347aa24e5..997dab2feac7 100644 --- a/contrib/tools/bison/src/Sbitset.h +++ b/contrib/tools/bison/src/Sbitset.h @@ -1,6 +1,6 @@ /* A simple, memory-efficient bitset implementation. - Copyright (C) 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/src/assoc.c b/contrib/tools/bison/src/assoc.c index fc1f937fb754..0c3de26fd5ae 100644 --- a/contrib/tools/bison/src/assoc.c +++ b/contrib/tools/bison/src/assoc.c @@ -1,6 +1,6 @@ /* Associativity information. - Copyright (C) 2002, 2005-2006, 2008-2015, 2018-2019 Free Software + Copyright (C) 2002, 2005-2006, 2008-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -29,9 +29,6 @@ assoc_to_string (assoc a) { switch (a) { - default: - abort (); - case undef_assoc: return "undefined associativity"; @@ -47,4 +44,5 @@ assoc_to_string (assoc a) case precedence_assoc: return "%precedence"; } + abort (); } diff --git a/contrib/tools/bison/src/assoc.h b/contrib/tools/bison/src/assoc.h index 680e2fbcc652..9fdbb466f31e 100644 --- a/contrib/tools/bison/src/assoc.h +++ b/contrib/tools/bison/src/assoc.h @@ -1,6 +1,6 @@ /* Associativity information. - Copyright (C) 2002, 2006, 2008-2015, 2018-2019 Free Software + Copyright (C) 2002, 2006, 2008-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/src/closure.c b/contrib/tools/bison/src/closure.c index 16be6452297d..5a93ded7296f 100644 --- a/contrib/tools/bison/src/closure.c +++ b/contrib/tools/bison/src/closure.c @@ -1,7 +1,7 @@ /* Closures for Bison Copyright (C) 1984, 1989, 2000-2002, 2004-2005, 2007, 2009-2015, - 2018-2019 Free Software Foundation, Inc. + 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -35,6 +35,9 @@ item_number *itemset; size_t nitemset; +/* RULESET contains a bit for each rule. CLOSURE sets the bits for + all rules which could potentially describe the next input to be + read. */ static bitset ruleset; /* internal data. See comments before set_fderives and set_firsts. */ @@ -51,7 +54,7 @@ static bitsetv firsts = NULL; `-----------------*/ static void -print_closure (char const *title, item_number const *array, size_t size) +closure_print (char const *title, item_number const *array, size_t size) { fprintf (stderr, "Closure: %s\n", title); for (size_t i = 0; i < size; ++i) @@ -167,7 +170,7 @@ set_fderives (void) void -new_closure (unsigned n) +closure_new (int n) { itemset = xnmalloc (n, sizeof *itemset); @@ -181,8 +184,8 @@ new_closure (unsigned n) void closure (item_number const *core, size_t n) { - if (trace_flag & trace_sets) - print_closure ("input", core, n); + if (trace_flag & trace_closure) + closure_print ("input", core, n); bitset_zero (ruleset); @@ -192,12 +195,12 @@ closure (item_number const *core, size_t n) /* core is sorted on item index in ritem, which is sorted on rule number. Compute itemset with the same sort. */ + nitemset = 0; + size_t c = 0; + /* A bit index over RULESET. */ rule_number ruleno; bitset_iterator iter; - - nitemset = 0; - size_t c = 0; BITSET_FOR_EACH (iter, ruleset, ruleno, 0) { item_number itemno = rules[ruleno].rhs - ritem; @@ -218,13 +221,13 @@ closure (item_number const *core, size_t n) c++; } - if (trace_flag & trace_sets) - print_closure ("output", itemset, nitemset); + if (trace_flag & trace_closure) + closure_print ("output", itemset, nitemset); } void -free_closure (void) +closure_free (void) { free (itemset); bitset_free (ruleset); diff --git a/contrib/tools/bison/src/closure.h b/contrib/tools/bison/src/closure.h index c75b8497e5a7..21d6ba196e94 100644 --- a/contrib/tools/bison/src/closure.h +++ b/contrib/tools/bison/src/closure.h @@ -1,6 +1,6 @@ /* Subroutines for bison - Copyright (C) 1984, 1989, 2000-2002, 2007, 2009-2015, 2018-2019 Free + Copyright (C) 1984, 1989, 2000-2002, 2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -27,29 +27,26 @@ data so that closure can be called. n is the number of elements to allocate for itemset. */ -void new_closure (unsigned n); +void closure_new (int n); /* Given the kernel (aka core) of a state (a sorted vector of item numbers ITEMS, of length N), set up RULESET and ITEMSET to indicate what rules could be run and which items could be accepted when those - items are the active ones. + items are the active ones. */ - RULESET contains a bit for each rule. CLOSURE sets the bits for - all rules which could potentially describe the next input to be - read. +void closure (item_number const *items, size_t n); - ITEMSET is a sorted vector of item numbers; NITEMSET is its size - (actually, points to just beyond the end of the part of it that is - significant). CLOSURE places there the indices of all items which - represent units of input that could arrive next. */ -void closure (item_number const *items, size_t n); +/* Free ITEMSET, RULESET and internal data. */ +void closure_free (void); -/* Frees ITEMSET, RULESET and internal data. */ -void free_closure (void); +/* ITEMSET is a sorted vector of item numbers; NITEMSET is its size + (actually, points to just beyond the end of the part of it that is + significant). CLOSURE places there the indices of all items which + represent units of input that could arrive next. */ extern item_number *itemset; extern size_t nitemset; diff --git a/contrib/tools/bison/src/complain.c b/contrib/tools/bison/src/complain.c index 50f65af54cef..f15c6b8bd14b 100644 --- a/contrib/tools/bison/src/complain.c +++ b/contrib/tools/bison/src/complain.c @@ -1,6 +1,6 @@ /* Declaration for error-reporting function for Bison. - Copyright (C) 2000-2002, 2004-2006, 2009-2015, 2018-2019 Free + Copyright (C) 2000-2002, 2004-2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -23,8 +23,10 @@ #include "system.h" #include -#include #include +#include +#include +#include #include "complain.h" #include "files.h" @@ -39,9 +41,9 @@ bool warnings_are_errors = false; /** Whether -Werror/-Wno-error was applied to a warning. */ typedef enum { - errority_unset = 0, /** No explict status. */ - errority_disabled = 1, /** Explictly disabled with -Wno-error=foo. */ - errority_enabled = 2 /** Explictly enabled with -Werror=foo. */ + errority_unset = 0, /** No explicit status. */ + errority_disabled = 1, /** Explicitly disabled with -Wno-error=foo. */ + errority_enabled = 2 /** Explicitly enabled with -Werror=foo. */ } errority; /** For each warning type, its errority. */ @@ -61,52 +63,105 @@ typedef enum /** For each warning type, its severity. */ static severity warnings_flag[warnings_size]; -static unsigned *indent_ptr = 0; +styled_ostream_t errstream = NULL; + +void +begin_use_class (const char *s, FILE *out) +{ + if (out == stderr) + { + if (color_debug) + fprintf (out, "<%s>", s); + else + { + styled_ostream_begin_use_class (errstream, s); + styled_ostream_flush_to_current_style (errstream); + } + } +} + +void +end_use_class (const char *s, FILE *out) +{ + if (out == stderr) + { + if (color_debug) + fprintf (out, "", s); + else + { + styled_ostream_end_use_class (errstream, s); + styled_ostream_flush_to_current_style (errstream); + } + } +} + +void +flush (FILE *out) +{ + if (out == stderr) + ostream_flush (errstream, FLUSH_THIS_STREAM); + fflush (out); +} /*------------------------. | --warnings's handling. | `------------------------*/ -static const char * const warnings_args[] = +ARGMATCH_DEFINE_GROUP (warning, warnings) + +static const argmatch_warning_doc argmatch_warning_docs[] = { - "none", - "midrule-values", - "yacc", - "conflicts-sr", - "conflicts-rr", - "deprecated", - "empty-rule", - "precedence", - "other", - "all", - "error", - "everything", - 0 + { "conflicts-sr", N_("S/R conflicts (enabled by default)") }, + { "conflicts-rr", N_("R/R conflicts (enabled by default)") }, + { "dangling-alias", N_("string aliases not attached to a symbol") }, + { "deprecated", N_("obsolete constructs") }, + { "empty-rule", N_("empty rules without %empty") }, + { "midrule-values", N_("unset or unused midrule values") }, + { "precedence", N_("useless precedence and associativity") }, + { "yacc", N_("incompatibilities with POSIX Yacc") }, + { "other", N_("all other warnings (enabled by default)") }, + { "all", N_("all the warnings except 'dangling-alias' and 'yacc'") }, + { "no-CATEGORY", N_("turn off warnings in CATEGORY") }, + { "none", N_("turn off all the warnings") }, + { "error[=CATEGORY]", N_("treat warnings as errors") }, + { NULL, NULL } }; -static const warnings warnings_types[] = +static const argmatch_warning_arg argmatch_warning_args[] = { - Wnone, - Wmidrule_values, - Wyacc, - Wconflicts_sr, - Wconflicts_rr, - Wdeprecated, - Wempty_rule, - Wprecedence, - Wother, - Wall, - Werror, - Weverything + { "all", Wall }, + { "conflicts-rr", Wconflicts_rr }, + { "conflicts-sr", Wconflicts_sr }, + { "dangling-alias", Wdangling_alias }, + { "deprecated", Wdeprecated }, + { "empty-rule", Wempty_rule }, + { "everything", Weverything }, + { "midrule-values", Wmidrule_values }, + { "none", Wnone }, + { "other", Wother }, + { "precedence", Wprecedence }, + { "yacc", Wyacc }, + { NULL, Wnone } }; -ARGMATCH_VERIFY (warnings_args, warnings_types); +const argmatch_warning_group_type argmatch_warning_group = +{ + argmatch_warning_args, + argmatch_warning_docs, + N_("Warning categories include:"), + NULL +}; + +void +warning_usage (FILE *out) +{ + argmatch_warning_usage (out); +} void warning_argmatch (char const *arg, size_t no, size_t err) { - int value = XARGMATCH ("--warning", arg + no + err, - warnings_args, warnings_types); + int value = *argmatch_warning_value ("--warning", arg + no + err); /* -Wnone == -Wno-everything, and -Wno-none == -Weverything. */ if (!value) @@ -145,7 +200,14 @@ warning_argmatch (char const *arg, size_t no, size_t err) void warnings_argmatch (char *args) { - if (args) + if (!args) + warning_argmatch ("all", 0, 0); + else if (STREQ (args, "help")) + { + warning_usage (stdout); + exit (EXIT_SUCCESS); + } + else for (args = strtok (args, ","); args; args = strtok (NULL, ",")) if (STREQ (args, "error")) warnings_are_errors = true; @@ -161,8 +223,43 @@ warnings_argmatch (char *args) warning_argmatch (args, no, err); } - else - warning_argmatch ("all", 0, 0); +} + +/* Color style for this type of message. */ +static const char* +severity_style (severity s) +{ + switch (s) + { + case severity_disabled: + case severity_unset: + return "note"; + case severity_warning: + return "warning"; + case severity_error: + case severity_fatal: + return "error"; + } + abort (); +} + +/* Prefix for this type of message. */ +static const char* +severity_prefix (severity s) +{ + switch (s) + { + case severity_disabled: + case severity_unset: + return ""; + case severity_warning: + return _("warning"); + case severity_error: + return _("error"); + case severity_fatal: + return _("fatal error"); + } + abort (); } @@ -170,9 +267,53 @@ warnings_argmatch (char *args) | complain. | `-----------*/ +void +complain_init_color (void) +{ +#if HAVE_LIBTEXTSTYLE + if (color_mode == color_yes + || color_mode == color_html + || (color_mode == color_tty && isatty (STDERR_FILENO))) + { + style_file_prepare ("BISON_STYLE", "BISON_STYLEDIR", pkgdatadir (), + "bison-default.css"); + /* As a fallback, use the default in the current directory. */ + struct stat statbuf; + if ((style_file_name == NULL || stat (style_file_name, &statbuf) < 0) + && stat ("bison-default.css", &statbuf) == 0) + style_file_name = "bison-default.css"; + } + else + /* No styling. */ + style_file_name = NULL; +#endif + + /* Workaround clang's warning (starting at Clang 3.5) about the stub + code of html_styled_ostream_create: + + | src/complain.c:274:7: error: code will never be executed [-Werror,-Wunreachable-code] + | ? html_styled_ostream_create (file_ostream_create (stderr), + | ^~~~~~~~~~~~~~~~~~~~~~~~~~ */ +#if defined __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunreachable-code" +#endif + errstream = + color_mode == color_html + ? html_styled_ostream_create (file_ostream_create (stderr), + style_file_name) + : styled_ostream_create (STDERR_FILENO, "(stderr)", TTYCTL_AUTO, + style_file_name); +#if defined __clang__ +# pragma clang diagnostic pop +#endif +} + void complain_init (void) { + caret_init (); + warnings warnings_default = Wconflicts_sr | Wconflicts_rr | Wdeprecated | Wother; @@ -185,6 +326,12 @@ complain_init (void) } } +void +complain_free (void) +{ + caret_free (); + styled_ostream_free (errstream); +} /* A diagnostic with FLAGS is about to be issued. With what severity? (severity_fatal, severity_error, severity_disabled, or @@ -229,19 +376,31 @@ warning_is_unset (warnings flags) return true; } -/** Display a "[-Wyacc]" like message on \a f. */ +bool +warning_is_enabled (warnings flags) +{ + return severity_warning <= warning_severity (flags); +} + +/** Display a "[-Wyacc]" like message on \a out. */ static void -warnings_print_categories (warnings warn_flags, FILE *f) +warnings_print_categories (warnings warn_flags, FILE *out) { - /* Display only the first match, the second is "-Wall". */ - for (size_t i = 0; warnings_args[i]; ++i) - if (warn_flags & warnings_types[i]) + for (int wbit = 0; wbit < warnings_size; ++wbit) + if (warn_flags & (1 << wbit)) { - severity s = warning_severity (warnings_types[i]); - fprintf (f, " [-W%s%s]", + warnings w = 1 << wbit; + severity s = warning_severity (w); + const char* style = severity_style (s); + fputs (" [", out); + begin_use_class (style, out); + fprintf (out, "-W%s%s", s == severity_error ? "error=" : "", - warnings_args[i]); + argmatch_warning_argument (&w)); + end_use_class (style, out); + fputc (']', out); + /* Display only the first match, the second is "-Wall". */ return; } } @@ -250,8 +409,10 @@ warnings_print_categories (warnings warn_flags, FILE *f) * * \param loc the location, defaulting to the current file, * or the program name. + * \param indent optional indentation for the error message. * \param flags the category for this message. - * \param prefix put before the message (e.g., "warning"). + * \param sever to decide the prefix to put before the message + * (e.g., "warning"). * \param message the error message, a printf format string. Iff it * ends with ": ", then no trailing newline is printed, * and the caller should print the remaining @@ -260,35 +421,41 @@ warnings_print_categories (warnings warn_flags, FILE *f) */ static void -error_message (const location *loc, warnings flags, const char *prefix, - const char *message, va_list args) +error_message (const location *loc, int *indent, warnings flags, + severity sever, const char *message, va_list args) { - unsigned pos = 0; + int pos = 0; if (loc) pos += location_print (*loc, stderr); else - pos += fprintf (stderr, "%s", current_file ? current_file : program_name); + pos += fprintf (stderr, "%s", grammar_file ? grammar_file : program_name); pos += fprintf (stderr, ": "); - if (indent_ptr) + if (indent) { - if (*indent_ptr) - prefix = NULL; - if (!*indent_ptr) - *indent_ptr = pos; - else if (*indent_ptr > pos) - fprintf (stderr, "%*s", *indent_ptr - pos, ""); - indent_ptr = NULL; + if (*indent) + sever = severity_disabled; + if (!*indent) + *indent = pos; + else if (*indent > pos) + fprintf (stderr, "%*s", *indent - pos, ""); } - if (prefix) - fprintf (stderr, "%s: ", prefix); + const char* style = severity_style (sever); + + if (sever != severity_disabled) + { + begin_use_class (style, stderr); + fprintf (stderr, "%s:", severity_prefix (sever)); + end_use_class (style, stderr); + fputc (' ', stderr); + } vfprintf (stderr, message, args); /* Print the type of warning, only if this is not a sub message (in which case the prefix is null). */ - if (! (flags & silent) && prefix) + if (! (flags & silent) && sever != severity_disabled) warnings_print_categories (flags, stderr); { @@ -296,20 +463,19 @@ error_message (const location *loc, warnings flags, const char *prefix, if (l < 2 || message[l - 2] != ':' || message[l - 1] != ' ') { putc ('\n', stderr); - fflush (stderr); + flush (stderr); if (loc && feature_flag & feature_caret && !(flags & no_caret)) - location_caret (*loc, stderr); + location_caret (*loc, style, stderr); } } - fflush (stderr); + flush (stderr); } -/** Raise a complaint. That can be a fatal error, an error or just a - warning. */ +/** Raise a complaint (fatal error, error or just warning). */ static void -complains (const location *loc, warnings flags, const char *message, - va_list args) +complains (const location *loc, int *indent, warnings flags, + const char *message, va_list args) { severity s = warning_severity (flags); if ((flags & complaint) && complaint_status < status_complaint) @@ -317,13 +483,9 @@ complains (const location *loc, warnings flags, const char *message, if (severity_warning <= s) { - const char* prefix = - s == severity_fatal ? _("fatal error") - : s == severity_error ? _("error") - : _("warning"); if (severity_error <= s && ! complaint_status) complaint_status = status_warning_as_error; - error_message (loc, flags, prefix, message, args); + error_message (loc, indent, flags, s, message, args); } if (flags & fatal) @@ -335,23 +497,22 @@ complain (location const *loc, warnings flags, const char *message, ...) { va_list args; va_start (args, message); - complains (loc, flags, message, args); + complains (loc, NULL, flags, message, args); va_end (args); } void -complain_indent (location const *loc, warnings flags, unsigned *indent, +complain_indent (location const *loc, warnings flags, int *indent, const char *message, ...) { va_list args; - indent_ptr = indent; va_start (args, message); - complains (loc, flags, message, args); + complains (loc, indent, flags, message, args); va_end (args); } void -complain_args (location const *loc, warnings w, unsigned *indent, +complain_args (location const *loc, warnings w, int *indent, int argc, char *argv[]) { switch (argc) @@ -389,24 +550,23 @@ bison_directive (location const *loc, char const *directive) void deprecated_directive (location const *loc, char const *old, char const *upd) { - if (feature_flag & feature_caret) - complain (loc, Wdeprecated, - _("deprecated directive, use %s"), - quote_n (1, upd)); - else - complain (loc, Wdeprecated, - _("deprecated directive: %s, use %s"), - quote (old), quote_n (1, upd)); - /* Register updates only if -Wdeprecated is enabled. */ - if (warnings_flag[warning_deprecated] != severity_disabled) - fixits_register (loc, upd); + if (warning_is_enabled (Wdeprecated)) + { + complain (loc, Wdeprecated, + _("deprecated directive: %s, use %s"), + quote (old), quote_n (1, upd)); + if (feature_flag & feature_caret) + location_caret_suggestion (*loc, upd, stderr); + /* Register updates only if -Wdeprecated is enabled. */ + fixits_register (loc, upd); + } } void duplicate_directive (char const *directive, location first, location second) { - unsigned i = 0; + int i = 0; if (feature_flag & feature_caret) complain_indent (&second, Wother, &i, _("duplicate directive")); else @@ -420,7 +580,7 @@ void duplicate_rule_directive (char const *directive, location first, location second) { - unsigned i = 0; + int i = 0; complain_indent (&second, complaint, &i, _("only one %s allowed per rule"), directive); i += SUB_INDENT; diff --git a/contrib/tools/bison/src/complain.h b/contrib/tools/bison/src/complain.h index 266992f6f461..9cb6a60657a4 100644 --- a/contrib/tools/bison/src/complain.h +++ b/contrib/tools/bison/src/complain.h @@ -1,6 +1,6 @@ /* Declaration for error-reporting function for Bison. - Copyright (C) 2000-2002, 2006, 2009-2015, 2018-2019 Free Software + Copyright (C) 2000-2002, 2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -24,6 +24,20 @@ /* Sub-messages indent. */ # define SUB_INDENT (4) +/*---------------. +| Error stream. | +`---------------*/ + +/** Enable a style on \a out provided it's stderr. */ +void begin_use_class (const char *style, FILE *out); + +/** Disable a style on \a out provided it's stderr. */ +void end_use_class (const char *style, FILE *out); + +/** Flush \a out. */ +void flush (FILE *out); + + /*-------------. | --warnings. | `-------------*/ @@ -31,14 +45,15 @@ /** The bits assigned to each warning type. */ typedef enum { - warning_midrule_values, /**< Unset or unused midrule values. */ + warning_conflicts_rr, + warning_conflicts_sr, + warning_dangling_alias, + warning_deprecated, + warning_empty_rule, + warning_midrule_values, + warning_other, + warning_precedence, warning_yacc, /**< POSIXME. */ - warning_conflicts_sr, /**< S/R conflicts. */ - warning_conflicts_rr, /**< R/R conflicts. */ - warning_empty_rule, /**< Implicitly empty rules. */ - warning_deprecated, /**< Obsolete constructs. */ - warning_precedence, /**< Useless precedence and associativity. */ - warning_other, /**< All other warnings. */ warnings_size /**< The number of warnings. Must be last. */ } warning_bit; @@ -46,6 +61,9 @@ typedef enum /** Whether -Werror was set. */ extern bool warnings_are_errors; +/** Document --warning arguments. */ +void warning_usage (FILE *out); + /** Decode a single argument from -W. * * \param arg the subarguments to decode. @@ -76,20 +94,26 @@ void warnings_argmatch (char *args); /** Initialize this module. */ void complain_init (void); +/** Reclaim resources. */ +void complain_free (void); + +/** Initialize support for colored messages. */ +void complain_init_color (void); + +/** Flags passed to diagnostics functions. */ typedef enum { Wnone = 0, /**< Issue no warnings. */ - Wmidrule_values = 1 << warning_midrule_values, - Wyacc = 1 << warning_yacc, - Wconflicts_sr = 1 << warning_conflicts_sr, Wconflicts_rr = 1 << warning_conflicts_rr, + Wconflicts_sr = 1 << warning_conflicts_sr, + Wdangling_alias = 1 << warning_dangling_alias, Wdeprecated = 1 << warning_deprecated, Wempty_rule = 1 << warning_empty_rule, - Wprecedence = 1 << warning_precedence, + Wmidrule_values = 1 << warning_midrule_values, Wother = 1 << warning_other, - - Werror = 1 << 10, /** This bit is no longer used. */ + Wprecedence = 1 << warning_precedence, + Wyacc = 1 << warning_yacc, complaint = 1 << 11, /**< All complaints. */ fatal = 1 << 12, /**< All fatal errors. */ @@ -98,23 +122,26 @@ typedef enum /**< All above warnings. */ Weverything = ~complaint & ~fatal & ~silent, - Wall = Weverything & ~Wyacc + Wall = Weverything & ~Wdangling_alias & ~Wyacc } warnings; /** Whether the warnings of \a flags are all unset. (Never enabled, never disabled). */ bool warning_is_unset (warnings flags); +/** Whether warnings of \a flags should be reported. */ +bool warning_is_enabled (warnings flags); + /** Make a complaint, with maybe a location. */ void complain (location const *loc, warnings flags, char const *message, ...) __attribute__ ((__format__ (__printf__, 3, 4))); /** Likewise, but with an \a argc/argv interface. */ -void complain_args (location const *loc, warnings w, unsigned *indent, +void complain_args (location const *loc, warnings w, int *indent, int argc, char *arg[]); /** Make a complaint with location and some indentation. */ -void complain_indent (location const *loc, warnings flags, unsigned *indent, +void complain_indent (location const *loc, warnings flags, int *indent, char const *message, ...) __attribute__ ((__format__ (__printf__, 4, 5))); diff --git a/contrib/tools/bison/src/conflicts.c b/contrib/tools/bison/src/conflicts.c index f81d8318645b..5ecd7d17476a 100644 --- a/contrib/tools/bison/src/conflicts.c +++ b/contrib/tools/bison/src/conflicts.c @@ -1,6 +1,6 @@ /* Find and resolve or report lookahead conflicts for bison, - Copyright (C) 1984, 1989, 1992, 2000-2015, 2018-2019 Free Software + Copyright (C) 1984, 1989, 1992, 2000-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -23,13 +23,13 @@ #include -#include "LR0.h" #include "complain.h" #include "conflicts.h" #include "files.h" #include "getargs.h" #include "gram.h" #include "lalr.h" +#include "lr0.h" #include "print-xml.h" #include "reader.h" #include "state.h" @@ -38,7 +38,10 @@ /* -1 stands for not specified. */ int expected_sr_conflicts = -1; int expected_rr_conflicts = -1; -static char *conflicts; + +/* CONFLICTS[STATE-NUM] -- Whether that state has unresolved conflicts. */ +static bool *conflicts; + static struct obstack solved_conflicts_obstack; static struct obstack solved_conflicts_xml_obstack; @@ -73,8 +76,9 @@ log_resolution (rule *r, symbol_number token, { case shift_resolution: case right_resolution: + obstack_sgrow (&solved_conflicts_obstack, " "); obstack_printf (&solved_conflicts_obstack, - _(" Conflict between rule %d and token %s" + _("Conflict between rule %d and token %s" " resolved as shift"), r->number, symbols[token]->tag); @@ -82,16 +86,18 @@ log_resolution (rule *r, symbol_number token, case reduce_resolution: case left_resolution: + obstack_sgrow (&solved_conflicts_obstack, " "); obstack_printf (&solved_conflicts_obstack, - _(" Conflict between rule %d and token %s" + _("Conflict between rule %d and token %s" " resolved as reduce"), r->number, symbols[token]->tag); break; case nonassoc_resolution: + obstack_sgrow (&solved_conflicts_obstack, " "); obstack_printf (&solved_conflicts_obstack, - _(" Conflict between rule %d and token %s" + _("Conflict between rule %d and token %s" " resolved as an error"), r->number, symbols[token]->tag); @@ -369,13 +375,16 @@ set_conflicts (state *s, symbol **errors) s->solved_conflicts_xml = obstack_finish0 (&solved_conflicts_xml_obstack); /* Loop over all rules which require lookahead in this state. Check - for conflicts not resolved above. */ - for (int i = 0; i < reds->num; ++i) - { - if (!bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set)) - conflicts[s->number] = 1; - bitset_or (lookahead_set, lookahead_set, reds->lookahead_tokens[i]); - } + for conflicts not resolved above. + + reds->lookahead_tokens can be NULL if the LR type is LR(0). */ + if (reds->lookahead_tokens) + for (int i = 0; i < reds->num; ++i) + { + if (!bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set)) + conflicts[s->number] = true; + bitset_or (lookahead_set, lookahead_set, reds->lookahead_tokens[i]); + } } @@ -425,7 +434,7 @@ conflicts_update_state_numbers (state_number old_to_new[], `---------------------------------------------*/ static size_t -count_state_sr_conflicts (state *s) +count_state_sr_conflicts (const state *s) { transitions *trans = s->transitions; reductions *reds = s->reductions; @@ -473,7 +482,7 @@ count_sr_conflicts (void) `-----------------------------------------------------------------*/ static size_t -count_state_rr_conflicts (state *s) +count_state_rr_conflicts (const state *s) { reductions *reds = s->reductions; size_t res = 0; @@ -585,24 +594,22 @@ conflicts_output (FILE *out) { bool printed_sth = false; for (state_number i = 0; i < nstates; ++i) - { - state *s = states[i]; - if (conflicts[i]) - { - int src = count_state_sr_conflicts (s); - int rrc = count_state_rr_conflicts (s); - fprintf (out, _("State %d "), i); - if (src && rrc) - fprintf (out, - _("conflicts: %d shift/reduce, %d reduce/reduce\n"), - src, rrc); - else if (src) - fprintf (out, _("conflicts: %d shift/reduce\n"), src); - else if (rrc) - fprintf (out, _("conflicts: %d reduce/reduce\n"), rrc); - printed_sth = true; - } - } + if (conflicts[i]) + { + const state *s = states[i]; + int src = count_state_sr_conflicts (s); + int rrc = count_state_rr_conflicts (s); + fprintf (out, _("State %d "), i); + if (src && rrc) + fprintf (out, + _("conflicts: %d shift/reduce, %d reduce/reduce\n"), + src, rrc); + else if (src) + fprintf (out, _("conflicts: %d shift/reduce\n"), src); + else if (rrc) + fprintf (out, _("conflicts: %d reduce/reduce\n"), rrc); + printed_sth = true; + } if (printed_sth) fputs ("\n\n", out); } diff --git a/contrib/tools/bison/src/conflicts.h b/contrib/tools/bison/src/conflicts.h index c068e36da96e..5b26efdefe09 100644 --- a/contrib/tools/bison/src/conflicts.h +++ b/contrib/tools/bison/src/conflicts.h @@ -1,6 +1,6 @@ /* Find and resolve or report lookahead conflicts for bison, - Copyright (C) 2000-2002, 2004, 2007, 2009-2015, 2018-2019 Free + Copyright (C) 2000-2002, 2004, 2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/src/derives.c b/contrib/tools/bison/src/derives.c index 7b7d5c94af39..c859a5e23d39 100644 --- a/contrib/tools/bison/src/derives.c +++ b/contrib/tools/bison/src/derives.c @@ -1,6 +1,6 @@ /* Match rules with nonterminals for bison, - Copyright (C) 1984, 1989, 2000-2003, 2005, 2009-2015, 2018-2019 Free + Copyright (C) 1984, 1989, 2000-2003, 2005, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -40,15 +40,12 @@ rule ***derives; static void print_derives (void) { - int i; - fputs ("DERIVES\n", stderr); - for (i = ntokens; i < nsyms; i++) + for (symbol_number i = ntokens; i < nsyms; ++i) { - rule **rp; fprintf (stderr, " %s derives\n", symbols[i]->tag); - for (rp = derives[i - ntokens]; *rp; ++rp) + for (rule **rp = derives[i - ntokens]; *rp; ++rp) { fprintf (stderr, " %3d ", (*rp)->user_number); rule_rhs_print (*rp, stderr); @@ -63,10 +60,6 @@ print_derives (void) void derives_compute (void) { - symbol_number i; - rule_number r; - rule **q; - /* DSET[NTERM - NTOKENS] -- A linked list of the numbers of the rules whose LHS is NTERM. */ rule_list **dset = xcalloc (nvars, sizeof *dset); @@ -76,7 +69,7 @@ derives_compute (void) indexed by rule numbers. */ rule_list *delts = xnmalloc (nrules, sizeof *delts); - for (r = nrules - 1; r >= 0; --r) + for (rule_number r = nrules - 1; r >= 0; --r) { symbol_number lhs = rules[r].lhs->number; rule_list *p = &delts[r]; @@ -90,9 +83,10 @@ derives_compute (void) it a single array. */ derives = xnmalloc (nvars, sizeof *derives); - q = xnmalloc (nvars + nrules, sizeof *q); + /* Q is the storage for DERIVES[...] (DERIVES[0] = q). */ + rule **q = xnmalloc (nvars + nrules, sizeof *q); - for (i = ntokens; i < nsyms; i++) + for (symbol_number i = ntokens; i < nsyms; ++i) { rule_list *p = dset[i - ntokens]; derives[i - ntokens] = q; @@ -115,6 +109,9 @@ derives_compute (void) void derives_free (void) { - free (derives[0]); - free (derives); + if (derives) + { + free (derives[0]); + free (derives); + } } diff --git a/contrib/tools/bison/src/derives.h b/contrib/tools/bison/src/derives.h index 521a10c60b0b..33430e6ff5ea 100644 --- a/contrib/tools/bison/src/derives.h +++ b/contrib/tools/bison/src/derives.h @@ -1,6 +1,6 @@ /* Match rules with nonterminals for bison, - Copyright (C) 1984, 1989, 2000-2002, 2009-2015, 2018-2019 Free + Copyright (C) 1984, 1989, 2000-2002, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/src/files.c b/contrib/tools/bison/src/files.c index 727a41af802c..8bc7a4da041f 100644 --- a/contrib/tools/bison/src/files.c +++ b/contrib/tools/bison/src/files.c @@ -1,6 +1,6 @@ /* Open and close files for Bison. - Copyright (C) 1984, 1986, 1989, 1992, 2000-2015, 2018-2019 Free + Copyright (C) 1984, 1986, 1989, 1992, 2000-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -21,11 +21,13 @@ #include #include "system.h" +#include /* PKGDATADIR */ #include #include #include #include #include +#include /* relocate2 */ #include #include @@ -49,7 +51,7 @@ location spec_name_prefix_loc = EMPTY_LOCATION_INIT; char *spec_verbose_file = NULL; /* for --verbose. */ char *spec_graph_file = NULL; /* for -g. */ char *spec_xml_file = NULL; /* for -x. */ -char *spec_defines_file = NULL; /* for --defines. */ +char *spec_header_file = NULL; /* for --defines. */ char *parser_file_name; /* All computed output file names. */ @@ -66,7 +68,6 @@ static generated_file *generated_files = NULL; static int generated_files_size = 0; uniqstr grammar_file = NULL; -uniqstr current_file = NULL; /* If --output=dir/foo.c was specified, DIR_PREFIX is 'dir/' and ALL_BUT_EXT and ALL_BUT_TAB_EXT are 'dir/foo'. @@ -343,14 +344,15 @@ compute_output_file_names (void) if (defines_flag) { - if (! spec_defines_file) - spec_defines_file = concat2 (all_but_ext, header_extension); + if (! spec_header_file) + spec_header_file = concat2 (all_but_ext, header_extension); } if (graph_flag) { if (! spec_graph_file) - spec_graph_file = concat2 (all_but_tab_ext, ".dot"); + spec_graph_file = concat2 (all_but_tab_ext, + 304 <= required_version ? ".gv" : ".dot"); output_file_name_check (&spec_graph_file, false); } @@ -414,6 +416,30 @@ unlink_generated_sources (void) unlink (generated_files[i].name); } +/* Memory allocated by relocate2, to free. */ +static char *relocate_buffer = NULL; + +#include "uniqstr.h" +#include +#define STR(a) XSTR(a) +#define XSTR(a) #a +char const * +pkgdatadir (void) +{ + const char* arc_path = getenv("ARCADIA_ROOT_DISTBUILD"); + if (arc_path == NULL) + arc_path = ArcadiaRoot(); + return uniqstr_concat(3, arc_path, "/", STR(BISON_DATA_DIR)); + + if (relocate_buffer) + return relocate_buffer; + else + { + char const *cp = getenv ("BISON_PKGDATADIR"); + return cp ? cp : relocate2 (PKGDATADIR, &relocate_buffer); + } +} + void output_file_names_free (void) { @@ -421,10 +447,11 @@ output_file_names_free (void) free (spec_verbose_file); free (spec_graph_file); free (spec_xml_file); - free (spec_defines_file); + free (spec_header_file); free (parser_file_name); free (dir_prefix); for (int i = 0; i < generated_files_size; i++) free (generated_files[i].name); free (generated_files); + free (relocate_buffer); } diff --git a/contrib/tools/bison/src/files.h b/contrib/tools/bison/src/files.h index d5ee44c274a3..00814ad05176 100644 --- a/contrib/tools/bison/src/files.h +++ b/contrib/tools/bison/src/files.h @@ -1,6 +1,6 @@ /* File names and variables for bison, - Copyright (C) 1984, 1989, 2000-2002, 2006-2007, 2009-2015, 2018-2019 + Copyright (C) 1984, 1989, 2000-2002, 2006-2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -48,7 +48,7 @@ extern char *spec_graph_file; extern char *spec_xml_file; /* File name specified with --defines. */ -extern char *spec_defines_file; +extern char *spec_header_file; /* Directory prefix of output file names. */ extern char *dir_prefix; @@ -58,12 +58,12 @@ extern char *dir_prefix; and therefore GCC warns about a name clash. */ extern uniqstr grammar_file; -/* The current file name. Might change with #line. */ -extern uniqstr current_file; - /* The computed base for output file names. */ extern char *all_but_ext; +/* Where our data files are installed. */ +char const *pkgdatadir (void); + void compute_output_file_names (void); void output_file_names_free (void); diff --git a/contrib/tools/bison/src/fixits.c b/contrib/tools/bison/src/fixits.c index 5ffd793524e7..37a0b7dd998a 100644 --- a/contrib/tools/bison/src/fixits.c +++ b/contrib/tools/bison/src/fixits.c @@ -1,6 +1,6 @@ /* Support for fixing grammar files. - Copyright (C) 2019 Free Software Foundation, Inc. + Copyright (C) 2019-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -52,6 +52,11 @@ fixit_new (location const *loc, char const* fix) return res; } +static int +fixit_cmp (const fixit *a, const fixit *b) +{ + return location_cmp (a->location, b->location); +} static void fixit_free (fixit *f) @@ -69,8 +74,8 @@ fixit_print (fixit const *f, FILE *out) { fprintf (out, "fix-it:%s:{%d:%d-%d:%d}:%s\n", quotearg_n_style (1, c_quoting_style, f->location.start.file), - f->location.start.line, f->location.start.column, - f->location.end.line, f->location.end.column, + f->location.start.line, f->location.start.byte, + f->location.end.line, f->location.end.byte, quotearg_n_style (2, c_quoting_style, f->fix)); } @@ -85,8 +90,8 @@ fixits_register (location const *loc, char const* fix) (gl_listelement_dispose_fn) fixit_free, true); fixit *f = fixit_new (loc, fix); - gl_list_add_last (fixits, f); - if (feature_flag & feature_fixit_parsable) + gl_sortedlist_add (fixits, (gl_listelement_compar_fn) fixit_cmp, f); + if (feature_flag & feature_fixit) fixit_print (f, stderr); } @@ -136,19 +141,29 @@ fixits_run (void) } putc (c, out); } + /* Look for the right offset. */ - while (offset < f->location.start.column) + bool need_eol = false; + while (offset < f->location.start.byte) { int c = getc (in); if (c == EOF) break; ++offset; - putc (c, out); + if (c == '\n') + /* The position we are asked for is beyond the actual + line: pad with spaces, and remember we need a \n. */ + need_eol = true; + putc (need_eol ? ' ' : c, out); } /* Paste the fix instead. */ fputs (f->fix, out); + /* Maybe install the eol afterwards. */ + if (need_eol) + putc ('\n', out); + /* Skip the bad input. */ while (line < f->location.end.line) { @@ -161,16 +176,17 @@ fixits_run (void) offset = 1; } } - while (offset < f->location.end.column) + while (offset < f->location.end.byte) { int c = getc (in); if (c == EOF) break; ++offset; } + /* If erasing the content of a full line, also remove the end-of-line. */ - if (f->fix[0] == 0 && f->location.start.column == 1) + if (f->fix[0] == 0 && f->location.start.byte == 1) { int c = getc (in); if (c == EOF) diff --git a/contrib/tools/bison/src/fixits.h b/contrib/tools/bison/src/fixits.h index 45c2780af8f5..f79217a3d322 100644 --- a/contrib/tools/bison/src/fixits.h +++ b/contrib/tools/bison/src/fixits.h @@ -1,6 +1,6 @@ /* Support for fixing grammar files. - Copyright (C) 2019 Free Software Foundation, Inc. + Copyright (C) 2019-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/contrib/tools/bison/src/flex-scanner.h b/contrib/tools/bison/src/flex-scanner.h index 9e4408f49dc1..6f6861741acd 100644 --- a/contrib/tools/bison/src/flex-scanner.h +++ b/contrib/tools/bison/src/flex-scanner.h @@ -1,6 +1,6 @@ /* Common parts between scan-code.l, scan-gram.l, and scan-skel.l. - Copyright (C) 2006, 2009-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/src/getargs.c b/contrib/tools/bison/src/getargs.c index 417e163c2aaf..6f19a4ea8cc5 100644 --- a/contrib/tools/bison/src/getargs.c +++ b/contrib/tools/bison/src/getargs.c @@ -1,6 +1,6 @@ /* Parse command line arguments for Bison. - Copyright (C) 1984, 1986, 1989, 1992, 2000-2015, 2018-2019 Free + Copyright (C) 1984, 1986, 1989, 1992, 2000-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -19,8 +19,9 @@ along with this program. If not, see . */ #include +#include "getargs.h" + #include "system.h" -#include "output.h" #include #include @@ -28,12 +29,13 @@ #include #include #include +#include +#include #include "complain.h" #include "files.h" -#include "getargs.h" #include "muscle-tab.h" -#include "quote.h" +#include "output.h" #include "uniqstr.h" bool defines_flag = false; @@ -43,6 +45,7 @@ bool no_lines_flag = false; bool token_table_flag = false; location yacc_loc = EMPTY_LOCATION_INIT; bool update_flag = false; /* for -u */ +bool color_debug = false; bool nondeterministic_parser = false; bool glr_parser = false; @@ -65,28 +68,28 @@ const char *skeleton = NULL; int language_prio = default_prio; struct bison_language const *language = &valid_languages[0]; +typedef int* (xargmatch_fn) (const char *context, const char *arg); + /** Decode an option's key. * - * \param opt option being decoded. - * \param keys array of valid subarguments. - * \param values array of corresponding (int) values. - * \param all the all value. - * \param flags the flags to update - * \param arg the subarguments to decode. - * If null, then activate all the flags. - * \param no length of the potential "no-" prefix. - * Can be 0 or 3. If 3, negate the action of the subargument. + * \param opt option being decoded. + * \param xargmatch matching function. + * \param all the value of the argument 'all'. + * \param flags the flags to update + * \param arg the subarguments to decode. + * If null, then activate all the flags. + * \param no length of the potential "no-" prefix. + * Can be 0 or 3. If 3, negate the action of the subargument. * * If VALUE != 0 then KEY sets flags and no-KEY clears them. * If VALUE == 0 then KEY clears all flags from \c all and no-KEY sets all * flags from \c all. Thus no-none = all and no-all = none. */ static void -flag_argmatch (const char *opt, - const char *const keys[], const int values[], +flag_argmatch (const char *opt, xargmatch_fn xargmatch, int all, int *flags, char *arg, size_t no) { - int value = XARGMATCH (opt, arg + no, keys, values); + int value = *xargmatch (opt, arg + no); /* -rnone == -rno-all, and -rno-none == -rall. */ if (!value) @@ -101,30 +104,38 @@ flag_argmatch (const char *opt, *flags |= value; } +typedef void (usage_fn) (FILE *out); + /** Decode an option's set of keys. * - * \param opt option being decoded (e.g., --report). - * \param keys array of valid subarguments. - * \param values array of corresponding (int) values. - * \param all the all value. - * \param flags the flags to update - * \param args comma separated list of effective subarguments to decode. - * If 0, then activate all the flags. + * \param opt option being decoded (e.g., --report). + * \param xargmatch matching function. + * \param usage function that implement --help for this option. + * \param all the value of the argument 'all'. + * \param flags the flags to update + * \param args comma separated list of effective subarguments to decode. + * If 0, then activate all the flags. */ static void flags_argmatch (const char *opt, - const char * const keys[], const int values[], + xargmatch_fn xargmatch, + usage_fn usage, int all, int *flags, char *args) { - if (args) + if (!args) + *flags |= all; + else if (STREQ (args, "help")) + { + usage (stdout); + exit (EXIT_SUCCESS); + } + else for (args = strtok (args, ","); args; args = strtok (NULL, ",")) { size_t no = STRPREFIX_LIT ("no-", args) ? 3 : 0; - flag_argmatch (opt, keys, - values, all, flags, args, no); + flag_argmatch (opt, xargmatch, + all, flags, args, no); } - else - *flags |= all; } @@ -139,110 +150,188 @@ flags_argmatch (const char *opt, * \arg FlagName_flag the flag to update. */ #define FLAGS_ARGMATCH(FlagName, Args, All) \ - flags_argmatch ("--" #FlagName, FlagName ## _args, FlagName ## _types, \ + flags_argmatch ("--" #FlagName, \ + (xargmatch_fn*) argmatch_## FlagName ## _value, \ + argmatch_## FlagName ## _usage, \ All, &FlagName ## _flag, Args) +/*---------------------. +| --color's handling. | +`---------------------*/ + +enum color + { + color_always, + color_never, + color_auto + }; + +ARGMATCH_DEFINE_GROUP (color, enum color) + +static const argmatch_color_doc argmatch_color_docs[] = +{ + { "always", N_("colorize the output") }, + { "never", N_("don't colorize the output") }, + { "auto", N_("colorize if the output device is a tty") }, + { NULL, NULL }, +}; + +static const argmatch_color_arg argmatch_color_args[] = +{ + { "always", color_always }, + { "yes", color_always }, + { "never", color_never }, + { "no", color_never }, + { "auto", color_auto }, + { "tty", color_auto }, + { NULL, color_always }, +}; + +const argmatch_color_group_type argmatch_color_group = +{ + argmatch_color_args, + argmatch_color_docs, + /* TRANSLATORS: Use the same translation for WHEN as in the + --color=WHEN help message. */ + N_("WHEN can be one of the following:"), + NULL +}; + /*----------------------. | --report's handling. | `----------------------*/ -static const char * const report_args[] = +ARGMATCH_DEFINE_GROUP (report, enum report) + +static const argmatch_report_doc argmatch_report_docs[] = { - /* In a series of synonyms, present the most meaningful first, so - that argmatch_valid be more readable. */ - "none", - "state", "states", - "itemset", "itemsets", - "lookahead", "lookaheads", "look-ahead", - "solved", - "all", - 0 + { "states", N_("describe the states") }, + { "itemsets", N_("complete the core item sets with their closure") }, + { "lookaheads", N_("explicitly associate lookahead tokens to items") }, + { "solved", N_("describe shift/reduce conflicts solving") }, + { "all", N_("include all the above information") }, + { "none", N_("disable the report") }, + { NULL, NULL }, }; -static const int report_types[] = +static const argmatch_report_arg argmatch_report_args[] = { - report_none, - report_states, report_states, - report_states | report_itemsets, report_states | report_itemsets, - report_states | report_lookahead_tokens, - report_states | report_lookahead_tokens, - report_states | report_lookahead_tokens, - report_states | report_solved_conflicts, - report_all + { "none", report_none }, + { "states", report_states }, + { "itemsets", report_states | report_itemsets }, + { "lookaheads", report_states | report_lookahead_tokens }, + { "solved", report_states | report_solved_conflicts }, + { "all", report_all }, + { NULL, report_none }, }; -ARGMATCH_VERIFY (report_args, report_types); - +const argmatch_report_group_type argmatch_report_group = +{ + argmatch_report_args, + argmatch_report_docs, + /* TRANSLATORS: Use the same translation for THINGS as in the + --report=THINGS help message. */ + N_("THINGS is a list of comma separated words that can include:"), + NULL +}; /*---------------------. | --trace's handling. | `---------------------*/ -static const char * const trace_args[] = +ARGMATCH_DEFINE_GROUP (trace, enum trace) + +static const argmatch_trace_doc argmatch_trace_docs[] = { - "none - no traces", - "scan - grammar scanner traces", - "parse - grammar parser traces", - "automaton - construction of the automaton", - "bitsets - use of bitsets", - "grammar - reading, reducing the grammar", - "resource - memory consumption (where available)", - "sets - grammar sets: firsts, nullable etc.", - "muscles - m4 definitions passed to the skeleton", - "tools - m4 invocation", - "m4 - m4 traces", - "skeleton - skeleton postprocessing", - "time - time consumption", - "ielr - IELR conversion", - "all - all of the above", - 0 + /* Meant for developers only, don't translate them. */ + { "none", "no traces" }, + { "locations", "full display of the locations" }, + { "scan", "grammar scanner traces" }, + { "parse", "grammar parser traces" }, + { "automaton", "construction of the automaton" }, + { "bitsets", "use of bitsets" }, + { "closure", "input/output of closure" }, + { "grammar", "reading, reducing the grammar" }, + { "resource", "memory consumption (where available)" }, + { "sets", "grammar sets: firsts, nullable etc." }, + { "muscles", "m4 definitions passed to the skeleton" }, + { "tools", "m4 invocation" }, + { "m4", "m4 traces" }, + { "skeleton", "skeleton postprocessing" }, + { "time", "time consumption" }, + { "ielr", "IELR conversion" }, + { "all", "all of the above" }, + { NULL, NULL}, }; -static const int trace_types[] = +static const argmatch_trace_arg argmatch_trace_args[] = { - trace_none, - trace_scan, - trace_parse, - trace_automaton, - trace_bitsets, - trace_grammar, - trace_resource, - trace_sets, - trace_muscles, - trace_tools, - trace_m4, - trace_skeleton, - trace_time, - trace_ielr, - trace_all + { "none", trace_none }, + { "locations", trace_locations }, + { "scan", trace_scan }, + { "parse", trace_parse }, + { "automaton", trace_automaton }, + { "bitsets", trace_bitsets }, + { "closure", trace_closure }, + { "grammar", trace_grammar }, + { "resource", trace_resource }, + { "sets", trace_sets }, + { "muscles", trace_muscles }, + { "tools", trace_tools }, + { "m4", trace_m4 }, + { "skeleton", trace_skeleton }, + { "time", trace_time }, + { "ielr", trace_ielr }, + { "all", trace_all }, + { NULL, trace_none}, }; -ARGMATCH_VERIFY (trace_args, trace_types); - +const argmatch_trace_group_type argmatch_trace_group = +{ + argmatch_trace_args, + argmatch_trace_docs, + N_("TRACES is a list of comma separated words that can include:"), + NULL +}; /*-----------------------. | --feature's handling. | `-----------------------*/ -static const char * const feature_args[] = +ARGMATCH_DEFINE_GROUP (feature, enum feature) + +static const argmatch_feature_doc argmatch_feature_docs[] = { - "none", - "caret", "diagnostics-show-caret", - "fixit", "diagnostics-parseable-fixits", - "all", - 0 + { "caret", N_("show errors with carets") }, + { "fixit", N_("show machine-readable fixes") }, + { "syntax-only", N_("do not generate any file") }, + { "all", N_("all of the above") }, + { "none", N_("disable all of the above") }, + { NULL, NULL } }; -static const int feature_types[] = +static const argmatch_feature_arg argmatch_feature_args[] = { - feature_none, - feature_caret, feature_caret, - feature_fixit_parsable, feature_fixit_parsable, - feature_all + { "none", feature_none }, + { "caret", feature_caret }, + { "diagnostics-show-caret", feature_caret }, + { "fixit", feature_fixit }, + { "diagnostics-parseable-fixits", feature_fixit }, + { "syntax-only", feature_syntax_only }, + { "all", feature_all }, + { NULL, feature_none} }; -ARGMATCH_VERIFY (feature_args, feature_types); +const argmatch_feature_group_type argmatch_feature_group = +{ + argmatch_feature_args, + argmatch_feature_docs, + /* TRANSLATORS: Use the same translation for FEATURES as in the + --feature=FEATURES help message. */ + N_("FEATURES is a list of comma separated words that can include:"), + NULL +}; /*-------------------------------------------. | Display the help message and exit STATUS. | @@ -266,8 +355,7 @@ usage (int status) printf (_("Usage: %s [OPTION]... FILE\n"), program_name); fputs (_("\ Generate a deterministic LR or generalized LR (GLR) parser employing\n\ -LALR(1), IELR(1), or canonical LR(1) parser tables. IELR(1) and\n\ -canonical LR(1) support is experimental.\n\ +LALR(1), IELR(1), or canonical LR(1) parser tables.\n\ \n\ "), stdout); @@ -277,10 +365,10 @@ Mandatory arguments to long options are mandatory for short options too.\n\ fputs (_("\ The same is true for optional arguments.\n\ "), stdout); + putc ('\n', stdout); fputs (_("\ -\n\ -Operation modes:\n\ +Operation Modes:\n\ -h, --help display this help and exit\n\ -V, --version output version information and exit\n\ --print-localedir output directory containing locale-dependent data\n\ @@ -288,32 +376,48 @@ Operation modes:\n\ --print-datadir output directory containing skeletons and XSLT\n\ and exit\n\ -u, --update apply fixes to the source grammar file and exit\n\ - -y, --yacc emulate POSIX Yacc\n\ + -f, --feature[=FEATURES] activate miscellaneous features\n\ +\n\ +"), stdout); + + argmatch_feature_usage (stdout); + putc ('\n', stdout); + + fputs (_("\ +Diagnostics:\n\ -W, --warnings[=CATEGORY] report the warnings falling in CATEGORY\n\ - -f, --feature[=FEATURE] activate miscellaneous features\n\ + --color[=WHEN] whether to colorize the diagnostics\n\ + --style=FILE specify the CSS FILE for colorizer diagnostics\n\ \n\ "), stdout); + warning_usage (stdout); + putc ('\n', stdout); + + argmatch_color_usage (stdout); + putc ('\n', stdout); + fputs (_("\ -Parser:\n\ +Tuning the Parser:\n\ -L, --language=LANGUAGE specify the output programming language\n\ -S, --skeleton=FILE specify the skeleton to use\n\ -t, --debug instrument the parser for tracing\n\ same as '-Dparse.trace'\n\ --locations enable location support\n\ - -D, --define=NAME[=VALUE] similar to '%define NAME \"VALUE\"'\n\ - -F, --force-define=NAME[=VALUE] override '%define NAME \"VALUE\"'\n\ + -D, --define=NAME[=VALUE] similar to '%define NAME VALUE'\n\ + -F, --force-define=NAME[=VALUE] override '%define NAME VALUE'\n\ -p, --name-prefix=PREFIX prepend PREFIX to the external symbols\n\ - deprecated by '-Dapi.prefix=PREFIX'\n\ + deprecated by '-Dapi.prefix={PREFIX}'\n\ -l, --no-lines don't generate '#line' directives\n\ -k, --token-table include a table of token names\n\ + -y, --yacc emulate POSIX Yacc\n\ "), stdout); putc ('\n', stdout); /* Keep -d and --defines separate so that ../build-aux/cross-options.pl * won't assume that -d also takes an argument. */ fputs (_("\ -Output:\n\ +Output Files:\n\ --defines[=FILE] also produce a header file\n\ -d likewise but cannot specify FILE (for POSIX Yacc)\n\ -r, --report=THINGS also produce details on the automaton\n\ @@ -323,46 +427,12 @@ Output:\n\ -o, --output=FILE leave output to FILE\n\ -g, --graph[=FILE] also output a graph of the automaton\n\ -x, --xml[=FILE] also output an XML report of the automaton\n\ - (the XML schema is experimental)\n\ -"), stdout); - putc ('\n', stdout); - - fputs (_("\ -Warning categories include:\n\ - 'midrule-values' unset or unused midrule values\n\ - 'yacc' incompatibilities with POSIX Yacc\n\ - 'conflicts-sr' S/R conflicts (enabled by default)\n\ - 'conflicts-rr' R/R conflicts (enabled by default)\n\ - 'deprecated' obsolete constructs\n\ - 'empty-rule' empty rules without %empty\n\ - 'precedence' useless precedence and associativity\n\ - 'other' all other warnings (enabled by default)\n\ - 'all' all the warnings except 'yacc'\n\ - 'no-CATEGORY' turn off warnings in CATEGORY\n\ - 'none' turn off all the warnings\n\ - 'error[=CATEGORY]' treat warnings as errors\n\ "), stdout); putc ('\n', stdout); - fputs (_("\ -THINGS is a list of comma separated words that can include:\n\ - 'state' describe the states\n\ - 'itemset' complete the core item sets with their closure\n\ - 'lookahead' explicitly associate lookahead tokens to items\n\ - 'solved' describe shift/reduce conflicts solving\n\ - 'all' include all the above information\n\ - 'none' disable the report\n\ -"), stdout); + argmatch_report_usage (stdout); putc ('\n', stdout); - fputs (_("\ -FEATURE is a list of comma separated words that can include:\n\ - 'caret' show errors with carets\n\ - 'all' all of the above\n\ - 'none' disable all of the above\n\ - "), stdout); - - putc ('\n', stdout); printf (_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT); printf (_("%s home page: <%s>.\n"), PACKAGE_NAME, PACKAGE_URL); fputs (_("General help using GNU software: " @@ -436,7 +506,7 @@ skeleton_arg (char const *arg, int prio, location loc) void language_argmatch (char const *arg, int prio, location loc) { - char const *msg; + char const *msg = NULL; if (prio < language_prio) { @@ -451,10 +521,9 @@ language_argmatch (char const *arg, int prio, location loc) } else if (language_prio == prio) msg = _("multiple language declarations are invalid"); - else - return; - complain (&loc, complaint, msg, quotearg_colon (arg)); + if (msg) + complain (&loc, complaint, msg, quotearg_colon (arg)); } /*----------------------. @@ -491,12 +560,16 @@ static char const short_options[] = /* Values for long options that do not have single-letter equivalents. */ enum { - LOCATIONS_OPTION = CHAR_MAX + 1, - PRINT_LOCALEDIR_OPTION, + COLOR_OPTION = CHAR_MAX + 1, + FIXED_OUTPUT_FILES_OPTION, + LOCATIONS_OPTION, PRINT_DATADIR_OPTION, - REPORT_FILE_OPTION + PRINT_LOCALEDIR_OPTION, + REPORT_FILE_OPTION, + STYLE_OPTION }; +/* In the same order as in usage(), and in the documentation. */ static struct option const long_options[] = { /* Operation modes. */ @@ -505,53 +578,43 @@ static struct option const long_options[] = { "print-localedir", no_argument, 0, PRINT_LOCALEDIR_OPTION }, { "print-datadir", no_argument, 0, PRINT_DATADIR_OPTION }, { "update", no_argument, 0, 'u' }, - { "warnings", optional_argument, 0, 'W' }, - - /* Parser. */ - { "name-prefix", required_argument, 0, 'p' }, - - /* Output. */ + { "feature", optional_argument, 0, 'f' }, + + /* Diagnostics. */ + { "warnings", optional_argument, 0, 'W' }, + { "color", optional_argument, 0, COLOR_OPTION }, + { "style", optional_argument, 0, STYLE_OPTION }, + + /* Tuning the Parser. */ + { "language", required_argument, 0, 'L' }, + { "skeleton", required_argument, 0, 'S' }, + { "debug", no_argument, 0, 't' }, + { "locations", no_argument, 0, LOCATIONS_OPTION }, + { "define", required_argument, 0, 'D' }, + { "force-define", required_argument, 0, 'F' }, + { "name-prefix", required_argument, 0, 'p' }, + { "no-lines", no_argument, 0, 'l' }, + { "token-table", no_argument, 0, 'k' }, + { "yacc", no_argument, 0, 'y' }, + + /* Output Files. */ + { "defines", optional_argument, 0, 'd' }, + { "report", required_argument, 0, 'r' }, + { "report-file", required_argument, 0, REPORT_FILE_OPTION }, + { "verbose", no_argument, 0, 'v' }, { "file-prefix", required_argument, 0, 'b' }, { "output", required_argument, 0, 'o' }, - { "output-file", required_argument, 0, 'o' }, { "graph", optional_argument, 0, 'g' }, { "xml", optional_argument, 0, 'x' }, - { "report", required_argument, 0, 'r' }, - { "report-file", required_argument, 0, REPORT_FILE_OPTION }, - { "verbose", no_argument, 0, 'v' }, /* Hidden. */ - { "trace", optional_argument, 0, 'T' }, - - /* Output. */ - { "defines", optional_argument, 0, 'd' }, - { "feature", optional_argument, 0, 'f' }, - - /* Operation modes. */ - { "fixed-output-files", no_argument, 0, 'y' }, - { "yacc", no_argument, 0, 'y' }, - - /* Parser. */ - { "debug", no_argument, 0, 't' }, - { "define", required_argument, 0, 'D' }, - { "force-define", required_argument, 0, 'F' }, - { "locations", no_argument, 0, LOCATIONS_OPTION }, - { "no-lines", no_argument, 0, 'l' }, - { "skeleton", required_argument, 0, 'S' }, - { "language", required_argument, 0, 'L' }, - { "token-table", no_argument, 0, 'k' }, + { "fixed-output-files", no_argument, 0, FIXED_OUTPUT_FILES_OPTION }, + { "output-file", required_argument, 0, 'o' }, + { "trace", optional_argument, 0, 'T' }, {0, 0, 0, 0} }; -/* Under DOS, there is no difference on the case. This can be - troublesome when looking for '.tab' etc. */ -#ifdef MSDOS -# define AS_FILE_NAME(File) (strlwr (File), (File)) -#else -# define AS_FILE_NAME(File) (File) -#endif - /* Build a location for the current command line argument. */ static location @@ -559,19 +622,52 @@ command_line_location (void) { location res; /* "" is used in GCC's messages about -D. */ - boundary_set (&res.start, uniqstr_new (""), optind - 1, -1); + boundary_set (&res.start, uniqstr_new (""), optind - 1, -1, -1); res.end = res.start; return res; } +/* Handle the command line options for color support. Do it early, so + that error messages from getargs be also colored as per the user's + request. This is consistent with the way GCC and Clang behave. */ + +static void +getargs_colors (int argc, char *argv[]) +{ + for (int i = 1; i < argc; i++) + { + const char *arg = argv[i]; + if (STRPREFIX_LIT ("--color=", arg)) + { + const char *color = arg + strlen ("--color="); + if (STREQ (color, "debug")) + color_debug = true; + else + handle_color_option (color); + } + else if (STREQ ("--color", arg)) + handle_color_option (NULL); + else if (STRPREFIX_LIT ("--style=", arg)) + { + const char *style = arg + strlen ("--style="); + handle_style_option (style); + } + } + complain_init_color (); +} + + void getargs (int argc, char *argv[]) { - int c; + getargs_colors (argc, argv); + int c; while ((c = getopt_long (argc, argv, short_options, long_options, NULL)) != -1) + { + location loc = command_line_location (); switch (c) { /* ASCII Sorting for short options (i.e., upper case then @@ -604,7 +700,7 @@ getargs (int argc, char *argv[]) *end = 0; } } - muscle_percent_define_insert (name, command_line_location (), + muscle_percent_define_insert (name, loc, kind, value ? value : "", c == 'D' ? MUSCLE_PERCENT_DEFINE_D : MUSCLE_PERCENT_DEFINE_F); @@ -612,13 +708,11 @@ getargs (int argc, char *argv[]) break; case 'L': - language_argmatch (optarg, command_line_prio, - command_line_location ()); + language_argmatch (optarg, command_line_prio, loc); break; case 'S': - skeleton_arg (AS_FILE_NAME (optarg), command_line_prio, - command_line_location ()); + skeleton_arg (optarg, command_line_prio, loc); break; case 'T': @@ -638,7 +732,7 @@ getargs (int argc, char *argv[]) break; case 'b': - spec_file_prefix = AS_FILE_NAME (optarg); + spec_file_prefix = optarg; break; case 'd': @@ -646,8 +740,8 @@ getargs (int argc, char *argv[]) defines_flag = true; if (optarg) { - free (spec_defines_file); - spec_defines_file = xstrdup (AS_FILE_NAME (optarg)); + free (spec_header_file); + spec_header_file = xstrdup (optarg); } break; @@ -656,7 +750,7 @@ getargs (int argc, char *argv[]) if (optarg) { free (spec_graph_file); - spec_graph_file = xstrdup (AS_FILE_NAME (optarg)); + spec_graph_file = xstrdup (optarg); } break; @@ -672,7 +766,7 @@ getargs (int argc, char *argv[]) break; case 'o': - spec_outfile = AS_FILE_NAME (optarg); + spec_outfile = optarg; break; case 'p': @@ -685,13 +779,14 @@ getargs (int argc, char *argv[]) case 't': muscle_percent_define_insert ("parse.trace", - command_line_location (), + loc, muscle_keyword, "", MUSCLE_PERCENT_DEFINE_D); break; case 'u': update_flag = true; + feature_flag |= feature_syntax_only; break; case 'v': @@ -703,18 +798,28 @@ getargs (int argc, char *argv[]) if (optarg) { free (spec_xml_file); - spec_xml_file = xstrdup (AS_FILE_NAME (optarg)); + spec_xml_file = xstrdup (optarg); } break; case 'y': warning_argmatch ("yacc", 0, 0); - yacc_loc = command_line_location (); + yacc_loc = loc; + break; + + case COLOR_OPTION: + /* Handled in getargs_colors. */ + break; + + case FIXED_OUTPUT_FILES_OPTION: + complain (&loc, Wdeprecated, + _("deprecated option: %s, use %s"), + quote ("--fixed-output-files"), quote_n (1, "-o y.tab.c")); + spec_outfile = "y.tab.c"; break; case LOCATIONS_OPTION: - muscle_percent_define_ensure ("locations", - command_line_location (), true); + muscle_percent_define_ensure ("locations", loc, true); break; case PRINT_LOCALEDIR_OPTION: @@ -727,12 +832,17 @@ getargs (int argc, char *argv[]) case REPORT_FILE_OPTION: free (spec_verbose_file); - spec_verbose_file = xstrdup (AS_FILE_NAME (optarg)); + spec_verbose_file = xstrdup (optarg); + break; + + case STYLE_OPTION: + /* Handled in getargs_colors. */ break; default: usage (EXIT_FAILURE); } + } if (argc - optind != 1) { @@ -743,7 +853,7 @@ getargs (int argc, char *argv[]) usage (EXIT_FAILURE); } - current_file = grammar_file = uniqstr_new (argv[optind]); + grammar_file = uniqstr_new (argv[optind]); MUSCLE_INSERT_C_STRING ("file_name", grammar_file); } diff --git a/contrib/tools/bison/src/getargs.h b/contrib/tools/bison/src/getargs.h index c5adb8487ab5..397419262ed3 100644 --- a/contrib/tools/bison/src/getargs.h +++ b/contrib/tools/bison/src/getargs.h @@ -1,6 +1,6 @@ /* Parse command line arguments for bison. - Copyright (C) 1984, 1986, 1989, 1992, 2000-2015, 2018-2019 Free + Copyright (C) 1984, 1986, 1989, 1992, 2000-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -41,7 +41,7 @@ extern bool no_lines_flag; /* for -l */ extern bool token_table_flag; /* for -k */ extern location yacc_loc; /* for -y */ extern bool update_flag; /* for -u */ - +extern bool color_debug; /* --color=debug. */ /* GLR_PARSER is true if the input file says to use the GLR (Generalized LR) parser, and to output some additional information used by the GLR algorithm. */ @@ -103,6 +103,8 @@ enum trace trace_m4 = 1 << 10, /**< M4 traces. */ trace_muscles = 1 << 11, /**< M4 definitions of the muscles. */ trace_ielr = 1 << 12, /**< IELR conversion. */ + trace_closure = 1 << 13, /**< Input/output of closure(). */ + trace_locations = 1 << 14, /**< Full display of locations. */ trace_all = ~0 /**< All of the above. */ }; /** What debug items bison displays during its run. */ @@ -114,10 +116,11 @@ extern int trace_flag; enum feature { - feature_none = 0, /**< No additional feature. */ - feature_caret = 1 << 0, /**< Output errors with carets. */ - feature_fixit_parsable = 1 << 1, /**< Issue instructions to fix the sources. */ - feature_all = ~0 /**< All above features. */ + feature_none = 0, /**< No additional feature. */ + feature_caret = 1 << 0, /**< Output errors with carets. */ + feature_fixit = 1 << 1, /**< Issue instructions to fix the sources. */ + feature_syntax_only = 1 << 2, /**< Don't generate output. */ + feature_all = ~0 /**< All above features. */ }; /** What additional features to use. */ extern int feature_flag; diff --git a/contrib/tools/bison/src/gram.c b/contrib/tools/bison/src/gram.c index 7f2c943961ca..6202b82a735a 100644 --- a/contrib/tools/bison/src/gram.c +++ b/contrib/tools/bison/src/gram.c @@ -1,6 +1,6 @@ /* Allocate input grammar variables for Bison. - Copyright (C) 1984, 1986, 1989, 2001-2003, 2005-2015, 2018-2019 Free + Copyright (C) 1984, 1986, 1989, 2001-2003, 2005-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -32,7 +32,7 @@ /* Comments for these variables are in gram.h. */ item_number *ritem = NULL; -unsigned nritems = 0; +int nritems = 0; rule *rules = NULL; rule_number nrules = 0; @@ -48,6 +48,34 @@ int max_user_token_number = 256; int required_version = 0; +rule const * +item_rule (item_number const *item) +{ + item_number const *sp = item; + while (0 <= *sp) + ++sp; + rule_number r = item_number_as_rule_number (*sp); + return &rules[r]; +} + + +void +item_print (item_number *item, rule const *previous_rule, FILE *out) +{ + rule const *r = item_rule (item); + rule_lhs_print (r, previous_rule ? previous_rule->lhs : NULL, out); + + for (item_number *sp = r->rhs; sp < item; sp++) + fprintf (out, " %s", symbols[*sp]->tag); + fputs (" .", out); + if (0 <= *r->rhs) + for (item_number *sp = item; 0 <= *sp; ++sp) + fprintf (out, " %s", symbols[*sp]->tag); + else + fprintf (out, " %%empty"); +} + + bool rule_useful_in_grammar_p (rule const *r) { @@ -66,6 +94,12 @@ rule_useless_in_parser_p (rule const *r) return !r->useful && rule_useful_in_grammar_p (r); } +bool +rule_useless_chain_p (rule const *r) +{ + return rule_rhs_length (r) == 1 && !r->action; +} + void rule_lhs_print (rule const *r, sym_content const *previous_lhs, FILE *out) { @@ -86,7 +120,7 @@ size_t rule_rhs_length (rule const *r) { size_t res = 0; - for (item_number *rhsp = r->rhs; *rhsp >= 0; ++rhsp) + for (item_number *rhsp = r->rhs; 0 <= *rhsp; ++rhsp) ++res; return res; } @@ -95,8 +129,8 @@ void rule_rhs_print (rule const *r, FILE *out) { if (0 <= *r->rhs) - for (item_number *rp = r->rhs; *rp >= 0; rp++) - fprintf (out, " %s", symbols[*rp]->tag); + for (item_number *rhsp = r->rhs; 0 <= *rhsp; ++rhsp) + fprintf (out, " %s", symbols[*rhsp]->tag); else fputs (" %empty", out); } @@ -107,9 +141,9 @@ rule_rhs_print_xml (rule const *r, FILE *out, int level) if (*r->rhs >= 0) { xml_puts (out, level, ""); - for (item_number *rp = r->rhs; *rp >= 0; rp++) + for (item_number *rhsp = r->rhs; 0 <= *rhsp; ++rhsp) xml_printf (out, level + 1, "%s", - xml_escape (symbols[*rp]->tag)); + xml_escape (symbols[*rhsp]->tag)); xml_puts (out, level, ""); } else @@ -120,11 +154,18 @@ rule_rhs_print_xml (rule const *r, FILE *out, int level) } } +void +rule_print (rule const *r, rule const *prev_rule, FILE *out) +{ + rule_lhs_print (r, prev_rule ? prev_rule->lhs : NULL, out); + rule_rhs_print (r, out); +} + void ritem_print (FILE *out) { fputs ("RITEM\n", out); - for (unsigned i = 0; i < nritems; ++i) + for (int i = 0; i < nritems; ++i) if (ritem[i] >= 0) fprintf (out, " %s", symbols[ritem[i]]->tag); else @@ -138,7 +179,7 @@ ritem_longest_rhs (void) int max = 0; for (rule_number r = 0; r < nrules; ++r) { - int length = rule_rhs_length (&rules[r]); + size_t length = rule_rhs_length (&rules[r]); if (length > max) max = length; } @@ -151,7 +192,7 @@ grammar_rules_partial_print (FILE *out, const char *title, rule_filter filter) { bool first = true; - sym_content *previous_lhs = NULL; + rule *previous_rule = NULL; /* rule # : LHS -> RHS */ for (rule_number r = 0; r < nrules + nuseless_productions; r++) @@ -160,13 +201,12 @@ grammar_rules_partial_print (FILE *out, const char *title, continue; if (first) fprintf (out, "%s\n\n", title); - else if (previous_lhs && previous_lhs != rules[r].lhs) + else if (previous_rule && previous_rule->lhs != rules[r].lhs) fputc ('\n', out); first = false; - rule_lhs_print (&rules[r], previous_lhs, out); - rule_rhs_print (&rules[r], out); - fprintf (out, "\n"); - previous_lhs = rules[r].lhs; + rule_print (&rules[r], previous_rule, out); + fputc ('\n', out); + previous_rule = &rules[r]; } if (!first) fputs ("\n\n", out); @@ -189,13 +229,10 @@ grammar_rules_print_xml (FILE *out, int level) xml_puts (out, level + 1, ""); first = false; { - char const *usefulness; - if (rule_useless_in_grammar_p (&rules[r])) - usefulness = "useless-in-grammar"; - else if (rule_useless_in_parser_p (&rules[r])) - usefulness = "useless-in-parser"; - else - usefulness = "useful"; + char const *usefulness + = rule_useless_in_grammar_p (&rules[r]) ? "useless-in-grammar" + : rule_useless_in_parser_p (&rules[r]) ? "useless-in-parser" + : "useful"; xml_indent (out, level + 2); fprintf (out, "content->prec, symbols[i]->content->assoc, @@ -235,42 +271,49 @@ grammar_dump (FILE *out, const char *title) fprintf (out, "\n\n"); } + fprintf (out, "Non terminals\n-------------\n\n"); + { + fprintf (out, "Value Tag\n"); + + for (symbol_number i = ntokens; i < nsyms; i++) + fprintf (out, "%5d %s\n", + i, symbols[i]->tag); + fprintf (out, "\n\n"); + } + fprintf (out, "Rules\n-----\n\n"); { fprintf (out, - "Num (Prec, Assoc, Useful, Ritem Range) Lhs" - " -> Rhs (Ritem range) [Num]\n"); - for (rule_number i = 0; i < nrules + nuseless_productions; i++) + "Num (Prec, Assoc, Useful, UselessChain) Lhs" + " -> (Ritem Range) Rhs\n"); + for (rule_number i = 0; i < nrules + nuseless_productions; ++i) { rule const *rule_i = &rules[i]; - unsigned const rhs_itemno = rule_i->rhs - ritem; - /* Find the last RHS index in ritems. */ - unsigned rhs_count = 0; - for (item_number *rp = rule_i->rhs; *rp >= 0; ++rp) - ++rhs_count; - fprintf (out, "%3d (%2d, %2d, %2d, %2u-%2u) %2d ->", + int const rhs_itemno = rule_i->rhs - ritem; + int length = rule_rhs_length (rule_i); + aver (item_number_as_rule_number (rule_i->rhs[length]) == i); + fprintf (out, "%3d (%2d, %2d, %2s, %2s) %2d -> (%2u-%2u)", i, rule_i->prec ? rule_i->prec->prec : 0, rule_i->prec ? rule_i->prec->assoc : 0, - rule_i->useful, - rhs_itemno, - rhs_itemno + rhs_count - 1, - rule_i->lhs->number); + rule_i->useful ? "t" : "f", + rule_useless_chain_p (rule_i) ? "t" : "f", + rule_i->lhs->number, + rhs_itemno, rhs_itemno + length - 1); /* Dumped the RHS. */ - for (item_number *rp = rule_i->rhs; *rp >= 0; ++rp) - fprintf (out, " %3d", *rp); - fprintf (out, " [%d]\n", - item_number_as_rule_number (rule_i->rhs[rhs_count+1])); + for (item_number *rhsp = rule_i->rhs; 0 <= *rhsp; ++rhsp) + fprintf (out, " %3d", *rhsp); + fputc ('\n', out); } } fprintf (out, "\n\n"); fprintf (out, "Rules interpreted\n-----------------\n\n"); - for (rule_number r = 0; r < nrules + nuseless_productions; r++) + for (rule_number r = 0; r < nrules + nuseless_productions; ++r) { fprintf (out, "%-5d %s:", r, rules[r].lhs->symbol->tag); rule_rhs_print (&rules[r], out); - fprintf (out, "\n"); + fputc ('\n', out); } fprintf (out, "\n\n"); } @@ -278,7 +321,7 @@ grammar_dump (FILE *out, const char *title) void grammar_rules_useless_report (const char *message) { - for (rule_number r = 0; r < nrules ; ++r) + for (rule_number r = 0; r < nrules; ++r) /* Don't complain about rules whose LHS is useless, we already complained about it. */ if (!reduce_nonterminal_useless_in_grammar (rules[r].lhs) diff --git a/contrib/tools/bison/src/gram.h b/contrib/tools/bison/src/gram.h index 83dd8aacf7c5..afae95a78b26 100644 --- a/contrib/tools/bison/src/gram.h +++ b/contrib/tools/bison/src/gram.h @@ -1,6 +1,6 @@ /* Data definitions for internal representation of Bison's input. - Copyright (C) 1984, 1986, 1989, 1992, 2001-2007, 2009-2015, 2018-2019 + Copyright (C) 1984, 1986, 1989, 1992, 2001-2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -42,9 +42,9 @@ Internally, we cannot use the number 0 for a rule because for instance RITEM stores both symbol (the RHS) and rule numbers: the - symbols are shorts >= 0, and rule number are stored negative. + symbols are integers >= 0, and rule numbers are stored negative. Therefore 0 cannot be used, since it would be both the rule number - 0, and the token $end). + 0, and the token $end. Actions are accessed via the rule number. @@ -55,8 +55,7 @@ RULES[R].lhs -- the symbol of the left hand side of rule R. - RULES[R].rhs -- the index in RITEM of the beginning of the portion - for rule R. + RULES[R].rhs -- the beginning of the portion of RITEM for rule R. RULES[R].prec -- the symbol providing the precedence level of R. @@ -75,16 +74,16 @@ RULES[R].line -- the line where R was defined. - RULES[R].useful -- true iff the rule is used (i.e., false if thrown - away by reduce). + RULES[R].useful -- whether the rule is used. False if thrown away + by reduce(). The right hand side is stored as symbol numbers in a portion of RITEM. The length of the portion is one greater than the number of symbols in the rule's right hand side. The last element in the portion - contains minus R, which identifies it as the end of a portion and - says which rule it is for. + contains -R, which identifies it as the end of a portion and says + which rule it is for. The portions of RITEM come in order of increasing rule number. NRITEMS is the total length of RITEM. Each element of RITEM is @@ -115,7 +114,7 @@ extern int nvars; typedef int item_number; # define ITEM_NUMBER_MAX INT_MAX extern item_number *ritem; -extern unsigned nritems; +extern int nritems; /* There is weird relationship between OT1H item_number and OTOH symbol_number and rule_number: we store the latter in @@ -146,7 +145,6 @@ item_number_is_symbol_number (item_number i) /* Rule numbers. */ typedef int rule_number; # define RULE_NUMBER_MAX INT_MAX -extern rule_number nrules; static inline item_number rule_number_as_item_number (rule_number r) @@ -166,6 +164,7 @@ item_number_is_rule_number (item_number i) return i < 0; } + /*--------. | Rules. | `--------*/ @@ -192,6 +191,7 @@ typedef struct /* This symbol was attached to the rule via %prec. */ sym_content *precsym; + /* Location of the rhs. */ location location; bool useful; bool is_predicate; @@ -202,26 +202,40 @@ typedef struct int expected_rr_conflicts; const char *action; - location action_location; + location action_loc; } rule; +/* The used rules (size NRULES). */ extern rule *rules; +extern rule_number nrules; + +/* Get the rule associated to this item. ITEM points inside RITEM. */ +rule const *item_rule (item_number const *item); + +/* Pretty-print this ITEM (as in the report). ITEM points inside + RITEM. PREVIOUS_RULE is used to see if the lhs is common, in which + case LHS is factored. Passing NULL is fine. */ +void item_print (item_number *item, rule const *previous_rule, + FILE *out); /* A function that selects a rule. */ typedef bool (*rule_filter) (rule const *); -/* Return true IFF the rule has a 'number' smaller than NRULES. That is, it is - useful in the grammar. */ +/* Whether the rule has a 'number' smaller than NRULES. That is, it + is useful in the grammar. */ bool rule_useful_in_grammar_p (rule const *r); -/* Return true IFF the rule has a 'number' higher than NRULES. That is, it is +/* Whether the rule has a 'number' higher than NRULES. That is, it is useless in the grammar. */ bool rule_useless_in_grammar_p (rule const *r); -/* Return true IFF the rule is not flagged as useful but is useful in the +/* Whether the rule is not flagged as useful but is useful in the grammar. In other words, it was discarded because of conflicts. */ bool rule_useless_in_parser_p (rule const *r); +/* Whether the rule has a single RHS, and no user action. */ +bool rule_useless_chain_p (rule const *r); + /* Print this rule's number and lhs on OUT. If a PREVIOUS_LHS was already displayed (by a previous call for another rule), avoid useless repetitions. */ @@ -229,12 +243,15 @@ void rule_lhs_print (rule const *r, sym_content const *previous_lhs, FILE *out); void rule_lhs_print_xml (rule const *r, FILE *out, int level); -/* Return the length of the RHS. */ +/* The length of the RHS. */ size_t rule_rhs_length (rule const *r); /* Print this rule's RHS on OUT. */ void rule_rhs_print (rule const *r, FILE *out); +/* Print this rule on OUT. If a PREVIOUS_RULE was already displayed, + avoid useless repetitions of their LHS. */ +void rule_print (rule const *r, rule const *prev_rule, FILE *out); @@ -252,7 +269,7 @@ extern int max_user_token_number; /* Dump RITEM for traces. */ void ritem_print (FILE *out); -/* Return the size of the longest rule RHS. */ +/* The size of the longest rule RHS. */ size_t ritem_longest_rhs (void); /* Print the grammar's rules that match FILTER on OUT under TITLE. */ diff --git a/contrib/tools/bison/src/graphviz.c b/contrib/tools/bison/src/graphviz.c index 75e4a6e6a8fc..80a2ff99ddd8 100644 --- a/contrib/tools/bison/src/graphviz.c +++ b/contrib/tools/bison/src/graphviz.c @@ -1,6 +1,6 @@ /* Output Graphviz specification of a state machine generated by Bison. - Copyright (C) 2006-2007, 2009-2015, 2018-2019 Free Software + Copyright (C) 2006-2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -159,6 +159,9 @@ output_red (state const *s, reductions const *reds, FILE *fout) bitset no_reduce_set; no_reduce_bitset_init (s, &no_reduce_set); + rule *default_reduction + = yydefact[s->number] ? &rules[yydefact[s->number] - 1] : NULL; + /* Two obstacks are needed: one for the enabled reductions, and one for the disabled reductions, because in the end we want two separate edges, even though in most cases only one will actually @@ -171,11 +174,6 @@ output_red (state const *s, reductions const *reds, FILE *fout) const int source = s->number; for (int j = 0; j < reds->num; ++j) { - rule *default_reduction = - yydefact[s->number] - ? &rules[yydefact[s->number] - 1] - : NULL; - bool defaulted = default_reduction && default_reduction == reds->rules[j]; /* Build the lookahead tokens lists, one for enabled transitions diff --git a/contrib/tools/bison/src/graphviz.h b/contrib/tools/bison/src/graphviz.h index cceb1fbd3d71..06b423586684 100644 --- a/contrib/tools/bison/src/graphviz.h +++ b/contrib/tools/bison/src/graphviz.h @@ -1,6 +1,6 @@ /* Output Graphviz specification of a state machine generated by Bison. - Copyright (C) 2006, 2010-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2006, 2010-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/src/ielr.c b/contrib/tools/bison/src/ielr.c index 867b8a0a2afc..8e34b2cc3237 100644 --- a/contrib/tools/bison/src/ielr.c +++ b/contrib/tools/bison/src/ielr.c @@ -1,6 +1,6 @@ /* IELR main implementation. - Copyright (C) 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -36,7 +36,36 @@ #include "symtab.h" /** Records the value of the \%define variable lr.type. */ -typedef enum { LR_TYPE__LALR, LR_TYPE__IELR, LR_TYPE__CANONICAL_LR } LrType; +typedef enum + { + LR_TYPE__LR0, + LR_TYPE__LALR, + LR_TYPE__IELR, + LR_TYPE__CANONICAL_LR + } LrType; + +/* The user's requested LR type. */ +static LrType +lr_type_get (void) +{ + char *type = muscle_percent_define_get ("lr.type"); + LrType res; + if (STREQ (type, "lr""(0)")) + res = LR_TYPE__LR0; + else if (STREQ (type, "lalr")) + res = LR_TYPE__LALR; + else if (STREQ (type, "ielr")) + res = LR_TYPE__IELR; + else if (STREQ (type, "canonical-lr")) + res = LR_TYPE__CANONICAL_LR; + else + { + aver (false); + abort (); + } + free (type); + return res; +} /** * \post: @@ -49,7 +78,7 @@ static bitset ielr_compute_ritem_sees_lookahead_set (void) { bitset result = bitset_create (nritems, BITSET_FIXED); - unsigned i = nritems-1; + int i = nritems-1; while (0 < i) { --i; @@ -167,10 +196,7 @@ ielr_compute_internal_follow_edges (bitset ritem_sees_lookahead_set, relation_transpose (edgesp, ngotos); if (trace_flag & trace_ielr) - { - fprintf (stderr, "internal_follow_edges:\n"); - relation_print (*edgesp, ngotos, stderr); - } + relation_print ("internal_follow_edges", *edgesp, ngotos, NULL, stderr); } /** @@ -215,7 +241,7 @@ ielr_compute_follow_kernel_items (bitset ritem_sees_lookahead_set, && bitset_test (ritem_sees_lookahead_set, items[j])) bitset_set ((*follow_kernel_itemsp)[i], j); } - relation_digraph (internal_follow_edges, ngotos, follow_kernel_itemsp); + relation_digraph (internal_follow_edges, ngotos, *follow_kernel_itemsp); if (trace_flag & trace_ielr) { @@ -271,12 +297,11 @@ ielr_compute_always_follows (goto_number ***edgesp, } free (edge_array); } - relation_digraph (*edgesp, ngotos, always_followsp); + relation_digraph (*edgesp, ngotos, *always_followsp); if (trace_flag & trace_ielr) { - fprintf (stderr, "always follow edges:\n"); - relation_print (*edgesp, ngotos, stderr); + relation_print ("always follow edges", *edgesp, ngotos, NULL, stderr); fprintf (stderr, "always_follows:\n"); debug_bitsetv (*always_followsp); } @@ -393,7 +418,7 @@ ielr_item_has_lookahead (state *s, symbol_number lhs, size_t item, top-level invocation), go get it. */ if (!lhs) { - unsigned i; + int i; for (i = s->items[item]; !item_number_is_rule_number (ritem[i]); ++i) @@ -471,7 +496,7 @@ ielr_compute_annotation_lists (bitsetv follow_kernel_items, AnnotationIndex *annotation_counts = xnmalloc (nstates, sizeof *annotation_counts); ContributionIndex max_contributions = 0; - unsigned total_annotations = 0; + int total_annotations = 0; *inadequacy_listsp = xnmalloc (nstates, sizeof **inadequacy_listsp); *annotation_listsp = xnmalloc (nstates, sizeof **annotation_listsp); @@ -540,7 +565,7 @@ typedef struct state_list /** * nextIsocore is the next state in a circularly linked-list of all states * with the same core. The one originally computed by generate_states in - * LR0.c is lr0Isocore. + * lr0.c is lr0Isocore. */ struct state_list *lr0Isocore; struct state_list *nextIsocore; @@ -608,7 +633,7 @@ ielr_compute_lookaheads (bitsetv follow_kernel_items, bitsetv always_follows, { if (item_number_is_rule_number (ritem[t->items[t_item] - 2])) { - unsigned rule_item; + int rule_item; for (rule_item = t->items[t_item]; !item_number_is_rule_number (ritem[rule_item]); ++rule_item) @@ -1051,41 +1076,40 @@ ielr_split_states (bitsetv follow_kernel_items, bitsetv always_follows, } } + void ielr (void) { - LrType lr_type; - - /* Examine user options. */ - { - char *type = muscle_percent_define_get ("lr.type"); - if (STREQ (type, "lalr")) - lr_type = LR_TYPE__LALR; - else if (STREQ (type, "ielr")) - lr_type = LR_TYPE__IELR; - else if (STREQ (type, "canonical-lr")) - lr_type = LR_TYPE__CANONICAL_LR; - else - { - aver (false); - abort (); - } - free (type); - } + LrType lr_type = lr_type_get (); /* Phase 0: LALR(1). */ - timevar_push (tv_lalr); - if (lr_type == LR_TYPE__CANONICAL_LR) - set_goto_map (); - else - lalr (); - if (lr_type == LR_TYPE__LALR) + switch (lr_type) { + case LR_TYPE__LR0: + timevar_push (tv_lalr); + set_goto_map (); + timevar_pop (tv_lalr); + return; + + case LR_TYPE__CANONICAL_LR: + timevar_push (tv_lalr); + set_goto_map (); + timevar_pop (tv_lalr); + break; + + case LR_TYPE__LALR: + timevar_push (tv_lalr); + lalr (); bitsetv_free (goto_follows); timevar_pop (tv_lalr); return; + + case LR_TYPE__IELR: + timevar_push (tv_lalr); + lalr (); + timevar_pop (tv_lalr); + break; } - timevar_pop (tv_lalr); { bitsetv follow_kernel_items; diff --git a/contrib/tools/bison/src/ielr.h b/contrib/tools/bison/src/ielr.h index 17dcb2c8c87e..bb62625a0657 100644 --- a/contrib/tools/bison/src/ielr.h +++ b/contrib/tools/bison/src/ielr.h @@ -1,6 +1,6 @@ /* IELR main implementation. - Copyright (C) 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/src/lalr.c b/contrib/tools/bison/src/lalr.c index 0f1149d7fbdf..8b8724d04f95 100644 --- a/contrib/tools/bison/src/lalr.c +++ b/contrib/tools/bison/src/lalr.c @@ -1,6 +1,6 @@ /* Compute lookahead criteria for Bison. - Copyright (C) 1984, 1986, 1989, 2000-2015, 2018-2019 Free Software + Copyright (C) 1984, 1986, 1989, 2000-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -28,18 +28,19 @@ #include #include -#include "LR0.h" #include "complain.h" #include "derives.h" #include "getargs.h" #include "gram.h" #include "lalr.h" +#include "lr0.h" #include "muscle-tab.h" #include "nullable.h" #include "reader.h" #include "relation.h" #include "symtab.h" +/* goto_map[nterm - NTOKENS] -> number of gotos. */ goto_number *goto_map = NULL; goto_number ngotos = 0; state_number *from_state = NULL; @@ -53,8 +54,16 @@ typedef struct goto_list goto_number value; } goto_list; +static goto_list * +goto_list_new (goto_number value, struct goto_list *next) +{ + goto_list *res = xmalloc (sizeof *res); + res->next = next; + res->value = value; + return res; +} -/* LA is an NLA by NTOKENS matrix of bits. LA[l, i] is 1 if the rule +/* LA is an nLA by NTOKENS matrix of bits. LA[l, i] is 1 if the rule LArule[l] is applicable in the appropriate state when the next token is symbol i. If LA[l, i] and LA[l, j] are both 1 for i != j, it is a conflict. */ @@ -63,31 +72,48 @@ static bitsetv LA = NULL; size_t nLA; +/* "(p, A) includes (p', B)" iff + B → βAγ, γ nullable, and p'-- β --> p (i.e., state p' reaches p on label β). + + Definition p.621 [DeRemer 1982]. + + INCLUDES[(p, A)] = [(p', B),...] */ static goto_number **includes; + +/* "(q, A → ω) lookback (p, A)" iff state p reaches state q on label ω. + + Definition p.621 [DeRemer 1982]. */ static goto_list **lookback; +static void +goto_print (goto_number i, FILE *out) +{ + const state_number src = from_state[i]; + const state_number dst = to_state[i]; + symbol_number var = states[dst]->accessing_symbol; + fprintf (out, + "goto[%ld] = (%d, %s, %d)", i, src, symbols[var]->tag, dst); +} void set_goto_map (void) { - goto_number *temp_map = xnmalloc (nvars + 1, sizeof *temp_map); - + /* Count the number of gotos (ngotos) per nterm (goto_map). */ goto_map = xcalloc (nvars + 1, sizeof *goto_map); ngotos = 0; for (state_number s = 0; s < nstates; ++s) { - transitions *sp = states[s]->transitions; - for (int i = sp->num - 1; i >= 0 && TRANSITION_IS_GOTO (sp, i); --i) + transitions *trans = states[s]->transitions; + for (int i = trans->num - 1; 0 <= i && TRANSITION_IS_GOTO (trans, i); --i) { ngotos++; - /* Abort if (ngotos + 1) would overflow. */ aver (ngotos != GOTO_NUMBER_MAXIMUM); - - goto_map[TRANSITION_SYMBOL (sp, i) - ntokens]++; + goto_map[TRANSITION_SYMBOL (trans, i) - ntokens]++; } } + goto_number *temp_map = xnmalloc (nvars + 1, sizeof *temp_map); { goto_number k = 0; for (symbol_number i = ntokens; i < nsyms; ++i) @@ -108,21 +134,28 @@ set_goto_map (void) for (state_number s = 0; s < nstates; ++s) { - const transitions *sp = states[s]->transitions; - for (int i = sp->num - 1; i >= 0 && TRANSITION_IS_GOTO (sp, i); --i) + const transitions *trans = states[s]->transitions; + for (int i = trans->num - 1; 0 <= i && TRANSITION_IS_GOTO (trans, i); --i) { - goto_number k = temp_map[TRANSITION_SYMBOL (sp, i) - ntokens]++; + goto_number k = temp_map[TRANSITION_SYMBOL (trans, i) - ntokens]++; from_state[k] = s; - to_state[k] = sp->states[i]->number; + to_state[k] = trans->states[i]->number; } } free (temp_map); + + if (trace_flag & trace_automaton) + for (int i = 0; i < ngotos; ++i) + { + goto_print (i, stderr); + fputc ('\n', stderr); + } } goto_number -map_goto (state_number s0, symbol_number sym) +map_goto (state_number src, symbol_number sym) { goto_number low = goto_map[sym - ntokens]; goto_number high = goto_map[sym - ntokens + 1] - 1; @@ -132,39 +165,62 @@ map_goto (state_number s0, symbol_number sym) aver (low <= high); goto_number middle = (low + high) / 2; state_number s = from_state[middle]; - if (s == s0) + if (s == src) return middle; - else if (s < s0) + else if (s < src) low = middle + 1; else high = middle - 1; } } +/* Print FOLLOWS for debugging. */ +static void +follows_print (const char* title, FILE *out) +{ + fprintf (out, "%s:\n", title); + for (goto_number i = 0; i < ngotos; ++i) + { + fputs (" FOLLOWS[", out); + goto_print (i, out); + fputs ("] =", out); + bitset_iterator iter; + symbol_number sym; + BITSET_FOR_EACH (iter, goto_follows[i], sym, 0) + fprintf (out, " %s", symbols[sym]->tag); + fputc ('\n', out); + } + fputc ('\n', out); +} +/* Build goto_follows. */ static void -initialize_F (void) +initialize_goto_follows (void) { goto_number **reads = xnmalloc (ngotos, sizeof *reads); - goto_number *edge = xnmalloc (ngotos + 1, sizeof *edge); - goto_number nedges = 0; + goto_number *edge = xnmalloc (ngotos, sizeof *edge); goto_follows = bitsetv_create (ngotos, ntokens, BITSET_FIXED); for (goto_number i = 0; i < ngotos; ++i) { - state_number stateno = to_state[i]; - const transitions *sp = states[stateno]->transitions; + state_number dst = to_state[i]; + const transitions *trans = states[dst]->transitions; int j; - FOR_EACH_SHIFT (sp, j) - bitset_set (goto_follows[i], TRANSITION_SYMBOL (sp, j)); + FOR_EACH_SHIFT (trans, j) + bitset_set (goto_follows[i], TRANSITION_SYMBOL (trans, j)); - for (; j < sp->num; ++j) + /* Gotos outgoing from DST. */ + goto_number nedges = 0; + for (; j < trans->num; ++j) { - symbol_number sym = TRANSITION_SYMBOL (sp, j); + symbol_number sym = TRANSITION_SYMBOL (trans, j); if (nullable[sym - ntokens]) - edge[nedges++] = map_goto (stateno, sym); + { + assert (nedges < ngotos); + edge[nedges++] = map_goto (dst, sym); + } } if (nedges == 0) @@ -174,82 +230,164 @@ initialize_F (void) reads[i] = xnmalloc (nedges + 1, sizeof reads[i][0]); memcpy (reads[i], edge, nedges * sizeof edge[0]); reads[i][nedges] = END_NODE; - nedges = 0; } } + if (trace_flag & trace_automaton) + { + follows_print ("follows after shifts", stderr); + relation_print ("reads", reads, ngotos, goto_print, stderr); + } - relation_digraph (reads, ngotos, &goto_follows); + relation_digraph (reads, ngotos, goto_follows); + if (trace_flag & trace_automaton) + follows_print ("follows after read", stderr); for (goto_number i = 0; i < ngotos; ++i) free (reads[i]); - free (reads); free (edge); } +/* Find the state which LOOKBACK[LOOKBACK_INDEX] is about. */ +static const state * +lookback_find_state (int lookback_index) +{ + state *res = NULL; + for (int j = 0; j < nstates; ++j) + if (states[j]->reductions + && states[j]->reductions->lookahead_tokens) + { + if (states[j]->reductions->lookahead_tokens - LA > lookback_index) + /* Went too far. */ + break; + else + res = states[j]; + } + /* Pacify "potential null pointer dereference" warning. */ + if (!res) + abort (); + return res; +} + +/* Print LOOKBACK for debugging. */ static void -add_lookback_edge (state *s, rule *r, goto_number gotono) +lookback_print (FILE *out) { - int ri = state_reduction_find (s, r); - goto_list *sp = xmalloc (sizeof *sp); - sp->next = lookback[(s->reductions->lookahead_tokens - LA) + ri]; - sp->value = gotono; - lookback[(s->reductions->lookahead_tokens - LA) + ri] = sp; + fputs ("lookback:\n", out); + for (int i = 0; i < nLA; ++i) + if (lookback[i]) + { + fprintf (out, " %3d = ", i); + const state *s = lookback_find_state (i); + int rnum = i - (s->reductions->lookahead_tokens - LA); + const rule *r = s->reductions->rules[rnum]; + fprintf (out, "(%3d, ", s->number); + rule_print (r, NULL, out); + fputs (") ->", out); + for (goto_list *sp = lookback[i]; sp; sp = sp->next) + { + fputc (' ', out); + goto_print (sp->value, out); + } + fputc ('\n', out); + } + fputc ('\n', out); } +/* Add (S, R) -> GOTONO to LOOKBACK. + "(q, A → ω) lookback (p, A)" iff state p reaches state q on label ω. + The goto number GOTONO, whose source is S (which is + inconsistent), */ +static void +add_lookback_edge (state *s, rule const *r, goto_number gotono) +{ + int ri = state_reduction_find (s, r); + int idx = (s->reductions->lookahead_tokens - LA) + ri; + lookback[idx] = goto_list_new (gotono, lookback[idx]); +} + + +/* Compute INCLUDES and LOOKBACK. Corresponds to step E in Sec. 6 of + [DeRemer 1982]. */ static void build_relations (void) { - goto_number *edge = xnmalloc (ngotos + 1, sizeof *edge); - state_number *states1 = xnmalloc (ritem_longest_rhs () + 1, sizeof *states1); + goto_number *edge = xnmalloc (ngotos, sizeof *edge); + state_number *path = xnmalloc (ritem_longest_rhs () + 1, sizeof *path); includes = xnmalloc (ngotos, sizeof *includes); + /* For each goto (from SRC to DST labeled by nterm VAR), iterate + over each rule with VAR as LHS, and find the path PATH from SRC + labeled with the RHS of the rule. */ for (goto_number i = 0; i < ngotos; ++i) { - int nedges = 0; - symbol_number symbol1 = states[to_state[i]]->accessing_symbol; + const state_number src = from_state[i]; + const state_number dst = to_state[i]; + symbol_number var = states[dst]->accessing_symbol; - for (rule **rulep = derives[symbol1 - ntokens]; *rulep; rulep++) + /* Size of EDGE. */ + int nedges = 0; + for (rule **rulep = derives[var - ntokens]; *rulep; ++rulep) { - int length = 1; - item_number const *rp; - state *s = states[from_state[i]]; - states1[0] = s->number; + rule const *r = *rulep; + state *s = states[src]; + path[0] = s->number; - for (rp = (*rulep)->rhs; ! item_number_is_rule_number (*rp); rp++) + /* Length of PATH. */ + int length = 1; + for (item_number const *rp = r->rhs; 0 <= *rp; rp++) { - s = transitions_to (s->transitions, - item_number_as_symbol_number (*rp)); - states1[length++] = s->number; + symbol_number sym = item_number_as_symbol_number (*rp); + s = transitions_to (s, sym); + path[length++] = s->number; } + /* S is the end of PATH. */ if (!s->consistent) - add_lookback_edge (s, *rulep, i); + add_lookback_edge (s, r, i); - length--; - bool done = false; - while (!done) + /* Walk back PATH from penultimate to beginning. + + The "0 <= p" part is actually useless: each rhs ends in a + rule number (for which ISVAR(...) is false), and there is + a sentinel (ritem[-1]=0) before the first rhs. */ + for (int p = length - 2; 0 <= p && ISVAR (r->rhs[p]); --p) { - done = true; - /* Each rhs ends in a rule number, and there is a - sentinel (ritem[-1]=0) before the first rhs, so it is safe to - decrement RP here. */ - rp--; - if (ISVAR (*rp)) - { - /* Downcasting from item_number to symbol_number. */ - edge[nedges++] = map_goto (states1[--length], - item_number_as_symbol_number (*rp)); - if (nullable[*rp - ntokens]) - done = false; - } + symbol_number sym = item_number_as_symbol_number (r->rhs[p]); + goto_number g = map_goto (path[p], sym); + /* Insert G if not already in EDGE. + FIXME: linear search. A bitset instead? */ + { + bool found = false; + for (int j = 0; !found && j < nedges; ++j) + found = edge[j] == g; + if (!found) + { + assert (nedges < ngotos); + edge[nedges++] = g; + } + } + if (!nullable[sym - ntokens]) + break; } } + if (trace_flag & trace_automaton) + { + goto_print (i, stderr); + fputs (" edges = ", stderr); + for (int j = 0; j < nedges; ++j) + { + fputc (' ', stderr); + goto_print (edge[j], stderr); + } + fputc ('\n', stderr); + } + if (nedges == 0) includes[i] = NULL; else @@ -262,21 +400,22 @@ build_relations (void) } free (edge); - free (states1); + free (path); relation_transpose (&includes, ngotos); + if (trace_flag & trace_automaton) + relation_print ("includes", includes, ngotos, goto_print, stderr); } - - +/* Compute FOLLOWS from INCLUDES, and free INCLUDES. */ static void -compute_FOLLOWS (void) +compute_follows (void) { - relation_digraph (includes, ngotos, &goto_follows); - + relation_digraph (includes, ngotos, goto_follows); + if (trace_flag & trace_sets) + follows_print ("follows after includes", stderr); for (goto_number i = 0; i < ngotos; ++i) free (includes[i]); - free (includes); } @@ -284,6 +423,9 @@ compute_FOLLOWS (void) static void compute_lookahead_tokens (void) { + if (trace_flag & trace_automaton) + lookback_print (stderr); + for (size_t i = 0; i < nLA; ++i) for (goto_list *sp = lookback[i]; sp; sp = sp->next) bitset_or (LA[i], LA[i], goto_follows[sp->value]); @@ -291,7 +433,6 @@ compute_lookahead_tokens (void) /* Free LOOKBACK. */ for (size_t i = 0; i < nLA; ++i) LIST_FREE (goto_list, lookback[i]); - free (lookback); } @@ -304,16 +445,15 @@ compute_lookahead_tokens (void) static int state_lookahead_tokens_count (state *s, bool default_reduction_only_for_accept) { - int n_lookahead_tokens = 0; - reductions *rp = s->reductions; - transitions *sp = s->transitions; + const reductions *reds = s->reductions; + const transitions *trans = s->transitions; /* Transitions are only disabled during conflict resolution, and that hasn't happened yet, so there should be no need to check that transition 0 hasn't been disabled before checking if it is a shift. However, this check was performed at one time, so we leave it as an aver. */ - aver (sp->num == 0 || !TRANSITION_IS_DISABLED (sp, 0)); + aver (trans->num == 0 || !TRANSITION_IS_DISABLED (trans, 0)); /* We need a lookahead either to distinguish different reductions (i.e., there are two or more), or to distinguish a reduction from a @@ -323,15 +463,13 @@ state_lookahead_tokens_count (state *s, bool default_reduction_only_for_accept) a lookahead token that makes sense there, and so no lookahead token should be read) if the user has otherwise disabled default reductions. */ - if (rp->num > 1 - || (rp->num == 1 && sp->num && TRANSITION_IS_SHIFT (sp, 0)) - || (rp->num == 1 && rp->rules[0]->number != 0 - && default_reduction_only_for_accept)) - n_lookahead_tokens += rp->num; - else - s->consistent = true; - - return n_lookahead_tokens; + s->consistent = + !(reds->num > 1 + || (reds->num == 1 && trans->num && TRANSITION_IS_SHIFT (trans, 0)) + || (reds->num == 1 && reds->rules[0]->number != 0 + && default_reduction_only_for_accept)); + + return s->consistent ? 0 : reds->num; } @@ -385,47 +523,58 @@ initialize_LA (void) static void lookahead_tokens_print (FILE *out) { - fprintf (out, "Lookahead tokens: BEGIN\n"); + fputs ("Lookaheads:\n", out); for (state_number i = 0; i < nstates; ++i) { const reductions *reds = states[i]->reductions; - int n_lookahead_tokens = 0; - - if (reds->lookahead_tokens) - for (int j = 0; j < reds->num; ++j) - if (reds->lookahead_tokens[j]) - ++n_lookahead_tokens; - - fprintf (out, "State %d: %d lookahead tokens\n", - i, n_lookahead_tokens); - - if (reds->lookahead_tokens) - for (int j = 0; j < reds->num; ++j) - { - bitset_iterator iter; - int k; - BITSET_FOR_EACH (iter, reds->lookahead_tokens[j], k, 0) - fprintf (out, " on %d (%s) -> rule %d\n", - k, symbols[k]->tag, - reds->rules[j]->number); - } + if (reds->num) + { + fprintf (out, " State %d:\n", i); + for (int j = 0; j < reds->num; ++j) + { + fprintf (out, " rule %d:", reds->rules[j]->number); + if (reds->lookahead_tokens) + { + bitset_iterator iter; + int k; + BITSET_FOR_EACH (iter, reds->lookahead_tokens[j], k, 0) + fprintf (out, " %s", symbols[k]->tag); + } + fputc ('\n', out); + } + } } - fprintf (out, "Lookahead tokens: END\n"); + fputc ('\n', out); } void lalr (void) { + if (trace_flag & trace_automaton) + { + fputc ('\n', stderr); + begin_use_class ("trace0", stderr); + fprintf (stderr, "lalr: begin"); + end_use_class ("trace0", stderr); + fputc ('\n', stderr); + } initialize_LA (); set_goto_map (); - initialize_F (); + initialize_goto_follows (); lookback = xcalloc (nLA, sizeof *lookback); build_relations (); - compute_FOLLOWS (); + compute_follows (); compute_lookahead_tokens (); if (trace_flag & trace_sets) lookahead_tokens_print (stderr); + if (trace_flag & trace_automaton) + { + begin_use_class ("trace0", stderr); + fprintf (stderr, "lalr: done"); + end_use_class ("trace0", stderr); + fputc ('\n', stderr); + } } diff --git a/contrib/tools/bison/src/lalr.h b/contrib/tools/bison/src/lalr.h index b06b3051ec1b..f94123a4bcba 100644 --- a/contrib/tools/bison/src/lalr.h +++ b/contrib/tools/bison/src/lalr.h @@ -1,7 +1,7 @@ /* Compute lookahead criteria for bison, Copyright (C) 1984, 1986, 1989, 2000, 2002, 2004, 2006-2007, - 2009-2015, 2018-2019 Free Software Foundation, Inc. + 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -83,8 +83,8 @@ typedef size_t goto_number; /** Index into #from_state and #to_state. All the transitions that accept a particular variable are grouped - together and GOTO_MAP[I - NTOKENS] is the index in FROM_STATE and - TO_STATE of the first of them. */ + together in FROM_STATE and TO_STATE, with indexes from GOTO_MAP[I - + NTOKENS] to GOTO_MAP[I - NTOKENS + 1] - 1 (including both). */ extern goto_number *goto_map; /** The size of #from_state and #to_state. */ @@ -96,11 +96,10 @@ extern state_number *from_state; /** State number it leads to. */ extern state_number *to_state; -/** Map a state/symbol pair into its numeric representation. */ -goto_number map_goto (state_number s0, symbol_number sym); +/** The number of the goto from state SRC labeled with nterm SYM. */ +goto_number map_goto (state_number src, symbol_number sym); /* goto_follows[i] is the set of tokens following goto i. */ extern bitsetv goto_follows; - #endif /* !LALR_H_ */ diff --git a/contrib/tools/bison/src/location.c b/contrib/tools/bison/src/location.c index 6876890c02a7..5631b10bfa94 100644 --- a/contrib/tools/bison/src/location.c +++ b/contrib/tools/bison/src/location.c @@ -1,6 +1,6 @@ /* Locations for Bison - Copyright (C) 2002, 2005-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2002, 2005-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -21,57 +21,99 @@ #include #include "system.h" +#include #include #include +#include /* fileno */ +#include +#include /* fstat */ +#include + +#ifdef WINSIZE_IN_PTEM +# include +# error #include +#endif #include "complain.h" +#include "getargs.h" #include "location.h" -location const empty_location = EMPTY_LOCATION_INIT; +location const empty_loc = EMPTY_LOCATION_INIT; -/* If BUF is null, add BUFSIZE (which in this case must be less than - INT_MAX) to COLUMN; otherwise, add mbsnwidth (BUF, BUFSIZE, 0) to - COLUMN. If an overflow occurs, or might occur but is undetectable, - return INT_MAX. Assume COLUMN is nonnegative. */ +static int +min_int (int a, int b) +{ + return a < b ? a : b; +} -static inline int -add_column_width (int column, char const *buf, size_t bufsize) +static int +max_int (int a, int b) { - size_t width; - unsigned remaining_columns = INT_MAX - column; + return a >= b ? a : b; +} - if (buf) +/* The terminal width. Not less than 40. */ +static int +columns (void) +{ + const char *cp = getenv ("COLUMNS"); + int res = 80; + if (cp && *cp) { - if (INT_MAX / 2 <= bufsize) - return INT_MAX; - width = mbsnwidth (buf, bufsize, 0); + long l = strtol (cp, NULL, 10); + res = 0 <= l && l <= INT_MAX ? l : INT_MAX; } else - width = bufsize; - - return width <= remaining_columns ? column + width : INT_MAX; + { +#ifdef TIOCGWINSZ + struct winsize ws; + if (ioctl (STDERR_FILENO, TIOCGWINSZ, &ws) != -1 + && 0 < ws.ws_col && ws.ws_col == (size_t) ws.ws_col) + res = ws.ws_col; +#endif + } + return max_int (res, 40); } -/* Set *LOC and adjust scanner cursor to account for token TOKEN of - size SIZE. */ +/* Available screen width. */ +static int screen_width = 80; -void -location_compute (location *loc, boundary *cur, char const *token, size_t size) +/* The ellipsis symbol to use for this locale, and the number of + screen-columns it uses. */ +static const char *ellipsis = "..."; +static int ellipsize = 3; + +/* If BUF is null, add BUFSIZE (which in this case must be less than + INT_MAX) to COLUMN; otherwise, add mbsnwidth (BUF, BUFSIZE, 0) to + COLUMN. If an overflow occurs, return INT_MAX. */ + +static inline int +add_column_width (int column, char const *buf, size_t bufsize) +{ + int width + = buf ? mbsnwidth (buf, bufsize, 0) + : INT_MAX <= bufsize ? INT_MAX + : bufsize; + return column <= INT_MAX - width ? column + width : INT_MAX; +} + +static void +boundary_compute (boundary *cur, char const *token, size_t size) { int line = cur->line; int column = cur->column; + int byte = cur->byte; char const *p0 = token; char const *p = token; char const *lim = token + size; - loc->start = *cur; - - for (p = token; p < lim; p++) + for (p = token; p < lim; ++p) switch (*p) { case '\n': line += line < INT_MAX; column = 1; + byte = 1; p0 = p + 1; break; @@ -79,59 +121,94 @@ location_compute (location *loc, boundary *cur, char const *token, size_t size) column = add_column_width (column, p0, p - p0); column = add_column_width (column, NULL, 8 - ((column - 1) & 7)); p0 = p + 1; + byte += byte < INT_MAX; break; default: + byte += byte < INT_MAX; break; } + column = add_column_width (column, p0, p - p0); cur->line = line; - cur->column = column = add_column_width (column, p0, p - p0); + cur->column = column; + cur->byte = byte; +} + + +/* Set *LOC and adjust scanner cursor to account for token TOKEN of + size SIZE. */ +void +location_compute (location *loc, boundary *cur, char const *token, size_t size) +{ + loc->start = *cur; + boundary_compute (cur, token, size); loc->end = *cur; - if (line == INT_MAX && loc->start.line != INT_MAX) + if (loc->end.line == INT_MAX && loc->start.line != INT_MAX) complain (loc, Wother, _("line number overflow")); - if (column == INT_MAX && loc->start.column != INT_MAX) + if (loc->end.column == INT_MAX && loc->start.column != INT_MAX) complain (loc, Wother, _("column number overflow")); + /* TRANSLATORS: we are counting bytes, and there are too many. */ + if (loc->end.byte == INT_MAX && loc->start.byte != INT_MAX) + complain (loc, Wother, _("byte number overflow")); } +static int +boundary_print (boundary const *b, FILE *out) +{ + return fprintf (out, "%s:%d.%d@%d", + quotearg_n_style (3, escape_quoting_style, b->file), + b->line, b->column, b->byte); +} -unsigned +int location_print (location loc, FILE *out) { - unsigned res = 0; - int end_col = 0 != loc.end.column ? loc.end.column - 1 : 0; - res += fprintf (out, "%s", - quotearg_n_style (3, escape_quoting_style, loc.start.file)); - if (0 <= loc.start.line) + int res = 0; + if (trace_flag & trace_locations) { - res += fprintf (out, ":%d", loc.start.line); - if (0 <= loc.start.column) - res += fprintf (out, ".%d", loc.start.column); + res += boundary_print (&loc.start, out); + res += fprintf (out, "-"); + res += boundary_print (&loc.end, out); } - if (loc.start.file != loc.end.file) + else { - res += fprintf (out, "-%s", - quotearg_n_style (3, escape_quoting_style, - loc.end.file)); - if (0 <= loc.end.line) + aver (loc.start.file); + aver (loc.end.file); + int end_col = 0 != loc.end.column ? loc.end.column - 1 : 0; + res += fprintf (out, "%s", + quotearg_n_style (3, escape_quoting_style, loc.start.file)); + if (0 < loc.start.line) { - res += fprintf (out, ":%d", loc.end.line); - if (0 <= end_col) - res += fprintf (out, ".%d", end_col); + res += fprintf (out, ":%d", loc.start.line); + if (0 < loc.start.column) + res += fprintf (out, ".%d", loc.start.column); } - } - else if (0 <= loc.end.line) - { - if (loc.start.line < loc.end.line) + if (loc.start.file != loc.end.file) { - res += fprintf (out, "-%d", loc.end.line); - if (0 <= end_col) - res += fprintf (out, ".%d", end_col); + res += fprintf (out, "-%s", + quotearg_n_style (3, escape_quoting_style, + loc.end.file)); + if (0 < loc.end.line) + { + res += fprintf (out, ":%d", loc.end.line); + if (0 <= end_col) + res += fprintf (out, ".%d", end_col); + } + } + else if (0 < loc.end.line) + { + if (loc.start.line < loc.end.line) + { + res += fprintf (out, "-%d", loc.end.line); + if (0 <= end_col) + res += fprintf (out, ".%d", end_col); + } + else if (0 <= end_col && loc.start.column < end_col) + res += fprintf (out, "-%d", end_col); } - else if (0 <= end_col && loc.start.column < end_col) - res += fprintf (out, "-%d", end_col); } return res; @@ -140,82 +217,300 @@ location_print (location loc, FILE *out) /* Persistent data used by location_caret to avoid reopening and rereading the same file all over for each error. */ -struct caret_info +static struct { - FILE *source; - size_t line; + /* Raw input file. */ + FILE *file; + /* Input file as a stream of multibyte characters. */ + mb_file_t mbfile; + /* The position within the last file we quoted. If POS.FILE is non + NULL, but FILE is NULL, it means this file is special and should + not be quoted. */ + boundary pos; + /* Offset in FILE of the current line (i.e., where line POS.LINE + starts). */ size_t offset; -}; - -static struct caret_info caret_info = { NULL, 1, 0 }; + /* Length of the current line. */ + int line_len; + /* Given the initial column to display, the offset (number of + characters to skip at the beginning of the line). */ + int skip; + + /* Available width to quote the source file. Eight chars are + consumed by the left-margin (with line number). */ + int width; +} caret_info; + +void caret_init (void) +{ + screen_width = columns (); + /* TRANSLATORS: This is used when a line is too long, and is + displayed truncated. Use an ellipsis appropriate for your + language, remembering that "…" (U+2026 HORIZONTAL ELLIPSIS) + sometimes misdisplays and that "..." (three ASCII periods) is a + safer choice in some locales. */ + ellipsis = _("..."); + ellipsize = mbswidth (ellipsis, 0); +} void -cleanup_caret () +caret_free (void) { - if (caret_info.source) - fclose (caret_info.source); - caret_info.source = NULL; - caret_info.line = 1; - caret_info.offset = 0; + if (caret_info.file) + { + fclose (caret_info.file); + caret_info.file = NULL; + } } -void -location_caret (location loc, FILE *out) +/* Open FILE for quoting, if needed, and if possible. Return whether + the file can quoted. */ +static bool +caret_set_file (const char *file) { - /* FIXME: find a way to support multifile locations, and only open once each - file. That would make the procedure future-proof. */ - if (! (caret_info.source - || (caret_info.source = fopen (loc.start.file, "r"))) - || loc.start.column == -1 || loc.start.line == -1) - return; + /* If a different file than before, close and let the rest open + the new one. */ + if (caret_info.pos.file && caret_info.pos.file != file) + { + caret_free (); + caret_info.pos.file = NULL; + } + if (!caret_info.pos.file) + { + caret_info.pos.file = file; + if ((caret_info.file = fopen (caret_info.pos.file, "r"))) + { + /* If the file is not regular (imagine #line 1 "/dev/stdin" + in the input file for instance), don't try to quote the + file. Keep caret_info.file set so that we don't try to + open it again, but leave caret_info.file NULL so that we + don't try to quote it. */ + struct stat buf; + if (fstat (fileno (caret_info.file), &buf) == 0 + && buf.st_mode & S_IFREG) + { + caret_info.pos.line = 1; + mbf_init (caret_info.mbfile, caret_info.file); + } + else + caret_free (); + } + } + return !!caret_info.file; +} + +/* Getc, but smash \r\n as \n. */ +static void +caret_getc_internal (mbchar_t *res) +{ + mbf_getc (*res, caret_info.mbfile); + if (mb_iseq (*res, '\r')) + { + mbchar_t c; + mbf_getc (c, caret_info.mbfile); + if (mb_iseq (c, '\n')) + mb_copy (res, &c); + else + mbf_ungetc (c, caret_info.mbfile); + } +} + +#define caret_getc(Var) caret_getc_internal(&Var) +/* Move CARET_INFO (which has a valid FILE) to the line number LINE. + Compute and cache that line's length in CARET_INFO.LINE_LEN. + Return whether successful. */ +static bool +caret_set_line (int line) +{ /* If the line we want to quote is seekable (the same line as the previous location), just seek it. If it was a previous line, we lost track of it, so return to the start of file. */ - if (caret_info.line <= loc.start.line) - fseek (caret_info.source, caret_info.offset, SEEK_SET); - else + if (line < caret_info.pos.line) { - caret_info.line = 1; + caret_info.pos.line = 1; caret_info.offset = 0; - fseek (caret_info.source, caret_info.offset, SEEK_SET); } + if (fseek (caret_info.file, caret_info.offset, SEEK_SET)) + return false; + + /* If this is the same line as the previous one, we are done. */ + if (line < caret_info.pos.line) + return true; /* Advance to the line's position, keeping track of the offset. */ - while (caret_info.line < loc.start.line) - caret_info.line += getc (caret_info.source) == '\n'; - caret_info.offset = ftell (caret_info.source); + while (caret_info.pos.line < line) + { + mbchar_t c; + caret_getc (c); + if (mb_iseof (c)) + /* Something is wrong, that line number does not exist. */ + return false; + caret_info.pos.line += mb_iseq (c, '\n'); + } + caret_info.offset = ftell (caret_info.file); + caret_info.pos.column = 1; + /* Reset mbf's internal state. + FIXME: should be done in mbfile. */ + caret_info.mbfile.eof_seen = 0; + + /* Find the number of columns of this line. */ + while (true) + { + mbchar_t c; + caret_getc (c); + if (mb_iseof (c) || mb_iseq (c, '\n')) + break; + boundary_compute (&caret_info.pos, mb_ptr (c), mb_len (c)); + } + caret_info.line_len = caret_info.pos.column; + /* Go back to the beginning of line. */ + if (fseek (caret_info.file, caret_info.offset, SEEK_SET)) + return false; + /* Reset mbf's internal state. + FIXME: should be done in mbfile. */ + caret_info.mbfile.eof_seen = 0; + caret_info.pos.column = 1; + return true; +} + +/* Compute CARET_INFO.WIDTH and CARET_INFO.SKIP based on the fact that + the first column to display in the current line is COL. */ +static bool +caret_set_column (int col) +{ + /* Available width. Eight chars are consumed by the left-margin + (with line number). */ + caret_info.width = screen_width - 8; + caret_info.skip = 0; + if (caret_info.width < caret_info.line_len) + { + /* We cannot quote the whole line. Make sure we can see the + beginning of the location. */ + caret_info.skip = caret_info.width < col ? col - 10 : 0; + } + /* If we skip the initial part, we insert "..." before. */ + if (caret_info.skip) + caret_info.width -= ellipsize; + /* If the end of line does not fit, we also need to truncate the + end, and leave "..." there. */ + if (caret_info.width < caret_info.line_len - caret_info.skip) + caret_info.width -= ellipsize; + return true; +} + +void +location_caret (location loc, const char *style, FILE *out) +{ + if (!loc.start.line) + return; + if (!caret_set_file (loc.start.file)) + return; + if (!caret_set_line (loc.start.line)) + return; + if (!caret_set_column (loc.start.column)) + return; + + const int width = caret_info.width; + const int skip = caret_info.skip; /* Read the actual line. Don't update the offset, so that we keep a pointer to the start of the line. */ { - int c = getc (caret_info.source); - if (c != EOF) + mbchar_t c; + caret_getc (c); + if (!mb_iseof (c)) { - /* Quote the file, indent by a single column. */ - putc (' ', out); - do - putc (c, out); - while ((c = getc (caret_info.source)) != EOF && c != '\n'); - putc ('\n', out); + /* The last column to highlight. Only the first line of + multiline locations are quoted, in which case the ending + column is the end of line. + + We used to work with byte offsets, and that was much + easier. However, we went back to using (visual) columns to + support truncating of long lines. */ + const int col_end + = loc.start.line == loc.end.line + ? loc.end.column + : caret_info.line_len; + /* Quote the file (at most the first line in the case of + multiline locations). */ + { + fprintf (out, "%5d | %s", loc.start.line, skip ? ellipsis : ""); + /* Whether we opened the style. If the line is not as + expected (maybe the file was changed since the scanner + ran), we might reach the end before we actually saw the + opening column. */ + enum { before, inside, after } state = before; + while (!mb_iseof (c) && !mb_iseq (c, '\n')) + { + // We might have already opened (and even closed!) the + // style and yet have the equality of the columns if we + // just saw zero-width characters. + if (state == before + && caret_info.pos.column == loc.start.column) + { + begin_use_class (style, out); + state = inside; + } + if (skip < caret_info.pos.column) + mb_putc (c, out); + boundary_compute (&caret_info.pos, mb_ptr (c), mb_len (c)); + caret_getc (c); + if (state == inside + && (caret_info.pos.column == col_end + || width < caret_info.pos.column - skip)) + { + end_use_class (style, out); + state = after; + } + if (width < caret_info.pos.column - skip) + { + fputs (ellipsis, out); + break; + } + } + if (state == inside) + { + // The line is shorter than expected. + end_use_class (style, out); + state = after; + } + putc ('\n', out); + } + /* Print the carets with the same indentation as above. */ { - /* The caret of a multiline location ends with the first line. */ - size_t len = loc.start.line != loc.end.line - ? ftell (caret_info.source) - caret_info.offset - : loc.end.column; - int i; - - /* Print the carets (at least one), with the same indent as above.*/ - fprintf (out, " %*s", loc.start.column - 1, ""); - for (i = loc.start.column; i == loc.start.column || i < len; ++i) - putc (i == loc.start.column ? '^' : '~', out); - } - putc ('\n', out); + fprintf (out, " | %*s", + loc.start.column - 1 - skip + (skip ? ellipsize : 0), ""); + begin_use_class (style, out); + putc ('^', out); + /* Underlining a multiline location ends with the first + line. */ + for (int i = loc.start.column - 1 - skip + 1, + i_end = min_int (col_end - 1 - skip, width); + i < i_end; ++i) + putc ('~', out); + end_use_class (style, out); + putc ('\n', out); + } } } } +void +location_caret_suggestion (location loc, const char *s, FILE *out) +{ + const char *style = "fixit-insert"; + fprintf (out, " | %*s", + loc.start.column - 1 - caret_info.skip + + (caret_info.skip ? ellipsize : 0), + ""); + begin_use_class (style, out); + fputs (s, out); + end_use_class (style, out); + putc ('\n', out); +} + bool location_empty (location loc) { @@ -224,17 +519,29 @@ location_empty (location loc) } void -boundary_set_from_string (boundary *bound, char *loc_str) -{ - /* Must search in reverse since the file name field may - * contain '.' or ':'. */ - char *delim = strrchr (loc_str, '.'); - aver (delim); - *delim = '\0'; - bound->column = atoi (delim+1); - delim = strrchr (loc_str, ':'); - aver (delim); - *delim = '\0'; - bound->line = atoi (delim+1); - bound->file = uniqstr_new (loc_str); +boundary_set_from_string (boundary *bound, char *str) +{ + /* Must search in reverse since the file name field may contain '.' + or ':'. */ + char *at = strrchr (str, '@'); + if (at) + { + *at = '\0'; + bound->byte = atoi (at+1); + } + { + char *dot = strrchr (str, '.'); + aver (dot); + *dot = '\0'; + bound->column = atoi (dot+1); + if (!at) + bound->byte = bound->column; + } + { + char *colon = strrchr (str, ':'); + aver (colon); + *colon = '\0'; + bound->line = atoi (colon+1); + } + bound->file = uniqstr_new (str); } diff --git a/contrib/tools/bison/src/location.h b/contrib/tools/bison/src/location.h index 39e0507d967c..cb3025c6a830 100644 --- a/contrib/tools/bison/src/location.h +++ b/contrib/tools/bison/src/location.h @@ -1,6 +1,6 @@ /* Locations for Bison - Copyright (C) 2002, 2004-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2002, 2004-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -33,31 +33,35 @@ typedef struct /* The name of the file that contains the boundary. */ uniqstr file; - /* If nonnegative, the (origin-1) line that contains the boundary. + /* If positive, the line (starting at 1) that contains the boundary. If this is INT_MAX, the line number has overflowed. - Meaningless and not displayed if negative. + Meaningless and not displayed if nonpositive. */ int line; - /* If nonnegative, the (origin-1) column just after the boundary. + /* If positive, the column (starting at 1) just after the boundary. This is neither a byte count, nor a character count; it is a - column count. If this is INT_MAX, the column number has + (visual) column count. If this is INT_MAX, the column number has overflowed. - Meaningless and not displayed if negative. - */ + Meaningless and not displayed if nonpositive. */ int column; + /* If nonnegative, the byte number (starting at 0) in the current + line. Not displayed (unless --trace=location). */ + int byte; + } boundary; -/* Set the position of \a a. */ +/* Set the position of \a p. */ static inline void -boundary_set (boundary *b, const char *f, int l, int c) +boundary_set (boundary *p, const char *f, int l, int c, int b) { - b->file = f; - b->line = l; - b->column = c; + p->file = f; + p->line = l; + p->column = c; + p->byte = b; } /* Return -1, 0, 1, depending whether a is before, equal, or @@ -65,7 +69,12 @@ boundary_set (boundary *b, const char *f, int l, int c) static inline int boundary_cmp (boundary a, boundary b) { - int res = strcmp (a.file, b.file); + /* Locations with no file first. */ + int res = + a.file && b.file ? strcmp (a.file, b.file) + : a.file ? 1 + : b.file ? -1 + : 0; if (!res) res = a.line - b.line; if (!res) @@ -95,8 +104,8 @@ typedef struct # define GRAM_LTYPE location -# define EMPTY_LOCATION_INIT {{NULL, 0, 0}, {NULL, 0, 0}} -extern location const empty_location; +# define EMPTY_LOCATION_INIT {{NULL, 0, 0, 0}, {NULL, 0, 0, 0}} +extern location const empty_loc; /* Set *LOC and adjust scanner cursor to account for token TOKEN of size SIZE. */ @@ -106,14 +115,22 @@ void location_compute (location *loc, /* Print location to file. Return number of actually printed characters. Warning: uses quotearg's slot 3. */ -unsigned location_print (location loc, FILE *out); +int location_print (location loc, FILE *out); + +/* Prepare the use of location_caret. */ +void caret_init (void); /* Free any allocated resources and close any open file handles that are left-over by the usage of location_caret. */ -void cleanup_caret (void); +void caret_free (void); + +/* Quote the line containing LOC onto OUT. Highlight the part of LOC + with the color STYLE. */ +void location_caret (location loc, const char* style, FILE *out); -/* Output to OUT the line and caret corresponding to location LOC. */ -void location_caret (location loc, FILE *out); +/* Display a suggestion of replacement for LOC with S. To call after + location_caret. */ +void location_caret_suggestion (location loc, const char *s, FILE *out); /* Return -1, 0, 1, depending whether a is before, equal, or after b. */ @@ -129,7 +146,8 @@ location_cmp (location a, location b) /* Whether this is the empty location. */ bool location_empty (location loc); -/* LOC_STR must be formatted as 'file:line.column', it will be modified. */ -void boundary_set_from_string (boundary *bound, char *loc_str); +/* STR must be formatted as 'file:line.column@byte' or 'file:line.column', + it will be modified. */ +void boundary_set_from_string (boundary *bound, char *str); #endif /* ! defined LOCATION_H_ */ diff --git a/contrib/tools/bison/src/LR0.c b/contrib/tools/bison/src/lr0.c similarity index 70% rename from contrib/tools/bison/src/LR0.c rename to contrib/tools/bison/src/lr0.c index d977d3645581..2ebdcf8a4dc4 100644 --- a/contrib/tools/bison/src/LR0.c +++ b/contrib/tools/bison/src/lr0.c @@ -1,6 +1,6 @@ /* Generate the LR(0) parser states for Bison. - Copyright (C) 1984, 1986, 1989, 2000-2002, 2004-2015, 2018-2019 Free + Copyright (C) 1984, 1986, 1989, 2000-2002, 2004-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -27,12 +27,12 @@ #include -#include "LR0.h" #include "closure.h" #include "complain.h" #include "getargs.h" #include "gram.h" #include "lalr.h" +#include "lr0.h" #include "reader.h" #include "reduce.h" #include "state.h" @@ -47,24 +47,35 @@ typedef struct state_list static state_list *first_state = NULL; static state_list *last_state = NULL; +/* Print CORE for debugging. */ +static void +core_print (size_t core_size, item_number *core, FILE *out) +{ + for (int i = 0; i < core_size; ++i) + { + item_print (ritem + core[i], NULL, out); + fputc ('\n', out); + } +} -/*------------------------------------------------------------------. -| A state was just discovered from another state. Queue it for | -| later examination, in order to find its transitions. Return it. | -`------------------------------------------------------------------*/ +/*-----------------------------------------------------------------. +| A state was just discovered by transitioning on SYM from another | +| state. Queue this state for later examination, in order to find | +| its outgoing transitions. Return it. | +`-----------------------------------------------------------------*/ static state * state_list_append (symbol_number sym, size_t core_size, item_number *core) { state_list *node = xmalloc (sizeof *node); - state *s = state_new (sym, core_size, core); + state *res = state_new (sym, core_size, core); if (trace_flag & trace_automaton) fprintf (stderr, "state_list_append (state = %d, symbol = %d (%s))\n", nstates, sym, symbols[sym]->tag); node->next = NULL; - node->state = s; + node->state = res; if (!first_state) first_state = node; @@ -72,17 +83,28 @@ state_list_append (symbol_number sym, size_t core_size, item_number *core) last_state->next = node; last_state = node; - return s; + return res; } -static int nshifts; -static symbol_number *shift_symbol; +/* Symbols that can be "shifted" (including non terminals) from the + current state. */ +bitset shift_symbol; static rule **redset; +/* For the current state, the list of pointers to states that can be + reached via a shift/goto. Could be indexed by the reaching symbol, + but labels of incoming transitions can be recovered by the state + itself. */ static state **shiftset; + +/* KERNEL_BASE[symbol-number] -> list of item numbers (offsets inside + RITEM) of length KERNEL_SIZE[symbol-number]. */ static item_number **kernel_base; static int *kernel_size; + +/* A single dimension array that serves as storage for + KERNEL_BASE. */ static item_number *kernel_items; @@ -98,10 +120,11 @@ allocate_itemsets (void) sizeof *symbol_count); for (rule_number r = 0; r < nrules; ++r) - for (item_number *rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) + for (item_number *rhsp = rules[r].rhs; 0 <= *rhsp; ++rhsp) { - count++; - symbol_count[*rhsp]++; + symbol_number sym = item_number_as_symbol_number (*rhsp); + count += 1; + symbol_count[sym] += 1; } /* See comments before new_itemsets. All the vectors of items @@ -124,6 +147,25 @@ allocate_itemsets (void) kernel_size = xnmalloc (nsyms, sizeof *kernel_size); } +/* Print the current kernel (in KERNEL_BASE). */ +static void +kernel_print (FILE *out) +{ + for (symbol_number i = 0; i < nsyms; ++i) + if (kernel_size[i]) + { + fprintf (out, "kernel[%s] =\n", symbols[i]->tag); + core_print (kernel_size[i], kernel_base[i], out); + } +} + +/* Make sure the kernel is in sane state. */ +static void +kernel_check (void) +{ + for (symbol_number i = 0; i < nsyms - 1; ++i) + assert (kernel_base[i] + kernel_size[i] <= kernel_base[i + 1]); +} static void allocate_storage (void) @@ -133,14 +175,14 @@ allocate_storage (void) shiftset = xnmalloc (nsyms, sizeof *shiftset); redset = xnmalloc (nrules, sizeof *redset); state_hash_new (); - shift_symbol = xnmalloc (nsyms, sizeof *shift_symbol); + shift_symbol = bitset_create (nsyms, BITSET_FIXED); } static void free_storage (void) { - free (shift_symbol); + bitset_free (shift_symbol); free (redset); free (shiftset); free (kernel_base); @@ -152,44 +194,58 @@ free_storage (void) -/*---------------------------------------------------------------. -| Find which symbols can be shifted in S, and for each one | -| record which items would be active after that shift. Uses the | -| contents of itemset. | -| | -| shift_symbol is set to a vector of the symbols that can be | -| shifted. For each symbol in the grammar, kernel_base[symbol] | -| points to a vector of item numbers activated if that symbol is | -| shifted, and kernel_size[symbol] is their numbers. | -| | -| itemset is sorted on item index in ritem, which is sorted on | -| rule number. Compute each kernel_base[symbol] with the same | -| sort. | -`---------------------------------------------------------------*/ +/*------------------------------------------------------------------. +| Find which term/nterm symbols can be "shifted" in S, and for each | +| one record which items would be active after that transition. | +| Uses the contents of itemset. | +| | +| shift_symbol is a bitset of the term/nterm symbols that can be | +| shifted. For each symbol in the grammar, kernel_base[symbol] | +| points to a vector of item numbers activated if that symbol is | +| shifted, and kernel_size[symbol] is their numbers. | +| | +| itemset is sorted on item index in ritem, which is sorted on rule | +| number. Compute each kernel_base[symbol] with the same sort. | +`------------------------------------------------------------------*/ static void new_itemsets (state *s) { if (trace_flag & trace_automaton) - fprintf (stderr, "Entering new_itemsets, state = %d\n", s->number); + fprintf (stderr, "new_itemsets: begin: state = %d\n", s->number); memset (kernel_size, 0, nsyms * sizeof *kernel_size); - nshifts = 0; + bitset_zero (shift_symbol); + + if (trace_flag & trace_automaton) + { + fprintf (stderr, "initial kernel:\n"); + kernel_print (stderr); + } for (size_t i = 0; i < nitemset; ++i) if (item_number_is_symbol_number (ritem[itemset[i]])) { - symbol_number sym = item_number_as_symbol_number (ritem[itemset[i]]); - if (!kernel_size[sym]) + if (trace_flag & trace_automaton) { - shift_symbol[nshifts] = sym; - nshifts++; + fputs ("working on: ", stderr); + item_print (ritem + itemset[i], NULL, stderr); + fputc ('\n', stderr); } - + symbol_number sym = item_number_as_symbol_number (ritem[itemset[i]]); + bitset_set (shift_symbol, sym); kernel_base[sym][kernel_size[sym]] = itemset[i] + 1; kernel_size[sym]++; } + + if (trace_flag & trace_automaton) + { + fprintf (stderr, "final kernel:\n"); + kernel_print (stderr); + fprintf (stderr, "new_itemsets: end: state = %d\n\n", s->number); + } + kernel_check (); } @@ -204,8 +260,12 @@ static state * get_state (symbol_number sym, size_t core_size, item_number *core) { if (trace_flag & trace_automaton) - fprintf (stderr, "Entering get_state, symbol = %d (%s)\n", - sym, symbols[sym]->tag); + { + fprintf (stderr, "Entering get_state, symbol = %d (%s), core:\n", + sym, symbols[sym]->tag); + core_print (core_size, core, stderr); + fputc ('\n', stderr); + } state *s = state_hash_lookup (core_size, core); if (!s) @@ -228,24 +288,19 @@ static void append_states (state *s) { if (trace_flag & trace_automaton) - fprintf (stderr, "Entering append_states, state = %d\n", s->number); + fprintf (stderr, "append_states: begin: state = %d\n", s->number); - /* First sort shift_symbol into increasing order. */ - - for (int i = 1; i < nshifts; i++) - { - const symbol_number sym = shift_symbol[i]; - int j = i; - for (; 0 < j && sym < shift_symbol[j - 1]; j--) - shift_symbol[j] = shift_symbol[j - 1]; - shift_symbol[j] = sym; - } - - for (int i = 0; i < nshifts; i++) + bitset_iterator iter; + symbol_number sym; + int i = 0; + BITSET_FOR_EACH (iter, shift_symbol, sym, 0) { - const symbol_number sym = shift_symbol[i]; shiftset[i] = get_state (sym, kernel_size[sym], kernel_base[sym]); + ++i; } + + if (trace_flag & trace_automaton) + fprintf (stderr, "append_states: end: state = %d\n", s->number); } @@ -277,6 +332,17 @@ save_reductions (state *s) } } + if (trace_flag & trace_automaton) + { + fprintf (stderr, "reduction[%d] = {\n", s->number); + for (int i = 0; i < count; ++i) + { + rule_print (redset[i], NULL, stderr); + fputc ('\n', stderr); + } + fputs ("}\n", stderr); + } + /* Make a reductions structure and copy the data into it. */ state_reductions_set (s, count, redset); } @@ -324,7 +390,7 @@ void generate_states (void) { allocate_storage (); - new_closure (nritems); + closure_new (nritems); /* Create the initial state. The 0 at the lhs is the index of the item of this initial rule. */ @@ -344,18 +410,17 @@ generate_states (void) closure (s->items, s->nitems); /* Record the reductions allowed out of this state. */ save_reductions (s); - /* Find the itemsets of the states that shifts can reach. */ + /* Find the itemsets of the states that shifts/gotos can reach. */ new_itemsets (s); /* Find or create the core structures for those states. */ append_states (s); /* Create the shifts structures for the shifts to those states, now that the state numbers transitioning to are known. */ - state_transitions_set (s, nshifts, shiftset); + state_transitions_set (s, bitset_count (shift_symbol), shiftset); } /* discard various storage */ - free_closure (); free_storage (); /* Set up STATES. */ diff --git a/contrib/tools/bison/src/LR0.h b/contrib/tools/bison/src/lr0.h similarity index 96% rename from contrib/tools/bison/src/LR0.h rename to contrib/tools/bison/src/lr0.h index 3197ee905524..31366dbdea7f 100644 --- a/contrib/tools/bison/src/LR0.h +++ b/contrib/tools/bison/src/lr0.h @@ -1,6 +1,6 @@ /* Generate the LR(0) parser states for Bison. - Copyright (C) 1984, 1986, 1989, 2000-2002, 2009-2015, 2018-2019 Free + Copyright (C) 1984, 1986, 1989, 2000-2002, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -21,8 +21,6 @@ #ifndef LR0_H_ # define LR0_H_ -# include "state.h" - void generate_states (void); #endif /* !LR0_H_ */ diff --git a/contrib/tools/bison/src/main.c b/contrib/tools/bison/src/main.c index 164712f484e7..9b9374278763 100644 --- a/contrib/tools/bison/src/main.c +++ b/contrib/tools/bison/src/main.c @@ -1,7 +1,7 @@ /* Top level entry point of Bison. Copyright (C) 1984, 1986, 1989, 1992, 1995, 2000-2002, 2004-2015, - 2018-2019 Free Software Foundation, Inc. + 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -23,14 +23,14 @@ #include #include +#include #include #include +#include #include #include /* relocate2 */ #include -#include "LR0.h" -#include "closeout.h" #include "complain.h" #include "conflicts.h" #include "derives.h" @@ -38,15 +38,15 @@ #include "fixits.h" #include "getargs.h" #include "gram.h" -#include "lalr.h" #include "ielr.h" +#include "lalr.h" +#include "lr0.h" #include "muscle-tab.h" #include "nullable.h" #include "output.h" -#include "print.h" -#include "print_graph.h" +#include "print-graph.h" #include "print-xml.h" -#include +#include "print.h" #include "reader.h" #include "reduce.h" #include "scan-code.h" @@ -92,7 +92,7 @@ main (int argc, char *argv[]) the grammar; see gram.h. */ timevar_push (tv_reader); - reader (); + reader (grammar_file); timevar_pop (tv_reader); if (complaint_status == status_complaint) @@ -147,7 +147,10 @@ main (int argc, char *argv[]) print_precedence_warnings (); - if (!update_flag) + /* Whether to generate output files. */ + bool generate = !(feature_flag & feature_syntax_only); + + if (generate) { /* Output file names. */ compute_output_file_names (); @@ -188,13 +191,15 @@ main (int argc, char *argv[]) timevar_pop (tv_free); /* Output the tables and the parser to ftable. In file output. */ - if (!update_flag) + if (generate) { timevar_push (tv_parser); output (); timevar_pop (tv_parser); } + finish: + timevar_push (tv_free); nullable_free (); derives_free (); @@ -211,20 +216,15 @@ main (int argc, char *argv[]) muscle_free (); code_scanner_free (); skel_scanner_free (); - quotearg_free (); timevar_pop (tv_free); if (trace_flag & trace_bitsets) bitset_stats_dump (stderr); - finish: - /* Stop timing and print the times. */ timevar_stop (tv_total); timevar_print (stderr); - cleanup_caret (); - /* Fix input file now, even if there are errors: that's less warnings in the following runs. */ if (!fixits_empty ()) @@ -238,5 +238,8 @@ main (int argc, char *argv[]) } uniqstrs_free (); + complain_free (); + quotearg_free (); + return complaint_status ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/contrib/tools/bison/src/muscle-tab.c b/contrib/tools/bison/src/muscle-tab.c index 8a1b00fc638c..5778b8f31944 100644 --- a/contrib/tools/bison/src/muscle-tab.c +++ b/contrib/tools/bison/src/muscle-tab.c @@ -1,6 +1,6 @@ /* Muscle table manager for Bison. - Copyright (C) 2001-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -21,13 +21,13 @@ #include "system.h" #include +#include #include "complain.h" #include "files.h" #include "fixits.h" #include "getargs.h" #include "muscle-tab.h" -#include "quote.h" muscle_kind muscle_kind_new (char const *k) @@ -126,8 +126,8 @@ muscle_init (void) /* Initialize the muscle obstack. */ obstack_init (&muscle_obstack); - muscle_table = hash_initialize (HT_INITIAL_CAPACITY, NULL, hash_muscle, - hash_compare_muscles, muscle_entry_free); + muscle_table = hash_xinitialize (HT_INITIAL_CAPACITY, NULL, hash_muscle, + hash_compare_muscles, muscle_entry_free); /* Version and input file. */ MUSCLE_INSERT_STRING ("version", VERSION); @@ -211,7 +211,7 @@ muscle_syncline_grow (char const *key, location loc) obstack_printf (&muscle_obstack, "]b4_syncline(%d, ", loc.start.line); obstack_quote (&muscle_obstack, quotearg_style (c_quoting_style, loc.start.file)); - obstack_sgrow (&muscle_obstack, ")["); + obstack_sgrow (&muscle_obstack, ")dnl\n["); char const *extension = obstack_finish0 (&muscle_obstack); muscle_grow (key, extension, "", ""); obstack_free (&muscle_obstack, extension); @@ -227,7 +227,7 @@ void muscle_code_grow (const char *key, const char *val, location loc) { muscle_syncline_grow (key, loc); - muscle_grow (key, val, "\n", "\n"); + muscle_grow (key, val, "", "\n"); } @@ -275,18 +275,14 @@ muscle_boundary_grow (char const *key, boundary bound) { obstack_sgrow (&muscle_obstack, "[["); obstack_escape (&muscle_obstack, bound.file); - obstack_printf (&muscle_obstack, ":%d.%d]]", bound.line, bound.column); + obstack_printf (&muscle_obstack, ":%d.%d@@%d]]", bound.line, bound.column, bound.byte); char const *extension = obstack_finish0 (&muscle_obstack); muscle_grow (key, extension, "", ""); obstack_free (&muscle_obstack, extension); } -/* In the format '[[file_name:line.column]], [[file_name:line.column]]', - append LOC to MUSCLE. Use digraphs for special characters in each - file name. */ - -static void +void muscle_location_grow (char const *key, location loc) { muscle_boundary_grow (key, loc.start); @@ -296,7 +292,6 @@ muscle_location_grow (char const *key, location loc) #define COMMON_DECODE(Value) \ case '$': \ - ++(Value); aver (*(Value) == '['); \ ++(Value); aver (*(Value) == ']'); \ ++(Value); aver (*(Value) == '['); \ obstack_sgrow (&muscle_obstack, "$"); \ @@ -529,7 +524,7 @@ muscle_percent_define_insert (char const *var, location variable_loc, = atoi (muscle_find_const (how_name)); if (how_old == MUSCLE_PERCENT_DEFINE_F) goto end; - unsigned i = 0; + int i = 0; /* If assigning the same value, make it a warning. */ warnings warn = STREQ (value, current_value) ? Wother : complaint; complain_indent (&variable_loc, warn, &i, @@ -630,17 +625,17 @@ muscle_percent_define_check_kind (char const *variable, muscle_kind kind) { case muscle_code: complain (&loc, Wdeprecated, - "%%define variable '%s' requires '{...}' values", + _("%%define variable '%s' requires '{...}' values"), variable); break; case muscle_keyword: complain (&loc, Wdeprecated, - "%%define variable '%s' requires keyword values", + _("%%define variable '%s' requires keyword values"), variable); break; case muscle_string: complain (&loc, Wdeprecated, - "%%define variable '%s' requires '\"...\"' values", + _("%%define variable '%s' requires '\"...\"' values"), variable); break; } @@ -714,9 +709,11 @@ muscle_percent_define_default (char const *variable, char const *value) { uniqstr loc_name = muscle_name (variable, "loc"); location loc; - loc.start.file = loc.end.file = ""; - loc.start.line = loc.end.line = -1; - loc.start.column = loc.end.column = -1; + loc.start.file = ""; + loc.start.line = -1; + loc.start.column = -1; + loc.start.byte = -1; + loc.end = loc.start; muscle_insert (loc_name, ""); muscle_location_grow (loc_name, loc); } @@ -741,7 +738,7 @@ muscle_percent_define_check_values (char const * const *values) if (!*values) { location loc = muscle_percent_define_get_loc (*variablep); - unsigned i = 0; + int i = 0; complain_indent (&loc, complaint, &i, _("invalid value for %%define variable %s: %s"), quote (*variablep), quote_n (1, value)); diff --git a/contrib/tools/bison/src/muscle-tab.h b/contrib/tools/bison/src/muscle-tab.h index 70c45db57c7a..a0dd2020a52f 100644 --- a/contrib/tools/bison/src/muscle-tab.h +++ b/contrib/tools/bison/src/muscle-tab.h @@ -1,6 +1,6 @@ /* Muscle table manager for Bison, - Copyright (C) 2001-2003, 2006-2015, 2018-2019 Free Software + Copyright (C) 2001-2003, 2006-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -119,6 +119,11 @@ void muscle_pair_list_grow (const char *muscle, void muscle_user_name_list_grow (char const *key, char const *user_name, location loc); +/* In the format '[[file_name:line.column]], [[file_name:line.column]]', + append LOC to MUSCLE. Use digraphs for special characters in each + file name. */ +void muscle_location_grow (char const *key, location loc); + /* Indicates whether a variable's value was specified with -D/--define, with -F/--force-define, or in the grammar file. */ typedef enum { diff --git a/contrib/tools/bison/src/named-ref.c b/contrib/tools/bison/src/named-ref.c index b9f49c4f6353..6e639ac221f6 100644 --- a/contrib/tools/bison/src/named-ref.c +++ b/contrib/tools/bison/src/named-ref.c @@ -1,6 +1,6 @@ /* Named symbol references for Bison - Copyright (C) 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/src/named-ref.h b/contrib/tools/bison/src/named-ref.h index bc9f99fac3cc..250c713fa8b2 100644 --- a/contrib/tools/bison/src/named-ref.h +++ b/contrib/tools/bison/src/named-ref.h @@ -1,6 +1,6 @@ /* Named symbol references for Bison - Copyright (C) 2009-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/src/nullable.c b/contrib/tools/bison/src/nullable.c index 7d6cf9c88541..453b4e596be2 100644 --- a/contrib/tools/bison/src/nullable.c +++ b/contrib/tools/bison/src/nullable.c @@ -1,6 +1,6 @@ /* Calculate which nonterminals can expand into the null string for Bison. - Copyright (C) 1984, 1989, 2000-2006, 2009-2015, 2018-2019 Free + Copyright (C) 1984, 1989, 2000-2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/src/nullable.h b/contrib/tools/bison/src/nullable.h index 60caf3db2214..236c50541d5f 100644 --- a/contrib/tools/bison/src/nullable.h +++ b/contrib/tools/bison/src/nullable.h @@ -1,6 +1,6 @@ /* Part of the bison parser generator, - Copyright (C) 2000, 2002, 2009-2015, 2018-2019 Free Software + Copyright (C) 2000, 2002, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/src/output.c b/contrib/tools/bison/src/output.c index 10a6d38a7ad5..5eccea4941e0 100644 --- a/contrib/tools/bison/src/output.c +++ b/contrib/tools/bison/src/output.c @@ -1,6 +1,6 @@ /* Output the generated parsing program for Bison. - Copyright (C) 1984, 1986, 1989, 1992, 2000-2015, 2018-2019 Free + Copyright (C) 1984, 1986, 1989, 1992, 2000-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -21,12 +21,10 @@ #include #include "system.h" -#include #include /* IS_PATH_WITH_DIR */ #include #include #include -#include /* relocate2 */ #include #include #include @@ -44,29 +42,8 @@ #include "symtab.h" #include "tables.h" -#include "uniqstr.h" - -#include - -#define STR(a) XSTR(a) -#define XSTR(a) #a - -const char* -default_pkgdatadir() -{ - const char* arc_path = getenv("ARCADIA_ROOT_DISTBUILD"); - if (arc_path == NULL) - arc_path = ArcadiaRoot(); - return uniqstr_concat(3, arc_path, "/", STR(BISON_DATA_DIR)); -} -#undef PKGDATADIR -#define PKGDATADIR (default_pkgdatadir()) - static struct obstack format_obstack; -/* Memory allocated by relocate2, to free. */ -static char *relocate_buffer = NULL; - /*-------------------------------------------------------------------. | Create a function NAME which associates to the muscle NAME the | @@ -114,7 +91,6 @@ Name (char const *name, Type *table_data, Type first, \ MUSCLE_INSERT_LONG_INT (obstack_finish0 (&format_obstack), lmax); \ } -GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_unsigned_table, unsigned) GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_int_table, int) GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_base_table, base_number) GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_rule_number_table, rule_number) @@ -156,9 +132,8 @@ string_output (FILE *out, char const *string) } -/*----------------------------. -| Prepare the symbols names. | -`----------------------------*/ +/* Generate the b4_ (e.g., b4_tname) table with the + symbol names (aka tags). */ static void prepare_symbol_names (char const *muscle_name) @@ -238,17 +213,17 @@ prepare_symbols (void) static void prepare_rules (void) { - unsigned *prhs = xnmalloc (nrules, sizeof *prhs); + int *prhs = xnmalloc (nrules, sizeof *prhs); item_number *rhs = xnmalloc (nritems, sizeof *rhs); - unsigned *rline = xnmalloc (nrules, sizeof *rline); + int *rline = xnmalloc (nrules, sizeof *rline); symbol_number *r1 = xnmalloc (nrules, sizeof *r1); - unsigned *r2 = xnmalloc (nrules, sizeof *r2); + int *r2 = xnmalloc (nrules, sizeof *r2); int *dprec = xnmalloc (nrules, sizeof *dprec); int *merger = xnmalloc (nrules, sizeof *merger); int *immediate = xnmalloc (nrules, sizeof *immediate); /* Index in RHS. */ - unsigned i = 0; + int i = 0; for (rule_number r = 0; r < nrules; ++r) { /* Index of rule R in RHS. */ @@ -275,10 +250,10 @@ prepare_rules (void) aver (i == nritems); muscle_insert_item_number_table ("rhs", rhs, ritem[0], 1, nritems); - muscle_insert_unsigned_table ("prhs", prhs, 0, 0, nrules); - muscle_insert_unsigned_table ("rline", rline, 0, 0, nrules); + muscle_insert_int_table ("prhs", prhs, 0, 0, nrules); + muscle_insert_int_table ("rline", rline, 0, 0, nrules); muscle_insert_symbol_number_table ("r1", r1, 0, 0, nrules); - muscle_insert_unsigned_table ("r2", r2, 0, 0, nrules); + muscle_insert_int_table ("r2", r2, 0, 0, nrules); muscle_insert_int_table ("dprec", dprec, 0, 0, nrules); muscle_insert_int_table ("merger", merger, 0, 0, nrules); muscle_insert_int_table ("immediate", immediate, 0, 0, nrules); @@ -383,9 +358,9 @@ symbol_numbers_output (FILE *out) } -/*---------------------------------. -| Output the user actions to OUT. | -`---------------------------------*/ +/*-------------------------------------------. +| Output the user reduction actions to OUT. | +`-------------------------------------------*/ static void user_actions_output (FILE *out) @@ -394,11 +369,20 @@ user_actions_output (FILE *out) for (rule_number r = 0; r < nrules; ++r) if (rules[r].action) { - fprintf (out, "%s(%d, [b4_syncline(%d, ", + /* The useless "" is there to pacify syntax-check. */ + fprintf (out, "%s""(%d, [", rules[r].is_predicate ? "b4_predicate_case" : "b4_case", - r + 1, rules[r].action_location.start.line); - string_output (out, rules[r].action_location.start.file); - fprintf (out, ")\n[ %s]])\n\n", rules[r].action); + r + 1); + if (!no_lines_flag) + { + fprintf (out, "b4_syncline(%d, ", + rules[r].action_loc.start.line); + string_output (out, rules[r].action_loc.start.file); + fprintf (out, ")dnl\n"); + } + fprintf (out, "[%*s%s]])\n\n", + rules[r].action_loc.start.column - 1, "", + rules[r].action); } fputs ("])\n\n", out); } @@ -457,13 +441,13 @@ prepare_symbol_definitions (void) key = obstack_finish0 (&format_obstack); /* Whether the symbol has an identifier. */ - const char *value = symbol_id_get (sym); + const char *id = symbol_id_get (sym); SET_KEY ("has_id"); - MUSCLE_INSERT_INT (key, !!value); + MUSCLE_INSERT_INT (key, !!id); /* Its identifier. */ SET_KEY ("id"); - MUSCLE_INSERT_STRING (key, value ? value : ""); + MUSCLE_INSERT_STRING (key, id ? id : ""); /* Its tag. Typically for documentation purpose. */ SET_KEY ("tag"); @@ -502,8 +486,13 @@ prepare_symbol_definitions (void) SET_KEY2 (pname, "line"); MUSCLE_INSERT_INT (key, p->location.start.line); + SET_KEY2 (pname, "loc"); + muscle_location_grow (key, p->location); + SET_KEY (pname); - MUSCLE_INSERT_STRING_RAW (key, p->code); + obstack_printf (&muscle_obstack, + "%*s%s", p->location.start.column - 1, "", p->code); + muscle_insert (key, obstack_finish0 (&muscle_obstack)); } } #undef SET_KEY2 @@ -553,10 +542,10 @@ prepare_actions (void) parser, so we could avoid accidents by not writing them out in that case. Nevertheless, it seems even better to be able to use the GLR skeletons even without the non-deterministic tables. */ - muscle_insert_unsigned_table ("conflict_list_heads", conflict_table, - conflict_table[0], 1, high + 1); - muscle_insert_unsigned_table ("conflicting_rules", conflict_list, - 0, 1, conflict_list_cnt); + muscle_insert_int_table ("conflict_list_heads", conflict_table, + conflict_table[0], 1, high + 1); + muscle_insert_int_table ("conflicting_rules", conflict_list, + 0, 1, conflict_list_cnt); } @@ -703,7 +692,7 @@ prepare (void) #define DEFINE(Name) MUSCLE_INSERT_STRING (#Name, Name ? Name : "") DEFINE (dir_prefix); DEFINE (parser_file_name); - DEFINE (spec_defines_file); + DEFINE (spec_header_file); DEFINE (spec_file_prefix); DEFINE (spec_graph_file); DEFINE (spec_name_prefix); @@ -755,17 +744,4 @@ output (void) unlink_generated_sources (); obstack_free (&format_obstack, NULL); - free (relocate_buffer); -} - -char const * -pkgdatadir (void) -{ - if (relocate_buffer) - return relocate_buffer; - else - { - char const *cp = getenv ("BISON_PKGDATADIR"); - return cp ? cp : relocate2 (PKGDATADIR, &relocate_buffer); - } } diff --git a/contrib/tools/bison/src/output.h b/contrib/tools/bison/src/output.h index c308bf563030..641013063fa0 100644 --- a/contrib/tools/bison/src/output.h +++ b/contrib/tools/bison/src/output.h @@ -1,6 +1,6 @@ /* Output the generated parsing program for bison, - Copyright (C) 2000-2003, 2006-2007, 2009-2015, 2018-2019 Free + Copyright (C) 2000-2003, 2006-2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -24,7 +24,4 @@ /* Output the parsing tables and the parser code to FTABLE. */ void output (void); -/* Where our data files are installed. */ -char const *pkgdatadir (void); - #endif /* !OUTPUT_H_ */ diff --git a/contrib/tools/bison/src/parse-gram.c b/contrib/tools/bison/src/parse-gram.c index fb5add9c28a5..33f9553f0383 100644 --- a/contrib/tools/bison/src/parse-gram.c +++ b/contrib/tools/bison/src/parse-gram.c @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.2.90.23-0bbcb-dirty. */ +/* A Bison parser, made by GNU Bison 3.5.4. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation, + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -48,7 +48,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "3.2.90.23-0bbcb-dirty" +#define YYBISON_VERSION "3.5.4" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -63,12 +63,12 @@ #define YYPULL 1 /* "%code top" blocks. */ -#line 27 "src/parse-gram.y" /* yacc.c:315 */ +#line 27 "src/parse-gram.y" /* On column 0 to please syntax-check. */ #include -#line 72 "src/parse-gram.c" /* yacc.c:315 */ +#line 72 "src/parse-gram.c" /* Substitute the type names. */ #define YYSTYPE GRAM_STYPE #define YYLTYPE GRAM_LTYPE @@ -80,7 +80,15 @@ #define yynerrs gram_nerrs - +# ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast (Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) +# else +# define YY_CAST(Type, Val) ((Type) (Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) +# endif +# endif # ifndef YY_NULLPTR # if defined __cplusplus # if 201103L <= __cplusplus @@ -101,253 +109,33 @@ # define YYERROR_VERBOSE 1 #endif -/* In a future release of Bison, this section will be replaced - by #include "src/parse-gram.h". */ -#ifndef YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED -# define YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED -/* Debug traces. */ -#ifndef GRAM_DEBUG -# if defined YYDEBUG -#if YYDEBUG -# define GRAM_DEBUG 1 -# else -# define GRAM_DEBUG 0 -# endif -# else /* ! defined YYDEBUG */ -# define GRAM_DEBUG 1 -# endif /* ! defined YYDEBUG */ -#endif /* ! defined GRAM_DEBUG */ -#if GRAM_DEBUG -extern int gram_debug; -#endif -/* "%code requires" blocks. */ -#line 21 "src/parse-gram.y" /* yacc.c:352 */ - - #include "symlist.h" - #include "symtab.h" -#line 239 "src/parse-gram.y" /* yacc.c:352 */ - - typedef enum - { - param_none = 0, - param_lex = 1 << 0, - param_parse = 1 << 1, - param_both = param_lex | param_parse - } param_type; -#line 682 "src/parse-gram.y" /* yacc.c:352 */ - - #include "muscle-tab.h" - typedef struct - { - char const *chars; - muscle_kind kind; - } value_type; - -#line 147 "src/parse-gram.c" /* yacc.c:352 */ - -/* Token type. */ -#ifndef GRAM_TOKENTYPE -# define GRAM_TOKENTYPE - enum gram_tokentype - { - GRAM_EOF = 0, - STRING = 258, - PERCENT_TOKEN = 259, - PERCENT_NTERM = 260, - PERCENT_TYPE = 261, - PERCENT_DESTRUCTOR = 262, - PERCENT_PRINTER = 263, - PERCENT_LEFT = 264, - PERCENT_RIGHT = 265, - PERCENT_NONASSOC = 266, - PERCENT_PRECEDENCE = 267, - PERCENT_PREC = 268, - PERCENT_DPREC = 269, - PERCENT_MERGE = 270, - PERCENT_CODE = 271, - PERCENT_DEFAULT_PREC = 272, - PERCENT_DEFINE = 273, - PERCENT_DEFINES = 274, - PERCENT_ERROR_VERBOSE = 275, - PERCENT_EXPECT = 276, - PERCENT_EXPECT_RR = 277, - PERCENT_FLAG = 278, - PERCENT_FILE_PREFIX = 279, - PERCENT_GLR_PARSER = 280, - PERCENT_INITIAL_ACTION = 281, - PERCENT_LANGUAGE = 282, - PERCENT_NAME_PREFIX = 283, - PERCENT_NO_DEFAULT_PREC = 284, - PERCENT_NO_LINES = 285, - PERCENT_NONDETERMINISTIC_PARSER = 286, - PERCENT_OUTPUT = 287, - PERCENT_REQUIRE = 288, - PERCENT_SKELETON = 289, - PERCENT_START = 290, - PERCENT_TOKEN_TABLE = 291, - PERCENT_VERBOSE = 292, - PERCENT_YACC = 293, - BRACED_CODE = 294, - BRACED_PREDICATE = 295, - BRACKETED_ID = 296, - CHAR = 297, - EPILOGUE = 298, - EQUAL = 299, - ID = 300, - ID_COLON = 301, - PERCENT_PERCENT = 302, - PIPE = 303, - PROLOGUE = 304, - SEMICOLON = 305, - TAG = 306, - TAG_ANY = 307, - TAG_NONE = 308, - INT = 309, - PERCENT_PARAM = 310, - PERCENT_UNION = 311, - PERCENT_EMPTY = 312 - }; -#endif - -/* Value type. */ -#if ! defined GRAM_STYPE && ! defined GRAM_STYPE_IS_DECLARED - -union GRAM_STYPE -{ - - /* precedence_declarator */ - assoc precedence_declarator; - /* "string" */ - char* STRING; - /* "{...}" */ - char* BRACED_CODE; - /* "%?{...}" */ - char* BRACED_PREDICATE; - /* "epilogue" */ - char* EPILOGUE; - /* "%{...%}" */ - char* PROLOGUE; - /* code_props_type */ - code_props_type code_props_type; - /* "integer" */ - int INT; - /* int.opt */ - int yytype_79; - /* named_ref.opt */ - named_ref* yytype_91; - /* "%param" */ - param_type PERCENT_PARAM; - /* token_decl */ - symbol* token_decl; - /* token_decl_for_prec */ - symbol* token_decl_for_prec; - /* id */ - symbol* id; - /* id_colon */ - symbol* id_colon; - /* symbol */ - symbol* symbol; - /* string_as_id */ - symbol* string_as_id; - /* string_as_id.opt */ - symbol* yytype_98; - /* generic_symlist */ - symbol_list* generic_symlist; - /* generic_symlist_item */ - symbol_list* generic_symlist_item; - /* nterm_decls */ - symbol_list* nterm_decls; - /* token_decls */ - symbol_list* token_decls; - /* token_decl.1 */ - symbol_list* yytype_77; - /* token_decls_for_prec */ - symbol_list* token_decls_for_prec; - /* token_decl_for_prec.1 */ - symbol_list* yytype_81; - /* symbol_decls */ - symbol_list* symbol_decls; - /* symbol_decl.1 */ - symbol_list* yytype_84; - /* "%error-verbose" */ - uniqstr PERCENT_ERROR_VERBOSE; - /* "%" */ - uniqstr PERCENT_FLAG; - /* "%file-prefix" */ - uniqstr PERCENT_FILE_PREFIX; - /* "%name-prefix" */ - uniqstr PERCENT_NAME_PREFIX; - /* "%yacc" */ - uniqstr PERCENT_YACC; - /* "[identifier]" */ - uniqstr BRACKETED_ID; - /* "identifier" */ - uniqstr ID; - /* "identifier:" */ - uniqstr ID_COLON; - /* "" */ - uniqstr TAG; - /* tag.opt */ - uniqstr yytype_71; - /* tag */ - uniqstr tag; - /* variable */ - uniqstr variable; - /* "char" */ - unsigned char CHAR; - /* value */ - value_type value; -#line 301 "src/parse-gram.c" /* yacc.c:352 */ -}; - -typedef union GRAM_STYPE GRAM_STYPE; -# define GRAM_STYPE_IS_TRIVIAL 1 -# define GRAM_STYPE_IS_DECLARED 1 -#endif - -/* Location type. */ -#if ! defined GRAM_LTYPE && ! defined GRAM_LTYPE_IS_DECLARED -typedef struct GRAM_LTYPE GRAM_LTYPE; -struct GRAM_LTYPE -{ - int first_line; - int first_column; - int last_line; - int last_column; -}; -# define GRAM_LTYPE_IS_DECLARED 1 -# define GRAM_LTYPE_IS_TRIVIAL 1 -#endif - - - -int gram_parse (void); - -#endif /* !YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED */ +#include "parse-gram.h" /* Unqualified %code blocks. */ -#line 33 "src/parse-gram.y" /* yacc.c:355 */ +#line 33 "src/parse-gram.y" #include "system.h" + + #include #include + #include + #include + #include + #include - #include "c-ctype.h" #include "complain.h" #include "conflicts.h" #include "files.h" #include "getargs.h" #include "gram.h" #include "named-ref.h" - #include "quotearg.h" #include "reader.h" #include "scan-code.h" #include "scan-gram.h" - #include "vasnprintf.h" - #include "xmemdup0.h" static int current_prec = 0; - static location current_lhs_location; + static location current_lhs_loc; static named_ref *current_lhs_named_ref; static symbol *current_lhs_symbol; static symbol_class current_class = unknown_sym; @@ -392,6 +180,9 @@ int gram_parse (void); static void handle_name_prefix (location const *loc, char const *directive, char const *value); + /* Handle a %pure-parser directive. */ + static void handle_pure_parser (location const *loc, char const *directive); + /* Handle a %require directive. */ static void handle_require (location const *loc, char const *version); @@ -399,18 +190,18 @@ int gram_parse (void); static void handle_skeleton (location const *loc, char const *skel); /* Handle a %yacc directive. */ - static void handle_yacc (location const *loc, char const *directive); + static void handle_yacc (location const *loc); + /* Implementation of yyerror. */ static void gram_error (location const *, char const *); /* A string that describes a char (e.g., 'a' -> "'a'"). */ static char const *char_name (char); - #define YYTYPE_INT16 int_fast16_t - #define YYTYPE_INT8 int_fast8_t - #define YYTYPE_UINT16 uint_fast16_t - #define YYTYPE_UINT8 uint_fast8_t -#line 249 "src/parse-gram.y" /* yacc.c:355 */ + /* Add style to semantic values in traces. */ + static void tron (FILE *yyo); + static void troff (FILE *yyo); +#line 261 "src/parse-gram.y" /** Add a lex-param and/or a parse-param. * @@ -421,34 +212,81 @@ int gram_parse (void); static void add_param (param_type type, char *decl, location loc); static param_type current_param = param_none; -#line 425 "src/parse-gram.c" /* yacc.c:355 */ +#line 216 "src/parse-gram.c" #ifdef short # undef short #endif -#ifdef YYTYPE_UINT8 -typedef YYTYPE_UINT8 yytype_uint8; -#else -typedef unsigned char yytype_uint8; +/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure + and (if available) are included + so that the code can choose integer types of a good width. */ + +#ifndef __PTRDIFF_MAX__ +# include /* INFRINGES ON USER NAME SPACE */ +# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_STDINT_H +# endif #endif -#ifdef YYTYPE_INT8 -typedef YYTYPE_INT8 yytype_int8; +/* Narrow types that promote to a signed type and that can represent a + signed or unsigned integer of at least N bits. In tables they can + save space and decrease cache pressure. Promoting to a signed type + helps avoid bugs in integer arithmetic. */ + +#ifdef __INT_LEAST8_MAX__ +typedef __INT_LEAST8_TYPE__ yytype_int8; +#elif defined YY_STDINT_H +typedef int_least8_t yytype_int8; #else typedef signed char yytype_int8; #endif -#ifdef YYTYPE_UINT16 -typedef YYTYPE_UINT16 yytype_uint16; +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; #else -typedef unsigned short yytype_uint16; +typedef short yytype_int16; #endif -#ifdef YYTYPE_INT16 -typedef YYTYPE_INT16 yytype_int16; +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; #else -typedef short yytype_int16; +typedef short yytype_uint8; +#endif + +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; +#else +typedef int yytype_uint16; +#endif + +#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif #endif #ifndef YYSIZE_T @@ -456,7 +294,7 @@ typedef short yytype_int16; # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t -# elif ! defined YYSIZE_T +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else @@ -464,7 +302,19 @@ typedef short yytype_int16; # endif #endif -#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) +#define YYSIZE_MAXIMUM \ + YY_CAST (YYPTRDIFF_T, \ + (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ + ? YYPTRDIFF_MAXIMUM \ + : YY_CAST (YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) + +/* Stored state numbers (used for stacks). */ +typedef yytype_uint8 yy_state_t; + +/* State numbers in computations. */ +typedef int yy_state_fast_t; #ifndef YY_ # if defined YYENABLE_NLS && YYENABLE_NLS @@ -478,22 +328,20 @@ typedef short yytype_int16; # endif #endif -#ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) +#ifndef YY_ATTRIBUTE_PURE +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) # else -# define YY_ATTRIBUTE(Spec) /* empty */ +# define YY_ATTRIBUTE_PURE # endif #endif -#ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) -#endif - #ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +# else +# define YY_ATTRIBUTE_UNUSED +# endif #endif /* Suppress unused-variable warnings by "using" E. */ @@ -505,11 +353,11 @@ typedef short yytype_int16; #if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ _Pragma ("GCC diagnostic pop") #else # define YY_INITIAL_VALUE(Value) Value @@ -522,6 +370,20 @@ typedef short yytype_int16; # define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif +#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END \ + _Pragma ("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END +#endif + + +#define YY_ASSERT(E) ((void) (0 && (E))) #if 1 @@ -576,18 +438,19 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ /* A type that is properly aligned for any stack member. */ union yyalloc { - yytype_int16 yyss_alloc; + yy_state_t yyss_alloc; YYSTYPE yyvs_alloc; YYLTYPE yyls_alloc; }; /* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) +# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ # define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE) \ + + YYSIZEOF (YYLTYPE)) \ + 2 * YYSTACK_GAP_MAXIMUM) # define YYCOPY_NEEDED 1 @@ -600,11 +463,11 @@ union yyalloc # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ do \ { \ - YYSIZE_T yynewbytes; \ + YYPTRDIFF_T yynewbytes; \ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ + yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / YYSIZEOF (*yyptr); \ } \ while (0) @@ -616,12 +479,12 @@ union yyalloc # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ # define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) + __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) # else # define YYCOPY(Dst, Src, Count) \ do \ { \ - YYSIZE_T yyi; \ + YYPTRDIFF_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (Dst)[yyi] = (Src)[yyi]; \ } \ @@ -633,80 +496,42 @@ union yyalloc /* YYFINAL -- State number of the termination state. */ #define YYFINAL 3 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 229 +#define YYLAST 234 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 58 +#define YYNTOKENS 60 /* YYNNTS -- Number of nonterminals. */ #define YYNNTS 42 /* YYNRULES -- Number of rules. */ -#define YYNRULES 121 +#define YYNRULES 122 /* YYNSTATES -- Number of states. */ -#define YYNSTATES 164 +#define YYNSTATES 166 #define YYUNDEFTOK 2 -#define YYMAXUTOK 312 +#define YYMAXUTOK 314 + /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM as returned by yylex, with out-of-bounds checking. */ -#define YYTRANSLATE(YYX) \ - ((unsigned) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) - -/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM - as returned by yylex. */ -static const yytype_uint8 yytranslate[] = -{ - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, - 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57 -}; +#define YYTRANSLATE(YYX) (YYX) #if GRAM_DEBUG /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_uint16 yyrline[] = +static const yytype_int16 yyrline[] = { - 0, 281, 281, 290, 291, 295, 296, 302, 306, 311, - 312, 317, 318, 319, 320, 321, 326, 331, 332, 333, - 334, 335, 336, 336, 337, 338, 339, 340, 341, 342, - 343, 347, 348, 357, 358, 362, 373, 377, 381, 389, - 399, 400, 410, 411, 417, 430, 430, 435, 435, 440, - 444, 454, 455, 456, 457, 461, 462, 467, 468, 472, - 473, 477, 478, 479, 492, 501, 505, 509, 517, 518, - 522, 535, 536, 548, 552, 556, 564, 566, 571, 578, - 588, 592, 596, 604, 605, 613, 614, 620, 621, 622, - 629, 629, 637, 638, 639, 644, 647, 649, 651, 653, - 655, 657, 659, 661, 663, 668, 669, 678, 702, 703, - 704, 705, 717, 719, 734, 739, 740, 745, 754, 755, - 759, 760 + 0, 293, 293, 302, 303, 307, 308, 314, 318, 323, + 324, 329, 330, 331, 332, 333, 338, 343, 344, 345, + 346, 347, 348, 348, 349, 350, 351, 352, 353, 354, + 355, 356, 360, 361, 370, 371, 375, 386, 390, 394, + 402, 412, 413, 423, 424, 430, 443, 443, 448, 448, + 453, 457, 467, 468, 469, 470, 474, 475, 480, 481, + 485, 486, 490, 491, 492, 505, 514, 518, 522, 530, + 531, 535, 548, 549, 561, 565, 569, 577, 579, 584, + 591, 601, 605, 609, 617, 622, 634, 635, 641, 642, + 643, 650, 650, 658, 659, 660, 665, 668, 670, 672, + 674, 676, 678, 680, 682, 684, 689, 690, 699, 723, + 724, 725, 726, 738, 740, 767, 772, 773, 778, 787, + 788, 792, 793 }; #endif @@ -723,14 +548,15 @@ static const char *const yytname[] = "\"%expect\"", "\"%expect-rr\"", "\"%\"", "\"%file-prefix\"", "\"%glr-parser\"", "\"%initial-action\"", "\"%language\"", "\"%name-prefix\"", "\"%no-default-prec\"", "\"%no-lines\"", - "\"%nondeterministic-parser\"", "\"%output\"", "\"%require\"", - "\"%skeleton\"", "\"%start\"", "\"%token-table\"", "\"%verbose\"", - "\"%yacc\"", "\"{...}\"", "\"%?{...}\"", "\"[identifier]\"", "\"char\"", - "\"epilogue\"", "\"=\"", "\"identifier\"", "\"identifier:\"", "\"%%\"", - "\"|\"", "\"%{...%}\"", "\";\"", "\"\"", "\"<*>\"", "\"<>\"", - "\"integer\"", "\"%param\"", "\"%union\"", "\"%empty\"", "$accept", - "input", "prologue_declarations", "prologue_declaration", "$@1", - "params", "grammar_declaration", "code_props_type", "union_name", + "\"%nondeterministic-parser\"", "\"%output\"", "\"%pure-parser\"", + "\"%require\"", "\"%skeleton\"", "\"%start\"", "\"%token-table\"", + "\"%verbose\"", "\"%yacc\"", "\"{...}\"", "\"%?{...}\"", + "\"[identifier]\"", "\"character literal\"", "\":\"", "\"epilogue\"", + "\"=\"", "\"identifier\"", "\"identifier:\"", "\"%%\"", "\"|\"", + "\"%{...%}\"", "\";\"", "\"\"", "\"<*>\"", "\"<>\"", "\"integer\"", + "\"%param\"", "\"%union\"", "\"%empty\"", "$accept", "input", + "prologue_declarations", "prologue_declaration", "$@1", "params", + "grammar_declaration", "code_props_type", "union_name", "symbol_declaration", "$@2", "$@3", "precedence_declarator", "tag.opt", "generic_symlist", "generic_symlist_item", "tag", "nterm_decls", "token_decls", "token_decl.1", "token_decl", "int.opt", @@ -745,92 +571,92 @@ static const char *const yytname[] = # ifdef YYPRINT /* YYTOKNUM[NUM] -- (External) token number corresponding to the (internal) symbol number NUM (which must be that of a token). */ -static const yytype_uint16 yytoknum[] = +static const yytype_int16 yytoknum[] = { 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312 + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314 }; # endif -#define YYPACT_NINF -123 +#define YYPACT_NINF (-130) -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-123))) +#define yypact_value_is_default(Yyn) \ + ((Yyn) == YYPACT_NINF) -#define YYTABLE_NINF -121 +#define YYTABLE_NINF (-122) -#define yytable_value_is_error(Yytable_value) \ +#define yytable_value_is_error(Yyn) \ 0 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ static const yytype_int16 yypact[] = { - -123, 6, 109, -123, -21, -123, -123, 2, -123, -123, - -123, -123, -123, -123, -11, -123, -7, 46, -123, 3, - 13, -123, 77, -123, 43, 87, 88, -123, -123, -123, - 91, 92, 94, 32, -123, -123, -123, 162, -123, -123, - -123, 53, -123, -123, 61, -123, 30, -123, -15, -15, - -123, -123, -123, 32, 50, 32, -123, -123, -123, -123, - 64, -123, 23, -123, -123, -123, -123, -123, -123, -123, - -123, -123, -123, -123, 54, -123, 55, 8, -123, -123, - 65, 68, -123, 69, 18, 32, 60, 32, -123, 70, - -123, 16, 72, 16, -123, 70, -123, 72, 32, 32, - -123, -123, -123, -123, -123, -123, -123, -123, 105, -123, - -123, -123, -123, -123, 110, -123, -123, -123, -123, 18, - -123, -123, -123, 32, 32, -123, -123, -123, 16, 16, - -123, 147, 32, -123, -123, -123, -123, 32, 16, -123, - -123, 37, 172, -123, -123, 32, 97, 101, 99, 100, - -123, -123, -123, 116, 65, 172, -123, -123, -123, -123, - -123, 65, -123, -123 + -130, 36, 110, -130, -22, -130, -130, 2, -130, -130, + -130, -130, -130, -130, -19, -130, -9, 40, -130, -17, + -2, -130, 57, -130, 21, 66, 77, -130, -130, -130, + 78, -130, 87, 92, 44, -130, -130, -130, 165, -130, + -130, -130, 50, -130, -130, 58, -130, 29, -130, 15, + 15, -130, -130, -130, 44, 47, 44, -130, -130, -130, + -130, 61, -130, 30, -130, -130, -130, -130, -130, -130, + -130, -130, -130, -130, -130, 51, -130, 53, 8, -130, + -130, 64, 67, -130, 68, 20, 44, 56, 44, -130, + 69, -130, -37, 59, -37, -130, 69, -130, 59, 44, + 44, -130, -130, -130, -130, -130, -130, -130, -130, 79, + -130, -130, -130, -130, -130, 111, -130, -130, -130, -130, + 20, -130, -130, -130, 44, 44, -130, -130, -130, -37, + -37, -130, 147, 44, -130, 108, -130, -130, 44, -37, + -130, -130, -130, -21, 175, -130, -130, 44, 97, 101, + 99, 100, -130, -130, -130, 117, 64, 175, -130, -130, + -130, -130, -130, 64, -130, -130 }; /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. Performed when YYTABLE does not specify something else to do. Zero means the default is an error. */ -static const yytype_uint8 yydefact[] = +static const yytype_int8 yydefact[] = { - 3, 0, 0, 1, 0, 47, 45, 0, 40, 41, - 51, 52, 53, 54, 0, 36, 0, 9, 11, 0, - 0, 7, 0, 15, 0, 0, 0, 37, 19, 20, - 0, 0, 0, 0, 26, 27, 28, 0, 6, 30, - 22, 42, 4, 5, 0, 33, 0, 29, 0, 0, - 117, 113, 112, 0, 49, 80, 115, 83, 116, 38, - 0, 107, 108, 10, 12, 13, 14, 16, 17, 18, - 21, 24, 25, 34, 0, 114, 0, 0, 85, 87, - 105, 0, 43, 0, 0, 0, 50, 73, 76, 71, - 79, 0, 48, 65, 68, 71, 46, 64, 81, 0, - 84, 39, 110, 111, 109, 8, 89, 88, 0, 86, - 2, 106, 90, 32, 23, 44, 61, 62, 63, 35, - 57, 60, 59, 74, 0, 77, 72, 78, 66, 0, - 69, 118, 82, 121, 95, 31, 58, 75, 67, 119, - 70, 91, 92, 95, 94, 0, 0, 0, 0, 0, - 98, 56, 99, 0, 105, 93, 100, 101, 102, 103, - 104, 105, 96, 97 + 3, 0, 0, 1, 0, 48, 46, 0, 41, 42, + 52, 53, 54, 55, 0, 37, 0, 9, 11, 0, + 0, 7, 0, 15, 0, 0, 0, 38, 19, 20, + 0, 24, 0, 0, 0, 27, 28, 29, 0, 6, + 31, 22, 43, 4, 5, 0, 34, 0, 30, 0, + 0, 118, 114, 113, 0, 50, 81, 116, 84, 117, + 39, 0, 108, 109, 10, 12, 13, 14, 16, 17, + 18, 21, 25, 26, 35, 0, 115, 0, 0, 86, + 88, 106, 0, 44, 0, 0, 0, 51, 74, 77, + 72, 80, 0, 49, 66, 69, 72, 47, 65, 82, + 0, 85, 40, 111, 112, 110, 8, 90, 89, 0, + 87, 2, 107, 91, 33, 23, 45, 62, 63, 64, + 36, 58, 61, 60, 75, 0, 78, 73, 79, 67, + 0, 70, 119, 83, 122, 0, 32, 59, 76, 68, + 120, 71, 96, 92, 93, 96, 95, 0, 0, 0, + 0, 0, 99, 57, 100, 0, 106, 94, 101, 102, + 103, 104, 105, 106, 97, 98 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int16 yypgoto[] = { - -123, -123, -123, -123, -123, -123, 155, -123, -123, -123, - -123, -123, -123, -123, -123, 41, -123, -123, 112, -84, - -62, 67, -123, -83, -64, -123, -43, -123, 103, -123, - -123, -123, 33, -122, -123, -123, -45, -123, -33, -35, - -123, -123 + -130, -130, -130, -130, -130, -130, 156, -130, -130, -130, + -130, -130, -130, -130, -130, 43, -130, -130, 114, -66, + -35, 83, -130, -84, -53, -130, -47, -130, 82, -130, + -130, -130, 35, -129, -130, -130, -46, -130, -34, -36, + -130, -130 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int16 yydefgoto[] = { - -1, 1, 2, 42, 81, 114, 76, 44, 83, 45, - 49, 48, 46, 153, 119, 120, 121, 96, 92, 93, - 94, 127, 86, 87, 88, 54, 55, 77, 78, 79, - 134, 141, 142, 112, 62, 105, 56, 80, 57, 58, - 140, 110 + -1, 1, 2, 43, 82, 115, 77, 45, 84, 46, + 50, 49, 47, 155, 120, 121, 122, 97, 93, 94, + 95, 128, 87, 88, 89, 55, 56, 78, 79, 80, + 135, 143, 144, 113, 63, 106, 57, 81, 58, 59, + 141, 111 }; /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If @@ -838,115 +664,117 @@ static const yytype_int16 yydefgoto[] = number is the opposite. If YYTABLE_NINF, syntax error. */ static const yytype_int16 yytable[] = { - 73, 89, 123, 95, 95, 50, 3, 128, -120, 74, - 98, 90, 5, 6, 7, 8, 9, 10, 11, 12, - 13, 50, 100, 125, 14, 15, 102, 51, 59, 47, - 52, 130, 162, 50, 60, 50, 91, 27, 61, 163, - 89, 137, 89, 33, 51, 138, 95, 52, 95, 63, - 90, 122, 90, 53, 75, 108, 132, 64, 51, 125, - 51, 52, 103, 52, 41, 100, 130, 65, 104, 116, - 117, 118, 51, 125, 51, 52, 130, 52, 89, 89, - 66, 85, 67, 95, 95, 143, 122, 144, 90, 90, - 68, 69, 89, 95, 70, 71, 139, 72, 82, 100, - 84, 99, 90, 101, 106, 107, 111, 113, 115, 154, - 4, 124, 156, 5, 6, 7, 8, 9, 10, 11, - 12, 13, 154, 129, 126, 14, 15, 16, 17, 18, - 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, - 29, 30, 31, 32, 33, 34, 35, 36, 133, 135, - 50, 157, 158, 159, 160, 161, 37, 43, 38, 39, - 136, 97, 131, 74, 40, 41, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 50, 155, 0, 14, 15, - 109, 0, 0, 0, 0, 145, 146, 147, 0, 0, - 0, 27, 0, 148, 149, 0, 0, 33, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 75, 0, - 0, -55, 150, 0, 51, 0, 0, 52, 41, 0, - 0, 0, 0, 151, 0, 0, 0, 0, 0, 152 + 74, 90, 124, 96, 96, 51, 52, 99, -121, 75, + 53, 91, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 60, 101, 51, 14, 15, 129, 164, 61, 145, + 48, 146, 51, 103, 165, 126, 3, 27, 62, 65, + 90, 138, 90, 64, 34, 52, 96, 51, 96, 53, + 91, 123, 91, 133, 66, 54, 76, 109, 52, 131, + 67, 68, 53, 52, 139, 101, 42, 53, 92, 69, + 104, 126, 52, 117, 118, 119, 53, 105, 90, 90, + 70, 71, 86, 96, 96, 126, 123, 52, 91, 91, + 72, 53, 90, 96, 131, 73, 140, 83, 85, 101, + 100, 102, 91, 107, 131, 108, 112, 114, 116, 125, + 156, 4, 130, 158, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 156, 134, 127, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 51, 136, 142, 159, 160, 161, 162, 163, 44, 38, + 110, 39, 40, 137, 98, 0, 75, 41, 42, 5, + 6, 7, 8, 9, 10, 11, 12, 13, 51, 132, + 157, 14, 15, 0, 0, 0, 0, 0, 147, 148, + 149, 0, 0, 0, 27, 0, 150, 151, 0, 0, + 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 76, 0, -56, 152, 0, 52, 0, + 0, 0, 53, 42, 0, 0, 0, 0, 153, 0, + 0, 0, 0, 0, 154 }; static const yytype_int16 yycheck[] = { - 33, 46, 85, 48, 49, 3, 0, 91, 0, 1, - 53, 46, 4, 5, 6, 7, 8, 9, 10, 11, - 12, 3, 55, 87, 16, 17, 3, 42, 39, 50, - 45, 93, 154, 3, 45, 3, 51, 29, 45, 161, - 85, 124, 87, 35, 42, 129, 91, 45, 93, 3, - 85, 84, 87, 51, 46, 47, 99, 54, 42, 123, - 42, 45, 39, 45, 56, 98, 128, 54, 45, 51, - 52, 53, 42, 137, 42, 45, 138, 45, 123, 124, - 3, 51, 39, 128, 129, 48, 119, 50, 123, 124, - 3, 3, 137, 138, 3, 3, 131, 3, 45, 132, - 39, 51, 137, 39, 50, 50, 41, 39, 39, 142, - 1, 51, 145, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 155, 51, 54, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 31, 32, 33, 34, 35, 36, 37, 38, 43, 39, - 3, 54, 51, 54, 54, 39, 47, 2, 49, 50, - 119, 49, 95, 1, 55, 56, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 3, 143, -1, 16, 17, - 77, -1, -1, -1, -1, 13, 14, 15, -1, -1, - -1, 29, -1, 21, 22, -1, -1, 35, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 46, -1, - -1, 39, 40, -1, 42, -1, -1, 45, 56, -1, - -1, -1, -1, 51, -1, -1, -1, -1, -1, 57 + 34, 47, 86, 49, 50, 3, 43, 54, 0, 1, + 47, 47, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 40, 56, 3, 16, 17, 92, 156, 47, 50, + 52, 52, 3, 3, 163, 88, 0, 29, 47, 56, + 86, 125, 88, 3, 36, 43, 92, 3, 94, 47, + 86, 85, 88, 100, 56, 53, 48, 49, 43, 94, + 3, 40, 47, 43, 130, 99, 58, 47, 53, 3, + 40, 124, 43, 53, 54, 55, 47, 47, 124, 125, + 3, 3, 53, 129, 130, 138, 120, 43, 124, 125, + 3, 47, 138, 139, 129, 3, 132, 47, 40, 133, + 53, 40, 138, 52, 139, 52, 42, 40, 40, 53, + 144, 1, 53, 147, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 157, 45, 56, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + 3, 40, 44, 56, 53, 56, 56, 40, 2, 49, + 78, 51, 52, 120, 50, -1, 1, 57, 58, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 3, 96, + 145, 16, 17, -1, -1, -1, -1, -1, 13, 14, + 15, -1, -1, -1, 29, -1, 21, 22, -1, -1, + -1, 36, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 48, -1, 40, 41, -1, 43, -1, + -1, -1, 47, 58, -1, -1, -1, -1, 53, -1, + -1, -1, -1, -1, 59 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ -static const yytype_uint8 yystos[] = +static const yytype_int8 yystos[] = { - 0, 59, 60, 0, 1, 4, 5, 6, 7, 8, + 0, 61, 62, 0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 47, 49, 50, - 55, 56, 61, 64, 65, 67, 70, 50, 69, 68, - 3, 42, 45, 51, 83, 84, 94, 96, 97, 39, - 45, 45, 92, 3, 54, 54, 3, 39, 3, 3, - 3, 3, 3, 96, 1, 46, 64, 85, 86, 87, - 95, 62, 45, 66, 39, 51, 80, 81, 82, 94, - 97, 51, 76, 77, 78, 94, 75, 76, 84, 51, - 96, 39, 3, 39, 45, 93, 50, 50, 47, 86, - 99, 41, 91, 39, 63, 39, 51, 52, 53, 72, - 73, 74, 96, 81, 51, 82, 54, 79, 77, 51, - 78, 79, 84, 43, 88, 39, 73, 81, 77, 97, - 98, 89, 90, 48, 50, 13, 14, 15, 21, 22, - 40, 51, 57, 71, 96, 90, 96, 54, 51, 54, - 54, 39, 91, 91 + 32, 33, 34, 35, 36, 37, 38, 39, 49, 51, + 52, 57, 58, 63, 66, 67, 69, 72, 52, 71, + 70, 3, 43, 47, 53, 85, 86, 96, 98, 99, + 40, 47, 47, 94, 3, 56, 56, 3, 40, 3, + 3, 3, 3, 3, 98, 1, 48, 66, 87, 88, + 89, 97, 64, 47, 68, 40, 53, 82, 83, 84, + 96, 99, 53, 78, 79, 80, 96, 77, 78, 86, + 53, 98, 40, 3, 40, 47, 95, 52, 52, 49, + 88, 101, 42, 93, 40, 65, 40, 53, 54, 55, + 74, 75, 76, 98, 83, 53, 84, 56, 81, 79, + 53, 80, 81, 86, 45, 90, 40, 75, 83, 79, + 99, 100, 44, 91, 92, 50, 52, 13, 14, 15, + 21, 22, 41, 53, 59, 73, 98, 92, 98, 56, + 53, 56, 56, 40, 93, 93 }; /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = +static const yytype_int8 yyr1[] = { - 0, 58, 59, 60, 60, 61, 61, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, - 61, 61, 62, 61, 61, 61, 61, 61, 61, 61, - 61, 63, 63, 64, 64, 64, 64, 64, 64, 64, - 65, 65, 66, 66, 64, 68, 67, 69, 67, 67, - 67, 70, 70, 70, 70, 71, 71, 72, 72, 73, - 73, 74, 74, 74, 75, 76, 76, 76, 77, 77, - 78, 79, 79, 80, 80, 80, 81, 81, 82, 82, - 83, 83, 83, 84, 84, 85, 85, 86, 86, 86, - 88, 87, 89, 89, 89, 90, 90, 90, 90, 90, - 90, 90, 90, 90, 90, 91, 91, 92, 93, 93, - 93, 93, 94, 94, 95, 96, 96, 97, 98, 98, - 99, 99 + 0, 60, 61, 62, 62, 63, 63, 63, 63, 63, + 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, + 63, 63, 64, 63, 63, 63, 63, 63, 63, 63, + 63, 63, 65, 65, 66, 66, 66, 66, 66, 66, + 66, 67, 67, 68, 68, 66, 70, 69, 71, 69, + 69, 69, 72, 72, 72, 72, 73, 73, 74, 74, + 75, 75, 76, 76, 76, 77, 78, 78, 78, 79, + 79, 80, 81, 81, 82, 82, 82, 83, 83, 84, + 84, 85, 85, 85, 86, 86, 87, 87, 88, 88, + 88, 90, 89, 91, 91, 91, 92, 92, 92, 92, + 92, 92, 92, 92, 92, 92, 93, 93, 94, 95, + 95, 95, 95, 96, 96, 97, 98, 98, 99, 100, + 100, 101, 101 }; /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = +static const yytype_int8 yyr2[] = { 0, 2, 4, 0, 2, 1, 1, 1, 3, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 1, - 1, 2, 0, 3, 2, 2, 1, 1, 1, 2, - 1, 2, 1, 1, 2, 3, 1, 1, 2, 3, - 1, 1, 0, 1, 3, 0, 3, 0, 3, 2, - 2, 1, 1, 1, 1, 0, 1, 1, 2, 1, - 1, 1, 1, 1, 1, 1, 2, 3, 1, 2, - 3, 0, 1, 1, 2, 3, 1, 2, 2, 1, - 1, 2, 3, 1, 2, 1, 2, 1, 2, 2, - 0, 4, 1, 3, 2, 0, 3, 4, 2, 2, - 3, 3, 3, 3, 3, 0, 1, 1, 0, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, - 0, 2 + 1, 2, 0, 3, 1, 2, 2, 1, 1, 1, + 2, 1, 2, 1, 1, 2, 3, 1, 1, 2, + 3, 1, 1, 0, 1, 3, 0, 3, 0, 3, + 2, 2, 1, 1, 1, 1, 0, 1, 1, 2, + 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, + 2, 3, 0, 1, 1, 2, 3, 1, 2, 2, + 1, 1, 2, 3, 1, 2, 1, 2, 1, 2, + 2, 0, 5, 1, 3, 2, 0, 3, 4, 2, + 2, 3, 3, 3, 3, 3, 0, 1, 1, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, + 1, 0, 2 }; @@ -1099,107 +927,113 @@ yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep, YY if (yytype < YYNTOKENS) YYPRINT (yyo, yytoknum[yytype], *yyvaluep); # endif +/* "%code pre-printer" blocks. */ +#line 213 "src/parse-gram.y" +tron (yyo); + +#line 935 "src/parse-gram.c" + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN switch (yytype) { case 3: /* "string" */ -#line 207 "src/parse-gram.y" /* yacc.c:680 */ - { fputs (quotearg_style (c_quoting_style, ((*yyvaluep).STRING)), yyo); } -#line 1108 "src/parse-gram.c" /* yacc.c:680 */ +#line 220 "src/parse-gram.y" + { fputs (((*yyvaluep).STRING), yyo); } +#line 942 "src/parse-gram.c" break; case 20: /* "%error-verbose" */ -#line 215 "src/parse-gram.y" /* yacc.c:680 */ - { fputs (((*yyvaluep).PERCENT_ERROR_VERBOSE), yyo); } -#line 1114 "src/parse-gram.c" /* yacc.c:680 */ +#line 227 "src/parse-gram.y" + { fputs (((*yyvaluep).PERCENT_ERROR_VERBOSE), yyo); } +#line 948 "src/parse-gram.c" break; case 23: /* "%" */ -#line 218 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "%%%s", ((*yyvaluep).PERCENT_FLAG)); } -#line 1120 "src/parse-gram.c" /* yacc.c:680 */ +#line 230 "src/parse-gram.y" + { fprintf (yyo, "%%%s", ((*yyvaluep).PERCENT_FLAG)); } +#line 954 "src/parse-gram.c" break; case 24: /* "%file-prefix" */ -#line 215 "src/parse-gram.y" /* yacc.c:680 */ - { fputs (((*yyvaluep).PERCENT_FILE_PREFIX), yyo); } -#line 1126 "src/parse-gram.c" /* yacc.c:680 */ +#line 227 "src/parse-gram.y" + { fputs (((*yyvaluep).PERCENT_FILE_PREFIX), yyo); } +#line 960 "src/parse-gram.c" break; case 28: /* "%name-prefix" */ -#line 215 "src/parse-gram.y" /* yacc.c:680 */ - { fputs (((*yyvaluep).PERCENT_NAME_PREFIX), yyo); } -#line 1132 "src/parse-gram.c" /* yacc.c:680 */ +#line 227 "src/parse-gram.y" + { fputs (((*yyvaluep).PERCENT_NAME_PREFIX), yyo); } +#line 966 "src/parse-gram.c" break; - case 38: /* "%yacc" */ -#line 215 "src/parse-gram.y" /* yacc.c:680 */ - { fputs (((*yyvaluep).PERCENT_YACC), yyo); } -#line 1138 "src/parse-gram.c" /* yacc.c:680 */ + case 33: /* "%pure-parser" */ +#line 227 "src/parse-gram.y" + { fputs (((*yyvaluep).PERCENT_PURE_PARSER), yyo); } +#line 972 "src/parse-gram.c" break; - case 39: /* "{...}" */ -#line 208 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "{\n%s\n}", ((*yyvaluep).BRACED_CODE)); } -#line 1144 "src/parse-gram.c" /* yacc.c:680 */ + case 40: /* "{...}" */ +#line 220 "src/parse-gram.y" + { fputs (((*yyvaluep).BRACED_CODE), yyo); } +#line 978 "src/parse-gram.c" break; - case 40: /* "%?{...}" */ -#line 208 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "{\n%s\n}", ((*yyvaluep).BRACED_PREDICATE)); } -#line 1150 "src/parse-gram.c" /* yacc.c:680 */ + case 41: /* "%?{...}" */ +#line 220 "src/parse-gram.y" + { fputs (((*yyvaluep).BRACED_PREDICATE), yyo); } +#line 984 "src/parse-gram.c" break; - case 41: /* "[identifier]" */ -#line 216 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "[%s]", ((*yyvaluep).BRACKETED_ID)); } -#line 1156 "src/parse-gram.c" /* yacc.c:680 */ + case 42: /* "[identifier]" */ +#line 228 "src/parse-gram.y" + { fprintf (yyo, "[%s]", ((*yyvaluep).BRACKETED_ID)); } +#line 990 "src/parse-gram.c" break; - case 42: /* "char" */ -#line 204 "src/parse-gram.y" /* yacc.c:680 */ - { fputs (char_name (((*yyvaluep).CHAR)), yyo); } -#line 1162 "src/parse-gram.c" /* yacc.c:680 */ + case 43: /* "character literal" */ +#line 217 "src/parse-gram.y" + { fputs (char_name (((*yyvaluep).CHAR)), yyo); } +#line 996 "src/parse-gram.c" break; - case 43: /* "epilogue" */ -#line 208 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "{\n%s\n}", ((*yyvaluep).EPILOGUE)); } -#line 1168 "src/parse-gram.c" /* yacc.c:680 */ + case 45: /* "epilogue" */ +#line 220 "src/parse-gram.y" + { fputs (((*yyvaluep).EPILOGUE), yyo); } +#line 1002 "src/parse-gram.c" break; - case 45: /* "identifier" */ -#line 215 "src/parse-gram.y" /* yacc.c:680 */ - { fputs (((*yyvaluep).ID), yyo); } -#line 1174 "src/parse-gram.c" /* yacc.c:680 */ + case 47: /* "identifier" */ +#line 227 "src/parse-gram.y" + { fputs (((*yyvaluep).ID), yyo); } +#line 1008 "src/parse-gram.c" break; - case 46: /* "identifier:" */ -#line 217 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "%s:", ((*yyvaluep).ID_COLON)); } -#line 1180 "src/parse-gram.c" /* yacc.c:680 */ + case 48: /* "identifier:" */ +#line 229 "src/parse-gram.y" + { fprintf (yyo, "%s:", ((*yyvaluep).ID_COLON)); } +#line 1014 "src/parse-gram.c" break; - case 49: /* "%{...%}" */ -#line 208 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "{\n%s\n}", ((*yyvaluep).PROLOGUE)); } -#line 1186 "src/parse-gram.c" /* yacc.c:680 */ + case 51: /* "%{...%}" */ +#line 220 "src/parse-gram.y" + { fputs (((*yyvaluep).PROLOGUE), yyo); } +#line 1020 "src/parse-gram.c" break; - case 51: /* "" */ -#line 219 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "<%s>", ((*yyvaluep).TAG)); } -#line 1192 "src/parse-gram.c" /* yacc.c:680 */ + case 53: /* "" */ +#line 231 "src/parse-gram.y" + { fprintf (yyo, "<%s>", ((*yyvaluep).TAG)); } +#line 1026 "src/parse-gram.c" break; - case 54: /* "integer" */ -#line 222 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "%d", ((*yyvaluep).INT)); } -#line 1198 "src/parse-gram.c" /* yacc.c:680 */ + case 56: /* "integer" */ +#line 234 "src/parse-gram.y" + { fprintf (yyo, "%d", ((*yyvaluep).INT)); } +#line 1032 "src/parse-gram.c" break; - case 55: /* "%param" */ -#line 261 "src/parse-gram.y" /* yacc.c:680 */ - { + case 57: /* "%param" */ +#line 273 "src/parse-gram.y" +{ switch (((*yyvaluep).PERCENT_PARAM)) { #define CASE(In, Out) \ @@ -1211,108 +1045,108 @@ yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep, YY case param_none: aver (false); break; } } -#line 1215 "src/parse-gram.c" /* yacc.c:680 */ +#line 1049 "src/parse-gram.c" break; - case 65: /* code_props_type */ -#line 397 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "%s", code_props_type_string (((*yyvaluep).code_props_type))); } -#line 1221 "src/parse-gram.c" /* yacc.c:680 */ + case 67: /* code_props_type */ +#line 410 "src/parse-gram.y" + { fprintf (yyo, "%s", code_props_type_string (((*yyvaluep).code_props_type))); } +#line 1055 "src/parse-gram.c" break; - case 71: /* tag.opt */ -#line 215 "src/parse-gram.y" /* yacc.c:680 */ - { fputs (((*yyvaluep).yytype_71), yyo); } -#line 1227 "src/parse-gram.c" /* yacc.c:680 */ + case 73: /* tag.opt */ +#line 227 "src/parse-gram.y" + { fputs (((*yyvaluep).yytype_73), yyo); } +#line 1061 "src/parse-gram.c" break; - case 72: /* generic_symlist */ -#line 231 "src/parse-gram.y" /* yacc.c:680 */ - { symbol_list_syms_print (((*yyvaluep).generic_symlist), yyo); } -#line 1233 "src/parse-gram.c" /* yacc.c:680 */ + case 74: /* generic_symlist */ +#line 243 "src/parse-gram.y" + { symbol_list_syms_print (((*yyvaluep).generic_symlist), yyo); } +#line 1067 "src/parse-gram.c" break; - case 73: /* generic_symlist_item */ -#line 231 "src/parse-gram.y" /* yacc.c:680 */ - { symbol_list_syms_print (((*yyvaluep).generic_symlist_item), yyo); } -#line 1239 "src/parse-gram.c" /* yacc.c:680 */ + case 75: /* generic_symlist_item */ +#line 243 "src/parse-gram.y" + { symbol_list_syms_print (((*yyvaluep).generic_symlist_item), yyo); } +#line 1073 "src/parse-gram.c" break; - case 74: /* tag */ -#line 219 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "<%s>", ((*yyvaluep).tag)); } -#line 1245 "src/parse-gram.c" /* yacc.c:680 */ + case 76: /* tag */ +#line 231 "src/parse-gram.y" + { fprintf (yyo, "<%s>", ((*yyvaluep).tag)); } +#line 1079 "src/parse-gram.c" break; - case 75: /* nterm_decls */ -#line 231 "src/parse-gram.y" /* yacc.c:680 */ - { symbol_list_syms_print (((*yyvaluep).nterm_decls), yyo); } -#line 1251 "src/parse-gram.c" /* yacc.c:680 */ + case 77: /* nterm_decls */ +#line 243 "src/parse-gram.y" + { symbol_list_syms_print (((*yyvaluep).nterm_decls), yyo); } +#line 1085 "src/parse-gram.c" break; - case 76: /* token_decls */ -#line 231 "src/parse-gram.y" /* yacc.c:680 */ - { symbol_list_syms_print (((*yyvaluep).token_decls), yyo); } -#line 1257 "src/parse-gram.c" /* yacc.c:680 */ + case 78: /* token_decls */ +#line 243 "src/parse-gram.y" + { symbol_list_syms_print (((*yyvaluep).token_decls), yyo); } +#line 1091 "src/parse-gram.c" break; - case 77: /* token_decl.1 */ -#line 231 "src/parse-gram.y" /* yacc.c:680 */ - { symbol_list_syms_print (((*yyvaluep).yytype_77), yyo); } -#line 1263 "src/parse-gram.c" /* yacc.c:680 */ + case 79: /* token_decl.1 */ +#line 243 "src/parse-gram.y" + { symbol_list_syms_print (((*yyvaluep).yytype_79), yyo); } +#line 1097 "src/parse-gram.c" break; - case 78: /* token_decl */ -#line 225 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "%s", ((*yyvaluep).token_decl) ? ((*yyvaluep).token_decl)->tag : ""); } -#line 1269 "src/parse-gram.c" /* yacc.c:680 */ + case 80: /* token_decl */ +#line 237 "src/parse-gram.y" + { fprintf (yyo, "%s", ((*yyvaluep).token_decl) ? ((*yyvaluep).token_decl)->tag : ""); } +#line 1103 "src/parse-gram.c" break; - case 79: /* int.opt */ -#line 222 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "%d", ((*yyvaluep).yytype_79)); } -#line 1275 "src/parse-gram.c" /* yacc.c:680 */ + case 81: /* int.opt */ +#line 234 "src/parse-gram.y" + { fprintf (yyo, "%d", ((*yyvaluep).yytype_81)); } +#line 1109 "src/parse-gram.c" break; - case 80: /* token_decls_for_prec */ -#line 231 "src/parse-gram.y" /* yacc.c:680 */ - { symbol_list_syms_print (((*yyvaluep).token_decls_for_prec), yyo); } -#line 1281 "src/parse-gram.c" /* yacc.c:680 */ + case 82: /* token_decls_for_prec */ +#line 243 "src/parse-gram.y" + { symbol_list_syms_print (((*yyvaluep).token_decls_for_prec), yyo); } +#line 1115 "src/parse-gram.c" break; - case 81: /* token_decl_for_prec.1 */ -#line 231 "src/parse-gram.y" /* yacc.c:680 */ - { symbol_list_syms_print (((*yyvaluep).yytype_81), yyo); } -#line 1287 "src/parse-gram.c" /* yacc.c:680 */ + case 83: /* token_decl_for_prec.1 */ +#line 243 "src/parse-gram.y" + { symbol_list_syms_print (((*yyvaluep).yytype_83), yyo); } +#line 1121 "src/parse-gram.c" break; - case 82: /* token_decl_for_prec */ -#line 225 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "%s", ((*yyvaluep).token_decl_for_prec) ? ((*yyvaluep).token_decl_for_prec)->tag : ""); } -#line 1293 "src/parse-gram.c" /* yacc.c:680 */ + case 84: /* token_decl_for_prec */ +#line 237 "src/parse-gram.y" + { fprintf (yyo, "%s", ((*yyvaluep).token_decl_for_prec) ? ((*yyvaluep).token_decl_for_prec)->tag : ""); } +#line 1127 "src/parse-gram.c" break; - case 83: /* symbol_decls */ -#line 231 "src/parse-gram.y" /* yacc.c:680 */ - { symbol_list_syms_print (((*yyvaluep).symbol_decls), yyo); } -#line 1299 "src/parse-gram.c" /* yacc.c:680 */ + case 85: /* symbol_decls */ +#line 243 "src/parse-gram.y" + { symbol_list_syms_print (((*yyvaluep).symbol_decls), yyo); } +#line 1133 "src/parse-gram.c" break; - case 84: /* symbol_decl.1 */ -#line 231 "src/parse-gram.y" /* yacc.c:680 */ - { symbol_list_syms_print (((*yyvaluep).yytype_84), yyo); } -#line 1305 "src/parse-gram.c" /* yacc.c:680 */ + case 86: /* symbol_decl.1 */ +#line 243 "src/parse-gram.y" + { symbol_list_syms_print (((*yyvaluep).yytype_86), yyo); } +#line 1139 "src/parse-gram.c" break; - case 92: /* variable */ -#line 215 "src/parse-gram.y" /* yacc.c:680 */ - { fputs (((*yyvaluep).variable), yyo); } -#line 1311 "src/parse-gram.c" /* yacc.c:680 */ + case 94: /* variable */ +#line 227 "src/parse-gram.y" + { fputs (((*yyvaluep).variable), yyo); } +#line 1145 "src/parse-gram.c" break; - case 93: /* value */ -#line 692 "src/parse-gram.y" /* yacc.c:680 */ - { + case 95: /* value */ +#line 713 "src/parse-gram.y" +{ switch (((*yyvaluep).value).kind) { case muscle_code: fprintf (yyo, "{%s}", ((*yyvaluep).value).chars); break; @@ -1320,42 +1154,48 @@ yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep, YY case muscle_string: fprintf (yyo, "\"%s\"", ((*yyvaluep).value).chars); break; } } -#line 1324 "src/parse-gram.c" /* yacc.c:680 */ +#line 1158 "src/parse-gram.c" break; - case 94: /* id */ -#line 225 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "%s", ((*yyvaluep).id) ? ((*yyvaluep).id)->tag : ""); } -#line 1330 "src/parse-gram.c" /* yacc.c:680 */ + case 96: /* id */ +#line 237 "src/parse-gram.y" + { fprintf (yyo, "%s", ((*yyvaluep).id) ? ((*yyvaluep).id)->tag : ""); } +#line 1164 "src/parse-gram.c" break; - case 95: /* id_colon */ -#line 226 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "%s:", ((*yyvaluep).id_colon)->tag); } -#line 1336 "src/parse-gram.c" /* yacc.c:680 */ + case 97: /* id_colon */ +#line 238 "src/parse-gram.y" + { fprintf (yyo, "%s:", ((*yyvaluep).id_colon)->tag); } +#line 1170 "src/parse-gram.c" break; - case 96: /* symbol */ -#line 225 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "%s", ((*yyvaluep).symbol) ? ((*yyvaluep).symbol)->tag : ""); } -#line 1342 "src/parse-gram.c" /* yacc.c:680 */ + case 98: /* symbol */ +#line 237 "src/parse-gram.y" + { fprintf (yyo, "%s", ((*yyvaluep).symbol) ? ((*yyvaluep).symbol)->tag : ""); } +#line 1176 "src/parse-gram.c" break; - case 97: /* string_as_id */ -#line 225 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "%s", ((*yyvaluep).string_as_id) ? ((*yyvaluep).string_as_id)->tag : ""); } -#line 1348 "src/parse-gram.c" /* yacc.c:680 */ + case 99: /* string_as_id */ +#line 237 "src/parse-gram.y" + { fprintf (yyo, "%s", ((*yyvaluep).string_as_id) ? ((*yyvaluep).string_as_id)->tag : ""); } +#line 1182 "src/parse-gram.c" break; - case 98: /* string_as_id.opt */ -#line 225 "src/parse-gram.y" /* yacc.c:680 */ - { fprintf (yyo, "%s", ((*yyvaluep).yytype_98) ? ((*yyvaluep).yytype_98)->tag : ""); } -#line 1354 "src/parse-gram.c" /* yacc.c:680 */ + case 100: /* string_as_id.opt */ +#line 237 "src/parse-gram.y" + { fprintf (yyo, "%s", ((*yyvaluep).yytype_100) ? ((*yyvaluep).yytype_100)->tag : ""); } +#line 1188 "src/parse-gram.c" break; default: break; } + YY_IGNORE_MAYBE_UNINITIALIZED_END +/* "%code post-printer" blocks. */ +#line 214 "src/parse-gram.y" +troff (yyo); + +#line 1199 "src/parse-gram.c" } @@ -1381,7 +1221,7 @@ yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE `------------------------------------------------------------------*/ static void -yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) { YYFPRINTF (stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) @@ -1404,19 +1244,19 @@ do { \ `------------------------------------------------*/ static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule) +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule) { - unsigned long yylno = yyrline[yyrule]; + int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, - yystos[yyssp[yyi + 1 - yynrhs]], + yystos[+yyssp[yyi + 1 - yynrhs]], &yyvsp[(yyi + 1) - (yynrhs)] , &(yylsp[(yyi + 1) - (yynrhs)]) ); YYFPRINTF (stderr, "\n"); @@ -1467,22 +1307,22 @@ int yydebug; using YYSTACK_FREE. Return 0 if successful or if no reallocation is required. Return 1 if memory is exhausted. */ static int -yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd, +yy_lac_stack_realloc (YYPTRDIFF_T *yycapacity, YYPTRDIFF_T yyadd, #if GRAM_DEBUG char const *yydebug_prefix, char const *yydebug_suffix, #endif - yytype_int16 **yybottom, - yytype_int16 *yybottom_no_free, - yytype_int16 **yytop, yytype_int16 *yytop_empty) + yy_state_t **yybottom, + yy_state_t *yybottom_no_free, + yy_state_t **yytop, yy_state_t *yytop_empty) { - YYSIZE_T yysize_old = - (YYSIZE_T) (*yytop == yytop_empty ? 0 : *yytop - *yybottom + 1); - YYSIZE_T yysize_new = yysize_old + yyadd; + YYPTRDIFF_T yysize_old = + *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1; + YYPTRDIFF_T yysize_new = yysize_old + yyadd; if (*yycapacity < yysize_new) { - YYSIZE_T yyalloc = 2 * yysize_new; - yytype_int16 *yybottom_new; + YYPTRDIFF_T yyalloc = 2 * yysize_new; + yy_state_t *yybottom_new; /* Use YYMAXDEPTH for maximum stack size given that the stack should never need to grow larger than the main state stack needs to grow without LAC. */ @@ -1495,7 +1335,9 @@ yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd, if (YYMAXDEPTH < yyalloc) yyalloc = YYMAXDEPTH; yybottom_new = - (yytype_int16*) YYSTACK_ALLOC (yyalloc * sizeof *yybottom_new); + YY_CAST (yy_state_t *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, + yyalloc * YYSIZEOF (*yybottom_new)))); if (!yybottom_new) { YYDPRINTF ((stderr, "%srealloc failed%s", yydebug_prefix, @@ -1595,11 +1437,11 @@ do { \ contents of either array, alter *YYES and *YYES_CAPACITY, and free any old *YYES other than YYESA. */ static int -yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, - YYSIZE_T *yyes_capacity, yytype_int16 *yyssp, int yytoken) +yy_lac (yy_state_t *yyesa, yy_state_t **yyes, + YYPTRDIFF_T *yyes_capacity, yy_state_t *yyssp, int yytoken) { - yytype_int16 *yyes_prev = yyssp; - yytype_int16 *yyesp = yyes_prev; + yy_state_t *yyes_prev = yyssp; + yy_state_t *yyesp = yyes_prev; YYDPRINTF ((stderr, "LAC: checking lookahead %s:", yytname[yytoken])); if (yytoken == YYUNDEFTOK) { @@ -1608,12 +1450,12 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, } while (1) { - int yyrule = yypact[*yyesp]; + int yyrule = yypact[+*yyesp]; if (yypact_value_is_default (yyrule) || (yyrule += yytoken) < 0 || YYLAST < yyrule || yycheck[yyrule] != yytoken) { - yyrule = yydefact[*yyesp]; + yyrule = yydefact[+*yyesp]; if (yyrule == 0) { YYDPRINTF ((stderr, " Err\n")); @@ -1636,11 +1478,11 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, yyrule = -yyrule; } { - YYSIZE_T yylen = yyr2[yyrule]; + YYPTRDIFF_T yylen = yyr2[yyrule]; YYDPRINTF ((stderr, " R%d", yyrule - 1)); if (yyesp != yyes_prev) { - YYSIZE_T yysize = (YYSIZE_T) (yyesp - *yyes + 1); + YYPTRDIFF_T yysize = yyesp - *yyes + 1; if (yylen < yysize) { yyesp -= yylen; @@ -1656,19 +1498,20 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, yyesp = yyes_prev -= yylen; } { - yytype_int16 yystate; + yy_state_fast_t yystate; { const int yylhs = yyr1[yyrule] - YYNTOKENS; const int yyi = yypgoto[yylhs] + *yyesp; - yystate = ((yytype_int16) - (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyesp - ? yytable[yyi] - : yydefgoto[yylhs])); + yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyesp + ? yytable[yyi] + : yydefgoto[yylhs]); } if (yyesp == yyes_prev) { yyesp = *yyes; - *yyesp = yystate; + YY_IGNORE_USELESS_CAST_BEGIN + *yyesp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END } else { @@ -1681,9 +1524,11 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, YYDPRINTF ((stderr, "\n")); return 2; } - *++yyesp = yystate; + YY_IGNORE_USELESS_CAST_BEGIN + *++yyesp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END } - YYDPRINTF ((stderr, " G%d", (int) yystate)); + YYDPRINTF ((stderr, " G%d", yystate)); } } } @@ -1693,13 +1538,13 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, # ifndef yystrlen # if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen +# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S))) # else /* Return the length of YYSTR. */ -static YYSIZE_T +static YYPTRDIFF_T yystrlen (const char *yystr) { - YYSIZE_T yylen; + YYPTRDIFF_T yylen; for (yylen = 0; yystr[yylen]; yylen++) continue; return yylen; @@ -1735,12 +1580,12 @@ yystpcpy (char *yydest, const char *yysrc) backslash-backslash). YYSTR is taken from yytname. If YYRES is null, do not copy; instead, return the length of what the result would have been. */ -static YYSIZE_T +static YYPTRDIFF_T yytnamerr (char *yyres, const char *yystr) { if (*yystr == '"') { - YYSIZE_T yyn = 0; + YYPTRDIFF_T yyn = 0; char const *yyp = yystr; for (;;) @@ -1771,10 +1616,10 @@ yytnamerr (char *yyres, const char *yystr) do_not_strip_quotes: ; } - if (! yyres) + if (yyres) + return yystpcpy (yyres, yystr) - yyres; + else return yystrlen (yystr); - - return (YYSIZE_T) (yystpcpy (yyres, yystr) - yyres); } # endif @@ -1789,20 +1634,20 @@ yytnamerr (char *yyres, const char *yystr) required number of bytes is too large to store or if yy_lac returned 2. */ static int -yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - yytype_int16 *yyesa, yytype_int16 **yyes, - YYSIZE_T *yyes_capacity, yytype_int16 *yyssp, int yytoken) +yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, + yy_state_t *yyesa, yy_state_t **yyes, + YYPTRDIFF_T *yyes_capacity, yy_state_t *yyssp, int yytoken) { - YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); - YYSIZE_T yysize = yysize0; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; /* Internationalized format string. */ const char *yyformat = YY_NULLPTR; - /* Arguments of yyformat. */ + /* Arguments of yyformat: reported tokens (one for the "unexpected", + one per "expected"). */ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - /* Number of reported tokens (one for the "unexpected", one per - "expected"). */ + /* Actual size of YYARG. */ int yycount = 0; + /* Cumulated lengths of YYARG. */ + YYPTRDIFF_T yysize = 0; /* There are many possibilities here to consider: - If this state is a consistent state with a default action, then @@ -1826,7 +1671,9 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, */ if (yytoken != YYEMPTY) { - int yyn = yypact[*yyssp]; + int yyn = yypact[+*yyssp]; + YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); + yysize = yysize0; YYDPRINTF ((stderr, "Constructing syntax error message\n")); yyarg[yycount++] = yytname[yytoken]; if (!yypact_value_is_default (yyn)) @@ -1852,7 +1699,8 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, } yyarg[yycount++] = yytname[yyx]; { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); + YYPTRDIFF_T yysize1 + = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) yysize = yysize1; else @@ -1883,7 +1731,9 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, } { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); + /* Don't count the "%s"s in the final size, but reserve room for + the terminator. */ + YYPTRDIFF_T yysize1 = yysize + (yystrlen (yyformat) - 2 * yycount) + 1; if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) yysize = yysize1; else @@ -1913,8 +1763,8 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, } else { - yyp++; - yyformat++; + ++yyp; + ++yyformat; } } return 0; @@ -1937,58 +1787,58 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN switch (yytype) { - case 72: /* generic_symlist */ -#line 230 "src/parse-gram.y" /* yacc.c:1257 */ - { symbol_list_free (((*yyvaluep).generic_symlist)); } -#line 1944 "src/parse-gram.c" /* yacc.c:1257 */ + case 74: /* generic_symlist */ +#line 242 "src/parse-gram.y" + { symbol_list_free (((*yyvaluep).generic_symlist)); } +#line 1794 "src/parse-gram.c" break; - case 73: /* generic_symlist_item */ -#line 230 "src/parse-gram.y" /* yacc.c:1257 */ - { symbol_list_free (((*yyvaluep).generic_symlist_item)); } -#line 1950 "src/parse-gram.c" /* yacc.c:1257 */ + case 75: /* generic_symlist_item */ +#line 242 "src/parse-gram.y" + { symbol_list_free (((*yyvaluep).generic_symlist_item)); } +#line 1800 "src/parse-gram.c" break; - case 75: /* nterm_decls */ -#line 230 "src/parse-gram.y" /* yacc.c:1257 */ - { symbol_list_free (((*yyvaluep).nterm_decls)); } -#line 1956 "src/parse-gram.c" /* yacc.c:1257 */ + case 77: /* nterm_decls */ +#line 242 "src/parse-gram.y" + { symbol_list_free (((*yyvaluep).nterm_decls)); } +#line 1806 "src/parse-gram.c" break; - case 76: /* token_decls */ -#line 230 "src/parse-gram.y" /* yacc.c:1257 */ - { symbol_list_free (((*yyvaluep).token_decls)); } -#line 1962 "src/parse-gram.c" /* yacc.c:1257 */ + case 78: /* token_decls */ +#line 242 "src/parse-gram.y" + { symbol_list_free (((*yyvaluep).token_decls)); } +#line 1812 "src/parse-gram.c" break; - case 77: /* token_decl.1 */ -#line 230 "src/parse-gram.y" /* yacc.c:1257 */ - { symbol_list_free (((*yyvaluep).yytype_77)); } -#line 1968 "src/parse-gram.c" /* yacc.c:1257 */ + case 79: /* token_decl.1 */ +#line 242 "src/parse-gram.y" + { symbol_list_free (((*yyvaluep).yytype_79)); } +#line 1818 "src/parse-gram.c" break; - case 80: /* token_decls_for_prec */ -#line 230 "src/parse-gram.y" /* yacc.c:1257 */ - { symbol_list_free (((*yyvaluep).token_decls_for_prec)); } -#line 1974 "src/parse-gram.c" /* yacc.c:1257 */ + case 82: /* token_decls_for_prec */ +#line 242 "src/parse-gram.y" + { symbol_list_free (((*yyvaluep).token_decls_for_prec)); } +#line 1824 "src/parse-gram.c" break; - case 81: /* token_decl_for_prec.1 */ -#line 230 "src/parse-gram.y" /* yacc.c:1257 */ - { symbol_list_free (((*yyvaluep).yytype_81)); } -#line 1980 "src/parse-gram.c" /* yacc.c:1257 */ + case 83: /* token_decl_for_prec.1 */ +#line 242 "src/parse-gram.y" + { symbol_list_free (((*yyvaluep).yytype_83)); } +#line 1830 "src/parse-gram.c" break; - case 83: /* symbol_decls */ -#line 230 "src/parse-gram.y" /* yacc.c:1257 */ - { symbol_list_free (((*yyvaluep).symbol_decls)); } -#line 1986 "src/parse-gram.c" /* yacc.c:1257 */ + case 85: /* symbol_decls */ +#line 242 "src/parse-gram.y" + { symbol_list_free (((*yyvaluep).symbol_decls)); } +#line 1836 "src/parse-gram.c" break; - case 84: /* symbol_decl.1 */ -#line 230 "src/parse-gram.y" /* yacc.c:1257 */ - { symbol_list_free (((*yyvaluep).yytype_84)); } -#line 1992 "src/parse-gram.c" /* yacc.c:1257 */ + case 86: /* symbol_decl.1 */ +#line 242 "src/parse-gram.y" + { symbol_list_free (((*yyvaluep).yytype_86)); } +#line 1842 "src/parse-gram.c" break; default: @@ -2028,7 +1878,7 @@ YYLTYPE yylloc = yyloc_default; /* Number of syntax errors so far. */ int yynerrs; - int yystate; + yy_state_fast_t yystate; /* Number of tokens to shift before error messages enabled. */ int yyerrstatus; @@ -2041,9 +1891,9 @@ YYLTYPE yylloc = yyloc_default; to reallocate them elsewhere. */ /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss; - yytype_int16 *yyssp; + yy_state_t yyssa[YYINITDEPTH]; + yy_state_t *yyss; + yy_state_t *yyssp; /* The semantic value stack. */ YYSTYPE yyvsa[YYINITDEPTH]; @@ -2058,11 +1908,11 @@ YYLTYPE yylloc = yyloc_default; /* The locations where the error started and ended. */ YYLTYPE yyerror_range[3]; - YYSIZE_T yystacksize; + YYPTRDIFF_T yystacksize; - yytype_int16 yyesa[20]; - yytype_int16 *yyes; - YYSIZE_T yyes_capacity; + yy_state_t yyesa[20]; + yy_state_t *yyes; + YYPTRDIFF_T yyes_capacity; int yy_lac_established = 0; int yyn; @@ -2078,7 +1928,7 @@ YYLTYPE yylloc = yyloc_default; /* Buffer for error messages, and its allocated size. */ char yymsgbuf[128]; char *yymsg = yymsgbuf; - YYSIZE_T yymsg_alloc = sizeof yymsgbuf; + YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf; #endif #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N)) @@ -2093,7 +1943,7 @@ YYLTYPE yylloc = yyloc_default; yystacksize = YYINITDEPTH; yyes = yyesa; - yyes_capacity = sizeof yyesa / sizeof *yyes; + yyes_capacity = 20; if (YYMAXDEPTH < yyes_capacity) yyes_capacity = YYMAXDEPTH; @@ -2105,15 +1955,16 @@ YYLTYPE yylloc = yyloc_default; yychar = YYEMPTY; /* Cause a token to be read. */ /* User initialization code. */ -#line 129 "src/parse-gram.y" /* yacc.c:1431 */ +#line 136 "src/parse-gram.y" { /* Bison's grammar can initial empty locations, hence a default location is needed. */ - boundary_set (&yylloc.start, current_file, 1, 1); - boundary_set (&yylloc.end, current_file, 1, 1); + boundary_set (&yylloc.start, grammar_file, 1, 1, 1); + boundary_set (&yylloc.end, grammar_file, 1, 1, 1); } -#line 2117 "src/parse-gram.c" /* yacc.c:1431 */ +#line 1967 "src/parse-gram.c" + yylsp[0] = yylloc; goto yysetstate; @@ -2128,10 +1979,14 @@ YYLTYPE yylloc = yyloc_default; /*--------------------------------------------------------------------. -| yynewstate -- set current state (the top of the stack) to yystate. | +| yysetstate -- set current state (the top of the stack) to yystate. | `--------------------------------------------------------------------*/ yysetstate: - *yyssp = (yytype_int16) yystate; + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YY_ASSERT (0 <= yystate && yystate < YYNSTATES); + YY_IGNORE_USELESS_CAST_BEGIN + *yyssp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END if (yyss + yystacksize - 1 <= yyssp) #if !defined yyoverflow && !defined YYSTACK_RELOCATE @@ -2139,15 +1994,15 @@ YYLTYPE yylloc = yyloc_default; #else { /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = (YYSIZE_T) (yyssp - yyss + 1); + YYPTRDIFF_T yysize = yyssp - yyss + 1; # if defined yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ + yy_state_t *yyss1 = yyss; YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; YYLTYPE *yyls1 = yyls; /* Each stack pointer address is followed by the size of the @@ -2155,9 +2010,9 @@ YYLTYPE yylloc = yyloc_default; conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - &yyls1, yysize * sizeof (*yylsp), + &yyss1, yysize * YYSIZEOF (*yyssp), + &yyvs1, yysize * YYSIZEOF (*yyvsp), + &yyls1, yysize * YYSIZEOF (*yylsp), &yystacksize); yyss = yyss1; yyvs = yyvs1; @@ -2172,9 +2027,10 @@ YYLTYPE yylloc = yyloc_default; yystacksize = YYMAXDEPTH; { - yytype_int16 *yyss1 = yyss; + yy_state_t *yyss1 = yyss; union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + YY_CAST (union yyalloc *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); if (! yyptr) goto yyexhaustedlab; YYSTACK_RELOCATE (yyss_alloc, yyss); @@ -2190,16 +2046,16 @@ YYLTYPE yylloc = yyloc_default; yyvsp = yyvs + yysize - 1; yylsp = yyls + yysize - 1; - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long) yystacksize)); + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "Stack size increased to %ld\n", + YY_CAST (long, yystacksize))); + YY_IGNORE_USELESS_CAST_END if (yyss + yystacksize - 1 <= yyssp) YYABORT; } #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); - if (yystate == YYFINAL) YYACCEPT; @@ -2263,16 +2119,15 @@ YYLTYPE yylloc = yyloc_default; /* Shift the lookahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - - /* Discard the shifted token. */ - yychar = YYEMPTY; - YY_LAC_DISCARD ("shift"); - yystate = yyn; YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END *++yylsp = yylloc; + + /* Discard the shifted token. */ + yychar = YYEMPTY; + YY_LAC_DISCARD ("shift"); goto yynewstate; @@ -2312,189 +2167,195 @@ YYLTYPE yylloc = yyloc_default; switch (yyn) { case 6: -#line 297 "src/parse-gram.y" /* yacc.c:1652 */ +#line 309 "src/parse-gram.y" { muscle_code_grow (union_seen ? "post_prologue" : "pre_prologue", translate_code ((yyvsp[0].PROLOGUE), (yylsp[0]), true), (yylsp[0])); code_scanner_last_string_free (); } -#line 2322 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2177 "src/parse-gram.c" break; case 7: -#line 303 "src/parse-gram.y" /* yacc.c:1652 */ +#line 315 "src/parse-gram.y" { muscle_percent_define_ensure ((yyvsp[0].PERCENT_FLAG), (yylsp[0]), true); } -#line 2330 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2185 "src/parse-gram.c" break; case 8: -#line 307 "src/parse-gram.y" /* yacc.c:1652 */ +#line 319 "src/parse-gram.y" { muscle_percent_define_insert ((yyvsp[-1].variable), (yyloc), (yyvsp[0].value).kind, (yyvsp[0].value).chars, MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE); } -#line 2339 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2194 "src/parse-gram.c" break; case 9: -#line 311 "src/parse-gram.y" /* yacc.c:1652 */ - { defines_flag = true; } -#line 2345 "src/parse-gram.c" /* yacc.c:1652 */ +#line 323 "src/parse-gram.y" + { defines_flag = true; } +#line 2200 "src/parse-gram.c" break; case 10: -#line 313 "src/parse-gram.y" /* yacc.c:1652 */ +#line 325 "src/parse-gram.y" { defines_flag = true; - spec_defines_file = xstrdup ((yyvsp[0].STRING)); + spec_header_file = xstrdup ((yyvsp[0].STRING)); } -#line 2354 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2209 "src/parse-gram.c" break; case 11: -#line 317 "src/parse-gram.y" /* yacc.c:1652 */ - { handle_error_verbose (&(yyloc), (yyvsp[0].PERCENT_ERROR_VERBOSE)); } -#line 2360 "src/parse-gram.c" /* yacc.c:1652 */ +#line 329 "src/parse-gram.y" + { handle_error_verbose (&(yyloc), (yyvsp[0].PERCENT_ERROR_VERBOSE)); } +#line 2215 "src/parse-gram.c" break; case 12: -#line 318 "src/parse-gram.y" /* yacc.c:1652 */ - { expected_sr_conflicts = (yyvsp[0].INT); } -#line 2366 "src/parse-gram.c" /* yacc.c:1652 */ +#line 330 "src/parse-gram.y" + { expected_sr_conflicts = (yyvsp[0].INT); } +#line 2221 "src/parse-gram.c" break; case 13: -#line 319 "src/parse-gram.y" /* yacc.c:1652 */ - { expected_rr_conflicts = (yyvsp[0].INT); } -#line 2372 "src/parse-gram.c" /* yacc.c:1652 */ +#line 331 "src/parse-gram.y" + { expected_rr_conflicts = (yyvsp[0].INT); } +#line 2227 "src/parse-gram.c" break; case 14: -#line 320 "src/parse-gram.y" /* yacc.c:1652 */ - { handle_file_prefix (&(yyloc), &(yylsp[-1]), (yyvsp[-1].PERCENT_FILE_PREFIX), (yyvsp[0].STRING)); } -#line 2378 "src/parse-gram.c" /* yacc.c:1652 */ +#line 332 "src/parse-gram.y" + { handle_file_prefix (&(yyloc), &(yylsp[-1]), (yyvsp[-1].PERCENT_FILE_PREFIX), (yyvsp[0].STRING)); } +#line 2233 "src/parse-gram.c" break; case 15: -#line 322 "src/parse-gram.y" /* yacc.c:1652 */ +#line 334 "src/parse-gram.y" { nondeterministic_parser = true; glr_parser = true; } -#line 2387 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2242 "src/parse-gram.c" break; case 16: -#line 327 "src/parse-gram.y" /* yacc.c:1652 */ +#line 339 "src/parse-gram.y" { muscle_code_grow ("initial_action", translate_code ((yyvsp[0].BRACED_CODE), (yylsp[0]), false), (yylsp[0])); code_scanner_last_string_free (); } -#line 2396 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2251 "src/parse-gram.c" break; case 17: -#line 331 "src/parse-gram.y" /* yacc.c:1652 */ - { language_argmatch ((yyvsp[0].STRING), grammar_prio, (yylsp[-1])); } -#line 2402 "src/parse-gram.c" /* yacc.c:1652 */ +#line 343 "src/parse-gram.y" + { language_argmatch ((yyvsp[0].STRING), grammar_prio, (yylsp[-1])); } +#line 2257 "src/parse-gram.c" break; case 18: -#line 332 "src/parse-gram.y" /* yacc.c:1652 */ - { handle_name_prefix (&(yyloc), (yyvsp[-1].PERCENT_NAME_PREFIX), (yyvsp[0].STRING)); } -#line 2408 "src/parse-gram.c" /* yacc.c:1652 */ +#line 344 "src/parse-gram.y" + { handle_name_prefix (&(yyloc), (yyvsp[-1].PERCENT_NAME_PREFIX), (yyvsp[0].STRING)); } +#line 2263 "src/parse-gram.c" break; case 19: -#line 333 "src/parse-gram.y" /* yacc.c:1652 */ - { no_lines_flag = true; } -#line 2414 "src/parse-gram.c" /* yacc.c:1652 */ +#line 345 "src/parse-gram.y" + { no_lines_flag = true; } +#line 2269 "src/parse-gram.c" break; case 20: -#line 334 "src/parse-gram.y" /* yacc.c:1652 */ - { nondeterministic_parser = true; } -#line 2420 "src/parse-gram.c" /* yacc.c:1652 */ +#line 346 "src/parse-gram.y" + { nondeterministic_parser = true; } +#line 2275 "src/parse-gram.c" break; case 21: -#line 335 "src/parse-gram.y" /* yacc.c:1652 */ - { spec_outfile = (yyvsp[0].STRING); } -#line 2426 "src/parse-gram.c" /* yacc.c:1652 */ +#line 347 "src/parse-gram.y" + { spec_outfile = (yyvsp[0].STRING); } +#line 2281 "src/parse-gram.c" break; case 22: -#line 336 "src/parse-gram.y" /* yacc.c:1652 */ - { current_param = (yyvsp[0].PERCENT_PARAM); } -#line 2432 "src/parse-gram.c" /* yacc.c:1652 */ +#line 348 "src/parse-gram.y" + { current_param = (yyvsp[0].PERCENT_PARAM); } +#line 2287 "src/parse-gram.c" break; case 23: -#line 336 "src/parse-gram.y" /* yacc.c:1652 */ - { current_param = param_none; } -#line 2438 "src/parse-gram.c" /* yacc.c:1652 */ +#line 348 "src/parse-gram.y" + { current_param = param_none; } +#line 2293 "src/parse-gram.c" break; case 24: -#line 337 "src/parse-gram.y" /* yacc.c:1652 */ - { handle_require (&(yylsp[0]), (yyvsp[0].STRING)); } -#line 2444 "src/parse-gram.c" /* yacc.c:1652 */ +#line 349 "src/parse-gram.y" + { handle_pure_parser (&(yyloc), (yyvsp[0].PERCENT_PURE_PARSER)); } +#line 2299 "src/parse-gram.c" break; case 25: -#line 338 "src/parse-gram.y" /* yacc.c:1652 */ - { handle_skeleton (&(yylsp[0]), (yyvsp[0].STRING)); } -#line 2450 "src/parse-gram.c" /* yacc.c:1652 */ +#line 350 "src/parse-gram.y" + { handle_require (&(yylsp[0]), (yyvsp[0].STRING)); } +#line 2305 "src/parse-gram.c" break; case 26: -#line 339 "src/parse-gram.y" /* yacc.c:1652 */ - { token_table_flag = true; } -#line 2456 "src/parse-gram.c" /* yacc.c:1652 */ +#line 351 "src/parse-gram.y" + { handle_skeleton (&(yylsp[0]), (yyvsp[0].STRING)); } +#line 2311 "src/parse-gram.c" break; case 27: -#line 340 "src/parse-gram.y" /* yacc.c:1652 */ - { report_flag |= report_states; } -#line 2462 "src/parse-gram.c" /* yacc.c:1652 */ +#line 352 "src/parse-gram.y" + { token_table_flag = true; } +#line 2317 "src/parse-gram.c" break; case 28: -#line 341 "src/parse-gram.y" /* yacc.c:1652 */ - { handle_yacc (&(yyloc), (yyvsp[0].PERCENT_YACC)); } -#line 2468 "src/parse-gram.c" /* yacc.c:1652 */ +#line 353 "src/parse-gram.y" + { report_flag |= report_states; } +#line 2323 "src/parse-gram.c" break; case 29: -#line 342 "src/parse-gram.y" /* yacc.c:1652 */ - { current_class = unknown_sym; yyerrok; } -#line 2474 "src/parse-gram.c" /* yacc.c:1652 */ +#line 354 "src/parse-gram.y" + { handle_yacc (&(yyloc)); } +#line 2329 "src/parse-gram.c" break; - case 31: -#line 347 "src/parse-gram.y" /* yacc.c:1652 */ - { add_param (current_param, (yyvsp[0].BRACED_CODE), (yylsp[0])); } -#line 2480 "src/parse-gram.c" /* yacc.c:1652 */ + case 30: +#line 355 "src/parse-gram.y" + { current_class = unknown_sym; yyerrok; } +#line 2335 "src/parse-gram.c" break; case 32: -#line 348 "src/parse-gram.y" /* yacc.c:1652 */ - { add_param (current_param, (yyvsp[0].BRACED_CODE), (yylsp[0])); } -#line 2486 "src/parse-gram.c" /* yacc.c:1652 */ +#line 360 "src/parse-gram.y" + { add_param (current_param, (yyvsp[0].BRACED_CODE), (yylsp[0])); } +#line 2341 "src/parse-gram.c" + break; + + case 33: +#line 361 "src/parse-gram.y" + { add_param (current_param, (yyvsp[0].BRACED_CODE), (yylsp[0])); } +#line 2347 "src/parse-gram.c" break; - case 34: -#line 359 "src/parse-gram.y" /* yacc.c:1652 */ + case 35: +#line 372 "src/parse-gram.y" { grammar_start_symbol_set ((yyvsp[0].symbol), (yylsp[0])); } -#line 2494 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2355 "src/parse-gram.c" break; - case 35: -#line 363 "src/parse-gram.y" /* yacc.c:1652 */ + case 36: +#line 376 "src/parse-gram.y" { code_props code; code_props_symbol_action_init (&code, (yyvsp[-1].BRACED_CODE), (yylsp[-1])); @@ -2505,27 +2366,27 @@ YYLTYPE yylloc = yyloc_default; symbol_list_free ((yyvsp[0].generic_symlist)); } } -#line 2509 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2370 "src/parse-gram.c" break; - case 36: -#line 374 "src/parse-gram.y" /* yacc.c:1652 */ + case 37: +#line 387 "src/parse-gram.y" { default_prec = true; } -#line 2517 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2378 "src/parse-gram.c" break; - case 37: -#line 378 "src/parse-gram.y" /* yacc.c:1652 */ + case 38: +#line 391 "src/parse-gram.y" { default_prec = false; } -#line 2525 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2386 "src/parse-gram.c" break; - case 38: -#line 382 "src/parse-gram.y" /* yacc.c:1652 */ + case 39: +#line 395 "src/parse-gram.y" { /* Do not invoke muscle_percent_code_grow here since it invokes muscle_user_name_list_grow. */ @@ -2533,493 +2394,512 @@ YYLTYPE yylloc = yyloc_default; translate_code_braceless ((yyvsp[0].BRACED_CODE), (yylsp[0])), (yylsp[0])); code_scanner_last_string_free (); } -#line 2537 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2398 "src/parse-gram.c" break; - case 39: -#line 390 "src/parse-gram.y" /* yacc.c:1652 */ + case 40: +#line 403 "src/parse-gram.y" { muscle_percent_code_grow ((yyvsp[-1].ID), (yylsp[-1]), translate_code_braceless ((yyvsp[0].BRACED_CODE), (yylsp[0])), (yylsp[0])); code_scanner_last_string_free (); } -#line 2546 "src/parse-gram.c" /* yacc.c:1652 */ - break; - - case 40: -#line 399 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.code_props_type) = destructor; } -#line 2552 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2407 "src/parse-gram.c" break; case 41: -#line 400 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.code_props_type) = printer; } -#line 2558 "src/parse-gram.c" /* yacc.c:1652 */ +#line 412 "src/parse-gram.y" + { (yyval.code_props_type) = destructor; } +#line 2413 "src/parse-gram.c" break; case 42: -#line 410 "src/parse-gram.y" /* yacc.c:1652 */ - {} -#line 2564 "src/parse-gram.c" /* yacc.c:1652 */ +#line 413 "src/parse-gram.y" + { (yyval.code_props_type) = printer; } +#line 2419 "src/parse-gram.c" break; case 43: -#line 411 "src/parse-gram.y" /* yacc.c:1652 */ - { muscle_percent_define_insert ("api.value.union.name", +#line 423 "src/parse-gram.y" + {} +#line 2425 "src/parse-gram.c" + break; + + case 44: +#line 424 "src/parse-gram.y" + { muscle_percent_define_insert ("api.value.union.name", (yylsp[0]), muscle_keyword, (yyvsp[0].ID), MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE); } -#line 2572 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2433 "src/parse-gram.c" break; - case 44: -#line 418 "src/parse-gram.y" /* yacc.c:1652 */ + case 45: +#line 431 "src/parse-gram.y" { union_seen = true; muscle_code_grow ("union_members", translate_code_braceless ((yyvsp[0].BRACED_CODE), (yylsp[0])), (yylsp[0])); code_scanner_last_string_free (); } -#line 2582 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2443 "src/parse-gram.c" break; - case 45: -#line 430 "src/parse-gram.y" /* yacc.c:1652 */ - { current_class = nterm_sym; } -#line 2588 "src/parse-gram.c" /* yacc.c:1652 */ + case 46: +#line 443 "src/parse-gram.y" + { current_class = nterm_sym; } +#line 2449 "src/parse-gram.c" break; - case 46: -#line 431 "src/parse-gram.y" /* yacc.c:1652 */ + case 47: +#line 444 "src/parse-gram.y" { current_class = unknown_sym; symbol_list_free ((yyvsp[0].nterm_decls)); } -#line 2597 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2458 "src/parse-gram.c" break; - case 47: -#line 435 "src/parse-gram.y" /* yacc.c:1652 */ - { current_class = token_sym; } -#line 2603 "src/parse-gram.c" /* yacc.c:1652 */ + case 48: +#line 448 "src/parse-gram.y" + { current_class = token_sym; } +#line 2464 "src/parse-gram.c" break; - case 48: -#line 436 "src/parse-gram.y" /* yacc.c:1652 */ + case 49: +#line 449 "src/parse-gram.y" { current_class = unknown_sym; symbol_list_free ((yyvsp[0].token_decls)); } -#line 2612 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2473 "src/parse-gram.c" break; - case 49: -#line 441 "src/parse-gram.y" /* yacc.c:1652 */ + case 50: +#line 454 "src/parse-gram.y" { symbol_list_free ((yyvsp[0].symbol_decls)); } -#line 2620 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2481 "src/parse-gram.c" break; - case 50: -#line 445 "src/parse-gram.y" /* yacc.c:1652 */ + case 51: +#line 458 "src/parse-gram.y" { ++current_prec; for (symbol_list *list = (yyvsp[0].token_decls_for_prec); list; list = list->next) symbol_precedence_set (list->content.sym, current_prec, (yyvsp[-1].precedence_declarator), (yylsp[-1])); symbol_list_free ((yyvsp[0].token_decls_for_prec)); } -#line 2631 "src/parse-gram.c" /* yacc.c:1652 */ - break; - - case 51: -#line 454 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.precedence_declarator) = left_assoc; } -#line 2637 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2492 "src/parse-gram.c" break; case 52: -#line 455 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.precedence_declarator) = right_assoc; } -#line 2643 "src/parse-gram.c" /* yacc.c:1652 */ +#line 467 "src/parse-gram.y" + { (yyval.precedence_declarator) = left_assoc; } +#line 2498 "src/parse-gram.c" break; case 53: -#line 456 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.precedence_declarator) = non_assoc; } -#line 2649 "src/parse-gram.c" /* yacc.c:1652 */ +#line 468 "src/parse-gram.y" + { (yyval.precedence_declarator) = right_assoc; } +#line 2504 "src/parse-gram.c" break; case 54: -#line 457 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.precedence_declarator) = precedence_assoc; } -#line 2655 "src/parse-gram.c" /* yacc.c:1652 */ +#line 469 "src/parse-gram.y" + { (yyval.precedence_declarator) = non_assoc; } +#line 2510 "src/parse-gram.c" break; case 55: -#line 461 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.yytype_71) = NULL; } -#line 2661 "src/parse-gram.c" /* yacc.c:1652 */ +#line 470 "src/parse-gram.y" + { (yyval.precedence_declarator) = precedence_assoc; } +#line 2516 "src/parse-gram.c" break; case 56: -#line 462 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.yytype_71) = (yyvsp[0].TAG); } -#line 2667 "src/parse-gram.c" /* yacc.c:1652 */ +#line 474 "src/parse-gram.y" + { (yyval.yytype_73) = NULL; } +#line 2522 "src/parse-gram.c" break; - case 58: -#line 468 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.generic_symlist) = symbol_list_append ((yyvsp[-1].generic_symlist), (yyvsp[0].generic_symlist_item)); } -#line 2673 "src/parse-gram.c" /* yacc.c:1652 */ + case 57: +#line 475 "src/parse-gram.y" + { (yyval.yytype_73) = (yyvsp[0].TAG); } +#line 2528 "src/parse-gram.c" break; case 59: -#line 472 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.generic_symlist_item) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])); } -#line 2679 "src/parse-gram.c" /* yacc.c:1652 */ +#line 481 "src/parse-gram.y" + { (yyval.generic_symlist) = symbol_list_append ((yyvsp[-1].generic_symlist), (yyvsp[0].generic_symlist_item)); } +#line 2534 "src/parse-gram.c" break; case 60: -#line 473 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.generic_symlist_item) = symbol_list_type_new ((yyvsp[0].tag), (yylsp[0])); } -#line 2685 "src/parse-gram.c" /* yacc.c:1652 */ +#line 485 "src/parse-gram.y" + { (yyval.generic_symlist_item) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])); } +#line 2540 "src/parse-gram.c" break; - case 62: -#line 478 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.tag) = uniqstr_new ("*"); } -#line 2691 "src/parse-gram.c" /* yacc.c:1652 */ + case 61: +#line 486 "src/parse-gram.y" + { (yyval.generic_symlist_item) = symbol_list_type_new ((yyvsp[0].tag), (yylsp[0])); } +#line 2546 "src/parse-gram.c" break; case 63: -#line 479 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.tag) = uniqstr_new (""); } -#line 2697 "src/parse-gram.c" /* yacc.c:1652 */ +#line 491 "src/parse-gram.y" + { (yyval.tag) = uniqstr_new ("*"); } +#line 2552 "src/parse-gram.c" break; - case 65: -#line 502 "src/parse-gram.y" /* yacc.c:1652 */ - { - (yyval.token_decls) = (yyvsp[0].yytype_77); - } -#line 2705 "src/parse-gram.c" /* yacc.c:1652 */ + case 64: +#line 492 "src/parse-gram.y" + { (yyval.tag) = uniqstr_new (""); } +#line 2558 "src/parse-gram.c" break; case 66: -#line 506 "src/parse-gram.y" /* yacc.c:1652 */ +#line 515 "src/parse-gram.y" { - (yyval.token_decls) = symbol_list_type_set ((yyvsp[0].yytype_77), (yyvsp[-1].TAG), (yylsp[-1])); + (yyval.token_decls) = (yyvsp[0].yytype_79); } -#line 2713 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2566 "src/parse-gram.c" break; case 67: -#line 510 "src/parse-gram.y" /* yacc.c:1652 */ +#line 519 "src/parse-gram.y" { - (yyval.token_decls) = symbol_list_append ((yyvsp[-2].token_decls), symbol_list_type_set ((yyvsp[0].yytype_77), (yyvsp[-1].TAG), (yylsp[-1]))); + (yyval.token_decls) = symbol_list_type_set ((yyvsp[0].yytype_79), (yyvsp[-1].TAG), (yylsp[-1])); } -#line 2721 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2574 "src/parse-gram.c" break; case 68: -#line 517 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.yytype_77) = symbol_list_sym_new ((yyvsp[0].token_decl), (yylsp[0])); } -#line 2727 "src/parse-gram.c" /* yacc.c:1652 */ +#line 523 "src/parse-gram.y" + { + (yyval.token_decls) = symbol_list_append ((yyvsp[-2].token_decls), symbol_list_type_set ((yyvsp[0].yytype_79), (yyvsp[-1].TAG), (yylsp[-1]))); + } +#line 2582 "src/parse-gram.c" break; case 69: -#line 518 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.yytype_77) = symbol_list_append ((yyvsp[-1].yytype_77), symbol_list_sym_new ((yyvsp[0].token_decl), (yylsp[0]))); } -#line 2733 "src/parse-gram.c" /* yacc.c:1652 */ +#line 530 "src/parse-gram.y" + { (yyval.yytype_79) = symbol_list_sym_new ((yyvsp[0].token_decl), (yylsp[0])); } +#line 2588 "src/parse-gram.c" break; case 70: -#line 523 "src/parse-gram.y" /* yacc.c:1652 */ +#line 531 "src/parse-gram.y" + { (yyval.yytype_79) = symbol_list_append ((yyvsp[-1].yytype_79), symbol_list_sym_new ((yyvsp[0].token_decl), (yylsp[0]))); } +#line 2594 "src/parse-gram.c" + break; + + case 71: +#line 536 "src/parse-gram.y" { (yyval.token_decl) = (yyvsp[-2].id); symbol_class_set ((yyvsp[-2].id), current_class, (yylsp[-2]), true); - if (0 <= (yyvsp[-1].yytype_79)) - symbol_user_token_number_set ((yyvsp[-2].id), (yyvsp[-1].yytype_79), (yylsp[-1])); - if ((yyvsp[0].yytype_98)) - symbol_make_alias ((yyvsp[-2].id), (yyvsp[0].yytype_98), (yylsp[0])); + if (0 <= (yyvsp[-1].yytype_81)) + symbol_user_token_number_set ((yyvsp[-2].id), (yyvsp[-1].yytype_81), (yylsp[-1])); + if ((yyvsp[0].yytype_100)) + symbol_make_alias ((yyvsp[-2].id), (yyvsp[0].yytype_100), (yylsp[0])); } -#line 2746 "src/parse-gram.c" /* yacc.c:1652 */ - break; - - case 71: -#line 535 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.yytype_79) = -1; } -#line 2752 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2607 "src/parse-gram.c" break; - case 73: -#line 549 "src/parse-gram.y" /* yacc.c:1652 */ - { - (yyval.token_decls_for_prec) = (yyvsp[0].yytype_81); - } -#line 2760 "src/parse-gram.c" /* yacc.c:1652 */ + case 72: +#line 548 "src/parse-gram.y" + { (yyval.yytype_81) = -1; } +#line 2613 "src/parse-gram.c" break; case 74: -#line 553 "src/parse-gram.y" /* yacc.c:1652 */ +#line 562 "src/parse-gram.y" { - (yyval.token_decls_for_prec) = symbol_list_type_set ((yyvsp[0].yytype_81), (yyvsp[-1].TAG), (yylsp[-1])); + (yyval.token_decls_for_prec) = (yyvsp[0].yytype_83); } -#line 2768 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2621 "src/parse-gram.c" break; case 75: -#line 557 "src/parse-gram.y" /* yacc.c:1652 */ +#line 566 "src/parse-gram.y" { - (yyval.token_decls_for_prec) = symbol_list_append ((yyvsp[-2].token_decls_for_prec), symbol_list_type_set ((yyvsp[0].yytype_81), (yyvsp[-1].TAG), (yylsp[-1]))); + (yyval.token_decls_for_prec) = symbol_list_type_set ((yyvsp[0].yytype_83), (yyvsp[-1].TAG), (yylsp[-1])); } -#line 2776 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2629 "src/parse-gram.c" break; case 76: -#line 565 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.yytype_81) = symbol_list_sym_new ((yyvsp[0].token_decl_for_prec), (yylsp[0])); } -#line 2782 "src/parse-gram.c" /* yacc.c:1652 */ +#line 570 "src/parse-gram.y" + { + (yyval.token_decls_for_prec) = symbol_list_append ((yyvsp[-2].token_decls_for_prec), symbol_list_type_set ((yyvsp[0].yytype_83), (yyvsp[-1].TAG), (yylsp[-1]))); + } +#line 2637 "src/parse-gram.c" break; case 77: -#line 567 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.yytype_81) = symbol_list_append ((yyvsp[-1].yytype_81), symbol_list_sym_new ((yyvsp[0].token_decl_for_prec), (yylsp[0]))); } -#line 2788 "src/parse-gram.c" /* yacc.c:1652 */ +#line 578 "src/parse-gram.y" + { (yyval.yytype_83) = symbol_list_sym_new ((yyvsp[0].token_decl_for_prec), (yylsp[0])); } +#line 2643 "src/parse-gram.c" break; case 78: -#line 572 "src/parse-gram.y" /* yacc.c:1652 */ - { - (yyval.token_decl_for_prec) = (yyvsp[-1].id); - symbol_class_set ((yyvsp[-1].id), token_sym, (yylsp[-1]), false); - if (0 <= (yyvsp[0].yytype_79)) - symbol_user_token_number_set ((yyvsp[-1].id), (yyvsp[0].yytype_79), (yylsp[0])); - } -#line 2799 "src/parse-gram.c" /* yacc.c:1652 */ +#line 580 "src/parse-gram.y" + { (yyval.yytype_83) = symbol_list_append ((yyvsp[-1].yytype_83), symbol_list_sym_new ((yyvsp[0].token_decl_for_prec), (yylsp[0]))); } +#line 2649 "src/parse-gram.c" break; - case 80: -#line 589 "src/parse-gram.y" /* yacc.c:1652 */ + case 79: +#line 585 "src/parse-gram.y" { - (yyval.symbol_decls) = (yyvsp[0].yytype_84); + (yyval.token_decl_for_prec) = (yyvsp[-1].id); + symbol_class_set ((yyvsp[-1].id), token_sym, (yylsp[-1]), false); + if (0 <= (yyvsp[0].yytype_81)) + symbol_user_token_number_set ((yyvsp[-1].id), (yyvsp[0].yytype_81), (yylsp[0])); } -#line 2807 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2660 "src/parse-gram.c" break; case 81: -#line 593 "src/parse-gram.y" /* yacc.c:1652 */ +#line 602 "src/parse-gram.y" { - (yyval.symbol_decls) = symbol_list_type_set ((yyvsp[0].yytype_84), (yyvsp[-1].TAG), (yylsp[-1])); + (yyval.symbol_decls) = (yyvsp[0].yytype_86); } -#line 2815 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2668 "src/parse-gram.c" break; case 82: -#line 597 "src/parse-gram.y" /* yacc.c:1652 */ +#line 606 "src/parse-gram.y" { - (yyval.symbol_decls) = symbol_list_append ((yyvsp[-2].symbol_decls), symbol_list_type_set ((yyvsp[0].yytype_84), (yyvsp[-1].TAG), (yylsp[-1]))); + (yyval.symbol_decls) = symbol_list_type_set ((yyvsp[0].yytype_86), (yyvsp[-1].TAG), (yylsp[-1])); } -#line 2823 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2676 "src/parse-gram.c" break; case 83: -#line 604 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.yytype_84) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])); } -#line 2829 "src/parse-gram.c" /* yacc.c:1652 */ +#line 610 "src/parse-gram.y" + { + (yyval.symbol_decls) = symbol_list_append ((yyvsp[-2].symbol_decls), symbol_list_type_set ((yyvsp[0].yytype_86), (yyvsp[-1].TAG), (yylsp[-1]))); + } +#line 2684 "src/parse-gram.c" break; case 84: -#line 605 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.yytype_84) = symbol_list_append ((yyvsp[-1].yytype_84), symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0]))); } -#line 2835 "src/parse-gram.c" /* yacc.c:1652 */ +#line 618 "src/parse-gram.y" + { + symbol_class_set ((yyvsp[0].symbol), pct_type_sym, (yylsp[0]), false); + (yyval.yytype_86) = symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0])); + } +#line 2693 "src/parse-gram.c" break; - case 89: -#line 623 "src/parse-gram.y" /* yacc.c:1652 */ + case 85: +#line 623 "src/parse-gram.y" { - yyerrok; + symbol_class_set ((yyvsp[0].symbol), pct_type_sym, (yylsp[0]), false); + (yyval.yytype_86) = symbol_list_append ((yyvsp[-1].yytype_86), symbol_list_sym_new ((yyvsp[0].symbol), (yylsp[0]))); } -#line 2843 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2702 "src/parse-gram.c" break; case 90: -#line 629 "src/parse-gram.y" /* yacc.c:1652 */ - { current_lhs ((yyvsp[-1].id_colon), (yylsp[-1]), (yyvsp[0].yytype_91)); } -#line 2849 "src/parse-gram.c" /* yacc.c:1652 */ +#line 644 "src/parse-gram.y" + { + yyerrok; + } +#line 2710 "src/parse-gram.c" break; case 91: -#line 630 "src/parse-gram.y" /* yacc.c:1652 */ - { - /* Free the current lhs. */ - current_lhs (0, (yylsp[-3]), 0); - } -#line 2858 "src/parse-gram.c" /* yacc.c:1652 */ +#line 650 "src/parse-gram.y" + { current_lhs ((yyvsp[-1].id_colon), (yylsp[-1]), (yyvsp[0].yytype_93)); } +#line 2716 "src/parse-gram.c" break; case 92: -#line 637 "src/parse-gram.y" /* yacc.c:1652 */ - { grammar_current_rule_end ((yylsp[0])); } -#line 2864 "src/parse-gram.c" /* yacc.c:1652 */ +#line 651 "src/parse-gram.y" + { + /* Free the current lhs. */ + current_lhs (0, (yylsp[-4]), 0); + } +#line 2725 "src/parse-gram.c" break; case 93: -#line 638 "src/parse-gram.y" /* yacc.c:1652 */ - { grammar_current_rule_end ((yylsp[0])); } -#line 2870 "src/parse-gram.c" /* yacc.c:1652 */ +#line 658 "src/parse-gram.y" + { grammar_current_rule_end ((yylsp[0])); } +#line 2731 "src/parse-gram.c" break; - case 95: -#line 645 "src/parse-gram.y" /* yacc.c:1652 */ - { grammar_current_rule_begin (current_lhs_symbol, current_lhs_location, - current_lhs_named_ref); } -#line 2877 "src/parse-gram.c" /* yacc.c:1652 */ + case 94: +#line 659 "src/parse-gram.y" + { grammar_current_rule_end ((yylsp[0])); } +#line 2737 "src/parse-gram.c" break; case 96: -#line 648 "src/parse-gram.y" /* yacc.c:1652 */ - { grammar_current_rule_symbol_append ((yyvsp[-1].symbol), (yylsp[-1]), (yyvsp[0].yytype_91)); } -#line 2883 "src/parse-gram.c" /* yacc.c:1652 */ +#line 666 "src/parse-gram.y" + { grammar_current_rule_begin (current_lhs_symbol, current_lhs_loc, + current_lhs_named_ref); } +#line 2744 "src/parse-gram.c" break; case 97: -#line 650 "src/parse-gram.y" /* yacc.c:1652 */ - { grammar_current_rule_action_append ((yyvsp[-1].BRACED_CODE), (yylsp[-1]), (yyvsp[0].yytype_91), (yyvsp[-2].yytype_71)); } -#line 2889 "src/parse-gram.c" /* yacc.c:1652 */ +#line 669 "src/parse-gram.y" + { grammar_current_rule_symbol_append ((yyvsp[-1].symbol), (yylsp[-1]), (yyvsp[0].yytype_93)); } +#line 2750 "src/parse-gram.c" break; case 98: -#line 652 "src/parse-gram.y" /* yacc.c:1652 */ - { grammar_current_rule_predicate_append ((yyvsp[0].BRACED_PREDICATE), (yylsp[0])); } -#line 2895 "src/parse-gram.c" /* yacc.c:1652 */ +#line 671 "src/parse-gram.y" + { grammar_current_rule_action_append ((yyvsp[-1].BRACED_CODE), (yylsp[-1]), (yyvsp[0].yytype_93), (yyvsp[-2].yytype_73)); } +#line 2756 "src/parse-gram.c" break; case 99: -#line 654 "src/parse-gram.y" /* yacc.c:1652 */ - { grammar_current_rule_empty_set ((yylsp[0])); } -#line 2901 "src/parse-gram.c" /* yacc.c:1652 */ +#line 673 "src/parse-gram.y" + { grammar_current_rule_predicate_append ((yyvsp[0].BRACED_PREDICATE), (yylsp[0])); } +#line 2762 "src/parse-gram.c" break; case 100: -#line 656 "src/parse-gram.y" /* yacc.c:1652 */ - { grammar_current_rule_prec_set ((yyvsp[0].symbol), (yylsp[0])); } -#line 2907 "src/parse-gram.c" /* yacc.c:1652 */ +#line 675 "src/parse-gram.y" + { grammar_current_rule_empty_set ((yylsp[0])); } +#line 2768 "src/parse-gram.c" break; case 101: -#line 658 "src/parse-gram.y" /* yacc.c:1652 */ - { grammar_current_rule_dprec_set ((yyvsp[0].INT), (yylsp[0])); } -#line 2913 "src/parse-gram.c" /* yacc.c:1652 */ +#line 677 "src/parse-gram.y" + { grammar_current_rule_prec_set ((yyvsp[0].symbol), (yylsp[0])); } +#line 2774 "src/parse-gram.c" break; case 102: -#line 660 "src/parse-gram.y" /* yacc.c:1652 */ - { grammar_current_rule_merge_set ((yyvsp[0].TAG), (yylsp[0])); } -#line 2919 "src/parse-gram.c" /* yacc.c:1652 */ +#line 679 "src/parse-gram.y" + { grammar_current_rule_dprec_set ((yyvsp[0].INT), (yylsp[0])); } +#line 2780 "src/parse-gram.c" break; case 103: -#line 662 "src/parse-gram.y" /* yacc.c:1652 */ - { grammar_current_rule_expect_sr ((yyvsp[0].INT), (yylsp[0])); } -#line 2925 "src/parse-gram.c" /* yacc.c:1652 */ +#line 681 "src/parse-gram.y" + { grammar_current_rule_merge_set ((yyvsp[0].TAG), (yylsp[0])); } +#line 2786 "src/parse-gram.c" break; case 104: -#line 664 "src/parse-gram.y" /* yacc.c:1652 */ - { grammar_current_rule_expect_rr ((yyvsp[0].INT), (yylsp[0])); } -#line 2931 "src/parse-gram.c" /* yacc.c:1652 */ +#line 683 "src/parse-gram.y" + { grammar_current_rule_expect_sr ((yyvsp[0].INT), (yylsp[0])); } +#line 2792 "src/parse-gram.c" break; case 105: -#line 668 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.yytype_91) = 0; } -#line 2937 "src/parse-gram.c" /* yacc.c:1652 */ +#line 685 "src/parse-gram.y" + { grammar_current_rule_expect_rr ((yyvsp[0].INT), (yylsp[0])); } +#line 2798 "src/parse-gram.c" break; case 106: -#line 669 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.yytype_91) = named_ref_new ((yyvsp[0].BRACKETED_ID), (yylsp[0])); } -#line 2943 "src/parse-gram.c" /* yacc.c:1652 */ +#line 689 "src/parse-gram.y" + { (yyval.yytype_93) = NULL; } +#line 2804 "src/parse-gram.c" break; - case 108: -#line 702 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.value).kind = muscle_keyword; (yyval.value).chars = ""; } -#line 2949 "src/parse-gram.c" /* yacc.c:1652 */ + case 107: +#line 690 "src/parse-gram.y" + { (yyval.yytype_93) = named_ref_new ((yyvsp[0].BRACKETED_ID), (yylsp[0])); } +#line 2810 "src/parse-gram.c" break; case 109: -#line 703 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.value).kind = muscle_keyword; (yyval.value).chars = (yyvsp[0].ID); } -#line 2955 "src/parse-gram.c" /* yacc.c:1652 */ +#line 723 "src/parse-gram.y" + { (yyval.value).kind = muscle_keyword; (yyval.value).chars = ""; } +#line 2816 "src/parse-gram.c" break; case 110: -#line 704 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.value).kind = muscle_string; (yyval.value).chars = (yyvsp[0].STRING); } -#line 2961 "src/parse-gram.c" /* yacc.c:1652 */ +#line 724 "src/parse-gram.y" + { (yyval.value).kind = muscle_keyword; (yyval.value).chars = (yyvsp[0].ID); } +#line 2822 "src/parse-gram.c" break; case 111: -#line 705 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.value).kind = muscle_code; (yyval.value).chars = strip_braces ((yyvsp[0].BRACED_CODE)); } -#line 2967 "src/parse-gram.c" /* yacc.c:1652 */ +#line 725 "src/parse-gram.y" + { (yyval.value).kind = muscle_string; (yyval.value).chars = (yyvsp[0].STRING); } +#line 2828 "src/parse-gram.c" break; case 112: -#line 718 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.id) = symbol_from_uniqstr ((yyvsp[0].ID), (yylsp[0])); } -#line 2973 "src/parse-gram.c" /* yacc.c:1652 */ +#line 726 "src/parse-gram.y" + { (yyval.value).kind = muscle_code; (yyval.value).chars = strip_braces ((yyvsp[0].BRACED_CODE)); } +#line 2834 "src/parse-gram.c" break; case 113: -#line 720 "src/parse-gram.y" /* yacc.c:1652 */ +#line 739 "src/parse-gram.y" + { (yyval.id) = symbol_from_uniqstr ((yyvsp[0].ID), (yylsp[0])); } +#line 2840 "src/parse-gram.c" + break; + + case 114: +#line 741 "src/parse-gram.y" { + const char *var = "api.token.raw"; if (current_class == nterm_sym) { - gram_error (&(yylsp[0]), - _("character literals cannot be nonterminals")); + complain (&(yylsp[0]), complaint, + _("character literals cannot be nonterminals")); YYERROR; } + if (muscle_percent_define_ifdef (var)) + { + int indent = 0; + complain_indent (&(yylsp[0]), complaint, &indent, + _("character literals cannot be used together" + " with %s"), var); + indent += SUB_INDENT; + location loc = muscle_percent_define_get_loc (var); + complain_indent (&loc, complaint, &indent, + _("definition of %s"), var); + } (yyval.id) = symbol_get (char_name ((yyvsp[0].CHAR)), (yylsp[0])); symbol_class_set ((yyval.id), token_sym, (yylsp[0]), false); symbol_user_token_number_set ((yyval.id), (yyvsp[0].CHAR), (yylsp[0])); } -#line 2989 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2868 "src/parse-gram.c" break; - case 114: -#line 734 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.id_colon) = symbol_from_uniqstr ((yyvsp[0].ID_COLON), (yylsp[0])); } -#line 2995 "src/parse-gram.c" /* yacc.c:1652 */ + case 115: +#line 767 "src/parse-gram.y" + { (yyval.id_colon) = symbol_from_uniqstr ((yyvsp[0].ID_COLON), (yylsp[0])); } +#line 2874 "src/parse-gram.c" break; - case 117: -#line 746 "src/parse-gram.y" /* yacc.c:1652 */ + case 118: +#line 779 "src/parse-gram.y" { (yyval.string_as_id) = symbol_get (quotearg_style (c_quoting_style, (yyvsp[0].STRING)), (yylsp[0])); symbol_class_set ((yyval.string_as_id), token_sym, (yylsp[0]), false); } -#line 3004 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2883 "src/parse-gram.c" break; - case 118: -#line 754 "src/parse-gram.y" /* yacc.c:1652 */ - { (yyval.yytype_98) = NULL; } -#line 3010 "src/parse-gram.c" /* yacc.c:1652 */ + case 119: +#line 787 "src/parse-gram.y" + { (yyval.yytype_100) = NULL; } +#line 2889 "src/parse-gram.c" break; - case 121: -#line 761 "src/parse-gram.y" /* yacc.c:1652 */ + case 122: +#line 794 "src/parse-gram.y" { muscle_code_grow ("epilogue", translate_code ((yyvsp[0].EPILOGUE), (yylsp[0]), true), (yylsp[0])); code_scanner_last_string_free (); } -#line 3019 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2898 "src/parse-gram.c" break; -#line 3023 "src/parse-gram.c" /* yacc.c:1652 */ +#line 2902 "src/parse-gram.c" + default: break; } if (yychar_backup != yychar) @@ -3089,7 +2969,7 @@ YYLTYPE yylloc = yyloc_default; { if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + yymsg = YY_CAST (char *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc))); if (!yymsg) { yymsg = yymsgbuf; @@ -3253,7 +3133,7 @@ YYLTYPE yylloc = yyloc_default; while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, yylsp); + yystos[+*yyssp], yyvsp, yylsp); YYPOPSTACK (1); } #ifndef yyoverflow @@ -3268,7 +3148,7 @@ YYLTYPE yylloc = yyloc_default; #endif return yyresult; } -#line 767 "src/parse-gram.y" /* yacc.c:1918 */ +#line 800 "src/parse-gram.y" /* Return the location of the left-hand side of a rule whose @@ -3406,6 +3286,7 @@ handle_file_prefix (location const *loc, deprecated_directive (dir_loc, directive, "%file-prefix"); } + static void handle_name_prefix (location const *loc, char const *directive, char const *value) @@ -3441,36 +3322,64 @@ handle_name_prefix (location const *loc, static void -handle_require (location const *loc, char const *version) +handle_pure_parser (location const *loc, char const *directive) +{ + bison_directive (loc, directive); + deprecated_directive (loc, directive, "%define api.pure"); + muscle_percent_define_insert ("api.pure", *loc, muscle_keyword, "", + MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE); +} + + +/* Convert VERSION into an int (MAJOR * 100 + MINOR). Return -1 on + errors. + + Changes of behavior are only on minor version changes, so "3.0.5" + is the same as "3.0": 300. */ +static int +str_to_version (char const *version) { - /* Changes of behavior are only on minor version changes, so "3.0.5" - is the same as "3.0". */ + IGNORE_TYPE_LIMITS_BEGIN + int res = 0; errno = 0; - char* cp = NULL; - unsigned long major = strtoul (version, &cp, 10); - if (errno || *cp != '.') - { - complain (loc, complaint, _("invalid version requirement: %s"), - version); - return; - } + char *cp = NULL; + long major = strtol (version, &cp, 10); + if (errno || cp == version || *cp != '.' || major < 0 + || INT_MULTIPLY_WRAPV (major, 100, &res)) + return -1; + ++cp; - unsigned long minor = strtoul (cp, NULL, 10); - if (errno) + char *cp1 = NULL; + long minor = strtol (cp, &cp1, 10); + if (errno || cp1 == cp || (*cp1 != '\0' && *cp1 != '.') + || ! (0 <= minor && minor < 100) + || INT_ADD_WRAPV (minor, res, &res)) + return -1; + + IGNORE_TYPE_LIMITS_END + return res; +} + + +static void +handle_require (location const *loc, char const *version) +{ + required_version = str_to_version (version); + if (required_version == -1) { complain (loc, complaint, _("invalid version requirement: %s"), version); + required_version = 0; return; } - required_version = major * 100 + minor; - /* Pretend to be at least 3.2, even if we are only 3.1-211, as it - allows us to check features published in 3.2 while developping - 3.2. */ - const char* api_version = "3.2"; + + /* Pretend to be at least 3.5, to check features published in that + version while developping it. */ + const char* api_version = "3.5"; const char* package_version = - strverscmp (api_version, PACKAGE_VERSION) > 0 + 0 < strverscmp (api_version, PACKAGE_VERSION) ? api_version : PACKAGE_VERSION; - if (strverscmp (version, package_version) > 0) + if (0 < strverscmp (version, package_version)) { complain (loc, complaint, _("require bison %s, but have %s"), version, package_version); @@ -3484,16 +3393,16 @@ handle_skeleton (location const *loc, char const *skel) char const *skeleton_user = skel; if (strchr (skeleton_user, '/')) { - size_t dir_length = strlen (current_file); - while (dir_length && current_file[dir_length - 1] != '/') + size_t dir_length = strlen (grammar_file); + while (dir_length && grammar_file[dir_length - 1] != '/') --dir_length; - while (dir_length && current_file[dir_length - 1] == '/') + while (dir_length && grammar_file[dir_length - 1] == '/') --dir_length; char *skeleton_build = xmalloc (dir_length + 1 + strlen (skeleton_user) + 1); if (dir_length > 0) { - memcpy (skeleton_build, current_file, dir_length); + memcpy (skeleton_build, grammar_file, dir_length); skeleton_build[dir_length++] = '/'; } strcpy (skeleton_build + dir_length, skeleton_user); @@ -3503,26 +3412,19 @@ handle_skeleton (location const *loc, char const *skel) skeleton_arg (skeleton_user, grammar_prio, *loc); } + static void -handle_yacc (location const *loc, char const *directive) +handle_yacc (location const *loc) { + const char *directive = "%yacc"; bison_directive (loc, directive); - bool warned = false; - if (location_empty (yacc_loc)) yacc_loc = *loc; else - { - duplicate_directive (directive, yacc_loc, *loc); - warned = true; - } - - if (!warned - && STRNEQ (directive, "%fixed-output-files") - && STRNEQ (directive, "%yacc")) - deprecated_directive (loc, directive, "%fixed-output-files"); + duplicate_directive (directive, yacc_loc, *loc); } + static void gram_error (location const *loc, char const *msg) { @@ -3547,7 +3449,7 @@ void current_lhs (symbol *sym, location loc, named_ref *ref) { current_lhs_symbol = sym; - current_lhs_location = loc; + current_lhs_loc = loc; if (sym) symbol_location_as_lhs_set (sym, loc); /* In order to simplify memory management, named references for lhs @@ -3558,3 +3460,13 @@ current_lhs (symbol *sym, location loc, named_ref *ref) free (current_lhs_named_ref); current_lhs_named_ref = ref; } + +static void tron (FILE *yyo) +{ + begin_use_class ("value", yyo); +} + +static void troff (FILE *yyo) +{ + end_use_class ("value", yyo); +} diff --git a/contrib/tools/bison/src/parse-gram.h b/contrib/tools/bison/src/parse-gram.h index 935488ff28bb..3a36b3c27370 100644 --- a/contrib/tools/bison/src/parse-gram.h +++ b/contrib/tools/bison/src/parse-gram.h @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.2.90.23-0bbcb-dirty. */ +/* A Bison parser, made by GNU Bison 3.5.4. */ /* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation, + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -52,11 +52,11 @@ extern int gram_debug; #endif /* "%code requires" blocks. */ -#line 21 "src/parse-gram.y" /* yacc.c:1921 */ +#line 21 "src/parse-gram.y" #include "symlist.h" #include "symtab.h" -#line 239 "src/parse-gram.y" /* yacc.c:1921 */ +#line 251 "src/parse-gram.y" typedef enum { @@ -65,7 +65,7 @@ extern int gram_debug; param_parse = 1 << 1, param_both = param_lex | param_parse } param_type; -#line 682 "src/parse-gram.y" /* yacc.c:1921 */ +#line 703 "src/parse-gram.y" #include "muscle-tab.h" typedef struct @@ -74,7 +74,7 @@ extern int gram_debug; muscle_kind kind; } value_type; -#line 78 "src/parse-gram.h" /* yacc.c:1921 */ +#line 78 "src/parse-gram.h" /* Token type. */ #ifndef GRAM_TOKENTYPE @@ -82,67 +82,68 @@ extern int gram_debug; enum gram_tokentype { GRAM_EOF = 0, - STRING = 258, - PERCENT_TOKEN = 259, - PERCENT_NTERM = 260, - PERCENT_TYPE = 261, - PERCENT_DESTRUCTOR = 262, - PERCENT_PRINTER = 263, - PERCENT_LEFT = 264, - PERCENT_RIGHT = 265, - PERCENT_NONASSOC = 266, - PERCENT_PRECEDENCE = 267, - PERCENT_PREC = 268, - PERCENT_DPREC = 269, - PERCENT_MERGE = 270, - PERCENT_CODE = 271, - PERCENT_DEFAULT_PREC = 272, - PERCENT_DEFINE = 273, - PERCENT_DEFINES = 274, - PERCENT_ERROR_VERBOSE = 275, - PERCENT_EXPECT = 276, - PERCENT_EXPECT_RR = 277, - PERCENT_FLAG = 278, - PERCENT_FILE_PREFIX = 279, - PERCENT_GLR_PARSER = 280, - PERCENT_INITIAL_ACTION = 281, - PERCENT_LANGUAGE = 282, - PERCENT_NAME_PREFIX = 283, - PERCENT_NO_DEFAULT_PREC = 284, - PERCENT_NO_LINES = 285, - PERCENT_NONDETERMINISTIC_PARSER = 286, - PERCENT_OUTPUT = 287, - PERCENT_REQUIRE = 288, - PERCENT_SKELETON = 289, - PERCENT_START = 290, - PERCENT_TOKEN_TABLE = 291, - PERCENT_VERBOSE = 292, - PERCENT_YACC = 293, - BRACED_CODE = 294, - BRACED_PREDICATE = 295, - BRACKETED_ID = 296, - CHAR = 297, - EPILOGUE = 298, - EQUAL = 299, - ID = 300, - ID_COLON = 301, - PERCENT_PERCENT = 302, - PIPE = 303, - PROLOGUE = 304, - SEMICOLON = 305, - TAG = 306, - TAG_ANY = 307, - TAG_NONE = 308, - INT = 309, - PERCENT_PARAM = 310, - PERCENT_UNION = 311, - PERCENT_EMPTY = 312 + STRING = 3, + PERCENT_TOKEN = 4, + PERCENT_NTERM = 5, + PERCENT_TYPE = 6, + PERCENT_DESTRUCTOR = 7, + PERCENT_PRINTER = 8, + PERCENT_LEFT = 9, + PERCENT_RIGHT = 10, + PERCENT_NONASSOC = 11, + PERCENT_PRECEDENCE = 12, + PERCENT_PREC = 13, + PERCENT_DPREC = 14, + PERCENT_MERGE = 15, + PERCENT_CODE = 16, + PERCENT_DEFAULT_PREC = 17, + PERCENT_DEFINE = 18, + PERCENT_DEFINES = 19, + PERCENT_ERROR_VERBOSE = 20, + PERCENT_EXPECT = 21, + PERCENT_EXPECT_RR = 22, + PERCENT_FLAG = 23, + PERCENT_FILE_PREFIX = 24, + PERCENT_GLR_PARSER = 25, + PERCENT_INITIAL_ACTION = 26, + PERCENT_LANGUAGE = 27, + PERCENT_NAME_PREFIX = 28, + PERCENT_NO_DEFAULT_PREC = 29, + PERCENT_NO_LINES = 30, + PERCENT_NONDETERMINISTIC_PARSER = 31, + PERCENT_OUTPUT = 32, + PERCENT_PURE_PARSER = 33, + PERCENT_REQUIRE = 34, + PERCENT_SKELETON = 35, + PERCENT_START = 36, + PERCENT_TOKEN_TABLE = 37, + PERCENT_VERBOSE = 38, + PERCENT_YACC = 39, + BRACED_CODE = 40, + BRACED_PREDICATE = 41, + BRACKETED_ID = 42, + CHAR = 43, + COLON = 44, + EPILOGUE = 45, + EQUAL = 46, + ID = 47, + ID_COLON = 48, + PERCENT_PERCENT = 49, + PIPE = 50, + PROLOGUE = 51, + SEMICOLON = 52, + TAG = 53, + TAG_ANY = 54, + TAG_NONE = 55, + INT = 56, + PERCENT_PARAM = 57, + PERCENT_UNION = 58, + PERCENT_EMPTY = 59 }; #endif /* Value type. */ #if ! defined GRAM_STYPE && ! defined GRAM_STYPE_IS_DECLARED - union GRAM_STYPE { @@ -163,9 +164,9 @@ union GRAM_STYPE /* "integer" */ int INT; /* int.opt */ - int yytype_79; + int yytype_81; /* named_ref.opt */ - named_ref* yytype_91; + named_ref* yytype_93; /* "%param" */ param_type PERCENT_PARAM; /* token_decl */ @@ -181,7 +182,7 @@ union GRAM_STYPE /* string_as_id */ symbol* string_as_id; /* string_as_id.opt */ - symbol* yytype_98; + symbol* yytype_100; /* generic_symlist */ symbol_list* generic_symlist; /* generic_symlist_item */ @@ -191,15 +192,15 @@ union GRAM_STYPE /* token_decls */ symbol_list* token_decls; /* token_decl.1 */ - symbol_list* yytype_77; + symbol_list* yytype_79; /* token_decls_for_prec */ symbol_list* token_decls_for_prec; /* token_decl_for_prec.1 */ - symbol_list* yytype_81; + symbol_list* yytype_83; /* symbol_decls */ symbol_list* symbol_decls; /* symbol_decl.1 */ - symbol_list* yytype_84; + symbol_list* yytype_86; /* "%error-verbose" */ uniqstr PERCENT_ERROR_VERBOSE; /* "%" */ @@ -208,8 +209,8 @@ union GRAM_STYPE uniqstr PERCENT_FILE_PREFIX; /* "%name-prefix" */ uniqstr PERCENT_NAME_PREFIX; - /* "%yacc" */ - uniqstr PERCENT_YACC; + /* "%pure-parser" */ + uniqstr PERCENT_PURE_PARSER; /* "[identifier]" */ uniqstr BRACKETED_ID; /* "identifier" */ @@ -219,18 +220,18 @@ union GRAM_STYPE /* "" */ uniqstr TAG; /* tag.opt */ - uniqstr yytype_71; + uniqstr yytype_73; /* tag */ uniqstr tag; /* variable */ uniqstr variable; - /* "char" */ + /* "character literal" */ unsigned char CHAR; /* value */ value_type value; -#line 232 "src/parse-gram.h" /* yacc.c:1921 */ -}; +#line 233 "src/parse-gram.h" +}; typedef union GRAM_STYPE GRAM_STYPE; # define GRAM_STYPE_IS_TRIVIAL 1 # define GRAM_STYPE_IS_DECLARED 1 diff --git a/contrib/tools/bison/src/print_graph.c b/contrib/tools/bison/src/print-graph.c similarity index 93% rename from contrib/tools/bison/src/print_graph.c rename to contrib/tools/bison/src/print-graph.c index ec0327868677..1dd6b15e7c23 100644 --- a/contrib/tools/bison/src/print_graph.c +++ b/contrib/tools/bison/src/print-graph.c @@ -1,6 +1,6 @@ /* Output a graph of the generated parser, for Bison. - Copyright (C) 2001-2007, 2009-2015, 2018-2019 Free Software + Copyright (C) 2001-2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -19,9 +19,10 @@ along with this program. If not, see . */ #include +#include "print-graph.h" + #include "system.h" -#include "LR0.h" #include "closure.h" #include "complain.h" #include "conflicts.h" @@ -30,7 +31,7 @@ #include "gram.h" #include "graphviz.h" #include "lalr.h" -#include "print_graph.h" +#include "lr0.h" #include "reader.h" #include "state.h" #include "symtab.h" @@ -63,12 +64,7 @@ print_core (struct obstack *oout, state *s) for (size_t i = 0; i < snritems; ++i) { item_number const *sp1 = ritem + sitems[i]; - item_number const *sp = sp1; - - while (0 <= *sp) - sp++; - - rule *r = &rules[item_number_as_rule_number (*sp)]; + rule const *r = item_rule (sp1); obstack_printf (oout, "%3d ", r->number); if (previous_lhs && UNIQSTR_EQ (previous_lhs->symbol->tag, @@ -79,13 +75,13 @@ print_core (struct obstack *oout, state *s) obstack_printf (oout, "%s: ", escape (r->lhs->symbol->tag)); previous_lhs = r->lhs; - for (sp = r->rhs; sp < sp1; sp++) + for (item_number const *sp = r->rhs; sp < sp1; sp++) obstack_printf (oout, "%s ", escape (symbols[*sp]->tag)); obstack_1grow (oout, '.'); if (0 <= *r->rhs) - for (/* Nothing */; *sp >= 0; ++sp) + for (item_number const *sp = sp1; 0 <= *sp; ++sp) obstack_printf (oout, " %s", escape (symbols[*sp]->tag)); else obstack_printf (oout, " %%empty"); @@ -184,10 +180,8 @@ print_graph (void) start_graph (fgraph); /* Output nodes and edges. */ - new_closure (nritems); for (int i = 0; i < nstates; i++) print_state (states[i], fgraph); - free_closure (); finish_graph (fgraph); xfclose (fgraph); diff --git a/contrib/tools/bison/src/print_graph.h b/contrib/tools/bison/src/print-graph.h similarity index 93% rename from contrib/tools/bison/src/print_graph.h rename to contrib/tools/bison/src/print-graph.h index a3e2b6763f67..c31a5ca28a83 100644 --- a/contrib/tools/bison/src/print_graph.h +++ b/contrib/tools/bison/src/print-graph.h @@ -1,6 +1,6 @@ /* Output a graph of the generated parser, for Bison. - Copyright (C) 2000, 2006, 2009-2015, 2018-2019 Free Software + Copyright (C) 2000, 2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/src/print-xml.c b/contrib/tools/bison/src/print-xml.c index b251e1504ccc..61fb93b4bff8 100644 --- a/contrib/tools/bison/src/print-xml.c +++ b/contrib/tools/bison/src/print-xml.c @@ -1,6 +1,6 @@ /* Print an xml on generated parser, for Bison, - Copyright (C) 2007, 2009-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -19,21 +19,21 @@ along with this program. If not, see . */ #include -#include "system.h" +#include "print-xml.h" -#include +#include "system.h" #include +#include -#include "LR0.h" #include "closure.h" #include "conflicts.h" #include "files.h" #include "getargs.h" #include "gram.h" #include "lalr.h" +#include "lr0.h" #include "print.h" -#include "print-xml.h" #include "reader.h" #include "reduce.h" #include "state.h" @@ -57,7 +57,6 @@ static struct escape_buf escape_bufs[num_escape_bufs]; static void print_core (FILE *out, int level, state *s) { - size_t i; item_number *sitems = s->items; size_t snritems = s->nitems; @@ -74,18 +73,12 @@ print_core (FILE *out, int level, state *s) xml_puts (out, level, ""); - for (i = 0; i < snritems; i++) + for (size_t i = 0; i < snritems; i++) { bool printed = false; item_number *sp1 = ritem + sitems[i]; - item_number *sp = sp1; - rule *r; - - while (0 <= *sp) - sp++; - - r = &rules[item_number_as_rule_number (*sp)]; - sp = r->rhs; + rule const *r = item_rule (sp1); + item_number *sp = r->rhs; /* Display the lookahead tokens? */ if (item_number_is_rule_number (*sp1)) @@ -336,7 +329,7 @@ print_reductions (FILE *out, int level, state *s) /*--------------------------------------------------------------. | Report on OUT all the actions (shifts, gotos, reductions, and | -| explicit erros from %nonassoc) of S. | +| explicit errors from %nonassoc) of S. | `--------------------------------------------------------------*/ static void @@ -380,15 +373,13 @@ print_state (FILE *out, int level, state *s) static void print_grammar (FILE *out, int level) { - symbol_number i; - fputc ('\n', out); xml_puts (out, level, ""); grammar_rules_print_xml (out, level); /* Terminals */ xml_puts (out, level + 1, ""); - for (i = 0; i < max_user_token_number + 1; i++) + for (symbol_number i = 0; i < max_user_token_number + 1; i++) if (token_translations[i] != undeftoken->content->number) { char const *tag = symbols[token_translations[i]]->tag; @@ -411,7 +402,7 @@ print_grammar (FILE *out, int level) /* Nonterminals */ xml_puts (out, level + 1, ""); - for (i = ntokens; i < nsyms + nuseless_nonterminals; i++) + for (symbol_number i = ntokens; i < nsyms + nuseless_nonterminals; i++) { char const *tag = symbols[i]->tag; xml_printf (out, level + 2, @@ -428,8 +419,7 @@ print_grammar (FILE *out, int level) void xml_indent (FILE *out, int level) { - int i; - for (i = 0; i < level; i++) + for (int i = 0; i < level; i++) fputs (" ", out); } @@ -460,14 +450,13 @@ xml_escape_string (struct escape_buf *buf, char const *str) { size_t len = strlen (str); size_t max_expansion = sizeof """ - 1; - char *p; if (buf->size <= max_expansion * len) { buf->size = max_expansion * len + 1; buf->ptr = x2realloc (buf->ptr, &buf->size); } - p = buf->ptr; + char *p = buf->ptr; for (; *str; str++) switch (*str) @@ -498,11 +487,11 @@ xml_escape (char const *str) void print_xml (void) { - int level = 0; - FILE *out = xfopen (spec_xml_file, "w"); fputs ("\n\n", out); + + int level = 0; xml_printf (out, level, "", @@ -517,29 +506,21 @@ print_xml (void) /* print grammar */ print_grammar (out, level + 1); - new_closure (nritems); - no_reduce_set = bitset_create (ntokens, BITSET_FIXED); + no_reduce_set = bitset_create (ntokens, BITSET_FIXED); /* print automaton */ fputc ('\n', out); xml_puts (out, level + 1, ""); - { - state_number i; - for (i = 0; i < nstates; i++) - print_state (out, level + 2, states[i]); - } + for (state_number i = 0; i < nstates; i++) + print_state (out, level + 2, states[i]); xml_puts (out, level + 1, ""); bitset_free (no_reduce_set); - free_closure (); xml_puts (out, 0, ""); - { - int i; - for (i = 0; i < num_escape_bufs; ++i) - free (escape_bufs[i].ptr); - } + for (int i = 0; i < num_escape_bufs; ++i) + free (escape_bufs[i].ptr); xfclose (out); } diff --git a/contrib/tools/bison/src/print-xml.h b/contrib/tools/bison/src/print-xml.h index 122c5595e74e..c057780b9386 100644 --- a/contrib/tools/bison/src/print-xml.h +++ b/contrib/tools/bison/src/print-xml.h @@ -1,6 +1,6 @@ /* Output an xml of the generated parser, for Bison. - Copyright (C) 2007, 2009-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -21,6 +21,10 @@ #ifndef PRINT_XML_H_ # define PRINT_XML_H_ +# include + +# include + void xml_indent (FILE *out, int level); void xml_puts (FILE *, int, char const *); void xml_printf (FILE *, int, char const *, ...); diff --git a/contrib/tools/bison/src/print.c b/contrib/tools/bison/src/print.c index 60bb2b3658f3..259c16b3f5f2 100644 --- a/contrib/tools/bison/src/print.c +++ b/contrib/tools/bison/src/print.c @@ -1,6 +1,6 @@ /* Print information on generated parser, for bison, - Copyright (C) 1984, 1986, 1989, 2000-2005, 2007, 2009-2015, 2018-2019 + Copyright (C) 1984, 1986, 1989, 2000-2005, 2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -23,13 +23,13 @@ #include -#include "LR0.h" #include "closure.h" #include "conflicts.h" #include "files.h" #include "getargs.h" #include "gram.h" #include "lalr.h" +#include "lr0.h" #include "muscle-tab.h" #include "print.h" #include "reader.h" @@ -63,8 +63,6 @@ print_core (FILE *out, state *s) { item_number *sitems = s->items; size_t snritems = s->nitems; - sym_content *previous_lhs = NULL; - /* Output all the items of a state, not only its kernel. */ if (report_flag & report_itemsets) { @@ -78,33 +76,18 @@ print_core (FILE *out, state *s) fputc ('\n', out); + rule const *previous_rule = NULL; for (size_t i = 0; i < snritems; i++) { item_number *sp1 = ritem + sitems[i]; - - item_number *sp = sp1; - while (*sp >= 0) - sp++; - - rule_number r = item_number_as_rule_number (*sp); - - rule_lhs_print (&rules[r], previous_lhs, out); - previous_lhs = rules[r].lhs; - - for (sp = rules[r].rhs; sp < sp1; sp++) - fprintf (out, " %s", symbols[*sp]->tag); - fputs (" .", out); - if (0 <= *rules[r].rhs) - for (/* Nothing */; 0 <= *sp; ++sp) - fprintf (out, " %s", symbols[*sp]->tag); - else - fprintf (out, " %%empty"); + rule const *r = item_rule (sp1); + item_print (sp1, previous_rule, out); + previous_rule = r; /* Display the lookahead tokens? */ if (report_flag & report_lookahead_tokens && item_number_is_rule_number (*sp1)) - state_rule_lookahead_tokens_print (s, &rules[r], out); - + state_rule_lookahead_tokens_print (s, r, out); fputc ('\n', out); } } @@ -336,7 +319,7 @@ print_reductions (FILE *out, state *s) /*--------------------------------------------------------------. | Report on OUT all the actions (shifts, gotos, reductions, and | -| explicit erros from %nonassoc) of S. | +| explicit errors from %nonassoc) of S. | `--------------------------------------------------------------*/ static void @@ -374,17 +357,6 @@ print_state (FILE *out, state *s) | Print information on the whole grammar. | `-----------------------------------------*/ -#define END_TEST(End) \ - do { \ - if (column + strlen (buffer) > (End)) \ - { \ - fprintf (out, "%s\n ", buffer); \ - column = 3; \ - buffer[0] = 0; \ - } \ - } while (0) - - static void print_terminal_symbols (FILE *out) { @@ -394,29 +366,20 @@ print_terminal_symbols (FILE *out) if (token_translations[i] != undeftoken->content->number) { const char *tag = symbols[token_translations[i]]->tag; - int column = strlen (tag); - char buffer[90]; - - buffer[0] = 0; - fputs (tag, out); - END_TEST (65); + fprintf (out, "%4s%s", "", tag); if (symbols[token_translations[i]]->content->type_name) - { - column += fprintf (out, " <%s>", - symbols[token_translations[i]]->content->type_name); - END_TEST (65); - } - sprintf (buffer, " (%d)", i); + fprintf (out, " <%s>", + symbols[token_translations[i]]->content->type_name); + fprintf (out, " (%d)", i); for (rule_number r = 0; r < nrules; r++) for (item_number *rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) if (item_number_as_symbol_number (*rhsp) == token_translations[i]) { - END_TEST (65); - sprintf (buffer + strlen (buffer), " %d", r); + fprintf (out, " %d", r); break; } - fprintf (out, "%s\n", buffer); + fputc ('\n', out); } fputs ("\n\n", out); } @@ -429,64 +392,46 @@ print_nonterminal_symbols (FILE *out) for (symbol_number i = ntokens; i < nsyms; i++) { const char *tag = symbols[i]->tag; - int column = strlen (tag); - int left_count = 0, right_count = 0; + bool on_left = false; + bool on_right = false; for (rule_number r = 0; r < nrules; r++) { - if (rules[r].lhs->number == i) - left_count++; - for (item_number *rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) - if (item_number_as_symbol_number (*rhsp) == i) - { - right_count++; - break; - } + on_left |= rules[r].lhs->number == i; + for (item_number *rhsp = rules[r].rhs; !on_right && 0 <= *rhsp; ++rhsp) + on_right |= item_number_as_symbol_number (*rhsp) == i; + if (on_left && on_right) + break; } - fputs (tag, out); + int column = 4 + strlen (tag); + fprintf (out, "%4s%s", "", tag); if (symbols[i]->content->type_name) column += fprintf (out, " <%s>", symbols[i]->content->type_name); - char buffer[90]; - buffer[0] = 0; - sprintf (buffer, " (%d)", i); - END_TEST (0); + fprintf (out, " (%d)\n", i); - if (left_count > 0) + if (on_left) { - END_TEST (65); - sprintf (buffer + strlen (buffer), _(" on left:")); - + fprintf (out, "%8s%s", "", _("on left:")); for (rule_number r = 0; r < nrules; r++) - { - if (rules[r].lhs->number == i) - { - END_TEST (65); - sprintf (buffer + strlen (buffer), " %d", r); - } - } + if (rules[r].lhs->number == i) + fprintf (out, " %d", r); + fputc ('\n', out); } - if (right_count > 0) + if (on_right) { - if (left_count > 0) - sprintf (buffer + strlen (buffer), ","); - END_TEST (65); - sprintf (buffer + strlen (buffer), _(" on right:")); + fprintf (out, "%8s%s", "", _("on right:")); for (rule_number r = 0; r < nrules; r++) - { - item_number *rhsp; - for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) - if (item_number_as_symbol_number (*rhsp) == i) - { - END_TEST (65); - sprintf (buffer + strlen (buffer), " %d", r); - break; - } - } + for (item_number *rhsp = rules[r].rhs; 0 <= *rhsp; ++rhsp) + if (item_number_as_symbol_number (*rhsp) == i) + { + fprintf (out, " %d", r); + break; + } + fputc ('\n', out); } - fprintf (out, "%s\n", buffer); } } @@ -507,17 +452,11 @@ print_results (void) print_terminal_symbols (out); print_nonterminal_symbols (out); - /* If the whole state item sets, not only the kernels, are wanted, - 'closure' will be run, which needs memory allocation/deallocation. */ - if (report_flag & report_itemsets) - new_closure (nritems); /* Storage for print_reductions. */ no_reduce_set = bitset_create (ntokens, BITSET_FIXED); for (state_number i = 0; i < nstates; i++) print_state (out, states[i]); bitset_free (no_reduce_set); - if (report_flag & report_itemsets) - free_closure (); xfclose (out); } diff --git a/contrib/tools/bison/src/print.h b/contrib/tools/bison/src/print.h index 83520062509f..027abce46c58 100644 --- a/contrib/tools/bison/src/print.h +++ b/contrib/tools/bison/src/print.h @@ -1,6 +1,6 @@ /* Print information on generated parser, for bison, - Copyright (C) 2000, 2009-2015, 2018-2019 Free Software Foundation, + Copyright (C) 2000, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/src/reader.c b/contrib/tools/bison/src/reader.c index 8d373416df88..80d307c6c213 100644 --- a/contrib/tools/bison/src/reader.c +++ b/contrib/tools/bison/src/reader.c @@ -1,7 +1,7 @@ /* Input parser for Bison Copyright (C) 1984, 1986, 1989, 1992, 1998, 2000-2003, 2005-2007, - 2009-2015, 2018-2019 Free Software Foundation, Inc. + 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -26,6 +26,7 @@ #include "complain.h" #include "conflicts.h" #include "files.h" +#include "fixits.h" #include "getargs.h" #include "gram.h" #include "muscle-tab.h" @@ -61,7 +62,7 @@ grammar_start_symbol_set (symbol *sym, location loc) { start_flag = true; startsymbol = sym; - startsymbol_location = loc; + startsymbol_loc = loc; } } @@ -123,19 +124,19 @@ record_merge_function_type (int merger, uniqstr type, location declaration_loc) aver (merge_function != NULL && merger_find == merger); if (merge_function->type != NULL && !UNIQSTR_EQ (merge_function->type, type)) { - unsigned indent = 0; + int indent = 0; complain_indent (&declaration_loc, complaint, &indent, _("result type clash on merge function %s: " "<%s> != <%s>"), quote (merge_function->name), type, merge_function->type); indent += SUB_INDENT; - complain_indent (&merge_function->type_declaration_location, complaint, + complain_indent (&merge_function->type_declaration_loc, complaint, &indent, _("previous declaration")); } merge_function->type = uniqstr_new (type); - merge_function->type_declaration_location = declaration_loc; + merge_function->type_declaration_loc = declaration_loc; } /*--------------------------------------. @@ -226,19 +227,13 @@ grammar_current_rule_begin (symbol *lhs, location loc, ++nrules; previous_rule_end = grammar_end; - symbol_list *p = grammar_symbol_append (lhs, loc); + current_rule = grammar_symbol_append (lhs, loc); if (lhs_name) - assign_named_ref (p, named_ref_copy (lhs_name)); - - current_rule = grammar_end; + assign_named_ref (current_rule, named_ref_copy (lhs_name)); /* Mark the rule's lhs as a nonterminal if not already so. */ - if (lhs->content->class == unknown_sym) - { - lhs->content->class = nterm_sym; - lhs->content->number = nvars; - ++nvars; - } + if (lhs->content->class == unknown_sym || lhs->content->class == pct_type_sym) + symbol_class_set (lhs, nterm_sym, empty_loc, false); else if (lhs->content->class == token_sym) complain (&loc, complaint, _("rule given for %s, which is a token"), lhs->tag); @@ -293,10 +288,10 @@ grammar_rule_check_and_complete (symbol_list *r) if (first_rhs) { char const *lhs_type = r->content.sym->content->type_name; - const char *rhs_type = + char const *rhs_type = first_rhs->content->type_name ? first_rhs->content->type_name : ""; if (!UNIQSTR_EQ (lhs_type, rhs_type)) - complain (&r->location, Wother, + complain (&r->rhs_loc, Wother, _("type clash on default action: <%s> != <%s>"), lhs_type, rhs_type); else @@ -309,7 +304,7 @@ grammar_rule_check_and_complete (symbol_list *r) if (is_cxx) { code_props_rule_action_init (&r->action_props, "{ $$ = $1; }", - r->location, r, + r->rhs_loc, r, /* name */ NULL, /* type */ NULL, /* is_predicate */ false); @@ -319,7 +314,7 @@ grammar_rule_check_and_complete (symbol_list *r) } /* Warn if there is no default for $$ but we need one. */ else - complain (&r->location, Wother, + complain (&r->rhs_loc, Wother, _("empty rule for typed nonterminal, and no action")); } @@ -336,9 +331,9 @@ grammar_rule_check_and_complete (symbol_list *r) { warnings warn_flag = midrule_warning ? Wmidrule_values : Wother; if (n) - complain (&l->location, warn_flag, _("unused value: $%d"), n); + complain (&l->sym_loc, warn_flag, _("unused value: $%d"), n); else - complain (&l->location, warn_flag, _("unset value: $$")); + complain (&l->rhs_loc, warn_flag, _("unset value: $$")); } } } @@ -346,14 +341,25 @@ grammar_rule_check_and_complete (symbol_list *r) /* Check that %empty => empty rule. */ if (r->percent_empty_loc.start.file && r->next && r->next->content.sym) - complain (&r->percent_empty_loc, complaint, - _("%%empty on non-empty rule")); + { + complain (&r->percent_empty_loc, complaint, + _("%%empty on non-empty rule")); + fixits_register (&r->percent_empty_loc, ""); + } /* Check that empty rule => %empty. */ if (!(r->next && r->next->content.sym) && !r->midrule_parent_rule - && !r->percent_empty_loc.start.file) - complain (&r->location, Wempty_rule, _("empty rule without %%empty")); + && !r->percent_empty_loc.start.file + && warning_is_enabled (Wempty_rule)) + { + complain (&r->rhs_loc, Wempty_rule, _("empty rule without %%empty")); + if (feature_flag & feature_caret) + location_caret_suggestion (r->rhs_loc, "%empty", stderr); + location loc = r->rhs_loc; + loc.end = loc.start; + fixits_register (&loc, " %empty "); + } /* See comments in grammar_current_rule_prec_set for how POSIX mandates this complaint. It's only for identifiers, so skip @@ -362,12 +368,12 @@ grammar_rule_check_and_complete (symbol_list *r) && r->ruleprec->tag[0] != '\'' && r->ruleprec->tag[0] != '"' && r->ruleprec->content->status != declared && !r->ruleprec->content->prec) - complain (&r->location, Wother, + complain (&r->rhs_loc, Wother, _("token for %%prec is not defined: %s"), r->ruleprec->tag); /* Check that the (main) action was not typed. */ if (r->action_props.type) - complain (&r->location, Wother, + complain (&r->rhs_loc, Wother, _("only midrule actions can be typed: %s"), r->action_props.type); } @@ -380,8 +386,8 @@ void grammar_current_rule_end (location loc) { /* Put an empty link in the list to mark the end of this rule */ - grammar_symbol_append (NULL, grammar_end->location); - current_rule->location = loc; + grammar_symbol_append (NULL, grammar_end->rhs_loc); + current_rule->rhs_loc = loc; } @@ -401,11 +407,11 @@ grammar_midrule_action (void) /* Make a DUMMY nonterminal, whose location is that of the midrule action. Create the MIDRULE. */ - location dummy_location = current_rule->action_props.location; - symbol *dummy = dummy_symbol_get (dummy_location); + location dummy_loc = current_rule->action_props.location; + symbol *dummy = dummy_symbol_get (dummy_loc); symbol_type_set(dummy, current_rule->action_props.type, current_rule->action_props.location); - symbol_list *midrule = symbol_list_sym_new (dummy, dummy_location); + symbol_list *midrule = symbol_list_sym_new (dummy, dummy_loc); /* Remember named_ref of previous action. */ named_ref *action_name = current_rule->action_props.named_ref; @@ -415,7 +421,7 @@ grammar_midrule_action (void) ++nrules; ++nritems; /* Attach its location and actions to that of the DUMMY. */ - midrule->location = dummy_location; + midrule->rhs_loc = dummy_loc; code_props_rule_action_init (&midrule->action_props, current_rule->action_props.code, current_rule->action_props.location, @@ -436,14 +442,14 @@ grammar_midrule_action (void) grammar = midrule; /* End the dummy's rule. */ - midrule->next = symbol_list_sym_new (NULL, dummy_location); + midrule->next = symbol_list_sym_new (NULL, dummy_loc); midrule->next->next = current_rule; previous_rule_end = midrule->next; /* Insert the dummy nonterminal replacing the midrule action into the current rule. Bind it to its dedicated rule. */ - grammar_current_rule_symbol_append (dummy, dummy_location, + grammar_current_rule_symbol_append (dummy, dummy_loc, action_name); grammar_end->midrule = midrule; midrule->midrule_parent_rule = current_rule; @@ -502,11 +508,11 @@ grammar_current_rule_dprec_set (int dprec, location loc) "%dprec"); else if (current_rule->dprec != 0) duplicate_rule_directive ("%dprec", - current_rule->dprec_location, loc); + current_rule->dprec_loc, loc); else { current_rule->dprec = dprec; - current_rule->dprec_location = loc; + current_rule->dprec_loc = loc; } } @@ -521,11 +527,11 @@ grammar_current_rule_merge_set (uniqstr name, location loc) "%merge"); if (current_rule->merger != 0) duplicate_rule_directive ("%merge", - current_rule->merger_declaration_location, loc); + current_rule->merger_declaration_loc, loc); else { current_rule->merger = get_merge_function (name); - current_rule->merger_declaration_location = loc; + current_rule->merger_declaration_loc = loc; } } @@ -595,17 +601,16 @@ grammar_current_rule_expect_rr (int count, location loc) } -/*---------------------------------------------------------------. -| Convert the rules into the representation using RRHS, RLHS and | -| RITEM. | -`---------------------------------------------------------------*/ +/*---------------------------------------------. +| Build RULES and RITEM from what was parsed. | +`---------------------------------------------*/ static void packgram (void) { - unsigned itemno = 0; + int itemno = 0; ritem = xnmalloc (nritems + 1, sizeof *ritem); - /* This sentinel is used by build_relations in gram.c. */ + /* This sentinel is used by build_relations() in lalr.c. */ *ritem++ = 0; rule_number ruleno = 0; @@ -615,11 +620,11 @@ packgram (void) { symbol_list *lhs = p; record_merge_function_type (lhs->merger, lhs->content.sym->content->type_name, - lhs->merger_declaration_location); + lhs->merger_declaration_loc); /* If the midrule's $$ is set or its $n is used, remove the '$' from the symbol name so that it's a user-defined symbol so that the default %destructor and %printer apply. */ - if (lhs->midrule_parent_rule + if (lhs->midrule_parent_rule /* i.e., symbol_is_dummy (lhs->content.sym). */ && (lhs->action_props.is_value_used || (symbol_list_n_get (lhs->midrule_parent_rule, lhs->midrule_parent_rhs_index) @@ -629,8 +634,8 @@ packgram (void) /* Don't check the generated rule 0. It has no action, so some rhs symbols may appear unused, but the parsing algorithm ensures that %destructor's are invoked appropriately. */ - if (p != grammar) - grammar_rule_check_and_complete (p); + if (lhs != grammar) + grammar_rule_check_and_complete (lhs); rules[ruleno].user_number = ruleno; rules[ruleno].number = ruleno; @@ -640,18 +645,18 @@ packgram (void) rules[ruleno].dprec = lhs->dprec; rules[ruleno].merger = lhs->merger; rules[ruleno].precsym = NULL; - rules[ruleno].location = lhs->location; + rules[ruleno].location = lhs->rhs_loc; rules[ruleno].useful = true; rules[ruleno].action = lhs->action_props.code; - rules[ruleno].action_location = lhs->action_props.location; + rules[ruleno].action_loc = lhs->action_props.location; rules[ruleno].is_predicate = lhs->action_props.is_predicate; - rules[ruleno].expected_sr_conflicts = p->expected_sr_conflicts; - rules[ruleno].expected_rr_conflicts = p->expected_rr_conflicts; + rules[ruleno].expected_sr_conflicts = lhs->expected_sr_conflicts; + rules[ruleno].expected_rr_conflicts = lhs->expected_rr_conflicts; /* Traverse the rhs. */ { size_t rule_length = 0; - for (p = p->next; p->content.sym; p = p->next) + for (p = lhs->next; p->content.sym; p = p->next) { ++rule_length; @@ -691,7 +696,8 @@ packgram (void) if (trace_flag & trace_sets) ritem_print (stderr); } - + + /*------------------------------------------------------------------. | Read in the grammar specification and record it in the format | | described in gram.h. All actions are copied into ACTION_OBSTACK, | @@ -700,39 +706,20 @@ packgram (void) `------------------------------------------------------------------*/ void -reader (void) +reader (const char *gram) { - /* Initialize the symbol table. */ + /* Set up symbol_table, semantic_type_table, and the built-in + symbols. */ symbols_new (); - /* Construct the accept symbol. */ - accept = symbol_get ("$accept", empty_location); - accept->content->class = nterm_sym; - accept->content->number = nvars++; - - /* Construct the error token */ - errtoken = symbol_get ("error", empty_location); - errtoken->content->class = token_sym; - errtoken->content->number = ntokens++; - - /* Construct a token that represents all undefined literal tokens. - It is always token number 2. */ - undeftoken = symbol_get ("$undefined", empty_location); - undeftoken->content->class = token_sym; - undeftoken->content->number = ntokens++; - - gram_in = xfopen (grammar_file, "r"); - - gram__flex_debug = trace_flag & trace_scan; - gram_debug = trace_flag & trace_parse; - gram_scanner_initialize (); + gram_scanner_open (gram); gram_parse (); + gram_scanner_close (); + prepare_percent_define_front_end_variables (); if (complaint_status < status_complaint) check_and_convert_grammar (); - - xfclose (gram_in); } static void @@ -754,11 +741,12 @@ prepare_percent_define_front_end_variables (void) /* Check %define front-end variables. */ { - static char const * const values[] = { - "lr.type", "lalr", "ielr", "canonical-lr", NULL, - "lr.default-reduction", "most", "consistent", "accepting", NULL, - NULL - }; + static char const * const values[] = + { + "lr.type", "lr""(0)", "lalr", "ielr", "canonical-lr", NULL, + "lr.default-reduction", "most", "consistent", "accepting", NULL, + NULL + }; muscle_percent_define_check_values (values); } } @@ -793,7 +781,7 @@ check_and_convert_grammar (void) /* If the user did not define her ENDTOKEN, do it now. */ if (!endtoken) { - endtoken = symbol_get ("$end", empty_location); + endtoken = symbol_get ("$end", empty_loc); endtoken->content->class = token_sym; endtoken->content->number = 0; /* Value specified by POSIX. */ @@ -815,11 +803,11 @@ check_and_convert_grammar (void) $accept: %start $end. */ { - symbol_list *p = symbol_list_sym_new (accept, empty_location); - p->location = grammar->location; - p->next = symbol_list_sym_new (startsymbol, empty_location); - p->next->next = symbol_list_sym_new (endtoken, empty_location); - p->next->next->next = symbol_list_sym_new (NULL, empty_location); + symbol_list *p = symbol_list_sym_new (accept, empty_loc); + p->rhs_loc = grammar->rhs_loc; + p->next = symbol_list_sym_new (startsymbol, empty_loc); + p->next->next = symbol_list_sym_new (endtoken, empty_loc); + p->next->next->next = symbol_list_sym_new (NULL, empty_loc); p->next->next->next->next = grammar; nrules += 1; nritems += 3; @@ -829,8 +817,7 @@ check_and_convert_grammar (void) aver (nsyms <= SYMBOL_NUMBER_MAXIMUM); aver (nsyms == ntokens + nvars); - /* Assign the symbols their symbol numbers. Write #defines for the - token symbols into FDEFINES if requested. */ + /* Assign the symbols their symbol numbers. */ symbols_pack (); /* Scan rule actions after invoking symbol_check_alias_consistency (in diff --git a/contrib/tools/bison/src/reader.h b/contrib/tools/bison/src/reader.h index 9f59dc0053c1..6b4f57ff1ac0 100644 --- a/contrib/tools/bison/src/reader.h +++ b/contrib/tools/bison/src/reader.h @@ -1,6 +1,6 @@ /* Input parser for Bison - Copyright (C) 2000-2003, 2005-2007, 2009-2015, 2018-2019 Free + Copyright (C) 2000-2003, 2005-2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -32,15 +32,9 @@ typedef struct merger_list struct merger_list* next; uniqstr name; uniqstr type; - location type_declaration_location; + location type_declaration_loc; } merger_list; -/* From the parser. */ -extern int gram_debug; -int gram_parse (void); - - -/* From reader.c. */ void grammar_start_symbol_set (symbol *sym, location loc); void grammar_current_rule_begin (symbol *lhs, location loc, named_ref *lhs_named_ref); @@ -60,7 +54,7 @@ void grammar_current_rule_action_append (const char *action, location loc, named_ref *nref, uniqstr tag); /* Attach a PREDICATE to the current rule. */ void grammar_current_rule_predicate_append (const char *predicate, location loc); -void reader (void); +void reader (const char *gram); void free_merger_functions (void); extern merger_list *merge_functions; diff --git a/contrib/tools/bison/src/reduce.c b/contrib/tools/bison/src/reduce.c index ff2f2325c082..4ed8531ecc82 100644 --- a/contrib/tools/bison/src/reduce.c +++ b/contrib/tools/bison/src/reduce.c @@ -1,6 +1,6 @@ /* Grammar reduction for Bison. - Copyright (C) 1988-1989, 2000-2003, 2005-2015, 2018-2019 Free + Copyright (C) 1988-1989, 2000-2003, 2005-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -39,21 +39,21 @@ #include "reduce.h" #include "symtab.h" -/* Set of all nonterminals whose language is not empty. */ +/* Set of nonterminals whose language is not empty. */ static bitset N; -/* Set of all rules which have no useless nonterminals in their RHS. */ +/* Set of rules that have no useless nonterminals in their RHS. */ static bitset P; -/* Set of all accessible symbols. */ +/* Set of accessible symbols. */ static bitset V; /* Set of symbols used to define rule precedence (so they are 'useless', but no warning should be issued). */ static bitset V1; -unsigned nuseless_productions; -unsigned nuseless_nonterminals; +int nuseless_productions; +int nuseless_nonterminals; #define bitset_swap(Lhs, Rhs) \ do { \ @@ -81,9 +81,11 @@ useful_production (rule_number r, bitset N0) } -/*---------------------------------------------------------. -| Remember that rules are 1-origin, symbols are 0-origin. | -`---------------------------------------------------------*/ +/*-----------------------------------------------------------------. +| Compute N, the set of nonterminals whose language is not empty. | +| | +| Remember that rules are 1-origin, symbols are 0-origin. | +`-----------------------------------------------------------------*/ static void useless_nonterminals (void) @@ -193,10 +195,10 @@ inaccessable_symbols (void) bitset_free (P); P = Pp; - unsigned nuseful_productions = bitset_count (P); + int nuseful_productions = bitset_count (P); nuseless_productions = nrules - nuseful_productions; - unsigned nuseful_nonterminals = 0; + int nuseful_nonterminals = 0; for (symbol_number i = ntokens; i < nsyms; ++i) nuseful_nonterminals += bitset_test (V, i); nuseless_nonterminals = nvars - nuseful_nonterminals; @@ -248,10 +250,7 @@ reduce_grammar_tables (void) /* Adjust NRITEMS. */ for (rule_number r = nrules; r < nrules + nuseless_productions; ++r) - { - int length = rule_rhs_length (&rules[r]); - nritems -= length + 1; - } + nritems -= rule_rhs_length (&rules[r]) + 1; } @@ -321,7 +320,7 @@ reduce_output (FILE *out) { fprintf (out, "%s\n\n", _("Nonterminals useless in grammar")); for (int i = 0; i < nuseless_nonterminals; ++i) - fprintf (out, " %s\n", symbols[nsyms + i]->tag); + fprintf (out, " %s\n", symbols[nsyms + i]->tag); fputs ("\n\n", out); } @@ -333,7 +332,7 @@ reduce_output (FILE *out) if (!b) fprintf (out, "%s\n\n", _("Terminals unused in grammar")); b = true; - fprintf (out, " %s\n", symbols[i]->tag); + fprintf (out, " %s\n", symbols[i]->tag); } if (b) fputs ("\n\n", out); @@ -378,23 +377,23 @@ reduce_grammar (void) inaccessable_symbols (); /* Did we reduce something? */ - if (!nuseless_nonterminals && !nuseless_productions) - return; - - reduce_print (); - - if (!bitset_test (N, accept->content->number - ntokens)) - complain (&startsymbol_location, fatal, - _("start symbol %s does not derive any sentence"), - startsymbol->tag); - - /* First reduce the nonterminals, as they renumber themselves in the - whole grammar. If you change the order, nonterms would be - renumbered only in the reduced grammar. */ - if (nuseless_nonterminals) - nonterminals_reduce (); - if (nuseless_productions) - reduce_grammar_tables (); + if (nuseless_nonterminals || nuseless_productions) + { + reduce_print (); + + if (!bitset_test (N, accept->content->number - ntokens)) + complain (&startsymbol_loc, fatal, + _("start symbol %s does not derive any sentence"), + startsymbol->tag); + + /* First reduce the nonterminals, as they renumber themselves in the + whole grammar. If you change the order, nonterms would be + renumbered only in the reduced grammar. */ + if (nuseless_nonterminals) + nonterminals_reduce (); + if (nuseless_productions) + reduce_grammar_tables (); + } if (trace_flag & trace_grammar) { diff --git a/contrib/tools/bison/src/reduce.h b/contrib/tools/bison/src/reduce.h index 9814962d7607..e55bedb80b6f 100644 --- a/contrib/tools/bison/src/reduce.h +++ b/contrib/tools/bison/src/reduce.h @@ -1,6 +1,6 @@ /* Grammar reduction for Bison. - Copyright (C) 2000-2002, 2007, 2009-2015, 2018-2019 Free Software + Copyright (C) 2000-2002, 2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -36,7 +36,7 @@ void reduce_free (void); * reduce_grammar. Size nvars + nuseless_nonterminals. */ extern symbol_number *nterm_map; -extern unsigned nuseless_nonterminals; -extern unsigned nuseless_productions; +extern int nuseless_nonterminals; +extern int nuseless_productions; #endif /* !REDUCE_H_ */ diff --git a/contrib/tools/bison/src/relation.c b/contrib/tools/bison/src/relation.c index 4371501d47b4..e9c500860301 100644 --- a/contrib/tools/bison/src/relation.c +++ b/contrib/tools/bison/src/relation.c @@ -1,6 +1,6 @@ /* Binary relations. - Copyright (C) 2002, 2004-2005, 2009-2015, 2018-2019 Free Software + Copyright (C) 2002, 2004-2005, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -27,19 +27,31 @@ #include "relation.h" void -relation_print (relation r, relation_node size, FILE *out) +relation_print (const char *title, + relation r, relation_node size, + relation_node_print print, FILE *out) { - relation_node i; - relation_node j; - - for (i = 0; i < size; ++i) - { - fprintf (out, "%3lu: ", (unsigned long) i); - if (r[i]) - for (j = 0; r[i][j] != END_NODE; ++j) - fprintf (out, "%3lu ", (unsigned long) r[i][j]); - fputc ('\n', out); - } + if (title) + fprintf (out, "%s:\n", title); + for (relation_node i = 0; i < size; ++i) + if (r[i]) + { + fputs (" ", out); + if (print) + print (i, out); + else + fprintf (out, "%3ld", (long) i); + fputc (':', out); + for (relation_node j = 0; r[i][j] != END_NODE; ++j) + { + fputc (' ', out); + if (print) + print (r[i][j], out); + else + fprintf (out, "%3ld", (long) r[i][j]); + } + fputc ('\n', out); + } fputc ('\n', out); } @@ -52,8 +64,8 @@ relation_print (relation r, relation_node size, FILE *out) `---------------------------------------------------------------*/ static relation R; -static relation_nodes INDEX; -static relation_nodes VERTICES; +static relation_nodes indexes; +static relation_nodes vertices; static relation_node top; static relation_node infinity; static bitsetv F; @@ -61,29 +73,26 @@ static bitsetv F; static void traverse (relation_node i) { - relation_node j; - relation_node height; - - VERTICES[++top] = i; - INDEX[i] = height = top; + vertices[++top] = i; + relation_node height = indexes[i] = top; if (R[i]) - for (j = 0; R[i][j] != END_NODE; ++j) + for (relation_node j = 0; R[i][j] != END_NODE; ++j) { - if (INDEX[R[i][j]] == 0) + if (indexes[R[i][j]] == 0) traverse (R[i][j]); - if (INDEX[i] > INDEX[R[i][j]]) - INDEX[i] = INDEX[R[i][j]]; + if (indexes[i] > indexes[R[i][j]]) + indexes[i] = indexes[R[i][j]]; bitset_or (F[i], F[i], F[R[i][j]]); } - if (INDEX[i] == height) + if (indexes[i] == height) for (;;) { - j = VERTICES[top--]; - INDEX[j] = infinity; + relation_node j = vertices[top--]; + indexes[j] = infinity; if (i == j) break; @@ -94,26 +103,24 @@ traverse (relation_node i) void -relation_digraph (relation r, relation_node size, bitsetv *function) +relation_digraph (relation r, relation_node size, bitsetv function) { - relation_node i; - infinity = size + 2; - INDEX = xcalloc (size + 1, sizeof *INDEX); - VERTICES = xnmalloc (size + 1, sizeof *VERTICES); + indexes = xcalloc (size + 1, sizeof *indexes); + vertices = xnmalloc (size + 1, sizeof *vertices); top = 0; R = r; - F = *function; + F = function; - for (i = 0; i < size; i++) - if (INDEX[i] == 0 && R[i]) + for (relation_node i = 0; i < size; i++) + if (indexes[i] == 0 && R[i]) traverse (i); - free (INDEX); - free (VERTICES); + free (indexes); + free (vertices); - *function = F; + function = F; } @@ -122,32 +129,27 @@ relation_digraph (relation r, relation_node size, bitsetv *function) `-------------------------------------------*/ void -relation_transpose (relation *R_arg, relation_node n) +relation_transpose (relation *R_arg, relation_node size) { relation r = *R_arg; - /* The result. */ - relation new_R = xnmalloc (n, sizeof *new_R); - /* END_R[I] -- next entry of NEW_R[I]. */ - relation end_R = xnmalloc (n, sizeof *end_R); - /* NEDGES[I] -- total size of NEW_R[I]. */ - size_t *nedges = xcalloc (n, sizeof *nedges); - relation_node i; - relation_node j; if (trace_flag & trace_sets) - { - fputs ("relation_transpose: input\n", stderr); - relation_print (r, n, stderr); - } + relation_print ("relation_transpose", r, size, NULL, stderr); /* Count. */ - for (i = 0; i < n; i++) + /* NEDGES[I] -- total size of NEW_R[I]. */ + size_t *nedges = xcalloc (size, sizeof *nedges); + for (relation_node i = 0; i < size; i++) if (r[i]) - for (j = 0; r[i][j] != END_NODE; ++j) + for (relation_node j = 0; r[i][j] != END_NODE; ++j) ++nedges[r[i][j]]; /* Allocate. */ - for (i = 0; i < n; i++) + /* The result. */ + relation new_R = xnmalloc (size, sizeof *new_R); + /* END_R[I] -- next entry of NEW_R[I]. */ + relation end_R = xnmalloc (size, sizeof *end_R); + for (relation_node i = 0; i < size; i++) { relation_node *sp = NULL; if (nedges[i] > 0) @@ -160,24 +162,21 @@ relation_transpose (relation *R_arg, relation_node n) } /* Store. */ - for (i = 0; i < n; i++) + for (relation_node i = 0; i < size; i++) if (r[i]) - for (j = 0; r[i][j] != END_NODE; ++j) + for (relation_node j = 0; r[i][j] != END_NODE; ++j) *end_R[r[i][j]]++ = i; free (nedges); free (end_R); /* Free the input: it is replaced with the result. */ - for (i = 0; i < n; i++) + for (relation_node i = 0; i < size; i++) free (r[i]); free (r); if (trace_flag & trace_sets) - { - fputs ("relation_transpose: output\n", stderr); - relation_print (new_R, n, stderr); - } + relation_print ("relation_transpose: output", new_R, size, NULL, stderr); *R_arg = new_R; } diff --git a/contrib/tools/bison/src/relation.h b/contrib/tools/bison/src/relation.h index e6b59ff8699b..143663934b61 100644 --- a/contrib/tools/bison/src/relation.h +++ b/contrib/tools/bison/src/relation.h @@ -1,6 +1,6 @@ /* Binary relations. - Copyright (C) 2002, 2004, 2009-2015, 2018-2019 Free Software + Copyright (C) 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -33,18 +33,23 @@ typedef size_t relation_node; typedef relation_node *relation_nodes; typedef relation_nodes *relation; +typedef void (relation_node_print) (relation_node node, FILE* out); /* Report a relation R that has SIZE vertices. */ -void relation_print (relation r, relation_node size, FILE *out); +void relation_print (const char *title, + relation r, size_t size, + relation_node_print print, FILE *out); /* Compute the transitive closure of the FUNCTION on the relation R with SIZE vertices. - If R (NODE-1, NODE-2) then on exit FUNCTION[NODE - 1] was extended - (unioned) with FUNCTION[NODE - 2]. */ -void relation_digraph (relation r, relation_node size, bitsetv *function); + If R (NODE1, NODE2) then on exit FUNCTION[NODE1] was extended + (unioned) with FUNCTION[NODE2]. -/* Destructively transpose *R_ARG, of size N. */ -void relation_transpose (relation *R_arg, relation_node n); + FUNCTION is in-out, R is read only. */ +void relation_digraph (const relation r, relation_node size, bitsetv function); + +/* Destructively transpose *R_ARG, of size SIZE. */ +void relation_transpose (relation *R_arg, relation_node size); #endif /* ! RELATION_H_ */ diff --git a/contrib/tools/bison/src/scan-code.c b/contrib/tools/bison/src/scan-code.c index 39b16dc3fe68..99d287b31f2b 100644 --- a/contrib/tools/bison/src/scan-code.c +++ b/contrib/tools/bison/src/scan-code.c @@ -700,7 +700,7 @@ struct yy_trans_info flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static const flex_int16_t yy_accept[91] = +static const flex_int16_t yy_accept[82] = { 0, 0, 0, 0, 0, 3, 3, 4, 4, 4, 4, 0, 0, 0, 0, 19, 17, 16, 17, 2, 17, @@ -708,9 +708,9 @@ static const flex_int16_t yy_accept[91] = 1, 0, 0, 3, 4, 4, 4, 4, 12, 0, 12, 12, 0, 0, 9, 10, 0, 13, 0, 13, 13, 0, 14, 0, 15, 0, 0, 0, 0, 0, - 0, 0, 12, 0, 0, 0, 0, 0, 13, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, - 12, 12, 0, 14, 12, 12, 0, 0, 0, 0 + 0, 0, 12, 0, 0, 0, 0, 0, 0, 13, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 } ; static const YY_CHAR yy_ec[256] = @@ -747,89 +747,85 @@ static const YY_CHAR yy_ec[256] = static const YY_CHAR yy_meta[19] = { 0, - 1, 1, 2, 1, 1, 1, 1, 3, 3, 1, - 3, 1, 2, 1, 1, 1, 1, 2 + 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, + 2, 1, 1, 1, 1, 1, 1, 1 } ; -static const flex_int16_t yy_base[97] = +static const flex_int16_t yy_base[88] = { 0, - 0, 13, 121, 120, 0, 3, 4, 5, 6, 7, - 27, 0, 20, 21, 125, 178, 178, 26, 178, 8, - 178, 41, 178, 178, 53, 178, 62, 74, 33, 119, - 178, 37, 44, 105, 178, 46, 101, 48, 178, 99, - 0, 96, 98, 91, 178, 178, 50, 178, 87, 0, - 86, 87, 178, 76, 178, 52, 50, 68, 71, 73, - 78, 74, 0, 16, 78, 84, 85, 0, 0, 94, - 86, 96, 55, 107, 0, 0, 58, 118, 100, 124, - 130, 136, 142, 106, 46, 0, 148, 43, 0, 178, - 165, 168, 4, 171, 1, 174 - + 0, 13, 101, 100, 0, 3, 4, 5, 6, 7, + 27, 0, 20, 21, 104, 182, 182, 26, 182, 8, + 182, 41, 182, 182, 53, 182, 62, 74, 33, 98, + 182, 37, 44, 86, 182, 46, 85, 48, 182, 88, + 0, 87, 87, 87, 182, 182, 50, 182, 83, 0, + 82, 79, 182, 103, 182, 52, 50, 68, 71, 73, + 78, 81, 0, 119, 64, 50, 130, 84, 0, 0, + 140, 155, 43, 16, 79, 12, 0, 0, 54, 2, + 182, 173, 175, 2, 177, 0, 179 } ; -static const flex_int16_t yy_def[97] = +static const flex_int16_t yy_def[88] = { 0, - 91, 91, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 11, 11, 11, 90, 90, 90, 90, 90, 90, - 90, 92, 90, 90, 90, 90, 90, 90, 90, 90, - 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, - 93, 90, 94, 90, 90, 90, 90, 90, 90, 95, - 90, 90, 90, 96, 90, 90, 90, 90, 90, 90, - 90, 92, 93, 94, 94, 90, 90, 27, 95, 90, - 96, 96, 25, 94, 66, 70, 90, 96, 94, 94, - 94, 94, 94, 96, 81, 81, 81, 87, 87, 0, - 90, 90, 90, 90, 90, 90 - + 82, 82, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 11, 11, 11, 81, 81, 81, 81, 81, 81, + 81, 83, 81, 81, 81, 81, 81, 81, 81, 81, + 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, + 84, 81, 85, 81, 81, 81, 81, 81, 81, 86, + 81, 81, 81, 87, 81, 81, 81, 81, 81, 81, + 81, 83, 84, 85, 81, 64, 81, 81, 27, 86, + 81, 87, 81, 72, 25, 25, 67, 71, 81, 81, + 0, 81, 81, 81, 81, 81, 81 } ; -static const flex_int16_t yy_nxt[197] = +static const flex_int16_t yy_nxt[201] = { 0, - 90, 90, 19, 69, 17, 19, 63, 21, 21, 33, + 81, 70, 19, 63, 17, 19, 53, 21, 21, 33, 34, 23, 23, 17, 17, 20, 17, 17, 20, 22, - 22, 22, 22, 65, 29, 29, 17, 17, 73, 17, + 22, 22, 22, 81, 29, 29, 17, 17, 72, 17, 24, 25, 26, 30, 30, 31, 27, 53, 56, 57, 28, 32, 36, 37, 54, 33, 34, 59, 37, 61, - 62, 67, 68, 56, 57, 74, 38, 39, 74, 31, - 40, 41, 53, 42, 43, 32, 90, 44, 45, 33, - 34, 46, 59, 37, 59, 37, 90, 47, 48, 61, - 62, 49, 50, 72, 51, 65, 67, 68, 52, 38, - 74, 75, 75, 72, 75, 70, 51, 51, 77, 66, - - 39, 76, 76, 72, 76, 65, 42, 65, 78, 42, - 48, 79, 73, 72, 80, 81, 60, 82, 77, 73, - 58, 83, 84, 55, 90, 72, 18, 18, 90, 90, - 77, 65, 90, 90, 82, 90, 74, 85, 86, 90, - 86, 90, 73, 65, 90, 90, 82, 90, 73, 65, - 87, 90, 90, 90, 73, 88, 89, 90, 89, 90, - 90, 90, 90, 90, 79, 16, 16, 16, 35, 35, - 35, 64, 90, 64, 71, 90, 71, 15, 90, 90, - 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, - 90, 90, 90, 90, 90, 90 + 62, 68, 69, 56, 57, 80, 38, 39, 53, 31, + 40, 41, 64, 42, 43, 32, 80, 44, 45, 33, + 34, 46, 59, 37, 59, 37, 76, 47, 48, 61, + 62, 49, 50, 81, 51, 68, 69, 71, 52, 65, + 81, 76, 51, 51, 66, 67, 38, 42, 42, 65, + + 60, 58, 55, 81, 65, 73, 18, 18, 81, 81, + 74, 81, 81, 81, 81, 73, 81, 81, 81, 81, + 73, 65, 81, 81, 81, 81, 66, 81, 81, 81, + 81, 75, 81, 81, 81, 81, 65, 77, 77, 81, + 77, 81, 81, 81, 81, 81, 39, 78, 78, 81, + 78, 81, 81, 81, 81, 81, 48, 73, 81, 81, + 81, 81, 74, 81, 81, 81, 81, 79, 81, 81, + 81, 81, 73, 16, 16, 35, 35, 64, 64, 72, + 72, 15, 81, 81, 81, 81, 81, 81, 81, 81, + 81, 81, 81, 81, 81, 81, 81, 81, 81, 81 } ; -static const flex_int16_t yy_chk[197] = +static const flex_int16_t yy_chk[201] = { 0, - 0, 0, 5, 95, 1, 6, 93, 7, 8, 20, + 0, 86, 5, 84, 1, 6, 80, 7, 8, 20, 20, 9, 10, 1, 1, 5, 1, 2, 6, 7, - 8, 9, 10, 64, 13, 14, 2, 2, 64, 2, + 8, 9, 10, 76, 13, 14, 2, 2, 74, 2, 11, 11, 11, 13, 14, 18, 11, 29, 32, 32, 11, 18, 22, 22, 29, 33, 33, 36, 36, 38, - 38, 47, 47, 56, 56, 88, 22, 25, 85, 57, - 25, 25, 77, 25, 25, 57, 73, 25, 27, 58, - 58, 27, 59, 59, 60, 60, 62, 27, 28, 61, - 61, 28, 28, 54, 28, 65, 67, 67, 28, 62, - 65, 66, 66, 71, 66, 52, 51, 49, 71, 44, - - 66, 70, 70, 72, 70, 43, 42, 79, 72, 40, - 70, 74, 79, 84, 74, 74, 37, 74, 84, 74, - 34, 74, 78, 30, 15, 78, 4, 3, 0, 0, - 78, 80, 0, 0, 80, 0, 80, 81, 81, 0, - 81, 0, 81, 82, 0, 0, 82, 0, 82, 83, - 83, 0, 0, 0, 83, 87, 87, 0, 87, 0, - 0, 0, 0, 0, 87, 91, 91, 91, 92, 92, - 92, 94, 0, 94, 96, 0, 96, 90, 90, 90, - 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, - 90, 90, 90, 90, 90, 90 + 38, 47, 47, 56, 56, 73, 22, 25, 79, 57, + 25, 25, 66, 25, 25, 57, 79, 25, 27, 58, + 58, 27, 59, 59, 60, 60, 65, 27, 28, 61, + 61, 28, 28, 62, 28, 68, 68, 52, 28, 43, + 75, 75, 51, 49, 43, 44, 62, 42, 40, 43, + + 37, 34, 30, 15, 43, 54, 4, 3, 0, 0, + 54, 0, 0, 0, 0, 54, 0, 0, 0, 0, + 54, 64, 0, 0, 0, 0, 64, 0, 0, 0, + 0, 64, 0, 0, 0, 0, 64, 67, 67, 0, + 67, 0, 0, 0, 0, 0, 67, 71, 71, 0, + 71, 0, 0, 0, 0, 0, 71, 72, 0, 0, + 0, 0, 72, 0, 0, 0, 0, 72, 0, 0, + 0, 0, 72, 82, 82, 83, 83, 85, 85, 87, + 87, 81, 81, 81, 81, 81, 81, 81, 81, 81, + 81, 81, 81, 81, 81, 81, 81, 81, 81, 81 } ; @@ -841,8 +837,8 @@ int yy_flex_debug = 1; static const flex_int16_t yy_rule_linenum[18] = { 0, - 115, 125, 126, 136, 141, 146, 152, 153, 154, 155, - 157, 165, 171, 181, 189, 199, 202 + 116, 126, 127, 137, 142, 147, 153, 154, 155, 156, + 158, 166, 172, 182, 190, 200, 203 } ; /* The intent behind this definition is that it'll catch @@ -856,7 +852,7 @@ char *yytext; #line 1 "/Users/akim/src/gnu/bison/src/scan-code.l" /* Bison Action Scanner -*- C -*- - Copyright (C) 2006-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2006-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -901,17 +897,18 @@ YY_DECL; #define YY_USER_ACTION location_compute (loc, &loc->end, yytext, yyleng); static char *fetch_type_name (char *cp, char const **type_name, - location dollar_loc); + const location *dollar_loc); static void handle_action_dollar (symbol_list *rule, char *cp, - location dollar_loc); -static void handle_action_at (symbol_list *rule, char *cp, location at_loc); + const location *dollar_loc); +static void handle_action_at (symbol_list *rule, char *cp, + const location *at_loc); /* A string to be pushed to obstack after dollar/at has been handled. */ static char *ref_tail_fields; -static location the_location; -static location *loc = &the_location; +static location current_loc; +static location *loc = ¤t_loc; /* A string representing the most recent translation. */ static char *last_string; @@ -919,8 +916,8 @@ static char *last_string; /* True if an untyped $$ or $n was seen. */ static bool untyped_var_seen; -#line 922 "src/scan-code.c" -#line 71 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 919 "src/scan-code.c" +#line 72 "/Users/akim/src/gnu/bison/src/scan-code.l" /* C and C++ comments in code. */ /* Strings and characters in code. */ @@ -937,7 +934,7 @@ static bool untyped_var_seen; /* C style identifier. Must start with letter. Will be used for named symbol references. Shall be kept synchronized with scan-gram.l "letter" and "id". */ -#line 940 "src/scan-code.c" +#line 937 "src/scan-code.c" #define INITIAL 0 #define SC_COMMENT 1 @@ -1221,7 +1218,7 @@ YY_DECL { /* %% [7.0] user's declarations go here */ -#line 97 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 98 "/Users/akim/src/gnu/bison/src/scan-code.l" @@ -1238,7 +1235,7 @@ YY_DECL | Scanning a C comment. The initial '/ *' is already eaten. | `------------------------------------------------------------*/ -#line 1241 "src/scan-code.c" +#line 1238 "src/scan-code.c" while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { @@ -1267,13 +1264,13 @@ YY_DECL while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 91 ) + if ( yy_current_state >= 82 ) yy_c = yy_meta[yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; ++yy_cp; } - while ( yy_current_state != 90 ); + while ( yy_current_state != 81 ); yy_cp = (yy_last_accepting_cpos); yy_current_state = (yy_last_accepting_state); @@ -1317,7 +1314,7 @@ YY_DECL case 1: /* rule 1 can match eol */ YY_RULE_SETUP -#line 115 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 116 "/Users/akim/src/gnu/bison/src/scan-code.l" STRING_GROW; BEGIN sc_context; YY_BREAK @@ -1329,13 +1326,13 @@ STRING_GROW; BEGIN sc_context; case 2: /* rule 2 can match eol */ YY_RULE_SETUP -#line 125 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 126 "/Users/akim/src/gnu/bison/src/scan-code.l" STRING_GROW; BEGIN sc_context; YY_BREAK case 3: /* rule 3 can match eol */ YY_RULE_SETUP -#line 126 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 127 "/Users/akim/src/gnu/bison/src/scan-code.l" STRING_GROW; YY_BREAK @@ -1347,7 +1344,7 @@ STRING_GROW; case 4: /* rule 4 can match eol */ YY_RULE_SETUP -#line 136 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 137 "/Users/akim/src/gnu/bison/src/scan-code.l" STRING_GROW; YY_BREAK @@ -1355,7 +1352,7 @@ STRING_GROW; case 5: YY_RULE_SETUP -#line 141 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 142 "/Users/akim/src/gnu/bison/src/scan-code.l" STRING_GROW; BEGIN sc_context; YY_BREAK @@ -1363,7 +1360,7 @@ STRING_GROW; BEGIN sc_context; case 6: YY_RULE_SETUP -#line 146 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 147 "/Users/akim/src/gnu/bison/src/scan-code.l" STRING_GROW; BEGIN sc_context; YY_BREAK @@ -1371,29 +1368,29 @@ STRING_GROW; BEGIN sc_context; case 7: YY_RULE_SETUP -#line 152 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 153 "/Users/akim/src/gnu/bison/src/scan-code.l" STRING_GROW; BEGIN SC_CHARACTER; YY_BREAK case 8: YY_RULE_SETUP -#line 153 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 154 "/Users/akim/src/gnu/bison/src/scan-code.l" STRING_GROW; BEGIN SC_STRING; YY_BREAK case 9: /* rule 9 can match eol */ YY_RULE_SETUP -#line 154 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 155 "/Users/akim/src/gnu/bison/src/scan-code.l" STRING_GROW; BEGIN SC_COMMENT; YY_BREAK case 10: /* rule 10 can match eol */ YY_RULE_SETUP -#line 155 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 156 "/Users/akim/src/gnu/bison/src/scan-code.l" STRING_GROW; BEGIN SC_LINE_COMMENT; YY_BREAK case 11: YY_RULE_SETUP -#line 157 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 158 "/Users/akim/src/gnu/bison/src/scan-code.l" { complain (loc, Wother, _("stray '%s'"), yytext); obstack_escape (&obstack_for_string, yytext); @@ -1403,21 +1400,22 @@ YY_RULE_SETUP case 12: +/* rule 12 can match eol */ YY_RULE_SETUP -#line 165 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 166 "/Users/akim/src/gnu/bison/src/scan-code.l" { ref_tail_fields = NULL; - handle_action_dollar (self->rule, yytext, *loc); + handle_action_dollar (self->rule, yytext, loc); if (ref_tail_fields) obstack_sgrow (&obstack_for_string, ref_tail_fields); } YY_BREAK case 13: YY_RULE_SETUP -#line 171 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 172 "/Users/akim/src/gnu/bison/src/scan-code.l" { ref_tail_fields = NULL; - handle_action_at (self->rule, yytext, *loc); + handle_action_at (self->rule, yytext, loc); if (ref_tail_fields) obstack_sgrow (&obstack_for_string, ref_tail_fields); } @@ -1426,11 +1424,12 @@ YY_RULE_SETUP case 14: +/* rule 14 can match eol */ YY_RULE_SETUP -#line 181 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 182 "/Users/akim/src/gnu/bison/src/scan-code.l" { const char *type_name = NULL; - fetch_type_name (yytext + 1, &type_name, *loc)[-1] = 0; + fetch_type_name (yytext + 1, &type_name, loc)[-1] = 0; obstack_sgrow (&obstack_for_string, "]b4_dollar_dollar("); obstack_quote (&obstack_for_string, type_name); obstack_sgrow (&obstack_for_string, ")["); @@ -1439,10 +1438,10 @@ YY_RULE_SETUP YY_BREAK case 15: YY_RULE_SETUP -#line 189 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 190 "/Users/akim/src/gnu/bison/src/scan-code.l" { obstack_sgrow (&obstack_for_string, "]b4_at_dollar["); - muscle_percent_define_ensure("locations", the_location, true); + muscle_percent_define_ensure("locations", *loc, true); } YY_BREAK @@ -1451,14 +1450,14 @@ YY_RULE_SETUP /* Escape M4 quoting characters in C code. */ case 16: YY_RULE_SETUP -#line 199 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 200 "/Users/akim/src/gnu/bison/src/scan-code.l" obstack_escape (&obstack_for_string, yytext); YY_BREAK /* By default, grow the string obstack with the input. */ case 17: /* rule 17 can match eol */ YY_RULE_SETUP -#line 202 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 203 "/Users/akim/src/gnu/bison/src/scan-code.l" STRING_GROW; YY_BREAK /* End of processing. */ @@ -1469,16 +1468,16 @@ case YY_STATE_EOF(SC_STRING): case YY_STATE_EOF(SC_CHARACTER): case YY_STATE_EOF(SC_RULE_ACTION): case YY_STATE_EOF(SC_SYMBOL_ACTION): -#line 205 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 206 "/Users/akim/src/gnu/bison/src/scan-code.l" STRING_FINISH; return last_string; YY_BREAK case 18: YY_RULE_SETUP -#line 208 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 209 "/Users/akim/src/gnu/bison/src/scan-code.l" YY_FATAL_ERROR( "flex scanner jammed" ); YY_BREAK -#line 1481 "src/scan-code.c" +#line 1480 "src/scan-code.c" case YY_END_OF_BUFFER: { @@ -1797,7 +1796,7 @@ static int yy_get_next_buffer (void) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 91 ) + if ( yy_current_state >= 82 ) yy_c = yy_meta[yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; @@ -1830,11 +1829,11 @@ static int yy_get_next_buffer (void) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 91 ) + if ( yy_current_state >= 82 ) yy_c = yy_meta[yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - yy_is_jam = (yy_current_state == 90); + yy_is_jam = (yy_current_state == 81); return yy_is_jam ? 0 : yy_current_state; } @@ -2583,7 +2582,7 @@ void yyfree (void * ptr ) /* %ok-for-header */ -#line 208 "/Users/akim/src/gnu/bison/src/scan-code.l" +#line 209 "/Users/akim/src/gnu/bison/src/scan-code.l" static inline bool @@ -2595,14 +2594,14 @@ is_dot_or_dash (char ch) static inline bool contains_dot_or_dash (const char* p) { - return strpbrk(p, ".-"); + return !!strpbrk (p, ".-"); } /* Defines a variant of a symbolic name resolution. */ typedef struct { /* Index in symbol list. */ - unsigned symbol_index; + int symbol_index; /* Matched symbol id and loc. */ uniqstr id; @@ -2629,8 +2628,8 @@ typedef struct #define VARIANT_NOT_VISIBLE_FROM_MIDRULE (1 << 2) static variant *variant_table = NULL; -static unsigned variant_table_size = 0; -static unsigned variant_count = 0; +static int variant_table_size = 0; +static int variant_count = 0; static variant * variant_table_grow (void) @@ -2665,7 +2664,7 @@ find_prefix_end (char const *prefix, char const *cp, char const *end) } static variant * -variant_add (uniqstr id, location id_loc, unsigned symbol_index, +variant_add (uniqstr id, location id_loc, int symbol_index, char const *cp, char const *cp_end, bool explicit_bracketing) { char const *prefix_end = find_prefix_end (id, cp, cp_end); @@ -2686,7 +2685,7 @@ variant_add (uniqstr id, location id_loc, unsigned symbol_index, } static const char * -get_at_spec(unsigned symbol_index) +get_at_spec(int symbol_index) { static char at_buf[20]; if (symbol_index == 0) @@ -2700,7 +2699,7 @@ static void show_sub_message (warnings warning, const char* cp, bool explicit_bracketing, int midrule_rhs_index, char dollar_or_at, - unsigned indent, const variant *var) + int indent, const variant *var) { const char *at_spec = get_at_spec (var->symbol_index); @@ -2764,9 +2763,9 @@ static void show_sub_messages (warnings warning, const char* cp, bool explicit_bracketing, int midrule_rhs_index, char dollar_or_at, - unsigned indent) + int indent) { - for (unsigned i = 0; i < variant_count; ++i) + for (int i = 0; i < variant_count; ++i) show_sub_message (warning | silent, cp, explicit_bracketing, midrule_rhs_index, dollar_or_at, @@ -2786,7 +2785,7 @@ show_sub_messages (warnings warning, accesses. */ static long parse_ref (char *cp, symbol_list *rule, int rule_length, - int midrule_rhs_index, char *text, location text_loc, + int midrule_rhs_index, char *text, const location *text_loc, char dollar_or_at) { if ('$' == *cp) @@ -2799,7 +2798,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, return num; else { - complain (&text_loc, complaint, _("integer out of range: %s"), + complain (text_loc, complaint, _("integer out of range: %s"), quote (text)); return INVALID_REF; } @@ -2816,7 +2815,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, /* Add all relevant variants. */ { - unsigned symbol_index; + int symbol_index; symbol_list *l; variant_count = 0; for (symbol_index = 0, l = rule; !symbol_list_null (l); @@ -2838,12 +2837,12 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, } /* Check errors. */ - unsigned valid_variants = 0; - unsigned valid_variant_index = 0; - for (unsigned i = 0; i < variant_count; ++i) + int valid_variants = 0; + int valid_variant_index = 0; + for (int i = 0; i < variant_count; ++i) { variant *var = &variant_table[i]; - unsigned symbol_index = var->symbol_index; + int symbol_index = var->symbol_index; /* Check visibility from midrule actions. */ if (midrule_rhs_index != 0 @@ -2869,16 +2868,16 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, { case 0: { - unsigned len = (explicit_bracketing || !ref_tail_fields) ? + int len = (explicit_bracketing || !ref_tail_fields) ? cp_end - cp : ref_tail_fields - cp; - unsigned indent = 0; + int indent = 0; - complain_indent (&text_loc, complaint, &indent, + complain_indent (text_loc, complaint, &indent, _("invalid reference: %s"), quote (text)); indent += SUB_INDENT; if (len == 0) { - location sym_loc = text_loc; + location sym_loc = *text_loc; sym_loc.start.column += 1; sym_loc.end = sym_loc.start; complain_indent (&sym_loc, complaint, &indent, @@ -2887,12 +2886,12 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, dollar_or_at); } else if (midrule_rhs_index) - complain_indent (&rule->location, complaint, &indent, + complain_indent (&rule->rhs_loc, complaint, &indent, _("symbol not found in production before $%d: " "%.*s"), midrule_rhs_index, len, cp); else - complain_indent (&rule->location, complaint, &indent, + complain_indent (&rule->rhs_loc, complaint, &indent, _("symbol not found in production: %.*s"), len, cp); @@ -2904,17 +2903,17 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, } case 1: { - unsigned indent = 0; + int indent = 0; if (variant_count > 1) { - complain_indent (&text_loc, Wother, &indent, + complain_indent (text_loc, Wother, &indent, _("misleading reference: %s"), quote (text)); show_sub_messages (Wother, cp, explicit_bracketing, midrule_rhs_index, dollar_or_at, indent + SUB_INDENT); } { - unsigned symbol_index = + int symbol_index = variant_table[valid_variant_index].symbol_index; return (symbol_index == midrule_rhs_index) ? LHS_REF : symbol_index; } @@ -2922,8 +2921,8 @@ parse_ref (char *cp, symbol_list *rule, int rule_length, case 2: default: { - unsigned indent = 0; - complain_indent (&text_loc, complaint, &indent, + int indent = 0; + complain_indent (text_loc, complaint, &indent, _("ambiguous reference: %s"), quote (text)); show_sub_messages (complaint, cp, explicit_bracketing, midrule_rhs_index, @@ -2946,7 +2945,7 @@ int max_left_semantic_context = 0; static char * fetch_type_name (char *cp, char const **type_name, - location dollar_loc) + const location *dollar_loc) { if (*cp == '<') { @@ -2959,7 +2958,7 @@ fetch_type_name (char *cp, char const **type_name, 'text' is needed for error messages. */ ++cp; if (untyped_var_seen) - complain (&dollar_loc, complaint, + complain (dollar_loc, complaint, _("explicit type given in untyped grammar")); tag_seen = true; } @@ -2975,7 +2974,7 @@ fetch_type_name (char *cp, char const **type_name, `------------------------------------------------------------------*/ static void -handle_action_dollar (symbol_list *rule, char *text, location dollar_loc) +handle_action_dollar (symbol_list *rule, char *text, const location *dollar_loc) { symbol_list *effective_rule; int effective_rule_length; @@ -2996,7 +2995,7 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc) char *cp = fetch_type_name (text + 1, &type_name, dollar_loc); int n = parse_ref (cp, effective_rule, effective_rule_length, rule->midrule_parent_rhs_index, text, dollar_loc, '$'); - /* End type_name. Don't do it ealier: parse_ref depends on TEXT. */ + /* End type_name. Don't do it earlier: parse_ref depends on TEXT. */ if (type_name) cp[-1] = '\0'; @@ -3011,16 +3010,16 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc) if (!type_name && !sym->content.sym->content->type_name) { - if (union_seen | tag_seen) + if (union_seen || tag_seen) { if (rule->midrule_parent_rule) - complain (&dollar_loc, complaint, + complain (dollar_loc, complaint, _("$$ for the midrule at $%d of %s" " has no declared type"), rule->midrule_parent_rhs_index, quote (effective_rule->content.sym->tag)); else - complain (&dollar_loc, complaint, + complain (dollar_loc, complaint, _("$$ of %s has no declared type"), quote (rule->content.sym->tag)); } @@ -3045,8 +3044,8 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc) if (!type_name && (!sym || !sym->content.sym->content->type_name)) { - if (union_seen | tag_seen) - complain (&dollar_loc, complaint, + if (union_seen || tag_seen) + complain (dollar_loc, complaint, _("$%s of %s has no declared type"), cp, quote (effective_rule->content.sym->tag)); else @@ -3069,7 +3068,7 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc) { if (muscle_percent_define_ifdef ("api.value.automove") && sym->action_props.is_value_used) - complain (&dollar_loc, Wother, + complain (dollar_loc, Wother, _("multiple occurrences of $%d with api.value.automove"), n); sym->action_props.is_value_used = true; @@ -3086,7 +3085,7 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc) `------------------------------------------------------*/ static void -handle_action_at (symbol_list *rule, char *text, location at_loc) +handle_action_at (symbol_list *rule, char *text, const location *at_loc) { symbol_list *effective_rule; int effective_rule_length; @@ -3102,7 +3101,7 @@ handle_action_at (symbol_list *rule, char *text, location at_loc) effective_rule_length = symbol_list_length (rule->next); } - muscle_percent_define_ensure("locations", at_loc, true); + muscle_percent_define_ensure ("locations", *at_loc, true); int n = parse_ref (text + 1, effective_rule, effective_rule_length, rule->midrule_parent_rhs_index, text, at_loc, '@'); @@ -3127,8 +3126,8 @@ handle_action_at (symbol_list *rule, char *text, location at_loc) | Initialize the scanner. | `-------------------------*/ -/* Translate the dollars and ats in \a self, in the context \a sc_context - (SC_RULE_ACTION, SC_SYMBOL_ACTION, INITIAL). */ +/* Translate the '$...' and '@...' in \a self, in the context \a + sc_context (SC_RULE_ACTION, SC_SYMBOL_ACTION, INITIAL). */ static char const * translate_action (code_props *self, int sc_context) diff --git a/contrib/tools/bison/src/scan-code.h b/contrib/tools/bison/src/scan-code.h index 483fe9ba56ce..06b6a73a1ecc 100644 --- a/contrib/tools/bison/src/scan-code.h +++ b/contrib/tools/bison/src/scan-code.h @@ -1,6 +1,6 @@ /* Bison code properties structure and scanner. - Copyright (C) 2006-2007, 2009-2015, 2018-2019 Free Software + Copyright (C) 2006-2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/src/scan-gram.c b/contrib/tools/bison/src/scan-gram.c index 49d954188727..a34ddb8f5f4f 100644 --- a/contrib/tools/bison/src/scan-gram.c +++ b/contrib/tools/bison/src/scan-gram.c @@ -691,8 +691,8 @@ static void yynoreturn yy_fatal_error ( const char* msg ); /* %% [3.0] code to copy yytext_ptr to yytext[] goes here, if %array \ */\ (yy_c_buf_p) = yy_cp; /* %% [4.0] data tables for the DFA and the user's section 1 definitions go here */ -#define YY_NUM_RULES 129 -#define YY_END_OF_BUFFER 130 +#define YY_NUM_RULES 127 +#define YY_END_OF_BUFFER 128 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info @@ -700,495 +700,584 @@ struct yy_trans_info flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static const flex_int16_t yy_accept[573] = +static const flex_int16_t yy_accept[600] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 92, 92, 112, 112, 112, 112, 0, 0, - 0, 0, 130, 79, 2, 2, 70, 79, 69, 79, - 1, 65, 79, 66, 66, 64, 76, 62, 65, 78, - 72, 63, 79, 89, 89, 127, 94, 93, 127, 80, - 96, 95, 83, 2, 1, 83, 82, 81, 83, 98, - 98, 99, 97, 80, 128, 118, 127, 117, 127, 127, - 127, 121, 124, 125, 127, 91, 127, 116, 115, 127, - 114, 113, 86, 2, 1, 84, 86, 86, 85, 86, - - 87, 2, 1, 87, 87, 79, 77, 61, 0, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 71, 65, 65, - 4, 3, 68, 66, 68, 0, 75, 0, 88, 111, - 109, 100, 111, 102, 103, 104, 105, 106, 107, 111, - 108, 111, 98, 98, 99, 126, 119, 120, 0, 122, - 0, 121, 123, 0, 90, 0, 0, 92, 112, 112, - 112, 112, 86, 84, 61, 0, 73, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, - - 61, 61, 61, 61, 61, 61, 61, 61, 3, 68, - 67, 74, 0, 100, 0, 0, 101, 0, 0, 0, + 0, 0, 91, 91, 111, 111, 111, 111, 0, 0, + 0, 0, 128, 78, 2, 2, 2, 69, 78, 68, + 78, 1, 64, 78, 65, 65, 60, 63, 75, 61, + 64, 77, 71, 62, 78, 88, 88, 88, 126, 126, + 93, 126, 92, 126, 126, 126, 126, 126, 126, 126, + 126, 79, 95, 126, 94, 82, 2, 2, 1, 82, + 81, 80, 82, 97, 97, 98, 96, 79, 117, 126, + 116, 126, 126, 126, 120, 123, 124, 126, 90, 126, + + 126, 115, 126, 114, 126, 113, 126, 112, 85, 2, + 2, 1, 83, 85, 85, 84, 85, 86, 2, 2, + 1, 86, 86, 78, 2, 76, 59, 0, 59, 59, + 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 59, 59, 59, 59, 70, 64, 64, 4, + 3, 67, 65, 67, 0, 74, 0, 88, 87, 93, + 110, 110, 108, 99, 110, 101, 102, 103, 104, 105, + 106, 110, 107, 110, 126, 0, 0, 0, 0, 0, + 0, 95, 97, 97, 98, 125, 118, 119, 0, 121, + 0, 120, 122, 0, 89, 0, 90, 0, 91, 0, + + 115, 111, 111, 111, 111, 111, 113, 85, 83, 59, + 0, 0, 72, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 59, 59, 3, 67, 66, 73, 0, 99, + 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 0, 100, - 0, 0, 61, 7, 61, 61, 61, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 22, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, - - 61, 61, 34, 61, 61, 61, 61, 61, 61, 42, - 61, 45, 61, 61, 48, 0, 0, 0, 61, 8, - 61, 61, 61, 13, 14, 61, 61, 61, 61, 61, - 61, 61, 61, 61, 25, 61, 61, 61, 61, 61, - 61, 61, 30, 61, 32, 61, 61, 61, 61, 61, - 61, 39, 61, 41, 43, 46, 61, 0, 0, 110, - 6, 61, 10, 61, 61, 61, 15, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, - 61, 61, 31, 61, 61, 61, 61, 61, 61, 61, - 61, 61, 61, 0, 61, 11, 61, 61, 61, 61, - - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, - 61, 61, 61, 61, 61, 61, 0, 58, 61, 61, - 36, 61, 61, 38, 61, 61, 61, 47, 5, 0, - 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, - 61, 61, 21, 61, 61, 61, 61, 27, 61, 57, - 28, 61, 61, 61, 61, 61, 40, 61, 61, 0, - 61, 61, 61, 61, 61, 16, 53, 61, 61, 61, - 61, 61, 23, 24, 61, 61, 61, 61, 61, 61, - 61, 61, 61, 61, 0, 0, 61, 61, 12, 61, - 61, 61, 61, 61, 20, 61, 61, 61, 61, 61, - - 61, 35, 61, 61, 61, 61, 61, 61, 61, 61, - 17, 61, 61, 61, 50, 61, 61, 61, 33, 37, - 59, 44, 60, 9, 51, 61, 61, 0, 54, 61, - 61, 61, 50, 50, 61, 61, 61, 49, 52, 61, - 61, 61, 50, 61, 61, 61, 61, 61, 19, 61, - 61, 61, 61, 61, 26, 56, 61, 61, 61, 61, - 61, 61, 61, 18, 55, 61, 61, 61, 61, 61, - 29, 0 + 0, 0, 0, 0, 0, 59, 59, 59, 59, 59, + 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, + + 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 59, 0, 99, 0, 0, 59, 7, 59, + 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 21, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 59, 59, 59, 59, 59, 33, 59, 59, + 59, 59, 59, 59, 40, 59, 43, 59, 59, 46, + 0, 0, 0, 59, 8, 59, 59, 59, 13, 14, + 59, 59, 59, 59, 59, 59, 59, 59, 59, 24, + 59, 59, 59, 59, 59, 59, 59, 29, 59, 31, + 59, 59, 59, 59, 59, 37, 59, 39, 41, 44, + + 59, 0, 0, 109, 6, 59, 10, 59, 59, 59, + 15, 59, 59, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 59, 59, 59, 30, 59, 59, 59, 59, + 59, 59, 59, 59, 59, 0, 59, 11, 59, 59, + 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 59, 59, 59, 59, 59, 0, 57, 59, + 59, 35, 59, 36, 59, 59, 59, 45, 5, 0, + 0, 59, 59, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 20, 59, 59, 59, 59, 26, 59, 56, + 27, 59, 59, 59, 59, 38, 59, 59, 0, 59, + + 59, 59, 59, 59, 16, 52, 59, 59, 59, 59, + 22, 23, 59, 59, 59, 59, 59, 59, 59, 59, + 59, 0, 0, 59, 59, 12, 59, 59, 59, 59, + 19, 59, 59, 59, 59, 59, 59, 34, 59, 59, + 59, 0, 59, 59, 59, 59, 17, 59, 59, 49, + 59, 59, 59, 32, 47, 42, 58, 9, 50, 59, + 59, 0, 53, 59, 59, 49, 49, 59, 59, 59, + 48, 51, 59, 59, 49, 59, 59, 59, 59, 18, + 59, 59, 59, 59, 25, 55, 59, 59, 59, 59, + 59, 54, 59, 59, 59, 59, 59, 28, 0 + } ; static const YY_CHAR yy_ec[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 2, 2, 4, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 5, 1, 6, 7, 1, 8, 1, 9, 1, - 1, 10, 1, 11, 12, 13, 14, 15, 16, 16, - 16, 16, 16, 16, 16, 17, 17, 18, 19, 20, - 21, 22, 23, 1, 24, 24, 24, 24, 24, 24, - 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 26, 25, 25, 27, 25, 25, - 28, 29, 30, 1, 31, 1, 32, 33, 34, 35, - - 36, 37, 38, 39, 40, 25, 41, 42, 43, 44, - 45, 46, 47, 48, 49, 50, 51, 52, 25, 53, - 54, 25, 55, 56, 57, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 4, 4, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 6, 7, 8, 9, 7, 10, 7, 11, 7, + 7, 12, 7, 13, 14, 15, 16, 17, 18, 18, + 18, 18, 18, 18, 18, 19, 19, 20, 21, 22, + 23, 24, 25, 26, 27, 27, 27, 27, 27, 27, + 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, + 28, 28, 28, 28, 29, 28, 28, 30, 28, 28, + 31, 32, 33, 26, 34, 26, 35, 36, 37, 38, + + 39, 40, 41, 42, 43, 28, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 28, 56, + 57, 28, 58, 59, 60, 26, 61, 62, 62, 62, + 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, + 62, 62, 62, 63, 63, 63, 63, 63, 63, 63, + 63, 63, 63, 63, 63, 63, 63, 63, 63, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 1, 1, 65, 65, 65, 65, 65, 65, 65, + + 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, + 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, + 65, 65, 65, 66, 67, 67, 67, 67, 67, 67, + 67, 67, 67, 67, 67, 67, 68, 67, 67, 69, + 70, 70, 70, 71, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } ; -static const YY_CHAR yy_meta[59] = +static const YY_CHAR yy_meta[73] = { 0, - 1, 2, 3, 1, 2, 4, 1, 4, 4, 4, - 4, 5, 6, 2, 7, 7, 7, 1, 4, 8, - 4, 8, 1, 7, 9, 9, 9, 10, 1, 11, - 9, 7, 7, 7, 7, 7, 7, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 4, 4, 4, 1 + 1, 2, 3, 2, 2, 2, 1, 4, 1, 4, + 4, 4, 4, 5, 6, 2, 7, 7, 7, 8, + 9, 10, 9, 10, 8, 8, 7, 7, 7, 7, + 11, 8, 12, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 9, 9, 9, + 8, 8, 8, 8, 1, 1, 1, 1, 1, 1, + 1, 8 } ; -static const flex_int16_t yy_base[599] = +static const flex_int16_t yy_base[618] = { 0, - 0, 998, 994, 993, 56, 57, 58, 61, 63, 90, - 76, 87, 70, 97, 117, 121, 66, 130, 140, 144, - 79, 107, 99, 109, 153, 159, 148, 152, 201, 995, - 182, 258, 1001, 0, 1006, 1006, 1006, 265, 1006, 1006, - 1006, 320, 153, 313, 153, 1006, 61, 1006, 330, 1006, - 1006, 1006, 958, 1006, 985, 1006, 1006, 1006, 383, 1006, - 1006, 1006, 1006, 1006, 1006, 161, 1006, 1006, 956, 985, - 110, 976, 1006, 983, 1006, 1006, 937, 1006, 169, 144, - 254, 1006, 1006, 1006, 250, 1006, 187, 1006, 1006, 265, - 1006, 1006, 0, 1006, 0, 0, 261, 1006, 1006, 951, - - 1006, 1006, 1006, 266, 950, 0, 1006, 0, 320, 951, - 945, 241, 293, 949, 946, 943, 250, 950, 294, 934, - 303, 245, 150, 311, 940, 947, 950, 1006, 436, 0, - 1006, 0, 0, 346, 480, 959, 1006, 940, 1006, 1006, - 1006, 342, 0, 1006, 1006, 1006, 1006, 1006, 1006, 0, - 1006, 0, 967, 330, 958, 1006, 1006, 1006, 365, 1006, - 369, 1006, 1006, 374, 1006, 378, 382, 948, 1006, 388, - 947, 392, 0, 0, 0, 398, 1006, 931, 939, 374, - 925, 926, 923, 924, 360, 921, 928, 923, 368, 932, - 917, 921, 398, 927, 912, 913, 333, 912, 912, 920, - - 921, 924, 907, 913, 907, 912, 903, 916, 0, 0, - 0, 1006, 905, 402, 0, 0, 0, 423, 431, 453, - 410, 459, 443, 465, 390, 471, 475, 479, 483, 379, - 916, 911, 895, 81, 895, 908, 893, 897, 905, 904, - 903, 926, 887, 898, 885, 922, 901, 894, 895, 415, - 448, 412, 882, 883, 420, 894, 883, 890, 874, 885, - 881, 874, 878, 884, 883, 873, 884, 882, 879, 1006, - 0, 0, 866, 0, 875, 861, 867, 862, 875, 854, - 859, 872, 893, 869, 857, 862, 850, 0, 854, 849, - 862, 333, 861, 856, 859, 854, 844, 856, 848, 839, - - 846, 852, 851, 836, 467, 845, 834, 847, 832, 0, - 837, 0, 836, 834, 0, 873, 0, 0, 823, 0, - 834, 839, 823, 0, 0, 475, 823, 826, 477, 839, - 838, 837, 836, 827, 0, 820, 828, 820, 826, 818, - 812, 810, 0, 809, 0, 846, 822, 820, 809, 808, - 805, 0, 802, 0, 479, 0, 802, 484, 0, 1006, - 0, 800, 800, 814, 795, 794, 480, 797, 799, 798, - 794, 799, 802, 791, 793, 789, 804, 799, 802, 797, - 787, 795, 516, 784, 793, 780, 795, 794, 789, 779, - 773, 772, 785, 519, 495, 0, 770, 783, 782, 769, - - 768, 779, 763, 762, 763, 799, 774, 777, 764, 771, - 755, 756, 753, 754, 768, 753, 525, 1006, 768, 755, - 0, 750, 749, 0, 752, 763, 762, 0, 1006, 787, - 746, 745, 745, 741, 740, 739, 738, 748, 734, 733, - 746, 749, 0, 737, 730, 741, 735, 0, 734, 0, - 0, 732, 726, 739, 723, 722, 0, 737, 736, 762, - 719, 718, 717, 731, 730, 0, 0, 722, 715, 714, - 711, 724, 0, 0, 717, 706, 705, 714, 721, 716, - 715, 714, 707, 706, 741, 499, 710, 709, 0, 699, - 698, 689, 690, 681, 0, 678, 663, 511, 513, 668, - - 664, 0, 654, 652, 663, 660, 661, 647, 612, 608, - 536, 605, 601, 610, 545, 603, 600, 605, 0, 0, - 0, 0, 0, 0, 0, 608, 607, 549, 1006, 531, - 533, 595, 556, 569, 591, 590, 527, 0, 0, 538, - 532, 524, 576, 531, 529, 513, 516, 515, 0, 499, - 498, 491, 467, 461, 0, 0, 459, 439, 435, 434, - 389, 381, 378, 0, 0, 390, 366, 347, 350, 307, - 0, 1006, 581, 592, 603, 614, 625, 636, 647, 653, - 662, 673, 684, 693, 699, 704, 713, 720, 286, 277, - 259, 187, 179, 173, 135, 133, 87, 729 - + 0, 1341, 68, 69, 81, 153, 85, 89, 99, 105, + 102, 109, 157, 161, 231, 301, 179, 194, 371, 441, + 195, 247, 241, 253, 266, 267, 273, 319, 513, 1340, + 344, 362, 1348, 0, 1351, 1351, 1344, 1351, 576, 1351, + 1351, 1351, 634, 63, 278, 59, 0, 1351, 71, 1351, + 0, 1351, 1351, 1351, 1301, 1351, 1342, 1328, 1351, 1351, + 1351, 1340, 1351, 702, 65, 1278, 75, 36, 0, 116, + 1279, 1351, 1351, 1337, 1351, 1351, 1351, 1336, 1351, 75, + 1351, 1351, 1293, 1323, 108, 1314, 1351, 1321, 1351, 1274, + 1351, 143, 159, 255, 1351, 1351, 1351, 154, 1351, 1330, + + 338, 1351, 1329, 1351, 392, 1351, 1328, 1351, 0, 1351, + 1327, 0, 0, 176, 1351, 1351, 1284, 1351, 1351, 1325, + 1351, 192, 1282, 0, 1351, 1351, 0, 350, 1283, 1277, + 157, 184, 1281, 1278, 1275, 253, 1282, 267, 1266, 177, + 170, 201, 344, 1272, 1279, 1282, 1351, 0, 0, 1351, + 0, 0, 318, 398, 1292, 1351, 1272, 1351, 1351, 1351, + 1351, 1311, 1351, 117, 441, 1351, 1351, 1351, 1351, 1351, + 1351, 447, 1351, 471, 1351, 322, 326, 342, 347, 350, + 356, 1351, 1299, 224, 1290, 1351, 1351, 1351, 489, 1351, + 590, 1351, 1351, 634, 1351, 712, 1351, 719, 1279, 1307, + + 1351, 1351, 741, 1277, 1305, 757, 1351, 0, 0, 0, + 762, 1304, 1351, 1259, 1267, 228, 1253, 1254, 1251, 1252, + 61, 1249, 1256, 1251, 254, 1260, 1245, 1249, 393, 1255, + 1240, 1241, 243, 1240, 1240, 1248, 1249, 1252, 1235, 1241, + 1235, 1240, 1231, 1244, 0, 0, 0, 1351, 1233, 123, + 752, 758, 786, 359, 391, 407, 778, 416, 1276, 804, + 294, 1275, 812, 348, 1274, 825, 284, 1273, 830, 835, + 1272, 840, 845, 464, 1271, 1238, 1233, 1217, 286, 1217, + 1230, 1215, 1219, 1227, 1226, 1225, 1249, 1209, 1220, 1207, + 1245, 1223, 1216, 1217, 156, 245, 222, 1204, 1205, 279, + + 1216, 1205, 1212, 1196, 1207, 1203, 1196, 1200, 1206, 1205, + 1195, 1206, 1204, 1201, 1351, 835, 841, 1188, 0, 1197, + 1183, 1189, 1184, 1197, 1176, 1181, 1194, 1216, 1191, 1179, + 1184, 1172, 0, 1176, 1171, 1184, 416, 1183, 1178, 1181, + 1176, 1166, 1178, 1170, 1161, 1168, 1174, 1173, 1158, 427, + 1167, 1156, 1169, 1154, 0, 1159, 0, 1158, 1156, 0, + 1197, 865, 871, 1145, 0, 1156, 1161, 1145, 0, 0, + 428, 1145, 1148, 573, 1161, 1160, 1159, 1158, 1149, 0, + 1142, 1150, 1142, 1148, 1140, 1134, 1132, 0, 1131, 0, + 1169, 1144, 1142, 1131, 1128, 0, 1125, 0, 574, 0, + + 1125, 485, 895, 1351, 0, 1123, 1123, 1137, 1118, 1117, + 575, 1120, 1122, 1118, 1123, 1126, 1115, 1117, 1113, 1128, + 1123, 1126, 1121, 1111, 1119, 913, 1108, 1117, 1104, 1119, + 1114, 1104, 1098, 1097, 1110, 639, 678, 0, 1095, 1108, + 1107, 1094, 1093, 1104, 1088, 1080, 1103, 1065, 1068, 1053, + 1060, 1031, 999, 996, 997, 1010, 993, 921, 1351, 1008, + 995, 0, 928, 0, 931, 942, 941, 0, 1351, 972, + 966, 924, 923, 922, 918, 917, 916, 914, 924, 904, + 917, 920, 0, 897, 890, 889, 883, 0, 876, 0, + 0, 874, 848, 854, 835, 0, 850, 849, 861, 810, + + 806, 805, 819, 783, 0, 0, 769, 762, 751, 764, + 0, 0, 757, 746, 733, 735, 739, 734, 733, 709, + 707, 743, 594, 709, 702, 0, 692, 691, 680, 681, + 0, 680, 676, 694, 695, 679, 665, 0, 643, 654, + 626, 229, 618, 613, 595, 594, 935, 547, 555, 943, + 541, 463, 462, 0, 0, 0, 0, 0, 0, 461, + 458, 948, 1351, 716, 427, 957, 861, 421, 405, 395, + 0, 0, 405, 392, 891, 387, 363, 347, 356, 0, + 340, 335, 326, 318, 0, 0, 325, 293, 314, 255, + 244, 0, 227, 192, 124, 124, 69, 0, 1351, 980, + + 992, 1004, 1016, 1028, 1040, 1047, 1050, 1057, 1063, 1075, + 1087, 1097, 1104, 1107, 1114, 1122, 1129 } ; -static const flex_int16_t yy_def[599] = +static const flex_int16_t yy_def[618] = { 0, - 572, 1, 573, 573, 574, 574, 574, 574, 575, 575, - 576, 576, 574, 574, 574, 574, 574, 574, 574, 574, - 574, 574, 574, 574, 574, 574, 574, 574, 572, 29, - 577, 577, 572, 578, 572, 572, 572, 572, 572, 572, - 572, 579, 572, 580, 580, 572, 572, 572, 579, 572, - 572, 572, 578, 572, 572, 572, 572, 572, 581, 572, - 572, 572, 572, 572, 572, 572, 572, 572, 572, 582, - 582, 572, 572, 582, 572, 572, 572, 572, 572, 572, - 572, 572, 572, 572, 572, 572, 572, 572, 572, 583, - 572, 572, 584, 572, 584, 585, 572, 572, 572, 584, - - 572, 572, 572, 572, 572, 578, 572, 586, 572, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 572, 579, 49, - 572, 587, 588, 580, 588, 572, 572, 572, 572, 572, - 572, 572, 589, 572, 572, 572, 572, 572, 572, 590, - 572, 591, 582, 582, 572, 572, 572, 572, 572, 572, - 572, 572, 572, 572, 572, 572, 572, 572, 572, 572, - 572, 572, 584, 585, 586, 572, 572, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - - 586, 586, 586, 586, 586, 586, 586, 586, 587, 588, - 135, 572, 572, 572, 592, 593, 591, 572, 572, 572, - 572, 572, 572, 572, 572, 572, 572, 572, 572, 583, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 572, 572, - 594, 595, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 572, 596, 597, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 572, 590, 572, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 572, 586, 586, 586, 586, 586, 586, - - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 572, 572, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 572, 572, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 598, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 598, 598, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 572, 572, 586, - 586, 586, 572, 572, 586, 586, 586, 586, 586, 586, - 586, 586, 572, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 586, 586, 586, 586, 586, 586, 586, 586, 586, - 586, 0, 572, 572, 572, 572, 572, 572, 572, 572, - 572, 572, 572, 572, 572, 572, 572, 572, 572, 572, - 572, 572, 572, 572, 572, 572, 572, 572 - + 599, 1, 600, 600, 601, 601, 6, 6, 602, 602, + 603, 603, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 599, 29, + 604, 604, 599, 605, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 606, 606, 605, 599, 599, 599, + 607, 599, 599, 599, 605, 599, 599, 599, 599, 599, + 599, 599, 599, 608, 599, 599, 599, 599, 609, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 610, 610, 599, 599, 610, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + + 599, 599, 599, 599, 611, 599, 599, 599, 612, 599, + 599, 612, 613, 599, 599, 599, 612, 599, 599, 599, + 599, 599, 599, 605, 599, 599, 614, 599, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 599, 43, 607, 599, + 615, 616, 606, 616, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 610, 610, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + + 599, 599, 599, 599, 599, 599, 599, 612, 613, 614, + 599, 599, 599, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 615, 616, 154, 599, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 611, 599, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 599, 599, 599, 599, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 599, 599, 599, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + + 614, 599, 599, 599, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 599, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 599, 599, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 599, 599, + 599, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 617, 614, + + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 617, 617, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 617, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 599, 599, 614, 614, 599, 599, 614, 614, 614, + 614, 614, 614, 614, 599, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 614, 614, + 614, 614, 614, 614, 614, 614, 614, 614, 0, 599, + + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 599, 599, 599 } ; -static const flex_int16_t yy_nxt[1065] = +static const flex_int16_t yy_nxt[1424] = { 0, - 34, 35, 36, 34, 35, 37, 34, 38, 39, 40, - 41, 34, 42, 43, 44, 45, 45, 34, 46, 47, - 48, 40, 34, 49, 49, 49, 49, 50, 34, 34, - 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, - 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, - 49, 49, 49, 49, 51, 52, 40, 34, 57, 57, - 61, 58, 58, 61, 64, 36, 62, 64, 75, 62, - 136, 76, 75, 65, 78, 76, 66, 77, 78, 79, - 67, 75, 137, 79, 59, 59, 59, 71, 85, 59, - 68, 64, 36, 360, 64, 72, 69, 73, 71, 75, - - 65, 86, 76, 66, 77, 78, 72, 67, 73, 75, - 79, 86, 276, 60, 60, 60, 85, 68, 60, 75, - 277, 154, 76, 75, 80, 78, 76, 87, 80, 78, - 79, 153, 75, 74, 79, 76, 81, 87, 78, 359, - 81, 318, 75, 79, 74, 76, 75, 80, 78, 76, - 91, 80, 78, 79, 91, 88, 92, 79, 89, 81, - 92, 88, 131, 81, 89, 160, 132, 134, 134, 134, - 131, 82, 161, 83, 132, 82, 90, 83, 157, 317, - 90, 90, 158, 102, 36, 272, 102, 90, 167, 168, - 201, 167, 103, 271, 82, 104, 84, 159, 82, 202, - - 84, 93, 94, 36, 93, 94, 93, 93, 93, 93, - 93, 95, 93, 96, 97, 98, 98, 98, 93, 93, - 93, 93, 93, 93, 96, 96, 96, 96, 93, 93, - 99, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 93, 93, 93, 93, 102, - 36, 162, 102, 165, 105, 217, 170, 171, 103, 170, - 131, 104, 107, 163, 132, 131, 180, 108, 166, 132, - 199, 188, 164, 216, 200, 189, 181, 109, 108, 108, - 108, 108, 215, 172, 190, 108, 108, 110, 111, 112, - - 113, 114, 115, 108, 116, 108, 117, 118, 119, 120, - 121, 108, 122, 123, 124, 125, 126, 108, 127, 128, - 106, 176, 176, 106, 176, 192, 106, 134, 134, 134, - 572, 129, 129, 572, 196, 182, 572, 106, 193, 135, - 183, 154, 106, 194, 336, 184, 203, 572, 106, 106, - 197, 153, 572, 198, 571, 204, 214, 214, 572, 572, - 134, 134, 134, 336, 205, 135, 218, 219, 256, 218, - 220, 221, 257, 220, 177, 222, 223, 106, 222, 224, - 225, 572, 224, 167, 168, 570, 167, 572, 141, 227, - 171, 141, 227, 229, 230, 569, 229, 142, 142, 176, - - 176, 240, 176, 165, 245, 141, 233, 172, 143, 250, - 234, 141, 241, 568, 144, 145, 270, 270, 166, 146, - 246, 567, 235, 566, 218, 219, 147, 218, 251, 565, - 148, 160, 149, 150, 151, 152, 106, 564, 161, 106, - 157, 252, 106, 297, 158, 563, 298, 129, 129, 293, - 162, 301, 177, 106, 220, 221, 294, 220, 106, 159, - 222, 223, 163, 222, 106, 106, 224, 225, 302, 224, - 562, 164, 167, 168, 561, 167, 227, 171, 349, 227, - 227, 171, 295, 227, 229, 230, 365, 229, 369, 296, - 391, 400, 560, 106, 211, 211, 211, 350, 394, 394, - - 394, 429, 559, 211, 486, 366, 431, 370, 558, 392, - 401, 211, 211, 211, 211, 211, 211, 417, 417, 417, - 417, 429, 516, 430, 517, 432, 417, 417, 417, 417, - 557, 556, 555, 394, 394, 394, 418, 528, 528, 528, - 528, 517, 540, 517, 541, 418, 533, 533, 533, 533, - 528, 528, 528, 528, 554, 553, 529, 533, 533, 533, - 533, 541, 552, 541, 551, 534, 550, 549, 548, 529, - 543, 543, 543, 543, 547, 546, 534, 543, 543, 543, - 543, 54, 54, 54, 54, 54, 54, 54, 54, 54, - 54, 54, 56, 56, 56, 56, 56, 56, 56, 56, - - 56, 56, 56, 63, 63, 63, 63, 63, 63, 63, - 63, 63, 63, 63, 70, 70, 70, 70, 70, 70, - 70, 70, 70, 70, 70, 101, 101, 101, 101, 101, - 101, 101, 101, 101, 101, 101, 106, 545, 544, 542, - 106, 106, 539, 538, 537, 536, 106, 130, 535, 532, - 531, 130, 130, 130, 530, 130, 527, 130, 133, 133, - 526, 133, 140, 140, 140, 140, 140, 140, 140, 140, - 140, 140, 140, 153, 153, 153, 153, 153, 153, 153, - 525, 153, 153, 153, 169, 169, 169, 169, 169, 169, - 169, 169, 169, 173, 524, 523, 173, 173, 522, 521, - - 173, 520, 173, 174, 174, 174, 519, 174, 175, 175, - 175, 518, 175, 209, 209, 515, 209, 209, 209, 209, - 209, 209, 209, 209, 210, 210, 210, 514, 210, 485, - 485, 513, 485, 485, 485, 485, 485, 485, 485, 485, - 512, 511, 510, 509, 508, 507, 486, 506, 505, 504, - 503, 502, 501, 500, 499, 498, 497, 496, 495, 494, - 493, 492, 491, 490, 489, 488, 487, 486, 484, 483, - 482, 481, 480, 479, 478, 477, 476, 475, 474, 473, - 472, 471, 470, 469, 468, 467, 466, 465, 464, 463, - 462, 461, 460, 459, 458, 457, 456, 455, 454, 453, - - 452, 451, 450, 449, 448, 447, 446, 445, 444, 443, - 442, 441, 440, 439, 438, 437, 436, 435, 434, 433, - 428, 427, 426, 425, 424, 423, 422, 421, 420, 419, - 416, 415, 414, 413, 412, 411, 410, 409, 408, 407, - 406, 405, 404, 403, 402, 399, 398, 397, 396, 395, - 393, 390, 389, 388, 387, 386, 385, 384, 383, 382, - 381, 380, 379, 378, 377, 376, 375, 374, 373, 372, - 371, 368, 367, 364, 363, 362, 361, 358, 357, 356, - 355, 354, 353, 352, 351, 348, 347, 346, 345, 344, - 343, 342, 341, 340, 339, 338, 337, 335, 334, 333, - + 34, 35, 36, 35, 37, 35, 34, 38, 34, 39, + 40, 41, 42, 34, 43, 44, 45, 46, 46, 47, + 48, 49, 50, 41, 34, 34, 51, 51, 51, 51, + 52, 34, 34, 51, 51, 51, 51, 51, 51, 51, + 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, + 51, 51, 51, 51, 51, 51, 51, 53, 54, 41, + 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, + 34, 34, 57, 57, 150, 153, 153, 153, 151, 58, + 58, 59, 155, 61, 59, 62, 150, 73, 63, 74, + 151, 73, 60, 74, 156, 75, 60, 178, 178, 75, + + 77, 36, 77, 78, 77, 285, 77, 36, 77, 78, + 77, 79, 64, 83, 80, 85, 286, 79, 81, 598, + 80, 184, 85, 86, 81, 87, 175, 175, 175, 82, + 86, 183, 87, 250, 250, 82, 177, 177, 177, 315, + 315, 59, 59, 59, 59, 65, 66, 67, 68, 69, + 70, 71, 72, 59, 187, 61, 59, 62, 188, 59, + 63, 60, 597, 59, 89, 60, 90, 91, 89, 195, + 90, 91, 92, 88, 189, 596, 92, 180, 180, 180, + 88, 59, 190, 60, 64, 196, 89, 150, 60, 91, + 191, 151, 60, 338, 92, 216, 59, 59, 60, 60, + + 339, 89, 60, 150, 91, 217, 98, 151, 235, 92, + 60, 232, 236, 59, 59, 59, 59, 65, 66, 67, + 68, 69, 70, 71, 72, 60, 60, 233, 59, 218, + 234, 469, 59, 59, 219, 60, 523, 184, 89, 220, + 93, 91, 595, 99, 237, 100, 92, 183, 60, 59, + 59, 60, 94, 238, 60, 99, 342, 100, 98, 343, + 60, 594, 60, 278, 192, 59, 59, 279, 102, 102, + 103, 103, 101, 104, 104, 106, 193, 107, 60, 280, + 60, 301, 340, 108, 101, 302, 194, 224, 95, 341, + 96, 225, 593, 290, 153, 153, 153, 105, 105, 195, + + 226, 228, 59, 59, 105, 60, 592, 154, 89, 291, + 93, 91, 59, 346, 229, 196, 92, 190, 59, 230, + 321, 106, 94, 107, 59, 191, 60, 591, 322, 108, + 347, 590, 60, 154, 153, 153, 153, 59, 59, 198, + 199, 198, 200, 198, 59, 119, 36, 119, 120, 119, + 105, 211, 211, 211, 212, 211, 121, 192, 95, 122, + 96, 589, 588, 119, 36, 119, 120, 119, 587, 193, + 123, 586, 59, 59, 121, 60, 585, 122, 89, 194, + 93, 91, 239, 175, 175, 175, 92, 175, 175, 175, + 59, 240, 94, 203, 204, 203, 205, 203, 584, 583, + + 241, 582, 60, 175, 175, 175, 295, 213, 254, 254, + 254, 255, 255, 255, 247, 247, 247, 256, 256, 256, + 175, 175, 175, 206, 247, 581, 296, 187, 95, 381, + 97, 188, 247, 247, 247, 247, 247, 247, 580, 297, + 394, 409, 59, 59, 579, 60, 578, 189, 89, 381, + 93, 91, 175, 175, 175, 577, 92, 251, 251, 251, + 394, 410, 94, 252, 252, 252, 599, 251, 175, 175, + 175, 576, 60, 252, 574, 251, 251, 251, 251, 251, + 251, 252, 252, 252, 252, 252, 252, 253, 253, 253, + 257, 258, 257, 259, 257, 206, 572, 253, 95, 571, + + 97, 436, 436, 436, 570, 253, 253, 253, 253, 253, + 253, 569, 59, 109, 110, 36, 110, 111, 110, 109, + 109, 109, 109, 109, 109, 112, 109, 113, 114, 115, + 115, 115, 109, 109, 109, 109, 109, 109, 109, 113, + 113, 113, 113, 109, 109, 116, 113, 113, 113, 113, + 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, + 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, + 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, + 109, 109, 109, 109, 109, 126, 413, 433, 442, 568, + 127, 260, 261, 260, 262, 260, 469, 565, 542, 564, + + 128, 523, 127, 127, 127, 127, 413, 434, 443, 127, + 127, 129, 130, 131, 132, 133, 134, 127, 135, 127, + 136, 137, 138, 139, 140, 127, 141, 142, 143, 144, + 145, 127, 146, 147, 124, 263, 264, 263, 265, 263, + 124, 469, 124, 470, 471, 561, 560, 148, 148, 559, + 149, 149, 149, 124, 558, 436, 436, 436, 124, 124, + 149, 149, 149, 149, 557, 124, 124, 149, 149, 149, + 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, + 149, 149, 149, 149, 149, 149, 149, 149, 149, 149, + 149, 472, 556, 555, 124, 124, 124, 124, 124, 124, + + 124, 124, 124, 124, 124, 124, 162, 551, 552, 163, + 554, 473, 163, 266, 267, 266, 268, 266, 164, 164, + 198, 199, 198, 200, 198, 553, 163, 552, 552, 573, + 165, 550, 549, 163, 548, 547, 166, 167, 546, 545, + 544, 168, 270, 204, 270, 271, 270, 543, 169, 573, + 523, 541, 170, 540, 171, 172, 173, 174, 273, 274, + 273, 275, 273, 211, 211, 211, 212, 211, 316, 316, + 316, 539, 538, 537, 317, 317, 317, 536, 316, 257, + 258, 257, 259, 257, 317, 535, 316, 316, 316, 316, + 316, 316, 317, 317, 317, 317, 317, 317, 534, 533, + + 532, 531, 253, 253, 253, 260, 261, 260, 262, 260, + 530, 529, 253, 263, 264, 263, 265, 263, 528, 213, + 253, 253, 253, 253, 253, 253, 266, 267, 266, 268, + 266, 198, 199, 198, 200, 198, 270, 204, 270, 271, + 270, 270, 204, 270, 271, 270, 273, 274, 273, 275, + 273, 362, 362, 362, 527, 526, 525, 363, 363, 363, + 524, 362, 575, 575, 575, 575, 575, 363, 523, 362, + 362, 362, 362, 362, 362, 363, 363, 363, 363, 363, + 363, 403, 403, 403, 521, 520, 519, 404, 404, 404, + 518, 403, 575, 575, 575, 575, 575, 404, 517, 403, + + 403, 403, 403, 403, 403, 404, 404, 404, 404, 404, + 404, 252, 252, 252, 458, 458, 458, 458, 458, 516, + 515, 252, 458, 458, 458, 458, 458, 514, 513, 252, + 252, 252, 252, 252, 252, 459, 562, 562, 562, 562, + 562, 512, 511, 459, 566, 566, 566, 566, 566, 562, + 562, 562, 562, 562, 510, 509, 508, 563, 566, 566, + 566, 566, 566, 507, 506, 567, 505, 504, 503, 502, + 563, 501, 500, 499, 469, 498, 497, 496, 495, 567, + 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, + 56, 56, 60, 60, 60, 60, 60, 60, 60, 60, + + 60, 60, 60, 60, 76, 76, 76, 76, 76, 76, + 76, 76, 76, 76, 76, 76, 84, 84, 84, 84, + 84, 84, 84, 84, 84, 84, 84, 84, 118, 118, + 118, 118, 118, 118, 118, 118, 118, 118, 118, 118, + 124, 494, 493, 492, 124, 124, 491, 124, 490, 489, + 488, 124, 152, 152, 149, 149, 149, 161, 161, 161, + 161, 161, 161, 161, 161, 161, 161, 161, 161, 179, + 179, 179, 179, 179, 179, 183, 183, 183, 183, 183, + 183, 183, 183, 183, 487, 183, 183, 202, 202, 202, + 202, 202, 202, 202, 202, 202, 202, 208, 486, 485, + + 208, 208, 484, 483, 208, 208, 208, 208, 209, 209, + 209, 210, 210, 210, 245, 245, 482, 245, 245, 245, + 245, 245, 245, 245, 245, 245, 246, 246, 246, 522, + 522, 481, 522, 522, 522, 522, 522, 522, 522, 522, + 522, 480, 479, 478, 477, 476, 475, 474, 468, 467, + 466, 465, 464, 463, 462, 461, 460, 457, 456, 455, + 454, 453, 452, 451, 450, 449, 448, 447, 446, 445, + 444, 441, 440, 439, 438, 437, 435, 432, 431, 430, + 429, 428, 427, 426, 425, 424, 423, 422, 421, 420, + 419, 418, 417, 416, 415, 414, 412, 411, 408, 407, + + 406, 405, 402, 401, 400, 399, 398, 397, 396, 395, + 393, 392, 391, 390, 389, 388, 387, 386, 385, 384, + 383, 382, 380, 379, 378, 377, 376, 375, 374, 373, + 372, 371, 370, 369, 368, 367, 366, 365, 364, 361, + 360, 359, 358, 357, 356, 355, 354, 353, 352, 351, + 350, 349, 348, 345, 344, 337, 336, 335, 334, 333, 332, 331, 330, 329, 328, 327, 326, 325, 324, 323, - 322, 321, 320, 319, 316, 315, 314, 313, 312, 311, - 310, 309, 308, 307, 306, 305, 304, 303, 300, 299, - 292, 291, 290, 289, 288, 287, 286, 285, 284, 283, - 282, 281, 280, 279, 278, 275, 274, 273, 269, 268, - 267, 266, 265, 264, 263, 262, 261, 260, 259, 258, - 255, 254, 253, 249, 248, 247, 244, 243, 242, 239, - 238, 237, 236, 232, 231, 228, 226, 155, 154, 213, - 212, 208, 207, 206, 195, 191, 187, 186, 185, 179, - 178, 138, 138, 156, 154, 155, 154, 138, 139, 138, - - 572, 100, 55, 55, 53, 33, 572, 572, 572, 572, - 572, 572, 572, 572, 572, 572, 572, 572, 572, 572, - 572, 572, 572, 572, 572, 572, 572, 572, 572, 572, - 572, 572, 572, 572, 572, 572, 572, 572, 572, 572, - 572, 572, 572, 572, 572, 572, 572, 572, 572, 572, - 572, 572, 572, 572, 572, 572, 572, 572, 572, 572, - 572, 572, 572, 572 + 320, 319, 318, 274, 204, 267, 264, 261, 258, 314, + 313, 312, 311, 310, 309, 308, 307, 306, 305, 304, + 303, 300, 299, 298, 294, 293, 292, 289, 288, 287, + + 284, 283, 282, 281, 277, 276, 211, 204, 272, 199, + 269, 185, 184, 161, 249, 248, 244, 243, 242, 231, + 227, 223, 222, 221, 215, 214, 157, 125, 157, 125, + 207, 201, 197, 186, 184, 185, 184, 157, 125, 182, + 181, 176, 160, 159, 158, 157, 125, 599, 117, 55, + 33, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599 } ; -static const flex_int16_t yy_chk[1065] = +static const flex_int16_t yy_chk[1424] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 5, 6, - 7, 5, 6, 8, 9, 9, 7, 9, 17, 8, - 47, 17, 13, 9, 17, 13, 9, 13, 13, 17, - 9, 21, 47, 13, 5, 6, 7, 11, 21, 8, - 9, 10, 10, 597, 10, 11, 10, 11, 12, 14, - - 10, 23, 14, 10, 14, 14, 12, 10, 12, 22, - 14, 24, 234, 5, 6, 7, 22, 10, 8, 15, - 234, 71, 15, 16, 15, 15, 16, 23, 16, 16, - 15, 71, 18, 11, 16, 18, 15, 24, 18, 596, - 16, 595, 19, 18, 12, 19, 20, 19, 19, 20, - 27, 20, 20, 19, 28, 25, 27, 20, 25, 19, - 28, 26, 43, 20, 26, 80, 43, 45, 45, 45, - 66, 15, 80, 15, 66, 16, 27, 16, 79, 594, - 28, 25, 79, 31, 31, 593, 31, 26, 87, 87, - 123, 87, 31, 592, 19, 31, 19, 79, 20, 123, - - 20, 29, 29, 29, 29, 29, 29, 29, 29, 29, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 3, 4, 44, 46, 46, 46, 44, 3, + 4, 5, 49, 5, 5, 5, 80, 7, 5, 7, + 80, 8, 7, 8, 49, 7, 8, 68, 68, 8, + + 9, 9, 9, 9, 9, 221, 10, 10, 10, 10, + 10, 9, 5, 10, 9, 11, 221, 10, 9, 597, + 10, 85, 12, 11, 10, 11, 65, 65, 65, 9, + 12, 85, 12, 164, 164, 10, 67, 67, 67, 250, + 250, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 6, 92, 6, 6, 6, 92, 13, + 6, 13, 596, 14, 13, 14, 13, 13, 14, 98, + 14, 14, 13, 11, 92, 595, 14, 70, 70, 70, + 12, 17, 93, 17, 6, 98, 17, 114, 13, 17, + 93, 114, 14, 295, 17, 131, 18, 21, 18, 21, + + 295, 18, 21, 122, 18, 131, 21, 122, 141, 18, + 17, 140, 141, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 18, 21, 140, 13, 132, + 140, 542, 14, 15, 132, 15, 542, 184, 15, 132, + 15, 15, 594, 23, 142, 23, 15, 184, 23, 22, + 17, 22, 15, 142, 22, 24, 297, 24, 22, 297, + 24, 593, 15, 216, 94, 18, 21, 216, 25, 26, + 25, 26, 23, 25, 26, 27, 94, 27, 22, 216, + 27, 233, 296, 27, 24, 233, 94, 136, 15, 296, + 15, 136, 591, 225, 45, 45, 45, 25, 26, 267, + + 136, 138, 15, 16, 27, 16, 590, 45, 16, 225, + 16, 16, 23, 300, 138, 267, 16, 261, 22, 138, + 279, 28, 16, 28, 24, 261, 28, 589, 279, 28, + 300, 588, 16, 45, 153, 153, 153, 25, 26, 101, + 101, 101, 101, 101, 27, 31, 31, 31, 31, 31, + 28, 128, 128, 128, 128, 128, 31, 264, 16, 31, + 16, 587, 584, 32, 32, 32, 32, 32, 583, 264, + 32, 582, 16, 19, 32, 19, 581, 32, 19, 264, + 19, 19, 143, 176, 176, 176, 19, 177, 177, 177, + 28, 143, 19, 105, 105, 105, 105, 105, 579, 578, + + 143, 577, 19, 178, 178, 178, 229, 128, 179, 179, + 179, 180, 180, 180, 154, 154, 154, 181, 181, 181, + 254, 254, 254, 105, 154, 576, 229, 258, 19, 337, + 19, 258, 154, 154, 154, 154, 154, 154, 574, 229, + 350, 371, 19, 20, 573, 20, 570, 258, 20, 337, + 20, 20, 255, 255, 255, 569, 20, 165, 165, 165, + 350, 371, 20, 172, 172, 172, 274, 165, 256, 256, + 256, 568, 20, 172, 565, 165, 165, 165, 165, 165, + 165, 172, 172, 172, 172, 172, 172, 174, 174, 174, + 189, 189, 189, 189, 189, 274, 561, 174, 20, 560, + + 20, 402, 402, 402, 553, 174, 174, 174, 174, 174, + 174, 552, 20, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, - 29, 29, 29, 29, 29, 29, 29, 29, 29, 32, - 32, 81, 32, 85, 32, 591, 90, 90, 32, 90, - 97, 32, 38, 81, 97, 104, 112, 38, 85, 104, - 122, 117, 81, 590, 122, 117, 112, 38, 38, 38, - 38, 38, 589, 90, 117, 38, 38, 38, 38, 38, - - 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - 42, 109, 109, 42, 109, 119, 42, 44, 44, 44, - 49, 42, 42, 49, 121, 113, 49, 42, 119, 44, - 113, 154, 42, 119, 292, 113, 124, 49, 42, 42, - 121, 154, 49, 121, 570, 124, 142, 142, 49, 49, - 134, 134, 134, 292, 124, 44, 159, 159, 197, 159, - 161, 161, 197, 161, 109, 164, 164, 42, 164, 166, - 166, 230, 166, 167, 167, 569, 167, 49, 59, 170, - 170, 59, 170, 172, 172, 568, 172, 59, 59, 176, - - 176, 185, 176, 225, 189, 59, 180, 230, 59, 193, - 180, 59, 185, 567, 59, 59, 214, 214, 225, 59, - 189, 566, 180, 563, 218, 218, 59, 218, 193, 562, - 59, 221, 59, 59, 59, 59, 129, 561, 221, 129, - 219, 193, 129, 252, 219, 560, 252, 129, 129, 250, - 223, 255, 176, 129, 220, 220, 250, 220, 129, 219, - 222, 222, 223, 222, 129, 129, 224, 224, 255, 224, - 559, 223, 226, 226, 558, 226, 227, 227, 305, 227, - 228, 228, 251, 228, 229, 229, 326, 229, 329, 251, - 355, 367, 557, 129, 135, 135, 135, 305, 358, 358, - - 358, 486, 554, 135, 486, 326, 395, 329, 553, 355, - 367, 135, 135, 135, 135, 135, 135, 383, 383, 383, - 383, 394, 498, 394, 499, 395, 417, 417, 417, 417, - 552, 551, 550, 394, 394, 394, 383, 511, 511, 511, - 511, 498, 530, 499, 531, 417, 515, 515, 515, 515, - 528, 528, 528, 528, 548, 547, 511, 533, 533, 533, - 533, 530, 546, 531, 545, 515, 544, 542, 541, 528, - 534, 534, 534, 534, 540, 537, 533, 543, 543, 543, - 543, 573, 573, 573, 573, 573, 573, 573, 573, 573, - 573, 573, 574, 574, 574, 574, 574, 574, 574, 574, - - 574, 574, 574, 575, 575, 575, 575, 575, 575, 575, - 575, 575, 575, 575, 576, 576, 576, 576, 576, 576, - 576, 576, 576, 576, 576, 577, 577, 577, 577, 577, - 577, 577, 577, 577, 577, 577, 578, 536, 535, 532, - 578, 578, 527, 526, 518, 517, 578, 579, 516, 514, - 513, 579, 579, 579, 512, 579, 510, 579, 580, 580, - 509, 580, 581, 581, 581, 581, 581, 581, 581, 581, - 581, 581, 581, 582, 582, 582, 582, 582, 582, 582, - 508, 582, 582, 582, 583, 583, 583, 583, 583, 583, - 583, 583, 583, 584, 507, 506, 584, 584, 505, 504, - - 584, 503, 584, 585, 585, 585, 501, 585, 586, 586, - 586, 500, 586, 587, 587, 497, 587, 587, 587, 587, - 587, 587, 587, 587, 588, 588, 588, 496, 588, 598, - 598, 494, 598, 598, 598, 598, 598, 598, 598, 598, - 493, 492, 491, 490, 488, 487, 485, 484, 483, 482, - 481, 480, 479, 478, 477, 476, 475, 472, 471, 470, - 469, 468, 465, 464, 463, 462, 461, 460, 459, 458, - 456, 455, 454, 453, 452, 449, 447, 446, 445, 444, - 442, 441, 440, 439, 438, 437, 436, 435, 434, 433, - 432, 431, 430, 427, 426, 425, 423, 422, 420, 419, - - 416, 415, 414, 413, 412, 411, 410, 409, 408, 407, - 406, 405, 404, 403, 402, 401, 400, 399, 398, 397, - 393, 392, 391, 390, 389, 388, 387, 386, 385, 384, - 382, 381, 380, 379, 378, 377, 376, 375, 374, 373, - 372, 371, 370, 369, 368, 366, 365, 364, 363, 362, - 357, 353, 351, 350, 349, 348, 347, 346, 344, 342, - 341, 340, 339, 338, 337, 336, 334, 333, 332, 331, - 330, 328, 327, 323, 322, 321, 319, 316, 314, 313, - 311, 309, 308, 307, 306, 304, 303, 302, 301, 300, - 299, 298, 297, 296, 295, 294, 293, 291, 290, 289, - - 287, 286, 285, 284, 283, 282, 281, 280, 279, 278, - 277, 276, 275, 273, 269, 268, 267, 266, 265, 264, - 263, 262, 261, 260, 259, 258, 257, 256, 254, 253, - 249, 248, 247, 246, 245, 244, 243, 242, 241, 240, - 239, 238, 237, 236, 235, 233, 232, 231, 213, 208, - 207, 206, 205, 204, 203, 202, 201, 200, 199, 198, - 196, 195, 194, 192, 191, 190, 188, 187, 186, 184, - 183, 182, 181, 179, 178, 171, 168, 155, 153, 138, - 136, 127, 126, 125, 120, 118, 116, 115, 114, 111, - 110, 105, 100, 77, 74, 72, 70, 69, 55, 53, - - 33, 30, 4, 3, 2, 572, 572, 572, 572, 572, - 572, 572, 572, 572, 572, 572, 572, 572, 572, 572, - 572, 572, 572, 572, 572, 572, 572, 572, 572, 572, - 572, 572, 572, 572, 572, 572, 572, 572, 572, 572, - 572, 572, 572, 572, 572, 572, 572, 572, 572, 572, - 572, 572, 572, 572, 572, 572, 572, 572, 572, 572, - 572, 572, 572, 572 + 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, + 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, + 29, 29, 29, 29, 29, 39, 374, 399, 411, 551, + 39, 191, 191, 191, 191, 191, 523, 549, 523, 548, + + 39, 523, 39, 39, 39, 39, 374, 399, 411, 39, + 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, + 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, + 39, 39, 39, 39, 43, 194, 194, 194, 194, 194, + 43, 436, 43, 436, 436, 546, 545, 43, 43, 544, + 43, 43, 43, 43, 543, 436, 436, 436, 43, 43, + 43, 43, 43, 43, 541, 43, 43, 43, 43, 43, + 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, + 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, + 43, 437, 540, 539, 43, 43, 43, 43, 43, 43, + + 43, 43, 43, 43, 43, 43, 64, 534, 535, 64, + 537, 437, 64, 196, 196, 196, 196, 196, 64, 64, + 198, 198, 198, 198, 198, 536, 64, 534, 535, 564, + 64, 533, 532, 64, 530, 529, 64, 64, 528, 527, + 525, 64, 203, 203, 203, 203, 203, 524, 64, 564, + 522, 521, 64, 520, 64, 64, 64, 64, 206, 206, + 206, 206, 206, 211, 211, 211, 211, 211, 251, 251, + 251, 519, 518, 517, 252, 252, 252, 516, 251, 257, + 257, 257, 257, 257, 252, 515, 251, 251, 251, 251, + 251, 251, 252, 252, 252, 252, 252, 252, 514, 513, + + 510, 509, 253, 253, 253, 260, 260, 260, 260, 260, + 508, 507, 253, 263, 263, 263, 263, 263, 504, 211, + 253, 253, 253, 253, 253, 253, 266, 266, 266, 266, + 266, 269, 269, 269, 269, 269, 270, 270, 270, 270, + 270, 272, 272, 272, 272, 272, 273, 273, 273, 273, + 273, 316, 316, 316, 503, 502, 501, 317, 317, 317, + 500, 316, 567, 567, 567, 567, 567, 317, 499, 316, + 316, 316, 316, 316, 316, 317, 317, 317, 317, 317, + 317, 362, 362, 362, 498, 497, 495, 363, 363, 363, + 494, 362, 575, 575, 575, 575, 575, 363, 493, 362, + + 362, 362, 362, 362, 362, 363, 363, 363, 363, 363, + 363, 403, 403, 403, 426, 426, 426, 426, 426, 492, + 489, 403, 458, 458, 458, 458, 458, 487, 486, 403, + 403, 403, 403, 403, 403, 426, 547, 547, 547, 547, + 547, 485, 484, 458, 550, 550, 550, 550, 550, 562, + 562, 562, 562, 562, 482, 481, 480, 547, 566, 566, + 566, 566, 566, 479, 478, 550, 477, 476, 475, 474, + 562, 473, 472, 471, 470, 467, 466, 465, 463, 566, + 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, + 600, 600, 601, 601, 601, 601, 601, 601, 601, 601, + + 601, 601, 601, 601, 602, 602, 602, 602, 602, 602, + 602, 602, 602, 602, 602, 602, 603, 603, 603, 603, + 603, 603, 603, 603, 603, 603, 603, 603, 604, 604, + 604, 604, 604, 604, 604, 604, 604, 604, 604, 604, + 605, 461, 460, 457, 605, 605, 456, 605, 455, 454, + 453, 605, 606, 606, 607, 607, 607, 608, 608, 608, + 608, 608, 608, 608, 608, 608, 608, 608, 608, 609, + 609, 609, 609, 609, 609, 610, 610, 610, 610, 610, + 610, 610, 610, 610, 452, 610, 610, 611, 611, 611, + 611, 611, 611, 611, 611, 611, 611, 612, 451, 450, + + 612, 612, 449, 448, 612, 612, 612, 612, 613, 613, + 613, 614, 614, 614, 615, 615, 447, 615, 615, 615, + 615, 615, 615, 615, 615, 615, 616, 616, 616, 617, + 617, 446, 617, 617, 617, 617, 617, 617, 617, 617, + 617, 445, 444, 443, 442, 441, 440, 439, 435, 434, + 433, 432, 431, 430, 429, 428, 427, 425, 424, 423, + 422, 421, 420, 419, 418, 417, 416, 415, 414, 413, + 412, 410, 409, 408, 407, 406, 401, 397, 395, 394, + 393, 392, 391, 389, 387, 386, 385, 384, 383, 382, + 381, 379, 378, 377, 376, 375, 373, 372, 368, 367, + + 366, 364, 361, 359, 358, 356, 354, 353, 352, 351, + 349, 348, 347, 346, 345, 344, 343, 342, 341, 340, + 339, 338, 336, 335, 334, 332, 331, 330, 329, 328, + 327, 326, 325, 324, 323, 322, 321, 320, 318, 314, + 313, 312, 311, 310, 309, 308, 307, 306, 305, 304, + 303, 302, 301, 299, 298, 294, 293, 292, 291, 290, + 289, 288, 287, 286, 285, 284, 283, 282, 281, 280, + 278, 277, 276, 275, 271, 268, 265, 262, 259, 249, + 244, 243, 242, 241, 240, 239, 238, 237, 236, 235, + 234, 232, 231, 230, 228, 227, 226, 224, 223, 222, + + 220, 219, 218, 217, 215, 214, 212, 205, 204, 200, + 199, 185, 183, 162, 157, 155, 146, 145, 144, 139, + 137, 135, 134, 133, 130, 129, 123, 120, 117, 111, + 107, 103, 100, 90, 88, 86, 84, 83, 78, 74, + 71, 66, 62, 58, 57, 55, 37, 33, 30, 2, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599, 599, 599, 599, 599, 599, 599, 599, + 599, 599, 599 } ; static yy_state_type yy_last_accepting_state; @@ -1197,22 +1286,22 @@ static char *yy_last_accepting_cpos; extern int yy_flex_debug; int yy_flex_debug = 1; -static const flex_int16_t yy_rule_linenum[129] = +static const flex_int16_t yy_rule_linenum[127] = { 0, - 190, 193, 194, 195, 203, 221, 222, 223, 224, 225, - 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, - 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, - 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, - 256, 257, 258, 259, 260, 261, 262, 263, 267, 271, - 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, - 285, 289, 290, 291, 293, 300, 301, 305, 310, 313, - 316, 319, 327, 334, 335, 336, 342, 349, 356, 376, - 386, 401, 406, 425, 438, 454, 469, 486, 487, 498, - 509, 510, 522, 531, 541, 560, 572, 586, 587, 598, - - 608, 618, 619, 620, 621, 622, 623, 624, 627, 629, - 637, 655, 660, 661, 667, 668, 679, 685, 691, 697, - 713, 714, 718, 725, 741, 761, 792, 793 + 198, 201, 202, 203, 209, 227, 228, 229, 230, 231, + 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, + 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, + 262, 263, 264, 265, 266, 267, 271, 275, 279, 282, + 283, 284, 285, 286, 287, 288, 289, 290, 292, 296, + 297, 298, 299, 301, 308, 309, 313, 318, 321, 324, + 327, 335, 342, 343, 344, 350, 357, 364, 384, 394, + 409, 415, 434, 447, 463, 478, 495, 496, 507, 518, + 519, 531, 540, 550, 569, 581, 595, 596, 607, 617, + + 627, 628, 629, 630, 631, 632, 633, 636, 638, 646, + 664, 669, 670, 676, 677, 688, 694, 700, 706, 722, + 723, 727, 734, 750, 770, 809 } ; /* The intent behind this definition is that it'll catch @@ -1226,7 +1315,7 @@ char *yytext; #line 1 "/Users/akim/src/gnu/bison/src/scan-gram.l" /* Bison Grammar Scanner -*- C -*- - Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc. + Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -1244,6 +1333,8 @@ char *yytext; along with this program. If not, see . */ #define YY_NO_INPUT 1 #line 24 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#include + #include #include #include @@ -1272,9 +1363,6 @@ static boundary scanner_cursor; #define YY_USER_ACTION location_compute (loc, &scanner_cursor, yytext, yyleng); -static size_t no_cr_read (FILE *, char *, size_t); -#define YY_INPUT(buf, result, size) ((result) = no_cr_read (yyin, buf, size)) - /* Report that yytext is an extension, and evaluate to its token type. */ #define BISON_DIRECTIVE(Directive) \ (bison_directive (loc, yytext), PERCENT_ ## Directive) @@ -1294,6 +1382,7 @@ static size_t no_cr_read (FILE *, char *, size_t); #define ROLLBACK_CURRENT_TOKEN \ do { \ scanner_cursor.column -= mbsnwidth (yytext, yyleng, 0); \ + scanner_cursor.byte -= yyleng; \ yyless (0); \ } while (0) @@ -1301,10 +1390,14 @@ static size_t no_cr_read (FILE *, char *, size_t); do { \ deprecated_directive (loc, yytext, Msg); \ scanner_cursor.column -= mbsnwidth (Msg, strlen (Msg), 0); \ + scanner_cursor.byte -= strlen (Msg); \ for (size_t i = strlen (Msg); i != 0; --i) \ unput (Msg[i - 1]); \ } while (0) +/* The current file name. Might change with #line. */ +static uniqstr current_file = NULL; + /* A string representing the most recently saved token. */ static char *last_string = NULL; @@ -1321,13 +1414,13 @@ gram_scanner_last_string_free (void) } static void handle_syncline (char *, location); -static unsigned long scan_integer (char const *p, int base, location loc); +static int scan_integer (char const *p, int base, location loc); static int convert_ucn_to_byte (char const *hex_text); static void unexpected_eof (boundary, char const *); static void unexpected_newline (boundary, char const *); -#line 1329 "src/scan-gram.c" -#line 108 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 1422 "src/scan-gram.c" +#line 112 "/Users/akim/src/gnu/bison/src/scan-gram.l" /* A C-like comment in directives/rules. */ /* Strings and characters in directives/rules. */ @@ -1353,11 +1446,12 @@ static void unexpected_newline (boundary, char const *); /* Bracketed identifiers support. */ + /* UTF-8 Encoded Unicode Code Point, from Flex's documentation. */ /* Zero or more instances of backslash-newline. Following GCC, allow white space between the backslash and the newline. */ /* An equal sign, with optional leading whitespaces. This is used in some deprecated constructs. */ -#line 1360 "src/scan-gram.c" +#line 1454 "src/scan-gram.c" #define INITIAL 0 #define SC_YACC_COMMENT 1 @@ -1655,7 +1749,7 @@ YY_DECL { /* %% [7.0] user's declarations go here */ -#line 151 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 159 "/Users/akim/src/gnu/bison/src/scan-gram.l" /* Nesting level. Either for nested braces, or nested angle brackets @@ -1666,7 +1760,7 @@ YY_DECL int context_state PACIFY_CC (= 0); /* Location of most recent identifier, when applicable. */ - location id_loc PACIFY_CC (= empty_location); + location id_loc PACIFY_CC (= empty_loc); /* Where containing code started, when applicable. Its initial value is relevant only when yylex is invoked in the SC_EPILOGUE @@ -1692,7 +1786,7 @@ YY_DECL | Scanning white space. | `-----------------------*/ -#line 1695 "src/scan-gram.c" +#line 1789 "src/scan-gram.c" while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { @@ -1722,13 +1816,13 @@ YY_DECL while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 573 ) + if ( yy_current_state >= 600 ) yy_c = yy_meta[yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; ++yy_cp; } - while ( yy_current_state != 572 ); + while ( yy_current_state != 599 ); yy_cp = (yy_last_accepting_cpos); yy_current_state = (yy_last_accepting_state); @@ -1747,13 +1841,13 @@ YY_DECL { if ( yy_act == 0 ) fprintf( stderr, "--scanner backing up\n" ); - else if ( yy_act < 129 ) + else if ( yy_act < 127 ) fprintf( stderr, "--accepting rule at line %ld (\"%s\")\n", (long)yy_rule_linenum[yy_act], yytext ); - else if ( yy_act == 129 ) + else if ( yy_act == 127 ) fprintf( stderr, "--accepting default rule (\"%s\")\n", yytext ); - else if ( yy_act == 130 ) + else if ( yy_act == 128 ) fprintf( stderr, "--(end of buffer or a NUL)\n" ); else fprintf( stderr, "--EOF (start condition %d)\n", YY_START ); @@ -1772,35 +1866,33 @@ YY_DECL /* Comments and white space. */ case 1: YY_RULE_SETUP -#line 190 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 198 "/Users/akim/src/gnu/bison/src/scan-gram.l" { complain (loc, Wother, _("stray ',' treated as white space")); } YY_BREAK case 2: /* rule 2 can match eol */ -#line 194 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 202 "/Users/akim/src/gnu/bison/src/scan-gram.l" case 3: /* rule 3 can match eol */ YY_RULE_SETUP -#line 194 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 202 "/Users/akim/src/gnu/bison/src/scan-gram.l" continue; YY_BREAK case 4: YY_RULE_SETUP -#line 195 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 203 "/Users/akim/src/gnu/bison/src/scan-gram.l" { token_start = loc->start; context_state = YY_START; BEGIN SC_YACC_COMMENT; } YY_BREAK -/* #line directives are not documented, and may be withdrawn or - modified in future versions of Bison. */ case 5: /* rule 5 can match eol */ YY_RULE_SETUP -#line 203 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 209 "/Users/akim/src/gnu/bison/src/scan-gram.l" { handle_syncline (yytext + sizeof "#line " - 1, *loc); } @@ -1818,312 +1910,309 @@ YY_RULE_SETUP case 6: YY_RULE_SETUP -#line 221 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 227 "/Users/akim/src/gnu/bison/src/scan-gram.l" return BISON_DIRECTIVE (NONASSOC); YY_BREAK case 7: YY_RULE_SETUP -#line 222 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 228 "/Users/akim/src/gnu/bison/src/scan-gram.l" return BISON_DIRECTIVE (CODE); YY_BREAK case 8: YY_RULE_SETUP -#line 223 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 229 "/Users/akim/src/gnu/bison/src/scan-gram.l" RETURN_PERCENT_FLAG ("parse.trace"); YY_BREAK case 9: YY_RULE_SETUP -#line 224 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 230 "/Users/akim/src/gnu/bison/src/scan-gram.l" return BISON_DIRECTIVE (DEFAULT_PREC); YY_BREAK case 10: YY_RULE_SETUP -#line 225 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 231 "/Users/akim/src/gnu/bison/src/scan-gram.l" return BISON_DIRECTIVE (DEFINE); YY_BREAK case 11: YY_RULE_SETUP -#line 226 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 232 "/Users/akim/src/gnu/bison/src/scan-gram.l" return BISON_DIRECTIVE (DEFINES); YY_BREAK case 12: YY_RULE_SETUP -#line 227 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 233 "/Users/akim/src/gnu/bison/src/scan-gram.l" return BISON_DIRECTIVE (DESTRUCTOR); YY_BREAK case 13: YY_RULE_SETUP -#line 228 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 234 "/Users/akim/src/gnu/bison/src/scan-gram.l" return BISON_DIRECTIVE (DPREC); YY_BREAK case 14: YY_RULE_SETUP -#line 229 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 235 "/Users/akim/src/gnu/bison/src/scan-gram.l" return BISON_DIRECTIVE (EMPTY); YY_BREAK case 15: YY_RULE_SETUP -#line 230 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 236 "/Users/akim/src/gnu/bison/src/scan-gram.l" return BISON_DIRECTIVE (EXPECT); YY_BREAK case 16: YY_RULE_SETUP -#line 231 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 237 "/Users/akim/src/gnu/bison/src/scan-gram.l" return BISON_DIRECTIVE (EXPECT_RR); YY_BREAK case 17: YY_RULE_SETUP -#line 232 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 238 "/Users/akim/src/gnu/bison/src/scan-gram.l" RETURN_VALUE (PERCENT_FILE_PREFIX, uniqstr_new (yytext)); YY_BREAK case 18: YY_RULE_SETUP -#line 233 "/Users/akim/src/gnu/bison/src/scan-gram.l" -RETURN_VALUE (PERCENT_YACC, uniqstr_new (yytext)); +#line 239 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return BISON_DIRECTIVE (INITIAL_ACTION); YY_BREAK case 19: YY_RULE_SETUP -#line 234 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return BISON_DIRECTIVE (INITIAL_ACTION); +#line 240 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return BISON_DIRECTIVE (GLR_PARSER); YY_BREAK case 20: YY_RULE_SETUP -#line 235 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return BISON_DIRECTIVE (GLR_PARSER); +#line 241 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return BISON_DIRECTIVE (LANGUAGE); YY_BREAK case 21: YY_RULE_SETUP -#line 236 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return BISON_DIRECTIVE (LANGUAGE); +#line 242 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return PERCENT_LEFT; YY_BREAK case 22: YY_RULE_SETUP -#line 237 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return PERCENT_LEFT; +#line 243 "/Users/akim/src/gnu/bison/src/scan-gram.l" +RETURN_PERCENT_PARAM (lex); YY_BREAK case 23: YY_RULE_SETUP -#line 238 "/Users/akim/src/gnu/bison/src/scan-gram.l" -RETURN_PERCENT_PARAM (lex); +#line 244 "/Users/akim/src/gnu/bison/src/scan-gram.l" +RETURN_PERCENT_FLAG ("locations"); YY_BREAK case 24: YY_RULE_SETUP -#line 239 "/Users/akim/src/gnu/bison/src/scan-gram.l" -RETURN_PERCENT_FLAG ("locations"); +#line 245 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return BISON_DIRECTIVE (MERGE); YY_BREAK case 25: YY_RULE_SETUP -#line 240 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return BISON_DIRECTIVE (MERGE); +#line 246 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return BISON_DIRECTIVE (NO_DEFAULT_PREC); YY_BREAK case 26: YY_RULE_SETUP -#line 241 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return BISON_DIRECTIVE (NO_DEFAULT_PREC); +#line 247 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return BISON_DIRECTIVE (NO_LINES); YY_BREAK case 27: YY_RULE_SETUP -#line 242 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return BISON_DIRECTIVE (NO_LINES); +#line 248 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return PERCENT_NONASSOC; YY_BREAK case 28: YY_RULE_SETUP -#line 243 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return PERCENT_NONASSOC; +#line 249 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return BISON_DIRECTIVE (NONDETERMINISTIC_PARSER); YY_BREAK case 29: YY_RULE_SETUP -#line 244 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return BISON_DIRECTIVE (NONDETERMINISTIC_PARSER); +#line 250 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return BISON_DIRECTIVE (NTERM); YY_BREAK case 30: YY_RULE_SETUP -#line 245 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return BISON_DIRECTIVE (NTERM); +#line 251 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return BISON_DIRECTIVE (OUTPUT); YY_BREAK case 31: YY_RULE_SETUP -#line 246 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return BISON_DIRECTIVE (OUTPUT); +#line 252 "/Users/akim/src/gnu/bison/src/scan-gram.l" +RETURN_PERCENT_PARAM (both); YY_BREAK case 32: YY_RULE_SETUP -#line 247 "/Users/akim/src/gnu/bison/src/scan-gram.l" -RETURN_PERCENT_PARAM (both); +#line 253 "/Users/akim/src/gnu/bison/src/scan-gram.l" +RETURN_PERCENT_PARAM (parse); YY_BREAK case 33: YY_RULE_SETUP -#line 248 "/Users/akim/src/gnu/bison/src/scan-gram.l" -RETURN_PERCENT_PARAM (parse); +#line 254 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return PERCENT_PREC; YY_BREAK case 34: YY_RULE_SETUP -#line 249 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return PERCENT_PREC; +#line 255 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return BISON_DIRECTIVE (PRECEDENCE); YY_BREAK case 35: YY_RULE_SETUP -#line 250 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return BISON_DIRECTIVE (PRECEDENCE); +#line 256 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return BISON_DIRECTIVE (PRINTER); YY_BREAK case 36: YY_RULE_SETUP -#line 251 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return BISON_DIRECTIVE (PRINTER); +#line 257 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return BISON_DIRECTIVE (REQUIRE); YY_BREAK case 37: YY_RULE_SETUP -#line 252 "/Users/akim/src/gnu/bison/src/scan-gram.l" -RETURN_PERCENT_FLAG ("api.pure"); +#line 258 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return PERCENT_RIGHT; YY_BREAK case 38: YY_RULE_SETUP -#line 253 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return BISON_DIRECTIVE (REQUIRE); +#line 259 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return BISON_DIRECTIVE (SKELETON); YY_BREAK case 39: YY_RULE_SETUP -#line 254 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return PERCENT_RIGHT; +#line 260 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return PERCENT_START; YY_BREAK case 40: YY_RULE_SETUP -#line 255 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return BISON_DIRECTIVE (SKELETON); +#line 261 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return BISON_DIRECTIVE (TOKEN); YY_BREAK case 41: YY_RULE_SETUP -#line 256 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return PERCENT_START; +#line 262 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return PERCENT_TOKEN; YY_BREAK case 42: YY_RULE_SETUP -#line 257 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return BISON_DIRECTIVE (TOKEN); +#line 263 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return BISON_DIRECTIVE (TOKEN_TABLE); YY_BREAK case 43: YY_RULE_SETUP -#line 258 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return PERCENT_TOKEN; +#line 264 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return PERCENT_TYPE; YY_BREAK case 44: YY_RULE_SETUP -#line 259 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return BISON_DIRECTIVE (TOKEN_TABLE); +#line 265 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return PERCENT_UNION; YY_BREAK case 45: YY_RULE_SETUP -#line 260 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return PERCENT_TYPE; +#line 266 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return BISON_DIRECTIVE (VERBOSE); YY_BREAK case 46: YY_RULE_SETUP -#line 261 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return PERCENT_UNION; +#line 267 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return PERCENT_YACC; YY_BREAK +/* Deprecated since Bison 2.3b (2008-05-27), but the warning is + issued only since Bison 3.4. */ case 47: YY_RULE_SETUP -#line 262 "/Users/akim/src/gnu/bison/src/scan-gram.l" -return BISON_DIRECTIVE (VERBOSE); - YY_BREAK -case 48: -YY_RULE_SETUP -#line 263 "/Users/akim/src/gnu/bison/src/scan-gram.l" -RETURN_VALUE (PERCENT_YACC, uniqstr_new (yytext)); +#line 271 "/Users/akim/src/gnu/bison/src/scan-gram.l" +RETURN_VALUE (PERCENT_PURE_PARSER, uniqstr_new (yytext)); YY_BREAK /* Deprecated since Bison 3.0 (2013-07-25), but the warning is issued only since Bison 3.3. */ -case 49: +case 48: YY_RULE_SETUP -#line 267 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 275 "/Users/akim/src/gnu/bison/src/scan-gram.l" RETURN_VALUE (PERCENT_ERROR_VERBOSE, uniqstr_new (yytext)); YY_BREAK /* Deprecated since Bison 2.6 (2012-07-19), but the warning is issued only since Bison 3.3. */ -case 50: -/* rule 50 can match eol */ +case 49: +/* rule 49 can match eol */ YY_RULE_SETUP -#line 271 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 279 "/Users/akim/src/gnu/bison/src/scan-gram.l" RETURN_VALUE (PERCENT_NAME_PREFIX, uniqstr_new (yytext)); YY_BREAK /* Deprecated since Bison 2.7.90, 2012. */ -case 51: +case 50: YY_RULE_SETUP -#line 274 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 282 "/Users/akim/src/gnu/bison/src/scan-gram.l" DEPRECATED ("%default-prec"); YY_BREAK -case 52: +case 51: YY_RULE_SETUP -#line 275 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 283 "/Users/akim/src/gnu/bison/src/scan-gram.l" RETURN_VALUE (PERCENT_ERROR_VERBOSE, uniqstr_new (yytext)); YY_BREAK -case 53: +case 52: YY_RULE_SETUP -#line 276 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 284 "/Users/akim/src/gnu/bison/src/scan-gram.l" DEPRECATED ("%expect-rr"); YY_BREAK -case 54: -/* rule 54 can match eol */ +case 53: +/* rule 53 can match eol */ YY_RULE_SETUP -#line 277 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 285 "/Users/akim/src/gnu/bison/src/scan-gram.l" RETURN_VALUE (PERCENT_FILE_PREFIX, uniqstr_new (yytext)); YY_BREAK -case 55: +case 54: YY_RULE_SETUP -#line 278 "/Users/akim/src/gnu/bison/src/scan-gram.l" -RETURN_VALUE (PERCENT_YACC, uniqstr_new (yytext)); +#line 286 "/Users/akim/src/gnu/bison/src/scan-gram.l" +DEPRECATED ("%output \"y.tab.c\""); YY_BREAK -case 56: +case 55: YY_RULE_SETUP -#line 279 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 287 "/Users/akim/src/gnu/bison/src/scan-gram.l" DEPRECATED ("%no-default-prec"); YY_BREAK -case 57: +case 56: YY_RULE_SETUP -#line 280 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 288 "/Users/akim/src/gnu/bison/src/scan-gram.l" DEPRECATED ("%no-lines"); YY_BREAK -case 58: -/* rule 58 can match eol */ +case 57: +/* rule 57 can match eol */ YY_RULE_SETUP -#line 281 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 289 "/Users/akim/src/gnu/bison/src/scan-gram.l" DEPRECATED ("%output"); YY_BREAK -case 59: -YY_RULE_SETUP -#line 282 "/Users/akim/src/gnu/bison/src/scan-gram.l" -DEPRECATED ("%pure-parser"); - YY_BREAK -case 60: +case 58: YY_RULE_SETUP -#line 283 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 290 "/Users/akim/src/gnu/bison/src/scan-gram.l" DEPRECATED ("%token-table"); YY_BREAK -case 61: +case 59: YY_RULE_SETUP -#line 285 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 292 "/Users/akim/src/gnu/bison/src/scan-gram.l" { complain (loc, complaint, _("invalid directive: %s"), quote (yytext)); } YY_BREAK -case 62: +case 60: YY_RULE_SETUP -#line 289 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 296 "/Users/akim/src/gnu/bison/src/scan-gram.l" +return COLON; + YY_BREAK +case 61: +YY_RULE_SETUP +#line 297 "/Users/akim/src/gnu/bison/src/scan-gram.l" return EQUAL; YY_BREAK -case 63: +case 62: YY_RULE_SETUP -#line 290 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 298 "/Users/akim/src/gnu/bison/src/scan-gram.l" return PIPE; YY_BREAK -case 64: +case 63: YY_RULE_SETUP -#line 291 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 299 "/Users/akim/src/gnu/bison/src/scan-gram.l" return SEMICOLON; YY_BREAK -case 65: +case 64: YY_RULE_SETUP -#line 293 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 301 "/Users/akim/src/gnu/bison/src/scan-gram.l" { val->ID = uniqstr_new (yytext); id_loc = *loc; @@ -2131,47 +2220,47 @@ YY_RULE_SETUP BEGIN SC_AFTER_IDENTIFIER; } YY_BREAK -case 66: +case 65: YY_RULE_SETUP -#line 300 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 308 "/Users/akim/src/gnu/bison/src/scan-gram.l" RETURN_VALUE (INT, scan_integer (yytext, 10, *loc)); YY_BREAK -case 67: +case 66: YY_RULE_SETUP -#line 301 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 309 "/Users/akim/src/gnu/bison/src/scan-gram.l" RETURN_VALUE (INT, scan_integer (yytext, 16, *loc)); YY_BREAK /* Identifiers may not start with a digit. Yet, don't silently accept "1FOO" as "1 FOO". */ -case 68: +case 67: YY_RULE_SETUP -#line 305 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 313 "/Users/akim/src/gnu/bison/src/scan-gram.l" { complain (loc, complaint, _("invalid identifier: %s"), quote (yytext)); } YY_BREAK /* Characters. */ -case 69: +case 68: YY_RULE_SETUP -#line 310 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 318 "/Users/akim/src/gnu/bison/src/scan-gram.l" token_start = loc->start; BEGIN SC_ESCAPED_CHARACTER; YY_BREAK /* Strings. */ -case 70: +case 69: YY_RULE_SETUP -#line 313 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 321 "/Users/akim/src/gnu/bison/src/scan-gram.l" token_start = loc->start; BEGIN SC_ESCAPED_STRING; YY_BREAK /* Prologue. */ -case 71: +case 70: YY_RULE_SETUP -#line 316 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 324 "/Users/akim/src/gnu/bison/src/scan-gram.l" code_start = loc->start; BEGIN SC_PROLOGUE; YY_BREAK /* Code in between braces. */ -case 72: +case 71: YY_RULE_SETUP -#line 319 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 327 "/Users/akim/src/gnu/bison/src/scan-gram.l" { STRING_GROW; nesting = 0; @@ -2180,10 +2269,10 @@ YY_RULE_SETUP } YY_BREAK /* Semantic predicate. */ -case 73: -/* rule 73 can match eol */ +case 72: +/* rule 72 can match eol */ YY_RULE_SETUP -#line 327 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 335 "/Users/akim/src/gnu/bison/src/scan-gram.l" { nesting = 0; code_start = loc->start; @@ -2191,28 +2280,28 @@ YY_RULE_SETUP } YY_BREAK /* A type. */ -case 74: +case 73: YY_RULE_SETUP -#line 334 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 342 "/Users/akim/src/gnu/bison/src/scan-gram.l" return TAG_ANY; YY_BREAK -case 75: +case 74: YY_RULE_SETUP -#line 335 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 343 "/Users/akim/src/gnu/bison/src/scan-gram.l" return TAG_NONE; YY_BREAK -case 76: +case 75: YY_RULE_SETUP -#line 336 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 344 "/Users/akim/src/gnu/bison/src/scan-gram.l" { nesting = 0; token_start = loc->start; BEGIN SC_TAG; } YY_BREAK -case 77: +case 76: YY_RULE_SETUP -#line 342 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 350 "/Users/akim/src/gnu/bison/src/scan-gram.l" { static int percent_percent_count; if (++percent_percent_count == 2) @@ -2220,9 +2309,9 @@ YY_RULE_SETUP return PERCENT_PERCENT; } YY_BREAK -case 78: +case 77: YY_RULE_SETUP -#line 349 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 357 "/Users/akim/src/gnu/bison/src/scan-gram.l" { bracketed_id_str = NULL; bracketed_id_start = loc->start; @@ -2230,9 +2319,9 @@ YY_RULE_SETUP BEGIN SC_BRACKETED_ID; } YY_BREAK -case 79: +case 78: YY_RULE_SETUP -#line 356 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 364 "/Users/akim/src/gnu/bison/src/scan-gram.l" { complain (loc, complaint, "%s: %s", ngettext ("invalid character", "invalid characters", yyleng), @@ -2240,7 +2329,7 @@ YY_RULE_SETUP } YY_BREAK case YY_STATE_EOF(INITIAL): -#line 362 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 370 "/Users/akim/src/gnu/bison/src/scan-gram.l" { loc->start = loc->end = scanner_cursor; yyterminate (); @@ -2253,9 +2342,9 @@ case YY_STATE_EOF(INITIAL): `--------------------------------------------------------------*/ -case 80: +case 79: YY_RULE_SETUP -#line 376 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 384 "/Users/akim/src/gnu/bison/src/scan-gram.l" complain (loc, complaint, _("invalid null character")); YY_BREAK @@ -2264,9 +2353,9 @@ complain (loc, complaint, _("invalid null character")); `-----------------------------------------------------------------*/ -case 81: +case 80: YY_RULE_SETUP -#line 386 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 394 "/Users/akim/src/gnu/bison/src/scan-gram.l" { if (bracketed_id_str) { @@ -2283,18 +2372,19 @@ YY_RULE_SETUP } } YY_BREAK -case 82: +case 81: YY_RULE_SETUP -#line 401 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 409 "/Users/akim/src/gnu/bison/src/scan-gram.l" { + ROLLBACK_CURRENT_TOKEN; BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL); *loc = id_loc; return ID_COLON; } YY_BREAK -case 83: +case 82: YY_RULE_SETUP -#line 406 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 415 "/Users/akim/src/gnu/bison/src/scan-gram.l" { ROLLBACK_CURRENT_TOKEN; BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL); @@ -2303,7 +2393,7 @@ YY_RULE_SETUP } YY_BREAK case YY_STATE_EOF(SC_AFTER_IDENTIFIER): -#line 412 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 421 "/Users/akim/src/gnu/bison/src/scan-gram.l" { BEGIN (bracketed_id_str ? SC_RETURN_BRACKETED_ID : INITIAL); *loc = id_loc; @@ -2316,9 +2406,9 @@ case YY_STATE_EOF(SC_AFTER_IDENTIFIER): `--------------------------------*/ -case 84: +case 83: YY_RULE_SETUP -#line 425 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 434 "/Users/akim/src/gnu/bison/src/scan-gram.l" { if (bracketed_id_str) { @@ -2333,9 +2423,9 @@ YY_RULE_SETUP } } YY_BREAK -case 85: +case 84: YY_RULE_SETUP -#line 438 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 447 "/Users/akim/src/gnu/bison/src/scan-gram.l" { BEGIN bracketed_id_context_state; if (bracketed_id_str) @@ -2352,9 +2442,9 @@ YY_RULE_SETUP complain (loc, complaint, _("an identifier expected")); } YY_BREAK -case 86: +case 85: YY_RULE_SETUP -#line 454 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 463 "/Users/akim/src/gnu/bison/src/scan-gram.l" { complain (loc, complaint, "%s: %s", ngettext ("invalid character in bracketed name", @@ -2363,7 +2453,7 @@ YY_RULE_SETUP } YY_BREAK case YY_STATE_EOF(SC_BRACKETED_ID): -#line 461 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 470 "/Users/akim/src/gnu/bison/src/scan-gram.l" { BEGIN bracketed_id_context_state; unexpected_eof (bracketed_id_start, "]"); @@ -2372,9 +2462,9 @@ case YY_STATE_EOF(SC_BRACKETED_ID): -case 87: +case 86: YY_RULE_SETUP -#line 469 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 478 "/Users/akim/src/gnu/bison/src/scan-gram.l" { ROLLBACK_CURRENT_TOKEN; val->BRACKETED_ID = bracketed_id_str; @@ -2390,19 +2480,19 @@ YY_RULE_SETUP `---------------------------------------------------------------*/ -case 88: +case 87: YY_RULE_SETUP -#line 486 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 495 "/Users/akim/src/gnu/bison/src/scan-gram.l" BEGIN context_state; YY_BREAK -case 89: -/* rule 89 can match eol */ +case 88: +/* rule 88 can match eol */ YY_RULE_SETUP -#line 487 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 496 "/Users/akim/src/gnu/bison/src/scan-gram.l" continue; YY_BREAK case YY_STATE_EOF(SC_YACC_COMMENT): -#line 488 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 497 "/Users/akim/src/gnu/bison/src/scan-gram.l" unexpected_eof (token_start, "*/"); BEGIN context_state; YY_BREAK @@ -2411,14 +2501,14 @@ unexpected_eof (token_start, "*/"); BEGIN context_state; `------------------------------------------------------------*/ -case 90: -/* rule 90 can match eol */ +case 89: +/* rule 89 can match eol */ YY_RULE_SETUP -#line 498 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 507 "/Users/akim/src/gnu/bison/src/scan-gram.l" STRING_GROW; BEGIN context_state; YY_BREAK case YY_STATE_EOF(SC_COMMENT): -#line 499 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 508 "/Users/akim/src/gnu/bison/src/scan-gram.l" unexpected_eof (token_start, "*/"); BEGIN context_state; YY_BREAK @@ -2427,20 +2517,20 @@ unexpected_eof (token_start, "*/"); BEGIN context_state; `--------------------------------------------------------------*/ -case 91: -/* rule 91 can match eol */ +case 90: +/* rule 90 can match eol */ YY_RULE_SETUP -#line 509 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 518 "/Users/akim/src/gnu/bison/src/scan-gram.l" STRING_GROW; BEGIN context_state; YY_BREAK -case 92: -/* rule 92 can match eol */ +case 91: +/* rule 91 can match eol */ YY_RULE_SETUP -#line 510 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 519 "/Users/akim/src/gnu/bison/src/scan-gram.l" STRING_GROW; YY_BREAK case YY_STATE_EOF(SC_LINE_COMMENT): -#line 511 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 520 "/Users/akim/src/gnu/bison/src/scan-gram.l" BEGIN context_state; YY_BREAK @@ -2450,9 +2540,9 @@ BEGIN context_state; `------------------------------------------------*/ -case 93: +case 92: YY_RULE_SETUP -#line 522 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 531 "/Users/akim/src/gnu/bison/src/scan-gram.l" { STRING_FINISH; BEGIN INITIAL; @@ -2463,13 +2553,13 @@ YY_RULE_SETUP } YY_BREAK case YY_STATE_EOF(SC_ESCAPED_STRING): -#line 530 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 539 "/Users/akim/src/gnu/bison/src/scan-gram.l" unexpected_eof (token_start, "\""); YY_BREAK -case 94: -/* rule 94 can match eol */ +case 93: +/* rule 93 can match eol */ YY_RULE_SETUP -#line 531 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 540 "/Users/akim/src/gnu/bison/src/scan-gram.l" unexpected_newline (token_start, "\""); YY_BREAK @@ -2479,9 +2569,9 @@ unexpected_newline (token_start, "\""); `----------------------------------------------------------*/ -case 95: +case 94: YY_RULE_SETUP -#line 541 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 550 "/Users/akim/src/gnu/bison/src/scan-gram.l" { STRING_FINISH; loc->start = token_start; @@ -2502,14 +2592,14 @@ YY_RULE_SETUP return CHAR; } YY_BREAK -case 96: -/* rule 96 can match eol */ +case 95: +/* rule 95 can match eol */ YY_RULE_SETUP -#line 560 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 569 "/Users/akim/src/gnu/bison/src/scan-gram.l" unexpected_newline (token_start, "'"); YY_BREAK case YY_STATE_EOF(SC_ESCAPED_CHARACTER): -#line 561 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 570 "/Users/akim/src/gnu/bison/src/scan-gram.l" unexpected_eof (token_start, "'"); YY_BREAK @@ -2518,9 +2608,9 @@ unexpected_eof (token_start, "'"); `--------------------------------------------------------------*/ -case 97: +case 96: YY_RULE_SETUP -#line 572 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 581 "/Users/akim/src/gnu/bison/src/scan-gram.l" { --nesting; if (nesting < 0) @@ -2535,19 +2625,19 @@ YY_RULE_SETUP STRING_GROW; } YY_BREAK -case 98: -/* rule 98 can match eol */ +case 97: +/* rule 97 can match eol */ YY_RULE_SETUP -#line 586 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 595 "/Users/akim/src/gnu/bison/src/scan-gram.l" STRING_GROW; YY_BREAK -case 99: +case 98: YY_RULE_SETUP -#line 587 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 596 "/Users/akim/src/gnu/bison/src/scan-gram.l" STRING_GROW; nesting += yyleng; YY_BREAK case YY_STATE_EOF(SC_TAG): -#line 589 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 598 "/Users/akim/src/gnu/bison/src/scan-gram.l" unexpected_eof (token_start, ">"); YY_BREAK @@ -2556,76 +2646,76 @@ unexpected_eof (token_start, ">"); `----------------------------*/ -case 100: +case 99: YY_RULE_SETUP -#line 598 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 607 "/Users/akim/src/gnu/bison/src/scan-gram.l" { verify (UCHAR_MAX < ULONG_MAX); - unsigned long c = strtoul (yytext + 1, NULL, 8); - if (!c || UCHAR_MAX < c) + long c = strtol (yytext + 1, NULL, 8); + if (0 < c && c <= UCHAR_MAX) + obstack_1grow (&obstack_for_string, c); + else complain (loc, complaint, _("invalid number after \\-escape: %s"), yytext+1); - else - obstack_1grow (&obstack_for_string, c); } YY_BREAK -case 101: +case 100: YY_RULE_SETUP -#line 608 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 617 "/Users/akim/src/gnu/bison/src/scan-gram.l" { verify (UCHAR_MAX < ULONG_MAX); - unsigned long c = strtoul (yytext + 2, NULL, 16); - if (!c || UCHAR_MAX < c) + long c = strtol (yytext + 2, NULL, 16); + if (0 < c && c <= UCHAR_MAX) + obstack_1grow (&obstack_for_string, c); + else complain (loc, complaint, _("invalid number after \\-escape: %s"), yytext+1); - else - obstack_1grow (&obstack_for_string, c); } YY_BREAK -case 102: +case 101: YY_RULE_SETUP -#line 618 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 627 "/Users/akim/src/gnu/bison/src/scan-gram.l" obstack_1grow (&obstack_for_string, '\a'); YY_BREAK -case 103: +case 102: YY_RULE_SETUP -#line 619 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 628 "/Users/akim/src/gnu/bison/src/scan-gram.l" obstack_1grow (&obstack_for_string, '\b'); YY_BREAK -case 104: +case 103: YY_RULE_SETUP -#line 620 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 629 "/Users/akim/src/gnu/bison/src/scan-gram.l" obstack_1grow (&obstack_for_string, '\f'); YY_BREAK -case 105: +case 104: YY_RULE_SETUP -#line 621 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 630 "/Users/akim/src/gnu/bison/src/scan-gram.l" obstack_1grow (&obstack_for_string, '\n'); YY_BREAK -case 106: +case 105: YY_RULE_SETUP -#line 622 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 631 "/Users/akim/src/gnu/bison/src/scan-gram.l" obstack_1grow (&obstack_for_string, '\r'); YY_BREAK -case 107: +case 106: YY_RULE_SETUP -#line 623 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 632 "/Users/akim/src/gnu/bison/src/scan-gram.l" obstack_1grow (&obstack_for_string, '\t'); YY_BREAK -case 108: +case 107: YY_RULE_SETUP -#line 624 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 633 "/Users/akim/src/gnu/bison/src/scan-gram.l" obstack_1grow (&obstack_for_string, '\v'); YY_BREAK /* \\[\"\'?\\] would be shorter, but it confuses xgettext. */ -case 109: +case 108: YY_RULE_SETUP -#line 627 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 636 "/Users/akim/src/gnu/bison/src/scan-gram.l" obstack_1grow (&obstack_for_string, yytext[1]); YY_BREAK -case 110: +case 109: YY_RULE_SETUP -#line 629 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 638 "/Users/akim/src/gnu/bison/src/scan-gram.l" { int c = convert_ucn_to_byte (yytext); if (c <= 0) @@ -2635,10 +2725,10 @@ YY_RULE_SETUP obstack_1grow (&obstack_for_string, c); } YY_BREAK -case 111: -/* rule 111 can match eol */ +case 110: +/* rule 110 can match eol */ YY_RULE_SETUP -#line 637 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 646 "/Users/akim/src/gnu/bison/src/scan-gram.l" { char const *p = yytext + 1; /* Quote only if escaping won't make the character visible. */ @@ -2656,46 +2746,46 @@ YY_RULE_SETUP `--------------------------------------------*/ -case 112: -/* rule 112 can match eol */ +case 111: +/* rule 111 can match eol */ YY_RULE_SETUP -#line 655 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 664 "/Users/akim/src/gnu/bison/src/scan-gram.l" STRING_GROW; YY_BREAK -case 113: +case 112: YY_RULE_SETUP -#line 660 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 669 "/Users/akim/src/gnu/bison/src/scan-gram.l" STRING_GROW; BEGIN context_state; YY_BREAK -case 114: -/* rule 114 can match eol */ +case 113: +/* rule 113 can match eol */ YY_RULE_SETUP -#line 661 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 670 "/Users/akim/src/gnu/bison/src/scan-gram.l" unexpected_newline (token_start, "'"); YY_BREAK case YY_STATE_EOF(SC_CHARACTER): -#line 662 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 671 "/Users/akim/src/gnu/bison/src/scan-gram.l" unexpected_eof (token_start, "'"); YY_BREAK -case 115: +case 114: YY_RULE_SETUP -#line 667 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 676 "/Users/akim/src/gnu/bison/src/scan-gram.l" STRING_GROW; BEGIN context_state; YY_BREAK -case 116: -/* rule 116 can match eol */ +case 115: +/* rule 115 can match eol */ YY_RULE_SETUP -#line 668 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 677 "/Users/akim/src/gnu/bison/src/scan-gram.l" unexpected_newline (token_start, "\""); YY_BREAK case YY_STATE_EOF(SC_STRING): -#line 669 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 678 "/Users/akim/src/gnu/bison/src/scan-gram.l" unexpected_eof (token_start, "\""); YY_BREAK @@ -2704,9 +2794,9 @@ unexpected_eof (token_start, "\""); `---------------------------------------------------*/ -case 117: +case 116: YY_RULE_SETUP -#line 679 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 688 "/Users/akim/src/gnu/bison/src/scan-gram.l" { STRING_GROW; context_state = YY_START; @@ -2714,9 +2804,9 @@ YY_RULE_SETUP BEGIN SC_CHARACTER; } YY_BREAK -case 118: +case 117: YY_RULE_SETUP -#line 685 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 694 "/Users/akim/src/gnu/bison/src/scan-gram.l" { STRING_GROW; context_state = YY_START; @@ -2724,10 +2814,10 @@ YY_RULE_SETUP BEGIN SC_STRING; } YY_BREAK -case 119: -/* rule 119 can match eol */ +case 118: +/* rule 118 can match eol */ YY_RULE_SETUP -#line 691 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 700 "/Users/akim/src/gnu/bison/src/scan-gram.l" { STRING_GROW; context_state = YY_START; @@ -2735,10 +2825,10 @@ YY_RULE_SETUP BEGIN SC_COMMENT; } YY_BREAK -case 120: -/* rule 120 can match eol */ +case 119: +/* rule 119 can match eol */ YY_RULE_SETUP -#line 697 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 706 "/Users/akim/src/gnu/bison/src/scan-gram.l" { STRING_GROW; context_state = YY_START; @@ -2752,37 +2842,37 @@ YY_RULE_SETUP `-----------------------------------------------------------*/ -case 121: -/* rule 121 can match eol */ +case 120: +/* rule 120 can match eol */ YY_RULE_SETUP -#line 713 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 722 "/Users/akim/src/gnu/bison/src/scan-gram.l" STRING_GROW; nesting++; YY_BREAK -case 122: -/* rule 122 can match eol */ +case 121: +/* rule 121 can match eol */ YY_RULE_SETUP -#line 714 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 723 "/Users/akim/src/gnu/bison/src/scan-gram.l" STRING_GROW; nesting--; YY_BREAK /* Tokenize '<<%' correctly (as '<<' '%') rather than incorrectly (as '<' '<%'). */ -case 123: -/* rule 123 can match eol */ +case 122: +/* rule 122 can match eol */ YY_RULE_SETUP -#line 718 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 727 "/Users/akim/src/gnu/bison/src/scan-gram.l" STRING_GROW; YY_BREAK case YY_STATE_EOF(SC_BRACED_CODE): case YY_STATE_EOF(SC_PREDICATE): -#line 720 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 729 "/Users/akim/src/gnu/bison/src/scan-gram.l" unexpected_eof (code_start, "}"); YY_BREAK -case 124: +case 123: YY_RULE_SETUP -#line 725 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 734 "/Users/akim/src/gnu/bison/src/scan-gram.l" { obstack_1grow (&obstack_for_string, '}'); @@ -2799,9 +2889,9 @@ YY_RULE_SETUP -case 125: +case 124: YY_RULE_SETUP -#line 741 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 750 "/Users/akim/src/gnu/bison/src/scan-gram.l" { --nesting; if (nesting < 0) @@ -2821,9 +2911,9 @@ YY_RULE_SETUP `--------------------------------------------------------------*/ -case 126: +case 125: YY_RULE_SETUP -#line 761 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 770 "/Users/akim/src/gnu/bison/src/scan-gram.l" { STRING_FINISH; loc->start = code_start; @@ -2832,7 +2922,7 @@ YY_RULE_SETUP } YY_BREAK case YY_STATE_EOF(SC_PROLOGUE): -#line 768 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 777 "/Users/akim/src/gnu/bison/src/scan-gram.l" unexpected_eof (code_start, "%}"); YY_BREAK @@ -2843,7 +2933,7 @@ unexpected_eof (code_start, "%}"); case YY_STATE_EOF(SC_EPILOGUE): -#line 779 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 788 "/Users/akim/src/gnu/bison/src/scan-gram.l" { STRING_FINISH; loc->start = code_start; @@ -2855,20 +2945,27 @@ case YY_STATE_EOF(SC_EPILOGUE): /*-----------------------------------------------------. | By default, grow the string obstack with the input. | `-----------------------------------------------------*/ -case 127: -#line 793 "/Users/akim/src/gnu/bison/src/scan-gram.l" -case 128: -/* rule 128 can match eol */ + + +/* Accept multibyte characters in one block instead of byte after + byte, so that add_column_width and mbsnwidth can compute correct + screen width. + + Add a fallthrough "|." so that non UTF-8 input is still accepted + and does not jam the scanner. */ +case 126: +/* rule 126 can match eol */ YY_RULE_SETUP -#line 793 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 809 "/Users/akim/src/gnu/bison/src/scan-gram.l" STRING_GROW; YY_BREAK -case 129: + +case 127: YY_RULE_SETUP -#line 795 "/Users/akim/src/gnu/bison/src/scan-gram.l" +#line 812 "/Users/akim/src/gnu/bison/src/scan-gram.l" YY_FATAL_ERROR( "flex scanner jammed" ); YY_BREAK -#line 2871 "src/scan-gram.c" +#line 2968 "src/scan-gram.c" case YY_STATE_EOF(SC_RETURN_BRACKETED_ID): yyterminate(); @@ -3181,7 +3278,7 @@ static int yy_get_next_buffer (void) for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) { /* %% [16.0] code to find the next state goes here */ - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 58); + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 72); if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; @@ -3190,7 +3287,7 @@ static int yy_get_next_buffer (void) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 573 ) + if ( yy_current_state >= 600 ) yy_c = yy_meta[yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; @@ -3214,7 +3311,7 @@ static int yy_get_next_buffer (void) /* %% [17.0] code to find the next state, and perhaps do backing up, goes here */ char *yy_cp = (yy_c_buf_p); - YY_CHAR yy_c = 58; + YY_CHAR yy_c = 72; if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; @@ -3223,11 +3320,11 @@ static int yy_get_next_buffer (void) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 573 ) + if ( yy_current_state >= 600 ) yy_c = yy_meta[yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - yy_is_jam = (yy_current_state == 572); + yy_is_jam = (yy_current_state == 599); return yy_is_jam ? 0 : yy_current_state; } @@ -4020,54 +4117,7 @@ void yyfree (void * ptr ) /* %ok-for-header */ -#line 795 "/Users/akim/src/gnu/bison/src/scan-gram.l" - - -/* Read bytes from FP into buffer BUF of size SIZE. Return the - number of bytes read. Remove '\r' from input, treating \r\n - and isolated \r as \n. */ - -static size_t -no_cr_read (FILE *fp, char *buf, size_t size) -{ - size_t bytes_read = fread (buf, 1, size, fp); - if (bytes_read) - { - char *w = memchr (buf, '\r', bytes_read); - if (w) - { - char const *r = ++w; - char const *lim = buf + bytes_read; - - for (;;) - { - /* Found an '\r'. Treat it like '\n', but ignore any - '\n' that immediately follows. */ - w[-1] = '\n'; - if (r == lim) - { - int ch = getc (fp); - if (ch != '\n' && ungetc (ch, fp) != ch) - break; - } - else if (*r == '\n') - r++; - - /* Copy until the next '\r'. */ - do - { - if (r == lim) - return w - buf; - } - while ((*w++ = *r++) != '\r'); - } - - return w - buf; - } - } - - return bytes_read; -} +#line 812 "/Users/akim/src/gnu/bison/src/scan-gram.l" @@ -4075,7 +4125,7 @@ no_cr_read (FILE *fp, char *buf, size_t size) | Scan NUMBER for a base-BASE integer at location LOC. | `------------------------------------------------------*/ -static unsigned long +static int scan_integer (char const *number, int base, location loc) { verify (INT_MAX < ULONG_MAX); @@ -4083,9 +4133,10 @@ scan_integer (char const *number, int base, location loc) complain (&loc, Wyacc, _("POSIX Yacc does not support hexadecimal literals")); - unsigned long num = strtoul (number, NULL, base); + errno = 0; + long num = strtol (number, NULL, base); - if (INT_MAX < num) + if (! (0 <= num && num <= INT_MAX && errno == 0)) { complain (&loc, complaint, _("integer out of range: %s"), quote (number)); @@ -4106,7 +4157,7 @@ static int convert_ucn_to_byte (char const *ucn) { verify (UCHAR_MAX <= INT_MAX); - unsigned long code = strtoul (ucn + 2, NULL, 16); + long code = strtol (ucn + 2, NULL, 16); /* FIXME: Currently we assume Unicode-compatible unibyte characters on ASCII hosts (i.e., Latin-1 on hosts with 8-bit bytes). On @@ -4114,7 +4165,7 @@ convert_ucn_to_byte (char const *ucn) These limitations should be removed once we add support for multibyte characters. */ - if (UCHAR_MAX < code) + if (! (0 <= code && code <= UCHAR_MAX)) return -1; #if ! ('$' == 0x24 && '@' == 0x40 && '`' == 0x60 && '~' == 0x7e) @@ -4161,8 +4212,9 @@ static void handle_syncline (char *args, location loc) { char *file; - unsigned long lineno = strtoul (args, &file, 10); - if (INT_MAX <= lineno) + errno = 0; + long lineno = strtol (args, &file, 10); + if (! (0 <= lineno && lineno <= INT_MAX && errno == 0)) { complain (&loc, Wother, _("line number overflow")); lineno = INT_MAX; @@ -4174,7 +4226,7 @@ handle_syncline (char *args, location loc) *strchr (file + 1, '"') = '\0'; current_file = uniqstr_new (file + 1); } - boundary_set (&scanner_cursor, current_file, lineno, 1); + boundary_set (&scanner_cursor, current_file, lineno, 1, 1); } @@ -4195,6 +4247,7 @@ unexpected_end (boundary start, char const *msgid, char const *token_end) /* Adjust scanner cursor so that any later message does not count the characters about to be inserted. */ scanner_cursor.column -= i; + scanner_cursor.byte -= i; while (i != 0) unput (token_end[--i]); @@ -4231,26 +4284,30 @@ unexpected_newline (boundary start, char const *token_end) } -/*-------------------------. -| Initialize the scanner. | -`-------------------------*/ - void -gram_scanner_initialize (void) +gram_scanner_open (const char *gram) { + gram__flex_debug = trace_flag & trace_scan; + gram_debug = trace_flag & trace_parse; obstack_init (&obstack_for_string); + current_file = gram; + gram_in = xfopen (gram, "r"); +} + + +void +gram_scanner_close () +{ + xfclose (gram_in); + /* Reclaim Flex's buffers. */ + yylex_destroy (); } -/*-----------------------------------------------. -| Free all the memory allocated to the scanner. | -`-----------------------------------------------*/ void gram_scanner_free (void) { obstack_free (&obstack_for_string, 0); - /* Reclaim Flex's buffers. */ - yylex_destroy (); } diff --git a/contrib/tools/bison/src/scan-gram.h b/contrib/tools/bison/src/scan-gram.h index f25d183f1e59..4483fa816a51 100644 --- a/contrib/tools/bison/src/scan-gram.h +++ b/contrib/tools/bison/src/scan-gram.h @@ -1,6 +1,6 @@ /* Bison Grammar Scanner - Copyright (C) 2006-2007, 2009-2015, 2018-2019 Free Software + Copyright (C) 2006-2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -21,18 +21,15 @@ #ifndef SCAN_GRAM_H_ # define SCAN_GRAM_H_ -/* From the scanner. */ -extern FILE *gram_in; -extern int gram__flex_debug; -void gram_scanner_initialize (void); +/* Initialize the scanner to read file GRAM. */ +void gram_scanner_open (const char *gram); +/* Close the open files. */ +void gram_scanner_close (void); + +/* Free all the memory allocated to the scanner. */ void gram_scanner_free (void); void gram_scanner_last_string_free (void); -/* These are declared by the scanner, but not used. We put them here - to pacify "make syntax-check". */ -extern FILE *gram_out; -extern int gram_lineno; - # define GRAM_LEX_DECL int gram_lex (GRAM_STYPE *val, location *loc) GRAM_LEX_DECL; diff --git a/contrib/tools/bison/src/scan-skel.h b/contrib/tools/bison/src/scan-skel.h index 20fa09da8e90..5a6b5f3f361b 100644 --- a/contrib/tools/bison/src/scan-skel.h +++ b/contrib/tools/bison/src/scan-skel.h @@ -1,6 +1,6 @@ /* Scan Bison Skeletons. - Copyright (C) 2005-2007, 2009-2015, 2018-2019 Free Software + Copyright (C) 2005-2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/src/state.c b/contrib/tools/bison/src/state.c index 0fc93206012f..356ccdf17fd6 100644 --- a/contrib/tools/bison/src/state.c +++ b/contrib/tools/bison/src/state.c @@ -1,6 +1,6 @@ /* Type definitions for the finite state machine for Bison. - Copyright (C) 2001-2007, 2009-2015, 2018-2019 Free Software + Copyright (C) 2001-2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -19,13 +19,16 @@ along with this program. If not, see . */ #include +#include "state.h" + #include "system.h" #include +#include "closure.h" #include "complain.h" +#include "getargs.h" #include "gram.h" -#include "state.h" #include "print-xml.h" @@ -39,31 +42,24 @@ `-----------------------------------------*/ static transitions * -transitions_new (int num, state **the_states) +transitions_new (int num, state **dst) { - size_t states_size = num * sizeof *the_states; + size_t states_size = num * sizeof *dst; transitions *res = xmalloc (offsetof (transitions, states) + states_size); res->num = num; - memcpy (res->states, the_states, states_size); + memcpy (res->states, dst, states_size); return res; } -/*-------------------------------------------------------. -| Return the state such that SHIFTS contain a shift/goto | -| to it on SYM. Abort if none found. | -`-------------------------------------------------------*/ - state * -transitions_to (transitions *shifts, symbol_number sym) +transitions_to (state *s, symbol_number sym) { - int j; - for (j = 0; ; j++) - { - aver (j < shifts->num); - if (TRANSITION_SYMBOL (shifts, j) == sym) - return shifts->states[j]; - } + transitions *trans = s->transitions; + for (int i = 0; i < trans->num; ++i) + if (TRANSITION_SYMBOL (trans, i) == sym) + return trans->states[i]; + abort (); } @@ -82,7 +78,8 @@ errs_new (int num, symbol **tokens) size_t symbols_size = num * sizeof *tokens; errs *res = xmalloc (offsetof (errs, symbols) + symbols_size); res->num = num; - memcpy (res->symbols, tokens, symbols_size); + if (tokens) + memcpy (res->symbols, tokens, symbols_size); return res; } @@ -131,12 +128,10 @@ state * state_new (symbol_number accessing_symbol, size_t nitems, item_number *core) { - state *res; - size_t items_size = nitems * sizeof *core; - aver (nstates < STATE_NUMBER_MAXIMUM); - res = xmalloc (offsetof (state, items) + items_size); + size_t items_size = nitems * sizeof *core; + state *res = xmalloc (offsetof (state, items) + items_size); res->number = nstates++; res->accessing_symbol = accessing_symbol; res->transitions = NULL; @@ -158,12 +153,10 @@ state_new (symbol_number accessing_symbol, state * state_new_isocore (state const *s) { - state *res; - size_t items_size = s->nitems * sizeof *s->items; - aver (nstates < STATE_NUMBER_MAXIMUM); - res = xmalloc (offsetof (state, items) + items_size); + size_t items_size = s->nitems * sizeof *s->items; + state *res = xmalloc (offsetof (state, items) + items_size); res->number = nstates++; res->accessing_symbol = s->accessing_symbol; res->transitions = @@ -196,15 +189,32 @@ state_free (state *s) } +void +state_transitions_print (const state *s, FILE *out) +{ + const transitions *trans = s->transitions; + fprintf (out, "transitions of %d (%d):\n", + s->number, trans->num); + for (int i = 0; i < trans->num; ++i) + fprintf (out, " %d: (%d, %s, %d)\n", + i, + s->number, + symbols[s->transitions->states[i]->accessing_symbol]->tag, + s->transitions->states[i]->number); +} + + /*---------------------------. | Set the transitions of S. | `---------------------------*/ void -state_transitions_set (state *s, int num, state **trans) +state_transitions_set (state *s, int num, state **dst) { aver (!s->transitions); - s->transitions = transitions_new (num, trans); + s->transitions = transitions_new (num, dst); + if (trace_flag & trace_automaton) + state_transitions_print (s, stderr); } @@ -221,14 +231,13 @@ state_reductions_set (state *s, int num, rule **reds) int -state_reduction_find (state *s, rule *r) +state_reduction_find (state *s, rule const *r) { - int i; reductions *reds = s->reductions; - for (i = 0; i < reds->num; ++i) + for (int i = 0; i < reds->num; ++i) if (reds->rules[i] == r) return i; - return -1; + abort (); } @@ -251,7 +260,7 @@ state_errs_set (state *s, int num, symbol **tokens) `--------------------------------------------------*/ void -state_rule_lookahead_tokens_print (state *s, rule *r, FILE *out) +state_rule_lookahead_tokens_print (state *s, rule const *r, FILE *out) { /* Find the reduction we are handling. */ reductions *reds = s->reductions; @@ -274,7 +283,7 @@ state_rule_lookahead_tokens_print (state *s, rule *r, FILE *out) } void -state_rule_lookahead_tokens_print_xml (state *s, rule *r, +state_rule_lookahead_tokens_print_xml (state *s, rule const *r, FILE *out, int level) { /* Find the reduction we are handling. */ @@ -310,12 +319,10 @@ static struct hash_table *state_table = NULL; static inline bool state_compare (state const *s1, state const *s2) { - size_t i; - if (s1->nitems != s2->nitems) return false; - for (i = 0; i < s1->nitems; ++i) + for (size_t i = 0; i < s1->nitems; ++i) if (s1->items[i] != s2->items[i]) return false; @@ -333,8 +340,7 @@ state_hash (state const *s, size_t tablesize) { /* Add up the state's item numbers to get a hash key. */ size_t key = 0; - size_t i; - for (i = 0; i < s->nitems; ++i) + for (size_t i = 0; i < s->nitems; ++i) key += s->items[i]; return key % tablesize; } @@ -353,11 +359,11 @@ state_hasher (void const *s, size_t tablesize) void state_hash_new (void) { - state_table = hash_initialize (HT_INITIAL_CAPACITY, - NULL, - state_hasher, - state_comparator, - NULL); + state_table = hash_xinitialize (HT_INITIAL_CAPACITY, + NULL, + state_hasher, + state_comparator, + NULL); } @@ -394,11 +400,9 @@ state_hash_lookup (size_t nitems, item_number *core) { size_t items_size = nitems * sizeof *core; state *probe = xmalloc (offsetof (state, items) + items_size); - state *entry; - probe->nitems = nitems; memcpy (probe->items, core, items_size); - entry = hash_lookup (state_table, probe); + state *entry = hash_lookup (state_table, probe); free (probe); return entry; } @@ -414,12 +418,9 @@ state_record_reachable_states (state *s, bitset reachable) if (bitset_test (reachable, s->number)) return; bitset_set (reachable, s->number); - { - int i; - for (i = 0; i < s->transitions->num; ++i) - if (!TRANSITION_IS_DISABLED (s->transitions, i)) - state_record_reachable_states (s->transitions->states[i], reachable); - } + for (int i = 0; i < s->transitions->num; ++i) + if (!TRANSITION_IS_DISABLED (s->transitions, i)) + state_record_reachable_states (s->transitions->states[i], reachable); } void @@ -428,23 +429,20 @@ state_remove_unreachable_states (state_number old_to_new[]) state_number nstates_reachable = 0; bitset reachable = bitset_create (nstates, BITSET_FIXED); state_record_reachable_states (states[0], reachable); - { - state_number i; - for (i = 0; i < nstates; ++i) - { - if (bitset_test (reachable, states[i]->number)) - { - states[nstates_reachable] = states[i]; - states[nstates_reachable]->number = nstates_reachable; - old_to_new[i] = nstates_reachable++; - } - else - { - state_free (states[i]); - old_to_new[i] = nstates; - } - } - } + for (state_number i = 0; i < nstates; ++i) + { + if (bitset_test (reachable, states[i]->number)) + { + states[nstates_reachable] = states[i]; + states[nstates_reachable]->number = nstates_reachable; + old_to_new[i] = nstates_reachable++; + } + else + { + state_free (states[i]); + old_to_new[i] = nstates; + } + } nstates = nstates_reachable; bitset_free (reachable); } @@ -460,8 +458,8 @@ state **states = NULL; void states_free (void) { - state_number i; - for (i = 0; i < nstates; ++i) + closure_free (); + for (state_number i = 0; i < nstates; ++i) state_free (states[i]); free (states); } diff --git a/contrib/tools/bison/src/state.h b/contrib/tools/bison/src/state.h index 5b37ed6a4790..8fd9088ab358 100644 --- a/contrib/tools/bison/src/state.h +++ b/contrib/tools/bison/src/state.h @@ -1,6 +1,6 @@ /* Type definitions for the finite state machine for Bison. - Copyright (C) 1984, 1989, 2000-2004, 2007, 2009-2015, 2018-2019 Free + Copyright (C) 1984, 1989, 2000-2004, 2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -51,11 +51,11 @@ lookahead token alone). When the states are generated, these actions are represented in two other lists. - Each transition structure describes the possible transitions out - of one state, the state whose number is in the number field. Each - contains a vector of numbers of the states that transitions can go - to. The accessing_symbol fields of those states' cores say what - kind of input leads to them. + Each transition structure describes the possible transitions out of + one state (there are NUM of them). Each contains a vector of + numbers of the states that transitions can go to. The + accessing_symbol fields of those states' cores say what kind of + input leads to them. A transition to state zero should be ignored: conflict resolution deletes transitions by having them point to zero. @@ -112,7 +112,7 @@ typedef struct state state; typedef struct { - int num; + int num; /** Size of destination STATES. */ state *states[1]; } transitions; @@ -159,9 +159,9 @@ typedef struct if (!TRANSITION_IS_DISABLED (Transitions, Iter)) -/* Return the state such SHIFTS contain a shift/goto to it on SYM. - Abort if none found. */ -struct state *transitions_to (transitions *shifts, symbol_number sym); +/* The destination of the transition (shift/goto) from state S on + label SYM (term or nterm). Abort if none found. */ +struct state *transitions_to (state *s, symbol_number sym); /*-------. @@ -233,21 +233,26 @@ state *state_new (symbol_number accessing_symbol, size_t core_size, item_number *core); state *state_new_isocore (state const *s); -/* Set the transitions of STATE. */ -void state_transitions_set (state *s, int num, state **trans); +/* Record that from S we can reach all the DST states (NUM of them). */ +void state_transitions_set (state *s, int num, state **dst); + +/* Print the transitions of state s for debug. */ +void state_transitions_print (const state *s, FILE *out); /* Set the reductions of STATE. */ void state_reductions_set (state *s, int num, rule **reds); -int state_reduction_find (state *s, rule *r); +/* The index of the reduction of state S that corresponds to rule R. + Aborts if there is no reduction of R in S. */ +int state_reduction_find (state *s, rule const *r); /* Set the errs of STATE. */ void state_errs_set (state *s, int num, symbol **errors); /* Print on OUT all the lookahead tokens such that this STATE wants to reduce R. */ -void state_rule_lookahead_tokens_print (state *s, rule *r, FILE *out); -void state_rule_lookahead_tokens_print_xml (state *s, rule *r, +void state_rule_lookahead_tokens_print (state *s, rule const *r, FILE *out); +void state_rule_lookahead_tokens_print_xml (state *s, rule const *r, FILE *out, int level); /* Create/destroy the states hash table. */ diff --git a/contrib/tools/bison/src/symlist.c b/contrib/tools/bison/src/symlist.c index c5947cc8903f..9bb0deaacbdb 100644 --- a/contrib/tools/bison/src/symlist.c +++ b/contrib/tools/bison/src/symlist.c @@ -1,6 +1,6 @@ /* Lists of symbols for Bison - Copyright (C) 2002, 2005-2007, 2009-2015, 2018-2019 Free Software + Copyright (C) 2002, 2005-2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -34,7 +34,7 @@ symbol_list_sym_new (symbol *sym, location loc) res->content_type = SYMLIST_SYMBOL; res->content.sym = sym; - res->location = res->sym_loc = loc; + res->sym_loc = loc; res->named_ref = NULL; res->midrule = NULL; @@ -42,13 +42,14 @@ symbol_list_sym_new (symbol *sym, location loc) res->midrule_parent_rhs_index = 0; /* Members used for LHS only. */ + res->rhs_loc = empty_loc; res->ruleprec = NULL; - res->percent_empty_loc = empty_location; + res->percent_empty_loc = empty_loc; code_props_none_init (&res->action_props); res->dprec = 0; - res->dprec_location = empty_location; + res->dprec_loc = empty_loc; res->merger = 0; - res->merger_declaration_location = empty_location; + res->merger_declaration_loc = empty_loc; res->expected_sr_conflicts = -1; res->expected_rr_conflicts = -1; @@ -73,7 +74,7 @@ symbol_list_type_new (uniqstr type_name, location loc) res->content.sem_type->location = loc; res->content.sem_type->status = undeclared; - res->location = res->sym_loc = loc; + res->sym_loc = loc; res->named_ref = NULL; res->next = NULL; @@ -97,6 +98,7 @@ symbol_list_type_set (symbol_list *syms, uniqstr type_name, location loc) void symbol_list_syms_print (const symbol_list *l, FILE *f) { + fputc ('[', f); char const *sep = ""; for (/* Nothing. */; l && l->content.sym; l = l->next) { @@ -105,10 +107,12 @@ symbol_list_syms_print (const symbol_list *l, FILE *f) : l->content_type == SYMLIST_TYPE ? "type: " : "invalid content_type: ", f); - symbol_print (l->content.sym, f); - fputs (l->action_props.is_value_used ? " used" : " unused", f); + if (l->content_type == SYMLIST_SYMBOL) + symbol_print (l->content.sym, f); + fputs (l->action_props.is_value_used ? " (used)" : " (unused)", f); sep = ", "; } + fputc (']', f); } @@ -148,14 +152,13 @@ symbol_list_append (symbol_list *list, symbol_list *node) void symbol_list_free (symbol_list *list) { - symbol_list *node, *next; - for (node = list; node; node = next) + for (symbol_list *next; list; list = next) { - next = node->next; - named_ref_free (node->named_ref); - if (node->content_type == SYMLIST_TYPE) - free (node->content.sem_type); - free (node); + next = list->next; + named_ref_free (list->named_ref); + if (list->content_type == SYMLIST_TYPE) + free (list->content.sem_type); + free (list); } } diff --git a/contrib/tools/bison/src/symlist.h b/contrib/tools/bison/src/symlist.h index d8ae90c97d22..d94b7aa1b0d7 100644 --- a/contrib/tools/bison/src/symlist.h +++ b/contrib/tools/bison/src/symlist.h @@ -1,6 +1,6 @@ /* Lists of symbols for Bison - Copyright (C) 2002, 2005-2007, 2009-2015, 2018-2019 Free Software + Copyright (C) 2002, 2005-2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -26,7 +26,9 @@ # include "symtab.h" # include "named-ref.h" -/* A list of symbols, used during the parsing to store the rules. */ +/* A list of symbols, used during the parsing for many different + purposes: rules, symbol declarations or properties (such as + %destructor, etc.)... */ typedef struct symbol_list { /** @@ -48,7 +50,6 @@ typedef struct symbol_list */ semantic_type *sem_type; } content; - location location; /* Named reference. */ named_ref *named_ref; @@ -67,9 +68,13 @@ typedef struct symbol_list struct symbol_list *midrule_parent_rule; int midrule_parent_rhs_index; - /* ---------------------------------------------- */ - /* Apply to the rule (attached to the LHS only). */ - /* ---------------------------------------------- */ + /*--------------------------------------------------------------. + | Used for rules only (attached to the "LHS", one per rule even | + | when several RHSs are bound to a single lhs via "|"). | + `--------------------------------------------------------------*/ + + /* Location of the RHS. */ + location rhs_loc; /* Precedence/associativity. */ symbol *ruleprec; @@ -79,13 +84,13 @@ typedef struct symbol_list code_props action_props; /* The location of the first %empty for this rule, or \a - empty_location. */ + empty_loc. */ location percent_empty_loc; int dprec; - location dprec_location; + location dprec_loc; int merger; - location merger_declaration_location; + location merger_declaration_loc; /* Counts of the number of expected conflicts for this rule, or -1 if none given. */ diff --git a/contrib/tools/bison/src/symtab.c b/contrib/tools/bison/src/symtab.c index b9a934f72665..b4106ea0b04c 100644 --- a/contrib/tools/bison/src/symtab.c +++ b/contrib/tools/bison/src/symtab.c @@ -1,6 +1,6 @@ /* Symbol table manager for Bison. - Copyright (C) 1984, 1989, 2000-2002, 2004-2015, 2018-2019 Free + Copyright (C) 1984, 1989, 2000-2002, 2004-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -19,21 +19,31 @@ along with this program. If not, see . */ #include +#include "symtab.h" + #include "system.h" +#include +#include #include +#include #include "complain.h" +#include "getargs.h" #include "gram.h" -#include "symtab.h" +#include "intprops.h" -/*-------------------------------------------------------------------. -| Symbols sorted by tag. Allocated by the first invocation of | -| symbols_do, after which no more symbols should be created. | -`-------------------------------------------------------------------*/ +static struct hash_table *symbol_table = NULL; +static struct hash_table *semantic_type_table = NULL; + +/*----------------------------------------------------------------. +| Symbols sorted by tag. Allocated by table_sort, after which no | +| more symbols should be created. | +`----------------------------------------------------------------*/ static symbol **symbols_sorted = NULL; -static symbol **semantic_types_sorted = NULL; +static semantic_type **semantic_types_sorted = NULL; + /*------------------------. | Distinguished symbols. | @@ -44,7 +54,7 @@ symbol *undeftoken = NULL; symbol *endtoken = NULL; symbol *accept = NULL; symbol *startsymbol = NULL; -location startsymbol_location; +location startsymbol_loc; /* Precedence relation graph. */ static symgraph **prec_nodes; @@ -67,10 +77,12 @@ sym_content_new (symbol *s) res->symbol = s; res->type_name = NULL; + res->type_loc = empty_loc; for (int i = 0; i < CODE_PROPS_SIZE; ++i) code_props_none_init (&res->props[i]); res->number = NUMBER_UNDEFINED; + res->prec_loc = empty_loc; res->prec = 0; res->assoc = undef_assoc; res->user_token_number = USER_NUMBER_UNDEFINED; @@ -147,8 +159,8 @@ symbol_free (void *ptr) declaration first. */ -static -void symbols_sort (symbol **first, symbol **second) +static void +symbols_sort (symbol **first, symbol **second) { if (0 < location_cmp ((*first)->location, (*second)->location)) { @@ -160,8 +172,8 @@ void symbols_sort (symbol **first, symbol **second) /* Likewise, for locations. */ -static -void locations_sort (location *first, location *second) +static void +locations_sort (location *first, location *second) { if (0 < location_cmp (*first, *second)) { @@ -196,7 +208,7 @@ semantic_type_new (uniqstr tag, const location *loc) uniqstr_assert (tag); res->tag = tag; - res->location = loc ? *loc : empty_location; + res->location = loc ? *loc : empty_loc; res->status = undeclared; for (int i = 0; i < CODE_PROPS_SIZE; ++i) code_props_none_init (&res->props[i]); @@ -222,7 +234,14 @@ symbol_print (symbol const *s, FILE *f) { if (s) { - fputs (s->tag, f); + symbol_class c = s->content->class; + fprintf (f, "%s: %s", + c == unknown_sym ? "unknown" + : c == pct_type_sym ? "%type" + : c == token_sym ? "token" + : c == nterm_sym ? "nterm" + : NULL, /* abort. */ + s->tag); SYMBOL_ATTR_PRINT (type_name); SYMBOL_CODE_PRINT (destructor); SYMBOL_CODE_PRINT (printer); @@ -277,7 +296,7 @@ static void complain_symbol_redeclared (symbol *s, const char *what, location first, location second) { - unsigned i = 0; + int i = 0; locations_sort (&first, &second); complain_indent (&second, complaint, &i, _("%s redeclaration for %s"), what, s->tag); @@ -290,7 +309,7 @@ static void complain_semantic_type_redeclared (semantic_type *s, const char *what, location first, location second) { - unsigned i = 0; + int i = 0; locations_sort (&first, &second); complain_indent (&second, complaint, &i, _("%s redeclaration for <%s>"), what, s->tag); @@ -302,16 +321,68 @@ complain_semantic_type_redeclared (semantic_type *s, const char *what, location static void complain_class_redeclared (symbol *sym, symbol_class class, location second) { - unsigned i = 0; + int i = 0; complain_indent (&second, complaint, &i, class == token_sym ? _("symbol %s redeclared as a token") : _("symbol %s redeclared as a nonterminal"), sym->tag); - i += SUB_INDENT; - complain_indent (&sym->location, complaint, &i, - _("previous definition")); + if (!location_empty (sym->location)) + { + i += SUB_INDENT; + complain_indent (&sym->location, complaint, &i, + _("previous definition")); + } } +static const symbol * +symbol_from_uniqstr_fuzzy (const uniqstr key) +{ + aver (symbols_sorted); +#define FSTRCMP_THRESHOLD 0.6 + double best_similarity = FSTRCMP_THRESHOLD; + const symbol *res = NULL; + size_t count = hash_get_n_entries (symbol_table); + for (int i = 0; i < count; ++i) + { + symbol *sym = symbols_sorted[i]; + if (STRNEQ (key, sym->tag) + && (sym->content->status == declared + || sym->content->status == undeclared)) + { + double similarity = fstrcmp_bounded (key, sym->tag, best_similarity); + if (best_similarity < similarity) + { + res = sym; + best_similarity = similarity; + } + } + } + return res; +} + +static void +complain_symbol_undeclared (symbol *sym) +{ + assert (sym->content->status != declared); + const symbol *best = symbol_from_uniqstr_fuzzy (sym->tag); + if (best) + { + complain (&sym->location, + sym->content->status == needed ? complaint : Wother, + _("symbol %s is used, but is not defined as a token" + " and has no rules; did you mean %s?"), + quote_n (0, sym->tag), + quote_n (1, best->tag)); + if (feature_flag & feature_caret) + location_caret_suggestion (sym->location, best->tag, stderr); + } + else + complain (&sym->location, + sym->content->status == needed ? complaint : Wother, + _("symbol %s is used, but is not defined as a token" + " and has no rules"), + quote (sym->tag)); +} void symbol_location_as_lhs_set (symbol *sym, location loc) @@ -334,12 +405,12 @@ symbol_type_set (symbol *sym, uniqstr type_name, location loc) tag_seen = true; if (sym->content->type_name) complain_symbol_redeclared (sym, "%type", - sym->content->type_location, loc); + sym->content->type_loc, loc); else { uniqstr_assert (type_name); sym->content->type_name = type_name; - sym->content->type_location = loc; + sym->content->type_loc = loc; } } } @@ -421,12 +492,12 @@ symbol_precedence_set (symbol *sym, int prec, assoc a, location loc) sym_content *s = sym->content; if (s->prec) complain_symbol_redeclared (sym, assoc_to_string (a), - s->prec_location, loc); + s->prec_loc, loc); else { s->prec = prec; s->assoc = a; - s->prec_location = loc; + s->prec_loc = loc; } } @@ -439,15 +510,33 @@ symbol_precedence_set (symbol *sym, int prec, assoc a, location loc) | Set the CLASS associated with SYM. | `------------------------------------*/ +static void +complain_pct_type_on_token (location *loc) +{ + complain (loc, Wyacc, + _("POSIX yacc reserves %%type to nonterminals")); +} + void symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring) { aver (class != unknown_sym); sym_content *s = sym->content; - if (s->class != unknown_sym && s->class != class) + if (class == pct_type_sym) + { + if (s->class == token_sym) + complain_pct_type_on_token (&loc); + else if (s->class == unknown_sym) + s->class = class; + } + else if (s->class != unknown_sym && s->class != pct_type_sym + && s->class != class) complain_class_redeclared (sym, class, loc); else { + if (class == token_sym && s->class == pct_type_sym) + complain_pct_type_on_token (&sym->location); + if (class == nterm_sym && s->class != nterm_sym) s->number = nvars++; else if (class == token_sym && s->number == NUMBER_UNDEFINED) @@ -457,9 +546,19 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring) if (declaring) { if (s->status == declared) - complain (&loc, Wother, _("symbol %s redeclared"), sym->tag); + { + int i = 0; + complain_indent (&loc, Wother, &i, + _("symbol %s redeclared"), sym->tag); + i += SUB_INDENT; + complain_indent (&sym->location, Wother, &i, + _("previous declaration")); + } else - s->status = declared; + { + sym->location = loc; + s->status = declared; + } } } } @@ -480,11 +579,14 @@ symbol_user_token_number_set (symbol *sym, int user_token_number, location loc) && *user_token_numberp != user_token_number) complain (&loc, complaint, _("redefining user token number of %s"), sym->tag); + else if (user_token_number == INT_MAX) + complain (&loc, complaint, _("user token number of %s too large"), + sym->tag); else { *user_token_numberp = user_token_number; /* User defined $end token? */ - if (user_token_number == 0) + if (user_token_number == 0 && !endtoken) { endtoken = sym->content->symbol; /* It is always mapped to 0, so it was already counted in @@ -502,22 +604,24 @@ symbol_user_token_number_set (symbol *sym, int user_token_number, location loc) | nonterminal. | `----------------------------------------------------------*/ -static inline bool +static void symbol_check_defined (symbol *sym) { sym_content *s = sym->content; - if (s->class == unknown_sym) + if (s->class == unknown_sym || s->class == pct_type_sym) { - assert (s->status != declared); - complain (&sym->location, - s->status == needed ? complaint : Wother, - _("symbol %s is used, but is not defined as a token" - " and has no rules"), - sym->tag); + complain_symbol_undeclared (sym); s->class = nterm_sym; s->number = nvars++; } + if (s->class == token_sym + && sym->tag[0] == '"' + && !sym->is_alias) + complain (&sym->location, Wdangling_alias, + _("string literal %s not attached to a symbol"), + sym->tag); + for (int i = 0; i < 2; ++i) symbol_code_props_get (sym, i)->is_used = true; @@ -529,11 +633,9 @@ symbol_check_defined (symbol *sym) if (sem_type) sem_type->status = declared; } - - return true; } -static inline bool +static void semantic_type_check_defined (semantic_type *sem_type) { /* <*> and <> do not have to be "declared". */ @@ -552,24 +654,8 @@ semantic_type_check_defined (semantic_type *sem_type) complain (&sem_type->location, Wother, _("type <%s> is used, but is not associated to any symbol"), sem_type->tag); - - return true; -} - -static bool -symbol_check_defined_processor (void *sym, void *null ATTRIBUTE_UNUSED) -{ - return symbol_check_defined (sym); -} - -static bool -semantic_type_check_defined_processor (void *sem_type, - void *null ATTRIBUTE_UNUSED) -{ - return semantic_type_check_defined (sem_type); } - /*-------------------------------------------------------------------. | Merge the properties (precedence, associativity, etc.) of SYM, and | | its string-named alias STR; check consistency. | @@ -582,10 +668,10 @@ symbol_merge_properties (symbol *sym, symbol *str) { if (str->content->type_name) symbol_type_set (sym, - str->content->type_name, str->content->type_location); + str->content->type_name, str->content->type_loc); else symbol_type_set (str, - sym->content->type_name, sym->content->type_location); + sym->content->type_name, sym->content->type_loc); } @@ -599,10 +685,10 @@ symbol_merge_properties (symbol *sym, symbol *str) { if (str->content->prec) symbol_precedence_set (sym, str->content->prec, str->content->assoc, - str->content->prec_location); + str->content->prec_loc); else symbol_precedence_set (str, sym->content->prec, sym->content->assoc, - sym->content->prec_location); + sym->content->prec_loc); } } @@ -636,7 +722,7 @@ symbol_make_alias (symbol *sym, symbol *str, location loc) | into FDEFINES. Put in SYMBOLS. | `-------------------------------------------------------------------*/ -static inline bool +static void symbol_pack (symbol *this) { aver (this->content->number != NUMBER_UNDEFINED); @@ -644,19 +730,12 @@ symbol_pack (symbol *this) this->content->number += ntokens; symbols[this->content->number] = this->content->symbol; - return true; -} - -static bool -symbol_pack_processor (void *this, void *null ATTRIBUTE_UNUSED) -{ - return symbol_pack (this); } static void complain_user_token_number_redeclared (int num, symbol *first, symbol *second) { - unsigned i = 0; + int i = 0; symbols_sort (&first, &second); complain_indent (&second->location, complaint, &i, _("user token number %d redeclaration for %s"), @@ -671,7 +750,7 @@ complain_user_token_number_redeclared (int num, symbol *first, symbol *second) | Put THIS in TOKEN_TRANSLATIONS if it is a token. | `--------------------------------------------------*/ -static inline bool +static void symbol_translation (symbol *this) { /* Nonterminal? */ @@ -688,14 +767,6 @@ symbol_translation (symbol *this) token_translations[this->content->user_token_number] = this->content->number; } - - return true; -} - -static bool -symbol_translation_processor (void *this, void *null ATTRIBUTE_UNUSED) -{ - return symbol_translation (this); } @@ -706,9 +777,6 @@ symbol_translation_processor (void *this, void *null ATTRIBUTE_UNUSED) /* Initial capacity of symbol and semantic type hash table. */ #define HT_INITIAL_CAPACITY 257 -static struct hash_table *symbol_table = NULL; -static struct hash_table *semantic_type_table = NULL; - static inline bool hash_compare_symbol (const symbol *m1, const symbol *m2) { @@ -768,16 +836,33 @@ hash_semantic_type_hasher (void const *m, size_t tablesize) void symbols_new (void) { - symbol_table = hash_initialize (HT_INITIAL_CAPACITY, - NULL, - hash_symbol_hasher, - hash_symbol_comparator, - symbol_free); - semantic_type_table = hash_initialize (HT_INITIAL_CAPACITY, - NULL, - hash_semantic_type_hasher, - hash_semantic_type_comparator, - free); + symbol_table = hash_xinitialize (HT_INITIAL_CAPACITY, + NULL, + hash_symbol_hasher, + hash_symbol_comparator, + symbol_free); + + /* Construct the accept symbol. */ + accept = symbol_get ("$accept", empty_loc); + accept->content->class = nterm_sym; + accept->content->number = nvars++; + + /* Construct the error token */ + errtoken = symbol_get ("error", empty_loc); + errtoken->content->class = token_sym; + errtoken->content->number = ntokens++; + + /* Construct a token that represents all undefined literal tokens. + It is always token number 2. */ + undeftoken = symbol_get ("$undefined", empty_loc); + undeftoken->content->class = token_sym; + undeftoken->content->number = ntokens++; + + semantic_type_table = hash_xinitialize (HT_INITIAL_CAPACITY, + NULL, + hash_semantic_type_hasher, + hash_semantic_type_comparator, + free); } @@ -864,9 +949,9 @@ dummy_symbol_get (location loc) { /* Incremented for each generated symbol. */ static int dummy_count = 0; - static char buf[256]; - - sprintf (buf, "$@%d", ++dummy_count); + char buf[32]; + int len = snprintf (buf, sizeof buf, "$@%d", ++dummy_count); + assure (len < sizeof buf); symbol *sym = symbol_get (buf, loc); sym->content->class = nterm_sym; sym->content->number = nvars++; @@ -894,36 +979,25 @@ symbols_free (void) } -/*---------------------------------------------------------------. -| Look for undefined symbols, report an error, and consider them | -| terminals. | -`---------------------------------------------------------------*/ - static int -symbols_cmp (symbol const *a, symbol const *b) +symbol_cmp (void const *a, void const *b) { - return strcmp (a->tag, b->tag); + return location_cmp ((*(symbol * const *)a)->location, + (*(symbol * const *)b)->location); } -static int -symbols_cmp_qsort (void const *a, void const *b) -{ - return symbols_cmp (*(symbol * const *)a, *(symbol * const *)b); -} +/* Store in *SORTED an array of pointers to the symbols contained in + TABLE, sorted (alphabetically) by tag. */ static void -symbols_do (Hash_processor processor, void *processor_data, - struct hash_table *table, symbol ***sorted) +table_sort (struct hash_table *table, symbol ***sorted) { + aver (!*sorted); size_t count = hash_get_n_entries (table); - if (!*sorted) - { - *sorted = xnmalloc (count, sizeof **sorted); - hash_get_entries (table, (void**)*sorted, count); - qsort (*sorted, count, sizeof **sorted, symbols_cmp_qsort); - } - for (size_t i = 0; i < count; ++i) - processor ((*sorted)[i], processor_data); + *sorted = xnmalloc (count + 1, sizeof **sorted); + hash_get_entries (table, (void**)*sorted, count); + qsort (*sorted, count, sizeof **sorted, symbol_cmp); + (*sorted)[count] = NULL; } /*--------------------------------------------------------------. @@ -934,10 +1008,20 @@ symbols_do (Hash_processor processor, void *processor_data, void symbols_check_defined (void) { - symbols_do (symbol_check_defined_processor, NULL, - symbol_table, &symbols_sorted); - symbols_do (semantic_type_check_defined_processor, NULL, - semantic_type_table, &semantic_types_sorted); + table_sort (symbol_table, &symbols_sorted); + /* semantic_type, like symbol, starts with a 'tag' field and then a + 'location' field. And here we only deal with arrays/hashes of + pointers, sizeof is not an issue. + + So instead of implementing table_sort (and symbol_cmp) once for + each type, let's lie a bit to the typing system, and treat + 'semantic_type' as if it were 'symbol'. */ + table_sort (semantic_type_table, (symbol ***) &semantic_types_sorted); + + for (int i = 0; symbols_sorted[i]; ++i) + symbol_check_defined (symbols_sorted[i]); + for (int i = 0; semantic_types_sorted[i]; ++i) + semantic_type_check_defined (semantic_types_sorted[i]); } /*------------------------------------------------------------------. @@ -978,7 +1062,13 @@ symbols_token_translations_init (void) { sym_content *this = symbols[i]->content; if (this->user_token_number == USER_NUMBER_UNDEFINED) - this->user_token_number = ++max_user_token_number; + { + IGNORE_TYPE_LIMITS_BEGIN + if (INT_ADD_WRAPV (max_user_token_number, 1, &max_user_token_number)) + complain (NULL, fatal, _("token number too large")); + IGNORE_TYPE_LIMITS_END + this->user_token_number = max_user_token_number; + } if (this->user_token_number > max_user_token_number) max_user_token_number = this->user_token_number; } @@ -988,10 +1078,10 @@ symbols_token_translations_init (void) /* Initialize all entries for literal tokens to the internal token number for $undefined, which represents all invalid inputs. */ - for (int i = 0; i < max_user_token_number + 1; i++) + for (int i = 0; i < max_user_token_number + 1; ++i) token_translations[i] = undeftoken->content->number; - symbols_do (symbol_translation_processor, NULL, - symbol_table, &symbols_sorted); + for (int i = 0; symbols_sorted[i]; ++i) + symbol_translation (symbols_sorted[i]); } @@ -1004,7 +1094,8 @@ void symbols_pack (void) { symbols = xcalloc (nsyms, sizeof *symbols); - symbols_do (symbol_pack_processor, NULL, symbol_table, &symbols_sorted); + for (int i = 0; symbols_sorted[i]; ++i) + symbol_pack (symbols_sorted[i]); /* Aliases leave empty slots in symbols, so remove them. */ { @@ -1029,11 +1120,11 @@ symbols_pack (void) symbols_token_translations_init (); if (startsymbol->content->class == unknown_sym) - complain (&startsymbol_location, fatal, + complain (&startsymbol_loc, fatal, _("the start symbol %s is undefined"), startsymbol->tag); else if (startsymbol->content->class == token_sym) - complain (&startsymbol_location, fatal, + complain (&startsymbol_loc, fatal, _("the start symbol %s is a token"), startsymbol->tag); } @@ -1204,14 +1295,14 @@ print_precedence_warnings (void) && !prec_nodes[i]->succ) { if (is_assoc_useless (s)) - complain (&s->content->prec_location, Wprecedence, + complain (&s->content->prec_loc, Wprecedence, _("useless precedence and associativity for %s"), s->tag); else if (s->content->assoc == precedence_assoc) - complain (&s->content->prec_location, Wprecedence, + complain (&s->content->prec_loc, Wprecedence, _("useless precedence for %s"), s->tag); } else if (is_assoc_useless (s)) - complain (&s->content->prec_location, Wprecedence, + complain (&s->content->prec_loc, Wprecedence, _("useless associativity for %s, use %%precedence"), s->tag); } free (used_assoc); diff --git a/contrib/tools/bison/src/symtab.h b/contrib/tools/bison/src/symtab.h index c22811265d2a..f3421774df64 100644 --- a/contrib/tools/bison/src/symtab.h +++ b/contrib/tools/bison/src/symtab.h @@ -1,6 +1,6 @@ /* Definitions for symtab.c and callers, part of Bison. - Copyright (C) 1984, 1989, 1992, 2000-2002, 2004-2015, 2018-2019 Free + Copyright (C) 1984, 1989, 1992, 2000-2002, 2004-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -38,9 +38,15 @@ /** Symbol classes. */ typedef enum { - unknown_sym, /**< Undefined. */ - token_sym, /**< Terminal. */ - nterm_sym /**< Nonterminal. */ + /** Undefined. */ + unknown_sym, + /** Declared with %type: same as Undefined, but triggered a Wyacc if + applied to a terminal. */ + pct_type_sym, + /** Terminal. */ + token_sym, + /** Nonterminal. */ + nterm_sym } symbol_class; @@ -72,7 +78,7 @@ typedef enum needed, /** Defined with %type or %token (good). */ declared, - } status; + } declaration_status; enum code_props_type { @@ -122,9 +128,9 @@ struct sym_content uniqstr type_name; /** Its \c \%type's location. */ - location type_location; + location type_loc; - /** Any \c \%destructor (resp. \%printer) declared specificially for this + /** Any \c \%destructor (resp. \%printer) declared specifically for this symbol. Access this field only through symbol's interface functions. For @@ -134,7 +140,7 @@ struct sym_content code_props props[CODE_PROPS_SIZE]; symbol_number number; - location prec_location; + location prec_loc; int prec; assoc assoc; @@ -144,7 +150,7 @@ struct sym_content int user_token_number; symbol_class class; - status status; + declaration_status status; }; /** Undefined user number. */ @@ -219,7 +225,8 @@ void symbol_precedence_set (symbol *sym, int prec, assoc a, location loc); /** Set the \c class associated with \c sym. Whether \c declaring means whether this class definition comes - from %nterm or %token. */ + from %nterm or %token (but not %type, prec/assoc, etc.). A symbol + can have "declaring" set only at most once. */ void symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring); @@ -246,7 +253,7 @@ extern symbol *accept; /** The user start symbol. */ extern symbol *startsymbol; /** The location of the \c \%start declaration. */ -extern location startsymbol_location; +extern location startsymbol_loc; /** Whether a symbol declared with a type tag. */ extern bool tag_seen; @@ -321,7 +328,7 @@ typedef struct { /** Its status : "undeclared", "used" or "declared". It cannot be "needed". */ - status status; + declaration_status status; /** Any \c %destructor and %printer declared for this semantic type. */ @@ -345,7 +352,8 @@ void semantic_type_code_props_set (semantic_type *type, | Symbol and semantic type tables. | `----------------------------------*/ -/** Create the symbol and semantic type tables. */ +/** Create the symbol and semantic type tables, and the built-in + symbols. */ void symbols_new (void); /** Free all the memory allocated for symbols and semantic types. */ diff --git a/contrib/tools/bison/src/system.h b/contrib/tools/bison/src/system.h index 8a82c788e0bf..606d3c466813 100644 --- a/contrib/tools/bison/src/system.h +++ b/contrib/tools/bison/src/system.h @@ -1,6 +1,6 @@ /* System-dependent definitions for Bison. - Copyright (C) 2000-2007, 2009-2015, 2018-2019 Free Software + Copyright (C) 2000-2007, 2009-2015, 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -73,6 +73,24 @@ typedef size_t uintptr_t; # include # include +// Clang and ICC like to pretend they are GCC. +# if defined __GNUC__ && !defined __clang__ && !defined __ICC +# define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) +# endif + +// See https://lists.gnu.org/archive/html/bug-bison/2019-10/msg00061.html +// and https://trac.macports.org/ticket/59927. +# if defined GCC_VERSION && 405 <= GCC_VERSION +# define IGNORE_TYPE_LIMITS_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wtype-limits\"") +# define IGNORE_TYPE_LIMITS_END \ + _Pragma ("GCC diagnostic pop") +# else +# define IGNORE_TYPE_LIMITS_BEGIN +# define IGNORE_TYPE_LIMITS_END +# endif + /*-----------------. | GCC extensions. | @@ -196,10 +214,10 @@ typedef size_t uintptr_t; /* Output Str both quoted for M4 (i.e., embed in [[...]]), and escaped for our postprocessing (i.e., escape M4 special characters). If - Str is empty (or NULL), output "[]" instead of "[[]]" as it make M4 - programming easier (m4_ifval can be used). + Str is empty (or NULL), output "[]" instead of "[[]]" as it makes + M4 programming easier (m4_ifval can be used). - For instance "[foo]" -> "[[@{foo@}]]", "$$" -> "[[$][$][]]". */ + For instance "[foo]" -> "[[@{foo@}]]", "$$" -> "[[$][$][]]". */ # define obstack_quote(Obs, Str) \ do { \ @@ -249,14 +267,4 @@ typedef size_t uintptr_t; } \ } while (0) - -/*---------------------------------------------. -| Debugging memory allocation (must be last). | -`---------------------------------------------*/ - -# if WITH_DMALLOC -# define DMALLOC_FUNC_CHECK -# include -# endif /* WITH_DMALLOC */ - #endif /* ! BISON_SYSTEM_H */ diff --git a/contrib/tools/bison/src/tables.c b/contrib/tools/bison/src/tables.c index 30849c33b57f..b6a8404ae6e7 100644 --- a/contrib/tools/bison/src/tables.c +++ b/contrib/tools/bison/src/tables.c @@ -1,6 +1,6 @@ /* Output the generated parsing program for Bison. - Copyright (C) 1984, 1986, 1989, 1992, 2000-2006, 2009-2015, 2018-2019 + Copyright (C) 1984, 1986, 1989, 1992, 2000-2006, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -21,6 +21,7 @@ #include #include "system.h" +#include #include #include "complain.h" @@ -83,7 +84,7 @@ int nvectors; static base_number **froms; static base_number **tos; -static unsigned **conflict_tos; +static int **conflict_tos; static size_t *tally; static base_number *width; @@ -110,11 +111,13 @@ base_number *base = NULL; computation equals to BASE_MINIMUM, later mapped to BASE_NINF to keep parser tables small. */ base_number base_ninf = 0; -static base_number *pos = NULL; +/* Bitset representing an integer set in the range + -nstates..table_size (as an upper bound) */ +static bitset pos_set = NULL; -static unsigned *conflrow; -unsigned *conflict_table; -unsigned *conflict_list; +static int *conflrow; +int *conflict_table; +int *conflict_list; int conflict_list_cnt; static int conflict_list_free; @@ -150,20 +153,23 @@ table_grow (int desired) table_size *= 2; if (trace_flag & trace_resource) - fprintf (stderr, "growing table and check from: %d to %d\n", + fprintf (stderr, "growing tables from %d to %d\n", old_size, table_size); table = xnrealloc (table, table_size, sizeof *table); + memset (table + old_size, 0, + sizeof *table * (table_size - old_size)); + conflict_table = xnrealloc (conflict_table, table_size, sizeof *conflict_table); + memset (conflict_table + old_size, 0, + sizeof *conflict_table * (table_size - old_size)); + check = xnrealloc (check, table_size, sizeof *check); + for (int i = old_size; i < table_size; ++i) + check[i] = -1; - for (/* Nothing. */; old_size < table_size; ++old_size) - { - table[old_size] = 0; - conflict_table[old_size] = 0; - check[old_size] = -1; - } + bitset_resize (pos_set, table_size + nstates); } @@ -236,22 +242,16 @@ conflict_row (state *s) static rule * action_row (state *s) { - rule *default_reduction = NULL; - reductions *reds = s->reductions; - transitions *trans = s->transitions; - errs *errp = s->errs; - /* Set to nonzero to inhibit having any default reduction. */ - bool nodefault = false; - bool conflicted = false; - for (state_number i = 0; i < ntokens; i++) actrow[i] = conflrow[i] = 0; + reductions *reds = s->reductions; + bool conflicted = false; if (reds->lookahead_tokens) /* loop over all the rules available here which require lookahead (in reverse order to give precedence to the first rule) */ - for (int i = reds->num - 1; i >= 0; --i) + for (int i = reds->num - 1; 0 <= i; --i) /* and find each token which the rule finds acceptable to come next */ { @@ -273,6 +273,9 @@ action_row (state *s) /* Now see which tokens are allowed for shifts in this state. For them, record the shift as the thing to do. So shift is preferred to reduce. */ + transitions *trans = s->transitions; + /* Set to nonzero to inhibit having any default reduction. */ + bool nodefault = false; { int i; FOR_EACH_SHIFT (trans, i) @@ -297,6 +300,7 @@ action_row (state *s) /* See which tokens are an explicit error in this state (due to %nonassoc). For them, record ACTION_NUMBER_MINIMUM as the action. */ + errs *errp = s->errs; for (int i = 0; i < errp->num; i++) { symbol *sym = errp->symbols[i]; @@ -316,7 +320,7 @@ action_row (state *s) /* Now find the most common reduction and make it the default action for this state. */ - + rule *default_reduction = NULL; if (reds->num >= 1 && !nodefault) { if (s->consistent) @@ -345,14 +349,12 @@ action_row (state *s) actions that match the default are replaced with zero, which means "use the default". */ - if (max > 0) - { - for (symbol_number j = 0; j < ntokens; j++) - if (actrow[j] - == rule_number_as_item_number (default_reduction->number) - && ! (nondeterministic_parser && conflrow[j])) - actrow[j] = 0; - } + if (0 < max) + for (symbol_number j = 0; j < ntokens; j++) + if (actrow[j] + == rule_number_as_item_number (default_reduction->number) + && ! (nondeterministic_parser && conflrow[j])) + actrow[j] = 0; } } @@ -389,7 +391,7 @@ save_row (state_number s) /* Allocate non defaulted actions. */ base_number *sp1 = froms[s] = xnmalloc (count, sizeof *sp1); base_number *sp2 = tos[s] = xnmalloc (count, sizeof *sp2); - unsigned *sp3 = conflict_tos[s] = + int *sp3 = conflict_tos[s] = nondeterministic_parser ? xnmalloc (count, sizeof *sp3) : NULL; /* Store non defaulted actions. */ @@ -606,7 +608,6 @@ matching_state (vector_number vector) { size_t t = tally[i]; int w = width[i]; - int prev; /* If VECTOR has GLR conflicts, return -1 */ if (conflict_tos[i] != NULL) @@ -614,7 +615,7 @@ matching_state (vector_number vector) if (conflict_tos[i][j] != 0) return -1; - for (prev = vector - 1; 0 <= prev; prev--) + for (int prev = vector - 1; 0 <= prev; prev--) { vector_number j = order[prev]; /* Given how ORDER was computed, if the WIDTH or TALLY is @@ -645,7 +646,7 @@ pack_vector (vector_number vector) size_t t = tally[i]; base_number *from = froms[i]; base_number *to = tos[i]; - unsigned *conflict_to = conflict_tos[i]; + int *conflict_to = conflict_tos[i]; aver (t != 0); @@ -664,10 +665,8 @@ pack_vector (vector_number vector) ok = false; } - if (ok) - for (int k = 0; k < vector; k++) - if (pos[k] == res) - ok = false; + if (ok && bitset_test (pos_set, nstates + res)) + ok = false; } if (ok) @@ -725,7 +724,7 @@ static void pack_table (void) { base = xnmalloc (nvectors, sizeof *base); - pos = xnmalloc (nentries, sizeof *pos); + pos_set = bitset_create (table_size + nstates, BITSET_FRUGAL); table = xcalloc (table_size, sizeof *table); conflict_table = xcalloc (table_size, sizeof *conflict_table); check = xnmalloc (table_size, sizeof *check); @@ -751,7 +750,12 @@ pack_table (void) /* Action of I were already coded for S. */ place = base[s]; - pos[i] = place; + /* Store PLACE into POS_SET. PLACE might not belong to the set + of possible values for instance with useless tokens. It + would be more satisfying to eliminate the need for this + 'if'. */ + if (0 <= nstates + place) + bitset_set (pos_set, nstates + place); base[order[i]] = place; } @@ -759,7 +763,7 @@ pack_table (void) base_ninf = table_ninf_remap (base, nvectors, BASE_MINIMUM); table_ninf = table_ninf_remap (table, high + 1, ACTION_NUMBER_MINIMUM); - free (pos); + bitset_free (pos_set); } diff --git a/contrib/tools/bison/src/tables.h b/contrib/tools/bison/src/tables.h index 0504e38c46e2..b0d420ad13de 100644 --- a/contrib/tools/bison/src/tables.h +++ b/contrib/tools/bison/src/tables.h @@ -1,6 +1,6 @@ /* Prepare the LALR and GLR parser tables. - Copyright (C) 2002, 2004, 2009-2015, 2018-2019 Free Software + Copyright (C) 2002, 2004, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -122,8 +122,8 @@ extern base_number *base; keep parser tables small. */ extern base_number base_ninf; -extern unsigned *conflict_table; -extern unsigned *conflict_list; +extern int *conflict_table; +extern int *conflict_list; extern int conflict_list_cnt; extern base_number *table; diff --git a/contrib/tools/bison/src/uniqstr.c b/contrib/tools/bison/src/uniqstr.c index f654d55ef178..d16e254a60cb 100644 --- a/contrib/tools/bison/src/uniqstr.c +++ b/contrib/tools/bison/src/uniqstr.c @@ -1,6 +1,6 @@ /* Keep a unique copy of strings. - Copyright (C) 2002-2005, 2009-2015, 2018-2019 Free Software + Copyright (C) 2002-2005, 2009-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -157,11 +157,11 @@ hash_uniqstr (void const *m, size_t tablesize) void uniqstrs_new (void) { - uniqstrs_table = hash_initialize (HT_INITIAL_CAPACITY, - NULL, - hash_uniqstr, - hash_compare_uniqstr, - free); + uniqstrs_table = hash_xinitialize (HT_INITIAL_CAPACITY, + NULL, + hash_uniqstr, + hash_compare_uniqstr, + free); } diff --git a/contrib/tools/bison/src/uniqstr.h b/contrib/tools/bison/src/uniqstr.h index 1fd731807f26..8f61ef4be1eb 100644 --- a/contrib/tools/bison/src/uniqstr.h +++ b/contrib/tools/bison/src/uniqstr.h @@ -1,6 +1,6 @@ /* Keeping a unique copy of strings. - Copyright (C) 2002-2003, 2008-2015, 2018-2019 Free Software + Copyright (C) 2002-2003, 2008-2015, 2018-2020 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. diff --git a/contrib/tools/bison/ya.make b/contrib/tools/bison/ya.make index 1fc51ad5ab12..975025a0e13f 100644 --- a/contrib/tools/bison/ya.make +++ b/contrib/tools/bison/ya.make @@ -3,6 +3,7 @@ PROGRAM(bison) LICENSE( + Bison-exception-2.2 AND GPL-3.0-only AND GPL-3.0-or-later AND GPL-3.0-or-later WITH Bison-exception-2.2 @@ -10,9 +11,9 @@ LICENSE( LICENSE_TEXTS(.yandex_meta/licenses.list.txt) -VERSION(3.3.2) +VERSION(3.5.4) -ORIGINAL_SOURCE(mirror://gnu/bison/bison-3.3.2.tar.gz) +ORIGINAL_SOURCE(mirror://gnu/bison/bison-3.5.4.tar.gz) PEERDIR( contrib/tools/bison/lib @@ -29,7 +30,7 @@ NO_RUNTIME() CFLAGS( -DEXEEXT=\"\" - -DINSTALLDIR=\"/var/empty/bison-3.3.2/bin\" + -DINSTALLDIR=\"/var/empty/bison-3.5.4/bin\" -DBISON_DATA_DIR=contrib/tools/bison/data ) @@ -37,7 +38,6 @@ SRCS( arcadia_root.cpp.in src/AnnotationList.c src/InadequacyList.c - src/LR0.c src/Sbitset.c src/assoc.c src/closure.c @@ -52,15 +52,16 @@ SRCS( src/ielr.c src/lalr.c src/location.c + src/lr0.c src/main.c src/muscle-tab.c src/named-ref.c src/nullable.c src/output.c src/parse-gram.c + src/print-graph.c src/print-xml.c src/print.c - src/print_graph.c src/reader.c src/reduce.c src/relation.c From 55c4d6e43a8d293d088b2501098a802a40cade9a Mon Sep 17 00:00:00 2001 From: nechda Date: Sun, 4 Aug 2024 11:39:23 +0300 Subject: [PATCH 035/104] Append Y_ prefix for ANNOTATE* macro d0e25a75f327b12876f6c11ca30660f3b99a4c71 --- .../base/internal/dynamic_annotations.h | 124 +++++++++--------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/contrib/restricted/abseil-cpp-tstring/y_absl/base/internal/dynamic_annotations.h b/contrib/restricted/abseil-cpp-tstring/y_absl/base/internal/dynamic_annotations.h index 2ac2679133ea..7233cde126d2 100644 --- a/contrib/restricted/abseil-cpp-tstring/y_absl/base/internal/dynamic_annotations.h +++ b/contrib/restricted/abseil-cpp-tstring/y_absl/base/internal/dynamic_annotations.h @@ -21,7 +21,7 @@ // in the program. // // The annotations that should be used by users are macros in all upper-case -// (e.g., ANNOTATE_THREAD_NAME). +// (e.g., Y_ANNOTATE_THREAD_NAME). // // Actual implementation of these macros may differ depending on the dynamic // analysis tool being used. @@ -122,21 +122,21 @@ // Report that we may have a benign race at `pointer`, with size // "sizeof(*(pointer))". `pointer` must be a non-void* pointer. Insert at the // point where `pointer` has been allocated, preferably close to the point -// where the race happens. See also ANNOTATE_BENIGN_RACE_STATIC. -#define ANNOTATE_BENIGN_RACE(pointer, description) \ +// where the race happens. See also Y_ANNOTATE_BENIGN_RACE_STATIC. +#define Y_ANNOTATE_BENIGN_RACE(pointer, description) \ Y_ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateBenignRaceSized) \ (__FILE__, __LINE__, pointer, sizeof(*(pointer)), description) -// Same as ANNOTATE_BENIGN_RACE(`address`, `description`), but applies to +// Same as Y_ANNOTATE_BENIGN_RACE(`address`, `description`), but applies to // the memory range [`address`, `address`+`size`). -#define ANNOTATE_BENIGN_RACE_SIZED(address, size, description) \ +#define Y_ANNOTATE_BENIGN_RACE_SIZED(address, size, description) \ Y_ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateBenignRaceSized) \ (__FILE__, __LINE__, address, size, description) // Enable (`enable`!=0) or disable (`enable`==0) race detection for all threads. // This annotation could be useful if you want to skip expensive race analysis // during some period of program execution, e.g. during initialization. -#define ANNOTATE_ENABLE_RACE_DETECTION(enable) \ +#define Y_ANNOTATE_ENABLE_RACE_DETECTION(enable) \ Y_ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateEnableRaceDetection) \ (__FILE__, __LINE__, enable) @@ -144,7 +144,7 @@ // Annotations useful for debugging. // Report the current thread `name` to a race detector. -#define ANNOTATE_THREAD_NAME(name) \ +#define Y_ANNOTATE_THREAD_NAME(name) \ Y_ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateThreadName)(__FILE__, __LINE__, name) // ------------------------------------------------------------- @@ -153,41 +153,41 @@ // object. // Report that a lock has been created at address `lock`. -#define ANNOTATE_RWLOCK_CREATE(lock) \ +#define Y_ANNOTATE_RWLOCK_CREATE(lock) \ Y_ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockCreate)(__FILE__, __LINE__, lock) // Report that a linker initialized lock has been created at address `lock`. #ifdef Y_ABSL_HAVE_THREAD_SANITIZER -#define ANNOTATE_RWLOCK_CREATE_STATIC(lock) \ +#define Y_ANNOTATE_RWLOCK_CREATE_STATIC(lock) \ Y_ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockCreateStatic) \ (__FILE__, __LINE__, lock) #else -#define ANNOTATE_RWLOCK_CREATE_STATIC(lock) ANNOTATE_RWLOCK_CREATE(lock) +#define Y_ANNOTATE_RWLOCK_CREATE_STATIC(lock) Y_ANNOTATE_RWLOCK_CREATE(lock) #endif // Report that the lock at address `lock` is about to be destroyed. -#define ANNOTATE_RWLOCK_DESTROY(lock) \ +#define Y_ANNOTATE_RWLOCK_DESTROY(lock) \ Y_ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockDestroy)(__FILE__, __LINE__, lock) // Report that the lock at address `lock` has been acquired. // `is_w`=1 for writer lock, `is_w`=0 for reader lock. -#define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \ +#define Y_ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \ Y_ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockAcquired) \ (__FILE__, __LINE__, lock, is_w) // Report that the lock at address `lock` is about to be released. // `is_w`=1 for writer lock, `is_w`=0 for reader lock. -#define ANNOTATE_RWLOCK_RELEASED(lock, is_w) \ +#define Y_ANNOTATE_RWLOCK_RELEASED(lock, is_w) \ Y_ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateRWLockReleased) \ (__FILE__, __LINE__, lock, is_w) -// Apply ANNOTATE_BENIGN_RACE_SIZED to a static variable `static_var`. -#define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \ +// Apply Y_ANNOTATE_BENIGN_RACE_SIZED to a static variable `static_var`. +#define Y_ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \ namespace { \ class static_var##_annotator { \ public: \ static_var##_annotator() { \ - ANNOTATE_BENIGN_RACE_SIZED(&static_var, sizeof(static_var), \ + Y_ANNOTATE_BENIGN_RACE_SIZED(&static_var, sizeof(static_var), \ #static_var ": " description); \ } \ }; \ @@ -196,16 +196,16 @@ #else // Y_ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED == 0 -#define ANNOTATE_RWLOCK_CREATE(lock) // empty -#define ANNOTATE_RWLOCK_CREATE_STATIC(lock) // empty -#define ANNOTATE_RWLOCK_DESTROY(lock) // empty -#define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) // empty -#define ANNOTATE_RWLOCK_RELEASED(lock, is_w) // empty -#define ANNOTATE_BENIGN_RACE(address, description) // empty -#define ANNOTATE_BENIGN_RACE_SIZED(address, size, description) // empty -#define ANNOTATE_THREAD_NAME(name) // empty -#define ANNOTATE_ENABLE_RACE_DETECTION(enable) // empty -#define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) // empty +#define Y_ANNOTATE_RWLOCK_CREATE(lock) // empty +#define Y_ANNOTATE_RWLOCK_CREATE_STATIC(lock) // empty +#define Y_ANNOTATE_RWLOCK_DESTROY(lock) // empty +#define Y_ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) // empty +#define Y_ANNOTATE_RWLOCK_RELEASED(lock, is_w) // empty +#define Y_ANNOTATE_BENIGN_RACE(address, description) // empty +#define Y_ANNOTATE_BENIGN_RACE_SIZED(address, size, description) // empty +#define Y_ANNOTATE_THREAD_NAME(name) // empty +#define Y_ANNOTATE_ENABLE_RACE_DETECTION(enable) // empty +#define Y_ANNOTATE_BENIGN_RACE_STATIC(static_var, description) // empty #endif // Y_ABSL_INTERNAL_RACE_ANNOTATIONS_ENABLED @@ -216,28 +216,28 @@ #include -#define ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \ +#define Y_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \ __msan_unpoison(address, size) -#define ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) \ +#define Y_ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) \ __msan_allocated_memory(address, size) #else // Y_ABSL_INTERNAL_MEMORY_ANNOTATIONS_ENABLED == 0 #if DYNAMIC_ANNOTATIONS_ENABLED == 1 -#define ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \ +#define Y_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \ do { \ (void)(address); \ (void)(size); \ } while (0) -#define ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) \ +#define Y_ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) \ do { \ (void)(address); \ (void)(size); \ } while (0) #else -#define ANNOTATE_MEMORY_IS_INITIALIZED(address, size) // empty -#define ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) // empty +#define Y_ANNOTATE_MEMORY_IS_INITIALIZED(address, size) // empty +#define Y_ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) // empty #endif #endif // Y_ABSL_INTERNAL_MEMORY_ANNOTATIONS_ENABLED @@ -265,14 +265,14 @@ #if Y_ABSL_INTERNAL_READS_ANNOTATIONS_ENABLED == 1 // Request the analysis tool to ignore all reads in the current thread until -// ANNOTATE_IGNORE_READS_END is called. Useful to ignore intentional racey +// Y_ANNOTATE_IGNORE_READS_END is called. Useful to ignore intentional racey // reads, while still checking other reads and all writes. -// See also ANNOTATE_UNPROTECTED_READ. -#define ANNOTATE_IGNORE_READS_BEGIN() \ +// See also Y_ANNOTATE_UNPROTECTED_READ. +#define Y_ANNOTATE_IGNORE_READS_BEGIN() \ Y_ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateIgnoreReadsBegin)(__FILE__, __LINE__) // Stop ignoring reads. -#define ANNOTATE_IGNORE_READS_END() \ +#define Y_ANNOTATE_IGNORE_READS_END() \ Y_ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateIgnoreReadsEnd)(__FILE__, __LINE__) #elif defined(Y_ABSL_INTERNAL_ANNOTALYSIS_ENABLED) @@ -284,16 +284,16 @@ // TODO(delesley) -- The exclusive lock here ignores writes as well, but // allows IGNORE_READS_AND_WRITES to work properly. -#define ANNOTATE_IGNORE_READS_BEGIN() \ +#define Y_ANNOTATE_IGNORE_READS_BEGIN() \ Y_ABSL_INTERNAL_GLOBAL_SCOPED(AbslInternalAnnotateIgnoreReadsBegin)() -#define ANNOTATE_IGNORE_READS_END() \ +#define Y_ANNOTATE_IGNORE_READS_END() \ Y_ABSL_INTERNAL_GLOBAL_SCOPED(AbslInternalAnnotateIgnoreReadsEnd)() #else -#define ANNOTATE_IGNORE_READS_BEGIN() // empty -#define ANNOTATE_IGNORE_READS_END() // empty +#define Y_ANNOTATE_IGNORE_READS_BEGIN() // empty +#define Y_ANNOTATE_IGNORE_READS_END() // empty #endif @@ -302,60 +302,60 @@ #if Y_ABSL_INTERNAL_WRITES_ANNOTATIONS_ENABLED == 1 -// Similar to ANNOTATE_IGNORE_READS_BEGIN, but ignore writes instead. -#define ANNOTATE_IGNORE_WRITES_BEGIN() \ +// Similar to Y_ANNOTATE_IGNORE_READS_BEGIN, but ignore writes instead. +#define Y_ANNOTATE_IGNORE_WRITES_BEGIN() \ Y_ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateIgnoreWritesBegin)(__FILE__, __LINE__) // Stop ignoring writes. -#define ANNOTATE_IGNORE_WRITES_END() \ +#define Y_ANNOTATE_IGNORE_WRITES_END() \ Y_ABSL_INTERNAL_GLOBAL_SCOPED(AnnotateIgnoreWritesEnd)(__FILE__, __LINE__) #else -#define ANNOTATE_IGNORE_WRITES_BEGIN() // empty -#define ANNOTATE_IGNORE_WRITES_END() // empty +#define Y_ANNOTATE_IGNORE_WRITES_BEGIN() // empty +#define Y_ANNOTATE_IGNORE_WRITES_END() // empty #endif // ------------------------------------------------------------------------- -// Define the ANNOTATE_IGNORE_READS_AND_WRITES_* annotations using the more +// Define the Y_ANNOTATE_IGNORE_READS_AND_WRITES_* annotations using the more // primitive annotations defined above. // // Instead of doing -// ANNOTATE_IGNORE_READS_BEGIN(); +// Y_ANNOTATE_IGNORE_READS_BEGIN(); // ... = x; -// ANNOTATE_IGNORE_READS_END(); +// Y_ANNOTATE_IGNORE_READS_END(); // one can use -// ... = ANNOTATE_UNPROTECTED_READ(x); +// ... = Y_ANNOTATE_UNPROTECTED_READ(x); #if defined(Y_ABSL_INTERNAL_READS_WRITES_ANNOTATIONS_ENABLED) // Start ignoring all memory accesses (both reads and writes). -#define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \ +#define Y_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \ do { \ - ANNOTATE_IGNORE_READS_BEGIN(); \ - ANNOTATE_IGNORE_WRITES_BEGIN(); \ + Y_ANNOTATE_IGNORE_READS_BEGIN(); \ + Y_ANNOTATE_IGNORE_WRITES_BEGIN(); \ } while (0) // Stop ignoring both reads and writes. -#define ANNOTATE_IGNORE_READS_AND_WRITES_END() \ +#define Y_ANNOTATE_IGNORE_READS_AND_WRITES_END() \ do { \ - ANNOTATE_IGNORE_WRITES_END(); \ - ANNOTATE_IGNORE_READS_END(); \ + Y_ANNOTATE_IGNORE_WRITES_END(); \ + Y_ANNOTATE_IGNORE_READS_END(); \ } while (0) #ifdef __cplusplus -// ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racey reads. -#define ANNOTATE_UNPROTECTED_READ(x) \ +// Y_ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racey reads. +#define Y_ANNOTATE_UNPROTECTED_READ(x) \ y_absl::base_internal::AnnotateUnprotectedRead(x) #endif #else -#define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() // empty -#define ANNOTATE_IGNORE_READS_AND_WRITES_END() // empty -#define ANNOTATE_UNPROTECTED_READ(x) (x) +#define Y_ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() // empty +#define Y_ANNOTATE_IGNORE_READS_AND_WRITES_END() // empty +#define Y_ANNOTATE_UNPROTECTED_READ(x) (x) #endif @@ -368,7 +368,7 @@ // sanitizer/common_interface_defs.h, which is provided by the compiler. #include -#define ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid) \ +#define Y_ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid) \ __sanitizer_annotate_contiguous_container(beg, end, old_mid, new_mid) #define ADDRESS_SANITIZER_REDZONE(name) \ struct { \ @@ -377,7 +377,7 @@ #else -#define ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid) +#define Y_ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid) #define ADDRESS_SANITIZER_REDZONE(name) static_assert(true, "") #endif // Y_ABSL_HAVE_ADDRESS_SANITIZER From e30f7061bad712a7934e383fef27613fc6a1b2d7 Mon Sep 17 00:00:00 2001 From: nechda Date: Sun, 4 Aug 2024 13:43:56 +0300 Subject: [PATCH 036/104] fix _io.TextIOWrapper.write() write during flush 816f3097d548522bcfae2b763098747304285d0f --- contrib/tools/python3/Modules/_io/textio.c | 31 +++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/contrib/tools/python3/Modules/_io/textio.c b/contrib/tools/python3/Modules/_io/textio.c index 14dd19d95c24..4a1ba22d381a 100644 --- a/contrib/tools/python3/Modules/_io/textio.c +++ b/contrib/tools/python3/Modules/_io/textio.c @@ -1723,16 +1723,26 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text) bytes_len = PyBytes_GET_SIZE(b); } - if (self->pending_bytes == NULL) { - self->pending_bytes_count = 0; - self->pending_bytes = b; - } - else if (self->pending_bytes_count + bytes_len > self->chunk_size) { - // Prevent to concatenate more than chunk_size data. - if (_textiowrapper_writeflush(self) < 0) { - Py_DECREF(b); - return NULL; + // We should avoid concatinating huge data. + // Flush the buffer before adding b to the buffer if b is not small. + // https://github.com/python/cpython/issues/87426 + if (bytes_len >= self->chunk_size) { + // _textiowrapper_writeflush() calls buffer.write(). + // self->pending_bytes can be appended during buffer->write() + // or other thread. + // We need to loop until buffer becomes empty. + // https://github.com/python/cpython/issues/118138 + // https://github.com/python/cpython/issues/119506 + while (self->pending_bytes != NULL) { + if (_textiowrapper_writeflush(self) < 0) { + Py_DECREF(b); + return NULL; + } } + } + + if (self->pending_bytes == NULL) { + assert(self->pending_bytes_count == 0); self->pending_bytes = b; } else if (!PyList_CheckExact(self->pending_bytes)) { @@ -1741,6 +1751,9 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text) Py_DECREF(b); return NULL; } + // Since Python 3.12, allocating GC object won't trigger GC and release + // GIL. See https://github.com/python/cpython/issues/97922 + assert(!PyList_CheckExact(self->pending_bytes)); PyList_SET_ITEM(list, 0, self->pending_bytes); PyList_SET_ITEM(list, 1, b); self->pending_bytes = list; From df5a8e17b7f64a8c7086988670187d172bf9392a Mon Sep 17 00:00:00 2001 From: thegeorg Date: Sun, 4 Aug 2024 15:38:59 +0300 Subject: [PATCH 037/104] Update contrib/restricted/abseil-cpp to 20240722.0 d546de87f4113d314e722b1646c13db9f6aa5026 --- .../abseil-cpp/absl/algorithm/container.h | 75 +- .../abseil-cpp/absl/algorithm/ya.make | 4 +- .../abseil-cpp/absl/base/attributes.h | 84 + .../restricted/abseil-cpp/absl/base/config.h | 85 +- .../absl/base/dynamic_annotations.h | 16 - .../absl/base/internal/nullability_impl.h | 4 +- .../abseil-cpp/absl/base/internal/poison.cc | 84 + .../abseil-cpp/absl/base/internal/poison.h | 59 + .../abseil-cpp/absl/base/internal/spinlock.h | 16 +- .../absl/base/internal/unscaledcycleclock.cc | 12 - .../base/internal/unscaledcycleclock_config.h | 8 +- .../restricted/abseil-cpp/absl/base/macros.h | 48 + .../abseil-cpp/absl/base/no_destructor.h | 75 +- .../abseil-cpp/absl/base/nullability.h | 40 +- .../abseil-cpp/absl/base/optimization.h | 11 + .../restricted/abseil-cpp/absl/base/options.h | 2 +- .../abseil-cpp/absl/base/prefetch.h | 2 +- .../restricted/abseil-cpp/absl/base/ya.make | 1 + .../abseil-cpp/absl/container/flat_hash_map.h | 80 +- .../abseil-cpp/absl/container/flat_hash_set.h | 66 +- .../absl/container/hash_container_defaults.h | 45 + .../absl/container/inlined_vector.h | 13 + .../container/internal/common_policy_traits.h | 31 +- .../container/internal/compressed_tuple.h | 31 +- .../container/internal/container_memory.h | 35 +- .../internal/hash_function_defaults.h | 69 +- .../container/internal/hash_policy_traits.h | 50 + .../container/internal/hashtablez_sampler.cc | 29 +- .../container/internal/hashtablez_sampler.h | 34 +- .../absl/container/internal/inlined_vector.h | 74 +- .../absl/container/internal/raw_hash_map.h | 14 +- .../absl/container/internal/raw_hash_set.cc | 405 +++- .../absl/container/internal/raw_hash_set.h | 1757 ++++++++++++----- .../internal/crc32_x86_arm_combined_simd.h | 36 +- .../absl/crc/internal/crc_cord_state.cc | 7 +- .../absl/crc/internal/crc_memcpy_fallback.cc | 3 +- .../internal/crc_memcpy_x86_arm_combined.cc | 20 +- .../crc/internal/crc_non_temporal_memcpy.cc | 2 +- .../absl/crc/internal/crc_x86_arm_combined.cc | 18 +- .../absl/crc/internal/non_temporal_memcpy.h | 35 +- .../absl/debugging/failure_signal_handler.h | 2 +- .../internal/bounded_utf8_length_sequence.h | 126 ++ .../internal/decode_rust_punycode.cc | 258 +++ .../debugging/internal/decode_rust_punycode.h | 55 + .../absl/debugging/internal/demangle.cc | 1143 ++++++++++- .../absl/debugging/internal/demangle.h | 3 + .../absl/debugging/internal/demangle_rust.cc | 925 +++++++++ .../absl/debugging/internal/demangle_rust.h | 42 + .../absl/debugging/internal/elf_mem_image.cc | 59 +- .../absl/debugging/internal/elf_mem_image.h | 15 +- .../internal/stacktrace_aarch64-inl.inc | 17 +- .../debugging/internal/utf8_for_code_point.cc | 70 + .../debugging/internal/utf8_for_code_point.h | 47 + .../abseil-cpp/absl/debugging/ya.make | 3 + .../abseil-cpp/absl/flags/commandlineflag.h | 11 + .../restricted/abseil-cpp/absl/flags/flag.h | 2 + .../abseil-cpp/absl/flags/internal/flag.cc | 147 +- .../abseil-cpp/absl/flags/internal/flag.h | 222 ++- .../abseil-cpp/absl/flags/reflection.cc | 10 + .../absl/functional/any_invocable.h | 16 +- .../absl/functional/internal/any_invocable.h | 14 +- .../abseil-cpp/absl/functional/ya.make | 4 +- .../abseil-cpp/absl/hash/internal/hash.cc | 2 +- .../abseil-cpp/absl/hash/internal/hash.h | 16 +- .../absl/hash/internal/low_level_hash.cc | 88 +- .../absl/hash/internal/low_level_hash.h | 4 + .../abseil-cpp/absl/log/absl_vlog_is_on.h | 6 +- .../abseil-cpp/absl/log/die_if_null.h | 2 +- .../restricted/abseil-cpp/absl/log/globals.h | 43 +- .../abseil-cpp/absl/log/internal/check_op.cc | 20 + .../abseil-cpp/absl/log/internal/check_op.h | 84 +- .../abseil-cpp/absl/log/internal/conditions.h | 4 +- .../abseil-cpp/absl/log/internal/log_impl.h | 46 +- .../absl/log/internal/log_message.cc | 151 +- .../absl/log/internal/log_message.h | 27 +- .../abseil-cpp/absl/log/internal/nullstream.h | 11 +- .../abseil-cpp/absl/log/internal/strip.h | 36 + contrib/restricted/abseil-cpp/absl/log/log.h | 6 +- .../restricted/abseil-cpp/absl/log/log_sink.h | 15 +- .../abseil-cpp/absl/log/vlog_is_on.h | 72 - .../restricted/abseil-cpp/absl/memory/ya.make | 4 +- .../abseil-cpp/absl/meta/type_traits.h | 180 +- .../restricted/abseil-cpp/absl/meta/ya.make | 4 +- .../abseil-cpp/absl/numeric/int128.cc | 3 - .../abseil-cpp/absl/numeric/int128.h | 40 +- .../absl/numeric/int128_have_intrinsic.inc | 14 + .../absl/numeric/int128_no_intrinsic.inc | 18 + .../abseil-cpp/absl/numeric/internal/bits.h | 8 +- .../profiling/internal/periodic_sampler.h | 2 +- .../abseil-cpp/absl/random/seed_sequences.h | 2 + .../absl/status/internal/statusor_internal.h | 63 +- .../abseil-cpp/absl/status/status.cc | 4 - .../abseil-cpp/absl/status/status.h | 8 +- .../abseil-cpp/absl/status/statusor.h | 250 +-- .../abseil-cpp/absl/strings/ascii.cc | 103 +- .../abseil-cpp/absl/strings/cord.cc | 35 +- .../restricted/abseil-cpp/absl/strings/cord.h | 75 +- .../abseil-cpp/absl/strings/escaping.cc | 91 +- .../abseil-cpp/absl/strings/escaping.h | 33 +- .../absl/strings/has_absl_stringify.h | 1 + .../absl/strings/internal/charconv_bigint.h | 10 + .../absl/strings/internal/cord_internal.h | 38 +- .../absl/strings/internal/cord_rep_btree.h | 4 +- .../absl/strings/internal/cordz_functions.cc | 32 +- .../absl/strings/internal/cordz_functions.h | 36 +- .../absl/strings/internal/cordz_handle.cc | 48 +- .../absl/strings/internal/cordz_info.cc | 19 +- .../absl/strings/internal/cordz_info.h | 13 +- .../absl/strings/internal/escaping.cc | 7 +- .../absl/strings/internal/str_join_internal.h | 25 +- .../strings/internal/str_split_internal.h | 6 +- .../abseil-cpp/absl/strings/numbers.cc | 440 +---- .../abseil-cpp/absl/strings/numbers.h | 163 +- .../abseil-cpp/absl/strings/str_cat.cc | 191 +- .../abseil-cpp/absl/strings/str_cat.h | 154 +- .../abseil-cpp/absl/strings/str_format.h | 2 +- .../abseil-cpp/absl/strings/str_join.h | 24 +- .../abseil-cpp/absl/strings/str_split.h | 4 +- .../abseil-cpp/absl/strings/string_view.h | 5 +- .../abseil-cpp/absl/strings/substitute.cc | 4 + .../synchronization/internal/graphcycles.cc | 13 +- .../synchronization/internal/graphcycles.h | 5 + .../abseil-cpp/absl/synchronization/mutex.h | 9 +- .../abseil-cpp/absl/time/civil_time.h | 4 +- .../restricted/abseil-cpp/absl/time/clock.cc | 16 +- .../abseil-cpp/absl/time/duration.cc | 111 +- .../restricted/abseil-cpp/absl/time/format.cc | 3 +- .../time/internal/cctz/src/time_zone_libc.cc | 2 +- .../internal/cctz/src/time_zone_lookup.cc | 29 - .../absl/time/internal/cctz/src/tzfile.h | 6 +- .../restricted/abseil-cpp/absl/time/time.h | 102 +- .../abseil-cpp/absl/types/compare.h | 505 +++++ .../abseil-cpp/absl/types/internal/optional.h | 4 +- .../abseil-cpp/absl/types/internal/variant.h | 122 +- .../abseil-cpp/absl/types/optional.h | 33 +- .../restricted/abseil-cpp/absl/types/span.h | 5 +- .../abseil-cpp/absl/types/variant.h | 43 +- .../abseil-cpp/absl/utility/utility.h | 44 +- .../abseil-cpp/absl/utility/ya.make | 4 +- contrib/restricted/abseil-cpp/ya.make | 6 +- 140 files changed, 7858 insertions(+), 2675 deletions(-) create mode 100644 contrib/restricted/abseil-cpp/absl/base/internal/poison.cc create mode 100644 contrib/restricted/abseil-cpp/absl/base/internal/poison.h create mode 100644 contrib/restricted/abseil-cpp/absl/container/hash_container_defaults.h create mode 100644 contrib/restricted/abseil-cpp/absl/debugging/internal/bounded_utf8_length_sequence.h create mode 100644 contrib/restricted/abseil-cpp/absl/debugging/internal/decode_rust_punycode.cc create mode 100644 contrib/restricted/abseil-cpp/absl/debugging/internal/decode_rust_punycode.h create mode 100644 contrib/restricted/abseil-cpp/absl/debugging/internal/demangle_rust.cc create mode 100644 contrib/restricted/abseil-cpp/absl/debugging/internal/demangle_rust.h create mode 100644 contrib/restricted/abseil-cpp/absl/debugging/internal/utf8_for_code_point.cc create mode 100644 contrib/restricted/abseil-cpp/absl/debugging/internal/utf8_for_code_point.h delete mode 100644 contrib/restricted/abseil-cpp/absl/log/vlog_is_on.h create mode 100644 contrib/restricted/abseil-cpp/absl/types/compare.h diff --git a/contrib/restricted/abseil-cpp/absl/algorithm/container.h b/contrib/restricted/abseil-cpp/absl/algorithm/container.h index c7bafae1477c..6bbe3b5adf40 100644 --- a/contrib/restricted/abseil-cpp/absl/algorithm/container.h +++ b/contrib/restricted/abseil-cpp/absl/algorithm/container.h @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,7 @@ #include #include "absl/algorithm/algorithm.h" +#include "absl/base/config.h" #include "absl/base/macros.h" #include "absl/base/nullability.h" #include "absl/meta/type_traits.h" @@ -92,17 +94,17 @@ using ContainerPointerType = // using std::end; // std::foo(begin(c), end(c)); // becomes -// std::foo(container_algorithm_internal::begin(c), -// container_algorithm_internal::end(c)); +// std::foo(container_algorithm_internal::c_begin(c), +// container_algorithm_internal::c_end(c)); // These are meant for internal use only. template -ContainerIter c_begin(C& c) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 ContainerIter c_begin(C& c) { return begin(c); } template -ContainerIter c_end(C& c) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 ContainerIter c_end(C& c) { return end(c); } @@ -145,8 +147,9 @@ bool c_linear_search(const C& c, EqualityComparable&& value) { // Container-based version of the `std::distance()` function to // return the number of elements within a container. template -container_algorithm_internal::ContainerDifferenceType c_distance( - const C& c) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 + container_algorithm_internal::ContainerDifferenceType + c_distance(const C& c) { return std::distance(container_algorithm_internal::c_begin(c), container_algorithm_internal::c_end(c)); } @@ -210,6 +213,16 @@ container_algorithm_internal::ContainerIter c_find(C& c, T&& value) { std::forward(value)); } +// c_contains() +// +// Container-based version of the `std::ranges::contains()` C++23 +// function to search a container for a value. +template +bool c_contains(const Sequence& sequence, T&& value) { + return absl::c_find(sequence, std::forward(value)) != + container_algorithm_internal::c_end(sequence); +} + // c_find_if() // // Container-based version of the `std::find_if()` function to find @@ -426,6 +439,26 @@ container_algorithm_internal::ContainerIter c_search( std::forward(pred)); } +// c_contains_subrange() +// +// Container-based version of the `std::ranges::contains_subrange()` +// C++23 function to search a container for a subsequence. +template +bool c_contains_subrange(Sequence1& sequence, Sequence2& subsequence) { + return absl::c_search(sequence, subsequence) != + container_algorithm_internal::c_end(sequence); +} + +// Overload of c_contains_subrange() for using a predicate evaluation other than +// `==` as the function's test condition. +template +bool c_contains_subrange(Sequence1& sequence, Sequence2& subsequence, + BinaryPredicate&& pred) { + return absl::c_search(sequence, subsequence, + std::forward(pred)) != + container_algorithm_internal::c_end(sequence); +} + // c_search_n() // // Container-based version of the `std::search_n()` function to @@ -1500,8 +1533,9 @@ c_is_heap_until(RandomAccessContainer& sequence, LessThan&& comp) { // to return an iterator pointing to the element with the smallest value, using // `operator<` to make the comparisons. template -container_algorithm_internal::ContainerIter c_min_element( - Sequence& sequence) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 + container_algorithm_internal::ContainerIter + c_min_element(Sequence& sequence) { return std::min_element(container_algorithm_internal::c_begin(sequence), container_algorithm_internal::c_end(sequence)); } @@ -1509,8 +1543,9 @@ container_algorithm_internal::ContainerIter c_min_element( // Overload of c_min_element() for performing a `comp` comparison other than // `operator<`. template -container_algorithm_internal::ContainerIter c_min_element( - Sequence& sequence, LessThan&& comp) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 + container_algorithm_internal::ContainerIter + c_min_element(Sequence& sequence, LessThan&& comp) { return std::min_element(container_algorithm_internal::c_begin(sequence), container_algorithm_internal::c_end(sequence), std::forward(comp)); @@ -1522,8 +1557,9 @@ container_algorithm_internal::ContainerIter c_min_element( // to return an iterator pointing to the element with the largest value, using // `operator<` to make the comparisons. template -container_algorithm_internal::ContainerIter c_max_element( - Sequence& sequence) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 + container_algorithm_internal::ContainerIter + c_max_element(Sequence& sequence) { return std::max_element(container_algorithm_internal::c_begin(sequence), container_algorithm_internal::c_end(sequence)); } @@ -1531,8 +1567,9 @@ container_algorithm_internal::ContainerIter c_max_element( // Overload of c_max_element() for performing a `comp` comparison other than // `operator<`. template -container_algorithm_internal::ContainerIter c_max_element( - Sequence& sequence, LessThan&& comp) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 + container_algorithm_internal::ContainerIter + c_max_element(Sequence& sequence, LessThan&& comp) { return std::max_element(container_algorithm_internal::c_begin(sequence), container_algorithm_internal::c_end(sequence), std::forward(comp)); @@ -1545,8 +1582,9 @@ container_algorithm_internal::ContainerIter c_max_element( // smallest and largest values, respectively, using `operator<` to make the // comparisons. template -container_algorithm_internal::ContainerIterPairType c_minmax_element( - C& c) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 + container_algorithm_internal::ContainerIterPairType + c_minmax_element(C& c) { return std::minmax_element(container_algorithm_internal::c_begin(c), container_algorithm_internal::c_end(c)); } @@ -1554,8 +1592,9 @@ container_algorithm_internal::ContainerIterPairType c_minmax_element( // Overload of c_minmax_element() for performing `comp` comparisons other than // `operator<`. template -container_algorithm_internal::ContainerIterPairType c_minmax_element( - C& c, LessThan&& comp) { +ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 + container_algorithm_internal::ContainerIterPairType + c_minmax_element(C& c, LessThan&& comp) { return std::minmax_element(container_algorithm_internal::c_begin(c), container_algorithm_internal::c_end(c), std::forward(comp)); diff --git a/contrib/restricted/abseil-cpp/absl/algorithm/ya.make b/contrib/restricted/abseil-cpp/absl/algorithm/ya.make index ac5695f0720e..467248d2799d 100644 --- a/contrib/restricted/abseil-cpp/absl/algorithm/ya.make +++ b/contrib/restricted/abseil-cpp/absl/algorithm/ya.make @@ -6,9 +6,9 @@ LICENSE(Apache-2.0) LICENSE_TEXTS(.yandex_meta/licenses.list.txt) -VERSION(20240116.2) +VERSION(20240722.0) -ORIGINAL_SOURCE(https://github.com/abseil/abseil-cpp/archive/20240116.2.tar.gz) +ORIGINAL_SOURCE(https://github.com/abseil/abseil-cpp/archive/20240722.0.tar.gz) NO_RUNTIME() diff --git a/contrib/restricted/abseil-cpp/absl/base/attributes.h b/contrib/restricted/abseil-cpp/absl/base/attributes.h index d4f67a1295c9..5ea5ee3ef8c6 100644 --- a/contrib/restricted/abseil-cpp/absl/base/attributes.h +++ b/contrib/restricted/abseil-cpp/absl/base/attributes.h @@ -195,6 +195,9 @@ // ABSL_ATTRIBUTE_NORETURN // // Tells the compiler that a given function never returns. +// +// Deprecated: Prefer the `[[noreturn]]` attribute standardized by C++11 over +// this macro. #if ABSL_HAVE_ATTRIBUTE(noreturn) || (defined(__GNUC__) && !defined(__clang__)) #define ABSL_ATTRIBUTE_NORETURN __attribute__((noreturn)) #elif defined(_MSC_VER) @@ -702,6 +705,11 @@ _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") #define ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING \ _Pragma("GCC diagnostic pop") +#elif defined(_MSC_VER) +#define ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING \ + _Pragma("warning(push)") _Pragma("warning(disable: 4996)") +#define ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING \ + _Pragma("warning(pop)") #else #define ABSL_INTERNAL_DISABLE_DEPRECATED_DECLARATION_WARNING #define ABSL_INTERNAL_RESTORE_DEPRECATED_DECLARATION_WARNING @@ -808,14 +816,43 @@ // // See also the upstream documentation: // https://clang.llvm.org/docs/AttributeReference.html#lifetimebound +// https://learn.microsoft.com/en-us/cpp/code-quality/c26816?view=msvc-170 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::lifetimebound) #define ABSL_ATTRIBUTE_LIFETIME_BOUND [[clang::lifetimebound]] +#elif ABSL_HAVE_CPP_ATTRIBUTE(msvc::lifetimebound) +#define ABSL_ATTRIBUTE_LIFETIME_BOUND [[msvc::lifetimebound]] #elif ABSL_HAVE_ATTRIBUTE(lifetimebound) #define ABSL_ATTRIBUTE_LIFETIME_BOUND __attribute__((lifetimebound)) #else #define ABSL_ATTRIBUTE_LIFETIME_BOUND #endif +// ABSL_INTERNAL_ATTRIBUTE_VIEW indicates that a type acts like a view i.e. a +// raw (non-owning) pointer. This enables diagnoses similar to those enabled by +// ABSL_ATTRIBUTE_LIFETIME_BOUND. +// +// See the following links for details: +// https://reviews.llvm.org/D64448 +// https://lists.llvm.org/pipermail/cfe-dev/2018-November/060355.html +#if ABSL_HAVE_CPP_ATTRIBUTE(gsl::Pointer) +#define ABSL_INTERNAL_ATTRIBUTE_VIEW [[gsl::Pointer]] +#else +#define ABSL_INTERNAL_ATTRIBUTE_VIEW +#endif + +// ABSL_INTERNAL_ATTRIBUTE_OWNER indicates that a type acts like a smart +// (owning) pointer. This enables diagnoses similar to those enabled by +// ABSL_ATTRIBUTE_LIFETIME_BOUND. +// +// See the following links for details: +// https://reviews.llvm.org/D64448 +// https://lists.llvm.org/pipermail/cfe-dev/2018-November/060355.html +#if ABSL_HAVE_CPP_ATTRIBUTE(gsl::Owner) +#define ABSL_INTERNAL_ATTRIBUTE_OWNER [[gsl::Owner]] +#else +#define ABSL_INTERNAL_ATTRIBUTE_OWNER +#endif + // ABSL_ATTRIBUTE_TRIVIAL_ABI // Indicates that a type is "trivially relocatable" -- meaning it can be // relocated without invoking the constructor/destructor, using a form of move @@ -871,4 +908,51 @@ #define ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS #endif +// ABSL_ATTRIBUTE_UNINITIALIZED +// +// GCC and Clang support a flag `-ftrivial-auto-var-init=