OLD | NEW |
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 26 matching lines...) Expand all Loading... |
37 #include "parser.h" | 37 #include "parser.h" |
38 #include "regexp-macro-assembler.h" | 38 #include "regexp-macro-assembler.h" |
39 #include "regexp-macro-assembler-irregexp.h" | 39 #include "regexp-macro-assembler-irregexp.h" |
40 #include "string-stream.h" | 40 #include "string-stream.h" |
41 #include "zone-inl.h" | 41 #include "zone-inl.h" |
42 #ifdef V8_INTERPRETED_REGEXP | 42 #ifdef V8_INTERPRETED_REGEXP |
43 #include "interpreter-irregexp.h" | 43 #include "interpreter-irregexp.h" |
44 #else // V8_INTERPRETED_REGEXP | 44 #else // V8_INTERPRETED_REGEXP |
45 #include "macro-assembler.h" | 45 #include "macro-assembler.h" |
46 #include "code.h" | 46 #include "code.h" |
47 #ifdef V8_TARGET_ARCH_ARM | 47 #if V8_TARGET_ARCH_ARM |
48 #include "arm/assembler-arm.h" | 48 #include "arm/assembler-arm.h" |
49 #include "arm/macro-assembler-arm.h" | 49 #include "arm/macro-assembler-arm.h" |
50 #include "arm/regexp-macro-assembler-arm.h" | 50 #include "arm/regexp-macro-assembler-arm.h" |
51 #endif | 51 #endif |
52 #ifdef V8_TARGET_ARCH_A64 | 52 #if V8_TARGET_ARCH_A64 |
53 #include "a64/assembler-a64.h" | 53 #include "a64/assembler-a64.h" |
54 #include "a64/macro-assembler-a64.h" | 54 #include "a64/macro-assembler-a64.h" |
55 #include "a64/regexp-macro-assembler-a64.h" | 55 #include "a64/regexp-macro-assembler-a64.h" |
56 #endif | 56 #endif |
57 #ifdef V8_TARGET_ARCH_MIPS | 57 #if V8_TARGET_ARCH_MIPS |
58 #include "mips/assembler-mips.h" | 58 #include "mips/assembler-mips.h" |
59 #include "mips/macro-assembler-mips.h" | 59 #include "mips/macro-assembler-mips.h" |
60 #include "mips/regexp-macro-assembler-mips.h" | 60 #include "mips/regexp-macro-assembler-mips.h" |
61 #endif | 61 #endif |
62 #ifdef V8_TARGET_ARCH_X64 | 62 #if V8_TARGET_ARCH_X64 |
63 #include "x64/assembler-x64.h" | 63 #include "x64/assembler-x64.h" |
64 #include "x64/macro-assembler-x64.h" | 64 #include "x64/macro-assembler-x64.h" |
65 #include "x64/regexp-macro-assembler-x64.h" | 65 #include "x64/regexp-macro-assembler-x64.h" |
66 #endif | 66 #endif |
67 #ifdef V8_TARGET_ARCH_IA32 | 67 #if V8_TARGET_ARCH_IA32 |
68 #include "ia32/assembler-ia32.h" | 68 #include "ia32/assembler-ia32.h" |
69 #include "ia32/macro-assembler-ia32.h" | 69 #include "ia32/macro-assembler-ia32.h" |
70 #include "ia32/regexp-macro-assembler-ia32.h" | 70 #include "ia32/regexp-macro-assembler-ia32.h" |
71 #endif | 71 #endif |
72 #endif // V8_INTERPRETED_REGEXP | 72 #endif // V8_INTERPRETED_REGEXP |
73 | 73 |
74 using namespace v8::internal; | 74 using namespace v8::internal; |
75 | 75 |
76 | 76 |
77 static bool CheckParse(const char* input) { | 77 static bool CheckParse(const char* input) { |
(...skipping 14 matching lines...) Expand all Loading... |
92 FlatStringReader reader(Isolate::Current(), CStrVector(input)); | 92 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
93 RegExpCompileData result; | 93 RegExpCompileData result; |
94 CHECK(v8::internal::RegExpParser::ParseRegExp( | 94 CHECK(v8::internal::RegExpParser::ParseRegExp( |
95 &reader, false, &result, &zone)); | 95 &reader, false, &result, &zone)); |
96 CHECK(result.tree != NULL); | 96 CHECK(result.tree != NULL); |
97 CHECK(result.error.is_null()); | 97 CHECK(result.error.is_null()); |
98 SmartArrayPointer<const char> output = result.tree->ToString(&zone); | 98 SmartArrayPointer<const char> output = result.tree->ToString(&zone); |
99 return output; | 99 return output; |
100 } | 100 } |
101 | 101 |
| 102 |
102 static bool CheckSimple(const char* input) { | 103 static bool CheckSimple(const char* input) { |
103 V8::Initialize(NULL); | 104 V8::Initialize(NULL); |
104 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 105 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
105 Zone zone(Isolate::Current()); | 106 Zone zone(Isolate::Current()); |
106 FlatStringReader reader(Isolate::Current(), CStrVector(input)); | 107 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
107 RegExpCompileData result; | 108 RegExpCompileData result; |
108 CHECK(v8::internal::RegExpParser::ParseRegExp( | 109 CHECK(v8::internal::RegExpParser::ParseRegExp( |
109 &reader, false, &result, &zone)); | 110 &reader, false, &result, &zone)); |
110 CHECK(result.tree != NULL); | 111 CHECK(result.tree != NULL); |
111 CHECK(result.error.is_null()); | 112 CHECK(result.error.is_null()); |
112 return result.simple; | 113 return result.simple; |
113 } | 114 } |
114 | 115 |
115 struct MinMaxPair { | 116 struct MinMaxPair { |
116 int min_match; | 117 int min_match; |
117 int max_match; | 118 int max_match; |
118 }; | 119 }; |
119 | 120 |
| 121 |
120 static MinMaxPair CheckMinMaxMatch(const char* input) { | 122 static MinMaxPair CheckMinMaxMatch(const char* input) { |
121 V8::Initialize(NULL); | 123 V8::Initialize(NULL); |
122 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 124 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
123 Zone zone(Isolate::Current()); | 125 Zone zone(Isolate::Current()); |
124 FlatStringReader reader(Isolate::Current(), CStrVector(input)); | 126 FlatStringReader reader(Isolate::Current(), CStrVector(input)); |
125 RegExpCompileData result; | 127 RegExpCompileData result; |
126 CHECK(v8::internal::RegExpParser::ParseRegExp( | 128 CHECK(v8::internal::RegExpParser::ParseRegExp( |
127 &reader, false, &result, &zone)); | 129 &reader, false, &result, &zone)); |
128 CHECK(result.tree != NULL); | 130 CHECK(result.tree != NULL); |
129 CHECK(result.error.is_null()); | 131 CHECK(result.error.is_null()); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 CHECK_MIN_MAX("(?:ab){4,7}", 8, 14); | 377 CHECK_MIN_MAX("(?:ab){4,7}", 8, 14); |
376 CHECK_MIN_MAX("a\\bc", 2, 2); | 378 CHECK_MIN_MAX("a\\bc", 2, 2); |
377 CHECK_MIN_MAX("a\\Bc", 2, 2); | 379 CHECK_MIN_MAX("a\\Bc", 2, 2); |
378 CHECK_MIN_MAX("a\\sc", 3, 3); | 380 CHECK_MIN_MAX("a\\sc", 3, 3); |
379 CHECK_MIN_MAX("a\\Sc", 3, 3); | 381 CHECK_MIN_MAX("a\\Sc", 3, 3); |
380 CHECK_MIN_MAX("a(?=b)c", 2, 2); | 382 CHECK_MIN_MAX("a(?=b)c", 2, 2); |
381 CHECK_MIN_MAX("a(?=bbb|bb)c", 2, 2); | 383 CHECK_MIN_MAX("a(?=bbb|bb)c", 2, 2); |
382 CHECK_MIN_MAX("a(?!bbb|bb)c", 2, 2); | 384 CHECK_MIN_MAX("a(?!bbb|bb)c", 2, 2); |
383 } | 385 } |
384 | 386 |
| 387 |
385 TEST(ParserRegression) { | 388 TEST(ParserRegression) { |
386 CHECK_PARSE_EQ("[A-Z$-][x]", "(! [A-Z $ -] [x])"); | 389 CHECK_PARSE_EQ("[A-Z$-][x]", "(! [A-Z $ -] [x])"); |
387 CHECK_PARSE_EQ("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); | 390 CHECK_PARSE_EQ("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); |
388 CHECK_PARSE_EQ("{", "'{'"); | 391 CHECK_PARSE_EQ("{", "'{'"); |
389 CHECK_PARSE_EQ("a|", "(| 'a' %)"); | 392 CHECK_PARSE_EQ("a|", "(| 'a' %)"); |
390 } | 393 } |
391 | 394 |
392 static void ExpectError(const char* input, | 395 static void ExpectError(const char* input, |
393 const char* expected) { | 396 const char* expected) { |
394 V8::Initialize(NULL); | 397 V8::Initialize(NULL); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 for (int j = 0; j < kRangeCount; j++) { | 660 for (int j = 0; j < kRangeCount; j++) { |
658 uc16* range = ranges[j]; | 661 uc16* range = ranges[j]; |
659 bool is_on = false; | 662 bool is_on = false; |
660 for (int k = 0; !is_on && (k < 2 * kRangeSize); k += 2) | 663 for (int k = 0; !is_on && (k < 2 * kRangeSize); k += 2) |
661 is_on = (range[k] <= p && p <= range[k + 1]); | 664 is_on = (range[k] <= p && p <= range[k + 1]); |
662 CHECK_EQ(is_on, outs->Get(j)); | 665 CHECK_EQ(is_on, outs->Get(j)); |
663 } | 666 } |
664 } | 667 } |
665 } | 668 } |
666 | 669 |
| 670 |
667 // Test of debug-only syntax. | 671 // Test of debug-only syntax. |
668 #ifdef DEBUG | 672 #ifdef DEBUG |
669 | 673 |
670 TEST(ParsePossessiveRepetition) { | 674 TEST(ParsePossessiveRepetition) { |
671 bool old_flag_value = FLAG_regexp_possessive_quantifier; | 675 bool old_flag_value = FLAG_regexp_possessive_quantifier; |
672 | 676 |
673 // Enable possessive quantifier syntax. | 677 // Enable possessive quantifier syntax. |
674 FLAG_regexp_possessive_quantifier = true; | 678 FLAG_regexp_possessive_quantifier = true; |
675 | 679 |
676 CHECK_PARSE_EQ("a*+", "(# 0 - p 'a')"); | 680 CHECK_PARSE_EQ("a*+", "(# 0 - p 'a')"); |
(...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1813 ZoneList<CharacterRange> first_only(4, &zone); | 1817 ZoneList<CharacterRange> first_only(4, &zone); |
1814 ZoneList<CharacterRange> second_only(4, &zone); | 1818 ZoneList<CharacterRange> second_only(4, &zone); |
1815 ZoneList<CharacterRange> both(4, &zone); | 1819 ZoneList<CharacterRange> both(4, &zone); |
1816 } | 1820 } |
1817 | 1821 |
1818 | 1822 |
1819 TEST(Graph) { | 1823 TEST(Graph) { |
1820 V8::Initialize(NULL); | 1824 V8::Initialize(NULL); |
1821 Execute("\\b\\w+\\b", false, true, true); | 1825 Execute("\\b\\w+\\b", false, true, true); |
1822 } | 1826 } |
OLD | NEW |