Chromium Code Reviews| Index: src/ast/ast.cc |
| diff --git a/src/ast/ast.cc b/src/ast/ast.cc |
| index 3c8eb1ff7f1c109e4e9ee83824bc551815d2f55b..0fd1531387c62cb644fa383acab2c2e392dd0d1d 100644 |
| --- a/src/ast/ast.cc |
| +++ b/src/ast/ast.cc |
| @@ -926,6 +926,35 @@ bool RegExpCapture::IsAnchoredAtEnd() { |
| } |
| +int RegExpBackReference::max_match() { |
|
erikcorry
2015/12/15 08:09:19
Alternative simpler implementation is to return kI
|
| + switch (max_match_) { |
| + case kRecursionMarker: |
| + // The back reference references a capture that references this back |
| + // reference, leading to a recursion, e.g. /(\2)(\1)/. |
| + // Such captures cannot be satisfied and have the length 0. |
| + max_match_ = 0; |
| + break; |
| + case kUninitialized: |
| + // The max match length of a back reference is the length of the capture. |
| + if (capture_->body()) { |
| + // Mark this back reference to break possible recursion before |
| + // descending into the capture. |
| + max_match_ = kRecursionMarker; |
| + max_match_ = capture_->max_match(); |
| + } else { |
| + // If the capture has no body, it has not been parsed and does not |
| + // exist. Hence the length is 0. |
| + max_match_ = 0; |
| + } |
| + break; |
| + default: |
| + // max_match_ has already been found. |
| + break; |
| + } |
| + return max_match_; |
| +} |
| + |
| + |
| // Convert regular expression trees to a simple sexp representation. |
| // This representation should be different from the input grammar |
| // in as many cases as possible, to make it more difficult for incorrect |