OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef RUNTIME_VM_KERNEL_BINARY_H_ | 5 #ifndef RUNTIME_VM_KERNEL_BINARY_H_ |
6 #define RUNTIME_VM_KERNEL_BINARY_H_ | 6 #define RUNTIME_VM_KERNEL_BINARY_H_ |
7 | 7 |
8 #if !defined(DART_PRECOMPILED_RUNTIME) | 8 #if !defined(DART_PRECOMPILED_RUNTIME) |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 explicit TypeParameterScope(T* builder) : builder_(builder) { | 261 explicit TypeParameterScope(T* builder) : builder_(builder) { |
262 builder_->type_parameters().EnterScope(); | 262 builder_->type_parameters().EnterScope(); |
263 } | 263 } |
264 ~TypeParameterScope() { builder_->type_parameters().LeaveScope(); } | 264 ~TypeParameterScope() { builder_->type_parameters().LeaveScope(); } |
265 | 265 |
266 private: | 266 private: |
267 T* builder_; | 267 T* builder_; |
268 }; | 268 }; |
269 | 269 |
270 | 270 |
271 template <typename T> | |
272 class SwitchCaseScope { | |
273 public: | |
274 explicit SwitchCaseScope(T* builder) : builder_(builder) { | |
275 builder_->switch_cases().EnterScope(); | |
276 } | |
277 ~SwitchCaseScope() { builder_->switch_cases().LeaveScope(); } | |
278 | |
279 private: | |
280 T* builder_; | |
281 }; | |
282 | |
283 | |
284 // Unlike other scopes, labels from enclosing functions are not visible in | 271 // Unlike other scopes, labels from enclosing functions are not visible in |
285 // nested functions. The LabelScope class is used to hide outer labels. | 272 // nested functions. The LabelScope class is used to hide outer labels. |
286 template <typename Builder, typename Block> | 273 template <typename Builder, typename Block> |
287 class LabelScope { | 274 class LabelScope { |
288 public: | 275 public: |
289 explicit LabelScope(Builder* builder) : builder_(builder) { | 276 explicit LabelScope(Builder* builder) : builder_(builder) { |
290 outer_block_ = builder_->labels(); | 277 outer_block_ = builder_->labels(); |
291 builder_->set_labels(&block_); | 278 builder_->set_labels(&block_); |
292 } | 279 } |
293 ~LabelScope() { builder_->set_labels(outer_block_); } | 280 ~LabelScope() { builder_->set_labels(outer_block_); } |
294 | 281 |
295 private: | 282 private: |
296 Builder* builder_; | 283 Builder* builder_; |
297 Block block_; | 284 Block block_; |
298 Block* outer_block_; | 285 Block* outer_block_; |
299 }; | 286 }; |
300 | 287 |
301 | 288 |
302 class ReaderHelper { | 289 class ReaderHelper { |
303 public: | 290 public: |
304 ReaderHelper() : program_(NULL), labels_(NULL) {} | 291 ReaderHelper() : program_(NULL), labels_(NULL) {} |
305 | 292 |
306 Program* program() { return program_; } | 293 Program* program() { return program_; } |
307 void set_program(Program* program) { program_ = program; } | 294 void set_program(Program* program) { program_ = program; } |
308 | 295 |
309 BlockStack<VariableDeclaration>& variables() { return scope_; } | 296 BlockStack<VariableDeclaration>& variables() { return scope_; } |
310 BlockStack<TypeParameter>& type_parameters() { return type_parameters_; } | 297 BlockStack<TypeParameter>& type_parameters() { return type_parameters_; } |
311 BlockStack<SwitchCase>& switch_cases() { return switch_cases_; } | |
312 | 298 |
313 BlockStack<LabeledStatement>* labels() { return labels_; } | 299 BlockStack<LabeledStatement>* labels() { return labels_; } |
314 void set_labels(BlockStack<LabeledStatement>* labels) { labels_ = labels; } | 300 void set_labels(BlockStack<LabeledStatement>* labels) { labels_ = labels; } |
315 | 301 |
316 private: | 302 private: |
317 Program* program_; | 303 Program* program_; |
318 BlockStack<VariableDeclaration> scope_; | 304 BlockStack<VariableDeclaration> scope_; |
319 BlockStack<TypeParameter> type_parameters_; | 305 BlockStack<TypeParameter> type_parameters_; |
320 BlockStack<SwitchCase> switch_cases_; | |
321 BlockStack<LabeledStatement>* labels_; | 306 BlockStack<LabeledStatement>* labels_; |
322 }; | 307 }; |
323 | 308 |
324 | 309 |
325 class Reader { | 310 class Reader { |
326 public: | 311 public: |
327 Reader(const uint8_t* buffer, intptr_t size) | 312 Reader(const uint8_t* buffer, intptr_t size) |
328 : buffer_(buffer), | 313 : buffer_(buffer), |
329 size_(size), | 314 size_(size), |
330 offset_(0), | 315 offset_(0), |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 if (record) { | 400 if (record) { |
416 record_token_position(result); | 401 record_token_position(result); |
417 } | 402 } |
418 return result; | 403 return result; |
419 } | 404 } |
420 | 405 |
421 intptr_t ReadListLength() { return ReadUInt(); } | 406 intptr_t ReadListLength() { return ReadUInt(); } |
422 | 407 |
423 uint8_t ReadByte() { return buffer_[offset_++]; } | 408 uint8_t ReadByte() { return buffer_[offset_++]; } |
424 | 409 |
| 410 uint8_t PeekByte() { return buffer_[offset_]; } |
| 411 |
425 bool ReadBool() { return (ReadByte() & 1) == 1; } | 412 bool ReadBool() { return (ReadByte() & 1) == 1; } |
426 | 413 |
427 word ReadFlags() { return ReadByte(); } | 414 word ReadFlags() { return ReadByte(); } |
428 | 415 |
429 Tag ReadTag(uint8_t* payload = NULL) { | 416 Tag ReadTag(uint8_t* payload = NULL) { |
430 uint8_t byte = ReadByte(); | 417 uint8_t byte = ReadByte(); |
431 bool has_payload = (byte & kSpecializedTagHighBit) != 0; | 418 bool has_payload = (byte & kSpecializedTagHighBit) != 0; |
432 if (has_payload) { | 419 if (has_payload) { |
433 if (payload != NULL) { | 420 if (payload != NULL) { |
434 *payload = byte & kSpecializedPayloadMask; | 421 *payload = byte & kSpecializedPayloadMask; |
435 } | 422 } |
436 return static_cast<Tag>(byte & kSpecializedTagMask); | 423 return static_cast<Tag>(byte & kSpecializedTagMask); |
437 } else { | 424 } else { |
438 return static_cast<Tag>(byte); | 425 return static_cast<Tag>(byte); |
439 } | 426 } |
440 } | 427 } |
441 | 428 |
| 429 Tag PeekTag(uint8_t* payload = NULL) { |
| 430 uint8_t byte = PeekByte(); |
| 431 bool has_payload = (byte & kSpecializedTagHighBit) != 0; |
| 432 if (has_payload) { |
| 433 if (payload != NULL) { |
| 434 *payload = byte & kSpecializedPayloadMask; |
| 435 } |
| 436 return static_cast<Tag>(byte & kSpecializedTagMask); |
| 437 } else { |
| 438 return static_cast<Tag>(byte); |
| 439 } |
| 440 } |
| 441 |
442 const uint8_t* Consume(int count) { | 442 const uint8_t* Consume(int count) { |
443 ASSERT(offset_ + count <= size_); | 443 ASSERT(offset_ + count <= size_); |
444 const uint8_t* old = buffer_ + offset_; | 444 const uint8_t* old = buffer_ + offset_; |
445 offset_ += count; | 445 offset_ += count; |
446 return old; | 446 return old; |
447 } | 447 } |
448 | 448 |
449 void EnsureEnd() { | 449 void EnsureEnd() { |
450 if (offset_ != size_) { | 450 if (offset_ != size_) { |
451 FATAL2( | 451 FATAL2( |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 Reader* reader_; | 581 Reader* reader_; |
582 TokenPosition min_; | 582 TokenPosition min_; |
583 TokenPosition max_; | 583 TokenPosition max_; |
584 }; | 584 }; |
585 | 585 |
586 } // namespace kernel | 586 } // namespace kernel |
587 } // namespace dart | 587 } // namespace dart |
588 | 588 |
589 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 589 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
590 #endif // RUNTIME_VM_KERNEL_BINARY_H_ | 590 #endif // RUNTIME_VM_KERNEL_BINARY_H_ |
OLD | NEW |