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