OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PARSING_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
7 | 7 |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/hashmap.h" | 10 #include "src/hashmap.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 allow_harmony_destructuring_assignment_(false), | 115 allow_harmony_destructuring_assignment_(false), |
116 allow_strong_mode_(false), | 116 allow_strong_mode_(false), |
117 allow_legacy_const_(true), | 117 allow_legacy_const_(true), |
118 allow_harmony_do_expressions_(false), | 118 allow_harmony_do_expressions_(false), |
119 allow_harmony_function_name_(false) {} | 119 allow_harmony_function_name_(false) {} |
120 | 120 |
121 #define ALLOW_ACCESSORS(name) \ | 121 #define ALLOW_ACCESSORS(name) \ |
122 bool allow_##name() const { return allow_##name##_; } \ | 122 bool allow_##name() const { return allow_##name##_; } \ |
123 void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 123 void set_allow_##name(bool allow) { allow_##name##_ = allow; } |
124 | 124 |
125 #define SCANNER_ACCESSORS(name) \ | |
126 bool allow_##name() const { return scanner_->allow_##name(); } \ | |
127 void set_allow_##name(bool allow) { \ | |
128 return scanner_->set_allow_##name(allow); \ | |
129 } | |
130 | |
125 ALLOW_ACCESSORS(lazy); | 131 ALLOW_ACCESSORS(lazy); |
126 ALLOW_ACCESSORS(natives); | 132 ALLOW_ACCESSORS(natives); |
127 ALLOW_ACCESSORS(harmony_sloppy); | 133 ALLOW_ACCESSORS(harmony_sloppy); |
128 ALLOW_ACCESSORS(harmony_sloppy_function); | 134 ALLOW_ACCESSORS(harmony_sloppy_function); |
129 ALLOW_ACCESSORS(harmony_sloppy_let); | 135 ALLOW_ACCESSORS(harmony_sloppy_let); |
130 ALLOW_ACCESSORS(harmony_default_parameters); | 136 ALLOW_ACCESSORS(harmony_default_parameters); |
131 ALLOW_ACCESSORS(harmony_destructuring_bind); | 137 ALLOW_ACCESSORS(harmony_destructuring_bind); |
132 ALLOW_ACCESSORS(harmony_destructuring_assignment); | 138 ALLOW_ACCESSORS(harmony_destructuring_assignment); |
133 ALLOW_ACCESSORS(strong_mode); | 139 ALLOW_ACCESSORS(strong_mode); |
134 ALLOW_ACCESSORS(legacy_const); | 140 ALLOW_ACCESSORS(legacy_const); |
135 ALLOW_ACCESSORS(harmony_do_expressions); | 141 ALLOW_ACCESSORS(harmony_do_expressions); |
136 ALLOW_ACCESSORS(harmony_function_name); | 142 ALLOW_ACCESSORS(harmony_function_name); |
143 SCANNER_ACCESSORS(harmony_exponentiation_operator); | |
137 #undef ALLOW_ACCESSORS | 144 #undef ALLOW_ACCESSORS |
138 | 145 |
139 uintptr_t stack_limit() const { return stack_limit_; } | 146 uintptr_t stack_limit() const { return stack_limit_; } |
140 | 147 |
141 protected: | 148 protected: |
142 enum AllowRestrictedIdentifiers { | 149 enum AllowRestrictedIdentifiers { |
143 kAllowRestrictedIdentifiers, | 150 kAllowRestrictedIdentifiers, |
144 kDontAllowRestrictedIdentifiers | 151 kDontAllowRestrictedIdentifiers |
145 }; | 152 }; |
146 | 153 |
(...skipping 1957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2104 fni_->Infer(); | 2111 fni_->Infer(); |
2105 } else { | 2112 } else { |
2106 fni_->RemoveLastFunction(); | 2113 fni_->RemoveLastFunction(); |
2107 } | 2114 } |
2108 } | 2115 } |
2109 | 2116 |
2110 if (op == Token::ASSIGN && allow_harmony_function_name()) { | 2117 if (op == Token::ASSIGN && allow_harmony_function_name()) { |
2111 Traits::SetFunctionNameFromIdentifierRef(right, expression); | 2118 Traits::SetFunctionNameFromIdentifierRef(right, expression); |
2112 } | 2119 } |
2113 | 2120 |
2121 if (op == Token::ASSIGN_EXP) { | |
2122 DCHECK(!is_destructuring_assignment); | |
2123 return Traits::RewriteAssignExponentiation(expression, right, pos); | |
2124 } | |
2125 | |
2114 ExpressionT result = factory()->NewAssignment(op, expression, right, pos); | 2126 ExpressionT result = factory()->NewAssignment(op, expression, right, pos); |
2115 | 2127 |
2116 if (is_destructuring_assignment) { | 2128 if (is_destructuring_assignment) { |
2117 result = factory()->NewRewritableAssignmentExpression(result); | 2129 result = factory()->NewRewritableAssignmentExpression(result); |
2118 Traits::QueueDestructuringAssignmentForRewriting(result); | 2130 Traits::QueueDestructuringAssignmentForRewriting(result); |
2119 } | 2131 } |
2120 | 2132 |
2121 return result; | 2133 return result; |
2122 } | 2134 } |
2123 | 2135 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2204 } | 2216 } |
2205 | 2217 |
2206 | 2218 |
2207 // Precedence >= 4 | 2219 // Precedence >= 4 |
2208 template <class Traits> | 2220 template <class Traits> |
2209 typename ParserBase<Traits>::ExpressionT | 2221 typename ParserBase<Traits>::ExpressionT |
2210 ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, | 2222 ParserBase<Traits>::ParseBinaryExpression(int prec, bool accept_IN, |
2211 ExpressionClassifier* classifier, | 2223 ExpressionClassifier* classifier, |
2212 bool* ok) { | 2224 bool* ok) { |
2213 DCHECK(prec >= 4); | 2225 DCHECK(prec >= 4); |
2226 bool is_unary_op = Token::IsUnaryOp(peek()); | |
2214 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); | 2227 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); |
2228 | |
2229 if (peek() == Token::EXP && is_unary_op) { | |
2230 ReportUnexpectedTokenAt(scanner()->peek_location(), Token::EXP); | |
2231 *ok = false; | |
2232 return this->EmptyExpression(); | |
2233 } | |
2234 | |
2215 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { | 2235 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { |
2216 // prec1 >= 4 | 2236 // prec1 >= 4 |
2217 while (Precedence(peek(), accept_IN) == prec1) { | 2237 while (Precedence(peek(), accept_IN) == prec1) { |
2218 x = Traits::RewriteNonPattern(x, classifier, CHECK_OK); | 2238 x = Traits::RewriteNonPattern(x, classifier, CHECK_OK); |
2219 BindingPatternUnexpectedToken(classifier); | 2239 BindingPatternUnexpectedToken(classifier); |
2220 ArrowFormalParametersUnexpectedToken(classifier); | 2240 ArrowFormalParametersUnexpectedToken(classifier); |
2221 Token::Value op = Next(); | 2241 Token::Value op = Next(); |
2222 Scanner::Location op_location = scanner()->location(); | 2242 Scanner::Location op_location = scanner()->location(); |
2223 int pos = position(); | 2243 int pos = position(); |
2244 // TODO(caitp): cleanup right associativity of exponentiation operator | |
2245 // somehow | |
Dan Ehrenberg
2016/02/11 08:16:50
Seems like a good thing to do before submitting th
caitp (gmail)
2016/02/11 12:57:24
Yes it does-- the model for existing right associa
caitp (gmail)
2016/02/11 15:32:34
I've simplified the unary-op SyntaxError code and
| |
2224 ExpressionT y = | 2246 ExpressionT y = |
2225 ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK); | 2247 ParseBinaryExpression(op == Token::EXP ? prec1 : prec1 + 1, accept_IN, |
2248 classifier, CHECK_OK); | |
2226 y = Traits::RewriteNonPattern(y, classifier, CHECK_OK); | 2249 y = Traits::RewriteNonPattern(y, classifier, CHECK_OK); |
2227 | 2250 |
2228 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, | 2251 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, |
2229 factory())) { | 2252 factory())) { |
2230 continue; | 2253 continue; |
2231 } | 2254 } |
2232 | 2255 |
2233 // For now we distinguish between comparisons and other binary | 2256 // For now we distinguish between comparisons and other binary |
2234 // operations. (We could combine the two and get rid of this | 2257 // operations. (We could combine the two and get rid of this |
2235 // code and AST node eventually.) | 2258 // code and AST node eventually.) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2301 } | 2324 } |
2302 } | 2325 } |
2303 | 2326 |
2304 // Allow Traits do rewrite the expression. | 2327 // Allow Traits do rewrite the expression. |
2305 return this->BuildUnaryExpression(expression, op, pos, factory()); | 2328 return this->BuildUnaryExpression(expression, op, pos, factory()); |
2306 } else if (Token::IsCountOp(op)) { | 2329 } else if (Token::IsCountOp(op)) { |
2307 BindingPatternUnexpectedToken(classifier); | 2330 BindingPatternUnexpectedToken(classifier); |
2308 ArrowFormalParametersUnexpectedToken(classifier); | 2331 ArrowFormalParametersUnexpectedToken(classifier); |
2309 op = Next(); | 2332 op = Next(); |
2310 int beg_pos = peek_position(); | 2333 int beg_pos = peek_position(); |
2311 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); | 2334 ExpressionT expression = |
2335 this->ParseLeftHandSideExpression(classifier, CHECK_OK); | |
2312 expression = this->CheckAndRewriteReferenceExpression( | 2336 expression = this->CheckAndRewriteReferenceExpression( |
2313 expression, beg_pos, scanner()->location().end_pos, | 2337 expression, beg_pos, scanner()->location().end_pos, |
2314 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); | 2338 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); |
2315 this->MarkExpressionAsAssigned(expression); | 2339 this->MarkExpressionAsAssigned(expression); |
2316 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); | 2340 expression = Traits::RewriteNonPattern(expression, classifier, CHECK_OK); |
2317 | 2341 |
2318 return factory()->NewCountOperation(op, | 2342 return factory()->NewCountOperation(op, true /* prefix */, expression, |
2319 true /* prefix */, | |
2320 expression, | |
2321 position()); | 2343 position()); |
2322 | 2344 |
2323 } else { | 2345 } else { |
2324 return this->ParsePostfixExpression(classifier, ok); | 2346 return this->ParsePostfixExpression(classifier, ok); |
2325 } | 2347 } |
2326 } | 2348 } |
2327 | 2349 |
2328 | 2350 |
2329 template <class Traits> | 2351 template <class Traits> |
2330 typename ParserBase<Traits>::ExpressionT | 2352 typename ParserBase<Traits>::ExpressionT |
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3374 return; | 3396 return; |
3375 } | 3397 } |
3376 has_seen_constructor_ = true; | 3398 has_seen_constructor_ = true; |
3377 return; | 3399 return; |
3378 } | 3400 } |
3379 } | 3401 } |
3380 } // namespace internal | 3402 } // namespace internal |
3381 } // namespace v8 | 3403 } // namespace v8 |
3382 | 3404 |
3383 #endif // V8_PARSING_PARSER_BASE_H | 3405 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |