| 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_PARSER_H_ | 5 #ifndef V8_PARSER_H_ | 
| 6 #define V8_PARSER_H_ | 6 #define V8_PARSER_H_ | 
| 7 | 7 | 
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" | 
| 9 #include "src/ast.h" | 9 #include "src/ast.h" | 
| 10 #include "src/compiler.h"  // For CachedDataMode | 10 #include "src/compiler.h"  // For CachedDataMode | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 52     return static_cast<StrictMode>(backing_[kStrictModeIndex]); | 52     return static_cast<StrictMode>(backing_[kStrictModeIndex]); | 
| 53   } | 53   } | 
| 54 | 54 | 
| 55   bool is_valid() { return !backing_.is_empty(); } | 55   bool is_valid() { return !backing_.is_empty(); } | 
| 56 | 56 | 
| 57  private: | 57  private: | 
| 58   Vector<unsigned> backing_; | 58   Vector<unsigned> backing_; | 
| 59 }; | 59 }; | 
| 60 | 60 | 
| 61 | 61 | 
| 62 class ScriptData { | 62 // Wrapper around ScriptData to provide parser-specific functionality. | 
|  | 63 class ParseData { | 
| 63  public: | 64  public: | 
| 64   explicit ScriptData(Vector<unsigned> store) | 65   explicit ParseData(ScriptData* script_data) : script_data_(script_data) { | 
| 65       : store_(store), | 66     CHECK(IsAligned(script_data->length(), sizeof(unsigned))); | 
| 66         owns_store_(true) { } | 67     CHECK(IsSane()); | 
|  | 68   } | 
|  | 69   void Initialize(); | 
|  | 70   FunctionEntry GetFunctionEntry(int start); | 
|  | 71   int FunctionCount(); | 
| 67 | 72 | 
| 68   ScriptData(Vector<unsigned> store, bool owns_store) | 73   bool HasError(); | 
| 69       : store_(store), |  | 
| 70         owns_store_(owns_store) { } |  | 
| 71 | 74 | 
| 72   // The created ScriptData won't take ownership of the data. If the alignment | 75   unsigned* Data() {  // Writable data as unsigned int array. | 
| 73   // is not correct, this will copy the data (and the created ScriptData will | 76     return reinterpret_cast<unsigned*>(const_cast<byte*>(script_data_->data())); | 
| 74   // take ownership of the copy). |  | 
| 75   static ScriptData* New(const char* data, int length, bool owns_store = false); |  | 
| 76 |  | 
| 77   virtual ~ScriptData(); |  | 
| 78   virtual int Length(); |  | 
| 79   virtual const char* Data(); |  | 
| 80   virtual bool HasError(); |  | 
| 81 |  | 
| 82   void Initialize(); |  | 
| 83   void ReadNextSymbolPosition(); |  | 
| 84 |  | 
| 85   FunctionEntry GetFunctionEntry(int start); |  | 
| 86   int GetSymbolIdentifier(); |  | 
| 87   bool SanityCheck(); |  | 
| 88 |  | 
| 89   Scanner::Location MessageLocation() const; |  | 
| 90   bool IsReferenceError() const; |  | 
| 91   const char* BuildMessage() const; |  | 
| 92   const char* BuildArg() const; |  | 
| 93 |  | 
| 94   int function_count() { |  | 
| 95     int functions_size = |  | 
| 96         static_cast<int>(store_[PreparseDataConstants::kFunctionsSizeOffset]); |  | 
| 97     if (functions_size < 0) return 0; |  | 
| 98     if (functions_size % FunctionEntry::kSize != 0) return 0; |  | 
| 99     return functions_size / FunctionEntry::kSize; |  | 
| 100   } | 77   } | 
| 101   // The following functions should only be called if SanityCheck has |  | 
| 102   // returned true. |  | 
| 103   bool has_error() { return store_[PreparseDataConstants::kHasErrorOffset]; } |  | 
| 104   unsigned magic() { return store_[PreparseDataConstants::kMagicOffset]; } |  | 
| 105   unsigned version() { return store_[PreparseDataConstants::kVersionOffset]; } |  | 
| 106 | 78 | 
| 107  private: | 79  private: | 
| 108   // Disable copying and assigning; because of owns_store they won't be correct. | 80   bool IsSane(); | 
| 109   ScriptData(const ScriptData&); | 81   unsigned Magic(); | 
| 110   ScriptData& operator=(const ScriptData&); | 82   unsigned Version(); | 
|  | 83   int FunctionsSize(); | 
|  | 84   int Length() const { | 
|  | 85     // Script data length is already checked to be a multiple of unsigned size. | 
|  | 86     return script_data_->length() / sizeof(unsigned); | 
|  | 87   } | 
| 111 | 88 | 
| 112   friend class v8::ScriptCompiler; | 89   ScriptData* script_data_; | 
| 113   Vector<unsigned> store_; |  | 
| 114   unsigned char* symbol_data_; |  | 
| 115   unsigned char* symbol_data_end_; |  | 
| 116   int function_index_; | 90   int function_index_; | 
| 117   bool owns_store_; |  | 
| 118 | 91 | 
| 119   unsigned Read(int position) const; | 92   DISALLOW_COPY_AND_ASSIGN(ParseData); | 
| 120   unsigned* ReadAddress(int position) const; |  | 
| 121   // Reads a number from the current symbols |  | 
| 122   int ReadNumber(byte** source); |  | 
| 123 |  | 
| 124   // Read strings written by ParserRecorder::WriteString. |  | 
| 125   static const char* ReadString(unsigned* start, int* chars); |  | 
| 126 }; | 93 }; | 
| 127 | 94 | 
| 128 |  | 
| 129 // ---------------------------------------------------------------------------- | 95 // ---------------------------------------------------------------------------- | 
| 130 // REGEXP PARSING | 96 // REGEXP PARSING | 
| 131 | 97 | 
| 132 // A BufferedZoneList is an automatically growing list, just like (and backed | 98 // A BufferedZoneList is an automatically growing list, just like (and backed | 
| 133 // by) a ZoneList, that is optimized for the case of adding and removing | 99 // by) a ZoneList, that is optimized for the case of adding and removing | 
| 134 // a single element. The last element added is stored outside the backing list, | 100 // a single element. The last element added is stored outside the backing list, | 
| 135 // and if no more than one element is ever added, the ZoneList isn't even | 101 // and if no more than one element is ever added, the ZoneList isn't even | 
| 136 // allocated. | 102 // allocated. | 
| 137 // Elements must not be NULL pointers. | 103 // Elements must not be NULL pointers. | 
| 138 template <typename T, int initial_size> | 104 template <typename T, int initial_size> | 
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 639   FunctionLiteral* ParseLazy(); | 605   FunctionLiteral* ParseLazy(); | 
| 640   FunctionLiteral* ParseLazy(Utf16CharacterStream* source); | 606   FunctionLiteral* ParseLazy(Utf16CharacterStream* source); | 
| 641 | 607 | 
| 642   Isolate* isolate() { return isolate_; } | 608   Isolate* isolate() { return isolate_; } | 
| 643   CompilationInfo* info() const { return info_; } | 609   CompilationInfo* info() const { return info_; } | 
| 644 | 610 | 
| 645   // Called by ParseProgram after setting up the scanner. | 611   // Called by ParseProgram after setting up the scanner. | 
| 646   FunctionLiteral* DoParseProgram(CompilationInfo* info, | 612   FunctionLiteral* DoParseProgram(CompilationInfo* info, | 
| 647                                   Handle<String> source); | 613                                   Handle<String> source); | 
| 648 | 614 | 
| 649   // Report syntax error | 615   void SetCachedData(); | 
| 650   void ReportInvalidCachedData(const AstRawString* name, bool* ok); |  | 
| 651 |  | 
| 652   void SetCachedData(ScriptData** data, |  | 
| 653                      CachedDataMode cached_data_mode) { |  | 
| 654     cached_data_mode_ = cached_data_mode; |  | 
| 655     if (cached_data_mode == NO_CACHED_DATA) { |  | 
| 656       cached_data_ = NULL; |  | 
| 657     } else { |  | 
| 658       ASSERT(data != NULL); |  | 
| 659       cached_data_ = data; |  | 
| 660     } |  | 
| 661   } |  | 
| 662 | 616 | 
| 663   bool inside_with() const { return scope_->inside_with(); } | 617   bool inside_with() const { return scope_->inside_with(); } | 
| 664   ScriptData** cached_data() const { return cached_data_; } | 618   CachedDataMode cached_data_mode() const { return info_->cached_data_mode(); } | 
| 665   CachedDataMode cached_data_mode() const { return cached_data_mode_; } |  | 
| 666   Scope* DeclarationScope(VariableMode mode) { | 619   Scope* DeclarationScope(VariableMode mode) { | 
| 667     return IsLexicalVariableMode(mode) | 620     return IsLexicalVariableMode(mode) | 
| 668         ? scope_ : scope_->DeclarationScope(); | 621         ? scope_ : scope_->DeclarationScope(); | 
| 669   } | 622   } | 
| 670 | 623 | 
| 671   // All ParseXXX functions take as the last argument an *ok parameter | 624   // All ParseXXX functions take as the last argument an *ok parameter | 
| 672   // which is set to false if parsing failed; it is unchanged otherwise. | 625   // which is set to false if parsing failed; it is unchanged otherwise. | 
| 673   // By making the 'exception handling' explicit, we are forced to check | 626   // By making the 'exception handling' explicit, we are forced to check | 
| 674   // for failure at the call sites. | 627   // for failure at the call sites. | 
| 675   void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, | 628   void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, | 
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 802 | 755 | 
| 803   void InternalizeUseCounts(); | 756   void InternalizeUseCounts(); | 
| 804 | 757 | 
| 805   Isolate* isolate_; | 758   Isolate* isolate_; | 
| 806 | 759 | 
| 807   Handle<Script> script_; | 760   Handle<Script> script_; | 
| 808   Scanner scanner_; | 761   Scanner scanner_; | 
| 809   PreParser* reusable_preparser_; | 762   PreParser* reusable_preparser_; | 
| 810   Scope* original_scope_;  // for ES5 function declarations in sloppy eval | 763   Scope* original_scope_;  // for ES5 function declarations in sloppy eval | 
| 811   Target* target_stack_;  // for break, continue statements | 764   Target* target_stack_;  // for break, continue statements | 
| 812   ScriptData** cached_data_; | 765   ParseData* cached_parse_data_; | 
| 813   CachedDataMode cached_data_mode_; | 766   CachedDataMode cached_data_mode_; | 
| 814   AstValueFactory* ast_value_factory_; | 767   AstValueFactory* ast_value_factory_; | 
| 815 | 768 | 
| 816   CompilationInfo* info_; | 769   CompilationInfo* info_; | 
| 817 | 770 | 
| 818   // Pending errors. | 771   // Pending errors. | 
| 819   bool has_pending_error_; | 772   bool has_pending_error_; | 
| 820   Scanner::Location pending_error_location_; | 773   Scanner::Location pending_error_location_; | 
| 821   const char* pending_error_message_; | 774   const char* pending_error_message_; | 
| 822   const AstRawString* pending_error_arg_; | 775   const AstRawString* pending_error_arg_; | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
| 851  private: | 804  private: | 
| 852   static const int kLiteralTypeSlot = 0; | 805   static const int kLiteralTypeSlot = 0; | 
| 853   static const int kElementsSlot = 1; | 806   static const int kElementsSlot = 1; | 
| 854 | 807 | 
| 855   DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 808   DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 
| 856 }; | 809 }; | 
| 857 | 810 | 
| 858 } }  // namespace v8::internal | 811 } }  // namespace v8::internal | 
| 859 | 812 | 
| 860 #endif  // V8_PARSER_H_ | 813 #endif  // V8_PARSER_H_ | 
| OLD | NEW | 
|---|