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 "re2/regexp.h"
7#include "re2/walker-inl.h"
8
9namespace re2 {
10
11// Null walker.  For benchmarking the walker itself.
12
13class NullWalker : public Regexp::Walker<bool> {
14 public:
15  NullWalker() { }
16  bool PostVisit(Regexp* re, bool parent_arg, bool pre_arg,
17                 bool* child_args, int nchild_args);
18
19  bool ShortVisit(Regexp* re, bool a) {
20    // Should never be called: we use Walk not WalkExponential.
21    LOG(DFATAL) << "NullWalker::ShortVisit called";
22    return a;
23  }
24
25 private:
26  DISALLOW_EVIL_CONSTRUCTORS(NullWalker);
27};
28
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
31// can match an empty string).  Returns whether this clause can match an
32// empty string.
33bool NullWalker::PostVisit(Regexp* re, bool parent_arg, bool pre_arg,
34                                  bool* child_args, int nchild_args) {
35  return false;
36}
37
38// Returns whether re can match an empty string.
39void Regexp::NullWalk() {
40  NullWalker w;
41  w.Walk(this, false);
42}
43
44}  // namespace re2
45