| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 namespace v8 { | 35 namespace v8 { |
| 36 namespace internal { | 36 namespace internal { |
| 37 | 37 |
| 38 // ---------------------------------------------------------------------------- | 38 // ---------------------------------------------------------------------------- |
| 39 // Scanner | 39 // Scanner |
| 40 | 40 |
| 41 Scanner::Scanner(UnicodeCache* unicode_cache) | 41 Scanner::Scanner(UnicodeCache* unicode_cache) |
| 42 : unicode_cache_(unicode_cache), | 42 : unicode_cache_(unicode_cache), |
| 43 octal_pos_(Location::invalid()), | 43 octal_pos_(Location::invalid()), |
| 44 harmony_scoping_(false) { } | 44 harmony_scoping_(false), |
| 45 harmony_modules_(false) { } |
| 45 | 46 |
| 46 | 47 |
| 47 void Scanner::Initialize(UC16CharacterStream* source) { | 48 void Scanner::Initialize(UC16CharacterStream* source) { |
| 48 source_ = source; | 49 source_ = source; |
| 49 // Need to capture identifiers in order to recognize "get" and "set" | 50 // Need to capture identifiers in order to recognize "get" and "set" |
| 50 // in object literals. | 51 // in object literals. |
| 51 Init(); | 52 Init(); |
| 52 // Skip initial whitespace allowing HTML comment ends just like | 53 // Skip initial whitespace allowing HTML comment ends just like |
| 53 // after a newline and scan first token. | 54 // after a newline and scan first token. |
| 54 has_line_terminator_before_next_ = true; | 55 has_line_terminator_before_next_ = true; |
| (...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 KEYWORD("const", Token::CONST) \ | 824 KEYWORD("const", Token::CONST) \ |
| 824 KEYWORD("continue", Token::CONTINUE) \ | 825 KEYWORD("continue", Token::CONTINUE) \ |
| 825 KEYWORD_GROUP('d') \ | 826 KEYWORD_GROUP('d') \ |
| 826 KEYWORD("debugger", Token::DEBUGGER) \ | 827 KEYWORD("debugger", Token::DEBUGGER) \ |
| 827 KEYWORD("default", Token::DEFAULT) \ | 828 KEYWORD("default", Token::DEFAULT) \ |
| 828 KEYWORD("delete", Token::DELETE) \ | 829 KEYWORD("delete", Token::DELETE) \ |
| 829 KEYWORD("do", Token::DO) \ | 830 KEYWORD("do", Token::DO) \ |
| 830 KEYWORD_GROUP('e') \ | 831 KEYWORD_GROUP('e') \ |
| 831 KEYWORD("else", Token::ELSE) \ | 832 KEYWORD("else", Token::ELSE) \ |
| 832 KEYWORD("enum", Token::FUTURE_RESERVED_WORD) \ | 833 KEYWORD("enum", Token::FUTURE_RESERVED_WORD) \ |
| 833 KEYWORD("export", Token::FUTURE_RESERVED_WORD) \ | 834 KEYWORD("export", harmony_modules \ |
| 835 ? Token::EXPORT : Token::FUTURE_RESERVED_WORD) \ |
| 834 KEYWORD("extends", Token::FUTURE_RESERVED_WORD) \ | 836 KEYWORD("extends", Token::FUTURE_RESERVED_WORD) \ |
| 835 KEYWORD_GROUP('f') \ | 837 KEYWORD_GROUP('f') \ |
| 836 KEYWORD("false", Token::FALSE_LITERAL) \ | 838 KEYWORD("false", Token::FALSE_LITERAL) \ |
| 837 KEYWORD("finally", Token::FINALLY) \ | 839 KEYWORD("finally", Token::FINALLY) \ |
| 838 KEYWORD("for", Token::FOR) \ | 840 KEYWORD("for", Token::FOR) \ |
| 839 KEYWORD("function", Token::FUNCTION) \ | 841 KEYWORD("function", Token::FUNCTION) \ |
| 840 KEYWORD_GROUP('i') \ | 842 KEYWORD_GROUP('i') \ |
| 841 KEYWORD("if", Token::IF) \ | 843 KEYWORD("if", Token::IF) \ |
| 842 KEYWORD("implements", Token::FUTURE_STRICT_RESERVED_WORD) \ | 844 KEYWORD("implements", Token::FUTURE_STRICT_RESERVED_WORD) \ |
| 843 KEYWORD("import", Token::FUTURE_RESERVED_WORD) \ | 845 KEYWORD("import", harmony_modules \ |
| 846 ? Token::IMPORT : Token::FUTURE_RESERVED_WORD) \ |
| 844 KEYWORD("in", Token::IN) \ | 847 KEYWORD("in", Token::IN) \ |
| 845 KEYWORD("instanceof", Token::INSTANCEOF) \ | 848 KEYWORD("instanceof", Token::INSTANCEOF) \ |
| 846 KEYWORD("interface", Token::FUTURE_STRICT_RESERVED_WORD) \ | 849 KEYWORD("interface", Token::FUTURE_STRICT_RESERVED_WORD) \ |
| 847 KEYWORD_GROUP('l') \ | 850 KEYWORD_GROUP('l') \ |
| 848 KEYWORD("let", harmony_scoping \ | 851 KEYWORD("let", harmony_scoping \ |
| 849 ? Token::LET : Token::FUTURE_STRICT_RESERVED_WORD) \ | 852 ? Token::LET : Token::FUTURE_STRICT_RESERVED_WORD) \ |
| 853 KEYWORD_GROUP('m') \ |
| 854 KEYWORD("module", harmony_modules \ |
| 855 ? Token::MODULE : Token::IDENTIFIER) \ |
| 850 KEYWORD_GROUP('n') \ | 856 KEYWORD_GROUP('n') \ |
| 851 KEYWORD("new", Token::NEW) \ | 857 KEYWORD("new", Token::NEW) \ |
| 852 KEYWORD("null", Token::NULL_LITERAL) \ | 858 KEYWORD("null", Token::NULL_LITERAL) \ |
| 853 KEYWORD_GROUP('p') \ | 859 KEYWORD_GROUP('p') \ |
| 854 KEYWORD("package", Token::FUTURE_STRICT_RESERVED_WORD) \ | 860 KEYWORD("package", Token::FUTURE_STRICT_RESERVED_WORD) \ |
| 855 KEYWORD("private", Token::FUTURE_STRICT_RESERVED_WORD) \ | 861 KEYWORD("private", Token::FUTURE_STRICT_RESERVED_WORD) \ |
| 856 KEYWORD("protected", Token::FUTURE_STRICT_RESERVED_WORD) \ | 862 KEYWORD("protected", Token::FUTURE_STRICT_RESERVED_WORD) \ |
| 857 KEYWORD("public", Token::FUTURE_STRICT_RESERVED_WORD) \ | 863 KEYWORD("public", Token::FUTURE_STRICT_RESERVED_WORD) \ |
| 858 KEYWORD_GROUP('r') \ | 864 KEYWORD_GROUP('r') \ |
| 859 KEYWORD("return", Token::RETURN) \ | 865 KEYWORD("return", Token::RETURN) \ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 872 KEYWORD("void", Token::VOID) \ | 878 KEYWORD("void", Token::VOID) \ |
| 873 KEYWORD_GROUP('w') \ | 879 KEYWORD_GROUP('w') \ |
| 874 KEYWORD("while", Token::WHILE) \ | 880 KEYWORD("while", Token::WHILE) \ |
| 875 KEYWORD("with", Token::WITH) \ | 881 KEYWORD("with", Token::WITH) \ |
| 876 KEYWORD_GROUP('y') \ | 882 KEYWORD_GROUP('y') \ |
| 877 KEYWORD("yield", Token::FUTURE_STRICT_RESERVED_WORD) | 883 KEYWORD("yield", Token::FUTURE_STRICT_RESERVED_WORD) |
| 878 | 884 |
| 879 | 885 |
| 880 static Token::Value KeywordOrIdentifierToken(const char* input, | 886 static Token::Value KeywordOrIdentifierToken(const char* input, |
| 881 int input_length, | 887 int input_length, |
| 882 bool harmony_scoping) { | 888 bool harmony_scoping, |
| 889 bool harmony_modules) { |
| 883 ASSERT(input_length >= 1); | 890 ASSERT(input_length >= 1); |
| 884 const int kMinLength = 2; | 891 const int kMinLength = 2; |
| 885 const int kMaxLength = 10; | 892 const int kMaxLength = 10; |
| 886 if (input_length < kMinLength || input_length > kMaxLength) { | 893 if (input_length < kMinLength || input_length > kMaxLength) { |
| 887 return Token::IDENTIFIER; | 894 return Token::IDENTIFIER; |
| 888 } | 895 } |
| 889 switch (input[0]) { | 896 switch (input[0]) { |
| 890 default: | 897 default: |
| 891 #define KEYWORD_GROUP_CASE(ch) \ | 898 #define KEYWORD_GROUP_CASE(ch) \ |
| 892 break; \ | 899 break; \ |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 // Fallthrough if no longer able to complete keyword. | 955 // Fallthrough if no longer able to complete keyword. |
| 949 return ScanIdentifierSuffix(&literal); | 956 return ScanIdentifierSuffix(&literal); |
| 950 } | 957 } |
| 951 | 958 |
| 952 literal.Complete(); | 959 literal.Complete(); |
| 953 | 960 |
| 954 if (next_.literal_chars->is_ascii()) { | 961 if (next_.literal_chars->is_ascii()) { |
| 955 Vector<const char> chars = next_.literal_chars->ascii_literal(); | 962 Vector<const char> chars = next_.literal_chars->ascii_literal(); |
| 956 return KeywordOrIdentifierToken(chars.start(), | 963 return KeywordOrIdentifierToken(chars.start(), |
| 957 chars.length(), | 964 chars.length(), |
| 958 harmony_scoping_); | 965 harmony_scoping_, |
| 966 harmony_modules_); |
| 959 } | 967 } |
| 960 | 968 |
| 961 return Token::IDENTIFIER; | 969 return Token::IDENTIFIER; |
| 962 } | 970 } |
| 963 | 971 |
| 964 | 972 |
| 965 Token::Value Scanner::ScanIdentifierSuffix(LiteralScope* literal) { | 973 Token::Value Scanner::ScanIdentifierSuffix(LiteralScope* literal) { |
| 966 // Scan the rest of the identifier characters. | 974 // Scan the rest of the identifier characters. |
| 967 while (unicode_cache_->IsIdentifierPart(c0_)) { | 975 while (unicode_cache_->IsIdentifierPart(c0_)) { |
| 968 if (c0_ == '\\') { | 976 if (c0_ == '\\') { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 } | 1082 } |
| 1075 } | 1083 } |
| 1076 } | 1084 } |
| 1077 literal.Complete(); | 1085 literal.Complete(); |
| 1078 | 1086 |
| 1079 next_.location.end_pos = source_pos() - 1; | 1087 next_.location.end_pos = source_pos() - 1; |
| 1080 return true; | 1088 return true; |
| 1081 } | 1089 } |
| 1082 | 1090 |
| 1083 } } // namespace v8::internal | 1091 } } // namespace v8::internal |
| OLD | NEW |