| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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_H_ | 5 #ifndef RUNTIME_VM_KERNEL_H_ |
| 6 #define RUNTIME_VM_KERNEL_H_ | 6 #define RUNTIME_VM_KERNEL_H_ |
| 7 | 7 |
| 8 #if !defined(DART_PRECOMPILED_RUNTIME) | 8 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 | 259 |
| 260 DISALLOW_COPY_AND_ASSIGN(Tuple); | 260 DISALLOW_COPY_AND_ASSIGN(Tuple); |
| 261 }; | 261 }; |
| 262 | 262 |
| 263 | 263 |
| 264 class String { | 264 class String { |
| 265 public: | 265 public: |
| 266 // Read a string reference, which is an index into the string table. | 266 // Read a string reference, which is an index into the string table. |
| 267 static String* ReadFrom(Reader* reader); | 267 static String* ReadFrom(Reader* reader); |
| 268 | 268 |
| 269 // Read a string implementation, which is a size followed by a UTF-8 | |
| 270 // encoded string. | |
| 271 static String* ReadFromImpl(Reader* reader); | |
| 272 | |
| 273 // Read a string implementation given its size. | 269 // Read a string implementation given its size. |
| 274 static String* ReadRaw(Reader* reader, intptr_t size); | 270 static String* ReadRaw(Reader* reader, intptr_t size); |
| 275 | 271 |
| 276 String(const uint8_t* utf8, int length) { | 272 String(intptr_t offset, int size) : offset_(offset), size_(size) {} |
| 277 buffer_ = new uint8_t[length]; | |
| 278 size_ = length; | |
| 279 memmove(buffer_, utf8, length); | |
| 280 } | |
| 281 ~String() { delete[] buffer_; } | |
| 282 | 273 |
| 283 uint8_t* buffer() { return buffer_; } | 274 intptr_t offset() { return offset_; } |
| 284 int size() { return size_; } | 275 int size() { return size_; } |
| 285 | 276 |
| 286 bool is_empty() { return size_ == 0; } | 277 bool is_empty() { return size_ == 0; } |
| 287 | 278 |
| 288 private: | 279 private: |
| 289 uint8_t* buffer_; | 280 intptr_t offset_; |
| 290 int size_; | 281 int size_; |
| 291 | 282 |
| 292 DISALLOW_COPY_AND_ASSIGN(String); | 283 DISALLOW_COPY_AND_ASSIGN(String); |
| 293 }; | 284 }; |
| 294 | 285 |
| 295 | 286 |
| 296 class StringTable { | 287 class StringTable { |
| 297 public: | 288 public: |
| 298 void ReadFrom(Reader* reader); | 289 void ReadFrom(Reader* reader); |
| 299 | 290 |
| 300 List<String>& strings() { return strings_; } | 291 List<String>& strings() { return strings_; } |
| 301 | 292 |
| 302 private: | 293 private: |
| 303 StringTable() {} | 294 StringTable() {} |
| 304 | 295 |
| 305 friend class Program; | 296 friend class Program; |
| 306 | 297 |
| 307 List<String> strings_; | 298 List<String> strings_; |
| 308 | 299 |
| 309 DISALLOW_COPY_AND_ASSIGN(StringTable); | 300 DISALLOW_COPY_AND_ASSIGN(StringTable); |
| 310 }; | 301 }; |
| 311 | 302 |
| 312 | 303 |
| 304 class Source { |
| 305 public: |
| 306 ~Source(); |
| 307 |
| 308 private: |
| 309 uint8_t* uri_; // UTF-8 encoded. |
| 310 intptr_t uri_size_; // In bytes. |
| 311 uint8_t* source_code_; // UTF-8 encoded. |
| 312 intptr_t source_code_size_; // In bytes. |
| 313 intptr_t* line_starts_; |
| 314 intptr_t line_count_; |
| 315 |
| 316 friend class SourceTable; |
| 317 }; |
| 318 |
| 319 |
| 313 class SourceTable { | 320 class SourceTable { |
| 314 public: | 321 public: |
| 322 ~SourceTable(); |
| 323 |
| 315 void ReadFrom(Reader* reader); | 324 void ReadFrom(Reader* reader); |
| 316 ~SourceTable() { | 325 |
| 317 for (intptr_t i = 0; i < size_; ++i) { | 326 intptr_t size() { return size_; } |
| 318 delete source_code_[i]; | 327 |
| 319 delete[] line_starts_[i]; | 328 uint8_t* UriFor(intptr_t i) { return sources_[i].uri_; } |
| 320 } | 329 intptr_t UriSizeFor(intptr_t i) { return sources_[i].uri_size_; } |
| 321 delete[] source_code_; | 330 |
| 322 delete[] line_starts_; | 331 uint8_t* SourceCodeFor(intptr_t i) { return sources_[i].source_code_; } |
| 323 delete[] line_count_; | 332 intptr_t SourceCodeSizeFor(intptr_t i) { |
| 333 return sources_[i].source_code_size_; |
| 324 } | 334 } |
| 325 | 335 |
| 326 intptr_t size() { return size_; } | 336 intptr_t* LineStartsFor(intptr_t i) { return sources_[i].line_starts_; } |
| 327 String* SourceFor(intptr_t i) { return source_code_[i]; } | 337 intptr_t LineCountFor(intptr_t i) { return sources_[i].line_count_; } |
| 328 intptr_t* LineStartsFor(intptr_t i) { return line_starts_[i]; } | |
| 329 intptr_t LineCountFor(intptr_t i) { return line_count_[i]; } | |
| 330 | 338 |
| 331 private: | 339 private: |
| 332 SourceTable() | 340 SourceTable() : size_(0), sources_(NULL) {} |
| 333 : source_code_(NULL), line_starts_(NULL), line_count_(NULL), size_(0) {} | |
| 334 | 341 |
| 335 friend class Program; | 342 friend class Program; |
| 336 | 343 |
| 337 String** source_code_; | 344 // The number of entries in the table. |
| 338 intptr_t** line_starts_; | |
| 339 intptr_t* line_count_; | |
| 340 intptr_t size_; | 345 intptr_t size_; |
| 341 | 346 |
| 347 // An array of sources. |
| 348 Source* sources_; |
| 349 |
| 342 DISALLOW_COPY_AND_ASSIGN(SourceTable); | 350 DISALLOW_COPY_AND_ASSIGN(SourceTable); |
| 343 }; | 351 }; |
| 344 | 352 |
| 345 // Forward declare all classes. | 353 // Forward declare all classes. |
| 346 #define DO(name) class name; | 354 #define DO(name) class name; |
| 347 KERNEL_ALL_NODES_DO(DO) | 355 KERNEL_ALL_NODES_DO(DO) |
| 348 KERNEL_VISITORS_DO(DO) | 356 KERNEL_VISITORS_DO(DO) |
| 349 #undef DO | 357 #undef DO |
| 350 | 358 |
| 351 | 359 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 377 | 385 |
| 378 class CanonicalName { | 386 class CanonicalName { |
| 379 public: | 387 public: |
| 380 ~CanonicalName(); | 388 ~CanonicalName(); |
| 381 | 389 |
| 382 String* name() { return name_; } | 390 String* name() { return name_; } |
| 383 CanonicalName* parent() { return parent_; } | 391 CanonicalName* parent() { return parent_; } |
| 384 bool is_referenced() { return is_referenced_; } | 392 bool is_referenced() { return is_referenced_; } |
| 385 void set_referenced(bool referenced) { is_referenced_ = referenced; } | 393 void set_referenced(bool referenced) { is_referenced_ = referenced; } |
| 386 | 394 |
| 387 CanonicalName* AddChild(String* name); | 395 CanonicalName* AddChild(String* string); |
| 388 | |
| 389 bool IsAdministrative(); | |
| 390 bool IsPrivate(); | |
| 391 | |
| 392 bool IsRoot(); | |
| 393 bool IsLibrary(); | |
| 394 bool IsClass(); | |
| 395 bool IsMember(); | |
| 396 bool IsField(); | |
| 397 bool IsConstructor(); | |
| 398 bool IsProcedure(); | |
| 399 bool IsMethod(); | |
| 400 bool IsGetter(); | |
| 401 bool IsSetter(); | |
| 402 bool IsFactory(); | |
| 403 | |
| 404 // For a member (field, constructor, or procedure) return the canonical name | |
| 405 // of the enclosing class or library. | |
| 406 CanonicalName* EnclosingName(); | |
| 407 | 396 |
| 408 static CanonicalName* NewRoot(); | 397 static CanonicalName* NewRoot(); |
| 409 | 398 |
| 410 private: | 399 private: |
| 411 CanonicalName(); | 400 CanonicalName(); |
| 412 | 401 |
| 413 bool is_referenced_; | 402 bool is_referenced_; |
| 414 Ref<CanonicalName> parent_; | 403 Ref<CanonicalName> parent_; |
| 415 Ref<String> name_; | 404 Ref<String> name_; |
| 416 MallocGrowableArray<CanonicalName*> children_; | 405 MallocGrowableArray<CanonicalName*> children_; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 virtual void AcceptTreeVisitor(TreeVisitor* visitor); | 485 virtual void AcceptTreeVisitor(TreeVisitor* visitor); |
| 497 virtual void VisitChildren(Visitor* visitor); | 486 virtual void VisitChildren(Visitor* visitor); |
| 498 | 487 |
| 499 String* import_uri() { return import_uri_; } | 488 String* import_uri() { return import_uri_; } |
| 500 intptr_t source_uri_index() { return source_uri_index_; } | 489 intptr_t source_uri_index() { return source_uri_index_; } |
| 501 String* name() { return name_; } | 490 String* name() { return name_; } |
| 502 List<Class>& classes() { return classes_; } | 491 List<Class>& classes() { return classes_; } |
| 503 List<Field>& fields() { return fields_; } | 492 List<Field>& fields() { return fields_; } |
| 504 List<Procedure>& procedures() { return procedures_; } | 493 List<Procedure>& procedures() { return procedures_; } |
| 505 | 494 |
| 506 bool IsCorelibrary() { | |
| 507 static const char* dart_library = "dart:"; | |
| 508 static intptr_t dart_library_length = strlen(dart_library); | |
| 509 static const char* patch_library = "dart:_patch"; | |
| 510 static intptr_t patch_library_length = strlen(patch_library); | |
| 511 | |
| 512 if (name_->size() < 5) return false; | |
| 513 | |
| 514 // Check for dart: prefix. | |
| 515 char* buffer = reinterpret_cast<char*>(import_uri_->buffer()); | |
| 516 if (strncmp(buffer, dart_library, dart_library_length) != 0) { | |
| 517 return false; | |
| 518 } | |
| 519 | |
| 520 // Rasta emits dart:_patch and we should treat it as a user library. | |
| 521 if (name_->size() == patch_library_length && | |
| 522 strncmp(buffer, patch_library, patch_library_length) == 0) { | |
| 523 return false; | |
| 524 } | |
| 525 return true; | |
| 526 } | |
| 527 | |
| 528 const uint8_t* kernel_data() { return kernel_data_; } | 495 const uint8_t* kernel_data() { return kernel_data_; } |
| 529 intptr_t kernel_data_size() { return kernel_data_size_; } | 496 intptr_t kernel_data_size() { return kernel_data_size_; } |
| 530 | 497 |
| 531 private: | 498 private: |
| 532 Library() : name_(NULL), kernel_data_(NULL), kernel_data_size_(-1) {} | 499 Library() : name_(NULL), kernel_data_(NULL), kernel_data_size_(-1) {} |
| 533 | 500 |
| 534 template <typename T> | 501 template <typename T> |
| 535 friend class List; | 502 friend class List; |
| 536 | 503 |
| 537 Ref<String> name_; | 504 Ref<String> name_; |
| (...skipping 2349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2887 static Program* ReadFrom(Reader* reader); | 2854 static Program* ReadFrom(Reader* reader); |
| 2888 | 2855 |
| 2889 virtual ~Program(); | 2856 virtual ~Program(); |
| 2890 | 2857 |
| 2891 DEFINE_CASTING_OPERATIONS(Program); | 2858 DEFINE_CASTING_OPERATIONS(Program); |
| 2892 | 2859 |
| 2893 virtual void AcceptTreeVisitor(TreeVisitor* visitor); | 2860 virtual void AcceptTreeVisitor(TreeVisitor* visitor); |
| 2894 virtual void VisitChildren(Visitor* visitor); | 2861 virtual void VisitChildren(Visitor* visitor); |
| 2895 | 2862 |
| 2896 StringTable& string_table() { return string_table_; } | 2863 StringTable& string_table() { return string_table_; } |
| 2897 StringTable& source_uri_table() { return source_uri_table_; } | |
| 2898 SourceTable& source_table() { return source_table_; } | 2864 SourceTable& source_table() { return source_table_; } |
| 2899 List<Library>& libraries() { return libraries_; } | 2865 List<Library>& libraries() { return libraries_; } |
| 2900 CanonicalName* main_method() { return main_method_reference_; } | 2866 CanonicalName* main_method() { return main_method_reference_; } |
| 2901 CanonicalName* canonical_name_root() { return canonical_name_root_; } | 2867 CanonicalName* canonical_name_root() { return canonical_name_root_; } |
| 2902 MallocGrowableArray<MallocGrowableArray<intptr_t>*> valid_token_positions; | 2868 MallocGrowableArray<MallocGrowableArray<intptr_t>*> valid_token_positions; |
| 2903 MallocGrowableArray<MallocGrowableArray<intptr_t>*> yield_token_positions; | 2869 MallocGrowableArray<MallocGrowableArray<intptr_t>*> yield_token_positions; |
| 2870 intptr_t string_data_offset() { return string_data_offset_; } |
| 2904 | 2871 |
| 2905 private: | 2872 private: |
| 2906 Program() {} | 2873 Program() {} |
| 2907 | 2874 |
| 2908 Child<CanonicalName> canonical_name_root_; | 2875 Child<CanonicalName> canonical_name_root_; |
| 2909 List<Library> libraries_; | 2876 List<Library> libraries_; |
| 2910 Ref<CanonicalName> main_method_reference_; // Procedure. | 2877 Ref<CanonicalName> main_method_reference_; // Procedure. |
| 2911 StringTable string_table_; | 2878 StringTable string_table_; |
| 2912 StringTable source_uri_table_; | |
| 2913 SourceTable source_table_; | 2879 SourceTable source_table_; |
| 2914 | 2880 |
| 2881 // The offset from the start of the binary to the start of the UTF-8 encoded |
| 2882 // string data. |
| 2883 intptr_t string_data_offset_; |
| 2884 |
| 2915 DISALLOW_COPY_AND_ASSIGN(Program); | 2885 DISALLOW_COPY_AND_ASSIGN(Program); |
| 2916 }; | 2886 }; |
| 2917 | 2887 |
| 2918 | 2888 |
| 2919 class Reference : public AllStatic { | 2889 class Reference : public AllStatic { |
| 2920 public: | 2890 public: |
| 2921 static CanonicalName* ReadMemberFrom(Reader* reader, bool allow_null = false); | 2891 static CanonicalName* ReadMemberFrom(Reader* reader, bool allow_null = false); |
| 2922 | 2892 |
| 2923 static CanonicalName* ReadClassFrom(Reader* reader, bool allow_null = false); | 2893 static CanonicalName* ReadClassFrom(Reader* reader, bool allow_null = false); |
| 2924 | 2894 |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3313 } // namespace kernel | 3283 } // namespace kernel |
| 3314 | 3284 |
| 3315 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, | 3285 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, |
| 3316 intptr_t buffer_length); | 3286 intptr_t buffer_length); |
| 3317 | 3287 |
| 3318 | 3288 |
| 3319 } // namespace dart | 3289 } // namespace dart |
| 3320 | 3290 |
| 3321 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 3291 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| 3322 #endif // RUNTIME_VM_KERNEL_H_ | 3292 #endif // RUNTIME_VM_KERNEL_H_ |
| OLD | NEW |