| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 that->elements()->at(i).data.u_atom->Accept(this, data); | 325 that->elements()->at(i).data.u_atom->Accept(this, data); |
| 326 } | 326 } |
| 327 stream()->Add(")"); | 327 stream()->Add(")"); |
| 328 } | 328 } |
| 329 return NULL; | 329 return NULL; |
| 330 } | 330 } |
| 331 | 331 |
| 332 | 332 |
| 333 void* RegExpUnparser::VisitQuantifier(RegExpQuantifier* that, void* data) { | 333 void* RegExpUnparser::VisitQuantifier(RegExpQuantifier* that, void* data) { |
| 334 stream()->Add("(# %i ", that->min()); | 334 stream()->Add("(# %i ", that->min()); |
| 335 if (that->max() == RegExpQuantifier::kInfinity) { | 335 if (that->max() == RegExpTree::kInfinity) { |
| 336 stream()->Add("- "); | 336 stream()->Add("- "); |
| 337 } else { | 337 } else { |
| 338 stream()->Add("%i ", that->max()); | 338 stream()->Add("%i ", that->max()); |
| 339 } | 339 } |
| 340 stream()->Add(that->is_greedy() ? "g " : "n "); | 340 stream()->Add(that->is_greedy() ? "g " : "n "); |
| 341 that->body()->Accept(this, data); | 341 that->body()->Accept(this, data); |
| 342 stream()->Add(")"); | 342 stream()->Add(")"); |
| 343 return NULL; | 343 return NULL; |
| 344 } | 344 } |
| 345 | 345 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 374 } | 374 } |
| 375 | 375 |
| 376 | 376 |
| 377 SmartPointer<const char> RegExpTree::ToString() { | 377 SmartPointer<const char> RegExpTree::ToString() { |
| 378 RegExpUnparser unparser; | 378 RegExpUnparser unparser; |
| 379 Accept(&unparser, NULL); | 379 Accept(&unparser, NULL); |
| 380 return unparser.ToString(); | 380 return unparser.ToString(); |
| 381 } | 381 } |
| 382 | 382 |
| 383 | 383 |
| 384 RegExpDisjunction::RegExpDisjunction(ZoneList<RegExpTree*>* alternatives) |
| 385 : alternatives_(alternatives) { |
| 386 RegExpTree* first_alternative = alternatives->at(0); |
| 387 min_match_ = first_alternative->min_match(); |
| 388 max_match_ = first_alternative->max_match(); |
| 389 for (int i = 1; i < alternatives->length(); i++) { |
| 390 RegExpTree* alternative = alternatives->at(i); |
| 391 min_match_ = Min(min_match_, alternative->min_match()); |
| 392 max_match_ = Max(max_match_, alternative->max_match()); |
| 393 } |
| 394 } |
| 395 |
| 396 |
| 397 RegExpAlternative::RegExpAlternative(ZoneList<RegExpTree*>* nodes) |
| 398 : nodes_(nodes) { |
| 399 min_match_ = 0; |
| 400 max_match_ = 0; |
| 401 for (int i = 0; i < nodes->length(); i++) { |
| 402 RegExpTree* node = nodes->at(i); |
| 403 min_match_ += node->min_match(); |
| 404 int node_max_match = node->max_match(); |
| 405 if (kInfinity - max_match_ < node_max_match) { |
| 406 max_match_ = kInfinity; |
| 407 } else { |
| 408 max_match_ += node->max_match(); |
| 409 } |
| 410 } |
| 411 } |
| 412 |
| 413 |
| 384 } } // namespace v8::internal | 414 } } // namespace v8::internal |
| OLD | NEW |