| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 void set_end_pos(int value) { backing_[kEndPosOffset] = value; } | 65 void set_end_pos(int value) { backing_[kEndPosOffset] = value; } |
| 66 | 66 |
| 67 int literal_count() { return backing_[kLiteralCountOffset]; } | 67 int literal_count() { return backing_[kLiteralCountOffset]; } |
| 68 void set_literal_count(int value) { backing_[kLiteralCountOffset] = value; } | 68 void set_literal_count(int value) { backing_[kLiteralCountOffset] = value; } |
| 69 | 69 |
| 70 int property_count() { return backing_[kPropertyCountOffset]; } | 70 int property_count() { return backing_[kPropertyCountOffset]; } |
| 71 void set_property_count(int value) { | 71 void set_property_count(int value) { |
| 72 backing_[kPropertyCountOffset] = value; | 72 backing_[kPropertyCountOffset] = value; |
| 73 } | 73 } |
| 74 | 74 |
| 75 int predata_function_skip() { return backing_[kPredataFunctionSkipOffset]; } | |
| 76 void set_predata_function_skip(int value) { | |
| 77 backing_[kPredataFunctionSkipOffset] = value; | |
| 78 } | |
| 79 | |
| 80 int predata_symbol_skip() { return backing_[kPredataSymbolSkipOffset]; } | |
| 81 void set_predata_symbol_skip(int value) { | |
| 82 backing_[kPredataSymbolSkipOffset] = value; | |
| 83 } | |
| 84 | |
| 85 bool is_valid() { return backing_.length() > 0; } | 75 bool is_valid() { return backing_.length() > 0; } |
| 86 | 76 |
| 87 static const int kSize = 6; | 77 static const int kSize = 4; |
| 88 | 78 |
| 89 private: | 79 private: |
| 90 Vector<unsigned> backing_; | 80 Vector<unsigned> backing_; |
| 91 static const int kStartPosOffset = 0; | 81 static const int kStartPosOffset = 0; |
| 92 static const int kEndPosOffset = 1; | 82 static const int kEndPosOffset = 1; |
| 93 static const int kLiteralCountOffset = 2; | 83 static const int kLiteralCountOffset = 2; |
| 94 static const int kPropertyCountOffset = 3; | 84 static const int kPropertyCountOffset = 3; |
| 95 static const int kPredataFunctionSkipOffset = 4; | |
| 96 static const int kPredataSymbolSkipOffset = 5; | |
| 97 }; | 85 }; |
| 98 | 86 |
| 99 | 87 |
| 100 class ScriptDataImpl : public ScriptData { | 88 class ScriptDataImpl : public ScriptData { |
| 101 public: | 89 public: |
| 102 explicit ScriptDataImpl(Vector<unsigned> store) | 90 explicit ScriptDataImpl(Vector<unsigned> store) |
| 103 : store_(store), | 91 : store_(store), |
| 104 owns_store_(true) { } | 92 owns_store_(true) { } |
| 105 | 93 |
| 106 // Create an empty ScriptDataImpl that is guaranteed to not satisfy | 94 // Create an empty ScriptDataImpl that is guaranteed to not satisfy |
| 107 // a SanityCheck. | 95 // a SanityCheck. |
| 108 ScriptDataImpl() : store_(Vector<unsigned>()), owns_store_(false) { } | 96 ScriptDataImpl() : store_(Vector<unsigned>()), owns_store_(false) { } |
| 109 | 97 |
| 110 virtual ~ScriptDataImpl(); | 98 virtual ~ScriptDataImpl(); |
| 111 virtual int Length(); | 99 virtual int Length(); |
| 112 virtual const char* Data(); | 100 virtual const char* Data(); |
| 113 virtual bool HasError(); | 101 virtual bool HasError(); |
| 114 | 102 |
| 115 void Initialize(); | 103 void Initialize(); |
| 116 void ReadNextSymbolPosition(); | 104 void ReadNextSymbolPosition(); |
| 117 | 105 |
| 118 FunctionEntry GetFunctionEntry(int start); | 106 FunctionEntry GetFunctionEntry(int start); |
| 119 int GetSymbolIdentifier(); | 107 int GetSymbolIdentifier(); |
| 120 void SkipFunctionEntry(int start); | |
| 121 bool SanityCheck(); | 108 bool SanityCheck(); |
| 122 | 109 |
| 123 Scanner::Location MessageLocation(); | 110 Scanner::Location MessageLocation(); |
| 124 const char* BuildMessage(); | 111 const char* BuildMessage(); |
| 125 Vector<const char*> BuildArgs(); | 112 Vector<const char*> BuildArgs(); |
| 126 | 113 |
| 127 int symbol_count() { | 114 int symbol_count() { |
| 128 return (store_.length() > kHeaderSize) ? store_[kSymbolCountOffset] : 0; | 115 return (store_.length() > kHeaderSize) ? store_[kSymbolCountOffset] : 0; |
| 129 } | 116 } |
| 130 // The following functions should only be called if SanityCheck has | 117 // The following functions should only be called if SanityCheck has |
| 131 // returned true. | 118 // returned true. |
| 132 bool has_error() { return store_[kHasErrorOffset]; } | 119 bool has_error() { return store_[kHasErrorOffset]; } |
| 133 unsigned magic() { return store_[kMagicOffset]; } | 120 unsigned magic() { return store_[kMagicOffset]; } |
| 134 unsigned version() { return store_[kVersionOffset]; } | 121 unsigned version() { return store_[kVersionOffset]; } |
| 135 | 122 |
| 136 // Skip forward in the preparser data by the given number | |
| 137 // of unsigned ints of function entries and the given number of bytes of | |
| 138 // symbol id encoding. | |
| 139 void Skip(int function_entries, int symbol_entries) { | |
| 140 ASSERT(function_entries >= 0); | |
| 141 ASSERT(function_entries | |
| 142 <= (static_cast<int>(store_[kFunctionsSizeOffset]) | |
| 143 - (function_index_ - kHeaderSize))); | |
| 144 ASSERT(symbol_entries >= 0); | |
| 145 ASSERT(symbol_entries <= symbol_data_end_ - symbol_data_); | |
| 146 | |
| 147 unsigned max_function_skip = store_[kFunctionsSizeOffset] - | |
| 148 static_cast<unsigned>(function_index_ - kHeaderSize); | |
| 149 function_index_ += | |
| 150 Min(static_cast<unsigned>(function_entries), max_function_skip); | |
| 151 symbol_data_ += | |
| 152 Min(static_cast<unsigned>(symbol_entries), | |
| 153 static_cast<unsigned>(symbol_data_end_ - symbol_data_)); | |
| 154 } | |
| 155 | |
| 156 static const unsigned kMagicNumber = 0xBadDead; | 123 static const unsigned kMagicNumber = 0xBadDead; |
| 157 static const unsigned kCurrentVersion = 3; | 124 static const unsigned kCurrentVersion = 4; |
| 158 | 125 |
| 159 static const int kMagicOffset = 0; | 126 static const int kMagicOffset = 0; |
| 160 static const int kVersionOffset = 1; | 127 static const int kVersionOffset = 1; |
| 161 static const int kHasErrorOffset = 2; | 128 static const int kHasErrorOffset = 2; |
| 162 static const int kFunctionsSizeOffset = 3; | 129 static const int kFunctionsSizeOffset = 3; |
| 163 static const int kSymbolCountOffset = 4; | 130 static const int kSymbolCountOffset = 4; |
| 164 static const int kSizeOffset = 5; | 131 static const int kSizeOffset = 5; |
| 165 static const int kHeaderSize = 6; | 132 static const int kHeaderSize = 6; |
| 166 | 133 |
| 167 // If encoding a message, the following positions are fixed. | 134 // If encoding a message, the following positions are fixed. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 static const int kTypeSlot = 0; | 234 static const int kTypeSlot = 0; |
| 268 static const int kElementsSlot = 1; | 235 static const int kElementsSlot = 1; |
| 269 | 236 |
| 270 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 237 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 271 }; | 238 }; |
| 272 | 239 |
| 273 | 240 |
| 274 } } // namespace v8::internal | 241 } } // namespace v8::internal |
| 275 | 242 |
| 276 #endif // V8_PARSER_H_ | 243 #endif // V8_PARSER_H_ |
| OLD | NEW |