| 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_skip() { return backing_[kPredataSkipOffset]; } | 75 int predata_function_skip() { return backing_[kPredataFunctionSkipOffset]; } |
| 76 void set_predata_skip(int value) { | 76 void set_predata_function_skip(int value) { |
| 77 backing_[kPredataSkipOffset] = value; | 77 backing_[kPredataFunctionSkipOffset] = value; |
| 78 } | 78 } |
| 79 | 79 |
| 80 int predata_symbol_skip() { return backing_[kPredataSymbolSkipOffset]; } |
| 81 void set_predata_symbol_skip(int value) { |
| 82 backing_[kPredataSymbolSkipOffset] = value; |
| 83 } |
| 84 |
| 85 int symbol_id_skip() { return backing_[kSymbolIdSkipOffset]; } |
| 86 void set_symbol_id_skip(int value) { |
| 87 backing_[kSymbolIdSkipOffset] = value; |
| 88 } |
| 89 |
| 90 |
| 80 bool is_valid() { return backing_.length() > 0; } | 91 bool is_valid() { return backing_.length() > 0; } |
| 81 | 92 |
| 82 static const int kSize = 5; | 93 static const int kSize = 7; |
| 83 | 94 |
| 84 private: | 95 private: |
| 85 Vector<unsigned> backing_; | 96 Vector<unsigned> backing_; |
| 86 static const int kStartPosOffset = 0; | 97 static const int kStartPosOffset = 0; |
| 87 static const int kEndPosOffset = 1; | 98 static const int kEndPosOffset = 1; |
| 88 static const int kLiteralCountOffset = 2; | 99 static const int kLiteralCountOffset = 2; |
| 89 static const int kPropertyCountOffset = 3; | 100 static const int kPropertyCountOffset = 3; |
| 90 static const int kPredataSkipOffset = 4; | 101 static const int kPredataFunctionSkipOffset = 4; |
| 102 static const int kPredataSymbolSkipOffset = 5; |
| 103 static const int kSymbolIdSkipOffset = 6; |
| 91 }; | 104 }; |
| 92 | 105 |
| 93 | 106 |
| 94 class ScriptDataImpl : public ScriptData { | 107 class ScriptDataImpl : public ScriptData { |
| 95 public: | 108 public: |
| 96 explicit ScriptDataImpl(Vector<unsigned> store) | 109 explicit ScriptDataImpl(Vector<unsigned> store) |
| 97 : store_(store), | 110 : store_(store), |
| 98 index_(kHeaderSize) { } | 111 function_index_(kHeaderSize), |
| 112 symbol_id_(0), |
| 113 owns_store_(true) { |
| 114 Initialize(); |
| 115 } |
| 116 |
| 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 |
| 125 // a SanityCheck. |
| 126 ScriptDataImpl() : store_(Vector<unsigned>()), owns_store_(false) { } |
| 127 |
| 99 virtual ~ScriptDataImpl(); | 128 virtual ~ScriptDataImpl(); |
| 100 virtual int Length(); | 129 virtual int Length(); |
| 101 virtual const char* Data(); | 130 virtual const char* Data(); |
| 102 virtual bool HasError(); | 131 virtual bool HasError(); |
| 132 |
| 103 FunctionEntry GetFunctionEntry(int start); | 133 FunctionEntry GetFunctionEntry(int start); |
| 134 int GetSymbolIdentifier(int start); |
| 104 void SkipFunctionEntry(int start); | 135 void SkipFunctionEntry(int start); |
| 105 bool SanityCheck(); | 136 bool SanityCheck(); |
| 106 | 137 |
| 107 Scanner::Location MessageLocation(); | 138 Scanner::Location MessageLocation(); |
| 108 const char* BuildMessage(); | 139 const char* BuildMessage(); |
| 109 Vector<const char*> BuildArgs(); | 140 Vector<const char*> BuildArgs(); |
| 110 | 141 |
| 142 int symbol_count() { |
| 143 return (store_.length() > kHeaderSize) ? store_[kSymbolCountOffset] : 0; |
| 144 } |
| 145 // The following functions should only be called if SanityCheck has |
| 146 // returned true. |
| 111 bool has_error() { return store_[kHasErrorOffset]; } | 147 bool has_error() { return store_[kHasErrorOffset]; } |
| 112 unsigned magic() { return store_[kMagicOffset]; } | 148 unsigned magic() { return store_[kMagicOffset]; } |
| 113 unsigned version() { return store_[kVersionOffset]; } | 149 unsigned version() { return store_[kVersionOffset]; } |
| 150 |
| 114 // Skip forward in the preparser data by the given number | 151 // Skip forward in the preparser data by the given number |
| 115 // of unsigned ints. | 152 // of unsigned ints. |
| 116 virtual void Skip(int entries) { | 153 virtual void Skip(int function_entries, int symbol_entries, int symbol_ids) { |
| 117 ASSERT(entries >= 0); | 154 ASSERT(function_entries >= 0); |
| 118 ASSERT(entries <= store_.length() - index_); | 155 ASSERT(function_entries |
| 119 index_ += entries; | 156 <= (static_cast<int>(store_[kFunctionsSizeOffset]) |
| 157 - (function_index_ - kHeaderSize))); |
| 158 function_index_ += function_entries; |
| 159 symbol_index_ += symbol_entries; |
| 160 symbol_id_ += symbol_ids; |
| 120 } | 161 } |
| 121 | 162 |
| 122 static const unsigned kMagicNumber = 0xBadDead; | 163 static const unsigned kMagicNumber = 0xBadDead; |
| 123 static const unsigned kCurrentVersion = 1; | 164 static const unsigned kCurrentVersion = 2; |
| 124 | 165 |
| 125 static const int kMagicOffset = 0; | 166 static const int kMagicOffset = 0; |
| 126 static const int kVersionOffset = 1; | 167 static const int kVersionOffset = 1; |
| 127 static const int kHasErrorOffset = 2; | 168 static const int kHasErrorOffset = 2; |
| 128 static const int kSizeOffset = 3; | 169 static const int kFunctionsSizeOffset = 3; |
| 129 static const int kHeaderSize = 4; | 170 static const int kSymbolCountOffset = 4; |
| 171 static const int kSizeOffset = 5; |
| 172 static const int kHeaderSize = 6; |
| 173 |
| 174 static const int kMessageStartPos = 0; |
| 175 static const int kMessageEndPos = 1; |
| 176 static const int kMessageArgCountPos = 2; |
| 177 static const int kMessageTextPos = 3; |
| 130 | 178 |
| 131 private: | 179 private: |
| 132 Vector<unsigned> store_; | 180 Vector<unsigned> store_; |
| 133 int index_; | 181 int function_index_; |
| 182 int symbol_index_; |
| 183 int symbol_id_; |
| 184 bool owns_store_; |
| 134 | 185 |
| 135 unsigned Read(int position); | 186 unsigned Read(int position); |
| 136 unsigned* ReadAddress(int position); | 187 unsigned* ReadAddress(int position); |
| 137 | 188 |
| 138 void FindStart(int position); | 189 ScriptDataImpl(const char* backing_store, int length) |
| 190 : store_(reinterpret_cast<unsigned*>(const_cast<char*>(backing_store)), |
| 191 length / sizeof(unsigned)), |
| 192 function_index_(kHeaderSize), |
| 193 symbol_id_(0), |
| 194 owns_store_(false) { |
| 195 ASSERT_EQ(0, reinterpret_cast<intptr_t>(backing_store) % sizeof(unsigned)); |
| 196 Initialize(); |
| 197 } |
| 198 |
| 139 // Read strings written by ParserRecorder::WriteString. | 199 // Read strings written by ParserRecorder::WriteString. |
| 140 static const char* ReadString(unsigned* start, int* chars); | 200 static const char* ReadString(unsigned* start, int* chars); |
| 201 |
| 202 friend class ScriptData; |
| 141 }; | 203 }; |
| 142 | 204 |
| 143 | 205 |
| 144 // The parser: Takes a script and and context information, and builds a | 206 // The parser: Takes a script and and context information, and builds a |
| 145 // FunctionLiteral AST node. Returns NULL and deallocates any allocated | 207 // FunctionLiteral AST node. Returns NULL and deallocates any allocated |
| 146 // AST nodes if parsing failed. | 208 // AST nodes if parsing failed. |
| 147 FunctionLiteral* MakeAST(bool compile_in_global_context, | 209 FunctionLiteral* MakeAST(bool compile_in_global_context, |
| 148 Handle<Script> script, | 210 Handle<Script> script, |
| 149 v8::Extension* extension, | 211 v8::Extension* extension, |
| 150 ScriptDataImpl* pre_data, | 212 ScriptDataImpl* pre_data, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 static const int kTypeSlot = 0; | 266 static const int kTypeSlot = 0; |
| 205 static const int kElementsSlot = 1; | 267 static const int kElementsSlot = 1; |
| 206 | 268 |
| 207 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 269 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 208 }; | 270 }; |
| 209 | 271 |
| 210 | 272 |
| 211 } } // namespace v8::internal | 273 } } // namespace v8::internal |
| 212 | 274 |
| 213 #endif // V8_PARSER_H_ | 275 #endif // V8_PARSER_H_ |
| OLD | NEW |