MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / ComputeSimple

Method ComputeSimple

extern/re2/re2/simplify.cc:44–99  ·  view source on GitHub ↗

Assuming the simple_ flags on the children are accurate, is this Regexp* simple?

Source from the content-addressed store, hash-verified

42// Assuming the simple_ flags on the children are accurate,
43// is this Regexp* simple?
44bool Regexp::ComputeSimple() {
45 Regexp** subs;
46 switch (op_) {
47 case kRegexpNoMatch:
48 case kRegexpEmptyMatch:
49 case kRegexpLiteral:
50 case kRegexpLiteralString:
51 case kRegexpBeginLine:
52 case kRegexpEndLine:
53 case kRegexpBeginText:
54 case kRegexpWordBoundary:
55 case kRegexpNoWordBoundary:
56 case kRegexpEndText:
57 case kRegexpAnyChar:
58 case kRegexpAnyByte:
59 case kRegexpHaveMatch:
60 return true;
61 case kRegexpConcat:
62 case kRegexpAlternate:
63 // These are simple as long as the subpieces are simple.
64 subs = sub();
65 for (int i = 0; i < nsub_; i++)
66 if (!subs[i]->simple())
67 return false;
68 return true;
69 case kRegexpCharClass:
70 // Simple as long as the char class is not empty, not full.
71 if (ccb_ != NULL)
72 return !ccb_->empty() && !ccb_->full();
73 return !cc_->empty() && !cc_->full();
74 case kRegexpCapture:
75 subs = sub();
76 return subs[0]->simple();
77 case kRegexpStar:
78 case kRegexpPlus:
79 case kRegexpQuest:
80 subs = sub();
81 if (!subs[0]->simple())
82 return false;
83 switch (subs[0]->op_) {
84 case kRegexpStar:
85 case kRegexpPlus:
86 case kRegexpQuest:
87 case kRegexpEmptyMatch:
88 case kRegexpNoMatch:
89 return false;
90 default:
91 break;
92 }
93 return true;
94 case kRegexpRepeat:
95 return false;
96 }
97 LOG(DFATAL) << "Case not handled in ComputeSimple: " << op_;
98 return false;
99}
100
101// Walker subclass used by Simplify.

Callers 5

PushRegexpMethod · 0.80
PushRepeatOpMethod · 0.80
PushRepetitionMethod · 0.80
DoRightParenMethod · 0.80
DoCollapseMethod · 0.80

Calls 4

simpleMethod · 0.80
subFunction · 0.50
emptyMethod · 0.45
fullMethod · 0.45

Tested by

no test coverage detected