Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: src/ast/ast.cc

Issue 1522353002: [regexp] break recursion in mutually recursive capture/back references. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/ast/ast.h" 5 #include "src/ast/ast.h"
6 6
7 #include <cmath> // For isfinite. 7 #include <cmath> // For isfinite.
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/builtins.h" 9 #include "src/builtins.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 bool RegExpCapture::IsAnchoredAtStart() { 919 bool RegExpCapture::IsAnchoredAtStart() {
920 return body()->IsAnchoredAtStart(); 920 return body()->IsAnchoredAtStart();
921 } 921 }
922 922
923 923
924 bool RegExpCapture::IsAnchoredAtEnd() { 924 bool RegExpCapture::IsAnchoredAtEnd() {
925 return body()->IsAnchoredAtEnd(); 925 return body()->IsAnchoredAtEnd();
926 } 926 }
927 927
928 928
929 int RegExpBackReference::max_match() {
erikcorry 2015/12/15 08:09:19 Alternative simpler implementation is to return kI
930 switch (max_match_) {
931 case kRecursionMarker:
932 // The back reference references a capture that references this back
933 // reference, leading to a recursion, e.g. /(\2)(\1)/.
934 // Such captures cannot be satisfied and have the length 0.
935 max_match_ = 0;
936 break;
937 case kUninitialized:
938 // The max match length of a back reference is the length of the capture.
939 if (capture_->body()) {
940 // Mark this back reference to break possible recursion before
941 // descending into the capture.
942 max_match_ = kRecursionMarker;
943 max_match_ = capture_->max_match();
944 } else {
945 // If the capture has no body, it has not been parsed and does not
946 // exist. Hence the length is 0.
947 max_match_ = 0;
948 }
949 break;
950 default:
951 // max_match_ has already been found.
952 break;
953 }
954 return max_match_;
955 }
956
957
929 // Convert regular expression trees to a simple sexp representation. 958 // Convert regular expression trees to a simple sexp representation.
930 // This representation should be different from the input grammar 959 // This representation should be different from the input grammar
931 // in as many cases as possible, to make it more difficult for incorrect 960 // in as many cases as possible, to make it more difficult for incorrect
932 // parses to look as correct ones which is likely if the input and 961 // parses to look as correct ones which is likely if the input and
933 // output formats are alike. 962 // output formats are alike.
934 class RegExpUnparser final : public RegExpVisitor { 963 class RegExpUnparser final : public RegExpVisitor {
935 public: 964 public:
936 RegExpUnparser(std::ostream& os, Zone* zone) : os_(os), zone_(zone) {} 965 RegExpUnparser(std::ostream& os, Zone* zone) : os_(os), zone_(zone) {}
937 void VisitCharacterRange(CharacterRange that); 966 void VisitCharacterRange(CharacterRange that);
938 #define MAKE_CASE(Name) void* Visit##Name(RegExp##Name*, void* data) override; 967 #define MAKE_CASE(Name) void* Visit##Name(RegExp##Name*, void* data) override;
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 bool Literal::Match(void* literal1, void* literal2) { 1176 bool Literal::Match(void* literal1, void* literal2) {
1148 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); 1177 const AstValue* x = static_cast<Literal*>(literal1)->raw_value();
1149 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); 1178 const AstValue* y = static_cast<Literal*>(literal2)->raw_value();
1150 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) || 1179 return (x->IsString() && y->IsString() && x->AsString() == y->AsString()) ||
1151 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); 1180 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber());
1152 } 1181 }
1153 1182
1154 1183
1155 } // namespace internal 1184 } // namespace internal
1156 } // namespace v8 1185 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/ast.h ('k') | src/parsing/parser.cc » ('j') | test/mjsunit/regexp.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698