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

Side by Side Diff: src/parsing/parser-base.h

Issue 1678303002: [es7] implement exponentiation operator proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 4 years, 9 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
OLDNEW
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 allow_strong_mode_(false), 117 allow_strong_mode_(false),
118 allow_legacy_const_(true), 118 allow_legacy_const_(true),
119 allow_harmony_do_expressions_(false), 119 allow_harmony_do_expressions_(false),
120 allow_harmony_function_name_(false), 120 allow_harmony_function_name_(false),
121 allow_harmony_function_sent_(false) {} 121 allow_harmony_function_sent_(false) {}
122 122
123 #define ALLOW_ACCESSORS(name) \ 123 #define ALLOW_ACCESSORS(name) \
124 bool allow_##name() const { return allow_##name##_; } \ 124 bool allow_##name() const { return allow_##name##_; } \
125 void set_allow_##name(bool allow) { allow_##name##_ = allow; } 125 void set_allow_##name(bool allow) { allow_##name##_ = allow; }
126 126
127 #define SCANNER_ACCESSORS(name) \
128 bool allow_##name() const { return scanner_->allow_##name(); } \
129 void set_allow_##name(bool allow) { \
130 return scanner_->set_allow_##name(allow); \
131 }
132
127 ALLOW_ACCESSORS(lazy); 133 ALLOW_ACCESSORS(lazy);
128 ALLOW_ACCESSORS(natives); 134 ALLOW_ACCESSORS(natives);
129 ALLOW_ACCESSORS(harmony_sloppy); 135 ALLOW_ACCESSORS(harmony_sloppy);
130 ALLOW_ACCESSORS(harmony_sloppy_function); 136 ALLOW_ACCESSORS(harmony_sloppy_function);
131 ALLOW_ACCESSORS(harmony_sloppy_let); 137 ALLOW_ACCESSORS(harmony_sloppy_let);
132 ALLOW_ACCESSORS(harmony_default_parameters); 138 ALLOW_ACCESSORS(harmony_default_parameters);
133 ALLOW_ACCESSORS(harmony_destructuring_bind); 139 ALLOW_ACCESSORS(harmony_destructuring_bind);
134 ALLOW_ACCESSORS(harmony_destructuring_assignment); 140 ALLOW_ACCESSORS(harmony_destructuring_assignment);
135 ALLOW_ACCESSORS(strong_mode); 141 ALLOW_ACCESSORS(strong_mode);
136 ALLOW_ACCESSORS(legacy_const); 142 ALLOW_ACCESSORS(legacy_const);
137 ALLOW_ACCESSORS(harmony_do_expressions); 143 ALLOW_ACCESSORS(harmony_do_expressions);
138 ALLOW_ACCESSORS(harmony_function_name); 144 ALLOW_ACCESSORS(harmony_function_name);
139 ALLOW_ACCESSORS(harmony_function_sent); 145 ALLOW_ACCESSORS(harmony_function_sent);
146 SCANNER_ACCESSORS(harmony_exponentiation_operator);
140 #undef ALLOW_ACCESSORS 147 #undef ALLOW_ACCESSORS
141 148
142 uintptr_t stack_limit() const { return stack_limit_; } 149 uintptr_t stack_limit() const { return stack_limit_; }
143 150
144 protected: 151 protected:
145 enum AllowRestrictedIdentifiers { 152 enum AllowRestrictedIdentifiers {
146 kAllowRestrictedIdentifiers, 153 kAllowRestrictedIdentifiers,
147 kDontAllowRestrictedIdentifiers 154 kDontAllowRestrictedIdentifiers
148 }; 155 };
149 156
(...skipping 1951 matching lines...) Expand 10 before | Expand all | Expand 10 after
2101 fni_->Infer(); 2108 fni_->Infer();
2102 } else { 2109 } else {
2103 fni_->RemoveLastFunction(); 2110 fni_->RemoveLastFunction();
2104 } 2111 }
2105 } 2112 }
2106 2113
2107 if (op == Token::ASSIGN && allow_harmony_function_name()) { 2114 if (op == Token::ASSIGN && allow_harmony_function_name()) {
2108 Traits::SetFunctionNameFromIdentifierRef(right, expression); 2115 Traits::SetFunctionNameFromIdentifierRef(right, expression);
2109 } 2116 }
2110 2117
2118 if (op == Token::ASSIGN_EXP) {
2119 DCHECK(!is_destructuring_assignment);
2120 return Traits::RewriteExponentiation(expression, right, op, pos);
2121 }
2122
2111 ExpressionT result = factory()->NewAssignment(op, expression, right, pos); 2123 ExpressionT result = factory()->NewAssignment(op, expression, right, pos);
2112 2124
2113 if (is_destructuring_assignment) { 2125 if (is_destructuring_assignment) {
2114 result = factory()->NewRewritableExpression(result); 2126 result = factory()->NewRewritableExpression(result);
2115 Traits::QueueDestructuringAssignmentForRewriting(result); 2127 Traits::QueueDestructuringAssignmentForRewriting(result);
2116 } 2128 }
2117 2129
2118 return result; 2130 return result;
2119 } 2131 }
2120 2132
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2210 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); 2222 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK);
2211 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { 2223 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) {
2212 // prec1 >= 4 2224 // prec1 >= 4
2213 while (Precedence(peek(), accept_IN) == prec1) { 2225 while (Precedence(peek(), accept_IN) == prec1) {
2214 Traits::RewriteNonPattern(classifier, CHECK_OK); 2226 Traits::RewriteNonPattern(classifier, CHECK_OK);
2215 BindingPatternUnexpectedToken(classifier); 2227 BindingPatternUnexpectedToken(classifier);
2216 ArrowFormalParametersUnexpectedToken(classifier); 2228 ArrowFormalParametersUnexpectedToken(classifier);
2217 Token::Value op = Next(); 2229 Token::Value op = Next();
2218 Scanner::Location op_location = scanner()->location(); 2230 Scanner::Location op_location = scanner()->location();
2219 int pos = position(); 2231 int pos = position();
2232
2233 const bool is_right_associative = op == Token::EXP;
2234 const int next_prec = is_right_associative ? prec1 : prec1 + 1;
2220 ExpressionT y = 2235 ExpressionT y =
2221 ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK); 2236 ParseBinaryExpression(next_prec, accept_IN, classifier, CHECK_OK);
2222 Traits::RewriteNonPattern(classifier, CHECK_OK); 2237 Traits::RewriteNonPattern(classifier, CHECK_OK);
2223 2238
2224 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, 2239 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos,
2225 factory())) { 2240 factory())) {
2226 continue; 2241 continue;
2227 } 2242 }
2228 2243
2229 // For now we distinguish between comparisons and other binary 2244 // For now we distinguish between comparisons and other binary
2230 // operations. (We could combine the two and get rid of this 2245 // operations. (We could combine the two and get rid of this
2231 // code and AST node eventually.) 2246 // code and AST node eventually.)
(...skipping 11 matching lines...) Expand all
2243 return this->EmptyExpression(); 2258 return this->EmptyExpression();
2244 } else if (FLAG_harmony_instanceof && cmp == Token::INSTANCEOF) { 2259 } else if (FLAG_harmony_instanceof && cmp == Token::INSTANCEOF) {
2245 x = Traits::RewriteInstanceof(x, y, pos); 2260 x = Traits::RewriteInstanceof(x, y, pos);
2246 } else { 2261 } else {
2247 x = factory()->NewCompareOperation(cmp, x, y, pos); 2262 x = factory()->NewCompareOperation(cmp, x, y, pos);
2248 if (cmp != op) { 2263 if (cmp != op) {
2249 // The comparison was negated - add a NOT. 2264 // The comparison was negated - add a NOT.
2250 x = factory()->NewUnaryOperation(Token::NOT, x, pos); 2265 x = factory()->NewUnaryOperation(Token::NOT, x, pos);
2251 } 2266 }
2252 } 2267 }
2268
2269 } else if (op == Token::EXP) {
2270 x = Traits::RewriteExponentiation(x, y, op, pos);
2253 } else { 2271 } else {
2254 // We have a "normal" binary operation. 2272 // We have a "normal" binary operation.
2255 x = factory()->NewBinaryOperation(op, x, y, pos); 2273 x = factory()->NewBinaryOperation(op, x, y, pos);
2256 } 2274 }
2257 } 2275 }
2258 } 2276 }
2259 return x; 2277 return x;
2260 } 2278 }
2261 2279
2262 2280
(...skipping 29 matching lines...) Expand all
2292 *ok = false; 2310 *ok = false;
2293 return this->EmptyExpression(); 2311 return this->EmptyExpression();
2294 } else if (this->IsIdentifier(expression)) { 2312 } else if (this->IsIdentifier(expression)) {
2295 // "delete identifier" is a syntax error in strict mode. 2313 // "delete identifier" is a syntax error in strict mode.
2296 ReportMessage(MessageTemplate::kStrictDelete); 2314 ReportMessage(MessageTemplate::kStrictDelete);
2297 *ok = false; 2315 *ok = false;
2298 return this->EmptyExpression(); 2316 return this->EmptyExpression();
2299 } 2317 }
2300 } 2318 }
2301 2319
2320 if (peek() == Token::EXP) {
2321 ReportUnexpectedToken(Next());
2322 *ok = false;
2323 return this->EmptyExpression();
2324 }
2325
2302 // Allow Traits do rewrite the expression. 2326 // Allow Traits do rewrite the expression.
2303 return this->BuildUnaryExpression(expression, op, pos, factory()); 2327 return this->BuildUnaryExpression(expression, op, pos, factory());
2304 } else if (Token::IsCountOp(op)) { 2328 } else if (Token::IsCountOp(op)) {
2305 BindingPatternUnexpectedToken(classifier); 2329 BindingPatternUnexpectedToken(classifier);
2306 ArrowFormalParametersUnexpectedToken(classifier); 2330 ArrowFormalParametersUnexpectedToken(classifier);
2307 op = Next(); 2331 op = Next();
2308 int beg_pos = peek_position(); 2332 int beg_pos = peek_position();
2309 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); 2333 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK);
2310 expression = this->CheckAndRewriteReferenceExpression( 2334 expression = this->CheckAndRewriteReferenceExpression(
2311 expression, beg_pos, scanner()->location().end_pos, 2335 expression, beg_pos, scanner()->location().end_pos,
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after
3372 has_seen_constructor_ = true; 3396 has_seen_constructor_ = true;
3373 return; 3397 return;
3374 } 3398 }
3375 } 3399 }
3376 3400
3377 3401
3378 } // namespace internal 3402 } // namespace internal
3379 } // namespace v8 3403 } // namespace v8
3380 3404
3381 #endif // V8_PARSING_PARSER_BASE_H 3405 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« src/parsing/parser.cc ('K') | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698