| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 int predata_function_skip() { return backing_[kPredataFunctionSkipOffset]; } | 75 int predata_function_skip() { return backing_[kPredataFunctionSkipOffset]; } |
| 76 void set_predata_function_skip(int value) { | 76 void set_predata_function_skip(int value) { |
| 77 backing_[kPredataFunctionSkipOffset] = value; | 77 backing_[kPredataFunctionSkipOffset] = value; |
| 78 } | 78 } |
| 79 | 79 |
| 80 int predata_symbol_skip() { return backing_[kPredataSymbolSkipOffset]; } | 80 int predata_symbol_skip() { return backing_[kPredataSymbolSkipOffset]; } |
| 81 void set_predata_symbol_skip(int value) { | 81 void set_predata_symbol_skip(int value) { |
| 82 backing_[kPredataSymbolSkipOffset] = value; | 82 backing_[kPredataSymbolSkipOffset] = value; |
| 83 } | 83 } |
| 84 | 84 |
| 85 int symbol_id_skip() { return backing_[kSymbolIdSkipOffset]; } | |
| 86 void set_symbol_id_skip(int value) { | |
| 87 backing_[kSymbolIdSkipOffset] = value; | |
| 88 } | |
| 89 | |
| 90 | |
| 91 bool is_valid() { return backing_.length() > 0; } | 85 bool is_valid() { return backing_.length() > 0; } |
| 92 | 86 |
| 93 static const int kSize = 7; | 87 static const int kSize = 6; |
| 94 | 88 |
| 95 private: | 89 private: |
| 96 Vector<unsigned> backing_; | 90 Vector<unsigned> backing_; |
| 97 static const int kStartPosOffset = 0; | 91 static const int kStartPosOffset = 0; |
| 98 static const int kEndPosOffset = 1; | 92 static const int kEndPosOffset = 1; |
| 99 static const int kLiteralCountOffset = 2; | 93 static const int kLiteralCountOffset = 2; |
| 100 static const int kPropertyCountOffset = 3; | 94 static const int kPropertyCountOffset = 3; |
| 101 static const int kPredataFunctionSkipOffset = 4; | 95 static const int kPredataFunctionSkipOffset = 4; |
| 102 static const int kPredataSymbolSkipOffset = 5; | 96 static const int kPredataSymbolSkipOffset = 5; |
| 103 static const int kSymbolIdSkipOffset = 6; | |
| 104 }; | 97 }; |
| 105 | 98 |
| 106 | 99 |
| 107 class ScriptDataImpl : public ScriptData { | 100 class ScriptDataImpl : public ScriptData { |
| 108 public: | 101 public: |
| 109 explicit ScriptDataImpl(Vector<unsigned> store) | 102 explicit ScriptDataImpl(Vector<unsigned> store) |
| 110 : store_(store), | 103 : store_(store), |
| 111 function_index_(kHeaderSize), | 104 function_index_(kHeaderSize), |
| 112 symbol_id_(0), | |
| 113 owns_store_(true) { | 105 owns_store_(true) { |
| 114 Initialize(); | 106 Initialize(); |
| 115 } | 107 } |
| 116 | 108 |
| 117 void Initialize() { | |
| 118 if (store_.length() >= kHeaderSize) { | |
| 119 // Otherwise we won't satisfy the SanityCheck. | |
| 120 symbol_index_ = kHeaderSize + store_[kFunctionsSizeOffset]; | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 // Create an empty ScriptDataImpl that is guaranteed to not satisfy | 109 // Create an empty ScriptDataImpl that is guaranteed to not satisfy |
| 125 // a SanityCheck. | 110 // a SanityCheck. |
| 126 ScriptDataImpl() : store_(Vector<unsigned>()), owns_store_(false) { } | 111 ScriptDataImpl() : store_(Vector<unsigned>()), owns_store_(false) { } |
| 127 | 112 |
| 128 virtual ~ScriptDataImpl(); | 113 virtual ~ScriptDataImpl(); |
| 129 virtual int Length(); | 114 virtual int Length(); |
| 130 virtual const char* Data(); | 115 virtual const char* Data(); |
| 131 virtual bool HasError(); | 116 virtual bool HasError(); |
| 132 | 117 |
| 118 void Initialize(); |
| 119 void ReadNextSymbolPosition(); |
| 120 |
| 133 FunctionEntry GetFunctionEntry(int start); | 121 FunctionEntry GetFunctionEntry(int start); |
| 134 int GetSymbolIdentifier(int start); | 122 int GetSymbolIdentifier(); |
| 135 void SkipFunctionEntry(int start); | 123 void SkipFunctionEntry(int start); |
| 136 bool SanityCheck(); | 124 bool SanityCheck(); |
| 137 | 125 |
| 138 Scanner::Location MessageLocation(); | 126 Scanner::Location MessageLocation(); |
| 139 const char* BuildMessage(); | 127 const char* BuildMessage(); |
| 140 Vector<const char*> BuildArgs(); | 128 Vector<const char*> BuildArgs(); |
| 141 | 129 |
| 142 int symbol_count() { | 130 int symbol_count() { |
| 143 return (store_.length() > kHeaderSize) ? store_[kSymbolCountOffset] : 0; | 131 return (store_.length() > kHeaderSize) ? store_[kSymbolCountOffset] : 0; |
| 144 } | 132 } |
| 145 // The following functions should only be called if SanityCheck has | 133 // The following functions should only be called if SanityCheck has |
| 146 // returned true. | 134 // returned true. |
| 147 bool has_error() { return store_[kHasErrorOffset]; } | 135 bool has_error() { return store_[kHasErrorOffset]; } |
| 148 unsigned magic() { return store_[kMagicOffset]; } | 136 unsigned magic() { return store_[kMagicOffset]; } |
| 149 unsigned version() { return store_[kVersionOffset]; } | 137 unsigned version() { return store_[kVersionOffset]; } |
| 150 | 138 |
| 151 // Skip forward in the preparser data by the given number | 139 // Skip forward in the preparser data by the given number |
| 152 // of unsigned ints. | 140 // of unsigned ints of function entries and the given number of bytes of |
| 153 virtual void Skip(int function_entries, int symbol_entries, int symbol_ids) { | 141 // symbol id encoding. |
| 142 void Skip(int function_entries, int symbol_entries) { |
| 154 ASSERT(function_entries >= 0); | 143 ASSERT(function_entries >= 0); |
| 155 ASSERT(function_entries | 144 ASSERT(function_entries |
| 156 <= (static_cast<int>(store_[kFunctionsSizeOffset]) | 145 <= (static_cast<int>(store_[kFunctionsSizeOffset]) |
| 157 - (function_index_ - kHeaderSize))); | 146 - (function_index_ - kHeaderSize))); |
| 158 function_index_ += function_entries; | 147 ASSERT(symbol_entries >= 0); |
| 159 symbol_index_ += symbol_entries; | 148 ASSERT(symbol_entries <= symbol_data_end_ - symbol_data_); |
| 160 symbol_id_ += symbol_ids; | 149 |
| 150 unsigned max_function_skip = store_[kFunctionsSizeOffset] - |
| 151 static_cast<unsigned>(function_index_ - kHeaderSize); |
| 152 function_index_ += |
| 153 Min(static_cast<unsigned>(function_entries), max_function_skip); |
| 154 symbol_data_ += |
| 155 Min(static_cast<unsigned>(symbol_entries), |
| 156 static_cast<unsigned>(symbol_data_end_ - symbol_data_)); |
| 161 } | 157 } |
| 162 | 158 |
| 163 static const unsigned kMagicNumber = 0xBadDead; | 159 static const unsigned kMagicNumber = 0xBadDead; |
| 164 static const unsigned kCurrentVersion = 2; | 160 static const unsigned kCurrentVersion = 3; |
| 165 | 161 |
| 166 static const int kMagicOffset = 0; | 162 static const int kMagicOffset = 0; |
| 167 static const int kVersionOffset = 1; | 163 static const int kVersionOffset = 1; |
| 168 static const int kHasErrorOffset = 2; | 164 static const int kHasErrorOffset = 2; |
| 169 static const int kFunctionsSizeOffset = 3; | 165 static const int kFunctionsSizeOffset = 3; |
| 170 static const int kSymbolCountOffset = 4; | 166 static const int kSymbolCountOffset = 4; |
| 171 static const int kSizeOffset = 5; | 167 static const int kSizeOffset = 5; |
| 172 static const int kHeaderSize = 6; | 168 static const int kHeaderSize = 6; |
| 173 | 169 |
| 170 // If encoding a message, the following positions are fixed. |
| 174 static const int kMessageStartPos = 0; | 171 static const int kMessageStartPos = 0; |
| 175 static const int kMessageEndPos = 1; | 172 static const int kMessageEndPos = 1; |
| 176 static const int kMessageArgCountPos = 2; | 173 static const int kMessageArgCountPos = 2; |
| 177 static const int kMessageTextPos = 3; | 174 static const int kMessageTextPos = 3; |
| 178 | 175 |
| 176 static const byte kNumberTerminator = 0x80u; |
| 177 |
| 179 private: | 178 private: |
| 180 Vector<unsigned> store_; | 179 Vector<unsigned> store_; |
| 180 unsigned char* symbol_data_; |
| 181 unsigned char* symbol_data_end_; |
| 181 int function_index_; | 182 int function_index_; |
| 182 int symbol_index_; | |
| 183 int symbol_id_; | |
| 184 bool owns_store_; | 183 bool owns_store_; |
| 185 | 184 |
| 186 unsigned Read(int position); | 185 unsigned Read(int position); |
| 187 unsigned* ReadAddress(int position); | 186 unsigned* ReadAddress(int position); |
| 187 // Reads a number from the current symbols |
| 188 int ReadNumber(byte** source); |
| 188 | 189 |
| 189 ScriptDataImpl(const char* backing_store, int length) | 190 ScriptDataImpl(const char* backing_store, int length) |
| 190 : store_(reinterpret_cast<unsigned*>(const_cast<char*>(backing_store)), | 191 : store_(reinterpret_cast<unsigned*>(const_cast<char*>(backing_store)), |
| 191 length / sizeof(unsigned)), | 192 length / sizeof(unsigned)), |
| 192 function_index_(kHeaderSize), | 193 function_index_(kHeaderSize), |
| 193 symbol_id_(0), | |
| 194 owns_store_(false) { | 194 owns_store_(false) { |
| 195 ASSERT_EQ(0, reinterpret_cast<intptr_t>(backing_store) % sizeof(unsigned)); | 195 ASSERT_EQ(0, reinterpret_cast<intptr_t>(backing_store) % sizeof(unsigned)); |
| 196 Initialize(); | 196 Initialize(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 // Read strings written by ParserRecorder::WriteString. | 199 // Read strings written by ParserRecorder::WriteString. |
| 200 static const char* ReadString(unsigned* start, int* chars); | 200 static const char* ReadString(unsigned* start, int* chars); |
| 201 | 201 |
| 202 friend class ScriptData; | 202 friend class ScriptData; |
| 203 }; | 203 }; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 static const int kTypeSlot = 0; | 272 static const int kTypeSlot = 0; |
| 273 static const int kElementsSlot = 1; | 273 static const int kElementsSlot = 1; |
| 274 | 274 |
| 275 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 275 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 276 }; | 276 }; |
| 277 | 277 |
| 278 | 278 |
| 279 } } // namespace v8::internal | 279 } } // namespace v8::internal |
| 280 | 280 |
| 281 #endif // V8_PARSER_H_ | 281 #endif // V8_PARSER_H_ |
| OLD | NEW |