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