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