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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 static const int kMaxNumFunctionParameters = 32766; | 447 static const int kMaxNumFunctionParameters = 32766; |
446 static const int kMaxNumFunctionLocals = 32767; | 448 static const int kMaxNumFunctionLocals = 32767; |
447 FunctionLiteral* ParseLazy(CompilationInfo* info, | 449 FunctionLiteral* ParseLazy(CompilationInfo* info, |
448 UC16CharacterStream* source, | 450 UC16CharacterStream* source, |
449 ZoneScope* zone_scope); | 451 ZoneScope* zone_scope); |
450 enum Mode { | 452 enum Mode { |
451 PARSE_LAZILY, | 453 PARSE_LAZILY, |
452 PARSE_EAGERLY | 454 PARSE_EAGERLY |
453 }; | 455 }; |
454 | 456 |
| 457 enum VariableDeclarationContext { |
| 458 kSourceElement, |
| 459 kStatement, |
| 460 kForStatement |
| 461 }; |
| 462 |
455 Isolate* isolate() { return isolate_; } | 463 Isolate* isolate() { return isolate_; } |
456 Zone* zone() { return isolate_->zone(); } | 464 Zone* zone() { return isolate_->zone(); } |
457 | 465 |
458 // Called by ParseProgram after setting up the scanner. | 466 // Called by ParseProgram after setting up the scanner. |
459 FunctionLiteral* DoParseProgram(Handle<String> source, | 467 FunctionLiteral* DoParseProgram(Handle<String> source, |
460 bool in_global_context, | 468 bool in_global_context, |
461 StrictModeFlag strict_mode, | 469 StrictModeFlag strict_mode, |
462 ZoneScope* zone_scope); | 470 ZoneScope* zone_scope); |
463 | 471 |
464 // Report syntax error | 472 // Report syntax error |
465 void ReportUnexpectedToken(Token::Value token); | 473 void ReportUnexpectedToken(Token::Value token); |
466 void ReportInvalidPreparseData(Handle<String> name, bool* ok); | 474 void ReportInvalidPreparseData(Handle<String> name, bool* ok); |
467 void ReportMessage(const char* message, Vector<const char*> args); | 475 void ReportMessage(const char* message, Vector<const char*> args); |
468 | 476 |
469 bool inside_with() const { return with_nesting_level_ > 0; } | 477 bool inside_with() const { return with_nesting_level_ > 0; } |
470 JavaScriptScanner& scanner() { return scanner_; } | 478 JavaScriptScanner& scanner() { return scanner_; } |
471 Mode mode() const { return mode_; } | 479 Mode mode() const { return mode_; } |
472 ScriptDataImpl* pre_data() const { return pre_data_; } | 480 ScriptDataImpl* pre_data() const { return pre_data_; } |
473 | 481 |
474 // Check if the given string is 'eval' or 'arguments'. | 482 // Check if the given string is 'eval' or 'arguments'. |
475 bool IsEvalOrArguments(Handle<String> string); | 483 bool IsEvalOrArguments(Handle<String> string); |
476 | 484 |
477 // All ParseXXX functions take as the last argument an *ok parameter | 485 // All ParseXXX functions take as the last argument an *ok parameter |
478 // 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. |
479 // By making the 'exception handling' explicit, we are forced to check | 487 // By making the 'exception handling' explicit, we are forced to check |
480 // for failure at the call sites. | 488 // for failure at the call sites. |
481 void* ParseSourceElements(ZoneList<Statement*>* processor, | 489 void* ParseSourceElements(ZoneList<Statement*>* processor, |
482 int end_token, bool* ok); | 490 int end_token, bool* ok); |
| 491 Statement* ParseSourceElement(ZoneStringList* labels, bool* ok); |
483 Statement* ParseStatement(ZoneStringList* labels, bool* ok); | 492 Statement* ParseStatement(ZoneStringList* labels, bool* ok); |
484 Statement* ParseFunctionDeclaration(bool* ok); | 493 Statement* ParseFunctionDeclaration(bool* ok); |
485 Statement* ParseNativeDeclaration(bool* ok); | 494 Statement* ParseNativeDeclaration(bool* ok); |
486 Block* ParseBlock(ZoneStringList* labels, bool* ok); | 495 Block* ParseBlock(ZoneStringList* labels, bool* ok); |
487 Block* ParseScopedBlock(ZoneStringList* labels, bool* ok); | 496 Block* ParseScopedBlock(ZoneStringList* labels, bool* ok); |
488 Block* ParseVariableStatement(bool* ok); | 497 Block* ParseVariableStatement(VariableDeclarationContext var_context, |
489 Block* ParseVariableDeclarations(bool accept_IN, | 498 bool* ok); |
| 499 Block* ParseVariableDeclarations(VariableDeclarationContext var_context, |
490 Handle<String>* out, | 500 Handle<String>* out, |
491 bool* ok); | 501 bool* ok); |
492 Statement* ParseExpressionOrLabelledStatement(ZoneStringList* labels, | 502 Statement* ParseExpressionOrLabelledStatement(ZoneStringList* labels, |
493 bool* ok); | 503 bool* ok); |
494 IfStatement* ParseIfStatement(ZoneStringList* labels, bool* ok); | 504 IfStatement* ParseIfStatement(ZoneStringList* labels, bool* ok); |
495 Statement* ParseContinueStatement(bool* ok); | 505 Statement* ParseContinueStatement(bool* ok); |
496 Statement* ParseBreakStatement(ZoneStringList* labels, bool* ok); | 506 Statement* ParseBreakStatement(ZoneStringList* labels, bool* ok); |
497 Statement* ParseReturnStatement(bool* ok); | 507 Statement* ParseReturnStatement(bool* ok); |
498 Statement* ParseWithStatement(ZoneStringList* labels, bool* ok); | 508 Statement* ParseWithStatement(ZoneStringList* labels, bool* ok); |
499 CaseClause* ParseCaseClause(bool* default_seen_ptr, bool* ok); | 509 CaseClause* ParseCaseClause(bool* default_seen_ptr, bool* ok); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 private: | 758 private: |
749 static const int kTypeSlot = 0; | 759 static const int kTypeSlot = 0; |
750 static const int kElementsSlot = 1; | 760 static const int kElementsSlot = 1; |
751 | 761 |
752 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 762 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
753 }; | 763 }; |
754 | 764 |
755 } } // namespace v8::internal | 765 } } // namespace v8::internal |
756 | 766 |
757 #endif // V8_PARSER_H_ | 767 #endif // V8_PARSER_H_ |
OLD | NEW |