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

Side by Side Diff: src/parsing/preparser.h

Issue 2188153002: Speed up parsing w/ grammar shortcut. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix PreParserTraits::EmptyExpression Created 4 years, 4 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
« src/parsing/parser-base.h ('K') | « src/parsing/parser-base.h ('k') | no next file » | 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_PARSING_PREPARSER_H 5 #ifndef V8_PARSING_PREPARSER_H
6 #define V8_PARSING_PREPARSER_H 6 #define V8_PARSING_PREPARSER_H
7 7
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/hashmap.h" 10 #include "src/base/hashmap.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 TypeField::encode(kExpression) | 193 TypeField::encode(kExpression) |
194 ExpressionTypeField::encode(kSuperCallReference)); 194 ExpressionTypeField::encode(kSuperCallReference));
195 } 195 }
196 196
197 static PreParserExpression NoTemplateTag() { 197 static PreParserExpression NoTemplateTag() {
198 return PreParserExpression( 198 return PreParserExpression(
199 TypeField::encode(kExpression) | 199 TypeField::encode(kExpression) |
200 ExpressionTypeField::encode(kNoTemplateTagExpression)); 200 ExpressionTypeField::encode(kNoTemplateTagExpression));
201 } 201 }
202 202
203 static PreParserExpression Empty() {
204 return PreParserExpression(TypeField::encode(kExpression) |
205 ExpressionTypeField::encode(kEmptyExpression));
206 }
207
203 bool IsIdentifier() const { 208 bool IsIdentifier() const {
204 return TypeField::decode(code_) == kIdentifierExpression; 209 return TypeField::decode(code_) == kIdentifierExpression;
205 } 210 }
206 211
212 bool IsEmptyExpression() const {
213 return TypeField::decode(code_) == kExpression &&
214 ExpressionTypeField::decode(code_) == kEmptyExpression;
215 }
216
207 PreParserIdentifier AsIdentifier() const { 217 PreParserIdentifier AsIdentifier() const {
208 DCHECK(IsIdentifier()); 218 DCHECK(IsIdentifier());
209 return PreParserIdentifier(IdentifierTypeField::decode(code_)); 219 return PreParserIdentifier(IdentifierTypeField::decode(code_));
210 } 220 }
211 221
212 bool IsAssignment() const { 222 bool IsAssignment() const {
213 return TypeField::decode(code_) == kExpression && 223 return TypeField::decode(code_) == kExpression &&
214 ExpressionTypeField::decode(code_) == kAssignment; 224 ExpressionTypeField::decode(code_) == kAssignment;
215 } 225 }
216 226
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 }; 319 };
310 320
311 enum ExpressionType { 321 enum ExpressionType {
312 kThisExpression, 322 kThisExpression,
313 kThisPropertyExpression, 323 kThisPropertyExpression,
314 kPropertyExpression, 324 kPropertyExpression,
315 kCallExpression, 325 kCallExpression,
316 kCallEvalExpression, 326 kCallEvalExpression,
317 kSuperCallReference, 327 kSuperCallReference,
318 kNoTemplateTagExpression, 328 kNoTemplateTagExpression,
319 kAssignment 329 kAssignment,
330 kEmptyExpression
320 }; 331 };
321 332
322 explicit PreParserExpression(uint32_t expression_code) 333 explicit PreParserExpression(uint32_t expression_code)
323 : code_(expression_code) {} 334 : code_(expression_code) {}
324 335
325 // The first three bits are for the Type. 336 // The first three bits are for the Type.
326 typedef BitField<Type, 0, 3> TypeField; 337 typedef BitField<Type, 0, 3> TypeField;
327 338
328 // The high order bit applies only to nodes which would inherit from the 339 // The high order bit applies only to nodes which would inherit from the
329 // Expression ASTNode --- This is by necessity, due to the fact that 340 // Expression ASTNode --- This is by necessity, due to the fact that
330 // Expression nodes may be represented as multiple Types, not exclusively 341 // Expression nodes may be represented as multiple Types, not exclusively
331 // through kExpression. 342 // through kExpression.
332 // TODO(caitp, adamk): clean up PreParserExpression bitfields. 343 // TODO(caitp, adamk): clean up PreParserExpression bitfields.
333 typedef BitField<bool, 31, 1> ParenthesizedField; 344 typedef BitField<bool, 31, 1> ParenthesizedField;
334 345
335 // The rest of the bits are interpreted depending on the value 346 // The rest of the bits are interpreted depending on the value
336 // of the Type field, so they can share the storage. 347 // of the Type field, so they can share the storage.
337 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; 348 typedef BitField<ExpressionType, TypeField::kNext, 4> ExpressionTypeField;
338 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; 349 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField;
339 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> 350 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10>
340 IdentifierTypeField; 351 IdentifierTypeField;
341 typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField; 352 typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField;
342 353
343 uint32_t code_; 354 uint32_t code_;
344 }; 355 };
345 356
346 357
347 // The pre-parser doesn't need to build lists of expressions, identifiers, or 358 // The pre-parser doesn't need to build lists of expressions, identifiers, or
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 666
656 // Returns true if the expression is of type "this.foo". 667 // Returns true if the expression is of type "this.foo".
657 static bool IsThisProperty(PreParserExpression expression) { 668 static bool IsThisProperty(PreParserExpression expression) {
658 return expression.IsThisProperty(); 669 return expression.IsThisProperty();
659 } 670 }
660 671
661 static bool IsIdentifier(PreParserExpression expression) { 672 static bool IsIdentifier(PreParserExpression expression) {
662 return expression.IsIdentifier(); 673 return expression.IsIdentifier();
663 } 674 }
664 675
676 static bool IsEmptyExpression(PreParserExpression expression) {
677 return expression.IsEmptyExpression();
678 }
679
665 static PreParserIdentifier AsIdentifier(PreParserExpression expression) { 680 static PreParserIdentifier AsIdentifier(PreParserExpression expression) {
666 return expression.AsIdentifier(); 681 return expression.AsIdentifier();
667 } 682 }
668 683
669 static bool IsEvalIdentifier(PreParserExpression expression) { 684 static bool IsEvalIdentifier(PreParserExpression expression) {
670 return IsIdentifier(expression) && IsEval(AsIdentifier(expression)); 685 return IsIdentifier(expression) && IsEval(AsIdentifier(expression));
671 } 686 }
672 687
673 static bool IsDirectEvalCall(PreParserExpression expression) { 688 static bool IsDirectEvalCall(PreParserExpression expression) {
674 return expression.IsDirectEvalCall(); 689 return expression.IsDirectEvalCall();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 static void Void() {} 780 static void Void() {}
766 781
767 // "null" return type creators. 782 // "null" return type creators.
768 static PreParserIdentifier EmptyIdentifier() { 783 static PreParserIdentifier EmptyIdentifier() {
769 return PreParserIdentifier::Default(); 784 return PreParserIdentifier::Default();
770 } 785 }
771 static PreParserIdentifier EmptyIdentifierString() { 786 static PreParserIdentifier EmptyIdentifierString() {
772 return PreParserIdentifier::Default(); 787 return PreParserIdentifier::Default();
773 } 788 }
774 static PreParserExpression EmptyExpression() { 789 static PreParserExpression EmptyExpression() {
775 return PreParserExpression::Default(); 790 return PreParserExpression::Empty();
776 } 791 }
777 static PreParserExpression EmptyLiteral() { 792 static PreParserExpression EmptyLiteral() {
778 return PreParserExpression::Default(); 793 return PreParserExpression::Default();
779 } 794 }
780 static PreParserExpression EmptyObjectLiteralProperty() { 795 static PreParserExpression EmptyObjectLiteralProperty() {
781 return PreParserExpression::Default(); 796 return PreParserExpression::Default();
782 } 797 }
783 static PreParserExpression EmptyFunctionLiteral() { 798 static PreParserExpression EmptyFunctionLiteral() {
784 return PreParserExpression::Default(); 799 return PreParserExpression::Default();
785 } 800 }
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 const PreParserFormalParameters& parameters, FunctionKind kind, 1282 const PreParserFormalParameters& parameters, FunctionKind kind,
1268 FunctionLiteral::FunctionType function_type, bool* ok) { 1283 FunctionLiteral::FunctionType function_type, bool* ok) {
1269 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, 1284 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters,
1270 kind, function_type, ok); 1285 kind, function_type, ok);
1271 } 1286 }
1272 1287
1273 } // namespace internal 1288 } // namespace internal
1274 } // namespace v8 1289 } // namespace v8
1275 1290
1276 #endif // V8_PARSING_PREPARSER_H 1291 #endif // V8_PARSING_PREPARSER_H
OLDNEW
« src/parsing/parser-base.h ('K') | « src/parsing/parser-base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698