| 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/object.h" | 8 #include "vm/object.h" |
| 9 #include "vm/snapshot_ids.h" | 9 #include "vm/snapshot_ids.h" |
| 10 | 10 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 170 |
| 171 // Initialize frequently used symbols in the vm isolate. | 171 // Initialize frequently used symbols in the vm isolate. |
| 172 static void InitOnce(Isolate* isolate); | 172 static void InitOnce(Isolate* isolate); |
| 173 | 173 |
| 174 // Initialize and setup a symbol table for the isolate. | 174 // Initialize and setup a symbol table for the isolate. |
| 175 static void SetupSymbolTable(Isolate* isolate); | 175 static void SetupSymbolTable(Isolate* isolate); |
| 176 | 176 |
| 177 // Get number of symbols in an isolate's symbol table. | 177 // Get number of symbols in an isolate's symbol table. |
| 178 static intptr_t Size(Isolate* isolate); | 178 static intptr_t Size(Isolate* isolate); |
| 179 | 179 |
| 180 // Helper functions to create a symbol given a string or set of characters. | 180 // Creates a Symbol given a C string that is assumed to contain |
| 181 static RawString* New(const char* str); | 181 // UTF-8 encoded characters and '\0' is considered a termination character. |
| 182 template<typename T> | 182 // TODO(7123) - Rename this to FromCString(....). |
| 183 static RawString* New(const T* characters, intptr_t len); | 183 static RawString* New(const char* cstr); |
| 184 |
| 185 // Creates a new Symbol from an array of UTF-8 encoded characters. |
| 186 static RawString* FromUTF8(const uint8_t* utf8_array, intptr_t len); |
| 187 |
| 188 // Creates a new Symbol from an array of Latin-1 encoded characters. |
| 189 static RawString* FromLatin1(const uint8_t* latin1_array, intptr_t len); |
| 190 |
| 191 // Creates a new Symbol from an array of UTF-16 encoded characters. |
| 192 static RawString* FromUTF16(const uint16_t* utf16_array, intptr_t len); |
| 193 |
| 194 // Creates a new Symbol from an array of UTF-32 encoded characters. |
| 195 static RawString* FromUTF32(const int32_t* utf32_array, intptr_t len); |
| 196 |
| 184 static RawString* New(const String& str); | 197 static RawString* New(const String& str); |
| 185 static RawString* New(const String& str, | 198 static RawString* New(const String& str, |
| 186 intptr_t begin_index, | 199 intptr_t begin_index, |
| 187 intptr_t length); | 200 intptr_t length); |
| 188 | 201 |
| 189 // Returns char* of predefined symbol. | 202 // Returns char* of predefined symbol. |
| 190 static const char* Name(SymbolId symbol); | 203 static const char* Name(SymbolId symbol); |
| 191 | 204 |
| 192 static RawString* FromCharCode(int32_t char_code); | 205 static RawString* FromCharCode(int32_t char_code); |
| 193 | 206 |
| 194 static RawString** PredefinedAddress() { | 207 static RawString** PredefinedAddress() { |
| 195 return reinterpret_cast<RawString**>(&predefined_); | 208 return reinterpret_cast<RawString**>(&predefined_); |
| 196 } | 209 } |
| 197 | 210 |
| 198 private: | 211 private: |
| 199 enum { | 212 enum { |
| 200 kInitialVMIsolateSymtabSize = ((kMaxId + 15) & -16), | 213 kInitialVMIsolateSymtabSize = ((kMaxId + 15) & -16), |
| 201 kInitialSymtabSize = 256 | 214 kInitialSymtabSize = 256 |
| 202 }; | 215 }; |
| 203 | 216 |
| 217 // Helper functions to create a symbol given a string or set of characters. |
| 218 template<typename T> |
| 219 static RawString* NewSymbol(const T* characters, intptr_t len); |
| 220 |
| 204 // Add the string into the VM isolate symbol table. | 221 // Add the string into the VM isolate symbol table. |
| 205 static void Add(const Array& symbol_table, const String& str); | 222 static void Add(const Array& symbol_table, const String& str); |
| 206 | 223 |
| 207 // Insert symbol into symbol table, growing it if necessary. | 224 // Insert symbol into symbol table, growing it if necessary. |
| 208 static void InsertIntoSymbolTable(const Array& symbol_table, | 225 static void InsertIntoSymbolTable(const Array& symbol_table, |
| 209 const String& symbol, | 226 const String& symbol, |
| 210 intptr_t index); | 227 intptr_t index); |
| 211 | 228 |
| 212 // Grow the symbol table. | 229 // Grow the symbol table. |
| 213 static void GrowSymbolTable(const Array& symbol_table); | 230 static void GrowSymbolTable(const Array& symbol_table); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 227 static intptr_t LookupVMSymbol(RawObject* obj); | 244 static intptr_t LookupVMSymbol(RawObject* obj); |
| 228 static RawObject* GetVMSymbol(intptr_t object_id); | 245 static RawObject* GetVMSymbol(intptr_t object_id); |
| 229 static bool IsVMSymbolId(intptr_t object_id) { | 246 static bool IsVMSymbolId(intptr_t object_id) { |
| 230 return (object_id >= kMaxPredefinedObjectIds && | 247 return (object_id >= kMaxPredefinedObjectIds && |
| 231 object_id < (kMaxPredefinedObjectIds + kMaxId)); | 248 object_id < (kMaxPredefinedObjectIds + kMaxId)); |
| 232 } | 249 } |
| 233 | 250 |
| 234 // List of symbols that are stored in the vm isolate for easy access. | 251 // List of symbols that are stored in the vm isolate for easy access. |
| 235 static RawString* predefined_[kMaxId]; | 252 static RawString* predefined_[kMaxId]; |
| 236 | 253 |
| 254 friend class String; |
| 237 friend class SnapshotReader; | 255 friend class SnapshotReader; |
| 238 friend class SnapshotWriter; | 256 friend class SnapshotWriter; |
| 239 friend class ApiMessageReader; | 257 friend class ApiMessageReader; |
| 240 | 258 |
| 241 DISALLOW_COPY_AND_ASSIGN(Symbols); | 259 DISALLOW_COPY_AND_ASSIGN(Symbols); |
| 242 }; | 260 }; |
| 243 | 261 |
| 244 } // namespace dart | 262 } // namespace dart |
| 245 | 263 |
| 246 #endif // VM_SYMBOLS_H_ | 264 #endif // VM_SYMBOLS_H_ |
| OLD | NEW |