| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 | 403 |
| 404 // ---------------------------------------------------------------------------- | 404 // ---------------------------------------------------------------------------- |
| 405 // JAVASCRIPT PARSING | 405 // JAVASCRIPT PARSING |
| 406 | 406 |
| 407 class Parser; | 407 class Parser; |
| 408 class SingletonLogger; | 408 class SingletonLogger; |
| 409 | 409 |
| 410 class ParserTraits { | 410 class ParserTraits { |
| 411 public: | 411 public: |
| 412 typedef Parser* ParserType; | 412 typedef Parser* ParserType; |
| 413 |
| 414 // Types used by FunctionState and BlockState. |
| 415 typedef Scope ScopeClass; |
| 416 typedef AstNodeFactory<AstConstructionVisitor> FactoryType; |
| 417 typedef Variable GeneratorVariableType; |
| 418 typedef Zone FunctionStateParamType; |
| 419 |
| 413 // Return types for traversing functions. | 420 // Return types for traversing functions. |
| 414 typedef Handle<String> IdentifierType; | 421 typedef Handle<String> IdentifierType; |
| 415 typedef Expression* ExpressionType; | 422 typedef Expression* ExpressionType; |
| 416 | 423 |
| 417 explicit ParserTraits(Parser* parser) : parser_(parser) {} | 424 explicit ParserTraits(Parser* parser) : parser_(parser) {} |
| 418 | 425 |
| 426 // Custom operations executed when FunctionStates are created and destructed. |
| 427 template<typename FS> |
| 428 static void SetUpFunctionState(FS* function_state, Zone* zone) { |
| 429 Isolate* isolate = zone->isolate(); |
| 430 function_state->isolate_ = isolate; |
| 431 function_state->saved_ast_node_id_ = isolate->ast_node_id(); |
| 432 isolate->set_ast_node_id(BailoutId::FirstUsable().ToInt()); |
| 433 } |
| 434 |
| 435 template<typename FS> |
| 436 static void TearDownFunctionState(FS* function_state) { |
| 437 if (function_state->outer_function_state_ != NULL) { |
| 438 function_state->isolate_->set_ast_node_id( |
| 439 function_state->saved_ast_node_id_); |
| 440 } |
| 441 } |
| 442 |
| 419 // Helper functions for recursive descent. | 443 // Helper functions for recursive descent. |
| 420 bool is_classic_mode() const; | |
| 421 bool is_generator() const; | |
| 422 bool IsEvalOrArguments(Handle<String> identifier) const; | 444 bool IsEvalOrArguments(Handle<String> identifier) const; |
| 423 int NextMaterializedLiteralIndex(); | |
| 424 | 445 |
| 425 // Reporting errors. | 446 // Reporting errors. |
| 426 void ReportMessageAt(Scanner::Location source_location, | 447 void ReportMessageAt(Scanner::Location source_location, |
| 427 const char* message, | 448 const char* message, |
| 428 Vector<const char*> args); | 449 Vector<const char*> args); |
| 429 void ReportMessage(const char* message, Vector<Handle<String> > args); | 450 void ReportMessage(const char* message, Vector<Handle<String> > args); |
| 430 void ReportMessageAt(Scanner::Location source_location, | 451 void ReportMessageAt(Scanner::Location source_location, |
| 431 const char* message, | 452 const char* message, |
| 432 Vector<Handle<String> > args); | 453 Vector<Handle<String> > args); |
| 433 | 454 |
| 434 // "null" return type creators. | 455 // "null" return type creators. |
| 435 static IdentifierType EmptyIdentifier() { | 456 static IdentifierType EmptyIdentifier() { |
| 436 return Handle<String>(); | 457 return Handle<String>(); |
| 437 } | 458 } |
| 438 static ExpressionType EmptyExpression() { | 459 static ExpressionType EmptyExpression() { |
| 439 return NULL; | 460 return NULL; |
| 440 } | 461 } |
| 441 | 462 |
| 442 // Producing data during the recursive descent. | 463 // Producing data during the recursive descent. |
| 443 IdentifierType GetSymbol(); | 464 IdentifierType GetSymbol(); |
| 444 IdentifierType NextLiteralString(PretenureFlag tenured); | 465 IdentifierType NextLiteralString(PretenureFlag tenured); |
| 445 ExpressionType NewRegExpLiteral(IdentifierType js_pattern, | |
| 446 IdentifierType js_flags, | |
| 447 int literal_index, | |
| 448 int pos); | |
| 449 | 466 |
| 450 private: | 467 private: |
| 451 Parser* parser_; | 468 Parser* parser_; |
| 452 }; | 469 }; |
| 453 | 470 |
| 454 | 471 |
| 455 class Parser : public ParserBase<ParserTraits> { | 472 class Parser : public ParserBase<ParserTraits> { |
| 456 public: | 473 public: |
| 457 explicit Parser(CompilationInfo* info); | 474 explicit Parser(CompilationInfo* info); |
| 458 ~Parser() { | 475 ~Parser() { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 487 kStatement, | 504 kStatement, |
| 488 kForStatement | 505 kForStatement |
| 489 }; | 506 }; |
| 490 | 507 |
| 491 // If a list of variable declarations includes any initializers. | 508 // If a list of variable declarations includes any initializers. |
| 492 enum VariableDeclarationProperties { | 509 enum VariableDeclarationProperties { |
| 493 kHasInitializers, | 510 kHasInitializers, |
| 494 kHasNoInitializers | 511 kHasNoInitializers |
| 495 }; | 512 }; |
| 496 | 513 |
| 497 class BlockState; | |
| 498 | |
| 499 class FunctionState BASE_EMBEDDED { | |
| 500 public: | |
| 501 FunctionState(FunctionState** function_state_stack, | |
| 502 Scope** scope_stack, Scope* scope, | |
| 503 Zone* zone); | |
| 504 ~FunctionState(); | |
| 505 | |
| 506 int NextMaterializedLiteralIndex() { | |
| 507 return next_materialized_literal_index_++; | |
| 508 } | |
| 509 int materialized_literal_count() { | |
| 510 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; | |
| 511 } | |
| 512 | |
| 513 int NextHandlerIndex() { return next_handler_index_++; } | |
| 514 int handler_count() { return next_handler_index_; } | |
| 515 | |
| 516 void AddProperty() { expected_property_count_++; } | |
| 517 int expected_property_count() { return expected_property_count_; } | |
| 518 | |
| 519 void set_generator_object_variable(Variable *variable) { | |
| 520 ASSERT(variable != NULL); | |
| 521 ASSERT(!is_generator()); | |
| 522 generator_object_variable_ = variable; | |
| 523 } | |
| 524 Variable* generator_object_variable() const { | |
| 525 return generator_object_variable_; | |
| 526 } | |
| 527 bool is_generator() const { | |
| 528 return generator_object_variable_ != NULL; | |
| 529 } | |
| 530 | |
| 531 AstNodeFactory<AstConstructionVisitor>* factory() { return &factory_; } | |
| 532 | |
| 533 private: | |
| 534 // Used to assign an index to each literal that needs materialization in | |
| 535 // the function. Includes regexp literals, and boilerplate for object and | |
| 536 // array literals. | |
| 537 int next_materialized_literal_index_; | |
| 538 | |
| 539 // Used to assign a per-function index to try and catch handlers. | |
| 540 int next_handler_index_; | |
| 541 | |
| 542 // Properties count estimation. | |
| 543 int expected_property_count_; | |
| 544 | |
| 545 // For generators, the variable that holds the generator object. This | |
| 546 // variable is used by yield expressions and return statements. NULL | |
| 547 // indicates that this function is not a generator. | |
| 548 Variable* generator_object_variable_; | |
| 549 | |
| 550 FunctionState** function_state_stack_; | |
| 551 FunctionState* outer_function_state_; | |
| 552 Scope** scope_stack_; | |
| 553 Scope* outer_scope_; | |
| 554 Isolate* isolate_; | |
| 555 int saved_ast_node_id_; | |
| 556 AstNodeFactory<AstConstructionVisitor> factory_; | |
| 557 }; | |
| 558 | |
| 559 class ParsingModeScope BASE_EMBEDDED { | 514 class ParsingModeScope BASE_EMBEDDED { |
| 560 public: | 515 public: |
| 561 ParsingModeScope(Parser* parser, Mode mode) | 516 ParsingModeScope(Parser* parser, Mode mode) |
| 562 : parser_(parser), | 517 : parser_(parser), |
| 563 old_mode_(parser->mode()) { | 518 old_mode_(parser->mode()) { |
| 564 parser_->mode_ = mode; | 519 parser_->mode_ = mode; |
| 565 } | 520 } |
| 566 ~ParsingModeScope() { | 521 ~ParsingModeScope() { |
| 567 parser_->mode_ = old_mode_; | 522 parser_->mode_ = old_mode_; |
| 568 } | 523 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 Handle<Object> second); | 718 Handle<Object> second); |
| 764 | 719 |
| 765 // Generic AST generator for throwing errors from compiled code. | 720 // Generic AST generator for throwing errors from compiled code. |
| 766 Expression* NewThrowError(Handle<String> constructor, | 721 Expression* NewThrowError(Handle<String> constructor, |
| 767 Handle<String> type, | 722 Handle<String> type, |
| 768 Vector< Handle<Object> > arguments); | 723 Vector< Handle<Object> > arguments); |
| 769 | 724 |
| 770 PreParser::PreParseResult LazyParseFunctionLiteral( | 725 PreParser::PreParseResult LazyParseFunctionLiteral( |
| 771 SingletonLogger* logger); | 726 SingletonLogger* logger); |
| 772 | 727 |
| 773 AstNodeFactory<AstConstructionVisitor>* factory() { | |
| 774 return function_state_->factory(); | |
| 775 } | |
| 776 | |
| 777 Isolate* isolate_; | 728 Isolate* isolate_; |
| 778 ZoneList<Handle<String> > symbol_cache_; | 729 ZoneList<Handle<String> > symbol_cache_; |
| 779 | 730 |
| 780 Handle<Script> script_; | 731 Handle<Script> script_; |
| 781 Scanner scanner_; | 732 Scanner scanner_; |
| 782 PreParser* reusable_preparser_; | 733 PreParser* reusable_preparser_; |
| 783 Scope* scope_; // Scope stack. | |
| 784 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 734 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
| 785 FunctionState* function_state_; // Function state stack. | |
| 786 Target* target_stack_; // for break, continue statements | 735 Target* target_stack_; // for break, continue statements |
| 787 v8::Extension* extension_; | 736 v8::Extension* extension_; |
| 788 ScriptDataImpl* pre_parse_data_; | 737 ScriptDataImpl* pre_parse_data_; |
| 789 FuncNameInferrer* fni_; | 738 FuncNameInferrer* fni_; |
| 790 | 739 |
| 791 Mode mode_; | 740 Mode mode_; |
| 792 | 741 |
| 793 Zone* zone_; | 742 Zone* zone_; |
| 794 CompilationInfo* info_; | 743 CompilationInfo* info_; |
| 795 }; | 744 }; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 819 private: | 768 private: |
| 820 static const int kLiteralTypeSlot = 0; | 769 static const int kLiteralTypeSlot = 0; |
| 821 static const int kElementsSlot = 1; | 770 static const int kElementsSlot = 1; |
| 822 | 771 |
| 823 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 772 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 824 }; | 773 }; |
| 825 | 774 |
| 826 } } // namespace v8::internal | 775 } } // namespace v8::internal |
| 827 | 776 |
| 828 #endif // V8_PARSER_H_ | 777 #endif // V8_PARSER_H_ |
| OLD | NEW |