[DevTools] Remove forwarded connections counting
[chromium-blink-merge.git] / third_party / re2 / re2 / prefilter.h
blobc2f9dddd85656f4b16dedca3174bbd567a8980e6
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.
5 // Prefilter is the class used to extract string guards from regexps.
6 // Rather than using Prefilter class directly, use FilteredRE2.
7 // See filtered_re2.h
9 #ifndef RE2_PREFILTER_H_
10 #define RE2_PREFILTER_H_
12 #include "util/util.h"
14 namespace re2 {
16 class RE2;
18 class Regexp;
20 class Prefilter {
21 // Instead of using Prefilter directly, use FilteredRE2; see filtered_re2.h
22 public:
23 enum Op {
24 ALL = 0, // Everything matches
25 NONE, // Nothing matches
26 ATOM, // The string atom() must match
27 AND, // All in subs() must match
28 OR, // One of subs() must match
31 explicit Prefilter(Op op);
32 ~Prefilter();
34 Op op() { return op_; }
35 const string& atom() const { return atom_; }
36 void set_unique_id(int id) { unique_id_ = id; }
37 int unique_id() const { return unique_id_; }
39 // The children of the Prefilter node.
40 vector<Prefilter*>* subs() {
41 CHECK(op_ == AND || op_ == OR);
42 return subs_;
45 // Set the children vector. Prefilter takes ownership of subs and
46 // subs_ will be deleted when Prefilter is deleted.
47 void set_subs(vector<Prefilter*>* subs) { subs_ = subs; }
49 // Given a RE2, return a Prefilter. The caller takes ownership of
50 // the Prefilter and should deallocate it. Returns NULL if Prefilter
51 // cannot be formed.
52 static Prefilter* FromRE2(const RE2* re2);
54 // Returns a readable debug string of the prefilter.
55 string DebugString() const;
57 private:
58 class Info;
60 // Combines two prefilters together to create an AND. The passed
61 // Prefilters will be part of the returned Prefilter or deleted.
62 static Prefilter* And(Prefilter* a, Prefilter* b);
64 // Combines two prefilters together to create an OR. The passed
65 // Prefilters will be part of the returned Prefilter or deleted.
66 static Prefilter* Or(Prefilter* a, Prefilter* b);
68 // Generalized And/Or
69 static Prefilter* AndOr(Op op, Prefilter* a, Prefilter* b);
71 static Prefilter* FromRegexp(Regexp* a);
73 static Prefilter* FromString(const string& str);
75 static Prefilter* OrStrings(set<string>* ss);
77 static Info* BuildInfo(Regexp* re);
79 Prefilter* Simplify();
81 // Kind of Prefilter.
82 Op op_;
84 // Sub-matches for AND or OR Prefilter.
85 vector<Prefilter*>* subs_;
87 // Actual string to match in leaf node.
88 string atom_;
90 // If different prefilters have the same string atom, or if they are
91 // structurally the same (e.g., OR of same atom strings) they are
92 // considered the same unique nodes. This is the id for each unique
93 // node. This field is populated with a unique id for every node,
94 // and -1 for duplicate nodes.
95 int unique_id_;
97 // Used for debugging, helps in tracking memory leaks.
98 int alloc_id_;
100 DISALLOW_EVIL_CONSTRUCTORS(Prefilter);
103 } // namespace re2
105 #endif // RE2_PREFILTER_H_