Make the contents of regex.hpp all inline.

This commit is contained in:
jzmaddock
2020-11-29 19:10:05 +00:00
parent 9d64cf60ff
commit 49e8067b80
14 changed files with 146 additions and 259 deletions

View File

@ -23,6 +23,10 @@
# define BOOST_REGEX_CXX03 # define BOOST_REGEX_CXX03
#endif #endif
#if defined(BOOST_REGEX_RECURSIVE) && !defined(BOOST_REGEX_CXX03)
# define BOOST_REGEX_CXX03
#endif
#if defined(__has_include) #if defined(__has_include)
#if !defined(BOOST_REGEX_STANDALONE) && !__has_include(<boost/version.hpp>) #if !defined(BOOST_REGEX_STANDALONE) && !__has_include(<boost/version.hpp>)
#define BOOST_REGEX_STANDALONE #define BOOST_REGEX_STANDALONE
@ -374,21 +378,6 @@ BOOST_REGEX_DECL void BOOST_REGEX_CALL reset_stack_guard_page();
#endif #endif
/*****************************************************************************
*
* helper memory allocation functions:
*
****************************************************************************/
#if defined(__cplusplus) && defined(BOOST_REGEX_NON_RECURSIVE)
namespace boost{ namespace BOOST_REGEX_DETAIL_NS{
BOOST_REGEX_DECL void* BOOST_REGEX_CALL get_mem_block();
BOOST_REGEX_DECL void BOOST_REGEX_CALL put_mem_block(void*);
}} /* namespaces */
#endif
/***************************************************************************** /*****************************************************************************
* *
* Diagnostics: * Diagnostics:

View File

@ -27,8 +27,10 @@
#include <stdexcept> #include <stdexcept>
#ifdef BOOST_REGEX_CXX03 #ifdef BOOST_REGEX_CXX03
#include <boost/regex/v4/error_type.hpp> #include <boost/regex/v4/error_type.hpp>
#include <boost/regex/v4/regex_traits_defaults.hpp>
#else #else
#include <boost/regex/v5/error_type.hpp> #include <boost/regex/v5/error_type.hpp>
#include <boost/regex/v5/regex_traits_defaults.hpp>
#endif #endif
namespace boost{ namespace boost{
@ -51,17 +53,32 @@ namespace boost{
#pragma warning(disable : 26812) #pragma warning(disable : 26812)
#endif #endif
#endif #endif
class BOOST_REGEX_DECL regex_error : public std::runtime_error class regex_error : public std::runtime_error
{ {
public: public:
explicit regex_error(const std::string& s, regex_constants::error_type err = regex_constants::error_unknown, std::ptrdiff_t pos = 0); explicit regex_error(const std::string& s, regex_constants::error_type err = regex_constants::error_unknown, std::ptrdiff_t pos = 0)
explicit regex_error(regex_constants::error_type err); : std::runtime_error(s)
~regex_error() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE; , m_error_code(err)
, m_position(pos)
{
}
explicit regex_error(regex_constants::error_type err)
: std::runtime_error(::boost::BOOST_REGEX_DETAIL_NS::get_default_error_string(err))
, m_error_code(err)
, m_position(0)
{
}
~regex_error() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE {}
regex_constants::error_type code()const regex_constants::error_type code()const
{ return m_error_code; } { return m_error_code; }
std::ptrdiff_t position()const std::ptrdiff_t position()const
{ return m_position; } { return m_position; }
void raise()const; void raise()const
{
#ifndef BOOST_NO_EXCEPTIONS
::boost::throw_exception(*this);
#endif
}
private: private:
regex_constants::error_type m_error_code; regex_constants::error_type m_error_code;
std::ptrdiff_t m_position; std::ptrdiff_t m_position;
@ -72,7 +89,10 @@ typedef regex_error bad_expression;
namespace BOOST_REGEX_DETAIL_NS{ namespace BOOST_REGEX_DETAIL_NS{
BOOST_REGEX_DECL void BOOST_REGEX_CALL raise_runtime_error(const std::runtime_error& ex); inline void BOOST_REGEX_CALL raise_runtime_error(const std::runtime_error& ex)
{
::boost::throw_exception(ex);
}
template <class traits> template <class traits>
void raise_error(const traits& t, regex_constants::error_type code) void raise_error(const traits& t, regex_constants::error_type code)

View File

@ -69,6 +69,12 @@ struct mem_block_cache
} }
::operator delete(ptr); ::operator delete(ptr);
} }
static mem_block_cache& instance()
{
static mem_block_cache block_cache = { { {nullptr} } };
return block_cache;
}
}; };
@ -129,11 +135,43 @@ struct mem_block_cache
++cached_blocks; ++cached_blocks;
} }
} }
static mem_block_cache& instance()
{
#ifdef BOOST_HAS_THREADS
static mem_block_cache block_cache = { 0, 0, BOOST_STATIC_MUTEX_INIT, };
#else
static mem_block_cache block_cache = { 0, 0, };
#endif
return block_cache;
}
}; };
#endif #endif
extern mem_block_cache block_cache; #if BOOST_REGEX_MAX_CACHE_BLOCKS == 0
inline void* BOOST_REGEX_CALL get_mem_block()
{
return ::operator new(BOOST_REGEX_BLOCKSIZE);
}
inline void BOOST_REGEX_CALL put_mem_block(void* p)
{
::operator delete(p);
}
#else
inline void* BOOST_REGEX_CALL get_mem_block()
{
return mem_block_cache::instance().get();
}
inline void BOOST_REGEX_CALL put_mem_block(void* p)
{
mem_block_cache::instance().put(p);
}
#endif
} }
} // namespace boost } // namespace boost

View File

@ -45,7 +45,17 @@ namespace BOOST_REGEX_DETAIL_NS{
// //
// error checking API: // error checking API:
// //
BOOST_REGEX_DECL void BOOST_REGEX_CALL verify_options(boost::regex_constants::syntax_option_type ef, match_flag_type mf); inline void BOOST_REGEX_CALL verify_options(boost::regex_constants::syntax_option_type, match_flag_type mf)
{
//
// can't mix match_extra with POSIX matching rules:
//
if ((mf & match_extra) && (mf & match_posix))
{
std::logic_error msg("Usage Error: Can't mix regular expression captures with POSIX matching rules");
throw_exception(msg);
}
}
// //
// function can_start: // function can_start:
// //

View File

@ -20,7 +20,7 @@
#ifndef BOOST_REGEX_V4_PERL_MATCHER_NON_RECURSIVE_HPP #ifndef BOOST_REGEX_V4_PERL_MATCHER_NON_RECURSIVE_HPP
#define BOOST_REGEX_V4_PERL_MATCHER_NON_RECURSIVE_HPP #define BOOST_REGEX_V4_PERL_MATCHER_NON_RECURSIVE_HPP
#include <new> #include <boost/regex/v4/mem_block_cache.hpp>
#ifdef BOOST_MSVC #ifdef BOOST_MSVC
#pragma warning(push) #pragma warning(push)

View File

@ -31,6 +31,7 @@
#endif #endif
#include <boost/regex/config.hpp> #include <boost/regex/config.hpp>
#include <boost/cstdint.hpp>
#ifndef BOOST_REGEX_SYNTAX_TYPE_HPP #ifndef BOOST_REGEX_SYNTAX_TYPE_HPP
#include <boost/regex/v5/syntax_type.hpp> #include <boost/regex/v5/syntax_type.hpp>
@ -38,6 +39,7 @@
#ifndef BOOST_REGEX_ERROR_TYPE_HPP #ifndef BOOST_REGEX_ERROR_TYPE_HPP
#include <boost/regex/v5/error_type.hpp> #include <boost/regex/v5/error_type.hpp>
#endif #endif
#include <boost/regex/v5/regex_workaround.hpp>
#include <boost/type_traits/make_unsigned.hpp> #include <boost/type_traits/make_unsigned.hpp>
#include <boost/utility/enable_if.hpp> #include <boost/utility/enable_if.hpp>

View File

@ -69,6 +69,12 @@ struct mem_block_cache
} }
::operator delete(ptr); ::operator delete(ptr);
} }
static mem_block_cache& instance()
{
static mem_block_cache block_cache = { { {nullptr} } };
return block_cache;
}
}; };
@ -129,11 +135,43 @@ struct mem_block_cache
++cached_blocks; ++cached_blocks;
} }
} }
static mem_block_cache& instance()
{
#ifdef BOOST_HAS_THREADS
static mem_block_cache block_cache = { 0, 0, BOOST_STATIC_MUTEX_INIT, };
#else
static mem_block_cache block_cache = { 0, 0, };
#endif
return block_cache;
}
}; };
#endif #endif
extern mem_block_cache block_cache; #if BOOST_REGEX_MAX_CACHE_BLOCKS == 0
inline void* BOOST_REGEX_CALL get_mem_block()
{
return ::operator new(BOOST_REGEX_BLOCKSIZE);
}
inline void BOOST_REGEX_CALL put_mem_block(void* p)
{
::operator delete(p);
}
#else
inline void* BOOST_REGEX_CALL get_mem_block()
{
return mem_block_cache::instance().get();
}
inline void BOOST_REGEX_CALL put_mem_block(void* p)
{
mem_block_cache::instance().put(p);
}
#endif
} }
} // namespace boost } // namespace boost

View File

@ -45,7 +45,17 @@ namespace BOOST_REGEX_DETAIL_NS{
// //
// error checking API: // error checking API:
// //
BOOST_REGEX_DECL void BOOST_REGEX_CALL verify_options(boost::regex_constants::syntax_option_type ef, match_flag_type mf); inline void BOOST_REGEX_CALL verify_options(boost::regex_constants::syntax_option_type, match_flag_type mf)
{
//
// can't mix match_extra with POSIX matching rules:
//
if ((mf & match_extra) && (mf & match_posix))
{
std::logic_error msg("Usage Error: Can't mix regular expression captures with POSIX matching rules");
throw_exception(msg);
}
}
// //
// function can_start: // function can_start:
// //
@ -407,10 +417,6 @@ private:
bool find_imp(); bool find_imp();
bool match_imp(); bool match_imp();
#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
typedef bool (perl_matcher::*protected_proc_type)();
bool protected_call(protected_proc_type);
#endif
void estimate_max_state_count(std::random_access_iterator_tag*); void estimate_max_state_count(std::random_access_iterator_tag*);
void estimate_max_state_count(void*); void estimate_max_state_count(void*);
bool match_prefix(); bool match_prefix();

View File

@ -178,27 +178,10 @@ inline void perl_matcher<BidiIterator, Allocator, traits>::estimate_max_state_co
max_state_count = BOOST_REGEX_MAX_STATE_COUNT; max_state_count = BOOST_REGEX_MAX_STATE_COUNT;
} }
#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
template <class BidiIterator, class Allocator, class traits>
inline bool perl_matcher<BidiIterator, Allocator, traits>::protected_call(
protected_proc_type proc)
{
::boost::BOOST_REGEX_DETAIL_NS::concrete_protected_call
<perl_matcher<BidiIterator, Allocator, traits> >
obj(this, proc);
return obj.execute();
}
#endif
template <class BidiIterator, class Allocator, class traits> template <class BidiIterator, class Allocator, class traits>
inline bool perl_matcher<BidiIterator, Allocator, traits>::match() inline bool perl_matcher<BidiIterator, Allocator, traits>::match()
{ {
#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
return protected_call(&perl_matcher<BidiIterator, Allocator, traits>::match_imp);
#else
return match_imp(); return match_imp();
#endif
} }
template <class BidiIterator, class Allocator, class traits> template <class BidiIterator, class Allocator, class traits>
@ -242,11 +225,7 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_imp()
template <class BidiIterator, class Allocator, class traits> template <class BidiIterator, class Allocator, class traits>
inline bool perl_matcher<BidiIterator, Allocator, traits>::find() inline bool perl_matcher<BidiIterator, Allocator, traits>::find()
{ {
#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
return protected_call(&perl_matcher<BidiIterator, Allocator, traits>::find_imp);
#else
return find_imp(); return find_imp();
#endif
} }
template <class BidiIterator, class Allocator, class traits> template <class BidiIterator, class Allocator, class traits>

View File

@ -20,7 +20,7 @@
#ifndef BOOST_REGEX_V4_PERL_MATCHER_NON_RECURSIVE_HPP #ifndef BOOST_REGEX_V4_PERL_MATCHER_NON_RECURSIVE_HPP
#define BOOST_REGEX_V4_PERL_MATCHER_NON_RECURSIVE_HPP #define BOOST_REGEX_V4_PERL_MATCHER_NON_RECURSIVE_HPP
#include <new> #include <boost/regex/v5/mem_block_cache.hpp>
#ifdef BOOST_MSVC #ifdef BOOST_MSVC
#pragma warning(push) #pragma warning(push)

View File

@ -1,83 +0,0 @@
/*
*
* Copyright (c) 2004
* John Maddock
*
* Use, modification and distribution are subject to the
* Boost Software License, Version 1.0. (See accompanying file
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE basic_regex_creator.cpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Declares template class basic_regex_creator which fills in
* the data members of a regex_data object.
*/
#ifndef BOOST_REGEX_V4_PROTECTED_CALL_HPP
#define BOOST_REGEX_V4_PROTECTED_CALL_HPP
#include <boost/config.hpp>
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable: 4103)
#endif
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_PREFIX
#endif
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
namespace boost{
namespace BOOST_REGEX_DETAIL_NS{
class BOOST_REGEX_DECL abstract_protected_call
{
public:
bool BOOST_REGEX_CALL execute()const;
// this stops gcc-4 from complaining:
virtual ~abstract_protected_call(){}
private:
virtual bool call()const = 0;
};
template <class T>
class concrete_protected_call
: public abstract_protected_call
{
public:
typedef bool (T::*proc_type)();
concrete_protected_call(T* o, proc_type p)
: obj(o), proc(p) {}
private:
bool call()const BOOST_OVERRIDE;
T* obj;
proc_type proc;
};
template <class T>
bool concrete_protected_call<T>::call()const
{
return (obj->*proc)();
}
}
} // namespace boost
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable: 4103)
#endif
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif

