| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 canonicalize.get(old_char, '\0', &old_char); | 53 canonicalize.get(old_char, '\0', &old_char); |
| 54 canonicalize.get(new_char, '\0', &new_char); | 54 canonicalize.get(new_char, '\0', &new_char); |
| 55 if (old_char != new_char) { | 55 if (old_char != new_char) { |
| 56 return false; | 56 return false; |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 return true; | 59 return true; |
| 60 } | 60 } |
| 61 | 61 |
| 62 | 62 |
| 63 static bool BackRefMatchesNoCase(int from, |
| 64 int current, |
| 65 int len, |
| 66 Vector<const char> subject) { |
| 67 for (int i = 0; i < len; i++) { |
| 68 unsigned int old_char = subject[from++]; |
| 69 unsigned int new_char = subject[current++]; |
| 70 if (old_char == new_char) continue; |
| 71 if (old_char - 'A' <= 'Z' - 'A') old_char |= 0x20; |
| 72 if (new_char - 'A' <= 'Z' - 'A') new_char |= 0x20; |
| 73 if (old_char != new_char) return false; |
| 74 } |
| 75 return true; |
| 76 } |
| 77 |
| 78 |
| 63 #ifdef DEBUG | 79 #ifdef DEBUG |
| 64 static void TraceInterpreter(const byte* code_base, | 80 static void TraceInterpreter(const byte* code_base, |
| 65 const byte* pc, | 81 const byte* pc, |
| 66 int stack_depth, | 82 int stack_depth, |
| 67 int current_position, | 83 int current_position, |
| 68 int bytecode_length, | 84 int bytecode_length, |
| 69 const char* bytecode_name) { | 85 const char* bytecode_name) { |
| 70 if (FLAG_trace_regexp_bytecodes) { | 86 if (FLAG_trace_regexp_bytecodes) { |
| 71 PrintF("pc = %02x, sp = %d, current = %d, bc = %s", | 87 PrintF("pc = %02x, sp = %d, current = %d, bc = %s", |
| 72 pc - code_base, | 88 pc - code_base, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 89 current, \ | 105 current, \ |
| 90 BC_##name##_LENGTH, \ | 106 BC_##name##_LENGTH, \ |
| 91 #name); | 107 #name); |
| 92 #else | 108 #else |
| 93 #define BYTECODE(name) \ | 109 #define BYTECODE(name) \ |
| 94 case BC_##name: | 110 case BC_##name: |
| 95 #endif | 111 #endif |
| 96 | 112 |
| 97 | 113 |
| 98 | 114 |
| 115 template <typename Char> |
| 99 static bool RawMatch(const byte* code_base, | 116 static bool RawMatch(const byte* code_base, |
| 100 Vector<const uc16> subject, | 117 Vector<const Char> subject, |
| 101 int* registers, | 118 int* registers, |
| 102 int current, | 119 int current, |
| 103 int current_char) { | 120 int current_char) { |
| 104 const byte* pc = code_base; | 121 const byte* pc = code_base; |
| 105 static const int kBacktrackStackSize = 10000; | 122 static const int kBacktrackStackSize = 10000; |
| 106 int backtrack_stack[kBacktrackStackSize]; | 123 int backtrack_stack[kBacktrackStackSize]; |
| 107 int backtrack_stack_space = kBacktrackStackSize; | 124 int backtrack_stack_space = kBacktrackStackSize; |
| 108 int* backtrack_sp = backtrack_stack; | 125 int* backtrack_sp = backtrack_stack; |
| 109 #ifdef DEBUG | 126 #ifdef DEBUG |
| 110 if (FLAG_trace_regexp_bytecodes) { | 127 if (FLAG_trace_regexp_bytecodes) { |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 break; | 415 break; |
| 399 default: | 416 default: |
| 400 UNREACHABLE(); | 417 UNREACHABLE(); |
| 401 break; | 418 break; |
| 402 } | 419 } |
| 403 } | 420 } |
| 404 } | 421 } |
| 405 | 422 |
| 406 | 423 |
| 407 bool IrregexpInterpreter::Match(Handle<ByteArray> code_array, | 424 bool IrregexpInterpreter::Match(Handle<ByteArray> code_array, |
| 408 Handle<String> subject16, | 425 Handle<String> subject, |
| 409 int* registers, | 426 int* registers, |
| 410 int start_position) { | 427 int start_position) { |
| 411 ASSERT(StringShape(*subject16).IsTwoByteRepresentation()); | 428 ASSERT(subject->IsFlat(StringShape(*subject))); |
| 412 ASSERT(subject16->IsFlat(StringShape(*subject16))); | |
| 413 | 429 |
| 414 AssertNoAllocation a; | 430 AssertNoAllocation a; |
| 415 const byte* code_base = code_array->GetDataStartAddress(); | 431 const byte* code_base = code_array->GetDataStartAddress(); |
| 432 StringShape subject_shape(*subject); |
| 416 uc16 previous_char = '\n'; | 433 uc16 previous_char = '\n'; |
| 417 Vector<const uc16> subject_vector = | 434 if (subject_shape.IsAsciiRepresentation()) { |
| 418 Vector<const uc16>(subject16->GetTwoByteData(), subject16->length()); | 435 Vector<const char> subject_vector = subject->ToAsciiVector(); |
| 419 if (start_position != 0) previous_char = subject_vector[start_position - 1]; | 436 if (start_position != 0) previous_char = subject_vector[start_position - 1]; |
| 420 return RawMatch(code_base, | 437 return RawMatch(code_base, |
| 421 subject_vector, | 438 subject_vector, |
| 422 registers, | 439 registers, |
| 423 start_position, | 440 start_position, |
| 424 previous_char); | 441 previous_char); |
| 442 } else { |
| 443 Vector<const uc16> subject_vector = subject->ToUC16Vector(); |
| 444 if (start_position != 0) previous_char = subject_vector[start_position - 1]; |
| 445 return RawMatch(code_base, |
| 446 subject_vector, |
| 447 registers, |
| 448 start_position, |
| 449 previous_char); |
| 450 } |
| 425 } | 451 } |
| 426 | 452 |
| 427 } } // namespace v8::internal | 453 } } // namespace v8::internal |
| OLD | NEW |