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

Side by Side Diff: src/preparser.cc

Issue 6606006: [Isolates] Merge 6500:6700 from bleeding_edge to isolates. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: '' Created 9 years, 9 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/prettyprinter.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 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 case i::Token::EOS: 83 case i::Token::EOS:
84 return ReportMessageAt(source_location.beg_pos, source_location.end_pos, 84 return ReportMessageAt(source_location.beg_pos, source_location.end_pos,
85 "unexpected_eos", NULL); 85 "unexpected_eos", NULL);
86 case i::Token::NUMBER: 86 case i::Token::NUMBER:
87 return ReportMessageAt(source_location.beg_pos, source_location.end_pos, 87 return ReportMessageAt(source_location.beg_pos, source_location.end_pos,
88 "unexpected_token_number", NULL); 88 "unexpected_token_number", NULL);
89 case i::Token::STRING: 89 case i::Token::STRING:
90 return ReportMessageAt(source_location.beg_pos, source_location.end_pos, 90 return ReportMessageAt(source_location.beg_pos, source_location.end_pos,
91 "unexpected_token_string", NULL); 91 "unexpected_token_string", NULL);
92 case i::Token::IDENTIFIER: 92 case i::Token::IDENTIFIER:
93 case i::Token::FUTURE_RESERVED_WORD:
93 return ReportMessageAt(source_location.beg_pos, source_location.end_pos, 94 return ReportMessageAt(source_location.beg_pos, source_location.end_pos,
94 "unexpected_token_identifier", NULL); 95 "unexpected_token_identifier", NULL);
95 default: 96 default:
96 const char* name = i::Token::String(token); 97 const char* name = i::Token::String(token);
97 ReportMessageAt(source_location.beg_pos, source_location.end_pos, 98 ReportMessageAt(source_location.beg_pos, source_location.end_pos,
98 "unexpected_token", name); 99 "unexpected_token", name);
99 } 100 }
100 } 101 }
101 102
102 103
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 PreParser::Expression PreParser::ParseMemberWithNewPrefixesExpression( 791 PreParser::Expression PreParser::ParseMemberWithNewPrefixesExpression(
791 unsigned new_count, bool* ok) { 792 unsigned new_count, bool* ok) {
792 // MemberExpression :: 793 // MemberExpression ::
793 // (PrimaryExpression | FunctionLiteral) 794 // (PrimaryExpression | FunctionLiteral)
794 // ('[' Expression ']' | '.' Identifier | Arguments)* 795 // ('[' Expression ']' | '.' Identifier | Arguments)*
795 796
796 // Parse the initial primary or function expression. 797 // Parse the initial primary or function expression.
797 Expression result = kUnknownExpression; 798 Expression result = kUnknownExpression;
798 if (peek() == i::Token::FUNCTION) { 799 if (peek() == i::Token::FUNCTION) {
799 Consume(i::Token::FUNCTION); 800 Consume(i::Token::FUNCTION);
800 if (peek() == i::Token::IDENTIFIER) { 801 if (peek_any_identifier()) {
801 ParseIdentifier(CHECK_OK); 802 ParseIdentifier(CHECK_OK);
802 } 803 }
803 result = ParseFunctionLiteral(CHECK_OK); 804 result = ParseFunctionLiteral(CHECK_OK);
804 } else { 805 } else {
805 result = ParsePrimaryExpression(CHECK_OK); 806 result = ParsePrimaryExpression(CHECK_OK);
806 } 807 }
807 808
808 while (true) { 809 while (true) {
809 switch (peek()) { 810 switch (peek()) {
810 case i::Token::LBRACK: { 811 case i::Token::LBRACK: {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 // '(' Expression ')' 859 // '(' Expression ')'
859 860
860 Expression result = kUnknownExpression; 861 Expression result = kUnknownExpression;
861 switch (peek()) { 862 switch (peek()) {
862 case i::Token::THIS: { 863 case i::Token::THIS: {
863 Next(); 864 Next();
864 result = kThisExpression; 865 result = kThisExpression;
865 break; 866 break;
866 } 867 }
867 868
868 case i::Token::IDENTIFIER: { 869 case i::Token::IDENTIFIER:
870 case i::Token::FUTURE_RESERVED_WORD: {
869 ParseIdentifier(CHECK_OK); 871 ParseIdentifier(CHECK_OK);
870 result = kIdentifierExpression; 872 result = kIdentifierExpression;
871 break; 873 break;
872 } 874 }
873 875
874 case i::Token::NULL_LITERAL: 876 case i::Token::NULL_LITERAL:
875 case i::Token::TRUE_LITERAL: 877 case i::Token::TRUE_LITERAL:
876 case i::Token::FALSE_LITERAL: 878 case i::Token::FALSE_LITERAL:
877 case i::Token::NUMBER: { 879 case i::Token::NUMBER: {
878 Next(); 880 Next();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 // ObjectLiteral :: 948 // ObjectLiteral ::
947 // '{' ( 949 // '{' (
948 // ((IdentifierName | String | Number) ':' AssignmentExpression) 950 // ((IdentifierName | String | Number) ':' AssignmentExpression)
949 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) 951 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral)
950 // )*[','] '}' 952 // )*[','] '}'
951 953
952 Expect(i::Token::LBRACE, CHECK_OK); 954 Expect(i::Token::LBRACE, CHECK_OK);
953 while (peek() != i::Token::RBRACE) { 955 while (peek() != i::Token::RBRACE) {
954 i::Token::Value next = peek(); 956 i::Token::Value next = peek();
955 switch (next) { 957 switch (next) {
956 case i::Token::IDENTIFIER: { 958 case i::Token::IDENTIFIER:
959 case i::Token::FUTURE_RESERVED_WORD: {
957 bool is_getter = false; 960 bool is_getter = false;
958 bool is_setter = false; 961 bool is_setter = false;
959 ParseIdentifierOrGetOrSet(&is_getter, &is_setter, CHECK_OK); 962 ParseIdentifierOrGetOrSet(&is_getter, &is_setter, CHECK_OK);
960 if ((is_getter || is_setter) && peek() != i::Token::COLON) { 963 if ((is_getter || is_setter) && peek() != i::Token::COLON) {
961 i::Token::Value name = Next(); 964 i::Token::Value name = Next();
962 bool is_keyword = i::Token::IsKeyword(name); 965 bool is_keyword = i::Token::IsKeyword(name);
963 if (name != i::Token::IDENTIFIER && 966 if (name != i::Token::IDENTIFIER &&
967 name != i::Token::FUTURE_RESERVED_WORD &&
964 name != i::Token::NUMBER && 968 name != i::Token::NUMBER &&
965 name != i::Token::STRING && 969 name != i::Token::STRING &&
966 !is_keyword) { 970 !is_keyword) {
967 *ok = false; 971 *ok = false;
968 return kUnknownExpression; 972 return kUnknownExpression;
969 } 973 }
970 if (!is_keyword) { 974 if (!is_keyword) {
971 LogSymbol(); 975 LogSymbol();
972 } 976 }
973 ParseFunctionLiteral(CHECK_OK); 977 ParseFunctionLiteral(CHECK_OK);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 } 1155 }
1152 1156
1153 1157
1154 PreParser::Expression PreParser::GetStringSymbol() { 1158 PreParser::Expression PreParser::GetStringSymbol() {
1155 LogSymbol(); 1159 LogSymbol();
1156 return kUnknownExpression; 1160 return kUnknownExpression;
1157 } 1161 }
1158 1162
1159 1163
1160 PreParser::Identifier PreParser::ParseIdentifier(bool* ok) { 1164 PreParser::Identifier PreParser::ParseIdentifier(bool* ok) {
1161 Expect(i::Token::IDENTIFIER, ok); 1165 if (!Check(i::Token::FUTURE_RESERVED_WORD)) {
1166 Expect(i::Token::IDENTIFIER, ok);
1167 }
1162 if (!*ok) return kUnknownIdentifier; 1168 if (!*ok) return kUnknownIdentifier;
1163 return GetIdentifierSymbol(); 1169 return GetIdentifierSymbol();
1164 } 1170 }
1165 1171
1166 1172
1167 PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) { 1173 PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) {
1168 i::Token::Value next = Next(); 1174 i::Token::Value next = Next();
1169 if (i::Token::IsKeyword(next)) { 1175 if (i::Token::IsKeyword(next)) {
1170 int pos = scanner_->location().beg_pos; 1176 int pos = scanner_->location().beg_pos;
1171 const char* keyword = i::Token::String(next); 1177 const char* keyword = i::Token::String(next);
1172 log_->LogAsciiSymbol(pos, i::Vector<const char>(keyword, 1178 log_->LogAsciiSymbol(pos, i::Vector<const char>(keyword,
1173 i::StrLength(keyword))); 1179 i::StrLength(keyword)));
1174 return kUnknownExpression; 1180 return kUnknownExpression;
1175 } 1181 }
1176 if (next == i::Token::IDENTIFIER) { 1182 if (next == i::Token::IDENTIFIER ||
1183 next == i::Token::FUTURE_RESERVED_WORD) {
1177 return GetIdentifierSymbol(); 1184 return GetIdentifierSymbol();
1178 } 1185 }
1179 *ok = false; 1186 *ok = false;
1180 return kUnknownIdentifier; 1187 return kUnknownIdentifier;
1181 } 1188 }
1182 1189
1183 1190
1184 // This function reads an identifier and determines whether or not it 1191 // This function reads an identifier and determines whether or not it
1185 // is 'get' or 'set'. The reason for not using ParseIdentifier and 1192 // is 'get' or 'set'.
1186 // checking on the output is that this involves heap allocation which
1187 // we can't do during preparsing.
1188 PreParser::Identifier PreParser::ParseIdentifierOrGetOrSet(bool* is_get, 1193 PreParser::Identifier PreParser::ParseIdentifierOrGetOrSet(bool* is_get,
1189 bool* is_set, 1194 bool* is_set,
1190 bool* ok) { 1195 bool* ok) {
1191 Expect(i::Token::IDENTIFIER, CHECK_OK); 1196 PreParser::Identifier result = ParseIdentifier(CHECK_OK);
1192 if (scanner_->is_literal_ascii() && scanner_->literal_length() == 3) { 1197 if (scanner_->is_literal_ascii() && scanner_->literal_length() == 3) {
1193 const char* token = scanner_->literal_ascii_string().start(); 1198 const char* token = scanner_->literal_ascii_string().start();
1194 *is_get = strncmp(token, "get", 3) == 0; 1199 *is_get = strncmp(token, "get", 3) == 0;
1195 *is_set = !*is_get && strncmp(token, "set", 3) == 0; 1200 *is_set = !*is_get && strncmp(token, "set", 3) == 0;
1196 } 1201 }
1197 return GetIdentifierSymbol(); 1202 return result;
1203 }
1204
1205 bool PreParser::peek_any_identifier() {
1206 i::Token::Value next = peek();
1207 return next == i::Token::IDENTIFIER ||
1208 next == i::Token::FUTURE_RESERVED_WORD;
1198 } 1209 }
1199 1210
1200 #undef CHECK_OK 1211 #undef CHECK_OK
1201 } } // v8::preparser 1212 } } // v8::preparser
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | src/prettyprinter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698