View File

@ -81,9 +81,6 @@
#ifndef BOOST_REGEX_V4_MATCH_RESULTS_HPP #ifndef BOOST_REGEX_V4_MATCH_RESULTS_HPP
#include <boost/regex/v5/match_results.hpp> #include <boost/regex/v5/match_results.hpp>
#endif #endif
#ifndef BOOST_REGEX_V4_PROTECTED_CALL_HPP
#include <boost/regex/v5/protected_call.hpp>
#endif
#ifndef BOOST_REGEX_MATCHER_HPP #ifndef BOOST_REGEX_MATCHER_HPP
#include <boost/regex/v5/perl_matcher.hpp> #include <boost/regex/v5/perl_matcher.hpp>
#endif #endif

View File

@ -38,8 +38,10 @@
#ifndef BOOST_REGEX_ERROR_TYPE_HPP #ifndef BOOST_REGEX_ERROR_TYPE_HPP
#include <boost/regex/v5/error_type.hpp> #include <boost/regex/v5/error_type.hpp>
#endif #endif
#include <boost/regex/v5/regex_workaround.hpp>
#include <boost/type_traits/make_unsigned.hpp> #include <boost/type_traits/make_unsigned.hpp>
#include <boost/utility/enable_if.hpp> #include <boost/utility/enable_if.hpp>
#include <boost/cstdint.hpp>
#ifdef BOOST_NO_STDC_NAMESPACE #ifdef BOOST_NO_STDC_NAMESPACE
namespace std{ namespace std{

View File

@ -19,15 +19,12 @@
#define BOOST_REGEX_SOURCE #define BOOST_REGEX_SOURCE
#include <boost/config.hpp> #include <boost/regex/config.hpp>
#include <new>
#include <boost/regex.hpp>
#include <boost/throw_exception.hpp>
#if defined(BOOST_REGEX_HAS_MS_STACK_GUARD) && defined(_MSC_VER) && (_MSC_VER >= 1300)
# include <malloc.h>
#endif
#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD #ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
#include <malloc.h>
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
#endif #endif
@ -37,79 +34,13 @@
#define NOGDI #define NOGDI
#define NOUSER #define NOUSER
#include <windows.h> #include <windows.h>
#endif #include <stdexcept>
#include <boost/regex/pattern_except.hpp>
#if defined(BOOST_REGEX_NON_RECURSIVE) && !defined(BOOST_REGEX_V3) #include <boost/regex/v4/protected_call.hpp>
#if BOOST_REGEX_MAX_CACHE_BLOCKS == 0
#include <new>
#else
#include <boost/regex/v4/mem_block_cache.hpp>
#endif
#endif
#ifdef BOOST_INTEL
#pragma warning(disable:383)
#endif
namespace boost { namespace boost {
//
// fix: these are declared out of line here to ensure
// that dll builds contain the Virtual table for these
// types - this ensures that exceptions can be thrown
// from the dll and caught in an exe.
regex_error::regex_error(const std::string& s, regex_constants::error_type err, std::ptrdiff_t pos)
: std::runtime_error(s)
, m_error_code(err)
, m_position(pos)
{
}
regex_error::regex_error(regex_constants::error_type err)
: std::runtime_error(::boost::BOOST_REGEX_DETAIL_NS::get_default_error_string(err))
, m_error_code(err)
, m_position(0)
{
}
regex_error::~regex_error() BOOST_NOEXCEPT_OR_NOTHROW
{
}
void regex_error::raise()const
{
#ifndef BOOST_NO_EXCEPTIONS
::boost::throw_exception(*this);
#endif
}
namespace BOOST_REGEX_DETAIL_NS { namespace BOOST_REGEX_DETAIL_NS {
BOOST_REGEX_DECL void BOOST_REGEX_CALL raise_runtime_error(const std::runtime_error& ex)
{
::boost::throw_exception(ex);
}
//
// error checking API:
//
BOOST_REGEX_DECL void BOOST_REGEX_CALL verify_options(boost::regex::flag_type /*ef*/, match_flag_type mf)
{
#ifndef BOOST_REGEX_V3
//
// can't mix match_extra with POSIX matching rules:
//
if((mf & match_extra) && (mf & match_posix))
{
std::logic_error msg("Usage Error: Can't mix regular expression captures with POSIX matching rules");
throw_exception(msg);
}
#endif
}
#ifdef BOOST_REGEX_HAS_MS_STACK_GUARD
static void execute_eror() static void execute_eror()
{ {
// we only get here after a stack overflow, // we only get here after a stack overflow,
@ -175,52 +106,10 @@ BOOST_REGEX_DECL void BOOST_REGEX_CALL reset_stack_guard_page()
} }
#endif #endif
} }
#endif
#if defined(BOOST_REGEX_NON_RECURSIVE) && !defined(BOOST_REGEX_V3)
#if BOOST_REGEX_MAX_CACHE_BLOCKS == 0
BOOST_REGEX_DECL void* BOOST_REGEX_CALL get_mem_block()
{
return ::operator new(BOOST_REGEX_BLOCKSIZE);
} }
} // namspaces
BOOST_REGEX_DECL void BOOST_REGEX_CALL put_mem_block(void* p)
{
::operator delete(p);
}
#else
#if defined(BOOST_REGEX_MEM_BLOCK_CACHE_LOCK_FREE)
mem_block_cache block_cache = { { {nullptr} } } ;
#elif defined(BOOST_HAS_THREADS)
mem_block_cache block_cache = { 0, 0, BOOST_STATIC_MUTEX_INIT, };
#else
mem_block_cache block_cache = { 0, 0, };
#endif #endif
BOOST_REGEX_DECL void* BOOST_REGEX_CALL get_mem_block()
{
return block_cache.get();
}
BOOST_REGEX_DECL void BOOST_REGEX_CALL put_mem_block(void* p)
{
block_cache.put(p);
}
#endif
#endif
} // namespace BOOST_REGEX_DETAIL_NS
} // namespace boost
#if defined(BOOST_RE_USE_VCL) && defined(BOOST_REGEX_DYN_LINK) #if defined(BOOST_RE_USE_VCL) && defined(BOOST_REGEX_DYN_LINK)
int WINAPI DllEntryPoint(HINSTANCE , unsigned long , void*) int WINAPI DllEntryPoint(HINSTANCE , unsigned long , void*)