| OLD | NEW |
| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 157 |
| 158 class ParserApi { | 158 class ParserApi { |
| 159 public: | 159 public: |
| 160 // Parses the source code represented by the compilation info and sets its | 160 // Parses the source code represented by the compilation info and sets its |
| 161 // function literal. Returns false (and deallocates any allocated AST | 161 // function literal. Returns false (and deallocates any allocated AST |
| 162 // nodes) if parsing failed. | 162 // nodes) if parsing failed. |
| 163 static bool Parse(CompilationInfo* info); | 163 static bool Parse(CompilationInfo* info); |
| 164 | 164 |
| 165 // Generic preparser generating full preparse data. | 165 // Generic preparser generating full preparse data. |
| 166 static ScriptDataImpl* PreParse(UC16CharacterStream* source, | 166 static ScriptDataImpl* PreParse(UC16CharacterStream* source, |
| 167 v8::Extension* extension); | 167 v8::Extension* extension, |
| 168 bool harmony_block_scoping); |
| 168 | 169 |
| 169 // Preparser that only does preprocessing that makes sense if only used | 170 // Preparser that only does preprocessing that makes sense if only used |
| 170 // immediately after. | 171 // immediately after. |
| 171 static ScriptDataImpl* PartialPreParse(UC16CharacterStream* source, | 172 static ScriptDataImpl* PartialPreParse(UC16CharacterStream* source, |
| 172 v8::Extension* extension); | 173 v8::Extension* extension, |
| 174 bool harmony_block_scoping); |
| 173 }; | 175 }; |
| 174 | 176 |
| 175 // ---------------------------------------------------------------------------- | 177 // ---------------------------------------------------------------------------- |
| 176 // REGEXP PARSING | 178 // REGEXP PARSING |
| 177 | 179 |
| 178 // A BuffferedZoneList is an automatically growing list, just like (and backed | 180 // A BuffferedZoneList is an automatically growing list, just like (and backed |
| 179 // by) a ZoneList, that is optimized for the case of adding and removing | 181 // by) a ZoneList, that is optimized for the case of adding and removing |
| 180 // a single element. The last element added is stored outside the backing list, | 182 // a single element. The last element added is stored outside the backing list, |
| 181 // and if no more than one element is ever added, the ZoneList isn't even | 183 // and if no more than one element is ever added, the ZoneList isn't even |
| 182 // allocated. | 184 // allocated. |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 StrictModeFlag strict_mode); | 430 StrictModeFlag strict_mode); |
| 429 | 431 |
| 430 FunctionLiteral* ParseLazy(CompilationInfo* info); | 432 FunctionLiteral* ParseLazy(CompilationInfo* info); |
| 431 | 433 |
| 432 void ReportMessageAt(Scanner::Location loc, | 434 void ReportMessageAt(Scanner::Location loc, |
| 433 const char* message, | 435 const char* message, |
| 434 Vector<const char*> args); | 436 Vector<const char*> args); |
| 435 void ReportMessageAt(Scanner::Location loc, | 437 void ReportMessageAt(Scanner::Location loc, |
| 436 const char* message, | 438 const char* message, |
| 437 Vector<Handle<String> > args); | 439 Vector<Handle<String> > args); |
| 440 void SetHarmonyBlockScoping(bool block_scoping); |
| 438 | 441 |
| 439 private: | 442 private: |
| 440 // Limit on number of function parameters is chosen arbitrarily. | 443 // Limit on number of function parameters is chosen arbitrarily. |
| 441 // Code::Flags uses only the low 17 bits of num-parameters to | 444 // Code::Flags uses only the low 17 bits of num-parameters to |
| 442 // construct a hashable id, so if more than 2^17 are allowed, this | 445 // construct a hashable id, so if more than 2^17 are allowed, this |
| 443 // should be checked. | 446 // should be checked. |
| 444 static const int kMaxNumFunctionParameters = 32766; | 447 static const int kMaxNumFunctionParameters = 32766; |
| 445 static const int kMaxNumFunctionLocals = 32767; | 448 static const int kMaxNumFunctionLocals = 32767; |
| 446 FunctionLiteral* ParseLazy(CompilationInfo* info, | 449 FunctionLiteral* ParseLazy(CompilationInfo* info, |
| 447 UC16CharacterStream* source, | 450 UC16CharacterStream* source, |
| 448 ZoneScope* zone_scope); | 451 ZoneScope* zone_scope); |
| 449 enum Mode { | 452 enum Mode { |
| 450 PARSE_LAZILY, | 453 PARSE_LAZILY, |
| 451 PARSE_EAGERLY | 454 PARSE_EAGERLY |
| 452 }; | 455 }; |
| 453 | 456 |
| 457 enum VariableDeclarationContext { |
| 458 kSourceElement, |
| 459 kStatement, |
| 460 kForStatement |
| 461 }; |
| 462 |
| 454 Isolate* isolate() { return isolate_; } | 463 Isolate* isolate() { return isolate_; } |
| 455 Zone* zone() { return isolate_->zone(); } | 464 Zone* zone() { return isolate_->zone(); } |
| 456 | 465 |
| 457 // Called by ParseProgram after setting up the scanner. | 466 // Called by ParseProgram after setting up the scanner. |
| 458 FunctionLiteral* DoParseProgram(Handle<String> source, | 467 FunctionLiteral* DoParseProgram(Handle<String> source, |
| 459 bool in_global_context, | 468 bool in_global_context, |
| 460 StrictModeFlag strict_mode, | 469 StrictModeFlag strict_mode, |
| 461 ZoneScope* zone_scope); | 470 ZoneScope* zone_scope); |
| 462 | 471 |
| 463 // Report syntax error | 472 // Report syntax error |
| 464 void ReportUnexpectedToken(Token::Value token); | 473 void ReportUnexpectedToken(Token::Value token); |
| 465 void ReportInvalidPreparseData(Handle<String> name, bool* ok); | 474 void ReportInvalidPreparseData(Handle<String> name, bool* ok); |
| 466 void ReportMessage(const char* message, Vector<const char*> args); | 475 void ReportMessage(const char* message, Vector<const char*> args); |
| 467 | 476 |
| 468 bool inside_with() const { return with_nesting_level_ > 0; } | 477 bool inside_with() const { return with_nesting_level_ > 0; } |
| 469 JavaScriptScanner& scanner() { return scanner_; } | 478 JavaScriptScanner& scanner() { return scanner_; } |
| 470 Mode mode() const { return mode_; } | 479 Mode mode() const { return mode_; } |
| 471 ScriptDataImpl* pre_data() const { return pre_data_; } | 480 ScriptDataImpl* pre_data() const { return pre_data_; } |
| 472 | 481 |
| 473 // Check if the given string is 'eval' or 'arguments'. | 482 // Check if the given string is 'eval' or 'arguments'. |
| 474 bool IsEvalOrArguments(Handle<String> string); | 483 bool IsEvalOrArguments(Handle<String> string); |
| 475 | 484 |
| 476 // All ParseXXX functions take as the last argument an *ok parameter | 485 // All ParseXXX functions take as the last argument an *ok parameter |
| 477 // which is set to false if parsing failed; it is unchanged otherwise. | 486 // which is set to false if parsing failed; it is unchanged otherwise. |
| 478 // By making the 'exception handling' explicit, we are forced to check | 487 // By making the 'exception handling' explicit, we are forced to check |
| 479 // for failure at the call sites. | 488 // for failure at the call sites. |
| 480 void* ParseSourceElements(ZoneList<Statement*>* processor, | 489 void* ParseSourceElements(ZoneList<Statement*>* processor, |
| 481 int end_token, bool* ok); | 490 int end_token, bool* ok); |
| 491 Statement* ParseSourceElement(ZoneStringList* labels, bool* ok); |
| 482 Statement* ParseStatement(ZoneStringList* labels, bool* ok); | 492 Statement* ParseStatement(ZoneStringList* labels, bool* ok); |
| 483 Statement* ParseFunctionDeclaration(bool* ok); | 493 Statement* ParseFunctionDeclaration(bool* ok); |
| 484 Statement* ParseNativeDeclaration(bool* ok); | 494 Statement* ParseNativeDeclaration(bool* ok); |
| 485 Block* ParseBlock(ZoneStringList* labels, bool* ok); | 495 Block* ParseBlock(ZoneStringList* labels, bool* ok); |
| 486 Block* ParseVariableStatement(bool* ok); | 496 Block* ParseScopedBlock(ZoneStringList* labels, bool* ok); |
| 487 Block* ParseVariableDeclarations(bool accept_IN, | 497 Block* ParseVariableStatement(VariableDeclarationContext var_context, |
| 498 bool* ok); |
| 499 Block* ParseVariableDeclarations(VariableDeclarationContext var_context, |
| 488 Handle<String>* out, | 500 Handle<String>* out, |
| 489 bool* ok); | 501 bool* ok); |
| 490 Statement* ParseExpressionOrLabelledStatement(ZoneStringList* labels, | 502 Statement* ParseExpressionOrLabelledStatement(ZoneStringList* labels, |
| 491 bool* ok); | 503 bool* ok); |
| 492 IfStatement* ParseIfStatement(ZoneStringList* labels, bool* ok); | 504 IfStatement* ParseIfStatement(ZoneStringList* labels, bool* ok); |
| 493 Statement* ParseContinueStatement(bool* ok); | 505 Statement* ParseContinueStatement(bool* ok); |
| 494 Statement* ParseBreakStatement(ZoneStringList* labels, bool* ok); | 506 Statement* ParseBreakStatement(ZoneStringList* labels, bool* ok); |
| 495 Statement* ParseReturnStatement(bool* ok); | 507 Statement* ParseReturnStatement(bool* ok); |
| 496 Block* WithHelper(Expression* obj, ZoneStringList* labels, bool* ok); | |
| 497 Statement* ParseWithStatement(ZoneStringList* labels, bool* ok); | 508 Statement* ParseWithStatement(ZoneStringList* labels, bool* ok); |
| 498 CaseClause* ParseCaseClause(bool* default_seen_ptr, bool* ok); | 509 CaseClause* ParseCaseClause(bool* default_seen_ptr, bool* ok); |
| 499 SwitchStatement* ParseSwitchStatement(ZoneStringList* labels, bool* ok); | 510 SwitchStatement* ParseSwitchStatement(ZoneStringList* labels, bool* ok); |
| 500 DoWhileStatement* ParseDoWhileStatement(ZoneStringList* labels, bool* ok); | 511 DoWhileStatement* ParseDoWhileStatement(ZoneStringList* labels, bool* ok); |
| 501 WhileStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok); | 512 WhileStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok); |
| 502 Statement* ParseForStatement(ZoneStringList* labels, bool* ok); | 513 Statement* ParseForStatement(ZoneStringList* labels, bool* ok); |
| 503 Statement* ParseThrowStatement(bool* ok); | 514 Statement* ParseThrowStatement(bool* ok); |
| 504 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); | 515 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); |
| 505 TryStatement* ParseTryStatement(bool* ok); | 516 TryStatement* ParseTryStatement(bool* ok); |
| 506 DebuggerStatement* ParseDebuggerStatement(bool* ok); | 517 DebuggerStatement* ParseDebuggerStatement(bool* ok); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 | 556 |
| 546 // Decide if a property should be in the object boilerplate. | 557 // Decide if a property should be in the object boilerplate. |
| 547 bool IsBoilerplateProperty(ObjectLiteral::Property* property); | 558 bool IsBoilerplateProperty(ObjectLiteral::Property* property); |
| 548 // If the expression is a literal, return the literal value; | 559 // If the expression is a literal, return the literal value; |
| 549 // if the expression is a materialized literal and is simple return a | 560 // if the expression is a materialized literal and is simple return a |
| 550 // compile time value as encoded by CompileTimeValue::GetValue(). | 561 // compile time value as encoded by CompileTimeValue::GetValue(). |
| 551 // Otherwise, return undefined literal as the placeholder | 562 // Otherwise, return undefined literal as the placeholder |
| 552 // in the object literal boilerplate. | 563 // in the object literal boilerplate. |
| 553 Handle<Object> GetBoilerplateValue(Expression* expression); | 564 Handle<Object> GetBoilerplateValue(Expression* expression); |
| 554 | 565 |
| 555 enum FunctionLiteralType { | |
| 556 EXPRESSION, | |
| 557 DECLARATION | |
| 558 }; | |
| 559 | |
| 560 ZoneList<Expression*>* ParseArguments(bool* ok); | 566 ZoneList<Expression*>* ParseArguments(bool* ok); |
| 561 FunctionLiteral* ParseFunctionLiteral(Handle<String> var_name, | 567 FunctionLiteral* ParseFunctionLiteral(Handle<String> var_name, |
| 562 bool name_is_reserved, | 568 bool name_is_reserved, |
| 563 int function_token_position, | 569 int function_token_position, |
| 564 FunctionLiteralType type, | 570 FunctionLiteral::Type type, |
| 565 bool* ok); | 571 bool* ok); |
| 566 | 572 |
| 567 | 573 |
| 568 // Magical syntax support. | 574 // Magical syntax support. |
| 569 Expression* ParseV8Intrinsic(bool* ok); | 575 Expression* ParseV8Intrinsic(bool* ok); |
| 570 | 576 |
| 571 INLINE(Token::Value peek()) { | 577 INLINE(Token::Value peek()) { |
| 572 if (stack_overflow_) return Token::ILLEGAL; | 578 if (stack_overflow_) return Token::ILLEGAL; |
| 573 return scanner().peek(); | 579 return scanner().peek(); |
| 574 } | 580 } |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 v8::Extension* extension_; | 719 v8::Extension* extension_; |
| 714 bool is_pre_parsing_; | 720 bool is_pre_parsing_; |
| 715 ScriptDataImpl* pre_data_; | 721 ScriptDataImpl* pre_data_; |
| 716 FuncNameInferrer* fni_; | 722 FuncNameInferrer* fni_; |
| 717 bool stack_overflow_; | 723 bool stack_overflow_; |
| 718 // If true, the next (and immediately following) function literal is | 724 // If true, the next (and immediately following) function literal is |
| 719 // preceded by a parenthesis. | 725 // preceded by a parenthesis. |
| 720 // Heuristically that means that the function will be called immediately, | 726 // Heuristically that means that the function will be called immediately, |
| 721 // so never lazily compile it. | 727 // so never lazily compile it. |
| 722 bool parenthesized_function_; | 728 bool parenthesized_function_; |
| 729 bool harmony_block_scoping_; |
| 723 | 730 |
| 724 friend class LexicalScope; | 731 friend class LexicalScope; |
| 725 }; | 732 }; |
| 726 | 733 |
| 727 | 734 |
| 728 // Support for handling complex values (array and object literals) that | 735 // Support for handling complex values (array and object literals) that |
| 729 // can be fully handled at compile time. | 736 // can be fully handled at compile time. |
| 730 class CompileTimeValue: public AllStatic { | 737 class CompileTimeValue: public AllStatic { |
| 731 public: | 738 public: |
| 732 enum Type { | 739 enum Type { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 751 private: | 758 private: |
| 752 static const int kTypeSlot = 0; | 759 static const int kTypeSlot = 0; |
| 753 static const int kElementsSlot = 1; | 760 static const int kElementsSlot = 1; |
| 754 | 761 |
| 755 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 762 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 756 }; | 763 }; |
| 757 | 764 |
| 758 } } // namespace v8::internal | 765 } } // namespace v8::internal |
| 759 | 766 |
| 760 #endif // V8_PARSER_H_ | 767 #endif // V8_PARSER_H_ |
| OLD | NEW |