 Chromium Code Reviews
 Chromium Code Reviews Issue 43075:
  * Reapply revisions 1383, 1384, 1391, 1398, 1401, 1402,...  (Closed) 
  Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
    
  
    Issue 43075:
  * Reapply revisions 1383, 1384, 1391, 1398, 1401, 1402,...  (Closed) 
  Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/| Index: src/jsregexp.h | 
| =================================================================== | 
| --- src/jsregexp.h (revision 1489) | 
| +++ src/jsregexp.h (working copy) | 
| @@ -51,6 +51,7 @@ | 
| // Parses the RegExp pattern and prepares the JSRegExp object with | 
| // generic data and choice of implementation - as well as what | 
| // the implementation wants to store in the data field. | 
| + // Returns false if compilation fails. | 
| static Handle<Object> Compile(Handle<JSRegExp> re, | 
| Handle<String> pattern, | 
| Handle<String> flags); | 
| @@ -59,38 +60,45 @@ | 
| // This function calls the garbage collector if necessary. | 
| static Handle<Object> Exec(Handle<JSRegExp> regexp, | 
| Handle<String> subject, | 
| - Handle<Object> index); | 
| + int index, | 
| + Handle<JSArray> lastMatchInfo); | 
| // Call RegExp.prototyp.exec(string) in a loop. | 
| // Used by String.prototype.match and String.prototype.replace. | 
| // This function calls the garbage collector if necessary. | 
| static Handle<Object> ExecGlobal(Handle<JSRegExp> regexp, | 
| - Handle<String> subject); | 
| + Handle<String> subject, | 
| + Handle<JSArray> lastMatchInfo); | 
| // Prepares a JSRegExp object with Irregexp-specific data. | 
| - static Handle<Object> IrregexpPrepare(Handle<JSRegExp> re, | 
| - Handle<String> pattern, | 
| - JSRegExp::Flags flags); | 
| + static void IrregexpPrepare(Handle<JSRegExp> re, | 
| + Handle<String> pattern, | 
| + JSRegExp::Flags flags, | 
| + int capture_register_count); | 
| - static Handle<Object> AtomCompile(Handle<JSRegExp> re, | 
| - Handle<String> pattern, | 
| - JSRegExp::Flags flags, | 
| - Handle<String> match_pattern); | 
| + static void AtomCompile(Handle<JSRegExp> re, | 
| + Handle<String> pattern, | 
| + JSRegExp::Flags flags, | 
| + Handle<String> match_pattern); | 
| static Handle<Object> AtomExec(Handle<JSRegExp> regexp, | 
| Handle<String> subject, | 
| - Handle<Object> index); | 
| + int index, | 
| + Handle<JSArray> lastMatchInfo); | 
| static Handle<Object> AtomExecGlobal(Handle<JSRegExp> regexp, | 
| - Handle<String> subject); | 
| + Handle<String> subject, | 
| + Handle<JSArray> lastMatchInfo); | 
| // Execute an Irregexp bytecode pattern. | 
| static Handle<Object> IrregexpExec(Handle<JSRegExp> regexp, | 
| Handle<String> subject, | 
| - Handle<Object> index); | 
| + int index, | 
| + Handle<JSArray> lastMatchInfo); | 
| static Handle<Object> IrregexpExecGlobal(Handle<JSRegExp> regexp, | 
| - Handle<String> subject); | 
| + Handle<String> subject, | 
| + Handle<JSArray> lastMatchInfo); | 
| static void NewSpaceCollectionPrologue(); | 
| static void OldSpaceCollectionPrologue(); | 
| @@ -101,26 +109,49 @@ | 
| static Handle<String> StringToTwoByte(Handle<String> pattern); | 
| static Handle<String> CachedStringToTwoByte(Handle<String> pattern); | 
| - static const int kIrregexpImplementationIndex = 0; | 
| - static const int kIrregexpNumberOfCapturesIndex = 1; | 
| - static const int kIrregexpNumberOfRegistersIndex = 2; | 
| - static const int kIrregexpCodeIndex = 3; | 
| - static const int kIrregexpDataLength = 4; | 
| + // Offsets in the lastMatchInfo array. | 
| + static const int kLastCaptureCount = 0; | 
| + static const int kLastSubject = 1; | 
| + static const int kLastInput = 2; | 
| + static const int kFirstCapture = 1; | 
| + static const int kLastMatchOverhead = 3; | 
| + static int GetCapture(FixedArray* array, int index) { | 
| 
Mads Ager (chromium)
2009/03/11 13:49:17
This is a general comment on this code.  Don't let
 
Erik Corry
2009/03/11 14:01:06
Changed here, left alone other places in the file.
 | 
| + return Smi::cast(array->get(index + kFirstCapture))->value(); | 
| + } | 
| + static void SetLastCaptureCount(FixedArray* array, int to) { | 
| + array->set(kLastCaptureCount, Smi::FromInt(to)); | 
| + } | 
| + static void SetLastSubject(FixedArray* array, String* to) { | 
| + int capture_count = GetLastCaptureCount(array); | 
| + array->set(capture_count + kLastSubject, to); | 
| + } | 
| + static void SetLastInput(FixedArray* array, String* to) { | 
| + int capture_count = GetLastCaptureCount(array); | 
| + array->set(capture_count + kLastInput, to); | 
| + } | 
| + static void SetCapture(FixedArray* array, int index, int to) { | 
| + array->set(index + kFirstCapture, Smi::FromInt(to)); | 
| + } | 
| private: | 
| static String* last_ascii_string_; | 
| static String* two_byte_cached_string_; | 
| - static int IrregexpNumberOfCaptures(Handle<FixedArray> re); | 
| - static int IrregexpNumberOfRegisters(Handle<FixedArray> re); | 
| - static Handle<ByteArray> IrregexpByteCode(Handle<FixedArray> re); | 
| - static Handle<Code> IrregexpNativeCode(Handle<FixedArray> re); | 
| + static bool EnsureCompiledIrregexp(Handle<JSRegExp> re, bool is_ascii); | 
| + static int IrregexpMaxRegisterCount(FixedArray* re); | 
| + static void SetIrregexpMaxRegisterCount(FixedArray* re, int value); | 
| + static int IrregexpNumberOfCaptures(FixedArray* re); | 
| + static int IrregexpNumberOfRegisters(FixedArray* re); | 
| + static ByteArray* IrregexpByteCode(FixedArray* re, bool is_ascii); | 
| + static Code* IrregexpNativeCode(FixedArray* re, bool is_ascii); | 
| + | 
| // On a successful match, the result is a JSArray containing | 
| // captured positions. On a failure, the result is the null value. | 
| // Returns an empty handle in case of an exception. | 
| static Handle<Object> IrregexpExecOnce(Handle<FixedArray> regexp, | 
| int num_captures, | 
| + Handle<JSArray> lastMatchInfo, | 
| Handle<String> subject16, | 
| int previous_index, | 
| int* ovector, | 
| @@ -134,6 +165,10 @@ | 
| int character_position, | 
| int utf8_position); | 
| + // Used to access the lastMatchInfo array. | 
| + static int GetLastCaptureCount(FixedArray* array) { | 
| + return Smi::cast(array->get(kLastCaptureCount))->value(); | 
| + } | 
| // A one element cache of the last utf8_subject string and its length. The | 
| // subject JS String object is cached in the heap. We also cache a | 
| // translation between position and utf8 position. | 
| @@ -1319,12 +1354,26 @@ | 
| class RegExpEngine: public AllStatic { | 
| public: | 
| - static Handle<FixedArray> Compile(RegExpCompileData* input, | 
| - bool ignore_case, | 
| - bool multiline, | 
| - Handle<String> pattern, | 
| - bool is_ascii); | 
| + struct CompilationResult { | 
| + explicit CompilationResult(const char* error_message) | 
| + : error_message(error_message), | 
| + code(Heap::the_hole_value()), | 
| + num_registers(0) {} | 
| + CompilationResult(Object* code, int registers) | 
| + : error_message(NULL), | 
| + code(code), | 
| + num_registers(registers) {} | 
| + const char* error_message; | 
| + Object* code; | 
| + int num_registers; | 
| + }; | 
| + static CompilationResult Compile(RegExpCompileData* input, | 
| + bool ignore_case, | 
| + bool multiline, | 
| + Handle<String> pattern, | 
| + bool is_ascii); | 
| + | 
| static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); | 
| }; |