| 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/parsing/parser-base.h" | 10 #include "src/parsing/parser-base.h" |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 } | 329 } |
| 330 ZoneList<v8::internal::Statement*>* NewStatementList(int size, | 330 ZoneList<v8::internal::Statement*>* NewStatementList(int size, |
| 331 Zone* zone) const { | 331 Zone* zone) const { |
| 332 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); | 332 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); |
| 333 } | 333 } |
| 334 | 334 |
| 335 V8_INLINE void AddParameterInitializationBlock( | 335 V8_INLINE void AddParameterInitializationBlock( |
| 336 const ParserFormalParameters& parameters, | 336 const ParserFormalParameters& parameters, |
| 337 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok); | 337 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok); |
| 338 | 338 |
| 339 void ParseAsyncArrowSingleExpressionBody( | |
| 340 ZoneList<Statement*>* body, bool accept_IN, | |
| 341 Type::ExpressionClassifier* classifier, int pos, bool* ok); | |
| 342 | |
| 343 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, | 339 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, |
| 344 Expression* pattern, | 340 Expression* pattern, |
| 345 Expression* initializer, | 341 Expression* initializer, |
| 346 int initializer_end_position, bool is_rest); | 342 int initializer_end_position, bool is_rest); |
| 347 V8_INLINE void DeclareFormalParameter( | 343 V8_INLINE void DeclareFormalParameter( |
| 348 DeclarationScope* scope, | 344 DeclarationScope* scope, |
| 349 const ParserFormalParameters::Parameter& parameter, | 345 const ParserFormalParameters::Parameter& parameter, |
| 350 Type::ExpressionClassifier* classifier); | 346 Type::ExpressionClassifier* classifier); |
| 351 void ParseArrowFunctionFormalParameterList( | 347 void ParseArrowFunctionFormalParameterList( |
| 352 ParserFormalParameters* parameters, Expression* params, | 348 ParserFormalParameters* parameters, Expression* params, |
| 353 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, | 349 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, |
| 354 const Scope::Snapshot& scope_snapshot, bool* ok); | 350 const Scope::Snapshot& scope_snapshot, bool* ok); |
| 355 | 351 |
| 356 V8_INLINE Expression* ParseAsyncFunctionExpression(bool* ok); | |
| 357 | |
| 358 V8_INLINE DoExpression* ParseDoExpression(bool* ok); | |
| 359 | |
| 360 void ReindexLiterals(const ParserFormalParameters& parameters); | 352 void ReindexLiterals(const ParserFormalParameters& parameters); |
| 361 | 353 |
| 362 // Temporary glue; these functions will move to ParserBase. | |
| 363 Expression* ParseV8Intrinsic(bool* ok); | |
| 364 FunctionLiteral* ParseFunctionLiteral( | |
| 365 const AstRawString* name, Scanner::Location function_name_location, | |
| 366 FunctionNameValidity function_name_validity, FunctionKind kind, | |
| 367 int function_token_position, FunctionLiteral::FunctionType type, | |
| 368 LanguageMode language_mode, bool* ok); | |
| 369 V8_INLINE void SkipLazyFunctionBody( | |
| 370 int* materialized_literal_count, int* expected_property_count, bool* ok, | |
| 371 Scanner::BookmarkScope* bookmark = nullptr); | |
| 372 V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody( | |
| 373 const AstRawString* name, int pos, | |
| 374 const ParserFormalParameters& parameters, FunctionKind kind, | |
| 375 FunctionLiteral::FunctionType function_type, bool* ok); | |
| 376 | |
| 377 Expression* ParseClassLiteral(Type::ExpressionClassifier* classifier, | |
| 378 const AstRawString* name, | |
| 379 Scanner::Location class_name_location, | |
| 380 bool name_is_strict_reserved, int pos, | |
| 381 bool* ok); | |
| 382 | |
| 383 V8_INLINE void MarkCollectedTailCallExpressions(); | |
| 384 V8_INLINE void MarkTailPosition(Expression* expression); | |
| 385 | |
| 386 V8_INLINE void CheckConflictingVarDeclarations(Scope* scope, bool* ok); | |
| 387 | |
| 388 class TemplateLiteral : public ZoneObject { | |
| 389 public: | |
| 390 TemplateLiteral(Zone* zone, int pos) | |
| 391 : cooked_(8, zone), raw_(8, zone), expressions_(8, zone), pos_(pos) {} | |
| 392 | |
| 393 const ZoneList<Expression*>* cooked() const { return &cooked_; } | |
| 394 const ZoneList<Expression*>* raw() const { return &raw_; } | |
| 395 const ZoneList<Expression*>* expressions() const { return &expressions_; } | |
| 396 int position() const { return pos_; } | |
| 397 | |
| 398 void AddTemplateSpan(Literal* cooked, Literal* raw, int end, Zone* zone) { | |
| 399 DCHECK_NOT_NULL(cooked); | |
| 400 DCHECK_NOT_NULL(raw); | |
| 401 cooked_.Add(cooked, zone); | |
| 402 raw_.Add(raw, zone); | |
| 403 } | |
| 404 | |
| 405 void AddExpression(Expression* expression, Zone* zone) { | |
| 406 DCHECK_NOT_NULL(expression); | |
| 407 expressions_.Add(expression, zone); | |
| 408 } | |
| 409 | |
| 410 private: | |
| 411 ZoneList<Expression*> cooked_; | |
| 412 ZoneList<Expression*> raw_; | |
| 413 ZoneList<Expression*> expressions_; | |
| 414 int pos_; | |
| 415 }; | |
| 416 | |
| 417 typedef TemplateLiteral* TemplateLiteralState; | |
| 418 | |
| 419 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos); | |
| 420 V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail); | |
| 421 V8_INLINE void AddTemplateExpression(TemplateLiteralState* state, | |
| 422 Expression* expression); | |
| 423 V8_INLINE Expression* CloseTemplateLiteral(TemplateLiteralState* state, | |
| 424 int start, Expression* tag); | |
| 425 V8_INLINE Expression* NoTemplateTag() { return NULL; } | 354 V8_INLINE Expression* NoTemplateTag() { return NULL; } |
| 426 V8_INLINE static bool IsTaggedTemplate(const Expression* tag) { | 355 V8_INLINE static bool IsTaggedTemplate(const Expression* tag) { |
| 427 return tag != NULL; | 356 return tag != NULL; |
| 428 } | 357 } |
| 429 | 358 |
| 430 V8_INLINE ZoneList<v8::internal::Expression*>* PrepareSpreadArguments( | |
| 431 ZoneList<v8::internal::Expression*>* list); | |
| 432 V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) {} | 359 V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) {} |
| 433 V8_INLINE Expression* SpreadCall(Expression* function, | |
| 434 ZoneList<v8::internal::Expression*>* args, | |
| 435 int pos); | |
| 436 V8_INLINE Expression* SpreadCallNew(Expression* function, | |
| 437 ZoneList<v8::internal::Expression*>* args, | |
| 438 int pos); | |
| 439 | 360 |
| 440 Expression* ExpressionListToExpression(ZoneList<Expression*>* args); | 361 Expression* ExpressionListToExpression(ZoneList<Expression*>* args); |
| 441 | 362 |
| 442 // Rewrite all DestructuringAssignments in the current FunctionState. | |
| 443 V8_INLINE void RewriteDestructuringAssignments(); | |
| 444 | |
| 445 V8_INLINE Expression* RewriteExponentiation(Expression* left, | |
| 446 Expression* right, int pos); | |
| 447 V8_INLINE Expression* RewriteAssignExponentiation(Expression* left, | |
| 448 Expression* right, int pos); | |
| 449 | |
| 450 V8_INLINE Expression* RewriteAwaitExpression(Expression* value, int pos); | |
| 451 | |
| 452 V8_INLINE void QueueDestructuringAssignmentForRewriting( | |
| 453 Expression* assignment); | |
| 454 V8_INLINE void QueueNonPatternForRewriting(Expression* expr, bool* ok); | |
| 455 | |
| 456 void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property, | 363 void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property, |
| 457 const AstRawString* name); | 364 const AstRawString* name); |
| 458 | 365 |
| 459 void SetFunctionNameFromIdentifierRef(Expression* value, | 366 void SetFunctionNameFromIdentifierRef(Expression* value, |
| 460 Expression* identifier); | 367 Expression* identifier); |
| 461 | 368 |
| 462 // Rewrite expressions that are not used as patterns | |
| 463 V8_INLINE void RewriteNonPattern(Type::ExpressionClassifier* classifier, | |
| 464 bool* ok); | |
| 465 | |
| 466 V8_INLINE ZoneList<typename Type::ExpressionClassifier::Error>* | 369 V8_INLINE ZoneList<typename Type::ExpressionClassifier::Error>* |
| 467 GetReportedErrorList() const; | 370 GetReportedErrorList() const; |
| 468 V8_INLINE Zone* zone() const; | 371 V8_INLINE Zone* zone() const; |
| 469 | 372 |
| 470 V8_INLINE ZoneList<Expression*>* GetNonPatternList() const; | 373 V8_INLINE ZoneList<Expression*>* GetNonPatternList() const; |
| 471 | |
| 472 V8_INLINE Expression* RewriteYieldStar(Expression* generator, | |
| 473 Expression* expression, int pos); | |
| 474 }; | 374 }; |
| 475 | 375 |
| 476 class Parser : public ParserBase<Parser> { | 376 class Parser : public ParserBase<Parser> { |
| 477 public: | 377 public: |
| 478 explicit Parser(ParseInfo* info); | 378 explicit Parser(ParseInfo* info); |
| 479 ~Parser() { | 379 ~Parser() { |
| 480 delete reusable_preparser_; | 380 delete reusable_preparser_; |
| 481 reusable_preparser_ = NULL; | 381 reusable_preparser_ = NULL; |
| 482 delete cached_parse_data_; | 382 delete cached_parse_data_; |
| 483 cached_parse_data_ = NULL; | 383 cached_parse_data_ = NULL; |
| 484 } | 384 } |
| 485 | 385 |
| 486 // Parses the source code represented by the compilation info and sets its | 386 // Parses the source code represented by the compilation info and sets its |
| 487 // function literal. Returns false (and deallocates any allocated AST | 387 // function literal. Returns false (and deallocates any allocated AST |
| 488 // nodes) if parsing failed. | 388 // nodes) if parsing failed. |
| 489 static bool ParseStatic(ParseInfo* info); | 389 static bool ParseStatic(ParseInfo* info); |
| 490 bool Parse(ParseInfo* info); | 390 bool Parse(ParseInfo* info); |
| 491 void ParseOnBackground(ParseInfo* info); | 391 void ParseOnBackground(ParseInfo* info); |
| 492 | 392 |
| 493 void DeserializeScopeChain(ParseInfo* info, Handle<Context> context, | 393 void DeserializeScopeChain(ParseInfo* info, Handle<Context> context, |
| 494 Scope::DeserializationMode deserialization_mode); | 394 Scope::DeserializationMode deserialization_mode); |
| 495 | 395 |
| 496 // Handle errors detected during parsing, move statistics to Isolate, | 396 // Handle errors detected during parsing, move statistics to Isolate, |
| 497 // internalize strings (move them to the heap). | 397 // internalize strings (move them to the heap). |
| 498 void Internalize(Isolate* isolate, Handle<Script> script, bool error); | 398 void Internalize(Isolate* isolate, Handle<Script> script, bool error); |
| 499 void HandleSourceURLComments(Isolate* isolate, Handle<Script> script); | 399 void HandleSourceURLComments(Isolate* isolate, Handle<Script> script); |
| 500 | 400 |
| 501 private: | 401 private: |
| 402 friend class ParserBase<Parser>; |
| 502 // TODO(nikolaos): This should not be necessary. It will be removed | 403 // TODO(nikolaos): This should not be necessary. It will be removed |
| 503 // when the traits object stops delegating to the implementation object. | 404 // when the traits object stops delegating to the implementation object. |
| 504 friend class ParserBaseTraits<Parser>; | 405 friend class ParserBaseTraits<Parser>; |
| 505 | 406 |
| 506 // Runtime encoding of different completion modes. | 407 // Runtime encoding of different completion modes. |
| 507 enum CompletionKind { | 408 enum CompletionKind { |
| 508 kNormalCompletion, | 409 kNormalCompletion, |
| 509 kThrowCompletion, | 410 kThrowCompletion, |
| 510 kAbruptCompletion | 411 kAbruptCompletion |
| 511 }; | 412 }; |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 Block* BuildRejectPromiseOnException(Block* block); | 771 Block* BuildRejectPromiseOnException(Block* block); |
| 871 | 772 |
| 872 // Consumes the ending }. | 773 // Consumes the ending }. |
| 873 ZoneList<Statement*>* ParseEagerFunctionBody( | 774 ZoneList<Statement*>* ParseEagerFunctionBody( |
| 874 const AstRawString* function_name, int pos, | 775 const AstRawString* function_name, int pos, |
| 875 const ParserFormalParameters& parameters, FunctionKind kind, | 776 const ParserFormalParameters& parameters, FunctionKind kind, |
| 876 FunctionLiteral::FunctionType function_type, bool* ok); | 777 FunctionLiteral::FunctionType function_type, bool* ok); |
| 877 | 778 |
| 878 void ThrowPendingError(Isolate* isolate, Handle<Script> script); | 779 void ThrowPendingError(Isolate* isolate, Handle<Script> script); |
| 879 | 780 |
| 781 class TemplateLiteral : public ZoneObject { |
| 782 public: |
| 783 TemplateLiteral(Zone* zone, int pos) |
| 784 : cooked_(8, zone), raw_(8, zone), expressions_(8, zone), pos_(pos) {} |
| 785 |
| 786 const ZoneList<Expression*>* cooked() const { return &cooked_; } |
| 787 const ZoneList<Expression*>* raw() const { return &raw_; } |
| 788 const ZoneList<Expression*>* expressions() const { return &expressions_; } |
| 789 int position() const { return pos_; } |
| 790 |
| 791 void AddTemplateSpan(Literal* cooked, Literal* raw, int end, Zone* zone) { |
| 792 DCHECK_NOT_NULL(cooked); |
| 793 DCHECK_NOT_NULL(raw); |
| 794 cooked_.Add(cooked, zone); |
| 795 raw_.Add(raw, zone); |
| 796 } |
| 797 |
| 798 void AddExpression(Expression* expression, Zone* zone) { |
| 799 DCHECK_NOT_NULL(expression); |
| 800 expressions_.Add(expression, zone); |
| 801 } |
| 802 |
| 803 private: |
| 804 ZoneList<Expression*> cooked_; |
| 805 ZoneList<Expression*> raw_; |
| 806 ZoneList<Expression*> expressions_; |
| 807 int pos_; |
| 808 }; |
| 809 |
| 810 typedef TemplateLiteral* TemplateLiteralState; |
| 811 |
| 880 TemplateLiteralState OpenTemplateLiteral(int pos); | 812 TemplateLiteralState OpenTemplateLiteral(int pos); |
| 881 void AddTemplateSpan(TemplateLiteralState* state, bool tail); | 813 void AddTemplateSpan(TemplateLiteralState* state, bool tail); |
| 882 void AddTemplateExpression(TemplateLiteralState* state, | 814 void AddTemplateExpression(TemplateLiteralState* state, |
| 883 Expression* expression); | 815 Expression* expression); |
| 884 Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start, | 816 Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start, |
| 885 Expression* tag); | 817 Expression* tag); |
| 886 uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit); | 818 uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit); |
| 887 | 819 |
| 820 void ParseAsyncArrowSingleExpressionBody(ZoneList<Statement*>* body, |
| 821 bool accept_IN, |
| 822 ExpressionClassifier* classifier, |
| 823 int pos, bool* ok) { |
| 824 DesugarAsyncFunctionBody(ast_value_factory()->empty_string(), scope(), body, |
| 825 classifier, kAsyncArrowFunction, |
| 826 FunctionBodyType::kSingleExpression, accept_IN, |
| 827 pos, ok); |
| 828 } |
| 829 |
| 888 ZoneList<v8::internal::Expression*>* PrepareSpreadArguments( | 830 ZoneList<v8::internal::Expression*>* PrepareSpreadArguments( |
| 889 ZoneList<v8::internal::Expression*>* list); | 831 ZoneList<v8::internal::Expression*>* list); |
| 890 Expression* SpreadCall(Expression* function, | 832 Expression* SpreadCall(Expression* function, |
| 891 ZoneList<v8::internal::Expression*>* args, int pos); | 833 ZoneList<v8::internal::Expression*>* args, int pos); |
| 892 Expression* SpreadCallNew(Expression* function, | 834 Expression* SpreadCallNew(Expression* function, |
| 893 ZoneList<v8::internal::Expression*>* args, int pos); | 835 ZoneList<v8::internal::Expression*>* args, int pos); |
| 894 | 836 |
| 895 void SetLanguageMode(Scope* scope, LanguageMode mode); | 837 void SetLanguageMode(Scope* scope, LanguageMode mode); |
| 896 void RaiseLanguageMode(LanguageMode mode); | 838 void RaiseLanguageMode(LanguageMode mode); |
| 897 | 839 |
| 898 V8_INLINE void MarkCollectedTailCallExpressions(); | 840 V8_INLINE void MarkCollectedTailCallExpressions(); |
| 841 V8_INLINE void MarkTailPosition(Expression* expression); |
| 899 | 842 |
| 843 // Rewrite all DestructuringAssignments in the current FunctionState. |
| 900 V8_INLINE void RewriteDestructuringAssignments(); | 844 V8_INLINE void RewriteDestructuringAssignments(); |
| 901 | 845 |
| 902 V8_INLINE Expression* RewriteExponentiation(Expression* left, | 846 V8_INLINE Expression* RewriteExponentiation(Expression* left, |
| 903 Expression* right, int pos); | 847 Expression* right, int pos); |
| 904 V8_INLINE Expression* RewriteAssignExponentiation(Expression* left, | 848 V8_INLINE Expression* RewriteAssignExponentiation(Expression* left, |
| 905 Expression* right, int pos); | 849 Expression* right, int pos); |
| 906 | 850 |
| 907 friend class NonPatternRewriter; | 851 friend class NonPatternRewriter; |
| 908 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit); | 852 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit); |
| 909 | 853 |
| 854 // Rewrite expressions that are not used as patterns |
| 910 V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok); | 855 V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok); |
| 911 | 856 |
| 857 V8_INLINE void QueueDestructuringAssignmentForRewriting( |
| 858 Expression* assignment); |
| 859 V8_INLINE void QueueNonPatternForRewriting(Expression* expr, bool* ok); |
| 860 |
| 912 friend class InitializerRewriter; | 861 friend class InitializerRewriter; |
| 913 void RewriteParameterInitializer(Expression* expr, Scope* scope); | 862 void RewriteParameterInitializer(Expression* expr, Scope* scope); |
| 914 | 863 |
| 915 Expression* BuildCreateJSGeneratorObject(int pos, FunctionKind kind); | 864 Expression* BuildCreateJSGeneratorObject(int pos, FunctionKind kind); |
| 916 Expression* BuildPromiseResolve(Expression* value, int pos); | 865 Expression* BuildPromiseResolve(Expression* value, int pos); |
| 917 Expression* BuildPromiseReject(Expression* value, int pos); | 866 Expression* BuildPromiseReject(Expression* value, int pos); |
| 918 | 867 |
| 919 // Generic AST generator for throwing errors from compiled code. | 868 // Generic AST generator for throwing errors from compiled code. |
| 920 Expression* NewThrowError(Runtime::FunctionId function_id, | 869 Expression* NewThrowError(Runtime::FunctionId function_id, |
| 921 MessageTemplate::Template message, | 870 MessageTemplate::Template message, |
| 922 const AstRawString* arg, int pos); | 871 const AstRawString* arg, int pos); |
| 923 | 872 |
| 924 void FinalizeIteratorUse(Variable* completion, Expression* condition, | 873 void FinalizeIteratorUse(Variable* completion, Expression* condition, |
| 925 Variable* iter, Block* iterator_use, Block* result); | 874 Variable* iter, Block* iterator_use, Block* result); |
| 926 | 875 |
| 927 Statement* FinalizeForOfStatement(ForOfStatement* loop, Variable* completion, | 876 Statement* FinalizeForOfStatement(ForOfStatement* loop, Variable* completion, |
| 928 int pos); | 877 int pos); |
| 929 void BuildIteratorClose(ZoneList<Statement*>* statements, Variable* iterator, | 878 void BuildIteratorClose(ZoneList<Statement*>* statements, Variable* iterator, |
| 930 Variable* input, Variable* output); | 879 Variable* input, Variable* output); |
| 931 void BuildIteratorCloseForCompletion(ZoneList<Statement*>* statements, | 880 void BuildIteratorCloseForCompletion(ZoneList<Statement*>* statements, |
| 932 Variable* iterator, | 881 Variable* iterator, |
| 933 Expression* completion); | 882 Expression* completion); |
| 934 Statement* CheckCallable(Variable* var, Expression* error, int pos); | 883 Statement* CheckCallable(Variable* var, Expression* error, int pos); |
| 935 | 884 |
| 885 V8_INLINE Expression* RewriteAwaitExpression(Expression* value, int pos); |
| 886 |
| 936 Expression* RewriteYieldStar(Expression* generator, Expression* expression, | 887 Expression* RewriteYieldStar(Expression* generator, Expression* expression, |
| 937 int pos); | 888 int pos); |
| 938 | 889 |
| 939 void ParseArrowFunctionFormalParameters(ParserFormalParameters* parameters, | 890 void ParseArrowFunctionFormalParameters(ParserFormalParameters* parameters, |
| 940 Expression* params, int end_pos, | 891 Expression* params, int end_pos, |
| 941 bool* ok); | 892 bool* ok); |
| 942 void SetFunctionName(Expression* value, const AstRawString* name); | 893 void SetFunctionName(Expression* value, const AstRawString* name); |
| 943 | 894 |
| 944 Scanner scanner_; | 895 Scanner scanner_; |
| 945 PreParser* reusable_preparser_; | 896 PreParser* reusable_preparser_; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 965 | 916 |
| 966 bool ParserBaseTraits<Parser>::IsFutureStrictReserved( | 917 bool ParserBaseTraits<Parser>::IsFutureStrictReserved( |
| 967 const AstRawString* identifier) const { | 918 const AstRawString* identifier) const { |
| 968 return delegate()->scanner()->IdentifierIsFutureStrictReserved(identifier); | 919 return delegate()->scanner()->IdentifierIsFutureStrictReserved(identifier); |
| 969 } | 920 } |
| 970 | 921 |
| 971 const AstRawString* ParserBaseTraits<Parser>::EmptyIdentifierString() const { | 922 const AstRawString* ParserBaseTraits<Parser>::EmptyIdentifierString() const { |
| 972 return delegate()->ast_value_factory()->empty_string(); | 923 return delegate()->ast_value_factory()->empty_string(); |
| 973 } | 924 } |
| 974 | 925 |
| 975 void ParserBaseTraits<Parser>::SkipLazyFunctionBody( | |
| 976 int* materialized_literal_count, int* expected_property_count, bool* ok, | |
| 977 Scanner::BookmarkScope* bookmark) { | |
| 978 return delegate()->SkipLazyFunctionBody( | |
| 979 materialized_literal_count, expected_property_count, ok, bookmark); | |
| 980 } | |
| 981 | |
| 982 ZoneList<Statement*>* ParserBaseTraits<Parser>::ParseEagerFunctionBody( | |
| 983 const AstRawString* name, int pos, const ParserFormalParameters& parameters, | |
| 984 FunctionKind kind, FunctionLiteral::FunctionType function_type, bool* ok) { | |
| 985 return delegate()->ParseEagerFunctionBody(name, pos, parameters, kind, | |
| 986 function_type, ok); | |
| 987 } | |
| 988 | |
| 989 void ParserBaseTraits<Parser>::CheckConflictingVarDeclarations(Scope* scope, | |
| 990 bool* ok) { | |
| 991 delegate()->CheckConflictingVarDeclarations(scope, ok); | |
| 992 } | |
| 993 | |
| 994 | 926 |
| 995 // Support for handling complex values (array and object literals) that | 927 // Support for handling complex values (array and object literals) that |
| 996 // can be fully handled at compile time. | 928 // can be fully handled at compile time. |
| 997 class CompileTimeValue: public AllStatic { | 929 class CompileTimeValue: public AllStatic { |
| 998 public: | 930 public: |
| 999 enum LiteralType { | 931 enum LiteralType { |
| 1000 OBJECT_LITERAL_FAST_ELEMENTS, | 932 OBJECT_LITERAL_FAST_ELEMENTS, |
| 1001 OBJECT_LITERAL_SLOW_ELEMENTS, | 933 OBJECT_LITERAL_SLOW_ELEMENTS, |
| 1002 ARRAY_LITERAL | 934 ARRAY_LITERAL |
| 1003 }; | 935 }; |
| 1004 | 936 |
| 1005 static bool IsCompileTimeValue(Expression* expression); | 937 static bool IsCompileTimeValue(Expression* expression); |
| 1006 | 938 |
| 1007 // Get the value as a compile time value. | 939 // Get the value as a compile time value. |
| 1008 static Handle<FixedArray> GetValue(Isolate* isolate, Expression* expression); | 940 static Handle<FixedArray> GetValue(Isolate* isolate, Expression* expression); |
| 1009 | 941 |
| 1010 // Get the type of a compile time value returned by GetValue(). | 942 // Get the type of a compile time value returned by GetValue(). |
| 1011 static LiteralType GetLiteralType(Handle<FixedArray> value); | 943 static LiteralType GetLiteralType(Handle<FixedArray> value); |
| 1012 | 944 |
| 1013 // Get the elements array of a compile time value returned by GetValue(). | 945 // Get the elements array of a compile time value returned by GetValue(). |
| 1014 static Handle<FixedArray> GetElements(Handle<FixedArray> value); | 946 static Handle<FixedArray> GetElements(Handle<FixedArray> value); |
| 1015 | 947 |
| 1016 private: | 948 private: |
| 1017 static const int kLiteralTypeSlot = 0; | 949 static const int kLiteralTypeSlot = 0; |
| 1018 static const int kElementsSlot = 1; | 950 static const int kElementsSlot = 1; |
| 1019 | 951 |
| 1020 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 952 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 1021 }; | 953 }; |
| 1022 | 954 |
| 1023 ParserBaseTraits<Parser>::TemplateLiteralState | |
| 1024 ParserBaseTraits<Parser>::OpenTemplateLiteral(int pos) { | |
| 1025 return delegate()->OpenTemplateLiteral(pos); | |
| 1026 } | |
| 1027 | |
| 1028 void ParserBaseTraits<Parser>::AddTemplateSpan(TemplateLiteralState* state, | |
| 1029 bool tail) { | |
| 1030 delegate()->AddTemplateSpan(state, tail); | |
| 1031 } | |
| 1032 | |
| 1033 void ParserBaseTraits<Parser>::AddTemplateExpression( | |
| 1034 TemplateLiteralState* state, Expression* expression) { | |
| 1035 delegate()->AddTemplateExpression(state, expression); | |
| 1036 } | |
| 1037 | |
| 1038 Expression* ParserBaseTraits<Parser>::CloseTemplateLiteral( | |
| 1039 TemplateLiteralState* state, int start, Expression* tag) { | |
| 1040 return delegate()->CloseTemplateLiteral(state, start, tag); | |
| 1041 } | |
| 1042 | |
| 1043 ZoneList<v8::internal::Expression*>* ParserBaseTraits< | |
| 1044 Parser>::PrepareSpreadArguments(ZoneList<v8::internal::Expression*>* list) { | |
| 1045 return delegate()->PrepareSpreadArguments(list); | |
| 1046 } | |
| 1047 | |
| 1048 Expression* ParserBaseTraits<Parser>::SpreadCall( | |
| 1049 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) { | |
| 1050 return delegate()->SpreadCall(function, args, pos); | |
| 1051 } | |
| 1052 | |
| 1053 Expression* ParserBaseTraits<Parser>::SpreadCallNew( | |
| 1054 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) { | |
| 1055 return delegate()->SpreadCallNew(function, args, pos); | |
| 1056 } | |
| 1057 | |
| 1058 void ParserBaseTraits<Parser>::AddFormalParameter( | 955 void ParserBaseTraits<Parser>::AddFormalParameter( |
| 1059 ParserFormalParameters* parameters, Expression* pattern, | 956 ParserFormalParameters* parameters, Expression* pattern, |
| 1060 Expression* initializer, int initializer_end_position, bool is_rest) { | 957 Expression* initializer, int initializer_end_position, bool is_rest) { |
| 1061 bool is_simple = pattern->IsVariableProxy() && initializer == nullptr; | 958 bool is_simple = pattern->IsVariableProxy() && initializer == nullptr; |
| 1062 const AstRawString* name = | 959 const AstRawString* name = |
| 1063 is_simple ? pattern->AsVariableProxy()->raw_name() | 960 is_simple ? pattern->AsVariableProxy()->raw_name() |
| 1064 : delegate()->ast_value_factory()->empty_string(); | 961 : delegate()->ast_value_factory()->empty_string(); |
| 1065 parameters->params.Add( | 962 parameters->params.Add( |
| 1066 ParserFormalParameters::Parameter(name, pattern, initializer, | 963 ParserFormalParameters::Parameter(name, pattern, initializer, |
| 1067 initializer_end_position, is_rest), | 964 initializer_end_position, is_rest), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 if (is_async) { | 1002 if (is_async) { |
| 1106 init_block = delegate()->BuildRejectPromiseOnException(init_block); | 1003 init_block = delegate()->BuildRejectPromiseOnException(init_block); |
| 1107 } | 1004 } |
| 1108 | 1005 |
| 1109 if (init_block != nullptr) { | 1006 if (init_block != nullptr) { |
| 1110 body->Add(init_block, delegate()->zone()); | 1007 body->Add(init_block, delegate()->zone()); |
| 1111 } | 1008 } |
| 1112 } | 1009 } |
| 1113 } | 1010 } |
| 1114 | 1011 |
| 1115 Expression* ParserBaseTraits<Parser>::ParseAsyncFunctionExpression(bool* ok) { | |
| 1116 return delegate()->ParseAsyncFunctionExpression(ok); | |
| 1117 } | |
| 1118 | |
| 1119 DoExpression* ParserBaseTraits<Parser>::ParseDoExpression(bool* ok) { | |
| 1120 return delegate()->ParseDoExpression(ok); | |
| 1121 } | |
| 1122 | |
| 1123 Expression* ParserBaseTraits<Parser>::RewriteYieldStar(Expression* generator, | |
| 1124 Expression* iterable, | |
| 1125 int pos) { | |
| 1126 return delegate()->RewriteYieldStar(generator, iterable, pos); | |
| 1127 } | |
| 1128 | |
| 1129 } // namespace internal | 1012 } // namespace internal |
| 1130 } // namespace v8 | 1013 } // namespace v8 |
| 1131 | 1014 |
| 1132 #endif // V8_PARSING_PARSER_H_ | 1015 #endif // V8_PARSING_PARSER_H_ |
| OLD | NEW |