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

Side by Side Diff: src/jsregexp.h

Issue 16549002: Add type field to AST expression nodes (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « src/factory.cc ('k') | src/jsregexp.cc » ('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 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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 VISIT(Text) 422 VISIT(Text)
423 423
424 424
425 #define FORWARD_DECLARE(Name) class RegExp##Name; 425 #define FORWARD_DECLARE(Name) class RegExp##Name;
426 FOR_EACH_REG_EXP_TREE_TYPE(FORWARD_DECLARE) 426 FOR_EACH_REG_EXP_TREE_TYPE(FORWARD_DECLARE)
427 #undef FORWARD_DECLARE 427 #undef FORWARD_DECLARE
428 428
429 429
430 class TextElement { 430 class TextElement {
431 public: 431 public:
432 enum Type {UNINITIALIZED, ATOM, CHAR_CLASS}; 432 enum TextType {UNINITIALIZED, ATOM, CHAR_CLASS};
433 TextElement() : type(UNINITIALIZED) { } 433 TextElement() : text_type(UNINITIALIZED) { }
434 explicit TextElement(Type t) : type(t), cp_offset(-1) { } 434 explicit TextElement(TextType t) : text_type(t), cp_offset(-1) { }
435 static TextElement Atom(RegExpAtom* atom); 435 static TextElement Atom(RegExpAtom* atom);
436 static TextElement CharClass(RegExpCharacterClass* char_class); 436 static TextElement CharClass(RegExpCharacterClass* char_class);
437 int length(); 437 int length();
438 Type type; 438 TextType text_type;
439 union { 439 union {
440 RegExpAtom* u_atom; 440 RegExpAtom* u_atom;
441 RegExpCharacterClass* u_char_class; 441 RegExpCharacterClass* u_char_class;
442 } data; 442 } data;
443 int cp_offset; 443 int cp_offset;
444 }; 444 };
445 445
446 446
447 class Trace; 447 class Trace;
448 448
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 protected: 732 protected:
733 RegExpNode* FilterSuccessor(int depth, bool ignore_case); 733 RegExpNode* FilterSuccessor(int depth, bool ignore_case);
734 734
735 private: 735 private:
736 RegExpNode* on_success_; 736 RegExpNode* on_success_;
737 }; 737 };
738 738
739 739
740 class ActionNode: public SeqRegExpNode { 740 class ActionNode: public SeqRegExpNode {
741 public: 741 public:
742 enum Type { 742 enum ActionType {
743 SET_REGISTER, 743 SET_REGISTER,
744 INCREMENT_REGISTER, 744 INCREMENT_REGISTER,
745 STORE_POSITION, 745 STORE_POSITION,
746 BEGIN_SUBMATCH, 746 BEGIN_SUBMATCH,
747 POSITIVE_SUBMATCH_SUCCESS, 747 POSITIVE_SUBMATCH_SUCCESS,
748 EMPTY_MATCH_CHECK, 748 EMPTY_MATCH_CHECK,
749 CLEAR_CAPTURES 749 CLEAR_CAPTURES
750 }; 750 };
751 static ActionNode* SetRegister(int reg, int val, RegExpNode* on_success); 751 static ActionNode* SetRegister(int reg, int val, RegExpNode* on_success);
752 static ActionNode* IncrementRegister(int reg, RegExpNode* on_success); 752 static ActionNode* IncrementRegister(int reg, RegExpNode* on_success);
(...skipping 20 matching lines...) Expand all
773 RegExpCompiler* compiler, 773 RegExpCompiler* compiler,
774 int filled_in, 774 int filled_in,
775 bool not_at_start) { 775 bool not_at_start) {
776 return on_success()->GetQuickCheckDetails( 776 return on_success()->GetQuickCheckDetails(
777 details, compiler, filled_in, not_at_start); 777 details, compiler, filled_in, not_at_start);
778 } 778 }
779 virtual void FillInBMInfo(int offset, 779 virtual void FillInBMInfo(int offset,
780 int budget, 780 int budget,
781 BoyerMooreLookahead* bm, 781 BoyerMooreLookahead* bm,
782 bool not_at_start); 782 bool not_at_start);
783 Type type() { return type_; } 783 ActionType action_type() { return action_type_; }
784 // TODO(erikcorry): We should allow some action nodes in greedy loops. 784 // TODO(erikcorry): We should allow some action nodes in greedy loops.
785 virtual int GreedyLoopTextLength() { return kNodeIsTooComplexForGreedyLoops; } 785 virtual int GreedyLoopTextLength() { return kNodeIsTooComplexForGreedyLoops; }
786 786
787 private: 787 private:
788 union { 788 union {
789 struct { 789 struct {
790 int reg; 790 int reg;
791 int value; 791 int value;
792 } u_store_register; 792 } u_store_register;
793 struct { 793 struct {
(...skipping 12 matching lines...) Expand all
806 struct { 806 struct {
807 int start_register; 807 int start_register;
808 int repetition_register; 808 int repetition_register;
809 int repetition_limit; 809 int repetition_limit;
810 } u_empty_match_check; 810 } u_empty_match_check;
811 struct { 811 struct {
812 int range_from; 812 int range_from;
813 int range_to; 813 int range_to;
814 } u_clear_captures; 814 } u_clear_captures;
815 } data_; 815 } data_;
816 ActionNode(Type type, RegExpNode* on_success) 816 ActionNode(ActionType action_type, RegExpNode* on_success)
817 : SeqRegExpNode(on_success), 817 : SeqRegExpNode(on_success),
818 type_(type) { } 818 action_type_(action_type) { }
819 Type type_; 819 ActionType action_type_;
820 friend class DotPrinter; 820 friend class DotPrinter;
821 }; 821 };
822 822
823 823
824 class TextNode: public SeqRegExpNode { 824 class TextNode: public SeqRegExpNode {
825 public: 825 public:
826 TextNode(ZoneList<TextElement>* elms, 826 TextNode(ZoneList<TextElement>* elms,
827 RegExpNode* on_success) 827 RegExpNode* on_success)
828 : SeqRegExpNode(on_success), 828 : SeqRegExpNode(on_success),
829 elms_(elms) { } 829 elms_(elms) { }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 Trace* trace, 869 Trace* trace,
870 bool first_element_checked, 870 bool first_element_checked,
871 int* checked_up_to); 871 int* checked_up_to);
872 int Length(); 872 int Length();
873 ZoneList<TextElement>* elms_; 873 ZoneList<TextElement>* elms_;
874 }; 874 };
875 875
876 876
877 class AssertionNode: public SeqRegExpNode { 877 class AssertionNode: public SeqRegExpNode {
878 public: 878 public:
879 enum AssertionNodeType { 879 enum AssertionType {
880 AT_END, 880 AT_END,
881 AT_START, 881 AT_START,
882 AT_BOUNDARY, 882 AT_BOUNDARY,
883 AT_NON_BOUNDARY, 883 AT_NON_BOUNDARY,
884 AFTER_NEWLINE 884 AFTER_NEWLINE
885 }; 885 };
886 static AssertionNode* AtEnd(RegExpNode* on_success) { 886 static AssertionNode* AtEnd(RegExpNode* on_success) {
887 return new(on_success->zone()) AssertionNode(AT_END, on_success); 887 return new(on_success->zone()) AssertionNode(AT_END, on_success);
888 } 888 }
889 static AssertionNode* AtStart(RegExpNode* on_success) { 889 static AssertionNode* AtStart(RegExpNode* on_success) {
(...skipping 12 matching lines...) Expand all
902 virtual void Emit(RegExpCompiler* compiler, Trace* trace); 902 virtual void Emit(RegExpCompiler* compiler, Trace* trace);
903 virtual int EatsAtLeast(int still_to_find, int budget, bool not_at_start); 903 virtual int EatsAtLeast(int still_to_find, int budget, bool not_at_start);
904 virtual void GetQuickCheckDetails(QuickCheckDetails* details, 904 virtual void GetQuickCheckDetails(QuickCheckDetails* details,
905 RegExpCompiler* compiler, 905 RegExpCompiler* compiler,
906 int filled_in, 906 int filled_in,
907 bool not_at_start); 907 bool not_at_start);
908 virtual void FillInBMInfo(int offset, 908 virtual void FillInBMInfo(int offset,
909 int budget, 909 int budget,
910 BoyerMooreLookahead* bm, 910 BoyerMooreLookahead* bm,
911 bool not_at_start); 911 bool not_at_start);
912 AssertionNodeType type() { return type_; } 912 AssertionType assertion_type() { return assertion_type_; }
913 void set_type(AssertionNodeType type) { type_ = type; }
914 913
915 private: 914 private:
916 void EmitBoundaryCheck(RegExpCompiler* compiler, Trace* trace); 915 void EmitBoundaryCheck(RegExpCompiler* compiler, Trace* trace);
917 enum IfPrevious { kIsNonWord, kIsWord }; 916 enum IfPrevious { kIsNonWord, kIsWord };
918 void BacktrackIfPrevious(RegExpCompiler* compiler, 917 void BacktrackIfPrevious(RegExpCompiler* compiler,
919 Trace* trace, 918 Trace* trace,
920 IfPrevious backtrack_if_previous); 919 IfPrevious backtrack_if_previous);
921 AssertionNode(AssertionNodeType t, RegExpNode* on_success) 920 AssertionNode(AssertionType t, RegExpNode* on_success)
922 : SeqRegExpNode(on_success), type_(t) { } 921 : SeqRegExpNode(on_success), assertion_type_(t) { }
923 AssertionNodeType type_; 922 AssertionType assertion_type_;
924 }; 923 };
925 924
926 925
927 class BackReferenceNode: public SeqRegExpNode { 926 class BackReferenceNode: public SeqRegExpNode {
928 public: 927 public:
929 BackReferenceNode(int start_reg, 928 BackReferenceNode(int start_reg,
930 int end_reg, 929 int end_reg,
931 RegExpNode* on_success) 930 RegExpNode* on_success)
932 : SeqRegExpNode(on_success), 931 : SeqRegExpNode(on_success),
933 start_reg_(start_reg), 932 start_reg_(start_reg),
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 class Trace { 1329 class Trace {
1331 public: 1330 public:
1332 // A value for a property that is either known to be true, know to be false, 1331 // A value for a property that is either known to be true, know to be false,
1333 // or not known. 1332 // or not known.
1334 enum TriBool { 1333 enum TriBool {
1335 UNKNOWN = -1, FALSE = 0, TRUE = 1 1334 UNKNOWN = -1, FALSE = 0, TRUE = 1
1336 }; 1335 };
1337 1336
1338 class DeferredAction { 1337 class DeferredAction {
1339 public: 1338 public:
1340 DeferredAction(ActionNode::Type type, int reg) 1339 DeferredAction(ActionNode::ActionType action_type, int reg)
1341 : type_(type), reg_(reg), next_(NULL) { } 1340 : action_type_(action_type), reg_(reg), next_(NULL) { }
1342 DeferredAction* next() { return next_; } 1341 DeferredAction* next() { return next_; }
1343 bool Mentions(int reg); 1342 bool Mentions(int reg);
1344 int reg() { return reg_; } 1343 int reg() { return reg_; }
1345 ActionNode::Type type() { return type_; } 1344 ActionNode::ActionType action_type() { return action_type_; }
1346 private: 1345 private:
1347 ActionNode::Type type_; 1346 ActionNode::ActionType action_type_;
1348 int reg_; 1347 int reg_;
1349 DeferredAction* next_; 1348 DeferredAction* next_;
1350 friend class Trace; 1349 friend class Trace;
1351 }; 1350 };
1352 1351
1353 class DeferredCapture : public DeferredAction { 1352 class DeferredCapture : public DeferredAction {
1354 public: 1353 public:
1355 DeferredCapture(int reg, bool is_capture, Trace* trace) 1354 DeferredCapture(int reg, bool is_capture, Trace* trace)
1356 : DeferredAction(ActionNode::STORE_POSITION, reg), 1355 : DeferredAction(ActionNode::STORE_POSITION, reg),
1357 cp_offset_(trace->cp_offset()), 1356 cp_offset_(trace->cp_offset()),
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 Handle<String> sample_subject, 1614 Handle<String> sample_subject,
1616 bool is_ascii, Zone* zone); 1615 bool is_ascii, Zone* zone);
1617 1616
1618 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); 1617 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case);
1619 }; 1618 };
1620 1619
1621 1620
1622 } } // namespace v8::internal 1621 } } // namespace v8::internal
1623 1622
1624 #endif // V8_JSREGEXP_H_ 1623 #endif // V8_JSREGEXP_H_
OLDNEW
« no previous file with comments | « src/factory.cc ('k') | src/jsregexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698