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

Side by Side Diff: src/preparser.h

Issue 440373003: Revert "Rewind additional parser state when reinterpreting arrow arguments" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_PREPARSER_H 5 #ifndef V8_PREPARSER_H
6 #define V8_PREPARSER_H 6 #define V8_PREPARSER_H
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/func-name-inferrer.h" 10 #include "src/func-name-inferrer.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 void set_allow_arrow_functions(bool allow) { allow_arrow_functions_ = allow; } 107 void set_allow_arrow_functions(bool allow) { allow_arrow_functions_ = allow; }
108 void set_allow_modules(bool allow) { scanner()->SetHarmonyModules(allow); } 108 void set_allow_modules(bool allow) { scanner()->SetHarmonyModules(allow); }
109 void set_allow_harmony_scoping(bool allow) { 109 void set_allow_harmony_scoping(bool allow) {
110 scanner()->SetHarmonyScoping(allow); 110 scanner()->SetHarmonyScoping(allow);
111 } 111 }
112 void set_allow_harmony_numeric_literals(bool allow) { 112 void set_allow_harmony_numeric_literals(bool allow) {
113 scanner()->SetHarmonyNumericLiterals(allow); 113 scanner()->SetHarmonyNumericLiterals(allow);
114 } 114 }
115 115
116 protected: 116 protected:
117 friend class Traits::Type::Checkpoint;
118
119 enum AllowEvalOrArgumentsAsIdentifier { 117 enum AllowEvalOrArgumentsAsIdentifier {
120 kAllowEvalOrArguments, 118 kAllowEvalOrArguments,
121 kDontAllowEvalOrArguments 119 kDontAllowEvalOrArguments
122 }; 120 };
123 121
124 enum Mode { 122 enum Mode {
125 PARSE_LAZILY, 123 PARSE_LAZILY,
126 PARSE_EAGERLY 124 PARSE_EAGERLY
127 }; 125 };
128 126
129 class ParserCheckpoint;
130
131 // --------------------------------------------------------------------------- 127 // ---------------------------------------------------------------------------
132 // FunctionState and BlockState together implement the parser's scope stack. 128 // FunctionState and BlockState together implement the parser's scope stack.
133 // The parser's current scope is in scope_. BlockState and FunctionState 129 // The parser's current scope is in scope_. BlockState and FunctionState
134 // constructors push on the scope stack and the destructors pop. They are also 130 // constructors push on the scope stack and the destructors pop. They are also
135 // used to hold the parser's per-function and per-block state. 131 // used to hold the parser's per-function and per-block state.
136 class BlockState BASE_EMBEDDED { 132 class BlockState BASE_EMBEDDED {
137 public: 133 public:
138 BlockState(typename Traits::Type::Scope** scope_stack, 134 BlockState(typename Traits::Type::Scope** scope_stack,
139 typename Traits::Type::Scope* scope) 135 typename Traits::Type::Scope* scope)
140 : scope_stack_(scope_stack), 136 : scope_stack_(scope_stack),
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 212
217 FunctionState** function_state_stack_; 213 FunctionState** function_state_stack_;
218 FunctionState* outer_function_state_; 214 FunctionState* outer_function_state_;
219 typename Traits::Type::Scope** scope_stack_; 215 typename Traits::Type::Scope** scope_stack_;
220 typename Traits::Type::Scope* outer_scope_; 216 typename Traits::Type::Scope* outer_scope_;
221 int saved_ast_node_id_; // Only used by ParserTraits. 217 int saved_ast_node_id_; // Only used by ParserTraits.
222 typename Traits::Type::Zone* extra_param_; 218 typename Traits::Type::Zone* extra_param_;
223 typename Traits::Type::Factory factory_; 219 typename Traits::Type::Factory factory_;
224 220
225 friend class ParserTraits; 221 friend class ParserTraits;
226 friend class ParserCheckpoint;
227 };
228
229 // Annoyingly, arrow functions first parse as comma expressions, then when we
230 // see the => we have to go back and reinterpret the arguments as being formal
231 // parameters. To do so we need to reset some of the parser state back to
232 // what it was before the arguments were first seen.
233 class ParserCheckpoint : public Traits::Type::Checkpoint {
234 public:
235 template <typename Parser>
236 explicit ParserCheckpoint(Parser* parser)
237 : Traits::Type::Checkpoint(parser) {
238 function_state_ = parser->function_state_;
239 next_materialized_literal_index_ =
240 function_state_->next_materialized_literal_index_;
241 next_handler_index_ = function_state_->next_handler_index_;
242 expected_property_count_ = function_state_->expected_property_count_;
243 }
244
245 void Restore() {
246 Traits::Type::Checkpoint::Restore();
247 function_state_->next_materialized_literal_index_ =
248 next_materialized_literal_index_;
249 function_state_->next_handler_index_ = next_handler_index_;
250 function_state_->expected_property_count_ = expected_property_count_;
251 }
252
253 private:
254 FunctionState* function_state_;
255 int next_materialized_literal_index_;
256 int next_handler_index_;
257 int expected_property_count_;
258 }; 222 };
259 223
260 class ParsingModeScope BASE_EMBEDDED { 224 class ParsingModeScope BASE_EMBEDDED {
261 public: 225 public:
262 ParsingModeScope(ParserBase* parser, Mode mode) 226 ParsingModeScope(ParserBase* parser, Mode mode)
263 : parser_(parser), 227 : parser_(parser),
264 old_mode_(parser->mode()) { 228 old_mode_(parser->mode()) {
265 parser_->mode_ = mode; 229 parser_->mode_ = mode;
266 } 230 }
267 ~ParsingModeScope() { 231 ~ParsingModeScope() {
(...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 // dummy method right in this class. 1014 // dummy method right in this class.
1051 PreParserFactory* visitor() { return this; } 1015 PreParserFactory* visitor() { return this; }
1052 BailoutReason dont_optimize_reason() { return kNoReason; } 1016 BailoutReason dont_optimize_reason() { return kNoReason; }
1053 int* ast_properties() { 1017 int* ast_properties() {
1054 static int dummy = 42; 1018 static int dummy = 42;
1055 return &dummy; 1019 return &dummy;
1056 } 1020 }
1057 }; 1021 };
1058 1022
1059 1023
1060 class PreParserCheckpoint BASE_EMBEDDED {
1061 public:
1062 template <typename Parser>
1063 explicit PreParserCheckpoint(Parser* parser) {}
1064 void Restore() {}
1065 };
1066
1067
1068 class PreParser; 1024 class PreParser;
1069 1025
1070 class PreParserTraits { 1026 class PreParserTraits {
1071 public: 1027 public:
1072 struct Type { 1028 struct Type {
1073 // TODO(marja): To be removed. The Traits object should contain all the data 1029 // TODO(marja): To be removed. The Traits object should contain all the data
1074 // it needs. 1030 // it needs.
1075 typedef PreParser* Parser; 1031 typedef PreParser* Parser;
1076 1032
1077 // Used by FunctionState and BlockState. 1033 // Used by FunctionState and BlockState.
1078 typedef PreParserScope Scope; 1034 typedef PreParserScope Scope;
1079 typedef PreParserScope ScopePtr; 1035 typedef PreParserScope ScopePtr;
1080 typedef PreParserCheckpoint Checkpoint;
1081 1036
1082 // PreParser doesn't need to store generator variables. 1037 // PreParser doesn't need to store generator variables.
1083 typedef void GeneratorVariable; 1038 typedef void GeneratorVariable;
1084 // No interaction with Zones. 1039 // No interaction with Zones.
1085 typedef void Zone; 1040 typedef void Zone;
1086 1041
1087 typedef int AstProperties; 1042 typedef int AstProperties;
1088 typedef Vector<PreParserIdentifier> ParameterIdentifierVector; 1043 typedef Vector<PreParserIdentifier> ParameterIdentifierVector;
1089 1044
1090 // Return types for traversing functions. 1045 // Return types for traversing functions.
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after
2044 // YieldExpression 1999 // YieldExpression
2045 // LeftHandSideExpression AssignmentOperator AssignmentExpression 2000 // LeftHandSideExpression AssignmentOperator AssignmentExpression
2046 2001
2047 Scanner::Location lhs_location = scanner()->peek_location(); 2002 Scanner::Location lhs_location = scanner()->peek_location();
2048 2003
2049 if (peek() == Token::YIELD && is_generator()) { 2004 if (peek() == Token::YIELD && is_generator()) {
2050 return this->ParseYieldExpression(ok); 2005 return this->ParseYieldExpression(ok);
2051 } 2006 }
2052 2007
2053 if (fni_ != NULL) fni_->Enter(); 2008 if (fni_ != NULL) fni_->Enter();
2054 ParserCheckpoint checkpoint(this);
2055 ExpressionT expression = 2009 ExpressionT expression =
2056 this->ParseConditionalExpression(accept_IN, CHECK_OK); 2010 this->ParseConditionalExpression(accept_IN, CHECK_OK);
2057 2011
2058 if (allow_arrow_functions() && peek() == Token::ARROW) { 2012 if (allow_arrow_functions() && peek() == Token::ARROW) {
2059 checkpoint.Restore();
2060 expression = this->ParseArrowFunctionLiteral(lhs_location.beg_pos, 2013 expression = this->ParseArrowFunctionLiteral(lhs_location.beg_pos,
2061 expression, CHECK_OK); 2014 expression, CHECK_OK);
2062 return expression; 2015 return expression;
2063 } 2016 }
2064 2017
2065 if (!Token::IsAssignmentOp(peek())) { 2018 if (!Token::IsAssignmentOp(peek())) {
2066 if (fni_ != NULL) fni_->Leave(); 2019 if (fni_ != NULL) fni_->Leave();
2067 // Parsed conditional expression only (no assignment). 2020 // Parsed conditional expression only (no assignment).
2068 return expression; 2021 return expression;
2069 } 2022 }
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
2660 parser()->ReportMessage("accessor_get_set"); 2613 parser()->ReportMessage("accessor_get_set");
2661 } 2614 }
2662 *ok = false; 2615 *ok = false;
2663 } 2616 }
2664 } 2617 }
2665 2618
2666 2619
2667 } } // v8::internal 2620 } } // v8::internal
2668 2621
2669 #endif // V8_PREPARSER_H 2622 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698