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

Side by Side Diff: src/jsregexp.h

Issue 10386090: Implement loop for global regexps in regexp assembler. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix bugs, add tests, port to x64 and arm. Created 8 years, 7 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // Prepare a RegExp for being executed one or more times (using 102 // Prepare a RegExp for being executed one or more times (using
103 // IrregexpExecOnce) on the subject. 103 // IrregexpExecOnce) on the subject.
104 // This ensures that the regexp is compiled for the subject, and that 104 // This ensures that the regexp is compiled for the subject, and that
105 // the subject is flat. 105 // the subject is flat.
106 // Returns the number of integer spaces required by IrregexpExecOnce 106 // Returns the number of integer spaces required by IrregexpExecOnce
107 // as its "registers" argument. If the regexp cannot be compiled, 107 // as its "registers" argument. If the regexp cannot be compiled,
108 // an exception is set as pending, and this function returns negative. 108 // an exception is set as pending, and this function returns negative.
109 static int IrregexpPrepare(Handle<JSRegExp> regexp, 109 static int IrregexpPrepare(Handle<JSRegExp> regexp,
110 Handle<String> subject); 110 Handle<String> subject);
111 111
112 // Execute a regular expression once on the subject, starting from 112 // Calculate the size of offsets vector for the case of global regexp
113 // character "index". 113 // and the number of matches this vector is able to store.
114 // If successful, returns RE_SUCCESS and set the capture positions 114 static int GlobalOffsetsVectorSize(Handle<JSRegExp> regexp,
115 // in the first registers. 115 int registers_per_match,
116 int* max_matches);
117
118 // Execute a regular expression on the subject, starting from index.
119 // If matching succeeds, return the number of matches. This can be larger
120 // than one in the case of global regular expressions.
121 // The captures and subcaptures are stored into the registers vector.
116 // If matching fails, returns RE_FAILURE. 122 // If matching fails, returns RE_FAILURE.
117 // If execution fails, sets a pending exception and returns RE_EXCEPTION. 123 // If execution fails, sets a pending exception and returns RE_EXCEPTION.
118 static IrregexpResult IrregexpExecOnce(Handle<JSRegExp> regexp, 124 static int IrregexpExecRaw(Handle<JSRegExp> regexp,
119 Handle<String> subject, 125 Handle<String> subject,
120 int index, 126 int index,
121 Vector<int> registers); 127 Vector<int> registers);
122 128
123 // Execute an Irregexp bytecode pattern. 129 // Execute an Irregexp bytecode pattern.
124 // On a successful match, the result is a JSArray containing 130 // On a successful match, the result is a JSArray containing
125 // captured positions. On a failure, the result is the null value. 131 // captured positions. On a failure, the result is the null value.
126 // Returns an empty handle in case of an exception. 132 // Returns an empty handle in case of an exception.
127 static Handle<Object> IrregexpExec(Handle<JSRegExp> regexp, 133 static Handle<Object> IrregexpExec(Handle<JSRegExp> regexp,
128 Handle<String> subject, 134 Handle<String> subject,
129 int index, 135 int index,
130 Handle<JSArray> lastMatchInfo); 136 Handle<JSArray> lastMatchInfo);
131 137
(...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 : error_message(NULL), 1544 : error_message(NULL),
1539 code(code), 1545 code(code),
1540 num_registers(registers) {} 1546 num_registers(registers) {}
1541 const char* error_message; 1547 const char* error_message;
1542 Object* code; 1548 Object* code;
1543 int num_registers; 1549 int num_registers;
1544 }; 1550 };
1545 1551
1546 static CompilationResult Compile(RegExpCompileData* input, 1552 static CompilationResult Compile(RegExpCompileData* input,
1547 bool ignore_case, 1553 bool ignore_case,
1554 bool global,
1548 bool multiline, 1555 bool multiline,
1549 Handle<String> pattern, 1556 Handle<String> pattern,
1550 Handle<String> sample_subject, 1557 Handle<String> sample_subject,
1551 bool is_ascii); 1558 bool is_ascii);
1552 1559
1553 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); 1560 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case);
1554 }; 1561 };
1555 1562
1556 1563
1557 class OffsetsVector { 1564 class OffsetsVector {
1558 public: 1565 public:
1559 inline OffsetsVector(int num_registers, Isolate* isolate) 1566 inline OffsetsVector(int num_registers, Isolate* isolate)
1560 : offsets_vector_length_(num_registers) { 1567 : offsets_vector_length_(num_registers) {
1561 if (offsets_vector_length_ > Isolate::kJSRegexpStaticOffsetsVectorSize) { 1568 if (offsets_vector_length_ > Isolate::kJSRegexpStaticOffsetsVectorSize) {
1562 vector_ = NewArray<int>(offsets_vector_length_); 1569 vector_ = NewArray<int>(offsets_vector_length_);
1563 } else { 1570 } else {
1564 vector_ = isolate->jsregexp_static_offsets_vector(); 1571 vector_ = isolate->jsregexp_static_offsets_vector();
1565 } 1572 }
1566 } 1573 }
1567 inline ~OffsetsVector() { 1574 inline ~OffsetsVector() {
1568 if (offsets_vector_length_ > Isolate::kJSRegexpStaticOffsetsVectorSize) { 1575 if (offsets_vector_length_ > Isolate::kJSRegexpStaticOffsetsVectorSize) {
1569 DeleteArray(vector_); 1576 DeleteArray(vector_);
1570 vector_ = NULL; 1577 vector_ = NULL;
1571 } 1578 }
1572 } 1579 }
1573 inline int* vector() { return vector_; } 1580 inline int* vector() { return vector_; }
1574 inline int length() { return offsets_vector_length_; } 1581 inline int length() { return offsets_vector_length_; }
1575 1582
1576 static const int kStaticOffsetsVectorSize = 50; 1583 static const int kStaticOffsetsVectorSize =
1584 Isolate::kJSRegexpStaticOffsetsVectorSize;
1577 1585
1578 private: 1586 private:
1579 static Address static_offsets_vector_address(Isolate* isolate) { 1587 static Address static_offsets_vector_address(Isolate* isolate) {
1580 return reinterpret_cast<Address>(isolate->jsregexp_static_offsets_vector()); 1588 return reinterpret_cast<Address>(isolate->jsregexp_static_offsets_vector());
1581 } 1589 }
1582 1590
1583 int* vector_; 1591 int* vector_;
1584 int offsets_vector_length_; 1592 int offsets_vector_length_;
1585 1593
1586 friend class ExternalReference; 1594 friend class ExternalReference;
1587 }; 1595 };
1588 1596
1589 1597
1590 } } // namespace v8::internal 1598 } } // namespace v8::internal
1591 1599
1592 #endif // V8_JSREGEXP_H_ 1600 #endif // V8_JSREGEXP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698