OLD | NEW |
1 // Copyright 2009 The RE2 Authors. All Rights Reserved. | 1 // Copyright 2009 The RE2 Authors. All Rights Reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include "util/test.h" | 5 #include "util/test.h" |
6 #include "re2/regexp.h" | 6 #include "re2/regexp.h" |
7 #include "re2/walker-inl.h" | 7 #include "re2/walker-inl.h" |
8 | 8 |
9 namespace re2 { | 9 namespace re2 { |
10 | 10 |
11 // Null walker. For benchmarking the walker itself. | 11 // Null walker. For benchmarking the walker itself. |
12 | 12 |
13 class NullWalker : public Regexp::Walker<bool> { | 13 class NullWalker : public Regexp::Walker<bool> { |
14 public: | 14 public: |
15 NullWalker() { } | 15 NullWalker() { } |
16 bool PostVisit(Regexp* re, bool parent_arg, bool pre_arg, | 16 bool PostVisit(Regexp* re, bool parent_arg, bool pre_arg, |
17 bool* child_args, int nchild_args); | 17 bool* child_args, int nchild_args); |
18 | 18 |
19 bool ShortVisit(Regexp* re, bool a) { | 19 bool ShortVisit(Regexp* re, bool a) { |
20 // Should never be called: we use Walk not WalkExponential. | 20 // Should never be called: we use Walk not WalkExponential. |
21 LOG(DFATAL) << "NullWalker::ShortVisit called"; | 21 LOG(DFATAL) << "NullWalker::ShortVisit called"; |
22 return a; | 22 return a; |
23 } | 23 } |
24 | 24 |
25 private: | 25 private: |
26 DISALLOW_COPY_AND_ASSIGN(NullWalker); | 26 DISALLOW_EVIL_CONSTRUCTORS(NullWalker); |
27 }; | 27 }; |
28 | 28 |
29 // Called after visiting re's children. child_args contains the return | 29 // Called after visiting re's children. child_args contains the return |
30 // value from each of the children's PostVisits (i.e., whether each child | 30 // value from each of the children's PostVisits (i.e., whether each child |
31 // can match an empty string). Returns whether this clause can match an | 31 // can match an empty string). Returns whether this clause can match an |
32 // empty string. | 32 // empty string. |
33 bool NullWalker::PostVisit(Regexp* re, bool parent_arg, bool pre_arg, | 33 bool NullWalker::PostVisit(Regexp* re, bool parent_arg, bool pre_arg, |
34 bool* child_args, int nchild_args) { | 34 bool* child_args, int nchild_args) { |
35 return false; | 35 return false; |
36 } | 36 } |
37 | 37 |
38 // Returns whether re can match an empty string. | 38 // Returns whether re can match an empty string. |
39 void Regexp::NullWalk() { | 39 void Regexp::NullWalk() { |
40 NullWalker w; | 40 NullWalker w; |
41 w.Walk(this, false); | 41 w.Walk(this, false); |
42 } | 42 } |
43 | 43 |
44 } // namespace re2 | 44 } // namespace re2 |
OLD | NEW |