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

Method CompileSet

extern/re2/re2/compile.cc:1199–1239  ·  view source on GitHub ↗

Compiles RE set to Prog.

Source from the content-addressed store, hash-verified

1197
1198// Compiles RE set to Prog.
1199Prog* Compiler::CompileSet(Regexp* re, RE2::Anchor anchor, int64_t max_mem) {
1200 Compiler c;
1201 c.Setup(re->parse_flags(), max_mem, anchor);
1202
1203 Regexp* sre = re->Simplify();
1204 if (sre == NULL)
1205 return NULL;
1206
1207 Frag all = c.WalkExponential(sre, Frag(), 2*c.max_ninst_);
1208 sre->Decref();
1209 if (c.failed_)
1210 return NULL;
1211
1212 c.prog_->set_anchor_start(true);
1213 c.prog_->set_anchor_end(true);
1214
1215 if (anchor == RE2::UNANCHORED) {
1216 // Prepend .* or else the expression will effectively be anchored.
1217 // Complemented by the ANCHOR_BOTH case in PostVisit().
1218 all = c.Cat(c.DotStar(), all);
1219 }
1220 c.prog_->set_start(all.begin);
1221 c.prog_->set_start_unanchored(all.begin);
1222
1223 Prog* prog = c.Finish(re);
1224 if (prog == NULL)
1225 return NULL;
1226
1227 // Make sure DFA has enough memory to operate,
1228 // since we're not going to fall back to the NFA.
1229 bool dfa_failed = false;
1230 StringPiece sp = "hello, world";
1231 prog->SearchDFA(sp, sp, Prog::kAnchored, Prog::kManyMatch,
1232 NULL, &dfa_failed, NULL);
1233 if (dfa_failed) {
1234 delete prog;
1235 return NULL;
1236 }
1237
1238 return prog;
1239}
1240
1241Prog* Prog::CompileSet(Regexp* re, RE2::Anchor anchor, int64_t max_mem) {
1242 return Compiler::CompileSet(re, anchor, max_mem);

Callers

nothing calls this directly

Calls 14

FragClass · 0.85
SetupMethod · 0.80
parse_flagsMethod · 0.80
WalkExponentialMethod · 0.80
set_anchor_startMethod · 0.80
set_anchor_endMethod · 0.80
CatMethod · 0.80
DotStarMethod · 0.80
set_startMethod · 0.80
set_start_unanchoredMethod · 0.80
FinishMethod · 0.80
SearchDFAMethod · 0.80

Tested by

no test coverage detected