250515.2 · 79e2ec1efa87cc489ac09159b13a48c5ce184b02
some cleanup with override specifiers
reading declarations
@@ -76,6 +76,7 @@ class AbstractLexer { { M::operator=(matcher); lexer_ = matcher.lexer_;+ return *this; } protected: /// Returns true if matcher should wrap input after EOF (lexer wrap() should return 0 to wrap input after EOF).
@@ -37,6 +37,21 @@ #ifndef REFLEX_ABSMATCHER_H #define REFLEX_ABSMATCHER_H +/// Permit legacy C++ compilation of override (ignored) and C++11 override (applied).+#if __cplusplus < 201103L+#define REFLEX_OVERRIDE+#else+#define REFLEX_OVERRIDE override+#endif++#if defined(__GNUC__) || defined(__clang__)+#define REFLEX_LIKELY(x) __builtin_expect(!!(x), 1)+#define REFLEX_UNLIKELY(x) __builtin_expect(!!(x), 0)+#else+#define REFLEX_LIKELY(x) (x)+#define REFLEX_UNLIKELY(x) (x)+#endif+ /// This compile-time option may speed up buffer reallocation with realloc() instead of new and delete. #ifndef WITH_REALLOC #define WITH_REALLOC 1
@@ -98,12 +98,12 @@ class BoostMatcher : public PatternMatcher<boost::regex> { return *this; } /// Polymorphic cloning.- virtual BoostMatcher *clone()+ virtual BoostMatcher *clone() REFLEX_OVERRIDE { return new BoostMatcher(*this); } /// Reset this matcher's state to the initial state and when assigned new input.- virtual void reset(const char *opt = NULL)+ virtual void reset(const char *opt = NULL) REFLEX_OVERRIDE { DBGLOG("BoostMatcher::reset()"); itr_ = fin_ = boost::cregex_iterator();@@ -122,6 +122,7 @@ class BoostMatcher : public PatternMatcher<boost::regex> { /// Set the pattern to use with this matcher (the given pattern is shared and must be persistent). virtual PatternMatcher& pattern(const Pattern& pattern) ///< boost::regex for this matcher /// @returns this matcher.+ REFLEX_OVERRIDE { itr_ = fin_; return PatternMatcher::pattern(pattern);@@ -129,6 +130,7 @@ class BoostMatcher : public PatternMatcher<boost::regex> { /// Set the pattern to use with this matcher (the given pattern is shared and must be persistent). virtual PatternMatcher& pattern(const Pattern *pattern) ///< boost::regex for this matcher /// @returns this matcher.+ REFLEX_OVERRIDE { itr_ = fin_; return PatternMatcher::pattern(pattern);@@ -136,6 +138,7 @@ class BoostMatcher : public PatternMatcher<boost::regex> { /// Set the pattern from a regex string to use with this matcher. virtual PatternMatcher& pattern(const char *pattern) ///< regex string to instantiate internal pattern object /// @returns this matcher.+ REFLEX_OVERRIDE { itr_ = fin_; return PatternMatcher::pattern(pattern);@@ -143,6 +146,7 @@ class BoostMatcher : public PatternMatcher<boost::regex> { /// Set the pattern from a regex string to use with this matcher. virtual PatternMatcher& pattern(const std::string& pattern) ///< regex string to instantiate internal pattern object /// @returns this matcher.+ REFLEX_OVERRIDE { itr_ = fin_; return PatternMatcher::pattern(pattern);@@ -150,7 +154,7 @@ class BoostMatcher : public PatternMatcher<boost::regex> { /// Returns a pair of pointer and length of the captured match for n > 0 capture index or <text(),size() for n == 0. virtual std::pair<const char*,size_t> operator[](size_t n) ///< nth capture index > 0 or 0 /// @returns pair.- const+ const REFLEX_OVERRIDE { if (n == 0) return std::pair<const char*,size_t>(txt_, len_);@@ -161,6 +165,7 @@ class BoostMatcher : public PatternMatcher<boost::regex> { /// Returns the group capture identifier containing the group capture index >0 and name (or NULL) of a named group capture, or (1,NULL) by default virtual std::pair<size_t,const char*> group_id() /// @returns a pair of size_t and string+ REFLEX_OVERRIDE { grp_ = 1; if (itr_ == fin_ || (*itr_).size() <= 1)@@ -172,6 +177,7 @@ class BoostMatcher : public PatternMatcher<boost::regex> { /// Returns the next group capture identifier containing the group capture index >0 and name (or NULL) of a named group capture, or (0,NULL) when no more groups matched virtual std::pair<size_t,const char*> group_next_id() /// @returns a pair of size_t and string+ REFLEX_OVERRIDE { if (itr_ == fin_) return std::pair<size_t,const char*>(0, static_cast<const char*>(NULL)); // cast to appease MSVC 2010@@ -187,6 +193,7 @@ class BoostMatcher : public PatternMatcher<boost::regex> { /// The match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH, implemented with boost::regex. virtual size_t match(Method method) ///< match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH /// @returns nonzero when input matched the pattern using method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH.+ REFLEX_OVERRIDE { DBGLOG("BEGIN BoostMatcher::match(%d)", method); reset_text();
@@ -323,9 +323,9 @@ class Input { /// FILE* handler functor base class to analyze FILE* input, handle errors and non-blocking FILE* reads struct Handler { virtual size_t operator()(- FILE*, ///< open file- char*, ///< pointer to buffer with data read from file, may be changed by handler- size_t ///< length of the buffered data, should be returned by the functor, or shorter to ignore or zero to force EOF and stop reading+ FILE *file, ///< open file+ char *buf, ///< pointer to buffer with data read from file, may be changed by handler+ size_t len ///< length of the buffered data, should be returned by the functor, or shorter to ignore or zero to force EOF and stop reading ) = 0; virtual ~Handler() { }; };
@@ -69,12 +69,12 @@ class LineMatcher : public AbstractMatcher { return *this; } /// Polymorphic cloning.- virtual LineMatcher *clone()+ virtual LineMatcher *clone() REFLEX_OVERRIDE { return new LineMatcher(*this); } /// Reset this matcher's state to the initial state and when assigned new input.- virtual void reset(const char *opt = NULL)+ virtual void reset(const char *opt = NULL) REFLEX_OVERRIDE { DBGLOG("LineMatcher::reset()"); AbstractMatcher::reset(opt);@@ -83,19 +83,21 @@ class LineMatcher : public AbstractMatcher { /// Returns a pair <text(),size() for any n virtual std::pair<const char*,size_t> operator[](size_t) ///< ignored /// @returns pair.- const+ const REFLEX_OVERRIDE { return std::pair<const char*,size_t>(txt_, len_); } /// Returns (0,NULL) virtual std::pair<size_t,const char*> group_id() /// @returns a pair of size_t and string+ REFLEX_OVERRIDE { return std::pair<size_t,const char*>(0, static_cast<const char*>(NULL)); // cast to appease MSVC 2010 } /// Returns (0,NULL) virtual std::pair<size_t,const char*> group_next_id() /// @returns a pair of size_t and string+ REFLEX_OVERRIDE { return std::pair<size_t,const char*>(0, static_cast<const char*>(NULL)); // cast to appease MSVC 2010 }@@ -103,6 +105,7 @@ class LineMatcher : public AbstractMatcher { /// The match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH virtual size_t match(Method method) ///< match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH /// @returns nonzero when input matched a line+ REFLEX_OVERRIDE { DBGLOG("BEGIN LineMatcher::match(%d)", method); reset_text();
@@ -121,6 +121,7 @@ class Matcher : public PatternMatcher<reflex::Pattern> { /// Set the pattern to use with this matcher (the given pattern is shared and must be persistent). virtual Matcher& pattern(const Pattern& pattern) ///< pattern object for this matcher /// @returns this matcher+ REFLEX_OVERRIDE { DBGLOG("Matcher::pattern()"); if (pat_ != &pattern)@@ -133,6 +134,7 @@ class Matcher : public PatternMatcher<reflex::Pattern> { /// Set the pattern to use with this matcher (the given pattern is shared and must be persistent). virtual Matcher& pattern(const Pattern *pattern) ///< pattern object for this matcher /// @returns this matcher+ REFLEX_OVERRIDE { DBGLOG("Matcher::pattern()"); if (pat_ != pattern)@@ -145,6 +147,7 @@ class Matcher : public PatternMatcher<reflex::Pattern> { /// Set the pattern from a regex string to use with this matcher. virtual Matcher& pattern(const char *pattern) ///< regex string to instantiate internal pattern object /// @returns this matcher+ REFLEX_OVERRIDE { DBGLOG("Matcher::pattern(\"%s\")", pattern); PatternMatcher<reflex::Pattern>::pattern(pattern);@@ -154,6 +157,7 @@ class Matcher : public PatternMatcher<reflex::Pattern> { /// Set the pattern from a regex string to use with this matcher. virtual Matcher& pattern(const std::string& pattern) ///< regex string to instantiate internal pattern object /// @returns this matcher+ REFLEX_OVERRIDE { DBGLOG("Matcher::pattern(\"%s\")", pattern.c_str()); PatternMatcher<reflex::Pattern>::pattern(pattern);@@ -161,19 +165,20 @@ class Matcher : public PatternMatcher<reflex::Pattern> { return *this; } /// Returns a reference to the pattern associated with this matcher.- virtual const Pattern& pattern() const+ virtual const Pattern& pattern() /// @returns reference to pattern+ const REFLEX_OVERRIDE { ASSERT(pat_ != NULL); return *pat_; } /// Polymorphic cloning.- virtual Matcher *clone()+ virtual Matcher *clone() REFLEX_OVERRIDE { return new Matcher(*this); } /// Reset this matcher's state to the initial state.- virtual void reset(const char *opt = NULL)+ virtual void reset(const char *opt = NULL) REFLEX_OVERRIDE { DBGLOG("Matcher::reset()"); PatternMatcher<reflex::Pattern>::reset(opt);@@ -182,7 +187,7 @@ class Matcher : public PatternMatcher<reflex::Pattern> { init_advance(); } /// Returns captured text as a std::pair<const char*,size_t> with string pointer (non-0-terminated) and length.- virtual std::pair<const char*,size_t> operator[](size_t n) const+ virtual std::pair<const char*,size_t> operator[](size_t n) const REFLEX_OVERRIDE { if (n == 0) return std::pair<const char*,size_t>(txt_, len_);@@ -191,12 +196,14 @@ class Matcher : public PatternMatcher<reflex::Pattern> { /// Returns the group capture identifier containing the group capture index >0 and name (or NULL) of a named group capture, or (1,NULL) by default virtual std::pair<size_t,const char*> group_id() /// @returns a pair of size_t and string+ REFLEX_OVERRIDE { return std::pair<size_t,const char*>(accept(), static_cast<const char*>(NULL)); // cast to appease MSVC 2010 } /// Returns the next group capture identifier containing the group capture index >0 and name (or NULL) of a named group capture, or (0,NULL) when no more groups matched virtual std::pair<size_t,const char*> group_next_id() /// @returns (0,NULL)+ REFLEX_OVERRIDE { return std::pair<size_t,const char*>(0, static_cast<const char*>(NULL)); // cast to appease MSVC 2010 }@@ -1320,6 +1327,7 @@ class Matcher : public PatternMatcher<reflex::Pattern> { /// Returns true if input matched the pattern using method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH. virtual size_t match(Method method) ///< Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH /// @returns nonzero if input matched the pattern+ REFLEX_OVERRIDE ; /// match() with optimized AVX512BW string search scheme defined in matcher_avx512bw.cpp size_t simd_match_avx512bw(Method method);
@@ -142,12 +142,12 @@ class PCRE2Matcher : public PatternMatcher<std::string> { return *this; } /// Polymorphic cloning.- virtual PCRE2Matcher *clone()+ virtual PCRE2Matcher *clone() REFLEX_OVERRIDE { return new PCRE2Matcher(*this); } /// Reset this matcher's state to the initial state and when assigned new input.- virtual void reset(const char *opt = NULL)+ virtual void reset(const char *opt = NULL) REFLEX_OVERRIDE { DBGLOG("PCRE2Matcher::reset()"); flg_ = 0;@@ -191,6 +191,7 @@ class PCRE2Matcher : public PatternMatcher<std::string> { /// Set the pattern regex string to use with this matcher (the given pattern is shared and must be persistent). virtual PatternMatcher& pattern(const Pattern *pattern) ///< pointer to a regex string /// @returns this matcher.+ REFLEX_OVERRIDE { PatternMatcher::pattern(pattern); compile();@@ -199,6 +200,7 @@ class PCRE2Matcher : public PatternMatcher<std::string> { /// Set the pattern regex string to use with this matcher. virtual PatternMatcher& pattern(const char *pattern) ///< regex string /// @returns this matcher.+ REFLEX_OVERRIDE { PatternMatcher::pattern(pattern); compile();@@ -207,6 +209,7 @@ class PCRE2Matcher : public PatternMatcher<std::string> { /// Set the pattern regex string to use with this matcher. virtual PatternMatcher& pattern(const std::string& pattern) ///< regex string /// @returns this matcher.+ REFLEX_OVERRIDE { PatternMatcher::pattern(pattern); compile();@@ -215,7 +218,7 @@ class PCRE2Matcher : public PatternMatcher<std::string> { /// Returns a pair of pointer and length of the captured match for n > 0 capture index or <text(),size() for n == 0. virtual std::pair<const char*,size_t> operator[](size_t n) ///< nth capture index > 0 or 0 /// @returns pair.- const+ const REFLEX_OVERRIDE { if (n == 0) return std::pair<const char*,size_t>(txt_, len_);@@ -230,6 +233,7 @@ class PCRE2Matcher : public PatternMatcher<std::string> { /// Returns the group capture identifier containing the group capture index >0 and name (or NULL) of a named group capture, or (1,NULL) by default virtual std::pair<size_t,const char*> group_id() /// @returns a pair of size_t and string+ REFLEX_OVERRIDE { grp_ = 1; if (dat_ == NULL || pcre2_get_ovector_count(dat_) <= 1)@@ -242,6 +246,7 @@ class PCRE2Matcher : public PatternMatcher<std::string> { /// Returns the next group capture identifier containing the group capture index >0 and name (or NULL) of a named group capture, or (0,NULL) when no more groups matched virtual std::pair<size_t,const char*> group_next_id() /// @returns a pair of size_t and string+ REFLEX_OVERRIDE { if (dat_ == NULL) return std::pair<size_t,const char*>(0, static_cast<const char*>(NULL)); // cast to appease MSVC 2010@@ -311,6 +316,7 @@ class PCRE2Matcher : public PatternMatcher<std::string> { /// The match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH, implemented with PCRE2. virtual size_t match(Method method) ///< match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH /// @returns nonzero when input matched the pattern using method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH.+ REFLEX_OVERRIDE { DBGLOG("BEGIN PCRE2Matcher::match(%d)", method); reset_text();
@@ -95,12 +95,12 @@ class StdMatcher : public PatternMatcher<std::regex> { return *this; } /// Polymorphic cloning.- virtual StdMatcher *clone()+ virtual StdMatcher *clone() REFLEX_OVERRIDE { return new StdMatcher(*this); } /// Reset this matcher's state to the initial state and when assigned new input.- virtual void reset(const char *opt = NULL)+ virtual void reset(const char *opt = NULL) REFLEX_OVERRIDE { DBGLOG("StdMatcher::reset()"); itr_ = fin_ = std::cregex_iterator();@@ -120,6 +120,7 @@ class StdMatcher : public PatternMatcher<std::regex> { /// Set the pattern to use with this matcher (the given pattern is shared and must be persistent), overrides the ECMA/POSIX/AWK syntax option. virtual PatternMatcher& pattern(const Pattern *pattern) ///< std::regex for this matcher /// @returns this matcher.+ REFLEX_OVERRIDE { itr_ = fin_; return PatternMatcher::pattern(pattern);@@ -127,6 +128,7 @@ class StdMatcher : public PatternMatcher<std::regex> { /// Set the pattern to use with this matcher (the given pattern is shared and must be persistent), overrides the ECMA/POSIX/AWK syntax option. virtual PatternMatcher& pattern(const Pattern& pattern) ///< std::regex for this matcher /// @returns this matcher.+ REFLEX_OVERRIDE { itr_ = fin_; return PatternMatcher::pattern(pattern);@@ -134,6 +136,7 @@ class StdMatcher : public PatternMatcher<std::regex> { /// Set the pattern from a regex string to use with this matcher. virtual PatternMatcher& pattern(const char *pattern) ///< regex string to instantiate internal pattern object /// @returns this matcher.+ REFLEX_OVERRIDE { itr_ = fin_; PatternMatcher::pattern(new std::regex(pattern));@@ -143,13 +146,14 @@ class StdMatcher : public PatternMatcher<std::regex> { /// Set the pattern from a regex string to use with this matcher. virtual PatternMatcher& pattern(const std::string& pattern) ///< regex string to instantiate internal pattern object /// @returns this matcher.+ REFLEX_OVERRIDE { itr_ = fin_; PatternMatcher::pattern(new std::regex(pattern)); own_ = true; return *this; }- virtual std::pair<const char*,size_t> operator[](size_t n) const+ virtual std::pair<const char*,size_t> operator[](size_t n) const REFLEX_OVERRIDE { if (n == 0) return std::pair<const char*,size_t>(txt_, len_);@@ -160,6 +164,7 @@ class StdMatcher : public PatternMatcher<std::regex> { /// Returns the group capture identifier containing the group capture index >0 and name (or NULL) of a named group capture, or (1,NULL) by default virtual std::pair<size_t,const char*> group_id() /// @returns a pair of size_t and string+ REFLEX_OVERRIDE { grp_ = 1; if (itr_ == fin_ || (*itr_).size() <= 1)@@ -171,6 +176,7 @@ class StdMatcher : public PatternMatcher<std::regex> { /// Returns the next group capture identifier containing the group capture index >0 and name (or NULL) of a named group capture, or (0,NULL) when no more groups matched virtual std::pair<size_t,const char*> group_next_id() /// @returns a pair of size_t and string+ REFLEX_OVERRIDE { if (itr_ == fin_) return std::pair<size_t,const char*>(0, static_cast<const char*>(NULL)); // cast to appease MSVC 2010@@ -186,6 +192,7 @@ class StdMatcher : public PatternMatcher<std::regex> { /// The match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH, implemented with std::regex. virtual size_t match(Method method) ///< match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH /// @returns nonzero when input matched the pattern using method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH.+ REFLEX_OVERRIDE { DBGLOG("BEGIN StdMatcher::match(%d)", method); reset_text();@@ -411,6 +418,7 @@ class StdEcmaMatcher : public StdMatcher { /// Set the pattern to use with this matcher (the given pattern is shared and must be persistent), fails when a POSIX std::regex is given. virtual PatternMatcher& pattern(const Pattern& pattern) ///< std::regex for this matcher /// @returns this matcher.+ REFLEX_OVERRIDE { ASSERT(!(pattern.flags() & (std::regex::basic | std::regex::extended | std::regex::awk))); return StdMatcher::pattern(pattern);@@ -418,6 +426,7 @@ class StdEcmaMatcher : public StdMatcher { /// Set the pattern to use with this matcher (the given pattern is shared and must be persistent), fails when a POSIX std::regex is given. virtual PatternMatcher& pattern(const Pattern *pattern) ///< std::regex for this matcher /// @returns this matcher.+ REFLEX_OVERRIDE { ASSERT(!(pattern.flags() & (std::regex::basic | std::regex::extended | std::regex::awk))); return StdMatcher::pattern(pattern);@@ -425,6 +434,7 @@ class StdEcmaMatcher : public StdMatcher { /// Set the pattern from a regex string to use with this matcher. virtual PatternMatcher& pattern(const char *pattern) ///< regex string to instantiate internal pattern object /// @returns this matcher.+ REFLEX_OVERRIDE { itr_ = fin_; PatternMatcher::pattern(new std::regex(pattern, std::regex::ECMAScript));@@ -434,6 +444,7 @@ class StdEcmaMatcher : public StdMatcher { /// Set the pattern from a regex string to use with this matcher. virtual PatternMatcher& pattern(const std::string& pattern) ///< regex string to instantiate internal pattern object /// @returns this matcher.+ REFLEX_OVERRIDE { itr_ = fin_; PatternMatcher::pattern(new std::regex(pattern, std::regex::ECMAScript));@@ -492,6 +503,7 @@ class StdPosixMatcher : public StdMatcher { /// Set the pattern to use with this matcher (the given pattern is shared and must be persistent), fails when a non-POSIX ERE std::regex is given. virtual PatternMatcher& pattern(const Pattern& pattern) ///< std::regex for this matcher /// @returns this matcher.+ REFLEX_OVERRIDE { ASSERT(pattern.flags() & std::regex::awk); return StdMatcher::pattern(pattern);@@ -499,6 +511,7 @@ class StdPosixMatcher : public StdMatcher { /// Set the pattern to use with this matcher (the given pattern is shared and must be persistent), fails when a non-POSIX ERE std::regex is given. virtual PatternMatcher& pattern(const Pattern *pattern) ///< std::regex for this matcher /// @returns this matcher.+ REFLEX_OVERRIDE { ASSERT(pattern.flags() & std::regex::awk); return StdMatcher::pattern(pattern);@@ -506,6 +519,7 @@ class StdPosixMatcher : public StdMatcher { /// Set the pattern from a regex string to use with this matcher. virtual PatternMatcher& pattern(const char *pattern) ///< regex string to instantiate internal pattern object /// @returns this matcher.+ REFLEX_OVERRIDE { itr_ = fin_; PatternMatcher::pattern(new std::regex(pattern, std::regex::awk));@@ -515,6 +529,7 @@ class StdPosixMatcher : public StdMatcher { /// Set the pattern from a regex string to use with this matcher. virtual PatternMatcher& pattern(const std::string& pattern) ///< regex string to instantiate internal pattern object /// @returns this matcher.+ REFLEX_OVERRIDE { itr_ = fin_; PatternMatcher::pattern(new std::regex(pattern, std::regex::awk));
@@ -4362,7 +4362,7 @@ void Pattern::analyze_dfa(DFA::State *start) { if (pmh_[i] != 0xff) {- if (isprint(pmh_[i]))+ if (isprint(i)) DBGLOGN("pmh['%c'] = %02x", i, pmh_[i]); else DBGLOGN("pmh[%3d] = %02x", i, pmh_[i]);@@ -4372,7 +4372,7 @@ void Pattern::analyze_dfa(DFA::State *start) { if (pma_[i] != 0xff) {- if (isprint(pma_[i]))+ if (isprint(i)) DBGLOGN("pma['%c'] = %02x", i, pma_[i]); else DBGLOGN("pma[%3d] = %02x", i, pma_[i]);