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

Side by Side Diff: src/preparser.h

Issue 485473004: Refactor parser Checkpoints. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased 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.cc ('k') | src/preparser.cc » ('j') | 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 void set_allow_classes(bool allow) { 115 void set_allow_classes(bool allow) {
116 scanner()->SetHarmonyClasses(allow); 116 scanner()->SetHarmonyClasses(allow);
117 } 117 }
118 118
119 protected: 119 protected:
120 friend class Traits::Type::Checkpoint; 120 friend class Traits::Checkpoint;
121 121
122 enum AllowEvalOrArgumentsAsIdentifier { 122 enum AllowEvalOrArgumentsAsIdentifier {
123 kAllowEvalOrArguments, 123 kAllowEvalOrArguments,
124 kDontAllowEvalOrArguments 124 kDontAllowEvalOrArguments
125 }; 125 };
126 126
127 enum Mode { 127 enum Mode {
128 PARSE_LAZILY, 128 PARSE_LAZILY,
129 PARSE_EAGERLY 129 PARSE_EAGERLY
130 }; 130 };
131 131
132 class ParserCheckpoint; 132 class CheckpointBase;
133 133
134 // --------------------------------------------------------------------------- 134 // ---------------------------------------------------------------------------
135 // FunctionState and BlockState together implement the parser's scope stack. 135 // FunctionState and BlockState together implement the parser's scope stack.
136 // The parser's current scope is in scope_. BlockState and FunctionState 136 // The parser's current scope is in scope_. BlockState and FunctionState
137 // constructors push on the scope stack and the destructors pop. They are also 137 // constructors push on the scope stack and the destructors pop. They are also
138 // used to hold the parser's per-function and per-block state. 138 // used to hold the parser's per-function and per-block state.
139 class BlockState BASE_EMBEDDED { 139 class BlockState BASE_EMBEDDED {
140 public: 140 public:
141 BlockState(typename Traits::Type::Scope** scope_stack, 141 BlockState(typename Traits::Type::Scope** scope_stack,
142 typename Traits::Type::Scope* scope) 142 typename Traits::Type::Scope* scope)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 219
220 FunctionState** function_state_stack_; 220 FunctionState** function_state_stack_;
221 FunctionState* outer_function_state_; 221 FunctionState* outer_function_state_;
222 typename Traits::Type::Scope** scope_stack_; 222 typename Traits::Type::Scope** scope_stack_;
223 typename Traits::Type::Scope* outer_scope_; 223 typename Traits::Type::Scope* outer_scope_;
224 int saved_ast_node_id_; // Only used by ParserTraits. 224 int saved_ast_node_id_; // Only used by ParserTraits.
225 typename Traits::Type::Zone* extra_param_; 225 typename Traits::Type::Zone* extra_param_;
226 typename Traits::Type::Factory factory_; 226 typename Traits::Type::Factory factory_;
227 227
228 friend class ParserTraits; 228 friend class ParserTraits;
229 friend class ParserCheckpoint; 229 friend class CheckpointBase;
230 }; 230 };
231 231
232 // Annoyingly, arrow functions first parse as comma expressions, then when we 232 // Annoyingly, arrow functions first parse as comma expressions, then when we
233 // see the => we have to go back and reinterpret the arguments as being formal 233 // see the => we have to go back and reinterpret the arguments as being formal
234 // parameters. To do so we need to reset some of the parser state back to 234 // parameters. To do so we need to reset some of the parser state back to
235 // what it was before the arguments were first seen. 235 // what it was before the arguments were first seen.
236 class ParserCheckpoint : public Traits::Type::Checkpoint { 236 class CheckpointBase BASE_EMBEDDED {
237 public: 237 public:
238 template <typename Parser> 238 explicit CheckpointBase(ParserBase* parser) {
239 explicit ParserCheckpoint(Parser* parser)
240 : Traits::Type::Checkpoint(parser) {
241 function_state_ = parser->function_state_; 239 function_state_ = parser->function_state_;
242 next_materialized_literal_index_ = 240 next_materialized_literal_index_ =
243 function_state_->next_materialized_literal_index_; 241 function_state_->next_materialized_literal_index_;
244 next_handler_index_ = function_state_->next_handler_index_; 242 next_handler_index_ = function_state_->next_handler_index_;
245 expected_property_count_ = function_state_->expected_property_count_; 243 expected_property_count_ = function_state_->expected_property_count_;
246 } 244 }
247 245
248 void Restore() { 246 void Restore() {
249 Traits::Type::Checkpoint::Restore();
250 function_state_->next_materialized_literal_index_ = 247 function_state_->next_materialized_literal_index_ =
251 next_materialized_literal_index_; 248 next_materialized_literal_index_;
252 function_state_->next_handler_index_ = next_handler_index_; 249 function_state_->next_handler_index_ = next_handler_index_;
253 function_state_->expected_property_count_ = expected_property_count_; 250 function_state_->expected_property_count_ = expected_property_count_;
254 } 251 }
255 252
256 private: 253 private:
257 FunctionState* function_state_; 254 FunctionState* function_state_;
258 int next_materialized_literal_index_; 255 int next_materialized_literal_index_;
259 int next_handler_index_; 256 int next_handler_index_;
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 public: 1014 public:
1018 struct Type { 1015 struct Type {
1019 // TODO(marja): To be removed. The Traits object should contain all the data 1016 // TODO(marja): To be removed. The Traits object should contain all the data
1020 // it needs. 1017 // it needs.
1021 typedef PreParser* Parser; 1018 typedef PreParser* Parser;
1022 1019
1023 // Used by FunctionState and BlockState. 1020 // Used by FunctionState and BlockState.
1024 typedef PreParserScope Scope; 1021 typedef PreParserScope Scope;
1025 typedef PreParserScope ScopePtr; 1022 typedef PreParserScope ScopePtr;
1026 1023
1027 class Checkpoint BASE_EMBEDDED {
1028 public:
1029 template <typename Parser>
1030 explicit Checkpoint(Parser* parser) {}
1031 void Restore() {}
1032 };
1033
1034 // PreParser doesn't need to store generator variables. 1024 // PreParser doesn't need to store generator variables.
1035 typedef void GeneratorVariable; 1025 typedef void GeneratorVariable;
1036 // No interaction with Zones. 1026 // No interaction with Zones.
1037 typedef void Zone; 1027 typedef void Zone;
1038 1028
1039 typedef int AstProperties; 1029 typedef int AstProperties;
1040 typedef Vector<PreParserIdentifier> ParameterIdentifierVector; 1030 typedef Vector<PreParserIdentifier> ParameterIdentifierVector;
1041 1031
1042 // Return types for traversing functions. 1032 // Return types for traversing functions.
1043 typedef PreParserIdentifier Identifier; 1033 typedef PreParserIdentifier Identifier;
1044 typedef PreParserExpression Expression; 1034 typedef PreParserExpression Expression;
1045 typedef PreParserExpression YieldExpression; 1035 typedef PreParserExpression YieldExpression;
1046 typedef PreParserExpression FunctionLiteral; 1036 typedef PreParserExpression FunctionLiteral;
1047 typedef PreParserExpression ObjectLiteralProperty; 1037 typedef PreParserExpression ObjectLiteralProperty;
1048 typedef PreParserExpression Literal; 1038 typedef PreParserExpression Literal;
1049 typedef PreParserExpressionList ExpressionList; 1039 typedef PreParserExpressionList ExpressionList;
1050 typedef PreParserExpressionList PropertyList; 1040 typedef PreParserExpressionList PropertyList;
1051 typedef PreParserStatementList StatementList; 1041 typedef PreParserStatementList StatementList;
1052 1042
1053 // For constructing objects returned by the traversing functions. 1043 // For constructing objects returned by the traversing functions.
1054 typedef PreParserFactory Factory; 1044 typedef PreParserFactory Factory;
1055 }; 1045 };
1056 1046
1047 class Checkpoint;
1048
1057 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} 1049 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {}
1058 1050
1059 // Custom operations executed when FunctionStates are created and 1051 // Custom operations executed when FunctionStates are created and
1060 // destructed. (The PreParser doesn't need to do anything.) 1052 // destructed. (The PreParser doesn't need to do anything.)
1061 template<typename FunctionState> 1053 template<typename FunctionState>
1062 static void SetUpFunctionState(FunctionState* function_state, void*) {} 1054 static void SetUpFunctionState(FunctionState* function_state, void*) {}
1063 template<typename FunctionState> 1055 template<typename FunctionState>
1064 static void TearDownFunctionState(FunctionState* function_state, void*) {} 1056 static void TearDownFunctionState(FunctionState* function_state, void*) {}
1065 1057
1066 // Helper functions for recursive descent. 1058 // Helper functions for recursive descent.
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
1972 // YieldExpression 1964 // YieldExpression
1973 // LeftHandSideExpression AssignmentOperator AssignmentExpression 1965 // LeftHandSideExpression AssignmentOperator AssignmentExpression
1974 1966
1975 Scanner::Location lhs_location = scanner()->peek_location(); 1967 Scanner::Location lhs_location = scanner()->peek_location();
1976 1968
1977 if (peek() == Token::YIELD && is_generator()) { 1969 if (peek() == Token::YIELD && is_generator()) {
1978 return this->ParseYieldExpression(ok); 1970 return this->ParseYieldExpression(ok);
1979 } 1971 }
1980 1972
1981 if (fni_ != NULL) fni_->Enter(); 1973 if (fni_ != NULL) fni_->Enter();
1982 ParserCheckpoint checkpoint(this); 1974 typename Traits::Checkpoint checkpoint(this);
1983 ExpressionT expression = 1975 ExpressionT expression =
1984 this->ParseConditionalExpression(accept_IN, CHECK_OK); 1976 this->ParseConditionalExpression(accept_IN, CHECK_OK);
1985 1977
1986 if (allow_arrow_functions() && peek() == Token::ARROW) { 1978 if (allow_arrow_functions() && peek() == Token::ARROW) {
1987 checkpoint.Restore(); 1979 checkpoint.Restore();
1988 expression = this->ParseArrowFunctionLiteral(lhs_location.beg_pos, 1980 expression = this->ParseArrowFunctionLiteral(lhs_location.beg_pos,
1989 expression, CHECK_OK); 1981 expression, CHECK_OK);
1990 return expression; 1982 return expression;
1991 } 1983 }
1992 1984
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
2576 } 2568 }
2577 2569
2578 2570
2579 #undef CHECK_OK 2571 #undef CHECK_OK
2580 #undef CHECK_OK_CUSTOM 2572 #undef CHECK_OK_CUSTOM
2581 2573
2582 2574
2583 } } // v8::internal 2575 } } // v8::internal
2584 2576
2585 #endif // V8_PREPARSER_H 2577 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698