| 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_TO_IL_H_ | 5 #ifndef RUNTIME_VM_KERNEL_TO_IL_H_ |
| 6 #define RUNTIME_VM_KERNEL_TO_IL_H_ | 6 #define RUNTIME_VM_KERNEL_TO_IL_H_ |
| 7 | 7 |
| 8 #if !defined(DART_PRECOMPILED_RUNTIME) | 8 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 9 | 9 |
| 10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 const dart::Class* klass) | 232 const dart::Class* klass) |
| 233 : active_class_(active_class), saved_(*active_class) { | 233 : active_class_(active_class), saved_(*active_class) { |
| 234 active_class_->kernel_class = NULL; | 234 active_class_->kernel_class = NULL; |
| 235 active_class_->class_type_parameters = class_type_parameters; | 235 active_class_->class_type_parameters = class_type_parameters; |
| 236 active_class_->class_type_parameters_offset_start = | 236 active_class_->class_type_parameters_offset_start = |
| 237 class_type_parameters_offset_start; | 237 class_type_parameters_offset_start; |
| 238 active_class_->klass = klass; | 238 active_class_->klass = klass; |
| 239 active_class_->member = NULL; | 239 active_class_->member = NULL; |
| 240 } | 240 } |
| 241 | 241 |
| 242 | |
| 243 ActiveClassScope(ActiveClass* active_class, | |
| 244 Class* kernel_class, | |
| 245 const dart::Class* klass) | |
| 246 : active_class_(active_class), saved_(*active_class) { | |
| 247 active_class_->kernel_class = kernel_class; | |
| 248 active_class_->klass = klass; | |
| 249 active_class_->member = NULL; | |
| 250 | |
| 251 if (kernel_class != NULL) { | |
| 252 List<TypeParameter>& type_parameters = kernel_class->type_parameters(); | |
| 253 active_class_->class_type_parameters = type_parameters.length(); | |
| 254 active_class_->class_type_parameters_offset_start = | |
| 255 active_class_->class_type_parameters > 0 | |
| 256 ? type_parameters[0]->kernel_offset() | |
| 257 : -1; | |
| 258 } | |
| 259 } | |
| 260 | |
| 261 ~ActiveClassScope() { *active_class_ = saved_; } | 242 ~ActiveClassScope() { *active_class_ = saved_; } |
| 262 | 243 |
| 263 private: | 244 private: |
| 264 ActiveClass* active_class_; | 245 ActiveClass* active_class_; |
| 265 ActiveClass saved_; | 246 ActiveClass saved_; |
| 266 }; | 247 }; |
| 267 | 248 |
| 268 | 249 |
| 269 class ActiveMemberScope { | 250 class ActiveMemberScope { |
| 270 public: | 251 public: |
| 271 ActiveMemberScope(ActiveClass* active_class, | 252 ActiveMemberScope(ActiveClass* active_class, |
| 272 bool member_is_procedure, | 253 bool member_is_procedure, |
| 273 bool member_is_factory_procedure, | 254 bool member_is_factory_procedure, |
| 274 intptr_t member_type_parameters, | 255 intptr_t member_type_parameters, |
| 275 intptr_t member_type_parameters_offset_start) | 256 intptr_t member_type_parameters_offset_start) |
| 276 : active_class_(active_class), saved_(*active_class) { | 257 : active_class_(active_class), saved_(*active_class) { |
| 277 // The class and kernel_class is inherited. | 258 // The class and kernel_class is inherited. |
| 278 active_class_->member = NULL; | 259 active_class_->member = NULL; |
| 279 active_class_->member_is_procedure = member_is_procedure; | 260 active_class_->member_is_procedure = member_is_procedure; |
| 280 active_class_->member_is_factory_procedure = member_is_factory_procedure; | 261 active_class_->member_is_factory_procedure = member_is_factory_procedure; |
| 281 active_class_->member_type_parameters = member_type_parameters; | 262 active_class_->member_type_parameters = member_type_parameters; |
| 282 active_class_->member_type_parameters_offset_start = | 263 active_class_->member_type_parameters_offset_start = |
| 283 member_type_parameters_offset_start; | 264 member_type_parameters_offset_start; |
| 284 } | 265 } |
| 285 | 266 |
| 286 ActiveMemberScope(ActiveClass* active_class, Member* member) | |
| 287 : active_class_(active_class), saved_(*active_class) { | |
| 288 // The class and kernel_class is inherited. | |
| 289 active_class_->member = member; | |
| 290 | |
| 291 active_class_->member_is_procedure = false; | |
| 292 active_class_->member_is_factory_procedure = false; | |
| 293 active_class_->member_type_parameters = 0; | |
| 294 active_class_->member_type_parameters_offset_start = -1; | |
| 295 | |
| 296 if (member == NULL || !member->IsProcedure()) { | |
| 297 return; | |
| 298 } | |
| 299 | |
| 300 Procedure* procedure = Procedure::Cast(member); | |
| 301 active_class_->member_is_procedure = true; | |
| 302 active_class->member_is_factory_procedure = | |
| 303 procedure->kind() == Procedure::kFactory; | |
| 304 if (procedure->function() != NULL) { | |
| 305 TypeParameterList& type_parameters = | |
| 306 procedure->function()->type_parameters(); | |
| 307 if (type_parameters.length() > 0) { | |
| 308 active_class_->member_type_parameters = type_parameters.length(); | |
| 309 active_class_->member_type_parameters_offset_start = | |
| 310 type_parameters.first_offset; | |
| 311 } | |
| 312 } | |
| 313 } | |
| 314 | |
| 315 ~ActiveMemberScope() { *active_class_ = saved_; } | 267 ~ActiveMemberScope() { *active_class_ = saved_; } |
| 316 | 268 |
| 317 private: | 269 private: |
| 318 ActiveClass* active_class_; | 270 ActiveClass* active_class_; |
| 319 ActiveClass saved_; | 271 ActiveClass saved_; |
| 320 }; | 272 }; |
| 321 | 273 |
| 322 | 274 |
| 323 class TranslationHelper { | 275 class TranslationHelper { |
| 324 public: | 276 public: |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 | 352 |
| 401 const dart::String& DartSetterName(NameIndex setter); | 353 const dart::String& DartSetterName(NameIndex setter); |
| 402 const dart::String& DartSetterName(Name* setter_name); | 354 const dart::String& DartSetterName(Name* setter_name); |
| 403 const dart::String& DartSetterName(NameIndex parent, StringIndex setter); | 355 const dart::String& DartSetterName(NameIndex parent, StringIndex setter); |
| 404 | 356 |
| 405 const dart::String& DartGetterName(NameIndex getter); | 357 const dart::String& DartGetterName(NameIndex getter); |
| 406 const dart::String& DartGetterName(Name* getter_name); | 358 const dart::String& DartGetterName(Name* getter_name); |
| 407 const dart::String& DartGetterName(NameIndex parent, StringIndex getter); | 359 const dart::String& DartGetterName(NameIndex parent, StringIndex getter); |
| 408 | 360 |
| 409 const dart::String& DartFieldName(Name* kernel_name); | 361 const dart::String& DartFieldName(Name* kernel_name); |
| 362 const dart::String& DartFieldName(NameIndex parent, StringIndex field); |
| 410 | 363 |
| 411 const dart::String& DartInitializerName(Name* kernel_name); | 364 const dart::String& DartInitializerName(Name* kernel_name); |
| 412 | 365 |
| 413 const dart::String& DartMethodName(NameIndex method); | 366 const dart::String& DartMethodName(NameIndex method); |
| 414 const dart::String& DartMethodName(Name* method_name); | 367 const dart::String& DartMethodName(Name* method_name); |
| 415 const dart::String& DartMethodName(NameIndex parent, StringIndex method); | 368 const dart::String& DartMethodName(NameIndex parent, StringIndex method); |
| 416 | 369 |
| 417 const dart::String& DartFactoryName(NameIndex factory); | 370 const dart::String& DartFactoryName(NameIndex factory); |
| 418 | 371 |
| 419 const Array& ArgumentNames(List<NamedExpression>* named); | 372 const Array& ArgumentNames(List<NamedExpression>* named); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 449 Thread* thread_; | 402 Thread* thread_; |
| 450 Zone* zone_; | 403 Zone* zone_; |
| 451 Isolate* isolate_; | 404 Isolate* isolate_; |
| 452 Heap::Space allocation_space_; | 405 Heap::Space allocation_space_; |
| 453 | 406 |
| 454 TypedData& string_offsets_; | 407 TypedData& string_offsets_; |
| 455 TypedData& string_data_; | 408 TypedData& string_data_; |
| 456 TypedData& canonical_names_; | 409 TypedData& canonical_names_; |
| 457 }; | 410 }; |
| 458 | 411 |
| 459 // Regarding malformed types: | |
| 460 // The spec says in section "19.1 Static Types" roughly: | |
| 461 // | |
| 462 // A type T is malformed iff: | |
| 463 // * T does not denote a type in scope | |
| 464 // * T refers to a type parameter in a static member | |
| 465 // * T is a parametrized Type G<T1, ...> and G is malformed | |
| 466 // * T denotes declarations from multiple imports | |
| 467 // | |
| 468 // Any use of a malformed type gives rise to a static warning. A malformed | |
| 469 // type is then interpreted as dynamic by the static type checker and the | |
| 470 // runtime unless explicitly specified otherwise. | |
| 471 class DartTypeTranslator : public DartTypeVisitor { | |
| 472 public: | |
| 473 DartTypeTranslator(TranslationHelper* helper, | |
| 474 ActiveClass* active_class, | |
| 475 bool finalize = false) | |
| 476 : translation_helper_(*helper), | |
| 477 active_class_(active_class), | |
| 478 type_parameter_scope_(NULL), | |
| 479 zone_(helper->zone()), | |
| 480 result_(AbstractType::Handle(helper->zone())), | |
| 481 finalize_(finalize) {} | |
| 482 | |
| 483 // Can return a malformed type. | |
| 484 AbstractType& TranslateType(DartType* node); | |
| 485 | |
| 486 // Can return a malformed type. | |
| 487 AbstractType& TranslateTypeWithoutFinalization(DartType* node); | |
| 488 | |
| 489 // Is guaranteed to be not malformed. | |
| 490 const AbstractType& TranslateVariableType(VariableDeclaration* variable); | |
| 491 | |
| 492 | |
| 493 virtual void VisitDefaultDartType(DartType* node) { UNREACHABLE(); } | |
| 494 | |
| 495 virtual void VisitInvalidType(InvalidType* node); | |
| 496 | |
| 497 virtual void VisitFunctionType(FunctionType* node); | |
| 498 | |
| 499 virtual void VisitTypeParameterType(TypeParameterType* node); | |
| 500 | |
| 501 virtual void VisitInterfaceType(InterfaceType* node); | |
| 502 | |
| 503 virtual void VisitDynamicType(DynamicType* node); | |
| 504 | |
| 505 virtual void VisitVoidType(VoidType* node); | |
| 506 | |
| 507 virtual void VisitBottomType(BottomType* node); | |
| 508 | |
| 509 // Will return `TypeArguments::null()` in case any of the arguments are | |
| 510 // malformed. | |
| 511 const TypeArguments& TranslateInstantiatedTypeArguments( | |
| 512 const dart::Class& receiver_class, | |
| 513 DartType** receiver_type_arguments, | |
| 514 intptr_t length); | |
| 515 | |
| 516 // Will return `TypeArguments::null()` in case any of the arguments are | |
| 517 // malformed. | |
| 518 const TypeArguments& TranslateTypeArguments(DartType** dart_types, | |
| 519 intptr_t length); | |
| 520 | |
| 521 const Type& ReceiverType(const dart::Class& klass); | |
| 522 | |
| 523 private: | |
| 524 class TypeParameterScope { | |
| 525 public: | |
| 526 TypeParameterScope(DartTypeTranslator* translator, | |
| 527 List<TypeParameter>* parameters) | |
| 528 : parameters_(parameters), | |
| 529 outer_(translator->type_parameter_scope_), | |
| 530 translator_(translator) { | |
| 531 translator_->type_parameter_scope_ = this; | |
| 532 } | |
| 533 ~TypeParameterScope() { translator_->type_parameter_scope_ = outer_; } | |
| 534 | |
| 535 TypeParameterScope* outer() const { return outer_; } | |
| 536 List<TypeParameter>* parameters() const { return parameters_; } | |
| 537 | |
| 538 private: | |
| 539 List<TypeParameter>* parameters_; | |
| 540 TypeParameterScope* outer_; | |
| 541 DartTypeTranslator* translator_; | |
| 542 }; | |
| 543 | |
| 544 TranslationHelper& translation_helper_; | |
| 545 ActiveClass* active_class_; | |
| 546 TypeParameterScope* type_parameter_scope_; | |
| 547 Zone* zone_; | |
| 548 AbstractType& result_; | |
| 549 bool finalize_; | |
| 550 }; | |
| 551 | |
| 552 | 412 |
| 553 struct FunctionScope { | 413 struct FunctionScope { |
| 554 intptr_t kernel_offset; | 414 intptr_t kernel_offset; |
| 555 LocalScope* scope; | 415 LocalScope* scope; |
| 556 }; | 416 }; |
| 557 | 417 |
| 558 | 418 |
| 559 class ScopeBuildingResult : public ZoneAllocated { | 419 class ScopeBuildingResult : public ZoneAllocated { |
| 560 public: | 420 public: |
| 561 ScopeBuildingResult() | 421 ScopeBuildingResult() |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 // A chained list of try-catch blocks. Chaining and lookup is done by the | 718 // A chained list of try-catch blocks. Chaining and lookup is done by the |
| 859 // [TryCatchBlock] class. | 719 // [TryCatchBlock] class. |
| 860 TryCatchBlock* try_catch_block_; | 720 TryCatchBlock* try_catch_block_; |
| 861 intptr_t next_used_try_index_; | 721 intptr_t next_used_try_index_; |
| 862 | 722 |
| 863 // A chained list of catch blocks. Chaining and lookup is done by the | 723 // A chained list of catch blocks. Chaining and lookup is done by the |
| 864 // [CatchBlock] class. | 724 // [CatchBlock] class. |
| 865 CatchBlock* catch_block_; | 725 CatchBlock* catch_block_; |
| 866 | 726 |
| 867 ActiveClass active_class_; | 727 ActiveClass active_class_; |
| 868 DartTypeTranslator type_translator_; | |
| 869 | 728 |
| 870 StreamingFlowGraphBuilder* streaming_flow_graph_builder_; | 729 StreamingFlowGraphBuilder* streaming_flow_graph_builder_; |
| 871 | 730 |
| 872 friend class BreakableBlock; | 731 friend class BreakableBlock; |
| 873 friend class CatchBlock; | 732 friend class CatchBlock; |
| 874 friend class ConstantEvaluator; | 733 friend class ConstantEvaluator; |
| 875 friend class DartTypeTranslator; | |
| 876 friend class StreamingFlowGraphBuilder; | 734 friend class StreamingFlowGraphBuilder; |
| 877 friend class ScopeBuilder; | 735 friend class ScopeBuilder; |
| 878 friend class SwitchBlock; | 736 friend class SwitchBlock; |
| 879 friend class TryCatchBlock; | 737 friend class TryCatchBlock; |
| 880 friend class TryFinallyBlock; | 738 friend class TryFinallyBlock; |
| 881 }; | 739 }; |
| 882 | 740 |
| 883 | 741 |
| 884 class SwitchBlock { | 742 class SwitchBlock { |
| 885 public: | 743 public: |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 private: | 839 private: |
| 982 FlowGraphBuilder* builder_; | 840 FlowGraphBuilder* builder_; |
| 983 TryCatchBlock* outer_; | 841 TryCatchBlock* outer_; |
| 984 intptr_t try_index_; | 842 intptr_t try_index_; |
| 985 }; | 843 }; |
| 986 | 844 |
| 987 | 845 |
| 988 class TryFinallyBlock { | 846 class TryFinallyBlock { |
| 989 public: | 847 public: |
| 990 TryFinallyBlock(FlowGraphBuilder* builder, | 848 TryFinallyBlock(FlowGraphBuilder* builder, |
| 991 Statement* finalizer, | |
| 992 intptr_t finalizer_kernel_offset) | 849 intptr_t finalizer_kernel_offset) |
| 993 : builder_(builder), | 850 : builder_(builder), |
| 994 outer_(builder->try_finally_block_), | 851 outer_(builder->try_finally_block_), |
| 995 finalizer_(finalizer), | |
| 996 finalizer_kernel_offset_(finalizer_kernel_offset), | 852 finalizer_kernel_offset_(finalizer_kernel_offset), |
| 997 context_depth_(builder->context_depth_), | 853 context_depth_(builder->context_depth_), |
| 998 // Finalizers are executed outside of the try block hence | 854 // Finalizers are executed outside of the try block hence |
| 999 // try depth of finalizers are one less than current try | 855 // try depth of finalizers are one less than current try |
| 1000 // depth. | 856 // depth. |
| 1001 try_depth_(builder->try_depth_ - 1), | 857 try_depth_(builder->try_depth_ - 1), |
| 1002 try_index_(builder_->CurrentTryIndex()) { | 858 try_index_(builder_->CurrentTryIndex()) { |
| 1003 builder_->try_finally_block_ = this; | 859 builder_->try_finally_block_ = this; |
| 1004 } | 860 } |
| 1005 ~TryFinallyBlock() { builder_->try_finally_block_ = outer_; } | 861 ~TryFinallyBlock() { builder_->try_finally_block_ = outer_; } |
| 1006 | 862 |
| 1007 Statement* finalizer() const { return finalizer_; } | |
| 1008 intptr_t finalizer_kernel_offset() const { return finalizer_kernel_offset_; } | 863 intptr_t finalizer_kernel_offset() const { return finalizer_kernel_offset_; } |
| 1009 intptr_t context_depth() const { return context_depth_; } | 864 intptr_t context_depth() const { return context_depth_; } |
| 1010 intptr_t try_depth() const { return try_depth_; } | 865 intptr_t try_depth() const { return try_depth_; } |
| 1011 intptr_t try_index() const { return try_index_; } | 866 intptr_t try_index() const { return try_index_; } |
| 1012 TryFinallyBlock* outer() const { return outer_; } | 867 TryFinallyBlock* outer() const { return outer_; } |
| 1013 | 868 |
| 1014 private: | 869 private: |
| 1015 FlowGraphBuilder* const builder_; | 870 FlowGraphBuilder* const builder_; |
| 1016 TryFinallyBlock* const outer_; | 871 TryFinallyBlock* const outer_; |
| 1017 Statement* const finalizer_; | |
| 1018 intptr_t finalizer_kernel_offset_; | 872 intptr_t finalizer_kernel_offset_; |
| 1019 const intptr_t context_depth_; | 873 const intptr_t context_depth_; |
| 1020 const intptr_t try_depth_; | 874 const intptr_t try_depth_; |
| 1021 const intptr_t try_index_; | 875 const intptr_t try_index_; |
| 1022 }; | 876 }; |
| 1023 | 877 |
| 1024 | 878 |
| 1025 class BreakableBlock { | 879 class BreakableBlock { |
| 1026 public: | 880 public: |
| 1027 explicit BreakableBlock(FlowGraphBuilder* builder) | 881 explicit BreakableBlock(FlowGraphBuilder* builder) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 namespace kernel { | 972 namespace kernel { |
| 1119 | 973 |
| 1120 RawObject* EvaluateMetadata(const dart::Field& metadata_field); | 974 RawObject* EvaluateMetadata(const dart::Field& metadata_field); |
| 1121 RawObject* BuildParameterDescriptor(const Function& function); | 975 RawObject* BuildParameterDescriptor(const Function& function); |
| 1122 | 976 |
| 1123 } // namespace kernel | 977 } // namespace kernel |
| 1124 } // namespace dart | 978 } // namespace dart |
| 1125 | 979 |
| 1126 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 980 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| 1127 #endif // RUNTIME_VM_KERNEL_TO_IL_H_ | 981 #endif // RUNTIME_VM_KERNEL_TO_IL_H_ |
| OLD | NEW |