diff --git a/build/target.cmake b/build/target.cmake index b00ba2f50..d70a2d0fb 100644 --- a/build/target.cmake +++ b/build/target.cmake @@ -25,7 +25,7 @@ ENDIF() # Default options per compiler IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR ${COMPILER_CLANG_CL}) - SET (WALRUS_CXXFLAGS /std:c++17 /fp:strict /Zc:__cplusplus /EHs /source-charset:utf-8 /D_CRT_SECURE_NO_WARNINGS /D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING /wd4244 /wd4267 /wd4805 /wd4018 /wd4172) + SET (WALRUS_CXXFLAGS /std:c++11 /fp:strict /Zc:__cplusplus /EHs /source-charset:utf-8 /D_CRT_SECURE_NO_WARNINGS /D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING /wd4244 /wd4267 /wd4805 /wd4018 /wd4172) SET (WALRUS_CXXFLAGS_RELEASE /O2 /Oy-) SET (WALRUS_THIRDPARTY_CFLAGS /D_CRT_SECURE_NO_WARNINGS /Oy- /wd4146 /EHs) IF (${COMPILER_CLANG_CL}) @@ -41,7 +41,7 @@ IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR ${COMPILER_CLANG_CL}) SET (WALRUS_CXXFLAGS_SHAREDLIB) SET (WALRUS_LDFLAGS_SHAREDLIB) SET (WALRUS_CXXFLAGS_STATICLIB /DWASM_API_EXTERN) - SET (WALRUS_CXXFLAGS_SHELL /DWASM_API_EXTERN /std:c++17) + SET (WALRUS_CXXFLAGS_SHELL /DWASM_API_EXTERN /std:c++11) ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} @@ -73,7 +73,7 @@ ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") SET (WALRUS_CXXFLAGS_SHAREDLIB -fPIC) SET (WALRUS_LDFLAGS_SHAREDLIB -ldl) SET (WALRUS_CXXFLAGS_STATICLIB -fPIC -DWASM_API_EXTERN=) - SET (WALRUS_CXXFLAGS_SHELL -DWASM_API_EXTERN= -frtti -std=c++17) + SET (WALRUS_CXXFLAGS_SHELL -DWASM_API_EXTERN= -frtti -std=c++11) ELSEIF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # Clang and AppleClang SET (WALRUS_CXXFLAGS @@ -103,7 +103,7 @@ ELSEIF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # Clang and AppleClang SET (WALRUS_CXXFLAGS_SHAREDLIB -fPIC) SET (WALRUS_LDFLAGS_SHAREDLIB -ldl) SET (WALRUS_CXXFLAGS_STATICLIB -fPIC -DWASM_API_EXTERN=) - SET (WALRUS_CXXFLAGS_SHELL -DWASM_API_EXTERN= -frtti -std=c++17) + SET (WALRUS_CXXFLAGS_SHELL -DWASM_API_EXTERN= -frtti -std=c++11) ELSE() MESSAGE (FATAL_ERROR ${CMAKE_CXX_COMPILER_ID} " is Unsupported Compiler") ENDIF() diff --git a/src/shell/Shell.cpp b/src/shell/Shell.cpp index 97c6ea1ba..245b7d777 100644 --- a/src/shell/Shell.cpp +++ b/src/shell/Shell.cpp @@ -832,7 +832,7 @@ static void runExports(Store* store, const std::string& filename, const std::vec static void parseArguments(int argc, char* argv[], ArgParser& argParser) { - const std::vector args(argv + 1, argv + argc); + const std::vector args(argv + 1, argv + argc); for (auto it = args.begin(); it != args.end(); ++it) { if (*it == "--run-export") { @@ -842,12 +842,15 @@ static void parseArguments(int argc, char* argv[], ArgParser& argParser) } std::advance(it, 1); - argParser.exportToRun = *it; - } else if (auto arg = std::string(*it); endsWith(arg, "wat") || endsWith(arg, "wast") || endsWith(arg, "wasm")) { - argParser.fileNames.emplace_back(*it); + argParser.exportToRun = nonstd::to_string(*it); } else { - fprintf(stderr, "error: unknown argument: %s\n", it->data()); - exit(1); + auto arg = nonstd::to_string(*it); + if (endsWith(arg, "wat") || endsWith(arg, "wast") || endsWith(arg, "wasm")) { + argParser.fileNames.emplace_back(*it); + } else { + fprintf(stderr, "error: unknown argument: %s\n", it->data()); + exit(1); + } } } diff --git a/third_party/wabt/CMakeLists.txt b/third_party/wabt/CMakeLists.txt index ceca07e8b..e522d07e9 100644 --- a/third_party/wabt/CMakeLists.txt +++ b/third_party/wabt/CMakeLists.txt @@ -18,7 +18,7 @@ cmake_minimum_required(VERSION 3.1.0) project(WABT LANGUAGES C CXX VERSION 1.0.30) include(GNUInstallDirs) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/third_party/wabt/include/string_view.h b/third_party/wabt/include/string_view.h new file mode 100644 index 000000000..809a5a4f2 --- /dev/null +++ b/third_party/wabt/include/string_view.h @@ -0,0 +1,1684 @@ +// Copyright 2017-2020 by Martin Moene +// +// string-view lite, a C++17-like string_view for C++98 and later. +// For more information see https://github.com/martinmoene/string-view-lite +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#pragma once + +#ifndef NONSTD_SV_LITE_H_INCLUDED +#define NONSTD_SV_LITE_H_INCLUDED + +#define string_view_lite_MAJOR 1 +#define string_view_lite_MINOR 7 +#define string_view_lite_PATCH 0 + +#define string_view_lite_VERSION nssv_STRINGIFY(string_view_lite_MAJOR) "." nssv_STRINGIFY(string_view_lite_MINOR) "." nssv_STRINGIFY(string_view_lite_PATCH) + +#define nssv_STRINGIFY( x ) nssv_STRINGIFY_( x ) +#define nssv_STRINGIFY_( x ) #x + +// string-view lite configuration: + +#define nssv_STRING_VIEW_DEFAULT 0 +#define nssv_STRING_VIEW_NONSTD 1 +#define nssv_STRING_VIEW_STD 2 + +// tweak header support: + +#ifdef __has_include +# if __has_include() +# include +# endif +#define nssv_HAVE_TWEAK_HEADER 1 +#else +#define nssv_HAVE_TWEAK_HEADER 0 +//# pragma message("string_view.hpp: Note: Tweak header not supported.") +#endif + +// string_view selection and configuration: + +#if !defined( nssv_CONFIG_SELECT_STRING_VIEW ) +# define nssv_CONFIG_SELECT_STRING_VIEW ( nssv_HAVE_STD_STRING_VIEW ? nssv_STRING_VIEW_STD : nssv_STRING_VIEW_NONSTD ) +#endif + +#ifndef nssv_CONFIG_STD_SV_OPERATOR +# define nssv_CONFIG_STD_SV_OPERATOR 0 +#endif + +#ifndef nssv_CONFIG_USR_SV_OPERATOR +# define nssv_CONFIG_USR_SV_OPERATOR 1 +#endif + +#ifdef nssv_CONFIG_CONVERSION_STD_STRING +# define nssv_CONFIG_CONVERSION_STD_STRING_CLASS_METHODS nssv_CONFIG_CONVERSION_STD_STRING +# define nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS nssv_CONFIG_CONVERSION_STD_STRING +#endif + +#ifndef nssv_CONFIG_CONVERSION_STD_STRING_CLASS_METHODS +# define nssv_CONFIG_CONVERSION_STD_STRING_CLASS_METHODS 1 +#endif + +#ifndef nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS +# define nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS 1 +#endif + +#ifndef nssv_CONFIG_NO_STREAM_INSERTION +# define nssv_CONFIG_NO_STREAM_INSERTION 0 +#endif + +// Control presence of exception handling (try and auto discover): + +#ifndef nssv_CONFIG_NO_EXCEPTIONS +# if defined(_MSC_VER) +# include // for _HAS_EXCEPTIONS +# endif +# if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || (_HAS_EXCEPTIONS) +# define nssv_CONFIG_NO_EXCEPTIONS 0 +# else +# define nssv_CONFIG_NO_EXCEPTIONS 1 +# endif +#endif + +// C++ language version detection (C++23 is speculative): +// Note: VC14.0/1900 (VS2015) lacks too much from C++14. + +#ifndef nssv_CPLUSPLUS +# if defined(_MSVC_LANG ) && !defined(__clang__) +# define nssv_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG ) +# else +# define nssv_CPLUSPLUS __cplusplus +# endif +#endif + +#define nssv_CPP98_OR_GREATER ( nssv_CPLUSPLUS >= 199711L ) +#define nssv_CPP11_OR_GREATER ( nssv_CPLUSPLUS >= 201103L ) +#define nssv_CPP11_OR_GREATER_ ( nssv_CPLUSPLUS >= 201103L ) +#define nssv_CPP14_OR_GREATER ( nssv_CPLUSPLUS >= 201402L ) +#define nssv_CPP17_OR_GREATER ( nssv_CPLUSPLUS >= 201703L ) +#define nssv_CPP20_OR_GREATER ( nssv_CPLUSPLUS >= 202002L ) +#define nssv_CPP23_OR_GREATER ( nssv_CPLUSPLUS >= 202300L ) + +// use C++17 std::string_view if available and requested: + +#if nssv_CPP17_OR_GREATER && defined(__has_include ) +# if __has_include( ) +# define nssv_HAVE_STD_STRING_VIEW 1 +# else +# define nssv_HAVE_STD_STRING_VIEW 0 +# endif +#else +# define nssv_HAVE_STD_STRING_VIEW 0 +#endif + +#define nssv_USES_STD_STRING_VIEW ( (nssv_CONFIG_SELECT_STRING_VIEW == nssv_STRING_VIEW_STD) || ((nssv_CONFIG_SELECT_STRING_VIEW == nssv_STRING_VIEW_DEFAULT) && nssv_HAVE_STD_STRING_VIEW) ) + +#define nssv_HAVE_STARTS_WITH ( nssv_CPP20_OR_GREATER || !nssv_USES_STD_STRING_VIEW ) +#define nssv_HAVE_ENDS_WITH nssv_HAVE_STARTS_WITH + +// +// Use C++17 std::string_view: +// + +#if nssv_USES_STD_STRING_VIEW + +#include + +// Extensions for std::string: + +#if nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS + +namespace nonstd { + +template< class CharT, class Traits, class Allocator = std::allocator > +std::basic_string +to_string( std::basic_string_view v, Allocator const & a = Allocator() ) +{ + return std::basic_string( v.begin(), v.end(), a ); +} + +template< class CharT, class Traits, class Allocator > +std::basic_string_view +to_string_view( std::basic_string const & s ) +{ + return std::basic_string_view( s.data(), s.size() ); +} + +// Literal operators sv and _sv: + +#if nssv_CONFIG_STD_SV_OPERATOR + +using namespace std::literals::string_view_literals; + +#endif + +#if nssv_CONFIG_USR_SV_OPERATOR + +inline namespace literals { +inline namespace string_view_literals { + + +constexpr std::string_view operator "" _sv( const char* str, size_t len ) noexcept // (1) +{ + return std::string_view{ str, len }; +} + +constexpr std::u16string_view operator "" _sv( const char16_t* str, size_t len ) noexcept // (2) +{ + return std::u16string_view{ str, len }; +} + +constexpr std::u32string_view operator "" _sv( const char32_t* str, size_t len ) noexcept // (3) +{ + return std::u32string_view{ str, len }; +} + +constexpr std::wstring_view operator "" _sv( const wchar_t* str, size_t len ) noexcept // (4) +{ + return std::wstring_view{ str, len }; +} + +}} // namespace literals::string_view_literals + +#endif // nssv_CONFIG_USR_SV_OPERATOR + +} // namespace nonstd + +#endif // nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS + +namespace nonstd { + +using std::string_view; +using std::wstring_view; +using std::u16string_view; +using std::u32string_view; +using std::basic_string_view; + +// literal "sv" and "_sv", see above + +using std::operator==; +using std::operator!=; +using std::operator<; +using std::operator<=; +using std::operator>; +using std::operator>=; + +using std::operator<<; + +} // namespace nonstd + +#else // nssv_HAVE_STD_STRING_VIEW + +// +// Before C++17: use string_view lite: +// + +// Compiler versions: +// +// MSVC++ 6.0 _MSC_VER == 1200 nssv_COMPILER_MSVC_VERSION == 60 (Visual Studio 6.0) +// MSVC++ 7.0 _MSC_VER == 1300 nssv_COMPILER_MSVC_VERSION == 70 (Visual Studio .NET 2002) +// MSVC++ 7.1 _MSC_VER == 1310 nssv_COMPILER_MSVC_VERSION == 71 (Visual Studio .NET 2003) +// MSVC++ 8.0 _MSC_VER == 1400 nssv_COMPILER_MSVC_VERSION == 80 (Visual Studio 2005) +// MSVC++ 9.0 _MSC_VER == 1500 nssv_COMPILER_MSVC_VERSION == 90 (Visual Studio 2008) +// MSVC++ 10.0 _MSC_VER == 1600 nssv_COMPILER_MSVC_VERSION == 100 (Visual Studio 2010) +// MSVC++ 11.0 _MSC_VER == 1700 nssv_COMPILER_MSVC_VERSION == 110 (Visual Studio 2012) +// MSVC++ 12.0 _MSC_VER == 1800 nssv_COMPILER_MSVC_VERSION == 120 (Visual Studio 2013) +// MSVC++ 14.0 _MSC_VER == 1900 nssv_COMPILER_MSVC_VERSION == 140 (Visual Studio 2015) +// MSVC++ 14.1 _MSC_VER >= 1910 nssv_COMPILER_MSVC_VERSION == 141 (Visual Studio 2017) +// MSVC++ 14.2 _MSC_VER >= 1920 nssv_COMPILER_MSVC_VERSION == 142 (Visual Studio 2019) + +#if defined(_MSC_VER ) && !defined(__clang__) +# define nssv_COMPILER_MSVC_VER (_MSC_VER ) +# define nssv_COMPILER_MSVC_VERSION (_MSC_VER / 10 - 10 * ( 5 + (_MSC_VER < 1900 ) ) ) +#else +# define nssv_COMPILER_MSVC_VER 0 +# define nssv_COMPILER_MSVC_VERSION 0 +#endif + +#define nssv_COMPILER_VERSION( major, minor, patch ) ( 10 * ( 10 * (major) + (minor) ) + (patch) ) + +#if defined( __apple_build_version__ ) +# define nssv_COMPILER_APPLECLANG_VERSION nssv_COMPILER_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__) +# define nssv_COMPILER_CLANG_VERSION 0 +#elif defined( __clang__ ) +# define nssv_COMPILER_APPLECLANG_VERSION 0 +# define nssv_COMPILER_CLANG_VERSION nssv_COMPILER_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__) +#else +# define nssv_COMPILER_APPLECLANG_VERSION 0 +# define nssv_COMPILER_CLANG_VERSION 0 +#endif + +#if defined(__GNUC__) && !defined(__clang__) +# define nssv_COMPILER_GNUC_VERSION nssv_COMPILER_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) +#else +# define nssv_COMPILER_GNUC_VERSION 0 +#endif + +// half-open range [lo..hi): +#define nssv_BETWEEN( v, lo, hi ) ( (lo) <= (v) && (v) < (hi) ) + +// Presence of language and library features: + +#ifdef _HAS_CPP0X +# define nssv_HAS_CPP0X _HAS_CPP0X +#else +# define nssv_HAS_CPP0X 0 +#endif + +// Unless defined otherwise below, consider VC14 as C++11 for variant-lite: + +#if nssv_COMPILER_MSVC_VER >= 1900 +# undef nssv_CPP11_OR_GREATER +# define nssv_CPP11_OR_GREATER 1 +#endif + +#define nssv_CPP11_90 (nssv_CPP11_OR_GREATER_ || nssv_COMPILER_MSVC_VER >= 1500) +#define nssv_CPP11_100 (nssv_CPP11_OR_GREATER_ || nssv_COMPILER_MSVC_VER >= 1600) +#define nssv_CPP11_110 (nssv_CPP11_OR_GREATER_ || nssv_COMPILER_MSVC_VER >= 1700) +#define nssv_CPP11_120 (nssv_CPP11_OR_GREATER_ || nssv_COMPILER_MSVC_VER >= 1800) +#define nssv_CPP11_140 (nssv_CPP11_OR_GREATER_ || nssv_COMPILER_MSVC_VER >= 1900) +#define nssv_CPP11_141 (nssv_CPP11_OR_GREATER_ || nssv_COMPILER_MSVC_VER >= 1910) + +#define nssv_CPP14_000 (nssv_CPP14_OR_GREATER) +#define nssv_CPP17_000 (nssv_CPP17_OR_GREATER) + +// Presence of C++11 language features: + +#define nssv_HAVE_CONSTEXPR_11 nssv_CPP11_140 +#define nssv_HAVE_EXPLICIT_CONVERSION nssv_CPP11_140 +#define nssv_HAVE_INLINE_NAMESPACE nssv_CPP11_140 +#define nssv_HAVE_IS_DEFAULT nssv_CPP11_140 +#define nssv_HAVE_IS_DELETE nssv_CPP11_140 +#define nssv_HAVE_NOEXCEPT nssv_CPP11_140 +#define nssv_HAVE_NULLPTR nssv_CPP11_100 +#define nssv_HAVE_REF_QUALIFIER nssv_CPP11_140 +#define nssv_HAVE_UNICODE_LITERALS nssv_CPP11_140 +#define nssv_HAVE_USER_DEFINED_LITERALS nssv_CPP11_140 +#define nssv_HAVE_WCHAR16_T nssv_CPP11_100 +#define nssv_HAVE_WCHAR32_T nssv_CPP11_100 + +#if ! ( ( nssv_CPP11_OR_GREATER && nssv_COMPILER_CLANG_VERSION ) || nssv_BETWEEN( nssv_COMPILER_CLANG_VERSION, 300, 400 ) ) +# define nssv_HAVE_STD_DEFINED_LITERALS nssv_CPP11_140 +#else +# define nssv_HAVE_STD_DEFINED_LITERALS 0 +#endif + +// Presence of C++14 language features: + +#define nssv_HAVE_CONSTEXPR_14 nssv_CPP14_000 + +// Presence of C++17 language features: + +#define nssv_HAVE_NODISCARD nssv_CPP17_000 + +// Presence of C++ library features: + +#define nssv_HAVE_STD_HASH nssv_CPP11_120 + +// Presence of compiler intrinsics: + +// Providing char-type specializations for compare() and length() that +// use compiler intrinsics can improve compile- and run-time performance. +// +// The challenge is in using the right combinations of builtin availability +// and its constexpr-ness. +// +// | compiler | __builtin_memcmp (constexpr) | memcmp (constexpr) | +// |----------|------------------------------|---------------------| +// | clang | 4.0 (>= 4.0 ) | any (? ) | +// | clang-a | 9.0 (>= 9.0 ) | any (? ) | +// | gcc | any (constexpr) | any (? ) | +// | msvc | >= 14.2 C++17 (>= 14.2 ) | any (? ) | + +#define nssv_HAVE_BUILTIN_VER ( (nssv_CPP17_000 && nssv_COMPILER_MSVC_VERSION >= 142) || nssv_COMPILER_GNUC_VERSION > 0 || nssv_COMPILER_CLANG_VERSION >= 400 || nssv_COMPILER_APPLECLANG_VERSION >= 900 ) +#define nssv_HAVE_BUILTIN_CE ( nssv_HAVE_BUILTIN_VER ) + +#define nssv_HAVE_BUILTIN_MEMCMP ( (nssv_HAVE_CONSTEXPR_14 && nssv_HAVE_BUILTIN_CE) || !nssv_HAVE_CONSTEXPR_14 ) +#define nssv_HAVE_BUILTIN_STRLEN ( (nssv_HAVE_CONSTEXPR_11 && nssv_HAVE_BUILTIN_CE) || !nssv_HAVE_CONSTEXPR_11 ) + +#ifdef __has_builtin +# define nssv_HAVE_BUILTIN( x ) __has_builtin( x ) +#else +# define nssv_HAVE_BUILTIN( x ) 0 +#endif + +#if nssv_HAVE_BUILTIN(__builtin_memcmp) || nssv_HAVE_BUILTIN_VER +# define nssv_BUILTIN_MEMCMP __builtin_memcmp +#else +# define nssv_BUILTIN_MEMCMP memcmp +#endif + +#if nssv_HAVE_BUILTIN(__builtin_strlen) || nssv_HAVE_BUILTIN_VER +# define nssv_BUILTIN_STRLEN __builtin_strlen +#else +# define nssv_BUILTIN_STRLEN strlen +#endif + +// C++ feature usage: + +#if nssv_HAVE_CONSTEXPR_11 +# define nssv_constexpr constexpr +#else +# define nssv_constexpr /*constexpr*/ +#endif + +#if nssv_HAVE_CONSTEXPR_14 +# define nssv_constexpr14 constexpr +#else +# define nssv_constexpr14 /*constexpr*/ +#endif + +#if nssv_HAVE_EXPLICIT_CONVERSION +# define nssv_explicit explicit +#else +# define nssv_explicit /*explicit*/ +#endif + +#if nssv_HAVE_INLINE_NAMESPACE +# define nssv_inline_ns inline +#else +# define nssv_inline_ns /*inline*/ +#endif + +#if nssv_HAVE_NOEXCEPT +# define nssv_noexcept noexcept +#else +# define nssv_noexcept /*noexcept*/ +#endif + +//#if nssv_HAVE_REF_QUALIFIER +//# define nssv_ref_qual & +//# define nssv_refref_qual && +//#else +//# define nssv_ref_qual /*&*/ +//# define nssv_refref_qual /*&&*/ +//#endif + +#if nssv_HAVE_NULLPTR +# define nssv_nullptr nullptr +#else +# define nssv_nullptr NULL +#endif + +#if nssv_HAVE_NODISCARD +# define nssv_nodiscard [[nodiscard]] +#else +# define nssv_nodiscard /*[[nodiscard]]*/ +#endif + +// Additional includes: + +#include +#include +#include +#include +#include // std::char_traits<> + +#if ! nssv_CONFIG_NO_STREAM_INSERTION +# include +#endif + +#if ! nssv_CONFIG_NO_EXCEPTIONS +# include +#endif + +#if nssv_CPP11_OR_GREATER +# include +#endif + +// Clang, GNUC, MSVC warning suppression macros: + +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wreserved-user-defined-literal" +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wuser-defined-literals" +#elif nssv_COMPILER_GNUC_VERSION >= 480 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wliteral-suffix" +#endif // __clang__ + +#if nssv_COMPILER_MSVC_VERSION >= 140 +# define nssv_SUPPRESS_MSGSL_WARNING(expr) [[gsl::suppress(expr)]] +# define nssv_SUPPRESS_MSVC_WARNING(code, descr) __pragma(warning(suppress: code) ) +# define nssv_DISABLE_MSVC_WARNINGS(codes) __pragma(warning(push)) __pragma(warning(disable: codes)) +#else +# define nssv_SUPPRESS_MSGSL_WARNING(expr) +# define nssv_SUPPRESS_MSVC_WARNING(code, descr) +# define nssv_DISABLE_MSVC_WARNINGS(codes) +#endif + +#if defined(__clang__) +# define nssv_RESTORE_WARNINGS() _Pragma("clang diagnostic pop") +#elif nssv_COMPILER_GNUC_VERSION >= 480 +# define nssv_RESTORE_WARNINGS() _Pragma("GCC diagnostic pop") +#elif nssv_COMPILER_MSVC_VERSION >= 140 +# define nssv_RESTORE_WARNINGS() __pragma(warning(pop )) +#else +# define nssv_RESTORE_WARNINGS() +#endif + +// Suppress the following MSVC (GSL) warnings: +// - C4455, non-gsl : 'operator ""sv': literal suffix identifiers that do not +// start with an underscore are reserved +// - C26472, gsl::t.1 : don't use a static_cast for arithmetic conversions; +// use brace initialization, gsl::narrow_cast or gsl::narow +// - C26481: gsl::b.1 : don't use pointer arithmetic. Use span instead + +nssv_DISABLE_MSVC_WARNINGS( 4455 26481 26472 ) +//nssv_DISABLE_CLANG_WARNINGS( "-Wuser-defined-literals" ) +//nssv_DISABLE_GNUC_WARNINGS( -Wliteral-suffix ) + +namespace nonstd { namespace sv_lite { + +// +// basic_string_view declaration: +// + +template +< + class CharT, + class Traits = std::char_traits +> +class basic_string_view; + +namespace detail { + +// support constexpr comparison in C++14; +// for C++17 and later, use provided traits: + +template< typename CharT > +inline nssv_constexpr14 int compare( CharT const * s1, CharT const * s2, std::size_t count ) +{ + while ( count-- != 0 ) + { + if ( *s1 < *s2 ) return -1; + if ( *s1 > *s2 ) return +1; + ++s1; ++s2; + } + return 0; +} + +#if nssv_HAVE_BUILTIN_MEMCMP + +// specialization of compare() for char, see also generic compare() above: + +inline nssv_constexpr14 int compare( char const * s1, char const * s2, std::size_t count ) +{ + return nssv_BUILTIN_MEMCMP( s1, s2, count ); +} + +#endif + +#if nssv_HAVE_BUILTIN_STRLEN + +// specialization of length() for char, see also generic length() further below: + +inline nssv_constexpr std::size_t length( char const * s ) +{ + return nssv_BUILTIN_STRLEN( s ); +} + +#endif + +#if defined(__OPTIMIZE__) + +// gcc, clang provide __OPTIMIZE__ +// Expect tail call optimization to make length() non-recursive: + +template< typename CharT > +inline nssv_constexpr std::size_t length( CharT * s, std::size_t result = 0 ) +{ + return *s == '\0' ? result : length( s + 1, result + 1 ); +} + +#else // OPTIMIZE + +// non-recursive: + +template< typename CharT > +inline nssv_constexpr14 std::size_t length( CharT * s ) +{ + std::size_t result = 0; + while ( *s++ != '\0' ) + { + ++result; + } + return result; +} + +#endif // OPTIMIZE + +#if nssv_CPP11_OR_GREATER && ! nssv_CPP17_OR_GREATER +#if defined(__OPTIMIZE__) + +// gcc, clang provide __OPTIMIZE__ +// Expect tail call optimization to make search() non-recursive: + +template< class CharT, class Traits = std::char_traits > +constexpr const CharT* search( basic_string_view haystack, basic_string_view needle ) +{ + return haystack.starts_with( needle ) ? haystack.begin() : + haystack.empty() ? haystack.end() : search( haystack.substr(1), needle ); +} + +#else // OPTIMIZE + +// non-recursive: + +template< class CharT, class Traits = std::char_traits > +constexpr const CharT* search( basic_string_view haystack, basic_string_view needle ) +{ + return std::search( haystack.begin(), haystack.end(), needle.begin(), needle.end() ); +} + +#endif // OPTIMIZE +#endif // nssv_CPP11_OR_GREATER && ! nssv_CPP17_OR_GREATER + +} // namespace detail + +// +// basic_string_view: +// + +template +< + class CharT, + class Traits /* = std::char_traits */ +> +class basic_string_view +{ +public: + // Member types: + + typedef Traits traits_type; + typedef CharT value_type; + + typedef CharT * pointer; + typedef CharT const * const_pointer; + typedef CharT & reference; + typedef CharT const & const_reference; + + typedef const_pointer iterator; + typedef const_pointer const_iterator; + typedef std::reverse_iterator< const_iterator > reverse_iterator; + typedef std::reverse_iterator< const_iterator > const_reverse_iterator; + + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + // 24.4.2.1 Construction and assignment: + + nssv_constexpr basic_string_view() nssv_noexcept + : data_( nssv_nullptr ) + , size_( 0 ) + {} + +#if nssv_CPP11_OR_GREATER + nssv_constexpr basic_string_view( basic_string_view const & other ) nssv_noexcept = default; +#else + nssv_constexpr basic_string_view( basic_string_view const & other ) nssv_noexcept + : data_( other.data_) + , size_( other.size_) + {} +#endif + + nssv_constexpr basic_string_view( CharT const * s, size_type count ) nssv_noexcept // non-standard noexcept + : data_( s ) + , size_( count ) + {} + + nssv_constexpr basic_string_view( CharT const * s) nssv_noexcept // non-standard noexcept + : data_( s ) +#if nssv_CPP17_OR_GREATER + , size_( Traits::length(s) ) +#elif nssv_CPP11_OR_GREATER + , size_( detail::length(s) ) +#else + , size_( Traits::length(s) ) +#endif + {} + +#if nssv_HAVE_NULLPTR +# if nssv_HAVE_IS_DELETE + nssv_constexpr basic_string_view( std::nullptr_t ) nssv_noexcept = delete; +# else + private: nssv_constexpr basic_string_view( std::nullptr_t ) nssv_noexcept; public: +# endif +#endif + + // Assignment: + +#if nssv_CPP11_OR_GREATER + nssv_constexpr14 basic_string_view & operator=( basic_string_view const & other ) nssv_noexcept = default; +#else + nssv_constexpr14 basic_string_view & operator=( basic_string_view const & other ) nssv_noexcept + { + data_ = other.data_; + size_ = other.size_; + return *this; + } +#endif + + // 24.4.2.2 Iterator support: + + nssv_constexpr const_iterator begin() const nssv_noexcept { return data_; } + nssv_constexpr const_iterator end() const nssv_noexcept { return data_ + size_; } + + nssv_constexpr const_iterator cbegin() const nssv_noexcept { return begin(); } + nssv_constexpr const_iterator cend() const nssv_noexcept { return end(); } + + nssv_constexpr const_reverse_iterator rbegin() const nssv_noexcept { return const_reverse_iterator( end() ); } + nssv_constexpr const_reverse_iterator rend() const nssv_noexcept { return const_reverse_iterator( begin() ); } + + nssv_constexpr const_reverse_iterator crbegin() const nssv_noexcept { return rbegin(); } + nssv_constexpr const_reverse_iterator crend() const nssv_noexcept { return rend(); } + + // 24.4.2.3 Capacity: + + nssv_constexpr size_type size() const nssv_noexcept { return size_; } + nssv_constexpr size_type length() const nssv_noexcept { return size_; } + nssv_constexpr size_type max_size() const nssv_noexcept { return (std::numeric_limits< size_type >::max)(); } + + // since C++20 + nssv_nodiscard nssv_constexpr bool empty() const nssv_noexcept + { + return 0 == size_; + } + + // 24.4.2.4 Element access: + + nssv_constexpr const_reference operator[]( size_type pos ) const + { + return data_at( pos ); + } + + nssv_constexpr14 const_reference at( size_type pos ) const + { +#if nssv_CONFIG_NO_EXCEPTIONS + assert( pos < size() ); +#else + if ( pos >= size() ) + { + throw std::out_of_range("nonstd::string_view::at()"); + } +#endif + return data_at( pos ); + } + + nssv_constexpr const_reference front() const { return data_at( 0 ); } + nssv_constexpr const_reference back() const { return data_at( size() - 1 ); } + + nssv_constexpr const_pointer data() const nssv_noexcept { return data_; } + + // 24.4.2.5 Modifiers: + + nssv_constexpr14 void remove_prefix( size_type n ) + { + assert( n <= size() ); + data_ += n; + size_ -= n; + } + + nssv_constexpr14 void remove_suffix( size_type n ) + { + assert( n <= size() ); + size_ -= n; + } + + nssv_constexpr14 void swap( basic_string_view & other ) nssv_noexcept + { + const basic_string_view tmp(other); + other = *this; + *this = tmp; + } + + // 24.4.2.6 String operations: + + size_type copy( CharT * dest, size_type n, size_type pos = 0 ) const + { +#if nssv_CONFIG_NO_EXCEPTIONS + assert( pos <= size() ); +#else + if ( pos > size() ) + { + throw std::out_of_range("nonstd::string_view::copy()"); + } +#endif + const size_type rlen = (std::min)( n, size() - pos ); + + (void) Traits::copy( dest, data() + pos, rlen ); + + return rlen; + } + + nssv_constexpr14 basic_string_view substr( size_type pos = 0, size_type n = npos ) const + { +#if nssv_CONFIG_NO_EXCEPTIONS + assert( pos <= size() ); +#else + if ( pos > size() ) + { + throw std::out_of_range("nonstd::string_view::substr()"); + } +#endif + return basic_string_view( data() + pos, (std::min)( n, size() - pos ) ); + } + + // compare(), 6x: + + nssv_constexpr14 int compare( basic_string_view other ) const nssv_noexcept // (1) + { +#if nssv_CPP17_OR_GREATER + if ( const int result = Traits::compare( data(), other.data(), (std::min)( size(), other.size() ) ) ) +#else + if ( const int result = detail::compare( data(), other.data(), (std::min)( size(), other.size() ) ) ) +#endif + { + return result; + } + + return size() == other.size() ? 0 : size() < other.size() ? -1 : 1; + } + + nssv_constexpr int compare( size_type pos1, size_type n1, basic_string_view other ) const // (2) + { + return substr( pos1, n1 ).compare( other ); + } + + nssv_constexpr int compare( size_type pos1, size_type n1, basic_string_view other, size_type pos2, size_type n2 ) const // (3) + { + return substr( pos1, n1 ).compare( other.substr( pos2, n2 ) ); + } + + nssv_constexpr int compare( CharT const * s ) const // (4) + { + return compare( basic_string_view( s ) ); + } + + nssv_constexpr int compare( size_type pos1, size_type n1, CharT const * s ) const // (5) + { + return substr( pos1, n1 ).compare( basic_string_view( s ) ); + } + + nssv_constexpr int compare( size_type pos1, size_type n1, CharT const * s, size_type n2 ) const // (6) + { + return substr( pos1, n1 ).compare( basic_string_view( s, n2 ) ); + } + + // 24.4.2.7 Searching: + + // starts_with(), 3x, since C++20: + + nssv_constexpr bool starts_with( basic_string_view v ) const nssv_noexcept // (1) + { + return size() >= v.size() && compare( 0, v.size(), v ) == 0; + } + + nssv_constexpr bool starts_with( CharT c ) const nssv_noexcept // (2) + { + return starts_with( basic_string_view( &c, 1 ) ); + } + + nssv_constexpr bool starts_with( CharT const * s ) const // (3) + { + return starts_with( basic_string_view( s ) ); + } + + // ends_with(), 3x, since C++20: + + nssv_constexpr bool ends_with( basic_string_view v ) const nssv_noexcept // (1) + { + return size() >= v.size() && compare( size() - v.size(), npos, v ) == 0; + } + + nssv_constexpr bool ends_with( CharT c ) const nssv_noexcept // (2) + { + return ends_with( basic_string_view( &c, 1 ) ); + } + + nssv_constexpr bool ends_with( CharT const * s ) const // (3) + { + return ends_with( basic_string_view( s ) ); + } + + // find(), 4x: + + nssv_constexpr14 size_type find( basic_string_view v, size_type pos = 0 ) const nssv_noexcept // (1) + { + return assert( v.size() == 0 || v.data() != nssv_nullptr ) + , pos >= size() + ? npos : to_pos( +#if nssv_CPP11_OR_GREATER && ! nssv_CPP17_OR_GREATER + detail::search( substr(pos), v ) +#else + std::search( cbegin() + pos, cend(), v.cbegin(), v.cend(), Traits::eq ) +#endif + ); + } + + nssv_constexpr size_type find( CharT c, size_type pos = 0 ) const nssv_noexcept // (2) + { + return find( basic_string_view( &c, 1 ), pos ); + } + + nssv_constexpr size_type find( CharT const * s, size_type pos, size_type n ) const // (3) + { + return find( basic_string_view( s, n ), pos ); + } + + nssv_constexpr size_type find( CharT const * s, size_type pos = 0 ) const // (4) + { + return find( basic_string_view( s ), pos ); + } + + // rfind(), 4x: + + nssv_constexpr14 size_type rfind( basic_string_view v, size_type pos = npos ) const nssv_noexcept // (1) + { + if ( size() < v.size() ) + { + return npos; + } + + if ( v.empty() ) + { + return (std::min)( size(), pos ); + } + + const_iterator last = cbegin() + (std::min)( size() - v.size(), pos ) + v.size(); + const_iterator result = std::find_end( cbegin(), last, v.cbegin(), v.cend(), Traits::eq ); + + return result != last ? size_type( result - cbegin() ) : npos; + } + + nssv_constexpr14 size_type rfind( CharT c, size_type pos = npos ) const nssv_noexcept // (2) + { + return rfind( basic_string_view( &c, 1 ), pos ); + } + + nssv_constexpr14 size_type rfind( CharT const * s, size_type pos, size_type n ) const // (3) + { + return rfind( basic_string_view( s, n ), pos ); + } + + nssv_constexpr14 size_type rfind( CharT const * s, size_type pos = npos ) const // (4) + { + return rfind( basic_string_view( s ), pos ); + } + + // find_first_of(), 4x: + + nssv_constexpr size_type find_first_of( basic_string_view v, size_type pos = 0 ) const nssv_noexcept // (1) + { + return pos >= size() + ? npos + : to_pos( std::find_first_of( cbegin() + pos, cend(), v.cbegin(), v.cend(), Traits::eq ) ); + } + + nssv_constexpr size_type find_first_of( CharT c, size_type pos = 0 ) const nssv_noexcept // (2) + { + return find_first_of( basic_string_view( &c, 1 ), pos ); + } + + nssv_constexpr size_type find_first_of( CharT const * s, size_type pos, size_type n ) const // (3) + { + return find_first_of( basic_string_view( s, n ), pos ); + } + + nssv_constexpr size_type find_first_of( CharT const * s, size_type pos = 0 ) const // (4) + { + return find_first_of( basic_string_view( s ), pos ); + } + + // find_last_of(), 4x: + + nssv_constexpr size_type find_last_of( basic_string_view v, size_type pos = npos ) const nssv_noexcept // (1) + { + return empty() + ? npos + : pos >= size() + ? find_last_of( v, size() - 1 ) + : to_pos( std::find_first_of( const_reverse_iterator( cbegin() + pos + 1 ), crend(), v.cbegin(), v.cend(), Traits::eq ) ); + } + + nssv_constexpr size_type find_last_of( CharT c, size_type pos = npos ) const nssv_noexcept // (2) + { + return find_last_of( basic_string_view( &c, 1 ), pos ); + } + + nssv_constexpr size_type find_last_of( CharT const * s, size_type pos, size_type count ) const // (3) + { + return find_last_of( basic_string_view( s, count ), pos ); + } + + nssv_constexpr size_type find_last_of( CharT const * s, size_type pos = npos ) const // (4) + { + return find_last_of( basic_string_view( s ), pos ); + } + + // find_first_not_of(), 4x: + + nssv_constexpr size_type find_first_not_of( basic_string_view v, size_type pos = 0 ) const nssv_noexcept // (1) + { + return pos >= size() + ? npos + : to_pos( std::find_if( cbegin() + pos, cend(), not_in_view( v ) ) ); + } + + nssv_constexpr size_type find_first_not_of( CharT c, size_type pos = 0 ) const nssv_noexcept // (2) + { + return find_first_not_of( basic_string_view( &c, 1 ), pos ); + } + + nssv_constexpr size_type find_first_not_of( CharT const * s, size_type pos, size_type count ) const // (3) + { + return find_first_not_of( basic_string_view( s, count ), pos ); + } + + nssv_constexpr size_type find_first_not_of( CharT const * s, size_type pos = 0 ) const // (4) + { + return find_first_not_of( basic_string_view( s ), pos ); + } + + // find_last_not_of(), 4x: + + nssv_constexpr size_type find_last_not_of( basic_string_view v, size_type pos = npos ) const nssv_noexcept // (1) + { + return empty() + ? npos + : pos >= size() + ? find_last_not_of( v, size() - 1 ) + : to_pos( std::find_if( const_reverse_iterator( cbegin() + pos + 1 ), crend(), not_in_view( v ) ) ); + } + + nssv_constexpr size_type find_last_not_of( CharT c, size_type pos = npos ) const nssv_noexcept // (2) + { + return find_last_not_of( basic_string_view( &c, 1 ), pos ); + } + + nssv_constexpr size_type find_last_not_of( CharT const * s, size_type pos, size_type count ) const // (3) + { + return find_last_not_of( basic_string_view( s, count ), pos ); + } + + nssv_constexpr size_type find_last_not_of( CharT const * s, size_type pos = npos ) const // (4) + { + return find_last_not_of( basic_string_view( s ), pos ); + } + + // Constants: + +#if nssv_CPP17_OR_GREATER + static nssv_constexpr size_type npos = size_type(-1); +#elif nssv_CPP11_OR_GREATER + enum : size_type { npos = size_type(-1) }; +#else + enum { npos = size_type(-1) }; +#endif + +private: + struct not_in_view + { + const basic_string_view v; + + nssv_constexpr explicit not_in_view( basic_string_view v_ ) : v( v_ ) {} + + nssv_constexpr bool operator()( CharT c ) const + { + return npos == v.find_first_of( c ); + } + }; + + nssv_constexpr size_type to_pos( const_iterator it ) const + { + return it == cend() ? npos : size_type( it - cbegin() ); + } + + nssv_constexpr size_type to_pos( const_reverse_iterator it ) const + { + return it == crend() ? npos : size_type( crend() - it - 1 ); + } + + nssv_constexpr const_reference data_at( size_type pos ) const + { +#if nssv_BETWEEN( nssv_COMPILER_GNUC_VERSION, 1, 500 ) + return data_[pos]; +#else + return assert( pos < size() ), data_[pos]; +#endif + } + +private: + const_pointer data_; + size_type size_; + +public: +#if nssv_CONFIG_CONVERSION_STD_STRING_CLASS_METHODS + + template< class Allocator > + basic_string_view( std::basic_string const & s ) nssv_noexcept + : data_( s.data() ) + , size_( s.size() ) + {} + +#if nssv_HAVE_EXPLICIT_CONVERSION + + template< class Allocator > + explicit operator std::basic_string() const + { + return to_string( Allocator() ); + } + +#endif // nssv_HAVE_EXPLICIT_CONVERSION + +#if nssv_CPP11_OR_GREATER + + template< class Allocator = std::allocator > + std::basic_string + to_string( Allocator const & a = Allocator() ) const + { + return std::basic_string( begin(), end(), a ); + } + +#else + + std::basic_string + to_string() const + { + return std::basic_string( begin(), end() ); + } + + template< class Allocator > + std::basic_string + to_string( Allocator const & a ) const + { + return std::basic_string( begin(), end(), a ); + } + +#endif // nssv_CPP11_OR_GREATER + +#endif // nssv_CONFIG_CONVERSION_STD_STRING_CLASS_METHODS +}; + +// +// Non-member functions: +// + +// 24.4.3 Non-member comparison functions: +// lexicographically compare two string views (function template): + +template< class CharT, class Traits > +nssv_constexpr bool operator== ( + basic_string_view lhs, + basic_string_view rhs ) nssv_noexcept +{ return lhs.size() == rhs.size() && lhs.compare( rhs ) == 0; } + +template< class CharT, class Traits > +nssv_constexpr bool operator!= ( + basic_string_view lhs, + basic_string_view rhs ) nssv_noexcept +{ return !( lhs == rhs ); } + +template< class CharT, class Traits > +nssv_constexpr bool operator< ( + basic_string_view lhs, + basic_string_view rhs ) nssv_noexcept +{ return lhs.compare( rhs ) < 0; } + +template< class CharT, class Traits > +nssv_constexpr bool operator<= ( + basic_string_view lhs, + basic_string_view rhs ) nssv_noexcept +{ return lhs.compare( rhs ) <= 0; } + +template< class CharT, class Traits > +nssv_constexpr bool operator> ( + basic_string_view lhs, + basic_string_view rhs ) nssv_noexcept +{ return lhs.compare( rhs ) > 0; } + +template< class CharT, class Traits > +nssv_constexpr bool operator>= ( + basic_string_view lhs, + basic_string_view rhs ) nssv_noexcept +{ return lhs.compare( rhs ) >= 0; } + +// Let S be basic_string_view, and sv be an instance of S. +// Implementations shall provide sufficient additional overloads marked +// constexpr and noexcept so that an object t with an implicit conversion +// to S can be compared according to Table 67. + +#if ! nssv_CPP11_OR_GREATER || nssv_BETWEEN( nssv_COMPILER_MSVC_VERSION, 100, 141 ) + +// accommodate for older compilers: + +// == + +template< class CharT, class Traits> +nssv_constexpr bool operator==( + basic_string_view lhs, + CharT const * rhs ) nssv_noexcept +{ return lhs.size() == detail::length( rhs ) && lhs.compare( rhs ) == 0; } + +template< class CharT, class Traits> +nssv_constexpr bool operator==( + CharT const * lhs, + basic_string_view rhs ) nssv_noexcept +{ return detail::length( lhs ) == rhs.size() && rhs.compare( lhs ) == 0; } + +template< class CharT, class Traits> +nssv_constexpr bool operator==( + basic_string_view lhs, + std::basic_string rhs ) nssv_noexcept +{ return lhs.size() == rhs.size() && lhs.compare( rhs ) == 0; } + +template< class CharT, class Traits> +nssv_constexpr bool operator==( + std::basic_string rhs, + basic_string_view lhs ) nssv_noexcept +{ return lhs.size() == rhs.size() && lhs.compare( rhs ) == 0; } + +// != + +template< class CharT, class Traits> +nssv_constexpr bool operator!=( + basic_string_view lhs, + CharT const * rhs ) nssv_noexcept +{ return !( lhs == rhs ); } + +template< class CharT, class Traits> +nssv_constexpr bool operator!=( + CharT const * lhs, + basic_string_view rhs ) nssv_noexcept +{ return !( lhs == rhs ); } + +template< class CharT, class Traits> +nssv_constexpr bool operator!=( + basic_string_view lhs, + std::basic_string rhs ) nssv_noexcept +{ return !( lhs == rhs ); } + +template< class CharT, class Traits> +nssv_constexpr bool operator!=( + std::basic_string rhs, + basic_string_view lhs ) nssv_noexcept +{ return !( lhs == rhs ); } + +// < + +template< class CharT, class Traits> +nssv_constexpr bool operator<( + basic_string_view lhs, + CharT const * rhs ) nssv_noexcept +{ return lhs.compare( rhs ) < 0; } + +template< class CharT, class Traits> +nssv_constexpr bool operator<( + CharT const * lhs, + basic_string_view rhs ) nssv_noexcept +{ return rhs.compare( lhs ) > 0; } + +template< class CharT, class Traits> +nssv_constexpr bool operator<( + basic_string_view lhs, + std::basic_string rhs ) nssv_noexcept +{ return lhs.compare( rhs ) < 0; } + +template< class CharT, class Traits> +nssv_constexpr bool operator<( + std::basic_string rhs, + basic_string_view lhs ) nssv_noexcept +{ return rhs.compare( lhs ) > 0; } + +// <= + +template< class CharT, class Traits> +nssv_constexpr bool operator<=( + basic_string_view lhs, + CharT const * rhs ) nssv_noexcept +{ return lhs.compare( rhs ) <= 0; } + +template< class CharT, class Traits> +nssv_constexpr bool operator<=( + CharT const * lhs, + basic_string_view rhs ) nssv_noexcept +{ return rhs.compare( lhs ) >= 0; } + +template< class CharT, class Traits> +nssv_constexpr bool operator<=( + basic_string_view lhs, + std::basic_string rhs ) nssv_noexcept +{ return lhs.compare( rhs ) <= 0; } + +template< class CharT, class Traits> +nssv_constexpr bool operator<=( + std::basic_string rhs, + basic_string_view lhs ) nssv_noexcept +{ return rhs.compare( lhs ) >= 0; } + +// > + +template< class CharT, class Traits> +nssv_constexpr bool operator>( + basic_string_view lhs, + CharT const * rhs ) nssv_noexcept +{ return lhs.compare( rhs ) > 0; } + +template< class CharT, class Traits> +nssv_constexpr bool operator>( + CharT const * lhs, + basic_string_view rhs ) nssv_noexcept +{ return rhs.compare( lhs ) < 0; } + +template< class CharT, class Traits> +nssv_constexpr bool operator>( + basic_string_view lhs, + std::basic_string rhs ) nssv_noexcept +{ return lhs.compare( rhs ) > 0; } + +template< class CharT, class Traits> +nssv_constexpr bool operator>( + std::basic_string rhs, + basic_string_view lhs ) nssv_noexcept +{ return rhs.compare( lhs ) < 0; } + +// >= + +template< class CharT, class Traits> +nssv_constexpr bool operator>=( + basic_string_view lhs, + CharT const * rhs ) nssv_noexcept +{ return lhs.compare( rhs ) >= 0; } + +template< class CharT, class Traits> +nssv_constexpr bool operator>=( + CharT const * lhs, + basic_string_view rhs ) nssv_noexcept +{ return rhs.compare( lhs ) <= 0; } + +template< class CharT, class Traits> +nssv_constexpr bool operator>=( + basic_string_view lhs, + std::basic_string rhs ) nssv_noexcept +{ return lhs.compare( rhs ) >= 0; } + +template< class CharT, class Traits> +nssv_constexpr bool operator>=( + std::basic_string rhs, + basic_string_view lhs ) nssv_noexcept +{ return rhs.compare( lhs ) <= 0; } + +#else // newer compilers: + +#define nssv_BASIC_STRING_VIEW_I(T,U) typename std::decay< basic_string_view >::type + +#if defined(_MSC_VER) // issue 40 +# define nssv_MSVC_ORDER(x) , int=x +#else +# define nssv_MSVC_ORDER(x) /*, int=x*/ +#endif + +// == + +template< class CharT, class Traits nssv_MSVC_ORDER(1) > +nssv_constexpr bool operator==( + basic_string_view lhs, + nssv_BASIC_STRING_VIEW_I(CharT, Traits) rhs ) nssv_noexcept +{ return lhs.size() == rhs.size() && lhs.compare( rhs ) == 0; } + +template< class CharT, class Traits nssv_MSVC_ORDER(2) > +nssv_constexpr bool operator==( + nssv_BASIC_STRING_VIEW_I(CharT, Traits) lhs, + basic_string_view rhs ) nssv_noexcept +{ return lhs.size() == rhs.size() && lhs.compare( rhs ) == 0; } + +// != + +template< class CharT, class Traits nssv_MSVC_ORDER(1) > +nssv_constexpr bool operator!= ( + basic_string_view < CharT, Traits > lhs, + nssv_BASIC_STRING_VIEW_I( CharT, Traits ) rhs ) nssv_noexcept +{ return !( lhs == rhs ); } + +template< class CharT, class Traits nssv_MSVC_ORDER(2) > +nssv_constexpr bool operator!= ( + nssv_BASIC_STRING_VIEW_I( CharT, Traits ) lhs, + basic_string_view < CharT, Traits > rhs ) nssv_noexcept +{ return !( lhs == rhs ); } + +// < + +template< class CharT, class Traits nssv_MSVC_ORDER(1) > +nssv_constexpr bool operator< ( + basic_string_view < CharT, Traits > lhs, + nssv_BASIC_STRING_VIEW_I( CharT, Traits ) rhs ) nssv_noexcept +{ return lhs.compare( rhs ) < 0; } + +template< class CharT, class Traits nssv_MSVC_ORDER(2) > +nssv_constexpr bool operator< ( + nssv_BASIC_STRING_VIEW_I( CharT, Traits ) lhs, + basic_string_view < CharT, Traits > rhs ) nssv_noexcept +{ return lhs.compare( rhs ) < 0; } + +// <= + +template< class CharT, class Traits nssv_MSVC_ORDER(1) > +nssv_constexpr bool operator<= ( + basic_string_view < CharT, Traits > lhs, + nssv_BASIC_STRING_VIEW_I( CharT, Traits ) rhs ) nssv_noexcept +{ return lhs.compare( rhs ) <= 0; } + +template< class CharT, class Traits nssv_MSVC_ORDER(2) > +nssv_constexpr bool operator<= ( + nssv_BASIC_STRING_VIEW_I( CharT, Traits ) lhs, + basic_string_view < CharT, Traits > rhs ) nssv_noexcept +{ return lhs.compare( rhs ) <= 0; } + +// > + +template< class CharT, class Traits nssv_MSVC_ORDER(1) > +nssv_constexpr bool operator> ( + basic_string_view < CharT, Traits > lhs, + nssv_BASIC_STRING_VIEW_I( CharT, Traits ) rhs ) nssv_noexcept +{ return lhs.compare( rhs ) > 0; } + +template< class CharT, class Traits nssv_MSVC_ORDER(2) > +nssv_constexpr bool operator> ( + nssv_BASIC_STRING_VIEW_I( CharT, Traits ) lhs, + basic_string_view < CharT, Traits > rhs ) nssv_noexcept +{ return lhs.compare( rhs ) > 0; } + +// >= + +template< class CharT, class Traits nssv_MSVC_ORDER(1) > +nssv_constexpr bool operator>= ( + basic_string_view < CharT, Traits > lhs, + nssv_BASIC_STRING_VIEW_I( CharT, Traits ) rhs ) nssv_noexcept +{ return lhs.compare( rhs ) >= 0; } + +template< class CharT, class Traits nssv_MSVC_ORDER(2) > +nssv_constexpr bool operator>= ( + nssv_BASIC_STRING_VIEW_I( CharT, Traits ) lhs, + basic_string_view < CharT, Traits > rhs ) nssv_noexcept +{ return lhs.compare( rhs ) >= 0; } + +#undef nssv_MSVC_ORDER +#undef nssv_BASIC_STRING_VIEW_I + +#endif // compiler-dependent approach to comparisons + +// 24.4.4 Inserters and extractors: + +#if ! nssv_CONFIG_NO_STREAM_INSERTION + +namespace detail { + +template< class Stream > +void write_padding( Stream & os, std::streamsize n ) +{ + for ( std::streamsize i = 0; i < n; ++i ) + os.rdbuf()->sputc( os.fill() ); +} + +template< class Stream, class View > +Stream & write_to_stream( Stream & os, View const & sv ) +{ + typename Stream::sentry sentry( os ); + + if ( !sentry ) + return os; + + const std::streamsize length = static_cast( sv.length() ); + + // Whether, and how, to pad: + const bool pad = ( length < os.width() ); + const bool left_pad = pad && ( os.flags() & std::ios_base::adjustfield ) == std::ios_base::right; + + if ( left_pad ) + write_padding( os, os.width() - length ); + + // Write span characters: + os.rdbuf()->sputn( sv.begin(), length ); + + if ( pad && !left_pad ) + write_padding( os, os.width() - length ); + + // Reset output stream width: + os.width( 0 ); + + return os; +} + +} // namespace detail + +template< class CharT, class Traits > +std::basic_ostream & +operator<<( + std::basic_ostream& os, + basic_string_view sv ) +{ + return detail::write_to_stream( os, sv ); +} + +#endif // nssv_CONFIG_NO_STREAM_INSERTION + +// Several typedefs for common character types are provided: + +typedef basic_string_view string_view; +typedef basic_string_view wstring_view; +#if nssv_HAVE_WCHAR16_T +typedef basic_string_view u16string_view; +typedef basic_string_view u32string_view; +#endif + +}} // namespace nonstd::sv_lite + +// +// 24.4.6 Suffix for basic_string_view literals: +// + +#if nssv_HAVE_USER_DEFINED_LITERALS + +namespace nonstd { +nssv_inline_ns namespace literals { +nssv_inline_ns namespace string_view_literals { + +#if nssv_CONFIG_STD_SV_OPERATOR && nssv_HAVE_STD_DEFINED_LITERALS + +nssv_constexpr nonstd::sv_lite::string_view operator "" sv( const char* str, size_t len ) nssv_noexcept // (1) +{ + return nonstd::sv_lite::string_view{ str, len }; +} + +nssv_constexpr nonstd::sv_lite::u16string_view operator "" sv( const char16_t* str, size_t len ) nssv_noexcept // (2) +{ + return nonstd::sv_lite::u16string_view{ str, len }; +} + +nssv_constexpr nonstd::sv_lite::u32string_view operator "" sv( const char32_t* str, size_t len ) nssv_noexcept // (3) +{ + return nonstd::sv_lite::u32string_view{ str, len }; +} + +nssv_constexpr nonstd::sv_lite::wstring_view operator "" sv( const wchar_t* str, size_t len ) nssv_noexcept // (4) +{ + return nonstd::sv_lite::wstring_view{ str, len }; +} + +#endif // nssv_CONFIG_STD_SV_OPERATOR && nssv_HAVE_STD_DEFINED_LITERALS + +#if nssv_CONFIG_USR_SV_OPERATOR + +nssv_constexpr nonstd::sv_lite::string_view operator "" _sv( const char* str, size_t len ) nssv_noexcept // (1) +{ + return nonstd::sv_lite::string_view{ str, len }; +} + +nssv_constexpr nonstd::sv_lite::u16string_view operator "" _sv( const char16_t* str, size_t len ) nssv_noexcept // (2) +{ + return nonstd::sv_lite::u16string_view{ str, len }; +} + +nssv_constexpr nonstd::sv_lite::u32string_view operator "" _sv( const char32_t* str, size_t len ) nssv_noexcept // (3) +{ + return nonstd::sv_lite::u32string_view{ str, len }; +} + +nssv_constexpr nonstd::sv_lite::wstring_view operator "" _sv( const wchar_t* str, size_t len ) nssv_noexcept // (4) +{ + return nonstd::sv_lite::wstring_view{ str, len }; +} + +#endif // nssv_CONFIG_USR_SV_OPERATOR + +}}} // namespace nonstd::literals::string_view_literals + +#endif + +// +// Extensions for std::string: +// + +#if nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS + +namespace nonstd { +namespace sv_lite { + +// Exclude MSVC 14 (19.00): it yields ambiguous to_string(): + +#if nssv_CPP11_OR_GREATER && nssv_COMPILER_MSVC_VERSION != 140 + +template< class CharT, class Traits, class Allocator = std::allocator > +std::basic_string +to_string( basic_string_view v, Allocator const & a = Allocator() ) +{ + return std::basic_string( v.begin(), v.end(), a ); +} + +#else + +template< class CharT, class Traits > +std::basic_string +to_string( basic_string_view v ) +{ + return std::basic_string( v.begin(), v.end() ); +} + +template< class CharT, class Traits, class Allocator > +std::basic_string +to_string( basic_string_view v, Allocator const & a ) +{ + return std::basic_string( v.begin(), v.end(), a ); +} + +#endif // nssv_CPP11_OR_GREATER + +template< class CharT, class Traits, class Allocator > +basic_string_view +to_string_view( std::basic_string const & s ) +{ + return basic_string_view( s.data(), s.size() ); +} + +}} // namespace nonstd::sv_lite + +#endif // nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS + +// +// make types and algorithms available in namespace nonstd: +// + +namespace nonstd { + +using sv_lite::basic_string_view; +using sv_lite::string_view; +using sv_lite::wstring_view; + +#if nssv_HAVE_WCHAR16_T +using sv_lite::u16string_view; +#endif +#if nssv_HAVE_WCHAR32_T +using sv_lite::u32string_view; +#endif + +// literal "sv" + +using sv_lite::operator==; +using sv_lite::operator!=; +using sv_lite::operator<; +using sv_lite::operator<=; +using sv_lite::operator>; +using sv_lite::operator>=; + +#if ! nssv_CONFIG_NO_STREAM_INSERTION +using sv_lite::operator<<; +#endif + +#if nssv_CONFIG_CONVERSION_STD_STRING_FREE_FUNCTIONS +using sv_lite::to_string; +using sv_lite::to_string_view; +#endif + +} // namespace nonstd + +// 24.4.5 Hash support (C++11): + +// Note: The hash value of a string view object is equal to the hash value of +// the corresponding string object. + +#if nssv_HAVE_STD_HASH + +#include + +namespace std { + +template<> +struct hash< nonstd::string_view > +{ +public: + std::size_t operator()( nonstd::string_view v ) const nssv_noexcept + { + return std::hash()( std::string( v.data(), v.size() ) ); + } +}; + +template<> +struct hash< nonstd::wstring_view > +{ +public: + std::size_t operator()( nonstd::wstring_view v ) const nssv_noexcept + { + return std::hash()( std::wstring( v.data(), v.size() ) ); + } +}; + +template<> +struct hash< nonstd::u16string_view > +{ +public: + std::size_t operator()( nonstd::u16string_view v ) const nssv_noexcept + { + return std::hash()( std::u16string( v.data(), v.size() ) ); + } +}; + +template<> +struct hash< nonstd::u32string_view > +{ +public: + std::size_t operator()( nonstd::u32string_view v ) const nssv_noexcept + { + return std::hash()( std::u32string( v.data(), v.size() ) ); + } +}; + +} // namespace std + +#endif // nssv_HAVE_STD_HASH + +nssv_RESTORE_WARNINGS() + +#endif // nssv_HAVE_STD_STRING_VIEW +#endif // NONSTD_SV_LITE_H_INCLUDED diff --git a/third_party/wabt/include/wabt/binary-reader-logging.h b/third_party/wabt/include/wabt/binary-reader-logging.h index 495114853..bd0513dd4 100644 --- a/third_party/wabt/include/wabt/binary-reader-logging.h +++ b/third_party/wabt/include/wabt/binary-reader-logging.h @@ -39,7 +39,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate { Result BeginCustomSection(Index section_index, Offset size, - std::string_view section_name) override; + nonstd::string_view section_name) override; Result EndCustomSection() override; Result BeginTypeSection(Offset size) override; @@ -57,33 +57,33 @@ class BinaryReaderLogging : public BinaryReaderDelegate { Result OnImportCount(Index count) override; Result OnImport(Index index, ExternalKind kind, - std::string_view module_name, - std::string_view field_name) override; + nonstd::string_view module_name, + nonstd::string_view field_name) override; Result OnImportFunc(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index func_index, Index sig_index) override; Result OnImportTable(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index table_index, Type elem_type, const Limits* elem_limits) override; Result OnImportMemory(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index memory_index, const Limits* page_limits) override; Result OnImportGlobal(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index global_index, Type type, bool mutable_) override; Result OnImportTag(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index tag_index, Index sig_index) override; Result EndImportSection() override; @@ -118,7 +118,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate { Result OnExport(Index index, ExternalKind kind, Index item_index, - std::string_view name) override; + nonstd::string_view name) override; Result EndExportSection() override; Result BeginStartSection(Offset size) override; @@ -300,13 +300,13 @@ class BinaryReaderLogging : public BinaryReaderDelegate { Result OnModuleNameSubsection(Index index, uint32_t name_type, Offset subsection_size) override; - Result OnModuleName(std::string_view name) override; + Result OnModuleName(nonstd::string_view name) override; Result OnFunctionNameSubsection(Index index, uint32_t name_type, Offset subsection_size) override; Result OnFunctionNamesCount(Index num_functions) override; Result OnFunctionName(Index function_index, - std::string_view function_name) override; + nonstd::string_view function_name) override; Result OnLocalNameSubsection(Index index, uint32_t name_type, Offset subsection_size) override; @@ -314,13 +314,13 @@ class BinaryReaderLogging : public BinaryReaderDelegate { Result OnLocalNameLocalCount(Index function_index, Index num_locals) override; Result OnLocalName(Index function_index, Index local_index, - std::string_view local_name) override; + nonstd::string_view local_name) override; Result OnNameSubsection(Index index, NameSectionSubsection subsection_type, Offset subsection_size) override; Result OnNameEntry(NameSectionSubsection type, Index index, - std::string_view name) override; + nonstd::string_view name) override; Result OnNameCount(Index num_names) override; Result EndNamesSection() override; @@ -338,56 +338,56 @@ class BinaryReaderLogging : public BinaryReaderDelegate { uint32_t table_size, uint32_t table_align) override; Result OnDylinkNeededCount(Index count) override; - Result OnDylinkNeeded(std::string_view needed) override; + Result OnDylinkNeeded(nonstd::string_view needed) override; Result OnDylinkImportCount(Index count) override; Result OnDylinkExportCount(Index count) override; - Result OnDylinkImport(std::string_view module, - std::string_view name, + Result OnDylinkImport(nonstd::string_view module, + nonstd::string_view name, uint32_t flags) override; - Result OnDylinkExport(std::string_view name, uint32_t flags) override; + Result OnDylinkExport(nonstd::string_view name, uint32_t flags) override; Result EndDylinkSection() override; Result BeginTargetFeaturesSection(Offset size) override; Result OnFeatureCount(Index count) override; - Result OnFeature(uint8_t prefix, std::string_view name) override; + Result OnFeature(uint8_t prefix, nonstd::string_view name) override; Result EndTargetFeaturesSection() override; Result BeginLinkingSection(Offset size) override; Result OnSymbolCount(Index count) override; Result OnDataSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index segment, uint32_t offset, uint32_t size) override; Result OnFunctionSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index func_index) override; Result OnGlobalSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index global_index) override; Result OnSectionSymbol(Index index, uint32_t flags, Index section_index) override; Result OnTagSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index tag_index) override; Result OnTableSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index tag_index) override; Result OnSegmentInfoCount(Index count) override; Result OnSegmentInfo(Index index, - std::string_view name, + nonstd::string_view name, Address alignment, uint32_t flags) override; Result OnInitFunctionCount(Index count) override; Result OnInitFunction(uint32_t priority, Index function_index) override; Result OnComdatCount(Index count) override; - Result OnComdatBegin(std::string_view name, + Result OnComdatBegin(nonstd::string_view name, uint32_t flags, Index count) override; Result OnComdatEntry(ComdatType kind, Index index) override; @@ -399,7 +399,7 @@ class BinaryReaderLogging : public BinaryReaderDelegate { Result EndTagSection() override; /* Code Metadata sections */ - Result BeginCodeMetadataSection(std::string_view name, Offset size) override; + Result BeginCodeMetadataSection(nonstd::string_view name, Offset size) override; Result OnCodeMetadataFuncCount(Index count) override; Result OnCodeMetadataCount(Index function_index, Index count) override; Result OnCodeMetadata(Offset offset, const void* data, Address size) override; diff --git a/third_party/wabt/include/wabt/binary-reader-nop.h b/third_party/wabt/include/wabt/binary-reader-nop.h index 211a50be7..3bd4a4952 100644 --- a/third_party/wabt/include/wabt/binary-reader-nop.h +++ b/third_party/wabt/include/wabt/binary-reader-nop.h @@ -38,7 +38,7 @@ class BinaryReaderNop : public BinaryReaderDelegate { /* Custom section */ Result BeginCustomSection(Index section_index, Offset size, - std::string_view section_name) override { + nonstd::string_view section_name) override { return Result::Ok; } Result EndCustomSection() override { return Result::Ok; } @@ -66,43 +66,43 @@ class BinaryReaderNop : public BinaryReaderDelegate { Result OnImportCount(Index count) override { return Result::Ok; } Result OnImport(Index index, ExternalKind kind, - std::string_view module_name, - std::string_view field_name) override { + nonstd::string_view module_name, + nonstd::string_view field_name) override { return Result::Ok; } Result OnImportFunc(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index func_index, Index sig_index) override { return Result::Ok; } Result OnImportTable(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index table_index, Type elem_type, const Limits* elem_limits) override { return Result::Ok; } Result OnImportMemory(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index memory_index, const Limits* page_limits) override { return Result::Ok; } Result OnImportGlobal(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index global_index, Type type, bool mutable_) override { return Result::Ok; } Result OnImportTag(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index tag_index, Index sig_index) override { return Result::Ok; @@ -152,7 +152,7 @@ class BinaryReaderNop : public BinaryReaderDelegate { Result OnExport(Index index, ExternalKind kind, Index item_index, - std::string_view name) override { + nonstd::string_view name) override { return Result::Ok; } Result EndExportSection() override { return Result::Ok; } @@ -411,7 +411,7 @@ class BinaryReaderNop : public BinaryReaderDelegate { Offset subsection_size) override { return Result::Ok; } - Result OnModuleName(std::string_view name) override { return Result::Ok; } + Result OnModuleName(nonstd::string_view name) override { return Result::Ok; } Result OnFunctionNameSubsection(Index index, uint32_t name_type, Offset subsection_size) override { @@ -421,7 +421,7 @@ class BinaryReaderNop : public BinaryReaderDelegate { return Result::Ok; } Result OnFunctionName(Index function_index, - std::string_view function_name) override { + nonstd::string_view function_name) override { return Result::Ok; } Result OnLocalNameSubsection(Index index, @@ -438,7 +438,7 @@ class BinaryReaderNop : public BinaryReaderDelegate { } Result OnLocalName(Index function_index, Index local_index, - std::string_view local_name) override { + nonstd::string_view local_name) override { return Result::Ok; } Result EndNamesSection() override { return Result::Ok; } @@ -451,7 +451,7 @@ class BinaryReaderNop : public BinaryReaderDelegate { Result OnNameCount(Index num_names) override { return Result::Ok; } Result OnNameEntry(NameSectionSubsection type, Index index, - std::string_view name) override { + nonstd::string_view name) override { return Result::Ok; } @@ -475,7 +475,7 @@ class BinaryReaderNop : public BinaryReaderDelegate { Result EndTagSection() override { return Result::Ok; } /* Code Metadata sections */ - Result BeginCodeMetadataSection(std::string_view name, Offset size) override { + Result BeginCodeMetadataSection(nonstd::string_view name, Offset size) override { return Result::Ok; } Result OnCodeMetadataFuncCount(Index count) override { return Result::Ok; } @@ -498,17 +498,17 @@ class BinaryReaderNop : public BinaryReaderDelegate { return Result::Ok; } Result OnDylinkNeededCount(Index count) override { return Result::Ok; } - Result OnDylinkNeeded(std::string_view so_name) override { + Result OnDylinkNeeded(nonstd::string_view so_name) override { return Result::Ok; } Result OnDylinkImportCount(Index count) override { return Result::Ok; } Result OnDylinkExportCount(Index count) override { return Result::Ok; } - Result OnDylinkImport(std::string_view module, - std::string_view name, + Result OnDylinkImport(nonstd::string_view module, + nonstd::string_view name, uint32_t flags) override { return Result::Ok; } - Result OnDylinkExport(std::string_view name, uint32_t flags) override { + Result OnDylinkExport(nonstd::string_view name, uint32_t flags) override { return Result::Ok; } Result EndDylinkSection() override { return Result::Ok; } @@ -516,7 +516,7 @@ class BinaryReaderNop : public BinaryReaderDelegate { /* target_features section */ Result BeginTargetFeaturesSection(Offset size) override { return Result::Ok; } Result OnFeatureCount(Index count) override { return Result::Ok; } - Result OnFeature(uint8_t prefix, std::string_view name) override { + Result OnFeature(uint8_t prefix, nonstd::string_view name) override { return Result::Ok; } Result EndTargetFeaturesSection() override { return Result::Ok; } @@ -526,7 +526,7 @@ class BinaryReaderNop : public BinaryReaderDelegate { Result OnSymbolCount(Index count) override { return Result::Ok; } Result OnDataSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index segment, uint32_t offset, uint32_t size) override { @@ -534,13 +534,13 @@ class BinaryReaderNop : public BinaryReaderDelegate { } Result OnFunctionSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index func_index) override { return Result::Ok; } Result OnGlobalSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index global_index) override { return Result::Ok; } @@ -551,19 +551,19 @@ class BinaryReaderNop : public BinaryReaderDelegate { } Result OnTagSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index tag_index) override { return Result::Ok; } Result OnTableSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index table_index) override { return Result::Ok; } Result OnSegmentInfoCount(Index count) override { return Result::Ok; } Result OnSegmentInfo(Index index, - std::string_view name, + nonstd::string_view name, Address alignment, uint32_t flags) override { return Result::Ok; @@ -573,7 +573,7 @@ class BinaryReaderNop : public BinaryReaderDelegate { return Result::Ok; } Result OnComdatCount(Index count) override { return Result::Ok; } - Result OnComdatBegin(std::string_view name, + Result OnComdatBegin(nonstd::string_view name, uint32_t flags, Index count) override { return Result::Ok; diff --git a/third_party/wabt/include/wabt/binary-reader.h b/third_party/wabt/include/wabt/binary-reader.h index a658f32a9..0b8504976 100644 --- a/third_party/wabt/include/wabt/binary-reader.h +++ b/third_party/wabt/include/wabt/binary-reader.h @@ -19,7 +19,7 @@ #include #include -#include +#include "string_view.h" #include "wabt/binary.h" #include "wabt/common.h" @@ -86,7 +86,7 @@ class BinaryReaderDelegate { /* Custom section */ virtual Result BeginCustomSection(Index section_index, Offset size, - std::string_view section_name) = 0; + nonstd::string_view section_name) = 0; virtual Result EndCustomSection() = 0; /* Type section */ @@ -108,33 +108,33 @@ class BinaryReaderDelegate { virtual Result OnImportCount(Index count) = 0; virtual Result OnImport(Index index, ExternalKind kind, - std::string_view module_name, - std::string_view field_name) = 0; + nonstd::string_view module_name, + nonstd::string_view field_name) = 0; virtual Result OnImportFunc(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index func_index, Index sig_index) = 0; virtual Result OnImportTable(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index table_index, Type elem_type, const Limits* elem_limits) = 0; virtual Result OnImportMemory(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index memory_index, const Limits* page_limits) = 0; virtual Result OnImportGlobal(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index global_index, Type type, bool mutable_) = 0; virtual Result OnImportTag(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index tag_index, Index sig_index) = 0; virtual Result EndImportSection() = 0; @@ -174,7 +174,7 @@ class BinaryReaderDelegate { virtual Result OnExport(Index index, ExternalKind kind, Index item_index, - std::string_view name) = 0; + nonstd::string_view name) = 0; virtual Result EndExportSection() = 0; /* Start section */ @@ -375,13 +375,13 @@ class BinaryReaderDelegate { virtual Result OnModuleNameSubsection(Index index, uint32_t name_type, Offset subsection_size) = 0; - virtual Result OnModuleName(std::string_view name) = 0; + virtual Result OnModuleName(nonstd::string_view name) = 0; virtual Result OnFunctionNameSubsection(Index index, uint32_t name_type, Offset subsection_size) = 0; virtual Result OnFunctionNamesCount(Index num_functions) = 0; virtual Result OnFunctionName(Index function_index, - std::string_view function_name) = 0; + nonstd::string_view function_name) = 0; virtual Result OnLocalNameSubsection(Index index, uint32_t name_type, Offset subsection_size) = 0; @@ -390,14 +390,14 @@ class BinaryReaderDelegate { Index num_locals) = 0; virtual Result OnLocalName(Index function_index, Index local_index, - std::string_view local_name) = 0; + nonstd::string_view local_name) = 0; virtual Result OnNameSubsection(Index index, NameSectionSubsection subsection_type, Offset subsection_size) = 0; virtual Result OnNameCount(Index num_names) = 0; virtual Result OnNameEntry(NameSectionSubsection type, Index index, - std::string_view name) = 0; + nonstd::string_view name) = 0; virtual Result EndNamesSection() = 0; /* Reloc section */ @@ -417,18 +417,18 @@ class BinaryReaderDelegate { uint32_t table_align_log2) = 0; virtual Result OnDylinkImportCount(Index count) = 0; virtual Result OnDylinkExportCount(Index count) = 0; - virtual Result OnDylinkImport(std::string_view module, - std::string_view name, + virtual Result OnDylinkImport(nonstd::string_view module, + nonstd::string_view name, uint32_t flags) = 0; - virtual Result OnDylinkExport(std::string_view name, uint32_t flags) = 0; + virtual Result OnDylinkExport(nonstd::string_view name, uint32_t flags) = 0; virtual Result OnDylinkNeededCount(Index count) = 0; - virtual Result OnDylinkNeeded(std::string_view so_name) = 0; + virtual Result OnDylinkNeeded(nonstd::string_view so_name) = 0; virtual Result EndDylinkSection() = 0; /* target_features section */ virtual Result BeginTargetFeaturesSection(Offset size) = 0; virtual Result OnFeatureCount(Index count) = 0; - virtual Result OnFeature(uint8_t prefix, std::string_view name) = 0; + virtual Result OnFeature(uint8_t prefix, nonstd::string_view name) = 0; virtual Result EndTargetFeaturesSection() = 0; /* Linking section */ @@ -436,38 +436,38 @@ class BinaryReaderDelegate { virtual Result OnSymbolCount(Index count) = 0; virtual Result OnDataSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index segment, uint32_t offset, uint32_t size) = 0; virtual Result OnFunctionSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index function_index) = 0; virtual Result OnGlobalSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index global_index) = 0; virtual Result OnSectionSymbol(Index index, uint32_t flags, Index section_index) = 0; virtual Result OnTagSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index tag_index) = 0; virtual Result OnTableSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index table_index) = 0; virtual Result OnSegmentInfoCount(Index count) = 0; virtual Result OnSegmentInfo(Index index, - std::string_view name, + nonstd::string_view name, Address alignment_log2, uint32_t flags) = 0; virtual Result OnInitFunctionCount(Index count) = 0; virtual Result OnInitFunction(uint32_t priority, Index function_index) = 0; virtual Result OnComdatCount(Index count) = 0; - virtual Result OnComdatBegin(std::string_view name, + virtual Result OnComdatBegin(nonstd::string_view name, uint32_t flags, Index count) = 0; virtual Result OnComdatEntry(ComdatType kind, Index index) = 0; @@ -480,7 +480,7 @@ class BinaryReaderDelegate { virtual Result EndTagSection() = 0; /* Code Metadata sections */ - virtual Result BeginCodeMetadataSection(std::string_view name, + virtual Result BeginCodeMetadataSection(nonstd::string_view name, Offset size) = 0; virtual Result OnCodeMetadataFuncCount(Index count) = 0; virtual Result OnCodeMetadataCount(Index function_index, Index count) = 0; diff --git a/third_party/wabt/include/wabt/binary-writer.h b/third_party/wabt/include/wabt/binary-writer.h index dedba1bdc..1efe976e6 100644 --- a/third_party/wabt/include/wabt/binary-writer.h +++ b/third_party/wabt/include/wabt/binary-writer.h @@ -49,7 +49,7 @@ Result WriteBinaryModule(Stream*, const Module*, const WriteBinaryOptions&); void WriteType(Stream* stream, Type type, const char* desc = nullptr); void WriteStr(Stream* stream, - std::string_view s, + nonstd::string_view s, const char* desc, PrintChars print_chars = PrintChars::No); diff --git a/third_party/wabt/include/wabt/binding-hash.h b/third_party/wabt/include/wabt/binding-hash.h index f6b948fcb..df55e32c5 100644 --- a/third_party/wabt/include/wabt/binding-hash.h +++ b/third_party/wabt/include/wabt/binding-hash.h @@ -19,7 +19,7 @@ #include #include -#include +#include "string_view.h" #include #include @@ -54,7 +54,7 @@ class BindingHash : public std::unordered_multimap { return iter != end() ? iter->second.index : kInvalidIndex; } - Index FindIndex(std::string_view name) const { + Index FindIndex(nonstd::string_view name) const { return FindIndex(std::string(name)); } diff --git a/third_party/wabt/include/wabt/common.h b/third_party/wabt/include/wabt/common.h index a8d492efa..999361256 100644 --- a/third_party/wabt/include/wabt/common.h +++ b/third_party/wabt/include/wabt/common.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include "string_view.h" #include #include @@ -213,7 +213,7 @@ struct Location { }; Location() : line(0), first_column(0), last_column(0) {} - Location(std::string_view filename, + Location(nonstd::string_view filename, int line, int first_column, int last_column) @@ -223,7 +223,7 @@ struct Location { last_column(last_column) {} explicit Location(size_t offset) : offset(offset) {} - std::string_view filename; + nonstd::string_view filename; union { // For text files. struct { @@ -391,7 +391,7 @@ struct Limits { enum { WABT_USE_NATURAL_ALIGNMENT = 0xFFFFFFFFFFFFFFFF }; -Result ReadFile(std::string_view filename, std::vector* out_data); +Result ReadFile(nonstd::string_view filename, std::vector* out_data); void InitStdio(); diff --git a/third_party/wabt/include/wabt/error.h b/third_party/wabt/include/wabt/error.h index 9ea55e95e..561f4c6ef 100644 --- a/third_party/wabt/include/wabt/error.h +++ b/third_party/wabt/include/wabt/error.h @@ -18,7 +18,7 @@ #define WABT_ERROR_H_ #include -#include +#include "string_view.h" #include #include "wabt/common.h" @@ -43,7 +43,7 @@ static WABT_INLINE const char* GetErrorLevelName(ErrorLevel error_level) { class Error { public: Error() : error_level(ErrorLevel::Error) {} - Error(ErrorLevel error_level, Location loc, std::string_view message) + Error(ErrorLevel error_level, Location loc, nonstd::string_view message) : error_level(error_level), loc(loc), message(message) {} ErrorLevel error_level; diff --git a/third_party/wabt/include/wabt/ir.h b/third_party/wabt/include/wabt/ir.h index 6bd9ffa38..90b8ca809 100644 --- a/third_party/wabt/include/wabt/ir.h +++ b/third_party/wabt/include/wabt/ir.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include "string_view.h" #include #include @@ -43,7 +43,7 @@ enum class VarType { struct Var { explicit Var(); explicit Var(Index index, const Location& loc); - explicit Var(std::string_view name, const Location& loc); + explicit Var(nonstd::string_view name, const Location& loc); Var(Var&&); Var(const Var&); Var& operator=(const Var&); @@ -65,7 +65,7 @@ struct Var { void set_index(Index); void set_name(std::string&&); - void set_name(std::string_view); + void set_name(nonstd::string_view); Location loc; @@ -240,7 +240,7 @@ class TypeEntry { protected: explicit TypeEntry(TypeEntryKind kind, - std::string_view name = std::string_view(), + nonstd::string_view name = nonstd::string_view(), const Location& loc = Location()) : loc(loc), name(name), kind_(kind) {} @@ -253,7 +253,7 @@ class FuncType : public TypeEntry { return entry->kind() == TypeEntryKind::Func; } - explicit FuncType(std::string_view name = std::string_view()) + explicit FuncType(nonstd::string_view name = nonstd::string_view()) : TypeEntry(TypeEntryKind::Func, name) {} Index GetNumParams() const { return sig.GetNumParams(); } @@ -276,7 +276,7 @@ class StructType : public TypeEntry { return entry->kind() == TypeEntryKind::Struct; } - explicit StructType(std::string_view name = std::string_view()) + explicit StructType(nonstd::string_view name = nonstd::string_view()) : TypeEntry(TypeEntryKind::Struct) {} std::vector fields; @@ -288,7 +288,7 @@ class ArrayType : public TypeEntry { return entry->kind() == TypeEntryKind::Array; } - explicit ArrayType(std::string_view name = std::string_view()) + explicit ArrayType(nonstd::string_view name = nonstd::string_view()) : TypeEntry(TypeEntryKind::Array) {} Field field; @@ -635,14 +635,14 @@ class CallIndirectExpr : public ExprMixin { class CodeMetadataExpr : public ExprMixin { public: - explicit CodeMetadataExpr(std::string_view name, + explicit CodeMetadataExpr(nonstd::string_view name, std::vector data, const Location& loc = Location()) : ExprMixin(loc), name(std::move(name)), data(std::move(data)) {} - std::string_view name; + nonstd::string_view name; std::vector data; }; @@ -757,7 +757,7 @@ class AtomicFenceExpr : public ExprMixin { }; struct Tag { - explicit Tag(std::string_view name) : name(name) {} + explicit Tag(nonstd::string_view name) : name(name) {} std::string name; FuncDeclaration decl; @@ -825,7 +825,7 @@ inline bool operator!=(const LocalTypes::const_iterator& lhs, } struct Func { - explicit Func(std::string_view name) : name(name) {} + explicit Func(nonstd::string_view name) : name(name) {} Type GetParamType(Index index) const { return decl.GetParamType(index); } Type GetResultType(Index index) const { return decl.GetResultType(index); } @@ -848,7 +848,7 @@ struct Func { }; struct Global { - explicit Global(std::string_view name) : name(name) {} + explicit Global(nonstd::string_view name) : name(name) {} std::string name; Type type = Type::Void; @@ -857,7 +857,7 @@ struct Global { }; struct Table { - explicit Table(std::string_view name) + explicit Table(nonstd::string_view name) : name(name), elem_type(Type::FuncRef) {} std::string name; @@ -868,7 +868,7 @@ struct Table { typedef std::vector ExprListVector; struct ElemSegment { - explicit ElemSegment(std::string_view name) : name(name) {} + explicit ElemSegment(nonstd::string_view name) : name(name) {} uint8_t GetFlags(const Module*) const; SegmentKind kind = SegmentKind::Active; @@ -880,14 +880,14 @@ struct ElemSegment { }; struct Memory { - explicit Memory(std::string_view name) : name(name) {} + explicit Memory(nonstd::string_view name) : name(name) {} std::string name; Limits page_limits; }; struct DataSegment { - explicit DataSegment(std::string_view name) : name(name) {} + explicit DataSegment(nonstd::string_view name) : name(name) {} uint8_t GetFlags(const Module*) const; SegmentKind kind = SegmentKind::Active; @@ -926,7 +926,7 @@ class ImportMixin : public Import { class FuncImport : public ImportMixin { public: - explicit FuncImport(std::string_view name = std::string_view()) + explicit FuncImport(nonstd::string_view name = nonstd::string_view()) : ImportMixin(), func(name) {} Func func; @@ -934,7 +934,7 @@ class FuncImport : public ImportMixin { class TableImport : public ImportMixin { public: - explicit TableImport(std::string_view name = std::string_view()) + explicit TableImport(nonstd::string_view name = nonstd::string_view()) : ImportMixin(), table(name) {} Table table; @@ -942,7 +942,7 @@ class TableImport : public ImportMixin { class MemoryImport : public ImportMixin { public: - explicit MemoryImport(std::string_view name = std::string_view()) + explicit MemoryImport(nonstd::string_view name = nonstd::string_view()) : ImportMixin(), memory(name) {} Memory memory; @@ -950,7 +950,7 @@ class MemoryImport : public ImportMixin { class GlobalImport : public ImportMixin { public: - explicit GlobalImport(std::string_view name = std::string_view()) + explicit GlobalImport(nonstd::string_view name = nonstd::string_view()) : ImportMixin(), global(name) {} Global global; @@ -958,7 +958,7 @@ class GlobalImport : public ImportMixin { class TagImport : public ImportMixin { public: - explicit TagImport(std::string_view name = std::string_view()) + explicit TagImport(nonstd::string_view name = nonstd::string_view()) : ImportMixin(), tag(name) {} Tag tag; @@ -1016,7 +1016,7 @@ class ModuleFieldMixin : public ModuleField { class FuncModuleField : public ModuleFieldMixin { public: explicit FuncModuleField(const Location& loc = Location(), - std::string_view name = std::string_view()) + nonstd::string_view name = nonstd::string_view()) : ModuleFieldMixin(loc), func(name) {} Func func; @@ -1025,7 +1025,7 @@ class FuncModuleField : public ModuleFieldMixin { class GlobalModuleField : public ModuleFieldMixin { public: explicit GlobalModuleField(const Location& loc = Location(), - std::string_view name = std::string_view()) + nonstd::string_view name = nonstd::string_view()) : ModuleFieldMixin(loc), global(name) {} Global global; @@ -1062,7 +1062,7 @@ class TypeModuleField : public ModuleFieldMixin { class TableModuleField : public ModuleFieldMixin { public: explicit TableModuleField(const Location& loc = Location(), - std::string_view name = std::string_view()) + nonstd::string_view name = nonstd::string_view()) : ModuleFieldMixin(loc), table(name) {} Table table; @@ -1072,7 +1072,7 @@ class ElemSegmentModuleField : public ModuleFieldMixin { public: explicit ElemSegmentModuleField(const Location& loc = Location(), - std::string_view name = std::string_view()) + nonstd::string_view name = nonstd::string_view()) : ModuleFieldMixin(loc), elem_segment(name) {} @@ -1082,7 +1082,7 @@ class ElemSegmentModuleField class MemoryModuleField : public ModuleFieldMixin { public: explicit MemoryModuleField(const Location& loc = Location(), - std::string_view name = std::string_view()) + nonstd::string_view name = nonstd::string_view()) : ModuleFieldMixin(loc), memory(name) {} Memory memory; @@ -1092,7 +1092,7 @@ class DataSegmentModuleField : public ModuleFieldMixin { public: explicit DataSegmentModuleField(const Location& loc = Location(), - std::string_view name = std::string_view()) + nonstd::string_view name = nonstd::string_view()) : ModuleFieldMixin(loc), data_segment(name) {} @@ -1102,7 +1102,7 @@ class DataSegmentModuleField class TagModuleField : public ModuleFieldMixin { public: explicit TagModuleField(const Location& loc = Location(), - std::string_view name = std::string_view()) + nonstd::string_view name = nonstd::string_view()) : ModuleFieldMixin(loc), tag(name) {} Tag tag; @@ -1134,7 +1134,7 @@ struct Module { Index GetGlobalIndex(const Var&) const; const Global* GetGlobal(const Var&) const; Global* GetGlobal(const Var&); - const Export* GetExport(std::string_view) const; + const Export* GetExport(nonstd::string_view) const; Tag* GetTag(const Var&) const; Index GetTagIndex(const Var&) const; const DataSegment* GetDataSegment(const Var&) const; @@ -1365,7 +1365,7 @@ typedef ActionCommandBase ActionCommand; class RegisterCommand : public CommandMixin { public: - RegisterCommand(std::string_view module_name, const Var& var) + RegisterCommand(nonstd::string_view module_name, const Var& var) : module_name(module_name), var(var) {} std::string module_name; diff --git a/third_party/wabt/include/wabt/literal.h b/third_party/wabt/include/wabt/literal.h index 5eb8f4b0d..e130d3f2d 100644 --- a/third_party/wabt/include/wabt/literal.h +++ b/third_party/wabt/include/wabt/literal.h @@ -76,46 +76,46 @@ Result ParseDouble(LiteralType literal_type, uint64_t* out_bits); // Same as above but taking a string_view -inline Result ParseInt8(std::string_view v, +inline Result ParseInt8(nonstd::string_view v, uint8_t* out, ParseIntType parse_type) { return ParseInt8(v.data(), v.data() + v.size(), out, parse_type); } -inline Result ParseInt16(std::string_view v, +inline Result ParseInt16(nonstd::string_view v, uint16_t* out, ParseIntType parse_type) { return ParseInt16(v.data(), v.data() + v.size(), out, parse_type); } -inline Result ParseInt32(std::string_view v, +inline Result ParseInt32(nonstd::string_view v, uint32_t* out, ParseIntType parse_type) { return ParseInt32(v.data(), v.data() + v.size(), out, parse_type); } -inline Result ParseInt64(std::string_view v, +inline Result ParseInt64(nonstd::string_view v, uint64_t* out, ParseIntType parse_type) { return ParseInt64(v.data(), v.data() + v.size(), out, parse_type); } -inline Result ParseUint64(std::string_view v, uint64_t* out) { +inline Result ParseUint64(nonstd::string_view v, uint64_t* out) { return ParseUint64(v.data(), v.data() + v.size(), out); } -inline Result ParseUint128(std::string_view v, v128* out) { +inline Result ParseUint128(nonstd::string_view v, v128* out) { return ParseUint128(v.data(), v.data() + v.size(), out); } inline Result ParseFloat(LiteralType literal_type, - std::string_view v, + nonstd::string_view v, uint32_t* out_bits) { return ParseFloat(literal_type, v.data(), v.data() + v.size(), out_bits); } inline Result ParseDouble(LiteralType literal_type, - std::string_view v, + nonstd::string_view v, uint64_t* out_bits) { return ParseDouble(literal_type, v.data(), v.data() + v.size(), out_bits); } diff --git a/third_party/wabt/include/wabt/shared-validator.h b/third_party/wabt/include/wabt/shared-validator.h index 154f26197..4baf12f4b 100644 --- a/third_party/wabt/include/wabt/shared-validator.h +++ b/third_party/wabt/include/wabt/shared-validator.h @@ -83,7 +83,7 @@ class SharedValidator { Result OnExport(const Location&, ExternalKind, Var item_var, - std::string_view name); + nonstd::string_view name); Result OnStart(const Location&, Var func_var); diff --git a/third_party/wabt/include/wabt/stream.h b/third_party/wabt/include/wabt/stream.h index 67f50975e..e8969ef2c 100644 --- a/third_party/wabt/include/wabt/stream.h +++ b/third_party/wabt/include/wabt/stream.h @@ -158,7 +158,7 @@ class Stream { }; struct OutputBuffer { - Result WriteToFile(std::string_view filename) const; + Result WriteToFile(nonstd::string_view filename) const; Result WriteToStdout() const; void clear() { data.clear(); } @@ -180,7 +180,7 @@ class MemoryStream : public Stream { void Clear(); - Result WriteToFile(std::string_view filename) { + Result WriteToFile(nonstd::string_view filename) { return buf_->WriteToFile(filename); } @@ -198,7 +198,7 @@ class MemoryStream : public Stream { class FileStream : public Stream { public: WABT_DISALLOW_COPY_AND_ASSIGN(FileStream); - explicit FileStream(std::string_view filename, Stream* log_stream = nullptr); + explicit FileStream(nonstd::string_view filename, Stream* log_stream = nullptr); explicit FileStream(FILE*, Stream* log_stream = nullptr); FileStream(FileStream&&); FileStream& operator=(FileStream&&); diff --git a/third_party/wabt/include/wabt/token.h b/third_party/wabt/include/wabt/token.h index 7d17e1066..aac1a124c 100644 --- a/third_party/wabt/include/wabt/token.h +++ b/third_party/wabt/include/wabt/token.h @@ -17,7 +17,7 @@ #ifndef WABT_TOKEN_H_ #define WABT_TOKEN_H_ -#include +#include "string_view.h" #include "wabt/literal.h" #include "wabt/opcode.h" @@ -26,10 +26,10 @@ namespace wabt { struct Literal { Literal() = default; - Literal(LiteralType type, std::string_view text) : type(type), text(text) {} + Literal(LiteralType type, nonstd::string_view text) : type(type), text(text) {} LiteralType type; - std::string_view text; + nonstd::string_view text; }; enum class TokenType { @@ -80,7 +80,7 @@ struct Token { Token() : token_type_(TokenType::Invalid) {} Token(Location, TokenType); Token(Location, TokenType, Type); - Token(Location, TokenType, std::string_view); + Token(Location, TokenType, nonstd::string_view); Token(Location, TokenType, Opcode); Token(Location, TokenType, const Literal&); @@ -95,7 +95,7 @@ struct Token { bool HasOpcode() const { return IsTokenTypeOpcode(token_type_); } bool HasLiteral() const { return IsTokenTypeLiteral(token_type_); } - std::string_view text() const { + nonstd::string_view text() const { assert(HasText()); return text_; } @@ -122,7 +122,7 @@ struct Token { TokenType token_type_; union { - std::string_view text_; + nonstd::string_view text_; Type type_; Opcode opcode_; Literal literal_; diff --git a/third_party/wabt/include/wabt/wast-lexer.h b/third_party/wabt/include/wabt/wast-lexer.h index 385032ca7..c735d8afb 100644 --- a/third_party/wabt/include/wabt/wast-lexer.h +++ b/third_party/wabt/include/wabt/wast-lexer.h @@ -38,10 +38,10 @@ class WastLexer { public: WABT_DISALLOW_COPY_AND_ASSIGN(WastLexer); - WastLexer(std::unique_ptr source, std::string_view filename); + WastLexer(std::unique_ptr source, nonstd::string_view filename); // Convenience functions. - static std::unique_ptr CreateBufferLexer(std::string_view filename, + static std::unique_ptr CreateBufferLexer(nonstd::string_view filename, const void* data, size_t size); @@ -57,7 +57,7 @@ class WastLexer { enum class CharClass { Reserved = 1, Keyword = 2, HexDigit = 4, Digit = 8 }; Location GetLocation(); - std::string_view GetText(size_t offset = 0); + nonstd::string_view GetText(size_t offset = 0); Token BareToken(TokenType); Token LiteralToken(TokenType, LiteralType); @@ -66,7 +66,7 @@ class WastLexer { int PeekChar(); int ReadChar(); bool MatchChar(char); - bool MatchString(std::string_view); + bool MatchString(nonstd::string_view); void Newline(); bool ReadBlockComment(WastParser*); // Returns false if EOF. bool ReadLineComment(); // Returns false if EOF. @@ -88,7 +88,7 @@ class WastLexer { Token GetHexNumberToken(TokenType); Token GetInfToken(); Token GetNanToken(); - Token GetNameEqNumToken(std::string_view name, TokenType); + Token GetNameEqNumToken(nonstd::string_view name, TokenType); Token GetIdToken(); Token GetKeywordToken(); Token GetReservedToken(); diff --git a/third_party/wabt/src/binary-reader-ir.cc b/third_party/wabt/src/binary-reader-ir.cc index 3f64157d3..3e13b6e77 100644 --- a/third_party/wabt/src/binary-reader-ir.cc +++ b/third_party/wabt/src/binary-reader-ir.cc @@ -107,30 +107,30 @@ class BinaryReaderIR : public BinaryReaderNop { Result OnImportCount(Index count) override; Result OnImportFunc(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index func_index, Index sig_index) override; Result OnImportTable(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index table_index, Type elem_type, const Limits* elem_limits) override; Result OnImportMemory(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index memory_index, const Limits* page_limits) override; Result OnImportGlobal(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index global_index, Type type, bool mutable_) override; Result OnImportTag(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index tag_index, Index sig_index) override; @@ -154,7 +154,7 @@ class BinaryReaderIR : public BinaryReaderNop { Result OnExport(Index index, ExternalKind kind, Index item_index, - std::string_view name) override; + nonstd::string_view name) override; Result OnStartFunction(Index func_index) override; @@ -298,17 +298,17 @@ class BinaryReaderIR : public BinaryReaderNop { const void* data, Address size) override; - Result OnModuleName(std::string_view module_name) override; + Result OnModuleName(nonstd::string_view module_name) override; Result OnFunctionNamesCount(Index num_functions) override; Result OnFunctionName(Index function_index, - std::string_view function_name) override; + nonstd::string_view function_name) override; Result OnLocalNameLocalCount(Index function_index, Index num_locals) override; Result OnLocalName(Index function_index, Index local_index, - std::string_view local_name) override; + nonstd::string_view local_name) override; Result OnNameEntry(NameSectionSubsection type, Index index, - std::string_view name) override; + nonstd::string_view name) override; Result BeginTagSection(Offset size) override { return Result::Ok; } Result OnTagCount(Index count) override { return Result::Ok; } @@ -317,34 +317,34 @@ class BinaryReaderIR : public BinaryReaderNop { Result OnDataSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index segment, uint32_t offset, uint32_t size) override; Result OnFunctionSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index func_index) override; Result OnGlobalSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index global_index) override; Result OnSectionSymbol(Index index, uint32_t flags, Index section_index) override; /* Code Metadata sections */ - Result BeginCodeMetadataSection(std::string_view name, Offset size) override; + Result BeginCodeMetadataSection(nonstd::string_view name, Offset size) override; Result OnCodeMetadataFuncCount(Index count) override; Result OnCodeMetadataCount(Index function_index, Index count) override; Result OnCodeMetadata(Offset offset, const void* data, Address size) override; Result OnTagSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index tag_index) override; Result OnTableSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index table_index) override; private: @@ -363,14 +363,14 @@ class BinaryReaderIR : public BinaryReaderNop { Result AppendCatch(Catch&& catch_); void SetFuncDeclaration(FuncDeclaration* decl, Var var); void SetBlockDeclaration(BlockDeclaration* decl, Type sig_type); - Result SetMemoryName(Index index, std::string_view name); - Result SetTableName(Index index, std::string_view name); - Result SetFunctionName(Index index, std::string_view name); - Result SetTypeName(Index index, std::string_view name); - Result SetGlobalName(Index index, std::string_view name); - Result SetDataSegmentName(Index index, std::string_view name); - Result SetElemSegmentName(Index index, std::string_view name); - Result SetTagName(Index index, std::string_view name); + Result SetMemoryName(Index index, nonstd::string_view name); + Result SetTableName(Index index, nonstd::string_view name); + Result SetFunctionName(Index index, nonstd::string_view name); + Result SetTypeName(Index index, nonstd::string_view name); + Result SetGlobalName(Index index, nonstd::string_view name); + Result SetDataSegmentName(Index index, nonstd::string_view name); + Result SetElemSegmentName(Index index, nonstd::string_view name); + Result SetTagName(Index index, nonstd::string_view name); std::string GetUniqueName(BindingHash* bindings, const std::string& original_name); @@ -383,7 +383,7 @@ class BinaryReaderIR : public BinaryReaderNop { const char* filename_; CodeMetadataExprQueue code_metadata_queue_; - std::string_view current_metadata_name_; + nonstd::string_view current_metadata_name_; }; BinaryReaderIR::BinaryReaderIR(Module* out_module, @@ -540,13 +540,13 @@ Result BinaryReaderIR::OnImportCount(Index count) { } Result BinaryReaderIR::OnImportFunc(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index func_index, Index sig_index) { auto import = MakeUnique(); - import->module_name = module_name; - import->field_name = field_name; + import->module_name = nonstd::to_string(module_name); + import->field_name = nonstd::to_string(field_name); SetFuncDeclaration(&import->func.decl, Var(sig_index, GetLocation())); module_->AppendField( MakeUnique(std::move(import), GetLocation())); @@ -554,14 +554,14 @@ Result BinaryReaderIR::OnImportFunc(Index import_index, } Result BinaryReaderIR::OnImportTable(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index table_index, Type elem_type, const Limits* elem_limits) { auto import = MakeUnique(); - import->module_name = module_name; - import->field_name = field_name; + import->module_name = nonstd::to_string(module_name); + import->field_name = nonstd::to_string(field_name); import->table.elem_limits = *elem_limits; import->table.elem_type = elem_type; module_->AppendField( @@ -570,13 +570,13 @@ Result BinaryReaderIR::OnImportTable(Index import_index, } Result BinaryReaderIR::OnImportMemory(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index memory_index, const Limits* page_limits) { auto import = MakeUnique(); - import->module_name = module_name; - import->field_name = field_name; + import->module_name = nonstd::to_string(module_name); + import->field_name = nonstd::to_string(field_name); import->memory.page_limits = *page_limits; module_->AppendField( MakeUnique(std::move(import), GetLocation())); @@ -584,14 +584,14 @@ Result BinaryReaderIR::OnImportMemory(Index import_index, } Result BinaryReaderIR::OnImportGlobal(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index global_index, Type type, bool mutable_) { auto import = MakeUnique(); - import->module_name = module_name; - import->field_name = field_name; + import->module_name = nonstd::to_string(module_name); + import->field_name = nonstd::to_string(field_name); import->global.type = type; import->global.mutable_ = mutable_; module_->AppendField( @@ -600,13 +600,13 @@ Result BinaryReaderIR::OnImportGlobal(Index import_index, } Result BinaryReaderIR::OnImportTag(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index tag_index, Index sig_index) { auto import = MakeUnique(); - import->module_name = module_name; - import->field_name = field_name; + import->module_name = nonstd::to_string(module_name); + import->field_name = nonstd::to_string(field_name); SetFuncDeclaration(&import->tag.decl, Var(sig_index, GetLocation())); module_->AppendField( MakeUnique(std::move(import), GetLocation())); @@ -697,10 +697,10 @@ Result BinaryReaderIR::OnExportCount(Index count) { Result BinaryReaderIR::OnExport(Index index, ExternalKind kind, Index item_index, - std::string_view name) { + nonstd::string_view name) { auto field = MakeUnique(GetLocation()); Export& export_ = field->export_; - export_.name = name; + export_.name = nonstd::to_string(name); export_.var = Var(item_index, GetLocation()); export_.kind = kind; module_->AppendField(std::move(field)); @@ -1358,11 +1358,11 @@ Result BinaryReaderIR::OnFunctionNamesCount(Index count) { return Result::Ok; } -static std::string MakeDollarName(std::string_view name) { +static std::string MakeDollarName(nonstd::string_view name) { return std::string("$") + std::string(name); } -Result BinaryReaderIR::OnModuleName(std::string_view name) { +Result BinaryReaderIR::OnModuleName(nonstd::string_view name) { if (name.empty()) { return Result::Ok; } @@ -1371,7 +1371,7 @@ Result BinaryReaderIR::OnModuleName(std::string_view name) { return Result::Ok; } -Result BinaryReaderIR::SetGlobalName(Index index, std::string_view name) { +Result BinaryReaderIR::SetGlobalName(Index index, nonstd::string_view name) { if (name.empty()) { return Result::Ok; } @@ -1387,7 +1387,7 @@ Result BinaryReaderIR::SetGlobalName(Index index, std::string_view name) { return Result::Ok; } -Result BinaryReaderIR::SetFunctionName(Index index, std::string_view name) { +Result BinaryReaderIR::SetFunctionName(Index index, nonstd::string_view name) { if (name.empty()) { return Result::Ok; } @@ -1403,7 +1403,7 @@ Result BinaryReaderIR::SetFunctionName(Index index, std::string_view name) { return Result::Ok; } -Result BinaryReaderIR::SetTypeName(Index index, std::string_view name) { +Result BinaryReaderIR::SetTypeName(Index index, nonstd::string_view name) { if (name.empty()) { return Result::Ok; } @@ -1419,7 +1419,7 @@ Result BinaryReaderIR::SetTypeName(Index index, std::string_view name) { return Result::Ok; } -Result BinaryReaderIR::SetTableName(Index index, std::string_view name) { +Result BinaryReaderIR::SetTableName(Index index, nonstd::string_view name) { if (name.empty()) { return Result::Ok; } @@ -1435,7 +1435,7 @@ Result BinaryReaderIR::SetTableName(Index index, std::string_view name) { return Result::Ok; } -Result BinaryReaderIR::SetDataSegmentName(Index index, std::string_view name) { +Result BinaryReaderIR::SetDataSegmentName(Index index, nonstd::string_view name) { if (name.empty()) { return Result::Ok; } @@ -1451,7 +1451,7 @@ Result BinaryReaderIR::SetDataSegmentName(Index index, std::string_view name) { return Result::Ok; } -Result BinaryReaderIR::SetElemSegmentName(Index index, std::string_view name) { +Result BinaryReaderIR::SetElemSegmentName(Index index, nonstd::string_view name) { if (name.empty()) { return Result::Ok; } @@ -1467,7 +1467,7 @@ Result BinaryReaderIR::SetElemSegmentName(Index index, std::string_view name) { return Result::Ok; } -Result BinaryReaderIR::SetMemoryName(Index index, std::string_view name) { +Result BinaryReaderIR::SetMemoryName(Index index, nonstd::string_view name) { if (name.empty()) { return Result::Ok; } @@ -1483,7 +1483,7 @@ Result BinaryReaderIR::SetMemoryName(Index index, std::string_view name) { return Result::Ok; } -Result BinaryReaderIR::SetTagName(Index index, std::string_view name) { +Result BinaryReaderIR::SetTagName(Index index, nonstd::string_view name) { if (name.empty()) { return Result::Ok; } @@ -1499,13 +1499,13 @@ Result BinaryReaderIR::SetTagName(Index index, std::string_view name) { return Result::Ok; } -Result BinaryReaderIR::OnFunctionName(Index index, std::string_view name) { +Result BinaryReaderIR::OnFunctionName(Index index, nonstd::string_view name) { return SetFunctionName(index, name); } Result BinaryReaderIR::OnNameEntry(NameSectionSubsection type, Index index, - std::string_view name) { + nonstd::string_view name) { switch (type) { // TODO(sbc): remove OnFunctionName in favor of just using // OnNameEntry so that this works @@ -1552,7 +1552,7 @@ Result BinaryReaderIR::OnLocalNameLocalCount(Index index, Index count) { return Result::Ok; } -Result BinaryReaderIR::BeginCodeMetadataSection(std::string_view name, +Result BinaryReaderIR::BeginCodeMetadataSection(nonstd::string_view name, Offset size) { current_metadata_name_ = name; return Result::Ok; @@ -1581,7 +1581,7 @@ Result BinaryReaderIR::OnCodeMetadata(Offset offset, Result BinaryReaderIR::OnLocalName(Index func_index, Index local_index, - std::string_view name) { + nonstd::string_view name) { if (name.empty()) { return Result::Ok; } @@ -1602,7 +1602,7 @@ Result BinaryReaderIR::OnTagType(Index index, Index sig_index) { Result BinaryReaderIR::OnDataSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index segment, uint32_t offset, uint32_t size) { @@ -1632,7 +1632,7 @@ Result BinaryReaderIR::OnDataSymbol(Index index, Result BinaryReaderIR::OnFunctionSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index func_index) { if (name.empty()) { return Result::Ok; @@ -1655,7 +1655,7 @@ Result BinaryReaderIR::OnFunctionSymbol(Index index, Result BinaryReaderIR::OnGlobalSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index global_index) { return SetGlobalName(global_index, name); } @@ -1668,7 +1668,7 @@ Result BinaryReaderIR::OnSectionSymbol(Index index, Result BinaryReaderIR::OnTagSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index tag_index) { if (name.empty()) { return Result::Ok; @@ -1687,7 +1687,7 @@ Result BinaryReaderIR::OnTagSymbol(Index index, Result BinaryReaderIR::OnTableSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index table_index) { return SetTableName(table_index, name); } diff --git a/third_party/wabt/src/binary-reader-logging.cc b/third_party/wabt/src/binary-reader-logging.cc index e6241093e..833cdfaab 100644 --- a/third_party/wabt/src/binary-reader-logging.cc +++ b/third_party/wabt/src/binary-reader-logging.cc @@ -132,7 +132,7 @@ Result BinaryReaderLogging::BeginSection(Index section_index, Result BinaryReaderLogging::BeginCustomSection(Index section_index, Offset size, - std::string_view section_name) { + nonstd::string_view section_name) { LOGF("BeginCustomSection('" PRIstringview "', size: %" PRIzd ")\n", WABT_PRINTF_STRING_VIEW_ARG(section_name), size); Indent(); @@ -177,8 +177,8 @@ Result BinaryReaderLogging::OnArrayType(Index index, TypeMut field) { Result BinaryReaderLogging::OnImport(Index index, ExternalKind kind, - std::string_view module_name, - std::string_view field_name) { + nonstd::string_view module_name, + nonstd::string_view field_name) { LOGF("OnImport(index: %" PRIindex ", kind: %s, module: \"" PRIstringview "\", field: \"" PRIstringview "\")\n", index, GetKindName(kind), WABT_PRINTF_STRING_VIEW_ARG(module_name), @@ -187,8 +187,8 @@ Result BinaryReaderLogging::OnImport(Index index, } Result BinaryReaderLogging::OnImportFunc(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index func_index, Index sig_index) { LOGF("OnImportFunc(import_index: %" PRIindex ", func_index: %" PRIindex @@ -199,8 +199,8 @@ Result BinaryReaderLogging::OnImportFunc(Index import_index, } Result BinaryReaderLogging::OnImportTable(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index table_index, Type elem_type, const Limits* elem_limits) { @@ -214,8 +214,8 @@ Result BinaryReaderLogging::OnImportTable(Index import_index, } Result BinaryReaderLogging::OnImportMemory(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index memory_index, const Limits* page_limits) { char buf[100]; @@ -228,8 +228,8 @@ Result BinaryReaderLogging::OnImportMemory(Index import_index, } Result BinaryReaderLogging::OnImportGlobal(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index global_index, Type type, bool mutable_) { @@ -243,8 +243,8 @@ Result BinaryReaderLogging::OnImportGlobal(Index import_index, } Result BinaryReaderLogging::OnImportTag(Index import_index, - std::string_view module_name, - std::string_view field_name, + nonstd::string_view module_name, + nonstd::string_view field_name, Index tag_index, Index sig_index) { LOGF("OnImportTag(import_index: %" PRIindex ", tag_index: %" PRIindex @@ -280,7 +280,7 @@ Result BinaryReaderLogging::BeginGlobal(Index index, Type type, bool mutable_) { Result BinaryReaderLogging::OnExport(Index index, ExternalKind kind, Index item_index, - std::string_view name) { + nonstd::string_view name) { LOGF("OnExport(index: %" PRIindex ", kind: %s, item_index: %" PRIindex ", name: \"" PRIstringview "\")\n", index, GetKindName(kind), item_index, WABT_PRINTF_STRING_VIEW_ARG(name)); @@ -434,7 +434,7 @@ Result BinaryReaderLogging::OnModuleNameSubsection(Index index, return reader_->OnModuleNameSubsection(index, name_type, subsection_size); } -Result BinaryReaderLogging::OnModuleName(std::string_view name) { +Result BinaryReaderLogging::OnModuleName(nonstd::string_view name) { LOGF("OnModuleName(name: \"" PRIstringview "\")\n", WABT_PRINTF_STRING_VIEW_ARG(name)); return reader_->OnModuleName(name); @@ -449,7 +449,7 @@ Result BinaryReaderLogging::OnFunctionNameSubsection(Index index, return reader_->OnFunctionNameSubsection(index, name_type, subsection_size); } -Result BinaryReaderLogging::OnFunctionName(Index index, std::string_view name) { +Result BinaryReaderLogging::OnFunctionName(Index index, nonstd::string_view name) { LOGF("OnFunctionName(index: %" PRIindex ", name: \"" PRIstringview "\")\n", index, WABT_PRINTF_STRING_VIEW_ARG(name)); return reader_->OnFunctionName(index, name); @@ -466,7 +466,7 @@ Result BinaryReaderLogging::OnLocalNameSubsection(Index index, Result BinaryReaderLogging::OnLocalName(Index func_index, Index local_index, - std::string_view name) { + nonstd::string_view name) { LOGF("OnLocalName(func_index: %" PRIindex ", local_index: %" PRIindex ", name: \"" PRIstringview "\")\n", func_index, local_index, WABT_PRINTF_STRING_VIEW_ARG(name)); @@ -484,7 +484,7 @@ Result BinaryReaderLogging::OnNameSubsection( Result BinaryReaderLogging::OnNameEntry(NameSectionSubsection type, Index index, - std::string_view name) { + nonstd::string_view name) { LOGF("OnNameEntry(type: %s, index: %" PRIindex ", name: \"" PRIstringview "\")\n", GetNameSectionSubsectionName(type), index, @@ -503,21 +503,21 @@ Result BinaryReaderLogging::OnDylinkInfo(uint32_t mem_size, return reader_->OnDylinkInfo(mem_size, mem_align, table_size, table_align); } -Result BinaryReaderLogging::OnDylinkNeeded(std::string_view so_name) { +Result BinaryReaderLogging::OnDylinkNeeded(nonstd::string_view so_name) { LOGF("OnDylinkNeeded(name: " PRIstringview ")\n", WABT_PRINTF_STRING_VIEW_ARG(so_name)); return reader_->OnDylinkNeeded(so_name); } -Result BinaryReaderLogging::OnDylinkExport(std::string_view name, +Result BinaryReaderLogging::OnDylinkExport(nonstd::string_view name, uint32_t flags) { LOGF("OnDylinkExport(name: " PRIstringview ", flags: 0x%x)\n", WABT_PRINTF_STRING_VIEW_ARG(name), flags); return reader_->OnDylinkExport(name, flags); } -Result BinaryReaderLogging::OnDylinkImport(std::string_view module, - std::string_view name, +Result BinaryReaderLogging::OnDylinkImport(nonstd::string_view module, + nonstd::string_view name, uint32_t flags) { LOGF("OnDylinkImport(module: " PRIstringview ", name: " PRIstringview ", flags: 0x%x)\n", @@ -543,7 +543,7 @@ Result BinaryReaderLogging::OnReloc(RelocType type, return reader_->OnReloc(type, offset, index, addend); } -Result BinaryReaderLogging::OnFeature(uint8_t prefix, std::string_view name) { +Result BinaryReaderLogging::OnFeature(uint8_t prefix, nonstd::string_view name) { LOGF("OnFeature(prefix: '%c', name: '" PRIstringview "')\n", prefix, WABT_PRINTF_STRING_VIEW_ARG(name)); return reader_->OnFeature(prefix, name); @@ -551,7 +551,7 @@ Result BinaryReaderLogging::OnFeature(uint8_t prefix, std::string_view name) { Result BinaryReaderLogging::OnDataSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index segment, uint32_t offset, uint32_t size) { @@ -562,7 +562,7 @@ Result BinaryReaderLogging::OnDataSymbol(Index index, Result BinaryReaderLogging::OnFunctionSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index func_index) { LOGF("OnFunctionSymbol(name: " PRIstringview " flags: 0x%x index: %" PRIindex ")\n", @@ -572,7 +572,7 @@ Result BinaryReaderLogging::OnFunctionSymbol(Index index, Result BinaryReaderLogging::OnGlobalSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index global_index) { LOGF("OnGlobalSymbol(name: " PRIstringview " flags: 0x%x index: %" PRIindex ")\n", @@ -590,7 +590,7 @@ Result BinaryReaderLogging::OnSectionSymbol(Index index, Result BinaryReaderLogging::OnTagSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index tag_index) { LOGF("OnTagSymbol(name: " PRIstringview " flags: 0x%x index: %" PRIindex ")\n", @@ -600,7 +600,7 @@ Result BinaryReaderLogging::OnTagSymbol(Index index, Result BinaryReaderLogging::OnTableSymbol(Index index, uint32_t flags, - std::string_view name, + nonstd::string_view name, Index table_index) { LOGF("OnTableSymbol(name: " PRIstringview " flags: 0x%x index: %" PRIindex ")\n", @@ -609,7 +609,7 @@ Result BinaryReaderLogging::OnTableSymbol(Index index, } Result BinaryReaderLogging::OnSegmentInfo(Index index, - std::string_view name, + nonstd::string_view name, Address alignment, uint32_t flags) { LOGF("OnSegmentInfo(%d name: " PRIstringview ", alignment: %" PRIaddress @@ -624,7 +624,7 @@ Result BinaryReaderLogging::OnInitFunction(uint32_t priority, return reader_->OnInitFunction(priority, func_index); } -Result BinaryReaderLogging::OnComdatBegin(std::string_view name, +Result BinaryReaderLogging::OnComdatBegin(nonstd::string_view name, uint32_t flags, Index count) { LOGF("OnComdatBegin(" PRIstringview ", flags: %d, count: %" PRIindex ")\n", @@ -638,7 +638,7 @@ Result BinaryReaderLogging::OnComdatEntry(ComdatType kind, Index index) { return reader_->OnComdatEntry(kind, index); } -Result BinaryReaderLogging::BeginCodeMetadataSection(std::string_view name, +Result BinaryReaderLogging::BeginCodeMetadataSection(nonstd::string_view name, Offset size) { LOGF("BeginCodeMetadataSection('" PRIstringview "', size:%" PRIzd ")\n", WABT_PRINTF_STRING_VIEW_ARG(name), size); @@ -648,7 +648,7 @@ Result BinaryReaderLogging::BeginCodeMetadataSection(std::string_view name, Result BinaryReaderLogging::OnCodeMetadata(Offset code_offset, const void* data, Address size) { - std::string_view content(static_cast(data), size); + nonstd::string_view content(static_cast(data), size); LOGF("OnCodeMetadata(offset: %" PRIzd ", data: \"" PRIstringview "\")\n", code_offset, WABT_PRINTF_STRING_VIEW_ARG(content)); return reader_->OnCodeMetadata(code_offset, data, size); diff --git a/third_party/wabt/src/binary-reader.cc b/third_party/wabt/src/binary-reader.cc index abdba30bb..4c3ebd8c7 100644 --- a/third_party/wabt/src/binary-reader.cc +++ b/third_party/wabt/src/binary-reader.cc @@ -111,7 +111,7 @@ class BinaryReader { Result ReadRefType(Type* out_value, const char* desc) WABT_WARN_UNUSED; Result ReadExternalKind(ExternalKind* out_value, const char* desc) WABT_WARN_UNUSED; - Result ReadStr(std::string_view* out_str, const char* desc) WABT_WARN_UNUSED; + Result ReadStr(nonstd::string_view* out_str, const char* desc) WABT_WARN_UNUSED; Result ReadBytes(const void** out_data, Address* out_data_size, const char* desc) WABT_WARN_UNUSED; @@ -160,7 +160,7 @@ class BinaryReader { Result ReadDylink0Section(Offset section_size) WABT_WARN_UNUSED; Result ReadTargetFeaturesSections(Offset section_size) WABT_WARN_UNUSED; Result ReadLinkingSection(Offset section_size) WABT_WARN_UNUSED; - Result ReadCodeMetadataSection(std::string_view name, + Result ReadCodeMetadataSection(nonstd::string_view name, Offset section_size) WABT_WARN_UNUSED; Result ReadCustomSection(Index section_index, Offset section_size) WABT_WARN_UNUSED; @@ -378,14 +378,14 @@ Result BinaryReader::ReadExternalKind(ExternalKind* out_value, return Result::Ok; } -Result BinaryReader::ReadStr(std::string_view* out_str, const char* desc) { +Result BinaryReader::ReadStr(nonstd::string_view* out_str, const char* desc) { uint32_t str_len = 0; CHECK_RESULT(ReadU32Leb128(&str_len, "string length")); ERROR_UNLESS(state_.offset + str_len <= read_end_, "unable to read string: %s", desc); - *out_str = std::string_view( + *out_str = nonstd::string_view( reinterpret_cast(state_.data) + state_.offset, str_len); state_.offset += str_len; @@ -1883,7 +1883,7 @@ Result BinaryReader::ReadNameSection(Offset section_size) { case NameSectionSubsection::Module: CALLBACK(OnModuleNameSubsection, i, name_type, subsection_size); if (subsection_size) { - std::string_view name; + nonstd::string_view name; CHECK_RESULT(ReadStr(&name, "module name")); CALLBACK(OnModuleName, name); } @@ -1898,7 +1898,7 @@ Result BinaryReader::ReadNameSection(Offset section_size) { for (Index j = 0; j < num_names; ++j) { Index function_index; - std::string_view function_name; + nonstd::string_view function_name; CHECK_RESULT(ReadIndex(&function_index, "function index")); ERROR_UNLESS(function_index != last_function_index, @@ -1937,7 +1937,7 @@ Result BinaryReader::ReadNameSection(Offset section_size) { Index last_local_index = kInvalidIndex; for (Index k = 0; k < num_locals; ++k) { Index local_index; - std::string_view local_name; + nonstd::string_view local_name; CHECK_RESULT(ReadIndex(&local_index, "named index")); ERROR_UNLESS(local_index != last_local_index, @@ -1970,7 +1970,7 @@ Result BinaryReader::ReadNameSection(Offset section_size) { CALLBACK(OnNameCount, num_names); for (Index j = 0; j < num_names; ++j) { Index index; - std::string_view name; + nonstd::string_view name; CHECK_RESULT(ReadIndex(&index, "index")); CHECK_RESULT(ReadStr(&name, "name")); @@ -2080,7 +2080,7 @@ Result BinaryReader::ReadDylink0Section(Offset section_size) { CHECK_RESULT(ReadU32Leb128(&count, "needed_dynlibs")); CALLBACK(OnDylinkNeededCount, count); while (count--) { - std::string_view so_name; + nonstd::string_view so_name; CHECK_RESULT(ReadStr(&so_name, "dylib so_name")); CALLBACK(OnDylinkNeeded, so_name); } @@ -2090,8 +2090,8 @@ Result BinaryReader::ReadDylink0Section(Offset section_size) { CALLBACK(OnDylinkImportCount, count); for (Index i = 0; i < count; ++i) { uint32_t flags = 0; - std::string_view module; - std::string_view field; + nonstd::string_view module; + nonstd::string_view field; CHECK_RESULT(ReadStr(&module, "module")); CHECK_RESULT(ReadStr(&field, "field")); CHECK_RESULT(ReadU32Leb128(&flags, "flags")); @@ -2103,7 +2103,7 @@ Result BinaryReader::ReadDylink0Section(Offset section_size) { CALLBACK(OnDylinkExportCount, count); for (Index i = 0; i < count; ++i) { uint32_t flags = 0; - std::string_view name; + nonstd::string_view name; CHECK_RESULT(ReadStr(&name, "name")); CHECK_RESULT(ReadU32Leb128(&flags, "flags")); CALLBACK(OnDylinkExport, name, flags); @@ -2140,7 +2140,7 @@ Result BinaryReader::ReadDylinkSection(Offset section_size) { CHECK_RESULT(ReadU32Leb128(&count, "needed_dynlibs")); CALLBACK(OnDylinkNeededCount, count); while (count--) { - std::string_view so_name; + nonstd::string_view so_name; CHECK_RESULT(ReadStr(&so_name, "dylib so_name")); CALLBACK(OnDylinkNeeded, so_name); } @@ -2156,7 +2156,7 @@ Result BinaryReader::ReadTargetFeaturesSections(Offset section_size) { CALLBACK(OnFeatureCount, count); while (count--) { uint8_t prefix; - std::string_view name; + nonstd::string_view name; CHECK_RESULT(ReadU8(&prefix, "prefix")); CHECK_RESULT(ReadStr(&name, "feature name")); CALLBACK(OnFeature, prefix, name); @@ -2187,7 +2187,7 @@ Result BinaryReader::ReadLinkingSection(Offset section_size) { CHECK_RESULT(ReadU32Leb128(&count, "sym count")); CALLBACK(OnSymbolCount, count); for (Index i = 0; i < count; ++i) { - std::string_view name; + nonstd::string_view name; uint32_t flags = 0; uint32_t kind = 0; CHECK_RESULT(ReadU32Leb128(&kind, "sym type")); @@ -2247,7 +2247,7 @@ Result BinaryReader::ReadLinkingSection(Offset section_size) { CHECK_RESULT(ReadU32Leb128(&count, "info count")); CALLBACK(OnSegmentInfoCount, count); for (Index i = 0; i < count; i++) { - std::string_view name; + nonstd::string_view name; Address alignment_log2; uint32_t flags; CHECK_RESULT(ReadStr(&name, "segment name")); @@ -2273,7 +2273,7 @@ Result BinaryReader::ReadLinkingSection(Offset section_size) { while (count--) { uint32_t flags; uint32_t entry_count; - std::string_view name; + nonstd::string_view name; CHECK_RESULT(ReadStr(&name, "comdat name")); CHECK_RESULT(ReadU32Leb128(&flags, "flags")); CHECK_RESULT(ReadU32Leb128(&entry_count, "entry count")); @@ -2326,7 +2326,7 @@ Result BinaryReader::ReadTagSection(Offset section_size) { return Result::Ok; } -Result BinaryReader::ReadCodeMetadataSection(std::string_view name, +Result BinaryReader::ReadCodeMetadataSection(nonstd::string_view name, Offset section_size) { CALLBACK(BeginCodeMetadataSection, name, section_size); @@ -2379,7 +2379,7 @@ Result BinaryReader::ReadCodeMetadataSection(std::string_view name, Result BinaryReader::ReadCustomSection(Index section_index, Offset section_size) { - std::string_view section_name; + nonstd::string_view section_name; CHECK_RESULT(ReadStr(§ion_name, "section name")); CALLBACK(BeginCustomSection, section_index, section_size, section_name); ValueRestoreGuard guard(this); @@ -2401,7 +2401,7 @@ Result BinaryReader::ReadCustomSection(Index section_index, CHECK_RESULT(ReadLinkingSection(section_size)); } else if (options_.features.code_metadata_enabled() && section_name.find(WABT_BINARY_SECTION_CODE_METADATA) == 0) { - std::string_view metadata_name = section_name; + nonstd::string_view metadata_name = section_name; metadata_name.remove_prefix(sizeof(WABT_BINARY_SECTION_CODE_METADATA) - 1); CHECK_RESULT(ReadCodeMetadataSection(metadata_name, section_size)); } else { @@ -2508,9 +2508,9 @@ Result BinaryReader::ReadImportSection(Offset section_size) { CHECK_RESULT(ReadCount(&num_imports, "import count")); CALLBACK(OnImportCount, num_imports); for (Index i = 0; i < num_imports; ++i) { - std::string_view module_name; + nonstd::string_view module_name; CHECK_RESULT(ReadStr(&module_name, "import module name")); - std::string_view field_name; + nonstd::string_view field_name; CHECK_RESULT(ReadStr(&field_name, "import field name")); uint8_t kind; @@ -2649,7 +2649,7 @@ Result BinaryReader::ReadExportSection(Offset section_size) { CHECK_RESULT(ReadCount(&num_exports, "export count")); CALLBACK(OnExportCount, num_exports); for (Index i = 0; i < num_exports; ++i) { - std::string_view name; + nonstd::string_view name; CHECK_RESULT(ReadStr(&name, "export item name")); ExternalKind kind; diff --git a/third_party/wabt/src/binary-writer.cc b/third_party/wabt/src/binary-writer.cc index 93db5b196..5467b8c2a 100644 --- a/third_party/wabt/src/binary-writer.cc +++ b/third_party/wabt/src/binary-writer.cc @@ -22,7 +22,7 @@ #include #include #include -#include +#include "string_view.h" #include #include "wabt/config.h" @@ -40,7 +40,7 @@ namespace wabt { void WriteStr(Stream* stream, - std::string_view s, + nonstd::string_view s, const char* desc, PrintChars print_chars) { WriteU32Leb128(stream, s.length(), "string length"); @@ -82,8 +82,8 @@ void WriteLimits(Stream* stream, const Limits* limits) { } } -void WriteDebugName(Stream* stream, std::string_view name, const char* desc) { - std::string_view stripped_name = name; +void WriteDebugName(Stream* stream, nonstd::string_view name, const char* desc) { + nonstd::string_view stripped_name = name; if (!stripped_name.empty()) { // Strip leading $ from name assert(stripped_name.front() == '$'); @@ -141,7 +141,7 @@ class Symbol { private: SymbolType type_; - std::string_view name_; + nonstd::string_view name_; uint8_t flags_; union { Function function_; @@ -153,21 +153,21 @@ class Symbol { }; public: - Symbol(const std::string_view& name, uint8_t flags, const Function& f) + Symbol(const nonstd::string_view& name, uint8_t flags, const Function& f) : type_(Function::type), name_(name), flags_(flags), function_(f) {} - Symbol(const std::string_view& name, uint8_t flags, const Data& d) + Symbol(const nonstd::string_view& name, uint8_t flags, const Data& d) : type_(Data::type), name_(name), flags_(flags), data_(d) {} - Symbol(const std::string_view& name, uint8_t flags, const Global& g) + Symbol(const nonstd::string_view& name, uint8_t flags, const Global& g) : type_(Global::type), name_(name), flags_(flags), global_(g) {} - Symbol(const std::string_view& name, uint8_t flags, const Section& s) + Symbol(const nonstd::string_view& name, uint8_t flags, const Section& s) : type_(Section::type), name_(name), flags_(flags), section_(s) {} - Symbol(const std::string_view& name, uint8_t flags, const Tag& e) + Symbol(const nonstd::string_view& name, uint8_t flags, const Tag& e) : type_(Tag::type), name_(name), flags_(flags), tag_(e) {} - Symbol(const std::string_view& name, uint8_t flags, const Table& t) + Symbol(const nonstd::string_view& name, uint8_t flags, const Table& t) : type_(Table::type), name_(name), flags_(flags), table_(t) {} SymbolType type() const { return type_; } - const std::string_view& name() const { return name_; } + const nonstd::string_view& name() const { return name_; } uint8_t flags() const { return flags_; } SymbolVisibility visibility() const { @@ -226,9 +226,9 @@ class SymbolTable { std::vector tables_; std::vector globals_; - std::set seen_names_; + std::set seen_names_; - Result EnsureUnique(const std::string_view& name) { + Result EnsureUnique(const nonstd::string_view& name) { if (seen_names_.count(name)) { fprintf(stderr, "error: duplicate symbol when writing relocatable " @@ -242,7 +242,7 @@ class SymbolTable { template Result AddSymbol(std::vector* map, - std::string_view name, + nonstd::string_view name, bool imported, bool exported, T&& sym) { @@ -252,7 +252,7 @@ class SymbolTable { // Wabt currently has no way for a user to explicitly specify the name of // an import, so never set the EXPLICIT_NAME flag, and ignore any display // name fabricated by wabt. - name = std::string_view(); + name = nonstd::string_view(); } else { if (name.empty()) { // Definitions without a name are local. @@ -370,7 +370,7 @@ struct FuncCodeMetadata { struct CodeMetadataSection { std::vector entries; }; -typedef std::unordered_map +typedef std::unordered_map CodeMetadataSections; class BinaryWriter { @@ -1758,7 +1758,7 @@ void BinaryWriter::WriteCodeMetadataSections() { stream_ = &tmp_stream; for (auto& s : code_metadata_sections_) { std::string name = "metadata.code."; - name.append(s.first); + name.append(nonstd::to_string(s.first)); auto& section = s.second; BeginCustomSection(name.c_str()); WriteU32Leb128(stream_, section.entries.size(), "function count"); diff --git a/third_party/wabt/src/common.cc b/third_party/wabt/src/common.cc index 037b8304b..4db8c40bc 100644 --- a/third_party/wabt/src/common.cc +++ b/third_party/wabt/src/common.cc @@ -77,7 +77,7 @@ static Result ReadStdin(std::vector* out_data) { } } -Result ReadFile(std::string_view filename, std::vector* out_data) { +Result ReadFile(nonstd::string_view filename, std::vector* out_data) { std::string filename_str(filename); const char* filename_cstr = filename_str.c_str(); diff --git a/third_party/wabt/src/ir.cc b/third_party/wabt/src/ir.cc index 811c54a3b..1409d9819 100644 --- a/third_party/wabt/src/ir.cc +++ b/third_party/wabt/src/ir.cc @@ -108,7 +108,7 @@ bool FuncSignature::operator==(const FuncSignature& rhs) const { return param_types == rhs.param_types && result_types == rhs.result_types; } -const Export* Module::GetExport(std::string_view name) const { +const Export* Module::GetExport(nonstd::string_view name) const { Index index = export_bindings.FindIndex(name); if (index >= exports.size()) { return nullptr; @@ -580,9 +580,9 @@ void MakeTypeBindingReverseMapping( std::vector* out_reverse_mapping) { out_reverse_mapping->clear(); out_reverse_mapping->resize(num_types); - for (const auto& [name, binding] : bindings) { - assert(static_cast(binding.index) < out_reverse_mapping->size()); - (*out_reverse_mapping)[binding.index] = name; + for (const auto& it : bindings) { + assert(static_cast(it.second.index) < out_reverse_mapping->size()); + (*out_reverse_mapping)[it.second.index] = it.first; } } @@ -591,7 +591,7 @@ Var::Var() : Var(kInvalidIndex, Location()) {} Var::Var(Index index, const Location& loc) : loc(loc), type_(VarType::Index), index_(index) {} -Var::Var(std::string_view name, const Location& loc) +Var::Var(nonstd::string_view name, const Location& loc) : loc(loc), type_(VarType::Name), name_(name) {} Var::Var(Var&& rhs) : Var() { @@ -638,7 +638,7 @@ void Var::set_name(std::string&& name) { Construct(name_, std::move(name)); } -void Var::set_name(std::string_view name) { +void Var::set_name(nonstd::string_view name) { set_name(std::string(name)); } diff --git a/third_party/wabt/src/shared-validator.cc b/third_party/wabt/src/shared-validator.cc index 0bff32661..a1a27d415 100644 --- a/third_party/wabt/src/shared-validator.cc +++ b/third_party/wabt/src/shared-validator.cc @@ -199,7 +199,7 @@ Result SharedValidator::OnTag(const Location& loc, Var sig_var) { Result SharedValidator::OnExport(const Location& loc, ExternalKind kind, Var item_var, - std::string_view name) { + nonstd::string_view name) { Result result = Result::Ok; auto name_str = std::string(name); if (export_names_.find(name_str) != export_names_.end()) { diff --git a/third_party/wabt/src/stream.cc b/third_party/wabt/src/stream.cc index 5f27e01b2..c808d2ce7 100644 --- a/third_party/wabt/src/stream.cc +++ b/third_party/wabt/src/stream.cc @@ -132,7 +132,7 @@ void Stream::WriteMemoryDump(const void* start, } } -Result OutputBuffer::WriteToFile(std::string_view filename) const { +Result OutputBuffer::WriteToFile(nonstd::string_view filename) const { std::string filename_str(filename); FILE* file = fopen(filename_str.c_str(), "wb"); if (!file) { @@ -229,7 +229,7 @@ Result MemoryStream::TruncateImpl(size_t size) { return Result::Ok; } -FileStream::FileStream(std::string_view filename, Stream* log_stream) +FileStream::FileStream(nonstd::string_view filename, Stream* log_stream) : Stream(log_stream), file_(nullptr), offset_(0), should_close_(false) { std::string filename_str(filename); file_ = fopen(filename_str.c_str(), "wb"); diff --git a/third_party/wabt/src/token.cc b/third_party/wabt/src/token.cc index 576fadd18..17aa67d3c 100644 --- a/third_party/wabt/src/token.cc +++ b/third_party/wabt/src/token.cc @@ -52,7 +52,7 @@ Token::Token(Location loc, TokenType token_type, Type type) Construct(type_, type); } -Token::Token(Location loc, TokenType token_type, std::string_view text) +Token::Token(Location loc, TokenType token_type, nonstd::string_view text) : loc(loc), token_type_(token_type) { assert(HasText()); Construct(text_, text); diff --git a/third_party/wabt/src/walrus/binary-reader-walrus.cc b/third_party/wabt/src/walrus/binary-reader-walrus.cc index 5191385d6..39475168b 100644 --- a/third_party/wabt/src/walrus/binary-reader-walrus.cc +++ b/third_party/wabt/src/walrus/binary-reader-walrus.cc @@ -189,7 +189,7 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate { } /* Custom section */ - Result BeginCustomSection(Index section_index, Offset size, std::string_view section_name) override { + Result BeginCustomSection(Index section_index, Offset size, nonstd::string_view section_name) override { return Result::Ok; } Result EndCustomSection() override { @@ -230,31 +230,31 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate { m_externalDelegate->OnImportCount(count); return Result::Ok; } - Result OnImport(Index index, ExternalKind kind, std::string_view module_name, std::string_view field_name) override { + Result OnImport(Index index, ExternalKind kind, nonstd::string_view module_name, nonstd::string_view field_name) override { return Result::Ok; } - Result OnImportFunc(Index import_index, std::string_view module_name, std::string_view field_name, Index func_index, Index sig_index) override { + Result OnImportFunc(Index import_index, nonstd::string_view module_name, nonstd::string_view field_name, Index func_index, Index sig_index) override { CHECK_RESULT(m_validator.OnFunction(GetLocation(), Var(sig_index, GetLocation()))); m_externalDelegate->OnImportFunc(import_index, std::string(module_name), std::string(field_name), func_index, sig_index); return Result::Ok; } - Result OnImportTable(Index import_index, std::string_view module_name, std::string_view field_name, Index table_index, Type elem_type, const Limits *elem_limits) override { + Result OnImportTable(Index import_index, nonstd::string_view module_name, nonstd::string_view field_name, Index table_index, Type elem_type, const Limits *elem_limits) override { CHECK_RESULT(m_validator.OnTable(GetLocation(), elem_type, *elem_limits)); m_tableTypes.push_back(elem_type); m_externalDelegate->OnImportTable(import_index, std::string(module_name), std::string(field_name), table_index, elem_type, elem_limits->initial, elem_limits->has_max ? elem_limits->max : std::numeric_limits::max()); return Result::Ok; } - Result OnImportMemory(Index import_index, std::string_view module_name, std::string_view field_name, Index memory_index, const Limits *page_limits) override { + Result OnImportMemory(Index import_index, nonstd::string_view module_name, nonstd::string_view field_name, Index memory_index, const Limits *page_limits) override { CHECK_RESULT(m_validator.OnMemory(GetLocation(), *page_limits)); m_externalDelegate->OnImportMemory(import_index, std::string(module_name), std::string(field_name), memory_index, page_limits->initial, page_limits->has_max ? page_limits->max : (page_limits->is_64? WABT_MAX_PAGES64 : WABT_MAX_PAGES32)); return Result::Ok; } - Result OnImportGlobal(Index import_index, std::string_view module_name, std::string_view field_name, Index global_index, Type type, bool mutable_) override { + Result OnImportGlobal(Index import_index, nonstd::string_view module_name, nonstd::string_view field_name, Index global_index, Type type, bool mutable_) override { CHECK_RESULT(m_validator.OnGlobalImport(GetLocation(), type, mutable_)); m_externalDelegate->OnImportGlobal(import_index, std::string(module_name), std::string(field_name), global_index, type, mutable_); return Result::Ok; } - Result OnImportTag(Index import_index, std::string_view module_name, std::string_view field_name, Index tag_index, Index sig_index) override { + Result OnImportTag(Index import_index, nonstd::string_view module_name, nonstd::string_view field_name, Index tag_index, Index sig_index) override { CHECK_RESULT(m_validator.OnTag(GetLocation(), Var(sig_index, GetLocation()))); m_externalDelegate->OnImportTag(import_index, std::string(module_name), std::string(field_name), tag_index, sig_index); return Result::Ok; @@ -361,7 +361,7 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate { m_externalDelegate->OnExportCount(count); return Result::Ok; } - Result OnExport(Index index, ExternalKind kind, Index item_index, std::string_view name) override { + Result OnExport(Index index, ExternalKind kind, Index item_index, nonstd::string_view name) override { CHECK_RESULT(m_validator.OnExport(GetLocation(), kind, Var(item_index, GetLocation()), name)); m_externalDelegate->OnExport(static_cast(kind), index, std::string(name), item_index); return Result::Ok; @@ -1102,7 +1102,7 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate { abort(); return Result::Ok; } - Result OnModuleName(std::string_view name) override { + Result OnModuleName(nonstd::string_view name) override { abort(); return Result::Ok; } @@ -1114,7 +1114,7 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate { abort(); return Result::Ok; } - Result OnFunctionName(Index function_index, std::string_view function_name) override { + Result OnFunctionName(Index function_index, nonstd::string_view function_name) override { abort(); return Result::Ok; } @@ -1130,7 +1130,7 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate { abort(); return Result::Ok; } - Result OnLocalName(Index function_index, Index local_index, std::string_view local_name) override { + Result OnLocalName(Index function_index, Index local_index, nonstd::string_view local_name) override { abort(); return Result::Ok; } @@ -1147,7 +1147,7 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate { abort(); return Result::Ok; } - Result OnNameEntry(NameSectionSubsection type, Index index, std::string_view name) override { + Result OnNameEntry(NameSectionSubsection type, Index index, nonstd::string_view name) override { abort(); return Result::Ok; } @@ -1188,7 +1188,7 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate { } /* Code Metadata sections */ - Result BeginCodeMetadataSection(std::string_view name, Offset size) override { + Result BeginCodeMetadataSection(nonstd::string_view name, Offset size) override { abort(); return Result::Ok; } @@ -1222,7 +1222,7 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate { abort(); return Result::Ok; } - Result OnDylinkNeeded(std::string_view so_name) override { + Result OnDylinkNeeded(nonstd::string_view so_name) override { abort(); return Result::Ok; } @@ -1234,11 +1234,11 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate { abort(); return Result::Ok; } - Result OnDylinkImport(std::string_view module, std::string_view name, uint32_t flags) override { + Result OnDylinkImport(nonstd::string_view module, nonstd::string_view name, uint32_t flags) override { abort(); return Result::Ok; } - Result OnDylinkExport(std::string_view name, uint32_t flags) override { + Result OnDylinkExport(nonstd::string_view name, uint32_t flags) override { abort(); return Result::Ok; } @@ -1256,7 +1256,7 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate { abort(); return Result::Ok; } - Result OnFeature(uint8_t prefix, std::string_view name) override { + Result OnFeature(uint8_t prefix, nonstd::string_view name) override { abort(); return Result::Ok; } @@ -1274,15 +1274,15 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate { abort(); return Result::Ok; } - Result OnDataSymbol(Index index, uint32_t flags, std::string_view name, Index segment, uint32_t offset, uint32_t size) override { + Result OnDataSymbol(Index index, uint32_t flags, nonstd::string_view name, Index segment, uint32_t offset, uint32_t size) override { abort(); return Result::Ok; } - Result OnFunctionSymbol(Index index, uint32_t flags, std::string_view name, Index func_index) override { + Result OnFunctionSymbol(Index index, uint32_t flags, nonstd::string_view name, Index func_index) override { abort(); return Result::Ok; } - Result OnGlobalSymbol(Index index, uint32_t flags, std::string_view name, Index global_index) override { + Result OnGlobalSymbol(Index index, uint32_t flags, nonstd::string_view name, Index global_index) override { abort(); return Result::Ok; } @@ -1290,11 +1290,11 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate { abort(); return Result::Ok; } - Result OnTagSymbol(Index index, uint32_t flags, std::string_view name, Index tag_index) override { + Result OnTagSymbol(Index index, uint32_t flags, nonstd::string_view name, Index tag_index) override { abort(); return Result::Ok; } - Result OnTableSymbol(Index index, uint32_t flags, std::string_view name, Index table_index) override { + Result OnTableSymbol(Index index, uint32_t flags, nonstd::string_view name, Index table_index) override { abort(); return Result::Ok; } @@ -1302,7 +1302,7 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate { abort(); return Result::Ok; } - Result OnSegmentInfo(Index index, std::string_view name, Address alignment, uint32_t flags) override { + Result OnSegmentInfo(Index index, nonstd::string_view name, Address alignment, uint32_t flags) override { abort(); return Result::Ok; } @@ -1318,7 +1318,7 @@ class BinaryReaderDelegateWalrus: public BinaryReaderDelegate { abort(); return Result::Ok; } - Result OnComdatBegin(std::string_view name, uint32_t flags, Index count) override { + Result OnComdatBegin(nonstd::string_view name, uint32_t flags, Index count) override { abort(); return Result::Ok; } diff --git a/third_party/wabt/src/wast-lexer.cc b/third_party/wabt/src/wast-lexer.cc index a601b75db..32d62ece2 100644 --- a/third_party/wabt/src/wast-lexer.cc +++ b/third_party/wabt/src/wast-lexer.cc @@ -35,7 +35,7 @@ namespace { } // namespace WastLexer::WastLexer(std::unique_ptr source, - std::string_view filename) + nonstd::string_view filename) : source_(std::move(source)), filename_(filename), line_(1), @@ -47,7 +47,7 @@ WastLexer::WastLexer(std::unique_ptr source, // static std::unique_ptr WastLexer::CreateBufferLexer( - std::string_view filename, + nonstd::string_view filename, const void* data, size_t size) { return MakeUnique(MakeUnique(data, size), filename); @@ -183,8 +183,8 @@ Location WastLexer::GetLocation() { return Location(filename_, line_, column(token_start_), column(cursor_)); } -std::string_view WastLexer::GetText(size_t offset) { - return std::string_view(token_start_ + offset, +nonstd::string_view WastLexer::GetText(size_t offset) { + return nonstd::string_view(token_start_ + offset, (cursor_ - token_start_) - offset); } @@ -216,7 +216,7 @@ bool WastLexer::MatchChar(char c) { return false; } -bool WastLexer::MatchString(std::string_view s) { +bool WastLexer::MatchString(nonstd::string_view s) { const char* saved_cursor = cursor_; for (char c : s) { if (ReadChar() != c) { @@ -546,7 +546,7 @@ Token WastLexer::GetNanToken() { return GetKeywordToken(); } -Token WastLexer::GetNameEqNumToken(std::string_view name, +Token WastLexer::GetNameEqNumToken(nonstd::string_view name, TokenType token_type) { if (MatchString(name)) { if (MatchString("0x")) { diff --git a/third_party/wabt/src/wast-parser.cc b/third_party/wabt/src/wast-parser.cc index a3cc7a665..8406447db 100644 --- a/third_party/wabt/src/wast-parser.cc +++ b/third_party/wabt/src/wast-parser.cc @@ -42,7 +42,7 @@ bool IsPowerOfTwo(uint32_t x) { } template -void RemoveEscapes(std::string_view text, OutputIter dest) { +void RemoveEscapes(nonstd::string_view text, OutputIter dest) { // Remove surrounding quotes; if any. This may be empty if the string was // invalid (e.g. if it contained a bad escape sequence). if (text.size() <= 2) { @@ -142,11 +142,11 @@ void RemoveEscapes(std::string_view text, OutputIter dest) { } } -typedef std::vector TextVector; +typedef std::vector TextVector; template void RemoveEscapes(const TextVector& texts, OutputIter out) { - for (std::string_view text : texts) + for (nonstd::string_view text : texts) RemoveEscapes(text, out); } @@ -544,8 +544,8 @@ Result ResolveFuncTypes(Module* module, Errors* errors) { // local variables share the same index space, we need to increment the // local indexes bound to a given name by the number of parameters in // the function. - for (auto& [name, binding] : func->bindings) { - binding.index += func->GetNumParams(); + for (auto& it : func->bindings) { + it.second.index += func->GetNumParams(); } } @@ -768,7 +768,7 @@ Result WastParser::ParseVar(Var* out_var) { WABT_TRACE(ParseVar); if (PeekMatch(TokenType::Nat)) { Token token = Consume(); - std::string_view sv = token.literal().text; + nonstd::string_view sv = token.literal().text; uint64_t index = kInvalidIndex; if (Failed(ParseUint64(sv, &index))) { // Print an error, but don't fail parsing. @@ -1041,7 +1041,7 @@ bool WastParser::ParseOffsetOpt(Address* out_offset) { if (PeekMatch(TokenType::OffsetEqNat)) { Token token = Consume(); uint64_t offset64; - std::string_view sv = token.text(); + nonstd::string_view sv = token.text(); if (Failed(ParseInt64(sv, &offset64, ParseIntType::SignedAndUnsigned))) { Error(token.loc, "invalid offset \"" PRIstringview "\"", WABT_PRINTF_STRING_VIEW_ARG(sv)); @@ -1062,7 +1062,7 @@ bool WastParser::ParseAlignOpt(Address* out_align) { WABT_TRACE(ParseAlignOpt); if (PeekMatch(TokenType::AlignEqNat)) { Token token = Consume(); - std::string_view sv = token.text(); + nonstd::string_view sv = token.text(); if (Failed(ParseInt64(sv, out_align, ParseIntType::UnsignedOnly))) { Error(token.loc, "invalid alignment \"" PRIstringview "\"", WABT_PRINTF_STRING_VIEW_ARG(sv)); @@ -1141,7 +1141,7 @@ Result WastParser::ParseNat(uint64_t* out_nat, bool is_64) { } Token token = Consume(); - std::string_view sv = token.literal().text; + nonstd::string_view sv = token.literal().text; if (Failed(ParseUint64(sv, out_nat)) || (!is_64 && *out_nat > 0xffffffffu)) { Error(token.loc, "invalid int \"" PRIstringview "\"", WABT_PRINTF_STRING_VIEW_ARG(sv)); @@ -1942,7 +1942,7 @@ Result WastParser::ParseInstr(ExprList* exprs) { Result WastParser::ParseCodeMetadataAnnotation(ExprList* exprs) { WABT_TRACE(ParseCodeMetadataAnnotation); Token tk = Consume(); - std::string_view name = tk.text(); + nonstd::string_view name = tk.text(); name.remove_prefix(sizeof("metadata.code.") - 1); std::string data_text; CHECK_RESULT(ParseQuotedText(&data_text, false)); @@ -2548,7 +2548,7 @@ Result WastParser::ParseSimdV128Const(Const* const_, // For each type, parse the next literal, bound check it, and write it to // the array of bytes: if (integer) { - std::string_view sv = Consume().literal().text; + nonstd::string_view sv = Consume().literal().text; switch (lane_count) { case 16: { @@ -2750,7 +2750,7 @@ Result WastParser::ParseExternref(Const* const_) { } Literal literal; - std::string_view sv; + nonstd::string_view sv; const_->loc = GetLocation(); TokenType token_type = Peek();