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

Side by Side Diff: src/preparser.cc

Issue 156673002: Revert "Unify paren handling in Parser and PreParser." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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') | test/cctest/test-parsing.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 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 return ParseStatement(ok); 161 return ParseStatement(ok);
162 } 162 }
163 } 163 }
164 164
165 165
166 PreParser::SourceElements PreParser::ParseSourceElements(int end_token, 166 PreParser::SourceElements PreParser::ParseSourceElements(int end_token,
167 bool* ok) { 167 bool* ok) {
168 // SourceElements :: 168 // SourceElements ::
169 // (Statement)* <end_token> 169 // (Statement)* <end_token>
170 170
171 bool directive_prologue = true; 171 bool allow_directive_prologue = true;
172 while (peek() != end_token) { 172 while (peek() != end_token) {
173 if (directive_prologue && peek() != Token::STRING) {
174 directive_prologue = false;
175 }
176 Statement statement = ParseSourceElement(CHECK_OK); 173 Statement statement = ParseSourceElement(CHECK_OK);
177 if (directive_prologue) { 174 if (allow_directive_prologue) {
178 if (statement.IsUseStrictLiteral()) { 175 if (statement.IsUseStrictLiteral()) {
179 set_language_mode(allow_harmony_scoping() ? 176 set_language_mode(allow_harmony_scoping() ?
180 EXTENDED_MODE : STRICT_MODE); 177 EXTENDED_MODE : STRICT_MODE);
181 } else if (!statement.IsStringLiteral()) { 178 } else if (!statement.IsStringLiteral()) {
182 directive_prologue = false; 179 allow_directive_prologue = false;
183 } 180 }
184 } 181 }
185 } 182 }
186 return kUnknownSourceElements; 183 return kUnknownSourceElements;
187 } 184 }
188 185
189 186
190 #undef CHECK_OK 187 #undef CHECK_OK
191 #define CHECK_OK ok); \ 188 #define CHECK_OK ok); \
192 if (!*ok) return Statement::Default(); \ 189 if (!*ok) return Statement::Default(); \
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 if (num_decl != NULL) *num_decl = nvars; 461 if (num_decl != NULL) *num_decl = nvars;
465 return Statement::Default(); 462 return Statement::Default();
466 } 463 }
467 464
468 465
469 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { 466 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) {
470 // ExpressionStatement | LabelledStatement :: 467 // ExpressionStatement | LabelledStatement ::
471 // Expression ';' 468 // Expression ';'
472 // Identifier ':' Statement 469 // Identifier ':' Statement
473 470
474 bool starts_with_identifier = peek_any_identifier();
475 Expression expr = ParseExpression(true, CHECK_OK); 471 Expression expr = ParseExpression(true, CHECK_OK);
476 // Even if the expression starts with an identifier, it is not necessarily an 472 if (expr.IsRawIdentifier()) {
477 // identifier. For example, "foo + bar" starts with an identifier but is not
478 // an identifier.
479 if (peek() == Token::COLON && starts_with_identifier && expr.IsIdentifier()) {
480 // Expression is a single identifier, and not, e.g., a parenthesized
481 // identifier.
482 ASSERT(!expr.AsIdentifier().IsFutureReserved()); 473 ASSERT(!expr.AsIdentifier().IsFutureReserved());
483 ASSERT(is_classic_mode() || 474 ASSERT(is_classic_mode() ||
484 (!expr.AsIdentifier().IsFutureStrictReserved() && 475 (!expr.AsIdentifier().IsFutureStrictReserved() &&
485 !expr.AsIdentifier().IsYield())); 476 !expr.AsIdentifier().IsYield()));
486 Consume(Token::COLON); 477 if (peek() == Token::COLON) {
487 return ParseStatement(ok); 478 Consume(Token::COLON);
479 return ParseStatement(ok);
480 }
488 // Preparsing is disabled for extensions (because the extension details 481 // Preparsing is disabled for extensions (because the extension details
489 // aren't passed to lazily compiled functions), so we don't 482 // aren't passed to lazily compiled functions), so we don't
490 // accept "native function" in the preparser. 483 // accept "native function" in the preparser.
491 } 484 }
492 // Parsed expression statement. 485 // Parsed expression statement.
493 ExpectSemicolon(CHECK_OK); 486 ExpectSemicolon(CHECK_OK);
494 return Statement::ExpressionStatement(expr); 487 return Statement::ExpressionStatement(expr);
495 } 488 }
496 489
497 490
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 1163
1171 case Token::LBRACE: 1164 case Token::LBRACE:
1172 result = ParseObjectLiteral(CHECK_OK); 1165 result = ParseObjectLiteral(CHECK_OK);
1173 break; 1166 break;
1174 1167
1175 case Token::LPAREN: 1168 case Token::LPAREN:
1176 Consume(Token::LPAREN); 1169 Consume(Token::LPAREN);
1177 parenthesized_function_ = (peek() == Token::FUNCTION); 1170 parenthesized_function_ = (peek() == Token::FUNCTION);
1178 result = ParseExpression(true, CHECK_OK); 1171 result = ParseExpression(true, CHECK_OK);
1179 Expect(Token::RPAREN, CHECK_OK); 1172 Expect(Token::RPAREN, CHECK_OK);
1173 result = result.Parenthesize();
1180 break; 1174 break;
1181 1175
1182 case Token::MOD: 1176 case Token::MOD:
1183 result = ParseV8Intrinsic(CHECK_OK); 1177 result = ParseV8Intrinsic(CHECK_OK);
1184 break; 1178 break;
1185 1179
1186 default: { 1180 default: {
1187 Token::Value next = Next(); 1181 Token::Value next = Next();
1188 ReportUnexpectedToken(next); 1182 ReportUnexpectedToken(next);
1189 *ok = false; 1183 *ok = false;
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 ASSERT(IsAccessorAccessorConflict(old_type, type)); 1625 ASSERT(IsAccessorAccessorConflict(old_type, type));
1632 // Both accessors of the same type. 1626 // Both accessors of the same type.
1633 parser()->ReportMessageAt(scanner()->location(), 1627 parser()->ReportMessageAt(scanner()->location(),
1634 "accessor_get_set"); 1628 "accessor_get_set");
1635 } 1629 }
1636 *ok = false; 1630 *ok = false;
1637 } 1631 }
1638 } 1632 }
1639 1633
1640 } } // v8::internal 1634 } } // v8::internal
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698