Skip to content

Commit 79e2ec1

Browse files
committed
some cleanup with override specifiers
1 parent 2d54bf9 commit 79e2ec1

File tree

9 files changed

+76
-21
lines changed

9 files changed

+76
-21
lines changed

include/reflex/abslexer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class AbstractLexer {
7676
{
7777
M::operator=(matcher);
7878
lexer_ = matcher.lexer_;
79+
return *this;
7980
}
8081
protected:
8182
/// Returns true if matcher should wrap input after EOF (lexer wrap() should return 0 to wrap input after EOF).

include/reflex/absmatcher.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@
3737
#ifndef REFLEX_ABSMATCHER_H
3838
#define REFLEX_ABSMATCHER_H
3939

40+
/// Permit legacy C++ compilation of override (ignored) and C++11 override (applied).
41+
#if __cplusplus < 201103L
42+
#define REFLEX_OVERRIDE
43+
#else
44+
#define REFLEX_OVERRIDE override
45+
#endif
46+
47+
#if defined(__GNUC__) || defined(__clang__)
48+
#define REFLEX_LIKELY(x) __builtin_expect(!!(x), 1)
49+
#define REFLEX_UNLIKELY(x) __builtin_expect(!!(x), 0)
50+
#else
51+
#define REFLEX_LIKELY(x) (x)
52+
#define REFLEX_UNLIKELY(x) (x)
53+
#endif
54+
4055
/// This compile-time option may speed up buffer reallocation with realloc() instead of new and delete.
4156
#ifndef WITH_REALLOC
4257
#define WITH_REALLOC 1

include/reflex/boostmatcher.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ class BoostMatcher : public PatternMatcher<boost::regex> {
9898
return *this;
9999
}
100100
/// Polymorphic cloning.
101-
virtual BoostMatcher *clone()
101+
virtual BoostMatcher *clone() REFLEX_OVERRIDE
102102
{
103103
return new BoostMatcher(*this);
104104
}
105105
/// Reset this matcher's state to the initial state and when assigned new input.
106-
virtual void reset(const char *opt = NULL)
106+
virtual void reset(const char *opt = NULL) REFLEX_OVERRIDE
107107
{
108108
DBGLOG("BoostMatcher::reset()");
109109
itr_ = fin_ = boost::cregex_iterator();
@@ -122,35 +122,39 @@ class BoostMatcher : public PatternMatcher<boost::regex> {
122122
/// Set the pattern to use with this matcher (the given pattern is shared and must be persistent).
123123
virtual PatternMatcher& pattern(const Pattern& pattern) ///< boost::regex for this matcher
124124
/// @returns this matcher.
125+
REFLEX_OVERRIDE
125126
{
126127
itr_ = fin_;
127128
return PatternMatcher::pattern(pattern);
128129
}
129130
/// Set the pattern to use with this matcher (the given pattern is shared and must be persistent).
130131
virtual PatternMatcher& pattern(const Pattern *pattern) ///< boost::regex for this matcher
131132
/// @returns this matcher.
133+
REFLEX_OVERRIDE
132134
{
133135
itr_ = fin_;
134136
return PatternMatcher::pattern(pattern);
135137
}
136138
/// Set the pattern from a regex string to use with this matcher.
137139
virtual PatternMatcher& pattern(const char *pattern) ///< regex string to instantiate internal pattern object
138140
/// @returns this matcher.
141+
REFLEX_OVERRIDE
139142
{
140143
itr_ = fin_;
141144
return PatternMatcher::pattern(pattern);
142145
}
143146
/// Set the pattern from a regex string to use with this matcher.
144147
virtual PatternMatcher& pattern(const std::string& pattern) ///< regex string to instantiate internal pattern object
145148
/// @returns this matcher.
149+
REFLEX_OVERRIDE
146150
{
147151
itr_ = fin_;
148152
return PatternMatcher::pattern(pattern);
149153
}
150154
/// Returns a pair of pointer and length of the captured match for n > 0 capture index or <text(),size() for n == 0.
151155
virtual std::pair<const char*,size_t> operator[](size_t n) ///< nth capture index > 0 or 0
152156
/// @returns pair.
153-
const
157+
const REFLEX_OVERRIDE
154158
{
155159
if (n == 0)
156160
return std::pair<const char*,size_t>(txt_, len_);
@@ -161,6 +165,7 @@ class BoostMatcher : public PatternMatcher<boost::regex> {
161165
/// 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
162166
virtual std::pair<size_t,const char*> group_id()
163167
/// @returns a pair of size_t and string
168+
REFLEX_OVERRIDE
164169
{
165170
grp_ = 1;
166171
if (itr_ == fin_ || (*itr_).size() <= 1)
@@ -172,6 +177,7 @@ class BoostMatcher : public PatternMatcher<boost::regex> {
172177
/// 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
173178
virtual std::pair<size_t,const char*> group_next_id()
174179
/// @returns a pair of size_t and string
180+
REFLEX_OVERRIDE
175181
{
176182
if (itr_ == fin_)
177183
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> {
187193
/// The match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH, implemented with boost::regex.
188194
virtual size_t match(Method method) ///< match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH
189195
/// @returns nonzero when input matched the pattern using method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH.
196+
REFLEX_OVERRIDE
190197
{
191198
DBGLOG("BEGIN BoostMatcher::match(%d)", method);
192199
reset_text();

include/reflex/input.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ class Input {
323323
/// FILE* handler functor base class to analyze FILE* input, handle errors and non-blocking FILE* reads
324324
struct Handler {
325325
virtual size_t operator()(
326-
FILE*, ///< open file
327-
char*, ///< pointer to buffer with data read from file, may be changed by handler
328-
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
326+
FILE *file, ///< open file
327+
char *buf, ///< pointer to buffer with data read from file, may be changed by handler
328+
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
329329
) = 0;
330330
virtual ~Handler() { };
331331
};

include/reflex/linematcher.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ class LineMatcher : public AbstractMatcher {
6969
return *this;
7070
}
7171
/// Polymorphic cloning.
72-
virtual LineMatcher *clone()
72+
virtual LineMatcher *clone() REFLEX_OVERRIDE
7373
{
7474
return new LineMatcher(*this);
7575
}
7676
/// Reset this matcher's state to the initial state and when assigned new input.
77-
virtual void reset(const char *opt = NULL)
77+
virtual void reset(const char *opt = NULL) REFLEX_OVERRIDE
7878
{
7979
DBGLOG("LineMatcher::reset()");
8080
AbstractMatcher::reset(opt);
@@ -83,26 +83,29 @@ class LineMatcher : public AbstractMatcher {
8383
/// Returns a pair <text(),size() for any n
8484
virtual std::pair<const char*,size_t> operator[](size_t) ///< ignored
8585
/// @returns pair.
86-
const
86+
const REFLEX_OVERRIDE
8787
{
8888
return std::pair<const char*,size_t>(txt_, len_);
8989
}
9090
/// Returns (0,NULL)
9191
virtual std::pair<size_t,const char*> group_id()
9292
/// @returns a pair of size_t and string
93+
REFLEX_OVERRIDE
9394
{
9495
return std::pair<size_t,const char*>(0, static_cast<const char*>(NULL)); // cast to appease MSVC 2010
9596
}
9697
/// Returns (0,NULL)
9798
virtual std::pair<size_t,const char*> group_next_id()
9899
/// @returns a pair of size_t and string
100+
REFLEX_OVERRIDE
99101
{
100102
return std::pair<size_t,const char*>(0, static_cast<const char*>(NULL)); // cast to appease MSVC 2010
101103
}
102104
protected:
103105
/// The match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH
104106
virtual size_t match(Method method) ///< match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH
105107
/// @returns nonzero when input matched a line
108+
REFLEX_OVERRIDE
106109
{
107110
DBGLOG("BEGIN LineMatcher::match(%d)", method);
108111
reset_text();

include/reflex/matcher.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ class Matcher : public PatternMatcher<reflex::Pattern> {
121121
/// Set the pattern to use with this matcher (the given pattern is shared and must be persistent).
122122
virtual Matcher& pattern(const Pattern& pattern) ///< pattern object for this matcher
123123
/// @returns this matcher
124+
REFLEX_OVERRIDE
124125
{
125126
DBGLOG("Matcher::pattern()");
126127
if (pat_ != &pattern)
@@ -133,6 +134,7 @@ class Matcher : public PatternMatcher<reflex::Pattern> {
133134
/// Set the pattern to use with this matcher (the given pattern is shared and must be persistent).
134135
virtual Matcher& pattern(const Pattern *pattern) ///< pattern object for this matcher
135136
/// @returns this matcher
137+
REFLEX_OVERRIDE
136138
{
137139
DBGLOG("Matcher::pattern()");
138140
if (pat_ != pattern)
@@ -145,6 +147,7 @@ class Matcher : public PatternMatcher<reflex::Pattern> {
145147
/// Set the pattern from a regex string to use with this matcher.
146148
virtual Matcher& pattern(const char *pattern) ///< regex string to instantiate internal pattern object
147149
/// @returns this matcher
150+
REFLEX_OVERRIDE
148151
{
149152
DBGLOG("Matcher::pattern(\"%s\")", pattern);
150153
PatternMatcher<reflex::Pattern>::pattern(pattern);
@@ -154,26 +157,28 @@ class Matcher : public PatternMatcher<reflex::Pattern> {
154157
/// Set the pattern from a regex string to use with this matcher.
155158
virtual Matcher& pattern(const std::string& pattern) ///< regex string to instantiate internal pattern object
156159
/// @returns this matcher
160+
REFLEX_OVERRIDE
157161
{
158162
DBGLOG("Matcher::pattern(\"%s\")", pattern.c_str());
159163
PatternMatcher<reflex::Pattern>::pattern(pattern);
160164
init_advance();
161165
return *this;
162166
}
163167
/// Returns a reference to the pattern associated with this matcher.
164-
virtual const Pattern& pattern() const
168+
virtual const Pattern& pattern()
165169
/// @returns reference to pattern
170+
const REFLEX_OVERRIDE
166171
{
167172
ASSERT(pat_ != NULL);
168173
return *pat_;
169174
}
170175
/// Polymorphic cloning.
171-
virtual Matcher *clone()
176+
virtual Matcher *clone() REFLEX_OVERRIDE
172177
{
173178
return new Matcher(*this);
174179
}
175180
/// Reset this matcher's state to the initial state.
176-
virtual void reset(const char *opt = NULL)
181+
virtual void reset(const char *opt = NULL) REFLEX_OVERRIDE
177182
{
178183
DBGLOG("Matcher::reset()");
179184
PatternMatcher<reflex::Pattern>::reset(opt);
@@ -182,7 +187,7 @@ class Matcher : public PatternMatcher<reflex::Pattern> {
182187
init_advance();
183188
}
184189
/// Returns captured text as a std::pair<const char*,size_t> with string pointer (non-0-terminated) and length.
185-
virtual std::pair<const char*,size_t> operator[](size_t n) const
190+
virtual std::pair<const char*,size_t> operator[](size_t n) const REFLEX_OVERRIDE
186191
{
187192
if (n == 0)
188193
return std::pair<const char*,size_t>(txt_, len_);
@@ -191,12 +196,14 @@ class Matcher : public PatternMatcher<reflex::Pattern> {
191196
/// 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
192197
virtual std::pair<size_t,const char*> group_id()
193198
/// @returns a pair of size_t and string
199+
REFLEX_OVERRIDE
194200
{
195201
return std::pair<size_t,const char*>(accept(), static_cast<const char*>(NULL)); // cast to appease MSVC 2010
196202
}
197203
/// 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
198204
virtual std::pair<size_t,const char*> group_next_id()
199205
/// @returns (0,NULL)
206+
REFLEX_OVERRIDE
200207
{
201208
return std::pair<size_t,const char*>(0, static_cast<const char*>(NULL)); // cast to appease MSVC 2010
202209
}
@@ -1320,6 +1327,7 @@ class Matcher : public PatternMatcher<reflex::Pattern> {
13201327
/// Returns true if input matched the pattern using method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH.
13211328
virtual size_t match(Method method) ///< Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH
13221329
/// @returns nonzero if input matched the pattern
1330+
REFLEX_OVERRIDE
13231331
;
13241332
/// match() with optimized AVX512BW string search scheme defined in matcher_avx512bw.cpp
13251333
size_t simd_match_avx512bw(Method method);

include/reflex/pcre2matcher.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ class PCRE2Matcher : public PatternMatcher<std::string> {
142142
return *this;
143143
}
144144
/// Polymorphic cloning.
145-
virtual PCRE2Matcher *clone()
145+
virtual PCRE2Matcher *clone() REFLEX_OVERRIDE
146146
{
147147
return new PCRE2Matcher(*this);
148148
}
149149
/// Reset this matcher's state to the initial state and when assigned new input.
150-
virtual void reset(const char *opt = NULL)
150+
virtual void reset(const char *opt = NULL) REFLEX_OVERRIDE
151151
{
152152
DBGLOG("PCRE2Matcher::reset()");
153153
flg_ = 0;
@@ -191,6 +191,7 @@ class PCRE2Matcher : public PatternMatcher<std::string> {
191191
/// Set the pattern regex string to use with this matcher (the given pattern is shared and must be persistent).
192192
virtual PatternMatcher& pattern(const Pattern *pattern) ///< pointer to a regex string
193193
/// @returns this matcher.
194+
REFLEX_OVERRIDE
194195
{
195196
PatternMatcher::pattern(pattern);
196197
compile();
@@ -199,6 +200,7 @@ class PCRE2Matcher : public PatternMatcher<std::string> {
199200
/// Set the pattern regex string to use with this matcher.
200201
virtual PatternMatcher& pattern(const char *pattern) ///< regex string
201202
/// @returns this matcher.
203+
REFLEX_OVERRIDE
202204
{
203205
PatternMatcher::pattern(pattern);
204206
compile();
@@ -207,6 +209,7 @@ class PCRE2Matcher : public PatternMatcher<std::string> {
207209
/// Set the pattern regex string to use with this matcher.
208210
virtual PatternMatcher& pattern(const std::string& pattern) ///< regex string
209211
/// @returns this matcher.
212+
REFLEX_OVERRIDE
210213
{
211214
PatternMatcher::pattern(pattern);
212215
compile();
@@ -215,7 +218,7 @@ class PCRE2Matcher : public PatternMatcher<std::string> {
215218
/// Returns a pair of pointer and length of the captured match for n > 0 capture index or <text(),size() for n == 0.
216219
virtual std::pair<const char*,size_t> operator[](size_t n) ///< nth capture index > 0 or 0
217220
/// @returns pair.
218-
const
221+
const REFLEX_OVERRIDE
219222
{
220223
if (n == 0)
221224
return std::pair<const char*,size_t>(txt_, len_);
@@ -230,6 +233,7 @@ class PCRE2Matcher : public PatternMatcher<std::string> {
230233
/// 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
231234
virtual std::pair<size_t,const char*> group_id()
232235
/// @returns a pair of size_t and string
236+
REFLEX_OVERRIDE
233237
{
234238
grp_ = 1;
235239
if (dat_ == NULL || pcre2_get_ovector_count(dat_) <= 1)
@@ -242,6 +246,7 @@ class PCRE2Matcher : public PatternMatcher<std::string> {
242246
/// 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
243247
virtual std::pair<size_t,const char*> group_next_id()
244248
/// @returns a pair of size_t and string
249+
REFLEX_OVERRIDE
245250
{
246251
if (dat_ == NULL)
247252
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> {
311316
/// The match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH, implemented with PCRE2.
312317
virtual size_t match(Method method) ///< match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH
313318
/// @returns nonzero when input matched the pattern using method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH.
319+
REFLEX_OVERRIDE
314320
{
315321
DBGLOG("BEGIN PCRE2Matcher::match(%d)", method);
316322
reset_text();

0 commit comments

Comments
 (0)