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

Side by Side Diff: src/preparser.h

Issue 663373003: Assign bailout and type feedback IDs in a post-pass (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 PreParserScope* operator->() { return this; } 961 PreParserScope* operator->() { return this; }
966 962
967 private: 963 private:
968 ScopeType scope_type_; 964 ScopeType scope_type_;
969 StrictMode strict_mode_; 965 StrictMode strict_mode_;
970 }; 966 };
971 967
972 968
973 class PreParserFactory { 969 class PreParserFactory {
974 public: 970 public:
975 PreParserFactory(void*, void*, void*) {} 971 explicit PreParserFactory(void* unused_value_factory) {}
976 PreParserExpression NewStringLiteral(PreParserIdentifier identifier, 972 PreParserExpression NewStringLiteral(PreParserIdentifier identifier,
977 int pos) { 973 int pos) {
978 return PreParserExpression::Default(); 974 return PreParserExpression::Default();
979 } 975 }
980 PreParserExpression NewNumberLiteral(double number, 976 PreParserExpression NewNumberLiteral(double number,
981 int pos) { 977 int pos) {
982 return PreParserExpression::Default(); 978 return PreParserExpression::Default();
983 } 979 }
984 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern, 980 PreParserExpression NewRegExpLiteral(PreParserIdentifier js_pattern,
985 PreParserIdentifier js_flags, 981 PreParserIdentifier js_flags,
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 typedef PreParserIdentifier Identifier; 1406 typedef PreParserIdentifier Identifier;
1411 typedef PreParserExpression Expression; 1407 typedef PreParserExpression Expression;
1412 typedef PreParserStatement Statement; 1408 typedef PreParserStatement Statement;
1413 1409
1414 enum PreParseResult { 1410 enum PreParseResult {
1415 kPreParseStackOverflow, 1411 kPreParseStackOverflow,
1416 kPreParseSuccess 1412 kPreParseSuccess
1417 }; 1413 };
1418 1414
1419 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit) 1415 PreParser(Scanner* scanner, ParserRecorder* log, uintptr_t stack_limit)
1420 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL, NULL, 1416 : ParserBase<PreParserTraits>(scanner, stack_limit, NULL, log, NULL,
1421 this) {} 1417 this) {}
1422 1418
1423 // Pre-parse the program from the character stream; returns true on 1419 // Pre-parse the program from the character stream; returns true on
1424 // success (even if parsing failed, the pre-parse data successfully 1420 // success (even if parsing failed, the pre-parse data successfully
1425 // captured the syntax error), and false if a stack-overflow happened 1421 // captured the syntax error), and false if a stack-overflow happened
1426 // during parsing. 1422 // during parsing.
1427 PreParseResult PreParseProgram() { 1423 PreParseResult PreParseProgram() {
1428 PreParserScope scope(scope_, GLOBAL_SCOPE); 1424 PreParserScope scope(scope_, GLOBAL_SCOPE);
1429 PreParserFactory factory(NULL, NULL, NULL); 1425 PreParserFactory factory(NULL);
1430 FunctionState top_scope(&function_state_, &scope_, &scope, &factory); 1426 FunctionState top_scope(&function_state_, &scope_, &scope, &factory);
1431 bool ok = true; 1427 bool ok = true;
1432 int start_position = scanner()->peek_location().beg_pos; 1428 int start_position = scanner()->peek_location().beg_pos;
1433 ParseSourceElements(Token::EOS, &ok); 1429 ParseSourceElements(Token::EOS, &ok);
1434 if (stack_overflow()) return kPreParseStackOverflow; 1430 if (stack_overflow()) return kPreParseStackOverflow;
1435 if (!ok) { 1431 if (!ok) {
1436 ReportUnexpectedToken(scanner()->current_token()); 1432 ReportUnexpectedToken(scanner()->current_token());
1437 } else if (scope_->strict_mode() == STRICT) { 1433 } else if (scope_->strict_mode() == STRICT) {
1438 CheckOctalLiteral(start_position, scanner()->location().end_pos, &ok); 1434 CheckOctalLiteral(start_position, scanner()->location().end_pos, &ok);
1439 } 1435 }
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2609 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, ARROW_SCOPE); 2605 typename Traits::Type::ScopePtr scope = this->NewScope(scope_, ARROW_SCOPE);
2610 typename Traits::Type::StatementList body; 2606 typename Traits::Type::StatementList body;
2611 typename Traits::Type::AstProperties ast_properties; 2607 typename Traits::Type::AstProperties ast_properties;
2612 BailoutReason dont_optimize_reason = kNoReason; 2608 BailoutReason dont_optimize_reason = kNoReason;
2613 int num_parameters = -1; 2609 int num_parameters = -1;
2614 int materialized_literal_count = -1; 2610 int materialized_literal_count = -1;
2615 int expected_property_count = -1; 2611 int expected_property_count = -1;
2616 int handler_count = 0; 2612 int handler_count = 0;
2617 2613
2618 { 2614 {
2619 typename Traits::Type::Factory function_factory( 2615 typename Traits::Type::Factory function_factory(this->ast_value_factory());
2620 zone(), this->ast_value_factory(), ast_node_id_gen_);
2621 FunctionState function_state(&function_state_, &scope_, 2616 FunctionState function_state(&function_state_, &scope_,
2622 Traits::Type::ptr_to_scope(scope), 2617 Traits::Type::ptr_to_scope(scope),
2623 &function_factory); 2618 &function_factory);
2624 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); 2619 Scanner::Location dupe_error_loc = Scanner::Location::invalid();
2625 num_parameters = Traits::DeclareArrowParametersFromExpression( 2620 num_parameters = Traits::DeclareArrowParametersFromExpression(
2626 params_ast, scope_, &dupe_error_loc, ok); 2621 params_ast, scope_, &dupe_error_loc, ok);
2627 if (!*ok) { 2622 if (!*ok) {
2628 ReportMessageAt( 2623 ReportMessageAt(
2629 Scanner::Location(start_pos, scanner()->location().beg_pos), 2624 Scanner::Location(start_pos, scanner()->location().beg_pos),
2630 "malformed_arrow_function_parameter_list"); 2625 "malformed_arrow_function_parameter_list");
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
2832 DCHECK(IsAccessorAccessorConflict(old_type, type)); 2827 DCHECK(IsAccessorAccessorConflict(old_type, type));
2833 // Both accessors of the same type. 2828 // Both accessors of the same type.
2834 parser()->ReportMessage("accessor_get_set"); 2829 parser()->ReportMessage("accessor_get_set");
2835 } 2830 }
2836 *ok = false; 2831 *ok = false;
2837 } 2832 }
2838 } 2833 }
2839 } } // v8::internal 2834 } } // v8::internal
2840 2835
2841 #endif // V8_PREPARSER_H 2836 #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