Compiles RE set to Prog.
| 1197 | |
| 1198 | // Compiles RE set to Prog. |
| 1199 | Prog* 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 | |
| 1241 | Prog* Prog::CompileSet(Regexp* re, RE2::Anchor anchor, int64_t max_mem) { |
| 1242 | return Compiler::CompileSet(re, anchor, max_mem); |
nothing calls this directly
no test coverage detected