| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 VM_SYMBOLS_H_ | 5 #ifndef VM_SYMBOLS_H_ |
| 6 #define VM_SYMBOLS_H_ | 6 #define VM_SYMBOLS_H_ |
| 7 | 7 |
| 8 #include "vm/growable_array.h" | 8 #include "vm/growable_array.h" |
| 9 #include "vm/object.h" | 9 #include "vm/object.h" |
| 10 #include "vm/snapshot_ids.h" | 10 #include "vm/snapshot_ids.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 V(UnaryMinus, "unary-") \ | 26 V(UnaryMinus, "unary-") \ |
| 27 V(Identical, "identical") \ | 27 V(Identical, "identical") \ |
| 28 V(Length, "length") \ | 28 V(Length, "length") \ |
| 29 V(_setLength, "_setLength") \ | 29 V(_setLength, "_setLength") \ |
| 30 V(IndexToken, "[]") \ | 30 V(IndexToken, "[]") \ |
| 31 V(AssignIndexToken, "[]=") \ | 31 V(AssignIndexToken, "[]=") \ |
| 32 V(TopLevel, "::") \ | 32 V(TopLevel, "::") \ |
| 33 V(DefaultLabel, ":L") \ | 33 V(DefaultLabel, ":L") \ |
| 34 V(Other, "other") \ | 34 V(Other, "other") \ |
| 35 V(Call, "call") \ | 35 V(Call, "call") \ |
| 36 V(GetCall, "get:call") \ |
| 36 V(Current, "current") \ | 37 V(Current, "current") \ |
| 37 V(_current, "_current") \ | 38 V(_current, "_current") \ |
| 38 V(MoveNext, "moveNext") \ | 39 V(MoveNext, "moveNext") \ |
| 39 V(IsYieldEach, "isYieldEach") \ | 40 V(IsYieldEach, "isYieldEach") \ |
| 40 V(Value, "value") \ | 41 V(Value, "value") \ |
| 41 V(_EnumHelper, "_EnumHelper") \ | 42 V(_EnumHelper, "_EnumHelper") \ |
| 42 V(_SyncIterable, "_SyncIterable") \ | 43 V(_SyncIterable, "_SyncIterable") \ |
| 43 V(_SyncIterableConstructor, "_SyncIterable.") \ | 44 V(_SyncIterableConstructor, "_SyncIterable.") \ |
| 44 V(_SyncIterator, "_SyncIterator") \ | 45 V(_SyncIterator, "_SyncIterator") \ |
| 45 V(IteratorParameter, ":iterator") \ | 46 V(IteratorParameter, ":iterator") \ |
| 46 V(_AsyncStarStreamController, "_AsyncStarStreamController") \ | 47 V(_AsyncStarStreamController, "_AsyncStarStreamController") \ |
| 47 V(_AsyncStarStreamControllerConstructor, "_AsyncStarStreamController.") \ | 48 V(_AsyncStarStreamControllerConstructor, "_AsyncStarStreamController.") \ |
| 48 V(Controller, ":controller") \ | 49 V(Controller, ":controller") \ |
| 49 V(Stream, "stream") \ | 50 V(Stream, "stream") \ |
| 50 V(isPaused, "isPaused") \ | 51 V(isPaused, "isPaused") \ |
| 51 V(AddError, "addError") \ | 52 V(AddError, "addError") \ |
| 52 V(AddStream, "addStream") \ | 53 V(AddStream, "addStream") \ |
| 53 V(Cancel, "cancel") \ | 54 V(Cancel, "cancel") \ |
| 54 V(Close, "close") \ | 55 V(Close, "close") \ |
| 55 V(Values, "values") \ | 56 V(Values, "values") \ |
| 56 V(_EnumNames, "_enum_names") \ | 57 V(_EnumNames, "_enum_names") \ |
| 57 V(ExprTemp, ":expr_temp") \ | 58 V(ExprTemp, ":expr_temp") \ |
| 59 V(FinallyRetVal, ":finally_ret_val") \ |
| 58 V(AnonymousClosure, "<anonymous closure>") \ | 60 V(AnonymousClosure, "<anonymous closure>") \ |
| 59 V(AnonymousSignature, "<anonymous signature>") \ | 61 V(AnonymousSignature, "<anonymous signature>") \ |
| 60 V(ImplicitClosure, "<implicit closure>") \ | 62 V(ImplicitClosure, "<implicit closure>") \ |
| 61 V(ClosureParameter, ":closure") \ | 63 V(ClosureParameter, ":closure") \ |
| 62 V(TypeArgumentsParameter, ":type_arguments") \ | 64 V(TypeArgumentsParameter, ":type_arguments") \ |
| 63 V(AssertionError, "_AssertionError") \ | 65 V(AssertionError, "_AssertionError") \ |
| 64 V(CastError, "_CastError") \ | 66 V(CastError, "_CastError") \ |
| 65 V(TypeError, "_TypeError") \ | 67 V(TypeError, "_TypeError") \ |
| 66 V(FallThroughError, "FallThroughError") \ | 68 V(FallThroughError, "FallThroughError") \ |
| 67 V(AbstractClassInstantiationError, "AbstractClassInstantiationError") \ | 69 V(AbstractClassInstantiationError, "AbstractClassInstantiationError") \ |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 | 401 |
| 400 // List of strings that are pre created in the vm isolate. | 402 // List of strings that are pre created in the vm isolate. |
| 401 enum SymbolId { | 403 enum SymbolId { |
| 402 kIllegal = 0, | 404 kIllegal = 0, |
| 403 | 405 |
| 404 #define DEFINE_SYMBOL_INDEX(symbol, literal) \ | 406 #define DEFINE_SYMBOL_INDEX(symbol, literal) \ |
| 405 k##symbol##Id, | 407 k##symbol##Id, |
| 406 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_INDEX) | 408 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_INDEX) |
| 407 #undef DEFINE_SYMBOL_INDEX | 409 #undef DEFINE_SYMBOL_INDEX |
| 408 | 410 |
| 409 kKwTableStart, // First keyword at kKwTableStart + 1. | 411 kTokenTableStart, // First token at kTokenTableStart + 1. |
| 410 | 412 |
| 411 #define DEFINE_KEYWORD_SYMBOL_INDEX(t, s, p, a) \ | 413 #define DEFINE_TOKEN_SYMBOL_INDEX(t, s, p, a) \ |
| 412 t##Id, | 414 t##Id, |
| 413 DART_KEYWORD_LIST(DEFINE_KEYWORD_SYMBOL_INDEX) | 415 DART_TOKEN_LIST(DEFINE_TOKEN_SYMBOL_INDEX) |
| 414 #undef DEFINE_KEYWORD_SYMBOL_INDEX | 416 DART_KEYWORD_LIST(DEFINE_TOKEN_SYMBOL_INDEX) |
| 417 #undef DEFINE_TOKEN_SYMBOL_INDEX |
| 415 | 418 |
| 416 kNullCharId, // One char code symbol starts here and takes up 256 entries. | 419 kNullCharId, // One char code symbol starts here and takes up 256 entries. |
| 417 kMaxPredefinedId = kNullCharId + kMaxOneCharCodeSymbol + 1, | 420 kMaxPredefinedId = kNullCharId + kMaxOneCharCodeSymbol + 1, |
| 418 }; | 421 }; |
| 419 | 422 |
| 420 // Number of one character symbols being predefined in the predefined_ array. | 423 // Number of one character symbols being predefined in the predefined_ array. |
| 421 static const int kNumberOfOneCharCodeSymbols = | 424 static const int kNumberOfOneCharCodeSymbols = |
| 422 (kMaxPredefinedId - kNullCharId); | 425 (kMaxPredefinedId - kNullCharId); |
| 423 | 426 |
| 424 // Offset of Null character which is the predefined character symbol. | 427 // Offset of Null character which is the predefined character symbol. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 static const String& Percent() { | 520 static const String& Percent() { |
| 518 return *(symbol_handles_[kNullCharId + '%']); | 521 return *(symbol_handles_[kNullCharId + '%']); |
| 519 } | 522 } |
| 520 static const String& Caret() { | 523 static const String& Caret() { |
| 521 return *(symbol_handles_[kNullCharId + '^']); | 524 return *(symbol_handles_[kNullCharId + '^']); |
| 522 } | 525 } |
| 523 static const String& Tilde() { | 526 static const String& Tilde() { |
| 524 return *(symbol_handles_[kNullCharId + '~']); | 527 return *(symbol_handles_[kNullCharId + '~']); |
| 525 } | 528 } |
| 526 | 529 |
| 527 static const String& Empty() { return *(symbol_handles_[kKwTableStart]); } | 530 static const String& Empty() { return *(symbol_handles_[kTokenTableStart]); } |
| 528 static const String& False() { return *(symbol_handles_[kFALSEId]); } | 531 static const String& False() { return *(symbol_handles_[kFALSEId]); } |
| 529 static const String& Library() { return *(symbol_handles_[kLIBRARYId]); } | 532 static const String& Library() { return *(symbol_handles_[kLIBRARYId]); } |
| 530 static const String& Super() { return *(symbol_handles_[kSUPERId]); } | 533 static const String& Super() { return *(symbol_handles_[kSUPERId]); } |
| 531 static const String& This() { return *(symbol_handles_[kTHISId]); } | 534 static const String& This() { return *(symbol_handles_[kTHISId]); } |
| 532 static const String& True() { return *(symbol_handles_[kTRUEId]); } | 535 static const String& True() { return *(symbol_handles_[kTRUEId]); } |
| 533 static const String& Void() { return *(symbol_handles_[kVOIDId]); } | 536 static const String& Void() { return *(symbol_handles_[kVOIDId]); } |
| 534 | 537 |
| 535 // Access methods for symbol handles stored in the vm isolate for predefined | 538 // Access methods for symbol handles stored in the vm isolate for predefined |
| 536 // symbols. | 539 // symbols. |
| 537 #define DEFINE_SYMBOL_HANDLE_ACCESSOR(symbol, literal) \ | 540 #define DEFINE_SYMBOL_HANDLE_ACCESSOR(symbol, literal) \ |
| 538 static const String& symbol() { return *(symbol_handles_[k##symbol##Id]); } | 541 static const String& symbol() { return *(symbol_handles_[k##symbol##Id]); } |
| 539 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_HANDLE_ACCESSOR) | 542 PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_HANDLE_ACCESSOR) |
| 540 #undef DEFINE_SYMBOL_HANDLE_ACCESSOR | 543 #undef DEFINE_SYMBOL_HANDLE_ACCESSOR |
| 541 | 544 |
| 542 // Access methods for symbol handles stored in the vm isolate for keywords. | 545 // Access methods for symbol handles stored in the vm isolate for keywords. |
| 543 #define DEFINE_SYMBOL_HANDLE_ACCESSOR(t, s, p, a) \ | 546 #define DEFINE_SYMBOL_HANDLE_ACCESSOR(t, s, p, a) \ |
| 544 static const String& t() { return *(symbol_handles_[t##Id]); } | 547 static const String& t() { return *(symbol_handles_[t##Id]); } |
| 548 DART_TOKEN_LIST(DEFINE_SYMBOL_HANDLE_ACCESSOR) |
| 545 DART_KEYWORD_LIST(DEFINE_SYMBOL_HANDLE_ACCESSOR) | 549 DART_KEYWORD_LIST(DEFINE_SYMBOL_HANDLE_ACCESSOR) |
| 546 #undef DEFINE_SYMBOL_HANDLE_ACCESSOR | 550 #undef DEFINE_SYMBOL_HANDLE_ACCESSOR |
| 547 | 551 |
| 548 // Get symbol for scanner keyword. | 552 // Get symbol for scanner token. |
| 549 static const String& Keyword(Token::Kind keyword); | 553 static const String& Token(Token::Kind token); |
| 550 | 554 |
| 551 // Initialize frequently used symbols in the vm isolate. | 555 // Initialize frequently used symbols in the vm isolate. |
| 552 static void InitOnce(Isolate* isolate); | 556 static void InitOnce(Isolate* isolate); |
| 553 static void InitOnceFromSnapshot(Isolate* isolate); | 557 static void InitOnceFromSnapshot(Isolate* isolate); |
| 554 | 558 |
| 555 // Add all the symbols that were cached in the VM isolate to this isolate, | 559 // Add all the symbols that were cached in the VM isolate to this isolate, |
| 556 // we do this when an Isolate is not created from the snapshot so that | 560 // we do this when an Isolate is not created from the snapshot so that |
| 557 // we get a unified symbol table that can be be dumped into the VM isolate | 561 // we get a unified symbol table that can be be dumped into the VM isolate |
| 558 // snapshot. | 562 // snapshot. |
| 559 static void AddPredefinedSymbolsToIsolate(); | 563 static void AddPredefinedSymbolsToIsolate(); |
| 560 | 564 |
| 561 // Initialize and setup a symbol table for the isolate. | 565 // Initialize and setup a symbol table for the isolate. |
| 562 static void SetupSymbolTable(Isolate* isolate); | 566 static void SetupSymbolTable(Isolate* isolate); |
| 563 | 567 |
| 564 // Treat the symbol table as weak and collect garbage. Answer the number of | 568 // Treat the symbol table as weak and collect garbage. Answer the number of |
| 565 // symbols deleted from the symbol table because they where not referenced | 569 // symbols deleted from the symbol table because they where not referenced |
| 566 // from anywhere else. | 570 // from anywhere else. |
| 567 static intptr_t Compact(Isolate* isolate); | 571 static intptr_t Compact(Isolate* isolate); |
| 568 | 572 |
| 569 // Creates a Symbol given a C string that is assumed to contain | 573 // Creates a Symbol given a C string that is assumed to contain |
| 570 // UTF-8 encoded characters and '\0' is considered a termination character. | 574 // UTF-8 encoded characters and '\0' is considered a termination character. |
| 571 // TODO(7123) - Rename this to FromCString(....). | 575 // TODO(7123) - Rename this to FromCString(....). |
| 572 static RawString* New(const char* cstr) { | 576 static RawString* New(Thread* thread, const char* cstr) { |
| 573 return New(cstr, strlen(cstr)); | 577 return New(thread, cstr, strlen(cstr)); |
| 574 } | 578 } |
| 575 static RawString* New(const char* cstr, intptr_t length); | 579 static RawString* New(Thread* thread, const char* cstr, intptr_t length); |
| 576 | 580 |
| 577 // Creates a new Symbol from an array of UTF-8 encoded characters. | 581 // Creates a new Symbol from an array of UTF-8 encoded characters. |
| 578 static RawString* FromUTF8(const uint8_t* utf8_array, intptr_t len); | 582 static RawString* FromUTF8(Thread* thread, |
| 583 const uint8_t* utf8_array, |
| 584 intptr_t len); |
| 579 | 585 |
| 580 // Creates a new Symbol from an array of Latin-1 encoded characters. | 586 // Creates a new Symbol from an array of Latin-1 encoded characters. |
| 581 static RawString* FromLatin1(const uint8_t* latin1_array, intptr_t len); | 587 static RawString* FromLatin1(Thread* thread, |
| 588 const uint8_t* latin1_array, |
| 589 intptr_t len); |
| 582 | 590 |
| 583 // Creates a new Symbol from an array of UTF-16 encoded characters. | 591 // Creates a new Symbol from an array of UTF-16 encoded characters. |
| 584 static RawString* FromUTF16(const uint16_t* utf16_array, intptr_t len); | 592 static RawString* FromUTF16(Thread* thread, |
| 593 const uint16_t* utf16_array, |
| 594 intptr_t len); |
| 585 | 595 |
| 586 // Creates a new Symbol from an array of UTF-32 encoded characters. | 596 // Creates a new Symbol from an array of UTF-32 encoded characters. |
| 587 static RawString* FromUTF32(const int32_t* utf32_array, intptr_t len); | 597 static RawString* FromUTF32(Thread* thread, |
| 598 const int32_t* utf32_array, |
| 599 intptr_t len); |
| 588 | 600 |
| 589 static RawString* New(const String& str); | 601 static RawString* New(Thread* thread, const String& str); |
| 590 static RawString* New(const String& str, | 602 static RawString* New(Thread* thread, |
| 603 const String& str, |
| 591 intptr_t begin_index, | 604 intptr_t begin_index, |
| 592 intptr_t length); | 605 intptr_t length); |
| 593 | 606 |
| 594 static RawString* NewFormatted(const char* format, ...) | 607 static RawString* NewFormatted(Thread* thread, const char* format, ...) |
| 595 PRINTF_ATTRIBUTE(1, 2); | 608 PRINTF_ATTRIBUTE(2, 3); |
| 596 static RawString* NewFormattedV(const char* format, va_list args); | 609 static RawString* NewFormattedV(Thread* thread, |
| 610 const char* format, |
| 611 va_list args); |
| 597 | 612 |
| 598 static RawString* FromConcat(const String& str1, const String& str2); | 613 static RawString* FromConcat(Thread* thread, |
| 614 const String& str1, |
| 615 const String& str2); |
| 599 | 616 |
| 600 static RawString* FromConcatAll( | 617 static RawString* FromConcatAll(Thread* thread, |
| 601 const GrowableHandlePtrArray<const String>& strs); | 618 const GrowableHandlePtrArray<const String>& strs); |
| 602 | 619 |
| 620 static RawString* FromGet(Thread* thread, const String& str); |
| 621 static RawString* FromSet(Thread* thread, const String& str); |
| 622 static RawString* FromDot(Thread* thread, const String& str); |
| 623 |
| 603 // Returns char* of predefined symbol. | 624 // Returns char* of predefined symbol. |
| 604 static const char* Name(SymbolId symbol); | 625 static const char* Name(SymbolId symbol); |
| 605 | 626 |
| 606 static RawString* FromCharCode(int32_t char_code); | 627 static RawString* FromCharCode(Thread* thread, int32_t char_code); |
| 607 | 628 |
| 608 static RawString** PredefinedAddress() { | 629 static RawString** PredefinedAddress() { |
| 609 return reinterpret_cast<RawString**>(&predefined_); | 630 return reinterpret_cast<RawString**>(&predefined_); |
| 610 } | 631 } |
| 611 | 632 |
| 612 static void DumpStats(); | 633 static void DumpStats(); |
| 613 | 634 |
| 614 // Returns Symbol::Null if no symbol is found. | 635 // Returns Symbol::Null if no symbol is found. |
| 615 template<typename StringType> | 636 template<typename StringType> |
| 616 static RawString* Lookup(const StringType& str); | 637 static RawString* Lookup(Thread* thread, const StringType& str); |
| 617 | 638 |
| 618 // Returns Symbol::Null if no symbol is found. | 639 // Returns Symbol::Null if no symbol is found. |
| 619 static RawString* LookupFromConcat(const String& str1, const String& str2); | 640 static RawString* LookupFromConcat(Thread* thread, |
| 641 const String& str1, |
| 642 const String& str2); |
| 643 |
| 644 static RawString* LookupFromGet(Thread* thread, const String& str); |
| 645 static RawString* LookupFromSet(Thread* thread, const String& str); |
| 646 static RawString* LookupFromDot(Thread* thread, const String& str); |
| 620 | 647 |
| 621 private: | 648 private: |
| 622 enum { | 649 enum { |
| 623 kInitialVMIsolateSymtabSize = 1024, | 650 kInitialVMIsolateSymtabSize = 1024, |
| 624 kInitialSymtabSize = 2048 | 651 kInitialSymtabSize = 2048 |
| 625 }; | 652 }; |
| 626 | 653 |
| 627 static void GetStats(Isolate* isolate, | 654 static void GetStats(Isolate* isolate, |
| 628 intptr_t* size, | 655 intptr_t* size, |
| 629 intptr_t* capacity); | 656 intptr_t* capacity); |
| 630 | 657 |
| 631 template<typename StringType> | 658 template<typename StringType> |
| 632 static RawString* NewSymbol(const StringType& str); | 659 static RawString* NewSymbol(Thread* thread, const StringType& str); |
| 633 | 660 |
| 634 static intptr_t LookupVMSymbol(RawObject* obj); | 661 static intptr_t LookupVMSymbol(RawObject* obj); |
| 635 static RawObject* GetVMSymbol(intptr_t object_id); | 662 static RawObject* GetVMSymbol(intptr_t object_id); |
| 636 static bool IsVMSymbolId(intptr_t object_id) { | 663 static bool IsVMSymbolId(intptr_t object_id) { |
| 637 return (object_id >= kMaxPredefinedObjectIds && | 664 return (object_id >= kMaxPredefinedObjectIds && |
| 638 object_id < (kMaxPredefinedObjectIds + kMaxPredefinedId)); | 665 object_id < (kMaxPredefinedObjectIds + kMaxPredefinedId)); |
| 639 } | 666 } |
| 640 | 667 |
| 641 // List of Latin1 characters stored in the vm isolate as symbols | 668 // List of Latin1 characters stored in the vm isolate as symbols |
| 642 // in order to make Symbols::FromCharCode fast. This structure is | 669 // in order to make Symbols::FromCharCode fast. This structure is |
| 643 // used in generated dart code for direct access to these objects. | 670 // used in generated dart code for direct access to these objects. |
| 644 static RawString* predefined_[kNumberOfOneCharCodeSymbols]; | 671 static RawString* predefined_[kNumberOfOneCharCodeSymbols]; |
| 645 | 672 |
| 646 // List of handles for predefined symbols. | 673 // List of handles for predefined symbols. |
| 647 static String* symbol_handles_[kMaxPredefinedId]; | 674 static String* symbol_handles_[kMaxPredefinedId]; |
| 648 | 675 |
| 649 friend class Dart; | 676 friend class Dart; |
| 650 friend class String; | 677 friend class String; |
| 651 friend class SnapshotReader; | 678 friend class SnapshotReader; |
| 652 friend class SnapshotWriter; | 679 friend class SnapshotWriter; |
| 653 friend class ApiMessageReader; | 680 friend class ApiMessageReader; |
| 654 | 681 |
| 655 DISALLOW_COPY_AND_ASSIGN(Symbols); | 682 DISALLOW_COPY_AND_ASSIGN(Symbols); |
| 656 }; | 683 }; |
| 657 | 684 |
| 658 } // namespace dart | 685 } // namespace dart |
| 659 | 686 |
| 660 #endif // VM_SYMBOLS_H_ | 687 #endif // VM_SYMBOLS_H_ |
| OLD | NEW |