OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/regexp_assembler.h" | 5 #include "vm/regexp_assembler.h" |
6 | 6 |
7 #include "vm/flags.h" | 7 #include "vm/flags.h" |
8 #include "vm/regexp.h" | 8 #include "vm/regexp.h" |
| 9 #include "vm/unibrow-inl.h" |
9 | 10 |
10 namespace dart { | 11 namespace dart { |
11 | 12 |
| 13 void PrintUtf16(uint16_t c) { |
| 14 const char* format = |
| 15 (0x20 <= c && c <= 0x7F) ? "%c" : (c <= 0xff) ? "\\x%02x" : "\\u%04x"; |
| 16 OS::Print(format, c); |
| 17 } |
| 18 |
| 19 |
| 20 static RawBool* CaseInsensitiveCompareUC16(RawString* str_raw, |
| 21 RawSmi* lhs_index_raw, |
| 22 RawSmi* rhs_index_raw, |
| 23 RawSmi* length_raw) { |
| 24 const String& str = String::Handle(str_raw); |
| 25 const Smi& lhs_index = Smi::Handle(lhs_index_raw); |
| 26 const Smi& rhs_index = Smi::Handle(rhs_index_raw); |
| 27 const Smi& length = Smi::Handle(length_raw); |
| 28 |
| 29 // TODO(zerny): Optimize as single instance. V8 has this as an |
| 30 // isolate member. |
| 31 unibrow::Mapping<unibrow::Ecma262Canonicalize> canonicalize; |
| 32 |
| 33 for (intptr_t i = 0; i < length.Value(); i++) { |
| 34 int32_t c1 = str.CharAt(lhs_index.Value() + i); |
| 35 int32_t c2 = str.CharAt(rhs_index.Value() + i); |
| 36 if (c1 != c2) { |
| 37 int32_t s1[1] = {c1}; |
| 38 canonicalize.get(c1, '\0', s1); |
| 39 if (s1[0] != c2) { |
| 40 int32_t s2[1] = {c2}; |
| 41 canonicalize.get(c2, '\0', s2); |
| 42 if (s1[0] != s2[0]) { |
| 43 return Bool::False().raw(); |
| 44 } |
| 45 } |
| 46 } |
| 47 } |
| 48 return Bool::True().raw(); |
| 49 } |
| 50 |
| 51 |
| 52 DEFINE_RAW_LEAF_RUNTIME_ENTRY( |
| 53 CaseInsensitiveCompareUC16, |
| 54 4, |
| 55 false /* is_float */, |
| 56 reinterpret_cast<RuntimeFunction>(&CaseInsensitiveCompareUC16)); |
| 57 |
| 58 |
12 BlockLabel::BlockLabel() | 59 BlockLabel::BlockLabel() |
13 : block_(NULL), is_bound_(false), is_linked_(false), pos_(-1) { | 60 : block_(NULL), is_bound_(false), is_linked_(false), pos_(-1) { |
| 61 #if !defined(DART_PRECOMPILED_RUNTIME) |
14 if (!FLAG_interpret_irregexp) { | 62 if (!FLAG_interpret_irregexp) { |
15 // Only needed by the compiled IR backend. | 63 // Only needed by the compiled IR backend. |
16 block_ = new JoinEntryInstr(-1, -1, Thread::Current()->GetNextDeoptId()); | 64 block_ = new JoinEntryInstr(-1, -1, Thread::Current()->GetNextDeoptId()); |
17 } | 65 } |
| 66 #endif |
18 } | 67 } |
19 | 68 |
20 | 69 |
21 RegExpMacroAssembler::RegExpMacroAssembler(Zone* zone) | 70 RegExpMacroAssembler::RegExpMacroAssembler(Zone* zone) |
22 : slow_safe_compiler_(false), global_mode_(NOT_GLOBAL), zone_(zone) {} | 71 : slow_safe_compiler_(false), global_mode_(NOT_GLOBAL), zone_(zone) {} |
23 | 72 |
24 | 73 |
25 RegExpMacroAssembler::~RegExpMacroAssembler() {} | 74 RegExpMacroAssembler::~RegExpMacroAssembler() {} |
26 | 75 |
27 } // namespace dart | 76 } // namespace dart |
OLD | NEW |