| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 public: | 63 public: |
| 64 // Shorten type names defined by Traits. | 64 // Shorten type names defined by Traits. |
| 65 typedef typename Traits::Type::Expression ExpressionT; | 65 typedef typename Traits::Type::Expression ExpressionT; |
| 66 typedef typename Traits::Type::Identifier IdentifierT; | 66 typedef typename Traits::Type::Identifier IdentifierT; |
| 67 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; | 67 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; |
| 68 typedef typename Traits::Type::Literal LiteralT; | 68 typedef typename Traits::Type::Literal LiteralT; |
| 69 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; | 69 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; |
| 70 | 70 |
| 71 ParserBase(Scanner* scanner, uintptr_t stack_limit, v8::Extension* extension, | 71 ParserBase(Scanner* scanner, uintptr_t stack_limit, v8::Extension* extension, |
| 72 ParserRecorder* log, typename Traits::Type::Zone* zone, | 72 ParserRecorder* log, typename Traits::Type::Zone* zone, |
| 73 AstNode::IdGen* ast_node_id_gen, | |
| 74 typename Traits::Type::Parser this_object) | 73 typename Traits::Type::Parser this_object) |
| 75 : Traits(this_object), | 74 : Traits(this_object), |
| 76 parenthesized_function_(false), | 75 parenthesized_function_(false), |
| 77 scope_(NULL), | 76 scope_(NULL), |
| 78 function_state_(NULL), | 77 function_state_(NULL), |
| 79 extension_(extension), | 78 extension_(extension), |
| 80 fni_(NULL), | 79 fni_(NULL), |
| 81 log_(log), | 80 log_(log), |
| 82 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | 81 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
| 83 stack_limit_(stack_limit), | 82 stack_limit_(stack_limit), |
| 84 scanner_(scanner), | 83 scanner_(scanner), |
| 85 stack_overflow_(false), | 84 stack_overflow_(false), |
| 86 allow_lazy_(false), | 85 allow_lazy_(false), |
| 87 allow_natives_syntax_(false), | 86 allow_natives_syntax_(false), |
| 88 allow_arrow_functions_(false), | 87 allow_arrow_functions_(false), |
| 89 allow_harmony_object_literals_(false), | 88 allow_harmony_object_literals_(false), |
| 90 zone_(zone), | 89 zone_(zone) {} |
| 91 ast_node_id_gen_(ast_node_id_gen) {} | |
| 92 | 90 |
| 93 // Getters that indicate whether certain syntactical constructs are | 91 // Getters that indicate whether certain syntactical constructs are |
| 94 // allowed to be parsed by this instance of the parser. | 92 // allowed to be parsed by this instance of the parser. |
| 95 bool allow_lazy() const { return allow_lazy_; } | 93 bool allow_lazy() const { return allow_lazy_; } |
| 96 bool allow_natives_syntax() const { return allow_natives_syntax_; } | 94 bool allow_natives_syntax() const { return allow_natives_syntax_; } |
| 97 bool allow_arrow_functions() const { return allow_arrow_functions_; } | 95 bool allow_arrow_functions() const { return allow_arrow_functions_; } |
| 98 bool allow_modules() const { return scanner()->HarmonyModules(); } | 96 bool allow_modules() const { return scanner()->HarmonyModules(); } |
| 99 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } | 97 bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); } |
| 100 bool allow_harmony_numeric_literals() const { | 98 bool allow_harmony_numeric_literals() const { |
| 101 return scanner()->HarmonyNumericLiterals(); | 99 return scanner()->HarmonyNumericLiterals(); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 Mode old_mode_; | 268 Mode old_mode_; |
| 271 }; | 269 }; |
| 272 | 270 |
| 273 Scanner* scanner() const { return scanner_; } | 271 Scanner* scanner() const { return scanner_; } |
| 274 int position() { return scanner_->location().beg_pos; } | 272 int position() { return scanner_->location().beg_pos; } |
| 275 int peek_position() { return scanner_->peek_location().beg_pos; } | 273 int peek_position() { return scanner_->peek_location().beg_pos; } |
| 276 bool stack_overflow() const { return stack_overflow_; } | 274 bool stack_overflow() const { return stack_overflow_; } |
| 277 void set_stack_overflow() { stack_overflow_ = true; } | 275 void set_stack_overflow() { stack_overflow_ = true; } |
| 278 Mode mode() const { return mode_; } | 276 Mode mode() const { return mode_; } |
| 279 typename Traits::Type::Zone* zone() const { return zone_; } | 277 typename Traits::Type::Zone* zone() const { return zone_; } |
| 280 AstNode::IdGen* ast_node_id_gen() const { return ast_node_id_gen_; } | |
| 281 | 278 |
| 282 INLINE(Token::Value peek()) { | 279 INLINE(Token::Value peek()) { |
| 283 if (stack_overflow_) return Token::ILLEGAL; | 280 if (stack_overflow_) return Token::ILLEGAL; |
| 284 return scanner()->peek(); | 281 return scanner()->peek(); |
| 285 } | 282 } |
| 286 | 283 |
| 287 INLINE(Token::Value Next()) { | 284 INLINE(Token::Value Next()) { |
| 288 if (stack_overflow_) return Token::ILLEGAL; | 285 if (stack_overflow_) return Token::ILLEGAL; |
| 289 { | 286 { |
| 290 if (GetCurrentStackPosition() < stack_limit_) { | 287 if (GetCurrentStackPosition() < stack_limit_) { |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 private: | 570 private: |
| 574 Scanner* scanner_; | 571 Scanner* scanner_; |
| 575 bool stack_overflow_; | 572 bool stack_overflow_; |
| 576 | 573 |
| 577 bool allow_lazy_; | 574 bool allow_lazy_; |
| 578 bool allow_natives_syntax_; | 575 bool allow_natives_syntax_; |
| 579 bool allow_arrow_functions_; | 576 bool allow_arrow_functions_; |
| 580 bool allow_harmony_object_literals_; | 577 bool allow_harmony_object_literals_; |
| 581 | 578 |
| 582 typename Traits::Type::Zone* zone_; // Only used by Parser. | 579 typename Traits::Type::Zone* zone_; // Only used by Parser. |
| 583 AstNode::IdGen* ast_node_id_gen_; | |
| 584 }; | 580 }; |
| 585 | 581 |
| 586 | 582 |
| 587 class PreParserIdentifier { | 583 class PreParserIdentifier { |
| 588 public: | 584 public: |
| 589 PreParserIdentifier() : type_(kUnknownIdentifier) {} | 585 PreParserIdentifier() : type_(kUnknownIdentifier) {} |
| 590 static PreParserIdentifier Default() { | 586 static PreParserIdentifier Default() { |
| 591 return PreParserIdentifier(kUnknownIdentifier); | 587 return PreParserIdentifier(kUnknownIdentifier); |
| 592 } | 588 } |
| 593 static PreParserIdentifier Eval() { | 589 static PreParserIdentifier Eval() { |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 PreParserScope* operator->() { return this; } | 957 PreParserScope* operator->() { return this; } |
| 962 | 958 |
| 963 private: | 959 private: |
| 964 ScopeType scope_type_; | 960 ScopeType scope_type_; |
| 965 StrictMode strict_mode_; | 961 StrictMode strict_mode_; |
| 966 }; | 962 }; |
| 967 | 963 |
| 968 | 964 |
| 969 class PreParserFactory { | 965 class PreParserFactory { |
| 970 public: | 966 public: |
| 971 PreParserFactory(void*, void*, void*) {} | 967 PreParserFactory(void*, void*) {} |
| 972 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, | 968 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, |
| 973 int pos) { | 969 int pos) { |
| 974 return PreParserExpression::Default(); | 970 return PreParserExpression::Default(); |
| 975 } | 971 } |
| 976 PreParserExpression NewNumberLiteral(double number, | 972 PreParserExpression NewNumberLiteral(double number, |
| 977 int pos) { | 973 int pos) { |
| 978 return PreParserExpression::Default(); | 974 return PreParserExpression::Default(); |
| 979 } | 975 } |
| 980 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, | 976 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, |
| 981 PreParserIdentifier js_flags, | 977 PreParserIdentifier js_flags, |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1406 typedef PreParserIdentifier Identifier; | 1402 typedef PreParserIdentifier Identifier; |
| 1407 typedef PreParserExpression Expression; | 1403 typedef PreParserExpression Expression; |
| 1408 typedef PreParserStatement Statement; | 1404 typedef PreParserStatement Statement; |
| 1409 | 1405 |
| 1410 enum PreParseResult { | 1406 enum PreParseResult { |
| 1411 kPreParseStackOverflow, | 1407 kPreParseStackOverflow, |
| 1412 kPreParseSuccess | 1408 kPreParseSuccess |
| 1413 }; | 1409 }; |
| 1414 | 1410 |
| 1415 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit) | 1411 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit) |
| 1416 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, NULL, | 1412 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, |
| 1417 this) {} | 1413 this) {} |
| 1418 | 1414 |
| 1419 // Pre-parse the program from the character stream; returns true on | 1415 // Pre-parse the program from the character stream; returns true on |
| 1420 // success (even if parsing failed, the pre-parse data successfully | 1416 // success (even if parsing failed, the pre-parse data successfully |
| 1421 // captured the syntax error), and false if a stack-overflow happened | 1417 // captured the syntax error), and false if a stack-overflow happened |
| 1422 // during parsing. | 1418 // during parsing. |
| 1423 PreParseResult PreParseProgram() { | 1419 PreParseResult PreParseProgram() { |
| 1424 PreParserScope scope(scope_, GLOBAL_SCOPE); | 1420 PreParserScope scope(scope_, GLOBAL_SCOPE); |
| 1425 PreParserFactory factory(NULL, NULL, NULL); | 1421 PreParserFactory factory(NULL, NULL); |
| 1426 FunctionState top_scope(&function_state_, &scope_, &scope, &factory); | 1422 FunctionState top_scope(&function_state_, &scope_, &scope, &factory); |
| 1427 bool ok = true; | 1423 bool ok = true; |
| 1428 int start_position = scanner()->peek_location().beg_pos; | 1424 int start_position = scanner()->peek_location().beg_pos; |
| 1429 ParseSourceElements(Token::EOS, &ok); | 1425 ParseSourceElements(Token::EOS, &ok); |
| 1430 if (stack_overflow()) return kPreParseStackOverflow; | 1426 if (stack_overflow()) return kPreParseStackOverflow; |
| 1431 if (!ok) { | 1427 if (!ok) { |
| 1432 ReportUnexpectedToken(scanner()->current_token()); | 1428 ReportUnexpectedToken(scanner()->current_token()); |
| 1433 } else if (scope_->strict_mode() == STRICT) { | 1429 } else if (scope_->strict_mode() == STRICT) { |
| 1434 CheckOctalLiteral(start_position, scanner()->location().end_pos, &ok); | 1430 CheckOctalLiteral(start_position, scanner()->location().end_pos, &ok); |
| 1435 } | 1431 } |
| (...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2596 this->NewScope(scope_, FUNCTION_SCOPE); | 2592 this->NewScope(scope_, FUNCTION_SCOPE); |
| 2597 typename Traits::Type::StatementList body; | 2593 typename Traits::Type::StatementList body; |
| 2598 typename Traits::Type::AstProperties ast_properties; | 2594 typename Traits::Type::AstProperties ast_properties; |
| 2599 BailoutReason dont_optimize_reason = kNoReason; | 2595 BailoutReason dont_optimize_reason = kNoReason; |
| 2600 int num_parameters = -1; | 2596 int num_parameters = -1; |
| 2601 int materialized_literal_count = -1; | 2597 int materialized_literal_count = -1; |
| 2602 int expected_property_count = -1; | 2598 int expected_property_count = -1; |
| 2603 int handler_count = 0; | 2599 int handler_count = 0; |
| 2604 | 2600 |
| 2605 { | 2601 { |
| 2606 typename Traits::Type::Factory function_factory( | 2602 typename Traits::Type::Factory function_factory(zone(), |
| 2607 zone(), this->ast_value_factory(), ast_node_id_gen_); | 2603 this->ast_value_factory()); |
| 2608 FunctionState function_state(&function_state_, &scope_, | 2604 FunctionState function_state(&function_state_, &scope_, |
| 2609 Traits::Type::ptr_to_scope(scope), | 2605 Traits::Type::ptr_to_scope(scope), |
| 2610 &function_factory); | 2606 &function_factory); |
| 2611 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); | 2607 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); |
| 2612 num_parameters = Traits::DeclareArrowParametersFromExpression( | 2608 num_parameters = Traits::DeclareArrowParametersFromExpression( |
| 2613 params_ast, scope_, &dupe_error_loc, ok); | 2609 params_ast, scope_, &dupe_error_loc, ok); |
| 2614 if (!*ok) { | 2610 if (!*ok) { |
| 2615 ReportMessageAt( | 2611 ReportMessageAt( |
| 2616 Scanner::Location(start_pos, scanner()->location().beg_pos), | 2612 Scanner::Location(start_pos, scanner()->location().beg_pos), |
| 2617 "malformed_arrow_function_parameter_list"); | 2613 "malformed_arrow_function_parameter_list"); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2819 DCHECK(IsAccessorAccessorConflict(old_type, type)); | 2815 DCHECK(IsAccessorAccessorConflict(old_type, type)); |
| 2820 // Both accessors of the same type. | 2816 // Both accessors of the same type. |
| 2821 parser()->ReportMessage("accessor_get_set"); | 2817 parser()->ReportMessage("accessor_get_set"); |
| 2822 } | 2818 } |
| 2823 *ok = false; | 2819 *ok = false; |
| 2824 } | 2820 } |
| 2825 } | 2821 } |
| 2826 } } // v8::internal | 2822 } } // v8::internal |
| 2827 | 2823 |
| 2828 #endif // V8_PREPARSER_H | 2824 #endif // V8_PREPARSER_H |
| OLD | NEW |