Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(607)

Side by Side Diff: src/parser.h

Issue 5862002: Version 3.0.2. (Closed)
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« ChangeLog ('K') | « src/objects.h ('k') | src/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 162
163 163
164 class ParserApi { 164 class ParserApi {
165 public: 165 public:
166 // Parses the source code represented by the compilation info and sets its 166 // Parses the source code represented by the compilation info and sets its
167 // function literal. Returns false (and deallocates any allocated AST 167 // function literal. Returns false (and deallocates any allocated AST
168 // nodes) if parsing failed. 168 // nodes) if parsing failed.
169 static bool Parse(CompilationInfo* info); 169 static bool Parse(CompilationInfo* info);
170 170
171 // Generic preparser generating full preparse data. 171 // Generic preparser generating full preparse data.
172 static ScriptDataImpl* PreParse(UC16CharacterStream* source, 172 static ScriptDataImpl* PreParse(Handle<String> source,
173 unibrow::CharacterStream* stream,
173 v8::Extension* extension); 174 v8::Extension* extension);
174 175
175 // Preparser that only does preprocessing that makes sense if only used 176 // Preparser that only does preprocessing that makes sense if only used
176 // immediately after. 177 // immediately after.
177 static ScriptDataImpl* PartialPreParse(UC16CharacterStream* source, 178 static ScriptDataImpl* PartialPreParse(Handle<String> source,
179 unibrow::CharacterStream* stream,
178 v8::Extension* extension); 180 v8::Extension* extension);
179 }; 181 };
180 182
181 // ---------------------------------------------------------------------------- 183 // ----------------------------------------------------------------------------
182 // REGEXP PARSING 184 // REGEXP PARSING
183 185
184 // A BuffferedZoneList is an automatically growing list, just like (and backed 186 // A BuffferedZoneList is an automatically growing list, just like (and backed
185 // by) a ZoneList, that is optimized for the case of adding and removing 187 // by) a ZoneList, that is optimized for the case of adding and removing
186 // a single element. The last element added is stored outside the backing list, 188 // a single element. The last element added is stored outside the backing list,
187 // and if no more than one element is ever added, the ZoneList isn't even 189 // and if no more than one element is ever added, the ZoneList isn't even
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 FunctionLiteral* ParseProgram(Handle<String> source, 428 FunctionLiteral* ParseProgram(Handle<String> source,
427 bool in_global_context); 429 bool in_global_context);
428 430
429 FunctionLiteral* ParseLazy(Handle<SharedFunctionInfo> info); 431 FunctionLiteral* ParseLazy(Handle<SharedFunctionInfo> info);
430 432
431 void ReportMessageAt(Scanner::Location loc, 433 void ReportMessageAt(Scanner::Location loc,
432 const char* message, 434 const char* message,
433 Vector<const char*> args); 435 Vector<const char*> args);
434 436
435 protected: 437 protected:
436 FunctionLiteral* ParseLazy(Handle<SharedFunctionInfo> info,
437 UC16CharacterStream* source,
438 ZoneScope* zone_scope);
439 enum Mode { 438 enum Mode {
440 PARSE_LAZILY, 439 PARSE_LAZILY,
441 PARSE_EAGERLY 440 PARSE_EAGERLY
442 }; 441 };
443 442
444 // Called by ParseProgram after setting up the scanner.
445 FunctionLiteral* DoParseProgram(Handle<String> source,
446 bool in_global_context,
447 ZoneScope* zone_scope);
448
449 // Report syntax error 443 // Report syntax error
450 void ReportUnexpectedToken(Token::Value token); 444 void ReportUnexpectedToken(Token::Value token);
451 void ReportInvalidPreparseData(Handle<String> name, bool* ok); 445 void ReportInvalidPreparseData(Handle<String> name, bool* ok);
452 void ReportMessage(const char* message, Vector<const char*> args); 446 void ReportMessage(const char* message, Vector<const char*> args);
453 447
454 bool inside_with() const { return with_nesting_level_ > 0; } 448 bool inside_with() const { return with_nesting_level_ > 0; }
455 V8JavaScriptScanner& scanner() { return scanner_; } 449 Scanner& scanner() { return scanner_; }
456 Mode mode() const { return mode_; } 450 Mode mode() const { return mode_; }
457 ScriptDataImpl* pre_data() const { return pre_data_; } 451 ScriptDataImpl* pre_data() const { return pre_data_; }
458 452
459 // All ParseXXX functions take as the last argument an *ok parameter 453 // All ParseXXX functions take as the last argument an *ok parameter
460 // which is set to false if parsing failed; it is unchanged otherwise. 454 // which is set to false if parsing failed; it is unchanged otherwise.
461 // By making the 'exception handling' explicit, we are forced to check 455 // By making the 'exception handling' explicit, we are forced to check
462 // for failure at the call sites. 456 // for failure at the call sites.
463 void* ParseSourceElements(ZoneList<Statement*>* processor, 457 void* ParseSourceElements(ZoneList<Statement*>* processor,
464 int end_token, bool* ok); 458 int end_token, bool* ok);
465 Statement* ParseStatement(ZoneStringList* labels, bool* ok); 459 Statement* ParseStatement(ZoneStringList* labels, bool* ok);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 int function_token_position, 541 int function_token_position,
548 FunctionLiteralType type, 542 FunctionLiteralType type,
549 bool* ok); 543 bool* ok);
550 544
551 545
552 // Magical syntax support. 546 // Magical syntax support.
553 Expression* ParseV8Intrinsic(bool* ok); 547 Expression* ParseV8Intrinsic(bool* ok);
554 548
555 INLINE(Token::Value peek()) { 549 INLINE(Token::Value peek()) {
556 if (stack_overflow_) return Token::ILLEGAL; 550 if (stack_overflow_) return Token::ILLEGAL;
557 return scanner().peek(); 551 return scanner_.peek();
558 } 552 }
559 553
560 INLINE(Token::Value Next()) { 554 INLINE(Token::Value Next()) {
561 // BUG 1215673: Find a thread safe way to set a stack limit in 555 // BUG 1215673: Find a thread safe way to set a stack limit in
562 // pre-parse mode. Otherwise, we cannot safely pre-parse from other 556 // pre-parse mode. Otherwise, we cannot safely pre-parse from other
563 // threads. 557 // threads.
564 if (stack_overflow_) { 558 if (stack_overflow_) {
565 return Token::ILLEGAL; 559 return Token::ILLEGAL;
566 } 560 }
567 if (StackLimitCheck().HasOverflowed()) { 561 if (StackLimitCheck().HasOverflowed()) {
568 // Any further calls to Next or peek will return the illegal token. 562 // Any further calls to Next or peek will return the illegal token.
569 // The current call must return the next token, which might already
570 // have been peek'ed.
571 stack_overflow_ = true; 563 stack_overflow_ = true;
572 } 564 }
573 return scanner().Next(); 565 return scanner_.Next();
574 } 566 }
575 567
576 INLINE(void Consume(Token::Value token)); 568 INLINE(void Consume(Token::Value token));
577 void Expect(Token::Value token, bool* ok); 569 void Expect(Token::Value token, bool* ok);
578 bool Check(Token::Value token); 570 bool Check(Token::Value token);
579 void ExpectSemicolon(bool* ok); 571 void ExpectSemicolon(bool* ok);
580 572
581 Handle<String> GetSymbol(bool* ok); 573 Handle<String> GetSymbol(bool* ok);
582 574
583 // Get odd-ball literals. 575 // Get odd-ball literals.
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 // JSON PARSING 695 // JSON PARSING
704 696
705 // JSON is a subset of JavaScript, as specified in, e.g., the ECMAScript 5 697 // JSON is a subset of JavaScript, as specified in, e.g., the ECMAScript 5
706 // specification section 15.12.1 (and appendix A.8). 698 // specification section 15.12.1 (and appendix A.8).
707 // The grammar is given section 15.12.1.2 (and appendix A.8.2). 699 // The grammar is given section 15.12.1.2 (and appendix A.8.2).
708 class JsonParser BASE_EMBEDDED { 700 class JsonParser BASE_EMBEDDED {
709 public: 701 public:
710 // Parse JSON input as a single JSON value. 702 // Parse JSON input as a single JSON value.
711 // Returns null handle and sets exception if parsing failed. 703 // Returns null handle and sets exception if parsing failed.
712 static Handle<Object> Parse(Handle<String> source) { 704 static Handle<Object> Parse(Handle<String> source) {
713 if (source->IsExternalTwoByteString()) { 705 return JsonParser().ParseJson(source);
714 ExternalTwoByteStringUC16CharacterStream stream(
715 Handle<ExternalTwoByteString>::cast(source), 0, source->length());
716 return JsonParser().ParseJson(source, &stream);
717 } else {
718 GenericStringUC16CharacterStream stream(source, 0, source->length());
719 return JsonParser().ParseJson(source, &stream);
720 }
721 } 706 }
722 707
723 private: 708 private:
724 JsonParser() { } 709 JsonParser() { }
725 ~JsonParser() { } 710 ~JsonParser() { }
726 711
727 // Parse a string containing a single JSON value. 712 // Parse a string containing a single JSON value.
728 Handle<Object> ParseJson(Handle<String> script, UC16CharacterStream* source); 713 Handle<Object> ParseJson(Handle<String>);
729 // Parse a single JSON value from input (grammar production JSONValue). 714 // Parse a single JSON value from input (grammar production JSONValue).
730 // A JSON value is either a (double-quoted) string literal, a number literal, 715 // A JSON value is either a (double-quoted) string literal, a number literal,
731 // one of "true", "false", or "null", or an object or array literal. 716 // one of "true", "false", or "null", or an object or array literal.
732 Handle<Object> ParseJsonValue(); 717 Handle<Object> ParseJsonValue();
733 // Parse a JSON object literal (grammar production JSONObject). 718 // Parse a JSON object literal (grammar production JSONObject).
734 // An object literal is a squiggly-braced and comma separated sequence 719 // An object literal is a squiggly-braced and comma separated sequence
735 // (possibly empty) of key/value pairs, where the key is a JSON string 720 // (possibly empty) of key/value pairs, where the key is a JSON string
736 // literal, the value is a JSON value, and the two are separated by a colon. 721 // literal, the value is a JSON value, and the two are separated by a colon.
737 // A JSON array dosn't allow numbers and identifiers as keys, like a 722 // A JSON array dosn't allow numbers and identifiers as keys, like a
738 // JavaScript array. 723 // JavaScript array.
(...skipping 10 matching lines...) Expand all
749 Handle<Object> ReportUnexpectedToken() { return Handle<Object>::null(); } 734 Handle<Object> ReportUnexpectedToken() { return Handle<Object>::null(); }
750 // Converts the currently parsed literal to a JavaScript String. 735 // Converts the currently parsed literal to a JavaScript String.
751 Handle<String> GetString(); 736 Handle<String> GetString();
752 737
753 JsonScanner scanner_; 738 JsonScanner scanner_;
754 bool stack_overflow_; 739 bool stack_overflow_;
755 }; 740 };
756 } } // namespace v8::internal 741 } } // namespace v8::internal
757 742
758 #endif // V8_PARSER_H_ 743 #endif // V8_PARSER_H_
OLDNEW
« ChangeLog ('K') | « src/objects.h ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698