| 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 "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "vm/ast_printer.h" | 8 #include "vm/ast_printer.h" |
| 9 #include "vm/bit_vector.h" | 9 #include "vm/bit_vector.h" |
| 10 #include "vm/code_descriptors.h" | 10 #include "vm/code_descriptors.h" |
| (...skipping 2060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2071 cls.AddClosureFunction(function); | 2071 cls.AddClosureFunction(function); |
| 2072 } | 2072 } |
| 2073 ZoneGrowableArray<PushArgumentInstr*>* arguments = | 2073 ZoneGrowableArray<PushArgumentInstr*>* arguments = |
| 2074 new ZoneGrowableArray<PushArgumentInstr*>(2); | 2074 new ZoneGrowableArray<PushArgumentInstr*>(2); |
| 2075 ASSERT(function.context_scope() != ContextScope::null()); | 2075 ASSERT(function.context_scope() != ContextScope::null()); |
| 2076 | 2076 |
| 2077 // The function type of a closure may have type arguments. In that case, | 2077 // The function type of a closure may have type arguments. In that case, |
| 2078 // pass the type arguments of the instantiator. | 2078 // pass the type arguments of the instantiator. |
| 2079 const Class& cls = Class::ZoneHandle(function.signature_class()); | 2079 const Class& cls = Class::ZoneHandle(function.signature_class()); |
| 2080 ASSERT(!cls.IsNull()); | 2080 ASSERT(!cls.IsNull()); |
| 2081 const bool requires_type_arguments = cls.HasTypeArguments(); | 2081 const bool requires_type_arguments = cls.NumTypeArguments() > 0; |
| 2082 Value* type_arguments = NULL; | 2082 Value* type_arguments = NULL; |
| 2083 if (requires_type_arguments) { | 2083 if (requires_type_arguments) { |
| 2084 ASSERT(cls.type_arguments_field_offset() == | 2084 ASSERT(cls.type_arguments_field_offset() == |
| 2085 Closure::type_arguments_offset()); | 2085 Closure::type_arguments_offset()); |
| 2086 const Class& instantiator_class = Class::Handle( | 2086 const Class& instantiator_class = Class::Handle( |
| 2087 owner()->parsed_function()->function().Owner()); | 2087 owner()->parsed_function()->function().Owner()); |
| 2088 type_arguments = BuildInstantiatorTypeArguments(node->token_pos(), | 2088 type_arguments = BuildInstantiatorTypeArguments(node->token_pos(), |
| 2089 instantiator_class, | 2089 instantiator_class, |
| 2090 NULL); | 2090 NULL); |
| 2091 arguments->Add(PushArgument(type_arguments)); | 2091 arguments->Add(PushArgument(type_arguments)); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2150 PushArgumentInstr* push_receiver = PushArgument(receiver); | 2150 PushArgumentInstr* push_receiver = PushArgument(receiver); |
| 2151 ZoneGrowableArray<PushArgumentInstr*>* arguments = | 2151 ZoneGrowableArray<PushArgumentInstr*>* arguments = |
| 2152 new ZoneGrowableArray<PushArgumentInstr*>(2); | 2152 new ZoneGrowableArray<PushArgumentInstr*>(2); |
| 2153 arguments->Add(push_receiver); | 2153 arguments->Add(push_receiver); |
| 2154 ASSERT(function.context_scope() != ContextScope::null()); | 2154 ASSERT(function.context_scope() != ContextScope::null()); |
| 2155 | 2155 |
| 2156 // The function type of a closure may have type arguments. In that case, | 2156 // The function type of a closure may have type arguments. In that case, |
| 2157 // pass the type arguments of the instantiator. Otherwise, pass null object. | 2157 // pass the type arguments of the instantiator. Otherwise, pass null object. |
| 2158 const Class& cls = Class::Handle(function.signature_class()); | 2158 const Class& cls = Class::Handle(function.signature_class()); |
| 2159 ASSERT(!cls.IsNull()); | 2159 ASSERT(!cls.IsNull()); |
| 2160 const bool requires_type_arguments = cls.HasTypeArguments(); | 2160 const bool requires_type_arguments = cls.NumTypeArguments() > 0; |
| 2161 Value* type_arguments = NULL; | 2161 Value* type_arguments = NULL; |
| 2162 if (requires_type_arguments) { | 2162 if (requires_type_arguments) { |
| 2163 const Class& instantiator_class = Class::Handle( | 2163 const Class& instantiator_class = Class::Handle( |
| 2164 owner()->parsed_function()->function().Owner()); | 2164 owner()->parsed_function()->function().Owner()); |
| 2165 type_arguments = BuildInstantiatorTypeArguments(node->token_pos(), | 2165 type_arguments = BuildInstantiatorTypeArguments(node->token_pos(), |
| 2166 instantiator_class, | 2166 instantiator_class, |
| 2167 NULL); | 2167 NULL); |
| 2168 } else { | 2168 } else { |
| 2169 type_arguments = BuildNullValue(); | 2169 type_arguments = BuildNullValue(); |
| 2170 } | 2170 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2298 void EffectGraphVisitor::VisitCloneContextNode(CloneContextNode* node) { | 2298 void EffectGraphVisitor::VisitCloneContextNode(CloneContextNode* node) { |
| 2299 Value* context = Bind(new CurrentContextInstr()); | 2299 Value* context = Bind(new CurrentContextInstr()); |
| 2300 Value* clone = Bind(new CloneContextInstr(node->token_pos(), context)); | 2300 Value* clone = Bind(new CloneContextInstr(node->token_pos(), context)); |
| 2301 AddInstruction(new StoreContextInstr(clone)); | 2301 AddInstruction(new StoreContextInstr(clone)); |
| 2302 } | 2302 } |
| 2303 | 2303 |
| 2304 | 2304 |
| 2305 Value* EffectGraphVisitor::BuildObjectAllocation( | 2305 Value* EffectGraphVisitor::BuildObjectAllocation( |
| 2306 ConstructorCallNode* node) { | 2306 ConstructorCallNode* node) { |
| 2307 const Class& cls = Class::ZoneHandle(node->constructor().Owner()); | 2307 const Class& cls = Class::ZoneHandle(node->constructor().Owner()); |
| 2308 const bool requires_type_arguments = cls.HasTypeArguments(); | 2308 const bool requires_type_arguments = cls.NumTypeArguments() > 0; |
| 2309 | 2309 |
| 2310 // In checked mode, if the type arguments are uninstantiated, they may need to | 2310 // In checked mode, if the type arguments are uninstantiated, they may need to |
| 2311 // be checked against declared bounds at run time. | 2311 // be checked against declared bounds at run time. |
| 2312 Definition* allocation = NULL; | 2312 Definition* allocation = NULL; |
| 2313 if (FLAG_enable_type_checks && | 2313 if (FLAG_enable_type_checks && |
| 2314 requires_type_arguments && | 2314 requires_type_arguments && |
| 2315 !node->type_arguments().IsNull() && | 2315 !node->type_arguments().IsNull() && |
| 2316 !node->type_arguments().IsInstantiated() && | 2316 !node->type_arguments().IsInstantiated() && |
| 2317 node->type_arguments().IsBounded()) { | 2317 node->type_arguments().IsBounded()) { |
| 2318 ZoneGrowableArray<PushArgumentInstr*>* allocate_arguments = | 2318 ZoneGrowableArray<PushArgumentInstr*>* allocate_arguments = |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2551 type_arguments, | 2551 type_arguments, |
| 2552 instantiator_class, | 2552 instantiator_class, |
| 2553 instantiator_value)); | 2553 instantiator_value)); |
| 2554 } | 2554 } |
| 2555 | 2555 |
| 2556 | 2556 |
| 2557 void EffectGraphVisitor::BuildConstructorTypeArguments( | 2557 void EffectGraphVisitor::BuildConstructorTypeArguments( |
| 2558 ConstructorCallNode* node, | 2558 ConstructorCallNode* node, |
| 2559 ZoneGrowableArray<PushArgumentInstr*>* call_arguments) { | 2559 ZoneGrowableArray<PushArgumentInstr*>* call_arguments) { |
| 2560 const Class& cls = Class::ZoneHandle(node->constructor().Owner()); | 2560 const Class& cls = Class::ZoneHandle(node->constructor().Owner()); |
| 2561 ASSERT(cls.HasTypeArguments() && !node->constructor().IsFactory()); | 2561 ASSERT((cls.NumTypeArguments() > 0) && !node->constructor().IsFactory()); |
| 2562 if (node->type_arguments().IsNull() || | 2562 if (node->type_arguments().IsNull() || |
| 2563 node->type_arguments().IsInstantiated()) { | 2563 node->type_arguments().IsInstantiated()) { |
| 2564 Value* type_arguments_val = Bind(new ConstantInstr(node->type_arguments())); | 2564 Value* type_arguments_val = Bind(new ConstantInstr(node->type_arguments())); |
| 2565 call_arguments->Add(PushArgument(type_arguments_val)); | 2565 call_arguments->Add(PushArgument(type_arguments_val)); |
| 2566 | 2566 |
| 2567 // No instantiator required. | 2567 // No instantiator required. |
| 2568 Value* instantiator_val = Bind(new ConstantInstr( | 2568 Value* instantiator_val = Bind(new ConstantInstr( |
| 2569 Smi::ZoneHandle(Smi::New(StubCode::kNoInstantiator)))); | 2569 Smi::ZoneHandle(Smi::New(StubCode::kNoInstantiator)))); |
| 2570 call_arguments->Add(PushArgument(instantiator_val)); | 2570 call_arguments->Add(PushArgument(instantiator_val)); |
| 2571 return; | 2571 return; |
| (...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3839 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; | 3839 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; |
| 3840 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 3840 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 3841 OS::SNPrint(chars, len, kFormat, function_name, reason); | 3841 OS::SNPrint(chars, len, kFormat, function_name, reason); |
| 3842 const Error& error = Error::Handle( | 3842 const Error& error = Error::Handle( |
| 3843 LanguageError::New(String::Handle(String::New(chars)))); | 3843 LanguageError::New(String::Handle(String::New(chars)))); |
| 3844 Isolate::Current()->long_jump_base()->Jump(1, error); | 3844 Isolate::Current()->long_jump_base()->Jump(1, error); |
| 3845 } | 3845 } |
| 3846 | 3846 |
| 3847 | 3847 |
| 3848 } // namespace dart | 3848 } // namespace dart |
| OLD | NEW |