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

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

Issue 1914423002: [es8] Report proper syntax error for tail call expressions in for-in and for-of bodies. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@tco-fix
Patch Set: Created 4 years, 7 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 }; 191 };
192 192
193 struct TailCallExpression { 193 struct TailCallExpression {
194 TailCallExpression(ExpressionT expression, int pos) 194 TailCallExpression(ExpressionT expression, int pos)
195 : expression(expression), pos(pos) {} 195 : expression(expression), pos(pos) {}
196 196
197 ExpressionT expression; 197 ExpressionT expression;
198 int pos; 198 int pos;
199 }; 199 };
200 200
201 // Defines whether tail call expressions are allowed or not.
202 enum class ReturnExprContext {
203 // Tail call expressions are allowed.
204 kNormal,
205 // Tail call expressions are not allowed.
206 kInsideTryBlock,
207 kInsideForInOfBody,
208 };
209
201 class FunctionState BASE_EMBEDDED { 210 class FunctionState BASE_EMBEDDED {
202 public: 211 public:
203 FunctionState(FunctionState** function_state_stack, Scope** scope_stack, 212 FunctionState(FunctionState** function_state_stack, Scope** scope_stack,
204 Scope* scope, FunctionKind kind, 213 Scope* scope, FunctionKind kind,
205 typename Traits::Type::Factory* factory); 214 typename Traits::Type::Factory* factory);
206 ~FunctionState(); 215 ~FunctionState();
207 216
208 int NextMaterializedLiteralIndex() { 217 int NextMaterializedLiteralIndex() {
209 return next_materialized_literal_index_++; 218 return next_materialized_literal_index_++;
210 } 219 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 261
253 const List<DestructuringAssignment>& destructuring_assignments_to_rewrite() 262 const List<DestructuringAssignment>& destructuring_assignments_to_rewrite()
254 const { 263 const {
255 return destructuring_assignments_to_rewrite_; 264 return destructuring_assignments_to_rewrite_;
256 } 265 }
257 266
258 List<TailCallExpression>& expressions_in_tail_position() { 267 List<TailCallExpression>& expressions_in_tail_position() {
259 return expressions_in_tail_position_; 268 return expressions_in_tail_position_;
260 } 269 }
261 void AddExpressionInTailPosition(ExpressionT expression, int pos) { 270 void AddExpressionInTailPosition(ExpressionT expression, int pos) {
262 if (collect_expressions_in_tail_position_) { 271 if (return_expr_context() == ReturnExprContext::kNormal) {
263 expressions_in_tail_position_.Add(TailCallExpression(expression, pos)); 272 expressions_in_tail_position_.Add(TailCallExpression(expression, pos));
264 } 273 }
265 } 274 }
266 275
267 bool collect_expressions_in_tail_position() const { 276 ReturnExprContext return_expr_context() const {
268 return collect_expressions_in_tail_position_; 277 return return_expr_context_;
269 } 278 }
270 void set_collect_expressions_in_tail_position(bool collect) { 279 void set_return_expr_context(ReturnExprContext context) {
271 collect_expressions_in_tail_position_ = collect; 280 return_expr_context_ = context;
272 } 281 }
273 282
274 ZoneList<ExpressionT>* non_patterns_to_rewrite() { 283 ZoneList<ExpressionT>* non_patterns_to_rewrite() {
275 return &non_patterns_to_rewrite_; 284 return &non_patterns_to_rewrite_;
276 } 285 }
277 286
278 void next_function_is_parenthesized(bool parenthesized) { 287 void next_function_is_parenthesized(bool parenthesized) {
279 next_function_is_parenthesized_ = parenthesized; 288 next_function_is_parenthesized_ = parenthesized;
280 } 289 }
281 290
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // for generator functions to have this variable set. 326 // for generator functions to have this variable set.
318 Variable* generator_object_variable_; 327 Variable* generator_object_variable_;
319 328
320 FunctionState** function_state_stack_; 329 FunctionState** function_state_stack_;
321 FunctionState* outer_function_state_; 330 FunctionState* outer_function_state_;
322 Scope** scope_stack_; 331 Scope** scope_stack_;
323 Scope* outer_scope_; 332 Scope* outer_scope_;
324 333
325 List<DestructuringAssignment> destructuring_assignments_to_rewrite_; 334 List<DestructuringAssignment> destructuring_assignments_to_rewrite_;
326 List<TailCallExpression> expressions_in_tail_position_; 335 List<TailCallExpression> expressions_in_tail_position_;
327 bool collect_expressions_in_tail_position_; 336 ReturnExprContext return_expr_context_;
328 ZoneList<ExpressionT> non_patterns_to_rewrite_; 337 ZoneList<ExpressionT> non_patterns_to_rewrite_;
329 338
330 typename Traits::Type::Factory* factory_; 339 typename Traits::Type::Factory* factory_;
331 340
332 // If true, the next (and immediately following) function literal is 341 // If true, the next (and immediately following) function literal is
333 // preceded by a parenthesis. 342 // preceded by a parenthesis.
334 bool next_function_is_parenthesized_; 343 bool next_function_is_parenthesized_;
335 344
336 // The value of the parents' next_function_is_parenthesized_, as it applies 345 // The value of the parents' next_function_is_parenthesized_, as it applies
337 // to this function. Filled in by constructor. 346 // to this function. Filled in by constructor.
338 bool this_function_is_parenthesized_; 347 bool this_function_is_parenthesized_;
339 348
340 friend class ParserTraits; 349 friend class ParserTraits;
341 friend class PreParserTraits; 350 friend class PreParserTraits;
342 friend class Checkpoint; 351 friend class Checkpoint;
343 }; 352 };
344 353
345 // This scope disables collecting of expressions at tail call position. 354 // This scope sets current ReturnExprContext to given value.
346 class DontCollectExpressionsInTailPositionScope { 355 class ReturnExprScope {
347 public: 356 public:
348 explicit DontCollectExpressionsInTailPositionScope( 357 explicit ReturnExprScope(FunctionState* function_state,
349 FunctionState* function_state) 358 ReturnExprContext return_expr_context)
350 : function_state_(function_state), 359 : function_state_(function_state),
351 old_value_(function_state->collect_expressions_in_tail_position()) { 360 sav_return_expr_context_(function_state->return_expr_context()) {
352 function_state->set_collect_expressions_in_tail_position(false); 361 function_state->set_return_expr_context(return_expr_context);
353 } 362 }
354 ~DontCollectExpressionsInTailPositionScope() { 363 ~ReturnExprScope() {
355 function_state_->set_collect_expressions_in_tail_position(old_value_); 364 function_state_->set_return_expr_context(sav_return_expr_context_);
356 } 365 }
357 366
358 private: 367 private:
359 FunctionState* function_state_; 368 FunctionState* function_state_;
360 bool old_value_; 369 ReturnExprContext sav_return_expr_context_;
361 }; 370 };
362 371
363 // Collects all return expressions at tail call position in this scope 372 // Collects all return expressions at tail call position in this scope
364 // to a separate list. 373 // to a separate list.
365 class CollectExpressionsInTailPositionToListScope { 374 class CollectExpressionsInTailPositionToListScope {
366 public: 375 public:
367 CollectExpressionsInTailPositionToListScope(FunctionState* function_state, 376 CollectExpressionsInTailPositionToListScope(FunctionState* function_state,
368 List<TailCallExpression>* list) 377 List<TailCallExpression>* list)
369 : function_state_(function_state), list_(list) { 378 : function_state_(function_state), list_(list) {
370 function_state->expressions_in_tail_position().Swap(list_); 379 function_state->expressions_in_tail_position().Swap(list_);
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 expected_property_count_(0), 992 expected_property_count_(0),
984 this_location_(Scanner::Location::invalid()), 993 this_location_(Scanner::Location::invalid()),
985 return_location_(Scanner::Location::invalid()), 994 return_location_(Scanner::Location::invalid()),
986 super_location_(Scanner::Location::invalid()), 995 super_location_(Scanner::Location::invalid()),
987 kind_(kind), 996 kind_(kind),
988 generator_object_variable_(NULL), 997 generator_object_variable_(NULL),
989 function_state_stack_(function_state_stack), 998 function_state_stack_(function_state_stack),
990 outer_function_state_(*function_state_stack), 999 outer_function_state_(*function_state_stack),
991 scope_stack_(scope_stack), 1000 scope_stack_(scope_stack),
992 outer_scope_(*scope_stack), 1001 outer_scope_(*scope_stack),
993 collect_expressions_in_tail_position_(true), 1002 return_expr_context_(ReturnExprContext::kNormal),
994 non_patterns_to_rewrite_(0, scope->zone()), 1003 non_patterns_to_rewrite_(0, scope->zone()),
995 factory_(factory), 1004 factory_(factory),
996 next_function_is_parenthesized_(false), 1005 next_function_is_parenthesized_(false),
997 this_function_is_parenthesized_(false) { 1006 this_function_is_parenthesized_(false) {
998 *scope_stack_ = scope; 1007 *scope_stack_ = scope;
999 *function_state_stack = this; 1008 *function_state_stack = this;
1000 if (outer_function_state_) { 1009 if (outer_function_state_) {
1001 this_function_is_parenthesized_ = 1010 this_function_is_parenthesized_ =
1002 outer_function_state_->next_function_is_parenthesized_; 1011 outer_function_state_->next_function_is_parenthesized_;
1003 outer_function_state_->next_function_is_parenthesized_ = false; 1012 outer_function_state_->next_function_is_parenthesized_ = false;
(...skipping 2177 matching lines...) Expand 10 before | Expand all | Expand 10 after
3181 has_seen_constructor_ = true; 3190 has_seen_constructor_ = true;
3182 return; 3191 return;
3183 } 3192 }
3184 } 3193 }
3185 3194
3186 3195
3187 } // namespace internal 3196 } // namespace internal
3188 } // namespace v8 3197 } // namespace v8
3189 3198
3190 #endif // V8_PARSING_PARSER_BASE_H 3199 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.cc » ('j') | src/parsing/preparser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698