Incremental conversion of concatenated literals into strings. If top two elements on stack are both literal or string, collapse into single string. Don't walk down the stack -- the parser calls this frequently enough that below the bottom two is known to be collapsed. Only called when another regexp is about to be pushed on the stack, so that the topmost literal is not being considered. (Otherwise
| 1274 | // If r >= 0, consider pushing a literal r on the stack. |
| 1275 | // Return whether that happened. |
| 1276 | bool Regexp::ParseState::MaybeConcatString(int r, ParseFlags flags) { |
| 1277 | Regexp* re1; |
| 1278 | Regexp* re2; |
| 1279 | if ((re1 = stacktop_) == NULL || (re2 = re1->down_) == NULL) |
| 1280 | return false; |
| 1281 | |
| 1282 | if (re1->op_ != kRegexpLiteral && re1->op_ != kRegexpLiteralString) |
| 1283 | return false; |
| 1284 | if (re2->op_ != kRegexpLiteral && re2->op_ != kRegexpLiteralString) |
| 1285 | return false; |
| 1286 | if ((re1->parse_flags_ & FoldCase) != (re2->parse_flags_ & FoldCase)) |
| 1287 | return false; |
| 1288 | |
| 1289 | if (re2->op_ == kRegexpLiteral) { |
| 1290 | // convert into string |
| 1291 | Rune rune = re2->rune_; |
| 1292 | re2->op_ = kRegexpLiteralString; |
| 1293 | re2->nrunes_ = 0; |
| 1294 | re2->runes_ = NULL; |
| 1295 | re2->AddRuneToString(rune); |
| 1296 | } |
| 1297 | |
| 1298 | // push re1 into re2. |
| 1299 | if (re1->op_ == kRegexpLiteral) { |
| 1300 | re2->AddRuneToString(re1->rune_); |
| 1301 | } else { |
| 1302 | for (int i = 0; i < re1->nrunes_; i++) |
| 1303 | re2->AddRuneToString(re1->runes_[i]); |
| 1304 | re1->nrunes_ = 0; |
| 1305 | delete[] re1->runes_; |
| 1306 | re1->runes_ = NULL; |
| 1307 | } |
| 1308 | |
| 1309 | // reuse re1 if possible |
| 1310 | if (r >= 0) { |
| 1311 | re1->op_ = kRegexpLiteral; |
| 1312 | re1->rune_ = r; |
| 1313 | re1->parse_flags_ = static_cast<uint16_t>(flags); |
| 1314 | return true; |
| 1315 | } |
| 1316 | |
| 1317 | stacktop_ = re2; |
| 1318 | re1->Decref(); |
| 1319 | return false; |
| 1320 | } |
| 1321 | |
| 1322 | // Lexing routines. |
| 1323 |
nothing calls this directly
no test coverage detected