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

Side by Side Diff: src/preparser.h

Issue 8662037: Don't preparse large files to find boundaries of lazy functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 1 month 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 }; 103 };
104 104
105 105
106 class PreParser { 106 class PreParser {
107 public: 107 public:
108 enum PreParseResult { 108 enum PreParseResult {
109 kPreParseStackOverflow, 109 kPreParseStackOverflow,
110 kPreParseSuccess 110 kPreParseSuccess
111 }; 111 };
112 112
113
114 PreParser(i::Scanner* scanner,
115 i::ParserRecorder* log,
116 uintptr_t stack_limit,
117 bool allow_lazy,
118 bool allow_natives_syntax)
119 : scanner_(scanner),
120 log_(log),
121 scope_(NULL),
122 stack_limit_(stack_limit),
123 strict_mode_violation_location_(i::Scanner::Location::invalid()),
124 strict_mode_violation_type_(NULL),
125 stack_overflow_(false),
126 allow_lazy_(allow_lazy),
127 allow_natives_syntax_(allow_natives_syntax),
128 parenthesized_function_(false),
129 harmony_scoping_(scanner->HarmonyScoping()) { }
130
113 ~PreParser() {} 131 ~PreParser() {}
114 132
115 // Pre-parse the program from the character stream; returns true on 133 // Pre-parse the program from the character stream; returns true on
116 // success (even if parsing failed, the pre-parse data successfully 134 // success (even if parsing failed, the pre-parse data successfully
117 // captured the syntax error), and false if a stack-overflow happened 135 // captured the syntax error), and false if a stack-overflow happened
118 // during parsing. 136 // during parsing.
119 static PreParseResult PreParseProgram(i::Scanner* scanner, 137 static PreParseResult PreParseProgram(i::Scanner* scanner,
120 i::ParserRecorder* log, 138 i::ParserRecorder* log,
121 int flags, 139 int flags,
122 uintptr_t stack_limit) { 140 uintptr_t stack_limit) {
123 bool allow_lazy = (flags & i::kAllowLazy) != 0; 141 bool allow_lazy = (flags & i::kAllowLazy) != 0;
124 bool allow_natives_syntax = (flags & i::kAllowNativesSyntax) != 0; 142 bool allow_natives_syntax = (flags & i::kAllowNativesSyntax) != 0;
125 return PreParser(scanner, log, stack_limit, 143 return PreParser(scanner, log, stack_limit,
126 allow_lazy, allow_natives_syntax).PreParse(); 144 allow_lazy, allow_natives_syntax).PreParse();
127 } 145 }
128 146
147 // Parses a single function literal, from the opening parentheses before
148 // parameters to the closing brace after the body.
149 // Returns a FunctionEntry describing the body of the funciton in enough
150 // detail that it can be lazily compiled.
151 // The scanner is expected to have matched the "function" keyword and
152 // parameters, and have consumed the initial '{'.
153 // At return, unless an error occured, the scanner is positioned before the
154 // the final '}'.
155 PreParseResult PreParseLazyFunction(bool strict_mode,
156 i::ParserRecorder* log);
157
129 private: 158 private:
130 // Used to detect duplicates in object literals. Each of the values 159 // Used to detect duplicates in object literals. Each of the values
131 // kGetterProperty, kSetterProperty and kValueProperty represents 160 // kGetterProperty, kSetterProperty and kValueProperty represents
132 // a type of object literal property. When parsing a property, its 161 // a type of object literal property. When parsing a property, its
133 // type value is stored in the DuplicateFinder for the property name. 162 // type value is stored in the DuplicateFinder for the property name.
134 // Values are chosen so that having intersection bits means the there is 163 // Values are chosen so that having intersection bits means the there is
135 // an incompatibility. 164 // an incompatibility.
136 // I.e., you can add a getter to a property that already has a setter, since 165 // I.e., you can add a getter to a property that already has a setter, since
137 // kGetterProperty and kSetterProperty doesn't intersect, but not if it 166 // kGetterProperty and kSetterProperty doesn't intersect, but not if it
138 // already has a getter or a value. Adding the getter to an existing 167 // already has a getter or a value. Adding the getter to an existing
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 private: 470 private:
442 Scope** const variable_; 471 Scope** const variable_;
443 Scope* const prev_; 472 Scope* const prev_;
444 const ScopeType type_; 473 const ScopeType type_;
445 int materialized_literal_count_; 474 int materialized_literal_count_;
446 int expected_properties_; 475 int expected_properties_;
447 int with_nesting_count_; 476 int with_nesting_count_;
448 i::StrictModeFlag strict_mode_flag_; 477 i::StrictModeFlag strict_mode_flag_;
449 }; 478 };
450 479
451 // Private constructor only used in PreParseProgram.
452 PreParser(i::Scanner* scanner,
453 i::ParserRecorder* log,
454 uintptr_t stack_limit,
455 bool allow_lazy,
456 bool allow_natives_syntax)
457 : scanner_(scanner),
458 log_(log),
459 scope_(NULL),
460 stack_limit_(stack_limit),
461 strict_mode_violation_location_(i::Scanner::Location::invalid()),
462 strict_mode_violation_type_(NULL),
463 stack_overflow_(false),
464 allow_lazy_(allow_lazy),
465 allow_natives_syntax_(allow_natives_syntax),
466 parenthesized_function_(false),
467 harmony_scoping_(scanner->HarmonyScoping()) { }
468
469 // Preparse the program. Only called in PreParseProgram after creating 480 // Preparse the program. Only called in PreParseProgram after creating
470 // the instance. 481 // the instance.
471 PreParseResult PreParse() { 482 PreParseResult PreParse() {
472 Scope top_scope(&scope_, kTopLevelScope); 483 Scope top_scope(&scope_, kTopLevelScope);
473 bool ok = true; 484 bool ok = true;
474 int start_position = scanner_->peek_location().beg_pos; 485 int start_position = scanner_->peek_location().beg_pos;
475 ParseSourceElements(i::Token::EOS, &ok); 486 ParseSourceElements(i::Token::EOS, &ok);
476 if (stack_overflow_) return kPreParseStackOverflow; 487 if (stack_overflow_) return kPreParseStackOverflow;
477 if (!ok) { 488 if (!ok) {
478 ReportUnexpectedToken(scanner_->current_token()); 489 ReportUnexpectedToken(scanner_->current_token());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 Expression ParseMemberExpression(bool* ok); 549 Expression ParseMemberExpression(bool* ok);
539 Expression ParseMemberWithNewPrefixesExpression(unsigned new_count, bool* ok); 550 Expression ParseMemberWithNewPrefixesExpression(unsigned new_count, bool* ok);
540 Expression ParsePrimaryExpression(bool* ok); 551 Expression ParsePrimaryExpression(bool* ok);
541 Expression ParseArrayLiteral(bool* ok); 552 Expression ParseArrayLiteral(bool* ok);
542 Expression ParseObjectLiteral(bool* ok); 553 Expression ParseObjectLiteral(bool* ok);
543 Expression ParseRegExpLiteral(bool seen_equal, bool* ok); 554 Expression ParseRegExpLiteral(bool seen_equal, bool* ok);
544 Expression ParseV8Intrinsic(bool* ok); 555 Expression ParseV8Intrinsic(bool* ok);
545 556
546 Arguments ParseArguments(bool* ok); 557 Arguments ParseArguments(bool* ok);
547 Expression ParseFunctionLiteral(bool* ok); 558 Expression ParseFunctionLiteral(bool* ok);
559 void ParseLazyFunctionLiteralBody(bool* ok);
548 560
549 Identifier ParseIdentifier(bool* ok); 561 Identifier ParseIdentifier(bool* ok);
550 Identifier ParseIdentifierName(bool* ok); 562 Identifier ParseIdentifierName(bool* ok);
551 Identifier ParseIdentifierNameOrGetOrSet(bool* is_get, 563 Identifier ParseIdentifierNameOrGetOrSet(bool* is_get,
552 bool* is_set, 564 bool* is_set,
553 bool* ok); 565 bool* ok);
554 566
555 // Logs the currently parsed literal as a symbol in the preparser data. 567 // Logs the currently parsed literal as a symbol in the preparser data.
556 void LogSymbol(); 568 void LogSymbol();
557 // Log the currently parsed identifier. 569 // Log the currently parsed identifier.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 const char* strict_mode_violation_type_; 639 const char* strict_mode_violation_type_;
628 bool stack_overflow_; 640 bool stack_overflow_;
629 bool allow_lazy_; 641 bool allow_lazy_;
630 bool allow_natives_syntax_; 642 bool allow_natives_syntax_;
631 bool parenthesized_function_; 643 bool parenthesized_function_;
632 bool harmony_scoping_; 644 bool harmony_scoping_;
633 }; 645 };
634 } } // v8::preparser 646 } } // v8::preparser
635 647
636 #endif // V8_PREPARSER_H 648 #endif // V8_PREPARSER_H
OLDNEW
« src/parser.cc ('K') | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698