Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: src/jsregexp.cc

Issue 12468: Merge code review fixes. (Closed)
Patch Set: Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/jsregexp.h ('k') | src/jsregexp-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 List<RegExpNode*>* work_list_; 910 List<RegExpNode*>* work_list_;
911 int recursion_depth_; 911 int recursion_depth_;
912 RegExpMacroAssembler* macro_assembler_; 912 RegExpMacroAssembler* macro_assembler_;
913 bool is_case_independent_; 913 bool is_case_independent_;
914 }; 914 };
915 915
916 916
917 // Attempts to compile the regexp using an Irregexp code generator. Returns 917 // Attempts to compile the regexp using an Irregexp code generator. Returns
918 // a fixed array or a null handle depending on whether it succeeded. 918 // a fixed array or a null handle depending on whether it succeeded.
919 RegExpCompiler::RegExpCompiler(int capture_count, bool ignore_case) 919 RegExpCompiler::RegExpCompiler(int capture_count, bool ignore_case)
920 : next_register_(2 * (capture_count + 1)), 920 : next_register_(2 * (capture_count + 1)),
921 work_list_(NULL), 921 work_list_(NULL),
922 recursion_depth_(0), 922 recursion_depth_(0),
923 is_case_independent_(ignore_case) { 923 is_case_independent_(ignore_case) {
924 accept_ = new EndNode(EndNode::ACCEPT); 924 accept_ = new EndNode(EndNode::ACCEPT);
925 backtrack_ = new EndNode(EndNode::BACKTRACK); 925 backtrack_ = new EndNode(EndNode::BACKTRACK);
926 } 926 }
927 927
928 928
929 Handle<FixedArray> RegExpCompiler::Assemble( 929 Handle<FixedArray> RegExpCompiler::Assemble(
930 RegExpMacroAssembler* macro_assembler, 930 RegExpMacroAssembler* macro_assembler,
931 RegExpNode* start, 931 RegExpNode* start,
932 int capture_count) { 932 int capture_count) {
933 if (!FLAG_attempt_case_independent && is_case_independent_) { 933 if (!FLAG_attempt_case_independent && is_case_independent_) {
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 void DotPrinter::PrintOnFailure(RegExpNode* from, RegExpNode* on_failure) { 1542 void DotPrinter::PrintOnFailure(RegExpNode* from, RegExpNode* on_failure) {
1543 if (on_failure->IsBacktrack()) return; 1543 if (on_failure->IsBacktrack()) return;
1544 stream()->Add(" n%p -> n%p [style=dotted];\n", from, on_failure); 1544 stream()->Add(" n%p -> n%p [style=dotted];\n", from, on_failure);
1545 Visit(on_failure); 1545 Visit(on_failure);
1546 } 1546 }
1547 1547
1548 1548
1549 class TableEntryBodyPrinter { 1549 class TableEntryBodyPrinter {
1550 public: 1550 public:
1551 TableEntryBodyPrinter(StringStream* stream, ChoiceNode* choice) 1551 TableEntryBodyPrinter(StringStream* stream, ChoiceNode* choice)
1552 : stream_(stream), choice_(choice) { } 1552 : stream_(stream), choice_(choice) { }
1553 void Call(uc16 from, DispatchTable::Entry entry) { 1553 void Call(uc16 from, DispatchTable::Entry entry) {
1554 OutSet* out_set = entry.out_set(); 1554 OutSet* out_set = entry.out_set();
1555 for (unsigned i = 0; i < OutSet::kFirstLimit; i++) { 1555 for (unsigned i = 0; i < OutSet::kFirstLimit; i++) {
1556 if (out_set->Get(i)) { 1556 if (out_set->Get(i)) {
1557 stream()->Add(" n%p:s%io%i -> n%p;\n", 1557 stream()->Add(" n%p:s%io%i -> n%p;\n",
1558 choice(), 1558 choice(),
1559 from, 1559 from,
1560 i, 1560 i,
1561 choice()->alternatives()->at(i).node()); 1561 choice()->alternatives()->at(i).node());
1562 } 1562 }
1563 } 1563 }
1564 } 1564 }
1565 private: 1565 private:
1566 StringStream* stream() { return stream_; } 1566 StringStream* stream() { return stream_; }
1567 ChoiceNode* choice() { return choice_; } 1567 ChoiceNode* choice() { return choice_; }
1568 StringStream* stream_; 1568 StringStream* stream_;
1569 ChoiceNode* choice_; 1569 ChoiceNode* choice_;
1570 }; 1570 };
1571 1571
1572 1572
1573 class TableEntryHeaderPrinter { 1573 class TableEntryHeaderPrinter {
1574 public: 1574 public:
1575 explicit TableEntryHeaderPrinter(StringStream* stream) 1575 explicit TableEntryHeaderPrinter(StringStream* stream)
1576 : first_(true), stream_(stream) { } 1576 : first_(true), stream_(stream) { }
1577 void Call(uc16 from, DispatchTable::Entry entry) { 1577 void Call(uc16 from, DispatchTable::Entry entry) {
1578 if (first_) { 1578 if (first_) {
1579 first_ = false; 1579 first_ = false;
1580 } else { 1580 } else {
1581 stream()->Add("|"); 1581 stream()->Add("|");
1582 } 1582 }
1583 stream()->Add("{\\%k-\\%k|{", from, entry.to()); 1583 stream()->Add("{\\%k-\\%k|{", from, entry.to());
1584 OutSet* out_set = entry.out_set(); 1584 OutSet* out_set = entry.out_set();
1585 int priority = 0; 1585 int priority = 0;
1586 for (unsigned i = 0; i < OutSet::kFirstLimit; i++) { 1586 for (unsigned i = 0; i < OutSet::kFirstLimit; i++) {
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
2080 unibrow::uchar chars[unibrow::Ecma262UnCanonicalize::kMaxWidth]; 2080 unibrow::uchar chars[unibrow::Ecma262UnCanonicalize::kMaxWidth];
2081 if (IsSingleton()) { 2081 if (IsSingleton()) {
2082 // If this is a singleton we just expand the one character. 2082 // If this is a singleton we just expand the one character.
2083 int length = uncanonicalize.get(from(), '\0', chars); 2083 int length = uncanonicalize.get(from(), '\0', chars);
2084 for (int i = 0; i < length; i++) { 2084 for (int i = 0; i < length; i++) {
2085 uc32 chr = chars[i]; 2085 uc32 chr = chars[i];
2086 if (chr != from()) { 2086 if (chr != from()) {
2087 ranges->Add(CharacterRange::Singleton(chars[i])); 2087 ranges->Add(CharacterRange::Singleton(chars[i]));
2088 } 2088 }
2089 } 2089 }
2090 } else if (from() <= kRangeCanonicalizeMax 2090 } else if (from() <= kRangeCanonicalizeMax &&
2091 && to() <= kRangeCanonicalizeMax) { 2091 to() <= kRangeCanonicalizeMax) {
Mads Ager (chromium) 2008/11/26 07:33:58 Align to() with from().
2092 // If this is a range we expand the characters block by block, 2092 // If this is a range we expand the characters block by block,
2093 // expanding contiguous subranges (blocks) one at a time. 2093 // expanding contiguous subranges (blocks) one at a time.
2094 // The approach is as follows. For a given start character we 2094 // The approach is as follows. For a given start character we
2095 // look up the block that contains it, for instance 'a' if the 2095 // look up the block that contains it, for instance 'a' if the
2096 // start character is 'c'. A block is characterized by the property 2096 // start character is 'c'. A block is characterized by the property
2097 // that all characters uncanonicalize in the same way as the first 2097 // that all characters uncanonicalize in the same way as the first
2098 // element, except that each entry in the result is incremented 2098 // element, except that each entry in the result is incremented
2099 // by the distance from the first element. So a-z is a block 2099 // by the distance from the first element. So a-z is a block
2100 // because 'a' uncanonicalizes to ['a', 'A'] and the k'th letter 2100 // because 'a' uncanonicalizes to ['a', 'A'] and the k'th letter
2101 // uncanonicalizes to ['a' + k, 'A' + k]. 2101 // uncanonicalizes to ['a' + k, 'A' + k].
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
2595 byte codes[1024]; 2595 byte codes[1024];
2596 IrregexpAssembler assembler(Vector<byte>(codes, 1024)); 2596 IrregexpAssembler assembler(Vector<byte>(codes, 1024));
2597 RegExpMacroAssemblerIrregexp macro_assembler(&assembler); 2597 RegExpMacroAssemblerIrregexp macro_assembler(&assembler);
2598 return compiler.Assemble(&macro_assembler, 2598 return compiler.Assemble(&macro_assembler,
2599 node, 2599 node,
2600 input->capture_count); 2600 input->capture_count);
2601 } 2601 }
2602 2602
2603 2603
2604 }} // namespace v8::internal 2604 }} // namespace v8::internal
OLDNEW
« no previous file with comments | « src/jsregexp.h ('k') | src/jsregexp-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698