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

Side by Side Diff: src/preparser.cc

Issue 164183006: Revert "(Pre)Parser: Simplify NewExpression handling." (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 989 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 return Expression::Default(); 1000 return Expression::Default();
1001 } 1001 }
1002 return expression; 1002 return expression;
1003 } 1003 }
1004 1004
1005 1005
1006 PreParser::Expression PreParser::ParseLeftHandSideExpression(bool* ok) { 1006 PreParser::Expression PreParser::ParseLeftHandSideExpression(bool* ok) {
1007 // LeftHandSideExpression :: 1007 // LeftHandSideExpression ::
1008 // (NewExpression | MemberExpression) ... 1008 // (NewExpression | MemberExpression) ...
1009 1009
1010 Expression result = ParseMemberWithNewPrefixesExpression(CHECK_OK); 1010 Expression result = Expression::Default();
1011 if (peek() == Token::NEW) {
1012 result = ParseNewExpression(CHECK_OK);
1013 } else {
1014 result = ParseMemberExpression(CHECK_OK);
1015 }
1011 1016
1012 while (true) { 1017 while (true) {
1013 switch (peek()) { 1018 switch (peek()) {
1014 case Token::LBRACK: { 1019 case Token::LBRACK: {
1015 Consume(Token::LBRACK); 1020 Consume(Token::LBRACK);
1016 ParseExpression(true, CHECK_OK); 1021 ParseExpression(true, CHECK_OK);
1017 Expect(Token::RBRACK, CHECK_OK); 1022 Expect(Token::RBRACK, CHECK_OK);
1018 if (result.IsThis()) { 1023 if (result.IsThis()) {
1019 result = Expression::ThisProperty(); 1024 result = Expression::ThisProperty();
1020 } else { 1025 } else {
(...skipping 19 matching lines...) Expand all
1040 break; 1045 break;
1041 } 1046 }
1042 1047
1043 default: 1048 default:
1044 return result; 1049 return result;
1045 } 1050 }
1046 } 1051 }
1047 } 1052 }
1048 1053
1049 1054
1055 PreParser::Expression PreParser::ParseNewExpression(bool* ok) {
1056 // NewExpression ::
1057 // ('new')+ MemberExpression
1058
1059 // The grammar for new expressions is pretty warped. The keyword
1060 // 'new' can either be a part of the new expression (where it isn't
1061 // followed by an argument list) or a part of the member expression,
1062 // where it must be followed by an argument list. To accommodate
1063 // this, we parse the 'new' keywords greedily and keep track of how
1064 // many we have parsed. This information is then passed on to the
1065 // member expression parser, which is only allowed to match argument
1066 // lists as long as it has 'new' prefixes left
1067 unsigned new_count = 0;
1068 do {
1069 Consume(Token::NEW);
1070 new_count++;
1071 } while (peek() == Token::NEW);
1072
1073 return ParseMemberWithNewPrefixesExpression(new_count, ok);
1074 }
1075
1076
1077 PreParser::Expression PreParser::ParseMemberExpression(bool* ok) {
1078 return ParseMemberWithNewPrefixesExpression(0, ok);
1079 }
1080
1081
1050 PreParser::Expression PreParser::ParseMemberWithNewPrefixesExpression( 1082 PreParser::Expression PreParser::ParseMemberWithNewPrefixesExpression(
1051 bool* ok) { 1083 unsigned new_count, bool* ok) {
1052 // NewExpression ::
1053 // ('new')+ MemberExpression
1054
1055 // See Parser::ParseNewExpression.
1056
1057 if (peek() == Token::NEW) {
1058 Consume(Token::NEW);
1059 ParseMemberWithNewPrefixesExpression(CHECK_OK);
1060 if (peek() == Token::LPAREN) {
1061 // NewExpression with arguments.
1062 ParseArguments(CHECK_OK);
1063 }
1064 return Expression::Default();
1065 }
1066 // No 'new' keyword.
1067 return ParseMemberExpression(ok);
1068 }
1069
1070
1071 PreParser::Expression PreParser::ParseMemberExpression(bool* ok) {
1072 // MemberExpression :: 1084 // MemberExpression ::
1073 // (PrimaryExpression | FunctionLiteral) 1085 // (PrimaryExpression | FunctionLiteral)
1074 // ('[' Expression ']' | '.' Identifier | Arguments)* 1086 // ('[' Expression ']' | '.' Identifier | Arguments)*
1075 1087
1076 // Parse the initial primary or function expression. 1088 // Parse the initial primary or function expression.
1077 Expression result = Expression::Default(); 1089 Expression result = Expression::Default();
1078 if (peek() == Token::FUNCTION) { 1090 if (peek() == Token::FUNCTION) {
1079 Consume(Token::FUNCTION); 1091 Consume(Token::FUNCTION);
1080 1092
1081 bool is_generator = allow_generators() && Check(Token::MUL); 1093 bool is_generator = allow_generators() && Check(Token::MUL);
(...skipping 30 matching lines...) Expand all
1112 case Token::PERIOD: { 1124 case Token::PERIOD: {
1113 Consume(Token::PERIOD); 1125 Consume(Token::PERIOD);
1114 ParseIdentifierName(CHECK_OK); 1126 ParseIdentifierName(CHECK_OK);
1115 if (result.IsThis()) { 1127 if (result.IsThis()) {
1116 result = Expression::ThisProperty(); 1128 result = Expression::ThisProperty();
1117 } else { 1129 } else {
1118 result = Expression::Default(); 1130 result = Expression::Default();
1119 } 1131 }
1120 break; 1132 break;
1121 } 1133 }
1134 case Token::LPAREN: {
1135 if (new_count == 0) return result;
1136 // Consume one of the new prefixes (already parsed).
1137 ParseArguments(CHECK_OK);
1138 new_count--;
1139 result = Expression::Default();
1140 break;
1141 }
1122 default: 1142 default:
1123 return result; 1143 return result;
1124 } 1144 }
1125 } 1145 }
1126 } 1146 }
1127 1147
1128 1148
1129 PreParser::Expression PreParser::ParseArrayLiteral(bool* ok) { 1149 PreParser::Expression PreParser::ParseArrayLiteral(bool* ok) {
1130 // ArrayLiteral :: 1150 // ArrayLiteral ::
1131 // '[' Expression? (',' Expression?)* ']' 1151 // '[' Expression? (',' Expression?)* ']'
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 int identifier_pos = position(); 1420 int identifier_pos = position();
1401 if (scanner()->is_literal_ascii()) { 1421 if (scanner()->is_literal_ascii()) {
1402 log_->LogAsciiSymbol(identifier_pos, scanner()->literal_ascii_string()); 1422 log_->LogAsciiSymbol(identifier_pos, scanner()->literal_ascii_string());
1403 } else { 1423 } else {
1404 log_->LogUtf16Symbol(identifier_pos, scanner()->literal_utf16_string()); 1424 log_->LogUtf16Symbol(identifier_pos, scanner()->literal_utf16_string());
1405 } 1425 }
1406 } 1426 }
1407 1427
1408 1428
1409 } } // v8::internal 1429 } } // 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