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 "absl/log/absl_log.h"
6 #include "re2/regexp.h"
7 #include "re2/walker-inl.h"
8
9 namespace re2 {
10
11 // Null walker. For benchmarking the walker itself.
12
13 class NullWalker : public Regexp::Walker<bool> {
14 public:
NullWalker()15 NullWalker() {}
16
17 virtual bool PostVisit(Regexp* re, bool parent_arg, bool pre_arg,
18 bool* child_args, int nchild_args);
19
ShortVisit(Regexp * re,bool a)20 virtual bool ShortVisit(Regexp* re, bool a) {
21 // Should never be called: we use Walk(), not WalkExponential().
22 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
23 ABSL_LOG(DFATAL) << "NullWalker::ShortVisit called";
24 #endif
25 return a;
26 }
27
28 private:
29 NullWalker(const NullWalker&) = delete;
30 NullWalker& operator=(const NullWalker&) = delete;
31 };
32
33 // Called after visiting re's children. child_args contains the return
34 // value from each of the children's PostVisits (i.e., whether each child
35 // can match an empty string). Returns whether this clause can match an
36 // empty string.
PostVisit(Regexp * re,bool parent_arg,bool pre_arg,bool * child_args,int nchild_args)37 bool NullWalker::PostVisit(Regexp* re, bool parent_arg, bool pre_arg,
38 bool* child_args, int nchild_args) {
39 return false;
40 }
41
42 // Returns whether re can match an empty string.
NullWalk()43 void Regexp::NullWalk() {
44 NullWalker w;
45 w.Walk(this, false);
46 }
47
48 } // namespace re2
49