| OLD | NEW | 
|     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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   231       DCHECK(is_generator()); |   231       DCHECK(is_generator()); | 
|   232       generator_object_variable_ = variable; |   232       generator_object_variable_ = variable; | 
|   233     } |   233     } | 
|   234     typename Traits::Type::GeneratorVariable* generator_object_variable() |   234     typename Traits::Type::GeneratorVariable* generator_object_variable() | 
|   235         const { |   235         const { | 
|   236       return generator_object_variable_; |   236       return generator_object_variable_; | 
|   237     } |   237     } | 
|   238  |   238  | 
|   239     typename Traits::Type::Factory* factory() { return factory_; } |   239     typename Traits::Type::Factory* factory() { return factory_; } | 
|   240  |   240  | 
 |   241     void set_consecutive_class_declaration_batch_start(int position) { | 
 |   242       consecutive_class_declaration_batch_start_ = position; | 
 |   243     } | 
 |   244  | 
 |   245     int consecutive_class_declaration_batch_start() const { | 
 |   246       return consecutive_class_declaration_batch_start_; | 
 |   247     } | 
 |   248  | 
|   241    private: |   249    private: | 
|   242     // Used to assign an index to each literal that needs materialization in |   250     // Used to assign an index to each literal that needs materialization in | 
|   243     // the function.  Includes regexp literals, and boilerplate for object and |   251     // the function.  Includes regexp literals, and boilerplate for object and | 
|   244     // array literals. |   252     // array literals. | 
|   245     int next_materialized_literal_index_; |   253     int next_materialized_literal_index_; | 
|   246  |   254  | 
|   247     // Used to assign a per-function index to try and catch handlers. |   255     // Used to assign a per-function index to try and catch handlers. | 
|   248     int next_handler_index_; |   256     int next_handler_index_; | 
|   249  |   257  | 
|   250     // Properties count estimation. |   258     // Properties count estimation. | 
|   251     int expected_property_count_; |   259     int expected_property_count_; | 
|   252  |   260  | 
|   253     // Location of most recent 'return' statement (invalid if none). |   261     // Location of most recent 'return' statement (invalid if none). | 
|   254     Scanner::Location return_location_; |   262     Scanner::Location return_location_; | 
|   255  |   263  | 
|   256     // Location of call to the "super" constructor (invalid if none). |   264     // Location of call to the "super" constructor (invalid if none). | 
|   257     Scanner::Location super_call_location_; |   265     Scanner::Location super_call_location_; | 
|   258  |   266  | 
|   259     FunctionKind kind_; |   267     FunctionKind kind_; | 
|   260     // For generators, this variable may hold the generator object. It variable |   268     // For generators, this variable may hold the generator object. It variable | 
|   261     // is used by yield expressions and return statements. It is not necessary |   269     // is used by yield expressions and return statements. It is not necessary | 
|   262     // for generator functions to have this variable set. |   270     // for generator functions to have this variable set. | 
|   263     Variable* generator_object_variable_; |   271     Variable* generator_object_variable_; | 
|   264  |   272  | 
|   265     FunctionState** function_state_stack_; |   273     FunctionState** function_state_stack_; | 
|   266     FunctionState* outer_function_state_; |   274     FunctionState* outer_function_state_; | 
|   267     Scope** scope_stack_; |   275     Scope** scope_stack_; | 
|   268     Scope* outer_scope_; |   276     Scope* outer_scope_; | 
|   269     typename Traits::Type::Factory* factory_; |   277     typename Traits::Type::Factory* factory_; | 
 |   278     // For tracking which classes are declared consecutively. Needed for strong | 
 |   279     // mode. | 
 |   280     int consecutive_class_declaration_batch_start_; | 
