| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 return true; | 789 return true; |
| 790 } | 790 } |
| 791 | 791 |
| 792 // ---------------------------------------------------------------------------- | 792 // ---------------------------------------------------------------------------- |
| 793 // Keyword Matcher | 793 // Keyword Matcher |
| 794 | 794 |
| 795 KeywordMatcher::FirstState KeywordMatcher::first_states_[] = { | 795 KeywordMatcher::FirstState KeywordMatcher::first_states_[] = { |
| 796 { "break", KEYWORD_PREFIX, Token::BREAK }, | 796 { "break", KEYWORD_PREFIX, Token::BREAK }, |
| 797 { NULL, C, Token::ILLEGAL }, | 797 { NULL, C, Token::ILLEGAL }, |
| 798 { NULL, D, Token::ILLEGAL }, | 798 { NULL, D, Token::ILLEGAL }, |
| 799 { "else", KEYWORD_PREFIX, Token::ELSE }, | 799 { NULL, E, Token::ILLEGAL }, |
| 800 { NULL, F, Token::ILLEGAL }, | 800 { NULL, F, Token::ILLEGAL }, |
| 801 { NULL, UNMATCHABLE, Token::ILLEGAL }, | 801 { NULL, UNMATCHABLE, Token::ILLEGAL }, |
| 802 { NULL, UNMATCHABLE, Token::ILLEGAL }, | 802 { NULL, UNMATCHABLE, Token::ILLEGAL }, |
| 803 { NULL, I, Token::ILLEGAL }, | 803 { NULL, I, Token::ILLEGAL }, |
| 804 { NULL, UNMATCHABLE, Token::ILLEGAL }, | 804 { NULL, UNMATCHABLE, Token::ILLEGAL }, |
| 805 { NULL, UNMATCHABLE, Token::ILLEGAL }, | 805 { NULL, UNMATCHABLE, Token::ILLEGAL }, |
| 806 { NULL, UNMATCHABLE, Token::ILLEGAL }, | 806 { "let", KEYWORD_PREFIX, Token::FUTURE_RESERVED_WORD }, |
| 807 { NULL, UNMATCHABLE, Token::ILLEGAL }, | 807 { NULL, UNMATCHABLE, Token::ILLEGAL }, |
| 808 { NULL, N, Token::ILLEGAL }, | 808 { NULL, N, Token::ILLEGAL }, |
| 809 { NULL, UNMATCHABLE, Token::ILLEGAL }, | 809 { NULL, UNMATCHABLE, Token::ILLEGAL }, |
| 810 { NULL, UNMATCHABLE, Token::ILLEGAL }, | 810 { NULL, P, Token::ILLEGAL }, |
| 811 { NULL, UNMATCHABLE, Token::ILLEGAL }, | 811 { NULL, UNMATCHABLE, Token::ILLEGAL }, |
| 812 { "return", KEYWORD_PREFIX, Token::RETURN }, | 812 { "return", KEYWORD_PREFIX, Token::RETURN }, |
| 813 { "switch", KEYWORD_PREFIX, Token::SWITCH }, | 813 { NULL, S, Token::ILLEGAL }, |
| 814 { NULL, T, Token::ILLEGAL }, | 814 { NULL, T, Token::ILLEGAL }, |
| 815 { NULL, UNMATCHABLE, Token::ILLEGAL }, | 815 { NULL, UNMATCHABLE, Token::ILLEGAL }, |
| 816 { NULL, V, Token::ILLEGAL }, | 816 { NULL, V, Token::ILLEGAL }, |
| 817 { NULL, W, Token::ILLEGAL } | 817 { NULL, W, Token::ILLEGAL }, |
| 818 { NULL, UNMATCHABLE, Token::ILLEGAL }, |
| 819 { "yield", KEYWORD_PREFIX, Token::FUTURE_RESERVED_WORD } |
| 818 }; | 820 }; |
| 819 | 821 |
| 820 | 822 |
| 821 void KeywordMatcher::Step(unibrow::uchar input) { | 823 void KeywordMatcher::Step(unibrow::uchar input) { |
| 822 switch (state_) { | 824 switch (state_) { |
| 823 case INITIAL: { | 825 case INITIAL: { |
| 824 // matching the first character is the only state with significant fanout. | 826 // matching the first character is the only state with significant fanout. |
| 825 // Match only lower-case letters in range 'b'..'w'. | 827 // Match only lower-case letters in range 'b'..'y'. |
| 826 unsigned int offset = input - kFirstCharRangeMin; | 828 unsigned int offset = input - kFirstCharRangeMin; |
| 827 if (offset < kFirstCharRangeLength) { | 829 if (offset < kFirstCharRangeLength) { |
| 828 state_ = first_states_[offset].state; | 830 state_ = first_states_[offset].state; |
| 829 if (state_ == KEYWORD_PREFIX) { | 831 if (state_ == KEYWORD_PREFIX) { |
| 830 keyword_ = first_states_[offset].keyword; | 832 keyword_ = first_states_[offset].keyword; |
| 831 counter_ = 1; | 833 counter_ = 1; |
| 832 keyword_token_ = first_states_[offset].token; | 834 keyword_token_ = first_states_[offset].token; |
| 833 } | 835 } |
| 834 return; | 836 return; |
| 835 } | 837 } |
| 836 break; | 838 break; |
| 837 } | 839 } |
| 838 case KEYWORD_PREFIX: | 840 case KEYWORD_PREFIX: |
| 839 if (static_cast<unibrow::uchar>(keyword_[counter_]) == input) { | 841 if (static_cast<unibrow::uchar>(keyword_[counter_]) == input) { |
| 840 counter_++; | 842 counter_++; |
| 841 if (keyword_[counter_] == '\0') { | 843 if (keyword_[counter_] == '\0') { |
| 842 state_ = KEYWORD_MATCHED; | 844 state_ = KEYWORD_MATCHED; |
| 843 token_ = keyword_token_; | 845 token_ = keyword_token_; |
| 844 } | 846 } |
| 845 return; | 847 return; |
| 846 } | 848 } |
| 847 break; | 849 break; |
| 848 case KEYWORD_MATCHED: | 850 case KEYWORD_MATCHED: |
| 849 token_ = Token::IDENTIFIER; | 851 token_ = Token::IDENTIFIER; |
| 850 break; | 852 break; |
| 851 case C: | 853 case C: |
| 852 if (MatchState(input, 'a', CA)) return; | 854 if (MatchState(input, 'a', CA)) return; |
| 855 if (MatchKeywordStart(input, "class", 1, |
| 856 Token::FUTURE_RESERVED_WORD)) return; |
| 853 if (MatchState(input, 'o', CO)) return; | 857 if (MatchState(input, 'o', CO)) return; |
| 854 break; | 858 break; |
| 855 case CA: | 859 case CA: |
| 856 if (MatchKeywordStart(input, "case", 2, Token::CASE)) return; | 860 if (MatchKeywordStart(input, "case", 2, Token::CASE)) return; |
| 857 if (MatchKeywordStart(input, "catch", 2, Token::CATCH)) return; | 861 if (MatchKeywordStart(input, "catch", 2, Token::CATCH)) return; |
| 858 break; | 862 break; |
| 859 case CO: | 863 case CO: |
| 860 if (MatchState(input, 'n', CON)) return; | 864 if (MatchState(input, 'n', CON)) return; |
| 861 break; | 865 break; |
| 862 case CON: | 866 case CON: |
| 863 if (MatchKeywordStart(input, "const", 3, Token::CONST)) return; | 867 if (MatchKeywordStart(input, "const", 3, Token::CONST)) return; |
| 864 if (MatchKeywordStart(input, "continue", 3, Token::CONTINUE)) return; | 868 if (MatchKeywordStart(input, "continue", 3, Token::CONTINUE)) return; |
| 865 break; | 869 break; |
| 866 case D: | 870 case D: |
| 867 if (MatchState(input, 'e', DE)) return; | 871 if (MatchState(input, 'e', DE)) return; |
| 868 if (MatchKeyword(input, 'o', KEYWORD_MATCHED, Token::DO)) return; | 872 if (MatchKeyword(input, 'o', KEYWORD_MATCHED, Token::DO)) return; |
| 869 break; | 873 break; |
| 870 case DE: | 874 case DE: |
| 871 if (MatchKeywordStart(input, "debugger", 2, Token::DEBUGGER)) return; | 875 if (MatchKeywordStart(input, "debugger", 2, Token::DEBUGGER)) return; |
| 872 if (MatchKeywordStart(input, "default", 2, Token::DEFAULT)) return; | 876 if (MatchKeywordStart(input, "default", 2, Token::DEFAULT)) return; |
| 873 if (MatchKeywordStart(input, "delete", 2, Token::DELETE)) return; | 877 if (MatchKeywordStart(input, "delete", 2, Token::DELETE)) return; |
| 874 break; | 878 break; |
| 879 case E: |
| 880 if (MatchKeywordStart(input, "else", 1, Token::ELSE)) return; |
| 881 if (MatchKeywordStart(input, "enum", 1, |
| 882 Token::FUTURE_RESERVED_WORD)) return; |
| 883 if (MatchState(input, 'x', EX)) return; |
| 884 break; |
| 885 case EX: |
| 886 if (MatchKeywordStart(input, "export", 2, |
| 887 Token::FUTURE_RESERVED_WORD)) return; |
| 888 if (MatchKeywordStart(input, "extends", 2, |
| 889 Token::FUTURE_RESERVED_WORD)) return; |
| 890 break; |
| 875 case F: | 891 case F: |
| 876 if (MatchKeywordStart(input, "false", 1, Token::FALSE_LITERAL)) return; | 892 if (MatchKeywordStart(input, "false", 1, Token::FALSE_LITERAL)) return; |
| 877 if (MatchKeywordStart(input, "finally", 1, Token::FINALLY)) return; | 893 if (MatchKeywordStart(input, "finally", 1, Token::FINALLY)) return; |
| 878 if (MatchKeywordStart(input, "for", 1, Token::FOR)) return; | 894 if (MatchKeywordStart(input, "for", 1, Token::FOR)) return; |
| 879 if (MatchKeywordStart(input, "function", 1, Token::FUNCTION)) return; | 895 if (MatchKeywordStart(input, "function", 1, Token::FUNCTION)) return; |
| 880 break; | 896 break; |
| 881 case I: | 897 case I: |
| 882 if (MatchKeyword(input, 'f', KEYWORD_MATCHED, Token::IF)) return; | 898 if (MatchKeyword(input, 'f', KEYWORD_MATCHED, Token::IF)) return; |
| 899 if (MatchState(input, 'm', IM)) return; |
| 883 if (MatchKeyword(input, 'n', IN, Token::IN)) return; | 900 if (MatchKeyword(input, 'n', IN, Token::IN)) return; |
| 884 break; | 901 break; |
| 902 case IM: |
| 903 if (MatchState(input, 'p', IMP)) return; |
| 904 break; |
| 905 case IMP: |
| 906 if (MatchKeywordStart(input, "implements", 3, |
| 907 Token::FUTURE_RESERVED_WORD )) return; |
| 908 if (MatchKeywordStart(input, "import", 3, |
| 909 Token::FUTURE_RESERVED_WORD)) return; |
| 910 break; |
| 885 case IN: | 911 case IN: |
| 886 token_ = Token::IDENTIFIER; | 912 token_ = Token::IDENTIFIER; |
| 913 if (MatchKeywordStart(input, "interface", 2, |
| 914 Token::FUTURE_RESERVED_WORD)) return; |
| 887 if (MatchKeywordStart(input, "instanceof", 2, Token::INSTANCEOF)) return; | 915 if (MatchKeywordStart(input, "instanceof", 2, Token::INSTANCEOF)) return; |
| 888 break; | 916 break; |
| 889 case N: | 917 case N: |
| 890 if (MatchKeywordStart(input, "native", 1, Token::NATIVE)) return; | 918 if (MatchKeywordStart(input, "native", 1, Token::NATIVE)) return; |
| 891 if (MatchKeywordStart(input, "new", 1, Token::NEW)) return; | 919 if (MatchKeywordStart(input, "new", 1, Token::NEW)) return; |
| 892 if (MatchKeywordStart(input, "null", 1, Token::NULL_LITERAL)) return; | 920 if (MatchKeywordStart(input, "null", 1, Token::NULL_LITERAL)) return; |
| 893 break; | 921 break; |
| 922 case P: |
| 923 if (MatchKeywordStart(input, "package", 1, |
| 924 Token::FUTURE_RESERVED_WORD)) return; |
| 925 if (MatchState(input, 'r', PR)) return; |
| 926 if (MatchKeywordStart(input, "public", 1, |
| 927 Token::FUTURE_RESERVED_WORD)) return; |
| 928 break; |
| 929 case PR: |
| 930 if (MatchKeywordStart(input, "private", 2, |
| 931 Token::FUTURE_RESERVED_WORD)) return; |
| 932 if (MatchKeywordStart(input, "protected", 2, |
| 933 Token::FUTURE_RESERVED_WORD)) return; |
| 934 break; |
| 935 case S: |
| 936 if (MatchKeywordStart(input, "static", 1, |
| 937 Token::FUTURE_RESERVED_WORD)) return; |
| 938 if (MatchKeywordStart(input, "super", 1, |
| 939 Token::FUTURE_RESERVED_WORD)) return; |
| 940 if (MatchKeywordStart(input, "switch", 1, |
| 941 Token::SWITCH)) return; |
| 942 break; |
| 894 case T: | 943 case T: |
| 895 if (MatchState(input, 'h', TH)) return; | 944 if (MatchState(input, 'h', TH)) return; |
| 896 if (MatchState(input, 'r', TR)) return; | 945 if (MatchState(input, 'r', TR)) return; |
| 897 if (MatchKeywordStart(input, "typeof", 1, Token::TYPEOF)) return; | 946 if (MatchKeywordStart(input, "typeof", 1, Token::TYPEOF)) return; |
| 898 break; | 947 break; |
| 899 case TH: | 948 case TH: |
| 900 if (MatchKeywordStart(input, "this", 2, Token::THIS)) return; | 949 if (MatchKeywordStart(input, "this", 2, Token::THIS)) return; |
| 901 if (MatchKeywordStart(input, "throw", 2, Token::THROW)) return; | 950 if (MatchKeywordStart(input, "throw", 2, Token::THROW)) return; |
| 902 break; | 951 break; |
| 903 case TR: | 952 case TR: |
| 904 if (MatchKeywordStart(input, "true", 2, Token::TRUE_LITERAL)) return; | 953 if (MatchKeywordStart(input, "true", 2, Token::TRUE_LITERAL)) return; |
| 905 if (MatchKeyword(input, 'y', KEYWORD_MATCHED, Token::TRY)) return; | 954 if (MatchKeyword(input, 'y', KEYWORD_MATCHED, Token::TRY)) return; |
| 906 break; | 955 break; |
| 907 case V: | 956 case V: |
| 908 if (MatchKeywordStart(input, "var", 1, Token::VAR)) return; | 957 if (MatchKeywordStart(input, "var", 1, Token::VAR)) return; |
| 909 if (MatchKeywordStart(input, "void", 1, Token::VOID)) return; | 958 if (MatchKeywordStart(input, "void", 1, Token::VOID)) return; |
| 910 break; | 959 break; |
| 911 case W: | 960 case W: |
| 912 if (MatchKeywordStart(input, "while", 1, Token::WHILE)) return; | 961 if (MatchKeywordStart(input, "while", 1, Token::WHILE)) return; |
| 913 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; | 962 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; |
| 914 break; | 963 break; |
| 915 case UNMATCHABLE: | 964 case UNMATCHABLE: |
| 916 break; | 965 break; |
| 917 } | 966 } |
| 918 // On fallthrough, it's a failure. | 967 // On fallthrough, it's a failure. |
| 919 state_ = UNMATCHABLE; | 968 state_ = UNMATCHABLE; |
| 920 } | 969 } |
| 921 | 970 |
| 922 } } // namespace v8::internal | 971 } } // namespace v8::internal |
| OLD | NEW |