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

Side by Side Diff: src/preparser.cc

Issue 6246064: Issue 117 - strict mode and future reserved words (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address code review comments Created 9 years, 10 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/preparser.h ('k') | src/scanner-base.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 1
2 // Copyright 2010 the V8 project authors. All rights reserved. 2 // Copyright 2010 the V8 project authors. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without 3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are 4 // modification, are permitted provided that the following conditions are
5 // met: 5 // met:
6 // 6 //
7 // * Redistributions of source code must retain the above copyright 7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer. 8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above 9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following 10 // copyright notice, this list of conditions and the following
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 case i::Token::EOS: 76 case i::Token::EOS:
77 return ReportMessageAt(source_location.beg_pos, source_location.end_pos, 77 return ReportMessageAt(source_location.beg_pos, source_location.end_pos,
78 "unexpected_eos", NULL); 78 "unexpected_eos", NULL);
79 case i::Token::NUMBER: 79 case i::Token::NUMBER:
80 return ReportMessageAt(source_location.beg_pos, source_location.end_pos, 80 return ReportMessageAt(source_location.beg_pos, source_location.end_pos,
81 "unexpected_token_number", NULL); 81 "unexpected_token_number", NULL);
82 case i::Token::STRING: 82 case i::Token::STRING:
83 return ReportMessageAt(source_location.beg_pos, source_location.end_pos, 83 return ReportMessageAt(source_location.beg_pos, source_location.end_pos,
84 "unexpected_token_string", NULL); 84 "unexpected_token_string", NULL);
85 case i::Token::IDENTIFIER: 85 case i::Token::IDENTIFIER:
86 case i::Token::FUTURE_RESERVED_WORD:
86 return ReportMessageAt(source_location.beg_pos, source_location.end_pos, 87 return ReportMessageAt(source_location.beg_pos, source_location.end_pos,
87 "unexpected_token_identifier", NULL); 88 "unexpected_token_identifier", NULL);
88 default: 89 default:
89 const char* name = i::Token::String(token); 90 const char* name = i::Token::String(token);
90 ReportMessageAt(source_location.beg_pos, source_location.end_pos, 91 ReportMessageAt(source_location.beg_pos, source_location.end_pos,
91 "unexpected_token", name); 92 "unexpected_token", name);
92 } 93 }
93 } 94 }
94 95
95 96
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 PreParser::Expression PreParser::ParseMemberWithNewPrefixesExpression( 784 PreParser::Expression PreParser::ParseMemberWithNewPrefixesExpression(
784 unsigned new_count, bool* ok) { 785 unsigned new_count, bool* ok) {
785 // MemberExpression :: 786 // MemberExpression ::
786 // (PrimaryExpression | FunctionLiteral) 787 // (PrimaryExpression | FunctionLiteral)
787 // ('[' Expression ']' | '.' Identifier | Arguments)* 788 // ('[' Expression ']' | '.' Identifier | Arguments)*
788 789
789 // Parse the initial primary or function expression. 790 // Parse the initial primary or function expression.
790 Expression result = kUnknownExpression; 791 Expression result = kUnknownExpression;
791 if (peek() == i::Token::FUNCTION) { 792 if (peek() == i::Token::FUNCTION) {
792 Consume(i::Token::FUNCTION); 793 Consume(i::Token::FUNCTION);
793 if (peek() == i::Token::IDENTIFIER) { 794 if (peek_any_identifier()) {
794 ParseIdentifier(CHECK_OK); 795 ParseIdentifier(CHECK_OK);
795 } 796 }
796 result = ParseFunctionLiteral(CHECK_OK); 797 result = ParseFunctionLiteral(CHECK_OK);
797 } else { 798 } else {
798 result = ParsePrimaryExpression(CHECK_OK); 799 result = ParsePrimaryExpression(CHECK_OK);
799 } 800 }
800 801
801 while (true) { 802 while (true) {
802 switch (peek()) { 803 switch (peek()) {
803 case i::Token::LBRACK: { 804 case i::Token::LBRACK: {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 // '(' Expression ')' 852 // '(' Expression ')'
852 853
853 Expression result = kUnknownExpression; 854 Expression result = kUnknownExpression;
854 switch (peek()) { 855 switch (peek()) {
855 case i::Token::THIS: { 856 case i::Token::THIS: {
856 Next(); 857 Next();
857 result = kThisExpression; 858 result = kThisExpression;
858 break; 859 break;
859 } 860 }
860 861
861 case i::Token::IDENTIFIER: { 862 case i::Token::IDENTIFIER:
863 case i::Token::FUTURE_RESERVED_WORD: {
862 ParseIdentifier(CHECK_OK); 864 ParseIdentifier(CHECK_OK);
863 result = kIdentifierExpression; 865 result = kIdentifierExpression;
864 break; 866 break;
865 } 867 }
866 868
867 case i::Token::NULL_LITERAL: 869 case i::Token::NULL_LITERAL:
868 case i::Token::TRUE_LITERAL: 870 case i::Token::TRUE_LITERAL:
869 case i::Token::FALSE_LITERAL: 871 case i::Token::FALSE_LITERAL:
870 case i::Token::NUMBER: { 872 case i::Token::NUMBER: {
871 Next(); 873 Next();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 // ObjectLiteral :: 941 // ObjectLiteral ::
940 // '{' ( 942 // '{' (
941 // ((IdentifierName | String | Number) ':' AssignmentExpression) 943 // ((IdentifierName | String | Number) ':' AssignmentExpression)
942 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) 944 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral)
943 // )*[','] '}' 945 // )*[','] '}'
944 946
945 Expect(i::Token::LBRACE, CHECK_OK); 947 Expect(i::Token::LBRACE, CHECK_OK);
946 while (peek() != i::Token::RBRACE) { 948 while (peek() != i::Token::RBRACE) {
947 i::Token::Value next = peek(); 949 i::Token::Value next = peek();
948 switch (next) { 950 switch (next) {
949 case i::Token::IDENTIFIER: { 951 case i::Token::IDENTIFIER:
952 case i::Token::FUTURE_RESERVED_WORD: {
950 bool is_getter = false; 953 bool is_getter = false;
951 bool is_setter = false; 954 bool is_setter = false;
952 ParseIdentifierOrGetOrSet(&is_getter, &is_setter, CHECK_OK); 955 ParseIdentifierOrGetOrSet(&is_getter, &is_setter, CHECK_OK);
953 if ((is_getter || is_setter) && peek() != i::Token::COLON) { 956 if ((is_getter || is_setter) && peek() != i::Token::COLON) {
954 i::Token::Value name = Next(); 957 i::Token::Value name = Next();
955 bool is_keyword = i::Token::IsKeyword(name); 958 bool is_keyword = i::Token::IsKeyword(name);
956 if (name != i::Token::IDENTIFIER && 959 if (name != i::Token::IDENTIFIER &&
960 name != i::Token::FUTURE_RESERVED_WORD &&
957 name != i::Token::NUMBER && 961 name != i::Token::NUMBER &&
958 name != i::Token::STRING && 962 name != i::Token::STRING &&
959 !is_keyword) { 963 !is_keyword) {
960 *ok = false; 964 *ok = false;
961 return kUnknownExpression; 965 return kUnknownExpression;
962 } 966 }
963 if (!is_keyword) { 967 if (!is_keyword) {
964 LogSymbol(); 968 LogSymbol();
965 } 969 }
966 ParseFunctionLiteral(CHECK_OK); 970 ParseFunctionLiteral(CHECK_OK);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 } 1148 }
1145 1149
1146 1150
1147 PreParser::Expression PreParser::GetStringSymbol() { 1151 PreParser::Expression PreParser::GetStringSymbol() {
1148 LogSymbol(); 1152 LogSymbol();
1149 return kUnknownExpression; 1153 return kUnknownExpression;
1150 } 1154 }
1151 1155
1152 1156
1153 PreParser::Identifier PreParser::ParseIdentifier(bool* ok) { 1157 PreParser::Identifier PreParser::ParseIdentifier(bool* ok) {
1154 Expect(i::Token::IDENTIFIER, ok); 1158 if (!Check(i::Token::FUTURE_RESERVED_WORD)) {
1159 Expect(i::Token::IDENTIFIER, ok);
1160 }
1155 if (!*ok) return kUnknownIdentifier; 1161 if (!*ok) return kUnknownIdentifier;
1156 return GetIdentifierSymbol(); 1162 return GetIdentifierSymbol();
1157 } 1163 }
1158 1164
1159 1165
1160 PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) { 1166 PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) {
1161 i::Token::Value next = Next(); 1167 i::Token::Value next = Next();
1162 if (i::Token::IsKeyword(next)) { 1168 if (i::Token::IsKeyword(next)) {
1163 int pos = scanner_->location().beg_pos; 1169 int pos = scanner_->location().beg_pos;
1164 const char* keyword = i::Token::String(next); 1170 const char* keyword = i::Token::String(next);
1165 log_->LogAsciiSymbol(pos, i::Vector<const char>(keyword, 1171 log_->LogAsciiSymbol(pos, i::Vector<const char>(keyword,
1166 i::StrLength(keyword))); 1172 i::StrLength(keyword)));
1167 return kUnknownExpression; 1173 return kUnknownExpression;
1168 } 1174 }
1169 if (next == i::Token::IDENTIFIER) { 1175 if (next == i::Token::IDENTIFIER ||
1176 next == i::Token::FUTURE_RESERVED_WORD) {
1170 return GetIdentifierSymbol(); 1177 return GetIdentifierSymbol();
1171 } 1178 }
1172 *ok = false; 1179 *ok = false;
1173 return kUnknownIdentifier; 1180 return kUnknownIdentifier;
1174 } 1181 }
1175 1182
1176 1183
1177 // This function reads an identifier and determines whether or not it 1184 // This function reads an identifier and determines whether or not it
1178 // is 'get' or 'set'. The reason for not using ParseIdentifier and 1185 // is 'get' or 'set'.
1179 // checking on the output is that this involves heap allocation which
1180 // we can't do during preparsing.
1181 PreParser::Identifier PreParser::ParseIdentifierOrGetOrSet(bool* is_get, 1186 PreParser::Identifier PreParser::ParseIdentifierOrGetOrSet(bool* is_get,
1182 bool* is_set, 1187 bool* is_set,
1183 bool* ok) { 1188 bool* ok) {
1184 Expect(i::Token::IDENTIFIER, CHECK_OK); 1189 PreParser::Identifier result = ParseIdentifier(CHECK_OK);
1185 if (scanner_->is_literal_ascii() && scanner_->literal_length() == 3) { 1190 if (scanner_->is_literal_ascii() && scanner_->literal_length() == 3) {
1186 const char* token = scanner_->literal_ascii_string().start(); 1191 const char* token = scanner_->literal_ascii_string().start();
1187 *is_get = strncmp(token, "get", 3) == 0; 1192 *is_get = strncmp(token, "get", 3) == 0;
1188 *is_set = !*is_get && strncmp(token, "set", 3) == 0; 1193 *is_set = !*is_get && strncmp(token, "set", 3) == 0;
1189 } 1194 }
1190 return GetIdentifierSymbol(); 1195 return result;
1196 }
1197
1198 bool PreParser::peek_any_identifier() {
1199 i::Token::Value next = peek();
1200 return next == i::Token::IDENTIFIER ||
1201 next == i::Token::FUTURE_RESERVED_WORD;
1191 } 1202 }
1192 1203
1193 #undef CHECK_OK 1204 #undef CHECK_OK
1194 } } // v8::preparser 1205 } } // v8::preparser
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | src/scanner-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698