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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 bool is_generator, | 135 bool is_generator, |
136 int function_token_position, | 136 int function_token_position, |
137 FunctionLiteral::FunctionType type, | 137 FunctionLiteral::FunctionType type, |
138 bool* ok) { | 138 bool* ok) { |
139 return pre_parser_->ParseFunctionLiteral( | 139 return pre_parser_->ParseFunctionLiteral( |
140 name, function_name_location, name_is_strict_reserved, is_generator, | 140 name, function_name_location, name_is_strict_reserved, is_generator, |
141 function_token_position, type, ok); | 141 function_token_position, type, ok); |
142 } | 142 } |
143 | 143 |
144 | 144 |
145 PreParserExpression PreParserTraits::ParseConditionalExpression(bool accept_IN, | 145 PreParserExpression PreParserTraits::ParseBinaryExpression(int prec, |
146 bool* ok) { | 146 bool accept_IN, |
147 return pre_parser_->ParseConditionalExpression(accept_IN, ok); | 147 bool* ok) { |
| 148 return pre_parser_->ParseBinaryExpression(prec, accept_IN, ok); |
148 } | 149 } |
149 | 150 |
150 | 151 |
151 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 152 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
152 StrictMode strict_mode, bool is_generator, ParserRecorder* log) { | 153 StrictMode strict_mode, bool is_generator, ParserRecorder* log) { |
153 log_ = log; | 154 log_ = log; |
154 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 155 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
155 PreParserScope top_scope(scope_, GLOBAL_SCOPE); | 156 PreParserScope top_scope(scope_, GLOBAL_SCOPE); |
156 FunctionState top_state(&function_state_, &scope_, &top_scope); | 157 FunctionState top_state(&function_state_, &scope_, &top_scope); |
157 scope_->SetStrictMode(strict_mode); | 158 scope_->SetStrictMode(strict_mode); |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 | 833 |
833 | 834 |
834 #undef CHECK_OK | 835 #undef CHECK_OK |
835 #define CHECK_OK ok); \ | 836 #define CHECK_OK ok); \ |
836 if (!*ok) return Expression::Default(); \ | 837 if (!*ok) return Expression::Default(); \ |
837 ((void)0 | 838 ((void)0 |
838 #define DUMMY ) // to make indentation work | 839 #define DUMMY ) // to make indentation work |
839 #undef DUMMY | 840 #undef DUMMY |
840 | 841 |
841 | 842 |
842 // Precedence = 3 | |
843 PreParser::Expression PreParser::ParseConditionalExpression(bool accept_IN, | |
844 bool* ok) { | |
845 // ConditionalExpression :: | |
846 // LogicalOrExpression | |
847 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression | |
848 | |
849 // We start using the binary expression parser for prec >= 4 only! | |
850 Expression expression = ParseBinaryExpression(4, accept_IN, CHECK_OK); | |
851 if (peek() != Token::CONDITIONAL) return expression; | |
852 Consume(Token::CONDITIONAL); | |
853 // In parsing the first assignment expression in conditional | |
854 // expressions we always accept the 'in' keyword; see ECMA-262, | |
855 // section 11.12, page 58. | |
856 ParseAssignmentExpression(true, CHECK_OK); | |
857 Expect(Token::COLON, CHECK_OK); | |
858 ParseAssignmentExpression(accept_IN, CHECK_OK); | |
859 return Expression::Default(); | |
860 } | |
861 | |
862 | |
863 // Precedence >= 4 | 843 // Precedence >= 4 |
864 PreParser::Expression PreParser::ParseBinaryExpression(int prec, | 844 PreParser::Expression PreParser::ParseBinaryExpression(int prec, |
865 bool accept_IN, | 845 bool accept_IN, |
866 bool* ok) { | 846 bool* ok) { |
867 Expression result = ParseUnaryExpression(CHECK_OK); | 847 Expression result = ParseUnaryExpression(CHECK_OK); |
868 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { | 848 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { |
869 // prec1 >= 4 | 849 // prec1 >= 4 |
870 while (Precedence(peek(), accept_IN) == prec1) { | 850 while (Precedence(peek(), accept_IN) == prec1) { |
871 Next(); | 851 Next(); |
872 ParseBinaryExpression(prec1 + 1, accept_IN, CHECK_OK); | 852 ParseBinaryExpression(prec1 + 1, accept_IN, CHECK_OK); |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 | 1192 |
1213 | 1193 |
1214 void PreParser::LogSymbol() { | 1194 void PreParser::LogSymbol() { |
1215 if (log_->ShouldLogSymbols()) { | 1195 if (log_->ShouldLogSymbols()) { |
1216 scanner()->LogSymbol(log_, position()); | 1196 scanner()->LogSymbol(log_, position()); |
1217 } | 1197 } |
1218 } | 1198 } |
1219 | 1199 |
1220 | 1200 |
1221 } } // v8::internal | 1201 } } // v8::internal |
OLD | NEW |