| 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 18 matching lines...) Expand all Loading... |
| 29 #define V8_JSREGEXP_H_ | 29 #define V8_JSREGEXP_H_ |
| 30 | 30 |
| 31 namespace v8 { namespace internal { | 31 namespace v8 { namespace internal { |
| 32 | 32 |
| 33 | 33 |
| 34 class RegExpMacroAssembler; | 34 class RegExpMacroAssembler; |
| 35 | 35 |
| 36 | 36 |
| 37 class RegExpImpl { | 37 class RegExpImpl { |
| 38 public: | 38 public: |
| 39 static inline bool UseNativeRegexp() { |
| 40 #ifdef ARM |
| 41 return false; |
| 42 #else |
| 43 return FLAG_regexp_native; |
| 44 #endif |
| 45 } |
| 39 // Creates a regular expression literal in the old space. | 46 // Creates a regular expression literal in the old space. |
| 40 // This function calls the garbage collector if necessary. | 47 // This function calls the garbage collector if necessary. |
| 41 static Handle<Object> CreateRegExpLiteral(Handle<JSFunction> constructor, | 48 static Handle<Object> CreateRegExpLiteral(Handle<JSFunction> constructor, |
| 42 Handle<String> pattern, | 49 Handle<String> pattern, |
| 43 Handle<String> flags, | 50 Handle<String> flags, |
| 44 bool* has_pending_exception); | 51 bool* has_pending_exception); |
| 45 | 52 |
| 46 // Returns a string representation of a regular expression. | 53 // Returns a string representation of a regular expression. |
| 47 // Implements RegExp.prototype.toString, see ECMA-262 section 15.10.6.4. | 54 // Implements RegExp.prototype.toString, see ECMA-262 section 15.10.6.4. |
| 48 // This function calls the garbage collector if necessary. | 55 // This function calls the garbage collector if necessary. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 static Handle<String> StringToTwoByte(Handle<String> pattern); | 117 static Handle<String> StringToTwoByte(Handle<String> pattern); |
| 111 static Handle<String> CachedStringToTwoByte(Handle<String> pattern); | 118 static Handle<String> CachedStringToTwoByte(Handle<String> pattern); |
| 112 | 119 |
| 113 // Offsets in the lastMatchInfo array. | 120 // Offsets in the lastMatchInfo array. |
| 114 static const int kLastCaptureCount = 0; | 121 static const int kLastCaptureCount = 0; |
| 115 static const int kLastSubject = 1; | 122 static const int kLastSubject = 1; |
| 116 static const int kLastInput = 2; | 123 static const int kLastInput = 2; |
| 117 static const int kFirstCapture = 1; | 124 static const int kFirstCapture = 1; |
| 118 static const int kLastMatchOverhead = 3; | 125 static const int kLastMatchOverhead = 3; |
| 119 | 126 |
| 127 // Used to access the lastMatchInfo array. |
| 120 static int GetCapture(FixedArray* array, int index) { | 128 static int GetCapture(FixedArray* array, int index) { |
| 121 return Smi::cast(array->get(index + kFirstCapture))->value(); | 129 return Smi::cast(array->get(index + kFirstCapture))->value(); |
| 122 } | 130 } |
| 123 | 131 |
| 124 static void SetLastCaptureCount(FixedArray* array, int to) { | 132 static void SetLastCaptureCount(FixedArray* array, int to) { |
| 125 array->set(kLastCaptureCount, Smi::FromInt(to)); | 133 array->set(kLastCaptureCount, Smi::FromInt(to)); |
| 126 } | 134 } |
| 127 | 135 |
| 128 static void SetLastSubject(FixedArray* array, String* to) { | 136 static void SetLastSubject(FixedArray* array, String* to) { |
| 129 int capture_count = GetLastCaptureCount(array); | 137 int capture_count = GetLastCaptureCount(array); |
| 130 array->set(capture_count + kLastSubject, to); | 138 array->set(capture_count + kLastSubject, to); |
| 131 } | 139 } |
| 132 | 140 |
| 133 static void SetLastInput(FixedArray* array, String* to) { | 141 static void SetLastInput(FixedArray* array, String* to) { |
| 134 int capture_count = GetLastCaptureCount(array); | 142 int capture_count = GetLastCaptureCount(array); |
| 135 array->set(capture_count + kLastInput, to); | 143 array->set(capture_count + kLastInput, to); |
| 136 } | 144 } |
| 137 | 145 |
| 138 static void SetCapture(FixedArray* array, int index, int to) { | 146 static void SetCapture(FixedArray* array, int index, int to) { |
| 139 array->set(index + kFirstCapture, Smi::FromInt(to)); | 147 array->set(index + kFirstCapture, Smi::FromInt(to)); |
| 140 } | 148 } |
| 141 | 149 |
| 142 private: | 150 static int GetLastCaptureCount(FixedArray* array) { |
| 143 static String* last_ascii_string_; | 151 return Smi::cast(array->get(kLastCaptureCount))->value(); |
| 144 static String* two_byte_cached_string_; | 152 } |
| 145 | 153 |
| 146 static bool EnsureCompiledIrregexp(Handle<JSRegExp> re, bool is_ascii); | 154 // For acting on the JSRegExp data FixedArray. |
| 147 | |
| 148 static int IrregexpMaxRegisterCount(FixedArray* re); | 155 static int IrregexpMaxRegisterCount(FixedArray* re); |
| 149 static void SetIrregexpMaxRegisterCount(FixedArray* re, int value); | 156 static void SetIrregexpMaxRegisterCount(FixedArray* re, int value); |
| 150 static int IrregexpNumberOfCaptures(FixedArray* re); | 157 static int IrregexpNumberOfCaptures(FixedArray* re); |
| 151 static int IrregexpNumberOfRegisters(FixedArray* re); | 158 static int IrregexpNumberOfRegisters(FixedArray* re); |
| 152 static ByteArray* IrregexpByteCode(FixedArray* re, bool is_ascii); | 159 static ByteArray* IrregexpByteCode(FixedArray* re, bool is_ascii); |
| 153 static Code* IrregexpNativeCode(FixedArray* re, bool is_ascii); | 160 static Code* IrregexpNativeCode(FixedArray* re, bool is_ascii); |
| 154 | 161 |
| 162 private: |
| 163 static String* last_ascii_string_; |
| 164 static String* two_byte_cached_string_; |
| 165 |
| 166 static bool EnsureCompiledIrregexp(Handle<JSRegExp> re, bool is_ascii); |
| 167 |
| 168 |
| 155 // On a successful match, the result is a JSArray containing | 169 // On a successful match, the result is a JSArray containing |
| 156 // captured positions. On a failure, the result is the null value. | 170 // captured positions. On a failure, the result is the null value. |
| 157 // Returns an empty handle in case of an exception. | 171 // Returns an empty handle in case of an exception. |
| 158 static Handle<Object> IrregexpExecOnce(Handle<FixedArray> regexp, | 172 static Handle<Object> IrregexpExecOnce(Handle<FixedArray> regexp, |
| 159 int num_captures, | 173 int num_captures, |
| 160 Handle<JSArray> lastMatchInfo, | 174 Handle<JSArray> lastMatchInfo, |
| 161 Handle<String> subject16, | 175 Handle<String> subject16, |
| 162 int previous_index, | 176 int previous_index, |
| 163 int* ovector, | 177 int* ovector, |
| 164 int ovector_length); | 178 int ovector_length); |
| 165 | 179 |
| 166 // Set the subject cache. The previous string buffer is not deleted, so the | 180 // Set the subject cache. The previous string buffer is not deleted, so the |
| 167 // caller should ensure that it doesn't leak. | 181 // caller should ensure that it doesn't leak. |
| 168 static void SetSubjectCache(String* subject, | 182 static void SetSubjectCache(String* subject, |
| 169 char* utf8_subject, | 183 char* utf8_subject, |
| 170 int uft8_length, | 184 int uft8_length, |
| 171 int character_position, | 185 int character_position, |
| 172 int utf8_position); | 186 int utf8_position); |
| 173 | 187 |
| 174 // Used to access the lastMatchInfo array. | |
| 175 static int GetLastCaptureCount(FixedArray* array) { | |
| 176 return Smi::cast(array->get(kLastCaptureCount))->value(); | |
| 177 } | |
| 178 // A one element cache of the last utf8_subject string and its length. The | 188 // A one element cache of the last utf8_subject string and its length. The |
| 179 // subject JS String object is cached in the heap. We also cache a | 189 // subject JS String object is cached in the heap. We also cache a |
| 180 // translation between position and utf8 position. | 190 // translation between position and utf8 position. |
| 181 static char* utf8_subject_cache_; | 191 static char* utf8_subject_cache_; |
| 182 static int utf8_length_cache_; | 192 static int utf8_length_cache_; |
| 183 static int utf8_position_; | 193 static int utf8_position_; |
| 184 static int character_position_; | 194 static int character_position_; |
| 185 }; | 195 }; |
| 186 | 196 |
| 187 | 197 |
| (...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1380 Handle<String> pattern, | 1390 Handle<String> pattern, |
| 1381 bool is_ascii); | 1391 bool is_ascii); |
| 1382 | 1392 |
| 1383 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); | 1393 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); |
| 1384 }; | 1394 }; |
| 1385 | 1395 |
| 1386 | 1396 |
| 1387 } } // namespace v8::internal | 1397 } } // namespace v8::internal |
| 1388 | 1398 |
| 1389 #endif // V8_JSREGEXP_H_ | 1399 #endif // V8_JSREGEXP_H_ |
| OLD | NEW |