| 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 #include "vm/flow_graph_builder.h" | 5 #include "vm/flow_graph_builder.h" |
| 6 | 6 |
| 7 #include "vm/ast_printer.h" | 7 #include "vm/ast_printer.h" |
| 8 #include "vm/code_descriptors.h" | 8 #include "vm/code_descriptors.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 for_true.Do(BuildStoreExprTemp(constant_true)); | 738 for_true.Do(BuildStoreExprTemp(constant_true)); |
| 739 Join(for_test, for_true, for_right); | 739 Join(for_test, for_true, for_right); |
| 740 } | 740 } |
| 741 ReturnDefinition(BuildLoadExprTemp()); | 741 ReturnDefinition(BuildLoadExprTemp()); |
| 742 return; | 742 return; |
| 743 } | 743 } |
| 744 EffectGraphVisitor::VisitBinaryOpNode(node); | 744 EffectGraphVisitor::VisitBinaryOpNode(node); |
| 745 } | 745 } |
| 746 | 746 |
| 747 | 747 |
| 748 void EffectGraphVisitor::BuildTypecheckPushArguments( |
| 749 intptr_t token_pos, |
| 750 PushArgumentInstr** push_instantiator_result, |
| 751 PushArgumentInstr** push_instantiator_type_arguments_result) { |
| 752 const Class& instantiator_class = Class::Handle( |
| 753 owner()->parsed_function().function().Owner()); |
| 754 // Since called only when type tested against is not instantiated. |
| 755 ASSERT(instantiator_class.NumTypeParameters() > 0); |
| 756 Value* instantiator_type_arguments = NULL; |
| 757 Value* instantiator = BuildInstantiator(); |
| 758 if (instantiator == NULL) { |
| 759 // No instantiator when inside factory. |
| 760 *push_instantiator_result = PushArgument(BuildNullValue()); |
| 761 instantiator_type_arguments = |
| 762 BuildInstantiatorTypeArguments(token_pos, NULL); |
| 763 } else { |
| 764 instantiator = Bind(BuildStoreExprTemp(instantiator)); |
| 765 *push_instantiator_result = PushArgument(instantiator); |
| 766 Value* loaded = Bind(BuildLoadExprTemp()); |
| 767 instantiator_type_arguments = |
| 768 BuildInstantiatorTypeArguments(token_pos, loaded); |
| 769 } |
| 770 *push_instantiator_type_arguments_result = |
| 771 PushArgument(instantiator_type_arguments); |
| 772 } |
| 773 |
| 774 |
| 775 |
| 748 void EffectGraphVisitor::BuildTypecheckArguments( | 776 void EffectGraphVisitor::BuildTypecheckArguments( |
| 749 intptr_t token_pos, | 777 intptr_t token_pos, |
| 750 Value** instantiator_result, | 778 Value** instantiator_result, |
| 751 Value** instantiator_type_arguments_result) { | 779 Value** instantiator_type_arguments_result) { |
| 752 Value* instantiator = NULL; | 780 Value* instantiator = NULL; |
| 753 Value* instantiator_type_arguments = NULL; | 781 Value* instantiator_type_arguments = NULL; |
| 754 const Class& instantiator_class = Class::Handle( | 782 const Class& instantiator_class = Class::Handle( |
| 755 owner()->parsed_function().function().Owner()); | 783 owner()->parsed_function().function().Owner()); |
| 756 // Since called only when type tested against is not instantiated. | 784 // Since called only when type tested against is not instantiated. |
| 757 ASSERT(instantiator_class.NumTypeParameters() > 0); | 785 ASSERT(instantiator_class.NumTypeParameters() > 0); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 result = new ConstantInstr(negate_result ? bool_true : bool_false); | 906 result = new ConstantInstr(negate_result ? bool_true : bool_false); |
| 879 } | 907 } |
| 880 } | 908 } |
| 881 ReturnDefinition(result); | 909 ReturnDefinition(result); |
| 882 return; | 910 return; |
| 883 } | 911 } |
| 884 | 912 |
| 885 ValueGraphVisitor for_left_value(owner(), temp_index(), loop_depth()); | 913 ValueGraphVisitor for_left_value(owner(), temp_index(), loop_depth()); |
| 886 node->left()->Visit(&for_left_value); | 914 node->left()->Visit(&for_left_value); |
| 887 Append(for_left_value); | 915 Append(for_left_value); |
| 888 Value* instantiator = NULL; | 916 PushArgumentInstr* push_left = PushArgument(for_left_value.value()); |
| 889 Value* instantiator_type_arguments = NULL; | 917 PushArgumentInstr* push_instantiator = NULL; |
| 918 PushArgumentInstr* push_type_args = NULL; |
| 890 if (type.IsInstantiated()) { | 919 if (type.IsInstantiated()) { |
| 891 instantiator = BuildNullValue(); | 920 push_instantiator = PushArgument(BuildNullValue()); |
| 892 instantiator_type_arguments = BuildNullValue(); | 921 push_type_args = PushArgument(BuildNullValue()); |
| 893 } else { | 922 } else { |
| 894 BuildTypecheckArguments(node->token_pos(), | 923 BuildTypecheckPushArguments(node->token_pos(), |
| 895 &instantiator, | 924 &push_instantiator, |
| 896 &instantiator_type_arguments); | 925 &push_type_args); |
| 897 } | 926 } |
| 898 InstanceOfInstr* instance_of = | 927 const String& name = String::ZoneHandle(Symbols::New("_instanceOf")); |
| 899 new InstanceOfInstr(node->token_pos(), | 928 ZoneGrowableArray<PushArgumentInstr*>* arguments = |
| 900 for_left_value.value(), | 929 new ZoneGrowableArray<PushArgumentInstr*>(5); |
| 901 instantiator, | 930 arguments->Add(push_left); |
| 902 instantiator_type_arguments, | 931 arguments->Add(push_instantiator); |
| 903 node->right()->AsTypeNode()->type(), | 932 arguments->Add(push_type_args); |
| 904 (node->kind() == Token::kISNOT)); | 933 ASSERT(!node->right()->AsTypeNode()->type().IsNull()); |
| 905 ReturnDefinition(instance_of); | 934 Value* type_arg = Bind( |
| 935 new ConstantInstr(node->right()->AsTypeNode()->type())); |
| 936 arguments->Add(PushArgument(type_arg)); |
| 937 const Bool& negate = Bool::ZoneHandle(node->kind() == Token::kISNOT ? |
| 938 Bool::True() : Bool::False()); |
| 939 Value* negate_arg = Bind(new ConstantInstr(negate)); |
| 940 arguments->Add(PushArgument(negate_arg)); |
| 941 const intptr_t kNumArgsChecked = 1; |
| 942 InstanceCallInstr* call = new InstanceCallInstr(node->token_pos(), |
| 943 name, |
| 944 node->kind(), |
| 945 arguments, |
| 946 Array::ZoneHandle(), |
| 947 kNumArgsChecked); |
| 948 ReturnDefinition(call); |
| 906 } | 949 } |
| 907 | 950 |
| 908 | 951 |
| 909 void ValueGraphVisitor::BuildTypeCast(ComparisonNode* node) { | 952 void ValueGraphVisitor::BuildTypeCast(ComparisonNode* node) { |
| 910 ASSERT(Token::IsTypeCastOperator(node->kind())); | 953 ASSERT(Token::IsTypeCastOperator(node->kind())); |
| 911 const AbstractType& type = node->right()->AsTypeNode()->type(); | 954 const AbstractType& type = node->right()->AsTypeNode()->type(); |
| 912 ASSERT(type.IsFinalized()); // The type in a type cast may be malformed. | 955 ASSERT(type.IsFinalized()); // The type in a type cast may be malformed. |
| 913 ValueGraphVisitor for_value(owner(), temp_index(), loop_depth()); | 956 ValueGraphVisitor for_value(owner(), temp_index(), loop_depth()); |
| 914 node->left()->Visit(&for_value); | 957 node->left()->Visit(&for_value); |
| 915 Append(for_value); | 958 Append(for_value); |
| (...skipping 2102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3018 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; | 3061 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; |
| 3019 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 3062 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 3020 OS::SNPrint(chars, len, kFormat, function_name, reason); | 3063 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 3021 const Error& error = Error::Handle( | 3064 const Error& error = Error::Handle( |
| 3022 LanguageError::New(String::Handle(String::New(chars)))); | 3065 LanguageError::New(String::Handle(String::New(chars)))); |
| 3023 Isolate::Current()->long_jump_base()->Jump(1, error); | 3066 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 3024 } | 3067 } |
| 3025 | 3068 |
| 3026 | 3069 |
| 3027 } // namespace dart | 3070 } // namespace dart |
| OLD | NEW |