|   270  |   281  | 
|   271     friend class ParserTraits; |   282     friend class ParserTraits; | 
|   272     friend class Checkpoint; |   283     friend class Checkpoint; | 
|   273   }; |   284   }; | 
|   274  |   285  | 
|   275   // Annoyingly, arrow functions first parse as comma expressions, then when we |   286   // Annoyingly, arrow functions first parse as comma expressions, then when we | 
|   276   // see the => we have to go back and reinterpret the arguments as being formal |   287   // see the => we have to go back and reinterpret the arguments as being formal | 
|   277   // parameters.  To do so we need to reset some of the parser state back to |   288   // parameters.  To do so we need to reset some of the parser state back to | 
|   278   // what it was before the arguments were first seen. |   289   // what it was before the arguments were first seen. | 
|   279   class Checkpoint BASE_EMBEDDED { |   290   class Checkpoint BASE_EMBEDDED { | 
| (...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1625   // success (even if parsing failed, the pre-parse data successfully |  1636   // success (even if parsing failed, the pre-parse data successfully | 
|  1626   // captured the syntax error), and false if a stack-overflow happened |  1637   // captured the syntax error), and false if a stack-overflow happened | 
|  1627   // during parsing. |  1638   // during parsing. | 
|  1628   PreParseResult PreParseProgram(int* materialized_literals = 0) { |  1639   PreParseResult PreParseProgram(int* materialized_literals = 0) { | 
|  1629     Scope* scope = NewScope(scope_, SCRIPT_SCOPE); |  1640     Scope* scope = NewScope(scope_, SCRIPT_SCOPE); | 
|  1630     PreParserFactory factory(NULL); |  1641     PreParserFactory factory(NULL); | 
|  1631     FunctionState top_scope(&function_state_, &scope_, scope, kNormalFunction, |  1642     FunctionState top_scope(&function_state_, &scope_, scope, kNormalFunction, | 
|  1632                             &factory); |  1643                             &factory); | 
|  1633     bool ok = true; |  1644     bool ok = true; | 
|  1634     int start_position = scanner()->peek_location().beg_pos; |  1645     int start_position = scanner()->peek_location().beg_pos; | 
 |  1646     top_scope.set_consecutive_class_declaration_batch_start(start_position); | 
|  1635     ParseStatementList(Token::EOS, &ok); |  1647     ParseStatementList(Token::EOS, &ok); | 
|  1636     if (stack_overflow()) return kPreParseStackOverflow; |  1648     if (stack_overflow()) return kPreParseStackOverflow; | 
|  1637     if (!ok) { |  1649     if (!ok) { | 
|  1638       ReportUnexpectedToken(scanner()->current_token()); |  1650       ReportUnexpectedToken(scanner()->current_token()); | 
|  1639     } else if (is_strict(scope_->language_mode())) { |  1651     } else if (is_strict(scope_->language_mode())) { | 
|  1640       CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, |  1652       CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, | 
|  1641                               &ok); |  1653                               &ok); | 
|  1642     } |  1654     } | 
|  1643     if (materialized_literals) { |  1655     if (materialized_literals) { | 
|  1644       *materialized_literals = function_state_->materialized_literal_count(); |  1656       *materialized_literals = function_state_->materialized_literal_count(); | 
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1777       next_handler_index_(0), |  1789       next_handler_index_(0), | 
|  1778       expected_property_count_(0), |  1790       expected_property_count_(0), | 
|  1779       return_location_(Scanner::Location::invalid()), |  1791       return_location_(Scanner::Location::invalid()), | 
|  1780       super_call_location_(Scanner::Location::invalid()), |  1792       super_call_location_(Scanner::Location::invalid()), | 
|  1781       kind_(kind), |  1793       kind_(kind), | 
|  1782       generator_object_variable_(NULL), |  1794       generator_object_variable_(NULL), | 
|  1783       function_state_stack_(function_state_stack), |  1795       function_state_stack_(function_state_stack), | 
|  1784       outer_function_state_(*function_state_stack), |  1796       outer_function_state_(*function_state_stack), | 
|  1785       scope_stack_(scope_stack), |  1797       scope_stack_(scope_stack), | 
|  1786       outer_scope_(*scope_stack), |  1798       outer_scope_(*scope_stack), | 
|  1787       factory_(factory) { |  1799       factory_(factory), | 
 |  1800       consecutive_class_declaration_batch_start_(scope->start_position()) { | 
|  1788   *scope_stack_ = scope; |  1801   *scope_stack_ = scope; | 
|  1789   *function_state_stack = this; |  1802   *function_state_stack = this; | 
|  1790 } |  1803 } | 
|  1791  |  1804  | 
|  1792  |  1805  | 
|  1793 template <class Traits> |  1806 template <class Traits> | 
|  1794 ParserBase<Traits>::FunctionState::~FunctionState() { |  1807 ParserBase<Traits>::FunctionState::~FunctionState() { | 
|  1795   *scope_stack_ = outer_scope_; |  1808   *scope_stack_ = outer_scope_; | 
|  1796   *function_state_stack_ = outer_function_state_; |  1809   *function_state_stack_ = outer_function_state_; | 
|  1797 } |  1810 } | 
| (...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  3085     } |  3098     } | 
|  3086     if (num_parameters > Code::kMaxArguments) { |  3099     if (num_parameters > Code::kMaxArguments) { | 
|  3087       ReportMessageAt(Scanner::Location(params_ast->position(), position()), |  3100       ReportMessageAt(Scanner::Location(params_ast->position(), position()), | 
|  3088                       "too_many_parameters"); |  3101                       "too_many_parameters"); | 
|  3089       *ok = false; |  3102       *ok = false; | 
|  3090       return this->EmptyExpression(); |  3103       return this->EmptyExpression(); | 
|  3091     } |  3104     } | 
|  3092  |  3105  | 
|  3093     Expect(Token::ARROW, CHECK_OK); |  3106     Expect(Token::ARROW, CHECK_OK); | 
|  3094  |  3107  | 
 |  3108     function_state.set_consecutive_class_declaration_batch_start( | 
 |  3109         scanner()->location().beg_pos); | 
|  3095     if (peek() == Token::LBRACE) { |  3110     if (peek() == Token::LBRACE) { | 
|  3096       // Multiple statement body |  3111       // Multiple statement body | 
|  3097       Consume(Token::LBRACE); |  3112       Consume(Token::LBRACE); | 
|  3098       bool is_lazily_parsed = |  3113       bool is_lazily_parsed = | 
|  3099           (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); |  3114           (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); | 
|  3100       if (is_lazily_parsed) { |  3115       if (is_lazily_parsed) { | 
|  3101         body = this->NewStatementList(0, zone()); |  3116         body = this->NewStatementList(0, zone()); | 
|  3102         this->SkipLazyFunctionBody(this->EmptyIdentifier(), |  3117         this->SkipLazyFunctionBody(this->EmptyIdentifier(), | 
|  3103                                    &materialized_literal_count, |  3118                                    &materialized_literal_count, | 
|  3104                                    &expected_property_count, CHECK_OK); |  3119                                    &expected_property_count, CHECK_OK); | 
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  3341       *ok = false; |  3356       *ok = false; | 
|  3342       return; |  3357       return; | 
|  3343     } |  3358     } | 
|  3344     has_seen_constructor_ = true; |  3359     has_seen_constructor_ = true; | 
|  3345     return; |  3360     return; | 
|  3346   } |  3361   } | 
|  3347 } |  3362 } | 
|  3348 } }  // v8::internal |  3363 } }  // v8::internal | 
|  3349  |  3364  | 
|  3350 #endif  // V8_PREPARSER_H |  3365 #endif  // V8_PREPARSER_H | 
| OLD | NEW |