Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: runtime/vm/object.h

Issue 12730013: - Use dart:typedata types in the Dart API calls. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_message.cc ('k') | runtime/vm/raw_object_snapshot.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 4917 matching lines...) Expand 10 before | Expand all | Expand 10 after
4928 intptr_t ElementSizeInBytes() const { 4928 intptr_t ElementSizeInBytes() const {
4929 intptr_t cid = raw()->GetClassId(); 4929 intptr_t cid = raw()->GetClassId();
4930 return ElementSizeInBytes(cid); 4930 return ElementSizeInBytes(cid);
4931 } 4931 }
4932 4932
4933 intptr_t LengthInBytes() const { 4933 intptr_t LengthInBytes() const {
4934 intptr_t cid = raw()->GetClassId(); 4934 intptr_t cid = raw()->GetClassId();
4935 return (ElementSizeInBytes(cid) * Length()); 4935 return (ElementSizeInBytes(cid) * Length());
4936 } 4936 }
4937 4937
4938 void* DataAddr(intptr_t byte_offset) const {
4939 ASSERT((byte_offset >= 0) && (byte_offset < LengthInBytes()));
4940 return reinterpret_cast<void*>(raw_ptr()->data_ + byte_offset);
4941 }
4942
4938 #define TYPED_GETTER_SETTER(name, type) \ 4943 #define TYPED_GETTER_SETTER(name, type) \
4939 type Get##name(intptr_t byte_offset) const { \ 4944 type Get##name(intptr_t byte_offset) const { \
4940 return *reinterpret_cast<type*>(DataAddr(byte_offset)); \ 4945 return *reinterpret_cast<type*>(DataAddr(byte_offset)); \
4941 } \ 4946 } \
4942 void Set##name(intptr_t byte_offset, type value) const { \ 4947 void Set##name(intptr_t byte_offset, type value) const { \
4943 *reinterpret_cast<type*>(DataAddr(byte_offset)) = value; \ 4948 *reinterpret_cast<type*>(DataAddr(byte_offset)) = value; \
4944 } 4949 }
4945 TYPED_GETTER_SETTER(Int8, int8_t) 4950 TYPED_GETTER_SETTER(Int8, int8_t)
4946 TYPED_GETTER_SETTER(Uint8, uint8_t) 4951 TYPED_GETTER_SETTER(Uint8, uint8_t)
4947 TYPED_GETTER_SETTER(Int16, int16_t) 4952 TYPED_GETTER_SETTER(Int16, int16_t)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
4982 Heap::Space space = Heap::kNew); 4987 Heap::Space space = Heap::kNew);
4983 4988
4984 protected: 4989 protected:
4985 void SetLength(intptr_t value) const { 4990 void SetLength(intptr_t value) const {
4986 raw_ptr()->length_ = Smi::New(value); 4991 raw_ptr()->length_ = Smi::New(value);
4987 } 4992 }
4988 4993
4989 private: 4994 private:
4990 static const intptr_t element_size[]; 4995 static const intptr_t element_size[];
4991 4996
4992 void* DataAddr(intptr_t byte_offset) const {
4993 ASSERT((byte_offset >= 0) && (byte_offset < LengthInBytes()));
4994 return reinterpret_cast<void*>(raw_ptr()->data_ + byte_offset);
4995 }
4996
4997 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypedData, Instance); 4997 FINAL_HEAP_OBJECT_IMPLEMENTATION(TypedData, Instance);
4998 friend class Class; 4998 friend class Class;
4999 friend class ExternalTypedData; 4999 friend class ExternalTypedData;
5000 }; 5000 };
5001 5001
5002 5002
5003 class ExternalTypedData : public Instance { 5003 class ExternalTypedData : public Instance {
5004 public: 5004 public:
5005 intptr_t Length() const { 5005 intptr_t Length() const {
5006 ASSERT(!IsNull()); 5006 ASSERT(!IsNull());
5007 return Smi::Value(raw_ptr()->length_); 5007 return Smi::Value(raw_ptr()->length_);
5008 } 5008 }
5009 5009
5010 intptr_t ElementSizeInBytes() const { 5010 intptr_t ElementSizeInBytes() const {
5011 intptr_t cid = raw()->GetClassId(); 5011 intptr_t cid = raw()->GetClassId();
5012 return ElementSizeInBytes(cid); 5012 return ElementSizeInBytes(cid);
5013 } 5013 }
5014 5014
5015 intptr_t LengthInBytes() const { 5015 intptr_t LengthInBytes() const {
5016 intptr_t cid = raw()->GetClassId(); 5016 intptr_t cid = raw()->GetClassId();
5017 return (ElementSizeInBytes(cid) * Length()); 5017 return (ElementSizeInBytes(cid) * Length());
5018 } 5018 }
5019 5019
5020 void* GetPeer() const {
5021 return raw_ptr()->peer_;
5022 }
5023
5024 void* DataAddr(intptr_t byte_offset) const {
5025 ASSERT((byte_offset >= 0) && (byte_offset < LengthInBytes()));
5026 return reinterpret_cast<void*>(raw_ptr()->data_ + byte_offset);
5027 }
5028
5020 #define TYPED_GETTER_SETTER(name, type) \ 5029 #define TYPED_GETTER_SETTER(name, type) \
5021 type Get##name(intptr_t byte_offset) const { \ 5030 type Get##name(intptr_t byte_offset) const { \
5022 return *reinterpret_cast<type*>(DataAddr(byte_offset)); \ 5031 return *reinterpret_cast<type*>(DataAddr(byte_offset)); \
5023 } \ 5032 } \
5024 void Set##name(intptr_t byte_offset, type value) const { \ 5033 void Set##name(intptr_t byte_offset, type value) const { \
5025 *reinterpret_cast<type*>(DataAddr(byte_offset)) = value; \ 5034 *reinterpret_cast<type*>(DataAddr(byte_offset)) = value; \
5026 } 5035 }
5027 TYPED_GETTER_SETTER(Int8, int8_t) 5036 TYPED_GETTER_SETTER(Int8, int8_t)
5028 TYPED_GETTER_SETTER(Uint8, uint8_t) 5037 TYPED_GETTER_SETTER(Uint8, uint8_t)
5029 TYPED_GETTER_SETTER(Int16, int16_t) 5038 TYPED_GETTER_SETTER(Int16, int16_t)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
5072 5081
5073 void SetData(uint8_t* data) const { 5082 void SetData(uint8_t* data) const {
5074 raw_ptr()->data_ = data; 5083 raw_ptr()->data_ = data;
5075 } 5084 }
5076 5085
5077 void SetPeer(void* peer) const { 5086 void SetPeer(void* peer) const {
5078 raw_ptr()->peer_ = peer; 5087 raw_ptr()->peer_ = peer;
5079 } 5088 }
5080 5089
5081 private: 5090 private:
5082 void* DataAddr(intptr_t byte_offset) const {
5083 ASSERT((byte_offset >= 0) && (byte_offset < LengthInBytes()));
5084 return reinterpret_cast<void*>(raw_ptr()->data_ + byte_offset);
5085 }
5086
5087 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalTypedData, Instance); 5091 FINAL_HEAP_OBJECT_IMPLEMENTATION(ExternalTypedData, Instance);
5088 friend class Class; 5092 friend class Class;
5089 }; 5093 };
5090 5094
5091 5095
5092 class ByteArray : public Instance { 5096 class ByteArray : public Instance {
5093 public: 5097 public:
5094 intptr_t Length() const { 5098 intptr_t Length() const {
5095 ASSERT(!IsNull()); 5099 ASSERT(!IsNull());
5096 return Smi::Value(raw_ptr()->length_); 5100 return Smi::Value(raw_ptr()->length_);
(...skipping 1727 matching lines...) Expand 10 before | Expand all | Expand 10 after
6824 6828
6825 6829
6826 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 6830 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
6827 intptr_t index) { 6831 intptr_t index) {
6828 return array.At((index * kEntryLength) + kTargetFunctionIndex); 6832 return array.At((index * kEntryLength) + kTargetFunctionIndex);
6829 } 6833 }
6830 6834
6831 } // namespace dart 6835 } // namespace dart
6832 6836
6833 #endif // VM_OBJECT_H_ 6837 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_message.cc ('k') | runtime/vm/raw_object_snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698