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

Side by Side Diff: src/preparser.h

Issue 633373003: Simplify AST ID generation. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 6 years, 2 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/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 typename Traits::Type::Scope** scope_stack_; 163 typename Traits::Type::Scope** scope_stack_;
164 typename Traits::Type::Scope* outer_scope_; 164 typename Traits::Type::Scope* outer_scope_;
165 typename Traits::Type::Scope* scope_; 165 typename Traits::Type::Scope* scope_;
166 }; 166 };
167 167
168 class FunctionState BASE_EMBEDDED { 168 class FunctionState BASE_EMBEDDED {
169 public: 169 public:
170 FunctionState(FunctionState** function_state_stack, 170 FunctionState(FunctionState** function_state_stack,
171 typename Traits::Type::Scope** scope_stack, 171 typename Traits::Type::Scope** scope_stack,
172 typename Traits::Type::Scope* scope, 172 typename Traits::Type::Scope* scope,
173 typename Traits::Type::Zone* zone = NULL, 173 typename Traits::Type::Factory* factory);
174 AstValueFactory* ast_value_factory = NULL,
175 AstNode::IdGen* ast_node_id_gen = NULL);
176 FunctionState(FunctionState** function_state_stack, 174 FunctionState(FunctionState** function_state_stack,
177 typename Traits::Type::Scope** scope_stack, 175 typename Traits::Type::Scope** scope_stack,
178 typename Traits::Type::Scope** scope, 176 typename Traits::Type::Scope** scope,
179 typename Traits::Type::Zone* zone = NULL, 177 typename Traits::Type::Factory* factory);
180 AstValueFactory* ast_value_factory = NULL,
181 AstNode::IdGen* ast_node_id_gen = NULL);
182 ~FunctionState(); 178 ~FunctionState();
183 179
184 int NextMaterializedLiteralIndex() { 180 int NextMaterializedLiteralIndex() {
185 return next_materialized_literal_index_++; 181 return next_materialized_literal_index_++;
186 } 182 }
187 int materialized_literal_count() { 183 int materialized_literal_count() {
188 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; 184 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize;
189 } 185 }
190 186
191 int NextHandlerIndex() { return next_handler_index_++; } 187 int NextHandlerIndex() { return next_handler_index_++; }
(...skipping 10 matching lines...) Expand all
202 DCHECK(variable != NULL); 198 DCHECK(variable != NULL);
203 DCHECK(!is_generator()); 199 DCHECK(!is_generator());
204 generator_object_variable_ = variable; 200 generator_object_variable_ = variable;
205 is_generator_ = true; 201 is_generator_ = true;
206 } 202 }
207 typename Traits::Type::GeneratorVariable* generator_object_variable() 203 typename Traits::Type::GeneratorVariable* generator_object_variable()
208 const { 204 const {
209 return generator_object_variable_; 205 return generator_object_variable_;
210 } 206 }
211 207
212 typename Traits::Type::Factory* factory() { return &factory_; } 208 typename Traits::Type::Factory* factory() { return factory_; }
213 209
214 private: 210 private:
215 // Used to assign an index to each literal that needs materialization in 211 // Used to assign an index to each literal that needs materialization in
216 // the function. Includes regexp literals, and boilerplate for object and 212 // the function. Includes regexp literals, and boilerplate for object and
217 // array literals. 213 // array literals.
218 int next_materialized_literal_index_; 214 int next_materialized_literal_index_;
219 215
220 // Used to assign a per-function index to try and catch handlers. 216 // Used to assign a per-function index to try and catch handlers.
221 int next_handler_index_; 217 int next_handler_index_;
222 218
223 // Properties count estimation. 219 // Properties count estimation.
224 int expected_property_count_; 220 int expected_property_count_;
225 221
226 // Whether the function is a generator. 222 // Whether the function is a generator.
227 bool is_generator_; 223 bool is_generator_;
228 // For generators, this variable may hold the generator object. It variable 224 // For generators, this variable may hold the generator object. It variable
229 // is used by yield expressions and return statements. It is not necessary 225 // is used by yield expressions and return statements. It is not necessary
230 // for generator functions to have this variable set. 226 // for generator functions to have this variable set.
231 Variable* generator_object_variable_; 227 Variable* generator_object_variable_;
232 228
233 FunctionState** function_state_stack_; 229 FunctionState** function_state_stack_;
234 FunctionState* outer_function_state_; 230 FunctionState* outer_function_state_;
235 typename Traits::Type::Scope** scope_stack_; 231 typename Traits::Type::Scope** scope_stack_;
236 typename Traits::Type::Scope* outer_scope_; 232 typename Traits::Type::Scope* outer_scope_;
237 AstNode::IdGen* ast_node_id_gen_; // Only used by ParserTraits.
238 AstNode::IdGen saved_id_gen_; // Ditto.
239 typename Traits::Type::Zone* extra_param_; 233 typename Traits::Type::Zone* extra_param_;
240 typename Traits::Type::Factory factory_; 234 typename Traits::Type::Factory* factory_;
241 235
242 friend class ParserTraits; 236 friend class ParserTraits;
243 friend class Checkpoint; 237 friend class Checkpoint;
244 }; 238 };
245 239
246 // Annoyingly, arrow functions first parse as comma expressions, then when we 240 // Annoyingly, arrow functions first parse as comma expressions, then when we
247 // see the => we have to go back and reinterpret the arguments as being formal 241 // see the => we have to go back and reinterpret the arguments as being formal
248 // parameters. To do so we need to reset some of the parser state back to 242 // parameters. To do so we need to reset some of the parser state back to
249 // what it was before the arguments were first seen. 243 // what it was before the arguments were first seen.
250 class Checkpoint BASE_EMBEDDED { 244 class Checkpoint BASE_EMBEDDED {
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 typedef PreParserExpressionList ExpressionList; 1143 typedef PreParserExpressionList ExpressionList;
1150 typedef PreParserExpressionList PropertyList; 1144 typedef PreParserExpressionList PropertyList;
1151 typedef PreParserStatementList StatementList; 1145 typedef PreParserStatementList StatementList;
1152 1146
1153 // For constructing objects returned by the traversing functions. 1147 // For constructing objects returned by the traversing functions.
1154 typedef PreParserFactory Factory; 1148 typedef PreParserFactory Factory;
1155 }; 1149 };
1156 1150
1157 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} 1151 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {}
1158 1152
1159 // Custom operations executed when FunctionStates are created and
1160 // destructed. (The PreParser doesn't need to do anything.)
1161 template <typename FunctionState>
1162 static void SetUpFunctionState(FunctionState* function_state) {}
1163 template <typename FunctionState>
1164 static void TearDownFunctionState(FunctionState* function_state) {}
1165
1166 // Helper functions for recursive descent. 1153 // Helper functions for recursive descent.
1167 static bool IsEvalOrArguments(PreParserIdentifier identifier) { 1154 static bool IsEvalOrArguments(PreParserIdentifier identifier) {
1168 return identifier.IsEvalOrArguments(); 1155 return identifier.IsEvalOrArguments();
1169 } 1156 }
1170 1157
1171 static bool IsPrototype(PreParserIdentifier identifier) { 1158 static bool IsPrototype(PreParserIdentifier identifier) {
1172 return identifier.IsPrototype(); 1159 return identifier.IsPrototype();
1173 } 1160 }
1174 1161
1175 static bool IsConstructor(PreParserIdentifier identifier) { 1162 static bool IsConstructor(PreParserIdentifier identifier) {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit) 1425 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit)
1439 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, NULL, 1426 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, NULL,
1440 this) {} 1427 this) {}
1441 1428
1442 // Pre-parse the program from the character stream; returns true on 1429 // Pre-parse the program from the character stream; returns true on
1443 // success (even if parsing failed, the pre-parse data successfully 1430 // success (even if parsing failed, the pre-parse data successfully
1444 // captured the syntax error), and false if a stack-overflow happened 1431 // captured the syntax error), and false if a stack-overflow happened
1445 // during parsing. 1432 // during parsing.
1446 PreParseResult PreParseProgram() { 1433 PreParseResult PreParseProgram() {
1447 PreParserScope scope(scope_, GLOBAL_SCOPE); 1434 PreParserScope scope(scope_, GLOBAL_SCOPE);
1448 FunctionState top_scope(&function_state_, &scope_, &scope); 1435 PreParserFactory factory(NULL, NULL, NULL);
1436 FunctionState top_scope(&function_state_, &scope_, &scope, &factory);
1449 bool ok = true; 1437 bool ok = true;
1450 int start_position = scanner()->peek_location().beg_pos; 1438 int start_position = scanner()->peek_location().beg_pos;
1451 ParseSourceElements(Token::EOS, &ok); 1439 ParseSourceElements(Token::EOS, &ok);
1452 if (stack_overflow()) return kPreParseStackOverflow; 1440 if (stack_overflow()) return kPreParseStackOverflow;
1453 if (!ok) { 1441 if (!ok) {
1454 ReportUnexpectedToken(scanner()->current_token()); 1442 ReportUnexpectedToken(scanner()->current_token());
1455 } else if (scope_->strict_mode() == STRICT) { 1443 } else if (scope_->strict_mode() == STRICT) {
1456 CheckOctalLiteral(start_position, scanner()->location().end_pos, &ok); 1444 CheckOctalLiteral(start_position, scanner()->location().end_pos, &ok);
1457 } 1445 }
1458 return kPreParseSuccess; 1446 return kPreParseSuccess;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 Token::Value fvar_init_op, bool is_generator, bool* ok) { 1553 Token::Value fvar_init_op, bool is_generator, bool* ok) {
1566 return pre_parser_->ParseEagerFunctionBody(function_name, pos, fvar, 1554 return pre_parser_->ParseEagerFunctionBody(function_name, pos, fvar,
1567 fvar_init_op, is_generator, ok); 1555 fvar_init_op, is_generator, ok);
1568 } 1556 }
1569 1557
1570 1558
1571 template <class Traits> 1559 template <class Traits>
1572 ParserBase<Traits>::FunctionState::FunctionState( 1560 ParserBase<Traits>::FunctionState::FunctionState(
1573 FunctionState** function_state_stack, 1561 FunctionState** function_state_stack,
1574 typename Traits::Type::Scope** scope_stack, 1562 typename Traits::Type::Scope** scope_stack,
1575 typename Traits::Type::Scope* scope, typename Traits::Type::Zone* zone, 1563 typename Traits::Type::Scope* scope,
1576 AstValueFactory* ast_value_factory, AstNode::IdGen* ast_node_id_gen) 1564 typename Traits::Type::Factory* factory)
1577 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), 1565 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize),
1578 next_handler_index_(0), 1566 next_handler_index_(0),
1579 expected_property_count_(0), 1567 expected_property_count_(0),
1580 is_generator_(false), 1568 is_generator_(false),
1581 generator_object_variable_(NULL), 1569 generator_object_variable_(NULL),
1582 function_state_stack_(function_state_stack), 1570 function_state_stack_(function_state_stack),
1583 outer_function_state_(*function_state_stack), 1571 outer_function_state_(*function_state_stack),
1584 scope_stack_(scope_stack), 1572 scope_stack_(scope_stack),
1585 outer_scope_(*scope_stack), 1573 outer_scope_(*scope_stack),
1586 ast_node_id_gen_(ast_node_id_gen), 1574 factory_(factory) {
1587 factory_(zone, ast_value_factory, ast_node_id_gen) {
1588 *scope_stack_ = scope; 1575 *scope_stack_ = scope;
1589 *function_state_stack = this; 1576 *function_state_stack = this;
1590 Traits::SetUpFunctionState(this);
1591 } 1577 }
1592 1578
1593 1579
1594 template <class Traits> 1580 template <class Traits>
1595 ParserBase<Traits>::FunctionState::FunctionState( 1581 ParserBase<Traits>::FunctionState::FunctionState(
1596 FunctionState** function_state_stack, 1582 FunctionState** function_state_stack,
1597 typename Traits::Type::Scope** scope_stack, 1583 typename Traits::Type::Scope** scope_stack,
1598 typename Traits::Type::Scope** scope, typename Traits::Type::Zone* zone, 1584 typename Traits::Type::Scope** scope,
1599 AstValueFactory* ast_value_factory, AstNode::IdGen* ast_node_id_gen) 1585 typename Traits::Type::Factory* factory)
1600 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), 1586 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize),
1601 next_handler_index_(0), 1587 next_handler_index_(0),
1602 expected_property_count_(0), 1588 expected_property_count_(0),
1603 is_generator_(false), 1589 is_generator_(false),
1604 generator_object_variable_(NULL), 1590 generator_object_variable_(NULL),
1605 function_state_stack_(function_state_stack), 1591 function_state_stack_(function_state_stack),
1606 outer_function_state_(*function_state_stack), 1592 outer_function_state_(*function_state_stack),
1607 scope_stack_(scope_stack), 1593 scope_stack_(scope_stack),
1608 outer_scope_(*scope_stack), 1594 outer_scope_(*scope_stack),
1609 ast_node_id_gen_(ast_node_id_gen), 1595 factory_(factory) {
1610 factory_(zone, ast_value_factory, ast_node_id_gen) {
1611 *scope_stack_ = *scope; 1596 *scope_stack_ = *scope;
1612 *function_state_stack = this; 1597 *function_state_stack = this;
1613 Traits::SetUpFunctionState(this);
1614 } 1598 }
1615 1599
1616 1600
1617 template <class Traits> 1601 template <class Traits>
1618 ParserBase<Traits>::FunctionState::~FunctionState() { 1602 ParserBase<Traits>::FunctionState::~FunctionState() {
1619 *scope_stack_ = outer_scope_; 1603 *scope_stack_ = outer_scope_;
1620 *function_state_stack_ = outer_function_state_; 1604 *function_state_stack_ = outer_function_state_;
1621 Traits::TearDownFunctionState(this);
1622 } 1605 }
1623 1606
1624 1607
1625 template<class Traits> 1608 template<class Traits>
1626 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { 1609 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) {
1627 Scanner::Location source_location = scanner()->location(); 1610 Scanner::Location source_location = scanner()->location();
1628 1611
1629 // Four of the tokens are treated specially 1612 // Four of the tokens are treated specially
1630 switch (token) { 1613 switch (token) {
1631 case Token::EOS: 1614 case Token::EOS:
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
2644 this->NewScope(scope_, FUNCTION_SCOPE); 2627 this->NewScope(scope_, FUNCTION_SCOPE);
2645 typename Traits::Type::StatementList body; 2628 typename Traits::Type::StatementList body;
2646 typename Traits::Type::AstProperties ast_properties; 2629 typename Traits::Type::AstProperties ast_properties;
2647 BailoutReason dont_optimize_reason = kNoReason; 2630 BailoutReason dont_optimize_reason = kNoReason;
2648 int num_parameters = -1; 2631 int num_parameters = -1;
2649 int materialized_literal_count = -1; 2632 int materialized_literal_count = -1;
2650 int expected_property_count = -1; 2633 int expected_property_count = -1;
2651 int handler_count = 0; 2634 int handler_count = 0;
2652 2635
2653 { 2636 {
2654 FunctionState function_state(&function_state_, &scope_, &scope, zone(), 2637 typename Traits::Type::Factory function_factory(
2655 this->ast_value_factory(), ast_node_id_gen_); 2638 zone(), this->ast_value_factory(), ast_node_id_gen_);
2639 FunctionState function_state(&function_state_, &scope_, &scope,
2640 &function_factory);
2656 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); 2641 Scanner::Location dupe_error_loc = Scanner::Location::invalid();
2657 num_parameters = Traits::DeclareArrowParametersFromExpression( 2642 num_parameters = Traits::DeclareArrowParametersFromExpression(
2658 params_ast, scope_, &dupe_error_loc, ok); 2643 params_ast, scope_, &dupe_error_loc, ok);
2659 if (!*ok) { 2644 if (!*ok) {
2660 ReportMessageAt( 2645 ReportMessageAt(
2661 Scanner::Location(start_pos, scanner()->location().beg_pos), 2646 Scanner::Location(start_pos, scanner()->location().beg_pos),
2662 "malformed_arrow_function_parameter_list"); 2647 "malformed_arrow_function_parameter_list");
2663 return this->EmptyExpression(); 2648 return this->EmptyExpression();
2664 } 2649 }
2665 2650
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2864 DCHECK(IsAccessorAccessorConflict(old_type, type)); 2849 DCHECK(IsAccessorAccessorConflict(old_type, type));
2865 // Both accessors of the same type. 2850 // Both accessors of the same type.
2866 parser()->ReportMessage("accessor_get_set"); 2851 parser()->ReportMessage("accessor_get_set");
2867 } 2852 }
2868 *ok = false; 2853 *ok = false;
2869 } 2854 }
2870 } 2855 }
2871 } } // v8::internal 2856 } } // v8::internal
2872 2857
2873 #endif // V8_PREPARSER_H 2858 #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