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_PARSING_PARSER_H_ | 5 #ifndef V8_PARSING_PARSER_H_ |
6 #define V8_PARSING_PARSER_H_ | 6 #define V8_PARSING_PARSER_H_ |
7 | 7 |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
10 #include "src/base/compiler-specific.h" | 10 #include "src/base/compiler-specific.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 class ParseInfo; | 24 class ParseInfo; |
25 class ScriptData; | 25 class ScriptData; |
26 class ParserTarget; | 26 class ParserTarget; |
27 class ParserTargetScope; | 27 class ParserTargetScope; |
28 | 28 |
29 class FunctionEntry BASE_EMBEDDED { | 29 class FunctionEntry BASE_EMBEDDED { |
30 public: | 30 public: |
31 enum { | 31 enum { |
32 kStartPositionIndex, | 32 kStartPositionIndex, |
33 kEndPositionIndex, | 33 kEndPositionIndex, |
| 34 kNumParametersIndex, |
| 35 kFunctionLengthIndex, |
34 kLiteralCountIndex, | 36 kLiteralCountIndex, |
35 kPropertyCountIndex, | 37 kPropertyCountIndex, |
36 kLanguageModeIndex, | 38 kFlagsIndex, |
37 kUsesSuperPropertyIndex, | |
38 kCallsEvalIndex, | |
39 kSize | 39 kSize |
40 }; | 40 }; |
41 | 41 |
42 explicit FunctionEntry(Vector<unsigned> backing) | 42 explicit FunctionEntry(Vector<unsigned> backing) |
43 : backing_(backing) { } | 43 : backing_(backing) { } |
44 | 44 |
45 FunctionEntry() : backing_() { } | 45 FunctionEntry() : backing_() { } |
46 | 46 |
47 int start_pos() { return backing_[kStartPositionIndex]; } | 47 class LanguageModeField : public BitField<LanguageMode, 0, 1> {}; |
48 int end_pos() { return backing_[kEndPositionIndex]; } | 48 class UsesSuperPropertyField |
49 int literal_count() { return backing_[kLiteralCountIndex]; } | 49 : public BitField<bool, LanguageModeField::kNext, 1> {}; |
50 int property_count() { return backing_[kPropertyCountIndex]; } | 50 class CallsEvalField |
51 LanguageMode language_mode() { | 51 : public BitField<bool, UsesSuperPropertyField::kNext, 1> {}; |
52 DCHECK(is_valid_language_mode(backing_[kLanguageModeIndex])); | 52 class HasDuplicateParametersField |
53 return static_cast<LanguageMode>(backing_[kLanguageModeIndex]); | 53 : public BitField<bool, CallsEvalField::kNext, 1> {}; |
| 54 |
| 55 static uint32_t EncodeFlags(LanguageMode language_mode, |
| 56 bool uses_super_property, bool calls_eval, |
| 57 bool has_duplicate_parameters) { |
| 58 return LanguageModeField::encode(language_mode) | |
| 59 UsesSuperPropertyField::encode(uses_super_property) | |
| 60 CallsEvalField::encode(calls_eval) | |
| 61 HasDuplicateParametersField::encode(has_duplicate_parameters); |
54 } | 62 } |
55 bool uses_super_property() { return backing_[kUsesSuperPropertyIndex]; } | |
56 bool calls_eval() { return backing_[kCallsEvalIndex]; } | |
57 | 63 |
58 bool is_valid() { return !backing_.is_empty(); } | 64 int start_pos() const { return backing_[kStartPositionIndex]; } |
| 65 int end_pos() const { return backing_[kEndPositionIndex]; } |
| 66 int num_parameters() const { return backing_[kNumParametersIndex]; } |
| 67 int function_length() const { return backing_[kFunctionLengthIndex]; } |
| 68 int literal_count() const { return backing_[kLiteralCountIndex]; } |
| 69 int property_count() const { return backing_[kPropertyCountIndex]; } |
| 70 LanguageMode language_mode() const { |
| 71 return LanguageModeField::decode(backing_[kFlagsIndex]); |
| 72 } |
| 73 bool uses_super_property() const { |
| 74 return UsesSuperPropertyField::decode(backing_[kFlagsIndex]); |
| 75 } |
| 76 bool calls_eval() const { |
| 77 return CallsEvalField::decode(backing_[kFlagsIndex]); |
| 78 } |
| 79 bool has_duplicate_parameters() const { |
| 80 return HasDuplicateParametersField::decode(backing_[kFlagsIndex]); |
| 81 } |
| 82 |
| 83 bool is_valid() const { return !backing_.is_empty(); } |
59 | 84 |
60 private: | 85 private: |
61 Vector<unsigned> backing_; | 86 Vector<unsigned> backing_; |
62 }; | 87 }; |
63 | 88 |
64 | 89 |
65 // Wrapper around ScriptData to provide parser-specific functionality. | 90 // Wrapper around ScriptData to provide parser-specific functionality. |
66 class ParseData { | 91 class ParseData { |
67 public: | 92 public: |
68 static ParseData* FromCachedData(ScriptData* cached_data) { | 93 static ParseData* FromCachedData(ScriptData* cached_data) { |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 | 508 |
484 // Factory methods. | 509 // Factory methods. |
485 FunctionLiteral* DefaultConstructor(const AstRawString* name, bool call_super, | 510 FunctionLiteral* DefaultConstructor(const AstRawString* name, bool call_super, |
486 bool requires_class_field_init, int pos, | 511 bool requires_class_field_init, int pos, |
487 int end_pos, LanguageMode language_mode); | 512 int end_pos, LanguageMode language_mode); |
488 | 513 |
489 // Skip over a lazy function, either using cached data if we have it, or | 514 // Skip over a lazy function, either using cached data if we have it, or |
490 // by parsing the function with PreParser. Consumes the ending }. | 515 // by parsing the function with PreParser. Consumes the ending }. |
491 // If may_abort == true, the (pre-)parser may decide to abort skipping | 516 // If may_abort == true, the (pre-)parser may decide to abort skipping |
492 // in order to force the function to be eagerly parsed, after all. | 517 // in order to force the function to be eagerly parsed, after all. |
493 LazyParsingResult SkipLazyFunctionBody(int* materialized_literal_count, | 518 LazyParsingResult SkipFunction( |
494 int* expected_property_count, | 519 FunctionKind kind, DeclarationScope* function_scope, int* num_parameters, |
495 bool is_inner_function, bool may_abort, | 520 int* function_length, bool* has_duplicate_parameters, |
496 bool* ok); | 521 int* materialized_literal_count, int* expected_property_count, |
| 522 bool is_inner_function, bool may_abort, bool* ok); |
497 | 523 |
498 PreParser::PreParseResult ParseFunctionBodyWithPreParser( | 524 PreParser::PreParseResult ParseFunctionWithPreParser(FunctionKind kind, |
499 SingletonLogger* logger, bool is_inner_function, bool may_abort); | 525 DeclarationScope* scope, |
| 526 SingletonLogger* logger, |
| 527 bool is_inner_function, |
| 528 bool may_abort); |
500 | 529 |
501 Block* BuildParameterInitializationBlock( | 530 Block* BuildParameterInitializationBlock( |
502 const ParserFormalParameters& parameters, bool* ok); | 531 const ParserFormalParameters& parameters, bool* ok); |
503 Block* BuildRejectPromiseOnException(Block* block, bool* ok); | 532 Block* BuildRejectPromiseOnException(Block* block, bool* ok); |
504 | 533 |
505 // Consumes the ending }. | 534 // Consumes the ending }. |
506 ZoneList<Statement*>* ParseEagerFunctionBody( | 535 ZoneList<Statement*>* ParseEagerFunctionBody( |
507 const AstRawString* function_name, int pos, | 536 const AstRawString* function_name, int pos, |
508 const ParserFormalParameters& parameters, FunctionKind kind, | 537 const ParserFormalParameters& parameters, FunctionKind kind, |
509 FunctionLiteral::FunctionType function_type, bool* ok); | 538 FunctionLiteral::FunctionType function_type, bool* ok); |
510 | 539 |
| 540 ZoneList<Statement*>* ParseFunction( |
| 541 const AstRawString* function_name, int pos, FunctionKind kind, |
| 542 FunctionLiteral::FunctionType function_type, |
| 543 DeclarationScope* function_scope, int* num_parameters, |
| 544 int* function_length, bool* has_duplicate_parameters, |
| 545 int* materialized_literal_count, int* expected_property_count, bool* ok); |
| 546 |
511 void ThrowPendingError(Isolate* isolate, Handle<Script> script); | 547 void ThrowPendingError(Isolate* isolate, Handle<Script> script); |
512 | 548 |
513 class TemplateLiteral : public ZoneObject { | 549 class TemplateLiteral : public ZoneObject { |
514 public: | 550 public: |
515 TemplateLiteral(Zone* zone, int pos) | 551 TemplateLiteral(Zone* zone, int pos) |
516 : cooked_(8, zone), raw_(8, zone), expressions_(8, zone), pos_(pos) {} | 552 : cooked_(8, zone), raw_(8, zone), expressions_(8, zone), pos_(pos) {} |
517 | 553 |
518 const ZoneList<Expression*>* cooked() const { return &cooked_; } | 554 const ZoneList<Expression*>* cooked() const { return &cooked_; } |
519 const ZoneList<Expression*>* raw() const { return &raw_; } | 555 const ZoneList<Expression*>* raw() const { return &raw_; } |
520 const ZoneList<Expression*>* expressions() const { return &expressions_; } | 556 const ZoneList<Expression*>* expressions() const { return &expressions_; } |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 | 1177 |
1142 private: | 1178 private: |
1143 ParserTarget** variable_; | 1179 ParserTarget** variable_; |
1144 ParserTarget* previous_; | 1180 ParserTarget* previous_; |
1145 }; | 1181 }; |
1146 | 1182 |
1147 } // namespace internal | 1183 } // namespace internal |
1148 } // namespace v8 | 1184 } // namespace v8 |
1149 | 1185 |
1150 #endif // V8_PARSING_PARSER_H_ | 1186 #endif // V8_PARSING_PARSER_H_ |
OLD | NEW |