From dfb45be3f66e28d351889669b62e851d23d4307f Mon Sep 17 00:00:00 2001 From: kkm Date: Tue, 15 Jun 2021 21:06:18 -0700 Subject: [PATCH] Import v1.8.1 r1 http://www.openfst.org/twiki/bin/viewfile/FST/FstDownload?filename=openfst-1.8.1.tar.gz;rev=1 --- BUILD.bazel | 41 ++- Makefile.in | 6 +- NEWS | 7 +- README | 8 +- WORKSPACE.bazel | 4 +- aclocal.m4 | 23 +- configure | 100 ++----- configure.ac | 2 +- install-sh | 148 +++++----- ltmain.sh | 277 +++++++----------- m4/libtool.m4 | 55 +--- src/Makefile.in | 2 +- src/bin/Makefile.in | 2 +- src/bin/fstarcsort-main.cc | 6 +- src/bin/fstclosure-main.cc | 2 +- src/bin/fstcompile-main.cc | 27 +- src/bin/fstcompose-main.cc | 7 +- src/bin/fstconvert-main.cc | 5 +- src/bin/fstdeterminize-main.cc | 14 +- src/bin/fstdifference-main.cc | 7 +- src/bin/fstdisambiguate-main.cc | 8 +- src/bin/fstdraw-main.cc | 32 +- src/bin/fstencode-main.cc | 8 +- src/bin/fstepsnormalize-main.cc | 2 +- src/bin/fstequal-main.cc | 2 +- src/bin/fstequivalent-main.cc | 16 +- src/bin/fstinfo-main.cc | 7 +- src/bin/fstintersect-main.cc | 7 +- src/bin/fstisomorphic-main.cc | 2 +- src/bin/fstmap-main.cc | 16 +- src/bin/fstminimize-main.cc | 8 +- src/bin/fstprint-main.cc | 30 +- src/bin/fstproject-main.cc | 4 +- src/bin/fstprune-main.cc | 8 +- src/bin/fstpush-main.cc | 12 +- src/bin/fstrandgen-main.cc | 14 +- src/bin/fstrelabel-main.cc | 48 +-- src/bin/fstreplace-main.cc | 14 +- src/bin/fstreverse-main.cc | 2 +- src/bin/fstreweight-main.cc | 2 +- src/bin/fstrmepsilon-main.cc | 16 +- src/bin/fstshortestdistance-main.cc | 18 +- src/bin/fstshortestpath-main.cc | 15 +- src/bin/fstsymbols-main.cc | 36 +-- src/extensions/Makefile.in | 2 +- src/extensions/compact/Makefile.am | 2 +- src/extensions/compact/Makefile.in | 4 +- src/extensions/compress/Makefile.am | 2 +- src/extensions/compress/Makefile.in | 4 +- src/extensions/compress/fstcompress-main.cc | 4 +- src/extensions/const/Makefile.am | 2 +- src/extensions/const/Makefile.in | 4 +- src/extensions/far/Makefile.am | 4 +- src/extensions/far/Makefile.in | 6 +- src/extensions/far/farcompilestrings-main.cc | 34 ++- src/extensions/far/farconvert-main.cc | 7 +- src/extensions/far/farcreate-main.cc | 13 +- src/extensions/far/farequal-main.cc | 5 +- src/extensions/far/farextract-main.cc | 8 +- src/extensions/far/farinfo-main.cc | 4 +- src/extensions/far/farisomorphic-main.cc | 5 +- src/extensions/far/farprintstrings-main.cc | 23 +- src/extensions/linear/Makefile.am | 2 +- src/extensions/linear/Makefile.in | 4 +- src/extensions/linear/fstlinear-main.cc | 9 +- .../linear/fstloglinearapply-main.cc | 3 +- src/extensions/linear/linearscript.cc | 9 +- src/extensions/lookahead/Makefile.am | 2 +- src/extensions/lookahead/Makefile.in | 4 +- src/extensions/mpdt/Makefile.am | 2 +- src/extensions/mpdt/Makefile.in | 4 +- src/extensions/mpdt/mpdtcompose-main.cc | 14 +- src/extensions/mpdt/mpdtexpand-main.cc | 8 +- src/extensions/mpdt/mpdtinfo-main.cc | 5 +- src/extensions/mpdt/mpdtreverse-main.cc | 10 +- src/extensions/ngram/Makefile.am | 2 +- src/extensions/ngram/Makefile.in | 4 +- src/extensions/ngram/nthbit.cc | 2 +- src/extensions/pdt/Makefile.am | 2 +- src/extensions/pdt/Makefile.in | 4 +- src/extensions/pdt/pdtcompose-main.cc | 15 +- src/extensions/pdt/pdtexpand-main.cc | 13 +- src/extensions/pdt/pdtinfo-main.cc | 5 +- src/extensions/pdt/pdtreplace-main.cc | 17 +- src/extensions/pdt/pdtreverse-main.cc | 5 +- src/extensions/pdt/pdtshortestpath-main.cc | 17 +- src/extensions/python/Makefile.in | 2 +- src/extensions/python/cpywrapfst.pxd | 2 +- src/extensions/python/pywrapfst.cpp | 4 +- src/extensions/python/pywrapfst.pyx | 2 +- src/extensions/special/Makefile.am | 2 +- src/extensions/special/Makefile.in | 4 +- src/include/Makefile.in | 2 +- src/include/fst/accumulator.h | 22 +- src/include/fst/arc-map.h | 3 +- src/include/fst/bi-table.h | 8 +- src/include/fst/cache.h | 12 +- src/include/fst/compact-fst.h | 8 +- src/include/fst/compat.h | 61 +++- src/include/fst/complement.h | 6 +- src/include/fst/compose.h | 4 +- src/include/fst/connect.h | 63 ++-- src/include/fst/const-fst.h | 6 +- src/include/fst/determinize.h | 32 +- src/include/fst/dfs-visit.h | 33 ++- src/include/fst/disambiguate.h | 38 ++- src/include/fst/edit-fst.h | 15 +- src/include/fst/encode.h | 9 +- src/include/fst/equivalent.h | 11 +- src/include/fst/expander-cache.h | 26 +- .../fst/extensions/compress/compress.h | 23 +- src/include/fst/extensions/far/extract.h | 55 ++-- src/include/fst/extensions/far/far-class.h | 6 +- src/include/fst/extensions/far/far.h | 9 +- .../fst/extensions/far/print-strings.h | 6 +- src/include/fst/extensions/far/stlist.h | 3 +- src/include/fst/extensions/far/sttable.h | 5 +- .../fst/extensions/linear/linear-fst.h | 4 +- .../fst/extensions/linear/linearscript.h | 27 +- src/include/fst/extensions/linear/trie.h | 34 +-- src/include/fst/extensions/mpdt/expand.h | 2 +- src/include/fst/extensions/mpdt/mpdt.h | 4 +- .../fst/extensions/mpdt/read_write_utils.h | 6 +- src/include/fst/extensions/ngram/ngram-fst.h | 4 +- src/include/fst/extensions/ngram/nthbit.h | 2 +- src/include/fst/extensions/pdt/expand.h | 2 +- src/include/fst/extensions/special/phi-fst.h | 7 +- src/include/fst/extensions/special/rho-fst.h | 5 +- .../fst/extensions/special/sigma-fst.h | 4 +- src/include/fst/factor-weight.h | 5 +- src/include/fst/flags.h | 34 ++- src/include/fst/fst.h | 15 +- src/include/fst/label-reachable.h | 21 +- src/include/fst/log.h | 2 +- src/include/fst/lookahead-matcher.h | 30 +- src/include/fst/mapped-file.h | 2 +- src/include/fst/matcher.h | 11 +- src/include/fst/memory.h | 39 ++- src/include/fst/minimize.h | 6 +- src/include/fst/prune.h | 30 +- src/include/fst/queue.h | 20 +- src/include/fst/randequivalent.h | 2 +- src/include/fst/randgen.h | 6 +- src/include/fst/rational.h | 2 +- src/include/fst/relabel.h | 3 +- src/include/fst/replace-util.h | 4 +- src/include/fst/replace.h | 5 +- src/include/fst/rmepsilon.h | 15 +- src/include/fst/rmfinalepsilon.h | 2 +- src/include/fst/script/compile-impl.h | 27 +- src/include/fst/script/compile.h | 2 +- src/include/fst/script/convert.h | 2 +- src/include/fst/script/fst-class.h | 8 +- src/include/fst/script/map.h | 34 +-- src/include/fst/script/print.h | 2 +- src/include/fst/script/prune.h | 18 +- src/include/fst/script/shortest-path.h | 20 +- src/include/fst/script/weight-class.h | 7 +- src/include/fst/set-weight.h | 18 +- src/include/fst/shortest-path.h | 19 +- src/include/fst/sparse-tuple-weight.h | 1 - src/include/fst/state-map.h | 4 +- src/include/fst/string-weight.h | 16 +- src/include/fst/string.h | 67 ++--- src/include/fst/symbol-table-ops.h | 2 +- src/include/fst/symbol-table.h | 112 +++---- src/include/fst/synchronize.h | 127 ++++---- src/include/fst/test-properties.h | 14 +- src/include/fst/test/algo_test.h | 151 +++++----- src/include/fst/test/compactors.h | 2 +- src/include/fst/test/fst_test.h | 5 +- src/include/fst/topsort.h | 15 +- src/include/fst/util.h | 33 ++- src/include/fst/vector-fst.h | 4 +- src/include/fst/weight.h | 8 +- src/lib/Makefile.am | 2 +- src/lib/Makefile.in | 4 +- src/lib/flags.cc | 4 +- src/lib/fst.cc | 4 +- src/lib/mapped-file.cc | 10 +- src/lib/symbol-table.cc | 47 +-- src/lib/util.cc | 61 ++-- src/lib/weight.cc | 29 +- src/script/Makefile.am | 2 +- src/script/Makefile.in | 4 +- src/script/print.cc | 2 +- src/script/text-io.cc | 6 +- src/script/weight-class.cc | 4 +- src/test/Makefile.in | 5 +- src/test/algo_test.cc | 52 ++-- src/test/fst_test.cc | 2 +- src/test/weight_test.cc | 123 ++++---- test-driver | 8 +- 193 files changed, 1608 insertions(+), 1681 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 76b4783..4ba1eab 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") + package(default_visibility = ["//visibility:public"]) licenses(["notice"]) # Apache 2.0 @@ -23,6 +25,11 @@ config_setting( values = {"define": "absl=1"}, ) +DEFINES = select({ + "@bazel_tools//src/conditions:windows": ["FST_NO_DYNAMIC_LINKING"], + "//conditions:default": [], +}) + prefix_dir = "src/" static_binary = 1 @@ -130,6 +137,7 @@ cc_library( ], hdrs = PUBLIC_HEADERS, copts = ["-Wno-sign-compare"], + defines = DEFINES, includes = [prefix_dir + "include"], linkopts = ["-lm"], deps = [ @@ -148,6 +156,7 @@ cc_library( cc_library( name = "fst", hdrs = PUBLIC_HEADERS, + defines = DEFINES, includes = [prefix_dir + "include"], deps = [ ":fst-types", @@ -164,6 +173,7 @@ cc_library( cc_library( name = "fst-types", srcs = [prefix_dir + "lib/fst-types.cc"], + defines = DEFINES, deps = [":lib_lite"], alwayslink = 1, # because of registration ) @@ -171,11 +181,9 @@ cc_library( cc_library( name = "symbol-table", srcs = [prefix_dir + "lib/symbol-table.cc"], - hdrs = [ - prefix_dir + "include/fst/symbol-table.h", - prefix_dir + "include/fst/windows_defs.inc", - ], + hdrs = [prefix_dir + "include/fst/symbol-table.h"], copts = ["-Wno-sign-compare"], + defines = DEFINES, includes = [prefix_dir + "include"], deps = [ ":base", @@ -203,6 +211,7 @@ cc_library( prefix_dir + "include/fst/union-weight.h", prefix_dir + "include/fst/weight.h", ], + defines = DEFINES, includes = [prefix_dir + "include"], linkopts = ["-lm"], deps = [ @@ -277,6 +286,7 @@ cc_library( prefix_dir + "include/fst/lock.h", prefix_dir + "include/fst/log.h", prefix_dir + "include/fst/types.h", + prefix_dir + "include/fst/windows_defs.inc", ], defines = select({ ":has_absl": ["OPENFST_HAS_ABSL=1"], @@ -284,7 +294,7 @@ cc_library( }), includes = [prefix_dir + "include"], deps = select({ - ":has_absl": ["@io_abseil_cpp//absl/synchronization"], + ":has_absl": ["@com_google_absl//absl/synchronization"], "//conditions:default": [], }), ) @@ -713,7 +723,6 @@ cc_binary( deps = [":fstscript_verify"], ) - # Extension: Fst ARchive a/k/a FAR (extensions/far/) cc_library( @@ -971,7 +980,7 @@ cc_library( cc_library( name = "%s-fst" % type, srcs = [ - prefix_dir + "extensions/compact/%s-fst.cc" % type + prefix_dir + "extensions/compact/%s-fst.cc" % type, ], linkstatic = 1, deps = [":fst"], @@ -1041,7 +1050,7 @@ cc_binary( cc_library( name = "const%s-fst" % type, srcs = [ - prefix_dir + "extensions/const/const%s-fst.cc" % type + prefix_dir + "extensions/const/const%s-fst.cc" % type, ], linkstatic = 1, deps = [":fst"], @@ -1057,6 +1066,10 @@ cc_binary( cc_library( name = "linear-fst", + srcs = [ + prefix_dir + "extensions/linear/linear-classifier-fst.cc", + prefix_dir + "extensions/linear/linear-tagger-fst.cc", + ], hdrs = [ prefix_dir + "include/fst/extensions/linear/linear-fst-data-builder.h", prefix_dir + "include/fst/extensions/linear/linear-fst-data.h", @@ -1064,10 +1077,6 @@ cc_library( prefix_dir + "include/fst/extensions/linear/loglinear-apply.h", prefix_dir + "include/fst/extensions/linear/trie.h", ], - srcs = [ - prefix_dir + "extensions/linear/linear-classifier-fst.cc", - prefix_dir + "extensions/linear/linear-tagger-fst.cc", - ], linkstatic = 1, deps = [ ":fst", @@ -1085,8 +1094,8 @@ cc_library( includes = [prefix_dir + "include"], deps = [ ":base", - ":linear-fst", ":fstscript_base", + ":linear-fst", ], ) @@ -1112,7 +1121,7 @@ cc_library( cc_library( name = "%s_lookahead-fst" % type, srcs = [ - prefix_dir + "extensions/lookahead/%s_lookahead-fst.cc" % type + prefix_dir + "extensions/lookahead/%s_lookahead-fst.cc" % type, ], linkstatic = 1, deps = [":fst"], @@ -1130,10 +1139,10 @@ cc_library( cc_library( name = "%s-fst" % type, srcs = [ - prefix_dir + "include/fst/extensions/special/%s-fst.h" % type + prefix_dir + "include/fst/extensions/special/%s-fst.h" % type, ], hdrs = [ - prefix_dir + "extensions/special/%s-fst.cc" % type + prefix_dir + "extensions/special/%s-fst.cc" % type, ], linkstatic = 1, deps = [":fst"], diff --git a/Makefile.in b/Makefile.in index d8cc6f7..2e5456b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2020 Free Software Foundation, Inc. @@ -202,6 +202,8 @@ am__relativize = \ DIST_ARCHIVES = $(distdir).tar.gz GZIP_ENV = --best DIST_TARGETS = dist-gzip +# Exists only to be overridden by the user if desired. +AM_DISTCHECK_DVI_TARGET = dvi distuninstallcheck_listfiles = find . -type f -print am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \ | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$' @@ -668,7 +670,7 @@ distcheck: dist $(DISTCHECK_CONFIGURE_FLAGS) \ --srcdir=../.. --prefix="$$dc_install_base" \ && $(MAKE) $(AM_MAKEFLAGS) \ - && $(MAKE) $(AM_MAKEFLAGS) dvi \ + && $(MAKE) $(AM_MAKEFLAGS) $(AM_DISTCHECK_DVI_TARGET) \ && $(MAKE) $(AM_MAKEFLAGS) check \ && $(MAKE) $(AM_MAKEFLAGS) install \ && $(MAKE) $(AM_MAKEFLAGS) installcheck \ diff --git a/NEWS b/NEWS index 80bd55c..5dda925 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,7 @@ -OpenFst: Release 1.7 +OpenFst: Release 1.8 + * Expands smart-pointer use (1.8.1) + * Expands std::string_view use (1.8.1) + * Removes SymbolTableReadOptions (1.8.1) * Adds farconvert (1.8.0) * Migration to C++17 (1.8.0) * Updates Bazel build (1.8.0) @@ -7,6 +10,8 @@ OpenFst: Release 1.7 * Improves display of properties masks in pywrapfst (1.8.0) * Internal reference-counting/smart pointer improvements (1.8.0) * Deprecates PROJECT_(IN|OUT)PUT in favor of scoped enum ProjectType (1.8.0) + +OpenFst: Release 1.7 * TokenType is now a scoped enum (1.7.8) * pywrapfst is now Python 3-only (1.7.8) * fstproject now has --project_type flag (1.7.8) diff --git a/README b/README index 2441cce..d5ff9ad 100644 --- a/README +++ b/README @@ -2,11 +2,11 @@ OpenFst is a library for constructing, combining, optimizing, and searching weighted finite-state transducers (FSTs). REQUIREMENTS: - This version is known to work under Linux using g++ (>= 7) and OS X using - XCode (>= 9). It is expected to work wherever adequate POSIX (dlopen, + This version is known to work under Linux using g++ (>= 4.9) and OS X using + XCode (>= 5). It is expected to work wherever adequate POSIX (dlopen, ssize_t, basename), C99 (snprintf, strtoll, ), and C++17 - (, , , constexpr-if) support - is available. + (constexpr-if, , , , + ) support is available. INSTALLATION: Follow the generic GNU build system instructions in ./INSTALL. We diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 2c92a2d..768503b 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -19,7 +19,9 @@ workspace(name = "openfst") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( - name = "io_abseil_cpp", + # Name has to match workspace name in: + # https://github.com/abseil/abseil-cpp/blob/master/WORKSPACE + name = "com_google_absl", strip_prefix = "abseil-cpp-master", urls = ["https://github.com/abseil/abseil-cpp/archive/master.zip"], ) diff --git a/aclocal.m4 b/aclocal.m4 index eab6f94..f7d7d3e 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1,4 +1,4 @@ -# generated automatically by aclocal 1.16.2 -*- Autoconf -*- +# generated automatically by aclocal 1.16.3 -*- Autoconf -*- # Copyright (C) 1996-2020 Free Software Foundation, Inc. @@ -35,7 +35,7 @@ AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version='1.16' dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to dnl require some minimum version. Point them to the right macro. -m4_if([$1], [1.16.2], [], +m4_if([$1], [1.16.3], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) @@ -51,7 +51,7 @@ m4_define([_AM_AUTOCONF_VERSION], []) # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE. AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], -[AM_AUTOMAKE_VERSION([1.16.2])dnl +[AM_AUTOMAKE_VERSION([1.16.3])dnl m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) @@ -763,12 +763,7 @@ AC_DEFUN([AM_MISSING_HAS_RUN], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl AC_REQUIRE_AUX_FILE([missing])dnl if test x"${MISSING+set}" != xset; then - case $am_aux_dir in - *\ * | *\ *) - MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; - *) - MISSING="\${SHELL} $am_aux_dir/missing" ;; - esac + MISSING="\${SHELL} '$am_aux_dir/missing'" fi # Use eval to expand $SHELL if eval "$MISSING --is-lightweight"; then @@ -940,12 +935,14 @@ AC_DEFUN([AM_PATH_PYTHON], m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])]) else - dnl Query Python for its version number. Getting [:3] seems to be - dnl the best way to do this; it's what "site.py" does in the standard - dnl library. + dnl Query Python for its version number. Although site.py simply uses + dnl sys.version[:3], printing that failed with Python 3.10, since the + dnl trailing zero was eliminated. So now we output just the major + dnl and minor version numbers, as numbers. Apparently the tertiary + dnl version is not of interest. AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version], - [am_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[[:3]])"`]) + [am_cv_python_version=`$PYTHON -c "import sys; print('%u.%u' % sys.version_info[[:2]])"`]) AC_SUBST([PYTHON_VERSION], [$am_cv_python_version]) dnl Use the values of $prefix and $exec_prefix for the corresponding diff --git a/configure b/configure index fe3d500..c0f5f80 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for OpenFst 1.8.0. +# Generated by GNU Autoconf 2.69 for OpenFst 1.8.1. # # Report bugs to . # @@ -590,8 +590,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='OpenFst' PACKAGE_TARNAME='openfst' -PACKAGE_VERSION='1.8.0' -PACKAGE_STRING='OpenFst 1.8.0' +PACKAGE_VERSION='1.8.1' +PACKAGE_STRING='OpenFst 1.8.1' PACKAGE_BUGREPORT='help@www.openfst.org' PACKAGE_URL='' @@ -1398,7 +1398,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures OpenFst 1.8.0 to adapt to many kinds of systems. +\`configure' configures OpenFst 1.8.1 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1469,7 +1469,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of OpenFst 1.8.0:";; + short | recursive ) echo "Configuration of OpenFst 1.8.1:";; esac cat <<\_ACEOF @@ -1602,7 +1602,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -OpenFst configure 1.8.0 +OpenFst configure 1.8.1 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2043,7 +2043,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by OpenFst $as_me 1.8.0, which was +It was created by OpenFst $as_me 1.8.1, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2596,12 +2596,7 @@ program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` am_aux_dir=`cd "$ac_aux_dir" && pwd` if test x"${MISSING+set}" != xset; then - case $am_aux_dir in - *\ * | *\ *) - MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; - *) - MISSING="\${SHELL} $am_aux_dir/missing" ;; - esac + MISSING="\${SHELL} '$am_aux_dir/missing'" fi # Use eval to expand $SHELL if eval "$MISSING --is-lightweight"; then @@ -2906,7 +2901,7 @@ fi # Define the identity of the package. PACKAGE='openfst' - VERSION='1.8.0' + VERSION='1.8.1' cat >>confdefs.h <<_ACEOF @@ -5940,7 +5935,7 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) lt_cv_deplibs_check_method=pass_all ;; -netbsd* | netbsdelf*-gnu) +netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' else @@ -6302,7 +6297,7 @@ esac fi : ${AR=ar} -: ${AR_FLAGS=cr} +: ${AR_FLAGS=cru} @@ -6803,8 +6798,11 @@ _LT_EOF test $ac_status = 0; }; then # Now try to grab the symbols. nlist=conftest.nm - $ECHO "$as_me:$LINENO: $NM conftest.$ac_objext | $lt_cv_sys_global_symbol_pipe > $nlist" >&5 - if eval "$NM" conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist 2>&5 && test -s "$nlist"; then + if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist\""; } >&5 + (eval $NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && test -s "$nlist"; then # Try sorting and uniquifying the output. if sort "$nlist" | uniq > "$nlist"T; then mv -f "$nlist"T "$nlist" @@ -8023,8 +8021,8 @@ int forced_loaded() { return 2;} _LT_EOF echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&5 $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&5 - echo "$AR cr libconftest.a conftest.o" >&5 - $AR cr libconftest.a conftest.o 2>&5 + echo "$AR cru libconftest.a conftest.o" >&5 + $AR cru libconftest.a conftest.o 2>&5 echo "$RANLIB libconftest.a" >&5 $RANLIB libconftest.a 2>&5 cat > conftest.c << _LT_EOF @@ -9134,12 +9132,6 @@ lt_prog_compiler_static= lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-static' ;; - # flang / f18. f95 an alias for gfortran or flang on Debian - flang* | f18* | f95*) - lt_prog_compiler_wl='-Wl,' - lt_prog_compiler_pic='-fPIC' - lt_prog_compiler_static='-static' - ;; # icc used to be incompatible with GCC. # ICC 10 doesn't accept -KPIC any more. icc* | ifort*) @@ -9616,9 +9608,6 @@ $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie openbsd* | bitrig*) with_gnu_ld=no ;; - linux* | k*bsd*-gnu | gnu*) - link_all_deplibs=no - ;; esac ld_shlibs=yes @@ -9873,7 +9862,7 @@ _LT_EOF fi ;; - netbsd* | netbsdelf*-gnu) + netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' wlarc= @@ -10543,7 +10532,6 @@ $as_echo "$lt_cv_irix_exported_symbol" >&6; } if test yes = "$lt_cv_irix_exported_symbol"; then archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib' fi - link_all_deplibs=no else archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib' @@ -10565,7 +10553,7 @@ $as_echo "$lt_cv_irix_exported_symbol" >&6; } esac ;; - netbsd* | netbsdelf*-gnu) + netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out else @@ -11680,18 +11668,6 @@ fi dynamic_linker='GNU/Linux ld.so' ;; -netbsdelf*-gnu) - version_type=linux - need_lib_prefix=no - need_version=no - library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' - soname_spec='${libname}${release}${shared_ext}$major' - shlibpath_var=LD_LIBRARY_PATH - shlibpath_overrides_runpath=no - hardcode_into_libs=yes - dynamic_linker='NetBSD ld.elf_so' - ;; - netbsd*) version_type=sunos need_lib_prefix=no @@ -13082,7 +13058,7 @@ with_gnu_ld=$lt_cv_prog_gnu_ld # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' else GXX=no @@ -13574,7 +13550,7 @@ fi # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. - output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then @@ -13639,7 +13615,7 @@ fi # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. - output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then @@ -13978,7 +13954,7 @@ fi # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' else # FIXME: insert proper C++ library support @@ -14062,7 +14038,7 @@ fi # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' else # g++ 2.7 appears to require '-G' NOT '-shared' on this # platform. @@ -14073,7 +14049,7 @@ fi # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' fi hardcode_libdir_flag_spec_CXX='$wl-R $wl$libdir' @@ -14586,7 +14562,7 @@ lt_prog_compiler_static_CXX= ;; esac ;; - netbsd* | netbsdelf*-gnu) + netbsd*) ;; *qnx* | *nto*) # QNX uses GNU C++, but need to define -shared option too, otherwise @@ -14961,9 +14937,6 @@ $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie ;; esac ;; - linux* | k*bsd*-gnu | gnu*) - link_all_deplibs_CXX=no - ;; *) export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' ;; @@ -15657,18 +15630,6 @@ fi dynamic_linker='GNU/Linux ld.so' ;; -netbsdelf*-gnu) - version_type=linux - need_lib_prefix=no - need_version=no - library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' - soname_spec='${libname}${release}${shared_ext}$major' - shlibpath_var=LD_LIBRARY_PATH - shlibpath_overrides_runpath=no - hardcode_into_libs=yes - dynamic_linker='NetBSD ld.elf_so' - ;; - netbsd*) version_type=sunos need_lib_prefix=no @@ -16314,7 +16275,7 @@ $as_echo_n "checking for $am_display_PYTHON version... " >&6; } if ${am_cv_python_version+:} false; then : $as_echo_n "(cached) " >&6 else - am_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[:3])"` + am_cv_python_version=`$PYTHON -c "import sys; print('%u.%u' % sys.version_info[:2])"` fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_python_version" >&5 $as_echo "$am_cv_python_version" >&6; } @@ -17584,7 +17545,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by OpenFst $as_me 1.8.0, which was +This file was extended by OpenFst $as_me 1.8.1, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -17650,7 +17611,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -OpenFst config.status 1.8.0 +OpenFst config.status 1.8.1 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" @@ -18889,6 +18850,7 @@ See \`config.log' for more details" "$LINENO" 5; } cat <<_LT_EOF >> "$cfgfile" #! $SHELL # Generated automatically by $as_me ($PACKAGE) $VERSION +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # Provide generalized library-building support services. diff --git a/configure.ac b/configure.ac index 02cbf35..54d332a 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([OpenFst], [1.8.0], [help@www.openfst.org]) +AC_INIT([OpenFst], [1.8.1], [help@www.openfst.org]) AM_INIT_AUTOMAKE([foreign nostdinc -Wall -Werror subdir-objects]) AM_PROG_AR diff --git a/install-sh b/install-sh index 20d8b2e..ec298b5 100755 --- a/install-sh +++ b/install-sh @@ -1,7 +1,7 @@ #!/bin/sh # install - install a program, script, or datafile -scriptversion=2018-03-11.20; # UTC +scriptversion=2020-11-14.01; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the @@ -69,6 +69,11 @@ posix_mkdir= # Desired mode of installed file. mode=0755 +# Create dirs (including intermediate dirs) using mode 755. +# This is like GNU 'install' as of coreutils 8.32 (2020). +mkdir_umask=22 + +backupsuffix= chgrpcmd= chmodcmd=$chmodprog chowncmd= @@ -99,18 +104,28 @@ Options: --version display version info and exit. -c (ignored) - -C install only if different (preserve the last data modification time) + -C install only if different (preserve data modification time) -d create directories instead of installing files. -g GROUP $chgrpprog installed files to GROUP. -m MODE $chmodprog installed files to MODE. -o USER $chownprog installed files to USER. + -p pass -p to $cpprog. -s $stripprog installed files. + -S SUFFIX attempt to back up existing files, with suffix SUFFIX. -t DIRECTORY install into DIRECTORY. -T report an error if DSTFILE is a directory. Environment variables override the default commands: CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG + +By default, rm is invoked with -f; when overridden with RMPROG, +it's up to you to specify -f if you want it. + +If -S is not specified, no backups are attempted. + +Email bug reports to bug-automake@gnu.org. +Automake home page: https://www.gnu.org/software/automake/ " while test $# -ne 0; do @@ -137,8 +152,13 @@ while test $# -ne 0; do -o) chowncmd="$chownprog $2" shift;; + -p) cpprog="$cpprog -p";; + -s) stripcmd=$stripprog;; + -S) backupsuffix="$2" + shift;; + -t) is_target_a_directory=always dst_arg=$2 @@ -255,6 +275,10 @@ do dstdir=$dst test -d "$dstdir" dstdir_status=$? + # Don't chown directories that already exist. + if test $dstdir_status = 0; then + chowncmd="" + fi else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command @@ -301,22 +325,6 @@ do if test $dstdir_status != 0; then case $posix_mkdir in '') - # Create intermediate dirs using mode 755 as modified by the umask. - # This is like FreeBSD 'install' as of 1997-10-28. - umask=`umask` - case $stripcmd.$umask in - # Optimize common cases. - *[2367][2367]) mkdir_umask=$umask;; - .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; - - *[0-7]) - mkdir_umask=`expr $umask + 22 \ - - $umask % 100 % 40 + $umask % 20 \ - - $umask % 10 % 4 + $umask % 2 - `;; - *) mkdir_umask=$umask,go-w;; - esac - # With -d, create the new directory with the user-specified mode. # Otherwise, rely on $mkdir_umask. if test -n "$dir_arg"; then @@ -326,52 +334,49 @@ do fi posix_mkdir=false - case $umask in - *[123567][0-7][0-7]) - # POSIX mkdir -p sets u+wx bits regardless of umask, which - # is incompatible with FreeBSD 'install' when (umask & 300) != 0. - ;; - *) - # Note that $RANDOM variable is not portable (e.g. dash); Use it - # here however when possible just to lower collision chance. - tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ - - trap 'ret=$?; rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null; exit $ret' 0 - - # Because "mkdir -p" follows existing symlinks and we likely work - # directly in world-writeable /tmp, make sure that the '$tmpdir' - # directory is successfully created first before we actually test - # 'mkdir -p' feature. - if (umask $mkdir_umask && - $mkdirprog $mkdir_mode "$tmpdir" && - exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 - then - if test -z "$dir_arg" || { - # Check for POSIX incompatibilities with -m. - # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or - # other-writable bit of parent directory when it shouldn't. - # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. - test_tmpdir="$tmpdir/a" - ls_ld_tmpdir=`ls -ld "$test_tmpdir"` - case $ls_ld_tmpdir in - d????-?r-*) different_mode=700;; - d????-?--*) different_mode=755;; - *) false;; - esac && - $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { - ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` - test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" - } - } - then posix_mkdir=: - fi - rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" - else - # Remove any dirs left behind by ancient mkdir implementations. - rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null - fi - trap '' 0;; - esac;; + # The $RANDOM variable is not portable (e.g., dash). Use it + # here however when possible just to lower collision chance. + tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ + + trap ' + ret=$? + rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null + exit $ret + ' 0 + + # Because "mkdir -p" follows existing symlinks and we likely work + # directly in world-writeable /tmp, make sure that the '$tmpdir' + # directory is successfully created first before we actually test + # 'mkdir -p'. + if (umask $mkdir_umask && + $mkdirprog $mkdir_mode "$tmpdir" && + exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 + then + if test -z "$dir_arg" || { + # Check for POSIX incompatibilities with -m. + # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or + # other-writable bit of parent directory when it shouldn't. + # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. + test_tmpdir="$tmpdir/a" + ls_ld_tmpdir=`ls -ld "$test_tmpdir"` + case $ls_ld_tmpdir in + d????-?r-*) different_mode=700;; + d????-?--*) different_mode=755;; + *) false;; + esac && + $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { + ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` + test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" + } + } + then posix_mkdir=: + fi + rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" + else + # Remove any dirs left behind by ancient mkdir implementations. + rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null + fi + trap '' 0;; esac if @@ -382,7 +387,7 @@ do then : else - # The umask is ridiculous, or mkdir does not conform to POSIX, + # mkdir does not conform to POSIX, # or it failed possibly due to a race condition. Create the # directory the slow way, step by step, checking for races as we go. @@ -411,7 +416,7 @@ do prefixes= else if $posix_mkdir; then - (umask=$mkdir_umask && + (umask $mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break # Don't fail if two instances are running concurrently. test -d "$prefix" || exit 1 @@ -488,6 +493,13 @@ do then rm -f "$dsttmp" else + # If $backupsuffix is set, and the file being installed + # already exists, attempt a backup. Don't worry if it fails, + # e.g., if mv doesn't support -f. + if test -n "$backupsuffix" && test -f "$dst"; then + $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null + fi + # Rename the file to the real destination. $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || @@ -502,9 +514,9 @@ do # file should still install successfully. { test ! -f "$dst" || - $doit $rmcmd -f "$dst" 2>/dev/null || + $doit $rmcmd "$dst" 2>/dev/null || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && - { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } + { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } } || { echo "$0: cannot unlink or rename $dst" >&2 (exit 1); exit 1 diff --git a/ltmain.sh b/ltmain.sh index 0cb7f90..b6f1800 100644 --- a/ltmain.sh +++ b/ltmain.sh @@ -31,7 +31,7 @@ PROGRAM=libtool PACKAGE=libtool -VERSION="2.4.6 Debian-2.4.6-14" +VERSION=2.4.6 package_revision=2.4.6 @@ -387,7 +387,7 @@ EXIT_SKIP=77 # $? = 77 is used to indicate a skipped test to automake. # putting '$debug_cmd' at the start of all your functions, you can get # bash to show function call trace with: # -# debug_cmd='echo "${FUNCNAME[0]} $*" >&2' bash your-script-name +# debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name debug_cmd=${debug_cmd-":"} exit_cmd=: @@ -1370,7 +1370,7 @@ func_lt_ver () #! /bin/sh # Set a version string for this script. -scriptversion=2015-10-07.11; # UTC +scriptversion=2014-01-07.03; # UTC # A portable, pluggable option parser for Bourne shell. # Written by Gary V. Vaughan, 2010 @@ -1530,8 +1530,6 @@ func_run_hooks () { $debug_cmd - _G_rc_run_hooks=false - case " $hookable_fns " in *" $1 "*) ;; *) func_fatal_error "'$1' does not support hook funcions.n" ;; @@ -1540,16 +1538,16 @@ func_run_hooks () eval _G_hook_fns=\$$1_hooks; shift for _G_hook in $_G_hook_fns; do - if eval $_G_hook '"$@"'; then - # store returned options list back into positional - # parameters for next 'cmd' execution. - eval _G_hook_result=\$${_G_hook}_result - eval set dummy "$_G_hook_result"; shift - _G_rc_run_hooks=: - fi + eval $_G_hook '"$@"' + + # store returned options list back into positional + # parameters for next 'cmd' execution. + eval _G_hook_result=\$${_G_hook}_result + eval set dummy "$_G_hook_result"; shift done - $_G_rc_run_hooks && func_run_hooks_result=$_G_hook_result + func_quote_for_eval ${1+"$@"} + func_run_hooks_result=$func_quote_for_eval_result } @@ -1559,16 +1557,10 @@ func_run_hooks () ## --------------- ## # In order to add your own option parsing hooks, you must accept the -# full positional parameter list in your hook function, you may remove/edit -# any options that you action, and then pass back the remaining unprocessed +# full positional parameter list in your hook function, remove any +# options that you action, and then pass back the remaining unprocessed # options in '_result', escaped suitably for -# 'eval'. In this case you also must return $EXIT_SUCCESS to let the -# hook's caller know that it should pay attention to -# '_result'. Returning $EXIT_FAILURE signalizes that -# arguments are left untouched by the hook and therefore caller will ignore the -# result variable. -# -# Like this: +# 'eval'. Like this: # # my_options_prep () # { @@ -1578,11 +1570,9 @@ func_run_hooks () # usage_message=$usage_message' # -s, --silent don'\''t print informational messages # ' -# # No change in '$@' (ignored completely by this hook). There is -# # no need to do the equivalent (but slower) action: -# # func_quote_for_eval ${1+"$@"} -# # my_options_prep_result=$func_quote_for_eval_result -# false +# +# func_quote_for_eval ${1+"$@"} +# my_options_prep_result=$func_quote_for_eval_result # } # func_add_hook func_options_prep my_options_prep # @@ -1591,37 +1581,25 @@ func_run_hooks () # { # $debug_cmd # -# args_changed=false -# # # Note that for efficiency, we parse as many options as we can # # recognise in a loop before passing the remainder back to the # # caller on the first unrecognised argument we encounter. # while test $# -gt 0; do # opt=$1; shift # case $opt in -# --silent|-s) opt_silent=: -# args_changed=: -# ;; +# --silent|-s) opt_silent=: ;; # # Separate non-argument short options: # -s*) func_split_short_opt "$_G_opt" # set dummy "$func_split_short_opt_name" \ # "-$func_split_short_opt_arg" ${1+"$@"} # shift -# args_changed=: # ;; -# *) # Make sure the first unrecognised option "$_G_opt" -# # is added back to "$@", we could need that later -# # if $args_changed is true. -# set dummy "$_G_opt" ${1+"$@"}; shift; break ;; +# *) set dummy "$_G_opt" "$*"; shift; break ;; # esac # done # -# if $args_changed; then -# func_quote_for_eval ${1+"$@"} -# my_silent_option_result=$func_quote_for_eval_result -# fi -# -# $args_changed +# func_quote_for_eval ${1+"$@"} +# my_silent_option_result=$func_quote_for_eval_result # } # func_add_hook func_parse_options my_silent_option # @@ -1633,32 +1611,16 @@ func_run_hooks () # $opt_silent && $opt_verbose && func_fatal_help "\ # '--silent' and '--verbose' options are mutually exclusive." # -# false +# func_quote_for_eval ${1+"$@"} +# my_option_validation_result=$func_quote_for_eval_result # } # func_add_hook func_validate_options my_option_validation # -# You'll also need to manually amend $usage_message to reflect the extra +# You'll alse need to manually amend $usage_message to reflect the extra # options you parse. It's preferable to append if you can, so that # multiple option parsing hooks can be added safely. -# func_options_finish [ARG]... -# ---------------------------- -# Finishing the option parse loop (call 'func_options' hooks ATM). -func_options_finish () -{ - $debug_cmd - - _G_func_options_finish_exit=false - if func_run_hooks func_options ${1+"$@"}; then - func_options_finish_result=$func_run_hooks_result - _G_func_options_finish_exit=: - fi - - $_G_func_options_finish_exit -} - - # func_options [ARG]... # --------------------- # All the functions called inside func_options are hookable. See the @@ -1668,28 +1630,17 @@ func_options () { $debug_cmd - _G_rc_options=false + func_options_prep ${1+"$@"} + eval func_parse_options \ + ${func_options_prep_result+"$func_options_prep_result"} + eval func_validate_options \ + ${func_parse_options_result+"$func_parse_options_result"} - for my_func in options_prep parse_options validate_options options_finish - do - if eval func_$my_func '${1+"$@"}'; then - eval _G_res_var='$'"func_${my_func}_result" - eval set dummy "$_G_res_var" ; shift - _G_rc_options=: - fi - done - - # Save modified positional parameters for caller. As a top-level - # options-parser function we always need to set the 'func_options_result' - # variable (regardless the $_G_rc_options value). - if $_G_rc_options; then - func_options_result=$_G_res_var - else - func_quote_for_eval ${1+"$@"} - func_options_result=$func_quote_for_eval_result - fi + eval func_run_hooks func_options \ + ${func_validate_options_result+"$func_validate_options_result"} - $_G_rc_options + # save modified positional parameters for caller + func_options_result=$func_run_hooks_result } @@ -1698,9 +1649,9 @@ func_options () # All initialisations required before starting the option parse loop. # Note that when calling hook functions, we pass through the list of # positional parameters. If a hook function modifies that list, and -# needs to propagate that back to rest of this script, then the complete +# needs to propogate that back to rest of this script, then the complete # modified list must be put in 'func_run_hooks_result' before -# returning $EXIT_SUCCESS (otherwise $EXIT_FAILURE is returned). +# returning. func_hookable func_options_prep func_options_prep () { @@ -1710,14 +1661,10 @@ func_options_prep () opt_verbose=false opt_warning_types= - _G_rc_options_prep=false - if func_run_hooks func_options_prep ${1+"$@"}; then - _G_rc_options_prep=: - # save modified positional parameters for caller - func_options_prep_result=$func_run_hooks_result - fi + func_run_hooks func_options_prep ${1+"$@"} - $_G_rc_options_prep + # save modified positional parameters for caller + func_options_prep_result=$func_run_hooks_result } @@ -1731,20 +1678,18 @@ func_parse_options () func_parse_options_result= - _G_rc_parse_options=false # this just eases exit handling while test $# -gt 0; do # Defer to hook functions for initial option parsing, so they # get priority in the event of reusing an option name. - if func_run_hooks func_parse_options ${1+"$@"}; then - eval set dummy "$func_run_hooks_result"; shift - _G_rc_parse_options=: - fi + func_run_hooks func_parse_options ${1+"$@"} + + # Adjust func_parse_options positional parameters to match + eval set dummy "$func_run_hooks_result"; shift # Break out of the loop if we already parsed every option. test $# -gt 0 || break - _G_match_parse_options=: _G_opt=$1 shift case $_G_opt in @@ -1759,10 +1704,7 @@ func_parse_options () ;; --warnings|--warning|-W) - if test $# = 0 && func_missing_arg $_G_opt; then - _G_rc_parse_options=: - break - fi + test $# = 0 && func_missing_arg $_G_opt && break case " $warning_categories $1" in *" $1 "*) # trailing space prevents matching last $1 above @@ -1815,25 +1757,15 @@ func_parse_options () shift ;; - --) _G_rc_parse_options=: ; break ;; + --) break ;; -*) func_fatal_help "unrecognised option: '$_G_opt'" ;; - *) set dummy "$_G_opt" ${1+"$@"}; shift - _G_match_parse_options=false - break - ;; + *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;; esac - - $_G_match_parse_options && _G_rc_parse_options=: done - - if $_G_rc_parse_options; then - # save modified positional parameters for caller - func_quote_for_eval ${1+"$@"} - func_parse_options_result=$func_quote_for_eval_result - fi - - $_G_rc_parse_options + # save modified positional parameters for caller + func_quote_for_eval ${1+"$@"} + func_parse_options_result=$func_quote_for_eval_result } @@ -1846,21 +1778,16 @@ func_validate_options () { $debug_cmd - _G_rc_validate_options=false - # Display all warnings if -W was not given. test -n "$opt_warning_types" || opt_warning_types=" $warning_categories" - if func_run_hooks func_validate_options ${1+"$@"}; then - # save modified positional parameters for caller - func_validate_options_result=$func_run_hooks_result - _G_rc_validate_options=: - fi + func_run_hooks func_validate_options ${1+"$@"} # Bail if the options were screwed! $exit_cmd $EXIT_FAILURE - $_G_rc_validate_options + # save modified positional parameters for caller + func_validate_options_result=$func_run_hooks_result } @@ -2141,12 +2068,12 @@ include the following information: compiler: $LTCC compiler flags: $LTCFLAGS linker: $LD (gnu? $with_gnu_ld) - version: $progname $scriptversion Debian-2.4.6-14 + version: $progname (GNU libtool) 2.4.6 automake: `($AUTOMAKE --version) 2>/dev/null |$SED 1q` autoconf: `($AUTOCONF --version) 2>/dev/null |$SED 1q` Report bugs to . -GNU libtool home page: . +GNU libtool home page: . General help using GNU software: ." exit 0 } @@ -2343,8 +2270,6 @@ libtool_options_prep () nonopt= preserve_args= - _G_rc_lt_options_prep=: - # Shorthand for --mode=foo, only valid as the first argument case $1 in clean|clea|cle|cl) @@ -2368,18 +2293,11 @@ libtool_options_prep () uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u) shift; set dummy --mode uninstall ${1+"$@"}; shift ;; - *) - _G_rc_lt_options_prep=false - ;; esac - if $_G_rc_lt_options_prep; then - # Pass back the list of options. - func_quote_for_eval ${1+"$@"} - libtool_options_prep_result=$func_quote_for_eval_result - fi - - $_G_rc_lt_options_prep + # Pass back the list of options. + func_quote_for_eval ${1+"$@"} + libtool_options_prep_result=$func_quote_for_eval_result } func_add_hook func_options_prep libtool_options_prep @@ -2391,12 +2309,9 @@ libtool_parse_options () { $debug_cmd - _G_rc_lt_parse_options=false - # Perform our own loop to consume as many options as possible in # each iteration. while test $# -gt 0; do - _G_match_lt_parse_options=: _G_opt=$1 shift case $_G_opt in @@ -2471,22 +2386,15 @@ libtool_parse_options () func_append preserve_args " $_G_opt" ;; - # An option not handled by this hook function: - *) set dummy "$_G_opt" ${1+"$@"} ; shift - _G_match_lt_parse_options=false - break - ;; + # An option not handled by this hook function: + *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;; esac - $_G_match_lt_parse_options && _G_rc_lt_parse_options=: done - if $_G_rc_lt_parse_options; then - # save modified positional parameters for caller - func_quote_for_eval ${1+"$@"} - libtool_parse_options_result=$func_quote_for_eval_result - fi - $_G_rc_lt_parse_options + # save modified positional parameters for caller + func_quote_for_eval ${1+"$@"} + libtool_parse_options_result=$func_quote_for_eval_result } func_add_hook func_parse_options libtool_parse_options @@ -7312,6 +7220,11 @@ func_mode_link () arg=$func_stripname_result ;; + -Wl,--as-needed) + deplibs="$deplibs $arg" + continue + ;; + -Wl,*) func_stripname '-Wl,' '' "$arg" args=$func_stripname_result @@ -7364,16 +7277,10 @@ func_mode_link () # -tp=* Portland pgcc target processor selection # --sysroot=* for sysroot support # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization - # -specs=* GCC specs files # -stdlib=* select c++ std lib with clang - # -fsanitize=* Clang/GCC memory and address sanitizer - # -fuse-ld=* Linker select flags for GCC - # -static-* direct GCC to link specific libraries statically - # -fcilkplus Cilk Plus language extension features for C/C++ -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \ - -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \ - -specs=*|-fsanitize=*|-fuse-ld=*|-static-*|-fcilkplus) + -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*) func_quote_for_eval "$arg" arg=$func_quote_for_eval_result func_append compile_command " $arg" @@ -7622,6 +7529,7 @@ func_mode_link () case $linkmode in lib) + as_needed_flag= passes="conv dlpreopen link" for file in $dlfiles $dlprefiles; do case $file in @@ -7633,6 +7541,7 @@ func_mode_link () done ;; prog) + as_needed_flag= compile_deplibs= finalize_deplibs= alldeplibs=false @@ -7666,10 +7575,7 @@ func_mode_link () case $pass in dlopen) libs=$dlfiles ;; dlpreopen) libs=$dlprefiles ;; - link) - libs="$deplibs %DEPLIBS%" - test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs" - ;; + link) libs="$deplibs %DEPLIBS% $dependency_libs" ;; esac fi if test lib,dlpreopen = "$linkmode,$pass"; then @@ -7705,6 +7611,15 @@ func_mode_link () lib= found=false case $deplib in + -Wl,--as-needed) + if test prog,link = "$linkmode,$pass" || + test lib,link = "$linkmode,$pass"; then + as_needed_flag="$deplib " + else + deplibs="$deplib $deplibs" + fi + continue + ;; -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \ |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*) if test prog,link = "$linkmode,$pass"; then @@ -7988,19 +7903,19 @@ func_mode_link () # It is a libtool convenience library, so add in its objects. func_append convenience " $ladir/$objdir/$old_library" func_append old_convenience " $ladir/$objdir/$old_library" - tmp_libs= - for deplib in $dependency_libs; do - deplibs="$deplib $deplibs" - if $opt_preserve_dup_deps; then - case "$tmp_libs " in - *" $deplib "*) func_append specialdeplibs " $deplib" ;; - esac - fi - func_append tmp_libs " $deplib" - done elif test prog != "$linkmode" && test lib != "$linkmode"; then func_fatal_error "'$lib' is not a convenience library" fi + tmp_libs= + for deplib in $dependency_libs; do + deplibs="$deplib $deplibs" + if $opt_preserve_dup_deps; then + case "$tmp_libs " in + *" $deplib "*) func_append specialdeplibs " $deplib" ;; + esac + fi + func_append tmp_libs " $deplib" + done continue fi # $pass = conv @@ -8924,9 +8839,6 @@ func_mode_link () revision=$number_minor lt_irix_increment=no ;; - *) - func_fatal_configuration "$modename: unknown library version type '$version_type'" - ;; esac ;; no) @@ -10125,6 +10037,13 @@ EOF test "X$libobjs" = "X " && libobjs= fi + # A bit hacky. I had wanted to add \$as_needed_flag to archive_cmds instead, but that + # comes from libtool.m4 which is part of the project being built. This should put it + # in the right place though. + if test lib,link = "$linkmode,$pass" && test -n "$as_needed_flag"; then + libobjs=$as_needed_flag$libobjs + fi + save_ifs=$IFS; IFS='~' for cmd in $cmds; do IFS=$sp$nl @@ -10357,8 +10276,8 @@ EOF compile_deplibs=$new_libs - func_append compile_command " $compile_deplibs" - func_append finalize_command " $finalize_deplibs" + func_append compile_command " $as_needed_flag $compile_deplibs" + func_append finalize_command " $as_needed_flag $finalize_deplibs" if test -n "$rpath$xrpath"; then # If the user specified any rpath flags, then add them. diff --git a/m4/libtool.m4 b/m4/libtool.m4 index a6d21ae..a3bc337 100644 --- a/m4/libtool.m4 +++ b/m4/libtool.m4 @@ -728,6 +728,7 @@ _LT_CONFIG_SAVE_COMMANDS([ cat <<_LT_EOF >> "$cfgfile" #! $SHELL # Generated automatically by $as_me ($PACKAGE) $VERSION +# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # Provide generalized library-building support services. @@ -1041,8 +1042,8 @@ int forced_loaded() { return 2;} _LT_EOF echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&AS_MESSAGE_LOG_FD $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&AS_MESSAGE_LOG_FD - echo "$AR cr libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD - $AR cr libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD + echo "$AR cru libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD + $AR cru libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD echo "$RANLIB libconftest.a" >&AS_MESSAGE_LOG_FD $RANLIB libconftest.a 2>&AS_MESSAGE_LOG_FD cat > conftest.c << _LT_EOF @@ -1492,7 +1493,7 @@ need_locks=$enable_libtool_lock m4_defun([_LT_PROG_AR], [AC_CHECK_TOOLS(AR, [ar], false) : ${AR=ar} -: ${AR_FLAGS=cr} +: ${AR_FLAGS=cru} _LT_DECL([], [AR], [1], [The archiver]) _LT_DECL([], [AR_FLAGS], [1], [Flags to create an archive]) @@ -2886,18 +2887,6 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) dynamic_linker='GNU/Linux ld.so' ;; -netbsdelf*-gnu) - version_type=linux - need_lib_prefix=no - need_version=no - library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' - soname_spec='${libname}${release}${shared_ext}$major' - shlibpath_var=LD_LIBRARY_PATH - shlibpath_overrides_runpath=no - hardcode_into_libs=yes - dynamic_linker='NetBSD ld.elf_so' - ;; - netbsd*) version_type=sunos need_lib_prefix=no @@ -3557,7 +3546,7 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) lt_cv_deplibs_check_method=pass_all ;; -netbsd* | netbsdelf*-gnu) +netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' else @@ -4063,8 +4052,7 @@ _LT_EOF if AC_TRY_EVAL(ac_compile); then # Now try to grab the symbols. nlist=conftest.nm - $ECHO "$as_me:$LINENO: $NM conftest.$ac_objext | $lt_cv_sys_global_symbol_pipe > $nlist" >&AS_MESSAGE_LOG_FD - if eval "$NM" conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist 2>&AS_MESSAGE_LOG_FD && test -s "$nlist"; then + if AC_TRY_EVAL(NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) && test -s "$nlist"; then # Try sorting and uniquifying the output. if sort "$nlist" | uniq > "$nlist"T; then mv -f "$nlist"T "$nlist" @@ -4436,7 +4424,7 @@ m4_if([$1], [CXX], [ ;; esac ;; - netbsd* | netbsdelf*-gnu) + netbsd*) ;; *qnx* | *nto*) # QNX uses GNU C++, but need to define -shared option too, otherwise @@ -4704,12 +4692,6 @@ m4_if([$1], [CXX], [ _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; - # flang / f18. f95 an alias for gfortran or flang on Debian - flang* | f18* | f95*) - _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' - _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' - _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' - ;; # icc used to be incompatible with GCC. # ICC 10 doesn't accept -KPIC any more. icc* | ifort*) @@ -4954,9 +4936,6 @@ m4_if([$1], [CXX], [ ;; esac ;; - linux* | k*bsd*-gnu | gnu*) - _LT_TAGVAR(link_all_deplibs, $1)=no - ;; *) _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' ;; @@ -5019,9 +4998,6 @@ dnl Note also adjust exclude_expsyms for C++ above. openbsd* | bitrig*) with_gnu_ld=no ;; - linux* | k*bsd*-gnu | gnu*) - _LT_TAGVAR(link_all_deplibs, $1)=no - ;; esac _LT_TAGVAR(ld_shlibs, $1)=yes @@ -5276,7 +5252,7 @@ _LT_EOF fi ;; - netbsd* | netbsdelf*-gnu) + netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' wlarc= @@ -5797,7 +5773,6 @@ _LT_EOF if test yes = "$lt_cv_irix_exported_symbol"; then _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib' fi - _LT_TAGVAR(link_all_deplibs, $1)=no else _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry $output_objdir/so_locations -exports_file $export_symbols -o $lib' @@ -5819,7 +5794,7 @@ _LT_EOF esac ;; - netbsd* | netbsdelf*-gnu) + netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out else @@ -6445,7 +6420,7 @@ if test yes != "$_lt_caught_CXX_error"; then # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' else GXX=no @@ -6820,7 +6795,7 @@ if test yes != "$_lt_caught_CXX_error"; then # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. - output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then @@ -6885,7 +6860,7 @@ if test yes != "$_lt_caught_CXX_error"; then # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. - output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP " \-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then @@ -7224,7 +7199,7 @@ if test yes != "$_lt_caught_CXX_error"; then # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' else # FIXME: insert proper C++ library support @@ -7308,7 +7283,7 @@ if test yes != "$_lt_caught_CXX_error"; then # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' else # g++ 2.7 appears to require '-G' NOT '-shared' on this # platform. @@ -7319,7 +7294,7 @@ if test yes != "$_lt_caught_CXX_error"; then # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " \-L"' + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $wl$libdir' diff --git a/src/Makefile.in b/src/Makefile.in index 7418ba5..458a1bd 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2020 Free Software Foundation, Inc. diff --git a/src/bin/Makefile.in b/src/bin/Makefile.in index c28c1ee..75ad15f 100644 --- a/src/bin/Makefile.in +++ b/src/bin/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2020 Free Software Foundation, Inc. diff --git a/src/bin/fstarcsort-main.cc b/src/bin/fstarcsort-main.cc index 84098b6..99f931d 100644 --- a/src/bin/fstarcsort-main.cc +++ b/src/bin/fstarcsort-main.cc @@ -53,9 +53,9 @@ int fstarcsort_main(int argc, char **argv) { if (!fst) return 1; s::ArcSortType sort_type; - if (!s::GetArcSortType(FLAGS_sort_type, &sort_type)) { - LOG(ERROR) << argv[0] - << ": Unknown or unsupported sort type: " << FLAGS_sort_type; + if (!s::GetArcSortType(FST_FLAGS_sort_type, &sort_type)) { + LOG(ERROR) << argv[0] << ": Unknown or unsupported sort type: " + << FST_FLAGS_sort_type; return 1; } diff --git a/src/bin/fstclosure-main.cc b/src/bin/fstclosure-main.cc index 6464d22..95abae8 100644 --- a/src/bin/fstclosure-main.cc +++ b/src/bin/fstclosure-main.cc @@ -50,7 +50,7 @@ int fstclosure_main(int argc, char **argv) { std::unique_ptr fst(MutableFstClass::Read(in_name, true)); if (!fst) return 1; - s::Closure(fst.get(), s::GetClosureType(FLAGS_closure_plus)); + s::Closure(fst.get(), s::GetClosureType(FST_FLAGS_closure_plus)); return !fst->Write(out_name); } diff --git a/src/bin/fstcompile-main.cc b/src/bin/fstcompile-main.cc index 302f50d..029e9c8 100644 --- a/src/bin/fstcompile-main.cc +++ b/src/bin/fstcompile-main.cc @@ -67,34 +67,35 @@ int fstcompile_main(int argc, char **argv) { } std::istream &istrm = fstrm.is_open() ? fstrm : std::cin; - const SymbolTableTextOptions opts(FLAGS_allow_negative_labels); + const SymbolTableTextOptions opts(FST_FLAGS_allow_negative_labels); std::unique_ptr isyms; - if (!FLAGS_isymbols.empty()) { - isyms.reset(SymbolTable::ReadText(FLAGS_isymbols, opts)); + if (!FST_FLAGS_isymbols.empty()) { + isyms.reset(SymbolTable::ReadText(FST_FLAGS_isymbols, opts)); if (!isyms) return 1; } std::unique_ptr osyms; - if (!FLAGS_osymbols.empty()) { - osyms.reset(SymbolTable::ReadText(FLAGS_osymbols, opts)); + if (!FST_FLAGS_osymbols.empty()) { + osyms.reset(SymbolTable::ReadText(FST_FLAGS_osymbols, opts)); if (!osyms) return 1; } std::unique_ptr ssyms; - if (!FLAGS_ssymbols.empty()) { - ssyms.reset(SymbolTable::ReadText(FLAGS_ssymbols)); + if (!FST_FLAGS_ssymbols.empty()) { + ssyms.reset(SymbolTable::ReadText(FST_FLAGS_ssymbols)); if (!ssyms) return 1; } const std::string dest = argc > 2 && strcmp(argv[2], "-") != 0 ? argv[2] : ""; - s::CompileFst( - istrm, source, dest, FLAGS_fst_type, FLAGS_arc_type, isyms.get(), - osyms.get(), ssyms.get(), FLAGS_acceptor, - FLAGS_keep_isymbols, FLAGS_keep_osymbols, - FLAGS_keep_state_numbering, - FLAGS_allow_negative_labels); + s::CompileFst(istrm, source, dest, FST_FLAGS_fst_type, + FST_FLAGS_arc_type, isyms.get(), osyms.get(), + ssyms.get(), FST_FLAGS_acceptor, + FST_FLAGS_keep_isymbols, + FST_FLAGS_keep_osymbols, + FST_FLAGS_keep_state_numbering, + FST_FLAGS_allow_negative_labels); return 0; } diff --git a/src/bin/fstcompose-main.cc b/src/bin/fstcompose-main.cc index cb1ba3f..d7ceddf 100644 --- a/src/bin/fstcompose-main.cc +++ b/src/bin/fstcompose-main.cc @@ -72,13 +72,14 @@ int fstcompose_main(int argc, char **argv) { VectorFstClass ofst(ifst1->ArcType()); ComposeFilter compose_filter; - if (!s::GetComposeFilter(FLAGS_compose_filter, &compose_filter)) { + if (!s::GetComposeFilter(FST_FLAGS_compose_filter, + &compose_filter)) { LOG(ERROR) << argv[0] << ": Unknown or unsupported compose filter type: " - << FLAGS_compose_filter; + << FST_FLAGS_compose_filter; return 1; } - const ComposeOptions opts(FLAGS_connect, compose_filter); + const ComposeOptions opts(FST_FLAGS_connect, compose_filter); s::Compose(*ifst1, *ifst2, &ofst, opts); diff --git a/src/bin/fstconvert-main.cc b/src/bin/fstconvert-main.cc index 1e1aeb6..b271446 100644 --- a/src/bin/fstconvert-main.cc +++ b/src/bin/fstconvert-main.cc @@ -49,8 +49,9 @@ int fstconvert_main(int argc, char **argv) { std::unique_ptr ifst(FstClass::Read(in_name)); if (!ifst) return 1; - if (ifst->FstType() != FLAGS_fst_type) { - std::unique_ptr ofst(s::Convert(*ifst, FLAGS_fst_type)); + if (ifst->FstType() != FST_FLAGS_fst_type) { + std::unique_ptr ofst( + s::Convert(*ifst, FST_FLAGS_fst_type)); if (!ofst) return 1; return !ofst->Write(out_name); } else { diff --git a/src/bin/fstdeterminize-main.cc b/src/bin/fstdeterminize-main.cc index 2aef3a8..91a940a 100644 --- a/src/bin/fstdeterminize-main.cc +++ b/src/bin/fstdeterminize-main.cc @@ -51,9 +51,9 @@ int fstdeterminize_main(int argc, char **argv) { } DeterminizeType det_type; - if (!s::GetDeterminizeType(FLAGS_det_type, &det_type)) { + if (!s::GetDeterminizeType(FST_FLAGS_det_type, &det_type)) { LOG(ERROR) << argv[0] << ": Unknown or unsupported determinization type: " - << FLAGS_det_type; + << FST_FLAGS_det_type; return 1; } @@ -68,14 +68,14 @@ int fstdeterminize_main(int argc, char **argv) { VectorFstClass ofst(ifst->ArcType()); const auto weight_threshold = - FLAGS_weight.empty() + FST_FLAGS_weight.empty() ? WeightClass::Zero(ifst->WeightType()) - : WeightClass(ifst->WeightType(), FLAGS_weight); + : WeightClass(ifst->WeightType(), FST_FLAGS_weight); const s::DeterminizeOptions opts( - FLAGS_delta, weight_threshold, FLAGS_nstate, - FLAGS_subsequential_label, det_type, - FLAGS_increment_subsequential_label); + FST_FLAGS_delta, weight_threshold, FST_FLAGS_nstate, + FST_FLAGS_subsequential_label, det_type, + FST_FLAGS_increment_subsequential_label); s::Determinize(*ifst, &ofst, opts); diff --git a/src/bin/fstdifference-main.cc b/src/bin/fstdifference-main.cc index 703760f..52c56c9 100644 --- a/src/bin/fstdifference-main.cc +++ b/src/bin/fstdifference-main.cc @@ -66,13 +66,14 @@ int fstdifference_main(int argc, char **argv) { VectorFstClass ofst(ifst1->ArcType()); ComposeFilter compose_filter; - if (!s::GetComposeFilter(FLAGS_compose_filter, &compose_filter)) { + if (!s::GetComposeFilter(FST_FLAGS_compose_filter, + &compose_filter)) { LOG(ERROR) << argv[0] << ": Unknown or unsupported compose filter type: " - << FLAGS_compose_filter; + << FST_FLAGS_compose_filter; return 1; } - const DifferenceOptions opts(FLAGS_connect, compose_filter); + const DifferenceOptions opts(FST_FLAGS_connect, compose_filter); s::Difference(*ifst1, *ifst2, &ofst, opts); diff --git a/src/bin/fstdisambiguate-main.cc b/src/bin/fstdisambiguate-main.cc index ac022f1..fda569a 100644 --- a/src/bin/fstdisambiguate-main.cc +++ b/src/bin/fstdisambiguate-main.cc @@ -57,13 +57,13 @@ int fstdisambiguate_main(int argc, char **argv) { VectorFstClass ofst(ifst->ArcType()); const auto weight_threshold = - FLAGS_weight.empty() + FST_FLAGS_weight.empty() ? WeightClass::Zero(ifst->WeightType()) - : WeightClass(ifst->WeightType(), FLAGS_weight); + : WeightClass(ifst->WeightType(), FST_FLAGS_weight); const s::DisambiguateOptions opts( - FLAGS_delta, weight_threshold, FLAGS_nstate, - FLAGS_subsequential_label); + FST_FLAGS_delta, weight_threshold, FST_FLAGS_nstate, + FST_FLAGS_subsequential_label); s::Disambiguate(*ifst, &ofst, opts); diff --git a/src/bin/fstdraw-main.cc b/src/bin/fstdraw-main.cc index 769b592..f8a7042 100644 --- a/src/bin/fstdraw-main.cc +++ b/src/bin/fstdraw-main.cc @@ -80,44 +80,44 @@ int fstdraw_main(int argc, char **argv) { } std::ostream &ostrm = fstrm.is_open() ? fstrm : std::cout; - const SymbolTableTextOptions opts(FLAGS_allow_negative_labels); + const SymbolTableTextOptions opts(FST_FLAGS_allow_negative_labels); std::unique_ptr isyms; - if (!FLAGS_isymbols.empty() && !FLAGS_numeric) { - isyms.reset(SymbolTable::ReadText(FLAGS_isymbols, opts)); + if (!FST_FLAGS_isymbols.empty() && !FST_FLAGS_numeric) { + isyms.reset(SymbolTable::ReadText(FST_FLAGS_isymbols, opts)); if (!isyms) return 1; } std::unique_ptr osyms; - if (!FLAGS_osymbols.empty() && !FLAGS_numeric) { - osyms.reset(SymbolTable::ReadText(FLAGS_osymbols, opts)); + if (!FST_FLAGS_osymbols.empty() && !FST_FLAGS_numeric) { + osyms.reset(SymbolTable::ReadText(FST_FLAGS_osymbols, opts)); if (!osyms) return 1; } std::unique_ptr ssyms; - if (!FLAGS_ssymbols.empty() && !FLAGS_numeric) { - ssyms.reset(SymbolTable::ReadText(FLAGS_ssymbols)); + if (!FST_FLAGS_ssymbols.empty() && !FST_FLAGS_numeric) { + ssyms.reset(SymbolTable::ReadText(FST_FLAGS_ssymbols)); if (!ssyms) return 1; } - if (!isyms && !FLAGS_numeric && fst->InputSymbols()) { + if (!isyms && !FST_FLAGS_numeric && fst->InputSymbols()) { isyms.reset(fst->InputSymbols()->Copy()); } - if (!osyms && !FLAGS_numeric && fst->OutputSymbols()) { + if (!osyms && !FST_FLAGS_numeric && fst->OutputSymbols()) { osyms.reset(fst->OutputSymbols()->Copy()); } // "dest" is only used for the name of the file in error messages. const std::string dest = out_name.empty() ? "stdout" : out_name; s::Draw(*fst, isyms.get(), osyms.get(), ssyms.get(), - FLAGS_acceptor, FLAGS_title, - FLAGS_width, FLAGS_height, - FLAGS_portrait, FLAGS_vertical, - FLAGS_ranksep, FLAGS_nodesep, - FLAGS_fontsize, FLAGS_precision, - FLAGS_float_format, FLAGS_show_weight_one, ostrm, - dest); + FST_FLAGS_acceptor, FST_FLAGS_title, + FST_FLAGS_width, FST_FLAGS_height, + FST_FLAGS_portrait, FST_FLAGS_vertical, + FST_FLAGS_ranksep, FST_FLAGS_nodesep, + FST_FLAGS_fontsize, FST_FLAGS_precision, + FST_FLAGS_float_format, + FST_FLAGS_show_weight_one, ostrm, dest); return 0; } diff --git a/src/bin/fstencode-main.cc b/src/bin/fstencode-main.cc index 348beed..186b7a8 100644 --- a/src/bin/fstencode-main.cc +++ b/src/bin/fstencode-main.cc @@ -56,18 +56,18 @@ int fstencode_main(int argc, char **argv) { std::unique_ptr fst(MutableFstClass::Read(in_name, true)); if (!fst) return 1; - if (FLAGS_decode) { + if (FST_FLAGS_decode) { std::unique_ptr mapper( EncodeMapperClass::Read(mapper_name)); s::Decode(fst.get(), *mapper); - } else if (FLAGS_encode_reuse) { + } else if (FST_FLAGS_encode_reuse) { std::unique_ptr mapper( EncodeMapperClass::Read(mapper_name)); if (!mapper) return 1; s::Encode(fst.get(), mapper.get()); } else { - const auto flags = s::GetEncodeFlags(FLAGS_encode_labels, - FLAGS_encode_weights); + const auto flags = s::GetEncodeFlags(FST_FLAGS_encode_labels, + FST_FLAGS_encode_weights); EncodeMapperClass mapper(fst->ArcType(), flags); s::Encode(fst.get(), &mapper); if (!mapper.Write(mapper_name)) return 1; diff --git a/src/bin/fstepsnormalize-main.cc b/src/bin/fstepsnormalize-main.cc index 2013f72..7c72aae 100644 --- a/src/bin/fstepsnormalize-main.cc +++ b/src/bin/fstepsnormalize-main.cc @@ -54,7 +54,7 @@ int fstepsnormalize_main(int argc, char **argv) { VectorFstClass ofst(ifst->ArcType()); s::EpsNormalize(*ifst, &ofst, - s::GetEpsNormalizeType(FLAGS_eps_norm_output)); + s::GetEpsNormalizeType(FST_FLAGS_eps_norm_output)); return !ofst.Write(out_name); } diff --git a/src/bin/fstequal-main.cc b/src/bin/fstequal-main.cc index 38c4747..5f551ba 100644 --- a/src/bin/fstequal-main.cc +++ b/src/bin/fstequal-main.cc @@ -57,7 +57,7 @@ int fstequal_main(int argc, char **argv) { std::unique_ptr ifst2(FstClass::Read(in2_name)); if (!ifst2) return 1; - bool result = s::Equal(*ifst1, *ifst2, FLAGS_delta); + bool result = s::Equal(*ifst1, *ifst2, FST_FLAGS_delta); if (!result) VLOG(1) << "FSTs are not equal."; return result ? 0 : 2; diff --git a/src/bin/fstequivalent-main.cc b/src/bin/fstequivalent-main.cc index b03fb02..d2338ac 100644 --- a/src/bin/fstequivalent-main.cc +++ b/src/bin/fstequivalent-main.cc @@ -66,22 +66,22 @@ int fstequivalent_main(int argc, char **argv) { std::unique_ptr ifst2(FstClass::Read(in2_name)); if (!ifst2) return 1; - if (!FLAGS_random) { - bool result = s::Equivalent(*ifst1, *ifst2, FLAGS_delta); + if (!FST_FLAGS_random) { + bool result = s::Equivalent(*ifst1, *ifst2, FST_FLAGS_delta); if (!result) VLOG(1) << "FSTs are not equivalent"; return result ? 0 : 2; } else { s::RandArcSelection ras; - if (!s::GetRandArcSelection(FLAGS_select, &ras)) { + if (!s::GetRandArcSelection(FST_FLAGS_select, &ras)) { LOG(ERROR) << argv[0] << ": Unknown or unsupported select type " - << FLAGS_select; + << FST_FLAGS_select; return 1; } const RandGenOptions opts( - ras, FLAGS_max_length); - bool result = s::RandEquivalent(*ifst1, *ifst2, FLAGS_npath, - opts, FLAGS_delta, - FLAGS_seed); + ras, FST_FLAGS_max_length); + bool result = s::RandEquivalent(*ifst1, *ifst2, FST_FLAGS_npath, + opts, FST_FLAGS_delta, + FST_FLAGS_seed); if (!result) VLOG(1) << "FSTs are not equivalent"; return result ? 0 : 2; } diff --git a/src/bin/fstinfo-main.cc b/src/bin/fstinfo-main.cc index 954d01f..085c330 100644 --- a/src/bin/fstinfo-main.cc +++ b/src/bin/fstinfo-main.cc @@ -81,14 +81,15 @@ int fstinfo_main(int argc, char **argv) { const std::string in_name = (argc > 1 && (strcmp(argv[1], "-") != 0)) ? argv[1] : ""; - if (FLAGS_info_type == "fast") { + if (FST_FLAGS_info_type == "fast") { if (!PrintHeaderInfo(in_name)) return 1; } else { std::unique_ptr ifst(FstClass::Read(in_name)); if (!ifst) return 1; - s::Info(*ifst, FLAGS_test_properties, FLAGS_arc_filter, - FLAGS_info_type, FLAGS_fst_verify); + s::Info(*ifst, FST_FLAGS_test_properties, + FST_FLAGS_arc_filter, FST_FLAGS_info_type, + FST_FLAGS_fst_verify); } return 0; diff --git a/src/bin/fstintersect-main.cc b/src/bin/fstintersect-main.cc index 64501b9..fe18ad0 100644 --- a/src/bin/fstintersect-main.cc +++ b/src/bin/fstintersect-main.cc @@ -66,13 +66,14 @@ int fstintersect_main(int argc, char **argv) { VectorFstClass ofst(ifst1->ArcType()); ComposeFilter compose_filter; - if (!s::GetComposeFilter(FLAGS_compose_filter, &compose_filter)) { + if (!s::GetComposeFilter(FST_FLAGS_compose_filter, + &compose_filter)) { LOG(ERROR) << argv[0] << ": Unknown or unsupported compose filter type: " - << FLAGS_compose_filter; + << FST_FLAGS_compose_filter; return 1; } - const IntersectOptions opts(FLAGS_connect, compose_filter); + const IntersectOptions opts(FST_FLAGS_connect, compose_filter); s::Intersect(*ifst1, *ifst2, &ofst, opts); diff --git a/src/bin/fstisomorphic-main.cc b/src/bin/fstisomorphic-main.cc index 32e1e78..20f89eb 100644 --- a/src/bin/fstisomorphic-main.cc +++ b/src/bin/fstisomorphic-main.cc @@ -59,7 +59,7 @@ int fstisomorphic_main(int argc, char **argv) { std::unique_ptr ifst2(FstClass::Read(in2_name)); if (!ifst2) return 1; - bool result = s::Isomorphic(*ifst1, *ifst2, FLAGS_delta); + bool result = s::Isomorphic(*ifst1, *ifst2, FST_FLAGS_delta); if (!result) VLOG(1) << "FSTs are not isomorphic"; return result ? 0 : 2; diff --git a/src/bin/fstmap-main.cc b/src/bin/fstmap-main.cc index bf6771b..295cf0c 100644 --- a/src/bin/fstmap-main.cc +++ b/src/bin/fstmap-main.cc @@ -57,21 +57,21 @@ int fstmap_main(int argc, char **argv) { if (!ifst) return 1; s::MapType map_type; - if (!s::GetMapType(FLAGS_map_type, &map_type)) { + if (!s::GetMapType(FST_FLAGS_map_type, &map_type)) { LOG(ERROR) << argv[0] << ": Unknown or unsupported map type " - << FLAGS_map_type; + << FST_FLAGS_map_type; return 1; } - const auto weight_param = - !FLAGS_weight.empty() - ? WeightClass(ifst->WeightType(), FLAGS_weight) - : (FLAGS_map_type == "times" ? WeightClass::One(ifst->WeightType()) + const auto weight_param = !FST_FLAGS_weight.empty() + ? WeightClass(ifst->WeightType(), FST_FLAGS_weight) + : (FST_FLAGS_map_type == "times" + ? WeightClass::One(ifst->WeightType()) : WeightClass::Zero(ifst->WeightType())); std::unique_ptr ofst( - s::Map(*ifst, map_type, FLAGS_delta, - FLAGS_power, weight_param)); + s::Map(*ifst, map_type, FST_FLAGS_delta, + FST_FLAGS_power, weight_param)); return !ofst->Write(out_name); } diff --git a/src/bin/fstminimize-main.cc b/src/bin/fstminimize-main.cc index 27a88f7..f6e14c1 100644 --- a/src/bin/fstminimize-main.cc +++ b/src/bin/fstminimize-main.cc @@ -61,12 +61,12 @@ int fstminimize_main(int argc, char **argv) { if (argc > 3) { std::unique_ptr fst2(new VectorFstClass(fst1->ArcType())); - s::Minimize(fst1.get(), fst2.get(), FLAGS_delta, - FLAGS_allow_nondet); + s::Minimize(fst1.get(), fst2.get(), FST_FLAGS_delta, + FST_FLAGS_allow_nondet); if (!fst2->Write(out2_name)) return 1; } else { - s::Minimize(fst1.get(), nullptr, FLAGS_delta, - FLAGS_allow_nondet); + s::Minimize(fst1.get(), nullptr, FST_FLAGS_delta, + FST_FLAGS_allow_nondet); } return !fst1->Write(out1_name); diff --git a/src/bin/fstprint-main.cc b/src/bin/fstprint-main.cc index a2fbdc0..a1d5976 100644 --- a/src/bin/fstprint-main.cc +++ b/src/bin/fstprint-main.cc @@ -77,44 +77,44 @@ int fstprint_main(int argc, char **argv) { std::ostream &ostrm = fstrm.is_open() ? fstrm : std::cout; ostrm.precision(9); - const SymbolTableTextOptions opts(FLAGS_allow_negative_labels); + const SymbolTableTextOptions opts(FST_FLAGS_allow_negative_labels); std::unique_ptr isyms; - if (!FLAGS_isymbols.empty() && !FLAGS_numeric) { - isyms.reset(SymbolTable::ReadText(FLAGS_isymbols, opts)); + if (!FST_FLAGS_isymbols.empty() && !FST_FLAGS_numeric) { + isyms.reset(SymbolTable::ReadText(FST_FLAGS_isymbols, opts)); if (!isyms) return 1; } std::unique_ptr osyms; - if (!FLAGS_osymbols.empty() && !FLAGS_numeric) { - osyms.reset(SymbolTable::ReadText(FLAGS_osymbols, opts)); + if (!FST_FLAGS_osymbols.empty() && !FST_FLAGS_numeric) { + osyms.reset(SymbolTable::ReadText(FST_FLAGS_osymbols, opts)); if (!osyms) return 1; } std::unique_ptr ssyms; - if (!FLAGS_ssymbols.empty() && !FLAGS_numeric) { - ssyms.reset(SymbolTable::ReadText(FLAGS_ssymbols)); + if (!FST_FLAGS_ssymbols.empty() && !FST_FLAGS_numeric) { + ssyms.reset(SymbolTable::ReadText(FST_FLAGS_ssymbols)); if (!ssyms) return 1; } - if (!isyms && !FLAGS_numeric && fst->InputSymbols()) { + if (!isyms && !FST_FLAGS_numeric && fst->InputSymbols()) { isyms.reset(fst->InputSymbols()->Copy()); } - if (!osyms && !FLAGS_numeric && fst->OutputSymbols()) { + if (!osyms && !FST_FLAGS_numeric && fst->OutputSymbols()) { osyms.reset(fst->OutputSymbols()->Copy()); } s::Print(*fst, ostrm, dest, isyms.get(), osyms.get(), ssyms.get(), - FLAGS_acceptor, FLAGS_show_weight_one, - FLAGS_missing_symbol); + FST_FLAGS_acceptor, FST_FLAGS_show_weight_one, + FST_FLAGS_missing_symbol); - if (isyms && !FLAGS_save_isymbols.empty()) { - if (!isyms->WriteText(FLAGS_save_isymbols)) return 1; + if (isyms && !FST_FLAGS_save_isymbols.empty()) { + if (!isyms->WriteText(FST_FLAGS_save_isymbols)) return 1; } - if (osyms && !FLAGS_save_osymbols.empty()) { - if (!osyms->WriteText(FLAGS_save_osymbols)) return 1; + if (osyms && !FST_FLAGS_save_osymbols.empty()) { + if (!osyms->WriteText(FST_FLAGS_save_osymbols)) return 1; } return 0; diff --git a/src/bin/fstproject-main.cc b/src/bin/fstproject-main.cc index a52445b..4399b2d 100644 --- a/src/bin/fstproject-main.cc +++ b/src/bin/fstproject-main.cc @@ -54,9 +54,9 @@ int fstproject_main(int argc, char **argv) { if (!fst) return 1; ProjectType project_type; - if (!s::GetProjectType(FLAGS_project_type, &project_type)) { + if (!s::GetProjectType(FST_FLAGS_project_type, &project_type)) { LOG(ERROR) << argv[0] << ": Unknown or unsupported project type: " - << FLAGS_project_type; + << FST_FLAGS_project_type; return 1; } diff --git a/src/bin/fstprune-main.cc b/src/bin/fstprune-main.cc index 7611884..191803f 100644 --- a/src/bin/fstprune-main.cc +++ b/src/bin/fstprune-main.cc @@ -53,12 +53,12 @@ int fstprune_main(int argc, char **argv) { if (!fst) return 1; const auto weight_threshold = - FLAGS_weight.empty() + FST_FLAGS_weight.empty() ? WeightClass::Zero(fst->WeightType()) - : WeightClass(fst->WeightType(), FLAGS_weight); + : WeightClass(fst->WeightType(), FST_FLAGS_weight); - s::Prune(fst.get(), weight_threshold, FLAGS_nstate, - FLAGS_delta); + s::Prune(fst.get(), weight_threshold, FST_FLAGS_nstate, + FST_FLAGS_delta); return !fst->Write(out_name); } diff --git a/src/bin/fstpush-main.cc b/src/bin/fstpush-main.cc index 17a830d..59ba277 100644 --- a/src/bin/fstpush-main.cc +++ b/src/bin/fstpush-main.cc @@ -58,16 +58,16 @@ int fstpush_main(int argc, char **argv) { std::unique_ptr ifst(FstClass::Read(in_name)); if (!ifst) return 1; - const auto flags = s::GetPushFlags(FLAGS_push_weights, - FLAGS_push_labels, - FLAGS_remove_total_weight, - FLAGS_remove_common_affix); + const auto flags = s::GetPushFlags(FST_FLAGS_push_weights, + FST_FLAGS_push_labels, + FST_FLAGS_remove_total_weight, + FST_FLAGS_remove_common_affix); VectorFstClass ofst(ifst->ArcType()); s::Push(*ifst, &ofst, flags, - s::GetReweightType(FLAGS_to_final), - FLAGS_delta); + s::GetReweightType(FST_FLAGS_to_final), + FST_FLAGS_delta); return !ofst.Write(out_name); } diff --git a/src/bin/fstrandgen-main.cc b/src/bin/fstrandgen-main.cc index 44a7023..cff6c36 100644 --- a/src/bin/fstrandgen-main.cc +++ b/src/bin/fstrandgen-main.cc @@ -50,7 +50,7 @@ int fstrandgen_main(int argc, char **argv) { return 1; } - VLOG(1) << argv[0] << ": Seed = " << FLAGS_seed; + VLOG(1) << argv[0] << ": Seed = " << FST_FLAGS_seed; const std::string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : ""; @@ -63,18 +63,18 @@ int fstrandgen_main(int argc, char **argv) { VectorFstClass ofst(ifst->ArcType()); s::RandArcSelection ras; - if (!s::GetRandArcSelection(FLAGS_select, &ras)) { + if (!s::GetRandArcSelection(FST_FLAGS_select, &ras)) { LOG(ERROR) << argv[0] << ": Unknown or unsupported select type " - << FLAGS_select; + << FST_FLAGS_select; return 1; } s::RandGen(*ifst, &ofst, RandGenOptions( - ras, FLAGS_max_length, - FLAGS_npath, FLAGS_weighted, - FLAGS_remove_total_weight), - FLAGS_seed); + ras, FST_FLAGS_max_length, + FST_FLAGS_npath, FST_FLAGS_weighted, + FST_FLAGS_remove_total_weight), + FST_FLAGS_seed); return !ofst.Write(out_name); } diff --git a/src/bin/fstrelabel-main.cc b/src/bin/fstrelabel-main.cc index 3a84726..8c704f0 100644 --- a/src/bin/fstrelabel-main.cc +++ b/src/bin/fstrelabel-main.cc @@ -74,45 +74,49 @@ int fstrelabel_main(int argc, char **argv) { if (!fst) return 1; // Relabel with symbol tables. - const SymbolTableTextOptions opts(FLAGS_allow_negative_labels); + const SymbolTableTextOptions opts(FST_FLAGS_allow_negative_labels); - if (!FLAGS_relabel_isymbols.empty() || - !FLAGS_relabel_osymbols.empty()) { + if (!FST_FLAGS_relabel_isymbols.empty() || + !FST_FLAGS_relabel_osymbols.empty()) { bool attach_new_isymbols = (fst->InputSymbols() != nullptr); std::unique_ptr old_isymbols( - FLAGS_isymbols.empty() + FST_FLAGS_isymbols.empty() ? nullptr - : SymbolTable::ReadText(FLAGS_isymbols, opts)); + : SymbolTable::ReadText(FST_FLAGS_isymbols, opts)); const std::unique_ptr relabel_isymbols( - FLAGS_relabel_isymbols.empty() + FST_FLAGS_relabel_isymbols.empty() ? nullptr - : SymbolTable::ReadText(FLAGS_relabel_isymbols, opts)); + : SymbolTable::ReadText(FST_FLAGS_relabel_isymbols, + opts)); bool attach_new_osymbols = (fst->OutputSymbols() != nullptr); std::unique_ptr old_osymbols( - FLAGS_osymbols.empty() + FST_FLAGS_osymbols.empty() ? nullptr - : SymbolTable::ReadText(FLAGS_osymbols, opts)); + : SymbolTable::ReadText(FST_FLAGS_osymbols, opts)); const std::unique_ptr relabel_osymbols( - FLAGS_relabel_osymbols.empty() + FST_FLAGS_relabel_osymbols.empty() ? nullptr - : SymbolTable::ReadText(FLAGS_relabel_osymbols, opts)); - s::Relabel( - fst.get(), old_isymbols ? old_isymbols.get() : fst->InputSymbols(), - relabel_isymbols.get(), FLAGS_unknown_isymbol, attach_new_isymbols, - old_osymbols ? old_osymbols.get() : fst->OutputSymbols(), - relabel_osymbols.get(), FLAGS_unknown_osymbol, attach_new_osymbols); + : SymbolTable::ReadText(FST_FLAGS_relabel_osymbols, + opts)); + s::Relabel(fst.get(), + old_isymbols ? old_isymbols.get() : fst->InputSymbols(), + relabel_isymbols.get(), FST_FLAGS_unknown_isymbol, + attach_new_isymbols, + old_osymbols ? old_osymbols.get() : fst->OutputSymbols(), + relabel_osymbols.get(), FST_FLAGS_unknown_osymbol, + attach_new_osymbols); } else { // Reads in relabeling pairs. std::vector> ipairs; - if (!FLAGS_relabel_ipairs.empty()) { - if (!ReadLabelPairs(FLAGS_relabel_ipairs, &ipairs, - FLAGS_allow_negative_labels)) + if (!FST_FLAGS_relabel_ipairs.empty()) { + if (!ReadLabelPairs(FST_FLAGS_relabel_ipairs, &ipairs, + FST_FLAGS_allow_negative_labels)) return 1; } std::vector> opairs; - if (!FLAGS_relabel_opairs.empty()) { - if (!ReadLabelPairs(FLAGS_relabel_opairs, &opairs, - FLAGS_allow_negative_labels)) + if (!FST_FLAGS_relabel_opairs.empty()) { + if (!ReadLabelPairs(FST_FLAGS_relabel_opairs, &opairs, + FST_FLAGS_allow_negative_labels)) return 1; } s::Relabel(fst.get(), ipairs, opairs); diff --git a/src/bin/fstreplace-main.cc b/src/bin/fstreplace-main.cc index 6da624e..61912b7 100644 --- a/src/bin/fstreplace-main.cc +++ b/src/bin/fstreplace-main.cc @@ -66,18 +66,18 @@ int fstreplace_main(int argc, char **argv) { } ReplaceLabelType call_label_type; - if (!s::GetReplaceLabelType(FLAGS_call_arc_labeling, - FLAGS_epsilon_on_replace, + if (!s::GetReplaceLabelType(FST_FLAGS_call_arc_labeling, + FST_FLAGS_epsilon_on_replace, &call_label_type)) { LOG(ERROR) << argv[0] << ": Unknown or unsupported call arc replace " - << "label type: " << FLAGS_call_arc_labeling; + << "label type: " << FST_FLAGS_call_arc_labeling; } ReplaceLabelType return_label_type; - if (!s::GetReplaceLabelType(FLAGS_return_arc_labeling, - FLAGS_epsilon_on_replace, + if (!s::GetReplaceLabelType(FST_FLAGS_return_arc_labeling, + FST_FLAGS_epsilon_on_replace, &return_label_type)) { LOG(ERROR) << argv[0] << ": Unknown or unsupported return arc replace " - << "label type: " << FLAGS_return_arc_labeling; + << "label type: " << FST_FLAGS_return_arc_labeling; } if (pairs.empty()) { LOG(ERROR) << argv[0] << "At least one replace pair must be provided."; @@ -85,7 +85,7 @@ int fstreplace_main(int argc, char **argv) { } const auto root = pairs.front().first; const s::ReplaceOptions opts(root, call_label_type, return_label_type, - FLAGS_return_label); + FST_FLAGS_return_label); VectorFstClass ofst(pairs.back().second->ArcType()); s::Replace(s::BorrowPairs(pairs), &ofst, opts); diff --git a/src/bin/fstreverse-main.cc b/src/bin/fstreverse-main.cc index 73ef449..41570f9 100644 --- a/src/bin/fstreverse-main.cc +++ b/src/bin/fstreverse-main.cc @@ -53,7 +53,7 @@ int fstreverse_main(int argc, char **argv) { VectorFstClass ofst(ifst->ArcType()); - s::Reverse(*ifst, &ofst, FLAGS_require_superinitial); + s::Reverse(*ifst, &ofst, FST_FLAGS_require_superinitial); return !ofst.Write(out_name); } diff --git a/src/bin/fstreweight-main.cc b/src/bin/fstreweight-main.cc index 09c3d53..8e58441 100644 --- a/src/bin/fstreweight-main.cc +++ b/src/bin/fstreweight-main.cc @@ -58,7 +58,7 @@ int fstreweight_main(int argc, char **argv) { } s::Reweight(fst.get(), potential, - s::GetReweightType(FLAGS_to_final)); + s::GetReweightType(FST_FLAGS_to_final)); return !fst->Write(out_name); } diff --git a/src/bin/fstrmepsilon-main.cc b/src/bin/fstrmepsilon-main.cc index c6674ff..6bbb9f2 100644 --- a/src/bin/fstrmepsilon-main.cc +++ b/src/bin/fstrmepsilon-main.cc @@ -58,20 +58,20 @@ int fstrmepsilon_main(int argc, char **argv) { if (!fst) return 1; const auto weight_threshold = - FLAGS_weight.empty() + FST_FLAGS_weight.empty() ? WeightClass::Zero(fst->WeightType()) - : WeightClass(fst->WeightType(), FLAGS_weight); + : WeightClass(fst->WeightType(), FST_FLAGS_weight); QueueType queue_type; - if (!s::GetQueueType(FLAGS_queue_type, &queue_type)) { - LOG(ERROR) << argv[0] - << ": Unknown or unsupported queue type: " << FLAGS_queue_type; + if (!s::GetQueueType(FST_FLAGS_queue_type, &queue_type)) { + LOG(ERROR) << argv[0] << ": Unknown or unsupported queue type: " + << FST_FLAGS_queue_type; return 1; } - const s::RmEpsilonOptions opts(queue_type, FLAGS_connect, - weight_threshold, FLAGS_nstate, - FLAGS_delta); + const s::RmEpsilonOptions opts(queue_type, FST_FLAGS_connect, + weight_threshold, FST_FLAGS_nstate, + FST_FLAGS_delta); s::RmEpsilon(fst.get(), opts); diff --git a/src/bin/fstshortestdistance-main.cc b/src/bin/fstshortestdistance-main.cc index 35454da..0512b4d 100644 --- a/src/bin/fstshortestdistance-main.cc +++ b/src/bin/fstshortestdistance-main.cc @@ -62,24 +62,24 @@ int fstshortestdistance_main(int argc, char **argv) { std::vector distance; QueueType queue_type; - if (!s::GetQueueType(FLAGS_queue_type, &queue_type)) { - LOG(ERROR) << argv[0] - << ": Unknown or unsupported queue type: " << FLAGS_queue_type; + if (!s::GetQueueType(FST_FLAGS_queue_type, &queue_type)) { + LOG(ERROR) << argv[0] << ": Unknown or unsupported queue type: " + << FST_FLAGS_queue_type; return 1; } - if (FLAGS_reverse && queue_type != AUTO_QUEUE) { + if (FST_FLAGS_reverse && queue_type != AUTO_QUEUE) { LOG(ERROR) << argv[0] << ": Can't use non-default queue with reverse"; return 1; } - if (FLAGS_reverse) { - s::ShortestDistance(*ifst, &distance, FLAGS_reverse, - FLAGS_delta); + if (FST_FLAGS_reverse) { + s::ShortestDistance(*ifst, &distance, FST_FLAGS_reverse, + FST_FLAGS_delta); } else { const s::ShortestDistanceOptions opts(queue_type, s::ArcFilterType::ANY, - FLAGS_nstate, - FLAGS_delta); + FST_FLAGS_nstate, + FST_FLAGS_delta); s::ShortestDistance(*ifst, &distance, opts); } diff --git a/src/bin/fstshortestpath-main.cc b/src/bin/fstshortestpath-main.cc index 3ae6ae6..65adf65 100644 --- a/src/bin/fstshortestpath-main.cc +++ b/src/bin/fstshortestpath-main.cc @@ -61,22 +61,23 @@ int fstshortestpath_main(int argc, char **argv) { if (!ifst) return 1; const auto weight_threshold = - FLAGS_weight.empty() + FST_FLAGS_weight.empty() ? WeightClass::Zero(ifst->WeightType()) - : WeightClass(ifst->WeightType(), FLAGS_weight); + : WeightClass(ifst->WeightType(), FST_FLAGS_weight); VectorFstClass ofst(ifst->ArcType()); QueueType queue_type; - if (!s::GetQueueType(FLAGS_queue_type, &queue_type)) { - LOG(ERROR) << "Unknown or unsupported queue type: " << FLAGS_queue_type; + if (!s::GetQueueType(FST_FLAGS_queue_type, &queue_type)) { + LOG(ERROR) << "Unknown or unsupported queue type: " + << FST_FLAGS_queue_type; return 1; } const s::ShortestPathOptions opts( - queue_type, FLAGS_nshortest, FLAGS_unique, - FLAGS_delta, weight_threshold, - FLAGS_nstate); + queue_type, FST_FLAGS_nshortest, FST_FLAGS_unique, + FST_FLAGS_delta, weight_threshold, + FST_FLAGS_nstate); s::ShortestPath(*ifst, &ofst, opts); diff --git a/src/bin/fstsymbols-main.cc b/src/bin/fstsymbols-main.cc index d7b5503..329a762 100644 --- a/src/bin/fstsymbols-main.cc +++ b/src/bin/fstsymbols-main.cc @@ -68,62 +68,62 @@ int fstsymbols_main(int argc, char **argv) { std::unique_ptr fst(MutableFstClass::Read(in_name, true)); if (!fst) return 1; - if (!FLAGS_save_isymbols.empty()) { + if (!FST_FLAGS_save_isymbols.empty()) { const auto *isyms = fst->InputSymbols(); if (isyms) { - isyms->WriteText(FLAGS_save_isymbols); + isyms->WriteText(FST_FLAGS_save_isymbols); } else { LOG(ERROR) << argv[0] << ": Saving isymbols but there are no input symbols."; } } - if (!FLAGS_save_osymbols.empty()) { + if (!FST_FLAGS_save_osymbols.empty()) { const auto *osyms = fst->OutputSymbols(); if (osyms) { - osyms->WriteText(FLAGS_save_osymbols); + osyms->WriteText(FST_FLAGS_save_osymbols); } else { LOG(ERROR) << argv[0] << ": Saving osymbols but there are no output symbols."; } } - const SymbolTableTextOptions opts(FLAGS_allow_negative_labels); + const SymbolTableTextOptions opts(FST_FLAGS_allow_negative_labels); std::unique_ptr isyms; - if (!FLAGS_isymbols.empty()) { - isyms.reset(SymbolTable::ReadText(FLAGS_isymbols, opts)); + if (!FST_FLAGS_isymbols.empty()) { + isyms.reset(SymbolTable::ReadText(FST_FLAGS_isymbols, opts)); fst->SetInputSymbols(isyms.get()); - } else if (FLAGS_clear_isymbols) { + } else if (FST_FLAGS_clear_isymbols) { fst->SetInputSymbols(nullptr); } std::unique_ptr osyms; - if (!FLAGS_osymbols.empty()) { - osyms.reset(SymbolTable::ReadText(FLAGS_osymbols, opts)); + if (!FST_FLAGS_osymbols.empty()) { + osyms.reset(SymbolTable::ReadText(FST_FLAGS_osymbols, opts)); fst->SetOutputSymbols(osyms.get()); - } else if (FLAGS_clear_osymbols) { + } else if (FST_FLAGS_clear_osymbols) { fst->SetOutputSymbols(nullptr); } using Label = int64; - if (!FLAGS_relabel_ipairs.empty()) { + if (!FST_FLAGS_relabel_ipairs.empty()) { std::vector> ipairs; - ReadLabelPairs(FLAGS_relabel_ipairs, &ipairs, - FLAGS_allow_negative_labels); + ReadLabelPairs(FST_FLAGS_relabel_ipairs, &ipairs, + FST_FLAGS_allow_negative_labels); std::unique_ptr isyms_relabel( RelabelSymbolTable(fst->InputSymbols(), ipairs)); fst->SetInputSymbols(isyms_relabel.get()); } - if (!FLAGS_relabel_opairs.empty()) { + if (!FST_FLAGS_relabel_opairs.empty()) { std::vector> opairs; - ReadLabelPairs(FLAGS_relabel_opairs, &opairs, - FLAGS_allow_negative_labels); + ReadLabelPairs(FST_FLAGS_relabel_opairs, &opairs, + FST_FLAGS_allow_negative_labels); std::unique_ptr osyms_relabel( RelabelSymbolTable(fst->OutputSymbols(), opairs)); fst->SetOutputSymbols(osyms_relabel.get()); } - if (FLAGS_verify && !s::Verify(*fst)) return 1; + if (FST_FLAGS_verify && !s::Verify(*fst)) return 1; return !fst->Write(out_name); } diff --git a/src/extensions/Makefile.in b/src/extensions/Makefile.in index 40cc263..7090a14 100644 --- a/src/extensions/Makefile.in +++ b/src/extensions/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2020 Free Software Foundation, Inc. diff --git a/src/extensions/compact/Makefile.am b/src/extensions/compact/Makefile.am index 5e1fde8..c3c70ae 100644 --- a/src/extensions/compact/Makefile.am +++ b/src/extensions/compact/Makefile.am @@ -7,7 +7,7 @@ libfst_LTLIBRARIES = compact8_acceptor-fst.la compact8_string-fst.la compact8_un lib_LTLIBRARIES = libfstcompact.la libfstcompact_la_SOURCES = compact8_acceptor-fst.cc compact8_string-fst.cc compact8_unweighted-fst.cc compact8_unweighted_acceptor-fst.cc compact8_weighted_string-fst.cc compact16_acceptor-fst.cc compact16_string-fst.cc compact16_unweighted-fst.cc compact16_unweighted_acceptor-fst.cc compact16_weighted_string-fst.cc compact64_acceptor-fst.cc compact64_string-fst.cc compact64_unweighted-fst.cc compact64_unweighted_acceptor-fst.cc compact64_weighted_string-fst.cc -libfstcompact_la_LDFLAGS = -version-info 23:0:0 +libfstcompact_la_LDFLAGS = -version-info 24:0:0 compact8_acceptor_fst_la_SOURCES = compact8_acceptor-fst.cc compact8_acceptor_fst_la_LDFLAGS = -avoid-version -module diff --git a/src/extensions/compact/Makefile.in b/src/extensions/compact/Makefile.in index ed56736..f0feccc 100644 --- a/src/extensions/compact/Makefile.in +++ b/src/extensions/compact/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2020 Free Software Foundation, Inc. @@ -527,7 +527,7 @@ AM_CPPFLAGS = -I$(srcdir)/../../include $(ICU_CPPFLAGS) libfst_LTLIBRARIES = compact8_acceptor-fst.la compact8_string-fst.la compact8_unweighted-fst.la compact8_unweighted_acceptor-fst.la compact8_weighted_string-fst.la compact16_acceptor-fst.la compact16_string-fst.la compact16_unweighted-fst.la compact16_unweighted_acceptor-fst.la compact16_weighted_string-fst.la compact64_acceptor-fst.la compact64_string-fst.la compact64_unweighted-fst.la compact64_unweighted_acceptor-fst.la compact64_weighted_string-fst.la lib_LTLIBRARIES = libfstcompact.la libfstcompact_la_SOURCES = compact8_acceptor-fst.cc compact8_string-fst.cc compact8_unweighted-fst.cc compact8_unweighted_acceptor-fst.cc compact8_weighted_string-fst.cc compact16_acceptor-fst.cc compact16_string-fst.cc compact16_unweighted-fst.cc compact16_unweighted_acceptor-fst.cc compact16_weighted_string-fst.cc compact64_acceptor-fst.cc compact64_string-fst.cc compact64_unweighted-fst.cc compact64_unweighted_acceptor-fst.cc compact64_weighted_string-fst.cc -libfstcompact_la_LDFLAGS = -version-info 23:0:0 +libfstcompact_la_LDFLAGS = -version-info 24:0:0 compact8_acceptor_fst_la_SOURCES = compact8_acceptor-fst.cc compact8_acceptor_fst_la_LDFLAGS = -avoid-version -module compact8_string_fst_la_SOURCES = compact8_string-fst.cc diff --git a/src/extensions/compress/Makefile.am b/src/extensions/compress/Makefile.am index 6d024b4..c6c5b79 100644 --- a/src/extensions/compress/Makefile.am +++ b/src/extensions/compress/Makefile.am @@ -13,7 +13,7 @@ endif if HAVE_SCRIPT libfstcompressscript_la_SOURCES = compressscript.cc -libfstcompressscript_la_LDFLAGS = -version-info 23:0:0 +libfstcompressscript_la_LDFLAGS = -version-info 24:0:0 libfstcompressscript_la_LIBADD = ../../script/libfstscript.la \ ../../lib/libfst.la \ -lm $(DL_LIBS) diff --git a/src/extensions/compress/Makefile.in b/src/extensions/compress/Makefile.in index 77f1735..17b7fc2 100644 --- a/src/extensions/compress/Makefile.in +++ b/src/extensions/compress/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2020 Free Software Foundation, Inc. @@ -370,7 +370,7 @@ AM_CPPFLAGS = -I$(srcdir)/../../include $(ICU_CPPFLAGS) @HAVE_BIN_TRUE@fstcompress_SOURCES = fstcompress.cc fstcompress-main.cc @HAVE_SCRIPT_TRUE@libfstcompressscript_la_SOURCES = compressscript.cc -@HAVE_SCRIPT_TRUE@libfstcompressscript_la_LDFLAGS = -version-info 23:0:0 +@HAVE_SCRIPT_TRUE@libfstcompressscript_la_LDFLAGS = -version-info 24:0:0 @HAVE_SCRIPT_TRUE@libfstcompressscript_la_LIBADD = ../../script/libfstscript.la \ @HAVE_SCRIPT_TRUE@ ../../lib/libfst.la \ @HAVE_SCRIPT_TRUE@ -lm $(DL_LIBS) diff --git a/src/extensions/compress/fstcompress-main.cc b/src/extensions/compress/fstcompress-main.cc index a7dcdd6..7a7c410 100644 --- a/src/extensions/compress/fstcompress-main.cc +++ b/src/extensions/compress/fstcompress-main.cc @@ -52,8 +52,8 @@ int fstcompress_main(int argc, char **argv) { const std::string out_name = (argc > 2 && (strcmp(argv[2], "-") != 0)) ? argv[2] : ""; - if (FLAGS_decode) { - VectorFstClass fst(FLAGS_arc_type); + if (FST_FLAGS_decode) { + VectorFstClass fst(FST_FLAGS_arc_type); if (!s::Decompress(in_name, &fst)) { FSTERROR() << "Decompression failed"; return 1; diff --git a/src/extensions/const/Makefile.am b/src/extensions/const/Makefile.am index 5173b3f..8292b82 100644 --- a/src/extensions/const/Makefile.am +++ b/src/extensions/const/Makefile.am @@ -7,7 +7,7 @@ libfst_LTLIBRARIES = const8-fst.la const16-fst.la const64-fst.la lib_LTLIBRARIES = libfstconst.la libfstconst_la_SOURCES = const8-fst.cc const16-fst.cc const64-fst.cc -libfstconst_la_LDFLAGS = -version-info 23:0:0 +libfstconst_la_LDFLAGS = -version-info 24:0:0 const8_fst_la_SOURCES = const8-fst.cc const8_fst_la_LDFLAGS = -avoid-version -module diff --git a/src/extensions/const/Makefile.in b/src/extensions/const/Makefile.in index 6ac1efb..9376855 100644 --- a/src/extensions/const/Makefile.in +++ b/src/extensions/const/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2020 Free Software Foundation, Inc. @@ -371,7 +371,7 @@ AM_CPPFLAGS = -I$(srcdir)/../../include $(ICU_CPPFLAGS) libfst_LTLIBRARIES = const8-fst.la const16-fst.la const64-fst.la lib_LTLIBRARIES = libfstconst.la libfstconst_la_SOURCES = const8-fst.cc const16-fst.cc const64-fst.cc -libfstconst_la_LDFLAGS = -version-info 23:0:0 +libfstconst_la_LDFLAGS = -version-info 24:0:0 const8_fst_la_SOURCES = const8-fst.cc const8_fst_la_LDFLAGS = -avoid-version -module const16_fst_la_SOURCES = const16-fst.cc diff --git a/src/extensions/far/Makefile.am b/src/extensions/far/Makefile.am index 5358334..8b66c9f 100644 --- a/src/extensions/far/Makefile.am +++ b/src/extensions/far/Makefile.am @@ -9,13 +9,13 @@ lib_LTLIBRARIES = libfstfar.la endif libfstfar_la_SOURCES = sttable.cc stlist.cc -libfstfar_la_LDFLAGS = -version-info 23:0:0 +libfstfar_la_LDFLAGS = -version-info 24:0:0 libfstfar_la_LIBADD = ../../lib/libfst.la -lm $(DL_LIBS) if HAVE_SCRIPT libfstfarscript_la_SOURCES = far-class.cc farscript.cc getters.cc script-impl.cc \ strings.cc sttable.cc stlist.cc -libfstfarscript_la_LDFLAGS = -version-info 23:0:0 +libfstfarscript_la_LDFLAGS = -version-info 24:0:0 libfstfarscript_la_LIBADD = \ libfstfar.la ../../script/libfstscript.la \ ../../lib/libfst.la -lm $(DL_LIBS) diff --git a/src/extensions/far/Makefile.in b/src/extensions/far/Makefile.in index 49ea4d3..e0cea4d 100644 --- a/src/extensions/far/Makefile.in +++ b/src/extensions/far/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2020 Free Software Foundation, Inc. @@ -461,12 +461,12 @@ EXTRA_DIST = build_defs.bzl @HAVE_SCRIPT_FALSE@lib_LTLIBRARIES = libfstfar.la @HAVE_SCRIPT_TRUE@lib_LTLIBRARIES = libfstfar.la libfstfarscript.la libfstfar_la_SOURCES = sttable.cc stlist.cc -libfstfar_la_LDFLAGS = -version-info 23:0:0 +libfstfar_la_LDFLAGS = -version-info 24:0:0 libfstfar_la_LIBADD = ../../lib/libfst.la -lm $(DL_LIBS) @HAVE_SCRIPT_TRUE@libfstfarscript_la_SOURCES = far-class.cc farscript.cc getters.cc script-impl.cc \ @HAVE_SCRIPT_TRUE@ strings.cc sttable.cc stlist.cc -@HAVE_SCRIPT_TRUE@libfstfarscript_la_LDFLAGS = -version-info 23:0:0 +@HAVE_SCRIPT_TRUE@libfstfarscript_la_LDFLAGS = -version-info 24:0:0 @HAVE_SCRIPT_TRUE@libfstfarscript_la_LIBADD = \ @HAVE_SCRIPT_TRUE@ libfstfar.la ../../script/libfstscript.la \ @HAVE_SCRIPT_TRUE@ ../../lib/libfst.la -lm $(DL_LIBS) diff --git a/src/extensions/far/farcompilestrings-main.cc b/src/extensions/far/farcompilestrings-main.cc index f5f7c2d..a79f1ef 100644 --- a/src/extensions/far/farcompilestrings-main.cc +++ b/src/extensions/far/farcompilestrings-main.cc @@ -53,7 +53,7 @@ int farcompilestrings_main(int argc, char **argv) { s::ExpandArgs(argc, argv, &argc, &argv); std::vector in_sources; - if (FLAGS_file_list_input) { + if (FST_FLAGS_file_list_input) { for (int i = 1; i < argc - 1; ++i) { std::ifstream istrm(argv[i]); std::string str; @@ -75,33 +75,39 @@ int farcompilestrings_main(int argc, char **argv) { argc > 2 && strcmp(argv[argc - 1], "-") != 0 ? argv[argc - 1] : ""; fst::FarEntryType entry_type; - if (!s::GetFarEntryType(FLAGS_entry_type, &entry_type)) { - LOG(ERROR) << "Unknown or unsupported FAR entry type: " << FLAGS_entry_type; + if (!s::GetFarEntryType(FST_FLAGS_entry_type, &entry_type)) { + LOG(ERROR) << "Unknown or unsupported FAR entry type: " + << FST_FLAGS_entry_type; return 1; } fst::TokenType token_type; - if (!s::GetTokenType(FLAGS_token_type, &token_type)) { - LOG(ERROR) << "Unknown or unsupported FAR token type: " << FLAGS_token_type; + if (!s::GetTokenType(FST_FLAGS_token_type, &token_type)) { + LOG(ERROR) << "Unknown or unsupported FAR token type: " + << FST_FLAGS_token_type; return 1; } fst::FarType far_type; - if (!s::GetFarType(FLAGS_far_type, &far_type)) { - LOG(ERROR) << "Unknown or unsupported FAR type: " << FLAGS_far_type; + if (!s::GetFarType(FST_FLAGS_far_type, &far_type)) { + LOG(ERROR) << "Unknown or unsupported FAR type: " + << FST_FLAGS_far_type; return 1; } // Empty fst_type means vector for farcompilestrings, but "input FST type" // for farconvert. - const std::string fst_type = - FLAGS_fst_type.empty() ? "vector" : FLAGS_fst_type; + const std::string fst_type = FST_FLAGS_fst_type.empty() + ? "vector" + : FST_FLAGS_fst_type; - s::FarCompileStrings(in_sources, out_source, FLAGS_arc_type, fst_type, - far_type, FLAGS_generate_keys, entry_type, token_type, - FLAGS_symbols, FLAGS_unknown_symbol, FLAGS_keep_symbols, - FLAGS_initial_symbols, FLAGS_allow_negative_labels, - FLAGS_key_prefix, FLAGS_key_suffix); + s::FarCompileStrings( + in_sources, out_source, FST_FLAGS_arc_type, fst_type, far_type, + FST_FLAGS_generate_keys, entry_type, token_type, + FST_FLAGS_symbols, FST_FLAGS_unknown_symbol, + FST_FLAGS_keep_symbols, FST_FLAGS_initial_symbols, + FST_FLAGS_allow_negative_labels, + FST_FLAGS_key_prefix, FST_FLAGS_key_suffix); return 0; } diff --git a/src/extensions/far/farconvert-main.cc b/src/extensions/far/farconvert-main.cc index d9211a1..3445f04 100644 --- a/src/extensions/far/farconvert-main.cc +++ b/src/extensions/far/farconvert-main.cc @@ -53,8 +53,8 @@ int farconvert_main(int argc, char *argv[]) { argc > 2 && std::strcmp(argv[2], "-") != 0 ? argv[2] : ""; fst::FarType far_type; - if (!s::GetFarType(FLAGS_far_type, &far_type)) { - LOG(ERROR) << "Unknown --far_type " << FLAGS_far_type; + if (!s::GetFarType(FST_FLAGS_far_type, &far_type)) { + LOG(ERROR) << "Unknown --far_type " << FST_FLAGS_far_type; return 1; } @@ -83,7 +83,8 @@ int farconvert_main(int argc, char *argv[]) { } // Empty fst_type means use input fst type for each fst individually. - s::FarConvert(in_far, out_far, arc_type, FLAGS_fst_type, far_type); + s::FarConvert(in_far, out_far, arc_type, FST_FLAGS_fst_type, + far_type); return 0; } diff --git a/src/extensions/far/farcreate-main.cc b/src/extensions/far/farcreate-main.cc index b313945..ab86463 100644 --- a/src/extensions/far/farcreate-main.cc +++ b/src/extensions/far/farcreate-main.cc @@ -45,7 +45,7 @@ int farcreate_main(int argc, char **argv) { s::ExpandArgs(argc, argv, &argc, &argv); std::vector in_sources; - if (FLAGS_file_list_input) { + if (FST_FLAGS_file_list_input) { for (int i = 1; i < argc - 1; ++i) { std::ifstream istrm(argv[i]); std::string str; @@ -73,13 +73,16 @@ int farcreate_main(int argc, char **argv) { } fst::FarType far_type; - if (!s::GetFarType(FLAGS_far_type, &far_type)) { - LOG(ERROR) << "Unknown or unsupported FAR type: " << FLAGS_far_type; + if (!s::GetFarType(FST_FLAGS_far_type, &far_type)) { + LOG(ERROR) << "Unknown or unsupported FAR type: " + << FST_FLAGS_far_type; return 1; } - s::FarCreate(in_sources, out_source, arc_type, FLAGS_generate_keys, far_type, - FLAGS_key_prefix, FLAGS_key_suffix); + s::FarCreate(in_sources, out_source, arc_type, + FST_FLAGS_generate_keys, far_type, + FST_FLAGS_key_prefix, + FST_FLAGS_key_suffix); return 0; } diff --git a/src/extensions/far/farequal-main.cc b/src/extensions/far/farequal-main.cc index 528ff87..f14dfb4 100644 --- a/src/extensions/far/farequal-main.cc +++ b/src/extensions/far/farequal-main.cc @@ -46,8 +46,9 @@ int farequal_main(int argc, char **argv) { const auto arc_type = s::LoadArcTypeFromFar(argv[1]); if (arc_type.empty()) return 1; - bool result = s::FarEqual(argv[1], argv[2], arc_type, FLAGS_delta, - FLAGS_begin_key, FLAGS_end_key); + bool result = + s::FarEqual(argv[1], argv[2], arc_type, FST_FLAGS_delta, + FST_FLAGS_begin_key, FST_FLAGS_end_key); if (!result) VLOG(1) << "FARs are not equal."; diff --git a/src/extensions/far/farextract-main.cc b/src/extensions/far/farextract-main.cc index 1627cbc..87095a5 100644 --- a/src/extensions/far/farextract-main.cc +++ b/src/extensions/far/farextract-main.cc @@ -49,9 +49,11 @@ int farextract_main(int argc, char **argv) { const auto arc_type = s::LoadArcTypeFromFar(in_sources[0]); if (arc_type.empty()) return 1; - s::FarExtract(in_sources, arc_type, FLAGS_generate_filenames, FLAGS_keys, - FLAGS_key_separator, FLAGS_range_delimiter, - FLAGS_filename_prefix, FLAGS_filename_suffix); + s::FarExtract(in_sources, arc_type, FST_FLAGS_generate_filenames, + FST_FLAGS_keys, FST_FLAGS_key_separator, + FST_FLAGS_range_delimiter, + FST_FLAGS_filename_prefix, + FST_FLAGS_filename_suffix); return 0; } diff --git a/src/extensions/far/farinfo-main.cc b/src/extensions/far/farinfo-main.cc index d96c17e..9e9955e 100644 --- a/src/extensions/far/farinfo-main.cc +++ b/src/extensions/far/farinfo-main.cc @@ -48,8 +48,8 @@ int farinfo_main(int argc, char **argv) { const auto arc_type = s::LoadArcTypeFromFar(in_sources[0]); if (arc_type.empty()) return 1; - s::FarInfo(in_sources, arc_type, FLAGS_begin_key, FLAGS_end_key, - FLAGS_list_fsts); + s::FarInfo(in_sources, arc_type, FST_FLAGS_begin_key, + FST_FLAGS_end_key, FST_FLAGS_list_fsts); return 0; } diff --git a/src/extensions/far/farisomorphic-main.cc b/src/extensions/far/farisomorphic-main.cc index 4748bd4..baafa20 100644 --- a/src/extensions/far/farisomorphic-main.cc +++ b/src/extensions/far/farisomorphic-main.cc @@ -48,8 +48,9 @@ int farisomorphic_main(int argc, char **argv) { const auto arc_type = s::LoadArcTypeFromFar(argv[1]); if (arc_type.empty()) return 1; - bool result = s::FarIsomorphic(argv[1], argv[2], arc_type, FLAGS_delta, - FLAGS_begin_key, FLAGS_end_key); + bool result = s::FarIsomorphic( + argv[1], argv[2], arc_type, FST_FLAGS_delta, + FST_FLAGS_begin_key, FST_FLAGS_end_key); if (!result) VLOG(1) << "FARs are not isomorphic."; diff --git a/src/extensions/far/farprintstrings-main.cc b/src/extensions/far/farprintstrings-main.cc index ec3e102..898c222 100644 --- a/src/extensions/far/farprintstrings-main.cc +++ b/src/extensions/far/farprintstrings-main.cc @@ -56,22 +56,27 @@ int farprintstrings_main(int argc, char **argv) { if (arc_type.empty()) return 1; fst::FarEntryType entry_type; - if (!s::GetFarEntryType(FLAGS_entry_type, &entry_type)) { - LOG(ERROR) << "Unknown or unsupported FAR entry type: " << FLAGS_entry_type; + if (!s::GetFarEntryType(FST_FLAGS_entry_type, &entry_type)) { + LOG(ERROR) << "Unknown or unsupported FAR entry type: " + << FST_FLAGS_entry_type; return 1; } fst::TokenType token_type; - if (!s::GetTokenType(FLAGS_token_type, &token_type)) { - LOG(ERROR) << "Unknown or unsupported FAR token type: " << FLAGS_token_type; + if (!s::GetTokenType(FST_FLAGS_token_type, &token_type)) { + LOG(ERROR) << "Unknown or unsupported FAR token type: " + << FST_FLAGS_token_type; return 1; } - s::FarPrintStrings(in_sources, arc_type, entry_type, token_type, - FLAGS_begin_key, FLAGS_end_key, FLAGS_print_key, - FLAGS_print_weight, FLAGS_symbols, FLAGS_initial_symbols, - FLAGS_generate_filenames, FLAGS_filename_prefix, - FLAGS_filename_suffix); + s::FarPrintStrings( + in_sources, arc_type, entry_type, token_type, + FST_FLAGS_begin_key, FST_FLAGS_end_key, + FST_FLAGS_print_key, FST_FLAGS_print_weight, + FST_FLAGS_symbols, FST_FLAGS_initial_symbols, + FST_FLAGS_generate_filenames, + FST_FLAGS_filename_prefix, + FST_FLAGS_filename_suffix); return 0; } diff --git a/src/extensions/linear/Makefile.am b/src/extensions/linear/Makefile.am index 0619c75..6e0cb85 100644 --- a/src/extensions/linear/Makefile.am +++ b/src/extensions/linear/Makefile.am @@ -15,7 +15,7 @@ if HAVE_SCRIPT lib_LTLIBRARIES = libfstlinearscript.la libfstlinearscript_la_SOURCES = linearscript.cc -libfstlinearscript_la_LDFLAGS = -version-info 23:0:0 +libfstlinearscript_la_LDFLAGS = -version-info 24:0:0 libfstlinearscript_la_LIBADD = ../../script/libfstscript.la endif diff --git a/src/extensions/linear/Makefile.in b/src/extensions/linear/Makefile.in index c5d48d5..1ad15c2 100644 --- a/src/extensions/linear/Makefile.in +++ b/src/extensions/linear/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2020 Free Software Foundation, Inc. @@ -396,7 +396,7 @@ AM_CPPFLAGS = -I$(srcdir)/../../include $(ICU_CPPFLAGS) @HAVE_BIN_TRUE@fstloglinearapply_LDADD = libfstlinearscript.la ../../script/libfstscript.la @HAVE_SCRIPT_TRUE@lib_LTLIBRARIES = libfstlinearscript.la @HAVE_SCRIPT_TRUE@libfstlinearscript_la_SOURCES = linearscript.cc -@HAVE_SCRIPT_TRUE@libfstlinearscript_la_LDFLAGS = -version-info 23:0:0 +@HAVE_SCRIPT_TRUE@libfstlinearscript_la_LDFLAGS = -version-info 24:0:0 @HAVE_SCRIPT_TRUE@libfstlinearscript_la_LIBADD = ../../script/libfstscript.la libfst_LTLIBRARIES = linear_tagger-fst.la linear_classifier-fst.la linear_tagger_fst_la_SOURCES = linear-tagger-fst.cc diff --git a/src/extensions/linear/fstlinear-main.cc b/src/extensions/linear/fstlinear-main.cc index 29331dd..35ed679 100644 --- a/src/extensions/linear/fstlinear-main.cc +++ b/src/extensions/linear/fstlinear-main.cc @@ -39,10 +39,11 @@ int fstlinear_main(int argc, char **argv) { return 1; } - fst::script::LinearCompile(FLAGS_arc_type, FLAGS_epsilon_symbol, - FLAGS_unknown_symbol, FLAGS_vocab, argv + 1, - argc - 1, FLAGS_out, FLAGS_save_isymbols, - FLAGS_save_fsymbols, FLAGS_save_osymbols); + fst::script::LinearCompile( + FST_FLAGS_arc_type, FST_FLAGS_epsilon_symbol, + FST_FLAGS_unknown_symbol, FST_FLAGS_vocab, argv + 1, + argc - 1, FST_FLAGS_out, FST_FLAGS_save_isymbols, + FST_FLAGS_save_fsymbols, FST_FLAGS_save_osymbols); return 0; } diff --git a/src/extensions/linear/fstloglinearapply-main.cc b/src/extensions/linear/fstloglinearapply-main.cc index 0d68363..6de6f22 100644 --- a/src/extensions/linear/fstloglinearapply-main.cc +++ b/src/extensions/linear/fstloglinearapply-main.cc @@ -57,7 +57,8 @@ int fstloglinearapply_main(int argc, char **argv) { fst::StdVectorFst ofst; - fst::LogLinearApply(*ifst1, *ifst2, &ofst, FLAGS_normalize); + fst::LogLinearApply(*ifst1, *ifst2, &ofst, + FST_FLAGS_normalize); return !ofst.Write(out_name); } diff --git a/src/extensions/linear/linearscript.cc b/src/extensions/linear/linearscript.cc index c524c93..98cf63d 100644 --- a/src/extensions/linear/linearscript.cc +++ b/src/extensions/linear/linearscript.cc @@ -43,13 +43,14 @@ namespace fst { namespace script { bool ValidateDelimiter() { - return FLAGS_delimiter.size() == 1 && !std::isspace(FLAGS_delimiter[0]); + return FST_FLAGS_delimiter.size() == 1 && + !std::isspace(FST_FLAGS_delimiter[0]); } bool ValidateEmptySymbol() { - bool okay = !FLAGS_empty_symbol.empty(); - for (size_t i = 0; i < FLAGS_empty_symbol.size(); ++i) { - char c = FLAGS_empty_symbol[i]; + bool okay = !FST_FLAGS_empty_symbol.empty(); + for (size_t i = 0; i < FST_FLAGS_empty_symbol.size(); ++i) { + char c = FST_FLAGS_empty_symbol[i]; if (std::isspace(c)) okay = false; } return okay; diff --git a/src/extensions/lookahead/Makefile.am b/src/extensions/lookahead/Makefile.am index 0920be7..6c9b6b8 100644 --- a/src/extensions/lookahead/Makefile.am +++ b/src/extensions/lookahead/Makefile.am @@ -9,7 +9,7 @@ lib_LTLIBRARIES = libfstlookahead.la libfstlookahead_la_SOURCES = arc_lookahead-fst.cc ilabel_lookahead-fst.cc \ olabel_lookahead-fst.cc -libfstlookahead_la_LDFLAGS = -version-info 23:0:0 +libfstlookahead_la_LDFLAGS = -version-info 24:0:0 arc_lookahead_fst_la_SOURCES = arc_lookahead-fst.cc arc_lookahead_fst_la_LDFLAGS = -avoid-version -module diff --git a/src/extensions/lookahead/Makefile.in b/src/extensions/lookahead/Makefile.in index fe9001b..3b53a40 100644 --- a/src/extensions/lookahead/Makefile.in +++ b/src/extensions/lookahead/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2020 Free Software Foundation, Inc. @@ -382,7 +382,7 @@ lib_LTLIBRARIES = libfstlookahead.la libfstlookahead_la_SOURCES = arc_lookahead-fst.cc ilabel_lookahead-fst.cc \ olabel_lookahead-fst.cc -libfstlookahead_la_LDFLAGS = -version-info 23:0:0 +libfstlookahead_la_LDFLAGS = -version-info 24:0:0 arc_lookahead_fst_la_SOURCES = arc_lookahead-fst.cc arc_lookahead_fst_la_LDFLAGS = -avoid-version -module ilabel_lookahead_fst_la_SOURCES = ilabel_lookahead-fst.cc diff --git a/src/extensions/mpdt/Makefile.am b/src/extensions/mpdt/Makefile.am index 44fdf60..40934d0 100644 --- a/src/extensions/mpdt/Makefile.am +++ b/src/extensions/mpdt/Makefile.am @@ -20,7 +20,7 @@ endif if HAVE_SCRIPT lib_LTLIBRARIES = libfstmpdtscript.la libfstmpdtscript_la_SOURCES = mpdtscript.cc -libfstmpdtscript_la_LDFLAGS = -version-info 23:0:0 +libfstmpdtscript_la_LDFLAGS = -version-info 24:0:0 libfstmpdtscript_la_LIBADD = ../../script/libfstscript.la \ ../../lib/libfst.la -lm $(DL_LIBS) endif diff --git a/src/extensions/mpdt/Makefile.in b/src/extensions/mpdt/Makefile.in index b284cb1..1bc3fc9 100644 --- a/src/extensions/mpdt/Makefile.in +++ b/src/extensions/mpdt/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2020 Free Software Foundation, Inc. @@ -407,7 +407,7 @@ AM_CPPFLAGS = -I$(srcdir)/../../include $(ICU_CPPFLAGS) @HAVE_BIN_TRUE@mpdtreverse_SOURCES = mpdtreverse.cc mpdtreverse-main.cc @HAVE_SCRIPT_TRUE@lib_LTLIBRARIES = libfstmpdtscript.la @HAVE_SCRIPT_TRUE@libfstmpdtscript_la_SOURCES = mpdtscript.cc -@HAVE_SCRIPT_TRUE@libfstmpdtscript_la_LDFLAGS = -version-info 23:0:0 +@HAVE_SCRIPT_TRUE@libfstmpdtscript_la_LDFLAGS = -version-info 24:0:0 @HAVE_SCRIPT_TRUE@libfstmpdtscript_la_LIBADD = ../../script/libfstscript.la \ @HAVE_SCRIPT_TRUE@ ../../lib/libfst.la -lm $(DL_LIBS) diff --git a/src/extensions/mpdt/mpdtcompose-main.cc b/src/extensions/mpdt/mpdtcompose-main.cc index da82359..3931101 100644 --- a/src/extensions/mpdt/mpdtcompose-main.cc +++ b/src/extensions/mpdt/mpdtcompose-main.cc @@ -71,30 +71,32 @@ int mpdtcompose_main(int argc, char **argv) { std::unique_ptr ifst2(FstClass::Read(in2_name)); if (!ifst2) return 1; - if (FLAGS_mpdt_parentheses.empty()) { + if (FST_FLAGS_mpdt_parentheses.empty()) { LOG(ERROR) << argv[0] << ": No MPDT parenthesis label pairs provided"; return 1; } std::vector> parens; std::vector assignments; - if (!ReadLabelTriples(FLAGS_mpdt_parentheses, &parens, &assignments, false)) { + if (!ReadLabelTriples(FST_FLAGS_mpdt_parentheses, &parens, + &assignments, false)) { return 1; } VectorFstClass ofst(ifst1->ArcType()); PdtComposeFilter compose_filter; - if (!s::GetPdtComposeFilter(FLAGS_compose_filter, &compose_filter)) { + if (!s::GetPdtComposeFilter(FST_FLAGS_compose_filter, + &compose_filter)) { LOG(ERROR) << argv[0] << ": Unknown or unsupported compose filter type: " - << FLAGS_compose_filter; + << FST_FLAGS_compose_filter; return 1; } - const MPdtComposeOptions opts(FLAGS_connect, compose_filter); + const MPdtComposeOptions opts(FST_FLAGS_connect, compose_filter); s::MPdtCompose(*ifst1, *ifst2, parens, assignments, &ofst, opts, - FLAGS_left_mpdt); + FST_FLAGS_left_mpdt); return !ofst.Write(out_name); } diff --git a/src/extensions/mpdt/mpdtexpand-main.cc b/src/extensions/mpdt/mpdtexpand-main.cc index c8ea03e..999bce1 100644 --- a/src/extensions/mpdt/mpdtexpand-main.cc +++ b/src/extensions/mpdt/mpdtexpand-main.cc @@ -60,20 +60,22 @@ int mpdtexpand_main(int argc, char **argv) { std::unique_ptr ifst(FstClass::Read(in_name)); if (!ifst) return 1; - if (FLAGS_mpdt_parentheses.empty()) { + if (FST_FLAGS_mpdt_parentheses.empty()) { LOG(ERROR) << argv[0] << ": No MPDT parenthesis label pairs provided"; return 1; } std::vector> parens; std::vector assignments; - if (!ReadLabelTriples(FLAGS_mpdt_parentheses, &parens, &assignments, false)) { + if (!ReadLabelTriples(FST_FLAGS_mpdt_parentheses, &parens, + &assignments, false)) { return 1; } VectorFstClass ofst(ifst->ArcType()); - const MPdtExpandOptions opts(FLAGS_connect, FLAGS_keep_parentheses); + const MPdtExpandOptions opts(FST_FLAGS_connect, + FST_FLAGS_keep_parentheses); s::MPdtExpand(*ifst, parens, assignments, &ofst, opts); diff --git a/src/extensions/mpdt/mpdtinfo-main.cc b/src/extensions/mpdt/mpdtinfo-main.cc index a59b440..c316b23 100644 --- a/src/extensions/mpdt/mpdtinfo-main.cc +++ b/src/extensions/mpdt/mpdtinfo-main.cc @@ -55,14 +55,15 @@ int mpdtinfo_main(int argc, char **argv) { std::unique_ptr ifst(FstClass::Read(in_name)); if (!ifst) return 1; - if (FLAGS_mpdt_parentheses.empty()) { + if (FST_FLAGS_mpdt_parentheses.empty()) { LOG(ERROR) << argv[0] << ": No MPDT parenthesis label pairs provided"; return 1; } std::vector> parens; std::vector assignments; - if (!ReadLabelTriples(FLAGS_mpdt_parentheses, &parens, &assignments, false)) { + if (!ReadLabelTriples(FST_FLAGS_mpdt_parentheses, &parens, + &assignments, false)) { return 1; } diff --git a/src/extensions/mpdt/mpdtreverse-main.cc b/src/extensions/mpdt/mpdtreverse-main.cc index 16ee3d5..f0931da 100644 --- a/src/extensions/mpdt/mpdtreverse-main.cc +++ b/src/extensions/mpdt/mpdtreverse-main.cc @@ -59,19 +59,20 @@ int mpdtreverse_main(int argc, char **argv) { std::unique_ptr ifst(FstClass::Read(in_name)); if (!ifst) return 1; - if (FLAGS_mpdt_parentheses.empty()) { + if (FST_FLAGS_mpdt_parentheses.empty()) { LOG(ERROR) << argv[0] << ": No MPDT parenthesis label pairs provided"; return 1; } - if (FLAGS_mpdt_new_parentheses.empty()) { + if (FST_FLAGS_mpdt_new_parentheses.empty()) { LOG(ERROR) << argv[0] << ": No MPDT output parenthesis label file provided"; return 1; } std::vector> parens; std::vector assignments; - if (!ReadLabelTriples(FLAGS_mpdt_parentheses, &parens, &assignments, false)) { + if (!ReadLabelTriples(FST_FLAGS_mpdt_parentheses, &parens, + &assignments, false)) { return 1; } @@ -81,5 +82,6 @@ int mpdtreverse_main(int argc, char **argv) { if (!ofst.Write(out_name)) return 1; - return !WriteLabelTriples(FLAGS_mpdt_new_parentheses, parens, assignments); + return !WriteLabelTriples(FST_FLAGS_mpdt_new_parentheses, parens, + assignments); } diff --git a/src/extensions/ngram/Makefile.am b/src/extensions/ngram/Makefile.am index a9e475a..7d438c5 100644 --- a/src/extensions/ngram/Makefile.am +++ b/src/extensions/ngram/Makefile.am @@ -10,4 +10,4 @@ ngram_fst_la_SOURCES = bitmap-index.cc ngram-fst.cc nthbit.cc ngram_fst_la_LDFLAGS = -avoid-version -module libfstngram_la_SOURCES = bitmap-index.cc ngram-fst.cc nthbit.cc -libfstngram_la_LDFLAGS = -version-info 23:0:0 +libfstngram_la_LDFLAGS = -version-info 24:0:0 diff --git a/src/extensions/ngram/Makefile.in b/src/extensions/ngram/Makefile.in index 0a8ef9c..03497eb 100644 --- a/src/extensions/ngram/Makefile.in +++ b/src/extensions/ngram/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2020 Free Software Foundation, Inc. @@ -355,7 +355,7 @@ lib_LTLIBRARIES = libfstngram.la ngram_fst_la_SOURCES = bitmap-index.cc ngram-fst.cc nthbit.cc ngram_fst_la_LDFLAGS = -avoid-version -module libfstngram_la_SOURCES = bitmap-index.cc ngram-fst.cc nthbit.cc -libfstngram_la_LDFLAGS = -version-info 23:0:0 +libfstngram_la_LDFLAGS = -version-info 24:0:0 all: all-am .SUFFIXES: diff --git a/src/extensions/ngram/nthbit.cc b/src/extensions/ngram/nthbit.cc index 386891e..518604f 100644 --- a/src/extensions/ngram/nthbit.cc +++ b/src/extensions/ngram/nthbit.cc @@ -276,7 +276,7 @@ uint32 nth_bit(const uint64 v, uint32 r) { // constexpr uint64 kOnesStep8 = 0x0101010101010101; // printf("const uint64 kPrefixSumOverflow[64] = {\n"); // for (int k = 0; k < 64; ++k) { -// printf(" 0x%" FST_LL_FORMAT "x,\n", (0x7F - k) * kOnesStep8); +// printf(" 0x%x,\n", (0x7F - k) * kOnesStep8); // } // printf("};\n"); // diff --git a/src/extensions/pdt/Makefile.am b/src/extensions/pdt/Makefile.am index 497c87d..c930d5c 100644 --- a/src/extensions/pdt/Makefile.am +++ b/src/extensions/pdt/Makefile.am @@ -24,7 +24,7 @@ endif if HAVE_SCRIPT lib_LTLIBRARIES = libfstpdtscript.la libfstpdtscript_la_SOURCES = getters.cc pdtscript.cc -libfstpdtscript_la_LDFLAGS = -version-info 23:0:0 +libfstpdtscript_la_LDFLAGS = -version-info 24:0:0 libfstpdtscript_la_LIBADD = ../../script/libfstscript.la \ ../../lib/libfst.la -lm $(DL_LIBS) endif diff --git a/src/extensions/pdt/Makefile.in b/src/extensions/pdt/Makefile.in index 2542018..d8c10c9 100644 --- a/src/extensions/pdt/Makefile.in +++ b/src/extensions/pdt/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2020 Free Software Foundation, Inc. @@ -428,7 +428,7 @@ AM_CPPFLAGS = -I$(srcdir)/../../include $(ICU_CPPFLAGS) @HAVE_BIN_TRUE@pdtshortestpath_SOURCES = pdtshortestpath.cc pdtshortestpath-main.cc @HAVE_SCRIPT_TRUE@lib_LTLIBRARIES = libfstpdtscript.la @HAVE_SCRIPT_TRUE@libfstpdtscript_la_SOURCES = getters.cc pdtscript.cc -@HAVE_SCRIPT_TRUE@libfstpdtscript_la_LDFLAGS = -version-info 23:0:0 +@HAVE_SCRIPT_TRUE@libfstpdtscript_la_LDFLAGS = -version-info 24:0:0 @HAVE_SCRIPT_TRUE@libfstpdtscript_la_LIBADD = ../../script/libfstscript.la \ @HAVE_SCRIPT_TRUE@ ../../lib/libfst.la -lm $(DL_LIBS) diff --git a/src/extensions/pdt/pdtcompose-main.cc b/src/extensions/pdt/pdtcompose-main.cc index cc149c0..822f814 100644 --- a/src/extensions/pdt/pdtcompose-main.cc +++ b/src/extensions/pdt/pdtcompose-main.cc @@ -70,26 +70,29 @@ int pdtcompose_main(int argc, char **argv) { std::unique_ptr ifst2(FstClass::Read(in2_name)); if (!ifst2) return 1; - if (FLAGS_pdt_parentheses.empty()) { + if (FST_FLAGS_pdt_parentheses.empty()) { LOG(ERROR) << argv[0] << ": No PDT parenthesis label pairs provided"; return 1; } std::vector> parens; - if (!ReadLabelPairs(FLAGS_pdt_parentheses, &parens, false)) return 1; + if (!ReadLabelPairs(FST_FLAGS_pdt_parentheses, &parens, false)) + return 1; VectorFstClass ofst(ifst1->ArcType()); PdtComposeFilter compose_filter; - if (!s::GetPdtComposeFilter(FLAGS_compose_filter, &compose_filter)) { + if (!s::GetPdtComposeFilter(FST_FLAGS_compose_filter, + &compose_filter)) { LOG(ERROR) << argv[0] << ": Unknown or unsupported compose filter type: " - << FLAGS_compose_filter; + << FST_FLAGS_compose_filter; return 1; } - const PdtComposeOptions copts(FLAGS_connect, compose_filter); + const PdtComposeOptions copts(FST_FLAGS_connect, compose_filter); - s::PdtCompose(*ifst1, *ifst2, parens, &ofst, copts, FLAGS_left_pdt); + s::PdtCompose(*ifst1, *ifst2, parens, &ofst, copts, + FST_FLAGS_left_pdt); return !ofst.Write(out_name); } diff --git a/src/extensions/pdt/pdtexpand-main.cc b/src/extensions/pdt/pdtexpand-main.cc index 042b02d..3c1ce03 100644 --- a/src/extensions/pdt/pdtexpand-main.cc +++ b/src/extensions/pdt/pdtexpand-main.cc @@ -60,21 +60,24 @@ int pdtexpand_main(int argc, char **argv) { std::unique_ptr ifst(FstClass::Read(in_name)); if (!ifst) return 1; - if (FLAGS_pdt_parentheses.empty()) { + if (FST_FLAGS_pdt_parentheses.empty()) { LOG(ERROR) << argv[0] << ": No PDT parenthesis label pairs provided"; return 1; } std::vector> parens; - if (!ReadLabelPairs(FLAGS_pdt_parentheses, &parens, false)) return 1; + if (!ReadLabelPairs(FST_FLAGS_pdt_parentheses, &parens, false)) + return 1; const auto weight_threshold = - FLAGS_weight.empty() ? WeightClass::Zero(ifst->WeightType()) - : WeightClass(ifst->WeightType(), FLAGS_weight); + FST_FLAGS_weight.empty() + ? WeightClass::Zero(ifst->WeightType()) + : WeightClass(ifst->WeightType(), FST_FLAGS_weight); VectorFstClass ofst(ifst->ArcType()); s::PdtExpand(*ifst, parens, &ofst, - s::PdtExpandOptions(FLAGS_connect, FLAGS_keep_parentheses, + s::PdtExpandOptions(FST_FLAGS_connect, + FST_FLAGS_keep_parentheses, weight_threshold)); return !ofst.Write(out_name); diff --git a/src/extensions/pdt/pdtinfo-main.cc b/src/extensions/pdt/pdtinfo-main.cc index 366623e..13665b8 100644 --- a/src/extensions/pdt/pdtinfo-main.cc +++ b/src/extensions/pdt/pdtinfo-main.cc @@ -54,13 +54,14 @@ int pdtinfo_main(int argc, char **argv) { std::unique_ptr ifst(FstClass::Read(in_name)); if (!ifst) return 1; - if (FLAGS_pdt_parentheses.empty()) { + if (FST_FLAGS_pdt_parentheses.empty()) { LOG(ERROR) << argv[0] << ": No PDT parenthesis label pairs provided"; return 1; } std::vector> parens; - if (!ReadLabelPairs(FLAGS_pdt_parentheses, &parens, false)) return 1; + if (!ReadLabelPairs(FST_FLAGS_pdt_parentheses, &parens, false)) + return 1; s::PrintPdtInfo(*ifst, parens); diff --git a/src/extensions/pdt/pdtreplace-main.cc b/src/extensions/pdt/pdtreplace-main.cc index 412685b..656e50e 100644 --- a/src/extensions/pdt/pdtreplace-main.cc +++ b/src/extensions/pdt/pdtreplace-main.cc @@ -58,9 +58,10 @@ int pdtreplace_main(int argc, char **argv) { const std::string out_name = argc % 2 == 0 ? argv[argc - 1] : ""; PdtParserType parser_type; - if (!s::GetPdtParserType(FLAGS_pdt_parser_type, &parser_type)) { - LOG(ERROR) << argv[0] - << ": Unknown PDT parser type: " << FLAGS_pdt_parser_type; + if (!s::GetPdtParserType(FST_FLAGS_pdt_parser_type, + &parser_type)) { + LOG(ERROR) << argv[0] << ": Unknown PDT parser type: " + << FST_FLAGS_pdt_parser_type; return 1; } @@ -82,11 +83,13 @@ int pdtreplace_main(int argc, char **argv) { VectorFstClass ofst(pairs.back().second->ArcType()); std::vector> parens; s::PdtReplace(s::BorrowPairs(pairs), &ofst, &parens, root, parser_type, - FLAGS_start_paren_labels, FLAGS_left_paren_prefix, - FLAGS_right_paren_prefix); + FST_FLAGS_start_paren_labels, + FST_FLAGS_left_paren_prefix, + FST_FLAGS_right_paren_prefix); - if (!FLAGS_pdt_parentheses.empty()) { - if (!WriteLabelPairs(FLAGS_pdt_parentheses, parens)) return 1; + if (!FST_FLAGS_pdt_parentheses.empty()) { + if (!WriteLabelPairs(FST_FLAGS_pdt_parentheses, parens)) + return 1; } return !ofst.Write(out_name); diff --git a/src/extensions/pdt/pdtreverse-main.cc b/src/extensions/pdt/pdtreverse-main.cc index 6961477..66dfe84 100644 --- a/src/extensions/pdt/pdtreverse-main.cc +++ b/src/extensions/pdt/pdtreverse-main.cc @@ -56,13 +56,14 @@ int pdtreverse_main(int argc, char **argv) { std::unique_ptr ifst(FstClass::Read(in_name)); if (!ifst) return 1; - if (FLAGS_pdt_parentheses.empty()) { + if (FST_FLAGS_pdt_parentheses.empty()) { LOG(ERROR) << argv[0] << ": No PDT parenthesis label pairs provided"; return 1; } std::vector> parens; - if (!ReadLabelPairs(FLAGS_pdt_parentheses, &parens, false)) return 1; + if (!ReadLabelPairs(FST_FLAGS_pdt_parentheses, &parens, false)) + return 1; VectorFstClass ofst(ifst->ArcType()); diff --git a/src/extensions/pdt/pdtshortestpath-main.cc b/src/extensions/pdt/pdtshortestpath-main.cc index a43a46d..5c14c3e 100644 --- a/src/extensions/pdt/pdtshortestpath-main.cc +++ b/src/extensions/pdt/pdtshortestpath-main.cc @@ -60,30 +60,31 @@ int pdtshortestpath_main(int argc, char **argv) { std::unique_ptr ifst(FstClass::Read(in_name)); if (!ifst) return 1; - if (FLAGS_pdt_parentheses.empty()) { + if (FST_FLAGS_pdt_parentheses.empty()) { LOG(ERROR) << argv[0] << ": No PDT parenthesis label pairs provided"; return 1; } std::vector> parens; - if (!ReadLabelPairs(FLAGS_pdt_parentheses, &parens, false)) return 1; + if (!ReadLabelPairs(FST_FLAGS_pdt_parentheses, &parens, false)) + return 1; VectorFstClass ofst(ifst->ArcType()); QueueType qt; - if (FLAGS_queue_type == "fifo") { + if (FST_FLAGS_queue_type == "fifo") { qt = fst::FIFO_QUEUE; - } else if (FLAGS_queue_type == "lifo") { + } else if (FST_FLAGS_queue_type == "lifo") { qt = fst::LIFO_QUEUE; - } else if (FLAGS_queue_type == "state") { + } else if (FST_FLAGS_queue_type == "state") { qt = fst::STATE_ORDER_QUEUE; } else { - LOG(ERROR) << "Unknown queue type: " << FLAGS_queue_type; + LOG(ERROR) << "Unknown queue type: " << FST_FLAGS_queue_type; return 1; } - const s::PdtShortestPathOptions opts(qt, FLAGS_keep_parentheses, - FLAGS_path_gc); + const s::PdtShortestPathOptions opts( + qt, FST_FLAGS_keep_parentheses, FST_FLAGS_path_gc); s::PdtShortestPath(*ifst, parens, &ofst, opts); diff --git a/src/extensions/python/Makefile.in b/src/extensions/python/Makefile.in index 0eadba4..6a9c9c4 100644 --- a/src/extensions/python/Makefile.in +++ b/src/extensions/python/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2020 Free Software Foundation, Inc. diff --git a/src/extensions/python/cpywrapfst.pxd b/src/extensions/python/cpywrapfst.pxd index 231cff7..3fa870b 100644 --- a/src/extensions/python/cpywrapfst.pxd +++ b/src/extensions/python/cpywrapfst.pxd @@ -29,7 +29,7 @@ from cintegral_types cimport * cdef extern from "" nogil: - bool FLAGS_fst_error_fatal + bool FST_FLAGS_fst_error_fatal cdef extern from "" namespace "fst" nogil: diff --git a/src/extensions/python/pywrapfst.cpp b/src/extensions/python/pywrapfst.cpp index 219dbff..488d4b2 100644 --- a/src/extensions/python/pywrapfst.cpp +++ b/src/extensions/python/pywrapfst.cpp @@ -54578,10 +54578,10 @@ if (!__Pyx_RefNanny) { /* "pywrapfst.pyx":4704 * * # Masks fst_error_fatal in-module. - * fst.FLAGS_fst_error_fatal = False # <<<<<<<<<<<<<< + * fst.FST_FLAGS_fst_error_fatal = False # <<<<<<<<<<<<<< * */ - FLAGS_fst_error_fatal = 0; + FST_FLAGS_fst_error_fatal = 0; /* "pywrapfst.pyx":1 * #cython: c_string_encoding=utf8, c_string_type=unicode, language_level=3, nonecheck=True # <<<<<<<<<<<<<< diff --git a/src/extensions/python/pywrapfst.pyx b/src/extensions/python/pywrapfst.pyx index 8f7d298..c5944e0 100644 --- a/src/extensions/python/pywrapfst.pyx +++ b/src/extensions/python/pywrapfst.pyx @@ -4700,4 +4700,4 @@ cdef class FarWriter: # Masks fst_error_fatal in-module. -fst.FLAGS_fst_error_fatal = False +fst.FST_FLAGS_fst_error_fatal = False diff --git a/src/extensions/special/Makefile.am b/src/extensions/special/Makefile.am index 8d2479f..d65ad64 100644 --- a/src/extensions/special/Makefile.am +++ b/src/extensions/special/Makefile.am @@ -15,7 +15,7 @@ libfst_LTLIBRARIES = phi-fst.la rho-fst.la sigma-fst.la lib_LTLIBRARIES = libfstspecial.la libfstspecial_la_SOURCES = phi-fst.cc rho-fst.cc sigma-fst.cc -libfstspecial_la_LDFLAGS = -version-info 23:0:0 +libfstspecial_la_LDFLAGS = -version-info 24:0:0 phi_fst_la_SOURCES = phi-fst.cc phi_fst_la_LDFLAGS = -avoid-version -module diff --git a/src/extensions/special/Makefile.in b/src/extensions/special/Makefile.in index d94ef9c..0f48e74 100644 --- a/src/extensions/special/Makefile.in +++ b/src/extensions/special/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2020 Free Software Foundation, Inc. @@ -388,7 +388,7 @@ AM_CPPFLAGS = -I$(srcdir)/../../include -I$(srcdir)/../../bin $(ICU_CPPFLAGS) libfst_LTLIBRARIES = phi-fst.la rho-fst.la sigma-fst.la lib_LTLIBRARIES = libfstspecial.la libfstspecial_la_SOURCES = phi-fst.cc rho-fst.cc sigma-fst.cc -libfstspecial_la_LDFLAGS = -version-info 23:0:0 +libfstspecial_la_LDFLAGS = -version-info 24:0:0 phi_fst_la_SOURCES = phi-fst.cc phi_fst_la_LDFLAGS = -avoid-version -module rho_fst_la_SOURCES = rho-fst.cc diff --git a/src/include/Makefile.in b/src/include/Makefile.in index ce21052..53d0e1c 100644 --- a/src/include/Makefile.in +++ b/src/include/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2020 Free Software Foundation, Inc. diff --git a/src/include/fst/accumulator.h b/src/include/fst/accumulator.h index 2091bc8..9ac08ec 100644 --- a/src/include/fst/accumulator.h +++ b/src/include/fst/accumulator.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include @@ -33,6 +33,8 @@ #include #include +#include + namespace fst { // This class accumulates arc weights using the semiring Plus(). @@ -666,13 +668,8 @@ class ReplaceAccumulatorData { ReplaceAccumulatorData() : state_table_(nullptr) {} explicit ReplaceAccumulatorData( - const std::vector &accumulators) - : state_table_(nullptr) { - accumulators_.reserve(accumulators.size()); - for (const auto accumulator : accumulators) { - accumulators_.emplace_back(accumulator); - } - } + std::vector> &&accumulators) + : state_table_(nullptr), accumulators_(std::move(accumulators)) {} void Init(const std::vector *>> &fst_tuples, const StateTable *state_table) { @@ -680,7 +677,7 @@ class ReplaceAccumulatorData { accumulators_.resize(fst_tuples.size()); for (Label i = 0; i < accumulators_.size(); ++i) { if (!accumulators_[i]) { - accumulators_[i] = fst::make_unique(); + accumulators_[i] = std::make_unique(); accumulators_[i]->Init(*(fst_tuples[i].second)); } fst_array_.emplace_back(fst_tuples[i].second->Copy()); @@ -719,10 +716,11 @@ class ReplaceAccumulator { ReplaceAccumulatorData>()), error_(false) {} - explicit ReplaceAccumulator(const std::vector &accumulators) + explicit ReplaceAccumulator( + std::vector> &&accumulators) : init_(false), data_(std::make_shared>( - accumulators)), + std::move(accumulators))), error_(false) {} ReplaceAccumulator(const ReplaceAccumulator &acc, @@ -892,7 +890,7 @@ class SafeReplaceAccumulator { ArcIteratorPtr(const ArcIteratorPtr ©) {} void Set(const Fst &fst, StateId state_id) { - ptr_ = fst::make_unique>>(fst, state_id); + ptr_ = std::make_unique>>(fst, state_id); } ArcIterator> *get() { return ptr_.get(); } diff --git a/src/include/fst/arc-map.h b/src/include/fst/arc-map.h index a9a150a..48de960 100644 --- a/src/include/fst/arc-map.h +++ b/src/include/fst/arc-map.h @@ -23,7 +23,6 @@ #define FST_ARC_MAP_H_ #include -#include #include #include @@ -641,7 +640,7 @@ class ArcIterator> template inline void ArcMapFst::InitStateIterator( StateIteratorData *data) const { - data->base = fst::make_unique>>(*this); + data->base = std::make_unique>>(*this); } // Constructs and returns an ArcMapFst. This allows constructing ArcMapFsts diff --git a/src/include/fst/bi-table.h b/src/include/fst/bi-table.h index 7c5be23..3045f0c 100644 --- a/src/include/fst/bi-table.h +++ b/src/include/fst/bi-table.h @@ -111,7 +111,7 @@ class HashBiTable { }; // Enables alternative hash set representations below. -enum HSType { HS_STL = 0, HS_DENSE = 1, HS_SPARSE = 2, HS_FLAT = 3 }; +enum HSType { HS_STL, HS_FLAT }; // Default hash set is STL hash_set. template @@ -307,7 +307,7 @@ class VectorBiTable { // fingerprinting functor FP returns a unique fingerprint for each entry to be // hashed in the vector (these need to be suitable for indexing in a vector). // The hash functor H is used when hashing entry into the compact hash table. -template +template class VectorHashBiTable { public: friend class HashFunc; @@ -381,7 +381,6 @@ class VectorHashBiTable { private: static constexpr I kCurrentKey = -1; - static constexpr I kEmptyKey = -2; class HashFunc { public: @@ -443,9 +442,6 @@ class VectorHashBiTable { template constexpr I VectorHashBiTable::kCurrentKey; -template -constexpr I VectorHashBiTable::kEmptyKey; - // An implementation using a hash map for the entry to ID mapping. This version // permits erasing of arbitrary states. The entry T must have == defined and // its default constructor must produce a entry that will never be seen. F is diff --git a/src/include/fst/cache.h b/src/include/fst/cache.h index 800cd52..b8b7465 100644 --- a/src/include/fst/cache.h +++ b/src/include/fst/cache.h @@ -43,8 +43,9 @@ struct CacheOptions { bool gc; // Enables GC. size_t gc_limit; // Number of bytes allowed before GC. - explicit CacheOptions(bool gc = FLAGS_fst_default_cache_gc, - size_t gc_limit = FLAGS_fst_default_cache_gc_limit) + explicit CacheOptions( + bool gc = FST_FLAGS_fst_default_cache_gc, + size_t gc_limit = FST_FLAGS_fst_default_cache_gc_limit) : gc(gc), gc_limit(gc_limit) {} }; @@ -57,9 +58,10 @@ struct CacheImplOptions { CacheStore *store; // Cache store. bool own_store; // Should CacheImpl takes ownership of the store? - explicit CacheImplOptions(bool gc = FLAGS_fst_default_cache_gc, - size_t gc_limit = FLAGS_fst_default_cache_gc_limit, - CacheStore *store = nullptr) + explicit CacheImplOptions( + bool gc = FST_FLAGS_fst_default_cache_gc, + size_t gc_limit = FST_FLAGS_fst_default_cache_gc_limit, + CacheStore *store = nullptr) : gc(gc), gc_limit(gc_limit), store(store), own_store(true) {} explicit CacheImplOptions(const CacheOptions &opts) diff --git a/src/include/fst/compact-fst.h b/src/include/fst/compact-fst.h index 53a4a43..d55fa0a 100644 --- a/src/include/fst/compact-fst.h +++ b/src/include/fst/compact-fst.h @@ -436,7 +436,7 @@ template CompactArcStore *CompactArcStore::Read( std::istream &strm, const FstReadOptions &opts, const FstHeader &hdr, const ArcCompactor &arc_compactor) { - auto data = fst::make_unique(); + auto data = std::make_unique(); data->start_ = hdr.Start(); data->nstates_ = hdr.NumStates(); data->narcs_ = hdr.NumArcs(); @@ -447,7 +447,7 @@ CompactArcStore *CompactArcStore::Read( } auto b = (data->nstates_ + 1) * sizeof(Unsigned); data->states_region_.reset(MappedFile::Map( - &strm, opts.mode == FstReadOptions::MAP, opts.source, b)); + strm, opts.mode == FstReadOptions::MAP, opts.source, b)); if (!strm || !data->states_region_) { LOG(ERROR) << "CompactArcStore::Read: Read failed: " << opts.source; return nullptr; @@ -466,7 +466,7 @@ CompactArcStore *CompactArcStore::Read( } size_t b = data->ncompacts_ * sizeof(Element); data->compacts_region_.reset( - MappedFile::Map(&strm, opts.mode == FstReadOptions::MAP, opts.source, b)); + MappedFile::Map(strm, opts.mode == FstReadOptions::MAP, opts.source, b)); if (!strm || !data->compacts_region_) { LOG(ERROR) << "CompactArcStore::Read: Read failed: " << opts.source; return nullptr; @@ -982,7 +982,7 @@ class CompactFstImpl } static CompactFstImpl *Read(std::istream &strm, const FstReadOptions &opts) { - auto impl = fst::make_unique(); + auto impl = std::make_unique(); FstHeader hdr; if (!impl->ReadHeader(strm, opts, kMinFileVersion, &hdr)) { return nullptr; diff --git a/src/include/fst/compat.h b/src/include/fst/compat.h index 9c18750..e15aeeb 100644 --- a/src/include/fst/compat.h +++ b/src/include/fst/compat.h @@ -106,28 +106,17 @@ class CheckSummer { CheckSummer &operator=(const CheckSummer &) = delete; }; -// Defines make_unique and make_unique_default_init using a standard definition -// that should be compatible with the C++14 and C++20 (respectively) -// definitions. -// TODO(kbg): Remove these once we migrate to C++14 and C++20. - -template -std::unique_ptr make_unique(Args &&... args) { - return std::unique_ptr(new T(std::forward(args)...)); -} - -template -std::unique_ptr make_unique(size_t n) { - return std::unique_ptr(new typename std::remove_extent::type[n]()); -} +// Defines make_unique_for_overwrite using a standard definition that should be +// compatible with the C++20 definition. +// TODO(kbg): Remove these once we migrate to C++20. template -std::unique_ptr make_unique_default_init() { +std::unique_ptr make_unique_for_overwrite() { return std::unique_ptr(new T); } template -std::unique_ptr make_unique_default_init(size_t n) { +std::unique_ptr make_unique_for_overwrite(size_t n) { return std::unique_ptr(new typename std::remove_extent::type[n]); } @@ -192,6 +181,46 @@ void StripTrailingAsciiWhitespace(std::string *full); std::string StripTrailingAsciiWhitespace(const std::string &full); +class StringOrInt { + public: + StringOrInt(const std::string &s) : str_(s) {} // NOLINT + + StringOrInt(const char *s) : str_(std::string(s)) {} // NOLINT + + StringOrInt(int i) { // NOLINT + char buf[1024]; + sprintf(buf, "%d", i); + str_ = std::string(buf); + } + + const std::string &Get() const { return str_; } + + private: + std::string str_; +}; + +// TODO(kbg): Make this work with variadic template, maybe. + +inline std::string StrCat(const StringOrInt &s1, const StringOrInt &s2) { + return s1.Get() + s2.Get(); +} + +inline std::string StrCat(const StringOrInt &s1, const StringOrInt &s2, + const StringOrInt &s3) { + return s1.Get() + StrCat(s2, s3); +} + +inline std::string StrCat(const StringOrInt &s1, const StringOrInt &s2, + const StringOrInt &s3, const StringOrInt &s4) { + return s1.Get() + StrCat(s2, s3, s4); +} + +inline std::string StrCat(const StringOrInt &s1, const StringOrInt &s2, + const StringOrInt &s3, const StringOrInt &s4, + const StringOrInt &s5) { + return s1.Get() + StrCat(s2, s3, s4, s5); +} + } // namespace fst #endif // FST_LIB_COMPAT_H_ diff --git a/src/include/fst/complement.h b/src/include/fst/complement.h index cbb375e..613d1ac 100644 --- a/src/include/fst/complement.h +++ b/src/include/fst/complement.h @@ -214,7 +214,7 @@ class ArcIterator> : public ArcIteratorBase { ArcIterator(const ComplementFst &fst, StateId s) : s_(s), pos_(0) { if (s_ != 0) { aiter_ = - fst::make_unique>>(*fst.GetImpl()->fst_, s - 1); + std::make_unique>>(*fst.GetImpl()->fst_, s - 1); } } @@ -276,13 +276,13 @@ class ArcIterator> : public ArcIteratorBase { template inline void ComplementFst::InitStateIterator( StateIteratorData *data) const { - data->base = fst::make_unique>>(*this); + data->base = std::make_unique>>(*this); } template inline void ComplementFst::InitArcIterator( StateId s, ArcIteratorData *data) const { - data->base = fst::make_unique>>(*this, s); + data->base = std::make_unique>>(*this, s); } // Useful alias when using StdArc. diff --git a/src/include/fst/compose.h b/src/include/fst/compose.h index 56cc061..eafee10 100644 --- a/src/include/fst/compose.h +++ b/src/include/fst/compose.h @@ -719,7 +719,7 @@ template inline void ComposeFst::InitStateIterator( StateIteratorData *data) const { data->base = - fst::make_unique>>(*this); + std::make_unique>>(*this); } // Specialized matcher for ComposeFst. Supports MATCH_INPUT or MATCH_OUTPUT, @@ -963,7 +963,7 @@ struct ComposeOptions { // the composed FST into a MutableFst. If FST1 transduces string x to // y with weight a and FST2 transduces y to z with weight b, then // their composition transduces string x to z with weight -// Times(x, z). +// Times(a, b). // // The output labels of the first transducer or the input labels of // the second transducer must be sorted. The weights need to form a diff --git a/src/include/fst/connect.h b/src/include/fst/connect.h index bc208d1..ae4f1fb 100644 --- a/src/include/fst/connect.h +++ b/src/include/fst/connect.h @@ -21,7 +21,6 @@ #define FST_CONNECT_H_ #include -#include #include #include @@ -30,6 +29,7 @@ #include #include + namespace fst { // Finds and returns connected components. Use with Visit(). @@ -136,7 +136,7 @@ class SccVisitor { bool BackArc(StateId s, const Arc &arc) { const auto t = arc.nextstate; - if ((*dfnumber_)[t] < (*lowlink_)[s]) (*lowlink_)[s] = (*dfnumber_)[t]; + if (dfnumber_[t] < lowlink_[s]) lowlink_[s] = dfnumber_[t]; if ((*coaccess_)[t]) (*coaccess_)[s] = true; *props_ |= kCyclic; *props_ &= ~kAcyclic; @@ -149,9 +149,9 @@ class SccVisitor { bool ForwardOrCrossArc(StateId s, const Arc &arc) { const auto t = arc.nextstate; - if ((*dfnumber_)[t] < (*dfnumber_)[s] /* cross edge */ && (*onstack_)[t] && - (*dfnumber_)[t] < (*lowlink_)[s]) { - (*lowlink_)[s] = (*dfnumber_)[t]; + if (dfnumber_[t] < dfnumber_[s] /* cross edge */ && onstack_[t] && + dfnumber_[t] < lowlink_[s]) { + lowlink_[s] = dfnumber_[t]; } if ((*coaccess_)[t]) (*coaccess_)[s] = true; return true; @@ -168,10 +168,6 @@ class SccVisitor { } } if (coaccess_internal_) delete coaccess_; - dfnumber_.reset(); - lowlink_.reset(); - onstack_.reset(); - scc_stack_.reset(); } private: @@ -184,12 +180,11 @@ class SccVisitor { StateId nstates_; // State count. StateId nscc_; // SCC count. bool coaccess_internal_; - std::unique_ptr> dfnumber_; // State discovery times. - std::unique_ptr> - lowlink_; // lowlink[state] == dfnumber[state] => SCC root - std::unique_ptr> onstack_; // Is a state on the SCC stack? - std::unique_ptr> - scc_stack_; // SCC stack, with random access. + std::vector dfnumber_; // State discovery times. + std::vector + lowlink_; // lowlink[state] == dfnumber[state] => SCC root + std::vector onstack_; // Is a state on the SCC stack? + std::vector scc_stack_; // SCC stack, with random access. }; template @@ -209,26 +204,26 @@ inline void SccVisitor::InitVisit(const Fst &fst) { start_ = fst.Start(); nstates_ = 0; nscc_ = 0; - dfnumber_ = fst::make_unique>(); - lowlink_ = fst::make_unique>(); - onstack_ = fst::make_unique>(); - scc_stack_ = fst::make_unique>(); + dfnumber_.clear(); + lowlink_.clear(); + onstack_.clear(); + scc_stack_.clear(); } template inline bool SccVisitor::InitState(StateId s, StateId root) { - scc_stack_->push_back(s); - if (static_cast(dfnumber_->size()) <= s) { + scc_stack_.push_back(s); + if (static_cast(dfnumber_.size()) <= s) { if (scc_) scc_->resize(s + 1, -1); if (access_) access_->resize(s + 1, false); coaccess_->resize(s + 1, false); - dfnumber_->resize(s + 1, -1); - lowlink_->resize(s + 1, -1); - onstack_->resize(s + 1, false); + dfnumber_.resize(s + 1, -1); + lowlink_.resize(s + 1, -1); + onstack_.resize(s + 1, false); } - (*dfnumber_)[s] = nstates_; - (*lowlink_)[s] = nstates_; - (*onstack_)[s] = true; + dfnumber_[s] = nstates_; + lowlink_[s] = nstates_; + onstack_[s] = true; if (root == start_) { if (access_) (*access_)[s] = true; } else { @@ -243,20 +238,20 @@ inline bool SccVisitor::InitState(StateId s, StateId root) { template inline void SccVisitor::FinishState(StateId s, StateId p, const Arc *) { if (fst_->Final(s) != Weight::Zero()) (*coaccess_)[s] = true; - if ((*dfnumber_)[s] == (*lowlink_)[s]) { // Root of new SCC. + if (dfnumber_[s] == lowlink_[s]) { // Root of new SCC. bool scc_coaccess = false; - auto i = scc_stack_->size(); + auto i = scc_stack_.size(); StateId t; do { - t = (*scc_stack_)[--i]; + t = scc_stack_[--i]; if ((*coaccess_)[t]) scc_coaccess = true; } while (s != t); do { - t = scc_stack_->back(); + t = scc_stack_.back(); if (scc_) (*scc_)[t] = nscc_; if (scc_coaccess) (*coaccess_)[t] = true; - (*onstack_)[t] = false; - scc_stack_->pop_back(); + onstack_[t] = false; + scc_stack_.pop_back(); } while (s != t); if (!scc_coaccess) { *props_ |= kNotCoAccessible; @@ -266,7 +261,7 @@ inline void SccVisitor::FinishState(StateId s, StateId p, const Arc *) { } if (p != kNoStateId) { if ((*coaccess_)[s]) (*coaccess_)[p] = true; - if ((*lowlink_)[s] < (*lowlink_)[p]) (*lowlink_)[p] = (*lowlink_)[s]; + if (lowlink_[s] < lowlink_[p]) lowlink_[p] = lowlink_[s]; } } diff --git a/src/include/fst/const-fst.h b/src/include/fst/const-fst.h index 5970ecf..44fef12 100644 --- a/src/include/fst/const-fst.h +++ b/src/include/fst/const-fst.h @@ -196,7 +196,7 @@ ConstFstImpl::ConstFstImpl(const Fst &fst) { template ConstFstImpl *ConstFstImpl::Read( std::istream &strm, const FstReadOptions &opts) { - auto impl = fst::make_unique(); + auto impl = std::make_unique(); FstHeader hdr; if (!impl->ReadHeader(strm, opts, kMinFileVersion, &hdr)) return nullptr; impl->start_ = hdr.Start(); @@ -212,7 +212,7 @@ ConstFstImpl *ConstFstImpl::Read( } size_t b = impl->nstates_ * sizeof(ConstState); impl->states_region_.reset( - MappedFile::Map(&strm, opts.mode == FstReadOptions::MAP, opts.source, b)); + MappedFile::Map(strm, opts.mode == FstReadOptions::MAP, opts.source, b)); if (!strm || !impl->states_region_) { LOG(ERROR) << "ConstFst::Read: Read failed: " << opts.source; return nullptr; @@ -225,7 +225,7 @@ ConstFstImpl *ConstFstImpl::Read( } b = impl->narcs_ * sizeof(Arc); impl->arcs_region_.reset( - MappedFile::Map(&strm, opts.mode == FstReadOptions::MAP, opts.source, b)); + MappedFile::Map(strm, opts.mode == FstReadOptions::MAP, opts.source, b)); if (!strm || !impl->arcs_region_) { LOG(ERROR) << "ConstFst::Read: Read failed: " << opts.source; return nullptr; diff --git a/src/include/fst/determinize.h b/src/include/fst/determinize.h index b8f30ee..f3e330e 100644 --- a/src/include/fst/determinize.h +++ b/src/include/fst/determinize.h @@ -993,7 +993,7 @@ void DeterminizeFstImpl::Init(const Fst &fst, F *filter) { subsequential_label_, increment_subsequential_label_, increment_subsequential_label_); const FactorWeightFst factored_fst(det_fsa, fopts); - from_fst_ = fst::make_unique(factored_fst, + from_fst_ = std::make_unique(factored_fst, FromMapper(subsequential_label_)); } @@ -1024,7 +1024,7 @@ class ArcIterator> template inline void DeterminizeFst::InitStateIterator( StateIteratorData *data) const { - data->base = fst::make_unique>>(*this); + data->base = std::make_unique>>(*this); } // Useful aliases when using StdArc. @@ -1087,18 +1087,24 @@ void Determinize( nopts.gc_limit = 0; // Caches only the last state for fastest copy. if (opts.weight_threshold != Weight::Zero() || opts.state_threshold != kNoStateId) { - if (ifst.Properties(kAcceptor, false)) { - std::vector idistance; - std::vector odistance; - ShortestDistance(ifst, &idistance, true); - DeterminizeFst dfst(ifst, &idistance, &odistance, nopts); - PruneOptions> popts( - opts.weight_threshold, opts.state_threshold, AnyArcFilter(), - &odistance); - Prune(dfst, ofst, popts); + if constexpr (IsPath::value) { + if (ifst.Properties(kAcceptor, false)) { + std::vector idistance; + std::vector odistance; + ShortestDistance(ifst, &idistance, true); + DeterminizeFst dfst(ifst, &idistance, &odistance, nopts); + PruneOptions> popts( + opts.weight_threshold, opts.state_threshold, AnyArcFilter(), + &odistance); + Prune(dfst, ofst, popts); + } else { + *ofst = DeterminizeFst(ifst, nopts); + Prune(ofst, opts.weight_threshold, opts.state_threshold); + } } else { - *ofst = DeterminizeFst(ifst, nopts); - Prune(ofst, opts.weight_threshold, opts.state_threshold); + FSTERROR() << "Determinize: Weight needs to have the path " + << "property to use pruning options: " << Weight::Type(); + ofst->SetProperties(kError, kError); } } else { *ofst = DeterminizeFst(ifst, nopts); diff --git a/src/include/fst/dfs-visit.h b/src/include/fst/dfs-visit.h index 2d2839c..16c5db7 100644 --- a/src/include/fst/dfs-visit.h +++ b/src/include/fst/dfs-visit.h @@ -114,10 +114,12 @@ void DfsVisit(const FST &fst, Visitor *visitor, ArcFilter filter, return; } // An FST state's DFS status - static constexpr uint8 kDfsWhite = 0; // Undiscovered. - static constexpr uint8 kDfsGrey = 1; // Discovered but unfinished. - static constexpr uint8 kDfsBlack = 2; // Finished. - std::vector state_color; + enum class StateColor : uint8 { + kWhite = 0, // Undiscovered. + kGrey = 1, // Discovered but unfinished. + kBlack = 2, // Finished. + }; + std::vector state_color; std::stack *> state_stack; // DFS execution stack. MemoryPool> state_pool; // Pool for DFSStates. auto nstates = start + 1; // Number of known states in general case. @@ -126,13 +128,13 @@ void DfsVisit(const FST &fst, Visitor *visitor, ArcFilter filter, nstates = CountStates(fst); // uses ExpandedFst::NumStates(). expanded = true; } - state_color.resize(nstates, kDfsWhite); + state_color.resize(nstates, StateColor::kWhite); StateIterator siter(fst); // Continue DFS while true. bool dfs = true; // Iterate over trees in DFS forest. for (auto root = start; dfs && root < nstates;) { - state_color[root] = kDfsGrey; + state_color[root] = StateColor::kGrey; state_stack.push(new (&state_pool) internal::DfsState(fst, root)); dfs = visitor->InitState(root, root); while (!state_stack.empty()) { @@ -140,11 +142,11 @@ void DfsVisit(const FST &fst, Visitor *visitor, ArcFilter filter, const auto s = dfs_state->state_id; if (s >= static_cast(state_color.size())) { nstates = s + 1; - state_color.resize(nstates, kDfsWhite); + state_color.resize(nstates, StateColor::kWhite); } ArcIterator &aiter = dfs_state->arc_iter; if (!dfs || aiter.Done()) { - state_color[s] = kDfsBlack; + state_color[s] = StateColor::kBlack; internal::DfsState::Destroy(dfs_state, &state_pool); state_stack.pop(); if (!state_stack.empty()) { @@ -161,7 +163,7 @@ void DfsVisit(const FST &fst, Visitor *visitor, ArcFilter filter, if (arc.nextstate >= static_cast(state_color.size())) { nstates = arc.nextstate + 1; - state_color.resize(nstates, kDfsWhite); + state_color.resize(nstates, StateColor::kWhite); } if (!filter(arc)) { aiter.Next(); @@ -169,20 +171,19 @@ void DfsVisit(const FST &fst, Visitor *visitor, ArcFilter filter, } const auto next_color = state_color[arc.nextstate]; switch (next_color) { - default: - case kDfsWhite: + case StateColor::kWhite: dfs = visitor->TreeArc(s, arc); if (!dfs) break; - state_color[arc.nextstate] = kDfsGrey; + state_color[arc.nextstate] = StateColor::kGrey; state_stack.push(new (&state_pool) internal::DfsState(fst, arc.nextstate)); dfs = visitor->InitState(arc.nextstate, root); break; - case kDfsGrey: + case StateColor::kGrey: dfs = visitor->BackArc(s, arc); aiter.Next(); break; - case kDfsBlack: + case StateColor::kBlack: dfs = visitor->ForwardOrCrossArc(s, arc); aiter.Next(); break; @@ -191,14 +192,14 @@ void DfsVisit(const FST &fst, Visitor *visitor, ArcFilter filter, if (access_only) break; // Finds next tree root. for (root = root == start ? 0 : root + 1; - root < nstates && state_color[root] != kDfsWhite; ++root) { + root < nstates && state_color[root] != StateColor::kWhite; ++root) { } // Checks for a state beyond the largest known state. if (!expanded && root == nstates) { for (; !siter.Done(); siter.Next()) { if (siter.Value() == nstates) { ++nstates; - state_color.push_back(kDfsWhite); + state_color.push_back(StateColor::kWhite); break; } } diff --git a/src/include/fst/disambiguate.h b/src/include/fst/disambiguate.h index 11395d8..9301298 100644 --- a/src/include/fst/disambiguate.h +++ b/src/include/fst/disambiguate.h @@ -398,20 +398,26 @@ void Disambiguator::PreDisambiguate(const ExpandedFst &ifst, nopts.gc_limit = 0; // Cache only the last state for fastest copy. if (opts.weight_threshold != Weight::Zero() || opts.state_threshold != kNoStateId) { - /* TODO(riley): fails regression test; understand why - if (ifst.Properties(kAcceptor, true)) { - std::vector idistance, odistance; - ShortestDistance(ifst, &idistance, true); - DeterminizeFst dfst(ifst, &idistance, &odistance, nopts); - PruneOptions< Arc, AnyArcFilter> popts(opts.weight_threshold, - opts.state_threshold, - AnyArcFilter(), - &odistance); - Prune(dfst, ofst, popts); - } else */ - { - *ofst = DeterminizeFst(ifst, nopts); - Prune(ofst, opts.weight_threshold, opts.state_threshold); + if constexpr (IsPath::value) { + /* TODO(riley): fails regression test; understand why + if (ifst.Properties(kAcceptor, true)) { + std::vector idistance, odistance; + ShortestDistance(ifst, &idistance, true); + DeterminizeFst dfst(ifst, &idistance, &odistance, nopts); + PruneOptions< Arc, AnyArcFilter> popts(opts.weight_threshold, + opts.state_threshold, + AnyArcFilter(), + &odistance); + Prune(dfst, ofst, popts); + } else */ + { + *ofst = DeterminizeFst(ifst, nopts); + Prune(ofst, opts.weight_threshold, opts.state_threshold); + } + } else { + FSTERROR() << "Disambiguate: Weight must have path property to use " + << "pruning options: " << Weight::Type(); + error_ = true; } } else { *ofst = DeterminizeFst(ifst, nopts); @@ -422,7 +428,7 @@ void Disambiguator::PreDisambiguate(const ExpandedFst &ifst, template void Disambiguator::FindAmbiguities(const ExpandedFst &fst) { if (fst.Start() == kNoStateId) return; - candidates_ = fst::make_unique(ArcIdCompare(head_)); + candidates_ = std::make_unique(ArcIdCompare(head_)); const auto start_pr = std::make_pair(fst.Start(), fst.Start()); coreachable_.insert(start_pr); queue_.push_back(start_pr); @@ -463,7 +469,7 @@ void Disambiguator::FindAmbiguousPairs(const ExpandedFst &fst, if (spr.first != spr.second && head_[spr.first] == head_[spr.second]) { if (!merge_) { - merge_ = fst::make_unique>(fst.NumStates(), + merge_ = std::make_unique>(fst.NumStates(), kNoStateId); merge_->MakeAllSet(fst.NumStates()); } diff --git a/src/include/fst/edit-fst.h b/src/include/fst/edit-fst.h index 607e156..6805351 100644 --- a/src/include/fst/edit-fst.h +++ b/src/include/fst/edit-fst.h @@ -20,7 +20,7 @@ // // The EditFst class enables non-destructive edit operations on a wrapped // ExpandedFst. The implementation uses copy-on-write semantics at the node -// level: if a user has an underlying FST on which he or she wants to perform a +// level: if a user has an underlying FST on which they want to perform a // relatively small number of edits (read: mutations), then this implementation // will copy the edited node to an internal MutableFst and perform any edits in // situ on that copied node. This class supports all the methods of MutableFst @@ -40,7 +40,6 @@ #define FST_EDIT_FST_H_ #include -#include #include #include @@ -48,6 +47,8 @@ #include +#include + namespace fst { namespace internal { @@ -224,7 +225,7 @@ class EditFstData { // Provides information for the generic mutable arc iterator. void InitMutableArcIterator(StateId s, MutableArcIteratorData *data, const WrappedFstT *wrapped) { - data->base = fst::make_unique>( + data->base = std::make_unique>( &edits_, GetEditableInternalId(s, wrapped)); } @@ -246,8 +247,8 @@ class EditFstData { return external_to_internal_ids_.find(s); } - typename std::unordered_map::const_iterator NotInEditedMap() - const { + typename std::unordered_map::const_iterator + NotInEditedMap() const { return external_to_internal_ids_.end(); } @@ -341,7 +342,7 @@ EditFstData::Read(std::istream &strm, // This class enables non-destructive edit operations on a wrapped ExpandedFst. // The implementation uses copy-on-write semantics at the node level: if a user -// has an underlying FST on which he or she wants to perform a relatively small +// has an underlying FST on which they want to perform a relatively small // number of edits (read: mutations), then this implementation will copy the // edited node to an internal MutableFst and perform any edits in situ on that // copied node. This class supports all the methods of MutableFst except for @@ -601,7 +602,7 @@ inline void EditFstImpl::DeleteStates() { data_->DeleteStates(); // we are deleting all states, so just forget about pointer to wrapped_ // and do what default constructor does: set wrapped_ to a new VectorFst - wrapped_ = fst::make_unique(); + wrapped_ = std::make_unique(); const auto new_props = DeleteAllStatesProperties(FstImpl::Properties(), kStaticProperties); FstImpl::SetProperties(new_props); diff --git a/src/include/fst/encode.h b/src/include/fst/encode.h index e8873ce..901342f 100644 --- a/src/include/fst/encode.h +++ b/src/include/fst/encode.h @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -116,7 +115,7 @@ class EncodeTable { weight(flags & kEncodeWeights ? arc.weight : Weight::One()) {} static std::unique_ptr Read(std::istream &strm) { - auto triple = fst::make_unique(); + auto triple = std::make_unique(); ReadType(strm, &triple->ilabel); ReadType(strm, &triple->olabel); ReadType(strm, &triple->weight); @@ -170,9 +169,9 @@ class EncodeTable { // a clash with a true epsilon arc; to avoid this we hallucinate kNoLabel // labels instead. if (arc.nextstate == kNoStateId && (flags_ & kEncodeWeights)) { - return Encode(fst::make_unique(kNoLabel, kNoLabel, arc.weight)); + return Encode(std::make_unique(kNoLabel, kNoLabel, arc.weight)); } else { - return Encode(fst::make_unique(arc, flags_)); + return Encode(std::make_unique(arc, flags_)); } } @@ -245,7 +244,7 @@ EncodeTable *EncodeTable::Read(std::istream &strm, if (!hdr.Read(strm, source)) return nullptr; const auto flags = hdr.Flags(); const auto size = hdr.Size(); - auto table = fst::make_unique(flags); + auto table = std::make_unique(flags); for (int64 i = 0; i < size; ++i) { table->triples_.emplace_back(std::move(Triple::Read(strm))); table->triple2label_[table->triples_.back().get()] = table->triples_.size(); diff --git a/src/include/fst/equivalent.h b/src/include/fst/equivalent.h index 9903021..5dc4c9e 100644 --- a/src/include/fst/equivalent.h +++ b/src/include/fst/equivalent.h @@ -21,8 +21,7 @@ #define FST_EQUIVALENT_H_ #include -#include -#include +#include #include #include @@ -116,7 +115,7 @@ constexpr // of both acceptors. A disjoint tree forest (the union-find algorithm) is used // to represent the sets of states. The algorithm returns false if one of the // constructed sets contains both final and non-final states. Returns an -// optional error value (useful when FLAGS_error_fatal = false). +// optional error value (useful when FST_FLAGS_error_fatal = false). // // Complexity: // @@ -183,14 +182,14 @@ bool Equivalent(const Fst &fst1, const Fst &fst2, std::unordered_map>; Label2StatePairMap arc_pairs; // Pairs of MappedId's to be processed, organized in a queue. - std::deque> q; + std::queue> q; bool ret = true; // Returns early if the start states differ w.r.t. finality. if (Util::IsFinal(fst1, s1) != Util::IsFinal(fst2, s2)) ret = false; // Main loop: explores the two acceptors in a breadth-first manner, updating // the equivalence relation on the statesets. Loop invariant: each block of // the states contains either final states only or non-final states only. - for (q.emplace_back(s1, s2); ret && !q.empty(); q.pop_front()) { + for (q.emplace(s1, s2); ret && !q.empty(); q.pop()) { s1 = q.front().first; s2 = q.front().second; // Representatives of the equivalence classes of s1/s2. @@ -230,7 +229,7 @@ bool Equivalent(const Fst &fst1, const Fst &fst2, ret = false; break; } - q.push_back(pair); + q.push(pair); } } } diff --git a/src/include/fst/expander-cache.h b/src/include/fst/expander-cache.h index c2e39c3..b17f3d6 100644 --- a/src/include/fst/expander-cache.h +++ b/src/include/fst/expander-cache.h @@ -45,13 +45,13 @@ #include #include -#include #include #include #include #include #include +#include namespace fst { @@ -148,7 +148,7 @@ class NoGcKeepOneExpanderCache { auto i = cache_.find(state_id_); if (i != cache_.end()) state_ = std::move(i->second); if (state_ == nullptr) { - state_ = fst::make_unique(); + state_ = std::make_unique(); expander.Expand(state_id_, state_.get()); } return state_.get(); @@ -170,26 +170,26 @@ class HashExpanderCache { HashExpanderCache(const HashExpanderCache ©) { *this = copy; } HashExpanderCache &operator=(const HashExpanderCache ©) { - for (const auto &kv : copy.cache_) cache_[kv.first] = new State(*kv.second); + for (const auto &[id, state] : copy.cache_) { + cache_[id] = std::make_unique(*state); + } return *this; } - ~HashExpanderCache() { - for (auto i : cache_) delete i.second; - } + ~HashExpanderCache() = default; template State *FindOrExpand(Expander &expander, StateId state_id) { - auto it = cache_.insert(std::pair(state_id, nullptr)); - if (!it.second) return it.first->second; - auto *state = new State; - it.first->second = state; - expander.Expand(state_id, state); - return state; + auto [it, inserted] = cache_.emplace(state_id, nullptr); + if (inserted) { + it->second = std::make_unique(); + expander.Expand(state_id, it->second.get()); + } + return it->second.get(); } private: - std::unordered_map cache_; + std::unordered_map> cache_; }; template diff --git a/src/include/fst/extensions/compress/compress.h b/src/include/fst/extensions/compress/compress.h index d5df6fd..8925fb3 100644 --- a/src/include/fst/extensions/compress/compress.h +++ b/src/include/fst/extensions/compress/compress.h @@ -108,28 +108,13 @@ class LempelZiv { } } - ~LempelZiv() { - for (auto it = root_.next_number.begin(); it != root_.next_number.end(); - ++it) { - CleanUp(it->second); - } - } - private: struct Node { Var current_number; Edge current_edge; - std::map next_number; + std::map, EdgeLessThan> next_number; }; - void CleanUp(Node *temp) { - for (auto it = temp->next_number.begin(); it != temp->next_number.end(); - ++it) { - CleanUp(it->second); - } - delete temp; - } - Node root_; Var dict_number_; std::vector> decode_vector_; @@ -144,7 +129,7 @@ void LempelZiv::BatchEncode( while (it != input.cend()) { auto next = temp_node->next_number.find(*it); if (next != temp_node->next_number.cend()) { - temp_node = next->second; + temp_node = next->second.get(); ++it; } else { break; @@ -154,10 +139,10 @@ void LempelZiv::BatchEncode( output->emplace_back(temp_node->current_number, default_edge_); } else if (it != input.cend()) { output->emplace_back(temp_node->current_number, *it); - auto *new_node = new Node(); + auto new_node = std::make_unique(); new_node->current_number = dict_number_++; new_node->current_edge = *it; - temp_node->next_number[*it] = new_node; + temp_node->next_number[*it] = std::move(new_node); } if (it == input.cend()) break; } diff --git a/src/include/fst/extensions/far/extract.h b/src/include/fst/extensions/far/extract.h index a7a236c..14443bf 100644 --- a/src/include/fst/extensions/far/extract.h +++ b/src/include/fst/extensions/far/extract.h @@ -20,42 +20,41 @@ #ifndef FST_EXTENSIONS_FAR_EXTRACT_H_ #define FST_EXTENSIONS_FAR_EXTRACT_H_ +#include #include #include #include #include #include +#include namespace fst { template -inline void FarWriteFst(const Fst *fst, std::string key, std::string *okey, - int *nrep, int32 generate_sources, int i, - const std::string &source_prefix, - const std::string &source_suffix) { +inline void FarWriteFst(const Fst *fst, std::string_view key, + std::string *okey, int *nrep, int32 generate_sources, + int i, std::string_view source_prefix, + std::string_view source_suffix) { + DCHECK_NE(fst, nullptr); + DCHECK_NE(okey, nullptr); + DCHECK_NE(nrep, nullptr); if (key == *okey) { ++*nrep; } else { *nrep = 0; } - *okey = key; - std::string osource; + okey->assign(key.data(), key.size()); + std::ostringstream source_path; + source_path << source_prefix; if (generate_sources) { - std::ostringstream tmp; - tmp.width(generate_sources); - tmp.fill('0'); - tmp << i; - osource = tmp.str(); + source_path << std::setw(generate_sources) << std::setfill('0') << i; } else { - if (*nrep > 0) { - std::ostringstream tmp; - tmp << '.' << nrep; - key.append(tmp.str().data(), tmp.str().size()); - } - osource = key; + source_path << key; + if (*nrep > 0) source_path << '.' << *nrep; } - fst->Write(source_prefix + osource + source_suffix); + source_path << source_suffix; + fst->Write(source_path.str()); } template @@ -69,20 +68,16 @@ void FarExtract(const std::vector &isources, if (!far_reader) return; std::string okey; int nrep = 0; - std::vector key_vector; // User has specified a set of FSTs to extract, where some of these may in // fact be ranges. if (!keys.empty()) { - auto *keys_cstr = new char[keys.size() + 1]; - strcpy(keys_cstr, keys.c_str()); - SplitString(keys_cstr, key_separator.c_str(), &key_vector, true); + std::vector key_vector = + SplitString(keys, key_separator, true); int i = 0; for (size_t k = 0; k < key_vector.size(); ++k, ++i) { - std::string key = key_vector[k]; - auto *key_cstr = new char[key.size() + 1]; - strcpy(key_cstr, key.c_str()); - std::vector range_vector; - SplitString(key_cstr, range_delimiter.c_str(), &range_vector, false); + std::string_view key = key_vector[k]; + std::vector range_vector = + SplitString(key, range_delimiter, false); if (range_vector.size() == 1) { // Not a range if (!far_reader->Find(key)) { LOG(ERROR) << "FarExtract: Cannot find key " << key; @@ -92,8 +87,8 @@ void FarExtract(const std::vector &isources, FarWriteFst(fst, key, &okey, &nrep, generate_sources, i, source_prefix, source_suffix); } else if (range_vector.size() == 2) { // A legal range - std::string begin_key = range_vector[0]; - std::string end_key = range_vector[1]; + std::string_view begin_key = range_vector[0]; + std::string_view end_key = range_vector[1]; if (begin_key.empty() || end_key.empty()) { LOG(ERROR) << "FarExtract: Illegal range specification " << key; return; @@ -113,9 +108,7 @@ void FarExtract(const std::vector &isources, LOG(ERROR) << "FarExtract: Illegal range specification " << key; return; } - delete[] key_cstr; } - delete[] keys_cstr; return; } // Nothing specified, so just extracts everything. diff --git a/src/include/fst/extensions/far/far-class.h b/src/include/fst/extensions/far/far-class.h index 7204e4f..0053ce9 100644 --- a/src/include/fst/extensions/far/far-class.h +++ b/src/include/fst/extensions/far/far-class.h @@ -68,7 +68,7 @@ class FarReaderClassImpl : public FarReaderImplBase { bool Find(const std::string &key) final { return reader_->Find(key); } const FstClass *GetFstClass() const final { - fstc_ = fst::make_unique(*reader_->GetFst()); + fstc_ = std::make_unique(*reader_->GetFst()); return fstc_.get(); } @@ -157,7 +157,7 @@ class FarReaderClass { template void OpenFarReaderClass(OpenFarReaderClassArgs *args) { - auto impl = fst::make_unique>(args->args); + auto impl = std::make_unique>(args->args); if (impl->GetFarReader() == nullptr) { // Underlying reader failed to open, so return failure here, too. args->retval = nullptr; @@ -271,7 +271,7 @@ class FarWriterClass { template void CreateFarWriterClass(CreateFarWriterClassArgs *args) { args->retval = fst::WrapUnique( - new FarWriterClass(fst::make_unique>( + new FarWriterClass(std::make_unique>( std::get<0>(args->args), std::get<1>(args->args)))); } diff --git a/src/include/fst/extensions/far/far.h b/src/include/fst/extensions/far/far.h index cef7ff6..539f4e6 100644 --- a/src/include/fst/extensions/far/far.h +++ b/src/include/fst/extensions/far/far.h @@ -30,6 +30,7 @@ #include #include #include +#include namespace fst { @@ -137,7 +138,7 @@ class FarReader { virtual void Reset() = 0; // Sets current position to first entry >= key. Returns true if a match. - virtual bool Find(const std::string &key) = 0; + virtual bool Find(std::string_view key) = 0; // Current position at end of archive? virtual bool Done() const = 0; @@ -303,7 +304,7 @@ class STTableFarReader : public FarReader { void Reset() final { reader_->Reset(); } - bool Find(const std::string &key) final { return reader_->Find(key); } + bool Find(std::string_view key) final { return reader_->Find(key); } bool Done() const final { return reader_->Done(); } @@ -346,7 +347,7 @@ class STListFarReader : public FarReader { void Reset() final { reader_->Reset(); } - bool Find(const std::string &key) final { return reader_->Find(key); } + bool Find(std::string_view key) final { return reader_->Find(key); } bool Done() const final { return reader_->Done(); } @@ -424,7 +425,7 @@ class FstFarReader final : public FarReader { ReadFst(); } - bool Find(const std::string &key) final { + bool Find(std::string_view key) final { if (has_stdin_) { FSTERROR() << "FstFarReader::Find: Operation not supported on standard input"; diff --git a/src/include/fst/extensions/far/print-strings.h b/src/include/fst/extensions/far/print-strings.h index 8b47f70..a5797a8 100644 --- a/src/include/fst/extensions/far/print-strings.h +++ b/src/include/fst/extensions/far/print-strings.h @@ -78,10 +78,12 @@ void FarPrintStrings(const std::vector &isources, /*omit_epsilon=*/false); printer(*fst, &str); if (entry_type == FarEntryType::LINE) { - if (print_key) std::cout << key << FLAGS_far_field_separator[0]; + if (print_key) + std::cout << key << FST_FLAGS_far_field_separator[0]; std::cout << str; if (print_weight) { - std::cout << FLAGS_far_field_separator[0] << ShortestDistance(*fst); + std::cout << FST_FLAGS_far_field_separator[0] + << ShortestDistance(*fst); } std::cout << std::endl; } else if (entry_type == FarEntryType::FILE) { diff --git a/src/include/fst/extensions/far/stlist.h b/src/include/fst/extensions/far/stlist.h index ea0c051..82b1c08 100644 --- a/src/include/fst/extensions/far/stlist.h +++ b/src/include/fst/extensions/far/stlist.h @@ -34,6 +34,7 @@ #include #include +#include namespace fst { @@ -191,7 +192,7 @@ class STListReader { error_ = true; } - bool Find(const std::string &key) { + bool Find(std::string_view key) { FSTERROR() << "STListReader::Find: Operation not supported"; error_ = true; return false; diff --git a/src/include/fst/extensions/far/sttable.h b/src/include/fst/extensions/far/sttable.h index 5d5b361..cf8af20 100644 --- a/src/include/fst/extensions/far/sttable.h +++ b/src/include/fst/extensions/far/sttable.h @@ -30,6 +30,7 @@ #include #include +#include namespace fst { @@ -187,7 +188,7 @@ class STTableReader { MakeHeap(); } - bool Find(const std::string &key) { + bool Find(std::string_view key) { if (error_) return false; for (size_t i = 0; i < streams_.size(); ++i) LowerBound(i, key); MakeHeap(); @@ -235,7 +236,7 @@ class STTableReader { // Positions the stream at the position corresponding to the lower bound for // the specified key. - void LowerBound(size_t id, const std::string &find_key) { + void LowerBound(size_t id, std::string_view find_key) { auto *strm = streams_[id]; const auto &positions = positions_[id]; if (positions.empty()) return; diff --git a/src/include/fst/extensions/linear/linear-fst.h b/src/include/fst/extensions/linear/linear-fst.h index 441900b..28f35fe 100644 --- a/src/include/fst/extensions/linear/linear-fst.h +++ b/src/include/fst/extensions/linear/linear-fst.h @@ -580,7 +580,7 @@ class ArcIterator> template inline void LinearTaggerFst::InitStateIterator( StateIteratorData *data) const { - data->base = fst::make_unique>>(*this); + data->base = std::make_unique>>(*this); } namespace internal { @@ -1040,7 +1040,7 @@ template inline void LinearClassifierFst::InitStateIterator( StateIteratorData *data) const { data->base = - fst::make_unique>>(*this); + std::make_unique>>(*this); } // Specialized Matcher for LinearFsts. This matcher only supports diff --git a/src/include/fst/extensions/linear/linearscript.h b/src/include/fst/extensions/linear/linearscript.h index 4560328..c57e149 100644 --- a/src/include/fst/extensions/linear/linearscript.h +++ b/src/include/fst/extensions/linear/linearscript.h @@ -50,17 +50,18 @@ bool ValidateDelimiter(); bool ValidateEmptySymbol(); // Returns the proper label given the symbol. For symbols other than -// `FLAGS_start_symbol` or `FLAGS_end_symbol`, looks up the symbol +// `FST_FLAGS_start_symbol` or `FST_FLAGS_end_symbol`, looks up the symbol // table to decide the label. Depending on whether -// `FLAGS_start_symbol` and `FLAGS_end_symbol` are identical, it +// `FST_FLAGS_start_symbol` and `FST_FLAGS_end_symbol` are identical, it // either returns `kNoLabel` for later processing or decides the label // right away. template inline typename Arc::Label LookUp(const std::string &str, SymbolTable *syms) { - if (str == FLAGS_start_symbol) { - return str == FLAGS_end_symbol ? kNoLabel - : LinearFstData::kStartOfSentence; - } else if (str == FLAGS_end_symbol) { + if (str == FST_FLAGS_start_symbol) { + return str == FST_FLAGS_end_symbol + ? kNoLabel + : LinearFstData::kStartOfSentence; + } else if (str == FST_FLAGS_end_symbol) { return LinearFstData::kEndOfSentence; } else { return syms->AddSymbol(str); @@ -72,7 +73,7 @@ inline typename Arc::Label LookUp(const std::string &str, SymbolTable *syms) { template void SplitAndPush(const std::string &str, const char delim, SymbolTable *syms, std::vector *output) { - if (str == FLAGS_empty_symbol) return; + if (str == FST_FLAGS_empty_symbol) return; std::istringstream strm(str); std::string buf; while (std::getline(strm, buf, delim)) { @@ -118,7 +119,7 @@ bool GetModelRecord(const std::string &model, std::istream &strm, // // word features [ possible output ] // -// where features and possible output are `FLAGS_delimiter`-delimited lists of +// where features and possible output are `FST_FLAGS_delimiter`-delimited lists of // tokens template void AddVocab(const std::string &vocab, SymbolTable *isyms, SymbolTable *fsyms, @@ -177,9 +178,9 @@ void AddVocab(const std::string &vocab, SymbolTable *isyms, SymbolTable *fsyms, // // input sequence output sequence weight // -// input sequence is a `FLAGS_delimiter`-delimited sequence of feature +// input sequence is a `FST_FLAGS_delimiter`-delimited sequence of feature // labels (see `AddVocab()`) . output sequence is a -// `FLAGS_delimiter`-delimited sequence of output labels where the +// `FST_FLAGS_delimiter`-delimited sequence of output labels where the // last label is the output of the feature position before the history // boundary. template @@ -315,7 +316,7 @@ void LinearCompileTpl(LinearCompileArgs *args) { << LinearFstData::kStartOfSentence; VLOG(1) << "end-of-sentence label is " << LinearFstData::kEndOfSentence; - if (FLAGS_classifier) { + if (FST_FLAGS_classifier) { int num_classes = ScanNumClasses(models, models_length); LinearClassifierFstDataBuilder builder(num_classes, &isyms, &fsyms, &osyms); @@ -372,7 +373,7 @@ bool GetVocabRecord(const std::string &vocab, std::istream &strm, *word = LookUp(fields[0], isyms); - const char delim = FLAGS_delimiter[0]; + const char delim = FST_FLAGS_delimiter[0]; SplitAndPush(fields[1], delim, fsyms, feature_labels); SplitAndPush(fields[2], delim, osyms, possible_labels); @@ -399,7 +400,7 @@ bool GetModelRecord(const std::string &model, std::istream &strm, input_labels->clear(); output_labels->clear(); - const char delim = FLAGS_delimiter[0]; + const char delim = FST_FLAGS_delimiter[0]; SplitAndPush(fields[0], delim, fsyms, input_labels); SplitAndPush(fields[1], delim, osyms, output_labels); diff --git a/src/include/fst/extensions/linear/trie.h b/src/include/fst/extensions/linear/trie.h index 49ee1e1..cf6db2d 100644 --- a/src/include/fst/extensions/linear/trie.h +++ b/src/include/fst/extensions/linear/trie.h @@ -18,12 +18,13 @@ #ifndef FST_EXTENSIONS_LINEAR_TRIE_H_ #define FST_EXTENSIONS_LINEAR_TRIE_H_ -#include +#include #include #include #include #include +#include namespace fst { @@ -135,7 +136,7 @@ class NestedTrieTopology { NestedTrieTopology(); NestedTrieTopology(const NestedTrieTopology &that); - ~NestedTrieTopology(); + ~NestedTrieTopology() = default; void swap(NestedTrieTopology &that); NestedTrieTopology &operator=(const NestedTrieTopology &that); bool operator==(const NestedTrieTopology &that) const; @@ -154,29 +155,20 @@ class NestedTrieTopology { const_iterator end() const { return const_iterator(this, NumNodes()); } private: - std::vector nodes_; // Use pointers to avoid copying the maps when - // the vector grows + // Use pointers to avoid copying the maps when the vector grows + std::vector> nodes_; }; template NestedTrieTopology::NestedTrieTopology() { - nodes_.push_back(new NextMap); + nodes_.push_back(std::make_unique()); } template NestedTrieTopology::NestedTrieTopology(const NestedTrieTopology &that) { nodes_.reserve(that.nodes_.size()); - for (size_t i = 0; i < that.nodes_.size(); ++i) { - NextMap *node = that.nodes_[i]; - nodes_.push_back(new NextMap(*node)); - } -} - -template -NestedTrieTopology::~NestedTrieTopology() { - for (size_t i = 0; i < nodes_.size(); ++i) { - NextMap *node = nodes_[i]; - delete node; + for (const auto &node : that.nodes_) { + nodes_.push_back(std::make_unique(*node)); } } @@ -215,7 +207,7 @@ inline int NestedTrieTopology::Insert(int parent, const L &label) { if (ret == kNoTrieNodeId) { ret = NumNodes(); (*nodes_[parent])[label] = ret; - nodes_.push_back(new NextMap); + nodes_.push_back(std::make_unique()); } return ret; } @@ -231,8 +223,12 @@ inline std::istream &NestedTrieTopology::Read(std::istream &strm) { NestedTrieTopology new_trie; size_t num_nodes; if (!ReadType(strm, &num_nodes)) return strm; - for (size_t i = 1; i < num_nodes; ++i) new_trie.nodes_.push_back(new NextMap); - for (size_t i = 0; i < num_nodes; ++i) ReadType(strm, new_trie.nodes_[i]); + for (size_t i = 1; i < num_nodes; ++i) { + new_trie.nodes_.push_back(std::make_unique()); + } + for (size_t i = 0; i < num_nodes; ++i) { + ReadType(strm, new_trie.nodes_[i].get()); + } if (strm) swap(new_trie); return strm; } diff --git a/src/include/fst/extensions/mpdt/expand.h b/src/include/fst/extensions/mpdt/expand.h index 29f9516..05d9855 100644 --- a/src/include/fst/extensions/mpdt/expand.h +++ b/src/include/fst/extensions/mpdt/expand.h @@ -293,7 +293,7 @@ class ArcIterator> template inline void MPdtExpandFst::InitStateIterator( StateIteratorData *data) const { - data->base = fst::make_unique>>(*this); + data->base = std::make_unique>>(*this); } struct MPdtExpandOptions { diff --git a/src/include/fst/extensions/mpdt/mpdt.h b/src/include/fst/extensions/mpdt/mpdt.h index 93c60c8..a171c27 100644 --- a/src/include/fst/extensions/mpdt/mpdt.h +++ b/src/include/fst/extensions/mpdt/mpdt.h @@ -136,7 +136,7 @@ class MPdtStack { next_stack_id_(other.next_stack_id_) { std::transform(other.stacks_.begin(), other.stacks_.end(), stacks_.begin(), [](const std::unique_ptr> &ptr) { - return fst::make_unique>(*ptr); + return std::make_unique>(*ptr); }); } @@ -297,7 +297,7 @@ MPdtStack::MPdtStack( Config zero; for (Level level = 0; level < nlevels; ++level) { stacks_[level] = - fst::make_unique>(vectors[level]); + std::make_unique>(vectors[level]); neg_one[level] = -1; zero[level] = 0; } diff --git a/src/include/fst/extensions/mpdt/read_write_utils.h b/src/include/fst/extensions/mpdt/read_write_utils.h index 4904436..e30d421 100644 --- a/src/include/fst/extensions/mpdt/read_write_utils.h +++ b/src/include/fst/extensions/mpdt/read_write_utils.h @@ -27,6 +27,7 @@ #include #include +#include namespace fst { @@ -47,10 +48,9 @@ bool ReadLabelTriples(const std::string &source, pairs->clear(); while (fstrm.getline(line, kLineLen)) { ++nline; - std::vector col; - SplitString(line, "\n\t ", &col, true); + std::vector col = SplitString(line, "\n\t ", true); // Empty line or comment? - if (col.empty() || col[0][0] == '\0' || col[0][0] == '#') continue; + if (col.empty() || col[0].empty() || col[0][0] == '#') continue; if (col.size() != 3) { LOG(ERROR) << "ReadLabelTriples: Bad number of columns, " << "file = " << source << ", line = " << nline; diff --git a/src/include/fst/extensions/ngram/ngram-fst.h b/src/include/fst/extensions/ngram/ngram-fst.h index 6eab44e..2f0d623 100644 --- a/src/include/fst/extensions/ngram/ngram-fst.h +++ b/src/include/fst/extensions/ngram/ngram-fst.h @@ -111,7 +111,7 @@ class NGramFstImpl : public FstImpl { } static NGramFstImpl *Read(std::istream &strm, const FstReadOptions &opts) { - auto impl = fst::make_unique>(); + auto impl = std::make_unique>(); FstHeader hdr; if (!impl->ReadHeader(strm, opts, kMinFileVersion, &hdr)) return nullptr; uint64 num_states, num_futures, num_final; @@ -480,7 +480,7 @@ inline void NGramFst::InitArcIterator(StateId s, ArcIteratorData *data) const { GetImpl()->SetInstFuture(s, &inst_); GetImpl()->SetInstNode(&inst_); - data->base = fst::make_unique>>(*this, s); + data->base = std::make_unique>>(*this, s); } namespace internal { diff --git a/src/include/fst/extensions/ngram/nthbit.h b/src/include/fst/extensions/ngram/nthbit.h index 7ad479e..ea3aa81 100644 --- a/src/include/fst/extensions/ngram/nthbit.h +++ b/src/include/fst/extensions/ngram/nthbit.h @@ -83,7 +83,7 @@ inline uint32 nth_bit(const uint64 v, const uint32 r) { #if defined(__aarch64__) // Use the ARM64 CNT instruction to compute a byte-wise popcount. const uint64 s = - reinterpret_cast(vcnt_s8(reinterpret_cast(v))); + reinterpret_cast(vcnt_u8(reinterpret_cast(v))); #else constexpr uint64 kOnesStep4 = 0x1111111111111111; uint64 s = v; diff --git a/src/include/fst/extensions/pdt/expand.h b/src/include/fst/extensions/pdt/expand.h index 9ff199e..88afc4c 100644 --- a/src/include/fst/extensions/pdt/expand.h +++ b/src/include/fst/extensions/pdt/expand.h @@ -297,7 +297,7 @@ class ArcIterator> template inline void PdtExpandFst::InitStateIterator( StateIteratorData *data) const { - data->base = fst::make_unique>>(*this); + data->base = std::make_unique>>(*this); } // PrunedExpand prunes the delayed expansion of a pushdown transducer (PDT) diff --git a/src/include/fst/extensions/special/phi-fst.h b/src/include/fst/extensions/special/phi-fst.h index edd0769..c2ad4de 100644 --- a/src/include/fst/extensions/special/phi-fst.h +++ b/src/include/fst/extensions/special/phi-fst.h @@ -36,9 +36,10 @@ template class PhiFstMatcherData { public: explicit PhiFstMatcherData( - Label phi_label = FLAGS_phi_fst_phi_label, - bool phi_loop = FLAGS_phi_fst_phi_loop, - MatcherRewriteMode rewrite_mode = RewriteMode(FLAGS_phi_fst_rewrite_mode)) + Label phi_label = FST_FLAGS_phi_fst_phi_label, + bool phi_loop = FST_FLAGS_phi_fst_phi_loop, + MatcherRewriteMode rewrite_mode = + RewriteMode(FST_FLAGS_phi_fst_rewrite_mode)) : phi_label_(phi_label), phi_loop_(phi_loop), rewrite_mode_(rewrite_mode) {} diff --git a/src/include/fst/extensions/special/rho-fst.h b/src/include/fst/extensions/special/rho-fst.h index 9464fb0..7bb3b9b 100644 --- a/src/include/fst/extensions/special/rho-fst.h +++ b/src/include/fst/extensions/special/rho-fst.h @@ -35,8 +35,9 @@ template class RhoFstMatcherData { public: explicit RhoFstMatcherData( - Label rho_label = FLAGS_rho_fst_rho_label, - MatcherRewriteMode rewrite_mode = RewriteMode(FLAGS_rho_fst_rewrite_mode)) + Label rho_label = FST_FLAGS_rho_fst_rho_label, + MatcherRewriteMode rewrite_mode = + RewriteMode(FST_FLAGS_rho_fst_rewrite_mode)) : rho_label_(rho_label), rewrite_mode_(rewrite_mode) {} RhoFstMatcherData(const RhoFstMatcherData &data) diff --git a/src/include/fst/extensions/special/sigma-fst.h b/src/include/fst/extensions/special/sigma-fst.h index df10fdf..09f4232 100644 --- a/src/include/fst/extensions/special/sigma-fst.h +++ b/src/include/fst/extensions/special/sigma-fst.h @@ -35,9 +35,9 @@ template class SigmaFstMatcherData { public: explicit SigmaFstMatcherData( - Label sigma_label = FLAGS_sigma_fst_sigma_label, + Label sigma_label = FST_FLAGS_sigma_fst_sigma_label, MatcherRewriteMode rewrite_mode = - RewriteMode(FLAGS_sigma_fst_rewrite_mode)) + RewriteMode(FST_FLAGS_sigma_fst_rewrite_mode)) : sigma_label_(sigma_label), rewrite_mode_(rewrite_mode) {} SigmaFstMatcherData(const SigmaFstMatcherData &data) diff --git a/src/include/fst/factor-weight.h b/src/include/fst/factor-weight.h index 28fea77..f6352a6 100644 --- a/src/include/fst/factor-weight.h +++ b/src/include/fst/factor-weight.h @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -32,6 +31,8 @@ #include #include +#include + namespace fst { constexpr uint8 kFactorFinalWeights = 0x01; @@ -523,7 +524,7 @@ template inline void FactorWeightFst::InitStateIterator( StateIteratorData *data) const { data->base = - fst::make_unique>>( + std::make_unique>>( *this); } diff --git a/src/include/fst/flags.h b/src/include/fst/flags.h index 12a6bcc..ec157ec 100644 --- a/src/include/fst/flags.h +++ b/src/include/fst/flags.h @@ -35,7 +35,7 @@ // // DEFINE_int32(length, 0, "length"); // -// This defines variable FLAGS_length, initialized to 0. +// This defines variable FST_FLAGS_length, initialized to 0. // // Declaration example: // @@ -46,12 +46,12 @@ // // ShowUsage() can be used to print out command and flag usage. -#define DECLARE_bool(name) extern bool FLAGS_ ## name -#define DECLARE_string(name) extern std::string FLAGS_##name -#define DECLARE_int32(name) extern int32 FLAGS_ ## name -#define DECLARE_int64(name) extern int64 FLAGS_ ## name -#define DECLARE_uint64(name) extern uint64 FLAGS_##name -#define DECLARE_double(name) extern double FLAGS_ ## name +#define DECLARE_bool(name) extern bool FST_FLAGS_ ## name +#define DECLARE_string(name) extern std::string FST_FLAGS_##name +#define DECLARE_int32(name) extern int32 FST_FLAGS_ ## name +#define DECLARE_int64(name) extern int64 FST_FLAGS_ ## name +#define DECLARE_uint64(name) extern uint64 FST_FLAGS_##name +#define DECLARE_double(name) extern double FST_FLAGS_ ## name template struct FlagDescription { @@ -189,13 +189,13 @@ class FlagRegisterer { }; -#define DEFINE_VAR(type, name, value, doc) \ - type FLAGS_ ## name = value; \ - static FlagRegisterer \ - name ## _flags_registerer(#name, FlagDescription(&FLAGS_ ## name, \ - doc, \ - #type, \ - __FILE__, \ +#define DEFINE_VAR(type, name, value, doc) \ + type FST_FLAGS_ ## name = value; \ + static FlagRegisterer \ + name ## _flags_registerer(#name, FlagDescription(&FST_FLAGS_ ## name, \ + doc, \ + #type, \ + __FILE__, \ value)) #define DEFINE_bool(name, value, doc) DEFINE_VAR(bool, name, value, doc) @@ -213,6 +213,12 @@ DECLARE_string(tmpdir); void SetFlags(const char *usage, int *argc, char ***argv, bool remove_flags, const char *src = ""); +// This is an unpleasant hack around absl::SetFlag API. +template +void SetFlag(Type *flag, Value value) { + *flag = Type(value); +} + #define SET_FLAGS(usage, argc, argv, rmflags) \ SetFlags(usage, argc, argv, rmflags, __FILE__) diff --git a/src/include/fst/fst.h b/src/include/fst/fst.h index 80e3948..a207329 100644 --- a/src/include/fst/fst.h +++ b/src/include/fst/fst.h @@ -44,20 +44,7 @@ #include #include #include - -#ifndef OPENFST_HAVE_STD_STRING_VIEW -#ifdef __has_include -#if __has_include() && __cplusplus >= 201703L -#define OPENFST_HAVE_STD_STRING_VIEW 1 -#endif -#endif -#endif -#ifdef OPENFST_HAVE_STD_STRING_VIEW #include -#else -#include -#endif - DECLARE_bool(fst_align); @@ -122,7 +109,7 @@ struct FstWriteOptions { explicit FstWriteOptions(std::string_view source = "", bool write_header = true, bool write_isymbols = true, bool write_osymbols = true, - bool align = FLAGS_fst_align, + bool align = FST_FLAGS_fst_align, bool stream_write = false) : source(source), write_header(write_header), diff --git a/src/include/fst/label-reachable.h b/src/include/fst/label-reachable.h index b9414ba..5b09666 100644 --- a/src/include/fst/label-reachable.h +++ b/src/include/fst/label-reachable.h @@ -21,6 +21,7 @@ #ifndef FST_LABEL_REACHABLE_H_ #define FST_LABEL_REACHABLE_H_ +#include #include #include @@ -85,14 +86,15 @@ class LabelReachableData { static LabelReachableData *Read(std::istream &istrm, const FstReadOptions &opts) { - auto *data = new LabelReachableData(); + // NB: Using `new` to access private constructor. + auto data = fst::WrapUnique(new LabelReachableData()); ReadType(istrm, &data->reach_input_); ReadType(istrm, &data->keep_relabel_data_); data->have_relabel_data_ = data->keep_relabel_data_; if (data->keep_relabel_data_) ReadType(istrm, &data->label2index_); ReadType(istrm, &data->final_label_); ReadType(istrm, &data->interval_sets_); - return data; + return data.release(); } bool Write(std::ostream &ostrm, const FstWriteOptions &opts) const { @@ -187,12 +189,13 @@ class LabelReachable { using Interval = typename LabelIntervalSet::Interval; LabelReachable(const Fst &fst, bool reach_input, - Accumulator *accumulator = nullptr, + std::unique_ptr accumulator = nullptr, bool keep_relabel_data = true) - : fst_(new VectorFst(fst)), + : fst_(std::make_unique>(fst)), s_(kNoStateId), data_(std::make_shared(reach_input, keep_relabel_data)), - accumulator_(accumulator ? accumulator : new Accumulator()), + accumulator_(accumulator ? std::move(accumulator) + : std::make_unique()), ncalls_(0), nintervals_(0), reach_fst_input_(false), @@ -204,10 +207,11 @@ class LabelReachable { } explicit LabelReachable(std::shared_ptr data, - Accumulator *accumulator = nullptr) + std::unique_ptr accumulator = nullptr) : s_(kNoStateId), data_(std::move(data)), - accumulator_(accumulator ? accumulator : new Accumulator()), + accumulator_(accumulator ? std::move(accumulator) + : std::make_unique()), ncalls_(0), nintervals_(0), reach_fst_input_(false), @@ -217,7 +221,8 @@ class LabelReachable { bool safe = false) : s_(kNoStateId), data_(reachable.data_), - accumulator_(new Accumulator(*reachable.accumulator_, safe)), + accumulator_( + std::make_unique(*reachable.accumulator_, safe)), ncalls_(0), nintervals_(0), reach_fst_input_(reachable.reach_fst_input_), diff --git a/src/include/fst/log.h b/src/include/fst/log.h index b777a16..63c209b 100644 --- a/src/include/fst/log.h +++ b/src/include/fst/log.h @@ -44,7 +44,7 @@ class LogMessage { }; #define LOG(type) LogMessage(#type).stream() -#define VLOG(level) if ((level) <= FLAGS_v) LOG(INFO) +#define VLOG(level) if ((level) <= FST_FLAGS_v) LOG(INFO) // Checks inline void FstCheck(bool x, const char* expr, diff --git a/src/include/fst/lookahead-matcher.h b/src/include/fst/lookahead-matcher.h index e3fba9c..27afed2 100644 --- a/src/include/fst/lookahead-matcher.h +++ b/src/include/fst/lookahead-matcher.h @@ -458,23 +458,23 @@ class LabelLookAheadMatcher // This makes a copy of the FST. LabelLookAheadMatcher(const FST &fst, MatchType match_type, std::shared_ptr data = nullptr, - Accumulator *accumulator = nullptr) + std::unique_ptr accumulator = nullptr) : matcher_(fst, match_type), lfst_(nullptr), state_(kNoStateId), error_(false) { - Init(fst, match_type, data, accumulator); + Init(fst, match_type, data, std::move(accumulator)); } // This doesn't copy the FST. LabelLookAheadMatcher(const FST *fst, MatchType match_type, std::shared_ptr data = nullptr, - Accumulator *accumulator = nullptr) + std::unique_ptr accumulator = nullptr) : matcher_(fst, match_type), lfst_(nullptr), state_(kNoStateId), error_(false) { - Init(*fst, match_type, data, accumulator); + Init(*fst, match_type, data, std::move(accumulator)); } // This makes a copy of the FST. @@ -588,16 +588,19 @@ class LabelLookAheadMatcher private: void Init(const FST &fst, MatchType match_type, - std::shared_ptr data, Accumulator *accumulator) { + std::shared_ptr data, + std::unique_ptr accumulator) { const bool reach_input = match_type == MATCH_INPUT; if (data) { if (reach_input == data->ReachInput()) { - label_reachable_ = fst::make_unique(data, accumulator); + label_reachable_ = + std::make_unique(data, std::move(accumulator)); } } else if ((reach_input && (kFlags & kInputLookAheadMatcher)) || (!reach_input && (kFlags & kOutputLookAheadMatcher))) { - label_reachable_ = fst::make_unique( - fst, reach_input, accumulator, kFlags & kLookAheadKeepRelabelData); + label_reachable_ = + std::make_unique(fst, reach_input, std::move(accumulator), + kFlags & kLookAheadKeepRelabelData); } } @@ -725,11 +728,12 @@ inline LabelLookAheadRelabeler::LabelLookAheadRelabeler( // do a deep copy when the Fst is modified. mfst.reset(fst::down_cast *>(&fst)); } else { - mfst = fst::make_unique>(fst); + mfst = std::make_unique>(fst); } - RelabelForReachable(mfst.get(), *data, FLAGS_save_relabel_ipairs, - FLAGS_save_relabel_opairs); + RelabelForReachable(mfst.get(), *data, + FST_FLAGS_save_relabel_ipairs, + FST_FLAGS_save_relabel_opairs); if (is_mutable) { // Pointer was just borrowed, don't delete it. @@ -759,13 +763,13 @@ class LookAheadMatcher { lookahead_(false) { if (!base_) base_ = - fst::make_unique>(owned_fst_.get(), match_type); + std::make_unique>(owned_fst_.get(), match_type); } // This doesn't copy the FST. LookAheadMatcher(const FST *fst, MatchType match_type) : base_(fst->InitMatcher(match_type)), lookahead_(false) { - if (!base_) base_ = fst::make_unique>(fst, match_type); + if (!base_) base_ = std::make_unique>(fst, match_type); } // This makes a copy of the FST. diff --git a/src/include/fst/mapped-file.h b/src/include/fst/mapped-file.h index c182eea..18a478f 100644 --- a/src/include/fst/mapped-file.h +++ b/src/include/fst/mapped-file.h @@ -61,7 +61,7 @@ class MappedFile { // bool is advisory, and Map will default to allocating and reading. The // source argument needs to contain the filename that was used to open the // input stream. - static MappedFile *Map(std::istream *istrm, bool memorymap, + static MappedFile *Map(std::istream &istrm, bool memorymap, const std::string &source, size_t size); // Returns a MappedFile object that contains the contents of the file referred diff --git a/src/include/fst/matcher.h b/src/include/fst/matcher.h index fc4f016..8de8174 100644 --- a/src/include/fst/matcher.h +++ b/src/include/fst/matcher.h @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -30,6 +29,8 @@ #include // for all internal FST accessors. +#include + namespace fst { // Matchers find and iterate through requested labels at FST states. In the @@ -540,14 +541,14 @@ void HashMatcher::SetState(typename FST::Arc::StateId s) { // Resets everything for the state. state_ = s; loop_.nextstate = state_; - aiter_ = fst::make_unique>(fst_, state_); + aiter_ = std::make_unique>(fst_, state_); if (match_type_ == MATCH_NONE) { FSTERROR() << "HashMatcher: Bad match type"; error_ = true; } // Attempts to insert a new label table. auto it_and_success = state_table_->emplace( - state_, fst::make_unique()); + state_, std::make_unique()); // Sets instance's pointer to the label table for this state. label_table_ = it_and_success.first->second.get(); // If it already exists, no additional work is done and we simply return. @@ -1525,13 +1526,13 @@ class Matcher { : owned_fst_(fst.Copy()), base_(owned_fst_->InitMatcher(match_type)) { if (!base_) base_ = - fst::make_unique>(owned_fst_.get(), match_type); + std::make_unique>(owned_fst_.get(), match_type); } // This doesn't copy the FST. Matcher(const FST *fst, MatchType match_type) : base_(fst->InitMatcher(match_type)) { - if (!base_) base_ = fst::make_unique>(fst, match_type); + if (!base_) base_ = std::make_unique>(fst, match_type); } // This makes a copy of the FST. diff --git a/src/include/fst/memory.h b/src/include/fst/memory.h index 6d342f4..733e0a2 100644 --- a/src/include/fst/memory.h +++ b/src/include/fst/memory.h @@ -20,6 +20,7 @@ #ifndef FST_MEMORY_H_ #define FST_MEMORY_H_ +#include #include #include #include @@ -57,25 +58,23 @@ class MemoryArenaImpl : public MemoryArenaBase { explicit MemoryArenaImpl(size_t block_size = kAllocSize) : block_size_(block_size * kObjectSize), block_pos_(0) { - blocks_.emplace_front(new char[block_size_]); + blocks_.emplace_front(std::make_unique(block_size_)); } void *Allocate(size_t size) { const auto byte_size = size * kObjectSize; if (byte_size * kAllocFit > block_size_) { // Large block; adds new large block. - auto *ptr = new char[byte_size]; - blocks_.emplace_back(ptr); - return ptr; - } + blocks_.emplace_back(std::make_unique(byte_size)); + return blocks_.back().get(); + } if (block_pos_ + byte_size > block_size_) { // Doesn't fit; adds new standard block. - auto *ptr = new char[block_size_]; block_pos_ = 0; - blocks_.emplace_front(ptr); + blocks_.emplace_front(std::make_unique(block_size_)); } // Fits; uses current block. - auto *ptr = blocks_.front().get() + block_pos_; + auto *ptr = &blocks_.front()[block_pos_]; block_pos_ += byte_size; return ptr; } @@ -85,7 +84,7 @@ class MemoryArenaImpl : public MemoryArenaBase { private: const size_t block_size_; // Default block size in bytes. size_t block_pos_; // Current position in block in bytes. - std::list> blocks_; // List of allocated blocks. + std::list> blocks_; // List of allocated blocks. }; } // namespace internal @@ -113,7 +112,7 @@ class MemoryPoolImpl : public MemoryPoolBase { enum { kObjectSize = object_size }; struct Link { - char buf[kObjectSize]; + std::byte buf[kObjectSize]; Link *next; }; @@ -144,7 +143,7 @@ class MemoryPoolImpl : public MemoryPoolBase { private: MemoryArena mem_arena_; - Link *free_list_; + Link *free_list_; // Not owned. MemoryPoolImpl(const MemoryPoolImpl &) = delete; MemoryPoolImpl &operator=(const MemoryPoolImpl &) = delete; @@ -162,7 +161,7 @@ template class MemoryPool : public internal::MemoryPoolImpl { public: // 'pool_size' specifies the size of the initial pool and how it is extended. - MemoryPool(size_t pool_size = kAllocSize) + explicit MemoryPool(size_t pool_size = kAllocSize) : internal::MemoryPoolImpl(pool_size) {} }; @@ -176,12 +175,11 @@ class MemoryArenaCollection { template MemoryArena *Arena() { if (sizeof(T) >= arenas_.size()) arenas_.resize(sizeof(T) + 1); - MemoryArenaBase *arena = arenas_[sizeof(T)].get(); + auto &arena = arenas_[sizeof(T)]; if (arena == nullptr) { - arena = new MemoryArena(block_size_); - arenas_[sizeof(T)].reset(arena); + arena = std::make_unique>(block_size_); } - return static_cast *>(arena); + return static_cast *>(arena.get()); } size_t BlockSize() const { return block_size_; } @@ -201,12 +199,9 @@ class MemoryPoolCollection { template MemoryPool *Pool() { if (sizeof(T) >= pools_.size()) pools_.resize(sizeof(T) + 1); - MemoryPoolBase *pool = pools_[sizeof(T)].get(); - if (pool == nullptr) { - pool = new MemoryPool(pool_size_); - pools_[sizeof(T)].reset(pool); - } - return static_cast *>(pool); + auto &pool = pools_[sizeof(T)]; + if (pool == nullptr) pool = std::make_unique>(pool_size_); + return static_cast *>(pool.get()); } size_t PoolSize() const { return pool_size_; } diff --git a/src/include/fst/minimize.h b/src/include/fst/minimize.h index e6c6856..261806d 100644 --- a/src/include/fst/minimize.h +++ b/src/include/fst/minimize.h @@ -44,6 +44,8 @@ #include #include +#include + namespace fst { namespace internal { @@ -212,7 +214,7 @@ class CyclicMinimizer { auto p = this_map.emplace(hash, next_class); state_to_initial_class[s] = p.second ? next_class++ : p.first->second; } - // Lets the unordered_maps go out of scope before we allocate the classes, + // Lets the maps go out of scope before we allocate the classes, // to reduce the maximum amount of memory used. } P_.AllocateClasses(next_class); @@ -238,7 +240,7 @@ class CyclicMinimizer { PrePartition(fst); // Allocates arc iterator queue. ArcIterCompare comp(P_); - aiter_queue_ = fst::make_unique(comp); + aiter_queue_ = std::make_unique(comp); } // Partitions all classes with destination C. void Split(ClassId C) { diff --git a/src/include/fst/prune.h b/src/include/fst/prune.h index 7364c32..7c8a45e 100644 --- a/src/include/fst/prune.h +++ b/src/include/fst/prune.h @@ -107,13 +107,12 @@ struct PruneOptions { // have the path property. The weight of any cycle needs to be bounded; i.e., // // Plus(weight, Weight::One()) == Weight::One() -template ::type * = nullptr> +template void Prune(MutableFst *fst, const PruneOptions &opts = PruneOptions()) { using StateId = typename Arc::StateId; using Weight = typename Arc::Weight; + static_assert(IsPath::value, "Weight must have path property."); using StateHeap = Heap>; auto ns = fst->NumStates(); if (ns < 1) return; @@ -190,16 +189,6 @@ void Prune(MutableFst *fst, const PruneOptions &opts = fst->DeleteStates(dead); } -template ::type * = nullptr> -void Prune(MutableFst *fst, const PruneOptions &opts = - PruneOptions()) { - FSTERROR() << "Prune: Weight needs to have the path property: " - << Arc::Weight::Type(); - fst->SetProperties(kError, kError); -} - // Pruning algorithm: this version modifies its input and takes the // pruning threshold as an argument. It deletes states and arcs in the // FST that do not belong to a successful path whose weight is more @@ -230,14 +219,13 @@ void Prune(MutableFst *fst, typename Arc::Weight weight_threshold, // of any cycle needs to be bounded; i.e., // // Plus(weight, Weight::One()) == Weight::One() -template ::value>::type * = - nullptr> +template void Prune( const Fst &ifst, MutableFst *ofst, const PruneOptions &opts = PruneOptions()) { using StateId = typename Arc::StateId; using Weight = typename Arc::Weight; + static_assert(IsPath::value, "Weight must have path property."); using StateHeap = Heap>; ofst->DeleteStates(); ofst->SetInputSymbols(ifst.InputSymbols()); @@ -321,16 +309,6 @@ void Prune( } } -template ::value>::type - * = nullptr> -void Prune(const Fst &, MutableFst *ofst, - const PruneOptions &) { - FSTERROR() << "Prune: Weight needs to have the path property: " - << Arc::Weight::Type(); - ofst->SetProperties(kError, kError); -} - // Pruning algorithm: this version writes the pruned input FST to an // output MutableFst and simply takes the pruning threshold as an // argument. The output FST contains states and arcs that belong to a diff --git a/src/include/fst/queue.h b/src/include/fst/queue.h index 64a4f2c..778df06 100644 --- a/src/include/fst/queue.h +++ b/src/include/fst/queue.h @@ -650,13 +650,13 @@ class AutoQueue : public QueueBase { const auto props = fst.Properties(kAcyclic | kCyclic | kTopSorted | kUnweighted, false); if ((props & kTopSorted) || fst.Start() == kNoStateId) { - queue_ = fst::make_unique>(); + queue_ = std::make_unique>(); VLOG(2) << "AutoQueue: using state-order discipline"; } else if (props & kAcyclic) { - queue_ = fst::make_unique>(fst, filter); + queue_ = std::make_unique>(fst, filter); VLOG(2) << "AutoQueue: using top-order discipline"; } else if ((props & kUnweighted) && (Weight::Properties() & kIdempotent)) { - queue_ = fst::make_unique>(); + queue_ = std::make_unique>(); VLOG(2) << "AutoQueue: using LIFO discipline"; } else { uint64 properties; @@ -669,8 +669,8 @@ class AutoQueue : public QueueBase { std::unique_ptr comp; if constexpr (IsPath::value) { if (distance) { - less = fst::make_unique(); - comp = fst::make_unique(*distance, *less); + less = std::make_unique(); + comp = std::make_unique(*distance, *less); } } // Finds the queue type to use per SCC. @@ -680,14 +680,14 @@ class AutoQueue : public QueueBase { &unweighted); // If unweighted and semiring is idempotent, uses LIFO queue. if (unweighted) { - queue_ = fst::make_unique>(); + queue_ = std::make_unique>(); VLOG(2) << "AutoQueue: using LIFO discipline"; return; } // If all the SCC are trivial, the FST is acyclic and the scc number gives // the topological order. if (all_trivial) { - queue_ = fst::make_unique>(scc_); + queue_ = std::make_unique>(scc_); VLOG(2) << "AutoQueue: using top-order discipline"; return; } @@ -715,17 +715,17 @@ class AutoQueue : public QueueBase { } break; case LIFO_QUEUE: - queues_[i] = fst::make_unique>(); + queues_[i] = std::make_unique>(); VLOG(3) << "AutoQueue: SCC #" << i << ": using LIFO discipline"; break; case FIFO_QUEUE: default: - queues_[i] = fst::make_unique>(); + queues_[i] = std::make_unique>(); VLOG(3) << "AutoQueue: SCC #" << i << ": using FIFO discipine"; break; } } - queue_ = fst::make_unique>>( + queue_ = std::make_unique>>( scc_, &queues_); } } diff --git a/src/include/fst/randequivalent.h b/src/include/fst/randequivalent.h index f903302..f5066c3 100644 --- a/src/include/fst/randequivalent.h +++ b/src/include/fst/randequivalent.h @@ -43,7 +43,7 @@ namespace fst { // of the two FSTs the sum of the weights of all the successful paths // sharing the same input and output labels as the considered randomly // generated path and checks that these two values are within a user-specified -// delta. Returns optional error value (when FLAGS_error_fatal = false). +// delta. Returns optional error value (when FST_FLAGS_error_fatal = false). template bool RandEquivalent(const Fst &fst1, const Fst &fst2, int32 npath, const RandGenOptions &opts, diff --git a/src/include/fst/randgen.h b/src/include/fst/randgen.h index 4ebb752..14c4535 100644 --- a/src/include/fst/randgen.h +++ b/src/include/fst/randgen.h @@ -318,10 +318,10 @@ class ArcSampler> { selector_(sampler.selector_), max_length_(sampler.max_length_) { if (fst) { - accumulator_ = fst::make_unique(); + accumulator_ = std::make_unique(); accumulator_->Init(*fst); } else { // Shallow copy. - accumulator_ = fst::make_unique(*sampler.accumulator_); + accumulator_ = std::make_unique(*sampler.accumulator_); } } @@ -646,7 +646,7 @@ template inline void RandGenFst::InitStateIterator( StateIteratorData *data) const { data->base = - fst::make_unique>>( + std::make_unique>>( *this); } diff --git a/src/include/fst/rational.h b/src/include/fst/rational.h index a8c1322..19d2e87 100644 --- a/src/include/fst/rational.h +++ b/src/include/fst/rational.h @@ -241,7 +241,7 @@ class RationalFstImpl : public FstImpl { if (!replace_) { fst_tuples_[0].second = rfst_.Copy(); replace_ = - fst::make_unique>(fst_tuples_, replace_options_); + std::make_unique>(fst_tuples_, replace_options_); } return replace_.get(); } diff --git a/src/include/fst/relabel.h b/src/include/fst/relabel.h index 24fd2fd..5652f78 100644 --- a/src/include/fst/relabel.h +++ b/src/include/fst/relabel.h @@ -21,7 +21,6 @@ #define FST_RELABEL_H_ #include -#include #include #include @@ -469,7 +468,7 @@ class ArcIterator> : public CacheArcIterator> { template inline void RelabelFst::InitStateIterator( StateIteratorData *data) const { - data->base = fst::make_unique>>(*this); + data->base = std::make_unique>>(*this); } // Useful alias when using StdArc. diff --git a/src/include/fst/replace-util.h b/src/include/fst/replace-util.h index ef73ae6..aa03c55 100644 --- a/src/include/fst/replace-util.h +++ b/src/include/fst/replace-util.h @@ -21,8 +21,6 @@ #define FST_REPLACE_UTIL_H_ #include -#include -#include #include #include @@ -34,6 +32,8 @@ #include #include +#include +#include namespace fst { diff --git a/src/include/fst/replace.h b/src/include/fst/replace.h index 4e00b4d..9366bc0 100644 --- a/src/include/fst/replace.h +++ b/src/include/fst/replace.h @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -38,6 +37,8 @@ #include #include +#include + namespace fst { // Replace state tables have the form: @@ -1445,7 +1446,7 @@ template inline void ReplaceFst::InitStateIterator( StateIteratorData *data) const { data->base = - fst::make_unique>>( + std::make_unique>>( *this); } diff --git a/src/include/fst/rmepsilon.h b/src/include/fst/rmepsilon.h index d171a5e..3588e73 100644 --- a/src/include/fst/rmepsilon.h +++ b/src/include/fst/rmepsilon.h @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -40,6 +39,7 @@ #include #include +#include namespace fst { @@ -121,7 +121,7 @@ class RmEpsilonState { }; using ElementMap = std::unordered_map, - ElementHash, ElementEqual>; + ElementHash, ElementEqual>; const Fst &fst_; // Distance from state being expanded in epsilon-closure. @@ -294,7 +294,14 @@ void RmEpsilon(MutableFst *fst, kFstProperties); if (opts.weight_threshold != Weight::Zero() || opts.state_threshold != kNoStateId) { - Prune(fst, opts.weight_threshold, opts.state_threshold); + if constexpr (IsPath::value) { + Prune(fst, opts.weight_threshold, opts.state_threshold); + } else { + FSTERROR() << "RmEpsilon: Weight must have path property: " + << Weight::Type(); + fst->SetProperties(kError, kError); + return; + } } if (opts.connect && opts.weight_threshold == Weight::Zero() && opts.state_threshold == kNoStateId) { @@ -557,7 +564,7 @@ class ArcIterator> template inline void RmEpsilonFst::InitStateIterator( StateIteratorData *data) const { - data->base = fst::make_unique>>(*this); + data->base = std::make_unique>>(*this); } // Useful alias when using StdArc. diff --git a/src/include/fst/rmfinalepsilon.h b/src/include/fst/rmfinalepsilon.h index ca67c96..1c7a71d 100644 --- a/src/include/fst/rmfinalepsilon.h +++ b/src/include/fst/rmfinalepsilon.h @@ -20,7 +20,6 @@ #ifndef FST_RMFINALEPSILON_H_ #define FST_RMFINALEPSILON_H_ -#include #include #include @@ -28,6 +27,7 @@ #include #include +#include namespace fst { diff --git a/src/include/fst/script/compile-impl.h b/src/include/fst/script/compile-impl.h index ed1c18a..4bb2972 100644 --- a/src/include/fst/script/compile-impl.h +++ b/src/include/fst/script/compile-impl.h @@ -30,6 +30,7 @@ #include #include #include +#include DECLARE_string(fst_field_separator); @@ -84,12 +85,12 @@ class FstCompiler { add_symbols_ = add_symbols; bool start_state_populated = false; char line[kLineLen]; - const std::string separator = FLAGS_fst_field_separator + "\n"; + const std::string separator = + FST_FLAGS_fst_field_separator + "\n"; while (istrm.getline(line, kLineLen)) { ++nline_; - std::vector col; - SplitString(line, separator.c_str(), &col, true); - if (col.empty() || col[0][0] == '\0') continue; + std::vector col = SplitString(line, separator, true); + if (col.empty() || col[0].empty()) continue; if (col.size() > 5 || (col.size() > 4 && accep) || (col.size() == 3 && !accep)) { FSTERROR() << "FstCompiler: Bad number of columns, source = " << source_ @@ -151,7 +152,7 @@ class FstCompiler { // Maximum line length in text file. static constexpr int kLineLen = 8096; - StateId StrToId(const char *s, SymbolTable *syms, const char *name, + StateId StrToId(std::string_view s, SymbolTable *syms, const char *name, bool allow_negative = false) const { StateId n = 0; if (syms) { @@ -164,18 +165,18 @@ class FstCompiler { fst_.SetProperties(kError, kError); } } else { - char *p; - n = strtoll(s, &p, 10); - if (*p != '\0' || (!allow_negative && n < 0)) { + auto maybe_n = ParseInt64(s); + if (!maybe_n.has_value() || (!allow_negative && *maybe_n < 0)) { FSTERROR() << "FstCompiler: Bad " << name << " integer = \"" << s << "\", source = " << source_ << ", line = " << nline_; fst_.SetProperties(kError, kError); } + n = *maybe_n; } return n; } - StateId StrToStateId(const char *s) { + StateId StrToStateId(std::string_view s) { StateId n = StrToId(s, ssyms_, "state ID"); if (keep_state_numbering_) return n; // Remaps state IDs to make dense set. @@ -188,17 +189,17 @@ class FstCompiler { } } - StateId StrToILabel(const char *s) const { + StateId StrToILabel(std::string_view s) const { return StrToId(s, isyms_, "arc ilabel", allow_negative_labels_); } - StateId StrToOLabel(const char *s) const { + StateId StrToOLabel(std::string_view s) const { return StrToId(s, osyms_, "arc olabel", allow_negative_labels_); } - Weight StrToWeight(const char *s, bool allow_zero) const { + Weight StrToWeight(std::string_view s, bool allow_zero) const { Weight w; - std::istringstream strm(s); + std::istringstream strm(std::string{s}); strm >> w; if (!strm || (!allow_zero && w == Weight::Zero())) { FSTERROR() << "FstCompiler: Bad weight = \"" << s diff --git a/src/include/fst/script/compile.h b/src/include/fst/script/compile.h index 3e7265d..4f9765c 100644 --- a/src/include/fst/script/compile.h +++ b/src/include/fst/script/compile.h @@ -75,7 +75,7 @@ void CompileFstInternal(CompileFstArgs *args) { } else { fst = fst::WrapUnique(fstcompiler.Fst().Copy()); } - args->retval = fst ? fst::make_unique(std::move(fst)) : nullptr; + args->retval = fst ? std::make_unique(std::move(fst)) : nullptr; } void CompileFst(std::istream &istrm, const std::string &source, diff --git a/src/include/fst/script/convert.h b/src/include/fst/script/convert.h index af03215..c132cb6 100644 --- a/src/include/fst/script/convert.h +++ b/src/include/fst/script/convert.h @@ -40,7 +40,7 @@ void Convert(ConvertArgs *args) { const std::string &new_type = std::get<1>(args->args); std::unique_ptr> result(Convert(fst, new_type)); args->retval = - result ? fst::make_unique(std::move(result)) : nullptr; + result ? std::make_unique(std::move(result)) : nullptr; } std::unique_ptr Convert(const FstClass &fst, diff --git a/src/include/fst/script/fst-class.h b/src/include/fst/script/fst-class.h index 505fa2d..e5a14a8 100644 --- a/src/include/fst/script/fst-class.h +++ b/src/include/fst/script/fst-class.h @@ -301,11 +301,11 @@ class FstClass : public FstClassBase { template explicit FstClass(std::unique_ptr> fst) - : impl_(fst::make_unique>(std::move(fst))) {} + : impl_(std::make_unique>(std::move(fst))) {} template explicit FstClass(const Fst &fst) - : impl_(fst::make_unique>(fst)) {} + : impl_(std::make_unique>(fst)) {} FstClass(const FstClass &other) : impl_(other.impl_ == nullptr ? nullptr : other.impl_->Copy()) {} @@ -567,12 +567,12 @@ class VectorFstClass : public MutableFstClass { template static FstClassImplBase *Convert(const FstClass &other) { return new FstClassImpl( - fst::make_unique>(*other.GetFst())); + std::make_unique>(*other.GetFst())); } template static FstClassImplBase *Create() { - return new FstClassImpl(fst::make_unique>()); + return new FstClassImpl(std::make_unique>()); } }; diff --git a/src/include/fst/script/map.h b/src/include/fst/script/map.h index 718a7f2..310092f 100644 --- a/src/include/fst/script/map.h +++ b/src/include/fst/script/map.h @@ -35,7 +35,7 @@ template std::unique_ptr> ArcMap( const Fst &fst, const M &mapper) { using ToArc = typename M::ToArc; - auto ofst = fst::make_unique>(); + auto ofst = std::make_unique>(); ArcMap(fst, ofst.get(), mapper); return ofst; } @@ -44,7 +44,7 @@ template std::unique_ptr> StateMap( const Fst &fst, const M &mapper) { using ToArc = typename M::ToArc; - auto ofst = fst::make_unique>(); + auto ofst = std::make_unique>(); StateMap(fst, ofst.get(), mapper); return ofst; } @@ -80,81 +80,81 @@ void Map(MapArgs *args) { switch (map_type) { case MapType::ARC_SUM: { auto ofst = StateMap(ifst, ArcSumMapper(ifst)); - args->retval = fst::make_unique(std::move(ofst)); + args->retval = std::make_unique(std::move(ofst)); return; } case MapType::ARC_UNIQUE: { auto ofst = StateMap(ifst, ArcUniqueMapper(ifst)); - args->retval = fst::make_unique(std::move(ofst)); + args->retval = std::make_unique(std::move(ofst)); return; } case MapType::IDENTITY: { auto ofst = ArcMap(ifst, IdentityArcMapper()); - args->retval = fst::make_unique(std::move(ofst)); + args->retval = std::make_unique(std::move(ofst)); return; } case MapType::INPUT_EPSILON: { auto ofst = ArcMap(ifst, InputEpsilonMapper()); - args->retval = fst::make_unique(std::move(ofst)); + args->retval = std::make_unique(std::move(ofst)); return; } case MapType::INVERT: { auto ofst = ArcMap(ifst, InvertWeightMapper()); - args->retval = fst::make_unique(std::move(ofst)); + args->retval = std::make_unique(std::move(ofst)); return; } case MapType::OUTPUT_EPSILON: { auto ofst = ArcMap(ifst, OutputEpsilonMapper()); - args->retval = fst::make_unique(std::move(ofst)); + args->retval = std::make_unique(std::move(ofst)); return; } case MapType::PLUS: { const auto weight = *std::get<4>(args->args).GetWeight(); auto ofst = ArcMap(ifst, PlusMapper(weight)); - args->retval = fst::make_unique(std::move(ofst)); + args->retval = std::make_unique(std::move(ofst)); return; } case MapType::POWER: { const auto power = std::get<3>(args->args); auto ofst = ArcMap(ifst, PowerMapper(power)); - args->retval = fst::make_unique(std::move(ofst)); + args->retval = std::make_unique(std::move(ofst)); return; } case MapType::QUANTIZE: { const auto delta = std::get<2>(args->args); auto ofst = ArcMap(ifst, QuantizeMapper(delta)); - args->retval = fst::make_unique(std::move(ofst)); + args->retval = std::make_unique(std::move(ofst)); return; } case MapType::RMWEIGHT: { auto ofst = ArcMap(ifst, RmWeightMapper()); - args->retval = fst::make_unique(std::move(ofst)); + args->retval = std::make_unique(std::move(ofst)); return; } case MapType::SUPERFINAL: { auto ofst = ArcMap(ifst, SuperFinalMapper()); - args->retval = fst::make_unique(std::move(ofst)); + args->retval = std::make_unique(std::move(ofst)); return; } case MapType::TIMES: { const auto weight = *std::get<4>(args->args).GetWeight(); auto ofst = ArcMap(ifst, TimesMapper(weight)); - args->retval = fst::make_unique(std::move(ofst)); + args->retval = std::make_unique(std::move(ofst)); return; } case MapType::TO_LOG: { auto ofst = ArcMap(ifst, WeightConvertMapper()); - args->retval = fst::make_unique(std::move(ofst)); + args->retval = std::make_unique(std::move(ofst)); return; } case MapType::TO_LOG64: { auto ofst = ArcMap(ifst, WeightConvertMapper()); - args->retval = fst::make_unique(std::move(ofst)); + args->retval = std::make_unique(std::move(ofst)); return; } case MapType::TO_STD: { auto ofst = ArcMap(ifst, WeightConvertMapper()); - args->retval = fst::make_unique(std::move(ofst)); + args->retval = std::make_unique(std::move(ofst)); return; } } diff --git a/src/include/fst/script/print.h b/src/include/fst/script/print.h index 7c71379..0366553 100644 --- a/src/include/fst/script/print.h +++ b/src/include/fst/script/print.h @@ -73,7 +73,7 @@ void PrintFst(const Fst &fst, std::ostream &ostrm, const std::string &dest = "", const SymbolTable *isyms = nullptr, const SymbolTable *osyms = nullptr, const SymbolTable *ssyms = nullptr) { - const std::string sep = FLAGS_fst_field_separator.substr(0, 1); + const std::string sep = FST_FLAGS_fst_field_separator.substr(0, 1); FstPrinter fstprinter(fst, isyms, osyms, ssyms, true, true, sep); fstprinter.Print(ostrm, dest); } diff --git a/src/include/fst/script/prune.h b/src/include/fst/script/prune.h index 859a6e7..33e0958 100644 --- a/src/include/fst/script/prune.h +++ b/src/include/fst/script/prune.h @@ -36,8 +36,13 @@ void Prune(PruneArgs1 *args) { using Weight = typename Arc::Weight; const Fst &ifst = *std::get<0>(*args).GetFst(); MutableFst *ofst = std::get<1>(*args)->GetMutableFst(); - const auto weight_threshold = *std::get<2>(*args).GetWeight(); - Prune(ifst, ofst, weight_threshold, std::get<3>(*args), std::get<4>(*args)); + if constexpr (IsPath::value) { + const auto weight_threshold = *std::get<2>(*args).GetWeight(); + Prune(ifst, ofst, weight_threshold, std::get<3>(*args), std::get<4>(*args)); + } else { + FSTERROR() << "Prune: Weight must have path property: " << Weight::Type(); + ofst->SetProperties(kError, kError); + } } using PruneArgs2 = @@ -47,8 +52,13 @@ template void Prune(PruneArgs2 *args) { using Weight = typename Arc::Weight; MutableFst *fst = std::get<0>(*args)->GetMutableFst(); - const auto weight_threshold = *std::get<1>(*args).GetWeight(); - Prune(fst, weight_threshold, std::get<2>(*args), std::get<3>(*args)); + if constexpr (IsPath::value) { + const auto weight_threshold = *std::get<1>(*args).GetWeight(); + Prune(fst, weight_threshold, std::get<2>(*args), std::get<3>(*args)); + } else { + FSTERROR() << "Prune: Weight must have path property: " << Weight::Type(); + fst->SetProperties(kError, kError); + } } void Prune(const FstClass &ifst, MutableFstClass *ofst, diff --git a/src/include/fst/script/shortest-path.h b/src/include/fst/script/shortest-path.h index 18f2bea..0220068 100644 --- a/src/include/fst/script/shortest-path.h +++ b/src/include/fst/script/shortest-path.h @@ -59,13 +59,19 @@ void ShortestPath(const Fst &ifst, MutableFst *ofst, const ShortestPathOptions &opts) { using ArcFilter = AnyArcFilter; using Weight = typename Arc::Weight; - const std::unique_ptr queue( - QueueConstructor::Construct(ifst, distance)); - const fst::ShortestPathOptions sopts( - queue.get(), ArcFilter(), opts.nshortest, opts.unique, - /* has_distance=*/false, opts.delta, /* first_path=*/false, - *opts.weight_threshold.GetWeight(), opts.state_threshold); - ShortestPath(ifst, ofst, distance, sopts); + if constexpr (IsPath::value) { + const std::unique_ptr queue( + QueueConstructor::Construct(ifst, distance)); + const fst::ShortestPathOptions sopts( + queue.get(), ArcFilter(), opts.nshortest, opts.unique, + /* has_distance=*/false, opts.delta, /* first_path=*/false, + *opts.weight_threshold.GetWeight(), opts.state_threshold); + ShortestPath(ifst, ofst, distance, sopts); + } else { + FSTERROR() << "ShortestPath: Weight needs to have the path property: " + << Arc::Weight::Type(); + ofst->SetProperties(kError, kError); + } } template diff --git a/src/include/fst/script/weight-class.h b/src/include/fst/script/weight-class.h index ec5d64b..0dfc9f6 100644 --- a/src/include/fst/script/weight-class.h +++ b/src/include/fst/script/weight-class.h @@ -29,6 +29,7 @@ #include #include #include +#include namespace fst { namespace script { @@ -120,7 +121,7 @@ class WeightClass { explicit WeightClass(const WeightClassImpl &impl) : impl_(new WeightClassImpl(impl)) {} - WeightClass(const std::string &weight_type, const std::string &weight_str); + WeightClass(const std::string &weight_type, std::string_view weight_str); WeightClass(const WeightClass &other) : impl_(other.impl_ ? other.impl_->Copy() : nullptr) {} @@ -199,10 +200,10 @@ std::ostream &operator<<(std::ostream &o, const WeightClass &c); // Registration for generic weight types. -using StrToWeightImplBaseT = WeightImplBase *(*)(const std::string &str); +using StrToWeightImplBaseT = WeightImplBase *(*)(std::string_view str); template -WeightImplBase *StrToWeightImplBase(const std::string &str) { +WeightImplBase *StrToWeightImplBase(std::string_view str) { if (str == WeightClass::__ZERO__) { return new WeightClassImpl(W::Zero()); } else if (str == WeightClass::__ONE__) { diff --git a/src/include/fst/set-weight.h b/src/include/fst/set-weight.h index 3713bcc..671e414 100644 --- a/src/include/fst/set-weight.h +++ b/src/include/fst/set-weight.h @@ -32,14 +32,15 @@ #include #include +#include namespace fst { -constexpr int kSetEmpty = 0; // Label for the empty set. -constexpr int kSetUniv = -1; // Label for the universal set. -constexpr int kSetBad = -2; // Label for a non-set. -constexpr char kSetSeparator = '_'; // Label separator in sets. +constexpr int kSetEmpty = 0; // Label for the empty set. +constexpr int kSetUniv = -1; // Label for the universal set. +constexpr int kSetBad = -2; // Label for a non-set. +constexpr char kSetSeparator[] = "_"; // Label separator in sets. // Determines whether to use (intersect, union) or (union, intersect) // as (+, *) for the semiring. SET_INTERSECT_UNION_RESTRICTED is a @@ -365,14 +366,13 @@ inline std::istream &operator>>(std::istream &strm, weight = Weight(Label(kSetUniv)); } else { weight.Clear(); - char *p = nullptr; - for (const char *cs = str.c_str(); !p || *p != '\0'; cs = p + 1) { - const Label label = strtoll(cs, &p, 10); - if (p == cs || (*p != 0 && *p != kSetSeparator)) { + for (std::string_view sv : SplitString(str, kSetSeparator, false)) { + auto maybe_label = ParseInt64(sv); + if (!maybe_label.has_value()) { strm.clear(std::ios::badbit); break; } - weight.PushBack(label); + weight.PushBack(*maybe_label); } } return strm; diff --git a/src/include/fst/shortest-path.h b/src/include/fst/shortest-path.h index a9a57f8..9f7a5ed 100644 --- a/src/include/fst/shortest-path.h +++ b/src/include/fst/shortest-path.h @@ -461,15 +461,17 @@ void NShortestPath(const Fst &ifst, MutableFst *ofst, // // The algorithm relies on the shortest-distance algorithm. There are some // issues with the pseudo-code as written in the paper (viz., line 11). -template ::value>::type * = - nullptr> +template void ShortestPath(const Fst &ifst, MutableFst *ofst, std::vector *distance, const ShortestPathOptions &opts) { using StateId = typename Arc::StateId; using Weight = typename Arc::Weight; using RevArc = ReverseArc; + static_assert(IsPath::value, + "ShortestPath: Weight needs to have the path property and " + "be distributive"); + if (opts.nshortest == 1) { std::vector> parent; StateId f_parent; @@ -519,17 +521,6 @@ void ShortestPath(const Fst &ifst, MutableFst *ofst, distance->erase(distance->begin()); } -template ::value>::type - * = nullptr> -void ShortestPath(const Fst &, MutableFst *ofst, - std::vector *, - const ShortestPathOptions &) { - FSTERROR() << "ShortestPath: Weight needs to have the " - << "path property and be distributive: " << Arc::Weight::Type(); - ofst->SetProperties(kError, kError); -} - // Shortest-path algorithm: simplified interface. See above for a version that // allows finer control. The output mutable FST contains the n-shortest paths // in the input FST. The queue discipline is automatically selected. When unique diff --git a/src/include/fst/sparse-tuple-weight.h b/src/include/fst/sparse-tuple-weight.h index be5d3fb..79446c9 100644 --- a/src/include/fst/sparse-tuple-weight.h +++ b/src/include/fst/sparse-tuple-weight.h @@ -32,7 +32,6 @@ #include #include #include -#include #include diff --git a/src/include/fst/state-map.h b/src/include/fst/state-map.h index 3d67854..5dc6cff 100644 --- a/src/include/fst/state-map.h +++ b/src/include/fst/state-map.h @@ -276,7 +276,7 @@ class StateMapFstImpl : public CacheImpl { void InitStateIterator(StateIteratorData *datb) const { StateIteratorData data; fst_->InitStateIterator(&data); - datb->base = data.base ? fst::make_unique>( + datb->base = data.base ? std::make_unique>( std::move(data.base)) : nullptr; datb->nstates = data.nstates; @@ -422,7 +422,7 @@ class IdentityStateMapper { Weight Final(StateId state) const { return fst_.Final(state); } void SetState(StateId state) { - aiter_ = fst::make_unique>>(fst_, state); + aiter_ = std::make_unique>>(fst_, state); } bool Done() const { return aiter_->Done(); } diff --git a/src/include/fst/string-weight.h b/src/include/fst/string-weight.h index 8b86855..114aa67 100644 --- a/src/include/fst/string-weight.h +++ b/src/include/fst/string-weight.h @@ -30,13 +30,14 @@ #include #include #include +#include namespace fst { -constexpr int kStringInfinity = -1; // Label for the infinite string. -constexpr int kStringBad = -2; // Label for a non-string. -constexpr char kStringSeparator = '_'; // Label separator in strings. +constexpr int kStringInfinity = -1; // Label for the infinite string. +constexpr int kStringBad = -2; // Label for a non-string. +constexpr char kStringSeparator[] = "_"; // Label separator in strings. // Determines whether to use left or right string semiring. Includes a // 'restricted' version that signals an error if proper prefixes/suffixes @@ -335,14 +336,13 @@ inline std::istream &operator>>(std::istream &strm, weight = Weight::One(); } else { weight.Clear(); - char *p = nullptr; - for (const char *cs = str.c_str(); !p || *p != '\0'; cs = p + 1) { - const Label label = strtoll(cs, &p, 10); - if (p == cs || (*p != 0 && *p != kStringSeparator)) { + for (std::string_view sv : SplitString(str, kStringSeparator, false)) { + auto maybe_label = ParseInt64(sv); + if (!maybe_label.has_value()) { strm.clear(std::ios::badbit); break; } - weight.PushBack(label); + weight.PushBack(*maybe_label); } } return strm; diff --git a/src/include/fst/string.h b/src/include/fst/string.h index 54f3d4f..738834e 100644 --- a/src/include/fst/string.h +++ b/src/include/fst/string.h @@ -37,6 +37,8 @@ #include #include +#include + DECLARE_string(fst_field_separator); namespace fst { @@ -56,17 +58,10 @@ inline std::ostream &operator<<(std::ostream &strm, return strm; // unreachable } -OPENFST_DEPRECATED("Use `TokenType::SYMBOL` instead.") -static constexpr TokenType SYMBOL = TokenType::SYMBOL; -OPENFST_DEPRECATED("Use `TokenType::BYTE` instead.") -static constexpr TokenType BYTE = TokenType::BYTE; -OPENFST_DEPRECATED("Use `TokenType::UTF8` instead.") -static constexpr TokenType UTF8 = TokenType::UTF8; - namespace internal { template -bool ConvertSymbolToLabel(const char *str, const SymbolTable *syms, +bool ConvertSymbolToLabel(std::string_view str, const SymbolTable *syms, Label unknown_label, bool allow_negative, Label *output) { int64 n; @@ -80,13 +75,13 @@ bool ConvertSymbolToLabel(const char *str, const SymbolTable *syms, return false; } } else { - char *p; - n = strtoll(str, &p, 10); - if (*p != '\0' || (!allow_negative && n < 0)) { + const auto maybe_n = ParseInt64(str); + if (!maybe_n.has_value() || (!allow_negative && *maybe_n < 0)) { LOG(ERROR) << "ConvertSymbolToLabel: Bad label integer " << "= \"" << str << "\""; return false; } + n = *maybe_n; } *output = n; return true; @@ -96,7 +91,8 @@ template bool ConvertStringToLabels(const std::string &str, TokenType token_type, const SymbolTable *syms, Label unknown_label, bool allow_negative, std::vector