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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 152 |
153 | 153 |
154 #define CHECK_PARSE_ERROR(input) CHECK(!CheckParse(input)) | 154 #define CHECK_PARSE_ERROR(input) CHECK(!CheckParse(input)) |
155 #define CHECK_SIMPLE(input, simple) CHECK_EQ(simple, CheckSimple(input)); | 155 #define CHECK_SIMPLE(input, simple) CHECK_EQ(simple, CheckSimple(input)); |
156 #define CHECK_MIN_MAX(input, min, max) \ | 156 #define CHECK_MIN_MAX(input, min, max) \ |
157 { MinMaxPair min_max = CheckMinMaxMatch(input); \ | 157 { MinMaxPair min_max = CheckMinMaxMatch(input); \ |
158 CHECK_EQ(min, min_max.min_match); \ | 158 CHECK_EQ(min, min_max.min_match); \ |
159 CHECK_EQ(max, min_max.max_match); \ | 159 CHECK_EQ(max, min_max.max_match); \ |
160 } | 160 } |
161 | 161 |
162 | 162 TEST(Parser) { |
163 void TestRegExpParser(bool lookbehind) { | |
164 FLAG_harmony_regexp_lookbehind = lookbehind; | |
165 | |
166 CHECK_PARSE_ERROR("?"); | 163 CHECK_PARSE_ERROR("?"); |
167 | 164 |
168 CheckParseEq("abc", "'abc'"); | 165 CheckParseEq("abc", "'abc'"); |
169 CheckParseEq("", "%"); | 166 CheckParseEq("", "%"); |
170 CheckParseEq("abc|def", "(| 'abc' 'def')"); | 167 CheckParseEq("abc|def", "(| 'abc' 'def')"); |
171 CheckParseEq("abc|def|ghi", "(| 'abc' 'def' 'ghi')"); | 168 CheckParseEq("abc|def|ghi", "(| 'abc' 'def' 'ghi')"); |
172 CheckParseEq("^xxx$", "(: @^i 'xxx' @$i)"); | 169 CheckParseEq("^xxx$", "(: @^i 'xxx' @$i)"); |
173 CheckParseEq("ab\\b\\d\\bcd", "(: 'ab' @b [0-9] @b 'cd')"); | 170 CheckParseEq("ab\\b\\d\\bcd", "(: 'ab' @b [0-9] @b 'cd')"); |
174 CheckParseEq("\\w|\\d", "(| [0-9 A-Z _ a-z] [0-9])"); | 171 CheckParseEq("\\w|\\d", "(| [0-9 A-Z _ a-z] [0-9])"); |
175 CheckParseEq("a*", "(# 0 - g 'a')"); | 172 CheckParseEq("a*", "(# 0 - g 'a')"); |
(...skipping 11 matching lines...) Expand all Loading... |
187 CheckParseEq("xyz{1,}", "(: 'xy' (# 1 - g 'z'))"); | 184 CheckParseEq("xyz{1,}", "(: 'xy' (# 1 - g 'z'))"); |
188 CheckParseEq("xyz{1,}?", "(: 'xy' (# 1 - n 'z'))"); | 185 CheckParseEq("xyz{1,}?", "(: 'xy' (# 1 - n 'z'))"); |
189 CheckParseEq("a\\fb\\nc\\rd\\te\\vf", "'a\\x0cb\\x0ac\\x0dd\\x09e\\x0bf'"); | 186 CheckParseEq("a\\fb\\nc\\rd\\te\\vf", "'a\\x0cb\\x0ac\\x0dd\\x09e\\x0bf'"); |
190 CheckParseEq("a\\nb\\bc", "(: 'a\\x0ab' @b 'c')"); | 187 CheckParseEq("a\\nb\\bc", "(: 'a\\x0ab' @b 'c')"); |
191 CheckParseEq("(?:foo)", "'foo'"); | 188 CheckParseEq("(?:foo)", "'foo'"); |
192 CheckParseEq("(?: foo )", "' foo '"); | 189 CheckParseEq("(?: foo )", "' foo '"); |
193 CheckParseEq("(foo|bar|baz)", "(^ (| 'foo' 'bar' 'baz'))"); | 190 CheckParseEq("(foo|bar|baz)", "(^ (| 'foo' 'bar' 'baz'))"); |
194 CheckParseEq("foo|(bar|baz)|quux", "(| 'foo' (^ (| 'bar' 'baz')) 'quux')"); | 191 CheckParseEq("foo|(bar|baz)|quux", "(| 'foo' (^ (| 'bar' 'baz')) 'quux')"); |
195 CheckParseEq("foo(?=bar)baz", "(: 'foo' (-> + 'bar') 'baz')"); | 192 CheckParseEq("foo(?=bar)baz", "(: 'foo' (-> + 'bar') 'baz')"); |
196 CheckParseEq("foo(?!bar)baz", "(: 'foo' (-> - 'bar') 'baz')"); | 193 CheckParseEq("foo(?!bar)baz", "(: 'foo' (-> - 'bar') 'baz')"); |
197 if (lookbehind) { | |
198 CheckParseEq("foo(?<=bar)baz", "(: 'foo' (<- + 'bar') 'baz')"); | |
199 CheckParseEq("foo(?<!bar)baz", "(: 'foo' (<- - 'bar') 'baz')"); | |
200 } else { | |
201 CHECK_PARSE_ERROR("foo(?<=bar)baz"); | |
202 CHECK_PARSE_ERROR("foo(?<!bar)baz"); | |
203 } | |
204 CheckParseEq("()", "(^ %)"); | 194 CheckParseEq("()", "(^ %)"); |
205 CheckParseEq("(?=)", "(-> + %)"); | 195 CheckParseEq("(?=)", "(-> + %)"); |
206 CheckParseEq("[]", "^[\\x00-\\uffff]"); // Doesn't compile on windows | 196 CheckParseEq("[]", "^[\\x00-\\uffff]"); // Doesn't compile on windows |
207 CheckParseEq("[^]", "[\\x00-\\uffff]"); // \uffff isn't in codepage 1252 | 197 CheckParseEq("[^]", "[\\x00-\\uffff]"); // \uffff isn't in codepage 1252 |
208 CheckParseEq("[x]", "[x]"); | 198 CheckParseEq("[x]", "[x]"); |
209 CheckParseEq("[xyz]", "[x y z]"); | 199 CheckParseEq("[xyz]", "[x y z]"); |
210 CheckParseEq("[a-zA-Z0-9]", "[a-z A-Z 0-9]"); | 200 CheckParseEq("[a-zA-Z0-9]", "[a-z A-Z 0-9]"); |
211 CheckParseEq("[-123]", "[- 1 2 3]"); | 201 CheckParseEq("[-123]", "[- 1 2 3]"); |
212 CheckParseEq("[^123]", "^[1 2 3]"); | 202 CheckParseEq("[^123]", "^[1 2 3]"); |
213 CheckParseEq("]", "']'"); | 203 CheckParseEq("]", "']'"); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 "(: (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x')" | 260 "(: (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x') (^ 'x')" |
271 " (^ 'x') (^ 'x') (^ 'x') (^ 'x') '\\x09')"); | 261 " (^ 'x') (^ 'x') (^ 'x') (^ 'x') '\\x09')"); |
272 CheckParseEq("(a)\\1", "(: (^ 'a') (<- 1))"); | 262 CheckParseEq("(a)\\1", "(: (^ 'a') (<- 1))"); |
273 CheckParseEq("(a\\1)", "(^ 'a')"); | 263 CheckParseEq("(a\\1)", "(^ 'a')"); |
274 CheckParseEq("(\\1a)", "(^ 'a')"); | 264 CheckParseEq("(\\1a)", "(^ 'a')"); |
275 CheckParseEq("(?=a)?a", "'a'"); | 265 CheckParseEq("(?=a)?a", "'a'"); |
276 CheckParseEq("(?=a){0,10}a", "'a'"); | 266 CheckParseEq("(?=a){0,10}a", "'a'"); |
277 CheckParseEq("(?=a){1,10}a", "(: (-> + 'a') 'a')"); | 267 CheckParseEq("(?=a){1,10}a", "(: (-> + 'a') 'a')"); |
278 CheckParseEq("(?=a){9,10}a", "(: (-> + 'a') 'a')"); | 268 CheckParseEq("(?=a){9,10}a", "(: (-> + 'a') 'a')"); |
279 CheckParseEq("(?!a)?a", "'a'"); | 269 CheckParseEq("(?!a)?a", "'a'"); |
280 CheckParseEq("\\1(a)", "(: (<- 1) (^ 'a'))"); | 270 CheckParseEq("\\1(a)", "(^ 'a')"); |
281 CheckParseEq("(?!(a))\\1", "(: (-> - (^ 'a')) (<- 1))"); | 271 CheckParseEq("(?!(a))\\1", "(: (-> - (^ 'a')) (<- 1))"); |
282 CheckParseEq("(?!\\1(a\\1)\\1)\\1", | 272 CheckParseEq("(?!\\1(a\\1)\\1)\\1", "(: (-> - (: (^ 'a') (<- 1))) (<- 1))"); |
283 "(: (-> - (: (<- 1) (^ 'a') (<- 1))) (<- 1))"); | |
284 CheckParseEq("\\1\\2(a(?:\\1(b\\1\\2))\\2)\\1", | |
285 "(: (<- 1) (<- 2) (^ (: 'a' (^ 'b') (<- 2))) (<- 1))"); | |
286 if (lookbehind) { | |
287 CheckParseEq("\\1\\2(a(?<=\\1(b\\1\\2))\\2)\\1", | |
288 "(: (<- 1) (<- 2) (^ (: 'a' (<- + (^ 'b')) (<- 2))) (<- 1))"); | |
289 } | |
290 CheckParseEq("[\\0]", "[\\x00]"); | 273 CheckParseEq("[\\0]", "[\\x00]"); |
291 CheckParseEq("[\\11]", "[\\x09]"); | 274 CheckParseEq("[\\11]", "[\\x09]"); |
292 CheckParseEq("[\\11a]", "[\\x09 a]"); | 275 CheckParseEq("[\\11a]", "[\\x09 a]"); |
293 CheckParseEq("[\\011]", "[\\x09]"); | 276 CheckParseEq("[\\011]", "[\\x09]"); |
294 CheckParseEq("[\\00011]", "[\\x00 1 1]"); | 277 CheckParseEq("[\\00011]", "[\\x00 1 1]"); |
295 CheckParseEq("[\\118]", "[\\x09 8]"); | 278 CheckParseEq("[\\118]", "[\\x09 8]"); |
296 CheckParseEq("[\\111]", "[I]"); | 279 CheckParseEq("[\\111]", "[I]"); |
297 CheckParseEq("[\\1111]", "[I 1]"); | 280 CheckParseEq("[\\1111]", "[I 1]"); |
298 CheckParseEq("\\x34", "'\x34'"); | 281 CheckParseEq("\\x34", "'\x34'"); |
299 CheckParseEq("\\x60", "'\x60'"); | 282 CheckParseEq("\\x60", "'\x60'"); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 CHECK_MIN_MAX("a\\bc", 2, 2); | 393 CHECK_MIN_MAX("a\\bc", 2, 2); |
411 CHECK_MIN_MAX("a\\Bc", 2, 2); | 394 CHECK_MIN_MAX("a\\Bc", 2, 2); |
412 CHECK_MIN_MAX("a\\sc", 3, 3); | 395 CHECK_MIN_MAX("a\\sc", 3, 3); |
413 CHECK_MIN_MAX("a\\Sc", 3, 3); | 396 CHECK_MIN_MAX("a\\Sc", 3, 3); |
414 CHECK_MIN_MAX("a(?=b)c", 2, 2); | 397 CHECK_MIN_MAX("a(?=b)c", 2, 2); |
415 CHECK_MIN_MAX("a(?=bbb|bb)c", 2, 2); | 398 CHECK_MIN_MAX("a(?=bbb|bb)c", 2, 2); |
416 CHECK_MIN_MAX("a(?!bbb|bb)c", 2, 2); | 399 CHECK_MIN_MAX("a(?!bbb|bb)c", 2, 2); |
417 } | 400 } |
418 | 401 |
419 | 402 |
420 TEST(ParserWithLookbehind) { | |
421 TestRegExpParser(true); // Lookbehind enabled. | |
422 } | |
423 | |
424 | |
425 TEST(ParserWithoutLookbehind) { | |
426 TestRegExpParser(true); // Lookbehind enabled. | |
427 } | |
428 | |
429 | |
430 TEST(ParserRegression) { | 403 TEST(ParserRegression) { |
431 CheckParseEq("[A-Z$-][x]", "(! [A-Z $ -] [x])"); | 404 CheckParseEq("[A-Z$-][x]", "(! [A-Z $ -] [x])"); |
432 CheckParseEq("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); | 405 CheckParseEq("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')"); |
433 CheckParseEq("{", "'{'"); | 406 CheckParseEq("{", "'{'"); |
434 CheckParseEq("a|", "(| 'a' %)"); | 407 CheckParseEq("a|", "(| 'a' %)"); |
435 } | 408 } |
436 | 409 |
437 static void ExpectError(const char* input, | 410 static void ExpectError(const char* input, |
438 const char* expected) { | 411 const char* expected) { |
439 v8::HandleScope scope(CcTest::isolate()); | 412 v8::HandleScope scope(CcTest::isolate()); |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 ContextInitializer initializer; | 783 ContextInitializer initializer; |
811 Isolate* isolate = CcTest::i_isolate(); | 784 Isolate* isolate = CcTest::i_isolate(); |
812 Factory* factory = isolate->factory(); | 785 Factory* factory = isolate->factory(); |
813 Zone zone; | 786 Zone zone; |
814 | 787 |
815 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, | 788 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, |
816 4); | 789 4); |
817 | 790 |
818 Label fail, backtrack; | 791 Label fail, backtrack; |
819 m.PushBacktrack(&fail); | 792 m.PushBacktrack(&fail); |
820 m.CheckNotAtStart(0, NULL); | 793 m.CheckNotAtStart(NULL); |
821 m.LoadCurrentCharacter(2, NULL); | 794 m.LoadCurrentCharacter(2, NULL); |
822 m.CheckNotCharacter('o', NULL); | 795 m.CheckNotCharacter('o', NULL); |
823 m.LoadCurrentCharacter(1, NULL, false); | 796 m.LoadCurrentCharacter(1, NULL, false); |
824 m.CheckNotCharacter('o', NULL); | 797 m.CheckNotCharacter('o', NULL); |
825 m.LoadCurrentCharacter(0, NULL, false); | 798 m.LoadCurrentCharacter(0, NULL, false); |
826 m.CheckNotCharacter('f', NULL); | 799 m.CheckNotCharacter('f', NULL); |
827 m.WriteCurrentPositionToRegister(0, 0); | 800 m.WriteCurrentPositionToRegister(0, 0); |
828 m.WriteCurrentPositionToRegister(1, 3); | 801 m.WriteCurrentPositionToRegister(1, 3); |
829 m.AdvanceCurrentPosition(3); | 802 m.AdvanceCurrentPosition(3); |
830 m.PushBacktrack(&backtrack); | 803 m.PushBacktrack(&backtrack); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 ContextInitializer initializer; | 850 ContextInitializer initializer; |
878 Isolate* isolate = CcTest::i_isolate(); | 851 Isolate* isolate = CcTest::i_isolate(); |
879 Factory* factory = isolate->factory(); | 852 Factory* factory = isolate->factory(); |
880 Zone zone; | 853 Zone zone; |
881 | 854 |
882 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::UC16, | 855 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::UC16, |
883 4); | 856 4); |
884 | 857 |
885 Label fail, backtrack; | 858 Label fail, backtrack; |
886 m.PushBacktrack(&fail); | 859 m.PushBacktrack(&fail); |
887 m.CheckNotAtStart(0, NULL); | 860 m.CheckNotAtStart(NULL); |
888 m.LoadCurrentCharacter(2, NULL); | 861 m.LoadCurrentCharacter(2, NULL); |
889 m.CheckNotCharacter('o', NULL); | 862 m.CheckNotCharacter('o', NULL); |
890 m.LoadCurrentCharacter(1, NULL, false); | 863 m.LoadCurrentCharacter(1, NULL, false); |
891 m.CheckNotCharacter('o', NULL); | 864 m.CheckNotCharacter('o', NULL); |
892 m.LoadCurrentCharacter(0, NULL, false); | 865 m.LoadCurrentCharacter(0, NULL, false); |
893 m.CheckNotCharacter('f', NULL); | 866 m.CheckNotCharacter('f', NULL); |
894 m.WriteCurrentPositionToRegister(0, 0); | 867 m.WriteCurrentPositionToRegister(0, 0); |
895 m.WriteCurrentPositionToRegister(1, 3); | 868 m.WriteCurrentPositionToRegister(1, 3); |
896 m.AdvanceCurrentPosition(3); | 869 m.AdvanceCurrentPosition(3); |
897 m.PushBacktrack(&backtrack); | 870 m.PushBacktrack(&backtrack); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 Factory* factory = isolate->factory(); | 966 Factory* factory = isolate->factory(); |
994 Zone zone; | 967 Zone zone; |
995 | 968 |
996 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, | 969 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, |
997 4); | 970 4); |
998 | 971 |
999 m.WriteCurrentPositionToRegister(0, 0); | 972 m.WriteCurrentPositionToRegister(0, 0); |
1000 m.AdvanceCurrentPosition(2); | 973 m.AdvanceCurrentPosition(2); |
1001 m.WriteCurrentPositionToRegister(1, 0); | 974 m.WriteCurrentPositionToRegister(1, 0); |
1002 Label nomatch; | 975 Label nomatch; |
1003 m.CheckNotBackReference(0, false, &nomatch); | 976 m.CheckNotBackReference(0, &nomatch); |
1004 m.Fail(); | 977 m.Fail(); |
1005 m.Bind(&nomatch); | 978 m.Bind(&nomatch); |
1006 m.AdvanceCurrentPosition(2); | 979 m.AdvanceCurrentPosition(2); |
1007 Label missing_match; | 980 Label missing_match; |
1008 m.CheckNotBackReference(0, false, &missing_match); | 981 m.CheckNotBackReference(0, &missing_match); |
1009 m.WriteCurrentPositionToRegister(2, 0); | 982 m.WriteCurrentPositionToRegister(2, 0); |
1010 m.Succeed(); | 983 m.Succeed(); |
1011 m.Bind(&missing_match); | 984 m.Bind(&missing_match); |
1012 m.Fail(); | 985 m.Fail(); |
1013 | 986 |
1014 Handle<String> source = factory->NewStringFromStaticChars("^(..)..\1"); | 987 Handle<String> source = factory->NewStringFromStaticChars("^(..)..\1"); |
1015 Handle<Object> code_object = m.GetCode(source); | 988 Handle<Object> code_object = m.GetCode(source); |
1016 Handle<Code> code = Handle<Code>::cast(code_object); | 989 Handle<Code> code = Handle<Code>::cast(code_object); |
1017 | 990 |
1018 Handle<String> input = factory->NewStringFromStaticChars("fooofo"); | 991 Handle<String> input = factory->NewStringFromStaticChars("fooofo"); |
(...skipping 24 matching lines...) Expand all Loading... |
1043 Factory* factory = isolate->factory(); | 1016 Factory* factory = isolate->factory(); |
1044 Zone zone; | 1017 Zone zone; |
1045 | 1018 |
1046 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::UC16, | 1019 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::UC16, |
1047 4); | 1020 4); |
1048 | 1021 |
1049 m.WriteCurrentPositionToRegister(0, 0); | 1022 m.WriteCurrentPositionToRegister(0, 0); |
1050 m.AdvanceCurrentPosition(2); | 1023 m.AdvanceCurrentPosition(2); |
1051 m.WriteCurrentPositionToRegister(1, 0); | 1024 m.WriteCurrentPositionToRegister(1, 0); |
1052 Label nomatch; | 1025 Label nomatch; |
1053 m.CheckNotBackReference(0, false, &nomatch); | 1026 m.CheckNotBackReference(0, &nomatch); |
1054 m.Fail(); | 1027 m.Fail(); |
1055 m.Bind(&nomatch); | 1028 m.Bind(&nomatch); |
1056 m.AdvanceCurrentPosition(2); | 1029 m.AdvanceCurrentPosition(2); |
1057 Label missing_match; | 1030 Label missing_match; |
1058 m.CheckNotBackReference(0, false, &missing_match); | 1031 m.CheckNotBackReference(0, &missing_match); |
1059 m.WriteCurrentPositionToRegister(2, 0); | 1032 m.WriteCurrentPositionToRegister(2, 0); |
1060 m.Succeed(); | 1033 m.Succeed(); |
1061 m.Bind(&missing_match); | 1034 m.Bind(&missing_match); |
1062 m.Fail(); | 1035 m.Fail(); |
1063 | 1036 |
1064 Handle<String> source = factory->NewStringFromStaticChars("^(..)..\1"); | 1037 Handle<String> source = factory->NewStringFromStaticChars("^(..)..\1"); |
1065 Handle<Object> code_object = m.GetCode(source); | 1038 Handle<Object> code_object = m.GetCode(source); |
1066 Handle<Code> code = Handle<Code>::cast(code_object); | 1039 Handle<Code> code = Handle<Code>::cast(code_object); |
1067 | 1040 |
1068 const uc16 input_data[6] = {'f', 0x2028, 'o', 'o', 'f', 0x2028}; | 1041 const uc16 input_data[6] = {'f', 0x2028, 'o', 'o', 'f', 0x2028}; |
(...skipping 24 matching lines...) Expand all Loading... |
1093 v8::V8::Initialize(); | 1066 v8::V8::Initialize(); |
1094 ContextInitializer initializer; | 1067 ContextInitializer initializer; |
1095 Isolate* isolate = CcTest::i_isolate(); | 1068 Isolate* isolate = CcTest::i_isolate(); |
1096 Factory* factory = isolate->factory(); | 1069 Factory* factory = isolate->factory(); |
1097 Zone zone; | 1070 Zone zone; |
1098 | 1071 |
1099 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, | 1072 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, |
1100 0); | 1073 0); |
1101 | 1074 |
1102 Label not_at_start, newline, fail; | 1075 Label not_at_start, newline, fail; |
1103 m.CheckNotAtStart(0, ¬_at_start); | 1076 m.CheckNotAtStart(¬_at_start); |
1104 // Check that prevchar = '\n' and current = 'f'. | 1077 // Check that prevchar = '\n' and current = 'f'. |
1105 m.CheckCharacter('\n', &newline); | 1078 m.CheckCharacter('\n', &newline); |
1106 m.Bind(&fail); | 1079 m.Bind(&fail); |
1107 m.Fail(); | 1080 m.Fail(); |
1108 m.Bind(&newline); | 1081 m.Bind(&newline); |
1109 m.LoadCurrentCharacter(0, &fail); | 1082 m.LoadCurrentCharacter(0, &fail); |
1110 m.CheckNotCharacter('f', &fail); | 1083 m.CheckNotCharacter('f', &fail); |
1111 m.Succeed(); | 1084 m.Succeed(); |
1112 | 1085 |
1113 m.Bind(¬_at_start); | 1086 m.Bind(¬_at_start); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 | 1131 |
1159 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, | 1132 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, |
1160 4); | 1133 4); |
1161 | 1134 |
1162 Label fail, succ; | 1135 Label fail, succ; |
1163 | 1136 |
1164 m.WriteCurrentPositionToRegister(0, 0); | 1137 m.WriteCurrentPositionToRegister(0, 0); |
1165 m.WriteCurrentPositionToRegister(2, 0); | 1138 m.WriteCurrentPositionToRegister(2, 0); |
1166 m.AdvanceCurrentPosition(3); | 1139 m.AdvanceCurrentPosition(3); |
1167 m.WriteCurrentPositionToRegister(3, 0); | 1140 m.WriteCurrentPositionToRegister(3, 0); |
1168 m.CheckNotBackReferenceIgnoreCase(2, false, &fail); // Match "AbC". | 1141 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "AbC". |
1169 m.CheckNotBackReferenceIgnoreCase(2, false, &fail); // Match "ABC". | 1142 m.CheckNotBackReferenceIgnoreCase(2, &fail); // Match "ABC". |
1170 Label expected_fail; | 1143 Label expected_fail; |
1171 m.CheckNotBackReferenceIgnoreCase(2, false, &expected_fail); | 1144 m.CheckNotBackReferenceIgnoreCase(2, &expected_fail); |
1172 m.Bind(&fail); | 1145 m.Bind(&fail); |
1173 m.Fail(); | 1146 m.Fail(); |
1174 | 1147 |
1175 m.Bind(&expected_fail); | 1148 m.Bind(&expected_fail); |
1176 m.AdvanceCurrentPosition(3); // Skip "xYz" | 1149 m.AdvanceCurrentPosition(3); // Skip "xYz" |
1177 m.CheckNotBackReferenceIgnoreCase(2, false, &succ); | 1150 m.CheckNotBackReferenceIgnoreCase(2, &succ); |
1178 m.Fail(); | 1151 m.Fail(); |
1179 | 1152 |
1180 m.Bind(&succ); | 1153 m.Bind(&succ); |
1181 m.WriteCurrentPositionToRegister(1, 0); | 1154 m.WriteCurrentPositionToRegister(1, 0); |
1182 m.Succeed(); | 1155 m.Succeed(); |
1183 | 1156 |
1184 Handle<String> source = | 1157 Handle<String> source = |
1185 factory->NewStringFromStaticChars("^(abc)\1\1(?!\1)...(?!\1)"); | 1158 factory->NewStringFromStaticChars("^(abc)\1\1(?!\1)...(?!\1)"); |
1186 Handle<Object> code_object = m.GetCode(source); | 1159 Handle<Object> code_object = m.GetCode(source); |
1187 Handle<Code> code = Handle<Code>::cast(code_object); | 1160 Handle<Code> code = Handle<Code>::cast(code_object); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1359 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, | 1332 ArchRegExpMacroAssembler m(isolate, &zone, NativeRegExpMacroAssembler::LATIN1, |
1360 2); | 1333 2); |
1361 | 1334 |
1362 // At least 2048, to ensure the allocated space for registers | 1335 // At least 2048, to ensure the allocated space for registers |
1363 // span one full page. | 1336 // span one full page. |
1364 const int large_number = 8000; | 1337 const int large_number = 8000; |
1365 m.WriteCurrentPositionToRegister(large_number, 42); | 1338 m.WriteCurrentPositionToRegister(large_number, 42); |
1366 m.WriteCurrentPositionToRegister(0, 0); | 1339 m.WriteCurrentPositionToRegister(0, 0); |
1367 m.WriteCurrentPositionToRegister(1, 1); | 1340 m.WriteCurrentPositionToRegister(1, 1); |
1368 Label done; | 1341 Label done; |
1369 m.CheckNotBackReference(0, false, &done); // Performs a system-stack push. | 1342 m.CheckNotBackReference(0, &done); // Performs a system-stack push. |
1370 m.Bind(&done); | 1343 m.Bind(&done); |
1371 m.PushRegister(large_number, RegExpMacroAssembler::kNoStackLimitCheck); | 1344 m.PushRegister(large_number, RegExpMacroAssembler::kNoStackLimitCheck); |
1372 m.PopRegister(1); | 1345 m.PopRegister(1); |
1373 m.Succeed(); | 1346 m.Succeed(); |
1374 | 1347 |
1375 Handle<String> source = | 1348 Handle<String> source = |
1376 factory->NewStringFromStaticChars("<huge register space test>"); | 1349 factory->NewStringFromStaticChars("<huge register space test>"); |
1377 Handle<Object> code_object = m.GetCode(source); | 1350 Handle<Object> code_object = m.GetCode(source); |
1378 Handle<Code> code = Handle<Code>::cast(code_object); | 1351 Handle<Code> code = Handle<Code>::cast(code_object); |
1379 | 1352 |
(...skipping 28 matching lines...) Expand all Loading... |
1408 // ^f(o)o. | 1381 // ^f(o)o. |
1409 Label start, fail, backtrack; | 1382 Label start, fail, backtrack; |
1410 | 1383 |
1411 m.SetRegister(4, 42); | 1384 m.SetRegister(4, 42); |
1412 m.PushRegister(4, RegExpMacroAssembler::kNoStackLimitCheck); | 1385 m.PushRegister(4, RegExpMacroAssembler::kNoStackLimitCheck); |
1413 m.AdvanceRegister(4, 42); | 1386 m.AdvanceRegister(4, 42); |
1414 m.GoTo(&start); | 1387 m.GoTo(&start); |
1415 m.Fail(); | 1388 m.Fail(); |
1416 m.Bind(&start); | 1389 m.Bind(&start); |
1417 m.PushBacktrack(&fail); | 1390 m.PushBacktrack(&fail); |
1418 m.CheckNotAtStart(0, NULL); | 1391 m.CheckNotAtStart(NULL); |
1419 m.LoadCurrentCharacter(0, NULL); | 1392 m.LoadCurrentCharacter(0, NULL); |
1420 m.CheckNotCharacter('f', NULL); | 1393 m.CheckNotCharacter('f', NULL); |
1421 m.LoadCurrentCharacter(1, NULL); | 1394 m.LoadCurrentCharacter(1, NULL); |
1422 m.CheckNotCharacter('o', NULL); | 1395 m.CheckNotCharacter('o', NULL); |
1423 m.LoadCurrentCharacter(2, NULL); | 1396 m.LoadCurrentCharacter(2, NULL); |
1424 m.CheckNotCharacter('o', NULL); | 1397 m.CheckNotCharacter('o', NULL); |
1425 m.WriteCurrentPositionToRegister(0, 0); | 1398 m.WriteCurrentPositionToRegister(0, 0); |
1426 m.WriteCurrentPositionToRegister(1, 3); | 1399 m.WriteCurrentPositionToRegister(1, 3); |
1427 m.WriteCurrentPositionToRegister(2, 1); | 1400 m.WriteCurrentPositionToRegister(2, 1); |
1428 m.WriteCurrentPositionToRegister(3, 2); | 1401 m.WriteCurrentPositionToRegister(3, 2); |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1839 | 1812 |
1840 ZoneList<CharacterRange> first_only(4, &zone); | 1813 ZoneList<CharacterRange> first_only(4, &zone); |
1841 ZoneList<CharacterRange> second_only(4, &zone); | 1814 ZoneList<CharacterRange> second_only(4, &zone); |
1842 ZoneList<CharacterRange> both(4, &zone); | 1815 ZoneList<CharacterRange> both(4, &zone); |
1843 } | 1816 } |
1844 | 1817 |
1845 | 1818 |
1846 TEST(Graph) { | 1819 TEST(Graph) { |
1847 Execute("\\b\\w+\\b", false, true, true); | 1820 Execute("\\b\\w+\\b", false, true, true); |
1848 } | 1821 } |
OLD | NEW |