Chromium Code Reviews| 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_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
| 6 #define VM_OBJECT_H_ | 6 #define VM_OBJECT_H_ |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "platform/utils.h" | 10 #include "platform/utils.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 kVoidClass, | 137 kVoidClass, |
| 138 kUnresolvedClassClass, | 138 kUnresolvedClassClass, |
| 139 kTypeClass, | 139 kTypeClass, |
| 140 kTypeParameterClass, | 140 kTypeParameterClass, |
| 141 kInstantiatedTypeClass, | 141 kInstantiatedTypeClass, |
| 142 kAbstractTypeArgumentsClass, | 142 kAbstractTypeArgumentsClass, |
| 143 kTypeArgumentsClass, | 143 kTypeArgumentsClass, |
| 144 kInstantiatedTypeArgumentsClass, | 144 kInstantiatedTypeArgumentsClass, |
| 145 kFunctionClass, | 145 kFunctionClass, |
| 146 kFieldClass, | 146 kFieldClass, |
| 147 kLiteralTokenClass, | |
| 147 kTokenStreamClass, | 148 kTokenStreamClass, |
| 148 kScriptClass, | 149 kScriptClass, |
| 149 kLibraryClass, | 150 kLibraryClass, |
| 150 kLibraryPrefixClass, | 151 kLibraryPrefixClass, |
| 151 kCodeClass, | 152 kCodeClass, |
| 152 kInstructionsClass, | 153 kInstructionsClass, |
| 153 kPcDescriptorsClass, | 154 kPcDescriptorsClass, |
| 154 kLocalVarDescriptorsClass, | 155 kLocalVarDescriptorsClass, |
| 155 kExceptionHandlersClass, | 156 kExceptionHandlersClass, |
| 156 kContextClass, | 157 kContextClass, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 } | 273 } |
| 273 static RawClass* abstract_type_arguments_class() { | 274 static RawClass* abstract_type_arguments_class() { |
| 274 return abstract_type_arguments_class_; | 275 return abstract_type_arguments_class_; |
| 275 } | 276 } |
| 276 static RawClass* type_arguments_class() { return type_arguments_class_; } | 277 static RawClass* type_arguments_class() { return type_arguments_class_; } |
| 277 static RawClass* instantiated_type_arguments_class() { | 278 static RawClass* instantiated_type_arguments_class() { |
| 278 return instantiated_type_arguments_class_; | 279 return instantiated_type_arguments_class_; |
| 279 } | 280 } |
| 280 static RawClass* function_class() { return function_class_; } | 281 static RawClass* function_class() { return function_class_; } |
| 281 static RawClass* field_class() { return field_class_; } | 282 static RawClass* field_class() { return field_class_; } |
| 283 static RawClass* literal_token_class() { return literal_token_class_; } | |
| 282 static RawClass* token_stream_class() { return token_stream_class_; } | 284 static RawClass* token_stream_class() { return token_stream_class_; } |
| 283 static RawClass* script_class() { return script_class_; } | 285 static RawClass* script_class() { return script_class_; } |
| 284 static RawClass* library_class() { return library_class_; } | 286 static RawClass* library_class() { return library_class_; } |
| 285 static RawClass* library_prefix_class() { return library_prefix_class_; } | 287 static RawClass* library_prefix_class() { return library_prefix_class_; } |
| 286 static RawClass* code_class() { return code_class_; } | 288 static RawClass* code_class() { return code_class_; } |
| 287 static RawClass* instructions_class() { return instructions_class_; } | 289 static RawClass* instructions_class() { return instructions_class_; } |
| 288 static RawClass* pc_descriptors_class() { return pc_descriptors_class_; } | 290 static RawClass* pc_descriptors_class() { return pc_descriptors_class_; } |
| 289 static RawClass* var_descriptors_class() { return var_descriptors_class_; } | 291 static RawClass* var_descriptors_class() { return var_descriptors_class_; } |
| 290 static RawClass* exception_handlers_class() { | 292 static RawClass* exception_handlers_class() { |
| 291 return exception_handlers_class_; | 293 return exception_handlers_class_; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 static RawClass* type_class_; // Class of Type. | 385 static RawClass* type_class_; // Class of Type. |
| 384 static RawClass* type_parameter_class_; // Class of TypeParameter vm object. | 386 static RawClass* type_parameter_class_; // Class of TypeParameter vm object. |
| 385 static RawClass* instantiated_type_class_; // Class of InstantiatedType. | 387 static RawClass* instantiated_type_class_; // Class of InstantiatedType. |
| 386 // Class of AbstractTypeArguments vm object. | 388 // Class of AbstractTypeArguments vm object. |
| 387 static RawClass* abstract_type_arguments_class_; | 389 static RawClass* abstract_type_arguments_class_; |
| 388 // Class of the TypeArguments vm object. | 390 // Class of the TypeArguments vm object. |
| 389 static RawClass* type_arguments_class_; | 391 static RawClass* type_arguments_class_; |
| 390 static RawClass* instantiated_type_arguments_class_; // Class of Inst..ments. | 392 static RawClass* instantiated_type_arguments_class_; // Class of Inst..ments. |
| 391 static RawClass* function_class_; // Class of the Function vm object. | 393 static RawClass* function_class_; // Class of the Function vm object. |
| 392 static RawClass* field_class_; // Class of the Field vm object. | 394 static RawClass* field_class_; // Class of the Field vm object. |
| 395 static RawClass* literal_token_class_; // Class of LiteralToken vm object. | |
| 393 static RawClass* token_stream_class_; // Class of the TokenStream vm object. | 396 static RawClass* token_stream_class_; // Class of the TokenStream vm object. |
| 394 static RawClass* script_class_; // Class of the Script vm object. | 397 static RawClass* script_class_; // Class of the Script vm object. |
| 395 static RawClass* library_class_; // Class of the Library vm object. | 398 static RawClass* library_class_; // Class of the Library vm object. |
| 396 static RawClass* library_prefix_class_; // Class of Library prefix vm object. | 399 static RawClass* library_prefix_class_; // Class of Library prefix vm object. |
| 397 static RawClass* code_class_; // Class of the Code vm object. | 400 static RawClass* code_class_; // Class of the Code vm object. |
| 398 static RawClass* instructions_class_; // Class of the Instructions vm object. | 401 static RawClass* instructions_class_; // Class of the Instructions vm object. |
| 399 static RawClass* pc_descriptors_class_; // Class of PcDescriptors vm object. | 402 static RawClass* pc_descriptors_class_; // Class of PcDescriptors vm object. |
| 400 static RawClass* var_descriptors_class_; // Class of LocalVarDescriptors. | 403 static RawClass* var_descriptors_class_; // Class of LocalVarDescriptors. |
| 401 static RawClass* exception_handlers_class_; // Class of ExceptionHandlers. | 404 static RawClass* exception_handlers_class_; // Class of ExceptionHandlers. |
| 402 static RawClass* context_class_; // Class of the Context vm object. | 405 static RawClass* context_class_; // Class of the Context vm object. |
| (...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1550 void set_token_index(intptr_t token_index) const { | 1553 void set_token_index(intptr_t token_index) const { |
| 1551 raw_ptr()->token_index_ = token_index; | 1554 raw_ptr()->token_index_ = token_index; |
| 1552 } | 1555 } |
| 1553 static RawField* New(); | 1556 static RawField* New(); |
| 1554 | 1557 |
| 1555 HEAP_OBJECT_IMPLEMENTATION(Field, Object); | 1558 HEAP_OBJECT_IMPLEMENTATION(Field, Object); |
| 1556 friend class Class; | 1559 friend class Class; |
| 1557 }; | 1560 }; |
| 1558 | 1561 |
| 1559 | 1562 |
| 1563 class LiteralToken : public Object { | |
| 1564 public: | |
| 1565 Token::Kind kind() const { return raw_ptr()->kind_; } | |
| 1566 RawString* literal() const { return raw_ptr()->literal_; } | |
| 1567 RawObject* value() const { return raw_ptr()->value_; } | |
| 1568 | |
| 1569 static intptr_t InstanceSize() { | |
| 1570 return RoundedAllocationSize(sizeof(RawLiteralToken)); | |
| 1571 } | |
| 1572 | |
| 1573 static RawLiteralToken* New(); | |
| 1574 static RawLiteralToken* New(Token::Kind kind, const String& literal); | |
| 1575 | |
| 1576 private: | |
| 1577 void set_kind(Token::Kind kind) const { raw_ptr()->kind_ = kind; } | |
| 1578 void set_literal(const String& literal) const; | |
| 1579 void set_value(const Object& value) const; | |
| 1580 | |
| 1581 HEAP_OBJECT_IMPLEMENTATION(LiteralToken, Object); | |
| 1582 friend class Class; | |
| 1583 }; | |
| 1584 | |
| 1585 | |
| 1560 class TokenStream : public Object { | 1586 class TokenStream : public Object { |
| 1561 public: | 1587 public: |
| 1562 inline intptr_t Length() const; | 1588 inline intptr_t Length() const; |
| 1563 | 1589 |
| 1564 inline Token::Kind KindAt(intptr_t index) const; | 1590 inline Token::Kind KindAt(intptr_t index) const; |
| 1565 | 1591 |
| 1566 void SetTokenAt(intptr_t index, Token::Kind kind, const String& literal); | 1592 void SetTokenAt(intptr_t index, Token::Kind kind, const String& literal); |
| 1593 void SetTokenAt(intptr_t index, const Object& token); | |
| 1567 | 1594 |
| 1568 RawObject* LiteralAt(intptr_t index) const { | 1595 RawObject* TokenAt(intptr_t index) const; |
| 1569 return *EntryAddr(index, RawTokenStream::kLiteralEntry); | 1596 RawString* LiteralAt(intptr_t index) const; |
| 1570 } | |
| 1571 | 1597 |
| 1572 static intptr_t InstanceSize() { | 1598 static intptr_t InstanceSize() { |
| 1573 ASSERT(sizeof(RawTokenStream) == OFFSET_OF(RawTokenStream, data_)); | 1599 ASSERT(sizeof(RawTokenStream) == OFFSET_OF(RawTokenStream, data_)); |
| 1574 return 0; | 1600 return 0; |
| 1575 } | 1601 } |
| 1576 static intptr_t InstanceSize(intptr_t len) { | 1602 static intptr_t InstanceSize(intptr_t len) { |
| 1577 return RoundedAllocationSize( | 1603 ASSERT(RawTokenStream::kNumberOfEntries == 1); |
| 1578 sizeof(RawTokenStream) + | 1604 return RoundedAllocationSize(sizeof(RawTokenStream) + (len * kWordSize)); |
| 1579 (len * RawTokenStream::kNumberOfEntries * kWordSize)); | |
| 1580 } | 1605 } |
| 1581 static intptr_t StreamLength(intptr_t len) { | 1606 static intptr_t StreamLength(intptr_t len) { |
| 1582 return (len * RawTokenStream::kNumberOfEntries); | 1607 ASSERT(RawTokenStream::kNumberOfEntries == 1); |
| 1608 return len; | |
| 1583 } | 1609 } |
| 1584 | 1610 |
| 1585 static RawTokenStream* New(intptr_t length); | 1611 static RawTokenStream* New(intptr_t length); |
| 1586 static RawTokenStream* New(const Scanner::GrowableTokenStream& tokens); | 1612 static RawTokenStream* New(const Scanner::GrowableTokenStream& tokens); |
| 1587 | 1613 |
| 1588 private: | 1614 private: |
| 1589 void SetLength(intptr_t value) const; | 1615 void SetLength(intptr_t value) const; |
| 1590 | 1616 |
| 1591 RawObject** EntryAddr(intptr_t index, intptr_t entry_offset) const { | 1617 RawObject** EntryAddr(intptr_t index, intptr_t entry_offset) const { |
| 1592 ASSERT((index >=0) && (index < Length())); | 1618 ASSERT((index >=0) && (index < Length())); |
| 1593 intptr_t data_index = | 1619 ASSERT(RawTokenStream::kNumberOfEntries == 1); |
|
hausner
2012/02/29 00:22:37
Seems like a high price to pay for this assertion.
siva
2012/02/29 02:07:56
Done (i.e. got rid of the enum).
| |
| 1594 (index * RawTokenStream::kNumberOfEntries) + entry_offset; | 1620 intptr_t data_index = index + entry_offset; |
| 1595 return &raw_ptr()->data_[data_index]; | 1621 return &raw_ptr()->data_[data_index]; |
| 1596 } | 1622 } |
| 1597 | 1623 |
| 1598 RawSmi** SmiAddr(intptr_t index, intptr_t entry_offset) const { | 1624 RawSmi** SmiAddr(intptr_t index, intptr_t entry_offset) const { |
| 1599 return reinterpret_cast<RawSmi**>(EntryAddr(index, entry_offset)); | 1625 return reinterpret_cast<RawSmi**>(EntryAddr(index, entry_offset)); |
| 1600 } | 1626 } |
| 1601 | 1627 |
| 1602 HEAP_OBJECT_IMPLEMENTATION(TokenStream, Object); | 1628 HEAP_OBJECT_IMPLEMENTATION(TokenStream, Object); |
| 1603 friend class Class; | 1629 friend class Class; |
| 1604 }; | 1630 }; |
| (...skipping 2150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3755 raw_ptr()->value_ = Smi::New(value); | 3781 raw_ptr()->value_ = Smi::New(value); |
| 3756 } | 3782 } |
| 3757 | 3783 |
| 3758 | 3784 |
| 3759 intptr_t TokenStream::Length() const { | 3785 intptr_t TokenStream::Length() const { |
| 3760 return Smi::Value(raw_ptr()->length_); | 3786 return Smi::Value(raw_ptr()->length_); |
| 3761 } | 3787 } |
| 3762 | 3788 |
| 3763 | 3789 |
| 3764 Token::Kind TokenStream::KindAt(intptr_t index) const { | 3790 Token::Kind TokenStream::KindAt(intptr_t index) const { |
| 3765 return static_cast<Token::Kind>( | 3791 const Object& obj = Object::Handle(TokenAt(index)); |
| 3766 Smi::Value(*SmiAddr(index, RawTokenStream::kKindEntry))); | 3792 if (obj.IsSmi()) { |
| 3793 return static_cast<Token::Kind>( | |
| 3794 Smi::Value(reinterpret_cast<RawSmi*>(obj.raw()))); | |
| 3795 } else if (obj.IsLiteralToken()) { | |
| 3796 LiteralToken& token = LiteralToken::Handle(); | |
| 3797 token ^= obj.raw(); | |
| 3798 return token.kind(); | |
| 3799 } | |
| 3800 ASSERT(obj.IsString()); // Must be an identifier. | |
| 3801 return Token::kIDENT; | |
| 3767 } | 3802 } |
| 3768 | 3803 |
| 3769 | 3804 |
| 3770 void Context::SetAt(intptr_t index, const Instance& value) const { | 3805 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 3771 StorePointer(InstanceAddr(index), value.raw()); | 3806 StorePointer(InstanceAddr(index), value.raw()); |
| 3772 } | 3807 } |
| 3773 | 3808 |
| 3774 } // namespace dart | 3809 } // namespace dart |
| 3775 | 3810 |
| 3776 #endif // VM_OBJECT_H_ | 3811 #endif // VM_OBJECT_H_ |
| OLD | NEW |